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

[QUESTION] Alternative for $npm_package_* to pass multiple parameters to node #305

Closed
dandv opened this issue Jan 7, 2021 · 4 comments
Closed

Comments

@dandv
Copy link
Contributor

dandv commented Jan 7, 2021

Motivation ("The Why")

In my package.json, I have several scripts that call node with the same parameters over and over. To simplify that invocation, I've created a package.json variable, and am invoking the scripts like this:

{
  "nodeParams": "--experimental-specifier-resolution=node --harmony -r source-map-support/register",
  "scripts": {
    "dostuff": "node $npm_package_nodeParams myscript.js"
  }
}

This is quite common for calling compiled TypeScript code, but no longer works in v7 due to RFC21. However, I can't find what the recommended alternative is.

I picked up this idea from somewhere on StackOverflow, so I'm probably not the only one impacted by the change.

@ivpcode
Copy link

ivpcode commented Mar 24, 2021

hi, same issue.

@artischockee
Copy link

artischockee commented Mar 26, 2021

Same issue. I used to retrieve data from author.name field (in $npm_package_author_name env variable) and it was being revealed in my app. But, perhaps starting from this "RFC21", this variable is not showing at all, giving the consumer an empty string.

@isaacs
Copy link
Contributor

isaacs commented Aug 11, 2021

You can put these values in a config block in package.json, like this:

{
  "config": {
    "nodeParams": "--experimental-specifier-resolution=node --harmony -r source-map-support/register",
    "author": {
      "name": "Wile E. Coyote"
    }
  },
  "scripts": {
    "dostuff": "node $npm_package_config_nodeParams myscript.js",
    "whoami": "echo $npm_package_config_author_name"
  }
}

Passing the entirety of package.json into the environment was contributing to problems, because sometimes these files contain a lot of stuff, including very long strings that blew up the environment size. (We were also passing every last config value, even those set at the default value, so that was also adding to the problem.)

@isaacs isaacs closed this as completed Aug 11, 2021
@wu-lee
Copy link

wu-lee commented Feb 2, 2022

Thanks - this mechanism also provided access to parameters from the .npmrc file(s). What is the recommended forward and backward compatible way of getting access to those again?

Also, this information is not easy to find. See npm/cli#2452 (comment)

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

No branches or pull requests

5 participants