bunchee 6.3.3 → 6.4.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 +9 -1
- package/dist/bin/cli.js +22 -13
- package/dist/index.d.ts +2 -1
- package/dist/index.js +72 -45
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -282,7 +282,7 @@ This convention keeps shared modules private while enabling efficient bundling a
|
|
|
282
282
|
|
|
283
283
|
### CLI
|
|
284
284
|
|
|
285
|
-
####
|
|
285
|
+
#### Options
|
|
286
286
|
|
|
287
287
|
`bunchee` CLI provides few options to create different bundles or generating types. Call `bunchee --help` to see the help information in the terminal.
|
|
288
288
|
|
|
@@ -317,6 +317,14 @@ bunchee --no-external
|
|
|
317
317
|
|
|
318
318
|
This will include all dependencies within your output bundle.
|
|
319
319
|
|
|
320
|
+
#### Build Successful Command
|
|
321
|
+
|
|
322
|
+
A command to be executed after a build is successful can be specified using the `--success` option, which is useful for development watching mode:
|
|
323
|
+
|
|
324
|
+
```sh
|
|
325
|
+
bunchee --watch --success "node ./dist/index.js"
|
|
326
|
+
```
|
|
327
|
+
|
|
320
328
|
#### Prepare Package
|
|
321
329
|
|
|
322
330
|
```sh
|
package/dist/bin/cli.js
CHANGED
|
@@ -281,7 +281,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
|
|
|
281
281
|
];
|
|
282
282
|
addToExportDistMap(exportToDist, currentPath, [
|
|
283
283
|
outputConditionPair
|
|
284
|
-
]
|
|
284
|
+
]);
|
|
285
285
|
} else {
|
|
286
286
|
exportInfo.push([
|
|
287
287
|
exportValue,
|
|
@@ -308,9 +308,8 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
|
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
const mapExportFullPath = (exportPath)=>exportPath === '.' ? './index' : exportPath;
|
|
311
|
-
function addToExportDistMap(exportToDist, exportPath, outputConditionPairs
|
|
311
|
+
function addToExportDistMap(exportToDist, exportPath, outputConditionPairs) {
|
|
312
312
|
const fullPath = mapExportFullPath(exportPath);
|
|
313
|
-
// + (specialExportType ? '.' + specialExportType : '')
|
|
314
313
|
const existingExportInfo = exportToDist.get(fullPath);
|
|
315
314
|
if (!existingExportInfo) {
|
|
316
315
|
exportToDist.set(fullPath, outputConditionPairs);
|
|
@@ -647,7 +646,7 @@ function lint$1(pkg) {
|
|
|
647
646
|
}
|
|
648
647
|
}
|
|
649
648
|
|
|
650
|
-
var version = "6.
|
|
649
|
+
var version = "6.4.0";
|
|
651
650
|
|
|
652
651
|
async function writeDefaultTsconfig(tsConfigPath) {
|
|
653
652
|
await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
|
|
@@ -1082,10 +1081,11 @@ Options:
|
|
|
1082
1081
|
--runtime <runtime> build runtime (nodejs, browser). default: browser
|
|
1083
1082
|
--env <env> inlined process env variables, separate by comma. default: NODE_ENV
|
|
1084
1083
|
--cwd <cwd> specify current working directory
|
|
1085
|
-
--sourcemap enable sourcemap generation
|
|
1084
|
+
--sourcemap enable sourcemap generation
|
|
1086
1085
|
--no-dts do not generate types, default: undefined
|
|
1087
1086
|
--tsconfig path to tsconfig file, default: tsconfig.json
|
|
1088
1087
|
--dts-bundle bundle type declaration files, default: false
|
|
1088
|
+
--success <cmd> run command after build success
|
|
1089
1089
|
`;
|
|
1090
1090
|
function help() {
|
|
1091
1091
|
logger.log(helpMessage);
|
|
@@ -1141,7 +1141,7 @@ async function parseCliArgs(argv) {
|
|
|
1141
1141
|
description: 'js features target: swc target es versions'
|
|
1142
1142
|
}).option('sourcemap', {
|
|
1143
1143
|
type: 'boolean',
|
|
1144
|
-
default:
|
|
1144
|
+
default: undefined,
|
|
1145
1145
|
description: 'enable sourcemap generation'
|
|
1146
1146
|
}).option('env', {
|
|
1147
1147
|
type: 'string',
|
|
@@ -1160,6 +1160,9 @@ async function parseCliArgs(argv) {
|
|
|
1160
1160
|
}).option('prepare', {
|
|
1161
1161
|
type: 'boolean',
|
|
1162
1162
|
description: 'auto setup package.json for building'
|
|
1163
|
+
}).option('success', {
|
|
1164
|
+
type: 'string',
|
|
1165
|
+
description: 'run command after build success'
|
|
1163
1166
|
}).command('prepare', 'auto configure package.json exports for building', ()=>{}, (argv)=>{
|
|
1164
1167
|
return prepare(argv.cwd || process.cwd());
|
|
1165
1168
|
}).command('lint', 'lint package.json', ()=>{}, (argv)=>{
|
|
@@ -1194,13 +1197,18 @@ async function parseCliArgs(argv) {
|
|
|
1194
1197
|
external: args['external'] === false ? null : args['external'],
|
|
1195
1198
|
clean: args['clean'] !== false,
|
|
1196
1199
|
env: args['env'],
|
|
1197
|
-
tsconfig: args['tsconfig']
|
|
1200
|
+
tsconfig: args['tsconfig'],
|
|
1201
|
+
onSuccess: args['success']
|
|
1198
1202
|
};
|
|
1203
|
+
// When minify is enabled, sourcemap should be enabled by default, unless explicitly opted out
|
|
1204
|
+
if (parsedArgs.minify && typeof args['sourcemap'] === 'undefined') {
|
|
1205
|
+
parsedArgs.sourcemap = true;
|
|
1206
|
+
}
|
|
1199
1207
|
return parsedArgs;
|
|
1200
1208
|
}
|
|
1201
1209
|
async function run(args) {
|
|
1202
1210
|
var _args_external;
|
|
1203
|
-
const { source, format, watch, minify, sourcemap, target, runtime, dts, dtsBundle, env, clean, tsconfig } = args;
|
|
1211
|
+
const { source, format, watch, minify, sourcemap, target, runtime, dts, dtsBundle, env, clean, tsconfig, onSuccess } = args;
|
|
1204
1212
|
const cwd = args.cwd || process.cwd();
|
|
1205
1213
|
const file = args.file ? path__default.default.resolve(cwd, args.file) : undefined;
|
|
1206
1214
|
const bundleConfig = {
|
|
@@ -1212,13 +1220,14 @@ async function run(args) {
|
|
|
1212
1220
|
cwd,
|
|
1213
1221
|
target,
|
|
1214
1222
|
runtime,
|
|
1215
|
-
external: args.external === null ? null : ((_args_external = args.external) == null ?
|
|
1223
|
+
external: args.external === null ? null : ((_args_external = args.external) == null ? void 0 : _args_external.split(',')) || [],
|
|
1216
1224
|
watch: !!watch,
|
|
1217
1225
|
minify: !!minify,
|
|
1218
1226
|
sourcemap: sourcemap === false ? false : true,
|
|
1219
|
-
env: (env == null ?
|
|
1227
|
+
env: (env == null ? void 0 : env.split(',')) || [],
|
|
1220
1228
|
clean,
|
|
1221
|
-
tsconfig
|
|
1229
|
+
tsconfig,
|
|
1230
|
+
onSuccess
|
|
1222
1231
|
};
|
|
1223
1232
|
const cliEntry = source ? path__default.default.resolve(cwd, source) : '';
|
|
1224
1233
|
// lint package by default
|
|
@@ -1270,7 +1279,7 @@ async function run(args) {
|
|
|
1270
1279
|
if (assetJobs.length === 0) {
|
|
1271
1280
|
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');
|
|
1272
1281
|
}
|
|
1273
|
-
const outputState = initialBuildContext == null ?
|
|
1282
|
+
const outputState = initialBuildContext == null ? void 0 : initialBuildContext.pluginContext.outputState;
|
|
1274
1283
|
if (outputState) {
|
|
1275
1284
|
logOutputState(outputState.getSizeStats());
|
|
1276
1285
|
}
|
|
@@ -1297,7 +1306,7 @@ async function run(args) {
|
|
|
1297
1306
|
error: err
|
|
1298
1307
|
};
|
|
1299
1308
|
}
|
|
1300
|
-
if ((buildError == null ?
|
|
1309
|
+
if ((buildError == null ? void 0 : buildError.digest) === 'bunchee:not-existed') {
|
|
1301
1310
|
help();
|
|
1302
1311
|
} else {
|
|
1303
1312
|
if (watch) {
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ type BundleConfig = {
|
|
|
21
21
|
pkg?: PackageMetadata;
|
|
22
22
|
clean?: boolean;
|
|
23
23
|
tsconfig?: string;
|
|
24
|
+
onSuccess?: string | (() => void | Promise<void>);
|
|
24
25
|
_callbacks?: {
|
|
25
26
|
onBuildStart?: (state: any) => void;
|
|
26
27
|
onBuildEnd?: (assetJobs: any) => void;
|
|
@@ -44,6 +45,6 @@ type PackageMetadata = {
|
|
|
44
45
|
};
|
|
45
46
|
type BrowserslistConfig = string | string[] | Record<string, string>;
|
|
46
47
|
|
|
47
|
-
declare function bundle(cliEntryPath: string, { cwd: _cwd, ...options }?: BundleConfig): Promise<void>;
|
|
48
|
+
declare function bundle(cliEntryPath: string, { cwd: _cwd, onSuccess, ...options }?: BundleConfig): Promise<void>;
|
|
48
49
|
|
|
49
50
|
export { type BundleConfig, bundle };
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ var preserveDirectives = require('rollup-preserve-directives');
|
|
|
18
18
|
var MagicString = require('magic-string');
|
|
19
19
|
var CleanCSS = require('clean-css');
|
|
20
20
|
var pluginutils = require('@rollup/pluginutils');
|
|
21
|
+
var child_process = require('child_process');
|
|
21
22
|
|
|
22
23
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
24
|
|
|
@@ -445,7 +446,7 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
|
|
|
445
446
|
];
|
|
446
447
|
addToExportDistMap(exportToDist, currentPath, [
|
|
447
448
|
outputConditionPair
|
|
448
|
-
]
|
|
449
|
+
]);
|
|
449
450
|
} else {
|
|
450
451
|
exportInfo.push([
|
|
451
452
|
exportValue,
|
|
@@ -472,9 +473,8 @@ function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exp
|
|
|
472
473
|
}
|
|
473
474
|
}
|
|
474
475
|
const mapExportFullPath = (exportPath)=>exportPath === '.' ? './index' : exportPath;
|
|
475
|
-
function addToExportDistMap(exportToDist, exportPath, outputConditionPairs
|
|
476
|
+
function addToExportDistMap(exportToDist, exportPath, outputConditionPairs) {
|
|
476
477
|
const fullPath = mapExportFullPath(exportPath);
|
|
477
|
-
// + (specialExportType ? '.' + specialExportType : '')
|
|
478
478
|
const existingExportInfo = exportToDist.get(fullPath);
|
|
479
479
|
if (!existingExportInfo) {
|
|
480
480
|
exportToDist.set(fullPath, outputConditionPairs);
|
|
@@ -679,6 +679,7 @@ async function collectEntriesFromParsedExports(cwd, parsedExportsInfo, pkg, sour
|
|
|
679
679
|
continue;
|
|
680
680
|
}
|
|
681
681
|
if (!entries[entryExportPath]) {
|
|
682
|
+
// Create a new entry
|
|
682
683
|
entries[entryExportPath] = {
|
|
683
684
|
source: sourceFile,
|
|
684
685
|
name: normalizedExportPath,
|
|
@@ -896,7 +897,6 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
|
|
|
896
897
|
const sourceFileAbsolutePath = path__default.default.join(sourceFolderPath, file);
|
|
897
898
|
const exportPath = sourceFilenameToExportFullPath(file);
|
|
898
899
|
const isEsmPkg = isESModulePackage(pkg.type);
|
|
899
|
-
// const specialItems: [string, string][] = []
|
|
900
900
|
const specialExportType = getSpecialExportTypeFromSourcePath(file);
|
|
901
901
|
const normalizedExportPath = stripSpecialCondition(exportPath);
|
|
902
902
|
const isSpecialExport = specialExportType !== 'default';
|
|
@@ -1222,17 +1222,7 @@ function __insertCSS(code) {
|
|
|
1222
1222
|
create (code) {
|
|
1223
1223
|
return `__insertCSS(${JSON.stringify(code)});`;
|
|
1224
1224
|
}
|
|
1225
|
-
}
|
|
1226
|
-
cssAssertionImport: {
|
|
1227
|
-
global: '',
|
|
1228
|
-
create (code) {
|
|
1229
|
-
return `\
|
|
1230
|
-
const sheet = new CSSStyleSheet()
|
|
1231
|
-
sheet.replaceSync(${JSON.stringify(code)})
|
|
1232
|
-
export default sheet`;
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
};
|
|
1225
|
+
}};
|
|
1236
1226
|
const cleanCssInstance = new CleanCSS__default.default({});
|
|
1237
1227
|
function minify(code) {
|
|
1238
1228
|
return cleanCssInstance.minify(code).styles;
|
|
@@ -1308,7 +1298,7 @@ function hasNoSpecialCondition(conditionNames) {
|
|
|
1308
1298
|
...conditionNames
|
|
1309
1299
|
].every((name)=>!specialExportConventions.has(name));
|
|
1310
1300
|
}
|
|
1311
|
-
function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specialCondition) {
|
|
1301
|
+
function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specialCondition, isESMPkg) {
|
|
1312
1302
|
const hasBundle = bundlePath != null;
|
|
1313
1303
|
const formatCond = format === 'cjs' ? 'require' : 'import';
|
|
1314
1304
|
const isTypesCondName = conditionNames.has('types');
|
|
@@ -1316,9 +1306,14 @@ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specia
|
|
|
1316
1306
|
// Check if the format condition is matched:
|
|
1317
1307
|
// if there's condition existed, check if the format condition is matched;
|
|
1318
1308
|
// if there's no condition, just return true, assuming format doesn't matter;
|
|
1309
|
+
const bundleFormat = bundlePath.endsWith('.mjs') ? 'esm' : bundlePath.endsWith('.cjs') ? 'cjs' : isESMPkg ? 'esm' : 'cjs';
|
|
1310
|
+
// If there's only default condition, and the format is matched
|
|
1311
|
+
const isDefaultOnlyCondition = conditionNames.size === 1 && conditionNames.has('default') ? bundleFormat === format : true;
|
|
1319
1312
|
const isMatchedFormat = hasFormatCond ? conditionNames.has(formatCond) : true;
|
|
1320
|
-
const isMatchedConditionWithFormat =
|
|
1321
|
-
|
|
1313
|
+
const isMatchedConditionWithFormat = // Has matched special condition
|
|
1314
|
+
specialCondition !== 'default' && conditionNames.has(specialCondition) || // Match normal condition
|
|
1315
|
+
hasNoSpecialCondition(conditionNames);
|
|
1316
|
+
const match = isMatchedConditionWithFormat && !isTypesCondName && hasBundle && isMatchedFormat && isDefaultOnlyCondition;
|
|
1322
1317
|
if (!match) {
|
|
1323
1318
|
const fallback = runtimeExportConventionsFallback.get(specialCondition);
|
|
1324
1319
|
if (!fallback) {
|
|
@@ -1328,7 +1323,7 @@ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specia
|
|
|
1328
1323
|
// e.g. when import utils.js in index.js
|
|
1329
1324
|
// In output: index.browser.js should match util.browser.js, fallback to util.js
|
|
1330
1325
|
// The last guard condition is to ensure bundle condition but not types file.
|
|
1331
|
-
return isMatchedFormat && (conditionNames.has(specialCondition) || fallback.some((name)=>conditionNames.has(name)))
|
|
1326
|
+
return isMatchedFormat && !isTypesCondName && (specialCondition !== 'default' && conditionNames.has(specialCondition) || fallback.some((name)=>conditionNames.has(name)));
|
|
1332
1327
|
}
|
|
1333
1328
|
} else {
|
|
1334
1329
|
return match;
|
|
@@ -1341,22 +1336,27 @@ function findTypesFileCallback({ format, bundlePath, conditionNames }) {
|
|
|
1341
1336
|
return isTypesCondName && hasCondition && (formatCond ? conditionNames.has(formatCond) : true);
|
|
1342
1337
|
}
|
|
1343
1338
|
// Alias entry key to dist bundle path
|
|
1344
|
-
function aliasEntries({ entry: sourceFilePath,
|
|
1339
|
+
function aliasEntries({ entry: sourceFilePath, exportCondition, entries, isESMPkg, format, dts, cwd }) {
|
|
1340
|
+
const currentConditionNames = new Set(Object.keys(exportCondition.export)[0].split('.'));
|
|
1345
1341
|
// <imported source file path>: <relative path to source's bundle>
|
|
1346
1342
|
const sourceToRelativeBundleMap = new Map();
|
|
1347
|
-
|
|
1343
|
+
let specialCondition = getSpecialExportTypeFromConditionNames(currentConditionNames);
|
|
1348
1344
|
for (const [, exportCondition] of Object.entries(entries)){
|
|
1349
1345
|
const exportDistMaps = exportCondition.export;
|
|
1350
|
-
const exportMapEntries = Object.entries(exportDistMaps).map(([composedKey, bundlePath])=>
|
|
1351
|
-
|
|
1346
|
+
const exportMapEntries = Object.entries(exportDistMaps).map(([composedKey, bundlePath])=>{
|
|
1347
|
+
const conditionNames = new Set(composedKey.split('.'));
|
|
1348
|
+
return {
|
|
1349
|
+
conditionNames,
|
|
1352
1350
|
bundlePath,
|
|
1353
|
-
format
|
|
1354
|
-
|
|
1351
|
+
format,
|
|
1352
|
+
isDefaultCondition: conditionNames.size === 1 && conditionNames.has('default')
|
|
1353
|
+
};
|
|
1354
|
+
});
|
|
1355
1355
|
let matchedBundlePath;
|
|
1356
1356
|
if (dts) {
|
|
1357
1357
|
var _exportMapEntries_find;
|
|
1358
1358
|
// Find the type with format condition first
|
|
1359
|
-
matchedBundlePath = (_exportMapEntries_find = exportMapEntries.find(findTypesFileCallback)) == null ?
|
|
1359
|
+
matchedBundlePath = (_exportMapEntries_find = exportMapEntries.find(findTypesFileCallback)) == null ? void 0 : _exportMapEntries_find.bundlePath;
|
|
1360
1360
|
// If theres no format specific types such as import.types or require.types,
|
|
1361
1361
|
// fallback to the general types file.
|
|
1362
1362
|
if (!matchedBundlePath) {
|
|
@@ -1366,13 +1366,13 @@ function aliasEntries({ entry: sourceFilePath, conditionNames, entries, format,
|
|
|
1366
1366
|
...item,
|
|
1367
1367
|
format: undefined
|
|
1368
1368
|
});
|
|
1369
|
-
})) == null ?
|
|
1369
|
+
})) == null ? void 0 : _exportMapEntries_find1.bundlePath;
|
|
1370
1370
|
}
|
|
1371
1371
|
} else {
|
|
1372
1372
|
var _exportMapEntries_find2;
|
|
1373
1373
|
matchedBundlePath = (_exportMapEntries_find2 = exportMapEntries.find((item)=>{
|
|
1374
|
-
return findJsBundlePathCallback(item, specialCondition);
|
|
1375
|
-
})) == null ?
|
|
1374
|
+
return findJsBundlePathCallback(item, specialCondition, isESMPkg);
|
|
1375
|
+
})) == null ? void 0 : _exportMapEntries_find2.bundlePath;
|
|
1376
1376
|
}
|
|
1377
1377
|
if (matchedBundlePath) {
|
|
1378
1378
|
if (!sourceToRelativeBundleMap.has(exportCondition.source)) sourceToRelativeBundleMap.set(exportCondition.source, matchedBundlePath);
|
|
@@ -1435,11 +1435,11 @@ const swcMinifyOptions = {
|
|
|
1435
1435
|
}
|
|
1436
1436
|
};
|
|
1437
1437
|
async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal, cwd) {
|
|
1438
|
-
const enableIncrementalWithoutBuildInfo = tsCompilerOptions.incremental && !tsCompilerOptions.tsBuildInfoFile;
|
|
1438
|
+
const enableIncrementalWithoutBuildInfo = (tsCompilerOptions == null ? void 0 : tsCompilerOptions.incremental) && !(tsCompilerOptions == null ? void 0 : tsCompilerOptions.tsBuildInfoFile);
|
|
1439
1439
|
const incrementalOptions = enableIncrementalWithoutBuildInfo ? {
|
|
1440
1440
|
incremental: false
|
|
1441
1441
|
} : undefined;
|
|
1442
|
-
const compositeOptions = tsCompilerOptions.composite ? {
|
|
1442
|
+
const compositeOptions = (tsCompilerOptions == null ? void 0 : tsCompilerOptions.composite) ? {
|
|
1443
1443
|
composite: false
|
|
1444
1444
|
} : undefined;
|
|
1445
1445
|
const { options: overrideResolvedTsOptions } = await convertCompilerOptions(cwd, {
|
|
@@ -1454,7 +1454,7 @@ async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal,
|
|
|
1454
1454
|
// resolving types from <reference> from node_modules
|
|
1455
1455
|
preserveSymlinks: false,
|
|
1456
1456
|
target: 'ESNext',
|
|
1457
|
-
...!tsCompilerOptions.jsx ? {
|
|
1457
|
+
...!(tsCompilerOptions == null ? void 0 : tsCompilerOptions.jsx) ? {
|
|
1458
1458
|
jsx: 'react-jsx'
|
|
1459
1459
|
} : undefined,
|
|
1460
1460
|
// error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single
|
|
@@ -1492,7 +1492,7 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1492
1492
|
const inlineDefinedValues = getDefinedInlineVariables(bundleConfig.env || [], exportCondition);
|
|
1493
1493
|
const { useTypeScript } = buildContext;
|
|
1494
1494
|
const { runtime, target: jscTarget, minify: shouldMinify } = bundleConfig;
|
|
1495
|
-
const hasSpecifiedTsTarget = Boolean(tsCompilerOptions.target && tsConfigPath);
|
|
1495
|
+
const hasSpecifiedTsTarget = Boolean((tsCompilerOptions == null ? void 0 : tsCompilerOptions.target) && tsConfigPath);
|
|
1496
1496
|
const swcParserConfig = {
|
|
1497
1497
|
syntax: useTypeScript ? 'typescript' : 'ecmascript',
|
|
1498
1498
|
[useTypeScript ? 'tsx' : 'jsx']: true,
|
|
@@ -1531,13 +1531,13 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1531
1531
|
const sizePlugin = pluginContext.outputState.plugin(cwd);
|
|
1532
1532
|
// common plugins for both dts and ts assets that need to be processed
|
|
1533
1533
|
// If it's a .d.ts file under non-ESM package or .d.cts file, use cjs types alias.
|
|
1534
|
-
const aliasFormat = dts ? ((_bundleConfig_file = bundleConfig.file) == null ?
|
|
1535
|
-
const currentConditionNames = Object.keys(exportCondition.export)[0];
|
|
1534
|
+
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;
|
|
1536
1535
|
const aliasPlugin = aliasEntries({
|
|
1537
1536
|
entry,
|
|
1538
1537
|
entries,
|
|
1539
1538
|
format: aliasFormat,
|
|
1540
|
-
|
|
1539
|
+
isESMPkg: isESModulePackage(pkg.type),
|
|
1540
|
+
exportCondition,
|
|
1541
1541
|
dts,
|
|
1542
1542
|
cwd
|
|
1543
1543
|
});
|
|
@@ -1620,12 +1620,21 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1620
1620
|
};
|
|
1621
1621
|
}
|
|
1622
1622
|
|
|
1623
|
+
const hashTo3Char = memoize((input)=>{
|
|
1624
|
+
let hash = 0;
|
|
1625
|
+
for(let i = 0; i < input.length; i++){
|
|
1626
|
+
hash = (hash << 5) - hash + input.charCodeAt(i) // Simple hash shift
|
|
1627
|
+
;
|
|
1628
|
+
}
|
|
1629
|
+
return (hash >>> 0).toString(36).slice(0, 3) // Base36 + trim to 3 chars
|
|
1630
|
+
;
|
|
1631
|
+
});
|
|
1623
1632
|
function getModuleLayer(moduleMeta) {
|
|
1624
1633
|
const directives = (moduleMeta.preserveDirectives || {
|
|
1625
1634
|
directives: []
|
|
1626
1635
|
}).directives.map((d)=>d.replace(/^use /, '')).filter((d)=>d !== 'strict');
|
|
1627
1636
|
const moduleLayer = directives[0];
|
|
1628
|
-
return moduleLayer;
|
|
1637
|
+
return moduleLayer ? hashTo3Char(moduleLayer) : undefined;
|
|
1629
1638
|
}
|
|
1630
1639
|
// dependencyGraphMap: Map<subModuleId, Set<entryParentId>>
|
|
1631
1640
|
function createSplitChunks(dependencyGraphMap, entryFiles) {
|
|
@@ -1684,7 +1693,8 @@ function createSplitChunks(dependencyGraphMap, entryFiles) {
|
|
|
1684
1693
|
return;
|
|
1685
1694
|
}
|
|
1686
1695
|
const chunkName = path__default.default.basename(id, path__default.default.extname(id));
|
|
1687
|
-
const
|
|
1696
|
+
const layerSuffix = hashTo3Char(moduleLayer);
|
|
1697
|
+
const chunkGroup = `${chunkName}-${layerSuffix}`;
|
|
1688
1698
|
splitChunksGroupMap.set(id, chunkGroup);
|
|
1689
1699
|
return chunkGroup;
|
|
1690
1700
|
}
|
|
@@ -1697,7 +1707,7 @@ async function buildOutputConfigs(bundleConfig, exportCondition, buildContext, d
|
|
|
1697
1707
|
const { format } = bundleConfig;
|
|
1698
1708
|
const { entries, pkg, cwd, tsOptions: { tsCompilerOptions }, pluginContext } = buildContext;
|
|
1699
1709
|
// Add esm mark and interop helper if esm export is detected
|
|
1700
|
-
const useEsModuleMark = tsCompilerOptions == null ?
|
|
1710
|
+
const useEsModuleMark = tsCompilerOptions == null ? void 0 : tsCompilerOptions.esModuleInterop;
|
|
1701
1711
|
const absoluteOutputFile = path.resolve(cwd, bundleConfig.file);
|
|
1702
1712
|
const isEsmPkg = isESModulePackage(pkg.type);
|
|
1703
1713
|
const name = filePathWithoutExtension(absoluteOutputFile);
|
|
@@ -1907,7 +1917,7 @@ function hasMultiEntryExport(exportPaths) {
|
|
|
1907
1917
|
const exportKeys = Object.keys(exportPaths).filter((key)=>key !== './package.json');
|
|
1908
1918
|
return exportKeys.length > 0 && exportKeys.every((name)=>name.startsWith('.'));
|
|
1909
1919
|
}
|
|
1910
|
-
async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
1920
|
+
async function bundle(cliEntryPath, { cwd: _cwd, onSuccess, ...options } = {}) {
|
|
1911
1921
|
var _options__callbacks_onBuildStart, _options__callbacks;
|
|
1912
1922
|
const cwd = path.resolve(process.cwd(), _cwd || '');
|
|
1913
1923
|
assignDefault(options, 'format', 'esm');
|
|
@@ -1922,10 +1932,10 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1922
1932
|
const isFromCli = Boolean(cliEntryPath);
|
|
1923
1933
|
const tsConfigPath = resolveTsConfigPath(cwd, options.tsconfig);
|
|
1924
1934
|
let tsConfig = resolveTsConfig(cwd, tsConfigPath);
|
|
1925
|
-
let hasTsConfig = Boolean(tsConfig == null ?
|
|
1935
|
+
let hasTsConfig = Boolean(tsConfig == null ? void 0 : tsConfig.tsConfigPath);
|
|
1926
1936
|
const defaultTsOptions = {
|
|
1927
|
-
tsConfigPath: tsConfig == null ?
|
|
1928
|
-
tsCompilerOptions:
|
|
1937
|
+
tsConfigPath: tsConfig == null ? void 0 : tsConfig.tsConfigPath,
|
|
1938
|
+
tsCompilerOptions: tsConfig == null ? void 0 : tsConfig.tsCompilerOptions
|
|
1929
1939
|
};
|
|
1930
1940
|
// Handle single entry file
|
|
1931
1941
|
if (!isMultiEntries) {
|
|
@@ -2006,7 +2016,7 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
2006
2016
|
moduleDirectiveLayerMap: new Map()
|
|
2007
2017
|
}
|
|
2008
2018
|
};
|
|
2009
|
-
(_options__callbacks = options._callbacks) == null ?
|
|
2019
|
+
(_options__callbacks = options._callbacks) == null ? void 0 : (_options__callbacks_onBuildStart = _options__callbacks.onBuildStart) == null ? void 0 : _options__callbacks_onBuildStart.call(_options__callbacks, buildContext);
|
|
2010
2020
|
const generateTypes = hasTsConfig && options.dts !== false;
|
|
2011
2021
|
const rollupJobsOptions = {
|
|
2012
2022
|
isFromCli,
|
|
@@ -2016,9 +2026,26 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
2016
2026
|
var _options__callbacks_onBuildEnd, _options__callbacks1;
|
|
2017
2027
|
const assetJobs = await createAssetRollupJobs(options, buildContext, rollupJobsOptions);
|
|
2018
2028
|
(_options__callbacks1 = options._callbacks) == null ? void 0 : (_options__callbacks_onBuildEnd = _options__callbacks1.onBuildEnd) == null ? void 0 : _options__callbacks_onBuildEnd.call(_options__callbacks1, assetJobs);
|
|
2029
|
+
// Finished building successfully
|
|
2030
|
+
if (onSuccess) {
|
|
2031
|
+
if (typeof onSuccess === 'string') {
|
|
2032
|
+
const successProg = child_process.spawn(onSuccess, {
|
|
2033
|
+
shell: true,
|
|
2034
|
+
stdio: 'inherit',
|
|
2035
|
+
cwd
|
|
2036
|
+
});
|
|
2037
|
+
successProg.on('exit', (code)=>{
|
|
2038
|
+
if (code) {
|
|
2039
|
+
process.exitCode = code;
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
} else {
|
|
2043
|
+
await onSuccess();
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2019
2046
|
} catch (error) {
|
|
2020
2047
|
var _options__callbacks_onBuildError, _options__callbacks2;
|
|
2021
|
-
(_options__callbacks2 = options._callbacks) == null ?
|
|
2048
|
+
(_options__callbacks2 = options._callbacks) == null ? void 0 : (_options__callbacks_onBuildError = _options__callbacks2.onBuildError) == null ? void 0 : _options__callbacks_onBuildError.call(_options__callbacks2, error);
|
|
2022
2049
|
return Promise.reject(error);
|
|
2023
2050
|
}
|
|
2024
2051
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.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,16 +42,16 @@
|
|
|
42
42
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
43
43
|
"@rollup/plugin-replace": "^6.0.2",
|
|
44
44
|
"@rollup/plugin-wasm": "^6.2.2",
|
|
45
|
-
"@rollup/pluginutils": "^5.1.
|
|
46
|
-
"@swc/core": "^1.10.
|
|
47
|
-
"@swc/helpers": "^0.5.
|
|
45
|
+
"@rollup/pluginutils": "^5.1.4",
|
|
46
|
+
"@swc/core": "^1.10.16",
|
|
47
|
+
"@swc/helpers": "^0.5.15",
|
|
48
48
|
"clean-css": "^5.3.3",
|
|
49
49
|
"fast-glob": "^3.3.3",
|
|
50
50
|
"magic-string": "^0.30.17",
|
|
51
51
|
"ora": "^8.0.1",
|
|
52
52
|
"picomatch": "^4.0.2",
|
|
53
53
|
"pretty-bytes": "^5.6.0",
|
|
54
|
-
"rollup": "^4.
|
|
54
|
+
"rollup": "^4.34.7",
|
|
55
55
|
"rollup-plugin-dts": "^6.1.1",
|
|
56
56
|
"rollup-plugin-swc3": "^0.11.1",
|
|
57
57
|
"rollup-preserve-directives": "^1.1.3",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@types/clean-css": "^4.2.11",
|
|
77
77
|
"@types/node": "^22.9.3",
|
|
78
78
|
"@types/picomatch": "^3.0.1",
|
|
79
|
-
"@types/react": "19.0.
|
|
79
|
+
"@types/react": "^19.0.9",
|
|
80
80
|
"@types/yargs": "^17.0.33",
|
|
81
81
|
"bunchee": "link:./",
|
|
82
82
|
"cross-env": "^7.0.3",
|