@nx-devkit/prepare-for-release 0.0.1 → 0.1.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.
|
@@ -2,7 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
|
-
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
6
6
|
import { glob } from "tinyglobby";
|
|
7
7
|
//#region src/executors/publish-placeholder/executor.ts
|
|
8
8
|
const DEFAULT_REGISTRY = "https://registry.npmjs.org/";
|
|
@@ -176,12 +176,36 @@ function trustArgs(pkgName, trustRepo, registry) {
|
|
|
176
176
|
return args;
|
|
177
177
|
}
|
|
178
178
|
function runTrustFor(pkgName, trustRepo, registry) {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
stdio:
|
|
179
|
+
const npmCmd = resolveNpmCommand();
|
|
180
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
181
|
+
const child = spawn(npmCmd, trustArgs(pkgName, trustRepo, registry), { stdio: [
|
|
182
|
+
"inherit",
|
|
183
|
+
"inherit",
|
|
184
|
+
"pipe"
|
|
185
|
+
] });
|
|
186
|
+
let stderr = "";
|
|
187
|
+
const timer = setTimeout(() => {
|
|
188
|
+
child.kill();
|
|
189
|
+
rejectPromise(/* @__PURE__ */ new Error(`npm trust github timed out for ${pkgName}`));
|
|
190
|
+
}, NPM_SUBPROCESS_TIMEOUT_MS);
|
|
191
|
+
child.stderr?.on("data", (chunk) => {
|
|
192
|
+
stderr += chunk.toString();
|
|
193
|
+
process.stderr.write(chunk);
|
|
194
|
+
});
|
|
195
|
+
child.on("error", (err) => {
|
|
196
|
+
clearTimeout(timer);
|
|
197
|
+
rejectPromise(err);
|
|
198
|
+
});
|
|
199
|
+
child.on("close", (code) => {
|
|
200
|
+
clearTimeout(timer);
|
|
201
|
+
if (code !== 0) {
|
|
202
|
+
rejectPromise(/* @__PURE__ */ new Error(`npm trust github failed for ${pkgName} (exit ${code})${stderr ? `: ${stderr}` : ""}`));
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
console.log(` ✓ ${pkgName}`);
|
|
206
|
+
resolvePromise();
|
|
207
|
+
});
|
|
182
208
|
});
|
|
183
|
-
if (result.status !== 0) throw new Error(`npm trust github failed for ${pkgName} (exit ${result.status})`);
|
|
184
|
-
console.log(` ✓ ${pkgName}`);
|
|
185
209
|
}
|
|
186
210
|
async function publishOnePackage(pkgRoot, name, resolved) {
|
|
187
211
|
const { tarballPath, tempDir } = await buildPlaceholderTarball(pkgRoot, name, resolved.placeholderVersion, resolved.registry);
|
|
@@ -238,13 +262,13 @@ async function publishPlaceholderExecutor(options, context) {
|
|
|
238
262
|
const trustTargets = [...acc.published, ...acc.skipped];
|
|
239
263
|
console.log(`\nConfiguring GitHub OIDC trusted publishing for ${trustTargets.length} package(s) (requires MFA)...\n`);
|
|
240
264
|
for (const pkgName of trustTargets) try {
|
|
241
|
-
runTrustFor(pkgName, resolved.trustRepo, resolved.registry);
|
|
242
|
-
} catch (
|
|
243
|
-
if (
|
|
265
|
+
await runTrustFor(pkgName, resolved.trustRepo, resolved.registry);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (error instanceof Error && /already.*trust|conflict|exists/i.test(error.message)) {
|
|
244
268
|
console.log(` ⊙ ${pkgName} (trust already configured)`);
|
|
245
269
|
continue;
|
|
246
270
|
}
|
|
247
|
-
throw
|
|
271
|
+
throw error;
|
|
248
272
|
}
|
|
249
273
|
} else {
|
|
250
274
|
console.log("\nRun these locally (requires MFA) to enable GitHub OIDC trusted publishing:\n");
|
|
@@ -61,10 +61,10 @@ async function initGenerator(tree, options = {}) {
|
|
|
61
61
|
"1. Install the plugin in the consuming workspace:",
|
|
62
62
|
" bun add -D @nx-devkit/prepare-for-release",
|
|
63
63
|
"2. Run the bootstrap target to publish 0.0.0 placeholders:",
|
|
64
|
-
`
|
|
64
|
+
` bunx nx run ${projectName}:prepare-for-release`,
|
|
65
65
|
"3. For each published placeholder, run the corresponding `npm trust github` command printed by the executor (requires MFA).",
|
|
66
66
|
"4. Wire OIDC trusted publishing in .github/workflows/release.yml (see the template shipped with this plugin).",
|
|
67
|
-
"5. From then on, releases are automated via `
|
|
67
|
+
"5. From then on, releases are automated via `bunx nx release`."
|
|
68
68
|
];
|
|
69
69
|
for (const line of checklist) console.log(line);
|
|
70
70
|
return () => {};
|
package/executors.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"executors": {
|
|
3
3
|
"publish-placeholder": {
|
|
4
|
-
"implementation": "./dist/executors/publish-placeholder/executor",
|
|
4
|
+
"implementation": "./dist/executors/publish-placeholder/executor.mjs",
|
|
5
5
|
"schema": "./src/executors/publish-placeholder/schema.json",
|
|
6
6
|
"description": "Publishes a 0.0.0 placeholder tarball to the npm registry for every workspace package that is not yet published. Idempotent."
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx-devkit/prepare-for-release",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "./
|
|
8
|
-
"module": "./
|
|
9
|
-
"types": "./
|
|
7
|
+
"main": "./dist/index.mjs",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"types": "./
|
|
13
|
-
"default": "./
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
14
|
},
|
|
15
15
|
"./plugin": {
|
|
16
|
-
"types": "./
|
|
17
|
-
"default": "./
|
|
18
|
-
}
|
|
16
|
+
"types": "./dist/plugin.d.mts",
|
|
17
|
+
"default": "./dist/plugin.mjs"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
19
20
|
},
|
|
20
21
|
"executors": "./executors.json",
|
|
21
22
|
"files": [
|
|
22
23
|
"dist",
|
|
23
24
|
"executors.json",
|
|
25
|
+
"src/executors/publish-placeholder/schema.json",
|
|
24
26
|
"README.md"
|
|
25
27
|
],
|
|
26
28
|
"scripts": {
|
|
@@ -31,10 +33,10 @@
|
|
|
31
33
|
"@nx/devkit": "^22.0.0 || ^23.0.0"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"@nx/devkit": "22.7.1",
|
|
35
36
|
"tinyglobby": "^0.2.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
39
|
+
"@nx/devkit": "23.2.1",
|
|
38
40
|
"@types/node": "^20.19.0",
|
|
39
41
|
"memfs": "^4.50.0",
|
|
40
42
|
"tsdown": "^0.22.3",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "publish-placeholder executor",
|
|
5
|
+
"description": "Publishes a 0.0.0 placeholder tarball to the npm registry for every workspace package that is not yet published. Idempotent.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"scope": {
|
|
9
|
+
"type": "array",
|
|
10
|
+
"items": { "type": "string" },
|
|
11
|
+
"description": "Package scope prefixes to check. Default: every package in packages/*."
|
|
12
|
+
},
|
|
13
|
+
"placeholderTag": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "npm dist-tag applied to the placeholder publish.",
|
|
16
|
+
"default": "placeholder"
|
|
17
|
+
},
|
|
18
|
+
"placeholderVersion": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "Version written into the temporary placeholder package.json.",
|
|
21
|
+
"default": "0.0.0"
|
|
22
|
+
},
|
|
23
|
+
"registry": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "npm registry URL.",
|
|
26
|
+
"default": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"dryRun": {
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"description": "If true, do not actually publish or pack; just report what would happen.",
|
|
31
|
+
"default": false
|
|
32
|
+
},
|
|
33
|
+
"trust": {
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
"description": "If true, run `npm trust github` for each published package (requires MFA).",
|
|
36
|
+
"default": false
|
|
37
|
+
},
|
|
38
|
+
"trustRepo": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"pattern": "^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$",
|
|
41
|
+
"description": "`owner/repo` slug used to build the `npm trust github` command. Falls back to NPM_TRUST_REPO or GITHUB_REPOSITORY env vars."
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"additionalProperties": false
|
|
45
|
+
}
|