From 152b9876dd105cc6eacbea7fda209acc0e9e77e4 Mon Sep 17 00:00:00 2001 From: develar Date: Fri, 1 Jul 2016 09:00:10 +0200 Subject: [PATCH] fix: Ignore .DS_Store Files Closes #545 --- .travis.yml | 2 +- src/platformPackager.ts | 12 ++++++++++-- src/util/filter.ts | 24 +++++++++++++++--------- test/src/globTest.ts | 2 ++ typings/minimatch.d.ts | 2 ++ 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4b00fd9a6b..75d7a1e5f9e 100755 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/src/platformPackager.ts b/src/platformPackager.ts index b718155f9e1..090d83f70f8 100644 --- a/src/platformPackager.ts +++ b/src/platformPackager.ts @@ -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") @@ -308,8 +308,16 @@ export abstract class PlatformPackager const minimatchOptions = {} const parsedPatterns: Array = [] 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 } diff --git a/src/util/filter.ts b/src/util/filter.ts index 4158d0aef25..37239167014 100644 --- a/src/util/filter.ts +++ b/src/util/filter.ts @@ -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, ignoreFiles?: Set, rawFilter?: (file: string) => boolean): (file: string) => boolean { return function filter(it) { if (src === it) { @@ -76,15 +91,6 @@ function minimatchAll(path: string, patterns: Array): 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 } \ No newline at end of file diff --git a/test/src/globTest.ts b/test/src/globTest.ts index 7acf7445a23..161bad97df8 100644 --- a/test/src/globTest.ts +++ b/test/src/globTest.ts @@ -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"), @@ -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", diff --git a/typings/minimatch.d.ts b/typings/minimatch.d.ts index 1bd2b31ddb7..1408c3ee03e 100644 --- a/typings/minimatch.d.ts +++ b/typings/minimatch.d.ts @@ -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 } }