diff --git a/packages/electron-builder/src/asarUtil.ts b/packages/electron-builder/src/asarUtil.ts index 0a7f74be83c..e356922004a 100644 --- a/packages/electron-builder/src/asarUtil.ts +++ b/packages/electron-builder/src/asarUtil.ts @@ -143,21 +143,25 @@ export class AsarPackager { continue } - const nextSlashIndex = file.indexOf(path.sep, index + NODE_MODULES_PATTERN.length + 1) + let nextSlashIndex = file.indexOf(path.sep, index + NODE_MODULES_PATTERN.length + 1) if (nextSlashIndex < 0) { continue } + if (file[index + NODE_MODULES_PATTERN.length] === "@") { + nextSlashIndex = file.indexOf(path.sep, nextSlashIndex + 1) + } + if (!metadata.get(file)!.isFile()) { continue } - const nodeModuleDir = file.substring(0, nextSlashIndex) - if (autoUnpackDirs.has(nodeModuleDir)) { + const packageDir = file.substring(0, nextSlashIndex) + if (autoUnpackDirs.has(packageDir)) { const fileParent = path.dirname(file) - if (fileParent !== nodeModuleDir && !autoUnpackDirs.has(fileParent)) { + if (fileParent !== packageDir && !autoUnpackDirs.has(fileParent)) { autoUnpackDirs.add(fileParent) - addValue(dirToCreate, path.relative(this.src, nodeModuleDir), path.relative(nodeModuleDir, fileParent)) + addValue(dirToCreate, path.relative(this.src, packageDir), path.relative(packageDir, fileParent)) } continue } @@ -175,18 +179,18 @@ export class AsarPackager { continue } - debug(`${path.relative(this.src, nodeModuleDir)} is not packed into asar archive - contains executable code`) + debug(`${path.relative(this.src, packageDir)} is not packed into asar archive - contains executable code`) let fileParent = path.dirname(file) // create parent dir to be able to copy file later without directory existence check - addValue(dirToCreate, path.relative(this.src, nodeModuleDir), path.relative(nodeModuleDir, fileParent)) + addValue(dirToCreate, path.relative(this.src, packageDir), path.relative(packageDir, fileParent)) - while (fileParent !== nodeModuleDir) { + while (fileParent !== packageDir) { autoUnpackDirs.add(fileParent) fileParent = path.dirname(fileParent) } - autoUnpackDirs.add(nodeModuleDir) + autoUnpackDirs.add(packageDir) } if (dirToCreate.size > 0) { diff --git a/test/out/__snapshots__/BuildTest.js.snap b/test/out/__snapshots__/BuildTest.js.snap index 754124f87ac..66ba5ec6e9a 100644 --- a/test/out/__snapshots__/BuildTest.js.snap +++ b/test/out/__snapshots__/BuildTest.js.snap @@ -272,6 +272,44 @@ Object { } `; +exports[`smart unpack 2`] = ` +Array [ + "app.asar", + "electron.asar", + "app.asar.unpacked", + "app.asar.unpacked/node_modules", + "app.asar.unpacked/node_modules/edge-cs", + "app.asar.unpacked/node_modules/edge-cs/LICENSE.txt", + "app.asar.unpacked/node_modules/edge-cs/package.json", + "app.asar.unpacked/node_modules/edge-cs/tools", + "app.asar.unpacked/node_modules/edge-cs/tools/install.js", + "app.asar.unpacked/node_modules/edge-cs/src", + "app.asar.unpacked/node_modules/edge-cs/src/edge-cs", + "app.asar.unpacked/node_modules/edge-cs/src/edge-cs/EdgeCompiler.cs", + "app.asar.unpacked/node_modules/edge-cs/src/edge-cs/edge-cs.csproj", + "app.asar.unpacked/node_modules/edge-cs/src/edge-cs/edge-cs.sln", + "app.asar.unpacked/node_modules/edge-cs/src/edge-cs/Properties", + "app.asar.unpacked/node_modules/edge-cs/src/edge-cs/Properties/AssemblyInfo.cs", + "app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp", + "app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/EdgeCompiler.cs", + "app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/edge-cs-coreclr.sln", + "app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/edge-cs-coreclr.xproj", + "app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/gulpfile.js", + "app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/package.json", + "app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/project.json", + "app.asar.unpacked/node_modules/edge-cs/lib", + "app.asar.unpacked/node_modules/edge-cs/lib/edge-cs.dll", + "app.asar.unpacked/node_modules/edge-cs/lib/edge-cs.js", + "app.asar.unpacked/node_modules/edge-cs/lib/bootstrap", + "app.asar.unpacked/node_modules/edge-cs/lib/bootstrap/Dummy.cs", + "app.asar.unpacked/node_modules/edge-cs/lib/bootstrap/project.json", + "app.asar.unpacked/node_modules/@electron-builder", + "app.asar.unpacked/node_modules/@electron-builder/test-smart-unpack", + "app.asar.unpacked/node_modules/@electron-builder/test-smart-unpack/foo.dll", + "app.asar.unpacked/node_modules/@electron-builder/test-smart-unpack/package.json", +] +`; + exports[`www as default dir 1`] = ` Object { "linux": Array [], diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index fd9a724391a..f7b3a56eeec 100644 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -1,5 +1,6 @@ import BluebirdPromise from "bluebird-lst" import { Arch, BuildOptions, createTargets, DIR_TARGET, Platform } from "electron-builder" +import { walk } from "electron-builder-util/out/fs" import { readAsarJson } from "electron-builder/out/asar" import { normalizeOptions } from "electron-builder/out/builder" import { createYargs } from "electron-builder/out/cli/cliOptions" @@ -156,13 +157,18 @@ test.ifDevOrLinuxCi("smart unpack", app({ projectDirCreated: packageJson(it => { it.dependencies = { "debug": "^2.2.0", - "edge-cs": "^1.0.0" + "edge-cs": "1.2.1", + "@electron-builder/test-smart-unpack": "1.0.0", + "@electron-builder/test-smart-unpack-empty": "1.0.0", } }), packed: async context => { - expect(await readAsarJson(path.join(context.getResources(Platform.LINUX), "app.asar"), "node_modules/debug/package.json")).toMatchObject({ + const resourceDir = context.getResources(Platform.LINUX) + expect(await readAsarJson(path.join(resourceDir, "app.asar"), "node_modules/debug/package.json")).toMatchObject({ name: "debug" }) + + expect((await walk(resourceDir, file => !path.basename(file).startsWith("."))).map(it => it.substring(resourceDir.length + 1))).toMatchSnapshot() } }))