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

"Developing in the monorepo" instructions incomplete #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mikesamuel
Copy link

I ran into a problem with the previous startup instructions.

_scripts/build.sh and friends assume tools in ../node_modules/.bin relative to _scripts.

npm_bin=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)/../node_modules/.bin
$npm_bin/babel src -d lib

Normally npm install in a directory that contains a package.json will create a node_modules subdirectory, but not when the current directory is named node_modules.

Renaming the node_modules directory to something else, running npm install, and then changing the directory back does not work because require(...) will not look for a node_modules subdirectory inside a node_modules directory.

This happens because of how require(...) searches ancestor-ward:

NODE_MODULES_PATHS(START)

  1. let PARTS = path split(START)
  2. let I = count of PARTS - 1
  3. let DIRS = [GLOBAL_FOLDERS]
  4. while I >= 0,
    a. if PARTS[I] = "node_modules" CONTINUE

The changed setup instructions address the problem by cloning into a different directory name so that there is no node_modules path element on "$PWD".

I ran into a problem with the previous startup instructions.

`_scripts/build.sh` and friends assume tools in `../node_modules/.bin` relative to `_scripts`.

https://github.com/calebmer/node_modules/blob/770648585a7f96aa75604578146a08a8aec8bbf6/_scripts/build.sh#L7-L9

Normally `npm install` in a directory that contains a `package.json` will create a `node_modules` subdirectory, but not when the current directory is named `node_modules`.

Renaming the `node_modules` directory to something else, running `npm install`, and then changing the directory back does not work because `require(...)` will not look for a `node_modules` subdirectory inside a `node_modules` directory.

This happens because of how [`require(...)` searches](https://nodejs.org/api/modules.html#modules_all_together) ancestor-ward:

> NODE_MODULES_PATHS(START)
> 1. let PARTS = path split(START)
> 2. let I = count of PARTS - 1
> 3. let DIRS = [GLOBAL_FOLDERS]
> 4. while I >= 0,
>    a. **if PARTS[I] = "node_modules" CONTINUE**

The changed setup instructions address the problem by cloning into a different directory name so that there is no `node_modules` path element on "$PWD".
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