bunchee 5.0.0-beta.3 → 5.0.0-beta.5
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 +2 -0
- package/dist/bin/cli.js +8 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +88 -70
- package/package.json +20 -17
package/README.md
CHANGED
|
@@ -326,6 +326,7 @@ import { AppContext } from './app-context.shared-runtime'
|
|
|
326
326
|
- Minify (`-m`): Compress output.
|
|
327
327
|
- Watch (`-w`): Watch for source file changes.
|
|
328
328
|
- No Clean(`--no-clean`): Do not clean the dist folder before building. (default: `false`)
|
|
329
|
+
- TSConfig (`--tsconfig <path>`): Specify the path to the TypeScript configuration file. (default: `tsconfig.json`)
|
|
329
330
|
|
|
330
331
|
```sh
|
|
331
332
|
cd <project-root-dir>
|
|
@@ -458,6 +459,7 @@ await bundle(path.resolve('./src/index.ts'), {
|
|
|
458
459
|
runtime: 'nodejs', // 'browser' | 'nodejs'
|
|
459
460
|
cwd: process.cwd(), // string
|
|
460
461
|
clean: true, // boolean
|
|
462
|
+
tsconfig: 'tsconfig.json', // string
|
|
461
463
|
})
|
|
462
464
|
```
|
|
463
465
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -456,7 +456,7 @@ function lint$1(pkg) {
|
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
var version = "5.0.0-beta.
|
|
459
|
+
var version = "5.0.0-beta.5";
|
|
460
460
|
|
|
461
461
|
function relativify(path) {
|
|
462
462
|
return path.startsWith('.') ? path : `./${path}`;
|
|
@@ -799,6 +799,7 @@ Options:
|
|
|
799
799
|
--sourcemap enable sourcemap generation, default: false
|
|
800
800
|
--dts determine if need to generate types, default: undefined
|
|
801
801
|
--no-dts do not generate types, default: undefined
|
|
802
|
+
--tsconfig path to tsconfig file, default: tsconfig.json
|
|
802
803
|
`;
|
|
803
804
|
function help() {
|
|
804
805
|
logger.log(helpMessage);
|
|
@@ -830,6 +831,7 @@ function parseCliArgs(argv) {
|
|
|
830
831
|
'--no-external': Boolean,
|
|
831
832
|
'--no-clean': Boolean,
|
|
832
833
|
'--prepare': Boolean,
|
|
834
|
+
'--tsconfig': String,
|
|
833
835
|
'-h': '--help',
|
|
834
836
|
'-v': '--version',
|
|
835
837
|
'-w': '--watch',
|
|
@@ -857,13 +859,14 @@ function parseCliArgs(argv) {
|
|
|
857
859
|
external: !!args['--no-external'] ? null : args['--external'],
|
|
858
860
|
clean: !args['--no-clean'],
|
|
859
861
|
env: args['--env'],
|
|
860
|
-
prepare: !!args['--prepare']
|
|
862
|
+
prepare: !!args['--prepare'],
|
|
863
|
+
tsconfig: args['--tsconfig']
|
|
861
864
|
};
|
|
862
865
|
return parsedArgs;
|
|
863
866
|
}
|
|
864
867
|
async function run(args) {
|
|
865
868
|
var _args_external;
|
|
866
|
-
const { source, format, watch, minify, sourcemap, target, runtime, dts, env, clean } = args;
|
|
869
|
+
const { source, format, watch, minify, sourcemap, target, runtime, dts, env, clean, tsconfig } = args;
|
|
867
870
|
const cwd = args.cwd || process.cwd();
|
|
868
871
|
const file = args.file ? path__default.default.resolve(cwd, args.file) : undefined;
|
|
869
872
|
const bundleConfig = {
|
|
@@ -878,7 +881,8 @@ async function run(args) {
|
|
|
878
881
|
minify: !!minify,
|
|
879
882
|
sourcemap: sourcemap === false ? false : true,
|
|
880
883
|
env: (env == null ? void 0 : env.split(',')) || [],
|
|
881
|
-
clean
|
|
884
|
+
clean,
|
|
885
|
+
tsconfig
|
|
882
886
|
};
|
|
883
887
|
if (args.version) {
|
|
884
888
|
return logger.log(version);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
var rollup = require('rollup');
|
|
4
3
|
var fsp = require('fs/promises');
|
|
5
4
|
var fs = require('fs');
|
|
6
5
|
var path = require('path');
|
|
@@ -19,6 +18,7 @@ var MagicString = require('magic-string');
|
|
|
19
18
|
var CleanCSS = require('clean-css');
|
|
20
19
|
var pluginutils = require('@rollup/pluginutils');
|
|
21
20
|
var prettyBytes = require('pretty-bytes');
|
|
21
|
+
var rollup = require('rollup');
|
|
22
22
|
|
|
23
23
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
24
|
|
|
@@ -187,18 +187,6 @@ function isTypescriptFile(filename) {
|
|
|
187
187
|
function fileExists(filePath) {
|
|
188
188
|
return fs__default.default.existsSync(filePath);
|
|
189
189
|
}
|
|
190
|
-
async function removeDir(dirPath) {
|
|
191
|
-
try {
|
|
192
|
-
const dirStat = await fsp__default.default.stat(dirPath);
|
|
193
|
-
if (dirStat.isDirectory()) {
|
|
194
|
-
await rimraf.rimraf(dirPath);
|
|
195
|
-
}
|
|
196
|
-
} catch (err) {
|
|
197
|
-
if (err.code !== 'ENOENT') {
|
|
198
|
-
throw err;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
190
|
const isNotNull = (n)=>Boolean(n);
|
|
203
191
|
function resolveSourceFile(cwd, filename) {
|
|
204
192
|
return path__default.default.resolve(cwd, SRC, filename);
|
|
@@ -287,9 +275,29 @@ function joinRelativePath(...segments) {
|
|
|
287
275
|
function isESModulePackage(packageType) {
|
|
288
276
|
return packageType === 'module';
|
|
289
277
|
}
|
|
278
|
+
async function removeDir(dirPath) {
|
|
279
|
+
try {
|
|
280
|
+
const dirStat = await fsp__default.default.stat(dirPath);
|
|
281
|
+
if (dirStat.isDirectory()) {
|
|
282
|
+
await rimraf.rimraf(dirPath);
|
|
283
|
+
}
|
|
284
|
+
} catch (err) {
|
|
285
|
+
if (err.code !== 'ENOENT') {
|
|
286
|
+
throw err;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const removedDirs = new Set();
|
|
291
|
+
async function removeOutputDir(output, cwd) {
|
|
292
|
+
const dir = output.dir;
|
|
293
|
+
if (dir && dir !== cwd && !removedDirs.has(dir)) {
|
|
294
|
+
await removeDir(dir);
|
|
295
|
+
removedDirs.add(dir);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
290
298
|
|
|
291
299
|
let hasLoggedTsWarning = false;
|
|
292
|
-
function
|
|
300
|
+
function resolveTypescript(cwd) {
|
|
293
301
|
let ts;
|
|
294
302
|
const m = new module$1.Module('', undefined);
|
|
295
303
|
m.paths = module$1.Module._nodeModulePaths(cwd);
|
|
@@ -304,12 +312,12 @@ function resolveTypescriptHandler(cwd) {
|
|
|
304
312
|
}
|
|
305
313
|
return ts;
|
|
306
314
|
}
|
|
307
|
-
|
|
308
|
-
function resolveTsConfigHandler(cwd) {
|
|
315
|
+
function resolveTsConfigHandler(cwd, tsconfig = 'tsconfig.json') {
|
|
309
316
|
let tsCompilerOptions = {};
|
|
310
317
|
let tsConfigPath;
|
|
311
|
-
tsConfigPath = path.resolve(cwd,
|
|
318
|
+
tsConfigPath = path.resolve(cwd, tsconfig);
|
|
312
319
|
if (fileExists(tsConfigPath)) {
|
|
320
|
+
// Use the original ts handler to avoid memory leak
|
|
313
321
|
const ts = resolveTypescript(cwd);
|
|
314
322
|
const basePath = tsConfigPath ? path.dirname(tsConfigPath) : cwd;
|
|
315
323
|
const tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config;
|
|
@@ -324,6 +332,7 @@ function resolveTsConfigHandler(cwd) {
|
|
|
324
332
|
}
|
|
325
333
|
const resolveTsConfig = memoize(resolveTsConfigHandler);
|
|
326
334
|
async function convertCompilerOptions(cwd, json) {
|
|
335
|
+
// Use the original ts handler to avoid memory leak
|
|
327
336
|
const ts = resolveTypescript(cwd);
|
|
328
337
|
return ts.convertCompilerOptionsFromJson(json, './');
|
|
329
338
|
}
|
|
@@ -1472,6 +1481,9 @@ function createOutputState({ entries }) {
|
|
|
1472
1481
|
if (chunk.type !== 'chunk') {
|
|
1473
1482
|
return;
|
|
1474
1483
|
}
|
|
1484
|
+
if (!chunk.isEntry) {
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1475
1487
|
const size = chunk.code.length;
|
|
1476
1488
|
const sourceFileName = chunk.facadeModuleId || '';
|
|
1477
1489
|
const exportPath = removeScope(reversedMapping.get(sourceFileName) || '.');
|
|
@@ -1552,6 +1564,53 @@ function logOutputState(sizeCollector) {
|
|
|
1552
1564
|
});
|
|
1553
1565
|
}
|
|
1554
1566
|
|
|
1567
|
+
async function createAssetRollupJobs(options, buildContext, { isFromCli, generateTypes }) {
|
|
1568
|
+
const assetsConfigs = await buildEntryConfig(options, buildContext, false);
|
|
1569
|
+
const typesConfigs = generateTypes ? await buildEntryConfig(options, buildContext, true) : [];
|
|
1570
|
+
const allConfigs = assetsConfigs.concat(typesConfigs);
|
|
1571
|
+
for (const config of allConfigs){
|
|
1572
|
+
if (options.clean && !isFromCli) {
|
|
1573
|
+
await removeOutputDir(config.output, buildContext.cwd);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
const rollupJobs = allConfigs.map((rollupConfig)=>bundleOrWatch(options, rollupConfig));
|
|
1577
|
+
return await Promise.all(rollupJobs);
|
|
1578
|
+
}
|
|
1579
|
+
async function bundleOrWatch(options, rollupConfig) {
|
|
1580
|
+
if (options.watch) {
|
|
1581
|
+
return runWatch(rollupConfig);
|
|
1582
|
+
}
|
|
1583
|
+
return runBundle(rollupConfig);
|
|
1584
|
+
}
|
|
1585
|
+
function runBundle({ input, output }) {
|
|
1586
|
+
return rollup.rollup(input).then((bundle)=>{
|
|
1587
|
+
return bundle.write(output);
|
|
1588
|
+
}, catchErrorHandler);
|
|
1589
|
+
}
|
|
1590
|
+
function runWatch({ input, output }) {
|
|
1591
|
+
const watchOptions = [
|
|
1592
|
+
{
|
|
1593
|
+
...input,
|
|
1594
|
+
output: output,
|
|
1595
|
+
watch: {
|
|
1596
|
+
exclude: [
|
|
1597
|
+
'node_modules/**'
|
|
1598
|
+
]
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
];
|
|
1602
|
+
const watcher = rollup.watch(watchOptions);
|
|
1603
|
+
return watcher;
|
|
1604
|
+
}
|
|
1605
|
+
function catchErrorHandler(error) {
|
|
1606
|
+
if (!error) return;
|
|
1607
|
+
logger.error(error);
|
|
1608
|
+
// filter out the rollup plugin error information such as loc/frame/code...
|
|
1609
|
+
const err = new Error(error.message);
|
|
1610
|
+
err.stack = error.stack;
|
|
1611
|
+
throw err;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1555
1614
|
function assignDefault(options, name, defaultValue) {
|
|
1556
1615
|
if (!(name in options) || options[name] == null) {
|
|
1557
1616
|
options[name] = defaultValue;
|
|
@@ -1573,7 +1632,7 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1573
1632
|
// Original input file path, client path might change later
|
|
1574
1633
|
const inputFile = cliEntryPath;
|
|
1575
1634
|
const isFromCli = Boolean(cliEntryPath);
|
|
1576
|
-
let tsConfig = resolveTsConfig(cwd);
|
|
1635
|
+
let tsConfig = resolveTsConfig(cwd, options.tsconfig);
|
|
1577
1636
|
let hasTsConfig = Boolean(tsConfig == null ? void 0 : tsConfig.tsConfigPath);
|
|
1578
1637
|
const defaultTsOptions = {
|
|
1579
1638
|
tsConfigPath: tsConfig == null ? void 0 : tsConfig.tsConfigPath,
|
|
@@ -1609,17 +1668,6 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1609
1668
|
].filter(Boolean));
|
|
1610
1669
|
}
|
|
1611
1670
|
}
|
|
1612
|
-
const bundleOrWatch = async (rollupConfig)=>{
|
|
1613
|
-
if (options.clean) {
|
|
1614
|
-
if (!isFromCli) {
|
|
1615
|
-
await removeOutputDir(rollupConfig.output, cwd);
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
if (options.watch) {
|
|
1619
|
-
return runWatch(rollupConfig);
|
|
1620
|
-
}
|
|
1621
|
-
return runBundle(rollupConfig);
|
|
1622
|
-
};
|
|
1623
1671
|
const hasSpecifiedEntryFile = cliEntryPath ? fs__default.default.existsSync(cliEntryPath) && (await fsp__default.default.stat(cliEntryPath)).isFile() : false;
|
|
1624
1672
|
const hasNoEntry = !hasSpecifiedEntryFile && !isMultiEntries && !hasBin;
|
|
1625
1673
|
if (hasNoEntry) {
|
|
@@ -1663,34 +1711,21 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1663
1711
|
entriesAlias
|
|
1664
1712
|
}
|
|
1665
1713
|
};
|
|
1666
|
-
const
|
|
1667
|
-
const
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1714
|
+
const generateTypes = hasTsConfig && options.dts !== false;
|
|
1715
|
+
const rollupJobsOptions = {
|
|
1716
|
+
isFromCli,
|
|
1717
|
+
generateTypes
|
|
1718
|
+
};
|
|
1719
|
+
const assetJobs = await createAssetRollupJobs(options, buildContext, rollupJobsOptions);
|
|
1720
|
+
if (assetJobs.length === 0) {
|
|
1671
1721
|
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');
|
|
1672
1722
|
}
|
|
1673
|
-
if (
|
|
1674
|
-
|
|
1723
|
+
if (options.watch) {
|
|
1724
|
+
logWatcherBuildTime(assetJobs);
|
|
1675
1725
|
} else {
|
|
1676
|
-
|
|
1726
|
+
logOutputState(sizeCollector);
|
|
1677
1727
|
}
|
|
1678
|
-
return
|
|
1679
|
-
}
|
|
1680
|
-
function runWatch({ input, output }) {
|
|
1681
|
-
const watchOptions = [
|
|
1682
|
-
{
|
|
1683
|
-
...input,
|
|
1684
|
-
output: output,
|
|
1685
|
-
watch: {
|
|
1686
|
-
exclude: [
|
|
1687
|
-
'node_modules/**'
|
|
1688
|
-
]
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
];
|
|
1692
|
-
const watcher = rollup.watch(watchOptions);
|
|
1693
|
-
return watcher;
|
|
1728
|
+
return;
|
|
1694
1729
|
}
|
|
1695
1730
|
function logWatcherBuildTime(result) {
|
|
1696
1731
|
let watcherCounter = 0;
|
|
@@ -1727,15 +1762,6 @@ function logWatcherBuildTime(result) {
|
|
|
1727
1762
|
});
|
|
1728
1763
|
});
|
|
1729
1764
|
}
|
|
1730
|
-
async function removeOutputDir(output, cwd) {
|
|
1731
|
-
const dir = output.dir;
|
|
1732
|
-
if (dir && dir !== cwd) await removeDir(dir);
|
|
1733
|
-
}
|
|
1734
|
-
function runBundle({ input, output }) {
|
|
1735
|
-
return rollup.rollup(input).then((bundle)=>{
|
|
1736
|
-
return bundle.write(output);
|
|
1737
|
-
}, catchErrorHandler);
|
|
1738
|
-
}
|
|
1739
1765
|
function logError(error) {
|
|
1740
1766
|
if (!error) return;
|
|
1741
1767
|
// logging source code in format
|
|
@@ -1743,13 +1769,5 @@ function logError(error) {
|
|
|
1743
1769
|
process.stderr.write(error.frame + '\n');
|
|
1744
1770
|
}
|
|
1745
1771
|
}
|
|
1746
|
-
function catchErrorHandler(error) {
|
|
1747
|
-
if (!error) return;
|
|
1748
|
-
logError(error);
|
|
1749
|
-
// filter out the rollup plugin error information such as loc/frame/code...
|
|
1750
|
-
const err = new Error(error.message);
|
|
1751
|
-
err.stack = error.stack;
|
|
1752
|
-
throw err;
|
|
1753
|
-
}
|
|
1754
1772
|
|
|
1755
1773
|
exports.bundle = bundle;
|
package/package.json
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.5",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": "./dist/bin/cli.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "jest --env node",
|
|
10
|
+
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
|
|
11
|
+
"test:post": "POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts",
|
|
12
|
+
"clean": "rm -rf ./dist",
|
|
13
|
+
"typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
|
|
14
|
+
"prepublishOnly": "pnpm clean && pnpm build && chmod +x ./dist/bin/cli.js && pnpm test",
|
|
15
|
+
"tsx": "node -r @swc-node/register",
|
|
16
|
+
"build": "node -r @swc-node/register ./src/bin/index.ts --runtime node",
|
|
17
|
+
"format": "prettier --write .",
|
|
18
|
+
"prepare": "husky install"
|
|
19
|
+
},
|
|
8
20
|
"type": "commonjs",
|
|
9
21
|
"keywords": [
|
|
10
22
|
"bundler",
|
|
@@ -42,14 +54,14 @@
|
|
|
42
54
|
"@rollup/plugin-replace": "^5.0.5",
|
|
43
55
|
"@rollup/plugin-wasm": "^6.2.2",
|
|
44
56
|
"@rollup/pluginutils": "^5.1.0",
|
|
45
|
-
"@swc/core": "^1.
|
|
46
|
-
"@swc/helpers": "^0.5.
|
|
57
|
+
"@swc/core": "^1.4.8",
|
|
58
|
+
"@swc/helpers": "^0.5.6",
|
|
47
59
|
"arg": "^5.0.2",
|
|
48
60
|
"clean-css": "^5.3.3",
|
|
49
|
-
"magic-string": "^0.30.
|
|
61
|
+
"magic-string": "^0.30.8",
|
|
50
62
|
"pretty-bytes": "^5.6.0",
|
|
51
63
|
"rimraf": "^5.0.5",
|
|
52
|
-
"rollup": "^4.
|
|
64
|
+
"rollup": "^4.13.0",
|
|
53
65
|
"rollup-plugin-dts": "^6.1.0",
|
|
54
66
|
"rollup-plugin-swc3": "^0.11.0",
|
|
55
67
|
"rollup-preserve-directives": "^1.1.1",
|
|
@@ -68,6 +80,7 @@
|
|
|
68
80
|
},
|
|
69
81
|
"devDependencies": {
|
|
70
82
|
"@huozhi/testing-package": "1.0.0",
|
|
83
|
+
"@swc-node/register": "^1.9.0",
|
|
71
84
|
"@swc/jest": "^0.2.31",
|
|
72
85
|
"@swc/types": "^0.1.5",
|
|
73
86
|
"@types/clean-css": "^4.2.11",
|
|
@@ -80,7 +93,6 @@
|
|
|
80
93
|
"picocolors": "^1.0.0",
|
|
81
94
|
"prettier": "^3.0.0",
|
|
82
95
|
"react": "^18.2.0",
|
|
83
|
-
"tsx": "^4.6.2",
|
|
84
96
|
"typescript": "^5.3.2"
|
|
85
97
|
},
|
|
86
98
|
"lint-staged": {
|
|
@@ -104,14 +116,5 @@
|
|
|
104
116
|
],
|
|
105
117
|
"testTimeout": 60000
|
|
106
118
|
},
|
|
107
|
-
"packageManager": "pnpm@8.8.0"
|
|
108
|
-
|
|
109
|
-
"test": "jest --env node",
|
|
110
|
-
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
|
|
111
|
-
"test:post": "POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts",
|
|
112
|
-
"clean": "rm -rf ./dist",
|
|
113
|
-
"typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
|
|
114
|
-
"build": "tsx ./src/bin/index.ts --runtime node",
|
|
115
|
-
"format": "prettier --write ."
|
|
116
|
-
}
|
|
117
|
-
}
|
|
119
|
+
"packageManager": "pnpm@8.8.0"
|
|
120
|
+
}
|