Skip to content

Commit

Permalink
fix: Cannot copy files from parent directory of build output
Browse files Browse the repository at this point in the history
Close #1482
  • Loading branch information
develar committed Apr 26, 2017
1 parent 5a163df commit 7f00714
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"///": "all dependencies for all packages (hoisted)",
"dependencies": {
"7zip-bin": "^2.0.4",
"ajv": "^5.0.4-beta.2",
"ajv-keywords": "^2.0.1-beta.2",
"ajv": "^5.0.0",
"ajv-keywords": "^2.0.0",
"archiver": "^1.3.0",
"aws-sdk": "^2.45.0",
"bluebird-lst": "^1.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"homepage": "https://github.com/electron-userland/electron-builder",
"dependencies": {
"7zip-bin": "^2.0.4",
"ajv": "^5.0.4-beta.2",
"ajv-keywords": "^2.0.1-beta.2",
"ajv": "^5.0.0",
"ajv-keywords": "^2.0.0",
"bluebird-lst": "^1.0.2",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
Expand Down
26 changes: 22 additions & 4 deletions packages/electron-builder/src/fileMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ export class FileMatcher {
readonly from: string
readonly to: string

readonly patterns: Array<string>
private readonly patterns: Array<string>

constructor(from: string, to: string, private readonly macroExpander: (pattern: string) => string, patterns?: Array<string> | string | n) {
this.from = macroExpander(from)
this.to = macroExpander(to)
this.patterns = asArray(patterns).map(it => path.posix.normalize(macroExpander(it)))
this.patterns = asArray(patterns).map(it => this.normalizePattern(it))
}

private normalizePattern(pattern: string) {
return path.posix.normalize(this.macroExpander(pattern))
}

addPattern(pattern: string) {
this.patterns.push(path.posix.normalize(this.macroExpander(pattern)))
this.patterns.push(this.normalizePattern(pattern))
}

prependPattern(pattern: string) {
this.patterns.unshift(this.normalizePattern(pattern))
}

addAllPattern() {
Expand Down Expand Up @@ -74,13 +82,23 @@ export class FileMatcher {
}
}

export function createFileMatcher(info: BuildInfo, appDir: string, resourcesPath: string, macroExpander: (pattern: string) => string, platformSpecificBuildOptions: PlatformSpecificBuildOptions) {
export function createFileMatcher(info: BuildInfo, appDir: string, resourcesPath: string, macroExpander: (pattern: string) => string, platformSpecificBuildOptions: PlatformSpecificBuildOptions, buildResourceDir: string) {
const patterns = info.isPrepackedAppAsar ? null : getFileMatchers(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

if (matcher.isEmpty() || matcher.containsOnlyIgnore()) {
matcher.addAllPattern()
if (ignoreBuildResourceDirPattern != null) {
matcher.addPattern(ignoreBuildResourceDirPattern)
}
}
else {
if (ignoreBuildResourceDirPattern != null) {
matcher.prependPattern(ignoreBuildResourceDirPattern)
}
matcher.addPattern("package.json")
}
matcher.addPattern("!**/node_modules/*/{CHANGELOG.md,ChangeLog,changelog.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}")
Expand Down
3 changes: 1 addition & 2 deletions packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

const appDir = this.info.appDir
const ignoreFiles = new Set([path.resolve(this.info.projectDir, outDir),
path.resolve(this.info.projectDir, this.buildResourcesDir),
path.resolve(this.info.projectDir, "electron-builder.yml"),
path.resolve(this.info.projectDir, "electron-builder.json"),
path.resolve(this.info.projectDir, "electron-builder.json5")])
Expand Down Expand Up @@ -175,7 +174,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}
}

const defaultMatcher = createFileMatcher(this.info, appDir, resourcesPath, macroExpander, platformSpecificBuildOptions)
const defaultMatcher = createFileMatcher(this.info, appDir, resourcesPath, macroExpander, platformSpecificBuildOptions, path.resolve(this.info.projectDir, this.buildResourcesDir))
const isElectronCompile = asarOptions != null && isElectronCompileUsed(this.info)
if (isElectronCompile) {
defaultMatcher.addPattern("!.cache{,/**/*}")
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/test-app-build-sub/build/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node <script>document.write(process.versions.node)</script>,
Chrome <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
</body>
</html>
32 changes: 32 additions & 0 deletions test/fixtures/test-app-build-sub/build/app/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict"

const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow

let mainWindow

function createWindow () {
mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow.loadURL('file://' + __dirname + '/index.html')

mainWindow.webContents.openDevTools()

mainWindow.on('closed', function() {
mainWindow = null
});
}

app.on('ready', createWindow)

app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
})
23 changes: 23 additions & 0 deletions test/fixtures/test-app-build-sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "1.0.0",
"main": "./build/app/main.js",
"author": "true",
"name": "Foo",
"build": {
"electronVersion": "1.6.6",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
"mac": {
"category": "your.app.category.type"
},
"directories": {
"output": "build/dist"
},
"files": [
"build/app/**/*.js",
"build/app/**/*.html"
],
"asar": false
}
}
6 changes: 6 additions & 0 deletions test/out/__snapshots__/ExtraBuildTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Object {
}
`;

exports[`do not exclude build entirely (respect files) 1`] = `
Object {
"linux": Array [],
}
`;

exports[`override targets in the config - only arch 1`] = `
Object {
"win": Array [
Expand Down
7 changes: 5 additions & 2 deletions test/src/ExtraBuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { move, readFile } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
import { app, appThrows } from "./helpers/packTester"
import { app, appThrows, assertPack } from "./helpers/packTester"
import { expectUpdateMetadata } from "./helpers/winHelper"

function createBuildResourcesTest(platform: Platform) {
Expand Down Expand Up @@ -160,4 +160,7 @@ test.ifAll.ifDevOrLinuxCi("scheme validation extraFiles", app({
}
],
},
}))
}))

