seabox 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/blob.mjs CHANGED
@@ -1,104 +1,104 @@
1
- /**
2
- * blob.mjs
3
- * Create SEA configuration JSON and prepare blob for injection.
4
- */
5
-
6
- import fs from 'fs';
7
- import path from 'path';
8
- import { execFile } from 'child_process';
9
- import { promisify } from 'util';
10
- import * as diag from './diagnostics.mjs';
11
-
12
- const execFileAsync = promisify(execFile);
13
-
14
- /**
15
- * @typedef {Object} SeaBlobConfig
16
- * @property {string} main - Path to the entry script
17
- * @property {string} output - Output blob filename
18
- * @property {boolean} disableExperimentalSEAWarning - Suppress SEA warning
19
- * @property {boolean} useSnapshot - Enable V8 snapshot
20
- * @property {boolean} useCodeCache - Enable V8 code cache
21
- * @property {Object.<string, string|Buffer>} assets - Asset key -> content map
22
- */
23
-
24
- /**
25
- * Create the SEA configuration object for Node.js SEA tooling.
26
- * @param {string} entryScript - Path to the bundled entry script
27
- * @param {string} outputBlob - Output blob filename
28
- * @param {Array} assets - All assets to embed
29
- * @param {Object} config - SEA configuration
30
- * @returns {SeaBlobConfig}
31
- */
32
- export function createSeaConfig(entryScript, outputBlob, assets, config) {
33
- const seaConfig = {
34
- main: entryScript,
35
- output: outputBlob,
36
- disableExperimentalSEAWarning: config.disableExperimentalSEAWarning ?? true,
37
- useSnapshot: config.useSnapshot ?? false,
38
- useCodeCache: config.useCodeCache ?? false,
39
- assets: {}
40
- };
41
-
42
- // Add all assets as key -> buffer mappings
43
- for (const asset of assets) {
44
- // Handle inline content (e.g., manifest) vs file-based assets
45
- const content = asset.content
46
- ? asset.content
47
- : fs.readFileSync(asset.sourcePath);
48
- seaConfig.assets[asset.assetKey] = content;
49
- }
50
-
51
- return seaConfig;
52
- }
53
-
54
- /**
55
- * Write the SEA configuration to a JSON file.
56
- * This config file is consumed by `node --experimental-sea-config`.
57
- * @param {SeaBlobConfig} seaConfig
58
- * @param {string} outputPath - Path to write the config JSON
59
- * @param {Array} assets - Original asset entries
60
- * @param {string} tempDir - Temporary directory for inline assets
61
- */
62
- export function writeSeaConfigJson(seaConfig, outputPath, assets, tempDir) {
63
- // Node's SEA config expects asset values to be file paths (raw assets)
64
- const jsonConfig = {
65
- main: seaConfig.main,
66
- output: seaConfig.output,
67
- disableExperimentalSEAWarning: seaConfig.disableExperimentalSEAWarning,
68
- useSnapshot: seaConfig.useSnapshot,
69
- useCodeCache: seaConfig.useCodeCache,
70
- assets: {}
71
- };
72
-
73
- // Map asset keys to file paths
74
- for (const asset of assets) {
75
- if (asset.content) {
76
- // Inline content (e.g., manifest) - write to temp file
77
- const tempFilePath = path.join(tempDir, asset.assetKey.replace(/\//g, '_'));
78
- fs.mkdirSync(path.dirname(tempFilePath), { recursive: true });
79
- fs.writeFileSync(tempFilePath, asset.content);
80
- jsonConfig.assets[asset.assetKey] = tempFilePath;
81
- } else {
82
- // File-based asset - use source path
83
- jsonConfig.assets[asset.assetKey] = asset.sourcePath;
84
- }
85
- }
86
-
87
- fs.writeFileSync(outputPath, JSON.stringify(jsonConfig, null, 2), 'utf8');
88
- }
89
-
90
- /**
91
- * Generate the SEA blob using Node.js CLI.
92
- * Executes: node --experimental-sea-config sea-config.json
93
- * @param {string} seaConfigPath - Path to the SEA config JSON
94
- * @param {string} nodeBinary - Path to the Node.js binary to use
95
- * @returns {Promise<void>}
96
- */
97
- export async function generateBlob(seaConfigPath, nodeBinary = process.execPath) {
98
- try {
99
- await execFileAsync(nodeBinary, ['--experimental-sea-config', seaConfigPath]);
100
- diag.verbose('SEA blob generated successfully', 2);
101
- } catch (error) {
102
- throw new Error(`Failed to generate SEA blob: ${error.message}`);
103
- }
104
- }
1
+ /**
2
+ * blob.mjs
3
+ * Create SEA configuration JSON and prepare blob for injection.
4
+ */
5
+
6
+ import fs from 'fs';
7
+ import path from 'path';
8
+ import { execFile } from 'child_process';
9
+ import { promisify } from 'util';
10
+ import * as diag from './diagnostics.mjs';
11
+
12
+ const execFileAsync = promisify(execFile);
13
+
14
+ /**
15
+ * @typedef {Object} SeaBlobConfig
16
+ * @property {string} main - Path to the entry script
17
+ * @property {string} output - Output blob filename
18
+ * @property {boolean} disableExperimentalSEAWarning - Suppress SEA warning
19
+ * @property {boolean} useSnapshot - Enable V8 snapshot
20
+ * @property {boolean} useCodeCache - Enable V8 code cache
21
+ * @property {Object.<string, string|Buffer>} assets - Asset key -> content map
22
+ */
23
+
24
+ /**
25
+ * Create the SEA configuration object for Node.js SEA tooling.
26
+ * @param {string} entryScript - Path to the bundled entry script
27
+ * @param {string} outputBlob - Output blob filename
28
+ * @param {Array} assets - All assets to embed
29
+ * @param {Object} config - SEA configuration
30
+ * @returns {SeaBlobConfig}
31
+ */
32
+ export function createSeaConfig(entryScript, outputBlob, assets, config) {
33
+ const seaConfig = {
34
+ main: entryScript,
35
+ output: outputBlob,
36
+ disableExperimentalSEAWarning: config.disableExperimentalSEAWarning ?? true,
37
+ useSnapshot: config.useSnapshot ?? false,
38
+ useCodeCache: config.useCodeCache ?? false,
39
+ assets: {}
40
+ };
41
+
42
+ // Add all assets as key -> buffer mappings
43
+ for (const asset of assets) {
44
+ // Handle inline content (e.g., manifest) vs file-based assets
45
+ const content = asset.content
46
+ ? asset.content
47
+ : fs.readFileSync(asset.sourcePath);
48
+ seaConfig.assets[asset.assetKey] = content;
49
+ }
50
+
51
+ return seaConfig;
52
+ }
53
+
54
+ /**
55
+ * Write the SEA configuration to a JSON file.
56
+ * This config file is consumed by `node --experimental-sea-config`.
57
+ * @param {SeaBlobConfig} seaConfig
58
+ * @param {string} outputPath - Path to write the config JSON
59
+ * @param {Array} assets - Original asset entries
60
+ * @param {string} tempDir - Temporary directory for inline assets
61
+ */
62
+ export function writeSeaConfigJson(seaConfig, outputPath, assets, tempDir) {
63
+ // Node's SEA config expects asset values to be file paths (raw assets)
64
+ const jsonConfig = {
65
+ main: seaConfig.main,
66
+ output: seaConfig.output,
67
+ disableExperimentalSEAWarning: seaConfig.disableExperimentalSEAWarning,
68
+ useSnapshot: seaConfig.useSnapshot,
69
+ useCodeCache: seaConfig.useCodeCache,
70
+ assets: {}
71
+ };
72
+
73
+ // Map asset keys to file paths
74
+ for (const asset of assets) {
75
+ if (asset.content) {
76
+ // Inline content (e.g., manifest) - write to temp file
77
+ const tempFilePath = path.join(tempDir, asset.assetKey.replace(/\//g, '_'));
78
+ fs.mkdirSync(path.dirname(tempFilePath), { recursive: true });
79
+ fs.writeFileSync(tempFilePath, asset.content);
80
+ jsonConfig.assets[asset.assetKey] = tempFilePath;
81
+ } else {
82
+ // File-based asset - use source path
83
+ jsonConfig.assets[asset.assetKey] = asset.sourcePath;
84
+ }
85
+ }
86
+
87
+ fs.writeFileSync(outputPath, JSON.stringify(jsonConfig, null, 2), 'utf8');
88
+ }
89
+
90
+ /**
91
+ * Generate the SEA blob using Node.js CLI.
92
+ * Executes: node --experimental-sea-config sea-config.json
93
+ * @param {string} seaConfigPath - Path to the SEA config JSON
94
+ * @param {string} nodeBinary - Path to the Node.js binary to use
95
+ * @returns {Promise<void>}
96
+ */
97
+ export async function generateBlob(seaConfigPath, nodeBinary = process.execPath) {
98
+ try {
99
+ await execFileAsync(nodeBinary, ['--experimental-sea-config', seaConfigPath]);
100
+ diag.verbose('SEA blob generated successfully', 2);
101
+ } catch (error) {
102
+ throw new Error(`Failed to generate SEA blob: ${error.message}`);
103
+ }
104
+ }