[Feature] Add support for package.json script variables
See original GitHub issue- I’d be willing to implement a fix
Describe the bug
When using “yarn pack” in Yarn v1, package.json variables (such as npm_package_version) are honoured. This seems to not be th case in yarn v2.
To Reproduce
I have a package.json which defines a “pack” script like so:
"scripts": {
"pack": "yarn pack --filename my-file-v$npm_package_version.tar.gz",
}
The error when I run “yarn run pack” is Internal Error: Unbound variable "npm_package_version"
The minimal information needed to reproduce your issue (ideally a package.json with a single dep). Note that bugs without minimal reproductions might be closed.
Environment if relevant (please complete the following information):
- OS: Linux
- Node version 10.22.0
- Yarn version 2.1.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:31 (19 by maintainers)
Top Results From Across the Web
Three Things You Didn't Know You Could Do with npm Scripts
npm scripts are a great way to automate common tasks during your Node.js development flow. In this blog post we'll cover the basics...
Read more >scripts - npm Docs
The "scripts" property of your package.json file supports a number of built-in scripts and their preset life cycle events as well as arbitrary...
Read more >How can I use variables in package.json? - Stack Overflow
Any property from package.json can be referenced from scripts, prefix it with $npm_package and adding an _<prop> (underscore + property) for ...
Read more >Scripting inside package.json
Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run...
Read more >Running cross-platform tasks via npm package scripts - 2ality
npm run Scripts available via `npm run-script`: help scripts-help -w 40 ... npm run temporarily adds entries to the shell PATH variable ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Other use case is when it’s used on
.env
files for example:With yarn2 this is not possible and it is quite surprising that it doesn’t work by design
👋 I’m a bit late to the party but I also needed the yarn classic var envs, so I created a plugin for that: https://github.com/Ayc0/yarn-plugin-envs
@jheaff1 it should fit your needs