bunchee 6.0.0-rc.1 → 6.0.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 +2 -2
- package/dist/bin/cli.js +56 -39
- package/dist/index.js +1 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ The output format will based on the exports condition and also the file extensio
|
|
|
54
54
|
> [!NOTE]
|
|
55
55
|
> All the `dependencies` and `peerDependencies` will be marked as external automatically and not included in the bundle. If you want to include them in the bundle, you can use the `--no-external` option.
|
|
56
56
|
|
|
57
|
-
#### Prepare
|
|
57
|
+
#### Prepare Package
|
|
58
58
|
|
|
59
59
|
```sh
|
|
60
60
|
# Use bunchee to prepare package.json configuration
|
|
@@ -142,7 +142,7 @@ If you're using TypeScript with Node 10 and Node 16 module resolution, you can u
|
|
|
142
142
|
|
|
143
143
|
</details>
|
|
144
144
|
|
|
145
|
-
#### Lint
|
|
145
|
+
#### Lint Package
|
|
146
146
|
|
|
147
147
|
`lint` command will check the package.json configuration is valid or not, it can valid few things like:
|
|
148
148
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -373,6 +373,17 @@ function getExportTypeFromFile(filename, pkgType) {
|
|
|
373
373
|
return exportType;
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
+
const matchFile = (matchingPattern, filePath)=>{
|
|
377
|
+
return matchingPattern.some((pattern)=>{
|
|
378
|
+
// pattern is always posix
|
|
379
|
+
const normalizedPattern = path__default.default.posix.normalize(pattern);
|
|
380
|
+
const expandedPattern = normalizedPattern.endsWith('/') ? `${normalizedPattern}**` : `${normalizedPattern}/**`;
|
|
381
|
+
const matcher = picomatch__default.default(expandedPattern);
|
|
382
|
+
const normalizedFilePath = path__default.default.normalize(filePath.replace(/\\/g, '/'));
|
|
383
|
+
return matcher(normalizedFilePath);
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
|
|
376
387
|
function validateTypesFieldCondition(pair) {
|
|
377
388
|
const [outputPath, composedExportType] = pair;
|
|
378
389
|
const exportTypes = new Set(composedExportType.split('.'));
|
|
@@ -381,13 +392,6 @@ function validateTypesFieldCondition(pair) {
|
|
|
381
392
|
}
|
|
382
393
|
return false;
|
|
383
394
|
}
|
|
384
|
-
const isPathIncluded = (filesField, filePath)=>{
|
|
385
|
-
return filesField.some((pattern)=>{
|
|
386
|
-
const normalizedPattern = path__default.default.normalize(pattern);
|
|
387
|
-
const matcher = picomatch__default.default(normalizedPattern);
|
|
388
|
-
return matcher(filePath);
|
|
389
|
-
});
|
|
390
|
-
};
|
|
391
395
|
function validateFilesField(packageJson) {
|
|
392
396
|
const state = {
|
|
393
397
|
definedField: false,
|
|
@@ -420,7 +424,7 @@ function validateFilesField(packageJson) {
|
|
|
420
424
|
}
|
|
421
425
|
}
|
|
422
426
|
state.missingFiles = exportedPaths.filter((exportPath)=>{
|
|
423
|
-
return !
|
|
427
|
+
return !matchFile(filesField, exportPath);
|
|
424
428
|
});
|
|
425
429
|
return state;
|
|
426
430
|
}
|
|
@@ -431,7 +435,7 @@ function lint$1(pkg) {
|
|
|
431
435
|
if (!name) {
|
|
432
436
|
logger.warn('Missing package name');
|
|
433
437
|
}
|
|
434
|
-
const
|
|
438
|
+
const exportsState = {
|
|
435
439
|
badMainExtension: false,
|
|
436
440
|
badMainExport: false,
|
|
437
441
|
invalidExportsFieldType: false,
|
|
@@ -458,10 +462,10 @@ function lint$1(pkg) {
|
|
|
458
462
|
if (exports) {
|
|
459
463
|
if (typeof exports === 'string') {
|
|
460
464
|
if (hasCjsExtension(exports)) {
|
|
461
|
-
|
|
465
|
+
exportsState.badMainExport = true;
|
|
462
466
|
}
|
|
463
467
|
} else if (typeof exports !== 'object') {
|
|
464
|
-
|
|
468
|
+
exportsState.invalidExportsFieldType = true;
|
|
465
469
|
} else {
|
|
466
470
|
parsedExports.forEach((outputPairs)=>{
|
|
467
471
|
for (const outputPair of outputPairs){
|
|
@@ -470,7 +474,7 @@ function lint$1(pkg) {
|
|
|
470
474
|
outputPath,
|
|
471
475
|
composedExportType
|
|
472
476
|
])) {
|
|
473
|
-
|
|
477
|
+
exportsState.badTypesExport.push([
|
|
474
478
|
outputPath,
|
|
475
479
|
composedExportType
|
|
476
480
|
]);
|
|
@@ -487,12 +491,12 @@ function lint$1(pkg) {
|
|
|
487
491
|
const requireExt = requirePath && path__default.default.extname(requirePath);
|
|
488
492
|
const importExt = importPath && path__default.default.extname(importPath);
|
|
489
493
|
if (requireExt === '.mjs' || requireExt === '.js') {
|
|
490
|
-
|
|
491
|
-
|
|
494
|
+
exportsState.badEsmRequireExport.value = true;
|
|
495
|
+
exportsState.badEsmRequireExport.paths.push(requirePath);
|
|
492
496
|
}
|
|
493
497
|
if (importExt === '.cjs') {
|
|
494
|
-
|
|
495
|
-
|
|
498
|
+
exportsState.badEsmImportExport.value = true;
|
|
499
|
+
exportsState.badEsmImportExport.paths.push(importPath);
|
|
496
500
|
}
|
|
497
501
|
}
|
|
498
502
|
});
|
|
@@ -501,15 +505,15 @@ function lint$1(pkg) {
|
|
|
501
505
|
} else {
|
|
502
506
|
// Validate CJS package
|
|
503
507
|
if (main && path__default.default.extname(main) === '.mjs') {
|
|
504
|
-
|
|
508
|
+
exportsState.badMainExtension = true;
|
|
505
509
|
}
|
|
506
510
|
if (exports) {
|
|
507
511
|
if (typeof exports === 'string') {
|
|
508
512
|
if (path__default.default.extname(exports) === '.mjs') {
|
|
509
|
-
|
|
513
|
+
exportsState.badMainExport = true;
|
|
510
514
|
}
|
|
511
515
|
} else if (typeof exports !== 'object') {
|
|
512
|
-
|
|
516
|
+
exportsState.invalidExportsFieldType = true;
|
|
513
517
|
} else {
|
|
514
518
|
parsedExports.forEach((outputPairs)=>{
|
|
515
519
|
for (const outputPair of outputPairs){
|
|
@@ -518,7 +522,7 @@ function lint$1(pkg) {
|
|
|
518
522
|
outputPath,
|
|
519
523
|
composedExportType
|
|
520
524
|
])) {
|
|
521
|
-
|
|
525
|
+
exportsState.badTypesExport.push([
|
|
522
526
|
outputPath,
|
|
523
527
|
composedExportType
|
|
524
528
|
]);
|
|
@@ -535,12 +539,12 @@ function lint$1(pkg) {
|
|
|
535
539
|
const requireExt = requirePath && path__default.default.extname(requirePath);
|
|
536
540
|
const importExt = importPath && path__default.default.extname(importPath);
|
|
537
541
|
if (requireExt === '.mjs') {
|
|
538
|
-
|
|
539
|
-
|
|
542
|
+
exportsState.badCjsRequireExport.value = true;
|
|
543
|
+
exportsState.badCjsRequireExport.paths.push(requirePath);
|
|
540
544
|
}
|
|
541
545
|
if (importExt === '.js' || importExt === '.cjs') {
|
|
542
|
-
|
|
543
|
-
|
|
546
|
+
exportsState.badCjsImportExport.value = true;
|
|
547
|
+
exportsState.badCjsImportExport.paths.push(importPath);
|
|
544
548
|
}
|
|
545
549
|
}
|
|
546
550
|
});
|
|
@@ -548,6 +552,12 @@ function lint$1(pkg) {
|
|
|
548
552
|
}
|
|
549
553
|
}
|
|
550
554
|
const fieldState = validateFilesField(pkg);
|
|
555
|
+
const warningsCount = exportsState.badTypesExport.length + fieldState.missingFiles.length;
|
|
556
|
+
if (warningsCount) {
|
|
557
|
+
logger.warn(`Lint: ${warningsCount} issues found.`);
|
|
558
|
+
} else {
|
|
559
|
+
logger.info(`Lint: package.json is healthy.`);
|
|
560
|
+
}
|
|
551
561
|
if (!fieldState.definedField) {
|
|
552
562
|
logger.warn('Missing files field in package.json');
|
|
553
563
|
} else if (fieldState.missingFiles.length) {
|
|
@@ -556,52 +566,51 @@ function lint$1(pkg) {
|
|
|
556
566
|
logger.warn(` ${p}`);
|
|
557
567
|
});
|
|
558
568
|
}
|
|
559
|
-
if (
|
|
569
|
+
if (exportsState.badMainExtension) {
|
|
560
570
|
logger.warn('Cannot export `main` field with .mjs extension in CJS package, only .js extension is allowed');
|
|
561
571
|
}
|
|
562
|
-
if (
|
|
572
|
+
if (exportsState.badMainExport) {
|
|
563
573
|
if (isESM) {
|
|
564
574
|
logger.warn('Cannot export `exports` field with .cjs extension in ESM package, only .mjs and .js extensions are allowed');
|
|
565
575
|
} else {
|
|
566
576
|
logger.warn('Cannot export `exports` field with .mjs extension in CJS package, only .js and .cjs extensions are allowed');
|
|
567
577
|
}
|
|
568
578
|
}
|
|
569
|
-
if (
|
|
579
|
+
if (exportsState.invalidExportsFieldType) {
|
|
570
580
|
logger.warn('Invalid exports field type, only object or string is allowed');
|
|
571
581
|
}
|
|
572
|
-
if (
|
|
582
|
+
if (exportsState.badCjsRequireExport.value) {
|
|
573
583
|
logger.warn('Cannot export `require` field with .mjs extension in CJS package, only .cjs and .js extensions are allowed');
|
|
574
|
-
|
|
584
|
+
exportsState.badCjsRequireExport.paths.forEach((p)=>{
|
|
575
585
|
logger.warn(` ${p}`);
|
|
576
586
|
});
|
|
577
587
|
}
|
|
578
|
-
if (
|
|
588
|
+
if (exportsState.badCjsImportExport.value) {
|
|
579
589
|
logger.warn('Cannot export `import` field with .js or .cjs extension in CJS package, only .mjs extensions are allowed');
|
|
580
|
-
|
|
590
|
+
exportsState.badCjsImportExport.paths.forEach((p)=>{
|
|
581
591
|
logger.warn(` ${p}`);
|
|
582
592
|
});
|
|
583
593
|
}
|
|
584
|
-
if (
|
|
594
|
+
if (exportsState.badEsmRequireExport.value) {
|
|
585
595
|
logger.warn('Cannot export `require` field with .js or .mjs extension in ESM package, only .cjs extensions are allowed');
|
|
586
|
-
|
|
596
|
+
exportsState.badEsmRequireExport.paths.forEach((p)=>{
|
|
587
597
|
logger.warn(` ${p}`);
|
|
588
598
|
});
|
|
589
599
|
}
|
|
590
|
-
if (
|
|
600
|
+
if (exportsState.badEsmImportExport.value) {
|
|
591
601
|
logger.warn('Cannot export `import` field with .cjs extension in ESM package, only .js and .mjs extensions are allowed');
|
|
592
|
-
|
|
602
|
+
exportsState.badEsmImportExport.paths.forEach((p)=>{
|
|
593
603
|
logger.warn(` ${p}`);
|
|
594
604
|
});
|
|
595
605
|
}
|
|
596
|
-
if (
|
|
597
|
-
|
|
606
|
+
if (exportsState.badTypesExport.length) {
|
|
607
|
+
exportsState.badTypesExport.forEach(([outputPath, composedExportType])=>{
|
|
598
608
|
logger.error(`Bad export types field with ${composedExportType} in ${outputPath}, use "types" export condition for it`);
|
|
599
609
|
});
|
|
600
|
-
process.exit(1);
|
|
601
610
|
}
|
|
602
611
|
}
|
|
603
612
|
|
|
604
|
-
var version = "6.0.0
|
|
613
|
+
var version = "6.0.0";
|
|
605
614
|
|
|
606
615
|
async function writeDefaultTsconfig(tsConfigPath) {
|
|
607
616
|
await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
|
|
@@ -1094,6 +1103,9 @@ async function parseCliArgs(argv) {
|
|
|
1094
1103
|
}).option('dts-bundle', {
|
|
1095
1104
|
type: 'boolean',
|
|
1096
1105
|
description: 'bundle type declaration files'
|
|
1106
|
+
}).option('prepare', {
|
|
1107
|
+
type: 'boolean',
|
|
1108
|
+
description: 'auto setup package.json for building'
|
|
1097
1109
|
}).command('prepare', 'auto configure package.json exports for building', ()=>{}, (argv)=>{
|
|
1098
1110
|
return prepare(argv.cwd || process.cwd());
|
|
1099
1111
|
}).command('lint', 'lint package.json', ()=>{}, (argv)=>{
|
|
@@ -1105,6 +1117,11 @@ async function parseCliArgs(argv) {
|
|
|
1105
1117
|
cmd
|
|
1106
1118
|
};
|
|
1107
1119
|
}
|
|
1120
|
+
// Warn about this command being deprecated
|
|
1121
|
+
if (args['prepare']) {
|
|
1122
|
+
logger.warn('The "--prepare" option is deprecated. Please use `bunchee prepare` instead.');
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1108
1125
|
const source = args._[0];
|
|
1109
1126
|
const parsedArgs = {
|
|
1110
1127
|
source,
|
package/dist/index.js
CHANGED
|
@@ -1801,11 +1801,10 @@ function runWatch({ input, output }) {
|
|
|
1801
1801
|
}
|
|
1802
1802
|
function catchErrorHandler(error) {
|
|
1803
1803
|
if (!error) return;
|
|
1804
|
-
logger.error(error);
|
|
1805
1804
|
// filter out the rollup plugin error information such as loc/frame/code...
|
|
1806
1805
|
const err = new Error(error.message);
|
|
1807
1806
|
err.stack = error.stack;
|
|
1808
|
-
throw
|
|
1807
|
+
throw error;
|
|
1809
1808
|
}
|
|
1810
1809
|
|
|
1811
1810
|
function assignDefault(options, name, defaultValue) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "6.0.0
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": "./dist/bin/cli.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
42
42
|
"@rollup/plugin-replace": "^6.0.1",
|
|
43
43
|
"@rollup/plugin-wasm": "^6.2.2",
|
|
44
|
-
"@rollup/pluginutils": "^5.1.
|
|
44
|
+
"@rollup/pluginutils": "^5.1.3",
|
|
45
45
|
"@swc/core": "^1.9.3",
|
|
46
46
|
"@swc/helpers": "^0.5.11",
|
|
47
47
|
"clean-css": "^5.3.3",
|
|
48
48
|
"glob": "^11.0.0",
|
|
49
|
-
"magic-string": "^0.30.
|
|
49
|
+
"magic-string": "^0.30.14",
|
|
50
50
|
"ora": "^8.0.1",
|
|
51
51
|
"picomatch": "^4.0.2",
|
|
52
52
|
"pretty-bytes": "^5.6.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@huozhi/testing-package": "1.0.0",
|
|
73
|
-
"@swc-node/register": "^1.9
|
|
73
|
+
"@swc-node/register": "^1.10.9",
|
|
74
74
|
"@swc/jest": "^0.2.31",
|
|
75
75
|
"@swc/types": "^0.1.9",
|
|
76
76
|
"@types/clean-css": "^4.2.11",
|