Tuesday, 18 April 2017

How to `npm link` from multiple directories beside and below current?

I have a single subdirectory of local npm packages in a single git repo.

I need instead, to layer it into two separate parts : the rarely changing packages in a git submodule, and the often varying ones in the container repo.

So currently I have this...

 .
 ├── .meteor
 │   ├── meteor -> packages/meteor-tool/1.4.4_1/mt-os.linux.x86_64/meteor
 │   └── packages
 │       └── meteor-tool/1.4.4_1....bundle/lib/node_modules
 │                       ├── mmks_book -> /home/you/projects/meteor-mantra-kickstarter/.pkgs/mmks_book 
 │                       └── mmks_widget -> /home/you/projects/meteor-mantra-kickstarter/.pkgs/mmks_widget
   :   :    :
 ├── projects
 │   ├── meteor-mantra-kickstarter
 │   │   ├── node_modules
   :   :    :
 │   │   │   ├── mmks_book -> ../../../.meteor/packages/meteor-tool/.1.4.4_1....bundle/lib/node_modules/mmks_book
 │   │   │   ├── mmks_widget -> ../../../.meteor/packages/meteor-tool/.1.4.4_1....bundle/lib/node_modules/mmks_widget
   :   :    :
 │   │   ├── package.json
 │   │   ├── .pkgs
 │   │   │   ├── mmks_book
 │   │   │   └── mmks_widget
   :   :    :
 │   │   └── settings.json
 │   └── mmks
 └── .xsession-errors.old

The command meteor npm link, executed in each of the source code directories ~/projects/meteor-mantra-kickstarter/.pkgs/mmks_book and ~/projects/meteor-mantra-kickstarter/.pkgs/mmks_widget creates the symbolic links mmks_book and mmks_widget under ../../../.meteor/packages/meteor-tool/.1.4.4_1....bundle/lib/node_modules

Then, the corresponding symlinks in ~/projects/meteor-mantra-kickstarter/node_modules exist after I cd into the project root ~/projects/meteor-mantra-kickstarter and execute meteor npm link mmks_book and meteor npm link mmks_widget.

That has been working very well for me for months.

Now, the new layout looks like this ...

 .
 ├── .meteor
 │   ├── meteor -> packages/meteor-tool/1.4.4_1/mt-os.linux.x86_64/meteor
 │   └── packages
 │       └── meteor-tool/1.4.4_1....bundle/lib/node_modules
 │                       ├── mmks_book -> /home/you/projects/mmks/.pkgs/mmks_book 
 │                       └── mmks_widget -> /home/you/projects/mmks/meteor-mantra-kickstarter/.pkgs/mmks_widget
   :   :    :
 ├── projects
 │   └── mmks
 │       ├── .gitmodules
 │       ├── meteor-mantra-kickstarter
 │       │   ├── node_modules
   :   :    :
 │       │   │   ├── mmks_book -> ../../../.meteor/packages/meteor-tool/.1.4.4_1....bundle/lib/node_modules/mmks_book
 │       │   │   ├── mmks_widget -> ../../../.meteor/packages/meteor-tool/.1.4.4_1....bundle/lib/node_modules/mmks_widget
   :   :    :
 │       │   ├── package.json
 │       │   ├── .pkgs
 │       │   │   └── mmks_widget
   :   :    :
 │       │   └── settings.json
 │       └── .pkgs
 │           └── mmks_book
 └── .xsession-errors.old

The differences are :

  1. The directory meteor-mantra-kickstarter has moved under the directory mmks
  2. The .pkgs directory has undergone a sort of mitosis that leaves .pkgs/mmks_widget inside the git submodule meteor-mantra-kickstarter while .pkgs/mmks_book moves into the container parent.
  3. While the mmks_book and mmks_widget symlinks under ~/.meteor... have changed to point correctly to the new positions of their target packages, the symlinks in the node_modules directory of the submodule remain the same.

Unfortunately, this new layout results in mmks_book spewing many errors like ...

 Error: Cannot find module 'react'

... that I can work around by adding the missing dependencies to it's package.json definitions file ...

 ~/projects/mmks/.pkgs/mmks_book/package.json

Once I satisfy all the dependencies that that package requires, I can build meteor-mantra-kickstarter and its parent container mmks into a single apparently working application.

However, when I attempt to use mmks_book I find that it's direct dependencies complain about missing their own dependencies, possibly ad infinitum, and break the package's functionality.

Is there a way to do this, or am I attempting the impossible?


Versions :

you@yours:~$
you@yours:~$ meteor npm version
{ 'meteor-mantra-kickstarter': '0.4.0',
  npm: '4.4.4',
  ares: '1.10.1-DEV',
  http_parser: '2.7.0',
  icu: '56.1',
  modules: '46',
  node: '4.8.1',
  openssl: '1.0.2k',
  uv: '1.9.1',
  v8: '4.5.103.46',
  zlib: '1.2.8' }
you@yours:~$ meteor --version
Meteor 1.4.4.1
you@yours:~$
you@yours:~$



via Martin

No comments:

Post a Comment