Skip to content

Commit

Permalink
swapping to electron-rebuild for rebuilding native node addons
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Maietta committed Oct 19, 2022
1 parent 5f2b3f7 commit c10d81b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 39 deletions.
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ export class Packager {
const frameworkInfo = { version: this.framework.version, useCustomDist: true }
const config = this.config
if (config.nodeGypRebuild === true) {
await nodeGypRebuild(platform.nodeName, Arch[arch], frameworkInfo)
await nodeGypRebuild(Arch[arch])
}

if (config.npmRebuild === false) {
Expand Down
43 changes: 8 additions & 35 deletions packages/app-builder-lib/src/util/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { Lazy } from "lazy-val"
import { homedir } from "os"
import * as path from "path"
import { Configuration } from "../configuration"
// import { executeAppBuilderAndWriteJson } from "./appBuilder"
import { NodeModuleDirInfo } from "./packageDependencies"
import * as electronRebuild from 'electron-rebuild'
import * as electronRebuild from "electron-rebuild"
import { getElectronVersion } from "../electron/electronVersion"

export async function installOrRebuild(config: Configuration, appDir: string, options: RebuildOptions, forceInstall = false) {
Expand Down Expand Up @@ -119,24 +118,8 @@ function installDependencies(appDir: string, options: RebuildOptions): Promise<a
})
}

export async function nodeGypRebuild(platform: NodeJS.Platform, arch: string, frameworkInfo: DesktopFrameworkInfo) {
export async function nodeGypRebuild(arch: string) {
return rebuild(process.cwd(), false, arch)
// log.info({ platform, arch }, "executing node-gyp rebuild")
// // this script must be used only for electron
// const nodeGyp = `node-gyp${process.platform === "win32" ? ".cmd" : ""}`
// const args = ["rebuild"]
// // headers of old Electron versions do not have a valid config.gypi file
// // and --force-process-config must be passed to node-gyp >= 8.4.0 to
// // correctly build modules for them.
// // see also https://github.com/nodejs/node-gyp/pull/2497
// const [major, minor] = frameworkInfo.version
// .split(".")
// .slice(0, 2)
// .map(n => parseInt(n, 10))
// if (major <= 13 || (major == 14 && minor <= 1) || (major == 15 && minor <= 2)) {
// args.push("--force-process-config")
// }
// await spawn(nodeGyp, args, { env: getGypEnv(frameworkInfo, platform, arch, true) })
}

function getPackageToolPath() {
Expand Down Expand Up @@ -167,25 +150,15 @@ export interface RebuildOptions {
/** @internal */
export async function rebuild(appDir: string, buildFromSource: boolean, arch = process.arch) {
log.info({ appDir, arch }, "executing electron-rebuild")
return electronRebuild.rebuild({
const options: electronRebuild.RebuildOptions = {
buildPath: appDir,
electronVersion: await getElectronVersion(appDir),
arch,
force: true,
debug: log.isDebugEnabled,
// forceRebuildDependency: buildFromSource
// onlyModules: await options.productionDeps!.value
})
// const configuration: any = {
// dependencies: await options.productionDeps!.value,
// nodeExecPath: process.execPath,
// platform: options.platform || process.platform,
// arch: options.arch || process.arch,
// additionalArgs: options.additionalArgs,
// execPath: process.env.npm_execpath || process.env.NPM_CLI_JS,
// buildFromSource: options.buildFromSource === true,
// }

// const env = getGypEnv(options.frameworkInfo, configuration.platform, configuration.arch, options.buildFromSource === true)
// await executeAppBuilderAndWriteJson(["rebuild-node-modules"], configuration, { env, cwd: appDir })
}
if (buildFromSource) {
options.prebuildTagPrefix = "totally-not-a-real-prefix-to-force-rebuild"
}
return electronRebuild.rebuild(options)
}
4 changes: 1 addition & 3 deletions packages/electron-builder/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { InvalidConfigurationError, log } from "builder-util"
import * as chalk from "chalk"
import { getElectronVersion } from "app-builder-lib/out/electron/electronVersion"
import { readJson } from "fs-extra"
import * as isCi from "is-ci"
import * as path from "path"
Expand Down Expand Up @@ -76,7 +75,6 @@ async function checkIsOutdated() {
}

async function rebuildAppNativeCode(args: any) {
const projectDir = process.cwd()
// this script must be used only for electron
return nodeGypRebuild(args.platform, args.arch, { version: await getElectronVersion(projectDir), useCustomDist: true })
return nodeGypRebuild(args.arch)
}

0 comments on commit c10d81b

Please sign in to comment.