@orderly.network/npm-release 0.0.4-alpha.1 → 0.0.6-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/index.mjs +79 -38
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -7,17 +7,16 @@ import releaseIt from "release-it";
|
|
|
7
7
|
$.verbose = true;
|
|
8
8
|
|
|
9
9
|
const npm = {
|
|
10
|
-
registry: process.env.NPM_REGISTRY,
|
|
10
|
+
registry: process.env.NPM_REGISTRY || "https://registry.npmjs.org",
|
|
11
11
|
token: process.env.NPM_TOKEN,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
14
|
+
const internalNpm = {
|
|
15
|
+
registry: process.env.NPM_REGISTRY_INTERNAL,
|
|
16
|
+
token: process.env.NPM_TOKEN_INTERNAL,
|
|
17
|
+
};
|
|
19
18
|
|
|
20
|
-
const isPublicRegistry =
|
|
19
|
+
const isPublicRegistry = npm.registry === "https://registry.npmjs.org";
|
|
21
20
|
|
|
22
21
|
const git = {
|
|
23
22
|
name: process.env.GIT_NAME,
|
|
@@ -51,6 +50,7 @@ const RELEASE_IT_CONFIG = {
|
|
|
51
50
|
// package or with private registries that don't support whoami/access (actual publish
|
|
52
51
|
// still fails if the user lacks permission).
|
|
53
52
|
skipChecks: true,
|
|
53
|
+
// registry: npm.registry,
|
|
54
54
|
},
|
|
55
55
|
github: {
|
|
56
56
|
release: false,
|
|
@@ -92,31 +92,25 @@ function readPackageVersion() {
|
|
|
92
92
|
* Private: <registry>/-/web/detail/<name> (Verdaccio-style)
|
|
93
93
|
*/
|
|
94
94
|
function getPackagePageUrl(pkgName) {
|
|
95
|
-
|
|
96
|
-
const registry = raw.replace(/\/$/, "");
|
|
97
|
-
const isPublic = !npm.registry || registry === "https://registry.npmjs.org";
|
|
98
|
-
if (isPublic) {
|
|
95
|
+
if (isPublicRegistry) {
|
|
99
96
|
return `https://www.npmjs.com/package/${encodeURIComponent(pkgName)}`;
|
|
100
97
|
}
|
|
101
|
-
return `${registry}/-/web/detail/${encodeURIComponent(
|
|
98
|
+
return `${npm.registry.replace(/\/$/, "")}/-/web/detail/${encodeURIComponent(
|
|
99
|
+
pkgName
|
|
100
|
+
)}`;
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Build package page URL for internal npm registry (Verdaccio-style).
|
|
105
|
+
*/
|
|
106
|
+
function getInternalPackagePageUrl(pkgName) {
|
|
107
|
+
if (!internalNpm.registry) return null;
|
|
108
|
+
const base = internalNpm.registry.replace(/\/$/, "");
|
|
109
|
+
return `${base}/-/web/detail/${encodeURIComponent(pkgName)}`;
|
|
110
|
+
}
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const linkedPkg = `<${packageUrl}|${pkgName}@${version}>`;
|
|
115
|
-
const text = success
|
|
116
|
-
? `packages published successfully (${registryLabel} registry):\n${linkedPkg}`
|
|
117
|
-
: `packages publish failed (${registryLabel} registry):\n${linkedPkg}\n${
|
|
118
|
-
error || "Unknown error"
|
|
119
|
-
}`;
|
|
112
|
+
async function sendSlackNotify(text) {
|
|
113
|
+
if (!slackWebhookUrl) return;
|
|
120
114
|
|
|
121
115
|
try {
|
|
122
116
|
const res = await fetch(slackWebhookUrl, {
|
|
@@ -193,12 +187,11 @@ function configureNpmEnv() {
|
|
|
193
187
|
* Authenticate npm by appending an auth token to the local ~/.npmrc file.
|
|
194
188
|
* Uses custom registry if provided, defaults to public npm registry.
|
|
195
189
|
*/
|
|
196
|
-
async function authNPM() {
|
|
190
|
+
async function authNPM(registry, token) {
|
|
191
|
+
if (!registry || !token) return;
|
|
197
192
|
// Remove protocol from registry URL for .npmrc syntax
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
.replace("https://", "");
|
|
201
|
-
const content = `\n//${registry}/:_authToken="${npm.token}"`;
|
|
193
|
+
const hostname = registry.replace("http://", "").replace("https://", "");
|
|
194
|
+
const content = `\n//${hostname}/:_authToken="${token}"`;
|
|
202
195
|
await $`echo ${content} >> .npmrc`;
|
|
203
196
|
}
|
|
204
197
|
|
|
@@ -258,12 +251,47 @@ async function getReleaseItOptions() {
|
|
|
258
251
|
return options;
|
|
259
252
|
}
|
|
260
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Publish the current package to internal npm registry (same version, no git ops).
|
|
256
|
+
*/
|
|
257
|
+
async function publishToInternalNpm() {
|
|
258
|
+
const { registry, token } = internalNpm;
|
|
259
|
+
|
|
260
|
+
await authNPM(registry, token);
|
|
261
|
+
|
|
262
|
+
await $`npm publish --registry ${registry}`;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function getNotifyMessage({ success, error, publishedToInternal }) {
|
|
266
|
+
const registryLabel = isPublicRegistry ? "public" : "internal";
|
|
267
|
+
|
|
268
|
+
const { name: pkgName, version } = readPackageJson();
|
|
269
|
+
const packageUrl = getPackagePageUrl(pkgName);
|
|
270
|
+
const linkedPkg = `<${packageUrl}|${pkgName}@${version}>`;
|
|
271
|
+
|
|
272
|
+
if (success && publishedToInternal) {
|
|
273
|
+
const publicUrl = packageUrl();
|
|
274
|
+
const internalUrl = getInternalPackagePageUrl(pkgName);
|
|
275
|
+
const publicLink = `<${publicUrl}|${pkgName}@${version}>`;
|
|
276
|
+
const internalLink = internalUrl
|
|
277
|
+
? `<${internalUrl}|${pkgName}@${version}>`
|
|
278
|
+
: `${pkgName}@${version}`;
|
|
279
|
+
return `Package published successfully:\n• Public: ${publicLink}\n• Internal: ${internalLink}`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (success) {
|
|
283
|
+
return `packages published successfully (${registryLabel} registry):\n${linkedPkg}`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// failed to publish
|
|
287
|
+
return `packages publish failed (${registryLabel} registry):\n${linkedPkg}\n${
|
|
288
|
+
error || "Unknown error"
|
|
289
|
+
}`;
|
|
290
|
+
}
|
|
291
|
+
|
|
261
292
|
async function main() {
|
|
262
293
|
try {
|
|
263
|
-
|
|
264
|
-
if (npm.token) {
|
|
265
|
-
await authNPM();
|
|
266
|
-
}
|
|
294
|
+
await authNPM(npm.registry, npm.token);
|
|
267
295
|
|
|
268
296
|
configureNpmEnv();
|
|
269
297
|
await configureGit();
|
|
@@ -271,13 +299,26 @@ async function main() {
|
|
|
271
299
|
const releaseItOptions = await getReleaseItOptions();
|
|
272
300
|
await releaseIt(releaseItOptions);
|
|
273
301
|
|
|
274
|
-
|
|
302
|
+
const publishedToInternal =
|
|
303
|
+
isPublicRegistry && internalNpm.registry && internalNpm.token;
|
|
304
|
+
|
|
305
|
+
if (publishedToInternal) {
|
|
306
|
+
await publishToInternalNpm();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const message = getNotifyMessage({
|
|
310
|
+
success: true,
|
|
311
|
+
publishedToInternal: Boolean(publishedToInternal),
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
await sendSlackNotify(message);
|
|
275
315
|
} catch (err) {
|
|
276
316
|
console.error("release error: ", err);
|
|
277
|
-
|
|
317
|
+
const message = getNotifyMessage({
|
|
278
318
|
success: false,
|
|
279
319
|
error: err?.message,
|
|
280
320
|
});
|
|
321
|
+
await sendSlackNotify(message);
|
|
281
322
|
throw err;
|
|
282
323
|
}
|
|
283
324
|
}
|