diff --git a/packages/electron-builder-util/src/fs.ts b/packages/electron-builder-util/src/fs.ts index 50a72960f00..b470f9d6af9 100644 --- a/packages/electron-builder-util/src/fs.ts +++ b/packages/electron-builder-util/src/fs.ts @@ -41,7 +41,7 @@ export async function exists(file: string): Promise { } } -export async function walk(initialDirPath: string, filter?: Filter | null, consumer?: (file: string, stat: Stats, parent: string, extraIgnoredFiles: Set) => any): Promise> { +export async function walk(initialDirPath: string, filter?: Filter | null, consumer?: (file: string, stat: Stats, parent: string, extraIgnoredFiles: Set, siblingNames: Array) => any): Promise> { const result: Array = [] const queue: Array = [initialDirPath] let addDirToResult = false @@ -68,7 +68,7 @@ export async function walk(initialDirPath: string, filter?: Filter | null, consu return null } - const consumerResult = consumer == null ? null : consumer(filePath, stat, dirPath, extraIgnoredFiles) + const consumerResult = consumer == null ? null : consumer(filePath, stat, dirPath, extraIgnoredFiles, childNames) if (consumerResult == null || !("then" in consumerResult)) { if (stat.isDirectory()) { dirs.push(name) diff --git a/packages/electron-builder/src/asarUtil.ts b/packages/electron-builder/src/asarUtil.ts index 612daff447b..3d2ca38f483 100644 --- a/packages/electron-builder/src/asarUtil.ts +++ b/packages/electron-builder/src/asarUtil.ts @@ -59,12 +59,12 @@ export class AsarPackager { async pack(filter: Filter, isElectronCompile: boolean) { const metadata = this.metadata const nodeModulesSystemDependentSuffix = `${path.sep}node_modules` - let files = await walk(this.src, filter, (file, fileStat, parent, extraIgnoredFiles) => { + let files = await walk(this.src, filter, (file, fileStat, parent, extraIgnoredFiles, siblingNames) => { metadata.set(file, fileStat) // https://github.com/electron-userland/electron-builder/issues/1539 // but do not filter if we inside node_modules dir - if (fileStat.isDirectory() && file.endsWith(nodeModulesSystemDependentSuffix) && !parent.includes("node_modules")) { + if (fileStat.isDirectory() && file.endsWith(nodeModulesSystemDependentSuffix) && !parent.includes("node_modules") && siblingNames.includes("package.json")) { return dependencies(parent, extraIgnoredFiles) .then(it => { if (debug.enabled) {