The initial support for ESM entrypoint in SEA didn't support code cache. This patch implements that by following a path similar to how code cache in CJS SEA entrypoint is supported: at build time we generate the code cache from C++ and put it into the sea blob, and at runtime we consume it via a special case in compilation routines - for CJS this was CompileFunctionForCJSLoader, in the case of SourceTextModule, it's in Module::New. PR-URL: https://github.com/nodejs/node/pull/62158 Refs: https://github.com/nodejs/node/pull/61813 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
34 lines
800 B
JavaScript
34 lines
800 B
JavaScript
'use strict';
|
|
|
|
// This tests the creation of a single executable application with an ESM
|
|
// entry point using "mainFormat": "module" and "useCodeCache": true.
|
|
|
|
require('../common');
|
|
|
|
const {
|
|
buildSEA,
|
|
skipIfBuildSEAIsNotSupported,
|
|
} = require('../common/sea');
|
|
|
|
skipIfBuildSEAIsNotSupported();
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
const fixtures = require('../common/fixtures');
|
|
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
|
|
|
tmpdir.refresh();
|
|
|
|
const outputFile = buildSEA(fixtures.path('sea', 'esm-code-cache'));
|
|
|
|
spawnSyncAndExitWithoutError(
|
|
outputFile,
|
|
{
|
|
env: {
|
|
NODE_DEBUG_NATIVE: 'SEA',
|
|
...process.env,
|
|
},
|
|
},
|
|
{
|
|
stdout: /ESM SEA with code cache executed successfully/,
|
|
stderr: /SEA module code cache accepted/,
|
|
});
|