// test on all CI to check path separators
test.ifAll("do not exclude build entirely (respect files)", () => assertPack("test-app-build-sub", {targets: linuxDirTarget}))
61 changes: 31 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ acorn@^4.0.4:
version "4.0.11"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.11.tgz#edcda3bd937e7556410d42ed5860f67399c794c0"

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

ajv@^4.9.1:
version "4.11.7"
Expand All @@ -97,9 +97,9 @@ ajv@^4.9.1:
co "^4.6.0"
json-stable-stringify "^1.0.1"

ajv@^5.0.4-beta.2:
version "5.0.4-beta.3"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.0.4-beta.3.tgz#bb87e35a8f04787a3b7e9b7b2756a6acb6ac926c"
ajv@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.0.0.tgz#a2c717764e8036d15fd227b070ddaf7867ab413a"
dependencies:
co "^4.6.0"
json-stable-stringify "^1.0.1"
Expand Down Expand Up @@ -786,8 +786,8 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
delayed-stream "~1.0.0"

command-line-args@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-4.0.2.tgz#a99c2f28ceabcf26ac56d38e78b600ea3b57e650"
version "4.0.3"
resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-4.0.3.tgz#aefb061f107f0fd8d72b3c5e0ba042b319891bae"
dependencies:
array-back "^1.0.4"
find-replace "^1.0.3"
Expand Down Expand Up @@ -1025,8 +1025,8 @@ diff@^3.0.0, diff@^3.2.0:
resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9"

dmd@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/dmd/-/dmd-3.0.3.tgz#3c91f7ba895d379a21c187386d2427e52909a070"
version "3.0.4"
resolved "https://registry.yarnpkg.com/dmd/-/dmd-3.0.4.tgz#8a641518a7e2641f95777e046b5c4f085a9ec9b5"
dependencies:
array-back "^1.0.4"
cache-point "^0.4.0"
Expand All @@ -1039,7 +1039,7 @@ dmd@^3.0.0:
reduce-unique "^1.0.0"
reduce-without "^1.0.1"
test-value "^2.1.0"
walk-back "^2.0.1"
walk-back "^3.0.0"

doctrine@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -1536,7 +1536,7 @@ is-arrayish@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"

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

Expand Down Expand Up @@ -2085,10 +2085,10 @@ jsprim@^1.2.2:
verror "1.3.6"

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

klaw@~1.3.0:
version "1.3.1"
Expand Down Expand Up @@ -2269,18 +2269,14 @@ mime@^1.3.4:
dependencies:
brace-expansion "^1.0.0"

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

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

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
Expand Down Expand Up @@ -2383,7 +2379,7 @@ object-assign@^4.0.1, object-assign@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"

object-get@^2.0.4, object-get@^2.1.0:
object-get@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/object-get/-/object-get-2.1.0.tgz#722bbdb60039efa47cad3c6dc2ce51a85c02c5ae"

Expand Down Expand Up @@ -2709,10 +2705,11 @@ regex-cache@^0.4.2:
is-primitive "^2.0.0"

registry-auth-token@^3.0.1:
version "3.2.0"
resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.2.0.tgz#5bf3bd4608a2dd9242542c44d66ad8a5f9cdd3b0"
version "3.3.0"
resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-3.3.0.tgz#57ae67347e73d96345ed1bc01294c7237c02aa63"
dependencies:
rc "^1.1.6"
safe-buffer "^5.0.1"

registry-url@^3.0.3:
version "3.1.0"
Expand Down Expand Up @@ -2884,12 +2881,12 @@ sntp@1.x.x:
hoek "2.x.x"

sort-array@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/sort-array/-/sort-array-1.1.1.tgz#9032f6f0be284eecb12af98a3db02612828a66d1"
version "1.1.2"
resolved "https://registry.yarnpkg.com/sort-array/-/sort-array-1.1.2.tgz#b88986053c0170a7f9de63f18a49ec79c24c3e64"
dependencies:
array-back "^1.0.3"
object-get "^2.0.4"
typical "^2.4.2"
array-back "^1.0.4"
object-get "^2.1.0"
typical "^2.6.0"

source-map-support@^0.4.14, source-map-support@^0.4.2:
version "0.4.14"
Expand Down Expand Up @@ -3371,6 +3368,10 @@ walk-back@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/walk-back/-/walk-back-2.0.1.tgz#554e2a9d874fac47a8cb006bf44c2f0c4998a0a4"

walk-back@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/walk-back/-/walk-back-3.0.0.tgz#2358787a35da91032dad5e92f80b12370d8795c5"

walkdir@0.0.11, walkdir@^0.0.11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/walkdir/-/walkdir-0.0.11.tgz#a16d025eb931bd03b52f308caed0f40fcebe9532"
Expand Down Expand Up @@ -3400,8 +3401,8 @@ whatwg-encoding@^1.0.1:
iconv-lite "0.4.13"

whatwg-url@^4.3.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-4.7.0.tgz#202035ac1955b087cdd20fa8b58ded3ab1cd2af5"
version "4.7.1"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-4.7.1.tgz#df4dc2e3f25a63b1fa5b32ed6d6c139577d690de"
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"
Expand Down

0 comments on commit 7f00714

Please sign in to comment.