bunchee 5.5.1 → 5.6.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 +14 -0
- package/dist/bin/cli.js +95 -61
- package/dist/index.d.ts +2 -0
- package/dist/index.js +86 -4
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -470,6 +470,20 @@ Bunchee offers a convenient watch mode for rebuilding your library whenever chan
|
|
|
470
470
|
#### `target`
|
|
471
471
|
|
|
472
472
|
If you specify `target` option in `tsconfig.json`, then you don't have to pass it again through CLI.
|
|
473
|
+
To target a range of browsers, you can use the `browserslist` field in `package.json`, bunchee will use it to determine the target browsers for the output bundle.
|
|
474
|
+
|
|
475
|
+
For example:
|
|
476
|
+
|
|
477
|
+
```json
|
|
478
|
+
{
|
|
479
|
+
"browserslist": [
|
|
480
|
+
"last 1 version",
|
|
481
|
+
"> 1%",
|
|
482
|
+
"maintained node versions",
|
|
483
|
+
"not dead"
|
|
484
|
+
]
|
|
485
|
+
}
|
|
486
|
+
```
|
|
473
487
|
|
|
474
488
|
#### Package lint
|
|
475
489
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var path = require('path');
|
|
3
|
-
var
|
|
3
|
+
var yargs = require('yargs');
|
|
4
|
+
var helpers = require('yargs/helpers');
|
|
4
5
|
var perf_hooks = require('perf_hooks');
|
|
5
6
|
var fs = require('fs');
|
|
6
7
|
var fsp = require('fs/promises');
|
|
@@ -12,7 +13,7 @@ var prettyBytes = require('pretty-bytes');
|
|
|
12
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
|
|
14
15
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
15
|
-
var
|
|
16
|
+
var yargs__default = /*#__PURE__*/_interopDefault(yargs);
|
|
16
17
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
17
18
|
var fsp__default = /*#__PURE__*/_interopDefault(fsp);
|
|
18
19
|
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
|
@@ -524,7 +525,7 @@ function lint$1(pkg) {
|
|
|
524
525
|
}
|
|
525
526
|
}
|
|
526
527
|
|
|
527
|
-
var version = "5.
|
|
528
|
+
var version = "5.6.1";
|
|
528
529
|
|
|
529
530
|
function relativify(path) {
|
|
530
531
|
return path.startsWith('.') ? path : `./${path}`;
|
|
@@ -984,57 +985,90 @@ async function lint(cwd) {
|
|
|
984
985
|
}
|
|
985
986
|
await lint$1(await getPackageMeta(cwd));
|
|
986
987
|
}
|
|
987
|
-
function parseCliArgs(argv) {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
'
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
'
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
'
|
|
1001
|
-
|
|
1002
|
-
'
|
|
1003
|
-
'
|
|
1004
|
-
'
|
|
1005
|
-
|
|
1006
|
-
'
|
|
1007
|
-
'
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
}, {
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
988
|
+
async function parseCliArgs(argv) {
|
|
989
|
+
const args = await yargs__default.default(helpers.hideBin(argv)).option('cwd', {
|
|
990
|
+
type: 'string',
|
|
991
|
+
description: 'specify current working directory'
|
|
992
|
+
}).option('dts', {
|
|
993
|
+
coerce (arg) {
|
|
994
|
+
return arg === false ? false : undefined;
|
|
995
|
+
},
|
|
996
|
+
description: 'do not generate types'
|
|
997
|
+
}).option('clean', {
|
|
998
|
+
coerce (arg) {
|
|
999
|
+
return arg === false ? false : undefined;
|
|
1000
|
+
},
|
|
1001
|
+
description: 'do not clean dist folder before building'
|
|
1002
|
+
}).option('output', {
|
|
1003
|
+
type: 'string',
|
|
1004
|
+
alias: 'o',
|
|
1005
|
+
description: 'specify output filename'
|
|
1006
|
+
}).option('format', {
|
|
1007
|
+
type: 'string',
|
|
1008
|
+
alias: 'f',
|
|
1009
|
+
default: 'esm',
|
|
1010
|
+
description: 'type of output (esm, amd, cjs, iife, umd, system)'
|
|
1011
|
+
}).option('watch', {
|
|
1012
|
+
type: 'boolean',
|
|
1013
|
+
alias: 'w',
|
|
1014
|
+
description: 'watch src files changes'
|
|
1015
|
+
}).option('minify', {
|
|
1016
|
+
type: 'boolean',
|
|
1017
|
+
alias: 'm',
|
|
1018
|
+
description: 'compress output'
|
|
1019
|
+
}).option('help', {
|
|
1020
|
+
type: 'boolean',
|
|
1021
|
+
alias: 'h',
|
|
1022
|
+
description: 'output usage information'
|
|
1023
|
+
}).option('runtime', {
|
|
1024
|
+
type: 'string',
|
|
1025
|
+
default: 'browser',
|
|
1026
|
+
description: 'build runtime (nodejs, browser)'
|
|
1027
|
+
}).option('target', {
|
|
1028
|
+
type: 'string',
|
|
1029
|
+
description: 'js features target: swc target es versions'
|
|
1030
|
+
}).option('sourcemap', {
|
|
1031
|
+
type: 'boolean',
|
|
1032
|
+
default: false,
|
|
1033
|
+
description: 'enable sourcemap generation'
|
|
1034
|
+
}).option('env', {
|
|
1035
|
+
type: 'string',
|
|
1036
|
+
description: 'inlined process env variables, separate by comma'
|
|
1037
|
+
}).option('external', {
|
|
1038
|
+
coerce (arg) {
|
|
1039
|
+
return typeof arg === 'string' || typeof arg === 'boolean' ? arg : undefined;
|
|
1040
|
+
},
|
|
1041
|
+
description: 'specify an external dependency, separate by comma'
|
|
1042
|
+
}).option('prepare', {
|
|
1043
|
+
type: 'boolean',
|
|
1044
|
+
description: 'auto configure package.json exports for building'
|
|
1045
|
+
}).option('tsconfig', {
|
|
1046
|
+
type: 'string',
|
|
1047
|
+
description: 'path to tsconfig file'
|
|
1048
|
+
}).option('dts-bundle', {
|
|
1049
|
+
type: 'boolean',
|
|
1050
|
+
description: 'bundle type declaration files'
|
|
1051
|
+
}).version(version).help('help', 'output usage information').showHelpOnFail(true).parse();
|
|
1018
1052
|
const source = args._[0];
|
|
1019
1053
|
const parsedArgs = {
|
|
1020
1054
|
source,
|
|
1021
|
-
format: args['
|
|
1022
|
-
file: args['
|
|
1023
|
-
watch: args['
|
|
1024
|
-
minify: args['
|
|
1025
|
-
sourcemap: !!args['
|
|
1026
|
-
cwd: args['
|
|
1027
|
-
dts: args['
|
|
1028
|
-
dtsBundle: args['
|
|
1029
|
-
help: args['
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
external:
|
|
1034
|
-
clean:
|
|
1035
|
-
env: args['
|
|
1036
|
-
prepare: !!args['
|
|
1037
|
-
tsconfig: args['
|
|
1055
|
+
format: args['format'],
|
|
1056
|
+
file: args['output'],
|
|
1057
|
+
watch: args['watch'],
|
|
1058
|
+
minify: args['minify'],
|
|
1059
|
+
sourcemap: !!args['sourcemap'],
|
|
1060
|
+
cwd: args['cwd'],
|
|
1061
|
+
dts: args['dts'] === false ? false : undefined,
|
|
1062
|
+
dtsBundle: args['dts-bundle'],
|
|
1063
|
+
help: args['help'],
|
|
1064
|
+
runtime: args['runtime'],
|
|
1065
|
+
target: args['target'],
|
|
1066
|
+
// no-external is a boolean flag, turning external to `false`
|
|
1067
|
+
external: args['external'] === false ? null : args['external'],
|
|
1068
|
+
clean: args['clean'] !== false,
|
|
1069
|
+
env: args['env'],
|
|
1070
|
+
prepare: !!args['prepare'],
|
|
1071
|
+
tsconfig: args['tsconfig']
|
|
1038
1072
|
};
|
|
1039
1073
|
return parsedArgs;
|
|
1040
1074
|
}
|
|
@@ -1060,12 +1094,6 @@ async function run(args) {
|
|
|
1060
1094
|
clean,
|
|
1061
1095
|
tsconfig
|
|
1062
1096
|
};
|
|
1063
|
-
if (args.version) {
|
|
1064
|
-
return logger.log(version);
|
|
1065
|
-
}
|
|
1066
|
-
if (args.help) {
|
|
1067
|
-
return help();
|
|
1068
|
-
}
|
|
1069
1097
|
if (args.prepare) {
|
|
1070
1098
|
return await prepare(cwd);
|
|
1071
1099
|
}
|
|
@@ -1073,10 +1101,16 @@ async function run(args) {
|
|
|
1073
1101
|
// lint package
|
|
1074
1102
|
await lint(cwd);
|
|
1075
1103
|
const { default: ora } = await import('ora');
|
|
1076
|
-
const oraInstance = ora({
|
|
1104
|
+
const oraInstance = process.stdout.isTTY ? ora({
|
|
1077
1105
|
text: 'Building...\n\n',
|
|
1078
1106
|
color: 'green'
|
|
1079
|
-
})
|
|
1107
|
+
}) : {
|
|
1108
|
+
start: ()=>{},
|
|
1109
|
+
stop: ()=>{},
|
|
1110
|
+
clear: ()=>{},
|
|
1111
|
+
stopAndPersist: ()=>{},
|
|
1112
|
+
isSpinning: false
|
|
1113
|
+
};
|
|
1080
1114
|
const spinner = {
|
|
1081
1115
|
start: startSpinner,
|
|
1082
1116
|
stop: stopSpinner
|
|
@@ -1156,12 +1190,12 @@ async function run(args) {
|
|
|
1156
1190
|
async function main() {
|
|
1157
1191
|
let params, error;
|
|
1158
1192
|
try {
|
|
1159
|
-
params = parseCliArgs(process.argv
|
|
1193
|
+
params = await parseCliArgs(process.argv);
|
|
1160
1194
|
} catch (err) {
|
|
1161
1195
|
error = err;
|
|
1162
1196
|
}
|
|
1163
1197
|
if (error || !params) {
|
|
1164
|
-
if (!error) help()
|
|
1198
|
+
// if (!error) help()
|
|
1165
1199
|
return exit(error);
|
|
1166
1200
|
}
|
|
1167
1201
|
await run(params);
|
package/dist/index.d.ts
CHANGED
|
@@ -38,7 +38,9 @@ type PackageMetadata = {
|
|
|
38
38
|
exports?: string | Record<string, ExportCondition>;
|
|
39
39
|
types?: string;
|
|
40
40
|
typings?: string;
|
|
41
|
+
browserslist?: BrowserslistConfig;
|
|
41
42
|
};
|
|
43
|
+
type BrowserslistConfig = string | string[] | Record<string, string>;
|
|
42
44
|
|
|
43
45
|
declare function bundle(cliEntryPath: string, { cwd: _cwd, ...options }?: BundleConfig): Promise<void>;
|
|
44
46
|
|
package/dist/index.js
CHANGED
|
@@ -142,6 +142,67 @@ const runtimeExportConventions = new Set([
|
|
|
142
142
|
// Browser only
|
|
143
143
|
'browser'
|
|
144
144
|
]);
|
|
145
|
+
const runtimeExportConventionsFallback = new Map([
|
|
146
|
+
// ESM only runtime
|
|
147
|
+
[
|
|
148
|
+
'workerd',
|
|
149
|
+
[
|
|
150
|
+
'import',
|
|
151
|
+
'default'
|
|
152
|
+
]
|
|
153
|
+
],
|
|
154
|
+
[
|
|
155
|
+
'edge-light',
|
|
156
|
+
[
|
|
157
|
+
'import',
|
|
158
|
+
'default'
|
|
159
|
+
]
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
'browser',
|
|
163
|
+
[
|
|
164
|
+
'import',
|
|
165
|
+
'default'
|
|
166
|
+
]
|
|
167
|
+
],
|
|
168
|
+
// it could be CJS or ESM
|
|
169
|
+
[
|
|
170
|
+
'electron',
|
|
171
|
+
[
|
|
172
|
+
'default'
|
|
173
|
+
]
|
|
174
|
+
],
|
|
175
|
+
[
|
|
176
|
+
'react-server',
|
|
177
|
+
[
|
|
178
|
+
'default'
|
|
179
|
+
]
|
|
180
|
+
],
|
|
181
|
+
[
|
|
182
|
+
'react-native',
|
|
183
|
+
[
|
|
184
|
+
'default'
|
|
185
|
+
]
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
'node',
|
|
189
|
+
[
|
|
190
|
+
'default'
|
|
191
|
+
]
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
'deno',
|
|
195
|
+
[
|
|
196
|
+
'default'
|
|
197
|
+
]
|
|
198
|
+
],
|
|
199
|
+
[
|
|
200
|
+
'bun',
|
|
201
|
+
[
|
|
202
|
+
'default'
|
|
203
|
+
]
|
|
204
|
+
]
|
|
205
|
+
]);
|
|
145
206
|
const optimizeConventions = new Set([
|
|
146
207
|
'development',
|
|
147
208
|
'production'
|
|
@@ -1153,7 +1214,17 @@ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specia
|
|
|
1153
1214
|
const hasFormatCond = conditionNames.has('import') || conditionNames.has('require');
|
|
1154
1215
|
const isMatchedFormat = hasFormatCond ? conditionNames.has(formatCond) : true;
|
|
1155
1216
|
const isMatchedConditionWithFormat = conditionNames.has(specialCondition) || !conditionNames.has('default') && hasNoSpecialCondition(conditionNames);
|
|
1156
|
-
|
|
1217
|
+
const match = isMatchedConditionWithFormat && !isTypesCondName && hasBundle && isMatchedFormat;
|
|
1218
|
+
if (!match) {
|
|
1219
|
+
const fallback = runtimeExportConventionsFallback.get(specialCondition);
|
|
1220
|
+
if (!fallback) {
|
|
1221
|
+
return false;
|
|
1222
|
+
} else {
|
|
1223
|
+
return fallback.some((name)=>conditionNames.has(name));
|
|
1224
|
+
}
|
|
1225
|
+
} else {
|
|
1226
|
+
return match;
|
|
1227
|
+
}
|
|
1157
1228
|
}
|
|
1158
1229
|
function findTypesFileCallback({ format, bundlePath, conditionNames }) {
|
|
1159
1230
|
const hasCondition = bundlePath != null;
|
|
@@ -1316,7 +1387,7 @@ async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal,
|
|
|
1316
1387
|
const memoizeDtsPluginByKey = memoizeByKey(createDtsPlugin);
|
|
1317
1388
|
async function buildInputConfig(entry, bundleConfig, exportCondition, buildContext, dts) {
|
|
1318
1389
|
var _bundleConfig_file, _bundleConfig_file1;
|
|
1319
|
-
const { entries, pkg, cwd, tsOptions: { tsConfigPath, tsCompilerOptions }, pluginContext } = buildContext;
|
|
1390
|
+
const { entries, pkg, cwd, tsOptions: { tsConfigPath, tsCompilerOptions }, browserslistConfig, pluginContext } = buildContext;
|
|
1320
1391
|
const isBinEntry = isBinExportPath(exportCondition.name);
|
|
1321
1392
|
const hasNoExternal = bundleConfig.external === null;
|
|
1322
1393
|
var _bundleConfig_external;
|
|
@@ -1342,9 +1413,10 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1342
1413
|
exportDefaultFrom: true,
|
|
1343
1414
|
decorators: true
|
|
1344
1415
|
};
|
|
1416
|
+
const hasBrowserslistConfig = !!(browserslistConfig && !hasSpecifiedTsTarget);
|
|
1345
1417
|
const swcOptions = {
|
|
1346
1418
|
jsc: {
|
|
1347
|
-
...!hasSpecifiedTsTarget && {
|
|
1419
|
+
...!hasSpecifiedTsTarget && !hasBrowserslistConfig && {
|
|
1348
1420
|
target: jscTarget
|
|
1349
1421
|
},
|
|
1350
1422
|
loose: true,
|
|
@@ -1362,7 +1434,12 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1362
1434
|
},
|
|
1363
1435
|
sourceMaps: bundleConfig.sourcemap,
|
|
1364
1436
|
inlineSourcesContent: false,
|
|
1365
|
-
isModule: true
|
|
1437
|
+
isModule: true,
|
|
1438
|
+
...hasBrowserslistConfig && {
|
|
1439
|
+
env: {
|
|
1440
|
+
targets: browserslistConfig
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1366
1443
|
};
|
|
1367
1444
|
const sizePlugin = pluginContext.outputState.plugin(cwd);
|
|
1368
1445
|
// common plugins for both dts and ts assets that need to be processed
|
|
@@ -1823,6 +1900,10 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1823
1900
|
await writeDefaultTsconfig(tsConfigPath);
|
|
1824
1901
|
hasTsConfig = true;
|
|
1825
1902
|
}
|
|
1903
|
+
let browserslistConfig;
|
|
1904
|
+
if (options.runtime === 'browser') {
|
|
1905
|
+
browserslistConfig = pkg.browserslist;
|
|
1906
|
+
}
|
|
1826
1907
|
const outputState = createOutputState({
|
|
1827
1908
|
entries
|
|
1828
1909
|
});
|
|
@@ -1832,6 +1913,7 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1832
1913
|
cwd,
|
|
1833
1914
|
tsOptions: defaultTsOptions,
|
|
1834
1915
|
useTypeScript: hasTsConfig,
|
|
1916
|
+
browserslistConfig,
|
|
1835
1917
|
pluginContext: {
|
|
1836
1918
|
outputState,
|
|
1837
1919
|
moduleDirectiveLayerMap: new Map()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.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",
|
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"@rollup/pluginutils": "^5.1.0",
|
|
45
45
|
"@swc/core": "^1.7.14",
|
|
46
46
|
"@swc/helpers": "^0.5.11",
|
|
47
|
-
"arg": "^5.0.2",
|
|
48
47
|
"clean-css": "^5.3.3",
|
|
49
48
|
"magic-string": "^0.30.11",
|
|
50
49
|
"ora": "^8.0.1",
|
|
@@ -53,7 +52,8 @@
|
|
|
53
52
|
"rollup-plugin-dts": "^6.1.1",
|
|
54
53
|
"rollup-plugin-swc3": "^0.11.1",
|
|
55
54
|
"rollup-preserve-directives": "^1.1.2",
|
|
56
|
-
"tslib": "^2.7.0"
|
|
55
|
+
"tslib": "^2.7.0",
|
|
56
|
+
"yargs": "^17.7.2"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"typescript": "^4.1 || ^5.0"
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"@types/clean-css": "^4.2.11",
|
|
75
75
|
"@types/jest": "29.0.0",
|
|
76
76
|
"@types/node": "^20.4.1",
|
|
77
|
+
"@types/yargs": "^17.0.33",
|
|
77
78
|
"bunchee": "link:./",
|
|
78
79
|
"cross-env": "^7.0.3",
|
|
79
80
|
"husky": "^9.0.11",
|