Skip to content

Commit a55c573

Browse files
committed
feat: if only ignored patterns are specified — all not ignored files is copied
Closes #927
1 parent f4d7a2e commit a55c573

15 files changed

+126
-97
lines changed

docs/Options.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ Windows specific build options.
270270

271271
| Name | Description
272272
| --- | ---
273-
| target | <a name="WinBuildOptions-target"></a>Target package type: list of `nsis`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `nsis`.
274-
| signingHashAlgorithms | <a name="WinBuildOptions-signingHashAlgorithms"></a>Array of signing algorithms used. Defaults to `['sha1', 'sha256']`
273+
| target | <a name="WinBuildOptions-target"></a><p>Target package type: list of <code>nsis</code>, <code>appx</code>, <code>squirrel</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>, <code>dir</code>. Defaults to <code>nsis</code>.</p> <p>AppX package can be built only on Windows 10.</p>
274+
| signingHashAlgorithms | <a name="WinBuildOptions-signingHashAlgorithms"></a><p>Array of signing algorithms used. Defaults to <code>['sha1', 'sha256']</code></p> <p>Fo AppX <code>sha256</code> is always used.</p>
275275
| icon | <a name="WinBuildOptions-icon"></a>The path to application icon. Defaults to `build/icon.ico` (consider using this convention instead of complicating your configuration).
276276
| legalTrademarks | <a name="WinBuildOptions-legalTrademarks"></a>The trademarks and registered trademarks.
277-
| certificateFile | <a name="WinBuildOptions-certificateFile"></a>The path to the *.pfx certificate you want to sign with. Required only if you build on macOS and need different certificate than the one set in `CSC_LINK` - see [Code Signing](https://github.com/electron-userland/electron-builder/wiki/Code-Signing).
278-
| certificatePassword | <a name="WinBuildOptions-certificatePassword"></a>The password to the certificate provided in `certificateFile`. Required only if you build on macOS and need to use a different password than the one set in `CSC_KEY_PASSWORD` - see [Code Signing](https://github.com/electron-userland/electron-builder/wiki/Code-Signing).
277+
| certificateFile | <a name="WinBuildOptions-certificateFile"></a><p>The path to the *.pfx certificate you want to sign with. Please use it only if you cannot use env variable <code>CSC_LINK</code> (<code>WIN_CSC_LINK</code>) for some reason. Please see [Code Signing](https://github.com/electron-userland/electron-builder/wiki/Code-Signing).</p>
278+
| certificatePassword | <a name="WinBuildOptions-certificatePassword"></a><p>The password to the certificate provided in <code>certificateFile</code>. Please use it only if you cannot use env variable <code>CSC_KEY_PASSWORD</code> (<code>WIN_CSC_KEY_PASSWORD</code>) for some reason. Please see [Code Signing](https://github.com/electron-userland/electron-builder/wiki/Code-Signing).</p>
279279
| certificateSubjectName | <a name="WinBuildOptions-certificateSubjectName"></a>The name of the subject of the signing certificate. Required only for EV Code Signing and works only on Windows.
280280
| rfc3161TimeStampServer | <a name="WinBuildOptions-rfc3161TimeStampServer"></a>The URL of the RFC 3161 time stamp server. Defaults to `http://timestamp.comodoca.com/rfc3161`.
281281

@@ -306,9 +306,8 @@ Development dependencies are never copied in any case. You don't need to ignore
306306
[Multiple patterns](#multiple-glob-patterns) are supported. You can use `${os}` (expanded to mac, linux or win according to current platform) and `${arch}` in the pattern.
307307
If directory matched, all contents are copied. So, you can just specify `foo` to copy `foo` directory.
308308

309-
Remember that default pattern `**/*` is not added to your custom, so, you have to add it explicitly — e.g. `["**/*", "!ignoreMe${/*}"]`.
310-
311-
`package.json` is added to your custom in any case.
309+
Remember that default pattern `**/*` **is not added to your custom** if some of your patterns is not ignore (i.e. not starts with `!`).
310+
`package.json` is added to your custom in any case.
312311

313312
May be specified in the platform options (e.g. in the `build.mac`).
314313

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"update-wiki": "git subtree split -b wiki --prefix docs/ && git push -f wiki wiki:master",
2727
"whitespace": "whitespace 'src/**/*.ts'",
2828
"docker-images": "docker/build.sh",
29+
"test-deps-mac": "brew install rpm dpkg mono lzip gnu-tar graphicsmagick xz && brew install wine --without-x11",
2930
"precommit": "validate-commit-msg"
3031
},
3132
"repository": "electron-userland/electron-builder",

src/codeSign.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ async function _findIdentity(type: CertType, qualifier?: string | null, keychain
207207
export async function findIdentity(certType: CertType, qualifier?: string | null, keychain?: string | null): Promise<string | null> {
208208
let identity = process.env.CSC_NAME || qualifier
209209
if (isEmptyOrSpaces(identity)) {
210-
if (keychain == null && !isCi() && (process.env.CSC_IDENTITY_AUTO_DISCOVERY === "false")) {
210+
if (keychain == null && !isCi() && process.env.CSC_IDENTITY_AUTO_DISCOVERY === "false") {
211211
return null
212212
}
213213
else {

src/fileMatcher.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ export class FileMatcher {
3434
return this.patterns.length === 0
3535
}
3636

37+
containsOnlyIgnore(): boolean {
38+
return !this.isEmpty() && this.patterns.find(it => !it.startsWith("!")) == null
39+
}
40+
3741
getParsedPatterns(fromDir?: string): Array<Minimatch> {
3842
// https://github.com/electron-userland/electron-builder/issues/733
3943
const minimatchOptions = {dot: true}
4044

4145
const parsedPatterns: Array<Minimatch> = []
4246
const pathDifference = fromDir ? path.relative(fromDir, this.from) : null
4347

44-
for (let i = 0; i < this.patterns.length; i++) {
45-
let expandedPattern = this.expandPattern(this.patterns[i])
46-
if (pathDifference) {
48+
for (const p of this.patterns) {
49+
let expandedPattern = this.expandPattern(p)
50+
if (pathDifference != null) {
4751
expandedPattern = path.join(pathDifference, expandedPattern)
4852
}
4953

@@ -72,19 +76,19 @@ export class FileMatcher {
7276
}
7377
}
7478

75-
export function deprecatedUserIgnoreFilter(ignore: any, appDir: string) {
79+
export function deprecatedUserIgnoreFilter(ignore: Array<RegExp> | ((file: string) => boolean), appDir: string) {
7680
let ignoreFunc: any
77-
if (typeof (ignore) === "function") {
78-
ignoreFunc = function (file: string) { return !ignore(file) }
81+
if (typeof ignore === "function") {
82+
ignoreFunc = function (file: string) { return !(<any>ignore)(file) }
7983
}
8084
else {
8185
if (!Array.isArray(ignore)) {
8286
ignore = [ignore]
8387
}
8488

8589
ignoreFunc = function (file: string) {
86-
for (let i = 0; i < ignore.length; i++) {
87-
if (file.match(ignore[i])) {
90+
for (const i of <Array<RegExp>>ignore) {
91+
if (file.match(i)) {
8892
return false
8993
}
9094
}

src/platformPackager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
197197

198198
const patterns = this.getFileMatchers("files", appDir, path.join(resourcesPath, "app"), false, fileMatchOptions, platformSpecificBuildOptions)
199199
let defaultMatcher = patterns == null ? new FileMatcher(appDir, path.join(resourcesPath, "app"), fileMatchOptions) : patterns[0]
200-
if (defaultMatcher.isEmpty()) {
200+
if (defaultMatcher.isEmpty() || defaultMatcher.containsOnlyIgnore()) {
201201
defaultMatcher.addPattern("**/*")
202202
}
203203
else {
@@ -252,7 +252,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
252252
//noinspection ES6MissingAwait
253253
const promises = [promise, unlinkIfExists(path.join(resourcesPath, "default_app.asar")), unlinkIfExists(path.join(appOutDir, "version")), this.postInitApp(appOutDir)]
254254
if (this.platform !== Platform.MAC) {
255-
promises.push(rename(path.join(appOutDir, "LICENSE"), path.join(appOutDir, "LICENSE.electron.txt")) .catch(() => {/* ignore */}))
255+
promises.push(rename(path.join(appOutDir, "LICENSE"), path.join(appOutDir, "LICENSE.electron.txt")).catch(() => {/* ignore */}))
256256
}
257257
if (this.info.electronVersion != null && this.info.electronVersion[0] === "0") {
258258
// electron release >= 0.37.4 - the default_app/ folder is a default_app.asar file

src/targets/appx.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ import BluebirdPromise from "bluebird-lst-c"
99
import { Target } from "./targetFactory"
1010
import { getSignVendorPath } from "../windowsCodeSign"
1111
import sanitizeFileName from "sanitize-filename"
12+
import { release } from "os"
1213

1314
export default class AppXTarget extends Target {
1415
private readonly options: AppXOptions = Object.assign({}, this.packager.platformSpecificBuildOptions, this.packager.devMetadata.build.appx)
1516

1617
constructor(private readonly packager: WinPackager, private readonly outDir: string) {
1718
super("appx")
19+
20+
const osVersion = release()
21+
if (process.platform !== "win32" || parseInt(osVersion.substring(0, osVersion.indexOf(".")), 10) < 10) {
22+
throw new Error("AppX is supported only on Windows 10")
23+
}
1824
}
1925

2026
// no flatten - use asar or npm 3 or yarn

src/util/filter.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function hasMagic(pattern: Minimatch) {
1717
return true
1818
}
1919

20-
for (let i of set[0]) {
20+
for (const i of set[0]) {
2121
if (typeof i !== "string") {
2222
return true
2323
}
@@ -44,7 +44,6 @@ export function createFilter(src: string, patterns: Array<Minimatch>, ignoreFile
4444
}
4545

4646
let relative = it.substring(src.length + 1)
47-
4847
if (path.sep === "\\") {
4948
relative = relative.replace(/\\/g, "/")
5049
}
@@ -56,7 +55,7 @@ export function createFilter(src: string, patterns: Array<Minimatch>, ignoreFile
5655
// https://github.com/joshwnj/minimatch-all/blob/master/index.js
5756
function minimatchAll(path: string, patterns: Array<Minimatch>, stat: Stats): boolean {
5857
let match = false
59-
for (let pattern of patterns) {
58+
for (const pattern of patterns) {
6059
// If we've got a match, only re-test for exclusions.
6160
// if we don't have a match, only re-test for inclusions.
6261
if (match !== pattern.negate) {

test/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
In addition to [required system packages](./multi-platform-build.md), on MacOS `dpkg` is required to run Linux tests: `brew install dpkg`
2-
31
# Inspect output if test uses temporary directory
42
Set environment variable `TEST_APP_TMP_DIR` (e.g. `/tmp/electron-builder-test`).
53
Specified directory will be used instead of random temporary directory and *cleared* on each run.

test/jestSetup.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ test.ifNotCiMac = isCi && process.platform === "darwin" ? skip : test
3333

3434
test.ifDevOrWinCi = !isCi || isWindows ? test : skip
3535
test.ifDevOrLinuxCi = !isCi || process.platform === "linux" ? test : skip
36-
test.ifWinCi = isCi && isWindows ? test : skip
36+
test.ifWinCi = isCi && isWindows ? test : skip
37+
38+
delete process.env.CSC_NAME
39+
process.env.CSC_IDENTITY_AUTO_DISCOVERY = "false"

test/src/ArtifactPublisherTest.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ if (process.env.CI && process.platform === "win32") {
1111
})
1212
}
1313

14+
if (process.env.ELECTRON_BUILDER_OFFLINE === "true") {
15+
fit("Skip ArtifactPublisherTest suite — ELECTRON_BUILDER_OFFLINE is defined", () => {
16+
console.warn("[SKIP] Skip ArtifactPublisherTest suite — ELECTRON_BUILDER_OFFLINE is defined")
17+
})
18+
}
19+
1420
function getRandomInt(min: number, max: number) {
1521
return Math.floor(Math.random() * (max - min + 1)) + min
1622
}

0 commit comments

Comments
 (0)