Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions scripts/stage-bundled-plugin-runtime-deps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -526,6 +549,7 @@ function listInstalledDependencyNames(nodeModulesDir) {
}

function pruneStagedRuntimeDependencyCargo(nodeModulesDir, pruneConfig) {
pruneNodeModulesBinDirectories(nodeModulesDir);
for (const depName of listInstalledDependencyNames(nodeModulesDir)) {
pruneStagedInstalledDependencyCargo(nodeModulesDir, depName, pruneConfig);
}
Expand Down
7 changes: 7 additions & 0 deletions test/scripts/stage-bundled-plugin-runtime-deps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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__"),
Expand Down
Loading