In Node.js projects, I keep coming back to a small habit. When I use something from a third-party package, I often import it into one file under src/lib/. The rest of my code imports from that local file.
At first, the file may do almost nothing. It can look like an unnecessary stop on the way to the package. The payoff appears later, when the package moves an export or changes its API.
Its import path moves. Each caller may need an edit.
Its import path moves. The local module absorbs that change.
Start with a re-export
Say several files use a parser. Without a boundary, each file names the vendor’s package path. I can instead make one local module and have callers depend on it:
// src/lib/parser.ts
export { parseText } from '@vendor/parser/legacy';
// src/features/article.ts
import { parseText } from '../lib/parser.js';// src/lib/parser.js
export { parseText } from '@vendor/parser/legacy';
// src/features/article.js
import { parseText } from '../lib/parser.js';If the package later exports parseText from its root, I update the local module. The feature file does not need to learn where the vendor moved it.
// src/lib/parser.ts
export { parseText } from '@vendor/parser';// src/lib/parser.js
export { parseText } from '@vendor/parser';I call this my Adapter pattern. At its smallest, the module is only a re-export: a place where my app meets a dependency. When the package changes its calling convention, that same module becomes an adapter in the stricter sense, translating between the app’s interface and the vendor’s.
When a re-export is no longer enough
Suppose the new package version replaces parseText(input) with a parser object that expects { text: input }. A re-export cannot preserve the old call. I can expose the new interface, keep the old one working for now, and warn when a caller still uses it:
// src/lib/parser.ts
import { createParser } from '@vendor/parser';
const parser = createParser();
export function parseDocument(options: { text: string }): string {
return parser.parse(options);
}
export function parseText(input: string): string {
if (process.env.NODE_ENV !== 'production') {
console.warn('Migrate parseText() call to parseDocument({ text }).');
}
return parseDocument({ text: input });
}// src/lib/parser.js
import { createParser } from '@vendor/parser';
const parser = createParser();
export function parseDocument(options) {
return parser.parse(options);
}
export function parseText(input) {
if (process.env.NODE_ENV !== 'production') {
console.warn('Migrate parseText() call to parseDocument({ text }).');
}
return parseDocument({ text: input });
}The package names and signatures are fictional; the migration shape is the point. The TypeScript example uses NodeNext-style .js import paths for emitted ESM.That lets me migrate call sites incrementally. The warning makes old calls visible during development while production stays quiet. If this function runs often, I would limit the warning or use a code search or lint rule instead of flooding the console. Once every caller uses parseDocument, I can remove parseText.
What this does not solve
- Behavior can still change. If parsing now means something different, an unchanged function name cannot make the upgrade safe. I still need tests around the results my app cares about.
- A thin re-export can leak the vendor’s design. If callers use vendor-specific options and types everywhere, I may still have a large migration. A wrapper helps only when it offers an interface my app can actually keep stable.
- Too many boundaries add ceremony. I would not make a wrapper for every trivial import. A single giant
libsfile is not much better; small modules named for a dependency or capability are easier to find.
I also prefer explicit named exports over export *. The file then shows exactly which pieces of the package the app has chosen to depend on.
When I reach for it
This habit earns its keep when a dependency appears in many files, has import paths likely to move, or sits near an important part of the app. I start with the smallest boundary that helps. If an upgrade changes only a path, a re-export may be enough. If it changes a signature, I can adapt it there. If the meaning changes, I treat that as a real migration rather than pretending one file fixed everything.
Put one clear place between your code and a dependency when that seam will make change easier. Centralizing imports is useful. Owning the interface is the deeper payoff.
Further reading
This post describes a practice from my work. These docs explain the module features behind the examples: