Native optional devDependencies trick with npm workspaces
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 15/100
- Issue type
- Documentation
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, node.js
- Domain
- tooling
Research direction
Start with the root package.json and optionalDevDependencies/package.json examples, then review the described npm install and npm publish behavior if maintainers decide to document the trick. Done would require an explicit documentation or code request; this report currently provides neither.
Written by the indexing model from the issue text.
Description
Since npm install automatically uses your package.json's workspaces: [ ... ] value to install all workspaces at once, you can take advantage of this with a subfolder that has a package.json like:
// optionalDevDependencies/package.json
{
"optionalDependencies": {
"my-optional-dev-dependency": "^1.2.3"
}
}
and then the root package.json like:
{
"name": "my-awesome-package-with-optional-dev-dependencies",
"version": "4.5.6",
"optionalDependencies": {
"my-optional-production-dependency": "^10.11.12"
},
"devDependencies": {
"my-required-dev-dependency": "^7.8.9"
}
"workspaces": ["optionalDevDependencies"]
}
That way when you run npm install it will install the stuff from ./optionalDevDependencies/package.json's optionalDependencies, BUT when you npm publish it the workspace gets completely ignored and the only things left in the manifest are the required devDependencies and the production optionalDependencies.
I think this is a pretty cool trick! I used it to add all the esbuild targets as optional devDependency items for some testing of raw esbuild binary stuff. I needed some optional devDependency items so that npm would choose the right package for the os/cpu combo
// optionalDevDependencies/package.json
{
"optionalDependencies": {
"@esbuild/aix-ppc64": "0.19.11",
"@esbuild/android-arm": "0.19.11",
"@esbuild/android-arm64": "0.19.11",
"@esbuild/android-x64": "0.19.11",
"@esbuild/darwin-arm64": "0.19.11",
"@esbuild/darwin-x64": "0.19.11",
"@esbuild/freebsd-arm64": "0.19.11",
"@esbuild/freebsd-x64": "0.19.11",
"@esbuild/linux-arm": "0.19.11",
"@esbuild/linux-arm64": "0.19.11",
"@esbuild/linux-ia32": "0.19.11",
"@esbuild/linux-loong64": "0.19.11",
"@esbuild/linux-mips64el": "0.19.11",
"@esbuild/linux-ppc64": "0.19.11",
"@esbuild/linux-riscv64": "0.19.11",
"@esbuild/linux-s390x": "0.19.11",
"@esbuild/linux-x64": "0.19.11",
"@esbuild/netbsd-x64": "0.19.11",
"@esbuild/openbsd-x64": "0.19.11",
"@esbuild/sunos-x64": "0.19.11",
"@esbuild/win32-arm64": "0.19.11",
"@esbuild/win32-ia32": "0.19.11",
"@esbuild/win32-x64": "0.19.11"
}
}
This isn't really an issue. This is me trying to share this trick that I found that I thought was cool with anyone else who comes across the https://www.npmjs.com/package/optional-dev-dependency package (which is deprecated) or this github repository looking for a way to do optional dev dependencies. 😊
Feel free to close this if this is the wrong place for such stuff. ❤️
- Dominant language
- JavaScript
- Stars
- 5
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bcoe/optional-dev-dependency
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
bcoe/optional-dev-dependency#23 · 4 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
bcoe/optional-dev-dependency#21 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 30/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
bcoe/optional-dev-dependency#19 · 2 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
All issues in bcoe/optional-dev-dependency
Similar issues
-
curation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
amponce/archive-movie-browser#186 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
clerk/javascript#9852 ·
-
bug p1 tools
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
factory-active factory-automatic task-bug-reproduction-cannot-reproduce task-identify-harness-labels-done task-identify-issue-type-done
Difficulty 2/5 1-3 hours Newbie friendliness 84/100