-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: yarn 3 support for native modules via new electron/rebuild comp…
…ilation (#8112)
- Loading branch information
Showing
14 changed files
with
743 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"app-builder-lib": minor | ||
--- | ||
|
||
feat: implementing electron/rebuild with config option `useLegacyRebuilder` default: `true` to support Yarn 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as cp from "child_process" | ||
import * as path from "path" | ||
import { RebuildOptions } from "@electron/rebuild" | ||
import { log } from "builder-util" | ||
|
||
export const rebuild = async (options: RebuildOptions): Promise<void> => { | ||
const { arch } = options | ||
log.info({ arch }, `installing native dependencies`) | ||
|
||
const child = cp.fork(path.resolve(__dirname, "remote-rebuild.js"), [JSON.stringify(options)], { | ||
stdio: ["pipe", "pipe", "pipe", "ipc"], | ||
}) | ||
|
||
let pendingError: Error | ||
|
||
child.stdout?.on("data", chunk => { | ||
log.info(chunk.toString()) | ||
}) | ||
child.stderr?.on("data", chunk => { | ||
log.error(chunk.toString()) | ||
}) | ||
|
||
child.on("message", (message: { msg: string; moduleName: string; err: { message: string; stack: string } }) => { | ||
const { moduleName, msg } = message | ||
switch (msg) { | ||
case "module-found": { | ||
log.info({ moduleName, arch }, "preparing") | ||
break | ||
} | ||
case "module-done": { | ||
log.info({ moduleName, arch }, "finished") | ||
break | ||
} | ||
case "module-skip": { | ||
log.debug?.({ moduleName, arch }, "skipped. set ENV=electron-rebuild to determine why") | ||
break | ||
} | ||
case "rebuild-error": { | ||
pendingError = new Error(message.err.message) | ||
pendingError.stack = message.err.stack | ||
break | ||
} | ||
case "rebuild-done": { | ||
log.info("completed installing native dependencies") | ||
break | ||
} | ||
} | ||
}) | ||
|
||
await new Promise<void>((resolve, reject) => { | ||
child.on("exit", code => { | ||
if (code === 0 && !pendingError) { | ||
resolve() | ||
} else { | ||
reject(pendingError || new Error(`Rebuilder failed with exit code: ${code}`)) | ||
} | ||
}) | ||
}) | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/app-builder-lib/src/util/rebuild/remote-rebuild.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { rebuild, RebuildOptions } from "@electron/rebuild" | ||
|
||
if (!process.send) { | ||
console.error("The remote rebuilder expects to be spawned with an IPC channel") | ||
process.exit(1) | ||
} | ||
|
||
const options: RebuildOptions = JSON.parse(process.argv[2]) | ||
|
||
const rebuilder = rebuild(options) | ||
|
||
rebuilder.lifecycle.on("module-found", (moduleName: string) => process.send?.({ msg: "module-found", moduleName })) | ||
rebuilder.lifecycle.on("module-done", (moduleName: string) => process.send?.({ msg: "module-done", moduleName })) | ||
rebuilder.lifecycle.on("module-skip", (moduleName: string) => process.send?.({ msg: "module-skip", moduleName })) | ||
|
||
rebuilder | ||
.then(() => { | ||
process.send?.({ msg: "rebuild-done" }) | ||
return process.exit(0) | ||
}) | ||
.catch(err => { | ||
process.send?.({ | ||
msg: "rebuild-error", | ||
err: { | ||
message: err.message, | ||
stack: err.stack, | ||
}, | ||
}) | ||
process.exit(0) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.