Class: NodePackageBuilder

NodePackageBuilder()

new NodePackageBuilder()

Main class for building Node.js applications into single executable files using SEA (Single Executable Applications)
Supports cross-platform builds for Linux, macOS, and Windows

Source:

Methods

(async) build() → {Promise.<Array.<{platform: string, success: boolean, executable: string, path: string, buildId: string, error: string}>>}

Build executables for all configured platforms

Source:
Returns:

Promise that resolves to an array of build results

Type
Promise.<Array.<{platform: string, success: boolean, executable: string, path: string, buildId: string, error: string}>>

(async) buildForPlatform(platform) → {Promise.<{platform: string, success: boolean, executable: string, path: string, buildId: string}>}

Build executable for a specific platform

Parameters:
Name Type Description
platform string

Target platform ('linux', 'darwin', or 'win32')

Source:
Throws:

If build process fails

Type
Error
Returns:

Promise that resolves to build result

Type
Promise.<{platform: string, success: boolean, executable: string, path: string, buildId: string}>

checkNodeVersion()

Check if current Node.js version meets minimum requirements

Source:
Throws:

If Node.js version is too old

Type
Error

cleanup(files)

Clean up temporary files

Parameters:
Name Type Description
files Array.<string>

Array of file paths to clean up

Source:

cleanupTempDir()

Clean up temporary build directory for this instance

Source:

(async) createExecutable(platform, executableName)

Create executable file for target platform by copying Node.js binary

Parameters:
Name Type Description
platform string

Target platform

executableName string

Name of the executable to create

Source:
Throws:

If executable creation fails

Type
Error

createSeaConfig(platform) → {string}

Create SEA (Single Executable Application) configuration file for a platform

Parameters:
Name Type Description
platform string

Target platform

Source:
Returns:

Path to the created configuration file

Type
string

(async) downloadFile(url, filePath) → {Promise.<void>}

Download file from URL to local path using streaming

Parameters:
Name Type Description
url string

File URL to download

filePath string

Destination file path

Source:
Returns:

Promise that resolves when download completes

Type
Promise.<void>

(async) downloadNodeBinary(platform) → {Promise.<string>}

Download Node.js binary for target platform with caching support

Parameters:
Name Type Description
platform string

Target platform

Source:
Throws:

If download or extraction fails

Type
Error
Returns:

Promise that resolves to path of downloaded Node.js binary

Type
Promise.<string>

ensureTempDir()

Ensure temporary directories exist, creating them if necessary

Source:

(async) extractNodeBinary(archivePath, extractDir, platform, version) → {Promise.<void>}

Extract Node.js binary from archive file (ZIP for Windows, tar.gz for Unix)

Parameters:
Name Type Description
archivePath string

Path to archive file

extractDir string

Directory to extract to

platform string

Target platform

version string

Node.js version

Source:
Returns:

Promise that resolves when extraction completes

Type
Promise.<void>

(async) extractTarGz(tarPath, extractDir, version, platform) → {Promise.<void>}

Extract Node.js binary from tar.gz archive (Unix systems)

Parameters:
Name Type Description
tarPath string

Path to tar.gz file

extractDir string

Directory to extract to

version string

Node.js version

platform string

Target platform

Source:
Returns:

Promise that resolves when extraction completes

Type
Promise.<void>

(async) extractZip(zipPath, extractDir, version, platform) → {Promise.<void>}

Extract Node.js binary from ZIP archive (Windows)

Parameters:
Name Type Description
zipPath string

Path to ZIP file

extractDir string

Directory to extract to

version string

Node.js version

platform string

Target platform

Source:
Returns:

Promise that resolves when extraction completes

Type
Promise.<void>

generateBlob(configPath)

Generate blob file from SEA configuration using Node.js

Parameters:
Name Type Description
configPath string

Path to SEA configuration file

Source:
Throws:

If blob generation fails

Type
Error

generateBuildId() → {string}

Generate a unique build identifier using timestamp and random bytes

Source:
Returns:

Unique build ID string

Type
string

getExecutableName(platform) → {string}

Get executable name for platform with appropriate extension

Parameters:
Name Type Description
platform string

Target platform

Source:
Returns:

Executable name with platform-specific extension

Type
string

getNodeDownloadUrl(version, platform) → {string}

