fix(plugins): harden bundled runtime dep staging

This commit is contained in:
Peter Steinberger
2026-04-22 18:48:35 +01:00
parent 0e9c632444
commit 9d66a900e5
4 changed files with 64 additions and 2 deletions

View File

@@ -183,6 +183,12 @@ function assertSafeInstalledDistPath(relativePath, params) {
return candidatePath;
}
function isStagedRuntimeNodeModulesPath(relativePath) {
return /^dist\/extensions\/[^/]+\/node_modules(?:\/|$)/u.test(
normalizeRelativePath(relativePath),
);
}
function listInstalledDistFiles(params = {}) {
const readDir = params.readdirSync ?? readdirSync;
const distRoot = resolveInstalledDistRoot(params);
@@ -197,6 +203,10 @@ function listInstalledDistFiles(params = {}) {
if (!currentDir) {
continue;
}
const relativeCurrentDir = normalizeRelativePath(relative(packageRoot, currentDir));
if (isStagedRuntimeNodeModulesPath(relativeCurrentDir)) {
continue;
}
for (const entry of readDir(currentDir, { withFileTypes: true })) {
const entryPath = join(currentDir, entry.name);
if (entry.isSymbolicLink()) {
@@ -232,6 +242,10 @@ function pruneEmptyDistDirectories(params = {}) {
const pathLstat = params.lstatSync ?? lstatSync;
function prune(currentDir) {
const relativeCurrentDir = normalizeRelativePath(relative(packageRoot, currentDir));
if (isStagedRuntimeNodeModulesPath(relativeCurrentDir)) {
return;
}
for (const entry of readDir(currentDir, { withFileTypes: true })) {
if (entry.isSymbolicLink()) {
throw new Error(