bunchee 5.0.0-beta.8 → 5.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.
Files changed (3) hide show
  1. package/dist/bin/cli.js +149 -79
  2. package/dist/index.js +208 -137
  3. package/package.json +1 -1
package/dist/bin/cli.js CHANGED
@@ -162,7 +162,8 @@ function isTypescriptFile(filename) {
162
162
  function fileExists(filePath) {
163
163
  return fs__default.default.existsSync(filePath);
164
164
  }
165
- const hasAvailableExtension = (filename)=>availableExtensions.has(path__default.default.extname(filename).slice(1));
165
+ // 'index.server.js' -> 'index'
166
+ const getFileBasename = (str)=>str.split('.')[0];
166
167
  const hasCjsExtension = (filename)=>path__default.default.extname(filename) === '.cjs';
167
168
  const getMainFieldExportType = (pkg)=>{
168
169
  const isEsmPkg = isESModulePackage(pkg.type);
@@ -183,23 +184,27 @@ function joinRelativePath(...segments) {
183
184
  function isESModulePackage(packageType) {
184
185
  return packageType === 'module';
185
186
  }
187
+ function isBinExportPath(exportPath) {
188
+ return exportPath === BINARY_TAG || exportPath.startsWith(BINARY_TAG + '/');
189
+ }
186
190
 
187
191
  function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exportToDist) {
188
192
  // End of searching, export value is file path.
189
193
  // <export key>: <export value> (string)
190
194
  if (typeof exportValue === 'string') {
191
195
  const composedTypes = new Set(exportTypes);
192
- composedTypes.add(exportKey.startsWith('.') ? 'default' : exportKey);
193
- const exportInfo = exportToDist.get(currentPath);
196
+ const exportType = exportKey.startsWith('.') ? 'default' : exportKey;
197
+ composedTypes.add(exportType);
198
+ const exportInfo = exportToDist.get(mapExportFullPath(currentPath));
194
199
  const exportCondition = Array.from(composedTypes).join('.');
195
200
  if (!exportInfo) {
196
201
  const outputConditionPair = [
197
202
  exportValue,
198
203
  exportCondition
199
204
  ];
200
- exportToDist.set(currentPath, [
205
+ addToExportDistMap(exportToDist, currentPath, [
201
206
  outputConditionPair
202
- ]);
207
+ ], runtimeExportConventions.has(exportType) ? exportType : undefined);
203
208
  } else {
204
209
  exportInfo.push([
205
210
  exportValue,
@@ -225,10 +230,26 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
225
230
  }
226
231
  }
227
232
  }
233
+ const mapExportFullPath = (exportPath)=>exportPath === '.' ? './index' : exportPath;
234
+ function addToExportDistMap(exportToDist, exportPath, outputConditionPairs, specialExportType) {
235
+ const fullPath = mapExportFullPath(exportPath);
236
+ // + (specialExportType ? '.' + specialExportType : '')
237
+ const existingExportInfo = exportToDist.get(fullPath);
238
+ if (!existingExportInfo) {
239
+ exportToDist.set(fullPath, outputConditionPairs);
240
+ } else {
241
+ existingExportInfo.push(...outputConditionPairs);
242
+ }
243
+ }
228
244
  /**
229
245
  * parseExports - parse package.exports field and other fields like main,module to a map
230
246
  *
231
247
  * map from export path to output path and export conditions
248
+ *
249
+ * exportToDist: {
250
+ * './index': { development: ..., default: ... }
251
+ * './index.react-server': { development: ..., default: ... }
252
+ * }
232
253
  */ function parseExports(pkg) {
233
254
  var _pkg_exports;
234
255
  const exportsField = (_pkg_exports = pkg.exports) != null ? _pkg_exports : {};
@@ -243,7 +264,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
243
264
  exportsField,
244
265
  defaultCondition
245
266
  ];
246
- exportToDist.set(currentPath, [
267
+ addToExportDistMap(exportToDist, currentPath, [
247
268
  outputConditionPair
248
269
  ]);
249
270
  } else {
@@ -265,7 +286,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
265
286
  bins,
266
287
  defaultCondition
267
288
  ];
268
- exportToDist.set(BINARY_TAG, [
289
+ addToExportDistMap(exportToDist, BINARY_TAG, [
269
290
  outputConditionPair
270
291
  ]);
271
292
  } else {
@@ -277,7 +298,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
277
298
  binDistPath,
278
299
  exportType
279
300
  ];
280
- exportToDist.set(exportPath, [
301
+ addToExportDistMap(exportToDist, exportPath, [
281
302
  outputConditionPair
282
303
  ]);
283
304
  }
@@ -287,9 +308,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
287
308
  const mainExportPath = pkg.main;
288
309
  const moduleExportPath = pkg.module;
289
310
  const typesEntryPath = pkg.types;
290
- const existingExportInfo = exportToDist.get('.');
291
- exportToDist.set('.', [
292
- ...existingExportInfo || [],
311
+ addToExportDistMap(exportToDist, './index', [
293
312
  Boolean(mainExportPath) && [
294
313
  mainExportPath,
295
314
  getMainFieldExportType(pkg)
@@ -455,7 +474,7 @@ function lint$1(pkg) {
455
474
  }
456
475
  }
457
476
 
458
- var version = "5.0.0-beta.8";
477
+ var version = "5.0.1";
459
478
 
460
479
  function relativify(path) {
461
480
  return path.startsWith('.') ? path : `./${path}`;
@@ -470,20 +489,20 @@ async function writeDefaultTsconfig(tsConfigPath) {
470
489
  // shared.<export condition>.ts -> ./shared
471
490
  // index.ts -> ./index
472
491
  // index.development.ts -> ./index.development
473
- function sourceFilenameToExportPath(filename) {
492
+ function sourceFilenameToExportFullPath(filename) {
474
493
  const baseName = baseNameWithoutExtension(filename);
475
494
  let exportPath = baseName;
476
495
  return relativify(exportPath);
477
496
  }
478
- // ./index -> import|require|default
497
+ // ./index -> default
479
498
  // ./index.development -> development
480
499
  // ./index.react-server -> react-server
481
500
  function getExportTypeFromExportPath(exportPath) {
482
501
  // Skip the first two segments: `.` and `index`
483
502
  const exportTypes = exportPath.split('.').slice(2);
484
- return getExportTypeFromExportTypes(exportTypes);
503
+ return getExportTypeFromExportTypesArray(exportTypes);
485
504
  }
486
- function getSpecialExportTypeFromExportPath(composedExportType) {
505
+ function getSpecialExportTypeFromComposedExportPath(composedExportType) {
487
506
  const exportTypes = composedExportType.split('.');
488
507
  for (const exportType of exportTypes){
489
508
  if (specialExportConventions.has(exportType)) {
@@ -492,7 +511,7 @@ function getSpecialExportTypeFromExportPath(composedExportType) {
492
511
  }
493
512
  return 'default';
494
513
  }
495
- function getExportTypeFromExportTypes(types) {
514
+ function getExportTypeFromExportTypesArray(types) {
496
515
  let exportType = 'default';
497
516
  new Set(types).forEach((value)=>{
498
517
  if (specialExportConventions.has(value)) {
@@ -524,6 +543,95 @@ function normalizeExportPath(exportPath) {
524
543
  }
525
544
  return baseName;
526
545
  }
546
+ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpath, bins, exportsEntries) {
547
+ const isBinaryPath = isBinExportPath(originalSubpath);
548
+ const subpath = originalSubpath.replace(BINARY_TAG, 'bin');
549
+ const absoluteDirPath = path__default.default.join(sourceFolderPath, subpath);
550
+ const isDirectory = fs__default.default.existsSync(absoluteDirPath) ? (await fsp__default.default.stat(absoluteDirPath)).isDirectory() : false;
551
+ if (isDirectory) {
552
+ if (isBinaryPath) {
553
+ const binDirentList = await fsp__default.default.readdir(absoluteDirPath, {
554
+ withFileTypes: true
555
+ });
556
+ for (const binDirent of binDirentList){
557
+ if (binDirent.isFile()) {
558
+ const binFileAbsolutePath = path__default.default.join(binDirent.path, binDirent.name);
559
+ if (fs__default.default.existsSync(binFileAbsolutePath)) {
560
+ bins.set(normalizeExportPath(originalSubpath), binFileAbsolutePath);
561
+ }
562
+ }
563
+ }
564
+ } else {
565
+ // Search folder/index.<ext> convention entries
566
+ for (const extension of availableExtensions){
567
+ const indexAbsoluteFile = path__default.default.join(absoluteDirPath, `index.${extension}`);
568
+ // Search folder/index.<special type>.<ext> convention entries
569
+ for (const specialExportType of runtimeExportConventions){
570
+ const indexSpecialAbsoluteFile = path__default.default.join(absoluteDirPath, `index.${specialExportType}.${extension}`);
571
+ if (fs__default.default.existsSync(indexSpecialAbsoluteFile)) {
572
+ // Add special export path
573
+ // { ./<export path>.<special cond>: { <special cond>: 'index.<special cond>.<ext>' } }
574
+ const exportPath = relativify(subpath);
575
+ const specialExportPath = exportPath + '.' + specialExportType;
576
+ const sourceFilesMap = exportsEntries.get(specialExportPath) || {};
577
+ sourceFilesMap[specialExportType] = indexSpecialAbsoluteFile;
578
+ exportsEntries.set(specialExportPath, sourceFilesMap);
579
+ }
580
+ }
581
+ if (fs__default.default.existsSync(indexAbsoluteFile) && !isTestFile(indexAbsoluteFile)) {
582
+ const exportPath = relativify(subpath);
583
+ const sourceFilesMap = exportsEntries.get(exportPath) || {};
584
+ const exportType = getExportTypeFromExportPath(exportPath);
585
+ sourceFilesMap[exportType] = indexAbsoluteFile;
586
+ exportsEntries.set(exportPath, sourceFilesMap);
587
+ break;
588
+ }
589
+ }
590
+ }
591
+ } else {
592
+ // subpath could be a file
593
+ const dirName = path.dirname(subpath);
594
+ const baseName = path.basename(subpath);
595
+ // Read current file's directory
596
+ const dirPath = path__default.default.join(sourceFolderPath, dirName);
597
+ if (!fs__default.default.existsSync(dirPath)) {
598
+ return;
599
+ }
600
+ const dirents = await fsp__default.default.readdir(dirPath, {
601
+ withFileTypes: true
602
+ });
603
+ for (const dirent of dirents){
604
+ // index.development.js -> index.development
605
+ const direntBaseName = baseNameWithoutExtension(dirent.name);
606
+ const ext = path.extname(dirent.name).slice(1);
607
+ if (!dirent.isFile() || direntBaseName !== baseName || !availableExtensions.has(ext)) {
608
+ continue;
609
+ }
610
+ if (isTestFile(dirent.name)) {
611
+ continue;
612
+ }
613
+ const sourceFileAbsolutePath = path__default.default.join(dirent.path, dirent.name);
614
+ if (isBinaryPath) {
615
+ bins.set(originalSubpath, sourceFileAbsolutePath);
616
+ } else {
617
+ let sourceFilesMap = exportsEntries.get(originalSubpath) || {};
618
+ const exportType = getExportTypeFromExportPath(originalSubpath);
619
+ sourceFilesMap[exportType] = sourceFileAbsolutePath;
620
+ if (specialExportConventions.has(exportType)) {
621
+ // e.g. ./foo/index.react-server -> ./foo/index
622
+ const fallbackExportPath = sourceFilenameToExportFullPath(originalSubpath);
623
+ const fallbackSourceFilesMap = exportsEntries.get(fallbackExportPath) || {};
624
+ sourceFilesMap = {
625
+ ...fallbackSourceFilesMap,
626
+ ...sourceFilesMap
627
+ };
628
+ }
629
+ exportsEntries.set(originalSubpath, sourceFilesMap);
630
+ }
631
+ }
632
+ }
633
+ }
634
+ // For `prepare`
527
635
  async function collectSourceEntries(sourceFolderPath) {
528
636
  const bins = new Map();
529
637
  const exportsEntries = new Map();
@@ -536,65 +644,27 @@ async function collectSourceEntries(sourceFolderPath) {
536
644
  const entryFileDirentList = await fsp__default.default.readdir(sourceFolderPath, {
537
645
  withFileTypes: true
538
646
  });
647
+ // Collect source files for `exports` field
539
648
  for (const dirent of entryFileDirentList){
540
- if (dirent.isDirectory()) {
541
- if (dirent.name === 'bin') {
542
- const binDirentList = await fsp__default.default.readdir(path__default.default.join(sourceFolderPath, dirent.name), {
543
- withFileTypes: true
544
- });
545
- for (const binDirent of binDirentList){
546
- if (binDirent.isFile()) {
547
- const binFileAbsolutePath = path__default.default.join(sourceFolderPath, dirent.name, binDirent.name);
548
- const binExportPath = sourceFilenameToExportPath(binDirent.name);
549
- if (fs__default.default.existsSync(binFileAbsolutePath)) {
550
- bins.set(path.posix.join(BINARY_TAG, binExportPath), binFileAbsolutePath);
551
- }
552
- }
553
- }
554
- } else {
555
- // Search folder/index.<ext> convention entries
556
- for (const extension of availableExtensions){
557
- const indexAbsoluteFile = path__default.default.join(dirent.path, dirent.name, `index.${extension}`);
558
- // Search folder/index.<special type>.<ext> convention entries
559
- for (const specialExportType of runtimeExportConventions){
560
- const indexSpecialAbsoluteFile = path__default.default.join(dirent.path, dirent.name, `index.${specialExportType}.${extension}`);
561
- if (fs__default.default.existsSync(indexSpecialAbsoluteFile)) {
562
- // Add special export path
563
- // { ./<export path>.<special cond>: { <special cond>: 'index.<special cond>.<ext>' } }
564
- const exportPath = sourceFilenameToExportPath(dirent.name);
565
- const specialExportPath = exportPath + '.' + specialExportType;
566
- const sourceFilesMap = exportsEntries.get(specialExportPath) || {};
567
- sourceFilesMap[specialExportType] = indexSpecialAbsoluteFile;
568
- exportsEntries.set(specialExportPath, sourceFilesMap);
569
- }
570
- }
571
- if (fs__default.default.existsSync(indexAbsoluteFile) && !isTestFile(indexAbsoluteFile)) {
572
- const exportPath = sourceFilenameToExportPath(dirent.name);
573
- const sourceFilesMap = exportsEntries.get(exportPath) || {};
574
- const exportType = getExportTypeFromExportPath(exportPath);
575
- sourceFilesMap[exportType] = indexAbsoluteFile;
576
- exportsEntries.set(exportPath, sourceFilesMap);
577
- break;
578
- }
579
- }
580
- }
581
- } else if (dirent.isFile()) {
582
- const isAvailableExtension = availableExtensions.has(path__default.default.extname(dirent.name).slice(1));
583
- if (isAvailableExtension) {
584
- const exportPath = sourceFilenameToExportPath(dirent.name);
585
- const isBinFile = exportPath === './bin';
586
- const fullPath = path__default.default.join(sourceFolderPath, dirent.name);
587
- if (isBinFile) {
588
- bins.set(BINARY_TAG, fullPath);
589
- } else {
590
- if (hasAvailableExtension(dirent.name) && !isTestFile(dirent.name)) {
591
- const sourceFilesMap = exportsEntries.get(exportPath) || {};
592
- const exportType = getExportTypeFromExportPath(exportPath);
593
- sourceFilesMap[exportType] = fullPath;
594
- exportsEntries.set(exportPath, sourceFilesMap);
595
- }
596
- }
649
+ if (getFileBasename(dirent.name) === 'bin') {
650
+ continue;
651
+ }
652
+ const exportPath = sourceFilenameToExportFullPath(dirent.name);
653
+ await collectSourceEntriesByExportPath(sourceFolderPath, exportPath, bins, exportsEntries);
654
+ }
655
+ // Collect source files for `bin` field
656
+ const binDirent = entryFileDirentList.find((dirent)=>getFileBasename(dirent.name) === 'bin');
657
+ if (binDirent) {
658
+ if (binDirent.isDirectory()) {
659
+ const binDirentList = await fsp__default.default.readdir(path__default.default.join(binDirent.path, binDirent.name), {
660
+ withFileTypes: true
661
+ });
662
+ for (const binDirent of binDirentList){
663
+ const binExportPath = path.posix.join(BINARY_TAG, getFileBasename(binDirent.name));
664
+ await collectSourceEntriesByExportPath(sourceFolderPath, binExportPath, bins, exportsEntries);
597
665
  }
666
+ } else {
667
+ await collectSourceEntriesByExportPath(sourceFolderPath, BINARY_TAG, bins, exportsEntries);
598
668
  }
599
669
  }
600
670
  return {
@@ -646,7 +716,7 @@ function createExportCondition(exportName, sourceFile, moduleType) {
646
716
  function createExportConditionPair(exportName, sourceFile, moduleType) {
647
717
  // <exportName>.<specialCondition>
648
718
  let specialCondition;
649
- const specialConditionName = getSpecialExportTypeFromExportPath(exportName);
719
+ const specialConditionName = getSpecialExportTypeFromComposedExportPath(exportName);
650
720
  const normalizedExportPath = normalizeExportPath(exportName);
651
721
  if (specialConditionName !== 'default') {
652
722
  // e.g.
@@ -741,10 +811,10 @@ async function prepare(cwd) {
741
811
  const pkgExports = {};
742
812
  for (const [exportName, sourceFilesMap] of exportsEntries.entries()){
743
813
  for (const sourceFile of Object.values(sourceFilesMap)){
744
- const [key, value] = createExportConditionPair(exportName, sourceFile, pkgJson.type);
745
- pkgExports[key] = {
746
- ...value,
747
- ...pkgExports[key]
814
+ const [normalizedExportPath, conditions] = createExportConditionPair(exportName, sourceFile, pkgJson.type);
815
+ pkgExports[normalizedExportPath] = {
816
+ ...conditions,
817
+ ...pkgExports[normalizedExportPath]
748
818
  };
749
819
  }
750
820
  }
package/dist/index.js CHANGED
@@ -238,7 +238,6 @@ function filePathWithoutExtension(filePath) {
238
238
  }
239
239
  return filePath;
240
240
  }
241
- const hasAvailableExtension = (filename)=>availableExtensions.has(path__default.default.extname(filename).slice(1));
242
241
  const hasCjsExtension = (filename)=>path__default.default.extname(filename) === '.cjs';
243
242
  const getMainFieldExportType = (pkg)=>{
244
243
  const isEsmPkg = isESModulePackage(pkg.type);
@@ -282,6 +281,9 @@ async function removeOutputDir(output, cwd) {
282
281
  removedDirs.add(dir);
283
282
  }
284
283
  }
284
+ function isBinExportPath(exportPath) {
285
+ return exportPath === BINARY_TAG || exportPath.startsWith(BINARY_TAG + '/');
286
+ }
285
287
 
286
288
  const memoize = (fn, cacheKey, cacheArg)=>{
287
289
  const cache = cacheArg || new Map();
@@ -618,17 +620,18 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
618
620
  // <export key>: <export value> (string)
619
621
  if (typeof exportValue === 'string') {
620
622
  const composedTypes = new Set(exportTypes);
621
- composedTypes.add(exportKey.startsWith('.') ? 'default' : exportKey);
622
- const exportInfo = exportToDist.get(currentPath);
623
+ const exportType = exportKey.startsWith('.') ? 'default' : exportKey;
624
+ composedTypes.add(exportType);
625
+ const exportInfo = exportToDist.get(mapExportFullPath(currentPath));
623
626
  const exportCondition = Array.from(composedTypes).join('.');
624
627
  if (!exportInfo) {
625
628
  const outputConditionPair = [
626
629
  exportValue,
627
630
  exportCondition
628
631
  ];
629
- exportToDist.set(currentPath, [
632
+ addToExportDistMap(exportToDist, currentPath, [
630
633
  outputConditionPair
631
- ]);
634
+ ], runtimeExportConventions.has(exportType) ? exportType : undefined);
632
635
  } else {
633
636
  exportInfo.push([
634
637
  exportValue,
@@ -654,10 +657,26 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
654
657
  }
655
658
  }
656
659
  }
660
+ const mapExportFullPath = (exportPath)=>exportPath === '.' ? './index' : exportPath;
661
+ function addToExportDistMap(exportToDist, exportPath, outputConditionPairs, specialExportType) {
662
+ const fullPath = mapExportFullPath(exportPath);
663
+ // + (specialExportType ? '.' + specialExportType : '')
664
+ const existingExportInfo = exportToDist.get(fullPath);
665
+ if (!existingExportInfo) {
666
+ exportToDist.set(fullPath, outputConditionPairs);
667
+ } else {
668
+ existingExportInfo.push(...outputConditionPairs);
669
+ }
670
+ }
657
671
  /**
658
672
  * parseExports - parse package.exports field and other fields like main,module to a map
659
673
  *
660
674
  * map from export path to output path and export conditions
675
+ *
676
+ * exportToDist: {
677
+ * './index': { development: ..., default: ... }
678
+ * './index.react-server': { development: ..., default: ... }
679
+ * }
661
680
  */ function parseExports(pkg) {
662
681
  var _pkg_exports;
663
682
  const exportsField = (_pkg_exports = pkg.exports) != null ? _pkg_exports : {};
@@ -672,7 +691,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
672
691
  exportsField,
673
692
  defaultCondition
674
693
  ];
675
- exportToDist.set(currentPath, [
694
+ addToExportDistMap(exportToDist, currentPath, [
676
695
  outputConditionPair
677
696
  ]);
678
697
  } else {
@@ -694,7 +713,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
694
713
  bins,
695
714
  defaultCondition
696
715
  ];
697
- exportToDist.set(BINARY_TAG, [
716
+ addToExportDistMap(exportToDist, BINARY_TAG, [
698
717
  outputConditionPair
699
718
  ]);
700
719
  } else {
@@ -706,7 +725,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
706
725
  binDistPath,
707
726
  exportType
708
727
  ];
709
- exportToDist.set(exportPath, [
728
+ addToExportDistMap(exportToDist, exportPath, [
710
729
  outputConditionPair
711
730
  ]);
712
731
  }
@@ -716,9 +735,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
716
735
  const mainExportPath = pkg.main;
717
736
  const moduleExportPath = pkg.module;
718
737
  const typesEntryPath = pkg.types;
719
- const existingExportInfo = exportToDist.get('.');
720
- exportToDist.set('.', [
721
- ...existingExportInfo || [],
738
+ addToExportDistMap(exportToDist, './index', [
722
739
  Boolean(mainExportPath) && [
723
740
  mainExportPath,
724
741
  getMainFieldExportType(pkg)
@@ -836,7 +853,7 @@ function getExportTypeFromFile(filename, pkgType) {
836
853
  // shared.<export condition>.ts -> ./shared
837
854
  // index.ts -> ./index
838
855
  // index.development.ts -> ./index.development
839
- function sourceFilenameToExportPath(filename) {
856
+ function sourceFilenameToExportFullPath(filename) {
840
857
  const baseName = baseNameWithoutExtension(filename);
841
858
  let exportPath = baseName;
842
859
  return relativify(exportPath);
@@ -844,8 +861,8 @@ function sourceFilenameToExportPath(filename) {
844
861
  async function collectEntriesFromParsedExports(cwd, parsedExportsInfo, sourceFile) {
845
862
  const entries = {};
846
863
  if (sourceFile) {
847
- const defaultExport = parsedExportsInfo.get('.')[0];
848
- entries['.'] = {
864
+ const defaultExport = parsedExportsInfo.get('./index')[0];
865
+ entries['./index'] = {
849
866
  source: sourceFile,
850
867
  name: '.',
851
868
  export: {
@@ -854,13 +871,13 @@ async function collectEntriesFromParsedExports(cwd, parsedExportsInfo, sourceFil
854
871
  };
855
872
  }
856
873
  // Find source files
857
- const { bins, exportsEntries } = await collectSourceEntries(path.join(cwd, SRC));
874
+ const { bins, exportsEntries } = await collectSourceEntriesFromExportPaths(path.join(cwd, SRC), parsedExportsInfo);
858
875
  // A mapping between each export path and its related special export conditions,
859
876
  // excluding the 'default' export condition.
860
- // { '.' => Set('development') }
877
+ // { './index' => Set('development', 'edge-light') }
861
878
  const pathSpecialConditionsMap = {};
862
879
  for (const [exportPath] of exportsEntries){
863
- const normalizedExportPath = normalizeExportPath(exportPath);
880
+ const normalizedExportPath = stripSpecialCondition(exportPath);
864
881
  if (!pathSpecialConditionsMap[normalizedExportPath]) {
865
882
  pathSpecialConditionsMap[normalizedExportPath] = new Set();
866
883
  }
@@ -871,17 +888,19 @@ async function collectEntriesFromParsedExports(cwd, parsedExportsInfo, sourceFil
871
888
  }
872
889
  // Traverse source files and try to match the entries
873
890
  // Find exports from parsed exports info
874
- // entryExportPath can be: '.', './index.development', './shared.edge-light', etc.
891
+ // entryExportPath can be: './index', './index.development', './shared.edge-light', etc.
875
892
  for (const [entryExportPath, sourceFilesMap] of exportsEntries){
876
- const normalizedExportPath = normalizeExportPath(entryExportPath);
893
+ const normalizedExportPath = stripSpecialCondition(entryExportPath);
877
894
  const entryExportPathType = getExportTypeFromExportPath(entryExportPath);
878
895
  const outputExports = parsedExportsInfo.get(normalizedExportPath);
879
896
  if (!outputExports) {
880
897
  continue;
881
898
  }
882
- for (const [outputPath, composedExportType] of outputExports){
883
- const matchedExportType = getSpecialExportTypeFromExportPath(composedExportType);
899
+ for (const [outputPath, outputComposedExportType] of outputExports){
884
900
  // export type can be: default, development, react-server, etc.
901
+ const matchedExportType = getSpecialExportTypeFromComposedExportPath(outputComposedExportType);
902
+ const specialSet = pathSpecialConditionsMap[normalizedExportPath];
903
+ const hasSpecialEntry = specialSet.has(matchedExportType);
885
904
  const sourceFile = sourceFilesMap[matchedExportType] || sourceFilesMap.default;
886
905
  if (!sourceFile) {
887
906
  continue;
@@ -892,18 +911,19 @@ async function collectEntriesFromParsedExports(cwd, parsedExportsInfo, sourceFil
892
911
  name: normalizedExportPath,
893
912
  export: {}
894
913
  };
914
+ } else if (matchedExportType === entryExportPathType) {
915
+ entries[entryExportPath].source = sourceFile;
895
916
  }
896
- const exportMap = entries[entryExportPath].export;
897
- if (entryExportPathType === 'default' && matchedExportType !== 'default' && pathSpecialConditionsMap[normalizedExportPath].size > 0) {
898
- continue;
917
+ // output exports match
918
+ if (matchedExportType === entryExportPathType || !hasSpecialEntry && matchedExportType !== 'default') {
919
+ const exportMap = entries[entryExportPath].export;
920
+ exportMap[outputComposedExportType] = outputPath;
899
921
  }
900
- exportMap[composedExportType] = outputPath;
901
922
  }
902
923
  }
903
924
  // Handling binaries
904
925
  for (const [exportPath, sourceFile] of bins){
905
- const normalizedExportPath = normalizeExportPath(exportPath);
906
- const outputExports = parsedExportsInfo.get(normalizedExportPath);
926
+ const outputExports = parsedExportsInfo.get(exportPath);
907
927
  if (!outputExports) {
908
928
  continue;
909
929
  }
@@ -919,15 +939,15 @@ async function collectEntriesFromParsedExports(cwd, parsedExportsInfo, sourceFil
919
939
  }
920
940
  return entries;
921
941
  }
922
- // ./index -> import|require|default
942
+ // ./index -> default
923
943
  // ./index.development -> development
924
944
  // ./index.react-server -> react-server
925
945
  function getExportTypeFromExportPath(exportPath) {
926
946
  // Skip the first two segments: `.` and `index`
927
947
  const exportTypes = exportPath.split('.').slice(2);
928
- return getExportTypeFromExportTypes(exportTypes);
948
+ return getExportTypeFromExportTypesArray(exportTypes);
929
949
  }
930
- function getSpecialExportTypeFromExportPath(composedExportType) {
950
+ function getSpecialExportTypeFromComposedExportPath(composedExportType) {
931
951
  const exportTypes = composedExportType.split('.');
932
952
  for (const exportType of exportTypes){
933
953
  if (specialExportConventions.has(exportType)) {
@@ -936,7 +956,7 @@ function getSpecialExportTypeFromExportPath(composedExportType) {
936
956
  }
937
957
  return 'default';
938
958
  }
939
- function getExportTypeFromExportTypes(types) {
959
+ function getExportTypeFromExportTypesArray(types) {
940
960
  let exportType = 'default';
941
961
  new Set(types).forEach((value)=>{
942
962
  if (specialExportConventions.has(value)) {
@@ -968,78 +988,124 @@ function normalizeExportPath(exportPath) {
968
988
  }
969
989
  return baseName;
970
990
  }
971
- async function collectSourceEntries(sourceFolderPath) {
972
- const bins = new Map();
973
- const exportsEntries = new Map();
974
- if (!fs__default.default.existsSync(sourceFolderPath)) {
975
- return {
976
- bins,
977
- exportsEntries
978
- };
979
- }
980
- const entryFileDirentList = await fsp__default.default.readdir(sourceFolderPath, {
981
- withFileTypes: true
982
- });
983
- for (const dirent of entryFileDirentList){
984
- if (dirent.isDirectory()) {
985
- if (dirent.name === 'bin') {
986
- const binDirentList = await fsp__default.default.readdir(path__default.default.join(sourceFolderPath, dirent.name), {
987
- withFileTypes: true
988
- });
989
- for (const binDirent of binDirentList){
990
- if (binDirent.isFile()) {
991
- const binFileAbsolutePath = path__default.default.join(sourceFolderPath, dirent.name, binDirent.name);
992
- const binExportPath = sourceFilenameToExportPath(binDirent.name);
993
- if (fs__default.default.existsSync(binFileAbsolutePath)) {
994
- bins.set(path.posix.join(BINARY_TAG, binExportPath), binFileAbsolutePath);
995
- }
991
+ // ./index.react-server -> ./index
992
+ function stripSpecialCondition(exportPath) {
993
+ return exportPath.split('.').slice(0, 2).join('.');
994
+ }
995
+ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpath, bins, exportsEntries) {
996
+ const isBinaryPath = isBinExportPath(originalSubpath);
997
+ const subpath = originalSubpath.replace(BINARY_TAG, 'bin');
998
+ const absoluteDirPath = path__default.default.join(sourceFolderPath, subpath);
999
+ const isDirectory = fs__default.default.existsSync(absoluteDirPath) ? (await fsp__default.default.stat(absoluteDirPath)).isDirectory() : false;
1000
+ if (isDirectory) {
1001
+ if (isBinaryPath) {
1002
+ const binDirentList = await fsp__default.default.readdir(absoluteDirPath, {
1003
+ withFileTypes: true
1004
+ });
1005
+ for (const binDirent of binDirentList){
1006
+ if (binDirent.isFile()) {
1007
+ const binFileAbsolutePath = path__default.default.join(binDirent.path, binDirent.name);
1008
+ if (fs__default.default.existsSync(binFileAbsolutePath)) {
1009
+ bins.set(normalizeExportPath(originalSubpath), binFileAbsolutePath);
996
1010
  }
997
1011
  }
998
- } else {
999
- // Search folder/index.<ext> convention entries
1000
- for (const extension of availableExtensions){
1001
- const indexAbsoluteFile = path__default.default.join(dirent.path, dirent.name, `index.${extension}`);
1002
- // Search folder/index.<special type>.<ext> convention entries
1003
- for (const specialExportType of runtimeExportConventions){
1004
- const indexSpecialAbsoluteFile = path__default.default.join(dirent.path, dirent.name, `index.${specialExportType}.${extension}`);
1005
- if (fs__default.default.existsSync(indexSpecialAbsoluteFile)) {
1006
- // Add special export path
1007
- // { ./<export path>.<special cond>: { <special cond>: 'index.<special cond>.<ext>' } }
1008
- const exportPath = sourceFilenameToExportPath(dirent.name);
1009
- const specialExportPath = exportPath + '.' + specialExportType;
1010
- const sourceFilesMap = exportsEntries.get(specialExportPath) || {};
1011
- sourceFilesMap[specialExportType] = indexSpecialAbsoluteFile;
1012
- exportsEntries.set(specialExportPath, sourceFilesMap);
1013
- }
1014
- }
1015
- if (fs__default.default.existsSync(indexAbsoluteFile) && !isTestFile(indexAbsoluteFile)) {
1016
- const exportPath = sourceFilenameToExportPath(dirent.name);
1017
- const sourceFilesMap = exportsEntries.get(exportPath) || {};
1018
- const exportType = getExportTypeFromExportPath(exportPath);
1019
- sourceFilesMap[exportType] = indexAbsoluteFile;
1020
- exportsEntries.set(exportPath, sourceFilesMap);
1021
- break;
1012
+ }
1013
+ } else {
1014
+ // Search folder/index.<ext> convention entries
1015
+ for (const extension of availableExtensions){
1016
+ const indexAbsoluteFile = path__default.default.join(absoluteDirPath, `index.${extension}`);
1017
+ // Search folder/index.<special type>.<ext> convention entries
1018
+ for (const specialExportType of runtimeExportConventions){
1019
+ const indexSpecialAbsoluteFile = path__default.default.join(absoluteDirPath, `index.${specialExportType}.${extension}`);
1020
+ if (fs__default.default.existsSync(indexSpecialAbsoluteFile)) {
1021
+ // Add special export path
1022
+ // { ./<export path>.<special cond>: { <special cond>: 'index.<special cond>.<ext>' } }
1023
+ const exportPath = relativify(subpath);
1024
+ const specialExportPath = exportPath + '.' + specialExportType;
1025
+ const sourceFilesMap = exportsEntries.get(specialExportPath) || {};
1026
+ sourceFilesMap[specialExportType] = indexSpecialAbsoluteFile;
1027
+ exportsEntries.set(specialExportPath, sourceFilesMap);
1022
1028
  }
1023
1029
  }
1030
+ if (fs__default.default.existsSync(indexAbsoluteFile) && !isTestFile(indexAbsoluteFile)) {
1031
+ const exportPath = relativify(subpath);
1032
+ const sourceFilesMap = exportsEntries.get(exportPath) || {};
1033
+ const exportType = getExportTypeFromExportPath(exportPath);
1034
+ sourceFilesMap[exportType] = indexAbsoluteFile;
1035
+ exportsEntries.set(exportPath, sourceFilesMap);
1036
+ break;
1037
+ }
1024
1038
  }
1025
- } else if (dirent.isFile()) {
1026
- const isAvailableExtension = availableExtensions.has(path__default.default.extname(dirent.name).slice(1));
1027
- if (isAvailableExtension) {
1028
- const exportPath = sourceFilenameToExportPath(dirent.name);
1029
- const isBinFile = exportPath === './bin';
1030
- const fullPath = path__default.default.join(sourceFolderPath, dirent.name);
1031
- if (isBinFile) {
1032
- bins.set(BINARY_TAG, fullPath);
1033
- } else {
1034
- if (hasAvailableExtension(dirent.name) && !isTestFile(dirent.name)) {
1035
- const sourceFilesMap = exportsEntries.get(exportPath) || {};
1036
- const exportType = getExportTypeFromExportPath(exportPath);
1037
- sourceFilesMap[exportType] = fullPath;
1038
- exportsEntries.set(exportPath, sourceFilesMap);
1039
- }
1039
+ }
1040
+ } else {
1041
+ // subpath could be a file
1042
+ const dirName = path.dirname(subpath);
1043
+ const baseName = path.basename(subpath);
1044
+ // Read current file's directory
1045
+ const dirPath = path__default.default.join(sourceFolderPath, dirName);
1046
+ if (!fs__default.default.existsSync(dirPath)) {
1047
+ return;
1048
+ }
1049
+ const dirents = await fsp__default.default.readdir(dirPath, {
1050
+ withFileTypes: true
1051
+ });
1052
+ for (const dirent of dirents){
1053
+ // index.development.js -> index.development
1054
+ const direntBaseName = baseNameWithoutExtension(dirent.name);
1055
+ const ext = path.extname(dirent.name).slice(1);
1056
+ if (!dirent.isFile() || direntBaseName !== baseName || !availableExtensions.has(ext)) {
1057
+ continue;
1058
+ }
1059
+ if (isTestFile(dirent.name)) {
1060
+ continue;
1061
+ }
1062
+ const sourceFileAbsolutePath = path__default.default.join(dirent.path, dirent.name);
1063
+ if (isBinaryPath) {
1064
+ bins.set(originalSubpath, sourceFileAbsolutePath);
1065
+ } else {
1066
+ let sourceFilesMap = exportsEntries.get(originalSubpath) || {};
1067
+ const exportType = getExportTypeFromExportPath(originalSubpath);
1068
+ sourceFilesMap[exportType] = sourceFileAbsolutePath;
1069
+ if (specialExportConventions.has(exportType)) {
1070
+ // e.g. ./foo/index.react-server -> ./foo/index
1071
+ const fallbackExportPath = sourceFilenameToExportFullPath(originalSubpath);
1072
+ const fallbackSourceFilesMap = exportsEntries.get(fallbackExportPath) || {};
1073
+ sourceFilesMap = {
1074
+ ...fallbackSourceFilesMap,
1075
+ ...sourceFilesMap
1076
+ };
1040
1077
  }
1078
+ exportsEntries.set(originalSubpath, sourceFilesMap);
1079
+ }
1080
+ }
1081
+ }
1082
+ }
1083
+ /**
1084
+ * exportsEntries {
1085
+ * "./index" => {
1086
+ * "development" => source"
1087
+ * "react-server" => "source"
1088
+ * },
1089
+ * "./index.react-server" => {
1090
+ * "development" => source"
1091
+ * "react-server" => "source"
1092
+ * }
1093
+ * }
1094
+ */ async function collectSourceEntriesFromExportPaths(sourceFolderPath, parsedExportsInfo) {
1095
+ const bins = new Map();
1096
+ const exportsEntries = new Map();
1097
+ for (const [exportPath, exportInfo] of parsedExportsInfo.entries()){
1098
+ const specialConditions = new Set();
1099
+ for (const [_, composedExportType] of exportInfo){
1100
+ const specialExportType = getSpecialExportTypeFromComposedExportPath(composedExportType);
1101
+ if (specialExportType !== 'default') {
1102
+ specialConditions.add(specialExportType);
1041
1103
  }
1042
1104
  }
1105
+ await collectSourceEntriesByExportPath(sourceFolderPath, exportPath, bins, exportsEntries);
1106
+ for (const specialCondition of specialConditions){
1107
+ await collectSourceEntriesByExportPath(sourceFolderPath, exportPath + '.' + specialCondition, bins, exportsEntries);
1108
+ }
1043
1109
  }
1044
1110
  return {
1045
1111
  bins,
@@ -1047,6 +1113,27 @@ async function collectSourceEntries(sourceFolderPath) {
1047
1113
  };
1048
1114
  }
1049
1115
 
1116
+ function getModuleLayer(moduleMeta) {
1117
+ const directives = (moduleMeta.preserveDirectives || {
1118
+ directives: []
1119
+ }).directives.map((d)=>d.replace(/^use /, '')).filter((d)=>d !== 'strict');
1120
+ const moduleLayer = directives[0];
1121
+ return moduleLayer;
1122
+ }
1123
+ function getCustomModuleLayer(moduleId) {
1124
+ const segments = path__default.default.basename(moduleId).split('.');
1125
+ if (segments.length >= 2) {
1126
+ const [layerSegment, ext] = segments.slice(-2);
1127
+ const baseName = segments[0];
1128
+ const match = layerSegment.match(/^(\w+)-runtime$/);
1129
+ const layer = match && match[1];
1130
+ if (availableExtensions.has(ext) && layer && layer.length > 0) {
1131
+ return baseName + '-' + layer;
1132
+ }
1133
+ }
1134
+ return undefined;
1135
+ }
1136
+
1050
1137
  const swcMinifyOptions = {
1051
1138
  compress: {
1052
1139
  directives: false
@@ -1105,7 +1192,7 @@ const memoizeDtsPluginByKey = memoizeByKey(createDtsPlugin);
1105
1192
  for (const [entryExportPath, exportCondition] of Object.entries(entries)){
1106
1193
  const normalizedExportPath = normalizeExportPath(entryExportPath);
1107
1194
  // entryExportPath format: ./index, ./shared, etc.
1108
- const specialExportType = getSpecialExportTypeFromExportPath(entryExportPath);
1195
+ const specialExportType = getSpecialExportTypeFromComposedExportPath(entryExportPath);
1109
1196
  if (specialExportType === 'default') {
1110
1197
  alias[exportCondition.source] = path.posix.join(name || '', normalizedExportPath);
1111
1198
  }
@@ -1161,16 +1248,16 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1161
1248
  // common plugins for both dts and ts assets that need to be processed
1162
1249
  // If it's a .d.ts file under non-ESM package or .d.cts file, use cjs types alias.
1163
1250
  const aliasFormat = dts ? ((_bundleConfig_file = bundleConfig.file) == null ? void 0 : _bundleConfig_file.endsWith('.d.cts')) || ((_bundleConfig_file1 = bundleConfig.file) == null ? void 0 : _bundleConfig_file1.endsWith('.d.ts')) && !isESModulePackage(pkg.type) ? 'cjs' : 'esm' : bundleConfig.format;
1251
+ const aliasPlugin = aliasEntries({
1252
+ entry,
1253
+ entries,
1254
+ entriesAlias: pluginContext.entriesAlias,
1255
+ format: aliasFormat,
1256
+ dts
1257
+ });
1164
1258
  const commonPlugins = [
1165
1259
  json__default.default(),
1166
- sizePlugin,
1167
- aliasEntries({
1168
- entry,
1169
- entries,
1170
- entriesAlias: pluginContext.entriesAlias,
1171
- format: aliasFormat,
1172
- dts
1173
- })
1260
+ sizePlugin
1174
1261
  ];
1175
1262
  const typesPlugins = [
1176
1263
  ...commonPlugins,
@@ -1186,16 +1273,19 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1186
1273
  const dtsPlugin = await memoizeDtsPluginByKey(uniqueProcessId)(tsCompilerOptions, tsConfigPath, cwd);
1187
1274
  typesPlugins.push(dtsPlugin);
1188
1275
  }
1189
- const plugins = (dts ? typesPlugins : [
1276
+ const plugins = (dts ? [
1277
+ ...typesPlugins,
1278
+ aliasPlugin
1279
+ ] : [
1190
1280
  ...commonPlugins,
1281
+ preserveDirectives__default.default(),
1282
+ aliasPlugin,
1191
1283
  inlineCss({
1192
1284
  exclude: /node_modules/
1193
1285
  }),
1194
1286
  rawContent({
1195
1287
  exclude: /node_modules/
1196
1288
  }),
1197
- preserveDirectives__default.default(),
1198
- prependDirectives(),
1199
1289
  replace__default.default({
1200
1290
  values: inlineDefinedValues,
1201
1291
  preventAssignment: true
@@ -1215,7 +1305,8 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1215
1305
  }),
1216
1306
  commonjs__default.default({
1217
1307
  exclude: bundleConfig.external || null
1218
- })
1308
+ }),
1309
+ prependDirectives()
1219
1310
  ]).filter(isNotNull);
1220
1311
  return {
1221
1312
  input: entry,
@@ -1235,30 +1326,13 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1235
1326
  if (code === 'CIRCULAR_DEPENDENCY' && /Circular dependency:(\s|\S)*node_modules/.test(warning.message)) {
1236
1327
  return;
1237
1328
  }
1329
+ if (code === 'MODULE_LEVEL_DIRECTIVE') {
1330
+ return;
1331
+ }
1238
1332
  warn(warning);
1239
1333
  }
1240
1334
  };
1241
1335
  }
1242
- function getModuleLater(moduleMeta) {
1243
- const directives = (moduleMeta.preserveDirectives || {
1244
- directives: []
1245
- }).directives.map((d)=>d.replace(/^use /, '')).filter((d)=>d !== 'strict');
1246
- const moduleLayer = directives[0];
1247
- return moduleLayer;
1248
- }
1249
- function getCustomModuleLayer(moduleId) {
1250
- const segments = path__default.default.basename(moduleId).split('.');
1251
- if (segments.length >= 2) {
1252
- const [layerSegment, ext] = segments.slice(-2);
1253
- const baseName = segments[0];
1254
- const match = layerSegment.match(/^(\w+)-runtime$/);
1255
- const layer = match && match[1];
1256
- if (availableExtensions.has(ext) && layer && layer.length > 0) {
1257
- return baseName + '-' + layer;
1258
- }
1259
- }
1260
- return undefined;
1261
- }
1262
1336
  // dependencyGraphMap: Map<subModuleId, Set<entryParentId>>
1263
1337
  function createSplitChunks(dependencyGraphMap, entryFiles) {
1264
1338
  // If there's existing chunk being splitted, and contains a layer { <id>: <chunkGroup> }
@@ -1270,7 +1344,7 @@ function createSplitChunks(dependencyGraphMap, entryFiles) {
1270
1344
  }
1271
1345
  const { isEntry } = moduleInfo;
1272
1346
  const moduleMeta = moduleInfo.meta;
1273
- const moduleLayer = getModuleLater(moduleMeta);
1347
+ const moduleLayer = getModuleLayer(moduleMeta);
1274
1348
  if (!isEntry) {
1275
1349
  const cachedCustomModuleLayer = splitChunksGroupMap.get(id);
1276
1350
  if (cachedCustomModuleLayer) return cachedCustomModuleLayer;
@@ -1288,7 +1362,7 @@ function createSplitChunks(dependencyGraphMap, entryFiles) {
1288
1362
  if (!subModuleInfo) {
1289
1363
  continue;
1290
1364
  }
1291
- const subModuleLayer = getModuleLater(moduleMeta);
1365
+ const subModuleLayer = getModuleLayer(moduleMeta);
1292
1366
  if (subModuleLayer === moduleLayer) {
1293
1367
  if (!dependencyGraphMap.has(subId)) {
1294
1368
  dependencyGraphMap.set(subId, new Set());
@@ -1311,7 +1385,7 @@ function createSplitChunks(dependencyGraphMap, entryFiles) {
1311
1385
  // If other entry is dependency of this entry
1312
1386
  if (entryFiles.has(id)) {
1313
1387
  const entryModuleInfo = ctx.getModuleInfo(id);
1314
- const entryModuleLayer = getModuleLater(entryModuleInfo ? entryModuleInfo.meta : {});
1388
+ const entryModuleLayer = getModuleLayer(entryModuleInfo ? entryModuleInfo.meta : {});
1315
1389
  return entryModuleLayer === moduleLayer;
1316
1390
  }
1317
1391
  return false;
@@ -1520,20 +1594,17 @@ function createOutputState({ entries }) {
1520
1594
  }
1521
1595
  };
1522
1596
  }
1523
- function isBin(filename) {
1524
- return filename === BINARY_TAG || filename.startsWith(BINARY_TAG + '/');
1525
- }
1526
1597
  function isTypeFile(filename) {
1527
1598
  return filename.endsWith('.d.ts') || filename.endsWith('.d.mts') || filename.endsWith('.d.cts');
1528
1599
  }
1529
1600
  function normalizeExportName(exportName) {
1530
- const isBinary = isBin(exportName);
1601
+ const isBinary = isBinExportPath(exportName);
1531
1602
  let result = exportName;
1532
1603
  if (isBinary) {
1533
1604
  result = (exportName.replace(new RegExp(`^\\${BINARY_TAG}\\/?`), '') || '.') + ' (bin)';
1534
1605
  } else {
1535
1606
  const normalizedExportPath = normalizeExportPath(exportName);
1536
- const specialConditionName = getSpecialExportTypeFromExportPath(exportName);
1607
+ const specialConditionName = getSpecialExportTypeFromComposedExportPath(exportName);
1537
1608
  result = normalizedExportPath + (specialConditionName !== 'default' ? ` (${specialConditionName})` : '');
1538
1609
  }
1539
1610
  return result;
@@ -1674,7 +1745,7 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
1674
1745
  if (options.dts) {
1675
1746
  typesEntryPath = getExportFileTypePath(mainExportPath);
1676
1747
  }
1677
- parsedExportsInfo.set('.', [
1748
+ parsedExportsInfo.set('./index', [
1678
1749
  [
1679
1750
  mainExportPath,
1680
1751
  'default'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "5.0.0-beta.8",
3
+ "version": "5.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",