Programmatic SEA blob generation API
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
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',
}
);
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với API node:sea hiện có và luồng tạo --experimental-sea-config được mô tả trong issue, sau đó lần theo cách CLI tạo các blob SEA. Công việc được xem là hoàn tất khi một API JavaScript có thể tạo nội dung blob tương đương từ cấu hình được đề xuất mà không tạo các tệp cấu hình và blob tạm thời.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- api, tooling
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100