mirror of
https://github.com/nodejs/node.git
synced 2026-12-04 22:58:46 -05:00
PR-URL: https://github.com/nodejs/node/pull/59582 Fixes: https://github.com/nodejs/node/issues/60611 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
'use strict';
|
|
// This tests that SEA can load addons packaged as assets by writing them to disk
|
|
// and loading them via process.dlopen().
|
|
const common = require('../../common');
|
|
const { generateSEA, skipIfSingleExecutableIsNotSupported } = require('../../common/sea');
|
|
|
|
skipIfSingleExecutableIsNotSupported();
|
|
|
|
const assert = require('assert');
|
|
|
|
const tmpdir = require('../../common/tmpdir');
|
|
const { copyFileSync, writeFileSync, existsSync, rmSync } = require('fs');
|
|
const {
|
|
spawnSyncAndExitWithoutError,
|
|
spawnSyncAndAssert,
|
|
} = require('../../common/child_process');
|
|
const { join } = require('path');
|
|
const configFile = tmpdir.resolve('sea-config.json');
|
|
const seaPrepBlob = tmpdir.resolve('sea-prep.blob');
|
|
const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'sea');
|
|
tmpdir.refresh();
|
|
|
|
// Copy test fixture to working directory
|
|
const addonPath = join(__dirname, 'build', common.buildType, 'binding.node');
|
|
const copiedAddonPath = tmpdir.resolve('binding.node');
|
|
copyFileSync(addonPath, copiedAddonPath);
|
|
writeFileSync(tmpdir.resolve('sea.js'), `
|
|
const sea = require('node:sea');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const addonPath = path.join(${JSON.stringify(tmpdir.path)}, 'hello.node');
|
|
fs.writeFileSync(addonPath, new Uint8Array(sea.getRawAsset('hello.node')));
|
|
const mod = {exports: {}}
|
|
process.dlopen(mod, addonPath);
|
|
console.log('hello,', mod.exports.hello());
|
|
`, 'utf-8');
|
|
|
|
writeFileSync(configFile, `
|
|
{
|
|
"main": "sea.js",
|
|
"output": "sea-prep.blob",
|
|
"disableExperimentalSEAWarning": true,
|
|
"assets": {
|
|
"hello.node": "binding.node"
|
|
}
|
|
}
|
|
`, 'utf8');
|
|
|
|
spawnSyncAndExitWithoutError(
|
|
process.execPath,
|
|
['--experimental-sea-config', 'sea-config.json'],
|
|
{ cwd: tmpdir.path },
|
|
);
|
|
assert(existsSync(seaPrepBlob));
|
|
|
|
generateSEA(outputFile, process.execPath, seaPrepBlob);
|
|
|
|
// Remove the copied addon after it's been packaged into the SEA blob
|
|
rmSync(copiedAddonPath, { force: true });
|
|
|
|
spawnSyncAndAssert(
|
|
outputFile,
|
|
[],
|
|
{
|
|
env: {
|
|
...process.env,
|
|
NODE_DEBUG_NATIVE: 'SEA',
|
|
},
|
|
cwd: tmpdir.path,
|
|
},
|
|
{
|
|
stdout: /hello, world/,
|
|
},
|
|
);
|