MCPcopy Index your code
hub / github.com/nodejs/node / generateSEA

Function generateSEA

test/common/sea.js:136–203  ·  view source on GitHub ↗
(fixtureDir, options = {})

Source from the content-addressed store, hash-verified

134}
135
136function generateSEA(fixtureDir, options = {}) {
137 const {
138 workingDir = tmpdir.path,
139 configPath = 'sea-config.json',
140 verifyWorkflow = false,
141 } = options;
142 // Copy fixture files to working directory if they are different.
143 if (fixtureDir !== workingDir) {
144 fs.cpSync(fixtureDir, workingDir, { recursive: true });
145 }
146
147 // Determine the output executable path.
148 const outputFile = path.resolve(workingDir, process.platform === 'win32' ? 'sea.exe' : 'sea');
149
150 try {
151 // Copy the executable.
152 copyFileSync(process.execPath, outputFile);
153 console.log(`Copied ${process.execPath} to ${outputFile}`);
154 } catch (e) {
155 const message = `Cannot copy ${process.execPath} to ${outputFile}: ${inspect(e)}`;
156 if (verifyWorkflow) {
157 throw new Error(message, { cause: e });
158 }
159 common.skip(message);
160 }
161
162 // Generate the blob using --experimental-sea-config.
163 spawnSyncAndExitWithoutError(
164 process.execPath,
165 ['--experimental-sea-config', configPath],
166 {
167 cwd: workingDir,
168 env: {
169 NODE_DEBUG_NATIVE: 'SEA',
170 ...process.env,
171 },
172 },
173 );
174
175 // Parse the config to get the output file path.
176 const config = JSON.parse(fs.readFileSync(path.resolve(workingDir, configPath)));
177 assert.strictEqual(typeof config.output, 'string');
178 const seaPrepBlob = path.resolve(workingDir, config.output);
179 assert(fs.existsSync(seaPrepBlob), `Expected SEA blob ${seaPrepBlob} to exist`);
180
181 // Use postject to inject the blob.
182 const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js');
183 try {
184 spawnSyncAndExitWithoutError(process.execPath, [
185 postjectFile,
186 outputFile,
187 'NODE_SEA_BLOB',
188 seaPrepBlob,
189 '--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
190 ...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [],
191 ]);
192 } catch (e) {
193 const message = `Cannot inject ${seaPrepBlob} into ${outputFile}: ${inspect(e)}`;

Callers 2

test.jsFile · 0.85

Calls 12

signSEAFunction · 0.85
parseMethod · 0.65
copyFileSyncFunction · 0.50
inspectFunction · 0.50
assertFunction · 0.50
resolveMethod · 0.45
logMethod · 0.45
skipMethod · 0.45
readFileSyncMethod · 0.45
existsSyncMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…