bunchee 5.2.1 → 5.2.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/dist/bin/cli.js CHANGED
@@ -470,7 +470,7 @@ function lint$1(pkg) {
470
470
  }
471
471
  }
472
472
 
473
- var version = "5.2.1";
473
+ var version = "5.2.2";
474
474
 
475
475
  function relativify(path) {
476
476
  return path.startsWith('.') ? path : `./${path}`;
package/dist/index.js CHANGED
@@ -608,10 +608,6 @@ function getSpecialExportTypeFromComposedExportPath(composedExportType) {
608
608
  }
609
609
  return 'default';
610
610
  }
611
- function getSpecialExportTypeFromSourcePath(sourcePath) {
612
- const fileBaseName = baseNameWithoutExtension(sourcePath);
613
- return getSpecialExportTypeFromComposedExportPath(fileBaseName);
614
- }
615
611
  function getExportTypeFromExportTypesArray(types) {
616
612
  let exportType = 'default';
617
613
  new Set(types).forEach((value)=>{
@@ -623,6 +619,15 @@ function getExportTypeFromExportTypesArray(types) {
623
619
  });
624
620
  return exportType;
625
621
  }
622
+ function getSpecialExportTypeFromConditionNames(conditionNames) {
623
+ let exportType = 'default';
624
+ conditionNames.forEach((value)=>{
625
+ if (specialExportConventions.has(value)) {
626
+ exportType = value;
627
+ }
628
+ });
629
+ return exportType;
630
+ }
626
631
  // ./index -> .
627
632
  // ./index.development -> .
628
633
  // ./index.react-server -> .
@@ -1085,14 +1090,19 @@ function rawContent({ exclude }) {
1085
1090
  };
1086
1091
  }
1087
1092
 
1093
+ function hasNoSpecialCondition(conditionNames) {
1094
+ return [
1095
+ ...conditionNames
1096
+ ].every((name)=>!specialExportConventions.has(name));
1097
+ }
1088
1098
  function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specialCondition) {
1089
1099
  const hasBundle = bundlePath != null;
1090
1100
  const formatCond = format === 'cjs' ? 'require' : 'import';
1091
1101
  const isTypesCondName = conditionNames.has('types');
1092
1102
  const hasFormatCond = conditionNames.has('import') || conditionNames.has('require');
1093
1103
  const isMatchedFormat = hasFormatCond ? conditionNames.has(formatCond) : true;
1094
- const isMatchedConditionWithFormat = specialCondition !== 'default' ? conditionNames.has(specialCondition) || isMatchedFormat : isMatchedFormat;
1095
- return isMatchedConditionWithFormat && !isTypesCondName && hasBundle;
1104
+ const isMatchedConditionWithFormat = conditionNames.has(specialCondition) || !conditionNames.has('default') && hasNoSpecialCondition(conditionNames);
1105
+ return isMatchedConditionWithFormat && !isTypesCondName && hasBundle && isMatchedFormat;
1096
1106
  }
1097
1107
  function findTypesFileCallback({ format, bundlePath, conditionNames }) {
1098
1108
  const hasCondition = bundlePath != null;
@@ -1101,9 +1111,10 @@ function findTypesFileCallback({ format, bundlePath, conditionNames }) {
1101
1111
  return isTypesCondName && hasCondition && (formatCond ? conditionNames.has(formatCond) : true);
1102
1112
  }
1103
1113
  // Alias entry key to dist bundle path
1104
- function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
1114
+ function aliasEntries({ entry: sourceFilePath, conditionNames, entries, format, dts, cwd }) {
1105
1115
  // <imported source file path>: <relative path to source's bundle>
1106
1116
  const sourceToRelativeBundleMap = new Map();
1117
+ const specialCondition = getSpecialExportTypeFromConditionNames(conditionNames);
1107
1118
  for (const [, exportCondition] of Object.entries(entries)){
1108
1119
  const exportDistMaps = exportCondition.export;
1109
1120
  const exportMapEntries = Object.entries(exportDistMaps).map(([composedKey, bundlePath])=>({
@@ -1129,8 +1140,9 @@ function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
1129
1140
  }
1130
1141
  } else {
1131
1142
  var _exportMapEntries_find2;
1132
- const specialCondition = getSpecialExportTypeFromSourcePath(sourceFilePath);
1133
- matchedBundlePath = (_exportMapEntries_find2 = exportMapEntries.find((item)=>findJsBundlePathCallback(item, specialCondition))) == null ? void 0 : _exportMapEntries_find2.bundlePath;
1143
+ matchedBundlePath = (_exportMapEntries_find2 = exportMapEntries.find((item)=>{
1144
+ return findJsBundlePathCallback(item, specialCondition);
1145
+ })) == null ? void 0 : _exportMapEntries_find2.bundlePath;
1134
1146
  }
1135
1147
  if (matchedBundlePath) {
1136
1148
  if (!sourceToRelativeBundleMap.has(exportCondition.source)) sourceToRelativeBundleMap.set(exportCondition.source, matchedBundlePath);
@@ -1356,10 +1368,12 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1356
1368
  // common plugins for both dts and ts assets that need to be processed
1357
1369
  // If it's a .d.ts file under non-ESM package or .d.cts file, use cjs types alias.
1358
1370
  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;
1371
+ const currentConditionNames = Object.keys(exportCondition.export)[0];
1359
1372
  const aliasPlugin = aliasEntries({
1360
1373
  entry,
1361
1374
  entries,
1362
1375
  format: aliasFormat,
1376
+ conditionNames: new Set(currentConditionNames.split('.')),
1363
1377
  dts,
1364
1378
  cwd
1365
1379
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "5.2.1",
3
+ "version": "5.2.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",
@@ -42,7 +42,7 @@
42
42
  "@rollup/plugin-replace": "^5.0.5",
43
43
  "@rollup/plugin-wasm": "^6.2.2",
44
44
  "@rollup/pluginutils": "^5.1.0",
45
- "@swc/core": "^1.4.17",
45
+ "@swc/core": "^1.6.1",
46
46
  "@swc/helpers": "^0.5.11",
47
47
  "arg": "^5.0.2",
48
48
  "clean-css": "^5.3.3",
@@ -81,7 +81,7 @@
81
81
  "picocolors": "^1.0.0",
82
82
  "prettier": "^3.0.0",
83
83
  "react": "^18.2.0",
84
- "typescript": "^5.3.2"
84
+ "typescript": "^5.5.2"
85
85
  },
86
86
  "lint-staged": {
87
87
  "*.{js,jsx,ts,tsx,md,json,yml,yaml}": "prettier --write"