Skip to content

Commit 8769e82

Browse files
committed
refactor(sea): remove buildSeaBlob, let binject handle blob generation
Removed the buildSeaBlob() function that was generating SEA blobs using the host Node.js (e.g., v25.5.0) to generate blobs for node-smol targets (e.g., v24.10.0). binject now handles blob generation automatically when --sea points to a .json config file, using the target binary's Node.js version. This is critical for useCodeCache support since code cache is version-specific. Changes: - Removed buildSeaBlob() from builder.mjs (50+ lines) - Updated test-sea.mjs to pass configPath instead of blobPath - Added explanatory comments about config-based blob generation
1 parent 5c7abcf commit 8769e82

File tree

2 files changed

+22
-60
lines changed

2 files changed

+22
-60
lines changed

packages/cli/scripts/sea-build-utils/builder.mjs

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -88,56 +88,18 @@ export async function generateSeaConfig(entryPoint, outputPath) {
8888
// c8 ignore stop
8989

9090
// =============================================================================
91-
// Section 2: SEA Blob Generation.
91+
// Section 2: SEA Blob Generation (handled by binject).
9292
// =============================================================================
9393

94-
/**
95-
* Build SEA blob from configuration file.
96-
* Uses the current Node.js process instead of the target binary to avoid issues
97-
* with cross-platform builds and potentially corrupted downloaded binaries.
98-
*
99-
* The blob format is platform-independent, so we can safely use the host Node.js
100-
* process to generate blobs for any target platform. This approach:
101-
* 1. Enables cross-platform builds (e.g., building Windows binary on macOS).
102-
* 2. Avoids issues with downloaded node-smol binaries that may not run on host.
103-
* 3. Uses the most reliable Node.js binary available (current process).
104-
*
105-
* @param {string} configPath - Absolute path to sea-config.json file.
106-
* @returns Promise resolving to absolute path of generated blob file.
107-
*
108-
* @example
109-
* const blobPath = await buildSeaBlob('dist/sea/sea-config-socket-darwin-arm64.json')
110-
* // Returns: dist/sea/sea-blob-socket-darwin-arm64.blob
111-
*/
112-
// c8 ignore start - Requires spawning node binary with experimental SEA config.
113-
export async function buildSeaBlob(configPath) {
114-
const config = JSON.parse(await fs.readFile(configPath, 'utf8'))
115-
const blobPath = config.output
116-
117-
// Generate the blob using the current Node.js process.
118-
// We use process.execPath (the current Node) instead of the target binary because:
119-
// 1. The blob format is platform-independent.
120-
// 2. Downloaded node-smol binaries may have issues running on the host system.
121-
// 3. Cross-platform builds wouldn't work (e.g., building Windows binary on macOS).
122-
const spawnPromise = spawn(
123-
process.execPath,
124-
['--experimental-sea-config', configPath],
125-
{ stdio: 'inherit' },
126-
)
127-
128-
const result = await spawnPromise
129-
if (
130-
result &&
131-
typeof result === 'object' &&
132-
'exitCode' in result &&
133-
result.exitCode !== 0
134-
) {
135-
throw new Error(`Failed to generate SEA blob: exit code ${result.exitCode}`)
136-
}
137-
138-
return blobPath
139-
}
140-
// c8 ignore stop
94+
// Blob generation is now handled automatically by binject when --sea points to
95+
// a .json config file. The previous buildSeaBlob() function has been removed
96+
// because binject can generate the blob using the target binary's Node.js version,
97+
// which is critical for useCodeCache support (code cache is version-specific).
98+
//
99+
// This eliminates the Node.js version mismatch issue where we were using the host
100+
// Node.js (e.g., v25.5.0) to generate blobs for node-smol targets (e.g., v24.10.0).
101+
//
102+
// See injectSeaBlob() below for the config-based blob generation implementation.
141103

142104
// =============================================================================
143105
// Section 3: Binary Injection.

packages/cli/scripts/test-sea.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,7 @@ async function runWithToolsMode(platform, toolPaths) {
422422

423423
// Dynamic import Socket modules.
424424
const { getDefaultLogger } = await import('@socketsecurity/lib/logger')
425-
const { buildSeaBlob, injectSeaBlob } = await import(
426-
'./sea-build-utils/builder.mjs'
427-
)
425+
const { injectSeaBlob } = await import('./sea-build-utils/builder.mjs')
428426
const { downloadNodeBinary } = await import(
429427
'./sea-build-utils/downloads.mjs'
430428
)
@@ -472,12 +470,6 @@ async function runWithToolsMode(platform, toolPaths) {
472470

473471
await fs.writeFile(configPath, JSON.stringify(config, null, 2))
474472
logger.log(`Wrote SEA config: ${configPath}`)
475-
476-
// Build SEA blob.
477-
logger.log('Generating SEA blob...')
478-
await buildSeaBlob(configPath)
479-
const blobStats = await fs.stat(blobPath)
480-
logger.log(`Blob size: ${(blobStats.size / 1024 / 1024).toFixed(2)} MB`)
481473
logger.log('')
482474

483475
// Download node-smol binary.
@@ -494,10 +486,18 @@ async function runWithToolsMode(platform, toolPaths) {
494486
)
495487
logger.log('')
496488

497-
// Inject blob into node binary.
498-
logger.log('Injecting blob into node binary...')
489+
// Inject blob and VFS into binary.
490+
// binject will generate the blob automatically using the target binary's
491+
// Node.js version when --sea points to a config file.
492+
logger.log('Generating SEA blob and injecting into binary...')
499493
const cacheId = platform
500-
await injectSeaBlob(nodeBinary, blobPath, outputPath, cacheId)
494+
await injectSeaBlob(nodeBinary, configPath, outputPath, cacheId)
495+
496+
// Get blob size after it's generated by binject.
497+
if (existsSync(blobPath)) {
498+
const blobStats = await fs.stat(blobPath)
499+
logger.log(`Blob size: ${(blobStats.size / 1024 / 1024).toFixed(2)} MB`)
500+
}
501501

502502
// Results.
503503
const finalStats = await fs.stat(outputPath)

0 commit comments

Comments
 (0)