bunchee 5.2.0-beta.1 → 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
@@ -133,13 +133,6 @@ const logger = {
133
133
  console.log(color('green')('✓'), ...arg);
134
134
  }
135
135
  };
136
- function paint(prefix, prefixColor, ...arg) {
137
- if (pc.isColorSupported) {
138
- console.log(pc[prefixColor](prefix), ...arg);
139
- } else {
140
- console.log(prefix, ...arg);
141
- }
142
- }
143
136
 
144
137
  function exit(err) {
145
138
  logger.error(err);
@@ -477,7 +470,7 @@ function lint$1(pkg) {
477
470
  }
478
471
  }
479
472
 
480
- var version = "5.2.0-beta.1";
473
+ var version = "5.2.1";
481
474
 
482
475
  function relativify(path) {
483
476
  return path.startsWith('.') ? path : `./${path}`;
@@ -1025,25 +1018,42 @@ async function run(args) {
1025
1018
  // lint package
1026
1019
  await lint(cwd);
1027
1020
  const { default: ora } = await import('ora');
1028
- const spinner = ora({
1029
- text: 'Building...\n',
1021
+ const oraInstance = ora({
1022
+ text: 'Building...\n\n',
1030
1023
  color: 'green'
1031
1024
  });
1032
- function stopSpinner() {
1033
- if (spinner.isSpinning) {
1034
- spinner.stop();
1025
+ const spinner = {
1026
+ start: startSpinner,
1027
+ stop: stopSpinner
1028
+ };
1029
+ function startSpinner() {
1030
+ oraInstance.start();
1031
+ }
1032
+ function stopSpinner(text) {
1033
+ if (oraInstance.isSpinning) {
1034
+ oraInstance.clear();
1035
+ if (text) {
1036
+ oraInstance.stopAndPersist({
1037
+ symbol: '✔',
1038
+ text
1039
+ });
1040
+ } else {
1041
+ oraInstance.stop();
1042
+ }
1035
1043
  }
1036
1044
  }
1037
1045
  let initialBuildContext;
1038
1046
  function onBuildStart(buildContext) {
1039
1047
  initialBuildContext = buildContext;
1048
+ if (!watch) {
1049
+ spinner.start();
1050
+ }
1040
1051
  }
1041
1052
  function onBuildEnd(assetJobs) {
1053
+ // Stop spinner before logging output files and sizes on build end
1042
1054
  if (watch) {
1043
- logWatcherBuildTime(assetJobs);
1055
+ logWatcherBuildTime(assetJobs, spinner);
1044
1056
  } else {
1045
- // Stop spinner before logging output files and sizes
1046
- stopSpinner();
1047
1057
  if (assetJobs.length === 0) {
1048
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');
1049
1059
  }
@@ -1058,11 +1068,12 @@ async function run(args) {
1058
1068
  onBuildStart,
1059
1069
  onBuildEnd
1060
1070
  };
1061
- spinner.start();
1071
+ if (watch) {
1072
+ logger.log(`Watching project ${cwd}...`);
1073
+ }
1062
1074
  try {
1063
1075
  await index_js.bundle(cliEntry, bundleConfig);
1064
1076
  } catch (err) {
1065
- stopSpinner();
1066
1077
  if (err.name === 'NOT_EXISTED') {
1067
1078
  buildError = {
1068
1079
  digest: 'bunchee:not-existed',
@@ -1081,12 +1092,10 @@ async function run(args) {
1081
1092
  }
1082
1093
  // watching mode
1083
1094
  if (watch) {
1084
- logger.log(`Watching project ${cwd}...`);
1085
- return;
1095
+ spinner.stop();
1096
+ } else {
1097
+ spinner.stop(`bunchee ${version} build completed`);
1086
1098
  }
1087
- // build mode
1088
- logger.log();
1089
- paint('✓', 'green', `bunchee ${version} build completed`);
1090
1099
  }
1091
1100
  async function main() {
1092
1101
  let params, error;
@@ -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(`Build 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
@@ -556,6 +556,18 @@ async function collectEntriesFromParsedExports(cwd, parsedExportsInfo, sourceFil
556
556
  }
557
557
  // output exports match
558
558
  if (matchedExportType === entryExportPathType || !hasSpecialEntry && matchedExportType !== 'default') {
559
+ // When we dealing with special export conditions, we need to make sure
560
+ // the outputs won't override the default export output paths.
561
+ // e.g. We have './index' -> { default: 'index.js', development: 'index.development.js' };
562
+ // When we generate './index.react-server' -> { 'react-server': 'index.react-server.js' },
563
+ // Normalize the entryExportPath to './index' first and check if it already exists with output paths.
564
+ const normalizedEntryExportPath = stripSpecialCondition(entryExportPath);
565
+ if (// The entry already exists, e.g. normalize './index.react-server' to './index'
566
+ entries[normalizedEntryExportPath] && // Is special export condition
567
+ entryExportPathType !== 'default' && // The extracted special condition is not the current loop one.
568
+ entryExportPathType !== matchedExportType) {
569
+ continue;
570
+ }
559
571
  const exportMap = entries[entryExportPath].export;
560
572
  exportMap[outputComposedExportType] = outputPath;
561
573
  }
@@ -596,6 +608,10 @@ function getSpecialExportTypeFromComposedExportPath(composedExportType) {
596
608
  }
597
609
  return 'default';
598
610
  }
611
+ function getSpecialExportTypeFromSourcePath(sourcePath) {
612
+ const fileBaseName = baseNameWithoutExtension(sourcePath);
613
+ return getSpecialExportTypeFromComposedExportPath(fileBaseName);
614
+ }
599
615
  function getExportTypeFromExportTypesArray(types) {
600
616
  let exportType = 'default';
601
617
  new Set(types).forEach((value)=>{
@@ -1069,12 +1085,14 @@ function rawContent({ exclude }) {
1069
1085
  };
1070
1086
  }
1071
1087
 
1072
- function findJsBundlePathCallback({ format, bundlePath, conditionNames }) {
1073
- const hasCondition = bundlePath != null;
1088
+ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specialCondition) {
1089
+ const hasBundle = bundlePath != null;
1074
1090
  const formatCond = format === 'cjs' ? 'require' : 'import';
1075
1091
  const isTypesCondName = conditionNames.has('types');
1076
- const isMatchedFormat = conditionNames.has(formatCond);
1077
- 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;
1078
1096
  }
1079
1097
  function findTypesFileCallback({ format, bundlePath, conditionNames }) {
1080
1098
  const hasCondition = bundlePath != null;
@@ -1111,7 +1129,8 @@ function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
1111
1129
  }
1112
1130
  } else {
1113
1131
  var _exportMapEntries_find2;
1114
- 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;
1115
1134
  }
1116
1135
  if (matchedBundlePath) {
1117
1136
  if (!sourceToRelativeBundleMap.has(exportCondition.source)) sourceToRelativeBundleMap.set(exportCondition.source, matchedBundlePath);
@@ -1125,9 +1144,9 @@ function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
1125
1144
  if (resolved != null) {
1126
1145
  // For types, generate relative path to the other type files,
1127
1146
  // this will be compatible for the node10 ts module resolution.
1128
- const srcBundle = sourceToRelativeBundleMap.get(sourceFilePath);
1147
+ let srcBundle = sourceToRelativeBundleMap.get(sourceFilePath);
1129
1148
  // Resolved module bundle path
1130
- const resolvedModuleBundle = sourceToRelativeBundleMap.get(resolved.id);
1149
+ let resolvedModuleBundle = sourceToRelativeBundleMap.get(resolved.id);
1131
1150
  if (resolved.id !== sourceFilePath && srcBundle && resolvedModuleBundle) {
1132
1151
  const absoluteBundlePath = path__default.default.resolve(cwd, srcBundle);
1133
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-beta.1",
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",