quickbundle 0.0.0-next-8b15817 → 0.0.0-next-e01ceeb

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.js +201 -201
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,21 +1,70 @@
1
1
  import { helpers, termost } from 'termost';
2
- import { finished } from 'node:stream/promises';
3
- import { Readable } from 'node:stream';
4
- import { resolve, dirname, join, basename } from 'node:path';
5
- import { copyFile as copyFile$1, rename, mkdir, writeFile as writeFile$1, rm, readFile as readFile$1 } from 'node:fs/promises';
6
- import { createWriteStream } from 'node:fs';
7
- import decompress from 'decompress';
8
- import { watch as watch$1, rollup } from 'rollup';
2
+ import { gzipSize } from 'gzip-size';
3
+ import { join, resolve, dirname, basename } from 'node:path';
4
+ import { rollup, watch as watch$1 } from 'rollup';
5
+ import commonjs from '@rollup/plugin-commonjs';
6
+ import json from '@rollup/plugin-json';
7
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
8
+ import url from '@rollup/plugin-url';
9
9
  import { createRequire } from 'node:module';
10
- import { swc } from 'rollup-plugin-swc3';
11
- import externals from 'rollup-plugin-node-externals';
12
10
  import dts from 'rollup-plugin-dts';
13
- import url from '@rollup/plugin-url';
14
- import { nodeResolve } from '@rollup/plugin-node-resolve';
15
- import json from '@rollup/plugin-json';
16
- import commonjs from '@rollup/plugin-commonjs';
11
+ import externals from 'rollup-plugin-node-externals';
12
+ import { swc } from 'rollup-plugin-swc3';
13
+ import decompress from 'decompress';
14
+ import { createWriteStream } from 'node:fs';
15
+ import { copyFile as copyFile$1, rename, mkdir, writeFile as writeFile$1, rm, readFile as readFile$1 } from 'node:fs/promises';
16
+ import { Readable } from 'node:stream';
17
+ import { finished } from 'node:stream/promises';
17
18
  import os from 'node:os';
18
- import { gzipSize } from 'gzip-size';
19
+
20
+ var name = "quickbundle";
21
+ var version = "0.0.0-next-e01ceeb";
22
+
23
+ const onLog = (_, log)=>{
24
+ if (log.message.includes("Generated an empty chunk")) return;
25
+ };
26
+ const isRecord = (value)=>{
27
+ return typeof value === "object" && value !== null && !Array.isArray(value);
28
+ };
29
+
30
+ // eslint-disable-next-line sonarjs/cognitive-complexity
31
+ const build = async (input)=>{
32
+ process.env.NODE_ENV ??= "production";
33
+ const { data: configurations } = input;
34
+ const output = [];
35
+ for (const config of configurations){
36
+ const initialTime = Date.now();
37
+ const bundle = await rollup({
38
+ ...config,
39
+ onLog
40
+ });
41
+ if (config.output) {
42
+ const outputEntries = Array.isArray(config.output) ? config.output : [
43
+ config.output
44
+ ];
45
+ const promises = [];
46
+ for (const outputEntry of outputEntries){
47
+ const entryFileName = outputEntry.entryFileNames;
48
+ const outputFilePath = join(outputEntry.dir ?? "", typeof entryFileName === "string" ? entryFileName : "");
49
+ if (!outputFilePath) {
50
+ throw new Error("Misconfigured file entry point. Make sure to define an `import`, `require`, or `default` field.");
51
+ }
52
+ promises.push(new Promise((resolve, reject)=>{
53
+ bundle.write(outputEntry).then(()=>{
54
+ resolve({
55
+ elapsedTime: Date.now() - initialTime,
56
+ filePath: outputFilePath
57
+ });
58
+ }).catch((error)=>{
59
+ reject(error);
60
+ });
61
+ }));
62
+ }
63
+ output.push(...await Promise.all(promises));
64
+ }
65
+ }
66
+ return output;
67
+ };
19
68
 
