bunchee 5.2.0 → 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/README.md +1 -1
- package/dist/bin/cli.js +28 -15
- package/dist/index.js +29 -8
- package/package.json +3 -3
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.
|
|
473
|
+
var version = "5.2.2";
|
|
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
|
|
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 (
|
|
1027
|
-
|
|
1028
|
-
console.log();
|
|
1033
|
+
if (oraInstance.isSpinning) {
|
|
1034
|
+
oraInstance.clear();
|
|
1029
1035
|
if (text) {
|
|
1030
|
-
|
|
1036
|
+
oraInstance.stopAndPersist({
|
|
1031
1037
|
symbol: '✔',
|
|
1032
1038
|
text
|
|
1033
1039
|
});
|
|
1034
1040
|
} else {
|
|
1035
|
-
|
|
1041
|
+
oraInstance.stop();
|
|
1036
1042
|
}
|
|
1037
1043
|
}
|
|
1038
1044
|
}
|
|
1039
1045
|
let initialBuildContext;
|
|
1040
1046
|
function onBuildStart(buildContext) {
|
|
1041
1047
|
initialBuildContext = buildContext;
|
|
1042
|
-
|
|
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
|
-
|
|
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 (
|
|
1088
|
-
|
|
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)
|
|
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
|
-
|
|
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
|
@@ -619,6 +619,15 @@ function getExportTypeFromExportTypesArray(types) {
|
|
|
619
619
|
});
|
|
620
620
|
return exportType;
|
|
621
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
|
+
}
|
|
622
631
|
// ./index -> .
|
|
623
632
|
// ./index.development -> .
|
|
624
633
|
// ./index.react-server -> .
|
|
@@ -1081,12 +1090,19 @@ function rawContent({ exclude }) {
|
|
|
1081
1090
|
};
|
|
1082
1091
|
}
|
|
1083
1092
|
|
|
1084
|
-
function
|
|
1085
|
-
|
|
1093
|
+
function hasNoSpecialCondition(conditionNames) {
|
|
1094
|
+
return [
|
|
1095
|
+
...conditionNames
|
|
1096
|
+
].every((name)=>!specialExportConventions.has(name));
|
|
1097
|
+
}
|
|
1098
|
+
function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specialCondition) {
|
|
1099
|
+
const hasBundle = bundlePath != null;
|
|
1086
1100
|
const formatCond = format === 'cjs' ? 'require' : 'import';
|
|
1087
1101
|
const isTypesCondName = conditionNames.has('types');
|
|
1088
|
-
const
|
|
1089
|
-
|
|
1102
|
+
const hasFormatCond = conditionNames.has('import') || conditionNames.has('require');
|
|
1103
|
+
const isMatchedFormat = hasFormatCond ? conditionNames.has(formatCond) : true;
|
|
1104
|
+
const isMatchedConditionWithFormat = conditionNames.has(specialCondition) || !conditionNames.has('default') && hasNoSpecialCondition(conditionNames);
|
|
1105
|
+
return isMatchedConditionWithFormat && !isTypesCondName && hasBundle && isMatchedFormat;
|
|
1090
1106
|
}
|
|
1091
1107
|
function findTypesFileCallback({ format, bundlePath, conditionNames }) {
|
|
1092
1108
|
const hasCondition = bundlePath != null;
|
|
@@ -1095,9 +1111,10 @@ function findTypesFileCallback({ format, bundlePath, conditionNames }) {
|
|
|
1095
1111
|
return isTypesCondName && hasCondition && (formatCond ? conditionNames.has(formatCond) : true);
|
|
1096
1112
|
}
|
|
1097
1113
|
// Alias entry key to dist bundle path
|
|
1098
|
-
function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
|
|
1114
|
+
function aliasEntries({ entry: sourceFilePath, conditionNames, entries, format, dts, cwd }) {
|
|
1099
1115
|
// <imported source file path>: <relative path to source's bundle>
|
|
1100
1116
|
const sourceToRelativeBundleMap = new Map();
|
|
1117
|
+
const specialCondition = getSpecialExportTypeFromConditionNames(conditionNames);
|
|
1101
1118
|
for (const [, exportCondition] of Object.entries(entries)){
|
|
1102
1119
|
const exportDistMaps = exportCondition.export;
|
|
1103
1120
|
const exportMapEntries = Object.entries(exportDistMaps).map(([composedKey, bundlePath])=>({
|
|
@@ -1123,7 +1140,9 @@ function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
|
|
|
1123
1140
|
}
|
|
1124
1141
|
} else {
|
|
1125
1142
|
var _exportMapEntries_find2;
|
|
1126
|
-
matchedBundlePath = (_exportMapEntries_find2 = exportMapEntries.find(
|
|
1143
|
+
matchedBundlePath = (_exportMapEntries_find2 = exportMapEntries.find((item)=>{
|
|
1144
|
+
return findJsBundlePathCallback(item, specialCondition);
|
|
1145
|
+
})) == null ? void 0 : _exportMapEntries_find2.bundlePath;
|
|
1127
1146
|
}
|
|
1128
1147
|
if (matchedBundlePath) {
|
|
1129
1148
|
if (!sourceToRelativeBundleMap.has(exportCondition.source)) sourceToRelativeBundleMap.set(exportCondition.source, matchedBundlePath);
|
|
@@ -1137,9 +1156,9 @@ function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
|
|
|
1137
1156
|
if (resolved != null) {
|
|
1138
1157
|
// For types, generate relative path to the other type files,
|
|
1139
1158
|
// this will be compatible for the node10 ts module resolution.
|
|
1140
|
-
|
|
1159
|
+
let srcBundle = sourceToRelativeBundleMap.get(sourceFilePath);
|
|
1141
1160
|
// Resolved module bundle path
|
|
1142
|
-
|
|
1161
|
+
let resolvedModuleBundle = sourceToRelativeBundleMap.get(resolved.id);
|
|
1143
1162
|
if (resolved.id !== sourceFilePath && srcBundle && resolvedModuleBundle) {
|
|
1144
1163
|
const absoluteBundlePath = path__default.default.resolve(cwd, srcBundle);
|
|
1145
1164
|
const absoluteImportBundlePath = path__default.default.resolve(cwd, resolvedModuleBundle);
|
|
@@ -1349,10 +1368,12 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1349
1368
|
// common plugins for both dts and ts assets that need to be processed
|
|
1350
1369
|
// If it's a .d.ts file under non-ESM package or .d.cts file, use cjs types alias.
|
|
1351
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];
|
|
1352
1372
|
const aliasPlugin = aliasEntries({
|
|
1353
1373
|
entry,
|
|
1354
1374
|
entries,
|
|
1355
1375
|
format: aliasFormat,
|
|
1376
|
+
conditionNames: new Set(currentConditionNames.split('.')),
|
|
1356
1377
|
dts,
|
|
1357
1378
|
cwd
|
|
1358
1379
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "5.2.
|
|
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.
|
|
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.
|
|
84
|
+
"typescript": "^5.5.2"
|
|
85
85
|
},
|
|
86
86
|
"lint-staged": {
|
|
87
87
|
"*.{js,jsx,ts,tsx,md,json,yml,yaml}": "prettier --write"
|