Only publishes if the version number in package.json
differs from the latest on NPM
Customize the version-checking behavior, the registry URL, and path of your package
Keeps your NPM access token secret. Doesn't write it to ~/.npmrc
100% JavaScript (which is faster than Docker) and bundled to optimize loading time
Exposes the old and new version numbers, and the type of change (major, minor, patch, etc.) as variables that you can use in your workflow.
This package can be used three different ways:
To use the GitHub Action, you'll need to add it as a step in your Workflow file. By default, the only thing you need to do is set the token
parameter to your NPM auth token.
on: push
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
- run: npm install
- run: npm test
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
You can set any or all of the following input parameters:
Name | Type | Required? | Default | Description |
---|---|---|---|---|
token |
string | yes | The NPM auth token to use for publishing | |
registry |
string | no | https://registry.npmjs.org/ | The NPM registry URL to use |
package |
string | no | ./package.json | The path of your package.json file |
tag |
string | no | "latest" | The tag to publish to. This allows people to install the package using npm install <package-name>@<tag> . |
access |
string | no | "public" for non-scoped packages. "restricted" for scoped packages. | Determines whether the published package should be publicly visible, or restricted to members of your NPM organization. |
dry-run |
boolean | no | false | Run NPM publish with the --dry-run flag to prevent publication |
check-version |
boolean | no | true | Only publish to NPM if the version number in package.json differs from the latest on NPM |
npm-publish exposes some output variables, which you can use in later steps of your workflow. To access the output variables, you'll need to set an id
for the npm-publish step.
steps:
- id: publish
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
- if: steps.publish.outputs.type != 'none'
run: |
echo "Version changed: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}"
Variable | Type | Description |
---|---|---|
type |
string | The type of version change that occurred ("major", "minor", "patch", etc.). If there was no version change, then type will be "none". |
version |
string | The version that was published |
old-version |
string | The version number that was previously published to NPM |
tag |
string | The tag that the package was published to. |
access |
string | Indicates whether the published package is publicly visible or restricted to members of your NPM organization. |
dry-run |
boolean | Indicates whether NPM was run in "dry run" mode |
To use npm-package in your JavaScript code, you'll need to install it using NPM:
npm install @jsdevtools/npm-publish
You can then import it and use it in your code like this:
const npmPublish = require("@jsdevtools/npm-publish");
// Run npm-publish with all defaults
await npmPublish();
// Run npm-publish with options
await npmPublish({
package: "./path/to/package.json",
token: "YOUR_NPM_AUTH_TOKEN_HERE"
});
As shown in the example above, you can pass options to the npmPublish()
function. Here are the available options:
Name | Type | Default | Description |
---|---|---|---|
token |
string | NPM's default credentials | The NPM auth token to use for publishing. If not set, then NPM will |
registry |
string | https://registry.npmjs.org/ | The NPM registry URL to use |
package |
string | ./package.json | The path of your package.json file |
tag |
string | "latest" | The tag to publish to. This allows people to install the package using npm install <package-name>@<tag> . |
access |
string | "public" for non-scoped packages. "restricted" for scoped packages. | Determines whether the published package should be publicly visible, or restricted to members of your NPM organization. |
dryRun |
boolean | false | Run NPM publish with the --dry-run flag to prevent publication |
checkVersion |
boolean | true | Only publish to NPM if the version number in package.json differs from the latest on NPM |
quiet |
boolean | false | Suppress console output from NPM and npm-publish |
debug |
function | no-op | A function to log debug messages. You can set this to a custom function to receive debug messages, or just set it to console.debug to print debug messages to the console. |
The npmPublish()
function asynchronously returns an object with the following properties:
Name | Type | Description |
---|---|---|
type |
string | The type of version change that occurred ("major", "minor", "patch", etc.) If there was no version change, then the the type is "none". |
package |
string | The name of the NPM package that was published |
version |
string | The version number that was published |
oldVersion |
string | The version number that was previously published to NPM |
tag |
string | The tag that the package was published to. |
access |
string | Indicates whether the published package is publicly visible or restricted to members of your NPM organization. |
dryRun |
boolean | Indicates whether NPM was run in "dry run" mode |
To use npm-package from as a command-line tool in your terminal, you'll need to install it globally using NPM:
npm install -g @jsdevtools/npm-publish
You can then use it in your terminal or in Bash scripts. You can call it without any arguments, and it will publish the current directory using NPM's default credentials.
npm-publish
Or you can call it with arguments to explicitly set the NPM auth token, registry, package path, etc.
npm-publish --token=YOUR_NPM_AUTH_TOKEN_HERE ./path/to/package.json
Run npm-publish --help
to see the full list of options available.
> npm-publish --help
Usage: npm-publish [options] [package_path]
options:
--token <token> The NPM access token to use when publishing
--registry <url> The NPM registry URL to use
--tag <tag> The tag to publish to. Allows the package to be installed
using "npm install <package-name>@<tag>"
--access <access> "public" = The package will be publicly visible.
"restricted" = The package will only be visible to members
of your NPM organization.
--dry-run Don't actually publish to NPM, but report what would have
been published
--debug, -d Enable debug mode, with increased logging
--quiet, -q Suppress unnecessary output
--version, -v Print the version number
--help, -h Show help
package_path The absolute or relative path of the NPM package to publish.
Can be a directory path, or the path of a package.json file.
Defaults to the current directory.
Contributions, enhancements, and bug-fixes are welcome! Open an issue on GitHub and submit a pull request.
To build the project locally on your computer:
Clone this repogit clone https://github.com/JS-DevTools/npm-publish.git
Install dependenciesnpm install
Build the codenpm run build
Run the testsnpm test
npm-publish is 100% free and open-source, under the MIT license. Use it however you want.
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
Thanks to these awesome companies for their support of Open Source developers
本文主要介绍流程,代码如何书写不会过多描述,首先使用angular-cli初始化项目,如何操作直接略过,最简单不过 一. 首先安装ng-packagr:npm install ng-packagr –save-dev 二. 在项目根目录下创建ng-package.json文件和public-api.ts文件,修改package.json ng-package.json { "$schema":
Publish a package npm publish [|] [–tag ] [–access <public|restricted>] [–otp otpcode] [–dry-run] Publishes ‘.’ if no argument supplied Sets tag ‘latest’ if no --tag specified Publishes a package to t
按照网上百度到的其他去安装nodejs报错 ../lib/node_modules/npm/bin/npm-cli.js: No such file or directory 然后继续百度 说是软连接问题,修改后继续报错 Usage: npm <command> where <command> is one of: access, adduser, audit, bin, bugs,
npm 包发布其实很简单 npm publish 不过有时候推了github,忘记发布npm, 或者发布了npm,却忘记推github,导致了代码数据不同步 为了和github代码实现同步,使用Github Actions 确保npm包在本地能正常发布 步骤 1、点击 Actions 2、选择模板 :Node.js Package 3、修改成最简单的形式 name: Node.js Packag
1. registry 在下载包的时候,很多人喜欢设置taobao镜像,因为npm仓库服务器在国外,下载速度真是急死个人。发布的时候也一样,一般开源应用基本都发布到npmjs,公司内部包的话就会发到私有Npm仓库,我们可以在package.json设置一下你想要的发布的地址: "publishConfig": { "registry": "http://registry.npm.xxx.c
前置(可忽略) 如果发布的包只打算放在公司的私有镜像库中,需要先设置一下registry // 1、直接设置 npm config set registry <registry> // 2、有使用nrm的可以用nrm切换 nrm use <registry> // 3、项目根目录放一个.npmrc文件,内容包含下面内容 registry=<registry> 1、注册、登录(已有账号可跳过注册直
环境条件: 保证npm 的下载地址是 http://registry.npmjs.org ,如果使用的是淘宝镜像 修改为原本链接 npm config set registry http://registry.npmjs.org 提交个人模块步骤: 1,编写个人模块 2,初始化包描述 $npm init 3,注册包仓账号(如果注册过验证就可以,相同命令) $npm adduser 4,上传包 $n
npm ERR! code E403 npm ERR! 403 403 Forbidden - PUT http://registry.npmjs.org/dyhao - Forbidden npm ERR! 403 In most cases, you or one of your dependencies are requesting npm ERR! 403 a package versio
publish npm包需要以下步骤,做一下记录,以防以后使用再掉坑里 步骤: 1、检查镜像: 执行命令:npm config get registry 控制台打印的输出必须是 https://registry.npmjs.org/ 如果输出是 https://registry.npm.taobao.org/,执行第2步 2、修改为默认的npm镜像 执行命令:npm config set regi
npm config set registry https://registry.npmjs.org npm 地址 https://github.com/waillyer/tcplayer-ui.git 创建项目 修改打包配置 tsconfig.build.json { "compilerOptions": { "outDir": "dist", // 生成目录
今天在学习npm自定义包时发现第一次第一次上传正常,但是第二次上传包时出现了ERR400错误。 总结一下当时的操作 构建完自己的包 npm login登录 npm publish上传 打开npmjs官网 查看自己上传的文件 在packages栏里删除掉刚上传的包 回到编译器修改了一些数据 再次npm publish上传 出现ERR CODE 400报错 然后一直没找到问题所在,网上有人说是源的问题
上传项目到npm-->为社会做贡献 首先你得有一个项目 npm init 生成package.json 来设置相信息 注册登录npm:npm adduser 输入你的一些信息 查看当前npm登录人 npm whoami npm publish 出现问题: 192:react-native-native xieyusheng$ npm publish npm ERR! code ENEEDAUTH
Get help on npm npm help [<terms…>] If supplied a topic, then show the appropriate documentation page. If the topic does not exist, or if multiple terms are provided, then run the help-search command
npm 包发布方式(线上、线下) 线下发布 第一步,安装,开启第一个终端: npm install -g sinopia 安装 sinopia -l 127.0.0.1:4873 打开本地地址 出现问题 callback must be a funciton received undefined 解决: local-fs.js文件第42行修改 fs.unlink(tmp,function(){}
问题内容: 我更新到最新的节点v9.1.0,现在npm不起作用。 npm WARN npm npm不支持Node.js v9.1.0 问题答案: 事实证明,当前安装的版本与新版本不兼容,并且很难进行更新。 解决方案是先卸载然后重新安装,其中将包含的正确版本。 这是如何做: 卸载。 从https://nodejs.org安装
1 npm的历史、现状和发展 历史 2009年,npm(Node 包管理器)初次发布早期预览版; 2011年,npm 1.0:发布; 2015年,npm 支持私有模块 现状 npm公司发布了其软件包管理工具npm 5.0版,npm 5提升了性能,使其保持了对同类软件的竞争力。 npm的出现使我们分享代码或者复用代码变得更加简单。 发展 npm作为随同node.JS一起安装的包管理工具,在node包
npm 是 Node.js 的包管理工具,用来安装各种 Node.js 的扩展。 npm 是 JavaScript 的包管理工具,也是世界上最大的软件注册表。有超过 60 万个 JavaScript 代码包可供下载,每周下载约 30 亿次。npm 让 JavaScript 开发人员可以轻松地使用其他开发人员共享的代码。 npm 由三个不同的部分组成: 网站 注册表 命令行界面(CLI) 示例:查找
npm模块升级工具npm-check,提供命令行下的图形界面,可以手动选择升级哪些模块。 检查是否有需要更新、错误的和未使用的依赖: 功能特性: 依赖更新及时提醒 提供软件包更新接链,可以及时更新升级 友好的提示你所缺少的依赖包,减少不必要的盲目查找 支持安装在全局工作环境,via -g 平滑更新升级,via -u 支持公有域和私有域@scoped/packages 支持ES6-style 可交替
npm-upgrade Interactive CLI utility to easily update outdated NPM dependencies with changelogs inspection support. What is this for? If you are tired of manually upgrading package.json every time your
Overview Codebox npm is a serverless npm registry to allow companies that wish to keep their intellectual property. It allows sharing of npm modules within a company but additionally allows access to
npm and related build and dev tools Please feel free to create an issue or open a pull request if you need support or would like to contribute. Portable node, package managers and build tools Tagged I
npm-run Run executables in node_modules from the command-line Use npm-run to ensure you're using the same version of a package on the command-line and in package.json scripts. Any executable available