Features
- Local modules followed by symbolic links (no need reinstall it each time)
- Symlinks are relative so you can save it in repository (better than
npm link
with absolute symlinks) - Zip follows symlinks so your app.zip contains all it need (no broken links)
- Symlinks are relative so you can save it in repository (better than
- Local modules are shared between each other
- No dependencies duplication for shared local modules
- Single version of shared wrapper module (like
lodash
or else)- Also w/o duplication
- Recursive commands for installing and cleaning usual and shared modules
Install
npm install --global shmod
Usage
> shmodUsage: shmod find - Show all sharedDependencies shmod link - Find all sharedDependencies and map it to node_modules/@shared/ shmod install - Run recursive 'npm install'
Example
Directories layout:
a/
|--_modules/
| |- when/ # Shared wrapper module: content will be generated by 'shmod wrap'
| \- lodash/ # Shared wrapper module: content will be generated by 'shmod wrap'
\--b/
|- _modules/
| |- joi/ # Shared wrapper module: content will be generated by 'shmod wrap'
| \- lib/ # Custom shared module
| |- index.js
| \- package.json
\- app/
|- index.js
\- package.json
Shared wrapper modules
Prepare shared module in a/_modules
that wraps when
module:
> cd a/_modules/when> shmod wrap when 3.7.7package.json: Createindex.js: Create
Prepare shared module in a/_modules
that wraps lodash
module:
> cd a/_modules/lodash> shmod wrap lodash 4.17.4package.json: Createindex.js: Create
Prepare shared module in a/b/_modules
that wraps joi
module:
> cd a/b/_modules/joi> shmod wrap joi 10.2.0package.json: Createindex.js: Create
Shared library module
Write your custom library in a/b/_modules/lib/index.js
:
const _ = ;console; const when = ;moduleexports = when;
Specify shared dependencies for the app in a/b/app/package.json
used directly in the lib:
App module
Write your app in a/b/app/index.js
:
const lib = lib; // prints: 'lib promise' const Joi = ;console const when = ;when // Lodash not used directly from here, but used from the lib!!!
Specify shared dependencies for the app in a/b/app/package.json
used directly in the app:
Install shared local dependencies from upper `../*/_modules/' directories:
> cd a/b/app> shmod buildcd /Users/urukhai/Job/nu/npm/shmod/test/a/_modules/when && npm installcd /Users/urukhai/Job/nu/npm/shmod/test/a/b/_modules/lib && npm installcd /Users/urukhai/Job/nu/npm/shmod/test/a/_modules/lodash && npm installcd /Users/urukhai/Job/nu/npm/shmod/test/a/b/_modules/joi && npm installcd /Users/urukhai/Job/nu/npm/shmod/test/a/b/app && npm installLink: node_modules/@shared/when -> ../../../../_modules/whenLink: node_modules/@shared/lib -> ../../../_modules/libLink: node_modules/@shared/lodash -> ../../../../_modules/lodashLink: node_modules/@shared/joi -> ../../../_modules/joi
Run app:
> cd a/b/app> node --preserve-symlinks index.js # --preserve-symlinks required for working with node_modules/@shared/* symlinks _: squares: [ 1, 4, 9 ]
Results
- Check
a/b/app/node_modules/@shared/*
- there are local (relative) only links! Not absolute likenpm link
! - All your links to shared local modules in your git repository!
- Check
a/b/app/node_modules
: there is no duplication forwhen
while it used fromlib
andapp
! - Version of
when
specified once only ina/_modules/when/package.json
! - Version of
lodash
specified once only ina/_modules/lodash/package.json
! - Version of
joi
specified once only ina/b/_modules/joi/package.json
! - All shared and usual dependencies of the app was installed via single run
shmod build
!
Git ignore
Ignore anything in node_modules
but not @shared
**/node_modules/*!**/node_modules/@shared
Feedback
Feel free to add issue: https://bitbucket.org/nukisman/shmod/issues