Skip to content

Commit 516574d

Browse files
fix(registry-verification): use Windows-valid synthetic URL for createRequire shim
EmDash-Run: 9e7c91e5-80af-4c34-8c1b-be105396b012
1 parent fc87efe commit 516574d

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@emdash-cms/registry-verification": patch
3+
---
4+
5+
Fixes the generated `createRequire` shim in the ESM build so the synthetic file URL includes a drive letter. The previous driveless URL (`file:///emdash-registry-verification.js`) was rejected by `fileURLToPath()` on Windows, causing builds that inline this package (such as `emdash@0.37.0` on Windows) to fail when the Astro config was loaded.

packages/registry-verification/scripts/check-packed-output.mjs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { execFileSync } from "node:child_process";
22
import { createReadStream } from "node:fs";
33
import { mkdtemp, readFile, rm } from "node:fs/promises";
44
import { tmpdir } from "node:os";
5-
import { join } from "node:path";
5+
import path, { join } from "node:path";
66
import { pipeline } from "node:stream/promises";
7+
import { fileURLToPath } from "node:url";
78
import { createGunzip } from "node:zlib";
89

910
import { unpackTar } from "modern-tar/fs";
@@ -42,6 +43,27 @@ try {
4243
if (publishedOutput.includes("createRequire(import.meta.url)")) {
4344
throw new Error("Packed verifier output cannot be safely rebundled");
4445
}
46+
47+
// On Windows, fileURLToPath() rejects driveless file:/// URLs. The synthetic
48+
// base used for the CJS interop shim must include a drive letter so it is
49+
// accepted as a valid absolute file URL on every platform.
50+
const requireUrlMatch = publishedOutput.match(/__require = .*?createRequire\("([^"]+)"\)/);
51+
if (!requireUrlMatch) {
52+
throw new Error("Packed verifier output is missing the CJS interop shim");
53+
}
54+
const syntheticRequireUrl = requireUrlMatch[1];
55+
if (!/^file:\/\/\/[A-Za-z]:\//.test(syntheticRequireUrl)) {
56+
throw new Error(
57+
`Packed verifier createRequire URL is not Windows-valid: ${syntheticRequireUrl}`,
58+
);
59+
}
60+
const resolvedPath = fileURLToPath(syntheticRequireUrl);
61+
if (!path.isAbsolute(resolvedPath)) {
62+
throw new Error(
63+
`Packed verifier createRequire URL did not resolve to an absolute path: ${resolvedPath}`,
64+
);
65+
}
66+
4567
if (
4668
publishedBundleOutput.includes("createRequire") ||
4769
publishedBundleOutput.includes("@sigstore") ||

packages/registry-verification/tsdown.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import { defineConfig } from "tsdown";
55
const rebundleSafeRequire = {
66
name: "rebundle-safe-require",
77
renderChunk(code: string) {
8+
// Consumers rebundle this artifact, so `import.meta.url` may no longer name
9+
// a real file. The generated `require` only resolves Node builtins, so any
10+
// absolute file URL is sufficient. The URL must include a synthetic drive
11+
// letter: on Windows `fileURLToPath()` rejects driveless `file:///...` URLs.
812
return code.replace(
913
"createRequire(import.meta.url)",
10-
'createRequire("file:///emdash-registry-verification.js")',
14+
'createRequire("file:///C:/emdash-registry-verification.js")',
1115
);
1216
},
1317
};

0 commit comments

Comments
 (0)