fix: load staged dist-runtime plugins in docker

This commit is contained in:
Peter Steinberger
2026-04-22 18:20:40 +01:00
parent 72c765e736
commit a2512f0243
13 changed files with 311 additions and 12 deletions

View File

@@ -636,7 +636,8 @@ function applyBundledPluginRuntimeHotfixes(params = {}) {
export function isSourceCheckoutRoot(params) {
const pathExists = params.existsSync ?? existsSync;
return (
pathExists(join(params.packageRoot, ".git")) &&
(pathExists(join(params.packageRoot, ".git")) ||
pathExists(join(params.packageRoot, "pnpm-workspace.yaml"))) &&
pathExists(join(params.packageRoot, "src")) &&
pathExists(join(params.packageRoot, "extensions"))
);

View File

@@ -140,15 +140,35 @@ function shouldCopyRuntimeFile(sourcePath) {
);
}
function hasDefaultExport(sourcePath) {
const text = fs.readFileSync(sourcePath, "utf8");
return /\bexport\s+default\b/u.test(text) || /\bas\s+default\b/u.test(text);
}
function writeRuntimeModuleWrapper(sourcePath, targetPath) {
const specifier = relativeSymlinkTarget(sourcePath, targetPath).replace(/\\/g, "/");
const normalizedSpecifier = specifier.startsWith(".") ? specifier : `./${specifier}`;
const defaultForwarder = hasDefaultExport(sourcePath)
? [
`import defaultModule from ${JSON.stringify(normalizedSpecifier)};`,
`let defaultExport = defaultModule;`,
`for (let index = 0; index < 4 && defaultExport && typeof defaultExport === "object" && "default" in defaultExport; index += 1) {`,
` defaultExport = defaultExport.default;`,
`}`,
]
: [
`import * as module from ${JSON.stringify(normalizedSpecifier)};`,
`let defaultExport = "default" in module ? module.default : module;`,
`for (let index = 0; index < 4 && defaultExport && typeof defaultExport === "object" && "default" in defaultExport; index += 1) {`,
` defaultExport = defaultExport.default;`,
`}`,
];
fs.writeFileSync(
targetPath,
[
`export * from ${JSON.stringify(normalizedSpecifier)};`,
`import * as module from ${JSON.stringify(normalizedSpecifier)};`,
"export default module.default;",
...defaultForwarder,
"export { defaultExport as default };",
"",
].join("\n"),
"utf8",