node/test/sea/test-build-sea-executable-field.js
Joyee Cheung b935a3970b
sea: add --build-sea to generate SEA directly with Node.js binary
Instead of relying on a WASM build of postject to perform the
injection, add LIEF as dependency and generate the SEA directly
from core via a new CLI option --build-sea which takes the SEA
config. This simplifies SEA generation for users and makes it
easier to debug/maintain the SEA building process.

PR-URL: https://github.com/nodejs/node/pull/61167
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2026-01-22 23:32:50 +01:00

47 lines
1.4 KiB
JavaScript

// This tests --build-sea with the "executable" field pointing to a copied Node.js binary.
'use strict';
require('../common');
const { buildSEA, skipIfBuildSEAIsNotSupported } = require('../common/sea');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { spawnSyncAndAssert } = require('../common/child_process');
const fs = require('fs');
skipIfBuildSEAIsNotSupported();
tmpdir.refresh();
// Copy fixture files to working directory.
const fixtureDir = fixtures.path('sea', 'executable-field');
fs.cpSync(fixtureDir, tmpdir.path, { recursive: true });
// Copy the Node.js executable to the working directory.
const executableName = process.platform === 'win32' ? 'copy.exe' : 'copy';
fs.copyFileSync(process.execPath, tmpdir.resolve(executableName));
// Update the config to use the correct executable name and output extension.
const configPath = tmpdir.resolve('sea-config.json');
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
config.executable = executableName;
if (process.platform === 'win32') {
if (!config.output.endsWith('.exe')) {
config.output += '.exe';
}
}
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
// Build the SEA.
const outputFile = buildSEA(tmpdir.path, { workingDir: tmpdir.path });
spawnSyncAndAssert(
outputFile,
[],
{
cwd: tmpdir.path,
},
{
stdout: 'Hello from SEA with executable field!\n',
},
);