All packages (top-level and dependencies) go in the __bikeshed__/
directory where they are versioned.
node_modules/__bikeshed__/[email protected]/
node_modules/__bikeshed__/[email protected]/
node_modules/__bikeshed__/[email protected]/
node_modules/__bikeshed__/[email protected]/
When you install a package, it also creates a top-level entry which redirects to a specific version in the __bikeshed__/
directory.
This could be done with softlinks or auto-generated files. (require(x)
will load for x.js
).
node_modules/add_two_numbers.js
// auto-generated_file -- do not edit.
'use strict';
module.exports = require('__bikeshed__/[email protected]');
--or--
node_modules/add_two_numbers -> __bikeshed__/[email protected]
packages in the __bikeshed__/
directory also have a node_modules/
directory that redirect to a specific version:
node_modules/__bikeshed__/[email protected]/node_modules/lodash.js
// auto-generated_file -- do not edit.
'use strict';
module.exports = require('__bikeshed__/[email protected]');
--or--
node_modules/__bikeshed__/[email protected]/node_modules/lodash -> ../../[email protected]
This layout eliminates duplicate packages and creates a smaller and flatter node_modules/
directory. It also makes version swapping painless since you only need to change one file, not an entire hierarchy. The only downside I can see is an extra require()
call in the package stub. Using soft links would eliminate that issue.
The end!
And.... pnpm does that. 99.9% of node doesn't get it but once in a while you find something (like rollup or pnpm) that gets it.