-
Notifications
You must be signed in to change notification settings - Fork 0
Improve Electron rebuild error handling #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,21 +11,88 @@ const path = require('node:path'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const version = process.argv[2] || process.env.ELECTRON_VERSION || process.env.npm_config_target; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!version) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('[soem-node] Veuillez fournir la version d\'Electron (ex: 30.0.0).'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("[soem-node] Veuillez fournir la version d'Electron (ex: 30.0.0)."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(' Ex: node scripts/rebuild-electron.js 30.0.0'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.exit(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`[soem-node] Rebuild pour Electron v${version}...`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isWin = process.platform === 'win32'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cmakeJs = isWin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? path.join(__dirname, '..', 'node_modules', '.bin', 'cmake-js.cmd') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : 'npx'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const sharedArgs = ['--runtime=electron', `--runtimeVersion=${version}`, '--loglevel=verbose']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const localBinary = path.join( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __dirname, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '..', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'node_modules', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.bin', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isWin ? 'cmake-js.cmd' : 'cmake-js', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const args = isWin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? ['rebuild', '--runtime=electron', `--runtimeVersion=${version}`, '--loglevel=verbose'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : ['cmake-js', 'rebuild', '--runtime=electron', `--runtimeVersion=${version}`, '--loglevel=verbose']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const spawnOptions = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdio: 'pipe', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shell: isWin, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const res = spawnSync(cmakeJs, args, { stdio: 'inherit', shell: isWin }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.exit(res.status || 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pipeResult = (result) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.stdout?.length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.stdout.write(result.stdout); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.stderr?.length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.stderr.write(result.stderr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const formatCommand = (command, args) => [command, ...args].join(' '); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleFailure = (commandLabel, result) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let errorMessage = `[soem-node] Échec de l'exécution de ${commandLabel}.`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage += ` ${result.error.message}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (typeof result.status === 'number') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage += ` Code de sortie: ${result.status}.`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (result.signal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage += ` Signal reçu: ${result.signal}.`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const stderrOutput = result.stderr?.toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stderrOutput) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errorMessage += `\n--- stderr ---\n${stderrOutput.trimEnd()}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(errorMessage); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.exit(result.status || 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const execute = (command, args) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = spawnSync(command, args, spawnOptions); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pipeResult(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isWin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const args = ['rebuild', ...sharedArgs]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = execute(localBinary, args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.error || result.status !== 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleFailure(formatCommand(localBinary, args), result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.exit(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const npxArgs = ['cmake-js', 'rebuild', ...sharedArgs]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let result = execute('npx', npxArgs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.error?.code === 'ENOENT') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.warn("[soem-node] 'npx' est indisponible, tentative avec le binaire local cmake-js."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const directArgs = ['rebuild', ...sharedArgs]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = execute(localBinary, directArgs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.error || result.status !== 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleFailure(formatCommand(localBinary, directArgs), result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.exit(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.error || result.status !== 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleFailure(formatCommand('npx', npxArgs), result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+82
to
+95
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let result = execute('npx', npxArgs); | |
| if (result.error?.code === 'ENOENT') { | |
| console.warn("[soem-node] 'npx' est indisponible, tentative avec le binaire local cmake-js."); | |
| const directArgs = ['rebuild', ...sharedArgs]; | |
| result = execute(localBinary, directArgs); | |
| if (result.error || result.status !== 0) { | |
| handleFailure(formatCommand(localBinary, directArgs), result); | |
| } | |
| process.exit(0); | |
| } | |
| if (result.error || result.status !== 0) { | |
| handleFailure(formatCommand('npx', npxArgs), result); | |
| let npxResult = execute('npx', npxArgs); | |
| if (npxResult.error?.code === 'ENOENT') { | |
| console.warn("[soem-node] 'npx' est indisponible, tentative avec le binaire local cmake-js."); | |
| const directArgs = ['rebuild', ...sharedArgs]; | |
| const directResult = execute(localBinary, directArgs); | |
| if (directResult.error || directResult.status !== 0) { | |
| handleFailure(formatCommand(localBinary, directArgs), directResult); | |
| } | |
| process.exit(0); | |
| } | |
| if (npxResult.error || npxResult.status !== 0) { | |
| handleFailure(formatCommand('npx', npxArgs), npxResult); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The quote character has been changed from a backtick to a straight quote, which may cause display inconsistency. Consider keeping the original quote style for consistency.