Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Two child modules are being watched and linked #6

Merged
merged 13 commits into from Jul 5, 2019

Conversation

alechp
Copy link
Contributor

@alechp alechp commented Jul 4, 2019

No description provided.

@alechp
Copy link
Contributor Author

alechp commented Jul 4, 2019

Current issue is that child modules are being linked in protato-lib's root dir instead of node-starter (designated parent per protato.js config)

Screen Shot 2019-07-04 at 11 18 47 AM

@alechp alechp changed the title Two child modules are being watched and linked WIP Two child modules are being watched and linked Jul 4, 2019
@alechp
Copy link
Contributor Author

alechp commented Jul 4, 2019

Seems like there isn't an npm link equivalent for --prefix like npm install: https://stackoverflow.com/questions/14469515/how-to-npm-install-to-a-specified-directory

npm link --prefix /dir/ seems to specify where the symlink should be installed globally, not where the actual package should be linked to...

Not sure if --prefix can just be overloaded with something like
npm link --prefix ./my/parent/dir nameOfChildModule

Going to try that and then move onto exploring https://www.npmjs.com/package/yalc

@alechp
Copy link
Contributor Author

alechp commented Jul 4, 2019

Prefix seems to be doing something. Added a parentCmd setter to help.

This is the result:
Screen Shot 2019-07-04 at 12 08 24 PM
Screen Shot 2019-07-04 at 12 08 27 PM
Screen Shot 2019-07-04 at 12 09 02 PM
Screen Shot 2019-07-04 at 12 09 18 PM

I'm wondering if this is because --prefix is normally usr/local/lib/node_modules Compare that to:
/Users/alechp/Code/servexyz/protato/.repositories/protato-lib/sandbox/node-starter/lib/node_modules/npm-starter-sample-module

The issue of course is the lib being appended. But there's another question: is node_modules also being appended because of prefix? I Don't believe I'm generating this path anywhere which makes me think the answer is yes

@alechp
Copy link
Contributor Author

alechp commented Jul 4, 2019

Yeah doesn't seem like my hacky approach is the intended path.
https://npm.community/t/windows-npm-install-with-prefix-does-not-link-executables-to-the-bin-directory/1919

What's weird to me is: why is /lib/node_modules being appended at all?
Seems like I replace /usr/local with my parent path. Then it adds the lib/node_modules which seems like it would be the intended root dir usr/local/lib/node_modules

Wonder if there's another npm config I can overwrite temporarily?

prefix=/usr/local
registry=https://registry.npmjs.org

Found it:

❯ npm root -g
/usr/local/lib/node_modules

@alechp
Copy link
Contributor Author

alechp commented Jul 4, 2019

Relevant resources

https://docs.npmjs.com/misc/config#global
https://docs.npmjs.com/files/folders

Packages are dropped into the node_modules folder under the prefix. When installing locally, this means that you can require("packagename") to load its main module, or require("packagename/lib/path/to/sub/module") to load other modules.

Global installs on Unix systems go to {prefix}/lib/node_modules. Global installs on Windows go to {prefix}/node_modules (that is, no lib folder.)

Scoped packages are installed the same way, except they are grouped together in a sub-folder of the relevant node_modules folder with the name of that scope prefix by the @ symbol, e.g. npm install @myorg/package would place the package in {prefix}/node_modules/@myorg/package. See scope for more details.

If you wish to require() a package, then install it locally.

or just the important bits

Global installs on Unix systems go to {prefix}/lib/node_modules. Global installs on Windows go to {prefix}/node_modules (that is, no lib folder.)

This is where it's being set in npm config:

# NPM Global modules (npm get prefix)
export PATH="/usr/local/lib/node_modules:$PATH"

Meanwhile, this is npm config list results (to reiterate what we've already established):
Screen Shot 2019-07-04 at 12 45 38 PM

@alechp
Copy link
Contributor Author

alechp commented Jul 4, 2019

Started to think maybe I could bypass with npm install --link

Per https://docs.npmjs.com/cli/install: it sounded promising "The --link argument will cause npm to link global installs into the local space in some cases."

But after reading this thread seems like that's not the case
npm/npm#6863

Going to check out:
https://www.npmjs.com/package/linklocal

The caveat in linklocal sounds pretty obnoxious (especially given that the delay on npm link is already stretching):
https://www.npmjs.com/package/linklocal

@alechp
Copy link
Contributor Author

alechp commented Jul 4, 2019

Playing around with yalc.

Benefits

  1. Installs to local .yalc directory which means I bypass all of the global & prefixing issues I was having before

Screen Shot 2019-07-04 at 2 32 39 PM

Downsides so far seems to be

  1. Still a risk of needing to npm install
  2. Requires global install

Debug pain point

  1. It keeps installing node-starter instead of child modules. Not sure why

Screen Shot 2019-07-04 at 2 30 17 PM

@alechp
Copy link
Contributor Author

alechp commented Jul 4, 2019

Really scratching my head here. Starting to wonder if it has something to do with yalc's install path?

wclr/yalc#47

Notice that a yalc.lock file is created in protato-lib/ root directory. It's also created in node-starter (even though this is the parent which is doing the yalc add childModName or yalc link childModName (I've tried both)

node-starter is published regardless... Which is weird because the current directory is set to modifiedRootDir, which is consistently right (as seen in previous comment's log screenshot)

@alechp alechp merged commit 19e4c62 into master Jul 5, 2019
@alechp alechp deleted the two-child-modules branch July 5, 2019 18:29
@alechp alechp restored the two-child-modules branch July 5, 2019 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant