Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ npm install --runtime=electron --target=30.0.0

Le script `rebuild:electron` appelle `cmake-js rebuild --runtime=electron --runtimeVersion=<version>`. Pendant `npm install`, si vous passez `--runtime=electron --target=<version>`, le script `postinstall` détecte Electron et reconstruit automatiquement.

En cas d'échec, `npm run rebuild:electron` renvoie désormais un code de sortie non nul et affiche les erreurs de `cmake-js` pour faciliter le diagnostic. Sur les systèmes POSIX où `npx` est indisponible, le script bascule automatiquement sur le binaire `cmake-js` local installé avec le projet.

2) Chargement du binaire dans Electron

- Le chargement utilise le paquet `bindings` pour localiser `soem_addon.node`, compatible avec les bundles Electron et `asarUnpack`.
Expand Down
85 changes: 76 additions & 9 deletions scripts/rebuild-electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).");
Copy link

Copilot AI Sep 22, 2025

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.

Suggested change
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).`);

Copilot uses AI. Check for mistakes.
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',
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'pipe' stdio mode and then manually piping output may be less efficient than using 'inherit' for real-time output streaming, especially for long-running cmake operations.

Copilot uses AI. Check for mistakes.
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);
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The variable 'result' is reassigned in the fallback logic (line 87), which could make the code harder to follow. Consider using different variable names for clarity.

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The variable 'result' is reassigned in the fallback logic (line 87), which could make the code harder to follow. Consider using different variable names for clarity.

Suggested change
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);

Copilot uses AI. Check for mistakes.
}

process.exit(0);
Loading