Skip to content

Commit 50fe277

Browse files
committed
fix: 19.8.0 broke ignoring folders
Close #1741
1 parent 9e77231 commit 50fe277

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

.idea/dictionaries/develar.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/electron-builder/src/fileMatcher.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export class FileMatcher {
6262
const parsedPattern = new Minimatch(pattern, minimatchOptions)
6363
result.push(parsedPattern)
6464

65-
if (!hasMagic(parsedPattern)) {
65+
// do not add if contains dot (possibly file if has extension)
66+
if (!pattern.includes(".") && !hasMagic(parsedPattern)) {
6667
// https://github.com/electron-userland/electron-builder/issues/545
6768
// add **/*
6869
result.push(new Minimatch(`${pattern}/**/*`, minimatchOptions))
@@ -88,36 +89,38 @@ export function createFileMatcher(appDir: string, resourcesPath: string, macroEx
8889
const patterns = packager.info.isPrepackedAppAsar ? null : getFileMatchers(packager.info.config, "files", appDir, path.join(resourcesPath, "app"), false, macroExpander, platformSpecificBuildOptions)
8990
const matcher = patterns == null ? new FileMatcher(appDir, path.join(resourcesPath, "app"), macroExpander) : patterns[0]
9091

91-
const relativeBuildResourceDir = path.relative(matcher.from, buildResourceDir)
92-
const ignoreBuildResourceDirPattern = (relativeBuildResourceDir.length !== 0 && !relativeBuildResourceDir.startsWith(".")) ? `!${relativeBuildResourceDir}{,/**/*}` : null
9392
const customFirstPatterns: Array<string> = []
9493
if (matcher.isEmpty() || matcher.containsOnlyIgnore()) {
95-
if (ignoreBuildResourceDirPattern != null) {
96-
matcher.addPattern(ignoreBuildResourceDirPattern)
97-
}
9894
customFirstPatterns.push("**/*")
9995
}
10096
else {
101-
if (ignoreBuildResourceDirPattern != null) {
102-
customFirstPatterns.push(ignoreBuildResourceDirPattern)
103-
}
104-
10597
// prependPattern - user pattern should be after to be able to override
10698
customFirstPatterns.push("**/node_modules/**/*")
10799
matcher.addPattern("package.json")
108100
}
109101

102+
// https://github.com/electron-userland/electron-builder/issues/1482
103+
const relativeBuildResourceDir = path.relative(matcher.from, buildResourceDir)
104+
if (relativeBuildResourceDir.length !== 0 && !relativeBuildResourceDir.startsWith(".")) {
105+
customFirstPatterns.push(`!${relativeBuildResourceDir}{,/**/*}`)
106+
}
107+
110108
if (packager.platform !== Platform.WINDOWS) {
111109
// https://github.com/electron-userland/electron-builder/issues/1738
112110
customFirstPatterns.push("!**/node_modules/**/*.{dll,exe}")
113111
}
114112

115-
matcher.patterns.unshift(...customFirstPatterns)
113+
// add our default exclusions after user possibly defined "all" pattern
114+
const insertIndex = Math.max(0, matcher.patterns.findIndex(it => it == "**/*"))
115+
matcher.patterns.splice(insertIndex, 0, ...customFirstPatterns)
116116

117117
// https://github.com/electron-userland/electron-builder/issues/1738#issuecomment-310729208
118-
// must be before common ignore patterns (to ignore common ignores like .svn)
119-
matcher.addPattern("!**/node_modules/lzma-native/build/**/*")
120-
matcher.addPattern("**/node_modules/lzma-native/build/{Release,Debug}")
118+
// https://github.com/electron-userland/electron-builder/issues/1741#issuecomment-311111418 so, do not use inclusive pattern
119+
// matcher.addPattern("**/node_modules/lzma-native/build/{Release,Debug}")
120+
matcher.addPattern("!**/node_modules/lzma-native/build/*.{mk,gypi,Makefile}")
121+
matcher.addPattern("!**/node_modules/lzma-native/build/{Makefile,gyp-mac-tool}")
122+
matcher.addPattern("!**/node_modules/lzma-native/build/liblzma{,/**/*}")
123+
121124
matcher.addPattern("!**/node_modules/lzma-native/deps/xz-*")
122125
matcher.addPattern("!**/node_modules/lzma-native/deps/doc{,/**/*}")
123126

@@ -128,11 +131,9 @@ export function createFileMatcher(appDir: string, resourcesPath: string, macroEx
128131
//noinspection SpellCheckingInspection
129132
matcher.addPattern("!**/{.git,.hg,.svn,CVS,RCS,SCCS," +
130133
"__pycache__,.DS_Store,thumbs.db,.gitignore,.gitattributes," +
131-
".editorconfig,.flowconfig,.jshintrc,.eslintrc," +
132-
".yarn-integrity,.yarn-metadata.json,yarn-error.log,yarn.lock,npm-debug.log," +
133-
".idea,.vs," +
134-
"appveyor.yml,.travis.yml,circle.yml," +
135-
".nyc_output}")
134+
".idea,.vs,.editorconfig,.flowconfig,.jshintrc,.eslintrc," +
135+
".yarn-integrity,.yarn-metadata.json,yarn-error.log,yarn.lock,package-lock.json,npm-debug.log," +
136+
"appveyor.yml,.travis.yml,circle.yml,.nyc_output}")
136137

137138
return matcher
138139
}

test/out/__snapshots__/ignoreTest.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`2 ignore 1`] = `
4+
Object {
5+
"linux": Array [],
6+
}
7+
`;
8+
39
exports[`ignore build resources 1`] = `
410
Object {
511
"linux": Array [],

test/src/ignoreTest.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ test.ifDevOrLinuxCi("ignore build resources", app({
1919
},
2020
}))
2121

22+
test.ifDevOrLinuxCi("2 ignore", app({
23+
targets: Platform.LINUX.createTarget(DIR_TARGET),
24+
config: {
25+
asar: false,
26+
files: [
27+
"**/*",
28+
"!{app,build,electron,mobile,theme,uploads,util,dist,dist-app/aot,dist-app/app.bundle.js,dist-app/dependencies/shim.min.js,dist-app/dependencies/classList.min.js,dist-app/dependencies/web-animations.min.js,main.js,main-aot.js,favicon.ico,index.html,index-aot.html,index-cordova.html,index-aot.js,index-electron.js,index.bundle.js,systemjs.config.js,systemjs-angular-loader.js,package-lock.json}",
29+
"!*config*.json",
30+
"!**/*.{ts,scss,map,md,csv,wrapped}",
31+
"!**/*.{o,hprof,orig,pyc,pyo,rbc}",
32+
"!**/._*",
33+
"!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.editorconfig,.flowconfig,.yarn-metadata.json,.idea,appveyor.yml,.travis.yml,circle.yml,npm-debug.log,.nyc_output,yarn.lock,.yarn-integrity}"
34+
],
35+
}
36+
}, {
37+
projectDirCreated: projectDir => {
38+
return outputFile(path.join(projectDir, "electron/foo.txt"), "data")
39+
},
40+
packed: context => {
41+
return assertThat(path.join(context.getResources(Platform.LINUX), "app", "electron", "foo.txt")).doesNotExist()
42+
},
43+
}))
44+
2245
test.ifDevOrLinuxCi("ignore known ignored files", app({
2346
targets: Platform.LINUX.createTarget(DIR_TARGET),
2447
config: {

0 commit comments

Comments
 (0)