nodejs / nodejs/node

Programmatic SEA blob generation API

オープン
#52,777 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature request single-executable stale
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Currently, CLI commands and many files are involved in generating a SEA using Javascript.

For example:

import { execSync } from 'node:child_process';
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs';
import { inject } from 'postject';

const blobPath = 'path/to/sea.blob',
	configPath = 'path/to/sea.json',
	outputPath = 'path/to/executable';

writeFileSync(
	configPath,
	JSON.stringify({
		main: 'path/to/main.js',
		output: blobPath,
		disableExperimentalSEAWarning: true,
	})
);
execSync('node --experimental-sea-config ' + configPath, { stdio: 'inherit' });
copyFileSync(process.execPath, outputPath);
await inject(outputPath, 'NODE_SEA_BLOB', readFileSync(blobPath), {
	machoSegmentName: 'NODE_SEA',
	sentinelFuse: 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
});

It would be nice if Node.js provided a Javascript API for generating SEA blobs. This would eliminate extra file creation and streamline the SEA creation process. I propose adding a function to the node:sea module/API (Typescript used for clarity):

/**
 * Configuration options for generating a SEA blob
 * @see https://nodejs.org/api/single-executable-applications.html#generating-single-executable-preparation-blobs
 */
interface BlobConfiguration {
	main: string;
	disableExperimentalSEAWarning?: boolean;
	useSnapshot?: boolean;
	useCodeCache?: boolean;
	assets?: Record<string, string>;
}

/**
 * Generates a SEA blob to be injected into an executable
 * @param config configuration options for the blob
 * @returns The blob contents in a buffer
 */
function generateBlob(config: BlobConfiguration): Buffer;

This new function in the SEA API would allow for more streamlined and readable code:

import { copyFileSync } from 'node:fs';
import { generateBlob } from 'node:sea';
import { inject } from 'postject';

const outputPath = 'path/to/executable';

const blob = generateBlob({
	main: 'path/to/main.js',
	disableExperimentalSEAWarning: true,
});
copyFileSync(process.execPath, outputPath);
await inject(outputPath, 'NODE_SEA_BLOB', blob, {
	machoSegmentName: 'NODE_SEA',
	sentinelFuse: 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
});

Which could even be inlined:

import { copyFileSync } from 'node:fs';
import { generateBlob } from 'node:sea';
import { inject } from 'postject';

const outputPath = 'path/to/executable';

copyFileSync(process.execPath, outputPath);
await inject(
	outputPath,
	'NODE_SEA_BLOB',
	generateBlob({
		main: 'path/to/main.js',
		disableExperimentalSEAWarning: true,
	}),
	{
		machoSegmentName: 'NODE_SEA',
		sentinelFuse: 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
	}
);

Discussion
Issue on nodejs/single-executable

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

既存の node:sea API と、issue に記載されている --experimental-sea-config の生成フローから始め、CLI が SEA blob を生成する仕組みを追跡します。提案された設定から同等の blob 内容を一時的な設定ファイルや blob ファイルを作成せずに生成できる JavaScript API が実現すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
api, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。