Skip to content

Commit a0cb9b6

Browse files
committed
fix(release): share npm pack normalizer in plugin workflow
1 parent d422056 commit a0cb9b6

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

‎.github/workflows/plugin-npm-release.yml‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- "package.json"
1212
- "scripts/generate-npm-package-lock.mjs"
1313
- "scripts/lib/npm-publish-plan.mjs"
14+
- "scripts/lib/npm-json-output.mjs"
1415
- "scripts/lib/release-version.mjs"
1516
- "scripts/lib/plugin-npm-package-manifest.mjs"
1617
- "scripts/lib/plugin-npm-release.ts"
@@ -338,6 +339,7 @@ jobs:
338339
fetch-depth: 1
339340
sparse-checkout: |
340341
scripts/generate-npm-package-lock.mjs
342+
scripts/lib/npm-json-output.mjs
341343
scripts/lib/plugin-npm-package-manifest.mjs
342344
sparse-checkout-cone-mode: false
343345

@@ -347,6 +349,9 @@ jobs:
347349
cp \
348350
.release-tooling/scripts/generate-npm-package-lock.mjs \
349351
scripts/generate-npm-package-lock.mjs
352+
cp \
353+
.release-tooling/scripts/lib/npm-json-output.mjs \
354+
scripts/lib/npm-json-output.mjs
350355
cp \
351356
.release-tooling/scripts/lib/plugin-npm-package-manifest.mjs \
352357
scripts/lib/plugin-npm-package-manifest.mjs
@@ -398,29 +403,17 @@ jobs:
398403
OPENCLAW_PLUGIN_NPM_PACK_OUTPUT_DIR="${artifact_dir}" \
399404
bash scripts/plugin-npm-publish.sh --pack "${PACKAGE_DIR}" > "${pack_output}"
400405
401-
node - "${pack_output}" "${pack_json}" <<'NODE'
402-
const fs = require("node:fs");
406+
node --input-type=module - "${pack_output}" "${pack_json}" <<'NODE'
407+
import fs from "node:fs";
408+
import { resolveNpmJsonEntries } from "./scripts/lib/npm-json-output.mjs";
409+
403410
const raw = fs.readFileSync(process.argv[2], "utf8").trim();
404-
function resolvePackEntries(value) {
405-
if (Array.isArray(value)) return value;
406-
if (!value || typeof value !== "object") return [];
407-
const looksLikeEntry =
408-
typeof value.id === "string" ||
409-
typeof value.name === "string" ||
410-
typeof value.version === "string" ||
411-
typeof value.filename === "string";
412-
return looksLikeEntry
413-
? [value]
414-
: Object.values(value).filter(
415-
(entry) => entry && typeof entry === "object" && !Array.isArray(entry),
416-
);
417-
}
418411
let pack;
419412
for (let index = raw.length - 1; index >= 0; index -= 1) {
420413
if (raw[index] !== "[" && raw[index] !== "{") continue;
421414
try {
422415
const candidate = JSON.parse(raw.slice(index));
423-
const entries = resolvePackEntries(candidate);
416+
const entries = resolveNpmJsonEntries(candidate);
424417
if (entries.length > 0) {
425418
pack = entries;
426419
break;
@@ -1251,6 +1244,9 @@ jobs:
12511244
cp \
12521245
scripts/generate-npm-package-lock.mjs \
12531246
.publication-target/scripts/generate-npm-package-lock.mjs
1247+
cp \
1248+
scripts/lib/npm-json-output.mjs \
1249+
.publication-target/scripts/lib/npm-json-output.mjs
12541250
cp \
12551251
scripts/lib/plugin-npm-package-manifest.mjs \
12561252
.publication-target/scripts/lib/plugin-npm-package-manifest.mjs

‎test/scripts/plugin-npm-extended-stable-workflow.test.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe("plugin npm extended-stable workflow", () => {
105105
}
106106
});
107107

108-
it("overlays the complete trusted packaging helper dependency pair", () => {
108+
it("overlays the complete trusted packaging helper dependency set", () => {
109109
const parsed = workflow();
110110
const preflightCheckout = step(
111111
parsed.jobs?.preview_plugin_pack,
@@ -114,12 +114,16 @@ describe("plugin npm extended-stable workflow", () => {
114114
expect(preflightCheckout.with?.["sparse-checkout"]).toContain(
115115
"scripts/generate-npm-package-lock.mjs",
116116
);
117+
expect(preflightCheckout.with?.["sparse-checkout"]).toContain(
118+
"scripts/lib/npm-json-output.mjs",
119+
);
117120
expect(preflightCheckout.with?.["sparse-checkout"]).toContain(
118121
"scripts/lib/plugin-npm-package-manifest.mjs",
119122
);
120123

121124
const expectedCopies = [
122125
"scripts/generate-npm-package-lock.mjs",
126+
"scripts/lib/npm-json-output.mjs",
123127
"scripts/lib/plugin-npm-package-manifest.mjs",
124128
];
125129
for (const helperPath of expectedCopies) {
@@ -202,9 +206,11 @@ describe("plugin npm extended-stable workflow", () => {
202206
);
203207
expect(prepare.if).toBeUndefined();
204208
expect(prepare.run).toContain('bash scripts/plugin-npm-publish.sh --pack "${PACKAGE_DIR}"');
205-
expect(prepare.run).toContain("function resolvePackEntries(value)");
209+
expect(prepare.run).toContain(
210+
'import { resolveNpmJsonEntries } from "./scripts/lib/npm-json-output.mjs";',
211+
);
206212
expect(prepare.run).toContain('raw[index] !== "[" && raw[index] !== "{"');
207-
expect(prepare.run).toContain("const entries = resolvePackEntries(candidate)");
213+
expect(prepare.run).toContain("const entries = resolveNpmJsonEntries(candidate)");
208214
expect(prepare.run).toContain("npm can print bundled-dependency summaries");
209215
expect(prepare.run).toContain(
210216
"fs.writeFileSync(process.argv[3], `${JSON.stringify(pack, null, 2)}\\n`)",

0 commit comments

Comments
 (0)