@orderly.network/npm-release 0.0.3 → 0.0.4-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -1
- package/index.mjs +38 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
CLI for releasing npm packages using [release-it](https://github.com/release-it/release-it), with support for environment-based registry/token config, Git auth, pre-release tags, and Slack notifications.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **release-it driven** — Bump version, commit, tag, and publish via release-it.
|
|
8
|
+
- **Environment-based config** — Registry URL and npm token via `NPM_REGISTRY` / `NPM_TOKEN`; no local `.release-it.json` required.
|
|
9
|
+
- **Git authentication** — GitLab (and similar) push via `GIT_TOKEN` + `GIT_USERNAME`; commit identity via `GIT_NAME` / `GIT_EMAIL`.
|
|
10
|
+
- **Pre-release tags** — Optional `PRERELEASE_TAG` (e.g. `alpha`, `beta`) for prerelease versions and `npm dist-tag`.
|
|
11
|
+
- **Slack notifications** — Optional webhook for success/failure after publish.
|
|
12
|
+
- **Internal registry friendly** — When using a custom registry (non-npmjs.org), git tag creation is skipped so internal flows stay simple.
|
|
13
|
+
|
|
14
|
+
## Installation and usage
|
|
6
15
|
|
|
7
16
|
From your project root:
|
|
8
17
|
|
|
@@ -37,3 +46,38 @@ pnpm add -D @orderly.network/npm-release
|
|
|
37
46
|
| `RELEASE_VERSION_TYPE` | Bump type: `patch`, `minor`, or `major` |
|
|
38
47
|
| `PRERELEASE_TAG` | Pre-release identifier (e.g. `alpha`, `beta`); enables `--preRelease` and `--npm.tag` |
|
|
39
48
|
| `SLACK_WEBHOOK_URL` | Webhook URL for success/failure Slack notifications |
|
|
49
|
+
|
|
50
|
+
All variables are optional. Unset values use defaults or disable the corresponding feature (e.g. no Slack notification if `SLACK_WEBHOOK_URL` is not set).
|
|
51
|
+
|
|
52
|
+
## Behavior
|
|
53
|
+
|
|
54
|
+
### Internal registry
|
|
55
|
+
|
|
56
|
+
When `NPM_REGISTRY` is set and is **not** `https://registry.npmjs.org`, the CLI treats it as an internal registry and **does not create a git tag**. Commits and push still occur; only tagging is skipped.
|
|
57
|
+
|
|
58
|
+
### Pre-release
|
|
59
|
+
|
|
60
|
+
- If `PRERELEASE_TAG` is set and the current `package.json` version is already a prerelease with the same preId (e.g. `1.0.0-alpha.0` with tag `alpha`), the version is incremented as **prerelease** (e.g. `1.0.0-alpha.1`).
|
|
61
|
+
- Otherwise, the bump follows `RELEASE_VERSION_TYPE` (`patch`, `minor`, or `major`). When `PRERELEASE_TAG` is set, the new version is a prerelease and published under that npm dist-tag.
|
|
62
|
+
|
|
63
|
+
### Working directory
|
|
64
|
+
|
|
65
|
+
The CLI does **not** require a clean working directory. It is intended to run in CI after `pnpm install` or build steps that may change the lockfile or generated files.
|
|
66
|
+
|
|
67
|
+
## CI integration
|
|
68
|
+
|
|
69
|
+
In GitLab CI (or similar), set the needed environment variables (`GIT_NAME`, `GIT_EMAIL`, `GIT_USERNAME`, `GIT_TOKEN`, `NPM_REGISTRY`, `NPM_TOKEN`, `RELEASE_VERSION_TYPE`, `PRERELEASE_TAG`, `SLACK_WEBHOOK_URL`) and run:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pnpm release
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
or:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npx @orderly.network/npm-release
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|
package/index.mjs
CHANGED
|
@@ -11,12 +11,14 @@ const npm = {
|
|
|
11
11
|
token: process.env.NPM_TOKEN,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
// Internal registry = custom registry (not public npm)
|
|
14
|
+
// Internal registry = custom registry (not public npm)
|
|
15
15
|
const isInternalRegistry = Boolean(
|
|
16
16
|
npm.registry &&
|
|
17
17
|
npm.registry.replace(/\/$/, "") !== "https://registry.npmjs.org"
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
+
const isPublicRegistry = !isInternalRegistry;
|
|
21
|
+
|
|
20
22
|
const git = {
|
|
21
23
|
name: process.env.GIT_NAME,
|
|
22
24
|
email: process.env.GIT_EMAIL,
|
|
@@ -24,6 +26,9 @@ const git = {
|
|
|
24
26
|
token: process.env.GIT_TOKEN,
|
|
25
27
|
};
|
|
26
28
|
|
|
29
|
+
// Current branch in CI environment
|
|
30
|
+
const ciBranch = process.env.CI_COMMIT_BRANCH;
|
|
31
|
+
|
|
27
32
|
const preReleaseTag = process.env.PRERELEASE_TAG;
|
|
28
33
|
|
|
29
34
|
// Custom release version type (patch, minor, major)
|
|
@@ -34,7 +39,7 @@ const RELEASE_IT_CONFIG = {
|
|
|
34
39
|
ci: true,
|
|
35
40
|
git: {
|
|
36
41
|
commit: true,
|
|
37
|
-
tag:
|
|
42
|
+
tag: isPublicRegistry,
|
|
38
43
|
push: true,
|
|
39
44
|
// Allow release when working dir is not clean so it works as a third-party package in CI
|
|
40
45
|
// (e.g. after npm install or build steps that touch lockfile or generated files).
|
|
@@ -131,10 +136,6 @@ async function sendSlackNotify({ success, error }) {
|
|
|
131
136
|
}
|
|
132
137
|
}
|
|
133
138
|
|
|
134
|
-
function sanitizePreId(id) {
|
|
135
|
-
return String(id).replaceAll("/", "-");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
139
|
/**
|
|
139
140
|
* Extract the repository path (owner/name) from the git remote origin URL.
|
|
140
141
|
* Supports HTTPS and SSH URLs for GitHub and GitLab.
|
|
@@ -201,6 +202,30 @@ async function authNPM() {
|
|
|
201
202
|
await $`echo ${content} >> .npmrc`;
|
|
202
203
|
}
|
|
203
204
|
|
|
205
|
+
async function getCurrentBranch() {
|
|
206
|
+
let branch = ciBranch;
|
|
207
|
+
if (!branch) {
|
|
208
|
+
try {
|
|
209
|
+
branch =
|
|
210
|
+
(await $`git rev-parse --abbrev-ref HEAD`.quiet()).stdout?.trim() || "";
|
|
211
|
+
} catch {
|
|
212
|
+
branch = "";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return branch;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* get pre release tag from branch name for internal/* branches (e.g. internal/dev => dev)
|
|
220
|
+
*/
|
|
221
|
+
async function getPreReleaseTag() {
|
|
222
|
+
const branch = await getCurrentBranch();
|
|
223
|
+
if (branch.startsWith("internal/")) {
|
|
224
|
+
return branch.replace(/^internal\//, "");
|
|
225
|
+
}
|
|
226
|
+
return defaultTag;
|
|
227
|
+
}
|
|
228
|
+
|
|
204
229
|
/**
|
|
205
230
|
* When current version is already a pre-release (e.g. 1.0.0-alpha.0) and PRERELEASE_TAG
|
|
206
231
|
* matches the same preId (e.g. "alpha"), use increment "prerelease" so release-it bumps
|
|
@@ -208,14 +233,15 @@ async function authNPM() {
|
|
|
208
233
|
* Returns options for release-it programmatic API (merged with RELEASE_IT_CONFIG).
|
|
209
234
|
*/
|
|
210
235
|
async function getReleaseItOptions() {
|
|
236
|
+
const preTag = preReleaseTag || (await getPreReleaseTag());
|
|
237
|
+
|
|
211
238
|
let increment = releaseVersionType;
|
|
212
239
|
|
|
213
|
-
if (
|
|
240
|
+
if (preTag) {
|
|
214
241
|
const currentVersion = readPackageVersion();
|
|
215
242
|
const { isPrerelease, preId } = parseVersion(currentVersion);
|
|
216
|
-
const normalizedPreTag = sanitizePreId(preReleaseTag);
|
|
217
243
|
// Continue pre-release: alpha.0 -> alpha.1 (same preId)
|
|
218
|
-
if (isPrerelease && preId ===
|
|
244
|
+
if (isPrerelease && preId === preTag) {
|
|
219
245
|
increment = "prerelease";
|
|
220
246
|
}
|
|
221
247
|
}
|
|
@@ -225,9 +251,9 @@ async function getReleaseItOptions() {
|
|
|
225
251
|
increment,
|
|
226
252
|
};
|
|
227
253
|
|
|
228
|
-
if (
|
|
229
|
-
options.preRelease =
|
|
230
|
-
options.npm.tag =
|
|
254
|
+
if (preTag) {
|
|
255
|
+
options.preRelease = preTag;
|
|
256
|
+
options.npm.tag = preTag;
|
|
231
257
|
}
|
|
232
258
|
|
|
233
259
|
return options;
|