fix(plugin-sdk): sort hashed root alias dist chunks

This commit is contained in:
Vincent Koc
2026-04-14 17:53:10 +01:00
parent 30073feb6f
commit 665a8496d7
2 changed files with 29 additions and 1 deletions

View File

@@ -90,7 +90,9 @@ function getPackageRoot() {
function findDistChunkByPrefix(prefix) {
const distRoot = path.join(getPackageRoot(), "dist");
try {
const entries = fs.readdirSync(distRoot, { withFileTypes: true });
const entries = fs
.readdirSync(distRoot, { withFileTypes: true })
.toSorted((left, right) => left.name.localeCompare(right.name));
const match = entries.find(
(entry) =>
entry.isFile() && entry.name.startsWith(`${prefix}-`) && entry.name.endsWith(".js"),

View File

@@ -331,6 +331,32 @@ describe("plugin-sdk root alias", () => {
);
});
it("chooses hashed dist diagnostic events chunks deterministically", () => {
const packageRoot = createPackageRoot();
const distAliasPath = createDistAliasPath();
const lazyModule = loadRootAliasWithStubs({
aliasPath: distAliasPath,
distExists: false,
distEntries: ["diagnostic-events-zeta.js", "diagnostic-events-alpha.js"],
monolithicExports: {
r: (): (() => void) => () => undefined,
slowHelper: (): string => "loaded",
},
});
expect(
typeof (lazyModule.moduleExports.onDiagnosticEvent as (listener: () => void) => () => void)(
() => undefined,
),
).toBe("function");
expect(lazyModule.loadedSpecifiers).toContain(
path.join(packageRoot, "dist", "diagnostic-events-alpha.js"),
);
expect(lazyModule.loadedSpecifiers).not.toContain(
path.join(packageRoot, "dist", "diagnostic-events-zeta.js"),
);
});
it.each([
{
name: "forwards delegateCompactionToRuntime through the compat-backed root alias",