bunchee 4.2.2 → 4.2.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/dist/bin/cli.js +64 -7
- package/dist/index.js +130 -35
- package/package.json +4 -3
package/dist/bin/cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
var path = require('path');
|
|
3
3
|
var arg = require('arg');
|
|
4
4
|
var fs = require('fs/promises');
|
|
5
|
+
var require$$0 = require('tty');
|
|
5
6
|
var bunchee = require('bunchee');
|
|
6
7
|
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -9,6 +10,59 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
9
10
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
10
11
|
var arg__default = /*#__PURE__*/_interopDefault(arg);
|
|
11
12
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
13
|
+
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
|
14
|
+
|
|
15
|
+
function getDefaultExportFromCjs (x) {
|
|
16
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var picocolors = {exports: {}};
|
|
20
|
+
|
|
21
|
+
let tty = require$$0__default.default;
|
|
22
|
+
let isColorSupported = !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || tty.isatty(1) && process.env.TERM !== "dumb" || "CI" in process.env);
|
|
23
|
+
let formatter = (open, close, replace = open)=>(input)=>{
|
|
24
|
+
let string = "" + input;
|
|
25
|
+
let index = string.indexOf(close, open.length);
|
|
26
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
27
|
+
};
|
|
28
|
+
let replaceClose = (string, close, replace, index)=>{
|
|
29
|
+
let start = string.substring(0, index) + replace;
|
|
30
|
+
let end = string.substring(index + close.length);
|
|
31
|
+
let nextIndex = end.indexOf(close);
|
|
32
|
+
return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
|
|
33
|
+
};
|
|
34
|
+
let createColors = (enabled = isColorSupported)=>({
|
|
35
|
+
isColorSupported: enabled,
|
|
36
|
+
reset: enabled ? (s)=>`\x1b[0m${s}\x1b[0m` : String,
|
|
37
|
+
bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
|
|
38
|
+
dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
|
|
39
|
+
italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
|
|
40
|
+
underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
|
|
41
|
+
inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
|
|
42
|
+
hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
|
|
43
|
+
strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
|
|
44
|
+
black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
|
|
45
|
+
red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
|
|
46
|
+
green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
|
|
47
|
+
yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
|
|
48
|
+
blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
|
|
49
|
+
magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
|
|
50
|
+
cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
|
|
51
|
+
white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
|
|
52
|
+
gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
|
|
53
|
+
bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
|
|
54
|
+
bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
|
|
55
|
+
bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
|
|
56
|
+
bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
|
|
57
|
+
bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
|
|
58
|
+
bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
|
|
59
|
+
bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
|
|
60
|
+
bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String
|
|
61
|
+
});
|
|
62
|
+
picocolors.exports = createColors();
|
|
63
|
+
picocolors.exports.createColors = createColors;
|
|
64
|
+
var picocolorsExports = picocolors.exports;
|
|
65
|
+
var pc = /*@__PURE__*/ getDefaultExportFromCjs(picocolorsExports);
|
|
12
66
|
|
|
13
67
|
const logger = {
|
|
14
68
|
log (...arg) {
|
|
@@ -24,12 +78,18 @@ const logger = {
|
|
|
24
78
|
console.log(' ✓', ...arg);
|
|
25
79
|
}
|
|
26
80
|
};
|
|
81
|
+
function paint(prefix, prefixColor, ...arg) {
|
|
82
|
+
if (pc.isColorSupported) {
|
|
83
|
+
console.log(' ' + pc[prefixColor](prefix), ...arg);
|
|
84
|
+
} else {
|
|
85
|
+
console.log(' ' + prefix, ...arg);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
27
88
|
|
|
28
89
|
function exit(err) {
|
|
29
90
|
logger.error(err);
|
|
30
91
|
process.exit(1);
|
|
31
92
|
}
|
|
32
|
-
const formatDuration = (duration)=>duration >= 1000 ? `${duration / 1000}s` : `${duration}ms`;
|
|
33
93
|
async function hasPackageJson(cwd) {
|
|
34
94
|
return await fileExists(path__default.default.resolve(cwd, 'package.json'));
|
|
35
95
|
}
|
|
@@ -55,7 +115,7 @@ async function fileExists(filePath) {
|
|
|
55
115
|
}
|
|
56
116
|
}
|
|
57
117
|
|
|
58
|
-
var version = "4.2.
|
|
118
|
+
var version = "4.2.4";
|
|
59
119
|
|
|
60
120
|
const helpMessage = `
|
|
61
121
|
Usage: bunchee [options]
|
|
@@ -166,11 +226,8 @@ async function run(args) {
|
|
|
166
226
|
return help();
|
|
167
227
|
}
|
|
168
228
|
const entry = source ? path__default.default.resolve(cwd, source) : '';
|
|
169
|
-
let timeStart = Date.now();
|
|
170
|
-
let timeEnd;
|
|
171
229
|
try {
|
|
172
230
|
await bunchee.bundle(entry, bundleConfig);
|
|
173
|
-
timeEnd = Date.now();
|
|
174
231
|
} catch (err) {
|
|
175
232
|
if (err.name === 'NOT_EXISTED') {
|
|
176
233
|
help();
|
|
@@ -178,14 +235,14 @@ async function run(args) {
|
|
|
178
235
|
}
|
|
179
236
|
throw err;
|
|
180
237
|
}
|
|
181
|
-
const duration = timeEnd - timeStart;
|
|
182
238
|
// watching mode
|
|
183
239
|
if (watch) {
|
|
184
240
|
logger.log(`Watching assets in ${cwd}...`);
|
|
185
241
|
return;
|
|
186
242
|
}
|
|
187
243
|
// build mode
|
|
188
|
-
|
|
244
|
+
console.log();
|
|
245
|
+
paint('✓', 'green', `bunchee ${version} build completed`);
|
|
189
246
|
await lintPackage(cwd);
|
|
190
247
|
}
|
|
191
248
|
async function main() {
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var replace = require('@rollup/plugin-replace');
|
|
|
12
12
|
var esmShim = require('@rollup/plugin-esm-shim');
|
|
13
13
|
var preserveDirectives = require('rollup-preserve-directives');
|
|
14
14
|
var pluginutils = require('@rollup/pluginutils');
|
|
15
|
+
var require$$0 = require('tty');
|
|
15
16
|
var prettyBytes = require('pretty-bytes');
|
|
16
17
|
var module$1 = require('module');
|
|
17
18
|
|
|
@@ -24,6 +25,7 @@ var json__default = /*#__PURE__*/_interopDefault(json);
|
|
|
24
25
|
var replace__default = /*#__PURE__*/_interopDefault(replace);
|
|
25
26
|
var esmShim__default = /*#__PURE__*/_interopDefault(esmShim);
|
|
26
27
|
var preserveDirectives__default = /*#__PURE__*/_interopDefault(preserveDirectives);
|
|
28
|
+
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
|
27
29
|
var prettyBytes__default = /*#__PURE__*/_interopDefault(prettyBytes);
|
|
28
30
|
|
|
29
31
|
function minifyCSS(content) {
|
|
@@ -200,6 +202,58 @@ const dtsExtensions = {
|
|
|
200
202
|
mjs: '.d.mts'
|
|
201
203
|
};
|
|
202
204
|
|
|
205
|
+
function getDefaultExportFromCjs (x) {
|
|
206
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
var picocolors = {exports: {}};
|
|
210
|
+
|
|
211
|
+
let tty = require$$0__default.default;
|
|
212
|
+
let isColorSupported = !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || tty.isatty(1) && process.env.TERM !== "dumb" || "CI" in process.env);
|
|
213
|
+
let formatter = (open, close, replace = open)=>(input)=>{
|
|
214
|
+
let string = "" + input;
|
|
215
|
+
let index = string.indexOf(close, open.length);
|
|
216
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
217
|
+
};
|
|
218
|
+
let replaceClose = (string, close, replace, index)=>{
|
|
219
|
+
let start = string.substring(0, index) + replace;
|
|
220
|
+
let end = string.substring(index + close.length);
|
|
221
|
+
let nextIndex = end.indexOf(close);
|
|
222
|
+
return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
|
|
223
|
+
};
|
|
224
|
+
let createColors = (enabled = isColorSupported)=>({
|
|
225
|
+
isColorSupported: enabled,
|
|
226
|
+
reset: enabled ? (s)=>`\x1b[0m${s}\x1b[0m` : String,
|
|
227
|
+
bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
|
|
228
|
+
dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
|
|
229
|
+
italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
|
|
230
|
+
underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
|
|
231
|
+
inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
|
|
232
|
+
hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
|
|
233
|
+
strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
|
|
234
|
+
black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
|
|
235
|
+
red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
|
|
236
|
+
green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
|
|
237
|
+
yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
|
|
238
|
+
blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
|
|
239
|
+
magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
|
|
240
|
+
cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
|
|
241
|
+
white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
|
|
242
|
+
gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
|
|
243
|
+
bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
|
|
244
|
+
bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
|
|
245
|
+
bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
|
|
246
|
+
bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
|
|
247
|
+
bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
|
|
248
|
+
bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
|
|
249
|
+
bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
|
|
250
|
+
bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String
|
|
251
|
+
});
|
|
252
|
+
picocolors.exports = createColors();
|
|
253
|
+
picocolors.exports.createColors = createColors;
|
|
254
|
+
var picocolorsExports = picocolors.exports;
|
|
255
|
+
var pc = /*@__PURE__*/ getDefaultExportFromCjs(picocolorsExports);
|
|
256
|
+
|
|
203
257
|
const logger = {
|
|
204
258
|
log (...arg) {
|
|
205
259
|
console.log(' ', ...arg);
|
|
@@ -214,6 +268,13 @@ const logger = {
|
|
|
214
268
|
console.log(' ✓', ...arg);
|
|
215
269
|
}
|
|
216
270
|
};
|
|
271
|
+
function paint(prefix, prefixColor, ...arg) {
|
|
272
|
+
if (pc.isColorSupported) {
|
|
273
|
+
console.log(' ' + pc[prefixColor](prefix), ...arg);
|
|
274
|
+
} else {
|
|
275
|
+
console.log(' ' + prefix, ...arg);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
217
278
|
|
|
218
279
|
function exit(err) {
|
|
219
280
|
logger.error(err);
|
|
@@ -309,13 +370,13 @@ function constructFullExportCondition(exportCondition, packageType) {
|
|
|
309
370
|
[isEsmPkg ? 'import' : 'require']: exportCondition
|
|
310
371
|
};
|
|
311
372
|
} else {
|
|
312
|
-
const
|
|
373
|
+
const exportTypes = Object.keys(exportCondition);
|
|
313
374
|
fullExportCond = {};
|
|
314
|
-
|
|
315
|
-
const condition = exportCondition[
|
|
375
|
+
exportTypes.forEach((exportType)=>{
|
|
376
|
+
const condition = exportCondition[exportType];
|
|
316
377
|
// Filter out nullable value
|
|
317
|
-
if (
|
|
318
|
-
fullExportCond[
|
|
378
|
+
if (condition) {
|
|
379
|
+
fullExportCond[exportType] = condition;
|
|
319
380
|
}
|
|
320
381
|
});
|
|
321
382
|
}
|
|
@@ -323,22 +384,36 @@ function constructFullExportCondition(exportCondition, packageType) {
|
|
|
323
384
|
}
|
|
324
385
|
function joinRelativePath(...segments) {
|
|
325
386
|
let result = path.join(...segments);
|
|
326
|
-
// If the first segment starts with '
|
|
327
|
-
if (segments[0] === '.' && !result.startsWith('
|
|
387
|
+
// If the first segment starts with '.', ensure the result does too.
|
|
388
|
+
if (segments[0] === '.' && !result.startsWith('.')) {
|
|
328
389
|
result = './' + result;
|
|
329
390
|
}
|
|
330
391
|
return result;
|
|
331
392
|
}
|
|
332
|
-
function findExport(
|
|
333
|
-
// TODO: handle export condition based on package.type
|
|
393
|
+
function findExport(exportPath, exportCondition, paths, packageType) {
|
|
334
394
|
if (isExportLike(exportCondition)) {
|
|
335
|
-
|
|
395
|
+
const fullExportCondition = constructFullExportCondition(exportCondition, packageType);
|
|
396
|
+
paths[exportPath] = {
|
|
397
|
+
...paths[exportPath],
|
|
398
|
+
...fullExportCondition
|
|
399
|
+
};
|
|
336
400
|
return;
|
|
337
401
|
}
|
|
338
402
|
Object.keys(exportCondition).forEach((subpath)=>{
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
403
|
+
if (subpath.startsWith('.')) {
|
|
404
|
+
// subpath is actual export path, ./a, ./b, ...
|
|
405
|
+
const nestedExportPath = joinRelativePath(exportPath, subpath);
|
|
406
|
+
const nestedExportCondition = exportCondition[subpath];
|
|
407
|
+
findExport(nestedExportPath, nestedExportCondition, paths, packageType);
|
|
408
|
+
} else {
|
|
409
|
+
// subpath is exportType, import, require, ...
|
|
410
|
+
const exportType = subpath;
|
|
411
|
+
const defaultPath = exportCondition[subpath].default;
|
|
412
|
+
const nestedExportCondition = {
|
|
413
|
+
[exportType]: defaultPath
|
|
414
|
+
};
|
|
415
|
+
findExport(exportPath, nestedExportCondition, paths, packageType);
|
|
416
|
+
}
|
|
342
417
|
});
|
|
343
418
|
}
|
|
344
419
|
/**
|
|
@@ -348,11 +423,10 @@ function findExport(name, exportCondition, paths, packageType) {
|
|
|
348
423
|
*
|
|
349
424
|
* Input:
|
|
350
425
|
* {
|
|
351
|
-
* "
|
|
352
|
-
* "
|
|
353
|
-
* "
|
|
354
|
-
* "
|
|
355
|
-
* "types": "./sub.d.ts
|
|
426
|
+
* "./sub": {
|
|
427
|
+
* "import": {
|
|
428
|
+
* "types": "./sub.js",
|
|
429
|
+
* "default": "./sub.cjs",
|
|
356
430
|
* }
|
|
357
431
|
* }
|
|
358
432
|
* }
|
|
@@ -362,7 +436,7 @@ function findExport(name, exportCondition, paths, packageType) {
|
|
|
362
436
|
* "./sub": {
|
|
363
437
|
* "import": "./sub.js",
|
|
364
438
|
* "require": "./sub.cjs",
|
|
365
|
-
* "types": "./sub.d.ts,
|
|
439
|
+
* "types": "./sub.d.ts",
|
|
366
440
|
* }
|
|
367
441
|
* }
|
|
368
442
|
*
|
|
@@ -510,8 +584,7 @@ function isCjsExportName(pkg, name, ext) {
|
|
|
510
584
|
return !isESModule && [
|
|
511
585
|
'require',
|
|
512
586
|
'main',
|
|
513
|
-
'node'
|
|
514
|
-
'default'
|
|
587
|
+
'node'
|
|
515
588
|
].includes(name) && ext !== 'mjs' || ext === 'cjs';
|
|
516
589
|
}
|
|
517
590
|
function getExportConditionDist(pkg, parsedExportCondition, cwd) {
|
|
@@ -542,7 +615,6 @@ function getExportConditionDist(pkg, parsedExportCondition, cwd) {
|
|
|
542
615
|
});
|
|
543
616
|
}
|
|
544
617
|
if (dist.length === 0 && !pkg.bin) {
|
|
545
|
-
console.error(`Doesn't fin any exports in ${pkg.name}, using default dist path dist/index.js`);
|
|
546
618
|
const defaultFormat = isESModulePackage(pkg.type) ? 'esm' : 'cjs';
|
|
547
619
|
dist.push({
|
|
548
620
|
format: defaultFormat,
|
|
@@ -763,7 +835,9 @@ function getModuleLater(moduleMeta) {
|
|
|
763
835
|
return moduleLayer;
|
|
764
836
|
}
|
|
765
837
|
// dependencyGraphMap: Map<subModuleId, Set<entryParentId>>
|
|
766
|
-
function createSplitChunks(dependencyGraphMap) {
|
|
838
|
+
function createSplitChunks(dependencyGraphMap, entryFiles) {
|
|
839
|
+
// If there's existing chunk being splitted, and contains a layer { <id>: <chunkGroup> }
|
|
840
|
+
const splitChunksGroupMap = new Map();
|
|
767
841
|
return function splitChunks(id, ctx) {
|
|
768
842
|
const moduleInfo = ctx.getModuleInfo(id);
|
|
769
843
|
if (!moduleInfo) {
|
|
@@ -785,7 +859,10 @@ function createSplitChunks(dependencyGraphMap) {
|
|
|
785
859
|
if (!dependencyGraphMap.has(subId)) {
|
|
786
860
|
dependencyGraphMap.set(subId, new Set());
|
|
787
861
|
}
|
|
788
|
-
dependencyGraphMap.get(subId).add(
|
|
862
|
+
dependencyGraphMap.get(subId).add([
|
|
863
|
+
id,
|
|
864
|
+
moduleLayer
|
|
865
|
+
]);
|
|
789
866
|
}
|
|
790
867
|
}
|
|
791
868
|
}
|
|
@@ -795,18 +872,34 @@ function createSplitChunks(dependencyGraphMap) {
|
|
|
795
872
|
// when the module layer is same as entry layer, keep it as part of entry and don't split it;
|
|
796
873
|
// when the module layer is different from entry layer, split the module into a separate chunk as a separate boundary.
|
|
797
874
|
if (dependencyGraphMap.has(id)) {
|
|
798
|
-
const
|
|
799
|
-
|
|
875
|
+
const parentModuleIds = Array.from(dependencyGraphMap.get(id));
|
|
876
|
+
const isImportFromOtherEntry = parentModuleIds.some(([id])=>{
|
|
877
|
+
// If other entry is dependency of this entry
|
|
878
|
+
if (entryFiles.has(id)) {
|
|
879
|
+
const entryModuleInfo = ctx.getModuleInfo(id);
|
|
880
|
+
const entryModuleLayer = getModuleLater(entryModuleInfo ? entryModuleInfo.meta : {});
|
|
881
|
+
return entryModuleLayer === moduleLayer;
|
|
882
|
+
}
|
|
883
|
+
return false;
|
|
884
|
+
});
|
|
885
|
+
if (isImportFromOtherEntry) return;
|
|
886
|
+
const isPartOfCurrentEntry = parentModuleIds.every(([, layer])=>layer === moduleLayer);
|
|
887
|
+
if (isPartOfCurrentEntry) {
|
|
888
|
+
if (splitChunksGroupMap.has(id)) {
|
|
889
|
+
return splitChunksGroupMap.get(id);
|
|
890
|
+
}
|
|
800
891
|
return;
|
|
801
892
|
}
|
|
802
893
|
const chunkName = path__default.default.basename(id, path__default.default.extname(id));
|
|
803
|
-
|
|
894
|
+
const chunkGroup = `${chunkName}-${moduleLayer}`;
|
|
895
|
+
splitChunksGroupMap.set(id, chunkGroup);
|
|
896
|
+
return chunkGroup;
|
|
804
897
|
}
|
|
805
898
|
}
|
|
806
899
|
return;
|
|
807
900
|
};
|
|
808
901
|
}
|
|
809
|
-
function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { tsCompilerOptions }, pluginContext, dts) {
|
|
902
|
+
function buildOutputConfigs(entries, pkg, exportPaths, options, exportCondition, cwd, { tsCompilerOptions }, pluginContext, dts) {
|
|
810
903
|
const { format } = options;
|
|
811
904
|
// Add esm mark and interop helper if esm export is detected
|
|
812
905
|
const useEsModuleMark = hasEsmExport(exportPaths, tsCompilerOptions);
|
|
@@ -820,6 +913,7 @@ function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { t
|
|
|
820
913
|
dir: dtsFile ? path.dirname(dtsFile) : dtsDir
|
|
821
914
|
};
|
|
822
915
|
const outputFile = dtsFile || file;
|
|
916
|
+
const entryFiles = new Set(Object.values(entries).map((entry)=>entry.source));
|
|
823
917
|
return {
|
|
824
918
|
name: pkg.name || name,
|
|
825
919
|
...dts ? dtsPathConfig : {
|
|
@@ -832,7 +926,7 @@ function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { t
|
|
|
832
926
|
freeze: false,
|
|
833
927
|
strict: false,
|
|
834
928
|
sourcemap: options.sourcemap,
|
|
835
|
-
manualChunks: createSplitChunks(pluginContext.moduleDirectiveLayerMap),
|
|
929
|
+
manualChunks: createSplitChunks(pluginContext.moduleDirectiveLayerMap, entryFiles),
|
|
836
930
|
chunkFileNames: '[name]-[hash].js',
|
|
837
931
|
// By default in rollup, when creating multiple chunks, transitive imports of entry chunks
|
|
838
932
|
// will be added as empty imports to the entry chunks. Disable to avoid imports hoist outside of boundaries
|
|
@@ -951,7 +1045,7 @@ async function buildConfig(entries, pkg, exportPaths, bundleConfig, exportCondit
|
|
|
951
1045
|
// Generate dts job - single config
|
|
952
1046
|
if (dts) {
|
|
953
1047
|
const typeOutputExports = getExportTypeDist(exportCondition, cwd);
|
|
954
|
-
outputConfigs = typeOutputExports.map((typeFile)=>buildOutputConfigs(pkg, exportPaths, {
|
|
1048
|
+
outputConfigs = typeOutputExports.map((typeFile)=>buildOutputConfigs(entries, pkg, exportPaths, {
|
|
955
1049
|
...bundleConfig,
|
|
956
1050
|
format: 'es',
|
|
957
1051
|
useTypescript,
|
|
@@ -960,7 +1054,7 @@ async function buildConfig(entries, pkg, exportPaths, bundleConfig, exportCondit
|
|
|
960
1054
|
} else {
|
|
961
1055
|
// multi outputs with specified format
|
|
962
1056
|
outputConfigs = outputExports.map((exportDist)=>{
|
|
963
|
-
return buildOutputConfigs(pkg, exportPaths, {
|
|
1057
|
+
return buildOutputConfigs(entries, pkg, exportPaths, {
|
|
964
1058
|
...bundleConfig,
|
|
965
1059
|
file: exportDist.file,
|
|
966
1060
|
format: exportDist.format,
|
|
@@ -972,7 +1066,7 @@ async function buildConfig(entries, pkg, exportPaths, bundleConfig, exportCondit
|
|
|
972
1066
|
var _outputExports_;
|
|
973
1067
|
const fallbackFormat = (_outputExports_ = outputExports[0]) == null ? void 0 : _outputExports_.format;
|
|
974
1068
|
outputConfigs = [
|
|
975
|
-
buildOutputConfigs(pkg, exportPaths, {
|
|
1069
|
+
buildOutputConfigs(entries, pkg, exportPaths, {
|
|
976
1070
|
...bundleConfig,
|
|
977
1071
|
file,
|
|
978
1072
|
format: bundleConfig.format || fallbackFormat,
|
|
@@ -1022,7 +1116,7 @@ function createChunkSizeCollector({ entries }) {
|
|
|
1022
1116
|
const sourceFileName = chunk.facadeModuleId || '';
|
|
1023
1117
|
const exportPath = reversedMapping.get(sourceFileName) || '.';
|
|
1024
1118
|
addSize({
|
|
1025
|
-
fileName:
|
|
1119
|
+
fileName: path__default.default.isAbsolute(cwd) ? path__default.default.relative(cwd, filePath) : filePath,
|
|
1026
1120
|
size,
|
|
1027
1121
|
sourceFileName,
|
|
1028
1122
|
exportPath
|
|
@@ -1046,9 +1140,10 @@ function logSizeStats(sizeCollector) {
|
|
|
1046
1140
|
filesList.forEach((item)=>{
|
|
1047
1141
|
const [filename, , size] = item;
|
|
1048
1142
|
const padding = ' '.repeat(maxLength - filename.length);
|
|
1049
|
-
const
|
|
1143
|
+
const isTypeFile = dtsExtensionRegex.test(filename);
|
|
1144
|
+
const action = isTypeFile ? '[types]' : '[chunk]';
|
|
1050
1145
|
const prettiedSize = prettyBytes__default.default(size);
|
|
1051
|
-
|
|
1146
|
+
paint(' ' + action, isTypeFile ? 'blue' : 'white', `${filename}${padding} - ${prettiedSize}`);
|
|
1052
1147
|
});
|
|
1053
1148
|
});
|
|
1054
1149
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.4",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": "./dist/bin/cli.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -82,14 +82,15 @@
|
|
|
82
82
|
"@swc/types": "^0.1.5",
|
|
83
83
|
"@types/jest": "29.0.0",
|
|
84
84
|
"@types/node": "^20.4.1",
|
|
85
|
+
"bunchee": "link:./",
|
|
85
86
|
"husky": "^8.0.3",
|
|
86
87
|
"jest": "29.0.1",
|
|
87
88
|
"lint-staged": "^13.2.3",
|
|
89
|
+
"picocolors": "^1.0.0",
|
|
88
90
|
"prettier": "^3.0.0",
|
|
89
91
|
"react": "^18.2.0",
|
|
90
92
|
"tsx": "^4.6.2",
|
|
91
|
-
"typescript": "^5.3.2"
|
|
92
|
-
"bunchee": "link:./"
|
|
93
|
+
"typescript": "^5.3.2"
|
|
93
94
|
},
|
|
94
95
|
"lint-staged": {
|
|
95
96
|
"*.{ts,tsx,js,jsx,md,json,yml}": "prettier --write"
|