fix(release): track CommonJS package dist imports · openclaw/openclaw@c061373
vincentkoc
·
2026-06-23
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -50,6 +50,11 @@ function isImportSpecifierContext(source, index) {
|
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
| 53 | +function isRequireSpecifierContext(source, index) { |
| 54 | +const prefix = source.slice(Math.max(0, index - 32), index); |
| 55 | +return /\brequire\s*\(\s*$/u.test(prefix); |
| 56 | +} |
| 57 | + |
53 | 58 | function isImportMetaUrlContext(source, quoteStart, quoteEnd) { |
54 | 59 | const prefix = source.slice(Math.max(0, quoteStart - 32), quoteStart); |
55 | 60 | if (!/\bnew\s+URL\s*\(\s*$/u.test(prefix)) { |
@@ -115,6 +120,7 @@ function collectImportSpecifiers(source) {
|
115 | 120 | if (value.startsWith(".")) { |
116 | 121 | const isDistDependency = |
117 | 122 | isImportSpecifierContext(source, index) || |
| 123 | +isRequireSpecifierContext(source, index) || |
118 | 124 | (isImportMetaUrlContext(source, index, cursor) && hasJavaScriptFileExtension(value)); |
119 | 125 | if (isDistDependency) { |
120 | 126 | specifiers.push(value); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -271,6 +271,23 @@ describe("check-openclaw-package-tarball", () => {
|
271 | 271 | ); |
272 | 272 | }); |
273 | 273 | |
| 274 | +it("rejects CommonJS require chunks omitted from the postinstall inventory", () => { |
| 275 | +withTarball( |
| 276 | +["dist/index.cjs"], |
| 277 | +{ |
| 278 | +"dist/index.cjs": 'module.exports = require("./chunk.cjs");\n', |
| 279 | +"dist/chunk.cjs": "module.exports = {};\n", |
| 280 | +}, |
| 281 | +(tarball) => { |
| 282 | +const result = spawnSync("node", [CHECK_SCRIPT, tarball], { encoding: "utf8" }); |
| 283 | + |
| 284 | +expect(result.status).not.toBe(0); |
| 285 | +expect(result.stderr).toContain("inventory omits imported dist file dist/chunk.cjs"); |
| 286 | +}, |
| 287 | +"2026.4.27", |
| 288 | +); |
| 289 | +}); |
| 290 | + |
274 | 291 | it("rejects dist files with missing import.meta.url URL dependencies", () => { |
275 | 292 | withTarball( |
276 | 293 | ["dist/index.js"], |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -46,4 +46,19 @@ describe("check-package-dist-imports", () => {
|
46 | 46 | expect(result.status, result.stderr).toBe(0); |
47 | 47 | expect(result.stdout).toContain("OpenClaw package dist import closure passed."); |
48 | 48 | }); |
| 49 | + |
| 50 | +it("rejects missing CommonJS require chunks", () => { |
| 51 | +const root = makeTempDir(tempDirs, "openclaw-package-dist-imports-"); |
| 52 | +mkdirSync(join(root, "dist"), { recursive: true }); |
| 53 | +writeFileSync( |
| 54 | +join(root, "dist", "index.cjs"), |
| 55 | +'module.exports = require("./chunk.cjs");\n', |
| 56 | +"utf8", |
| 57 | +); |
| 58 | + |
| 59 | +const result = spawnSync("node", [CHECK_SCRIPT, root], { encoding: "utf8" }); |
| 60 | + |
| 61 | +expect(result.status).not.toBe(0); |
| 62 | +expect(result.stderr).toContain("dist/index.cjs imports missing dist/chunk.cjs"); |
| 63 | +}); |
49 | 64 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。