bunchee 5.2.0 → 5.2.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
@@ -252,7 +252,7 @@ Then when the library is integrated to an app such as Next.js, app bundler can t
252
252
  If you're using `"use client"` or `"use server"` in entry file, then it will be preserved on top and the dist file of that entry will become a client component.
253
253
  If you're using `"use client"` or `"use server"` in a file that used as a dependency for an entry, then that file containing directives be split into a separate chunk and hoist the directives to the top of the chunk.
254
254
 
255
- ### Shared Modules
255
+ ### Shared Modules (Experimental)
256
256
 
257
257
  There're always cases that you need to share code among bundles but they don't have to be a separate entry or exports. You want to have them bundled into a shared chunk and then use them in different bundles. You can use shared module convention `[name].[layer]-runtime.[ext]` to create shared modules bundles.
258
258
 
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.0";
473
+ var version = "5.2.1";
474
474
 
475
475
  function relativify(path) {
476
476
  return path.startsWith('.') ? path : `./${path}`;
@@ -1018,34 +1018,41 @@ async function run(args) {
1018
1018
  // lint package
1019
1019
  await lint(cwd);
1020
1020
  const { default: ora } = await import('ora');
1021
- const spinner = ora({
1021
+ const oraInstance = ora({
1022
1022
  text: 'Building...\n\n',
1023
1023
  color: 'green'
1024
1024
  });
1025
+ const spinner = {
1026
+ start: startSpinner,
1027
+ stop: stopSpinner
1028
+ };
1029
+ function startSpinner() {
1030
+ oraInstance.start();
1031
+ }
1025
1032
  function stopSpinner(text) {
1026
- if (spinner.isSpinning) {
1027
- spinner.clear();
1028
- console.log();
1033
+ if (oraInstance.isSpinning) {
1034
+ oraInstance.clear();
1029
1035
  if (text) {
1030
- spinner.stopAndPersist({
1036
+ oraInstance.stopAndPersist({
1031
1037
  symbol: '✔',
1032
1038
  text
1033
1039
  });
1034
1040
  } else {
1035
- spinner.stop();
1041
+ oraInstance.stop();
1036
1042
  }
1037
1043
  }
1038
1044
  }
1039
1045
  let initialBuildContext;
1040
1046
  function onBuildStart(buildContext) {
1041
1047
  initialBuildContext = buildContext;
1042
- spinner.start();
1048
+ if (!watch) {
1049
+ spinner.start();
1050
+ }
1043
1051
  }
1044
1052
  function onBuildEnd(assetJobs) {
1045
1053
  // Stop spinner before logging output files and sizes on build end
1046
1054
  if (watch) {
1047
- stopSpinner('');
1048
- logWatcherBuildTime(assetJobs);
1055
+ logWatcherBuildTime(assetJobs, spinner);
1049
1056
  } else {
1050
1057
  if (assetJobs.length === 0) {
1051
1058
  logger.warn('The "src" directory does not contain any entry files. ' + 'For proper usage, please refer to the following link: ' + 'https://github.com/huozhi/bunchee#usage');
@@ -1084,8 +1091,10 @@ async function run(args) {
1084
1091
  }
1085
1092
  }
1086
1093
  // watching mode
1087
- if (!watch) {
1088
- stopSpinner(`bunchee ${version} build completed`);
1094
+ if (watch) {
1095
+ spinner.stop();
1096
+ } else {
1097
+ spinner.stop(`bunchee ${version} build completed`);
1089
1098
  }
1090
1099
  }
1091
1100
  async function main() {
@@ -1101,24 +1110,28 @@ async function main() {
1101
1110
  }
1102
1111
  await run(params);
1103
1112
  }
1104
- function logWatcherBuildTime(result) {
1113
+ function logWatcherBuildTime(result, spinner) {
1105
1114
  let watcherCounter = 0;
1106
1115
  let startTime = 0;
1107
1116
  result.map((watcher)=>{
1108
1117
  function start() {
1109
- if (watcherCounter === 0) startTime = perf_hooks.performance.now();
1118
+ if (watcherCounter === 0) {
1119
+ startTime = perf_hooks.performance.now();
1120
+ spinner.start();
1121
+ }
1110
1122
  watcherCounter++;
1111
1123
  }
1112
1124
  function end() {
1113
1125
  watcherCounter--;
1114
1126
  if (watcherCounter === 0) {
1115
- logger.info(`Built in ${(perf_hooks.performance.now() - startTime).toFixed(2)}ms`);
1127
+ spinner.stop(`Built in ${(perf_hooks.performance.now() - startTime).toFixed(2)}ms`);
1116
1128
  }
1117
1129
  }
1118
1130
  watcher.on('event', (event)=>{
1119
1131
  switch(event.code){
1120
1132
  case 'ERROR':
1121
1133
  {
1134
+ spinner.stop();
1122
1135
  logError(event.error);
1123
1136
  break;
1124
1137
  }
package/dist/index.js CHANGED
@@ -608,6 +608,10 @@ 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
+ }
611
615
  function getExportTypeFromExportTypesArray(types) {
612
616
  let exportType = 'default';
613
617
  new Set(types).forEach((value)=>{
@@ -1081,12 +1085,14 @@ function rawContent({ exclude }) {
1081
1085
  };
1082
1086
  }
1083
1087
 
1084
- function findJsBundlePathCallback({ format, bundlePath, conditionNames }) {
1085
- const hasCondition = bundlePath != null;
1088
+ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specialCondition) {
1089
+ const hasBundle = bundlePath != null;
1086
1090
  const formatCond = format === 'cjs' ? 'require' : 'import';
1087
1091
  const isTypesCondName = conditionNames.has('types');
1088
- const isMatchedFormat = conditionNames.has(formatCond);
1089
- return isMatchedFormat && !isTypesCondName && hasCondition;
1092
+ const hasFormatCond = conditionNames.has('import') || conditionNames.has('require');
1093
+ const isMatchedFormat = hasFormatCond ? conditionNames.has(formatCond) : true;
1094
+ const isMatchedConditionWithFormat = specialCondition !== 'default' ? conditionNames.has(specialCondition) || isMatchedFormat : isMatchedFormat;
1095
+ return isMatchedConditionWithFormat && !isTypesCondName && hasBundle;
1090
1096
  }
1091
1097
  function findTypesFileCallback({ format, bundlePath, conditionNames }) {
1092
1098
  const hasCondition = bundlePath != null;
@@ -1123,7 +1129,8 @@ function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
1123
1129
  }
1124
1130
  } else {
1125
1131
  var _exportMapEntries_find2;
1126
- matchedBundlePath = (_exportMapEntries_find2 = exportMapEntries.find(findJsBundlePathCallback)) == null ? void 0 : _exportMapEntries_find2.bundlePath;
1132
+ const specialCondition = getSpecialExportTypeFromSourcePath(sourceFilePath);
1133
+ matchedBundlePath = (_exportMapEntries_find2 = exportMapEntries.find((item)=>findJsBundlePathCallback(item, specialCondition))) == null ? void 0 : _exportMapEntries_find2.bundlePath;
1127
1134
  }
1128
1135
  if (matchedBundlePath) {
1129
1136
  if (!sourceToRelativeBundleMap.has(exportCondition.source)) sourceToRelativeBundleMap.set(exportCondition.source, matchedBundlePath);
@@ -1137,9 +1144,9 @@ function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
1137
1144
  if (resolved != null) {
1138
1145
  // For types, generate relative path to the other type files,
1139
1146
  // this will be compatible for the node10 ts module resolution.
1140
- const srcBundle = sourceToRelativeBundleMap.get(sourceFilePath);
1147
+ let srcBundle = sourceToRelativeBundleMap.get(sourceFilePath);
1141
1148
  // Resolved module bundle path
1142
- const resolvedModuleBundle = sourceToRelativeBundleMap.get(resolved.id);
1149
+ let resolvedModuleBundle = sourceToRelativeBundleMap.get(resolved.id);
1143
1150
  if (resolved.id !== sourceFilePath && srcBundle && resolvedModuleBundle) {
1144
1151
  const absoluteBundlePath = path__default.default.resolve(cwd, srcBundle);
1145
1152
  const absoluteImportBundlePath = path__default.default.resolve(cwd, resolvedModuleBundle);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "5.2.0",
3
+ "version": "5.2.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",