Skip to content

Commit 103b6d5

Browse files
committed
fix: resolve bundled public surfaces from packaged dist
(cherry picked from commit 8771cfb)
1 parent 1110c24 commit 103b6d5

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/plugins/public-surface-runtime.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ describe("bundled plugin public surface runtime", () => {
7070
).toBe(sourceModulePath);
7171
});
7272

73+
it("falls back from an incomplete package dist-runtime override to packaged dist", () => {
74+
const packageRoot = createTempDir();
75+
const distModulePath = path.join(packageRoot, "dist", "extensions", "demo", "api.js");
76+
fs.mkdirSync(path.dirname(distModulePath), { recursive: true });
77+
fs.writeFileSync(distModulePath, "export const marker = 'dist';\n", "utf8");
78+
79+
const runtimeBundledPluginsDir = path.join(packageRoot, "dist-runtime", "extensions");
80+
fs.mkdirSync(path.join(runtimeBundledPluginsDir, "demo"), { recursive: true });
81+
82+
expect(
83+
resolveBundledPluginPublicSurfacePath({
84+
rootDir: packageRoot,
85+
bundledPluginsDir: runtimeBundledPluginsDir,
86+
dirName: "demo",
87+
artifactBasename: "api.js",
88+
}),
89+
).toBe(distModulePath);
90+
});
91+
7392
it("allows plugin-local nested artifact paths", () => {
7493
expect(normalizeBundledPluginArtifactSubpath("src/outbound-adapter.js")).toBe(
7594
"src/outbound-adapter.js",

src/plugins/public-surface-runtime.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function resolveBundledPluginSourcePublicSurfacePath(params: {
7070
return null;
7171
}
7272

73-
function resolvePackageSourceFallbackForBundledDir(params: {
73+
function resolvePackageFallbackForBundledDir(params: {
7474
rootDir: string;
7575
bundledPluginsDir: string;
7676
dirName: string;
@@ -85,6 +85,15 @@ function resolvePackageSourceFallbackForBundledDir(params: {
8585
if (!packageBundledDirs.includes(normalizedBundledDir)) {
8686
return null;
8787
}
88+
for (const packageBundledDir of packageBundledDirs) {
89+
if (packageBundledDir === normalizedBundledDir) {
90+
continue;
91+
}
92+
const builtCandidate = path.join(packageBundledDir, params.dirName, params.artifactBasename);
93+
if (fs.existsSync(builtCandidate)) {
94+
return builtCandidate;
95+
}
96+
}
8897
return resolveBundledPluginSourcePublicSurfacePath({
8998
sourceRoot: path.join(normalizedRootDir, "extensions"),
9099
dirName: params.dirName,
@@ -116,7 +125,7 @@ export function resolveBundledPluginPublicSurfacePath(params: {
116125
dirName,
117126
artifactBasename,
118127
}) ??
119-
resolvePackageSourceFallbackForBundledDir({
128+
resolvePackageFallbackForBundledDir({
120129
rootDir: params.rootDir,
121130
bundledPluginsDir: explicitBundledPluginsDir,
122131
dirName,

0 commit comments

Comments
 (0)