bunchee 6.10.0 → 6.11.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/README.md +3 -11
- package/dist/bin/cli.js +2 -3
- package/dist/index.js +45 -37
- package/package.json +9 -10
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
<p align="left">
|
|
8
8
|
<a href="https://npm.im/bunchee">
|
|
9
|
-
<img src="https://
|
|
9
|
+
<img src="https://img.shields.io/npm/v/bunchee?style=flat&colorA=000000&colorB=000000">
|
|
10
10
|
</a>
|
|
11
11
|
|
|
12
|
-
<a href="https://
|
|
13
|
-
<img src="https://
|
|
12
|
+
<a href="https://npm.im/bunchee">
|
|
13
|
+
<img src="https://img.shields.io/npm/dt/bunchee.svg?style=flat&colorA=000000&colorB=000000">
|
|
14
14
|
</a>
|
|
15
15
|
</p>
|
|
16
16
|
|
|
@@ -550,14 +550,6 @@ export { readme, config, styles, content }
|
|
|
550
550
|
|
|
551
551
|
All these imports will be bundled as string content, regardless of the original file extension.
|
|
552
552
|
|
|
553
|
-
### Agent Skills
|
|
554
|
-
|
|
555
|
-
If you want to use bunchee with coding agents with skills, run:
|
|
556
|
-
|
|
557
|
-
```sh
|
|
558
|
-
npx skills add huozhi/npm-skills
|
|
559
|
-
```
|
|
560
|
-
|
|
561
553
|
### Node.js API
|
|
562
554
|
|
|
563
555
|
```ts
|
package/dist/bin/cli.js
CHANGED
|
@@ -525,9 +525,8 @@ function addToExportDistMap(exportToDist, exportPath, outputConditionPairs) {
|
|
|
525
525
|
* './index.react-server': { development: ..., default: ... }
|
|
526
526
|
* }
|
|
527
527
|
*/ async function parseExports(pkg, cwd) {
|
|
528
|
-
var _pkg_exports;
|
|
528
|
+
var _pkg_exports, _pkg_bin;
|
|
529
529
|
const exportsField = (_pkg_exports = pkg.exports) != null ? _pkg_exports : {};
|
|
530
|
-
var _pkg_bin;
|
|
531
530
|
const bins = (_pkg_bin = pkg.bin) != null ? _pkg_bin : {};
|
|
532
531
|
const exportToDist = new Map();
|
|
533
532
|
const isEsmPkg = isESModulePackage(pkg.type);
|
|
@@ -856,7 +855,7 @@ async function lint$1(cwd) {
|
|
|
856
855
|
}
|
|
857
856
|
}
|
|
858
857
|
|
|
859
|
-
var version = "6.
|
|
858
|
+
var version = "6.11.0";
|
|
860
859
|
|
|
861
860
|
async function writeDefaultTsconfig(tsConfigPath) {
|
|
862
861
|
await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
|
package/dist/index.js
CHANGED
|
@@ -650,9 +650,8 @@ function addToExportDistMap(exportToDist, exportPath, outputConditionPairs) {
|
|
|
650
650
|
* './index.react-server': { development: ..., default: ... }
|
|
651
651
|
* }
|
|
652
652
|
*/ async function parseExports(pkg, cwd) {
|
|
653
|
-
var _pkg_exports;
|
|
653
|
+
var _pkg_exports, _pkg_bin;
|
|
654
654
|
const exportsField = (_pkg_exports = pkg.exports) != null ? _pkg_exports : {};
|
|
655
|
-
var _pkg_bin;
|
|
656
655
|
const bins = (_pkg_bin = pkg.bin) != null ? _pkg_bin : {};
|
|
657
656
|
const exportToDist = new Map();
|
|
658
657
|
const isEsmPkg = isESModulePackage(pkg.type);
|
|
@@ -915,6 +914,12 @@ function getSpecialExportTypeFromSourcePath(sourcePath) {
|
|
|
915
914
|
const fileBaseName = baseNameWithoutExtension(sourcePath);
|
|
916
915
|
return getSpecialExportTypeFromComposedExportPath(fileBaseName);
|
|
917
916
|
}
|
|
917
|
+
const ModuleFormat = {
|
|
918
|
+
none: 0,
|
|
919
|
+
esm: 1,
|
|
920
|
+
cjs: 2,
|
|
921
|
+
all: 3
|
|
922
|
+
};
|
|
918
923
|
function getExportTypeFromExportTypesArray(types) {
|
|
919
924
|
let exportType = 'default';
|
|
920
925
|
new Set(types).forEach((value)=>{
|
|
@@ -1033,9 +1038,16 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
|
|
|
1033
1038
|
*/ async function collectSourceEntriesFromExportPaths(sourceFolderPath, parsedExportsInfo, pkg) {
|
|
1034
1039
|
const bins = new Map();
|
|
1035
1040
|
const exportsEntries = new Map();
|
|
1041
|
+
let requiredPrivateModuleFormats = ModuleFormat.none;
|
|
1036
1042
|
for (const [exportPath, exportInfo] of parsedExportsInfo.entries()){
|
|
1037
1043
|
const specialConditions = new Set();
|
|
1038
|
-
for (const [
|
|
1044
|
+
for (const [outputPath, composedExportType] of exportInfo){
|
|
1045
|
+
// Collect required private shared module formats while walking export outputs.
|
|
1046
|
+
const exportType = composedExportType.split('.').pop();
|
|
1047
|
+
if (exportType !== 'types') {
|
|
1048
|
+
const ext = path__default.default.extname(outputPath).slice(1);
|
|
1049
|
+
requiredPrivateModuleFormats |= isCjsExportName(pkg, composedExportType, ext) ? ModuleFormat.cjs : ModuleFormat.esm;
|
|
1050
|
+
}
|
|
1039
1051
|
const specialExportType = getSpecialExportTypeFromComposedExportPath(composedExportType);
|
|
1040
1052
|
if (specialExportType !== 'default') {
|
|
1041
1053
|
specialConditions.add(specialExportType);
|
|
@@ -1064,6 +1076,7 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
|
|
|
1064
1076
|
],
|
|
1065
1077
|
expandDirectories: false
|
|
1066
1078
|
});
|
|
1079
|
+
const defaultPrivateModuleFormats = requiredPrivateModuleFormats !== ModuleFormat.none ? requiredPrivateModuleFormats : ModuleFormat.all;
|
|
1067
1080
|
for (const file of privateFiles){
|
|
1068
1081
|
const sourceFileAbsolutePath = path__default.default.join(sourceFolderPath, file);
|
|
1069
1082
|
const exportPath = sourceFilenameToExportFullPath(file);
|
|
@@ -1074,31 +1087,36 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
|
|
|
1074
1087
|
// export type: default => ''
|
|
1075
1088
|
// export type: development => '.development'
|
|
1076
1089
|
const condPart = isSpecialExport ? specialExportType + '.' : '';
|
|
1090
|
+
const sourceExt = path__default.default.extname(file).slice(1);
|
|
1091
|
+
const formats = sourceExt === 'cts' ? ModuleFormat.cjs : sourceExt === 'mts' ? ModuleFormat.esm : defaultPrivateModuleFormats;
|
|
1077
1092
|
// Map private shared files to the dist directory
|
|
1078
1093
|
// e.g. ./_utils.ts -> ./dist/_utils.js
|
|
1079
|
-
// TODO: improve the logic to only generate the required files, not all possible files
|
|
1080
1094
|
const isTs = isTypescriptFile(file);
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
];
|
|
1091
|
-
const privateExportInfo = [
|
|
1092
|
-
...isTs ? typesInfos : [],
|
|
1093
|
-
[
|
|
1095
|
+
const privateExportInfo = [];
|
|
1096
|
+
if (formats === ModuleFormat.esm || formats === ModuleFormat.all) {
|
|
1097
|
+
if (isTs) {
|
|
1098
|
+
privateExportInfo.push([
|
|
1099
|
+
posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.d.ts' : '.d.mts'))),
|
|
1100
|
+
condPart + 'import.types'
|
|
1101
|
+
]);
|
|
1102
|
+
}
|
|
1103
|
+
privateExportInfo.push([
|
|
1094
1104
|
posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.js' : '.mjs'))),
|
|
1095
1105
|
condPart + 'import.default'
|
|
1096
|
-
]
|
|
1097
|
-
|
|
1106
|
+
]);
|
|
1107
|
+
}
|
|
1108
|
+
if (formats === ModuleFormat.cjs || formats === ModuleFormat.all) {
|
|
1109
|
+
if (isTs) {
|
|
1110
|
+
privateExportInfo.push([
|
|
1111
|
+
posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.d.cts' : '.d.ts'))),
|
|
1112
|
+
condPart + 'require.types'
|
|
1113
|
+
]);
|
|
1114
|
+
}
|
|
1115
|
+
privateExportInfo.push([
|
|
1098
1116
|
posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.cjs' : '.js'))),
|
|
1099
1117
|
condPart + 'require.default'
|
|
1100
|
-
]
|
|
1101
|
-
|
|
1118
|
+
]);
|
|
1119
|
+
}
|
|
1102
1120
|
const exportsInfo = parsedExportsInfo.get(normalizedExportPath);
|
|
1103
1121
|
if (!exportsInfo) {
|
|
1104
1122
|
// Add private shared files to parsedExportsInfo
|
|
@@ -1299,21 +1317,16 @@ async function writeDefaultTsconfig(tsConfigPath) {
|
|
|
1299
1317
|
|
|
1300
1318
|
const FILENAME_REGEX = /__filename/;
|
|
1301
1319
|
const DIRNAME_REGEX = /__dirname/;
|
|
1302
|
-
// not char, or space before require(.resolve)?(
|
|
1303
|
-
const GLOBAL_REQUIRE_REGEX = /(?:^|[^.\w'"`])\brequire(\.resolve)?\(\s*[\r\n]*(\w|['"`])/;
|
|
1304
1320
|
const PolyfillComment = '/** rollup-private-do-not-use-esm-shim-polyfill */';
|
|
1305
|
-
const createESMShim = ({ filename, dirname
|
|
1321
|
+
const createESMShim = ({ filename, dirname })=>{
|
|
1306
1322
|
const useNodeUrl = filename || dirname;
|
|
1307
1323
|
const useNodePath = dirname;
|
|
1308
|
-
const useNodeModule = globalRequire;
|
|
1309
1324
|
return `\
|
|
1310
1325
|
${PolyfillComment}
|
|
1311
1326
|
${useNodeUrl ? `import __node_cjsUrl from 'node:url'` : ''};
|
|
1312
1327
|
${useNodePath ? `import __node_cjsPath from 'node:path';` : ''}
|
|
1313
|
-
${useNodeModule ? `import __node_cjsModule from 'node:module';` : ''}
|
|
1314
1328
|
${useNodeUrl ? 'const __filename = __node_cjsUrl.fileURLToPath(import.meta.url);' : ''}
|
|
1315
1329
|
${useNodePath ? 'const __dirname = __node_cjsPath.dirname(__filename);' : ''}
|
|
1316
|
-
${useNodeModule ? 'const require = __node_cjsModule.createRequire(import.meta.url);' : ''}
|
|
1317
1330
|
`.trim() + '\n';
|
|
1318
1331
|
};
|
|
1319
1332
|
function esmShim() {
|
|
@@ -1328,17 +1341,13 @@ function esmShim() {
|
|
|
1328
1341
|
}
|
|
1329
1342
|
let hasFilename = false;
|
|
1330
1343
|
let hasDirname = false;
|
|
1331
|
-
let hasGlobalRequire = false;
|
|
1332
1344
|
if (FILENAME_REGEX.test(code)) {
|
|
1333
1345
|
hasFilename = true;
|
|
1334
1346
|
}
|
|
1335
1347
|
if (DIRNAME_REGEX.test(code)) {
|
|
1336
1348
|
hasDirname = true;
|
|
1337
1349
|
}
|
|
1338
|
-
if (
|
|
1339
|
-
hasGlobalRequire = true;
|
|
1340
|
-
}
|
|
1341
|
-
if (!hasFilename && !hasDirname && !hasGlobalRequire) {
|
|
1350
|
+
if (!hasFilename && !hasDirname) {
|
|
1342
1351
|
return null;
|
|
1343
1352
|
}
|
|
1344
1353
|
const magicString = new MagicString__default.default(code);
|
|
@@ -1370,8 +1379,7 @@ function esmShim() {
|
|
|
1370
1379
|
}
|
|
1371
1380
|
magicString.appendRight(end, '\n' + createESMShim({
|
|
1372
1381
|
filename: hasFilename,
|
|
1373
|
-
dirname: hasDirname
|
|
1374
|
-
globalRequire: hasGlobalRequire
|
|
1382
|
+
dirname: hasDirname
|
|
1375
1383
|
}));
|
|
1376
1384
|
return {
|
|
1377
1385
|
code: magicString.toString(),
|
|
@@ -1406,8 +1414,8 @@ function minify(code) {
|
|
|
1406
1414
|
return cleanCssInstance.minify(code).styles;
|
|
1407
1415
|
}
|
|
1408
1416
|
function inlineCss(options) {
|
|
1409
|
-
const cssIds = new Set();
|
|
1410
1417
|
var _options_exclude;
|
|
1418
|
+
const cssIds = new Set();
|
|
1411
1419
|
const filter = pluginutils.createFilter([
|
|
1412
1420
|
'**/*.css'
|
|
1413
1421
|
], (_options_exclude = options.exclude) != null ? _options_exclude : []);
|
|
@@ -1809,11 +1817,11 @@ async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal,
|
|
|
1809
1817
|
}
|
|
1810
1818
|
const memoizeDtsPluginByKey = memoizeByKey(createDtsPlugin);
|
|
1811
1819
|
async function buildInputConfig(entry, bundleConfig, exportCondition, buildContext, dts) {
|
|
1820
|
+
var _bundleConfig_external;
|
|
1812
1821
|
var _bundleConfig_file, _bundleConfig_file1;
|
|
1813
1822
|
const { entries, pkg, cwd, tsOptions: { tsConfigPath, tsCompilerOptions }, browserslistConfig, pluginContext } = buildContext;
|
|
1814
1823
|
const isBinEntry = isBinExportPath(exportCondition.name);
|
|
1815
1824
|
const hasNoExternal = bundleConfig.external === null;
|
|
1816
|
-
var _bundleConfig_external;
|
|
1817
1825
|
const externals = hasNoExternal ? [] : [
|
|
1818
1826
|
pkg.peerDependencies,
|
|
1819
1827
|
pkg.dependencies,
|
|
@@ -2124,6 +2132,7 @@ function createSplitChunks(dependencyGraphMap, entryFiles) {
|
|
|
2124
2132
|
}
|
|
2125
2133
|
|
|
2126
2134
|
async function buildOutputConfigs(bundleConfig, exportCondition, buildContext, dts) {
|
|
2135
|
+
var _exportCondition_export_types;
|
|
2127
2136
|
const { format } = bundleConfig;
|
|
2128
2137
|
const { entries, pkg, cwd, tsOptions: { tsCompilerOptions }, pluginContext } = buildContext;
|
|
2129
2138
|
// Add esm mark and interop helper if esm export is detected
|
|
@@ -2131,7 +2140,6 @@ async function buildOutputConfigs(bundleConfig, exportCondition, buildContext, d
|
|
|
2131
2140
|
const absoluteOutputFile = path.resolve(cwd, bundleConfig.file);
|
|
2132
2141
|
const isEsmPkg = isESModulePackage(pkg.type);
|
|
2133
2142
|
const name = filePathWithoutExtension(absoluteOutputFile);
|
|
2134
|
-
var _exportCondition_export_types;
|
|
2135
2143
|
const dtsFile = path.resolve(cwd, dts ? bundleConfig.file : (_exportCondition_export_types = exportCondition.export.types) != null ? _exportCondition_export_types : getExportFileTypePath(bundleConfig.file));
|
|
2136
2144
|
const typesDir = path.dirname(dtsFile);
|
|
2137
2145
|
const jsDir = path.dirname(absoluteOutputFile);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.11.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",
|
|
@@ -59,20 +59,20 @@
|
|
|
59
59
|
},
|
|
60
60
|
"license": "MIT",
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@rollup/plugin-commonjs": "^29.0.
|
|
62
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
63
63
|
"@rollup/plugin-json": "^6.1.0",
|
|
64
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
65
|
-
"@rollup/plugin-replace": "^6.0.
|
|
64
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
65
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
66
66
|
"@rollup/plugin-wasm": "^6.2.2",
|
|
67
|
-
"@rollup/pluginutils": "^5.
|
|
68
|
-
"@swc/core": "^1.
|
|
67
|
+
"@rollup/pluginutils": "^5.4.0",
|
|
68
|
+
"@swc/core": "^1.15.40",
|
|
69
69
|
"@swc/helpers": "^0.5.17",
|
|
70
70
|
"clean-css": "^5.3.3",
|
|
71
71
|
"magic-string": "^0.30.17",
|
|
72
72
|
"nanospinner": "^1.2.2",
|
|
73
73
|
"picomatch": "^4.0.2",
|
|
74
74
|
"pretty-bytes": "^5.6.0",
|
|
75
|
-
"rollup": "^4.
|
|
75
|
+
"rollup": "^4.61.0",
|
|
76
76
|
"rollup-plugin-dts": "^6.4.1",
|
|
77
77
|
"rollup-plugin-swc3": "^0.11.1",
|
|
78
78
|
"rollup-preserve-directives": "^1.1.3",
|
|
@@ -102,12 +102,11 @@
|
|
|
102
102
|
"@types/react": "^19.2.14",
|
|
103
103
|
"@types/react-dom": "^19.2.3",
|
|
104
104
|
"@types/yargs": "^17.0.33",
|
|
105
|
-
"@typescript/native-preview": "*",
|
|
106
105
|
"bunchee": "link:./",
|
|
107
106
|
"cross-env": "^7.0.3",
|
|
108
107
|
"husky": "^9.0.11",
|
|
109
108
|
"lint-staged": "^15.2.2",
|
|
110
|
-
"next": "16.
|
|
109
|
+
"next": "^16.2.6",
|
|
111
110
|
"picocolors": "^1.0.0",
|
|
112
111
|
"postcss": "^8.5.4",
|
|
113
112
|
"prettier": "3.4.2",
|
|
@@ -115,7 +114,7 @@
|
|
|
115
114
|
"react-dom": "^19.2.1",
|
|
116
115
|
"tailwindcss": "^4.1.8",
|
|
117
116
|
"typescript": "^6.0.2",
|
|
118
|
-
"vitest": "^
|
|
117
|
+
"vitest": "^4.1.8"
|
|
119
118
|
},
|
|
120
119
|
"lint-staged": {
|
|
121
120
|
"*.{js,jsx,ts,tsx,md,json,yml,yaml}": "prettier --write"
|