bunchee 5.5.1 → 5.6.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 +14 -0
- package/dist/bin/cli.js +95 -61
- package/dist/index.d.ts +2 -0
- package/dist/index.js +14 -3
- 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.0";
|
|
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
|
@@ -1316,7 +1316,7 @@ async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal,
|
|
|
1316
1316
|
const memoizeDtsPluginByKey = memoizeByKey(createDtsPlugin);
|
|
1317
1317
|
async function buildInputConfig(entry, bundleConfig, exportCondition, buildContext, dts) {
|
|
1318
1318
|
var _bundleConfig_file, _bundleConfig_file1;
|
|
1319
|
-
const { entries, pkg, cwd, tsOptions: { tsConfigPath, tsCompilerOptions }, pluginContext } = buildContext;
|
|
1319
|
+
const { entries, pkg, cwd, tsOptions: { tsConfigPath, tsCompilerOptions }, browserslistConfig, pluginContext } = buildContext;
|
|
1320
1320
|
const isBinEntry = isBinExportPath(exportCondition.name);
|
|
1321
1321
|
const hasNoExternal = bundleConfig.external === null;
|
|
1322
1322
|
var _bundleConfig_external;
|
|
@@ -1342,9 +1342,10 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1342
1342
|
exportDefaultFrom: true,
|
|
1343
1343
|
decorators: true
|
|
1344
1344
|
};
|
|
1345
|
+
const hasBrowserslistConfig = !!(browserslistConfig && !hasSpecifiedTsTarget);
|
|
1345
1346
|
const swcOptions = {
|
|
1346
1347
|
jsc: {
|
|
1347
|
-
...!hasSpecifiedTsTarget && {
|
|
1348
|
+
...!hasSpecifiedTsTarget && !hasBrowserslistConfig && {
|
|
1348
1349
|
target: jscTarget
|
|
1349
1350
|
},
|
|
1350
1351
|
loose: true,
|
|
@@ -1362,7 +1363,12 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1362
1363
|
},
|
|
1363
1364
|
sourceMaps: bundleConfig.sourcemap,
|
|
1364
1365
|
inlineSourcesContent: false,
|
|
1365
|
-
isModule: true
|
|
1366
|
+
isModule: true,
|
|
1367
|
+
...hasBrowserslistConfig && {
|
|
1368
|
+
env: {
|
|
1369
|
+
targets: browserslistConfig
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1366
1372
|
};
|
|
1367
1373
|
const sizePlugin = pluginContext.outputState.plugin(cwd);
|
|
1368
1374
|
// common plugins for both dts and ts assets that need to be processed
|
|
@@ -1823,6 +1829,10 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1823
1829
|
await writeDefaultTsconfig(tsConfigPath);
|
|
1824
1830
|
hasTsConfig = true;
|
|
1825
1831
|
}
|
|
1832
|
+
let browserslistConfig;
|
|
1833
|
+
if (options.runtime === 'browser') {
|
|
1834
|
+
browserslistConfig = pkg.browserslist;
|
|
1835
|
+
}
|
|
1826
1836
|
const outputState = createOutputState({
|
|
1827
1837
|
entries
|
|
1828
1838
|
});
|
|
@@ -1832,6 +1842,7 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1832
1842
|
cwd,
|
|
1833
1843
|
tsOptions: defaultTsOptions,
|
|
1834
1844
|
useTypeScript: hasTsConfig,
|
|
1845
|
+
browserslistConfig,
|
|
1835
1846
|
pluginContext: {
|
|
1836
1847
|
outputState,
|
|
1837
1848
|
moduleDirectiveLayerMap: new Map()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.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",
|
|
@@ -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",
|