Skip to content

Commit abf3703

Browse files
authored
fix: "Can't reconcile two non-macho files" due to new Pre-Gyp-Copy functionality in electron/rebuild integration (#7519)
Adding native module to two-package test fixture. Ignoring electron/rebuild metadata and disabling its pregyp cache Exclude .husky and .github folders by default. Verify smart unpack for universal builds with native module (node-mac-permissions in this case)
1 parent b638c7f commit abf3703

16 files changed

+362
-97
lines changed

.changeset/flat-jars-glow.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"app-builder-lib": patch
3+
"electron-builder": patch
4+
---
5+
6+
fix: "Can't reconcile two non-macho files" due to `disablePreGypCopy` functionality in new electron/rebuild integration

packages/app-builder-lib/src/fileMatcher.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ export const excludedNames =
1717
"__pycache__,.DS_Store,thumbs.db,.gitignore,.gitkeep,.gitattributes,.npmignore," +
1818
".idea,.vs,.flowconfig,.jshintrc,.eslintrc,.circleci," +
1919
".yarn-integrity,.yarn-metadata.json,yarn-error.log,yarn.lock,package-lock.json,npm-debug.log," +
20-
"appveyor.yml,.travis.yml,circle.yml,.nyc_output"
20+
"appveyor.yml,.travis.yml,circle.yml,.nyc_output,.husky,.github"
2121

22-
export const excludedExts = "iml,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,suo,xproj,cc,d.ts"
22+
export const excludedExts =
23+
"iml,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,suo,xproj,cc,d.ts," +
24+
// https://github.com/electron-userland/electron-builder/issues/7512
25+
"mk,a,o,forge-meta"
2326

2427
function ensureNoEndSlash(file: string): string {
2528
if (path.sep !== "/") {

packages/app-builder-lib/src/macPackager.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
106106
return super.doPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets)
107107
}
108108
case Arch.universal: {
109+
const outDirName = (arch: Arch) => `${appOutDir}-${Arch[arch]}-temp`
110+
109111
const x64Arch = Arch.x64
110-
const x64AppOutDir = appOutDir + "--" + Arch[x64Arch]
112+
const x64AppOutDir = outDirName(x64Arch)
111113
await super.doPack(outDir, x64AppOutDir, platformName, x64Arch, platformSpecificBuildOptions, targets, false, true)
112114
const arm64Arch = Arch.arm64
113-
const arm64AppOutPath = appOutDir + "--" + Arch[arm64Arch]
115+
const arm64AppOutPath = outDirName(arm64Arch)
114116
await super.doPack(outDir, arm64AppOutPath, platformName, arm64Arch, platformSpecificBuildOptions, targets, false, true)
115117
const framework = this.info.framework
116118
log.info(

packages/app-builder-lib/src/packager.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ export class Packager {
495495
const frameworkInfo = { version: this.framework.version, useCustomDist: true }
496496
const config = this.config
497497
if (config.nodeGypRebuild === true) {
498-
await nodeGypRebuild(frameworkInfo, Arch[arch])
498+
await nodeGypRebuild(frameworkInfo, arch)
499499
}
500500

501501
if (config.npmRebuild === false) {
@@ -526,7 +526,6 @@ export class Packager {
526526
frameworkInfo,
527527
platform: platform.nodeName,
528528
arch: Arch[arch],
529-
productionDeps: this.getNodeDependencyInfo(null),
530529
})
531530
}
532531
}

packages/app-builder-lib/src/util/yarn.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { asArray, log, spawn } from "builder-util"
1+
import { Arch, archFromString, asArray, log, spawn } from "builder-util"
22
import { pathExists } from "fs-extra"
3-
import { Lazy } from "lazy-val"
43
import { homedir } from "os"
54
import * as path from "path"
65
import { Configuration } from "../configuration"
7-
import { NodeModuleDirInfo } from "./packageDependencies"
86
import * as electronRebuild from "@electron/rebuild"
97
import * as searchModule from "@electron/rebuild/lib/src/search-module"
108

@@ -25,7 +23,8 @@ export async function installOrRebuild(config: Configuration, appDir: string, op
2523
}
2624
await installDependencies(appDir, effectiveOptions)
2725
} else {
28-
await rebuild(appDir, config.buildDependenciesFromSource === true, options.frameworkInfo, options.arch)
26+
const arch = archFromString(options.arch || process.arch)
27+
await rebuild(appDir, config.buildDependenciesFromSource === true, options.frameworkInfo, arch)
2928
}
3029
}
3130

@@ -118,7 +117,7 @@ function installDependencies(appDir: string, options: RebuildOptions): Promise<a
118117
})
119118
}
120119

