本地路径依赖没有安装自己的依赖

Local path dependencies not installing their own dependencies

this answer 之后,我像这样安装了本地依赖项:

{
  "private": true,
  "dependencies": {
    "my_dependency": "../relative/path/to/my_dependency"
  }
}

my_dependency 依赖于 ESLint 及其插件:

{
  "name": "my_dependency",
  "dependencies": {
    "@typescript-eslint/eslint-plugin": "5.25.0",
    "@typescript-eslint/parser": "5.25.0",
    "eslint": "8.16.0",
    "eslint-plugin-import": "2.26.0",
    "eslint-plugin-node": "11.1.0"
  },

如果我安装 my_dependency 作为路径,eslint 并且它的插件未安装在 ./node_modules 中,因此 eslint CLI 不可用。

但是,如果我在 npm 上发布 my_dependency 并将其安装为包名称和版本,

{
  "private": true,
  "dependencies": {
    "my_dependency": "0.0.0"
  }
}

eslint 所有插件将添加到 ./node_modules.

如何让本地依赖达到同样的效果? 每次我在 my_dependency.

中进行更改时,我不想用仅用于实验的版本污染 npm 注册表

问题

不幸的是,那些本地路径包没有安装它们的依赖项。

note: Packages linked by local path will not have their own dependencies installed when npm install is ran in this case. You must run npm install from inside the local path itself.

来源:docs.npmjs.com/...

解决方法

有很多解决方法,但我认为最好的方法是使用 GitHub 存储库和可选的分支。

所以只需将您的代码推送到 github 存储库,比方说 my-npm-playground,假设您使用的 Github 用户名是 ada_lovelace,您可以 link 像这样的回购,

{
  "private": true,
  "dependencies": {
    "my_dependency": "ada_lovelace/my-npm-playground"
  }
}