bunchee 6.0.0-rc.1 → 6.0.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/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,16 +392,9 @@ 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
- definedField: false,
397
+ definedField: true,
394
398
  missingFiles: []
395
399
  };
396
400
  const filesField = packageJson.files || [];
@@ -420,7 +424,11 @@ function validateFilesField(packageJson) {
420
424
  }
421
425
  }
422
426
  state.missingFiles = exportedPaths.filter((exportPath)=>{
423
- return !isPathIncluded(filesField, exportPath);
427
+ // Special case for package.json
428
+ if (exportPath === './package.json') {
429
+ return false;
430
+ }
431
+ return !matchFile(filesField, exportPath);
424
432
  });
425
433
  return state;
426
434
  }
@@ -431,7 +439,7 @@ function lint$1(pkg) {
431
439
  if (!name) {
432
440
  logger.warn('Missing package name');
433
441
  }
434
- const state = {
442
+ const exportsState = {
435
443
  badMainExtension: false,
436
444
  badMainExport: false,
437
445
  invalidExportsFieldType: false,
@@ -458,10 +466,10 @@ function lint$1(pkg) {
458
466
  if (exports) {
459
467
  if (typeof exports === 'string') {
460
468
  if (hasCjsExtension(exports)) {
461
- state.badMainExport = true;
469
+ exportsState.badMainExport = true;
462
470
  }
463
471
  } else if (typeof exports !== 'object') {
464
- state.invalidExportsFieldType = true;
472
+ exportsState.invalidExportsFieldType = true;
465
473
  } else {
466
474
  parsedExports.forEach((outputPairs)=>{
467
475
  for (const outputPair of outputPairs){
@@ -470,7 +478,7 @@ function lint$1(pkg) {
470
478
  outputPath,
471
479
  composedExportType
472
480
  ])) {
473
- state.badTypesExport.push([
481
+ exportsState.badTypesExport.push([
474
482
  outputPath,
475
483
  composedExportType
476
484
  ]);
@@ -487,12 +495,12 @@ function lint$1(pkg) {
487
495
  const requireExt = requirePath && path__default.default.extname(requirePath);
488
496
  const importExt = importPath && path__default.default.extname(importPath);
489
497
  if (requireExt === '.mjs' || requireExt === '.js') {
490
- state.badEsmRequireExport.value = true;
491
- state.badEsmRequireExport.paths.push(requirePath);
498
+ exportsState.badEsmRequireExport.value = true;
499
+ exportsState.badEsmRequireExport.paths.push(requirePath);
492
500
  }
493
501
  if (importExt === '.cjs') {
494
- state.badEsmImportExport.value = true;
495
- state.badEsmImportExport.paths.push(importPath);
502
+ exportsState.badEsmImportExport.value = true;
503
+ exportsState.badEsmImportExport.paths.push(importPath);
496
504
  }
497
505
  }
498
506
  });
@@ -501,15 +509,15 @@ function lint$1(pkg) {
501
509
  } else {
502
510
  // Validate CJS package
503
511
  if (main && path__default.default.extname(main) === '.mjs') {
504
- state.badMainExtension = true;
512
+ exportsState.badMainExtension = true;
505
513
  }
506
514
  if (exports) {
507
515
  if (typeof exports === 'string') {
508
516
  if (path__default.default.extname(exports) === '.mjs') {
509
- state.badMainExport = true;
517
+ exportsState.badMainExport = true;
510
518
  }
511
519
  } else if (typeof exports !== 'object') {
512
- state.invalidExportsFieldType = true;
520
+ exportsState.invalidExportsFieldType = true;
513
521
  } else {
514
522
  parsedExports.forEach((outputPairs)=>{
515
523
  for (const outputPair of outputPairs){
@@ -518,7 +526,7 @@ function lint$1(pkg) {
518
526
  outputPath,
519
527
  composedExportType
520
528
  ])) {
521
- state.badTypesExport.push([
529
+ exportsState.badTypesExport.push([
522
530
  outputPath,
523
531
  composedExportType
524
532
  ]);
@@ -535,12 +543,12 @@ function lint$1(pkg) {
535
543
  const requireExt = requirePath && path__default.default.extname(requirePath);
536
544
  const importExt = importPath && path__default.default.extname(importPath);
537
545
  if (requireExt === '.mjs') {
538
- state.badCjsRequireExport.value = true;
539
- state.badCjsRequireExport.paths.push(requirePath);
546
+ exportsState.badCjsRequireExport.value = true;
547
+ exportsState.badCjsRequireExport.paths.push(requirePath);
540
548
  }
541
549
  if (importExt === '.js' || importExt === '.cjs') {
542
- state.badCjsImportExport.value = true;
543
- state.badCjsImportExport.paths.push(importPath);
550
+ exportsState.badCjsImportExport.value = true;
551
+ exportsState.badCjsImportExport.paths.push(importPath);
544
552
  }
545
553
  }
546
554
  });
@@ -548,6 +556,12 @@ function lint$1(pkg) {
548
556
  }
549
557
  }
550
558
  const fieldState = validateFilesField(pkg);
559
+ const warningsCount = exportsState.badTypesExport.length + fieldState.missingFiles.length;
560
+ if (warningsCount) {
561
+ logger.warn(`Lint: ${warningsCount} issues found.`);
562
+ } else {
563
+ logger.info(`Lint: package.json is healthy.`);
564
+ }
551
565
  if (!fieldState.definedField) {
552
566
  logger.warn('Missing files field in package.json');
553
567
  } else if (fieldState.missingFiles.length) {
@@ -556,52 +570,51 @@ function lint$1(pkg) {
556
570
  logger.warn(` ${p}`);
557
571
  });
558
572
  }
559
- if (state.badMainExtension) {
573
+ if (exportsState.badMainExtension) {
560
574
  logger.warn('Cannot export `main` field with .mjs extension in CJS package, only .js extension is allowed');
561
575
  }
562
- if (state.badMainExport) {
576
+ if (exportsState.badMainExport) {
563
577
  if (isESM) {
564
578
  logger.warn('Cannot export `exports` field with .cjs extension in ESM package, only .mjs and .js extensions are allowed');
565
579
  } else {
566
580
  logger.warn('Cannot export `exports` field with .mjs extension in CJS package, only .js and .cjs extensions are allowed');
567
581
  }
568
582
  }
569
- if (state.invalidExportsFieldType) {
583
+ if (exportsState.invalidExportsFieldType) {
570
584
  logger.warn('Invalid exports field type, only object or string is allowed');
571
585
  }
572
- if (state.badCjsRequireExport.value) {
586
+ if (exportsState.badCjsRequireExport.value) {
573
587
  logger.warn('Cannot export `require` field with .mjs extension in CJS package, only .cjs and .js extensions are allowed');
574
- state.badCjsRequireExport.paths.forEach((p)=>{
588
+ exportsState.badCjsRequireExport.paths.forEach((p)=>{
575
589
  logger.warn(` ${p}`);
576
590
  });
577
591
  }
578
- if (state.badCjsImportExport.value) {
592
+ if (exportsState.badCjsImportExport.value) {
579
593
  logger.warn('Cannot export `import` field with .js or .cjs extension in CJS package, only .mjs extensions are allowed');
580
- state.badCjsImportExport.paths.forEach((p)=>{
594
+ exportsState.badCjsImportExport.paths.forEach((p)=>{
581
595
  logger.warn(` ${p}`);
582
596
  });
583
597
  }
584
- if (state.badEsmRequireExport.value) {
598
+ if (exportsState.badEsmRequireExport.value) {
585
599
  logger.warn('Cannot export `require` field with .js or .mjs extension in ESM package, only .cjs extensions are allowed');
586
- state.badEsmRequireExport.paths.forEach((p)=>{
600
+ exportsState.badEsmRequireExport.paths.forEach((p)=>{
587
601
  logger.warn(` ${p}`);
588
602
  });
589
603
  }
590
- if (state.badEsmImportExport.value) {
604
+ if (exportsState.badEsmImportExport.value) {
591
605
  logger.warn('Cannot export `import` field with .cjs extension in ESM package, only .js and .mjs extensions are allowed');
592
- state.badEsmImportExport.paths.forEach((p)=>{
606
+ exportsState.badEsmImportExport.paths.forEach((p)=>{
593
607
  logger.warn(` ${p}`);
594
608
  });
595
609
  }
596
- if (state.badTypesExport.length) {
597
- state.badTypesExport.forEach(([outputPath, composedExportType])=>{
610
+ if (exportsState.badTypesExport.length) {
611
+ exportsState.badTypesExport.forEach(([outputPath, composedExportType])=>{
598
612
  logger.error(`Bad export types field with ${composedExportType} in ${outputPath}, use "types" export condition for it`);
599
613
  });
600
- process.exit(1);
601
614
  }
602
615
  }
603
616
 
604
- var version = "6.0.0-rc.1";
617
+ var version = "6.0.1";
605
618
 
606
619
  async function writeDefaultTsconfig(tsConfigPath) {
607
620
  await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
@@ -1094,6 +1107,9 @@ async function parseCliArgs(argv) {
1094
1107
  }).option('dts-bundle', {
1095
1108
  type: 'boolean',
1096
1109
  description: 'bundle type declaration files'
1110
+ }).option('prepare', {
1111
+ type: 'boolean',
1112
+ description: 'auto setup package.json for building'
1097
1113
  }).command('prepare', 'auto configure package.json exports for building', ()=>{}, (argv)=>{
1098
1114
  return prepare(argv.cwd || process.cwd());
1099
1115
  }).command('lint', 'lint package.json', ()=>{}, (argv)=>{
@@ -1105,6 +1121,11 @@ async function parseCliArgs(argv) {
1105
1121
  cmd
1106
1122
  };
1107
1123
  }
1124
+ // Warn about this command being deprecated
1125
+ if (args['prepare']) {
1126
+ logger.warn('The "--prepare" option is deprecated. Please use `bunchee prepare` instead.');
1127
+ return;
1128
+ }
1108
1129
  const source = args._[0];
1109
1130
  const parsedArgs = {
1110
1131
  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 err;
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-rc.1",
3
+ "version": "6.0.1",
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.0",
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.11",
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.0",
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",