bunchee 5.2.1 → 5.3.0-beta.0
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 +1 -1
- package/dist/index.js +31 -11
- package/package.json +4 -5
package/dist/bin/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -275,7 +275,9 @@ async function removeDir(dirPath) {
|
|
|
275
275
|
const removedDirs = new Set();
|
|
276
276
|
async function removeOutputDir(output, cwd) {
|
|
277
277
|
const dir = output.dir;
|
|
278
|
-
if (dir &&
|
|
278
|
+
if (dir && // not equal to cwd
|
|
279
|
+
dir !== cwd && // not equal to src/ dir
|
|
280
|
+
dir !== path__default.default.resolve(cwd, SRC) && !removedDirs.has(dir)) {
|
|
279
281
|
await removeDir(dir);
|
|
280
282
|
removedDirs.add(dir);
|
|
281
283
|
}
|
|
@@ -608,10 +610,6 @@ function getSpecialExportTypeFromComposedExportPath(composedExportType) {
|
|
|
608
610
|
}
|
|
609
611
|
return 'default';
|
|
610
612
|
}
|
|
611
|
-
function getSpecialExportTypeFromSourcePath(sourcePath) {
|
|
612
|
-
const fileBaseName = baseNameWithoutExtension(sourcePath);
|
|
613
|
-
return getSpecialExportTypeFromComposedExportPath(fileBaseName);
|
|
614
|
-
}
|
|
615
613
|
function getExportTypeFromExportTypesArray(types) {
|
|
616
614
|
let exportType = 'default';
|
|
617
615
|
new Set(types).forEach((value)=>{
|
|
@@ -623,6 +621,15 @@ function getExportTypeFromExportTypesArray(types) {
|
|
|
623
621
|
});
|
|
624
622
|
return exportType;
|
|
625
623
|
}
|
|
624
|
+
function getSpecialExportTypeFromConditionNames(conditionNames) {
|
|
625
|
+
let exportType = 'default';
|
|
626
|
+
conditionNames.forEach((value)=>{
|
|
627
|
+
if (specialExportConventions.has(value)) {
|
|
628
|
+
exportType = value;
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
return exportType;
|
|
632
|
+
}
|
|
626
633
|
// ./index -> .
|
|
627
634
|
// ./index.development -> .
|
|
628
635
|
// ./index.react-server -> .
|
|
@@ -1085,14 +1092,19 @@ function rawContent({ exclude }) {
|
|
|
1085
1092
|
};
|
|
1086
1093
|
}
|
|
1087
1094
|
|
|
1095
|
+
function hasNoSpecialCondition(conditionNames) {
|
|
1096
|
+
return [
|
|
1097
|
+
...conditionNames
|
|
1098
|
+
].every((name)=>!specialExportConventions.has(name));
|
|
1099
|
+
}
|
|
1088
1100
|
function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specialCondition) {
|
|
1089
1101
|
const hasBundle = bundlePath != null;
|
|
1090
1102
|
const formatCond = format === 'cjs' ? 'require' : 'import';
|
|
1091
1103
|
const isTypesCondName = conditionNames.has('types');
|
|
1092
1104
|
const hasFormatCond = conditionNames.has('import') || conditionNames.has('require');
|
|
1093
1105
|
const isMatchedFormat = hasFormatCond ? conditionNames.has(formatCond) : true;
|
|
1094
|
-
const isMatchedConditionWithFormat =
|
|
1095
|
-
return isMatchedConditionWithFormat && !isTypesCondName && hasBundle;
|
|
1106
|
+
const isMatchedConditionWithFormat = conditionNames.has(specialCondition) || !conditionNames.has('default') && hasNoSpecialCondition(conditionNames);
|
|
1107
|
+
return isMatchedConditionWithFormat && !isTypesCondName && hasBundle && isMatchedFormat;
|
|
1096
1108
|
}
|
|
1097
1109
|
function findTypesFileCallback({ format, bundlePath, conditionNames }) {
|
|
1098
1110
|
const hasCondition = bundlePath != null;
|
|
@@ -1101,9 +1113,10 @@ function findTypesFileCallback({ format, bundlePath, conditionNames }) {
|
|
|
1101
1113
|
return isTypesCondName && hasCondition && (formatCond ? conditionNames.has(formatCond) : true);
|
|
1102
1114
|
}
|
|
1103
1115
|
// Alias entry key to dist bundle path
|
|
1104
|
-
function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
|
|
1116
|
+
function aliasEntries({ entry: sourceFilePath, conditionNames, entries, format, dts, cwd }) {
|
|
1105
1117
|
// <imported source file path>: <relative path to source's bundle>
|
|
1106
1118
|
const sourceToRelativeBundleMap = new Map();
|
|
1119
|
+
const specialCondition = getSpecialExportTypeFromConditionNames(conditionNames);
|
|
1107
1120
|
for (const [, exportCondition] of Object.entries(entries)){
|
|
1108
1121
|
const exportDistMaps = exportCondition.export;
|
|
1109
1122
|
const exportMapEntries = Object.entries(exportDistMaps).map(([composedKey, bundlePath])=>({
|
|
@@ -1129,8 +1142,9 @@ function aliasEntries({ entry: sourceFilePath, entries, format, dts, cwd }) {
|
|
|
1129
1142
|
}
|
|
1130
1143
|
} else {
|
|
1131
1144
|
var _exportMapEntries_find2;
|
|
1132
|
-
|
|
1133
|
-
|
|
1145
|
+
matchedBundlePath = (_exportMapEntries_find2 = exportMapEntries.find((item)=>{
|
|
1146
|
+
return findJsBundlePathCallback(item, specialCondition);
|
|
1147
|
+
})) == null ? void 0 : _exportMapEntries_find2.bundlePath;
|
|
1134
1148
|
}
|
|
1135
1149
|
if (matchedBundlePath) {
|
|
1136
1150
|
if (!sourceToRelativeBundleMap.has(exportCondition.source)) sourceToRelativeBundleMap.set(exportCondition.source, matchedBundlePath);
|
|
@@ -1331,7 +1345,8 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1331
1345
|
const swcParserConfig = {
|
|
1332
1346
|
syntax: useTypeScript ? 'typescript' : 'ecmascript',
|
|
1333
1347
|
[useTypeScript ? 'tsx' : 'jsx']: true,
|
|
1334
|
-
exportDefaultFrom: true
|
|
1348
|
+
exportDefaultFrom: true,
|
|
1349
|
+
decorators: true
|
|
1335
1350
|
};
|
|
1336
1351
|
const swcOptions = {
|
|
1337
1352
|
jsc: {
|
|
@@ -1341,6 +1356,9 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1341
1356
|
loose: true,
|
|
1342
1357
|
externalHelpers: false,
|
|
1343
1358
|
parser: swcParserConfig,
|
|
1359
|
+
transform: {
|
|
1360
|
+
decoratorVersion: '2022-03'
|
|
1361
|
+
},
|
|
1344
1362
|
...shouldMinify && {
|
|
1345
1363
|
minify: {
|
|
1346
1364
|
...swcMinifyOptions,
|
|
@@ -1356,10 +1374,12 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1356
1374
|
// common plugins for both dts and ts assets that need to be processed
|
|
1357
1375
|
// If it's a .d.ts file under non-ESM package or .d.cts file, use cjs types alias.
|
|
1358
1376
|
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;
|
|
1377
|
+
const currentConditionNames = Object.keys(exportCondition.export)[0];
|
|
1359
1378
|
const aliasPlugin = aliasEntries({
|
|
1360
1379
|
entry,
|
|
1361
1380
|
entries,
|
|
1362
1381
|
format: aliasFormat,
|
|
1382
|
+
conditionNames: new Set(currentConditionNames.split('.')),
|
|
1363
1383
|
dts,
|
|
1364
1384
|
cwd
|
|
1365
1385
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0-beta.0",
|
|
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",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@huozhi/testing-package": "1.0.0",
|
|
71
71
|
"@swc-node/register": "^1.9.0",
|
|
72
72
|
"@swc/jest": "^0.2.31",
|
|
73
|
-
"@swc/types": "^0.1.
|
|
73
|
+
"@swc/types": "^0.1.9",
|
|
74
74
|
"@types/clean-css": "^4.2.11",
|
|
75
75
|
"@types/jest": "29.0.0",
|
|
76
76
|
"@types/node": "^20.4.1",
|
|
@@ -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"
|
|
@@ -104,7 +104,6 @@
|
|
|
104
104
|
],
|
|
105
105
|
"testTimeout": 60000
|
|
106
106
|
},
|
|
107
|
-
"packageManager": "pnpm@8.8.0",
|
|
108
107
|
"scripts": {
|
|
109
108
|
"test": "jest --env node",
|
|
110
109
|
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
|