Skip to content

Commit 7f00714

Browse files
committed
fix: Cannot copy files from parent directory of build output
Close #1482
1 parent 5a163df commit 7f00714

File tree

10 files changed

+137
-42
lines changed

10 files changed

+137
-42
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"///": "all dependencies for all packages (hoisted)",
2929
"dependencies": {
3030
"7zip-bin": "^2.0.4",
31-
"ajv": "^5.0.4-beta.2",
32-
"ajv-keywords": "^2.0.1-beta.2",
31+
"ajv": "^5.0.0",
32+
"ajv-keywords": "^2.0.0",
3333
"archiver": "^1.3.0",
3434
"aws-sdk": "^2.45.0",
3535
"bluebird-lst": "^1.0.2",

packages/electron-builder/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
"homepage": "https://github.com/electron-userland/electron-builder",
4646
"dependencies": {
4747
"7zip-bin": "^2.0.4",
48-
"ajv": "^5.0.4-beta.2",
49-
"ajv-keywords": "^2.0.1-beta.2",
48+
"ajv": "^5.0.0",
49+
"ajv-keywords": "^2.0.0",
5050
"bluebird-lst": "^1.0.2",
5151
"chalk": "^1.1.3",
5252
"chromium-pickle-js": "^0.2.0",

packages/electron-builder/src/fileMatcher.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@ export class FileMatcher {
1414
readonly from: string
1515
readonly to: string
1616

17-
readonly patterns: Array<string>
17+
private readonly patterns: Array<string>
1818

1919
constructor(from: string, to: string, private readonly macroExpander: (pattern: string) => string, patterns?: Array<string> | string | n) {
2020
this.from = macroExpander(from)
2121
this.to = macroExpander(to)
22-
this.patterns = asArray(patterns).map(it => path.posix.normalize(macroExpander(it)))
22+
this.patterns = asArray(patterns).map(it => this.normalizePattern(it))
23+
}
24+
25+
private normalizePattern(pattern: string) {
26+
return path.posix.normalize(this.macroExpander(pattern))
2327
}
2428

2529
addPattern(pattern: string) {
26-
this.patterns.push(path.posix.normalize(this.macroExpander(pattern)))
30+
this.patterns.push(this.normalizePattern(pattern))
31+
}
32+
33+
prependPattern(pattern: string) {
34+
this.patterns.unshift(this.normalizePattern(pattern))
2735
}
2836

2937
addAllPattern() {
@@ -74,13 +82,23 @@ export class FileMatcher {
7482
}
7583
}
7684

77-
export function createFileMatcher(info: BuildInfo, appDir: string, resourcesPath: string, macroExpander: (pattern: string) => string, platformSpecificBuildOptions: PlatformSpecificBuildOptions) {
85+
export function createFileMatcher(info: BuildInfo, appDir: string, resourcesPath: string, macroExpander: (pattern: string) => string, platformSpecificBuildOptions: PlatformSpecificBuildOptions, buildResourceDir: string) {
7886
const patterns = info.isPrepackedAppAsar ? null : getFileMatchers(info.config, "files", appDir, path.join(resourcesPath, "app"), false, macroExpander, platformSpecificBuildOptions)
7987
const matcher = patterns == null ? new FileMatcher(appDir, path.join(resourcesPath, "app"), macroExpander) : patterns[0]
88+
89+
const relativeBuildResourceDir = path.relative(matcher.from, buildResourceDir)
90+
const ignoreBuildResourceDirPattern = (relativeBuildResourceDir.length !== 0 && !relativeBuildResourceDir.startsWith(".")) ? `!${relativeBuildResourceDir}{,/**/*}` : null
91+
8092
if (matcher.isEmpty() || matcher.containsOnlyIgnore()) {
8193
matcher.addAllPattern()
94+
if (ignoreBuildResourceDirPattern != null) {
95+
matcher.addPattern(ignoreBuildResourceDirPattern)
96+
}
8297
}
8398
else {
99+
if (ignoreBuildResourceDirPattern != null) {
100+
matcher.prependPattern(ignoreBuildResourceDirPattern)
101+
}
84102
matcher.addPattern("package.json")
85103
}
86104
matcher.addPattern("!**/node_modules/*/{CHANGELOG.md,ChangeLog,changelog.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}")

packages/electron-builder/src/platformPackager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
142142

143143
const appDir = this.info.appDir
144144
const ignoreFiles = new Set([path.resolve(this.info.projectDir, outDir),
145-
path.resolve(this.info.projectDir, this.buildResourcesDir),
146145
path.resolve(this.info.projectDir, "electron-builder.yml"),
147146
path.resolve(this.info.projectDir, "electron-builder.json"),
148147
path.resolve(this.info.projectDir, "electron-builder.json5")])
@@ -175,7 +174,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
175174
}
176175
}
177176

178-
const defaultMatcher = createFileMatcher(this.info, appDir, resourcesPath, macroExpander, platformSpecificBuildOptions)
177+
const defaultMatcher = createFileMatcher(this.info, appDir, resourcesPath, macroExpander, platformSpecificBuildOptions, path.resolve(this.info.projectDir, this.buildResourcesDir))
179178
const isElectronCompile = asarOptions != null && isElectronCompileUsed(this.info)
180179
if (isElectronCompile) {
181180
defaultMatcher.addPattern("!.cache{,/**/*}")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Hello World!</title>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
We are using node <script>document.write(process.versions.node)</script>,
10+
Chrome <script>document.write(process.versions.chrome)</script>,
11+
and Electron <script>document.write(process.versions.electron)</script>.
12+
</body>
13+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use strict"
2+
3+
const electron = require('electron')
4+
const app = electron.app
5+
const BrowserWindow = electron.BrowserWindow
6+
7+
let mainWindow
8+
9+
function createWindow () {
10+
mainWindow = new BrowserWindow({width: 800, height: 600})
11+
mainWindow.loadURL('file://' + __dirname + '/index.html')
12+
13+
mainWindow.webContents.openDevTools()
14+
15+
mainWindow.on('closed', function() {
16+
mainWindow = null
17+
});
18+
}
19+
20+
app.on('ready', createWindow)
21+
22+
app.on('window-all-closed', function () {
23+
if (process.platform !== 'darwin') {
24+
app.quit()
25+
}
26+
})
27+
28+
app.on('activate', function () {
29+
if (mainWindow === null) {
30+
createWindow()
31+
}
32+
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version": "1.0.0",
3+
"main": "./build/app/main.js",
4+
"author": "true",
5+
"name": "Foo",
6+
"build": {
7+
"electronVersion": "1.6.6",
8+
"appId": "org.electron-builder.testApp",
9+
"compression": "store",
10+
"npmRebuild": false,
11+
"mac": {
12+
"category": "your.app.category.type"
13+
},
14+
"directories": {
15+
"output": "build/dist"
16+
},
17+
"files": [
18+
"build/app/**/*.js",
19+
"build/app/**/*.html"
20+
],
21+
"asar": false
22+
}
23+
}

test/out/__snapshots__/ExtraBuildTest.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Object {
2929
}
3030
`;
3131

32+
exports[`do not exclude build entirely (respect files) 1`] = `
33+
Object {
34+
"linux": Array [],
35+
}
36+
`;
37+
3238
exports[`override targets in the config - only arch 1`] = `
3339
Object {
3440
"win": Array [

test/src/ExtraBuildTest.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { move, readFile } from "fs-extra-p"
44
import { safeLoad } from "js-yaml"
55
import * as path from "path"
66
import { assertThat } from "./helpers/fileAssert"
7-
import { app, appThrows } from "./helpers/packTester"
7+
import { app, appThrows, assertPack } from "./helpers/packTester"
88
import { expectUpdateMetadata } from "./helpers/winHelper"
99

1010
function createBuildResourcesTest(platform: Platform) {
@@ -160,4 +160,7 @@ test.ifAll.ifDevOrLinuxCi("scheme validation extraFiles", app({
160160
}
161161
],
162162
},
163-
}))
163+
}))
164+
165+
// test on all CI to check path separators
166+
test.ifAll("do not exclude build entirely (respect files)", () => assertPack("test-app-build-sub", {targets: linuxDirTarget}))

yarn.lock

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ acorn@^4.0.4:
8686
version "4.0.11"
8787
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.11.tgz#edcda3bd937e7556410d42ed5860f67399c794c0"
8888

89-
ajv-keywords@^2.0.1-beta.2:
90-
version "2.0.1-beta.2"
91-
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.0.1-beta.2.tgz#b48f36d63e9334c5045bafde090db006328a0972"
89+
ajv-keywords@^2.0.0:
90+
version "2.0.0"
91+
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.0.0.tgz#a37d02f845b6f52569804164270b24cb6c6cee61"
9292

9393
ajv@^4.9.1:
9494
version "4.11.7"
@@ -97,9 +97,9 @@ ajv@^4.9.1:
9797
co "^4.6.0"
9898
json-stable-stringify "^1.0.1"
9999

100-
ajv@^5.0.4-beta.2:
101-
version "5.0.4-beta.3"
102-
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.0.4-beta.3.tgz#bb87e35a8f04787a3b7e9b7b2756a6acb6ac926c"
100+
ajv@^5.0.0:
101+
version "5.0.0"
102+
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.0.0.tgz#a2c717764e8036d15fd227b070ddaf7867ab413a"
103103
dependencies:
104104
co "^4.6.0"
105105
json-stable-stringify "^1.0.1"
@@ -786,8 +786,8 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
786786
delayed-stream "~1.0.0"
787787

788788
command-line-args@^4.0.1:
789-
version "4.0.2"
790-
resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-4.0.2.tgz#a99c2f28ceabcf26ac56d38e78b600ea3b57e650"
789+
version "4.0.3"
790+
resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-4.0.3.tgz#aefb061f107f0fd8d72b3c5e0ba042b319891bae"
791791
dependencies:
792792
array-back "^1.0.4"
793793
find-replace "^1.0.3"
@@ -1025,8 +1025,8 @@ diff@^3.0.0, diff@^3.2.0:
10251025
resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9"
10261026

10271027
dmd@^3.0.0:
1028-
version "3.0.3"
1029-
resolved "https://registry.yarnpkg.com/dmd/-/dmd-3.0.3.tgz#3c91f7ba895d379a21c187386d2427e52909a070"
1028+
version "3.0.4"
1029+
resolved "https://registry.yarnpkg.com/dmd/-/dmd-3.0.4.tgz#8a641518a7e2641f95777e046b5c4f085a9ec9b5"
10301030
dependencies:
10311031
array-back "^1.0.4"
10321032
cache-point "^0.4.0"
@@ -1039,7 +1039,7 @@ dmd@^3.0.0:
10391039
reduce-unique "^1.0.0"
10401040
reduce-without "^1.0.1"
10411041
test-value "^2.1.0"
1042-
walk-back "^2.0.1"
1042+
walk-back "^3.0.0"
10431043

10441044
doctrine@^2.0.0:
10451045
version "2.0.0"
@@ -1536,7 +1536,7 @@ is-arrayish@^0.2.1:
15361536
version "0.2.1"
15371537
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
15381538

1539-
is-buffer@^1.0.2:
1539+
is-buffer@^1.1.5:
15401540
version "1.1.5"
15411541
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc"
15421542

@@ -2085,10 +2085,10 @@ jsprim@^1.2.2:
20852085
verror "1.3.6"
20862086

20872087
kind-of@^3.0.2:
2088-
version "3.1.0"
2089-
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.1.0.tgz#475d698a5e49ff5e53d14e3e732429dc8bf4cf47"
2088+
version "3.2.0"
2089+
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.0.tgz#b58abe4d5c044ad33726a8c1525b48cf891bff07"
20902090
dependencies:
2091-
is-buffer "^1.0.2"
2091+
is-buffer "^1.1.5"
20922092

20932093
klaw@~1.3.0:
20942094
version "1.3.1"
@@ -2269,18 +2269,14 @@ mime@^1.3.4:
22692269
dependencies:
22702270
brace-expansion "^1.0.0"
22712271

2272-
minimist@0.0.8:
2272+
minimist@0.0.8, minimist@~0.0.1:
22732273
version "0.0.8"
22742274
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
22752275

22762276
minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0:
22772277
version "1.2.0"
22782278
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
22792279

2280-
minimist@~0.0.1:
2281-
version "0.0.10"
2282-
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
2283-
22842280
mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1:
22852281
version "0.5.1"
22862282
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
@@ -2383,7 +2379,7 @@ object-assign@^4.0.1, object-assign@^4.1.0:
23832379
version "4.1.1"
23842380
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
23852381

2386-
object-get@^2.0.4, object-get@^2.1.0:
2382+
object-get@^2.1.0:
23872383
version "2.1.0"
23882384
resolved "https://registry.yarnpkg.com/object-get/-/object-get-2.1.0.tgz#722bbdb60039efa47cad3c6dc2ce51a85c02c5ae"
23892385

@@ -2709,10 +2705,11 @@ regex-cache@^0.4.2:
27092705
is-primitive "^2.0.0"
27102706

27112707
registry-auth-token@^3.0.1:
2712-
version "3.2.0"
2713-
resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.2.0.tgz#5bf3bd4608a2dd9242542c44d66ad8a5f9cdd3b0"
2708+
version "3.3.0"
2709+
resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.3.0.tgz#57ae67347e73d96345ed1bc01294c7237c02aa63"
27142710
dependencies:
27152711
rc "^1.1.6"
2712+
safe-buffer "^5.0.1"
27162713

27172714
registry-url@^3.0.3:
27182715
version "3.1.0"
@@ -2884,12 +2881,12 @@ sntp@1.x.x:
28842881
hoek "2.x.x"
28852882

28862883
sort-array@^1.1.1:
2887-
version "1.1.1"
2888-
resolved "https://registry.yarnpkg.com/sort-array/-/sort-array-1.1.1.tgz#9032f6f0be284eecb12af98a3db02612828a66d1"
2884+
version "1.1.2"
2885+
resolved "https://registry.yarnpkg.com/sort-array/-/sort-array-1.1.2.tgz#b88986053c0170a7f9de63f18a49ec79c24c3e64"
28892886
dependencies:
2890-
array-back "^1.0.3"
2891-
object-get "^2.0.4"
2892-
typical "^2.4.2"
2887+
array-back "^1.0.4"
2888+
object-get "^2.1.0"
2889+
typical "^2.6.0"
28932890

28942891
source-map-support@^0.4.14, source-map-support@^0.4.2:
28952892
version "0.4.14"
@@ -3371,6 +3368,10 @@ walk-back@^2.0.1:
33713368
version "2.0.1"
33723369
resolved "https://registry.yarnpkg.com/walk-back/-/walk-back-2.0.1.tgz#554e2a9d874fac47a8cb006bf44c2f0c4998a0a4"
33733370

3371+
walk-back@^3.0.0:
3372+
version "3.0.0"
3373+
resolved "https://registry.yarnpkg.com/walk-back/-/walk-back-3.0.0.tgz#2358787a35da91032dad5e92f80b12370d8795c5"
3374+
33743375
walkdir@0.0.11, walkdir@^0.0.11:
33753376
version "0.0.11"
33763377
resolved "https://registry.yarnpkg.com/walkdir/-/walkdir-0.0.11.tgz#a16d025eb931bd03b52f308caed0f40fcebe9532"
@@ -3400,8 +3401,8 @@ whatwg-encoding@^1.0.1:
34003401
iconv-lite "0.4.13"
34013402

34023403
whatwg-url@^4.3.0:
3403-
version "4.7.0"
3404-
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-4.7.0.tgz#202035ac1955b087cdd20fa8b58ded3ab1cd2af5"
3404+
version "4.7.1"
3405+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-4.7.1.tgz#df4dc2e3f25a63b1fa5b32ed6d6c139577d690de"
34053406
dependencies:
34063407
tr46 "~0.0.3"
34073408
webidl-conversions "^3.0.0"

0 commit comments

Comments
 (0)