Skip to content

Commit

Permalink
fix: 19.8.0 broke ignoring folders
Browse files Browse the repository at this point in the history
Close #1741
  • Loading branch information
develar committed Jun 26, 2017
1 parent 9e77231 commit 50fe277
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/develar.xml

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

39 changes: 20 additions & 19 deletions packages/electron-builder/src/fileMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export class FileMatcher {
const parsedPattern = new Minimatch(pattern, minimatchOptions)
result.push(parsedPattern)

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

const relativeBuildResourceDir = path.relative(matcher.from, buildResourceDir)
const ignoreBuildResourceDirPattern = (relativeBuildResourceDir.length !== 0 && !relativeBuildResourceDir.startsWith(".")) ? `!${relativeBuildResourceDir}{,/**/*}` : null
const customFirstPatterns: Array<string> = []
if (matcher.isEmpty() || matcher.containsOnlyIgnore()) {
if (ignoreBuildResourceDirPattern != null) {
matcher.addPattern(ignoreBuildResourceDirPattern)
}
customFirstPatterns.push("**/*")
}
else {
if (ignoreBuildResourceDirPattern != null) {
customFirstPatterns.push(ignoreBuildResourceDirPattern)
}

// prependPattern - user pattern should be after to be able to override
customFirstPatterns.push("**/node_modules/**/*")
matcher.addPattern("package.json")
}

// https://github.com/electron-userland/electron-builder/issues/1482
const relativeBuildResourceDir = path.relative(matcher.from, buildResourceDir)
if (relativeBuildResourceDir.length !== 0 && !relativeBuildResourceDir.startsWith(".")) {
customFirstPatterns.push(`!${relativeBuildResourceDir}{,/**/*}`)
}

if (packager.platform !== Platform.WINDOWS) {
// https://github.com/electron-userland/electron-builder/issues/1738
customFirstPatterns.push("!**/node_modules/**/*.{dll,exe}")
}

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

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

matcher.addPattern("!**/node_modules/lzma-native/deps/xz-*")
matcher.addPattern("!**/node_modules/lzma-native/deps/doc{,/**/*}")

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

return matcher
}
Expand Down
6 changes: 6 additions & 0 deletions test/out/__snapshots__/ignoreTest.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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

exports[`ignore build resources 1`] = `
Object {
"linux": Array [],
Expand Down
23 changes: 23 additions & 0 deletions test/src/ignoreTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ test.ifDevOrLinuxCi("ignore build resources", app({
},
}))

test.ifDevOrLinuxCi("2 ignore", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
config: {
asar: false,
files: [
"**/*",
"!{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}",
"!*config*.json",
"!**/*.{ts,scss,map,md,csv,wrapped}",
"!**/*.{o,hprof,orig,pyc,pyo,rbc}",
"!**/._*",
"!**/{.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}"
],
}
}, {
projectDirCreated: projectDir => {
return outputFile(path.join(projectDir, "electron/foo.txt"), "data")
},
packed: context => {
return assertThat(path.join(context.getResources(Platform.LINUX), "app", "electron", "foo.txt")).doesNotExist()
},
}))

test.ifDevOrLinuxCi("ignore known ignored files", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
config: {
Expand Down

0 comments on commit 50fe277

Please sign in to comment.