bunchee 4.4.0 → 4.4.1
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 +20 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +44 -23
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -94,8 +94,9 @@ let createColors = (enabled = isColorSupported)=>({
|
|
|
94
94
|
});
|
|
95
95
|
picocolors.exports = createColors();
|
|
96
96
|
picocolors.exports.createColors = createColors;
|
|
97
|
+
|
|
97
98
|
var picocolorsExports = picocolors.exports;
|
|
98
|
-
var pc = /*@__PURE__*/
|
|
99
|
+
var pc = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
|
|
99
100
|
|
|
100
101
|
const defaultColorFn = (text)=>text;
|
|
101
102
|
function color(prefixColor) {
|
|
@@ -334,8 +335,15 @@ function findExport(exportPath, exportCondition, paths, packageType, currentPath
|
|
|
334
335
|
};
|
|
335
336
|
}
|
|
336
337
|
// main export '.' from main/module/typings
|
|
338
|
+
let mainExportCondition;
|
|
339
|
+
if (pkg.main) {
|
|
340
|
+
const mainExportType = isEsmPackage ? hasCjsExtension(pkg.main) ? 'require' : 'import' : 'require';
|
|
341
|
+
mainExportCondition = {
|
|
342
|
+
[mainExportType]: pkg.main
|
|
343
|
+
};
|
|
344
|
+
}
|
|
337
345
|
const defaultMainExport = constructFullExportCondition({
|
|
338
|
-
|
|
346
|
+
...mainExportCondition,
|
|
339
347
|
module: pkg.module,
|
|
340
348
|
types: getTypings(pkg)
|
|
341
349
|
}, packageType);
|
|
@@ -401,9 +409,6 @@ function lint$1(pkg) {
|
|
|
401
409
|
};
|
|
402
410
|
// Validate ESM package
|
|
403
411
|
if (isESM) {
|
|
404
|
-
if (main && hasCjsExtension(main)) {
|
|
405
|
-
state.badMainExtension = true;
|
|
406
|
-
}
|
|
407
412
|
if (exports) {
|
|
408
413
|
if (typeof exports === 'string') {
|
|
409
414
|
if (hasCjsExtension(exports)) {
|
|
@@ -438,6 +443,9 @@ function lint$1(pkg) {
|
|
|
438
443
|
}
|
|
439
444
|
}
|
|
440
445
|
} else {
|
|
446
|
+
if (main && path__default.default.extname(main) === '.mjs') {
|
|
447
|
+
state.badMainExtension = true;
|
|
448
|
+
}
|
|
441
449
|
// Validate CJS package
|
|
442
450
|
if (exports) {
|
|
443
451
|
if (typeof exports === 'string') {
|
|
@@ -474,7 +482,7 @@ function lint$1(pkg) {
|
|
|
474
482
|
}
|
|
475
483
|
}
|
|
476
484
|
if (state.badMainExtension) {
|
|
477
|
-
logger.warn('Cannot export `main` field with .
|
|
485
|
+
logger.warn('Cannot export `main` field with .mjs extension in CJS package, only .js extension is allowed');
|
|
478
486
|
}
|
|
479
487
|
if (state.badMainExport) {
|
|
480
488
|
logger.warn('Cannot export `exports` field with .cjs extension in ESM package, only .mjs and .js extensions are allowed');
|
|
@@ -508,7 +516,7 @@ function lint$1(pkg) {
|
|
|
508
516
|
}
|
|
509
517
|
}
|
|
510
518
|
|
|
511
|
-
var version = "4.4.
|
|
519
|
+
var version = "4.4.1";
|
|
512
520
|
|
|
513
521
|
function relativify(path) {
|
|
514
522
|
return path.startsWith('.') ? path : `./${path}`;
|
|
@@ -709,7 +717,9 @@ async function prepare(cwd) {
|
|
|
709
717
|
} else {
|
|
710
718
|
// Update existing exports
|
|
711
719
|
Object.keys(pkgExports).forEach((exportName)=>{
|
|
712
|
-
pkgJson.exports[exportName]
|
|
720
|
+
if (pkgJson.exports[exportName]) {
|
|
721
|
+
pkgJson.exports[exportName] = pkgExports[exportName];
|
|
722
|
+
}
|
|
713
723
|
});
|
|
714
724
|
}
|
|
715
725
|
}
|
|
@@ -827,11 +837,11 @@ async function run(args) {
|
|
|
827
837
|
if (args.prepare) {
|
|
828
838
|
return await prepare(cwd);
|
|
829
839
|
}
|
|
830
|
-
const
|
|
840
|
+
const cliEntry = source ? path__default.default.resolve(cwd, source) : '';
|
|
831
841
|
// lint package
|
|
832
842
|
await lint(cwd);
|
|
833
843
|
try {
|
|
834
|
-
await bunchee.bundle(
|
|
844
|
+
await bunchee.bundle(cliEntry, bundleConfig);
|
|
835
845
|
} catch (err) {
|
|
836
846
|
if (err.name === 'NOT_EXISTED') {
|
|
837
847
|
help();
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,6 @@ type PackageMetadata = {
|
|
|
33
33
|
typings?: string;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
declare function bundle(
|
|
36
|
+
declare function bundle(cliEntryPath: string, { cwd: _cwd, ...options }?: BundleConfig): Promise<any>;
|
|
37
37
|
|
|
38
38
|
export { type BundleConfig, bundle };
|
package/dist/index.js
CHANGED
|
@@ -82,8 +82,9 @@ let createColors = (enabled = isColorSupported)=>({
|
|
|
82
82
|
});
|
|
83
83
|
picocolors.exports = createColors();
|
|
84
84
|
picocolors.exports.createColors = createColors;
|
|
85
|
+
|
|
85
86
|
var picocolorsExports = picocolors.exports;
|
|
86
|
-
var pc = /*@__PURE__*/
|
|
87
|
+
var pc = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
|
|
87
88
|
|
|
88
89
|
const availableExtensions = new Set([
|
|
89
90
|
'js',
|
|
@@ -233,6 +234,7 @@ function filePathWithoutExtension(file) {
|
|
|
233
234
|
}
|
|
234
235
|
const nonNullable = (n)=>Boolean(n);
|
|
235
236
|
const hasAvailableExtension = (filename)=>availableExtensions.has(path__default.default.extname(filename).slice(1));
|
|
237
|
+
const hasCjsExtension = (filename)=>path__default.default.extname(filename) === '.cjs';
|
|
236
238
|
// TODO: add unit test
|
|
237
239
|
const baseNameWithoutExtension = (filename)=>path__default.default.basename(filename, path__default.default.extname(filename));
|
|
238
240
|
|
|
@@ -593,8 +595,15 @@ function findExport(exportPath, exportCondition, paths, packageType, currentPath
|
|
|
593
595
|
};
|
|
594
596
|
}
|
|
595
597
|
// main export '.' from main/module/typings
|
|
598
|
+
let mainExportCondition;
|
|
599
|
+
if (pkg.main) {
|
|
600
|
+
const mainExportType = isEsmPackage ? hasCjsExtension(pkg.main) ? 'require' : 'import' : 'require';
|
|
601
|
+
mainExportCondition = {
|
|
602
|
+
[mainExportType]: pkg.main
|
|
603
|
+
};
|
|
604
|
+
}
|
|
596
605
|
const defaultMainExport = constructFullExportCondition({
|
|
597
|
-
|
|
606
|
+
...mainExportCondition,
|
|
598
607
|
module: pkg.module,
|
|
599
608
|
types: getTypings(pkg)
|
|
600
609
|
}, packageType);
|
|
@@ -798,6 +807,13 @@ async function buildInputConfig(entry, options, buildContext, exportCondition, d
|
|
|
798
807
|
})
|
|
799
808
|
];
|
|
800
809
|
if (useTypeScript) {
|
|
810
|
+
const enableIncrementalWithoutBuildInfo = tsCompilerOptions.incremental && !tsCompilerOptions.tsBuildInfoFile;
|
|
811
|
+
const incrementalOptions = enableIncrementalWithoutBuildInfo ? {
|
|
812
|
+
incremental: false
|
|
813
|
+
} : undefined;
|
|
814
|
+
const compositeOptions = tsCompilerOptions.composite && enableIncrementalWithoutBuildInfo ? {
|
|
815
|
+
composite: false
|
|
816
|
+
} : undefined;
|
|
801
817
|
const { options: overrideResolvedTsOptions } = await convertCompilerOptions(cwd, {
|
|
802
818
|
declaration: true,
|
|
803
819
|
noEmit: false,
|
|
@@ -812,9 +828,9 @@ async function buildInputConfig(entry, options, buildContext, exportCondition, d
|
|
|
812
828
|
} : undefined,
|
|
813
829
|
// error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single
|
|
814
830
|
// file or when option '--tsBuildInfoFile' is specified.
|
|
815
|
-
...
|
|
816
|
-
|
|
817
|
-
|
|
831
|
+
...incrementalOptions,
|
|
832
|
+
// error TS6379: Composite projects may not disable incremental compilation.
|
|
833
|
+
...compositeOptions
|
|
818
834
|
});
|
|
819
835
|
const dtsPlugin = require('rollup-plugin-dts').default({
|
|
820
836
|
tsconfig: tsConfigPath,
|
|
@@ -841,17 +857,18 @@ async function buildInputConfig(entry, options, buildContext, exportCondition, d
|
|
|
841
857
|
preferBuiltins: runtime === 'node',
|
|
842
858
|
extensions: nodeResolveExtensions
|
|
843
859
|
}),
|
|
844
|
-
commonjs__default.default({
|
|
845
|
-
exclude: options.external || null
|
|
846
|
-
}),
|
|
847
|
-
json__default.default(),
|
|
848
860
|
pluginWasm.wasm(),
|
|
849
861
|
rollupPluginSwc3.swc({
|
|
850
862
|
include: availableESExtensionsRegex,
|
|
851
863
|
exclude: 'node_modules',
|
|
852
|
-
tsconfig
|
|
864
|
+
// Use `false` to disable retrieving tsconfig.json
|
|
865
|
+
tsconfig: tsConfigPath != null ? tsConfigPath : false,
|
|
853
866
|
...swcOptions
|
|
854
|
-
})
|
|
867
|
+
}),
|
|
868
|
+
commonjs__default.default({
|
|
869
|
+
exclude: options.external || null
|
|
870
|
+
}),
|
|
871
|
+
json__default.default()
|
|
855
872
|
]).filter(isNotNull);
|
|
856
873
|
return {
|
|
857
874
|
input: entry,
|
|
@@ -1284,11 +1301,12 @@ function logOutputState(sizeCollector) {
|
|
|
1284
1301
|
}).forEach((item, index)=>{
|
|
1285
1302
|
const [filename, , size] = item;
|
|
1286
1303
|
const normalizedExportName = normalizeExportName(exportName);
|
|
1287
|
-
const prefix = index === 0 ? normalizedExportName
|
|
1288
|
-
const
|
|
1289
|
-
const prettiedSize = prettyBytes__default.default(size);
|
|
1304
|
+
const prefix = index === 0 ? normalizedExportName : ' '.repeat(normalizedExportName.length);
|
|
1305
|
+
const filenamePadding = ' '.repeat(Math.max(maxLengthOfExportName, 'Exports'.length) - normalizedExportName.length);
|
|
1290
1306
|
const isType = isTypeFile(filename);
|
|
1291
|
-
|
|
1307
|
+
const sizePadding = ' '.repeat(Math.max(maxFilenameLength, 'File'.length) - filename.length);
|
|
1308
|
+
const prettiedSize = prettyBytes__default.default(size);
|
|
1309
|
+
console.log(prefix, filenamePadding, `${pc[isType ? 'dim' : 'bold'](filename)}`, sizePadding, prettiedSize);
|
|
1292
1310
|
});
|
|
1293
1311
|
});
|
|
1294
1312
|
}
|
|
@@ -1357,7 +1375,7 @@ function hasMultiEntryExport(exportPaths) {
|
|
|
1357
1375
|
const exportKeys = Object.keys(exportPaths).filter((key)=>key !== './package.json');
|
|
1358
1376
|
return exportKeys.length > 0 && exportKeys.every((name)=>name.startsWith('.'));
|
|
1359
1377
|
}
|
|
1360
|
-
async function bundle(
|
|
1378
|
+
async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
1361
1379
|
const cwd = path.resolve(process.cwd(), _cwd || '');
|
|
1362
1380
|
assignDefault(options, 'format', 'es');
|
|
1363
1381
|
assignDefault(options, 'minify', false);
|
|
@@ -1369,6 +1387,7 @@ async function bundle(entryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1369
1387
|
const isMultiEntries = hasMultiEntryExport(exportPaths) // exportPathsLength > 1
|
|
1370
1388
|
;
|
|
1371
1389
|
const hasBin = Boolean(pkg.bin);
|
|
1390
|
+
const isFromCli = Boolean(cliEntryPath);
|
|
1372
1391
|
let tsConfig = await resolveTsConfig(cwd);
|
|
1373
1392
|
let hasTsConfig = Boolean(tsConfig == null ? void 0 : tsConfig.tsConfigPath);
|
|
1374
1393
|
const defaultTsOptions = {
|
|
@@ -1379,10 +1398,10 @@ async function bundle(entryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1379
1398
|
if (!isMultiEntries) {
|
|
1380
1399
|
// Use specified string file path if possible, then fallback to the default behavior entry picking logic
|
|
1381
1400
|
// e.g. "exports": "./dist/index.js" -> use "./index.<ext>" as entry
|
|
1382
|
-
|
|
1401
|
+
cliEntryPath = cliEntryPath || await getSourcePathFromExportPath(cwd, '.', 'default') || '';
|
|
1383
1402
|
}
|
|
1384
1403
|
// Handle CLI input
|
|
1385
|
-
if (
|
|
1404
|
+
if (cliEntryPath) {
|
|
1386
1405
|
let mainEntryPath;
|
|
1387
1406
|
let typesEntryPath;
|
|
1388
1407
|
// with -o option
|
|
@@ -1401,18 +1420,20 @@ async function bundle(entryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1401
1420
|
}
|
|
1402
1421
|
const bundleOrWatch = async (rollupConfig)=>{
|
|
1403
1422
|
if (options.clean) {
|
|
1404
|
-
|
|
1423
|
+
if (!isFromCli) {
|
|
1424
|
+
await removeOutputDir(rollupConfig.output);
|
|
1425
|
+
}
|
|
1405
1426
|
}
|
|
1406
1427
|
if (options.watch) {
|
|
1407
1428
|
return Promise.resolve(runWatch(rollupConfig));
|
|
1408
1429
|
}
|
|
1409
1430
|
return runBundle(rollupConfig);
|
|
1410
1431
|
};
|
|
1411
|
-
const hasSpecifiedEntryFile =
|
|
1432
|
+
const hasSpecifiedEntryFile = cliEntryPath ? fs__default.default.existsSync(cliEntryPath) && (await fsp__default.default.stat(cliEntryPath)).isFile() : false;
|
|
1412
1433
|
const hasNoEntry = !hasSpecifiedEntryFile && !isMultiEntries && !hasBin;
|
|
1413
1434
|
if (hasNoEntry) {
|
|
1414
|
-
if (
|
|
1415
|
-
const err = new Error(`Entry file "${
|
|
1435
|
+
if (cliEntryPath) {
|
|
1436
|
+
const err = new Error(`Entry file "${cliEntryPath}" does not exist`);
|
|
1416
1437
|
err.name = 'NOT_EXISTED';
|
|
1417
1438
|
return Promise.reject(err);
|
|
1418
1439
|
} else if (cwd) {
|
|
@@ -1424,7 +1445,7 @@ async function bundle(entryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1424
1445
|
}
|
|
1425
1446
|
}
|
|
1426
1447
|
}
|
|
1427
|
-
const entries = await collectEntries(pkg,
|
|
1448
|
+
const entries = await collectEntries(pkg, cliEntryPath, exportPaths, cwd);
|
|
1428
1449
|
const hasTypeScriptFiles = Object.values(entries).some((entry)=>isTypescriptFile(entry.source));
|
|
1429
1450
|
if (hasTypeScriptFiles && !hasTsConfig) {
|
|
1430
1451
|
const tsConfigPath = path.resolve(cwd, 'tsconfig.json');
|