121-
export async function nodeGypRebuild(frameworkInfo: DesktopFrameworkInfo, arch: string) {
120+
export async function nodeGypRebuild(frameworkInfo: DesktopFrameworkInfo, arch: Arch) {
122121
return rebuild(process.cwd(), false, frameworkInfo, arch)
123122
}
124123

@@ -137,7 +136,6 @@ function isRunningYarn(execPath: string | null | undefined) {
137136

138137
export interface RebuildOptions {
139138
frameworkInfo: DesktopFrameworkInfo
140-
productionDeps?: Lazy<Array<NodeModuleDirInfo>>
141139

142140
platform?: NodeJS.Platform
143141
arch?: string
@@ -148,15 +146,15 @@ export interface RebuildOptions {
148146
}
149147

150148
/** @internal */
151-
export async function rebuild(appDir: string, buildFromSource: boolean, frameworkInfo: DesktopFrameworkInfo, arch = process.arch) {
152-
log.info({ arch, version: frameworkInfo.version, appDir }, "executing @electron/rebuild")
149+
export async function rebuild(appDir: string, buildFromSource: boolean, frameworkInfo: DesktopFrameworkInfo, arch: Arch) {
150+
log.info({ arch: Arch[arch], version: frameworkInfo.version, appDir }, "executing @electron/rebuild")
153151
const rootPath = await searchModule.getProjectRootPath(appDir)
154152
const options: electronRebuild.RebuildOptions = {
155153
buildPath: appDir,
156154
electronVersion: frameworkInfo.version,
157-
arch,
158-
debug: log.isDebugEnabled,
155+
arch: Arch[arch],
159156
projectRootPath: rootPath,
157+
disablePreGypCopy: true,
160158
}
161159
if (buildFromSource) {
162160
options.prebuildTagPrefix = "totally-not-a-real-prefix-to-force-rebuild"

packages/electron-builder/src/cli/install-app-deps.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#! /usr/bin/env node
22

3-
import { PACKAGE_VERSION } from "app-builder-lib/out/version"
4-
import { log, use, getArchCliNames } from "builder-util"
5-
import { printErrorAndExit } from "builder-util/out/promise"
6-
import { computeDefaultAppDirectory, getConfig } from "app-builder-lib/out/util/config"
73
import { getElectronVersion } from "app-builder-lib/out/electron/electronVersion"
8-
import { createLazyProductionDeps } from "app-builder-lib/out/util/packageDependencies"
4+
import { computeDefaultAppDirectory, getConfig } from "app-builder-lib/out/util/config"
95
import { installOrRebuild } from "app-builder-lib/out/util/yarn"
6+
import { PACKAGE_VERSION } from "app-builder-lib/out/version"
7+
import { getArchCliNames, log, use } from "builder-util"
8+
import { printErrorAndExit } from "builder-util/out/promise"
109
import { readJson } from "fs-extra"
1110
import { Lazy } from "lazy-val"
1211
import * as path from "path"
@@ -63,7 +62,6 @@ export async function installAppDeps(args: any) {
6362
frameworkInfo: { version, useCustomDist: true },
6463
platform: args.platform,
6564
arch: args.arch,
66-
productionDeps: createLazyProductionDeps(appDir, null),
6765
},
6866
appDir !== projectDir
6967
)

test/fixtures/test-app-two-native-modules/app/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"main": "index.js",
44
"version": "1.1.1",
55
"dependencies": {
6-
"install": "0.13.0"
6+
"debug": "4.1.1"
7+
},
8+
"optionalDependencies": {
9+
"node-mac-permissions": "^2.3.0"
710
}
811
}

test/snapshots/BuildTest.js.snap

-7
Original file line numberDiff line numberDiff line change
@@ -957,13 +957,6 @@ Object {
957957
},
958958
"minimist": Object {
959959
"files": Object {
960-
".github": Object {
961-
"files": Object {
962-
"FUNDING.yml": Object {
963-
"size": "<size>",
964-
},
965-
},
966-
},
967960
".nycrc": Object {
968961
"size": "<size>",
969962
},

test/snapshots/HoistedNodeModuleTest.js.snap

+44-22
Original file line numberDiff line numberDiff line change
@@ -185,45 +185,67 @@ Object {
185185
},
186186
"node_modules": Object {
187187
"files": Object {
188-
"install": Object {
188+
"debug": Object {
189189
"files": Object {
190190
"LICENSE": Object {
191-
"offset": "3479",
192-
"size": 1101,
191+
"offset": "3546",
192+
"size": 1107,
193193
},
194-
"install.js": Object {
195-
"offset": "4580",
196-
"size": 19880,
197-
},
198-
"install.min.js": Object {
199-
"offset": "24460",
200-
"size": 3663,
194+
"dist": Object {
195+
"files": Object {
196+
"debug.js": Object {
197+
"offset": "22150",
198+
"size": 27572,
199+
},
200+
},
201201
},
202202
"package.json": Object {
203-
"offset": "28123",
204-
"size": 529,
203+
"offset": "4653",
204+
"size": 947,
205205
},
206-
"scripts": Object {
206+
"src": Object {
207207
"files": Object {
208-
"docs.sh": Object {
209-
"executable": true,
210-
"offset": "28652",
211-
"size": 99,
208+
"browser.js": Object {
209+
"offset": "5600",
210+
"size": 5831,
212211
},
213-
"prepublish.sh": Object {
214-
"executable": true,
215-
"offset": "28751",
216-
"size": 83,
212+
"common.js": Object {
213+
"offset": "11431",
214+
"size": 5930,
215+
},
216+
"index.js": Object {
217+
"offset": "17361",
218+
"size": 314,
219+
},
220+
"node.js": Object {
221+
"offset": "17675",
222+
"size": 4475,
217223
},
218224
},
219225
},
220226
},
221227
},
228+
"ms": Object {
229+
"files": Object {
230+
"index.js": Object {
231+
"offset": "49722",
232+
"size": 3024,
233+
},
234+
"license.md": Object {
235+
"offset": "52746",
236+
"size": 1079,
237+
},
238+
"package.json": Object {
239+
"offset": "53825",
240+
"size": 497,
241+
},
242+
},
243+
},
222244
},
223245
},
224246
"package.json": Object {
225247
"offset": "3342",
226-
"size": 137,
248+
"size": 204,
227249
},
228250
},
229251
}

0 commit comments

Comments
 (0)