Get download URL for Node.js binary for specific version and platform

Parameters:
Name Type Description
version string

Node.js version

platform string

Target platform

Source:
Throws:

If platform is unsupported

Type
Error
Returns:

Download URL for Node.js binary

Type
string

(async) getRecommendedNodeVersion() → {Promise.<string>}

Get recommended Node.js version from official registry with fallback

Source:
Returns:

Promise that resolves to recommended Node.js version string

Type
Promise.<string>

(async) injectBlob(platform, executableName, blobPath)

Inject blob into executable using postject tool

Parameters:
Name Type Description
platform string

Target platform

executableName string

Name of the executable

blobPath string

Path to the blob file to inject

Source:
Throws:

If blob injection fails

Type
Error

isVersionGreaterOrEqual(current, required) → {boolean}

Compare version strings to determine if current version meets requirements

Parameters:
Name Type Description
current string

Current version string

required string

Required minimum version string

Source:
Returns:

True if current version is greater than or equal to required

Type
boolean

(async) signExecutable(platform, executableName)

Sign executable for distribution (macOS and Windows)

Parameters:
Name Type Description
platform string

Target platform

executableName string

Name of the executable to sign

Source:

(async) verifyWindowsExecutable(executableName)

Verify Windows executable is working correctly and not in REPL mode

Parameters:
Name Type Description
executableName string

Name of the executable to verify

Source:
Throws:

If executable is still in REPL mode

Type
Error

(static) cleanupAllTempDirs()

Clean up all temporary build directories from previous builds

Source:

(static) getSupportedPlatforms() → {Array.<string>}

Get list of supported target platforms

Source:
Returns:

Array of supported platform names

Type
Array.<string>

(static) validateMainFile(mainFile)

Validate that main file exists and is accessible

Parameters:
Name Type Description
mainFile string

Path to main file to validate

Source:
Throws:

If main file is invalid or doesn't exist

Type
Error

NodePackageBuilder(optionsopt)

new NodePackageBuilder(optionsopt)

Create a new NodePackageBuilder instance

Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Build configuration options

Properties
Name Type Attributes Default Description
main string <optional>
'index.js'

Main JavaScript file to build

output string <optional>
'app'

Output executable name

disableExperimentalSEAWarning boolean <optional>
true

Disable experimental SEA warning

useSnapshot boolean <optional>
false

Enable snapshot support

useCodeCache boolean <optional>
false

Enable code cache

assets Object <optional>
{}

Assets to include in the executable

platforms Array.<string> <optional>
['linux', 'darwin', 'win32']

Target platforms to build for

tempDir string <optional>

Temporary directory for build files

Source:

Methods

(async) build() → {Promise.<Array.<{platform: string, success: boolean, executable: string, path: string, buildId: string, error: string}>>}

Build executables for all configured platforms

Source:
Returns:

Promise that resolves to an array of build results

Type
Promise.<Array.<{platform: string, success: boolean, executable: string, path: string, buildId: string, error: string}>>

(async) buildForPlatform(platform) → {Promise.<{platform: string, success: boolean, executable: string, path: string, buildId: string}>}

Build executable for a specific platform

Parameters:
Name Type Description
platform string

Target platform ('linux', 'darwin', or 'win32')

Source:
Throws:

If build process fails

Type
Error
Returns:

Promise that resolves to build result

Type
Promise.<{platform: string, success: boolean, executable: string, path: string, buildId: string}>

checkNodeVersion()

Check if current Node.js version meets minimum requirements

Source:
Throws:

If Node.js version is too old

Type
Error

cleanup(files)

Clean up temporary files

Parameters:
Name Type Description
files Array.<string>

Array of file paths to clean up

Source:

cleanupTempDir()

Clean up temporary build directory for this instance

Source:

(async) createExecutable(platform, executableName)

Create executable file for target platform by copying Node.js binary

Parameters:
Name Type Description
platform string

Target platform

executableName string

Name of the executable to create

Source:
Throws:

If executable creation fails

Type
Error

createSeaConfig(platform) → {string}

Create SEA (Single Executable Application) configuration file for a platform

Parameters:
Name Type Description
platform string

Target platform

Source:
Returns:

Path to the created configuration file

Type
string

(async) downloadFile(url, filePath) → {Promise.<void>}

