bcoe / bcoe/optional-dev-dependency

Native optional devDependencies trick with npm workspaces

オープン
#22 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
5
フォーク
8
PR マージ指標
30日以内にマージされた PR はありません

説明

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:

```jsonc
// optionalDevDependencies/package.json
{
"optionalDependencies": {
"my-optional-dev-dependency": "^1.2.3"
}
}
```

and then the root package.json like:

```jsonc
{
"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

```jsonc
// 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. ❤️

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

root package.json と optionalDevDependencies/package.json の例から始め、maintainer がその方法を文書化することを決めた場合は、説明されている npm install と npm publish の動作を確認してください。完了とするには、ドキュメントまたはコードについての明示的な依頼が必要です。この報告には現在、そのどちらもありません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
tooling
issue の種類
ドキュメント
難易度
1/5
見積もり時間
1時間未満
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
15/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。