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

INIT_CWD does not get reset if npm install is invoked by another npm script #2578

Closed
jsg2021 opened this issue Jan 30, 2021 · 4 comments · Fixed by npm/config#12
Closed

INIT_CWD does not get reset if npm install is invoked by another npm script #2578

jsg2021 opened this issue Jan 30, 2021 · 4 comments · Fixed by npm/config#12
Assignees
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@jsg2021
Copy link

jsg2021 commented Jan 30, 2021

@Geod24 The tests are in npm/config@7070885 This is a bug in @npmcli/config, not in the cli itself.

Originally posted by @isaacs in #2033 (comment)

This is maybe more of a question. But I was surprised by the fact INIT_CWD retained the parent process's value when a post-install script installed a child-directory project...

@isaacs
Copy link
Contributor

isaacs commented Feb 2, 2021

Hm, yes, it appears that I misread the npm v6 behavior.

isaacs added a commit to npm/config that referenced this issue Feb 2, 2021
This should always be set to the npm cwd, even if already in the env.

Fix: npm/cli#2578
@darcyclarke darcyclarke added this to the OSS - Sprint 23 milestone Feb 2, 2021
@darcyclarke darcyclarke added Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release labels Feb 2, 2021
darcyclarke pushed a commit to npm/config that referenced this issue Feb 2, 2021
This should always be set to the npm cwd, even if already in the env.

Fix: npm/cli#2578
darcyclarke pushed a commit to npm/config that referenced this issue Feb 2, 2021
* Restore npm v6 behavior with INIT_CWD

This should always be set to the npm cwd, even if already in the env.

Fix: npm/cli#2578

* Do not set the PREFIX environment variable

Fix: npm/cli#2398
@mathiaswillburger
Copy link

mathiaswillburger commented Feb 9, 2021

How is INIT_CWD accessed now? I used it in my scripts on Windows like this, which always worked in version 6, but now doesn't anymore:

"scripts": {
    "format": "prettier-eslint --write %INIT_CWD%/src/**/*.{js,jsx}",
  },

I am using npm v7.5.3

@jsg2021
Copy link
Author

jsg2021 commented Feb 9, 2021

How is INIT_CWD accessed now? I used it in my scripts on Windows like this, which always worked in version 6, but now doesn't anymore:


"scripts": {

    "format": "prettier-eslint --write %INIT_CWD%/src/**/*.{js,jsx}",

  },

I am using npm v7.5.3

If your shell is bash for windows:

"scripts": {
    "format": "prettier-eslint --write $INIT_DIR/src/**/*.{js,jsx}",
 },

But you shouldn't need that, just use "./src..."

@mathiaswillburger
Copy link

mathiaswillburger commented Feb 9, 2021

Thanks @jsg2021 for the fast response.

You are obviously right that the easiest solution would be to use ./src. Unfortunately, prettier-eslint-cli requires an absolute path as parameter and does not accept relative paths to initialize it via npm scripts. Otherwise, it throws the error [ERR_ASSERTION]: 'basePath' should be an absolute path.

Using $INIT_DIR also does not work in version 7.5.3. For some reason, it does not get resolved. Neither do any of the other options like %INIT_CWD% $INIT_CWD $INIT_DIR %INIT_DIR% $PWD %PWD%

However, I finally found a workaround using cross-env-shell which resolves the paths correctly:

"scripts": {
    "format": "cross-env-shell prettier-eslint --write  %INIT_CWD%/src/**/*.{js,jsx}",
 },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants