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

RFC for npm run to traverse directory tree up to the root before failing #73

Closed
wants to merge 1 commit into from

Conversation

agorovyi
Copy link
Contributor

@agorovyi agorovyi commented Dec 5, 2019

Let npm run traverse monorepo directory tree up to the root before failing

With this request I would like to be able to execute npm run command that will traverse the directory tree up to the root level if it can't find a required /node_modules/.bin with executable command in subdirectory where it was executed from.

A detailed explanation and the rationale is covered in the .md file.

@agorovyi agorovyi changed the title Let npm run traverse monorepo directory tree up to the root before failing RFC for npm run to traverse directory tree up to the root before failing Dec 5, 2019
@darcyclarke darcyclarke added Agenda will be discussed at the Open RFC call Needs Discussion is pending a discussion Enhancement new feature or improvement Release 7.x semver:major backwards-incompatible breaking changes labels Dec 17, 2019
@isaacs
Copy link
Contributor

isaacs commented Jan 22, 2020

Ah! I had missed this PR, but I was working on the implementation for #90 today, saw the bit of code that sets up the PATH environ, and had a suspicion that this would be an issue.

In fact, rather than splitting on node_modules, it should append node_modules/.bin to every parent path. Eg, a module at /x/y/z/node_modules/a/node_modules/b would have a PATH containing:

/x/y/z/node_modules/a/node_modules/b/node_modules/.bin
/x/y/z/node_modules/a/node_modules/node_modules/.bin
/x/y/z/node_modules/a/node_modules/.bin
/x/y/z/node_modules/node_modules/.bin
/x/y/z/node_modules/.bin
/x/y/node_modules/.bin
/x/node_modules/.bin
/node_modules/.bin

I think it might be good to set a "project root" dir to not walk up past (ie, /x/y/z in this example), but getting that reliably is a little bit tricky, and I'm not sure it matters much.

So, I think npm v7 will satisfy you there by default.

As a corollary (which I'm not sure how or if to take advantage of?) is that we could put metadeps in ./node_modules/node_modules/, so they're accessible to anything in node_modules, but not to the root project. That could prevent unlisted deps, which are a problem in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement new feature or improvement Needs Discussion is pending a discussion semver:major backwards-incompatible breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants