bunchee 2.1.2 → 2.1.4

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.
package/README.md CHANGED
@@ -100,10 +100,20 @@ bunchee ./src/index.js -f esm -o ./dist/bundle.esm.js
100
100
  ### Node.js API
101
101
 
102
102
  ```js
103
+ import path from 'path'
103
104
  import { bundle } from 'bunchee'
104
105
 
105
- // options is same to CLI options
106
- await bundle(entryFilePath, options)
106
+ // The definition of these options can be found in help information
107
+ await bundle(path.resolve('./src/index.ts'), {
108
+ dts: false,
109
+ watch: false,
110
+ minify: false,
111
+ sourcemap: false,
112
+ external: [],
113
+ format: 'esm',
114
+ target: 'es2016',
115
+ runtime: 'nodejs',
116
+ })
107
117
  ```
108
118
 
109
119
  ### Typescript
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js CHANGED
@@ -12,6 +12,9 @@ function exit(err) {
12
12
  logger.error(err);
13
13
  process.exit(1);
14
14
  }
15
+ var formatDuration = function(duration) {
16
+ return duration >= 1000 ? "" + duration / 1000 + "s" : "" + duration + "ms";
17
+ };
15
18
  var logger = {
16
19
  log: function log(arg) {
17
20
  console.log(arg);
@@ -24,7 +27,7 @@ var logger = {
24
27
  }
25
28
  };
26
29
 
27
- var version = "2.1.2";
30
+ var version = "2.1.4";
28
31
 
29
32
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
30
33
  try {
@@ -261,7 +264,7 @@ function _run() {
261
264
  case 4:
262
265
  duration = timeEnd - timeStart;
263
266
  if (!watch) {
264
- logger.log("✨ Finished in " + duration + " ms");
267
+ logger.log("✨ Finished in " + formatDuration(duration));
265
268
  }
266
269
  return [
267
270
  2
package/dist/lib.d.ts CHANGED
@@ -1,126 +1,34 @@
1
- import * as url from 'url';
2
- import * as worker_threads from 'worker_threads';
3
- import * as _babel_core from '@babel/core';
1
+ import { JscTarget } from '@swc/core';
2
+ import { RollupOptions, InputOptions, OutputOptions } from 'rollup';
4
3
 
5
- declare const spread: {
6
- globalThis: typeof globalThis;
7
- eval(x: string): any;
8
- parseInt(string: string, radix?: number | undefined): number;
9
- parseFloat(string: string): number;
10
- isNaN(number: number): boolean;
11
- isFinite(number: number): boolean;
12
- decodeURI(encodedURI: string): string;
13
- decodeURIComponent(encodedURIComponent: string): string;
14
- encodeURI(uri: string): string;
15
- encodeURIComponent(uriComponent: string | number | boolean): string;
16
- escape(string: string): string;
17
- unescape(string: string): string;
18
- NaN: number;
19
- Infinity: number;
20
- Symbol: SymbolConstructor;
21
- Object: ObjectConstructor;
22
- Function: FunctionConstructor;
23
- String: StringConstructor;
24
- Boolean: BooleanConstructor;
25
- Number: NumberConstructor;
26
- Math: Math;
27
- Date: DateConstructor;
28
- RegExp: RegExpConstructor;
29
- Error: ErrorConstructor;
30
- EvalError: EvalErrorConstructor;
31
- RangeError: RangeErrorConstructor;
32
- ReferenceError: ReferenceErrorConstructor;
33
- SyntaxError: SyntaxErrorConstructor;
34
- TypeError: TypeErrorConstructor;
35
- URIError: URIErrorConstructor;
36
- JSON: JSON;
37
- Array: ArrayConstructor;
38
- Promise: PromiseConstructor;
39
- ArrayBuffer: ArrayBufferConstructor;
40
- DataView: DataViewConstructor;
41
- Int8Array: Int8ArrayConstructor;
42
- Uint8Array: Uint8ArrayConstructor;
43
- Uint8ClampedArray: Uint8ClampedArrayConstructor;
44
- Int16Array: Int16ArrayConstructor;
45
- Uint16Array: Uint16ArrayConstructor;
46
- Int32Array: Int32ArrayConstructor;
47
- Uint32Array: Uint32ArrayConstructor;
48
- Float32Array: Float32ArrayConstructor;
49
- Float64Array: Float64ArrayConstructor;
50
- Intl: typeof Intl;
51
- Map: MapConstructor;
52
- WeakMap: WeakMapConstructor;
53
- Set: SetConstructor;
54
- WeakSet: WeakSetConstructor;
55
- Proxy: ProxyConstructor;
56
- Reflect: typeof Reflect;
57
- SharedArrayBuffer: SharedArrayBufferConstructor;
58
- Atomics: Atomics;
59
- BigInt: BigIntConstructor;
60
- BigInt64Array: BigInt64ArrayConstructor;
61
- BigUint64Array: BigUint64ArrayConstructor;
62
- babel: typeof _babel_core;
63
- structuredClone<T>(value: T, transfer?: {
64
- transfer: readonly worker_threads.TransferListItem[];
65
- } | undefined): T;
66
- process: NodeJS.Process;
67
- console: Console;
68
- __filename: string;
69
- __dirname: string;
70
- require: NodeRequire;
71
- module: NodeModule;
72
- exports: any;
73
- gc: (() => void) | undefined;
74
- AbortController: {
75
- new (): AbortController;
76
- prototype: AbortController;
4
+ declare type ExportType = 'require' | 'export' | 'default' | string;
5
+ declare type CommonConfig = {
6
+ dts?: boolean;
7
+ format?: OutputOptions['format'];
8
+ minify?: boolean;
9
+ sourcemap?: boolean;
10
+ external?: string[];
11
+ runtime?: string;
12
+ exportCondition?: {
13
+ source: string;
14
+ name: string;
15
+ export: ExportCondition;
77
16
  };
78
- AbortSignal: {
79
- new (): AbortSignal;
80
- prototype: AbortSignal;
81
- };
82
- global: typeof globalThis;
83
- spyOn<T_1>(object: T_1, method: keyof T_1): jasmine.Spy;
84
- pending(reason?: string | undefined): void;
85
- fail(error?: any): never;
86
- beforeAll: jest.Lifecycle;
87
- beforeEach: jest.Lifecycle;
88
- afterAll: jest.Lifecycle;
89
- afterEach: jest.Lifecycle;
90
- describe: jest.Describe;
91
- fdescribe: jest.Describe;
92
- xdescribe: jest.Describe;
93
- it: jest.It;
94
- fit: jest.It;
95
- xit: jest.It;
96
- test: jest.It;
97
- xtest: jest.It;
98
- jest: typeof jest;
99
- jasmine: typeof jasmine;
100
- atob(data: string): string;
101
- btoa(data: string): string;
102
- Buffer: BufferConstructor;
103
- setTimeout: typeof setTimeout;
104
- clearTimeout(timeoutId: string | number | NodeJS.Timeout | undefined): void;
105
- setInterval: typeof setInterval;
106
- clearInterval(intervalId: string | number | NodeJS.Timeout | undefined): void;
107
- setImmediate: typeof setImmediate;
108
- clearImmediate(immediateId: NodeJS.Immediate | undefined): void;
109
- queueMicrotask(callback: () => void): void;
110
- URLSearchParams: typeof url.URLSearchParams;
111
- URL: typeof url.URL;
112
- undefined: undefined;
113
17
  };
114
- declare function loadList(): Promise<number[]>;
115
- declare const optionalChainFn: {
116
- <T>(this: T, thisArg: ThisParameterType<T>): OmitThisParameter<T>;
117
- <T_1, A0, A_1 extends any[], R>(this: (this: T_1, arg0: A0, ...args: A_1) => R, thisArg: T_1, arg0: A0): (...args: A_1) => R;
118
- <T_2, A0_1, A1, A_2 extends any[], R_1>(this: (this: T_2, arg0: A0_1, arg1: A1, ...args: A_2) => R_1, thisArg: T_2, arg0: A0_1, arg1: A1): (...args: A_2) => R_1;
119
- <T_3, A0_2, A1_1, A2, A_3 extends any[], R_2>(this: (this: T_3, arg0: A0_2, arg1: A1_1, arg2: A2, ...args: A_3) => R_2, thisArg: T_3, arg0: A0_2, arg1: A1_1, arg2: A2): (...args: A_3) => R_2;
120
- <T_4, A0_3, A1_2, A2_1, A3, A_4 extends any[], R_3>(this: (this: T_4, arg0: A0_3, arg1: A1_2, arg2: A2_1, arg3: A3, ...args: A_4) => R_3, thisArg: T_4, arg0: A0_3, arg1: A1_2, arg2: A2_1, arg3: A3): (...args: A_4) => R_3;
121
- <T_5, AX, R_4>(this: (this: T_5, ...args: AX[]) => R_4, thisArg: T_5, ...args: AX[]): (...args: AX[]) => R_4;
18
+ declare type ExportCondition = string | Record<ExportType, string>;
19
+ declare type BuncheeRollupConfig = Partial<Omit<RollupOptions, 'input' | 'output'>> & {
20
+ exportName?: string;
21
+ input: InputOptions;
22
+ output: OutputOptions[];
23
+ dtsOnly: boolean;
24
+ };
25
+ declare type CliArgs = CommonConfig & {
26
+ file?: string;
27
+ watch?: boolean;
28
+ cwd?: string;
29
+ target?: JscTarget;
122
30
  };
123
- declare class A {
124
- }
125
31
 
126
- export { A, loadList, optionalChainFn, spread };
32
+ declare function bundle(entryPath: string, { cwd, ...options }?: CliArgs): Promise<any>;
33
+
34
+ export { BuncheeRollupConfig, CliArgs, bundle };
package/dist/lib.js CHANGED
@@ -149,6 +149,9 @@ function exit(err) {
149
149
  logger.error(err);
150
150
  process.exit(1);
151
151
  }
152
+ var formatDuration = function(duration) {
153
+ return duration >= 1000 ? "" + duration / 1000 + "s" : "" + duration + "ms";
154
+ };
152
155
  function getPackageMeta(cwd) {
153
156
  var pkgFilePath = path__default["default"].resolve(cwd, "package.json");
154
157
  var targetPackageJson = {};
@@ -331,7 +334,7 @@ function buildOutputConfigs(options, pkg, param) {
331
334
  var dtsDir = typings ? path.dirname(path.resolve(config.rootDir, typings)) : path.resolve(config.rootDir, "dist");
332
335
  // file base name without extension
333
336
  var name = file ? file.replace(new RegExp("" + path.extname(file) + "$"), "") : undefined;
334
- var dtsFile = (exportCondition == null ? void 0 : exportCondition.name) ? path.resolve(dtsDir, (exportCondition.name === "." ? "index" : exportCondition.name) + ".d.ts") : file ? name + ".d.ts" : typings;
337
+ var dtsFile = file ? name + ".d.ts" : (exportCondition == null ? void 0 : exportCondition.name) ? path.resolve(dtsDir, (exportCondition.name === "." ? "index" : exportCondition.name) + ".d.ts") : typings;
335
338
  // If there's dts file, use `output.file`
336
339
  var dtsPathConfig = dtsFile ? {
337
340
  file: dtsFile
@@ -383,7 +386,6 @@ function buildConfig(entry, pkg, cliArgs, dtsOnly) {
383
386
  if (dtsOnly) {
384
387
  outputConfigs = [
385
388
  buildOutputConfigs(_extends$1({}, cliArgs, {
386
- file: undefined,
387
389
  format: "es",
388
390
  useTypescript: useTypescript
389
391
  }), pkg, typescriptOptions),
@@ -400,11 +402,11 @@ function buildConfig(entry, pkg, cliArgs, dtsOnly) {
400
402
  // CLI output option is always prioritized
401
403
  if (file) {
402
404
  var ref1;
403
- var format = (ref1 = outputExports[0]) == null ? void 0 : ref1.format;
405
+ var fallbackFormat = (ref1 = outputExports[0]) == null ? void 0 : ref1.format;
404
406
  outputConfigs = [
405
407
  buildOutputConfigs(_extends$1({}, cliArgs, {
406
408
  file: file,
407
- format: cliArgs.format || format,
409
+ format: cliArgs.format || fallbackFormat,
408
410
  useTypescript: useTypescript
409
411
  }), pkg, typescriptOptions),
410
412
  ];
@@ -568,8 +570,8 @@ var __generator = undefined && undefined.__generator || function(thisArg, body)
568
570
  };
569
571
  }
570
572
  };
571
- function logBuild(exportPath, dtsOnly, _duration) {
572
- logger.log(" ✓ " + (dtsOnly ? "Typed" : "Built") + " " + exportPath);
573
+ function logBuild(exportPath, dtsOnly, duration) {
574
+ logger.log(" ✓ " + (dtsOnly ? "Typed" : "Built") + " " + exportPath + " " + formatDuration(duration));
573
575
  }
574
576
  function assignDefault(options, name, defaultValue) {
575
577
  if (!(name in options) || options[name] == null) {
@@ -741,6 +743,7 @@ function runWatch(param, metadata) {
741
743
  }),
742
744
  ];
743
745
  var watcher = rollup.watch(watchOptions);
746
+ var startTime = Date.now();
744
747
  watcher.on("event", function(event) {
745
748
  switch(event.code){
746
749
  case "ERROR":
@@ -749,11 +752,15 @@ function runWatch(param, metadata) {
749
752
  }
750
753
  case "START":
751
754
  {
755
+ startTime = Date.now();
752
756
  logger.log("Start building " + metadata.source + " ...");
757
+ break;
753
758
  }
754
759
  case "END":
755
760
  {
756
- logBuild(metadata.source, dtsOnly);
761
+ var duration = Date.now() - startTime;
762
+ logBuild(metadata.source, dtsOnly, duration);
763
+ break;
757
764
  }
758
765
  default:
759
766
  return;
@@ -763,13 +770,15 @@ function runWatch(param, metadata) {
763
770
  }
764
771
  function runBundle(param, jobOptions) {
765
772
  var input = param.input, output = param.output, dtsOnly = param.dtsOnly;
773
+ var startTime = Date.now();
766
774
  return rollup.rollup(input).then(function(bundle) {
767
775
  var writeJobs = output.map(function(options) {
768
776
  return bundle.write(options);
769
777
  });
770
778
  return Promise.all(writeJobs);
771
779
  }, onError).then(function() {
772
- logBuild(jobOptions.source, dtsOnly);
780
+ var duration = Date.now() - startTime;
781
+ logBuild(jobOptions.source, dtsOnly, duration);
773
782
  });
774
783
  }
775
784
  function onError(error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": {
6
6
  "bunchee": "./dist/cli.js"
@@ -41,12 +41,12 @@
41
41
  "@rollup/plugin-commonjs": "22.0.2",
42
42
  "@rollup/plugin-json": "4.1.0",
43
43
  "@rollup/plugin-node-resolve": "13.3.0",
44
- "@swc/core": "^1.2.249",
44
+ "@swc/core": "^1.3.0",
45
45
  "arg": "5.0.0",
46
46
  "rollup": "2.74.1",
47
47
  "rollup-plugin-dts": "4.2.2",
48
48
  "rollup-plugin-preserve-shebang": "1.0.1",
49
- "rollup-plugin-swc3": "0.5.0",
49
+ "rollup-plugin-swc3": "0.6.0",
50
50
  "tslib": "2.4.0"
51
51
  },
52
52
  "peerDependencies": {