【问题标题】:Does publishing to NPM add dependencies?发布到 NPM 会添加依赖项吗?
【发布时间】:2019-07-28 00:24:57
【问题描述】:

react-canvas-draw 包在 GitHub 上的 package.json 中有以下内容:

  "dependencies": {
    "catenary-curve": "^1.0.1",
    "lazy-brush": "^1.0.1",
    "prop-types": "^15.6.2",
    "resize-observer-polyfill": "^1.5.0"
  },
  "peerDependencies": {
    "react": "16.x"
  },
  "devDependencies": {
    "all-contributors-cli": "^5.4.1",
    "babel-eslint": "^7.2.3",
    "css-loader": "^0.28.9",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "eslint": "^4.1.1",
    "eslint-config-react-app": "^2.1.0",
    "eslint-plugin-flowtype": "^2.34.1",
    "eslint-plugin-import": "^2.6.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-react": "^7.1.0",
    "gh-pages": "^1.1.0",
    "nwb": "0.21.x",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "style-loader": "^0.19.1"
  },

但是,当我view the package on NPM 时,我看到了:

            "dependencies": {
                "catenary-curve": "^1.0.1",
                "codecov": "^3.5.0",   // <-- note
                "coveralls": "^3.0.4", // <-- note
                "lazy-brush": "^1.0.1",
                "prop-types": "^15.6.2",
                "resize-observer-polyfill": "^1.5.0"
            },
            "peerDependencies": {
                "react": "16.x"
            },
            "devDependencies": {
                "all-contributors-cli": "^5.4.1",
                "babel-eslint": "^7.2.3",
                "css-loader": "^0.28.9",
                "enzyme": "^3.3.0",
                "enzyme-adapter-react-16": "^1.1.1",
                "eslint": "^4.1.1",
                "eslint-config-react-app": "^2.1.0",
                "eslint-plugin-flowtype": "^2.34.1",
                "eslint-plugin-import": "^2.6.0",
                "eslint-plugin-jsx-a11y": "^5.1.1",
                "eslint-plugin-react": "^7.1.0",
                "gh-pages": "^1.1.0",
                "nwb": "^0.21.5",
                "react": "^16.2.0",
                "react-dom": "^16.2.0",
                "style-loader": "^0.19.1"
            },

我在上面提到了我看到的另外两个包:codecov 和工作服。它们也显示在user-friendly site

为什么这些在 NPM 包条目中,但不在 GitHub 源中?


我唯一的想法:codecovcoveralls 这两个词只存在于 .travis.yml 文件中:

before_install:
- npm install codecov coveralls
- npm install nwb

...那么,npm publish 正在检测npm install 命令并向package.json 添加依赖项?我找不到任何支持这一点的东西,但我没有更好的想法。

【问题讨论】:

    标签: npm package.json


    【解决方案1】:

    您的假设是正确的,从NPM v5 开始执行npm install 会将它们作为依赖项添加到package.json。随后 travis 运行的 npm publish 将在包中包含这个“更新的”依赖项列表。


    有趣的是,它们与这些软件包一起提供,因为它们主要是“开发依赖项”,因此不需要包含在分布式包中。您可能想要打开一个问题或拉取请求,在package.json 中将这些声明为开发依赖项,或者在.travis.yml 中包含--save-dev

    (尽管后者也不会那么好,因为它会将那些未反映在 github 源中的已发布模块的开发部门“添加”为开发部门)。

    【讨论】:

      猜你喜欢
      • 2015-09-21
      • 2019-05-31
      • 2016-11-08
      • 2020-07-21
      • 2018-06-02
      • 2016-09-15
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多