20
69
  /**
21
70
  * Resolve a relative path from the Quickbundle node modules directory.
@@ -85,72 +134,17 @@ const unzip = async (input, output)=>{
85
134
  };
86
135
  const createCommand = (program, input)=>{
87
136
  return program.command(input).option({
88
- key: "minification",
89
- name: "minification",
137
+ defaultValue: false,
90
138
  description: "Enable minification",
91
- defaultValue: false
139
+ key: "minification",
140
+ name: "minification"
92
141
  }).option({
93
- key: "sourceMaps",
94
- name: "source-maps",
142
+ defaultValue: false,
95
143
  description: "Enable source maps generation",
96
- defaultValue: false
97
- });
98
- };
99
-
100
- const onLog = (_, log)=>{
101
- if (log.message.includes("Generated an empty chunk")) return;
102
- };
103
- const isRecord = (value)=>{
104
- return typeof value === "object" && value !== null && !Array.isArray(value);
105
- };
106
-
107
- const watch = (input)=>{
108
- process.env.NODE_ENV ??= "development";
109
- const watcher = watch$1(input.data.map((configItem)=>({
110
- ...configItem,
111
- onLog
112
- })));
113
- let startDuration;
114
- console.clear();
115
- watcher.on("event", async (event)=>{
116
- switch(event.code){
117
- case "START":
118
- {
119
- startDuration = Date.now();
120
- clearLog("Build in progress…", {
121
- type: "information"
122
- });
123
- return;
124
- }
125
- case "BUNDLE_END":
126
- {
127
- await event.result.close();
128
- break;
129
- }
130
- case "END":
131
- {
132
- const duration = Date.now() - startDuration;
133
- clearLog(`Build done in ${duration}ms (at ${new Date().toLocaleTimeString()})`, {
134
- type: "success"
135
- });
136
- return;
137
- }
138
- case "ERROR":
139
- {
140
- const { error } = event;
141
- clearLog(error.message, {
142
- type: "error"
143
- });
144
- console.error("\n", error);
145
- return;
146
- }
147
- }
144
+ key: "sourceMaps",
145
+ name: "source-maps"
148
146
  });
149
147
  };
150
- const clearLog = (...input)=>{
151
- console.clear();
152
- helpers.message(...input);
153
- };
154
148
 
155
149
  const require$1 = createRequire(import.meta.url);
156
150
  const PKG = require$1(resolveFromExternalDirectory("package.json"));
@@ -348,58 +342,67 @@ const createTypesConfig = (entryPoints, options)=>{
348
342
  };
349
343
  };
350
344
 
351
- const createWatchCommand = (program)=>{
345
+ const createBuildCommand = (program)=>{
352
346
  return createCommand(program, {
353
- name: "watch",
354
- description: "Watch and rebuild on any code change (development mode)"
347
+ description: "Build the source code (production mode)",
348
+ name: "build"
355
349
  }).task({
356
- handler (context) {
357
- watch(createConfiguration({
350
+ async handler (context) {
351
+ return build(createConfiguration({
358
352
  minification: context.minification,
359
353
  sourceMaps: context.sourceMaps,
360
354
  standalone: false
361
355
  }));
356
+ },
357
+ key: "buildOutput",
358
+ label: "Bundle assets 📦"
359
+ }).task({
360
+ async handler (context) {
361
+ return computeBundleSize(context.buildOutput);
362
+ },
363
+ key: "logInput",
364
+ label: "Generate report 📝",
365
+ skip (context) {
366
+ return context.buildOutput.length === 0;
367
+ }
368
+ }).task({
369
+ handler (context) {
370
+ context.logInput.forEach((item)=>{
371
+ helpers.message([
372
+ `${formatSize(item.rawSize)} raw`,
373
+ `${formatSize(item.compressedSize)} gzip`
374
+ ].map((message, index)=>{
375
+ return index === 0 ? message : ` ${message}`;
376
+ }).join("\n"), {
377
+ label: `${item.filePath} (took ${item.elapsedTime}ms)`,
378
+ lineBreak: {
379
+ end: false,
380
+ start: true
381
+ },
382
+ type: "information"
383
+ });
384
+ });
385
+ },
386
+ skip (context) {
387
+ return context.buildOutput.length === 0;
362
388
  }
363
389
  });
364
390
  };
365
-
366
- // eslint-disable-next-line sonarjs/cognitive-complexity
367
- const build = async (input)=>{
368
- process.env.NODE_ENV ??= "production";
369
- const { data: configurations } = input;
370
- const output = [];
371
- for (const config of configurations){
372
- const initialTime = Date.now();
373
- const bundle = await rollup({
374
- ...config,
375
- onLog
376
- });
377
- if (config.output) {
378
- const outputEntries = Array.isArray(config.output) ? config.output : [
379
- config.output
380
- ];
381
- const promises = [];
382
- for (const outputEntry of outputEntries){
383
- const entryFileName = outputEntry.entryFileNames;
384
- const outputFilePath = join(outputEntry.dir ?? "", typeof entryFileName === "string" ? entryFileName : "");
385
- if (!outputFilePath) {
386
- throw new Error("Misconfigured file entry point. Make sure to define an `import`, `require`, or `default` field.");
387
- }
388
- promises.push(new Promise((resolve, reject)=>{
389
- bundle.write(outputEntry).then(()=>{
390
- resolve({
391
- elapsedTime: Date.now() - initialTime,
392
- filePath: outputFilePath
393
- });
394
- }).catch((error)=>{
395
- reject(error);
396
- });
397
- }));
398
- }
399
- output.push(...await Promise.all(promises));
400
- }
401
- }
402
- return output;
391
+ const computeBundleSize = async (buildOutput)=>{
392
+ const computeFileSize = async (buildItemOutput)=>{
393
+ const content = await readFile(buildItemOutput.filePath);
394
+ const gzSize = await gzipSize(content);
395
+ return {
396
+ ...buildItemOutput,
397
+ compressedSize: gzSize,
398
+ rawSize: content.byteLength
399
+ };
400
+ };
401
+ return Promise.all(buildOutput.map(async (item)=>computeFileSize(item)));
402
+ };
403
+ const formatSize = (bytes)=>{
404
+ const kiloBytes = bytes / 1000;
405
+ return kiloBytes < 1 ? `${bytes} B` : `${kiloBytes.toFixed(2)} kB`;
403
406
  };
404
407
 
405
408
  const TEMPORARY_PATH = resolveFromInternalDirectory("dist", "tmp");
@@ -407,31 +410,27 @@ const TEMPORARY_DOWNLOAD_PATH = join(TEMPORARY_PATH, "zip");
407
410
  const TEMPORARY_RUNTIME_PATH = join(TEMPORARY_PATH, "runtime");
408
411
  const createCompileCommand = (program)=>{
409
412
  return program.command({
410
- name: "compile",
411
- description: "Compiles the source code into a self-contained executable"
413
+ description: "Compiles the source code into a self-contained executable",
414
+ name: "compile"
412
415
  }).option({
416
+ defaultValue: "local",
417
+ description: "Set a different cross-compilation target",
413
418
  key: "targetInput",
414
419
  name: {
415
420
  long: "target",
416
421
  short: "t"
417
- },
418
- description: "Set a different cross-compilation target",
419
- defaultValue: "local"
422
+ }
420
423
  }).task({
421
- key: "config",
422
- label: "Create configuration",
423
424
  handler () {
424
425
  return createConfiguration({
425
426
  minification: true,
426
427
  sourceMaps: false,
427
428
  standalone: true
428
429
  });
429
- }
430
- }).task({
431
- key: "osType",
432
- label ({ targetInput }) {
433
- return `Get \`${targetInput}\` runtime`;
434
430
  },
431
+ key: "config",
432
+ label: "Create configuration"
433
+ }).task({
435
434
  async handler ({ targetInput }) {
436
435
  if (targetInput === "local") {
437
436
  await copyFile(process.execPath, TEMPORARY_RUNTIME_PATH);
@@ -452,20 +451,17 @@ const createCompileCommand = (program)=>{
452
451
  filename: basename(TEMPORARY_RUNTIME_PATH)
453
452
  });
454
453
  return osType;
454
+ },
455
+ key: "osType",
456
+ label ({ targetInput }) {
457
+ return `Get \`${targetInput}\` runtime`;
455
458
  }
456
459
  }).task({
457
- label: "Build",
458
460
  async handler ({ config }) {
459
461
  await build(config);
460
- }
461
- }).task({
462
- label ({ config }) {
463
- const binaries = config.metadata.map(({ bin })=>{
464
- if (!bin) return undefined;
465
- return `\`${bin}\``;
466
- }).filter(Boolean).join(", ");
467
- return `Compile ${binaries}`;
468
462
  },
463
+ label: "Build"
464
+ }).task({
469
465
  async handler ({ config, osType }) {
470
466
  await Promise.all(config.metadata.map(async ({ bin, require })=>{
471
467
  if (!require || !bin) return;
@@ -475,16 +471,18 @@ const createCompileCommand = (program)=>{
475
471
  osType
476
472
  });
477
473
  }));
474
+ },
475
+ label ({ config }) {
476
+ const binaries = config.metadata.map(({ bin })=>{
477
+ if (!bin) return undefined;
478
+ return `\`${bin}\``;
479
+ }).filter(Boolean).join(", ");
480
+ return `Compile ${binaries}`;
478
481
  }
479
482
  });
480
483
  };
481
484
  const getOsType = (input)=>{
482
485
  switch(input){
483
- case "Windows_NT":
484
- case "win":
485
- {
486
- return "windows";
487
- }
488
486
  case "Darwin":
489
487
  case "darwin":
490
488
  {
@@ -495,6 +493,11 @@ const getOsType = (input)=>{
495
493
  {
496
494
  return "linux";
497
495
  }
496
+ case "win":
497
+ case "Windows_NT":
498
+ {
499
+ return "windows";
500
+ }
498
501
  default:
499
502
  {
500
503
  throw new Error(`Unsupported operating system \`${input}\``);
@@ -536,76 +539,73 @@ const compile = async ({ bin, input, osType })=>{
536
539
  ].map(async (path)=>removePath(path)));
537
540
  };
538
541
 
539
- const createBuildCommand = (program)=>{
542
+ const watch = (input)=>{
543
+ process.env.NODE_ENV ??= "development";
544
+ const watcher = watch$1(input.data.map((configItem)=>({
545
+ ...configItem,
546
+ onLog
547
+ })));
548
+ let startDuration;
549
+ console.clear();
550
+ watcher.on("event", async (event)=>{
551
+ switch(event.code){
552
+ case "BUNDLE_END":
553
+ {
554
+ await event.result.close();
555
+ break;
556
+ }
557
+ case "END":
558
+ {
559
+ const duration = Date.now() - startDuration;
560
+ clearLog(`Build done in ${duration}ms (at ${new Date().toLocaleTimeString()})`, {
561
+ type: "success"
562
+ });
563
+ return;
564
+ }
565
+ case "ERROR":
566
+ {
567
+ const { error } = event;
568
+ clearLog(error.message, {
569
+ type: "error"
570
+ });
571
+ console.error("\n", error);
572
+ return;
573
+ }
574
+ case "START":
575
+ {
576
+ startDuration = Date.now();
577
+ clearLog("Build in progress…", {
578
+ type: "information"
579
+ });
580
+ return;
581
+ }
582
+ }
583
+ });
584
+ };
585
+ const clearLog = (...input)=>{
586
+ console.clear();
587
+ helpers.message(...input);
588
+ };
589
+
590
+ const createWatchCommand = (program)=>{
540
591
  return createCommand(program, {
541
- name: "build",
542
- description: "Build the source code (production mode)"
592
+ description: "Watch and rebuild on any code change (development mode)",
593
+ name: "watch"
543
594
  }).task({
544
- key: "buildOutput",
545
- label: "Bundle assets 📦",
546
- async handler (context) {
547
- return build(createConfiguration({
595
+ handler (context) {
596
+ watch(createConfiguration({
548
597
  minification: context.minification,
549
598
  sourceMaps: context.sourceMaps,
550
599
  standalone: false
551
600
  }));
552
601
  }
553
- }).task({
554
- key: "logInput",
555
- label: "Generate report 📝",
556
- async handler (context) {
557
- return computeBundleSize(context.buildOutput);
558
- },
559
- skip (context) {
560
- return context.buildOutput.length === 0;
561
- }
562
- }).task({
563
- handler (context) {
564
- context.logInput.forEach((item)=>{
565
- helpers.message([
566
- `${formatSize(item.rawSize)} raw`,
567
- `${formatSize(item.compressedSize)} gzip`
568
- ].map((message, index)=>{
569
- return index === 0 ? message : ` ${message}`;
570
- }).join("\n"), {
571
- label: `${item.filePath} (took ${item.elapsedTime}ms)`,
572
- lineBreak: {
573
- end: false,
574
- start: true
575
- },
576
- type: "information"
577
- });
578
- });
579
- },
580
- skip (context) {
581
- return context.buildOutput.length === 0;
582
- }
583
602
  });
584
603
  };
585
- const computeBundleSize = async (buildOutput)=>{
586
- const computeFileSize = async (buildItemOutput)=>{
587
- const content = await readFile(buildItemOutput.filePath);
588
- const gzSize = await gzipSize(content);
589
- return {
590
- ...buildItemOutput,
591
- compressedSize: gzSize,
592
- rawSize: content.byteLength
593
- };
594
- };
595
- return Promise.all(buildOutput.map(async (item)=>computeFileSize(item)));
596
- };
597
- const formatSize = (bytes)=>{
598
- const kiloBytes = bytes / 1000;
599
- return kiloBytes < 1 ? `${bytes} B` : `${kiloBytes.toFixed(2)} kB`;
600
- };
601
-
602
- var name = "quickbundle";
603
- var version = "0.0.0-next-8b15817";
604
604
 
605
605
  const createProgram = (...commandBuilders)=>{
606
606
  const program = termost({
607
- name,
608
607
  description: "The zero-configuration transpiler and bundler for the web",
608
+ name,
609
609
  version
610
610
  });
611
611
  for (const commandBuilder of commandBuilders){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickbundle",
3
- "version": "0.0.0-next-8b15817",
3
+ "version": "0.0.0-next-e01ceeb",
4
4
  "description": "The zero-configuration transpiler and bundler for the web",
5
5
  "keywords": [
6
6
  "library",
@@ -40,22 +40,22 @@
40
40
  "dist"
41
41
  ],
42
42
  "dependencies": {
43
- "@rollup/plugin-commonjs": "^29.0.0",
43
+ "@rollup/plugin-commonjs": "^29.0.2",
44
44
  "@rollup/plugin-json": "^6.1.0",
45
45
  "@rollup/plugin-node-resolve": "^16.0.3",
46
46
  "@rollup/plugin-url": "^8.0.2",
47
- "@swc/core": "^1.15.2",
47
+ "@swc/core": "^1.15.21",
48
48
  "decompress": "^4.2.1",
49
49
  "gzip-size": "^7.0.0",
50
- "rollup": "^4.53.3",
51
- "rollup-plugin-dts": "^6.2.3",
50
+ "rollup": "^4.60.0",
51
+ "rollup-plugin-dts": "^6.4.1",
52
52
  "rollup-plugin-node-externals": "^8.1.2",
53
53
  "rollup-plugin-swc3": "^0.12.1",
54
54
  "termost": "^1.9.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/decompress": "4.2.7",
58
- "@types/node": "24.10.1"
58
+ "@types/node": "24.12.0"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "typescript": "^4.7.0 || ^5.0.0"