Download file from URL to local path using streaming

Parameters:
Name Type Description
url string

File URL to download

filePath string

Destination file path

Source:
Returns:

Promise that resolves when download completes

Type
Promise.<void>

(async) downloadNodeBinary(platform) → {Promise.<string>}

Download Node.js binary for target platform with caching support

Parameters:
Name Type Description
platform string

Target platform

Source:
Throws:

If download or extraction fails

Type
Error
Returns:

Promise that resolves to path of downloaded Node.js binary

Type
Promise.<string>

ensureTempDir()

Ensure temporary directories exist, creating them if necessary

Source:

(async) extractNodeBinary(archivePath, extractDir, platform, version) → {Promise.<void>}

Extract Node.js binary from archive file (ZIP for Windows, tar.gz for Unix)

Parameters:
Name Type Description
archivePath string

Path to archive file

extractDir string

Directory to extract to

platform string

Target platform

version string

Node.js version

Source:
Returns:

Promise that resolves when extraction completes

Type
Promise.<void>

(async) extractTarGz(tarPath, extractDir, version, platform) → {Promise.<void>}

Extract Node.js binary from tar.gz archive (Unix systems)

Parameters:
Name Type Description
tarPath string

Path to tar.gz file

extractDir string

Directory to extract to

version string

Node.js version

platform string

Target platform

Source:
Returns:

Promise that resolves when extraction completes

Type
Promise.<void>

(async) extractZip(zipPath, extractDir, version, platform) → {Promise.<void>}

Extract Node.js binary from ZIP archive (Windows)

Parameters:
Name Type Description
zipPath string

Path to ZIP file

extractDir string

Directory to extract to

version string

Node.js version

platform string

Target platform

Source:
Returns:

Promise that resolves when extraction completes

Type
Promise.<void>

generateBlob(configPath)

Generate blob file from SEA configuration using Node.js

Parameters:
Name Type Description
configPath string

Path to SEA configuration file

Source:
Throws:

If blob generation fails

Type
Error

generateBuildId() → {string}

Generate a unique build identifier using timestamp and random bytes

Source:
Returns:

Unique build ID string

Type
string

getExecutableName(platform) → {string}

Get executable name for platform with appropriate extension

Parameters:
Name Type Description
platform string

Target platform

Source:
Returns:

Executable name with platform-specific extension

Type
string

getNodeDownloadUrl(version, platform) → {string}

Get download URL for Node.js binary for specific version and platform

Parameters:
Name Type Description
version string

Node.js version

platform string

Target platform

Source:
Throws:

If platform is unsupported

Type
Error
Returns:

Download URL for Node.js binary

Type
string

(async) getRecommendedNodeVersion() → {Promise.<string>}

Get recommended Node.js version from official registry with fallback

Source:
Returns:

Promise that resolves to recommended Node.js version string

Type
Promise.<string>

(async) injectBlob(platform, executableName, blobPath)

Inject blob into executable using postject tool

Parameters:
Name Type Description
platform string

Target platform

executableName string

Name of the executable

blobPath string

Path to the blob file to inject

Source:
Throws:

If blob injection fails

Type
Error

isVersionGreaterOrEqual(current, required) → {boolean}

Compare version strings to determine if current version meets requirements

Parameters:
Name Type Description
current string

Current version string

required string

Required minimum version string

Source:
Returns:

True if current version is greater than or equal to required

Type
boolean

(async) signExecutable(platform, executableName)

Sign executable for distribution (macOS and Windows)

Parameters:
Name Type Description
platform string

Target platform

executableName string

Name of the executable to sign

Source:

(async) verifyWindowsExecutable(executableName)

Verify Windows executable is working correctly and not in REPL mode

Parameters:
Name Type Description
executableName string

Name of the executable to verify

Source:
Throws:

If executable is still in REPL mode

Type
Error

(static) cleanupAllTempDirs()

Clean up all temporary build directories from previous builds

Source:

(static) getSupportedPlatforms() → {Array.<string>}

Get list of supported target platforms

Source:
Returns:

Array of supported platform names

Type
Array.<string>

(static) validateMainFile(mainFile)

Validate that main file exists and is accessible

Parameters:
Name Type Description
mainFile string

Path to main file to validate

Source:
Throws:

If main file is invalid or doesn't exist

Type
Error