@hakobu/hakobu 1.0.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.
Files changed (284) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +673 -0
  3. package/dictionary/angular-bridge.js +3 -0
  4. package/dictionary/any-promise.js +3 -0
  5. package/dictionary/async.js +3 -0
  6. package/dictionary/aws-sdk.js +7 -0
  7. package/dictionary/babel-core.js +3 -0
  8. package/dictionary/batch.js +3 -0
  9. package/dictionary/bcrypt.js +3 -0
  10. package/dictionary/better-sqlite3.js +3 -0
  11. package/dictionary/bignum.js +3 -0
  12. package/dictionary/bindings.js +3 -0
  13. package/dictionary/blessed.js +8 -0
  14. package/dictionary/body-parser.js +9 -0
  15. package/dictionary/browserify.js +7 -0
  16. package/dictionary/bson.js +3 -0
  17. package/dictionary/buffermaker.js +7 -0
  18. package/dictionary/bunyan.js +9 -0
  19. package/dictionary/busboy.js +7 -0
  20. package/dictionary/bytes.js +3 -0
  21. package/dictionary/callsites.js +3 -0
  22. package/dictionary/chokidar.js +3 -0
  23. package/dictionary/coffee-script.js +7 -0
  24. package/dictionary/colors.js +3 -0
  25. package/dictionary/compression.js +3 -0
  26. package/dictionary/compressjs.js +7 -0
  27. package/dictionary/connect-mongo.js +3 -0
  28. package/dictionary/connect-mongodb.js +3 -0
  29. package/dictionary/connect-redis.js +3 -0
  30. package/dictionary/connect.js +10 -0
  31. package/dictionary/consolidate.js +3 -0
  32. package/dictionary/cookie-parser.js +3 -0
  33. package/dictionary/cookie.js +3 -0
  34. package/dictionary/cors.js +3 -0
  35. package/dictionary/cron.js +3 -0
  36. package/dictionary/cross-env.js +11 -0
  37. package/dictionary/cross-spawn-async.js +3 -0
  38. package/dictionary/curve25519.js +3 -0
  39. package/dictionary/data-preflight.js +7 -0
  40. package/dictionary/debug.js +3 -0
  41. package/dictionary/denymount.js +3 -0
  42. package/dictionary/diff.js +3 -0
  43. package/dictionary/drivelist.js +22 -0
  44. package/dictionary/ed25519.js +3 -0
  45. package/dictionary/ejs.js +3 -0
  46. package/dictionary/elasticsearch.js +3 -0
  47. package/dictionary/electron.js +17 -0
  48. package/dictionary/emailjs.js +3 -0
  49. package/dictionary/engine.io.js +3 -0
  50. package/dictionary/epoll.js +3 -0
  51. package/dictionary/errorhandler.js +7 -0
  52. package/dictionary/errors.js +7 -0
  53. package/dictionary/eslint.js +7 -0
  54. package/dictionary/etcher-image-write.js +3 -0
  55. package/dictionary/exceljs.js +21 -0
  56. package/dictionary/exiftool.exe.js +13 -0
  57. package/dictionary/exiftool.pl.js +13 -0
  58. package/dictionary/express-load.js +12 -0
  59. package/dictionary/express-session.js +3 -0
  60. package/dictionary/express.js +14 -0
  61. package/dictionary/extender.js +11 -0
  62. package/dictionary/extsprintf.js +3 -0
  63. package/dictionary/faye-websocket.js +3 -0
  64. package/dictionary/feathers.js +3 -0
  65. package/dictionary/findup-sync.js +3 -0
  66. package/dictionary/floordate.js +3 -0
  67. package/dictionary/fmt.js +3 -0
  68. package/dictionary/formidable.js +3 -0
  69. package/dictionary/fs-extra.js +3 -0
  70. package/dictionary/fsevents.js +3 -0
  71. package/dictionary/geoip-lite.js +7 -0
  72. package/dictionary/github.js +7 -0
  73. package/dictionary/gm.js +3 -0
  74. package/dictionary/google-closure-compiler-java.js +13 -0
  75. package/dictionary/google-closure-compiler.js +13 -0
  76. package/dictionary/googleapis.js +7 -0
  77. package/dictionary/got.js +3 -0
  78. package/dictionary/graceful-fs.js +19 -0
  79. package/dictionary/grpc.js +11 -0
  80. package/dictionary/gulp.js +3 -0
  81. package/dictionary/hap-nodejs.js +3 -0
  82. package/dictionary/heapdump.js +3 -0
  83. package/dictionary/hoek.js +3 -0
  84. package/dictionary/homebridge.js +3 -0
  85. package/dictionary/http-proxy.js +3 -0
  86. package/dictionary/http-server.js +3 -0
  87. package/dictionary/image-size.js +3 -0
  88. package/dictionary/indexof.js +3 -0
  89. package/dictionary/inquirer.js +3 -0
  90. package/dictionary/j.js +16 -0
  91. package/dictionary/jade.js +3 -0
  92. package/dictionary/jsdom.js +3 -0
  93. package/dictionary/json-stringify-date.js +3 -0
  94. package/dictionary/json-stringify-safe.js +3 -0
  95. package/dictionary/jsonwebtoken.js +3 -0
  96. package/dictionary/kerberos.js +3 -0
  97. package/dictionary/knex.js +7 -0
  98. package/dictionary/later.js +7 -0
  99. package/dictionary/level.js +3 -0
  100. package/dictionary/leveldown.js +10 -0
  101. package/dictionary/levelup.js +3 -0
  102. package/dictionary/liftoff.js +12 -0
  103. package/dictionary/lodash.js +3 -0
  104. package/dictionary/log4js.js +7 -0
  105. package/dictionary/logform.js +7 -0
  106. package/dictionary/machinepack-urls.js +7 -0
  107. package/dictionary/markdown.js +3 -0
  108. package/dictionary/mdns.js +6 -0
  109. package/dictionary/method-override.js +3 -0
  110. package/dictionary/microjob.js +16 -0
  111. package/dictionary/mime-types.js +3 -0
  112. package/dictionary/mime.js +3 -0
  113. package/dictionary/minimatch.js +3 -0
  114. package/dictionary/minstache.js +3 -0
  115. package/dictionary/module-deps.js +3 -0
  116. package/dictionary/moment-timezone.js +3 -0
  117. package/dictionary/moment.js +7 -0
  118. package/dictionary/mongodb-core.js +22 -0
  119. package/dictionary/mongodb.js +7 -0
  120. package/dictionary/mongoose.js +7 -0
  121. package/dictionary/mongoskin.js +7 -0
  122. package/dictionary/ms.js +3 -0
  123. package/dictionary/msgpack.js +3 -0
  124. package/dictionary/multer.js +3 -0
  125. package/dictionary/muri.js +3 -0
  126. package/dictionary/native-or-bluebird.js +3 -0
  127. package/dictionary/natives.js +3 -0
  128. package/dictionary/nconf.js +7 -0
  129. package/dictionary/nedb.js +3 -0
  130. package/dictionary/negotiator.js +7 -0
  131. package/dictionary/newrelic.js +3 -0
  132. package/dictionary/nib.js +3 -0
  133. package/dictionary/nightmare.js +18 -0
  134. package/dictionary/node-forge.js +7 -0
  135. package/dictionary/node-libcurl.js +3 -0
  136. package/dictionary/node-notifier.js +30 -0
  137. package/dictionary/node-pre-gyp.js +7 -0
  138. package/dictionary/node-redis-pubsub.js +3 -0
  139. package/dictionary/node-sass.js +3 -0
  140. package/dictionary/node-uuid.js +3 -0
  141. package/dictionary/node-xlsx.js +3 -0
  142. package/dictionary/node-zookeeper-client.js +7 -0
  143. package/dictionary/nodegit.js +7 -0
  144. package/dictionary/nodemailer-sendmail-transport.js +3 -0
  145. package/dictionary/nodemailer.js +3 -0
  146. package/dictionary/npm-registry-client.js +7 -0
  147. package/dictionary/npm.js +7 -0
  148. package/dictionary/nssocket.js +3 -0
  149. package/dictionary/oauth2orize.js +7 -0
  150. package/dictionary/octobat.js +3 -0
  151. package/dictionary/open.js +13 -0
  152. package/dictionary/opn.js +4 -0
  153. package/dictionary/optimist.js +3 -0
  154. package/dictionary/passport-local.js +3 -0
  155. package/dictionary/passport.js +3 -0
  156. package/dictionary/pg-cursor.js +3 -0
  157. package/dictionary/pg-query-stream.js +3 -0
  158. package/dictionary/pg-types.js +7 -0
  159. package/dictionary/pg.js +7 -0
  160. package/dictionary/pg.js.js +7 -0
  161. package/dictionary/pgpass.js +7 -0
  162. package/dictionary/phantom.js +19 -0
  163. package/dictionary/phantomjs-prebuilt.js +16 -0
  164. package/dictionary/pkginfo.js +3 -0
  165. package/dictionary/pm2.js +7 -0
  166. package/dictionary/pmx.js +3 -0
  167. package/dictionary/pouchdb.js +3 -0
  168. package/dictionary/primus-emitter.js +3 -0
  169. package/dictionary/primus-spark-latency.js +3 -0
  170. package/dictionary/primus.js +3 -0
  171. package/dictionary/publicsuffixlist.js +15 -0
  172. package/dictionary/pug.js +3 -0
  173. package/dictionary/punt.js +3 -0
  174. package/dictionary/puppeteer.js +13 -0
  175. package/dictionary/pwd.js +3 -0
  176. package/dictionary/q.js +3 -0
  177. package/dictionary/raven.js +3 -0
  178. package/dictionary/rc.js +12 -0
  179. package/dictionary/readable-stream.js +3 -0
  180. package/dictionary/rechoir.js +3 -0
  181. package/dictionary/redis-parser.js +3 -0
  182. package/dictionary/redis.js +3 -0
  183. package/dictionary/regression.js +3 -0
  184. package/dictionary/reload.js +7 -0
  185. package/dictionary/request.js +3 -0
  186. package/dictionary/require-uncached.js +3 -0
  187. package/dictionary/require_optional.js +3 -0
  188. package/dictionary/s3.js +3 -0
  189. package/dictionary/safe_datejs.js +3 -0
  190. package/dictionary/sails.js +33 -0
  191. package/dictionary/sax.js +3 -0
  192. package/dictionary/scrypt.js +3 -0
  193. package/dictionary/semver.js +3 -0
  194. package/dictionary/sequelize.js +7 -0
  195. package/dictionary/serialport.js +3 -0
  196. package/dictionary/sha3.js +3 -0
  197. package/dictionary/sharp.js +11 -0
  198. package/dictionary/shelljs.js +7 -0
  199. package/dictionary/sinon.js +3 -0
  200. package/dictionary/socket.io-client.js +13 -0
  201. package/dictionary/socket.io.js +12 -0
  202. package/dictionary/sqip.js +7 -0
  203. package/dictionary/sqlite3.js +7 -0
  204. package/dictionary/steam-crypto.js +7 -0
  205. package/dictionary/steam-resources.js +19 -0
  206. package/dictionary/steam.js +3 -0
  207. package/dictionary/stripe-webhook-middleware.js +3 -0
  208. package/dictionary/stripe.js +3 -0
  209. package/dictionary/strong-globalize.js +3 -0
  210. package/dictionary/stylus.js +14 -0
  211. package/dictionary/supervisor.js +3 -0
  212. package/dictionary/svgo.js +8 -0
  213. package/dictionary/tabtab.js +3 -0
  214. package/dictionary/tesseract.js.js +7 -0
  215. package/dictionary/thread-stream.js +7 -0
  216. package/dictionary/throng.js +3 -0
  217. package/dictionary/time.js +3 -0
  218. package/dictionary/tinify.js +7 -0
  219. package/dictionary/tiny-worker.js +7 -0
  220. package/dictionary/tmp.js +3 -0
  221. package/dictionary/transformers.js +3 -0
  222. package/dictionary/uglify-js.js +9 -0
  223. package/dictionary/umd.js +19 -0
  224. package/dictionary/underscore.js +3 -0
  225. package/dictionary/union.js +3 -0
  226. package/dictionary/update-notifier.js +3 -0
  227. package/dictionary/usage.js +7 -0
  228. package/dictionary/v8flags.js +13 -0
  229. package/dictionary/verror.js +3 -0
  230. package/dictionary/voc.js +3 -0
  231. package/dictionary/webdriverio.js +7 -0
  232. package/dictionary/winston-uber.js +7 -0
  233. package/dictionary/winston.js +7 -0
  234. package/dictionary/ws.js +3 -0
  235. package/dictionary/xlsx.js +16 -0
  236. package/dictionary/xml2js.js +3 -0
  237. package/dictionary/yargs.js +3 -0
  238. package/dictionary/zeromq.js +13 -0
  239. package/lib-es5/addon-extract.js +164 -0
  240. package/lib-es5/analyzer.js +687 -0
  241. package/lib-es5/app-bundle.js +133 -0
  242. package/lib-es5/appdir.js +265 -0
  243. package/lib-es5/bin.js +304 -0
  244. package/lib-es5/bootstrap.js +179 -0
  245. package/lib-es5/bundler.js +496 -0
  246. package/lib-es5/chmod.js +15 -0
  247. package/lib-es5/colors.js +12 -0
  248. package/lib-es5/commands.js +376 -0
  249. package/lib-es5/common.js +328 -0
  250. package/lib-es5/compress_type.js +10 -0
  251. package/lib-es5/config.js +291 -0
  252. package/lib-es5/detector.js +421 -0
  253. package/lib-es5/esm-hooks.js +366 -0
  254. package/lib-es5/esm-resolver.js +292 -0
  255. package/lib-es5/esm-transformer.js +378 -0
  256. package/lib-es5/exports-resolver.js +184 -0
  257. package/lib-es5/external-artifacts.js +170 -0
  258. package/lib-es5/fabricator.js +137 -0
  259. package/lib-es5/follow.js +190 -0
  260. package/lib-es5/help.js +52 -0
  261. package/lib-es5/index.d.ts +2 -0
  262. package/lib-es5/index.js +552 -0
  263. package/lib-es5/log.js +7 -0
  264. package/lib-es5/mach-o.js +262 -0
  265. package/lib-es5/manifest.js +21 -0
  266. package/lib-es5/options.js +19 -0
  267. package/lib-es5/packager.js +1036 -0
  268. package/lib-es5/packer.js +137 -0
  269. package/lib-es5/pe-metadata.js +130 -0
  270. package/lib-es5/producer.js +378 -0
  271. package/lib-es5/refiner.js +87 -0
  272. package/lib-es5/resolver.js +142 -0
  273. package/lib-es5/runtime-diagnostics.js +172 -0
  274. package/lib-es5/sea.js +307 -0
  275. package/lib-es5/snapshot-fs-patch.js +396 -0
  276. package/lib-es5/snapshot-fs.js +255 -0
  277. package/lib-es5/snapshot-index.js +135 -0
  278. package/lib-es5/snapshot-path.js +168 -0
  279. package/lib-es5/types.js +9 -0
  280. package/lib-es5/walker.js +1019 -0
  281. package/lib-es5/windows-sign.js +139 -0
  282. package/package.json +99 -0
  283. package/prelude/bootstrap.js +2263 -0
  284. package/prelude/diagnostic.js +147 -0
