-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: completely new npm script publish hook API
- Loading branch information
1 parent
fe718c4
commit 2fff524
Showing
17 changed files
with
8,322 additions
and
2,114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: [ master, next, next-major, beta, alpha ] | ||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.x | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Lint | ||
run: npm run lint | ||
- name: Test | ||
run: npm run test --if-present | ||
- name: Build | ||
run: npm run build --if-present | ||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Test | ||
on: | ||
push: | ||
branches: [ develop ] | ||
pull_request: | ||
branches: [ develop, master, next, next-major, beta, alpha ] | ||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
strategy: | ||
matrix: | ||
node-version: [ 10.x, 14.x ] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Lint | ||
run: npm run lint | ||
- name: Test | ||
run: npm run test --if-present |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,16 @@ | ||
# macOS | ||
.DS_Store | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
# Node dependency directory | ||
node_modules | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# next.js build output | ||
.next | ||
.env.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v12.18.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,84 @@ | ||
# <img src="https://upload.wikimedia.org/wikipedia/commons/d/db/Npm-logo.svg" height="20"> multi-publish <a href="https://npm.im/npm-multi-publish"><img src="https://badgen.net/npm/v/npm-multi-publish"></a> | ||
# npm-multi-publish [![Latest version](https://badgen.net/npm/v/npm-multi-publish)](https://npm.im/npm-multi-publish) [![Monthly downloads](https://badgen.net/npm/dm/npm-multi-publish)](https://npm.im/npm-multi-publish) [![Install size](https://packagephobia.now.sh/badge?p=npm-multi-publish)](https://packagephobia.now.sh/result?p=npm-multi-publish) | ||
|
||
> Publish a package to multiple npm registries | ||
Publish an npm package to multiple registries | ||
|
||
## :raised_hand: Why? | ||
To make a private repo available in multiple private npm registries | ||
## 🙋♂️ Why? | ||
- **🔥 High Compatibility** Works with anything that uses `npm publish` or `yarn publish`! | ||
- **⚡️ Easy setup** Just add it to your npm publish hooks! | ||
- **🙌 Streamlined** Publishes to all registries in one `npm publish`! | ||
|
||
## :rocket: Installation | ||
|
||
#### Global installation | ||
## 🚀 Install | ||
```sh | ||
$ npm i -g npm-multi-publish | ||
npm i -D npm-multi-publish | ||
``` | ||
#### Local installation (dev dependency) | ||
```sh | ||
$ npm i -D npm-multi-publish | ||
|
||
## 🚦 Quick Setup | ||
Add `npm-multi-publish` to your `package.json` `prepublishOnly` and `postpublish` hooks, and convert `publishConfig` into an array of configs: | ||
|
||
```diff | ||
{ | ||
..., | ||
|
||
"scripts": { | ||
+ "prepublishOnly": "npm-multi-publish", | ||
+ "postpublish": "npm-multi-publish" | ||
}, | ||
|
||
"publishConfig": [ | ||
+ { | ||
+ "registry": "Registry URL 1" | ||
+ }, | ||
+ { | ||
+ "registry": "Registry URL 2" | ||
+ }, | ||
+ ... | ||
], | ||
|
||
... | ||
} | ||
``` | ||
|
||
Add it to your `package.json` scripts to run it as `$ npm run multi-publish` (be careful not to call it `publish` as it's a [hook](https://docs.npmjs.com/misc/scripts#description)) | ||
```json | ||
{ | ||
... | ||
"scripts": { | ||
"multi-publish": "multi-publish" | ||
}, | ||
... | ||
} | ||
If using [Lerna](https://lerna.js.org/), add this configuration to the respective `package.json` of each package in the monorepo (not necessary in the root `package.json`). | ||
|
||
## 💁♀️ FAQ | ||
|
||
### Is it possible to authenticate to multiple npm registries with one `.npmrc`? | ||
|
||
[Yes](https://docs.npmjs.com/logging-in-to-an-npm-enterprise-registry-from-the-command-line#logging-in-with-a-scope-configured-to-point-to-an-npm-enterprise-registry). | ||
|
||
To login to an enterprise/custom registry: | ||
|
||
```sh | ||
$ npm login --registry=https://registry.company-name.npme.io | ||
``` | ||
|
||
## :beginner: Setup | ||
1. In your `package.json`, use [`publishConfig`](https://docs.npmjs.com/files/package.json#publishconfig) as an array to define the respective registries | ||
```json | ||
{ | ||
... | ||
"publishConfig": [ | ||
{ | ||
"registry": "..." | ||
}, | ||
{ | ||
"registry": "..." | ||
} | ||
], | ||
... | ||
} | ||
To verify authentication on a specific registry: | ||
|
||
```sh | ||
$ npm whoami --registry=https://registry.company-name.npme.io | ||
``` | ||
|
||
2. `$ multi-publish` if intalled globally, or `$ npm run multi-publish` if installed locally | ||
If you have certs for the respective registries, you can [add multiple certs to your `.npmrc` file](https://docs.npmjs.com/misc/config#ca). | ||
|
||
|
||
### How can I manage `.npmrc`s configured for multiple registries? | ||
|
||
Use [`npmrc`](https://www.npmjs.com/package/npmrc). When `npm-multi-publish` can't authenticate with a registry, it will wait for you to authenticate (eg. by toggling your npmrc or by logging in). | ||
|
||
|
||
## :book: FAQ | ||
- _Is it possible to authenticate to multiple npm registries with one `.npmrc`?_ | ||
### How can I test publishing to a registry? | ||
Use [`@pnpm/registry-mock`](https://github.com/pnpm/registry-mock/) to create a mock registry. | ||
|
||
Yes. Login to a specific registry via `$ npm login --registry=https://registry.company-name.npme.io`. Learn more [here](https://docs.npmjs.com/logging-in-to-an-npm-enterprise-registry-from-the-command-line#logging-in-with-a-scope-configured-to-point-to-an-npm-enterprise-registry). You can check if you're already authenticated to a registry via `$ npm whoami --registry=https://registry.company-name.npme.io`. If you have certs for the respective registries, you can [add multiple certs in your `npmrc` file](https://docs.npmjs.com/misc/config#ca). | ||
Set up a server directory: | ||
|
||
- _If I have multiple `.npmrc`s configured for the respective registries, how should I toggle between?_ | ||
```sh | ||
$ PNPM_REGISTRY_MOCK_PORT=4873 registry-mock prepare | ||
``` | ||
|
||
Start the server: | ||
|
||
```sh | ||
$ PNPM_REGISTRY_MOCK_PORT=4873 registry-mock | ||
``` | ||
|
||
Check out [`npmrc`](https://www.npmjs.com/package/npmrc). When multi-publish can't authenticate with a registry, it will wait for you to authenticate (eg. by toggling your npmrc or by logging in). | ||
Use a different port to instantiate multiple test registries. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const {existsSync} = require('fs'); | ||
const prepublishOnly = require('../lib/prepublish-only'); | ||
const postpublish = require('../lib/postpublish'); | ||
const { | ||
MULTI_PUBLISH_FILE, | ||
readJson, | ||
restorePkg, | ||
Exit, | ||
} = require('../lib/utils'); | ||
|
||
const {npm_lifecycle_event: lifeCycleEvent} = process.env; | ||
|
||
let state; | ||
|
||
(async () => { | ||
state = existsSync(MULTI_PUBLISH_FILE) && (await readJson(MULTI_PUBLISH_FILE)); | ||
|
||
if (lifeCycleEvent === 'prepublishOnly') { | ||
await prepublishOnly(state); | ||
} | ||
|
||
if (lifeCycleEvent === 'postpublish') { | ||
await postpublish(state); | ||
} | ||
})().catch(async error => { | ||
if (state) { | ||
await restorePkg(state); | ||
} | ||
|
||
if (!(error instanceof Exit)) { | ||
console.error(error); | ||
} | ||
|
||
process.exit(1); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.