发布 NPM 包的开发版本 [英] Publish development version of NPM package

查看:47
本文介绍了发布 NPM 包的开发版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何发布 NPM 包的开发版本?

How can I publish development version of NPM package?

我尝试为 package.json 中的 version 字段设置 "dev" 值,但在发布时出现错误:

I tried to set "dev" value for version field in package.json but I got an error when publishing it:

$ npm publish
npm ERR! Error: Invalid version: "dev"
npm ERR!     at Object.module.exports.fixVersionField (/usr/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/fixer.js:180:13)
npm ERR!     at /usr/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:29:38
npm ERR!     at Array.forEach (native)
npm ERR!     at normalize (/usr/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:28:15)
npm ERR!     at final (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:310:33)
npm ERR!     at then (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:33)
npm ERR!     at /usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:299:40
npm ERR!     at fs.js:266:14
npm ERR!     at /usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:103:5
npm ERR!     at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/isaacs/npm/issues>

npm ERR! System Linux 3.11.0-15-generic
npm ERR! command "node" "/usr/bin/npm" "publish"
npm ERR! cwd /home/ionicabizau/package-name
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.23
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/ionicabizau/package-name/npm-debug.log
npm ERR! not ok code 0

哪些是最接近的替代方案?

Which are the closest alternatives?

推荐答案

NPM 包版本必须满足 服务器

NPM package version must meet requirements of semver

正常版本号必须采用 X.Y.Z 形式,其中 X、Y 和 Z 是非负整数,并且不得包含前导零.X 是主要版本,Y 是次要版本,Z 是补丁版本.每个元素必须在数字上增加.例如:1.9.0 -> 1.10.0-> 1.11.0.

A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes. X is the major version, Y is the minor version, and Z is the patch version. Each element MUST increase numerically. For instance: 1.9.0 -> 1.10.0 -> 1.11.0.

因此不允许使用 dev 作为版本号.

So using dev as a version number is not allowed.

同样不建议发布任何处于开发状态的代码.如果您想在不同的模块中测试您的模块,您可以使用相对路径或使用 git 远程 URL 包含该模块.

Also it is not recommended to publish any code which is in development state. If you want to test your module within different module you can include that module using relative path or using git remote URL.

示例:

假设您正在开发的模块名为 foo 并且您想在模块 bar、脚本文件 bar/index.js 中测试它.让我们假设两个模块目录都在同一个父目录中.而不是将未完成模块foo发布到npm并将其安装在module bar,你可以这样做:

Let's say that the module which you are developing is called foo and you would like to test it in module bar, script file bar/index.js. Let's assume both module directories are in the same parent directory. Instead of publishing unfinished module foo to npm and install it in module bar, you can do as follows:

var foo = require('../foo')

正如 Ionicã Bizãu(下面的评论)所建议的,您也可以使用带有 git 远程 URL 的 npm install 例如

As suggested by Ionicã Bizãu (comments below), you can also use npm install with git remote URL e.g.

npm install <git remote url>

NPM 安装文档 提供了有关该安装方法的更多详细信息(选项 g).

NPM install documentation provides more details (option g) on that installation method.

或者,您可以使用本文中提出的方法:本地测试你的 npm 模块,无需将它们发布到 npmjs.org.

Alternatively you can use approach proposed in this post: Locally test your npm modules without publishing them to npmjs.org.

编辑

还有另一种需要 npm link 命令的替代解决方案:

  • 在您开发的模块中执行 npm link 命令.这将创建从 prefix/package-name 到当前文件夹的全局安装符号链接
  • 另一个步骤是在其他位置(其他模块/应用程序)执行 npm link package-name(其中 package-name 是您开发的包的名称)您用来测试开发的模块).这将创建从本地 node_modules 文件夹到全局符号链接(在第一步中创建)的符号链接.
  • Execute npm link command inside your developed module. That will create globally-installed symbolic link from prefix/package-name to the current folder
  • Another step is to execute npm link package-name (where package-name is a name of your developed package) in some other location (other module / application which you use to test the developed module). That will create a symlink from the local node_modules folder to the global symlink (which was created in the first step).

请注意,在某些操作系统中,您可能需要以特权用户身份运行第一个命令(通常是 sudo 帮助).

Note that you may need to run the first command as a privileged user (usually sudo helps) in some operating systems.

使用符号链接,您将能够向开发的模块添加更改,并立即在其他链接模块中查看其结果.

With symlinks in place you will be able to add changes to your developed module and see their results instantly in other linked modules.

我希望这会有所帮助.

这篇关于发布 NPM 包的开发版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