fix: resolve bundled public surfaces from packaged dist

This commit is contained in:
Peter Steinberger
2026-05-02 23:09:51 +01:00
parent bf91494035
commit 8771cfb5b7
2 changed files with 30 additions and 2 deletions

View File

@@ -70,6 +70,25 @@ describe("bundled plugin public surface runtime", () => {
).toBe(sourceModulePath);
});
it("falls back from an incomplete package dist-runtime override to packaged dist", () => {
const packageRoot = createTempDir();
const distModulePath = path.join(packageRoot, "dist", "extensions", "demo", "api.js");
fs.mkdirSync(path.dirname(distModulePath), { recursive: true });
fs.writeFileSync(distModulePath, "export const marker = 'dist';\n", "utf8");
const runtimeBundledPluginsDir = path.join(packageRoot, "dist-runtime", "extensions");
fs.mkdirSync(path.join(runtimeBundledPluginsDir, "demo"), { recursive: true });
expect(
resolveBundledPluginPublicSurfacePath({
rootDir: packageRoot,
bundledPluginsDir: runtimeBundledPluginsDir,
dirName: "demo",
artifactBasename: "api.js",
}),
).toBe(distModulePath);
});
it("allows plugin-local nested artifact paths", () => {
expect(normalizeBundledPluginArtifactSubpath("src/outbound-adapter.js")).toBe(
"src/outbound-adapter.js",

View File

@@ -70,7 +70,7 @@ export function resolveBundledPluginSourcePublicSurfacePath(params: {
return null;
}
function resolvePackageSourceFallbackForBundledDir(params: {
function resolvePackageFallbackForBundledDir(params: {
rootDir: string;
bundledPluginsDir: string;
dirName: string;
@@ -85,6 +85,15 @@ function resolvePackageSourceFallbackForBundledDir(params: {
if (!packageBundledDirs.includes(normalizedBundledDir)) {
return null;
}
for (const packageBundledDir of packageBundledDirs) {
if (packageBundledDir === normalizedBundledDir) {
continue;
}
const builtCandidate = path.join(packageBundledDir, params.dirName, params.artifactBasename);
if (fs.existsSync(builtCandidate)) {
return builtCandidate;
}
}
return resolveBundledPluginSourcePublicSurfacePath({
sourceRoot: path.join(normalizedRootDir, "extensions"),
dirName: params.dirName,
@@ -116,7 +125,7 @@ export function resolveBundledPluginPublicSurfacePath(params: {
dirName,
artifactBasename,
}) ??
resolvePackageSourceFallbackForBundledDir({
resolvePackageFallbackForBundledDir({
rootDir: params.rootDir,
bundledPluginsDir: explicitBundledPluginsDir,
dirName,