(
buildPath: string,
electronVersion: string,
platform: ForgePlatform,
arch: ForgeArch,
config: Partial<RebuildOptions> = {},
task: ForgeListrTask<Ctx>,
taskTitlePrefix = '',
)
| 9 | } from '@electron-forge/shared-types'; |
| 10 | |
| 11 | export const listrCompatibleRebuildHook = async <Ctx = never>( |
| 12 | buildPath: string, |
| 13 | electronVersion: string, |
| 14 | platform: ForgePlatform, |
| 15 | arch: ForgeArch, |
| 16 | config: Partial<RebuildOptions> = {}, |
| 17 | task: ForgeListrTask<Ctx>, |
| 18 | taskTitlePrefix = '', |
| 19 | ): Promise<void> => { |
| 20 | task.title = `${taskTitlePrefix}Preparing native dependencies`; |
| 21 | |
| 22 | const options: RebuildOptions = { |
| 23 | ...config, |
| 24 | buildPath, |
| 25 | electronVersion, |
| 26 | arch, |
| 27 | }; |
| 28 | |
| 29 | const child = cp.fork( |
| 30 | path.resolve(__dirname, 'remote-rebuild.js'), |
| 31 | [JSON.stringify(options)], |
| 32 | { |
| 33 | stdio: ['pipe', 'pipe', 'pipe', 'ipc'], |
| 34 | }, |
| 35 | ); |
| 36 | |
| 37 | let pendingError: Error; |
| 38 | let found = 0; |
| 39 | let done = 0; |
| 40 | |
| 41 | const redraw = () => { |
| 42 | task.title = `${taskTitlePrefix}Preparing native dependencies: ${done} / ${found}`; |
| 43 | }; |
| 44 | |
| 45 | child.stdout?.on('data', (chunk) => { |
| 46 | task.output = chunk.toString(); |
| 47 | }); |
| 48 | child.stderr?.on('data', (chunk) => { |
| 49 | task.output = chunk.toString(); |
| 50 | }); |
| 51 | |
| 52 | child.on( |
| 53 | 'message', |
| 54 | (message: { msg: string; err: { message: string; stack: string } }) => { |
| 55 | switch (message.msg) { |
| 56 | case 'module-found': { |
| 57 | found += 1; |
| 58 | redraw(); |
| 59 | break; |
| 60 | } |
| 61 | case 'module-done': { |
| 62 | done += 1; |
| 63 | redraw(); |
| 64 | break; |
| 65 | } |
| 66 | case 'rebuild-error': { |
| 67 | pendingError = new Error(message.err.message); |
| 68 | pendingError.stack = message.err.stack; |
no test coverage detected