package/lib-es5/sea.js ADDED
@@ -0,0 +1,307 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const child_process_1 = require("child_process");
7
+ const util_1 = __importDefault(require("util"));
8
+ const path_1 = require("path");
9
+ const promises_1 = require("fs/promises");
10
+ const fs_1 = require("fs");
11
+ const promises_2 = require("stream/promises");
12
+ const crypto_1 = require("crypto");
13
+ const os_1 = require("os");
14
+ const unzipper_1 = __importDefault(require("unzipper"));
15
+ const tar_1 = require("tar");
16
+ const log_1 = require("./log");
17
+ const mach_o_1 = require("./mach-o");
18
+ const exec = util_1.default.promisify(child_process_1.exec);
19
+ /** Returns stat of path when exits, false otherwise */
20
+ const exists = async (path) => {
21
+ try {
22
+ return await (0, promises_1.stat)(path);
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ };
28
+ const defaultSeaConfig = {
29
+ disableExperimentalSEAWarning: true,
30
+ useSnapshot: false,
31
+ useCodeCache: false,
32
+ };
33
+ /** Download a file from a given URL and save it to `filePath` */
34
+ async function downloadFile(url, filePath) {
35
+ const response = await fetch(url);
36
+ if (!response.ok || !response.body) {
37
+ throw new Error(`Failed to download file from ${url}`);
38
+ }
39
+ const fileStream = (0, fs_1.createWriteStream)(filePath);
40
+ return (0, promises_2.pipeline)(response.body, fileStream);
41
+ }
42
+ /** Extract node executable from the archive */
43
+ async function extract(os, archivePath) {
44
+ const nodeDir = (0, path_1.basename)(archivePath, os === 'win' ? '.zip' : '.tar.gz');
45
+ const archiveDir = (0, path_1.dirname)(archivePath);
46
+ let nodePath = '';
47
+ if (os === 'win') {
48
+ // use unzipper to extract the archive
49
+ const { files } = await unzipper_1.default.Open.file(archivePath);
50
+ const nodeBinPath = `${nodeDir}/node.exe`;
51
+ const nodeBin = files.find((file) => file.path === nodeBinPath);
52
+ if (!nodeBin) {
53
+ throw new Error('Node executable not found in the archive');
54
+ }
55
+ nodePath = (0, path_1.join)(archiveDir, `${nodeDir}.exe`);
56
+ // extract the node executable
57
+ await (0, promises_2.pipeline)(nodeBin.stream(), (0, fs_1.createWriteStream)(nodePath));
58
+ }
59
+ else {
60
+ const nodeBinPath = `${nodeDir}/bin/node`;
61
+ // use tar to extract the archive
62
+ await (0, tar_1.extract)({
63
+ file: archivePath,
64
+ cwd: archiveDir,
65
+ filter: (path) => path === nodeBinPath,
66
+ });
67
+ // check if the node executable exists
68
+ nodePath = (0, path_1.join)(archiveDir, nodeBinPath);
69
+ }
70
+ // check if the node executable exists
71
+ if (!(await exists(nodePath))) {
72
+ throw new Error('Node executable not found in the archive');
73
+ }
74
+ return nodePath;
75
+ }
76
+ /** Verify the checksum of downloaded NodeJS archive */
77
+ async function verifyChecksum(filePath, checksumUrl, fileName) {
78
+ const response = await fetch(checksumUrl);
79
+ if (!response.ok) {
80
+ throw new Error(`Failed to download checksum file from ${checksumUrl}`);
81
+ }
82
+ const checksums = await response.text();
83
+ const expectedChecksum = checksums
84
+ .split('\n')
85
+ .find((line) => line.includes(fileName))
86
+ ?.split(' ')[0];
87
+ if (!expectedChecksum) {
88
+ throw new Error(`Checksum for ${fileName} not found`);
89
+ }
90
+ const fileBuffer = await (0, promises_1.readFile)(filePath);
91
+ const hashSum = (0, crypto_1.createHash)('sha256');
92
+ hashSum.update(fileBuffer);
93
+ const actualChecksum = hashSum.digest('hex');
94
+ if (actualChecksum !== expectedChecksum) {
95
+ throw new Error(`Checksum verification failed for ${fileName}`);
96
+ }
97
+ }
98
+ /** Get the node os based on target platform */
99
+ function getNodeOs(platform) {
100
+ const allowedOSs = ['darwin', 'linux', 'win'];
101
+ const platformsMap = {
102
+ macos: 'darwin',
103
+ };
104
+ const validatedPlatform = platformsMap[platform] || platform;
105
+ if (!allowedOSs.includes(validatedPlatform)) {
106
+ throw new Error(`Unsupported OS: ${platform}`);
107
+ }
108
+ return validatedPlatform;
109
+ }
110
+ /** Get the node arch based on target arch */
111
+ function getNodeArch(arch) {
112
+ const allowedArchs = [
113
+ 'x64',
114
+ 'arm64',
115
+ 'armv7l',
116
+ 'ppc64',
117
+ 's390x',
118
+ 'riscv64',
119
+ 'loong64',
120
+ ];
121
+ if (!allowedArchs.includes(arch)) {
122
+ throw new Error(`Unsupported architecture: ${arch}`);
123
+ }
124
+ return arch;
125
+ }
126
+ /** Get latest node version based on the provided partial version */
127
+ async function getNodeVersion(os, arch, nodeVersion) {
128
+ // validate nodeVersion using regex. Allowed formats: 16, 16.0, 16.0.0
129
+ const regex = /^\d{1,2}(\.\d{1,2}){0,2}$/;
130
+ if (!regex.test(nodeVersion)) {
131
+ throw new Error('Invalid node version format');
132
+ }
133
+ const parts = nodeVersion.split('.');
134
+ if (parts.length > 3) {
135
+ throw new Error('Invalid node version format');
136
+ }
137
+ if (parts.length === 3) {
138
+ return nodeVersion;
139
+ }
140
+ let url;
141
+ switch (arch) {
142
+ case 'riscv64':
143
+ case 'loong64':
144
+ url = 'https://unofficial-builds.nodejs.org/download/release/index.json';
145
+ break;
146
+ default:
147
+ url = 'https://nodejs.org/dist/index.json';
148
+ break;
149
+ }
150
+ const response = await fetch(url);
151
+ if (!response.ok) {
152
+ throw new Error('Failed to fetch node versions');
153
+ }
154
+ const versions = await response.json();
155
+ const nodeOS = os === 'darwin' ? 'osx' : os;
156
+ const latestVersionAndFiles = versions
157
+ .map((v) => [v.version, v.files])
158
+ .find(([v, files]) => v.startsWith(`v${nodeVersion}`) &&
159
+ files.find((f) => f.startsWith(`${nodeOS}-${arch}`)));
160
+ if (!latestVersionAndFiles) {
161
+ throw new Error(`Node version ${nodeVersion} not found`);
162
+ }
163
+ return latestVersionAndFiles[0];
164
+ }
165
+ /** Fetch, validate and extract nodejs binary. Returns a path to it */
166
+ async function getNodejsExecutable(target, opts) {
167
+ if (opts.nodePath) {
168
+ // check if the nodePath exists
169
+ if (!(await exists(opts.nodePath))) {
170
+ throw new Error(`Priovided node executable path "${opts.nodePath}" does not exist`);
171
+ }
172
+ return opts.nodePath;
173
+ }
174
+ if (opts.useLocalNode) {
175
+ return process.execPath;
176
+ }
177
+ const os = getNodeOs(target.platform);
178
+ const arch = getNodeArch(target.arch);
179
+ const nodeVersion = await getNodeVersion(os, arch, target.nodeRange.replace('node', ''));
180
+ const fileName = `node-${nodeVersion}-${os}-${arch}.${os === 'win' ? 'zip' : 'tar.gz'}`;
181
+ let url;
182
+ let checksumUrl;
183
+ switch (arch) {
184
+ case 'riscv64':
185
+ case 'loong64':
186
+ url = `https://unofficial-builds.nodejs.org/download/release/${nodeVersion}/${fileName}`;
187
+ checksumUrl = `https://unofficial-builds.nodejs.org/download/release/${nodeVersion}/SHASUMS256.txt`;
188
+ break;
189
+ default:
190
+ url = `https://nodejs.org/dist/${nodeVersion}/${fileName}`;
191
+ checksumUrl = `https://nodejs.org/dist/${nodeVersion}/SHASUMS256.txt`;
192
+ break;
193
+ }
194
+ const downloadDir = (0, path_1.join)((0, os_1.homedir)(), '.pkg-cache', 'sea');
195
+ // Ensure the download directory exists
196
+ if (!(await exists(downloadDir))) {
197
+ await (0, promises_1.mkdir)(downloadDir, { recursive: true });
198
+ }
199
+ const filePath = (0, path_1.join)(downloadDir, fileName);
200
+ // skip download if file exists
201
+ if (!(await exists(filePath))) {
202
+ log_1.log.info(`Downloading nodejs executable from ${url}...`);
203
+ await downloadFile(url, filePath);
204
+ }
205
+ log_1.log.info(`Verifying checksum of ${fileName}`);
206
+ await verifyChecksum(filePath, checksumUrl, fileName);
207
+ log_1.log.info(`Extracting node binary from ${fileName}`);
208
+ const nodePath = await extract(os, filePath);
209
+ return nodePath;
210
+ }
211
+ /** Bake the blob into the executable */
212
+ async function bake(nodePath, target, blobPath) {
213
+ const outPath = (0, path_1.resolve)(process.cwd(), target.output);
214
+ log_1.log.info(`Creating executable for ${target.nodeRange}-${target.platform}-${target.arch}....`);
215
+ if (!(await exists((0, path_1.dirname)(outPath)))) {
216
+ await (0, promises_1.mkdir)((0, path_1.dirname)(outPath), { recursive: true });
217
+ }
218
+ // check if executable_path exists
219
+ if (await exists(outPath)) {
220
+ log_1.log.warn(`Executable ${outPath} already exists, will be overwritten`);
221
+ }
222
+ // copy the executable as the output executable
223
+ await (0, promises_1.copyFile)(nodePath, outPath);
224
+ log_1.log.info(`Injecting the blob into ${outPath}...`);
225
+ if (target.platform === 'macos') {
226
+ (0, mach_o_1.removeMachOExecutableSignature)(outPath);
227
+ await exec(`npx postject "${outPath}" NODE_SEA_BLOB "${blobPath}" --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 --macho-segment-name NODE_SEA`);
228
+ }
229
+ else {
230
+ await exec(`npx postject "${outPath}" NODE_SEA_BLOB "${blobPath}" --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2`);
231
+ }
232
+ }
233
+ /** Create NodeJS executable using sea */
234
+ async function sea(entryPoint, opts) {
235
+ entryPoint = (0, path_1.resolve)(process.cwd(), entryPoint);
236
+ if (!(await exists(entryPoint))) {
237
+ throw new Error(`Entrypoint path "${entryPoint}" does not exist`);
238
+ }
239
+ const nodeMajor = parseInt(process.version.slice(1).split('.')[0], 10);
240
+ // check node version, needs to be at least 20.0.0
241
+ if (nodeMajor < 20) {
242
+ throw new Error(`SEA support requires as least node v20.0.0, actual node version is ${process.version}`);
243
+ }
244
+ const nodePaths = await Promise.all(opts.targets.map((target) => getNodejsExecutable(target, opts)));
245
+ // create a temporary directory for the processing work
246
+ const tmpDir = (0, path_1.join)((0, os_1.tmpdir)(), 'pkg-sea', `${Date.now()}`);
247
+ await (0, promises_1.mkdir)(tmpDir, { recursive: true });
248
+ const previousDirectory = process.cwd();
249
+ try {
250
+ // change working directory to the temp directory
251
+ process.chdir(tmpDir);
252
+ // docs: https://nodejs.org/api/single-executable-applications.html
253
+ const blobPath = (0, path_1.join)(tmpDir, 'sea-prep.blob');
254
+ const seaConfigFilePath = (0, path_1.join)(tmpDir, 'sea-config.json');
255
+ const seaConfig = {
256
+ main: entryPoint,
257
+ output: blobPath,
258
+ ...{
259
+ ...defaultSeaConfig,
260
+ ...(opts.seaConfig || {}),
261
+ },
262
+ };
263
+ log_1.log.info('Creating sea-config.json file...');
264
+ await (0, promises_1.writeFile)(seaConfigFilePath, JSON.stringify(seaConfig));
265
+ log_1.log.info('Generating the blob...');
266
+ await exec(`node --experimental-sea-config "${seaConfigFilePath}"`);
267
+ await Promise.allSettled(nodePaths.map(async (nodePath, i) => {
268
+ const target = opts.targets[i];
269
+ await bake(nodePath, target, blobPath);
270
+ const output = target.output;
271
+ if (opts.signature && target.platform === 'macos') {
272
+ const buf = (0, mach_o_1.patchMachOExecutable)(await (0, promises_1.readFile)(output));
273
+ await (0, promises_1.writeFile)(output, buf);
274
+ try {
275
+ // sign executable ad-hoc to workaround the new mandatory signing requirement
276
+ // users can always replace the signature if necessary
277
+ (0, mach_o_1.signMachOExecutable)(output);
278
+ }
279
+ catch {
280
+ if (target.arch === 'arm64') {
281
+ log_1.log.warn('Unable to sign the macOS executable', [
282
+ 'Due to the mandatory code signing requirement, before the',
283
+ 'executable is distributed to end users, it must be signed.',
284
+ 'Otherwise, it will be immediately killed by kernel on launch.',
285
+ 'An ad-hoc signature is sufficient.',
286
+ 'To do that, run pkg on a Mac, or transfer the executable to a Mac',
287
+ 'and run "codesign --sign - <executable>", or (if you use Linux)',
288
+ 'install "ldid" utility to PATH and then run pkg again',
289
+ ]);
290
+ }
291
+ }
292
+ }
293
+ }));
294
+ }
295
+ catch (error) {
296
+ throw new Error(`Error while creating the executable: ${error}`);
297
+ }
298
+ finally {
299
+ // cleanup the temp directory
300
+ await (0, promises_1.rm)(tmpDir, { recursive: true }).catch(() => {
301
+ log_1.log.warn(`Failed to cleanup the temp directory ${tmpDir}`);
302
+ });
303
+ process.chdir(previousDirectory);
304
+ }
305
+ }
306
+ exports.default = sea;
307
+ //# sourceMappingURL=sea.js.map