Skip to content

Commit

Permalink
fix: Ignore .DS_Store Files
Browse files Browse the repository at this point in the history
Closes #545
  • Loading branch information
develar committed Jul 1, 2016
1 parent bf2aafb commit 152b987
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_install:
- chmod +x /tmp/7za
- curl -L https://dl.bintray.com/develar/bin/wine.7z > /tmp/wine.7z
- /tmp/7za x -o/usr/local/Cellar -y /tmp/wine.7z
- brew link fontconfig freetype gd gnutls jasper libgphoto2 libicns libtasn1 libusb libusb-compat little-cms2 nettle openssl sane-backends webp wine git-lfs gnu-tar dpkg graphicsmagick
- brew link fontconfig freetype gd gnutls jasper libgphoto2 libicns libtasn1 libusb libusb-compat little-cms2 nettle openssl sane-backends webp wine git-lfs gnu-tar dpkg graphicsmagick xz
- git-lfs pull

install:
Expand Down
12 changes: 10 additions & 2 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { checkFileInPackage, createAsarArchive } from "./asarUtil"
import deepAssign = require("deep-assign")
import { warn, log, task } from "./util/log"
import { AppInfo } from "./appInfo"
import { listDependencies, createFilter, copyFiltered } from "./util/filter"
import { listDependencies, createFilter, copyFiltered, hasMagic } from "./util/filter"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./util/awaiter")
Expand Down Expand Up @@ -308,8 +308,16 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
const minimatchOptions = {}
const parsedPatterns: Array<Minimatch> = []
for (let i = 0; i < patterns.length; i++) {
parsedPatterns[i] = new Minimatch(this.expandPattern(patterns[i], arch), minimatchOptions)
const pattern = this.expandPattern(patterns[i], arch)
const parsedPattern = new Minimatch(pattern, minimatchOptions)
parsedPatterns.push(parsedPattern)
if (!hasMagic(parsedPattern)) {
// https://github.com/electron-userland/electron-builder/issues/545
// add **/*
parsedPatterns.push(new Minimatch(`${pattern}/*/**`, minimatchOptions))
}
}

return parsedPatterns
}

Expand Down
24 changes: 15 additions & 9 deletions src/util/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ export function copyFiltered(src: string, destination: string, filter: (file: st
})
}

export function hasMagic(pattern: Minimatch) {
const set = pattern.set
if (set.length > 1) {
return true
}

for (let i of set[0]) {
if (typeof i !== 'string') {
return true
}
}

return false
}

export function createFilter(src: string, patterns: Array<Minimatch>, ignoreFiles?: Set<string>, rawFilter?: (file: string) => boolean): (file: string) => boolean {
return function filter(it) {
if (src === it) {
Expand Down Expand Up @@ -76,15 +91,6 @@ function minimatchAll(path: string, patterns: Array<Minimatch>): boolean {
// partial match — pattern: foo/bar.txt path: foo — we must allow foo
// use it only for non-negate patterns: const m = new Minimatch("!node_modules/@(electron-download|electron-prebuilt)/**/*", {dot: true }); m.match("node_modules", true) will return false, but must be true
match = pattern.match(path, !pattern.negate)
if (!match && !pattern.negate) {
const rawPattern = pattern.pattern
// 1 - slash
const patternLengthPlusSlash = rawPattern.length + 1
if (path.length > patternLengthPlusSlash) {
// foo: include all directory content
match = path[rawPattern.length] === "/" && path.startsWith(rawPattern)
}
}
}
return match
}
2 changes: 2 additions & 0 deletions test/src/globTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ test("extraResources", async () => {
}),
outputFile(path.join(projectDir, "foo/nameWithoutDot"), "nameWithoutDot"),
outputFile(path.join(projectDir, "bar/hello.txt"), "data"),
outputFile(path.join(projectDir, "foo", ".dot"), "data"),
outputFile(path.join(projectDir, `bar/${process.arch}.txt`), "data"),
outputFile(path.join(projectDir, `${osName}/${process.arch}.txt`), "data"),
outputFile(path.join(projectDir, "platformSpecificR"), "platformSpecificR"),
Expand All @@ -137,6 +138,7 @@ test("extraResources", async () => {
await assertThat(path.join(resourcesDir, osName, `${process.arch}.txt`)).isFile()
await assertThat(path.join(resourcesDir, "platformSpecificR")).isFile()
await assertThat(path.join(resourcesDir, "ignoreMe.txt")).doesNotExist()
await assertThat(path.join(resourcesDir, "foo", ".dot")).doesNotExist()
},
expectedContents: platform === Platform.WINDOWS ? pathSorter(expectedWinContents.concat(
winDirPrefix + "bar/hello.txt",
Expand Down
2 changes: 2 additions & 0 deletions typings/minimatch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ namespace minimatch {
* Take a `/-`split filename, and match it against a single row in the `regExpSet`. This method is mainly for internal use, but is exposed so that it can be used by a glob-walker that needs to avoid excessive filesystem calls.
*/
matchOne (fileArray: string[], patternArray: string[], partial: boolean): boolean;

set: any
}
}

Expand Down

0 comments on commit 152b987

Please sign in to comment.