quickbundle 0.0.0-next-d9c46be → 0.0.0-next-4ad7f8b

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 (2) hide show
  1. package/dist/index.mjs +46 -23
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { helpers, termost } from 'termost';
2
- import { readFile as readFile$1 } from 'node:fs/promises';
2
+ import { readFile as readFile$1, writeFile, rm } from 'node:fs/promises';
3
3
  import process, { chdir } from 'node:process';
4
4
  import { watch as watch$1, rollup } from 'rollup';
5
5
  import { join, dirname, basename } from 'node:path';
@@ -12,11 +12,10 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
12
12
  import json from '@rollup/plugin-json';
13
13
  import commonjs from '@rollup/plugin-commonjs';
14
14
  import os from 'node:os';
15
- import { writeFileSync } from 'node:fs';
16
15
  import { gzipSize } from 'gzip-size';
17
16
 
18
17
  var name = "quickbundle";
19
- var version = "0.0.0-next-d9c46be";
18
+ var version = "0.0.0-next-4ad7f8b";
20
19
 
21
20
  const CWD = process.cwd();
22
21
 
@@ -144,7 +143,7 @@ const getBuildableExports = ({ standalone })=>{
144
143
  * Following the [package entry-point specification](https://nodejs.org/api/packages.html#package-entry-points),
145
144
  * whenever an export object is defined, it take precedence over other classical entry-point fields
146
145
  * (such as main, module, and types defined at the root package.json level).
147
- */ if ((PKG.main || PKG.module) ?? PKG.types ?? !PKG.exports) {
146
+ */ if (PKG.main || PKG.module || PKG.types || !PKG.exports) {
148
147
  throw new Error("Invalid package entry points contract. Use the recommended [`exports` field](https://nodejs.org/api/packages.html#package-entry-points) instead and, for TypeScript-based projects, update the `tsconfig.json` file to resolve it properly (`moduleResolution` must be set to `Bundler` (or `NodeNext`)).");
149
148
  }
150
149
  const buildableExportFields = [
@@ -327,43 +326,67 @@ const createCompileCommand = (program)=>{
327
326
  name: "compile",
328
327
  description: "Compiles the source code into a self-contained executable"
329
328
  }).task({
330
- async handler () {
331
- const osType = os.type();
332
- const isWindowsOS = osType === "Windows_NT";
333
- const isMacOS = osType === "Darwin";
334
- const configuration = createConfiguration({
329
+ key: "osType",
330
+ label: "Get context",
331
+ handler () {
332
+ const type = os.type();
333
+ return type === "Windows_NT" ? "windows" : type === "Darwin" ? "macos" : "linux";
334
+ }
335
+ }).task({
336
+ key: "config",
337
+ label: "Create configuration",
338
+ handler () {
339
+ return createConfiguration({
335
340
  minification: true,
336
341
  sourceMaps: false,
337
342
  standalone: true
338
343
  });
339
- await build(configuration);
340
- for (const { bin, require: filePath } of configuration.metadata){
341
- if (!filePath || !bin) {
342
- throw new Error("Invalid configuration output. Missing `filePath` or `bin` field definition.");
343
- }
344
+ }
345
+ }).task({
346
+ label: "Build",
347
+ async handler ({ config }) {
348
+ await build(config);
349
+ }
350
+ }).task({
351
+ label ({ config }) {
352
+ const binaries = config.metadata.map(({ bin })=>{
353
+ if (!bin) return undefined;
354
+ return `\`${bin}\``;
355
+ }).filter(Boolean).join(", ");
356
+ return `Compile ${binaries}`;
357
+ },
358
+ async handler ({ config, osType }) {
359
+ // TODO: Optimize via Promise.allSettled + Update README.md
360
+ for (const { bin, require: filePath } of config.metadata){
361
+ if (!filePath || !bin) continue;
344
362
  chdir(dirname(filePath));
345
363
  const fileName = basename(filePath);
346
364
  const blobFileName = `${fileName}.blob`;
347
- /*
348
- * TODO: split with several tasks
349
- */ const executableFileName = `${bin}${isWindowsOS ? ".exe" : ""}`;
365
+ const executableFileName = `${bin}${osType === "windows" ? ".exe" : ""}`;
350
366
  const seaConfigFileName = `${fileName}.sea-config.json`;
351
- writeFileSync(seaConfigFileName, JSON.stringify({
367
+ await writeFile(seaConfigFileName, JSON.stringify({
352
368
  disableExperimentalSEAWarning: true,
353
369
  main: fileName,
354
370
  output: blobFileName,
355
371
  useCodeCache: false,
356
372
  useSnapshot: false
357
373
  }), "utf-8");
358
- await helpers.exec(`node --experimental-sea-config ${seaConfigFileName}`);
359
- await helpers.exec(`node -e "require('fs').copyFileSync(process.execPath, '${executableFileName}')"`);
360
- if (isMacOS) {
374
+ await Promise.all([
375
+ `node --experimental-sea-config ${seaConfigFileName}`,
376
+ `node -e "require('fs').copyFileSync(process.execPath, '${executableFileName}')"`
377
+ ].map(async (command)=>helpers.exec(command)));
378
+ if (osType === "macos") {
361
379
  await helpers.exec(`codesign --remove-signature ${executableFileName}`);
362
380
  }
363
- await helpers.exec(`npx postject ${executableFileName} NODE_SEA_BLOB ${blobFileName} --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 ${isMacOS ? "--macho-segment-name NODE_SEA" : ""}`);
364
- if (isMacOS) {
381
+ await helpers.exec(`npx postject ${executableFileName} NODE_SEA_BLOB ${blobFileName} --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 ${osType === "macos" ? "--macho-segment-name NODE_SEA" : ""}`);
382
+ if (osType === "macos") {
365
383
  await helpers.exec(`codesign --sign - ${executableFileName}`);
366
384
  }
385
+ await Promise.all([
386
+ blobFileName,
387
+ seaConfigFileName
388
+ ].map(async (file)=>rm(file)));
389
+ chdir(CWD);
367
390
  }
368
391
  }
369
392
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickbundle",
3
- "version": "0.0.0-next-d9c46be",
3
+ "version": "0.0.0-next-4ad7f8b",
4
4
  "description": "The zero-configuration transpiler and bundler for the web",
5
5
  "author": {
6
6
  "name": "Ayoub Adib",