@nx-devkit/prepare-for-release 0.0.1 → 0.1.1
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 +67 -54
- package/dist/executors/publish-placeholder/executor.mjs +34 -10
- package/dist/generators/init/generator.mjs +2 -2
- package/executors.json +1 -1
- package/generators.json +10 -0
- package/package.json +19 -10
- package/src/executors/publish-placeholder/schema.json +45 -0
- package/src/generators/init/schema.json +20 -0
package/README.md
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
# @nx-devkit/prepare-for-release
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Nx plugin + executor for bootstrapping npm packages: publishes a `0.0.0` placeholder tarball for every workspace package that doesn't exist on the registry yet, so the package name is claimed before you wire up [OIDC trusted publishing](https://docs.npmjs.com/trusted-publishers). Idempotent — already-published packages are skipped.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
| Surface | Kind | Purpose |
|
|
8
|
-
|---|---|---|
|
|
9
|
-
| `@nx-devkit/prepare-for-release:publish-placeholder` | Executor | Scans `packages/*`, publishes a `0.0.0` placeholder for any package not yet on the registry. |
|
|
10
|
-
| `@nx-devkit/prepare-for-release:init` | Generator | Adds the plugin to `nx.json`, creates a `tools` project with a `prepare-for-release` target, prints the post-setup checklist. |
|
|
11
|
-
| `@nx-devkit/prepare-for-release` (createNodesV2) | Plugin | Detects a `tools/project.json` referencing the executor and re-affirms the `prepare-for-release` target. |
|
|
12
|
-
|
|
13
|
-
The executor is idempotent — already-published packages are skipped — and never modifies the source `package.json` (the placeholder tarball is built in a temp directory). Use `dryRun: true` to preview.
|
|
5
|
+
Part of [nx-devkit](https://github.com/nx-devkit/nx.ts).
|
|
14
6
|
|
|
15
7
|
## Install
|
|
16
8
|
|
|
@@ -18,73 +10,94 @@ The executor is idempotent — already-published packages are skipped — and ne
|
|
|
18
10
|
bun add -D @nx-devkit/prepare-for-release
|
|
19
11
|
```
|
|
20
12
|
|
|
21
|
-
|
|
13
|
+
Requires `@nx/devkit` `^22 || ^23` (peer).
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
"plugins": ["@nx-devkit/prepare-for-release"]
|
|
26
|
-
}
|
|
27
|
-
```
|
|
15
|
+
## Bootstrap
|
|
28
16
|
|
|
29
|
-
|
|
17
|
+
Run the `init` generator — it registers the plugin in `nx.json` and creates a `tools` project with the `prepare-for-release` target:
|
|
30
18
|
|
|
31
19
|
```bash
|
|
32
|
-
|
|
20
|
+
npx nx g @nx-devkit/prepare-for-release:init
|
|
33
21
|
```
|
|
34
22
|
|
|
35
|
-
|
|
23
|
+
<!-- sym:generators.json → generators.init.factory,schema -->
|
|
36
24
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
Or do it manually:
|
|
26
|
+
|
|
27
|
+
1. Register the plugin in `nx.json` so `createNodesV2` can detect release-bootstrap projects:
|
|
28
|
+
|
|
29
|
+
```jsonc
|
|
30
|
+
{ "plugins": ["@nx-devkit/prepare-for-release"] }
|
|
41
31
|
```
|
|
42
32
|
|
|
43
|
-
|
|
33
|
+
2. Create `tools/project.json` wired to the executor:
|
|
44
34
|
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
trustRepo?: string; // default: process.env.NPM_TRUST_REPO or process.env.GITHUB_REPOSITORY or "nx-devkit/nx.ts"
|
|
35
|
+
```jsonc
|
|
36
|
+
{
|
|
37
|
+
"name": "tools",
|
|
38
|
+
"targets": {
|
|
39
|
+
"prepare-for-release": {
|
|
40
|
+
"executor": "@nx-devkit/prepare-for-release:publish-placeholder"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
54
43
|
}
|
|
55
44
|
```
|
|
56
45
|
|
|
57
|
-
|
|
46
|
+
The plugin's `createNodesV2` scans `**/project.json` for projects whose targets reference its executor and surfaces them on the graph.
|
|
47
|
+
|
|
48
|
+
Then run:
|
|
58
49
|
|
|
59
|
-
```
|
|
60
|
-
|
|
50
|
+
```bash
|
|
51
|
+
npx nx run tools:prepare-for-release
|
|
52
|
+
```
|
|
61
53
|
|
|
62
|
-
|
|
63
|
-
[@nx-devkit/prepare-for-release] @nx-devkit/tsdown: 404 → publishing 0.0.0 placeholder
|
|
64
|
-
[@nx-devkit/prepare-for-release] @nx-devkit/oxlint: 404 → publishing 0.0.0 placeholder
|
|
65
|
-
[@nx-devkit/prepare-for-release] @nx-devkit/biome: 0.5.0 already on registry, skipping
|
|
66
|
-
[@nx-devkit/prepare-for-release] @nx-devkit/typescript: 404 → publishing 0.0.0 placeholder
|
|
54
|
+
## What the executor does
|
|
67
55
|
|
|
68
|
-
|
|
69
|
-
Skipped: @nx-devkit/biome
|
|
56
|
+
For each package under `packages/*` (or your `scope` filter):
|
|
70
57
|
|
|
71
|
-
|
|
58
|
+
1. Checks the registry for an existing version of the package.
|
|
59
|
+
2. If the name is unclaimed, builds a minimal placeholder tarball **in a temp dir** — your source `package.json` is never mutated.
|
|
60
|
+
3. Publishes it with `npm publish --tag placeholder`.
|
|
61
|
+
4. Optionally runs `npm trust github` to bind OIDC trusted publishing to your repo.
|
|
62
|
+
|
|
63
|
+
Already-published packages are skipped on every run.
|
|
64
|
+
|
|
65
|
+
## Options
|
|
72
66
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
<!-- option reference consistent with src/executors/publish-placeholder/schema.json -->
|
|
68
|
+
|
|
69
|
+
```jsonc
|
|
70
|
+
// tools/project.json → targets.prepare-for-release.options
|
|
71
|
+
{
|
|
72
|
+
"scope": ["@nx-devkit"],
|
|
73
|
+
"placeholderTag": "placeholder",
|
|
74
|
+
"placeholderVersion": "0.0.0",
|
|
75
|
+
"registry": "https://registry.npmjs.org/",
|
|
76
|
+
"dryRun": false,
|
|
77
|
+
"trust": false,
|
|
78
|
+
"trustRepo": "owner/repo"
|
|
79
|
+
}
|
|
76
80
|
```
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
| Option | Default | Effect |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `scope` | every package in `packages/*` | Package scope prefixes to check. |
|
|
85
|
+
| `placeholderTag` | `placeholder` | npm dist-tag applied to the placeholder publish. |
|
|
86
|
+
| `placeholderVersion` | `0.0.0` | Version written into the temporary placeholder manifest. |
|
|
87
|
+
| `registry` | `https://registry.npmjs.org/` | npm registry URL. |
|
|
88
|
+
| `dryRun` | `false` | Report what would happen — no `npm pack`, no publish. |
|
|
89
|
+
| `trust` | `false` | Run `npm trust github` for every checked package — including already-published (skipped) ones — not just newly published (requires MFA). With `dryRun: true` the trust commands are printed, not run. |
|
|
90
|
+
| `trustRepo` | `NPM_TRUST_REPO` or `GITHUB_REPOSITORY` env, else `nx-devkit/nx.ts` | `owner/repo` slug for the `npm trust github` command. |
|
|
91
|
+
|
|
92
|
+
## Why placeholders
|
|
79
93
|
|
|
80
|
-
|
|
81
|
-
- Bootstrapping a multi-package monorepo so that downstream `nx release` + OIDC trusted publishing can take over from there.
|
|
82
|
-
- You want the placeholder publish to be idempotent and offline-friendly (it just shells out to `npm view` and `npm publish`).
|
|
94
|
+
npm OIDC trusted publishing requires the package to already exist before you can configure a trust relationship — but publishing the real package first defeats the point. Placeholders claim the name with throwaway `0.0.0` content under a `placeholder` tag (not `latest`), so users never install a stub by accident. The first real release lands under your normal version.
|
|
83
95
|
|
|
84
|
-
##
|
|
96
|
+
## Security notes
|
|
85
97
|
|
|
86
|
-
|
|
98
|
+
- The executor invokes `npm` via `spawnSync` with an argv array — no shell interpolation of package names, paths, or registry URLs.
|
|
99
|
+
- `npm trust github` runs only when `trust: true` and may prompt for MFA — it's a real-world side effect, not idempotent in the same sense.
|
|
87
100
|
|
|
88
101
|
## License
|
|
89
102
|
|
|
90
|
-
MIT
|
|
103
|
+
MIT
|
|
@@ -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/generators.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"generators": {
|
|
4
|
+
"init": {
|
|
5
|
+
"factory": "./dist/generators/init/generator.mjs",
|
|
6
|
+
"schema": "./src/generators/init/schema.json",
|
|
7
|
+
"description": "Wires @nx-devkit/prepare-for-release into an Nx workspace: adds the plugin to nx.json, creates a `tools` project with a `prepare-for-release` target, and prints the post-setup checklist."
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx-devkit/prepare-for-release",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
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
|
+
"./generators/init": {
|
|
20
|
+
"types": "./dist/generators/init/generator.d.mts",
|
|
21
|
+
"default": "./dist/generators/init/generator.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
19
24
|
},
|
|
20
25
|
"executors": "./executors.json",
|
|
26
|
+
"generators": "./generators.json",
|
|
21
27
|
"files": [
|
|
22
28
|
"dist",
|
|
23
29
|
"executors.json",
|
|
30
|
+
"generators.json",
|
|
31
|
+
"src/executors/publish-placeholder/schema.json",
|
|
32
|
+
"src/generators/init/schema.json",
|
|
24
33
|
"README.md"
|
|
25
34
|
],
|
|
26
35
|
"scripts": {
|
|
@@ -31,10 +40,10 @@
|
|
|
31
40
|
"@nx/devkit": "^22.0.0 || ^23.0.0"
|
|
32
41
|
},
|
|
33
42
|
"dependencies": {
|
|
34
|
-
"@nx/devkit": "22.7.1",
|
|
35
43
|
"tinyglobby": "^0.2.0"
|
|
36
44
|
},
|
|
37
45
|
"devDependencies": {
|
|
46
|
+
"@nx/devkit": "23.2.1",
|
|
38
47
|
"@types/node": "^20.19.0",
|
|
39
48
|
"memfs": "^4.50.0",
|
|
40
49
|
"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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "init generator",
|
|
5
|
+
"description": "Wires @nx-devkit/prepare-for-release into an Nx workspace: adds the plugin to nx.json, creates a `tools` project with a `prepare-for-release` target, and prints the post-setup checklist.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"projectName": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Name of the workspace project that hosts the prepare-for-release target.",
|
|
11
|
+
"default": "tools"
|
|
12
|
+
},
|
|
13
|
+
"pluginPath": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Module specifier for the plugin in nx.json plugins[]. Use a relative path or package name.",
|
|
16
|
+
"default": "@nx-devkit/prepare-for-release"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"additionalProperties": false
|
|
20
|
+
}
|