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

[BUG] 10.4 and later: $npm_package_config_* variables no longer work for arrays #7343

Closed
2 tasks done
Twipped opened this issue Apr 4, 2024 · 5 comments
Closed
2 tasks done

Comments

@Twipped
Copy link

Twipped commented Apr 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

In our package.json we have an array of values that we access via environment variables in our npm scripts. Example:

  "scripts": {
    "echo": "echo $npm_package_config_foo $npm_package_config_bar"
  },
  "config": {
    "foo": [
      "a",
      "b",
      "c"
    ],
    "bar": "d e f"
  },

Under 10.4 and 10.5, the $npm_package_config_foo variable is either empty, or isn't defined.

➜  /workspace git:(main) ✗ npm run echo 

> [email protected] echo
> echo $npm_package_config_foo $npm_package_config_bar

d e f
➜  /workspace git:(main) ✗ npm --version
10.5.0

Expected Behavior

Under npm 10.2 and 10.3, arrays would be concatenated into a space separated list.

Running npm run echo outputs:

➜  /workspace git:(main) ✗ npm run echo

> [email protected] echo
> echo $npm_package_config_foo $npm_package_config_bar

a b c d e f
➜  /workspace git:(main) ✗ npm --version
10.2.4

Steps To Reproduce

I have created a codesandbox with an example. https://codesandbox.io/p/devbox/dnkx8d

Running nvm i 18.19 will get you npm 10.2.4, and nvm i 18.20 will get you npm 10.5.0.

In my local debugging I confirmed the change was between 10.3 and 10.4.

Environment

  • npm: 10.5.0
  • Node.js: 18.20.1
  • OS Name: Linux and macOS
  • System Model Name: Macbook Pro M1, and in codesandbox
  • npm config:
; "env" config from environment

cache = "/root/.cache/npm" 
store-dir = "/root/.cache/pnpm" 

; node bin location = /usr/local/share/nvm/versions/node/v18.20.1/bin/node
; node version = v18.20.1
; npm local prefix = /workspace
; npm version = 10.5.0
; cwd = /workspace
; HOME = /root
; Run `npm config ls -l` to show all defaults.
@Twipped Twipped added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Apr 4, 2024
@milaninfy
Copy link
Contributor

@Twipped It can be accessed as "echo $npm_package_config_foo_0 $npm_package_config_foo_1 $npm_package_config_foo_2 $npm_package_config_bar"
This was done here npm/run-script#194

@Twipped
Copy link
Author

Twipped commented Apr 4, 2024

I understand that, but the behavior where the array was coerced into arguments has vanished, and it broke some of our workflows.

@milaninfy
Copy link
Contributor

@Twipped This is not a bug and it's expected behaviour and those values can be accessed as _0, _1, _2 and so on based on how many values are there in array. This behaviour got changed in v7 and it got fixed in this PR npm/run-script#194

@milaninfy milaninfy removed Bug thing that needs fixing Needs Triage needs review for next steps labels Apr 5, 2024
@milaninfy milaninfy closed this as not planned Won't fix, can't repro, duplicate, stale Apr 8, 2024
@Twipped
Copy link
Author

Twipped commented Apr 8, 2024

Did you read any of what I wrote? The behavior I'm referencing did not change in v7, it changed in 10.4 with the change of npm version released in node 18.19 and 18.20, and I gave you a reproduction of that exact change.

I am not talking about referencing individual items in the array, I'm talking about referencing the array as a whole. You released a breaking change as a minor update.

@markrzen
Copy link

markrzen commented Apr 9, 2024

@milaninfy Prior to the latest patch version change the behavior worked.

I am surprised that no one in the pull request called this interface change out as the breaking change that it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants