diff --git a/scripts/stage-bundled-plugin-runtime-deps.mjs b/scripts/stage-bundled-plugin-runtime-deps.mjs index 1431bce8fc68b..310cf004fe275 100644 --- a/scripts/stage-bundled-plugin-runtime-deps.mjs +++ b/scripts/stage-bundled-plugin-runtime-deps.mjs @@ -489,6 +489,29 @@ function pruneDependencyFilesBySuffixes(depRoot, suffixes) { }); } +function pruneNodeModulesBinDirectories(nodeModulesDir) { + if (!fs.existsSync(nodeModulesDir)) { + return; + } + const pending = [nodeModulesDir]; + while (pending.length > 0) { + const currentDir = pending.pop(); + if (!fs.existsSync(currentDir)) { + continue; + } + for (const entry of fs.readdirSync(currentDir, { withFileTypes: true })) { + const entryPath = path.join(currentDir, entry.name); + if (entry.name === ".bin") { + removePathIfExists(entryPath); + continue; + } + if (entry.isDirectory()) { + pending.push(entryPath); + } + } + } +} + function pruneStagedInstalledDependencyCargo(nodeModulesDir, depName, pruneConfig) { const depRoot = dependencyNodeModulesPath(nodeModulesDir, depName); if (depRoot === null) { @@ -526,6 +549,7 @@ function listInstalledDependencyNames(nodeModulesDir) { } function pruneStagedRuntimeDependencyCargo(nodeModulesDir, pruneConfig) { + pruneNodeModulesBinDirectories(nodeModulesDir); for (const depName of listInstalledDependencyNames(nodeModulesDir)) { pruneStagedInstalledDependencyCargo(nodeModulesDir, depName, pruneConfig); } diff --git a/test/scripts/stage-bundled-plugin-runtime-deps.test.ts b/test/scripts/stage-bundled-plugin-runtime-deps.test.ts index ae6d5b6b2bc9b..153968ec289c3 100644 --- a/test/scripts/stage-bundled-plugin-runtime-deps.test.ts +++ b/test/scripts/stage-bundled-plugin-runtime-deps.test.ts @@ -771,8 +771,14 @@ describe("stageBundledPluginRuntimeDeps", () => { fs.writeFileSync(path.join(gifwrapDir, "test", "fixtures", "large.gif"), "fixture\n", "utf8"); const playwrightDir = writePackage("playwright-core"); fs.mkdirSync(path.join(playwrightDir, "types"), { recursive: true }); + fs.mkdirSync(path.join(rootNodeModules, ".bin"), { recursive: true }); fs.writeFileSync(path.join(playwrightDir, "types", "types.d.ts"), "export {};\n", "utf8"); fs.writeFileSync(path.join(playwrightDir, "index.js"), "export {};\n", "utf8"); + fs.writeFileSync(path.join(playwrightDir, "cli.js"), "export {};\n", "utf8"); + fs.symlinkSync( + path.join("..", "playwright-core", "cli.js"), + path.join(rootNodeModules, ".bin", "playwright-core"), + ); const jimpDir = writePackage("@jimp/plugin-blit"); fs.mkdirSync(path.join(jimpDir, "src", "__image_snapshots__"), { recursive: true }); fs.writeFileSync( @@ -794,6 +800,7 @@ describe("stageBundledPluginRuntimeDeps", () => { expect(fs.existsSync(path.join(pluginDir, "node_modules", "playwright-core", "index.js"))).toBe( true, ); + expect(fs.existsSync(path.join(pluginDir, "node_modules", ".bin"))).toBe(false); expect( fs.existsSync( path.join(pluginDir, "node_modules", "@jimp", "plugin-blit", "src", "__image_snapshots__"),