Skip to content

Commit

Permalink
fix: respect ignore patterns for node modules if defined as file set …
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Nov 1, 2018
1 parent 91e6cc0 commit f52ce37
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 50 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/app-builder-lib/src/asar/unpackDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export async function detectUnpackedDirs(fileSet: ResolvedFileSet, autoUnpackDir

// https://github.com/electron-userland/electron-builder/issues/2679
let shouldUnpack = false
if (isLibOrExe(file)) {
// ffprobe-static and ffmpeg-static are known packages to always unpack
const moduleName = path.basename(packageDir)
if (moduleName === "ffprobe-static" || moduleName === "ffmpeg-static" || isLibOrExe(file)) {
shouldUnpack = true
}
else if (!file.includes(".", nextSlashIndex) && path.extname(file) === "") {
Expand Down
14 changes: 12 additions & 2 deletions packages/app-builder-lib/src/fileMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,18 @@ export function getNodeModuleFileMatcher(appDir: string, destination: string, ma
}

for (const pattern of patterns) {
if (typeof pattern === "string" && pattern.startsWith("!")) {
matcher.addPattern(pattern)
if (typeof pattern === "string") {
if (pattern.startsWith("!")) {
matcher.addPattern(pattern)
}
}
else {
const fileSet = (pattern as FileSet)
if (fileSet.from == null || fileSet.from === ".") {
for (const p of asArray(fileSet.filter)) {
matcher.addPattern(p)
}
}
}
}
}
Expand Down
10 changes: 1 addition & 9 deletions packages/app-builder-lib/src/util/NodeModuleCopyHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { resolveFunction } from "../platformPackager"
import { FileCopyHelper } from "./AppFileWalker"

const excludedFiles = new Set([".DS_Store", "node_modules" /* already in the queue */, "CHANGELOG.md", "ChangeLog", "changelog.md", "binding.gyp", ".npmignore"].concat(excludedNames.split(",")))
const topLevelExcludedFiles = new Set(["test.js", "karma.conf.js", ".coveralls.yml", "README.md", "readme.markdown", "README", "readme.md", "readme", "test", "__tests__", "tests", "powered-test", "example", "examples"])
const topLevelExcludedFiles = new Set(["test.js", "karma.conf.js", ".coveralls.yml", "README.md", "readme.markdown", "README", "readme.md", "readme", "test", "__tests__", "tests", "powered-test", "example", "examples", ".bin"])

/** @internal */
export class NodeModuleCopyHelper extends FileCopyHelper {
Expand All @@ -31,14 +31,6 @@ export class NodeModuleCopyHelper extends FileCopyHelper {
const depPath = path.normalize(tmpPath)
queue[0] = depPath

// if (dep.link != null) {
// this.metadata.set(dep.path, dep.stat!)
// const r = this.handleSymlink(dep.stat!, dep.path, dep.link!)
// if (r != null) {
// await r
// }
// }

while (queue.length > 0) {
const dirPath = queue.pop()!

Expand Down
3 changes: 2 additions & 1 deletion packages/app-builder-lib/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export async function getConfig(projectDir: string, configPath: string | null, c

// electron-webpack and electrify client config - want to exclude some files
// we add client files configuration to main parent file matcher
if (parentConfig.files != null && config.files != null && (Array.isArray(config.files) || typeof config.files === "string") && Array.isArray(parentConfig.files) && parentConfig.files.length > 0) {
const files = config.files == null ? [] : (Array.isArray(config.files) ? config.files : (typeof config.files === "string" ? [config.files] : []))
if (parentConfig.files != null && files.length !== 0 && Array.isArray(parentConfig.files) && parentConfig.files.length > 0) {
const mainFileSet = parentConfig.files[0]
if (typeof mainFileSet === "object" && (mainFileSet.from == null || mainFileSet.from === ".")) {
mainFileSet.filter = asArray(mainFileSet.filter)
Expand Down
35 changes: 0 additions & 35 deletions test/out/__snapshots__/BuildTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,6 @@ Object {
},
"detect-libc": Object {
"files": Object {
".bin": Object {
"files": Object {
"detect-libc": Object {
"link": "node_modules/detect-libc/bin/detect-libc.js",
},
},
},
"LICENSE": Object {
"size": 11357,
},
Expand Down Expand Up @@ -880,13 +873,6 @@ Object {
},
"mkdirp": Object {
"files": Object {
".bin": Object {
"files": Object {
"mkdirp": Object {
"link": "node_modules/mkdirp/bin/cmd.js",
},
},
},
"LICENSE": Object {
"size": 1141,
},
Expand Down Expand Up @@ -1206,13 +1192,6 @@ Object {
},
"prebuild-install": Object {
"files": Object {
".bin": Object {
"files": Object {
"prebuild-install": Object {
"link": "node_modules/prebuild-install/bin.js",
},
},
},
"CONTRIBUTING.md": Object {
"size": 220,
},
Expand Down Expand Up @@ -1289,13 +1268,6 @@ Object {
},
"rc": Object {
"files": Object {
".bin": Object {
"files": Object {
"rc": Object {
"link": "node_modules/rc/cli.js",
},
},
},
"LICENSE.APACHE2": Object {
"size": 586,
},
Expand Down Expand Up @@ -1433,13 +1405,6 @@ Object {
},
"semver": Object {
"files": Object {
".bin": Object {
"files": Object {
"semver": Object {
"link": "node_modules/semver/bin/semver",
},
},
},
"LICENSE": Object {
"size": 765,
},
Expand Down
33 changes: 33 additions & 0 deletions test/out/__snapshots__/globTest.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`asarUnpack and files ignore 1`] = `
Object {
"linux": Array [],
}
`;

exports[`asarUnpack and files ignore 2`] = `
Object {
"files": Object {
"index.html": Object {
"offset": "0",
"size": 378,
},
"index.js": Object {
"offset": "378",
"size": 619,
},
"package.json": Object {
"offset": "997",
"size": 224,
},
"path": Object {
"files": Object {
"app.asar": Object {
"offset": "1221",
"size": 714,
},
},
},
},
}
`;

exports[`failed peer dep 1`] = `
Object {
"linux": Array [],
Expand Down
5 changes: 4 additions & 1 deletion test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ test.ifAll.ifDevOrLinuxCi("posix smart unpack", app({
copyright: "Copyright © 2018 ${author}",
npmRebuild: true,
files: [
"!node_modules/napi-build-utils/napi-build-utils-1.0.0.tgz"
// test ignore pattern for node_modules defined as file set filter
{
filter: "!node_modules/napi-build-utils/napi-build-utils-1.0.0.tgz",
}
]
}
}, {
Expand Down
27 changes: 26 additions & 1 deletion test/src/globTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ async function createFiles(appDir: string) {
test.ifDevOrLinuxCi("unpackDir one", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
config: {
asarUnpack: ["assets", "b2", "do-not-unpack-dir/file.json"],
asarUnpack: [
"assets",
"b2",
"do-not-unpack-dir/file.json",
],
}
}, {
projectDirCreated: createFiles,
Expand Down Expand Up @@ -55,6 +59,27 @@ test.ifDevOrLinuxCi("unpackDir", () => {
})
})

test.ifDevOrLinuxCi("asarUnpack and files ignore", () => {
return assertPack("test-app", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
config: {
asarUnpack: [
"!**/ffprobe-static/bin/darwin/x64/ffprobe"
],
}
}, {
projectDirCreated: projectDir => outputFile(path.join(projectDir, "node_modules/ffprobe-static/bin/darwin/x64/ffprobe"), "data"),
packed: async context => {
const resourceDir = context.getResources(Platform.LINUX)
await Promise.all([
assertThat(path.join(resourceDir, "app.asar.unpacked", "node_modules/ffprobe-static/bin/darwin/x64/ffprobe")).doesNotExist(),
])

await verifyAsarFileTree(context.getResources(Platform.LINUX))
},
})
})

test.ifNotWindows("link", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
}, {
Expand Down

0 comments on commit f52ce37

Please sign in to comment.