bunchee 6.1.0 → 6.1.2

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
@@ -290,7 +290,7 @@ If you're using `"use client"` or `"use server"` in a file that used as a depend
290
290
 
291
291
  ### Shared Modules
292
292
 
293
- In some cases, you may need to share code across multiple bundles without promoting them to separate entries or exports. These modules should be bundled into shared chunks that can be reused by various bundles. By convention, files or directories prefixed with an underscore (`_<name>.<ext>` or `_<name>/index.<ext>`) are treated as **shared modules**. They're private and not exposed publicly as entry points or exports.
293
+ In some cases, you may need to share code across multiple bundles without promoting them to separate entries or exports. These modules should be bundled into shared chunks that can be reused by various bundles. By convention, files or directories **prefixed with an underscore** (`_<name>.<ext>` or `_<name>/**`) are treated as **shared modules**. They're private and not exposed publicly as entry points or exports. Testing, mocking related files are ignored. e.g. `_foo/a.test.ts` will not be treated as shared module.
294
294
 
295
295
  <details>
296
296
  <summary>Shared Utils Example</summary>
package/dist/bin/cli.js CHANGED
@@ -75,6 +75,7 @@ const DEFAULT_TS_CONFIG = {
75
75
  };
76
76
  const BINARY_TAG = '$binary';
77
77
  const PRIVATE_GLOB_PATTERN = '**/_*/**';
78
+ const TESTS_GLOB_PATTERN = '**/{__tests__/**,__mocks__/**,*.{test,spec}.*}';
78
79
 
79
80
  function getDefaultExportFromCjs (x) {
80
81
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -641,7 +642,7 @@ function lint$1(pkg) {
641
642
  }
642
643
  }
643
644
 
644
- var version = "6.1.0";
645
+ var version = "6.1.2";
645
646
 
646
647
  async function writeDefaultTsconfig(tsConfigPath) {
647
648
  await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
@@ -776,12 +777,18 @@ async function collectSourceEntries(sourceFolderPath) {
776
777
  const binMatches = await glob.glob(binPattern, {
777
778
  cwd: sourceFolderPath,
778
779
  nodir: true,
779
- ignore: PRIVATE_GLOB_PATTERN
780
+ ignore: [
781
+ PRIVATE_GLOB_PATTERN,
782
+ TESTS_GLOB_PATTERN
783
+ ]
780
784
  });
781
785
  const srcMatches = await glob.glob(srcPattern, {
782
786
  cwd: sourceFolderPath,
783
787
  nodir: true,
784
- ignore: PRIVATE_GLOB_PATTERN
788
+ ignore: [
789
+ PRIVATE_GLOB_PATTERN,
790
+ TESTS_GLOB_PATTERN
791
+ ]
785
792
  });
786
793
  for (const file of binMatches){
787
794
  // convert relative path to export path
@@ -1028,8 +1035,9 @@ function logOutputState(stats) {
1028
1035
  // Logging shared in debug mode
1029
1036
  if (isPrivateExportPath(exportName)) {
1030
1037
  if (index === 0 && process.env.DEBUG) {
1031
- const sizePadding = ' '.repeat(Math.max(maxFilenameLength, 'File'.length) - 'private shared'.length);
1032
- console.log(pc.dim(normalizeExportName(exportName)), filenamePadding, pc.dim('private shared'), sizePadding, pc.dim(prettiedSize));
1038
+ const label = '(chunk)';
1039
+ const sizePadding = ' '.repeat(Math.max(maxFilenameLength, 'File'.length) - label.length);
1040
+ console.log(pc.dim(normalizeExportName(exportName)), filenamePadding, pc.dim(label), sizePadding, pc.dim(prettiedSize));
1033
1041
  }
1034
1042
  return;
1035
1043
  }
package/dist/index.js CHANGED
@@ -242,6 +242,7 @@ const DEFAULT_TS_CONFIG = {
242
242
  };
243
243
  const BINARY_TAG = '$binary';
244
244
  const PRIVATE_GLOB_PATTERN = '**/_*/**';
245
+ const TESTS_GLOB_PATTERN = '**/{__tests__/**,__mocks__/**,*.{test,spec}.*}';
245
246
 
246
247
  function posixRelativify(path) {
247
248
  return path.startsWith('.') ? path : `./${path}`;
@@ -868,7 +869,8 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
868
869
  const privatePattern = `**/_*{,/*}{,{.${suffixPattern}}}.{${extPattern}}`;
869
870
  const privateFiles = await glob.glob(privatePattern, {
870
871
  cwd: sourceFolderPath,
871
- nodir: true
872
+ nodir: true,
873
+ ignore: TESTS_GLOB_PATTERN
872
874
  });
873
875
  for (const file of privateFiles){
874
876
  const sourceFileAbsolutePath = path__default.default.join(sourceFolderPath, file);
@@ -884,6 +886,17 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
884
886
  // Map private shared files to the dist directory
885
887
  // e.g. ./_utils.ts -> ./dist/_utils.js
886
888
  // TODO: improve the logic to only generate the required files, not all possible files
889
+ const isTs = isTypescriptFile(file);
890
+ const typesInfos = [
891
+ [
892
+ posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.d.ts' : '.d.mts'))),
893
+ condPart + 'import.types'
894
+ ],
895
+ [
896
+ posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.d.cts' : '.d.ts'))),
897
+ condPart + 'require.types'
898
+ ]
899
+ ];
887
900
  const privateExportInfo = [
888
901
  [
889
902
  posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.js' : '.mjs'))),
@@ -892,7 +905,8 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
892
905
  [
893
906
  posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.cjs' : '.js'))),
894
907
  condPart + 'require'
895
- ]
908
+ ],
909
+ ...isTs ? typesInfos : []
896
910
  ];
897
911
  const exportsInfo = parsedExportsInfo.get(normalizedExportPath);
898
912
  if (!exportsInfo) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "6.1.0",
3
+ "version": "6.1.2",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": "./dist/bin/cli.js",
6
6
  "main": "./dist/index.js",