quickbundle 0.0.0-next-180c331 → 0.0.0-next-ed1776f

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 +51 -27
  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-180c331";
18
+ var version = "0.0.0-next-ed1776f";
20
19
 
21
20
  const CWD = process.cwd();
22
21
 
@@ -123,13 +122,17 @@ const getBuildableExports = ({ standalone })=>{
123
122
  const bin = PKG.bin;
124
123
  const name = PKG.name;
125
124
  const source = PKG.source;
126
- return isRecord(bin) ? Object.entries(bin).map((data)=>({
127
- bin: data[0],
128
- require: data[1],
129
- source
130
- })) : [
125
+ if (isRecord(bin)) {
126
+ return Object.entries(bin).map((data)=>({
127
+ bin: data[0],
128
+ require: data[1],
129
+ source
130
+ }));
131
+ }
132
+ return [
131
133
  {
132
- bin: name,
134
+ // For scoped packages and if the `bin` is defined with a string value, the [scope name is discarded](the scope name is discarded when creating a binary) when creating a binary.
135
+ bin: name.replace(/^(@.*?\/)/, ""),
133
136
  require: bin,
134
137
  source
135
138
  }
@@ -140,7 +143,7 @@ const getBuildableExports = ({ standalone })=>{
140
143
  * Following the [package entry-point specification](https://nodejs.org/api/packages.html#package-entry-points),
141
144
  * whenever an export object is defined, it take precedence over other classical entry-point fields
142
145
  * (such as main, module, and types defined at the root package.json level).
143
- */ if (PKG.main ?? PKG.module ?? PKG.types ?? !PKG.exports) {
146
+ */ if (PKG.main || PKG.module || PKG.types || !PKG.exports) {
144
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`)).");
145
148
  }
146
149
  const buildableExportFields = [
@@ -323,28 +326,44 @@ const createCompileCommand = (program)=>{
323
326
  name: "compile",
324
327
  description: "Compiles the source code into a self-contained executable"
325
328
  }).task({
326
- async handler () {
327
- const osType = os.type();
328
- const isWindowsOS = osType === "Windows_NT";
329
- const isMacOS = osType === "Darwin";
330
- 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({
331
340
  minification: true,
332
341
  sourceMaps: false,
333
342
  standalone: true
334
343
  });
335
- await build(configuration);
336
- for (const { bin, require: filePath } of configuration.metadata){
337
- if (!filePath || !bin) {
338
- throw new Error("Invalid configuration output. Missing `filePath` or `bin` field definition.");
339
- }
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
+ for (const { bin, require: filePath } of config.metadata){
360
+ if (!filePath || !bin) continue;
340
361
  chdir(dirname(filePath));
341
362
  const fileName = basename(filePath);
342
363
  const blobFileName = `${fileName}.blob`;
343
- /*
344
- * TODO: split with several tasks
345
- */ const executableFileName = `${bin}${isWindowsOS ? ".exe" : ""}`;
364
+ const executableFileName = `${bin}${osType === "windows" ? ".exe" : ""}`;
346
365
  const seaConfigFileName = `${fileName}.sea-config.json`;
347
- writeFileSync(seaConfigFileName, JSON.stringify({
366
+ await writeFile(seaConfigFileName, JSON.stringify({
348
367
  disableExperimentalSEAWarning: true,
349
368
  main: fileName,
350
369
  output: blobFileName,
@@ -353,13 +372,18 @@ const createCompileCommand = (program)=>{
353
372
  }), "utf-8");
354
373
  await helpers.exec(`node --experimental-sea-config ${seaConfigFileName}`);
355
374
  await helpers.exec(`node -e "require('fs').copyFileSync(process.execPath, '${executableFileName}')"`);
356
- if (isMacOS) {
375
+ if (osType === "macos") {
357
376
  await helpers.exec(`codesign --remove-signature ${executableFileName}`);
358
377
  }
359
- await helpers.exec(`npx postject ${executableFileName} NODE_SEA_BLOB ${blobFileName} --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 ${isMacOS ? "--macho-segment-name NODE_SEA" : ""}`);
360
- if (isMacOS) {
378
+ await helpers.exec(`npx postject ${executableFileName} NODE_SEA_BLOB ${blobFileName} --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 ${osType === "macos" ? "--macho-segment-name NODE_SEA" : ""}`);
379
+ if (osType === "macos") {
361
380
  await helpers.exec(`codesign --sign - ${executableFileName}`);
362
381
  }
382
+ await Promise.all([
383
+ blobFileName,
384
+ seaConfigFileName
385
+ ].map(async (file)=>rm(file)));
386
+ chdir(CWD);
363
387
  }
364
388
  }
365
389
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickbundle",
3
- "version": "0.0.0-next-180c331",
3
+ "version": "0.0.0-next-ed1776f",
4
4
  "description": "The zero-configuration transpiler and bundler for the web",
5
5
  "author": {
6
6
  "name": "Ayoub Adib",