quickbundle 0.0.0-next-552a1f9 → 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 +218 -208
  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"));
@@ -259,6 +253,12 @@ const getBuildableExports = ({ standalone })=>{
259
253
  }
260
254
  return output;
261
255
  };
256
+ const getFileOutput = (filePath)=>{
257
+ return {
258
+ dir: dirname(filePath),
259
+ entryFileNames: basename(filePath)
260
+ };
261
+ };
262
262
  const getPlugins = (customPlugins, options)=>{
263
263
  return [
264
264
  !options.standalone && externals({
@@ -284,17 +284,21 @@ const createMainConfig = (entryPoints, options)=>{
284
284
  if (entryPoints.import && entryPoints.default && entryPoints.import !== entryPoints.default) {
285
285
  throw new Error("Both `import` and `default` export fields have been defined but with different values. To preserve proper `default` field resolution on the consumer side (i.e. to target ESM format), make sure to provide the same file path for both fields.");
286
286
  }
287
+ const commonOutputConfig = {
288
+ importAttributesKey: "with",
289
+ sourcemap: sourceMaps
290
+ };
287
291
  const output = [
288
292
  cjsInput && {
289
- file: cjsInput,
293
+ ...commonOutputConfig,
294
+ ...getFileOutput(cjsInput),
290
295
  format: "cjs",
291
- inlineDynamicImports: Boolean(options.standalone),
292
- sourcemap: sourceMaps
296
+ inlineDynamicImports: Boolean(options.standalone)
293
297
  },
294
298
  esmInput && {
295
- file: esmInput,
296
- format: "es",
297
- sourcemap: sourceMaps
299
+ ...commonOutputConfig,
300
+ ...getFileOutput(esmInput),
301
+ format: "es"
298
302
  }
299
303
  ].filter(Boolean);
300
304
  return {
@@ -313,9 +317,7 @@ const createTypesConfig = (entryPoints, options)=>{
313
317
  return {
314
318
  input: entryPoints.source,
315
319
  output: [
316
- {
317
- file: entryPoints.types
318
- }
320
+ getFileOutput(entryPoints.types)
319
321
  ],
320
322
  plugins: getPlugins([
321
323
  nodeResolve({
@@ -340,56 +342,67 @@ const createTypesConfig = (entryPoints, options)=>{
340
342
  };
341
343
  };
342
344
 
343
- const createWatchCommand = (program)=>{
345
+ const createBuildCommand = (program)=>{
344
346
  return createCommand(program, {
345
- name: "watch",
346
- description: "Watch and rebuild on any code change (development mode)"
347
+ description: "Build the source code (production mode)",
348
+ name: "build"
347
349
  }).task({
348
- handler (context) {
349
- watch(createConfiguration({
350
+ async handler (context) {
351
+ return build(createConfiguration({
350
352
  minification: context.minification,
351
353
  sourceMaps: context.sourceMaps,
352
354
  standalone: false
353
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;
354
388
  }
355
389
  });
356
390
  };
357
-
358
- const build = async (input)=>{
359
- process.env.NODE_ENV ??= "production";
360
- const { data: configurations } = input;
361
- const output = [];
362
- for (const config of configurations){
363
- const initialTime = Date.now();
364
- const bundle = await rollup({
365
- ...config,
366
- onLog
367
- });
368
- if (config.output) {
369
- const outputEntries = Array.isArray(config.output) ? config.output : [
370
- config.output
371
- ];
372
- const promises = [];
373
- for (const outputEntry of outputEntries){
374
- const outputFilePath = outputEntry.file ?? outputEntry.dir;
375
- if (!outputFilePath) {
376
- throw new Error("Misconfigured file entry point. Make sure to define an `import`, `require`, or `default` field.");
377
- }
378
- promises.push(new Promise((resolve, reject)=>{
379
- bundle.write(outputEntry).then(()=>{
380
- resolve({
381
- elapsedTime: Date.now() - initialTime,
382
- filePath: outputFilePath
383
- });
384
- }).catch((error)=>{
385
- reject(error);
386
- });
387
- }));
388
- }
389
- output.push(...await Promise.all(promises));
390
- }
391
- }
392
- 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`;
393
406
  };
394
407
 
395
408
  const TEMPORARY_PATH = resolveFromInternalDirectory("dist", "tmp");
@@ -397,31 +410,27 @@ const TEMPORARY_DOWNLOAD_PATH = join(TEMPORARY_PATH, "zip");
397
410
  const TEMPORARY_RUNTIME_PATH = join(TEMPORARY_PATH, "runtime");
398
411
  const createCompileCommand = (program)=>{
399
412
  return program.command({
400
- name: "compile",
401
- description: "Compiles the source code into a self-contained executable"
413
+ description: "Compiles the source code into a self-contained executable",
414
+ name: "compile"
402
415
  }).option({
416
+ defaultValue: "local",
417
+ description: "Set a different cross-compilation target",
403
418
  key: "targetInput",
404
419
  name: {
405
420
  long: "target",
406
421
  short: "t"
407
- },
408
- description: "Set a different cross-compilation target",
409
- defaultValue: "local"
422
+ }
410
423
  }).task({
411
- key: "config",
412
- label: "Create configuration",
413
424
  handler () {
414
425
  return createConfiguration({
415
426
  minification: true,
416
427
  sourceMaps: false,
417
428
  standalone: true
418
429
  });
419
- }
420
- }).task({
421
- key: "osType",
422
- label ({ targetInput }) {
423
- return `Get \`${targetInput}\` runtime`;
424
430
  },
431
+ key: "config",
432
+ label: "Create configuration"
433
+ }).task({
425
434
  async handler ({ targetInput }) {
426
435
  if (targetInput === "local") {
427
436
  await copyFile(process.execPath, TEMPORARY_RUNTIME_PATH);
@@ -442,20 +451,17 @@ const createCompileCommand = (program)=>{
442
451
  filename: basename(TEMPORARY_RUNTIME_PATH)
443
452
  });
444
453
  return osType;
454
+ },
455
+ key: "osType",
456
+ label ({ targetInput }) {
457
+ return `Get \`${targetInput}\` runtime`;
445
458
  }
446
459
  }).task({
447
- label: "Build",
448
460
  async handler ({ config }) {
449
461
  await build(config);
450
- }
451
- }).task({
452
- label ({ config }) {
453
- const binaries = config.metadata.map(({ bin })=>{
454
- if (!bin) return undefined;
455
- return `\`${bin}\``;
456
- }).filter(Boolean).join(", ");
457
- return `Compile ${binaries}`;
458
462
  },
463
+ label: "Build"
464
+ }).task({
459
465
  async handler ({ config, osType }) {
460
466
  await Promise.all(config.metadata.map(async ({ bin, require })=>{
461
467
  if (!require || !bin) return;
@@ -465,16 +471,18 @@ const createCompileCommand = (program)=>{
465
471
  osType
466
472
  });
467
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}`;
468
481
  }
469
482
  });
470
483
  };
471
484
  const getOsType = (input)=>{
472
485
  switch(input){
473
- case "Windows_NT":
474
- case "win":
475
- {
476
- return "windows";
477
- }
478
486
  case "Darwin":
479
487
  case "darwin":
480
488
  {
@@ -485,6 +493,11 @@ const getOsType = (input)=>{
485
493
  {
486
494
  return "linux";
487
495
  }
496
+ case "win":
497
+ case "Windows_NT":
498
+ {
499
+ return "windows";
500
+ }
488
501
  default:
489
502
  {
490
503
  throw new Error(`Unsupported operating system \`${input}\``);
@@ -526,76 +539,73 @@ const compile = async ({ bin, input, osType })=>{
526
539
  ].map(async (path)=>removePath(path)));
527
540
  };
528
541
 
529
- 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)=>{
530
591
  return createCommand(program, {
531
- name: "build",
532
- description: "Build the source code (production mode)"
592
+ description: "Watch and rebuild on any code change (development mode)",
593
+ name: "watch"
533
594
  }).task({
534
- key: "buildOutput",
535
- label: "Bundle assets 📦",
536
- async handler (context) {
537
- return build(createConfiguration({
595
+ handler (context) {
596
+ watch(createConfiguration({
538
597
  minification: context.minification,
539
598
  sourceMaps: context.sourceMaps,
540
599
  standalone: false
541
600
  }));
542
601
  }
543
- }).task({
544
- key: "logInput",
545
- label: "Generate report 📝",
546
- async handler (context) {
547
- return computeBundleSize(context.buildOutput);
548
- },
549
- skip (context) {
550
- return context.buildOutput.length === 0;
551
- }
552
- }).task({
553
- handler (context) {
554
- context.logInput.forEach((item)=>{
555
- helpers.message([
556
- `${formatSize(item.rawSize)} raw`,
557
- `${formatSize(item.compressedSize)} gzip`
558
- ].map((message, index)=>{
559
- return index === 0 ? message : ` ${message}`;
560
- }).join("\n"), {
561
- label: `${item.filePath} (took ${item.elapsedTime}ms)`,
562
- lineBreak: {
563
- end: false,
564
- start: true
565
- },
566
- type: "information"
567
- });
568
- });
569
- },
570
- skip (context) {
571
- return context.buildOutput.length === 0;
572
- }
573
602
  });
574
603
  };
575
- const computeBundleSize = async (buildOutput)=>{
576
- const computeFileSize = async (buildItemOutput)=>{
577
- const content = await readFile(buildItemOutput.filePath);
578
- const gzSize = await gzipSize(content);
579
- return {
580
- ...buildItemOutput,
581
- compressedSize: gzSize,
582
- rawSize: content.byteLength
583
- };
584
- };
585
- return Promise.all(buildOutput.map(async (item)=>computeFileSize(item)));
586
- };
587
- const formatSize = (bytes)=>{
588
- const kiloBytes = bytes / 1000;
589
- return kiloBytes < 1 ? `${bytes} B` : `${kiloBytes.toFixed(2)} kB`;
590
- };
591
-
592
- var name = "quickbundle";
593
- var version = "0.0.0-next-552a1f9";
594
604
 
595
605
  const createProgram = (...commandBuilders)=>{
596
606
  const program = termost({
597
- name,
598
607
  description: "The zero-configuration transpiler and bundler for the web",
608
+ name,
599
609
  version
600
610
  });
601
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-552a1f9",
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"