Skip to content

Commit 152b987

Browse files
committed
fix: Ignore .DS_Store Files
Closes #545
1 parent bf2aafb commit 152b987

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ before_install:
2121
- chmod +x /tmp/7za
2222
- curl -L https://dl.bintray.com/develar/bin/wine.7z > /tmp/wine.7z
2323
- /tmp/7za x -o/usr/local/Cellar -y /tmp/wine.7z
24-
- 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
24+
- 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
2525
- git-lfs pull
2626

2727
install:

src/platformPackager.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { checkFileInPackage, createAsarArchive } from "./asarUtil"
1313
import deepAssign = require("deep-assign")
1414
import { warn, log, task } from "./util/log"
1515
import { AppInfo } from "./appInfo"
16-
import { listDependencies, createFilter, copyFiltered } from "./util/filter"
16+
import { listDependencies, createFilter, copyFiltered, hasMagic } from "./util/filter"
1717

1818
//noinspection JSUnusedLocalSymbols
1919
const __awaiter = require("./util/awaiter")
@@ -308,8 +308,16 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
308308
const minimatchOptions = {}
309309
const parsedPatterns: Array<Minimatch> = []
310310
for (let i = 0; i < patterns.length; i++) {
311-
parsedPatterns[i] = new Minimatch(this.expandPattern(patterns[i], arch), minimatchOptions)
311+
const pattern = this.expandPattern(patterns[i], arch)
312+
const parsedPattern = new Minimatch(pattern, minimatchOptions)
313+
parsedPatterns.push(parsedPattern)
314+
if (!hasMagic(parsedPattern)) {
315+
// https://github.com/electron-userland/electron-builder/issues/545
316+
// add **/*
317+
parsedPatterns.push(new Minimatch(`${pattern}/*/**`, minimatchOptions))
318+
}
312319
}
320+
313321
return parsedPatterns
314322
}
315323

src/util/filter.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ export function copyFiltered(src: string, destination: string, filter: (file: st
1414
})
1515
}
1616

17+
export function hasMagic(pattern: Minimatch) {
18+
const set = pattern.set
19+
if (set.length > 1) {
20+
return true
21+
}
22+
23+
for (let i of set[0]) {
24+
if (typeof i !== 'string') {
25+
return true
26+
}
27+
}
28+
29+
return false
30+
}
31+
1732
export function createFilter(src: string, patterns: Array<Minimatch>, ignoreFiles?: Set<string>, rawFilter?: (file: string) => boolean): (file: string) => boolean {
1833
return function filter(it) {
1934
if (src === it) {
@@ -76,15 +91,6 @@ function minimatchAll(path: string, patterns: Array<Minimatch>): boolean {
7691
// partial match — pattern: foo/bar.txt path: foo — we must allow foo
7792
// 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
7893
match = pattern.match(path, !pattern.negate)
79-
if (!match && !pattern.negate) {
80-
const rawPattern = pattern.pattern
81-
// 1 - slash
82-
const patternLengthPlusSlash = rawPattern.length + 1
83-
if (path.length > patternLengthPlusSlash) {
84-
// foo: include all directory content
85-
match = path[rawPattern.length] === "/" && path.startsWith(rawPattern)
86-
}
87-
}
8894
}
8995
return match
9096
}

test/src/globTest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ test("extraResources", async () => {
115115
}),
116116
outputFile(path.join(projectDir, "foo/nameWithoutDot"), "nameWithoutDot"),
117117
outputFile(path.join(projectDir, "bar/hello.txt"), "data"),
118+
outputFile(path.join(projectDir, "foo", ".dot"), "data"),
118119
outputFile(path.join(projectDir, `bar/${process.arch}.txt`), "data"),
119120
outputFile(path.join(projectDir, `${osName}/${process.arch}.txt`), "data"),
120121
outputFile(path.join(projectDir, "platformSpecificR"), "platformSpecificR"),
@@ -137,6 +138,7 @@ test("extraResources", async () => {
137138
await assertThat(path.join(resourcesDir, osName, `${process.arch}.txt`)).isFile()
138139
await assertThat(path.join(resourcesDir, "platformSpecificR")).isFile()
139140
await assertThat(path.join(resourcesDir, "ignoreMe.txt")).doesNotExist()
141+
await assertThat(path.join(resourcesDir, "foo", ".dot")).doesNotExist()
140142
},
141143
expectedContents: platform === Platform.WINDOWS ? pathSorter(expectedWinContents.concat(
142144
winDirPrefix + "bar/hello.txt",

typings/minimatch.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ namespace minimatch {
101101
* 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.
102102
*/
103103
matchOne (fileArray: string[], patternArray: string[], partial: boolean): boolean;
104+
105+
set: any
104106
}
105107
}
106108

0 commit comments

Comments
 (0)