Skip to content

Commit 945a517

Browse files
committed
feat: ignore dll/exe files from node_modules if target platform not windows
Close #1738
1 parent fcae4c2 commit 945a517

File tree

9 files changed

+95
-47
lines changed

9 files changed

+95
-47
lines changed

.idea/dictionaries/develar.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ You can use macros in the file patterns, artifact file name patterns and publish
7676
* `**/*`
7777
* `!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}`
7878
* `!**/node_modules/.bin`
79-
* `!**/*.{o,hprof,orig,pyc,pyo,rbc}`
79+
* `!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}`
8080
* `!**/._*`
8181
* `!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.editorconfig,.flowconfig,.yarn-metadata.json,.idea,.vs,appveyor.yml,.travis.yml,circle.yml,npm-debug.log,.nyc_output,yarn.lock,.yarn-integrity}`
8282

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
},
6767
"devDependencies": {
6868
"@types/ini": "^1.3.29",
69-
"@types/jest": "^20.0.1",
69+
"@types/jest": "^20.0.2",
7070
"@types/js-yaml": "^3.5.31",
7171
"@types/source-map-support": "^0.4.0",
72-
"@types/xml2js": "^0.0.33",
72+
"@types/xml2js": "^0.4.0",
7373
"babel-plugin-array-includes": "^2.0.3",
7474
"babel-plugin-transform-async-to-module-method": "^6.24.1",
7575
"babel-plugin-transform-es2015-destructuring": "^6.23.0",

packages/electron-builder/src/fileMatcher.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import { copyDir, copyOrLinkFile, Filter, statOrNull } from "electron-builder-ut
44
import { mkdirs } from "fs-extra-p"
55
import { Minimatch } from "minimatch"
66
import * as path from "path"
7+
import { Platform } from "./core"
78
import { Config, FilePattern, PlatformSpecificBuildOptions } from "./metadata"
8-
import { BuildInfo } from "./packagerApi"
9+
import { PlatformPackager } from "./platformPackager"
910
import { createFilter, hasMagic } from "./util/filter"
1011

1112
/** @internal */
1213
export class FileMatcher {
1314
readonly from: string
1415
readonly to: string
1516

16-
private readonly patterns: Array<string>
17+
readonly patterns: Array<string>
1718

1819
constructor(from: string, to: string, private readonly macroExpander: (pattern: string) => string, patterns?: Array<string> | string | n) {
1920
this.from = macroExpander(from)
@@ -33,11 +34,6 @@ export class FileMatcher {
3334
this.patterns.unshift(this.normalizePattern(pattern))
3435
}
3536

36-
addAllPattern() {
37-
// must be first, see minimatchAll implementation
38-
this.patterns.unshift("**/*")
39-
}
40-
4137
isEmpty() {
4238
return this.patterns.length === 0
4339
}
@@ -86,31 +82,49 @@ export class FileMatcher {
8682
}
8783

8884
/** @internal */
89-
export function createFileMatcher(info: BuildInfo, appDir: string, resourcesPath: string, macroExpander: (pattern: string) => string, platformSpecificBuildOptions: PlatformSpecificBuildOptions, buildResourceDir: string) {
90-
const patterns = info.isPrepackedAppAsar ? null : getFileMatchers(info.config, "files", appDir, path.join(resourcesPath, "app"), false, macroExpander, platformSpecificBuildOptions)
85+
export function createFileMatcher(appDir: string, resourcesPath: string, macroExpander: (pattern: string) => string, platformSpecificBuildOptions: PlatformSpecificBuildOptions, packager: PlatformPackager<any>) {
86+
const buildResourceDir = path.resolve(packager.info.projectDir, packager.buildResourcesDir)
87+
88+
const patterns = packager.info.isPrepackedAppAsar ? null : getFileMatchers(packager.info.config, "files", appDir, path.join(resourcesPath, "app"), false, macroExpander, platformSpecificBuildOptions)
9189
const matcher = patterns == null ? new FileMatcher(appDir, path.join(resourcesPath, "app"), macroExpander) : patterns[0]
9290

9391
const relativeBuildResourceDir = path.relative(matcher.from, buildResourceDir)
9492
const ignoreBuildResourceDirPattern = (relativeBuildResourceDir.length !== 0 && !relativeBuildResourceDir.startsWith(".")) ? `!${relativeBuildResourceDir}{,/**/*}` : null
93+
const customFirstPatterns: Array<string> = []
9594
if (matcher.isEmpty() || matcher.containsOnlyIgnore()) {
9695
if (ignoreBuildResourceDirPattern != null) {
9796
matcher.addPattern(ignoreBuildResourceDirPattern)
9897
}
99-
matcher.prependPattern("**/*")
98+
customFirstPatterns.push("**/*")
10099
}
101100
else {
102101
if (ignoreBuildResourceDirPattern != null) {
103-
matcher.prependPattern(ignoreBuildResourceDirPattern)
102+
customFirstPatterns.push(ignoreBuildResourceDirPattern)
104103
}
104+
105105
// prependPattern - user pattern should be after to be able to override
106-
matcher.prependPattern("**/node_modules/**/*")
106+
customFirstPatterns.push("**/node_modules/**/*")
107107
matcher.addPattern("package.json")
108108
}
109+
110+
if (packager.platform !== Platform.WINDOWS) {
111+
// https://github.com/electron-userland/electron-builder/issues/1738
112+
customFirstPatterns.push("!**/node_modules/**/*.{dll,exe}")
113+
}
114+
115+
matcher.patterns.unshift(...customFirstPatterns)
116+
117+
// https://github.com/electron-userland/electron-builder/issues/1738#issuecomment-310729208
118+
// must be before common ignore patterns (to ignore common ignores like .svn)
119+
matcher.addPattern("!**/node_modules/lzma-native/build/**/*")
120+
matcher.addPattern("**/node_modules/lzma-native/build/{Release,Debug}")
121+
matcher.addPattern("!**/node_modules/lzma-native/deps/xz-*")
122+
matcher.addPattern("!**/node_modules/lzma-native/deps/doc{,/**/*}")
123+
109124
matcher.addPattern("!**/node_modules/*/{CHANGELOG.md,ChangeLog,changelog.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}")
110125
matcher.addPattern("!**/node_modules/.bin")
111-
matcher.addPattern("!**/*.{o,hprof,orig,pyc,pyo,rbc,swp}")
126+
matcher.addPattern(`!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}`)
112127
matcher.addPattern("!**/._*")
113-
matcher.addPattern("!*.iml")
114128
//noinspection SpellCheckingInspection
115129
matcher.addPattern("!**/{.git,.hg,.svn,CVS,RCS,SCCS," +
116130
"__pycache__,.DS_Store,thumbs.db,.gitignore,.gitattributes," +

packages/electron-builder/src/platformPackager.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,13 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
165165
}
166166
}
167167

168-
const defaultMatcher = createFileMatcher(this.info, appDir, resourcesPath, macroExpander, platformSpecificBuildOptions, path.resolve(this.info.projectDir, this.buildResourcesDir))
168+
const packContext: AfterPackContext = {
169+
appOutDir, outDir, arch, targets,
170+
packager: this,
171+
electronPlatformName: platformName,
172+
}
173+
174+
const defaultMatcher = createFileMatcher(appDir, resourcesPath, macroExpander, platformSpecificBuildOptions, this)
169175
const isElectronCompile = asarOptions != null && isElectronCompileUsed(this.info)
170176
if (isElectronCompile) {
171177
defaultMatcher.addPattern("!.cache{,/**/*}")
@@ -190,12 +196,6 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
190196
promise = new AsarPackager(appDir, resourcesPath, asarOptions, fileMatcher == null ? null : fileMatcher.createFilter(), transformer).pack(filter, isElectronCompile, this)
191197
}
192198

193-
const packContext: AfterPackContext = {
194-
appOutDir, outDir, arch, targets,
195-
packager: this,
196-
electronPlatformName: platformName,
197-
}
198-
199199
//noinspection ES6MissingAwait
200200
const promises = [promise, unlinkIfExists(path.join(resourcesPath, "default_app.asar")), unlinkIfExists(path.join(appOutDir, "version")), this.postInitApp(packContext)]
201201
if (this.platform !== Platform.MAC) {

test/out/__snapshots__/BuildTest.js.snap

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,32 @@ Object {
270270
}
271271
`;
272272
273-
exports[`relative index 1`] = `
273+
exports[`posix smart unpack 1`] = `
274274
Object {
275275
"linux": Array [],
276276
}
277277
`;
278278
279-
exports[`smart unpack 1`] = `
279+
exports[`posix smart unpack 2`] = `
280+
Array [
281+
"app.asar",
282+
"electron.asar",
283+
]
284+
`;
285+
286+
exports[`relative index 1`] = `
280287
Object {
281288
"linux": Array [],
282289
}
283290
`;
284291
285-
exports[`smart unpack 2`] = `
292+
exports[`win smart unpack 1`] = `
293+
Object {
294+
"win": Array [],
295+
}
296+
`;
297+
298+
exports[`win smart unpack 2`] = `
286299
Array [
287300
"app.asar",
288301
"electron.asar",
@@ -296,14 +309,10 @@ Array [
296309
"app.asar.unpacked/node_modules/edge-cs/src",
297310
"app.asar.unpacked/node_modules/edge-cs/src/edge-cs",
298311
"app.asar.unpacked/node_modules/edge-cs/src/edge-cs/EdgeCompiler.cs",
299-
"app.asar.unpacked/node_modules/edge-cs/src/edge-cs/edge-cs.csproj",
300-
"app.asar.unpacked/node_modules/edge-cs/src/edge-cs/edge-cs.sln",
301312
"app.asar.unpacked/node_modules/edge-cs/src/edge-cs/Properties",
302313
"app.asar.unpacked/node_modules/edge-cs/src/edge-cs/Properties/AssemblyInfo.cs",
303314
"app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp",
304315
"app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/EdgeCompiler.cs",
305-
"app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/edge-cs-coreclr.sln",
306-
"app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/edge-cs-coreclr.xproj",
307316
"app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/gulpfile.js",
308317
"app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/package.json",
309318
"app.asar.unpacked/node_modules/edge-cs/src/Edge.js.CSharp/project.json",

test/src/BuildTest.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ test.ifLinuxOrDevMac("beforeBuild", () => {
170170
})
171171
})
172172

173-
test.ifDevOrLinuxCi("smart unpack", app({
174-
targets: linuxDirTarget,
173+
// https://github.com/electron-userland/electron-builder/issues/1738
174+
test.ifAll.ifDevOrLinuxCi("win smart unpack", app({
175+
targets: Platform.WINDOWS.createTarget(DIR_TARGET),
175176
}, {
176177
installDepsBefore: true,
177178
projectDirCreated: packageJson(it => {
@@ -182,16 +183,31 @@ test.ifDevOrLinuxCi("smart unpack", app({
182183
"@electron-builder/test-smart-unpack-empty": "1.0.0",
183184
}
184185
}),
185-
packed: async context => {
186-
const resourceDir = context.getResources(Platform.LINUX)
187-
expect(await readAsarJson(path.join(resourceDir, "app.asar"), "node_modules/debug/package.json")).toMatchObject({
188-
name: "debug"
189-
})
190-
191-
expect((await walk(resourceDir, file => !path.basename(file).startsWith("."))).map(it => it.substring(resourceDir.length + 1))).toMatchSnapshot()
192-
}
186+
packed: context => verifySmartUnpack(context.getResources(Platform.WINDOWS))
193187
}))
194188

189+
async function verifySmartUnpack(resourceDir: string) {
190+
expect(await readAsarJson(path.join(resourceDir, "app.asar"), "node_modules/debug/package.json")).toMatchObject({
191+
name: "debug"
192+
})
193+
194+
expect((await walk(resourceDir, file => !path.basename(file).startsWith("."))).map(it => it.substring(resourceDir.length + 1))).toMatchSnapshot()
195+
}
196+
197+
// https://github.com/electron-userland/electron-builder/issues/1738
198+
test.ifAll.ifDevOrLinuxCi("posix smart unpack", app({
199+
targets: linuxDirTarget,
200+
}, {
201+
installDepsBefore: true,
202+
projectDirCreated: packageJson(it => {
203+
it.dependencies = {
204+
"debug": "^2.2.0",
205+
"edge-cs": "1.2.1",
206+
"lzma-native": "2.0.3",
207+
}
208+
}),
209+
packed: context => verifySmartUnpack(context.getResources(Platform.LINUX))}))
210+
195211
test("wine version", async () => {
196212
await checkWineVersion(BluebirdPromise.resolve("1.9.23 (Staging)"))
197213
await checkWineVersion(BluebirdPromise.resolve("2.0-rc2"))

test/src/helpers/packTester.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export async function assertPack(fixtureName: string, packagerOptions: PackagerO
9797
if (projectDirCreated != null) {
9898
await projectDirCreated(projectDir)
9999
if (checkOptions.installDepsBefore) {
100-
await spawn("node", [path.join(__dirname, "..", "..", "vendor", "yarn.js"), "install", "--production", "--no-bin-links"], {
100+
// bin links required (e.g. for node-pre-gyp - if package refers to it in the install script)
101+
await spawn("node", [path.join(__dirname, "..", "..", "vendor", "yarn.js"), "install", "--production", "--no-lockfile"], {
101102
cwd: projectDir,
102103
})
103104
}

yarn.lock

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
version "1.3.29"
2727
resolved "https://registry.yarnpkg.com/@types/ini/-/ini-1.3.29.tgz#1325e981e047d40d13ce0359b821475b97741d2f"
2828

29-
"@types/jest@^20.0.1":
29+
"@types/jest@^20.0.2":
3030
version "20.0.2"
3131
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-20.0.2.tgz#86c751121fb53dbd39bb1a08c45083da13f2dc67"
3232

@@ -44,9 +44,11 @@
4444
dependencies:
4545
"@types/node" "*"
4646

47-
"@types/xml2js@^0.0.33":
48-
version "0.0.33"
49-
resolved "https://registry.yarnpkg.com/@types/xml2js/-/xml2js-0.0.33.tgz#20c5dd6460245284d64a55690015b95e409fb7de"
47+
"@types/xml2js@^0.4.0":
48+
version "0.4.0"
49+
resolved "https://registry.yarnpkg.com/@types/xml2js/-/xml2js-0.4.0.tgz#e54a89a0055d5ed69305b2610f970909bf363e45"
50+
dependencies:
51+
"@types/node" "*"
5052

5153
abab@^1.0.3:
5254
version "1.0.3"
@@ -526,10 +528,14 @@ balanced-match@^1.0.0:
526528
version "1.0.0"
527529
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
528530

529-
base64-js@1.2.0, base64-js@^1.0.2:
531+
base64-js@1.2.0:
530532
version "1.2.0"
531533
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.0.tgz#a39992d723584811982be5e290bb6a53d86700f1"
532534

535+
base64-js@^1.0.2:
536+
version "1.2.1"
537+
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.1.tgz#a91947da1f4a516ea38e5b4ec0ec3773675e0886"
538+
533539
bcrypt-pbkdf@^1.0.0:
534540
version "1.0.1"
535541
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz#63bc5dcb61331b92bc05fd528953c33462a06f8d"

0 commit comments

Comments
 (0)