mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
A single executable application built with "vfsArchive" mounted its archive at the next free layer, like any file system a program mounts itself, and only in the main thread. A worker had no mount at all, so a path into the archive, such as the main script's __filename, could not be loaded there. Mount the archive at the layer reserved for --vfs-load instead, so it is at the same mount point in every thread, and mount it in each worker as well, with the main script placed at its root just as in the main thread. The worker reads the main script through a new getMainCode() binding, since no main script is handed to it. Unlike the --vfs-load source, the archive needs no provider that a preload could register, so its mount in a worker is not deferred past --import. Since the archive takes that mount point, reject --vfs-load alongside it: --build-sea refuses it in "execArgv", and the executable refuses it at startup when it comes from --node-options or from the execArgv of a worker. Also fix the example in vfs.md, which showed a file system a program mounts itself at layer 0, the layer reserved for these mounts. Signed-off-by: Philipp Dunkel <pip@pipobscure.com> PR-URL: https://github.com/nodejs/node/pull/66709 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
82 lines
2.4 KiB
JavaScript
82 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
// This tests the SEA VFS archive integration - a prebuilt ZIP archive of the
|
|
// assets is embedded into the executable and mounted through the ZipProvider.
|
|
|
|
const common = require('../common');
|
|
|
|
const {
|
|
buildSEA,
|
|
skipIfBuildSEAIsNotSupported,
|
|
} = require('../common/sea');
|
|
|
|
skipIfBuildSEAIsNotSupported();
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
const { spawnSyncAndAssert } = require('../common/child_process');
|
|
const fixtures = require('../common/fixtures');
|
|
const { createWriteStream } = require('fs');
|
|
const { pipeline } = require('stream/promises');
|
|
const { zipFiles } = require('zlib');
|
|
|
|
async function main() {
|
|
tmpdir.refresh();
|
|
|
|
// Build the assets archive with the ZIP support of node:zlib. This is what
|
|
// "vfsArchive" users do themselves before running --build-sea.
|
|
const fixture = (...args) => fixtures.path('sea', 'vfs-zip', ...args);
|
|
await pipeline(
|
|
zipFiles([
|
|
[fixture('config.json'), 'config.json'],
|
|
[fixture('greeting.txt'), 'data/greeting.txt'],
|
|
[fixture('math.js'), 'modules/math.js'],
|
|
[fixture('test-pkg-package.json'), 'node_modules/test-pkg/package.json'],
|
|
[fixture('test-pkg-index.js'), 'node_modules/test-pkg/index.js'],
|
|
]),
|
|
createWriteStream(tmpdir.resolve('assets.zip')),
|
|
);
|
|
}
|
|
|
|
main().then(common.mustCall(() => {
|
|
const outputFile = buildSEA(fixtures.path('sea', 'vfs-zip'));
|
|
|
|
spawnSyncAndAssert(
|
|
outputFile,
|
|
{
|
|
env: {
|
|
...process.env,
|
|
NODE_DEBUG_NATIVE: undefined,
|
|
},
|
|
},
|
|
{
|
|
stdout: /All SEA VFS zip tests passed!/,
|
|
stderr(stderr) {
|
|
if (/ExperimentalWarning: VirtualFileSystem/.test(stderr)) {
|
|
throw new Error('SEA VFS should not emit the public VirtualFileSystem warning');
|
|
}
|
|
},
|
|
},
|
|
);
|
|
|
|
// The archive is mounted where --vfs-load would mount its source, so the
|
|
// executable rejects --vfs-load at startup. --build-sea already refuses it
|
|
// in "execArgv", so pass it through --node-options instead.
|
|
const rejectedFile = buildSEA(fixtures.path('sea', 'vfs-zip'), {
|
|
configPath: 'sea-config-vfs-load-rejected.json',
|
|
});
|
|
spawnSyncAndAssert(
|
|
rejectedFile,
|
|
['--node-options=--experimental-vfs --vfs-load=assets.zip'],
|
|
{
|
|
env: {
|
|
...process.env,
|
|
NODE_DEBUG_NATIVE: undefined,
|
|
},
|
|
},
|
|
{
|
|
status: 9,
|
|
stderr: /--vfs-load cannot be used in a single executable application built with "vfsArchive"/,
|
|
},
|
|
);
|
|
}));
|