npm-dedupe-symlinks
v0.2.1
Published
Dedupes a package even if it contains symbolic links
Downloads
5
Readme
npm-dedupe-symlinks
ATTENTION: this command messes with your directory structure. In its current state it should be used with caution. Make a backup of your project first.
npm dedupe
ignores modules that are symbolic links (e. g. when using npm link
)
resulting in incomplete deduplication.
Thus npm-dedupe-symlinks
was created to dedupe the current working directory,
even if the node_modules
folder contains symbolic links. It does so by creating
a directory structure without any symbolic links, then using npm dedupe
and
recreating the symbolic links.
It can handle the following constellations:
my-package/node_modules/symlinkedModule
my-package/node_modules/@symlinkedScope/module
my-package/node_modules/@scope/symlinkedModule
It currently does not work for symbolic links that are nested deeper in the
directory hierarchy than one level (except for linked modules inside @scopes
).
Usage
npm install -g npm-dedupe-symlinks
cd /to/the/package/i/want/to/dedupe
npm-dedupe-symlinks
If the command fails, you may need to re-create your symbolic links. Dependencies might be lost as well.
Be warned: if you have one module symlinked into multiple projects, not all of those projects may work due to missing (deduped) dependencies.
Development
# after cloning, run once
npm run build
# there's also a watcher
npm run watch:build
FAQ
How does it work?
- unlink linked modules (only on the first level)
- create an empty directory in its place
- copy the
package.json
from the link's target to the empty directory - move the
node_modules
directory from the link's target to the empty directory - run
npm dedupe
- move the module's deduped
node_modules
directory (if it still exists) back to the link target - delete the directory, which is now empty again
- re-link the modules (create symbolic links)
It uses RxJS internally.
Moving the node_modules
directory is slow
Make sure everything is on the same volume.
TODO
- write some tests