mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(release): track CommonJS package dist imports
This commit is contained in:
@@ -50,6 +50,11 @@ function isImportSpecifierContext(source, index) {
|
||||
);
|
||||
}
|
||||
|
||||
function isRequireSpecifierContext(source, index) {
|
||||
const prefix = source.slice(Math.max(0, index - 32), index);
|
||||
return /\brequire\s*\(\s*$/u.test(prefix);
|
||||
}
|
||||
|
||||
function isImportMetaUrlContext(source, quoteStart, quoteEnd) {
|
||||
const prefix = source.slice(Math.max(0, quoteStart - 32), quoteStart);
|
||||
if (!/\bnew\s+URL\s*\(\s*$/u.test(prefix)) {
|
||||
@@ -115,6 +120,7 @@ function collectImportSpecifiers(source) {
|
||||
if (value.startsWith(".")) {
|
||||
const isDistDependency =
|
||||
isImportSpecifierContext(source, index) ||
|
||||
isRequireSpecifierContext(source, index) ||
|
||||
(isImportMetaUrlContext(source, index, cursor) && hasJavaScriptFileExtension(value));
|
||||
if (isDistDependency) {
|
||||
specifiers.push(value);
|
||||
|
||||
@@ -271,6 +271,23 @@ describe("check-openclaw-package-tarball", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects CommonJS require chunks omitted from the postinstall inventory", () => {
|
||||
withTarball(
|
||||
["dist/index.cjs"],
|
||||
{
|
||||
"dist/index.cjs": 'module.exports = require("./chunk.cjs");\n',
|
||||
"dist/chunk.cjs": "module.exports = {};\n",
|
||||
},
|
||||
(tarball) => {
|
||||
const result = spawnSync("node", [CHECK_SCRIPT, tarball], { encoding: "utf8" });
|
||||
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr).toContain("inventory omits imported dist file dist/chunk.cjs");
|
||||
},
|
||||
"2026.4.27",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects dist files with missing import.meta.url URL dependencies", () => {
|
||||
withTarball(
|
||||
["dist/index.js"],
|
||||
|
||||
@@ -46,4 +46,19 @@ describe("check-package-dist-imports", () => {
|
||||
expect(result.status, result.stderr).toBe(0);
|
||||
expect(result.stdout).toContain("OpenClaw package dist import closure passed.");
|
||||
});
|
||||
|
||||
it("rejects missing CommonJS require chunks", () => {
|
||||
const root = makeTempDir(tempDirs, "openclaw-package-dist-imports-");
|
||||
mkdirSync(join(root, "dist"), { recursive: true });
|
||||
writeFileSync(
|
||||
join(root, "dist", "index.cjs"),
|
||||
'module.exports = require("./chunk.cjs");\n',
|
||||
"utf8",
|
||||
);
|
||||
|
||||
const result = spawnSync("node", [CHECK_SCRIPT, root], { encoding: "utf8" });
|
||||
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr).toContain("dist/index.cjs imports missing dist/chunk.cjs");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user