arloliu / copy-node-modules

Fast deploy Node.js modules from local source folder to distination folder
26 stars 14 forks source link

Deeply nested dependencies are not copied #42

Open mpsijm opened 1 year ago

mpsijm commented 1 year ago

To reproduce:

~ $ mkdir tmp
~ $ cd tmp
~/tmp $ npm i --save mongoose@7.6.4
~/tmp $ npm i --save-dev copy-node-modules
~/tmp $ npm ls @mongodb-js/saslprep
tmp@ /home/mpsijm/tmp
└─┬ mongoose@7.6.4
  └─┬ mongodb@5.9.0
    └── @mongodb-js/saslprep@1.1.1 deduped

~/tmp $ mkdir dist
~/tmp $ npx copy-node-modules . dist
~/tmp $ cd dist
~/tmp/dist $ npm ls @mongodb-js/saslprep
/home/mpsijm/tmp/dist
└── (empty)

In this example, the nested dependency @mongodb-js/saslprep should be copied to dist/node_modules (as dependency of mongodb, but it's not. Note that mongodb itself is copied, even though its dependencies are not:

~/tmp/dist $ npm ls mongodb
/home/mpsijm/tmp/dist
├── mongodb@5.9.0 extraneous
└─┬ mongoose@7.6.4 extraneous
  └── mongodb@5.9.0 deduped

This is probably because mongodb exists at the top-level node_modules folder, whereas @mongodb-js/saslprep does not.

System info:

mpsijm commented 1 year ago

As a workaround, it is also possible to copy the entire repository, run npm i --omit dev, and then copy the resulting node_modules folder.