bunchee 3.1.0 → 3.2.0
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 +3 -3
- package/dist/cli.js +14 -8
- package/dist/index.js +81 -20
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -39,13 +39,13 @@ You can use the `exports` field to support different conditions and leverage the
|
|
|
39
39
|
```json
|
|
40
40
|
{
|
|
41
41
|
"exports": {
|
|
42
|
-
"
|
|
42
|
+
"module": "dist/index.esm.js",
|
|
43
43
|
"import": "dist/index.mjs",
|
|
44
|
-
"
|
|
44
|
+
"require": "dist/index.cjs"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "bunchee"
|
|
48
|
-
}
|
|
48
|
+
}
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
package/dist/cli.js
CHANGED
|
@@ -3,6 +3,12 @@ var path = require('path');
|
|
|
3
3
|
var arg = require('arg');
|
|
4
4
|
var fs = require('fs/promises');
|
|
5
5
|
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
9
|
+
var arg__default = /*#__PURE__*/_interopDefault(arg);
|
|
10
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
11
|
+
|
|
6
12
|
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
7
13
|
try {
|
|
8
14
|
var info = gen[key](arg);
|
|
@@ -42,7 +48,7 @@ function hasPackageJson(cwd) {
|
|
|
42
48
|
}
|
|
43
49
|
function _hasPackageJson() {
|
|
44
50
|
_hasPackageJson = _async_to_generator$1(function*(cwd) {
|
|
45
|
-
return yield fileExists(
|
|
51
|
+
return yield fileExists(path__default.default.resolve(cwd, 'package.json'));
|
|
46
52
|
});
|
|
47
53
|
return _hasPackageJson.apply(this, arguments);
|
|
48
54
|
}
|
|
@@ -51,10 +57,10 @@ function getPackageMeta(cwd) {
|
|
|
51
57
|
}
|
|
52
58
|
function _getPackageMeta() {
|
|
53
59
|
_getPackageMeta = _async_to_generator$1(function*(cwd) {
|
|
54
|
-
const pkgFilePath =
|
|
60
|
+
const pkgFilePath = path__default.default.resolve(cwd, 'package.json');
|
|
55
61
|
let targetPackageJson = {};
|
|
56
62
|
try {
|
|
57
|
-
targetPackageJson = JSON.parse((yield
|
|
63
|
+
targetPackageJson = JSON.parse((yield fs__default.default.readFile(pkgFilePath, {
|
|
58
64
|
encoding: 'utf-8'
|
|
59
65
|
})));
|
|
60
66
|
} catch (_) {}
|
|
@@ -79,7 +85,7 @@ function fileExists(filePath) {
|
|
|
79
85
|
function _fileExists() {
|
|
80
86
|
_fileExists = _async_to_generator$1(function*(filePath) {
|
|
81
87
|
try {
|
|
82
|
-
yield
|
|
88
|
+
yield fs__default.default.access(filePath);
|
|
83
89
|
return true;
|
|
84
90
|
} catch (err) {
|
|
85
91
|
if (err.code === 'ENOENT') {
|
|
@@ -91,7 +97,7 @@ function _fileExists() {
|
|
|
91
97
|
return _fileExists.apply(this, arguments);
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
var version = "3.
|
|
100
|
+
var version = "3.2.0";
|
|
95
101
|
|
|
96
102
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
97
103
|
try {
|
|
@@ -168,7 +174,7 @@ function _lintPackage() {
|
|
|
168
174
|
}
|
|
169
175
|
function parseCliArgs(argv) {
|
|
170
176
|
let args;
|
|
171
|
-
args =
|
|
177
|
+
args = arg__default.default({
|
|
172
178
|
'--cwd': String,
|
|
173
179
|
'--dts': Boolean,
|
|
174
180
|
'--output': String,
|
|
@@ -220,7 +226,7 @@ function _run() {
|
|
|
220
226
|
var _args_external;
|
|
221
227
|
const { source , format , watch , minify , sourcemap , target , runtime , dts , env } = args;
|
|
222
228
|
const cwd = args.cwd || process.cwd();
|
|
223
|
-
const file = args.file ?
|
|
229
|
+
const file = args.file ? path__default.default.resolve(cwd, args.file) : undefined;
|
|
224
230
|
const bundleConfig = {
|
|
225
231
|
dts,
|
|
226
232
|
file,
|
|
@@ -240,7 +246,7 @@ function _run() {
|
|
|
240
246
|
if (args.help) {
|
|
241
247
|
return help();
|
|
242
248
|
}
|
|
243
|
-
const entry = source ?
|
|
249
|
+
const entry = source ? path__default.default.resolve(cwd, source) : '';
|
|
244
250
|
const bundle = require('./index').bundle;
|
|
245
251
|
let timeStart = Date.now();
|
|
246
252
|
let timeEnd;
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
3
3
|
var fs = require('fs/promises');
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var rollup = require('rollup');
|
|
6
|
+
var pluginWasm = require('@rollup/plugin-wasm');
|
|
6
7
|
var rollupPluginSwc3 = require('rollup-plugin-swc3');
|
|
7
8
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
8
9
|
var shebang = require('rollup-plugin-preserve-shebang');
|
|
@@ -12,6 +13,16 @@ var replace = require('@rollup/plugin-replace');
|
|
|
12
13
|
var prettyBytes = require('pretty-bytes');
|
|
13
14
|
var module$1 = require('module');
|
|
14
15
|
|
|
16
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
|
|
18
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
19
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
20
|
+
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
|
|
21
|
+
var shebang__default = /*#__PURE__*/_interopDefault(shebang);
|
|
22
|
+
var json__default = /*#__PURE__*/_interopDefault(json);
|
|
23
|
+
var replace__default = /*#__PURE__*/_interopDefault(replace);
|
|
24
|
+
var prettyBytes__default = /*#__PURE__*/_interopDefault(prettyBytes);
|
|
25
|
+
|
|
15
26
|
function chunkSizeCollector() {
|
|
16
27
|
const sizes = new Map();
|
|
17
28
|
function addSize(name, size) {
|
|
@@ -25,10 +36,10 @@ function chunkSizeCollector() {
|
|
|
25
36
|
// Do nothing, but use the hook to keep the plugin instance alive
|
|
26
37
|
},
|
|
27
38
|
renderChunk (code, chunk, options) {
|
|
28
|
-
const dir = options.dir || options.file &&
|
|
39
|
+
const dir = options.dir || options.file && path__default.default.dirname(options.file);
|
|
29
40
|
let fileName = chunk.fileName;
|
|
30
41
|
if (dir) {
|
|
31
|
-
fileName =
|
|
42
|
+
fileName = path__default.default.relative(cwd, path__default.default.join(dir, fileName));
|
|
32
43
|
}
|
|
33
44
|
addSize(fileName, code.length);
|
|
34
45
|
return null;
|
|
@@ -40,7 +51,7 @@ function chunkSizeCollector() {
|
|
|
40
51
|
sizes.forEach((size, name)=>{
|
|
41
52
|
sizeStats.push([
|
|
42
53
|
name,
|
|
43
|
-
|
|
54
|
+
prettyBytes__default.default(size),
|
|
44
55
|
size
|
|
45
56
|
]);
|
|
46
57
|
});
|
|
@@ -72,7 +83,46 @@ function parseExport(exportsCondition) {
|
|
|
72
83
|
}
|
|
73
84
|
return paths;
|
|
74
85
|
}
|
|
75
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Get package exports paths
|
|
88
|
+
*
|
|
89
|
+
* Example:
|
|
90
|
+
*
|
|
91
|
+
* ```json
|
|
92
|
+
* {
|
|
93
|
+
* "exports": {
|
|
94
|
+
* ".": {
|
|
95
|
+
* "require": "./dist/index.cjs",
|
|
96
|
+
* "module": "./dist/index.esm.js",
|
|
97
|
+
* "default": "./dist/index.esm.js"
|
|
98
|
+
* },
|
|
99
|
+
* "./foo": {
|
|
100
|
+
* "require": "./dist/foo.cjs",
|
|
101
|
+
* "module": "./dist/foo.esm.js",
|
|
102
|
+
* "default": "./dist/foo.esm.js"
|
|
103
|
+
* }
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* will be parsed to:
|
|
109
|
+
*
|
|
110
|
+
* ```js
|
|
111
|
+
* {
|
|
112
|
+
* '.': {
|
|
113
|
+
* main: './dist/index.cjs',
|
|
114
|
+
* module: './dist/index.esm.js',
|
|
115
|
+
* export: './dist/index.esm.js'
|
|
116
|
+
* },
|
|
117
|
+
* './foo': {
|
|
118
|
+
* main: './dist/foo.cjs',
|
|
119
|
+
* module: './dist/foo.esm.js',
|
|
120
|
+
* export: './dist/foo.esm.js'
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
*
|
|
124
|
+
* pkg.main and pkg.module will be added to ['.'] if exists
|
|
125
|
+
*/ function getExportPaths(pkg) {
|
|
76
126
|
const pathsMap = {};
|
|
77
127
|
const mainExport = {};
|
|
78
128
|
if (pkg.main) {
|
|
@@ -203,10 +253,10 @@ function getPackageMeta(cwd) {
|
|
|
203
253
|
}
|
|
204
254
|
function _getPackageMeta() {
|
|
205
255
|
_getPackageMeta = _async_to_generator$3(function*(cwd) {
|
|
206
|
-
const pkgFilePath =
|
|
256
|
+
const pkgFilePath = path__default.default.resolve(cwd, 'package.json');
|
|
207
257
|
let targetPackageJson = {};
|
|
208
258
|
try {
|
|
209
|
-
targetPackageJson = JSON.parse((yield
|
|
259
|
+
targetPackageJson = JSON.parse((yield fs__default.default.readFile(pkgFilePath, {
|
|
210
260
|
encoding: 'utf-8'
|
|
211
261
|
})));
|
|
212
262
|
} catch (_) {}
|
|
@@ -231,7 +281,7 @@ function fileExists(filePath) {
|
|
|
231
281
|
function _fileExists() {
|
|
232
282
|
_fileExists = _async_to_generator$3(function*(filePath) {
|
|
233
283
|
try {
|
|
234
|
-
yield
|
|
284
|
+
yield fs__default.default.access(filePath);
|
|
235
285
|
return true;
|
|
236
286
|
} catch (err) {
|
|
237
287
|
if (err.code === 'ENOENT') {
|
|
@@ -245,15 +295,15 @@ function _fileExists() {
|
|
|
245
295
|
// . -> pkg name
|
|
246
296
|
// ./lite -> <pkg name>/lite
|
|
247
297
|
function getExportPath(pkg, cwd, exportName) {
|
|
248
|
-
const name = pkg.name ||
|
|
298
|
+
const name = pkg.name || path__default.default.basename(cwd);
|
|
249
299
|
if (exportName === '.' || !exportName) return name;
|
|
250
|
-
return
|
|
300
|
+
return path__default.default.join(name, exportName);
|
|
251
301
|
}
|
|
252
302
|
const isNotNull = (n)=>Boolean(n);
|
|
253
303
|
const SRC = 'src' // resolve from src/ directory
|
|
254
304
|
;
|
|
255
305
|
function resolveSourceFile(cwd, filename) {
|
|
256
|
-
return
|
|
306
|
+
return path__default.default.resolve(cwd, SRC, filename);
|
|
257
307
|
}
|
|
258
308
|
// Map '.' -> './index.[ext]'
|
|
259
309
|
// Map './lite' -> './lite.[ext]'
|
|
@@ -367,7 +417,7 @@ function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath , tsCompilerO
|
|
|
367
417
|
const hasSpecifiedTsTarget = Boolean((tsCompilerOptions == null ? void 0 : tsCompilerOptions.target) && tsConfigPath);
|
|
368
418
|
const sizePlugin = sizeCollector.plugin(cwd);
|
|
369
419
|
const commonPlugins = [
|
|
370
|
-
|
|
420
|
+
shebang__default.default(),
|
|
371
421
|
sizePlugin
|
|
372
422
|
];
|
|
373
423
|
const plugins = (dtsOnly ? [
|
|
@@ -390,7 +440,7 @@ function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath , tsCompilerO
|
|
|
390
440
|
})
|
|
391
441
|
] : [
|
|
392
442
|
...commonPlugins,
|
|
393
|
-
|
|
443
|
+
replace__default.default({
|
|
394
444
|
values: getBuildEnv(options.env || []),
|
|
395
445
|
preventAssignment: true
|
|
396
446
|
}),
|
|
@@ -404,10 +454,11 @@ function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath , tsCompilerO
|
|
|
404
454
|
'.jsx'
|
|
405
455
|
]
|
|
406
456
|
}),
|
|
407
|
-
|
|
457
|
+
commonjs__default.default({
|
|
408
458
|
include: /node_modules\//
|
|
409
459
|
}),
|
|
410
|
-
|
|
460
|
+
json__default.default(),
|
|
461
|
+
pluginWasm.wasm(),
|
|
411
462
|
rollupPluginSwc3.swc({
|
|
412
463
|
include: /\.(m|c)?[jt]sx?$/,
|
|
413
464
|
exclude: 'node_modules',
|
|
@@ -460,13 +511,22 @@ function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath , tsCompilerO
|
|
|
460
511
|
}
|
|
461
512
|
};
|
|
462
513
|
}
|
|
514
|
+
function hasEsmExport(exportPaths, tsCompilerOptions) {
|
|
515
|
+
let hasEsm = false;
|
|
516
|
+
for(const key in exportPaths){
|
|
517
|
+
const exportInfo = exportPaths[key];
|
|
518
|
+
if (exportInfo.import || exportInfo.module) {
|
|
519
|
+
hasEsm = true;
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return Boolean(hasEsm || (tsCompilerOptions == null ? void 0 : tsCompilerOptions.esModuleInterop));
|
|
524
|
+
}
|
|
463
525
|
function buildOutputConfigs(pkg, options, cwd, { tsCompilerOptions }, dtsOnly) {
|
|
464
526
|
const { format , exportCondition } = options;
|
|
465
527
|
const exportPaths = getExportPaths(pkg);
|
|
466
|
-
//
|
|
467
|
-
|
|
468
|
-
const mainExport = exportPaths['.'];
|
|
469
|
-
const useEsModuleMark = Boolean(tsCompilerOptions.esModuleInterop || mainExport.main && mainExport.module);
|
|
528
|
+
// Add esm mark and interop helper if esm export is detected
|
|
529
|
+
const useEsModuleMark = hasEsmExport(exportPaths, tsCompilerOptions);
|
|
470
530
|
const typings = getTypings(pkg);
|
|
471
531
|
const file = options.file && path.resolve(cwd, options.file);
|
|
472
532
|
const dtsDir = typings ? path.dirname(path.resolve(cwd, typings)) : path.resolve(cwd, 'dist');
|
|
@@ -486,7 +546,8 @@ function buildOutputConfigs(pkg, options, cwd, { tsCompilerOptions }, dtsOnly)
|
|
|
486
546
|
}, {
|
|
487
547
|
format,
|
|
488
548
|
exports: 'named',
|
|
489
|
-
esModule: useEsModuleMark,
|
|
549
|
+
esModule: useEsModuleMark || 'if-default-prop',
|
|
550
|
+
interop: 'auto',
|
|
490
551
|
freeze: false,
|
|
491
552
|
strict: false,
|
|
492
553
|
sourcemap: options.sourcemap
|
|
@@ -749,7 +810,7 @@ function _bundle() {
|
|
|
749
810
|
}
|
|
750
811
|
return runBundle(rollupConfig);
|
|
751
812
|
};
|
|
752
|
-
const hasSpecifiedEntryFile = entryPath ? (yield fileExists(entryPath)) && (yield
|
|
813
|
+
const hasSpecifiedEntryFile = entryPath ? (yield fileExists(entryPath)) && (yield fs__default.default.stat(entryPath)).isFile() : false;
|
|
753
814
|
if (!hasSpecifiedEntryFile && !isMultiEntries) {
|
|
754
815
|
const err = new Error(`Entry file \`${entryPath}\` is not existed`);
|
|
755
816
|
err.name = 'NOT_EXISTED';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": {
|
|
6
6
|
"bunchee": "./dist/cli.js"
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"@rollup/plugin-json": "6.0.0",
|
|
50
50
|
"@rollup/plugin-node-resolve": "15.0.2",
|
|
51
51
|
"@rollup/plugin-replace": "5.0.2",
|
|
52
|
+
"@rollup/plugin-wasm": "6.1.3",
|
|
52
53
|
"@swc/core": "1.3.46",
|
|
53
54
|
"@swc/helpers": "0.5.0",
|
|
54
55
|
"arg": "5.0.2",
|