bunchee 3.0.0 → 3.0.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 +2 -2
- package/dist/cli.js +1 -1
- package/dist/index.js +28 -26
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# bunchee
|
|
2
2
|
> zero config bundler for JavaScript/TypeScript/JSX library
|
|
3
3
|
|
|
4
|
-

|
|
5
5
|
|
|
6
6
|
<p align="left">
|
|
7
7
|
<a href="https://npm.im/bunchee">
|
|
@@ -76,7 +76,7 @@ Then just run `npm run build`, or `pnpm build` / `yarn build` if you're using th
|
|
|
76
76
|
- Runtime (`--runtime <runtime>`): Set build runtime (default: `'browser'`).
|
|
77
77
|
- Environment (`--env <env,>`): Define environment variables. (default: `NODE_ENV`, separate by comma)
|
|
78
78
|
- Working Directory (`--cwd <cwd>`): Set current working directory where containing `package.json`.
|
|
79
|
-
- Types
|
|
79
|
+
- Types (`--dts`): Generate TypeScript declaration files along with assets.
|
|
80
80
|
- Minify (`-m`): Compress output.
|
|
81
81
|
- Watch (`-w`): Watch for source file changes.
|
|
82
82
|
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -572,6 +572,12 @@ function _getSourcePathFromExportPath() {
|
|
|
572
572
|
});
|
|
573
573
|
return _getSourcePathFromExportPath.apply(this, arguments);
|
|
574
574
|
}
|
|
575
|
+
function hasMultiEntryExport(pkg) {
|
|
576
|
+
const packageExportsField = pkg.exports || {};
|
|
577
|
+
if (typeof packageExportsField === 'string') return false;
|
|
578
|
+
const exportKeys = (packageExportsField ? Object.keys(packageExportsField) : []).filter((key)=>key !== './package.json');
|
|
579
|
+
return exportKeys.length > 0 && exportKeys.every((name)=>name.startsWith('.'));
|
|
580
|
+
}
|
|
575
581
|
function bundle(entryPath) {
|
|
576
582
|
return _bundle.apply(this, arguments);
|
|
577
583
|
}
|
|
@@ -584,14 +590,11 @@ function _bundle() {
|
|
|
584
590
|
assignDefault(options, 'format', 'es');
|
|
585
591
|
assignDefault(options, 'minify', false);
|
|
586
592
|
assignDefault(options, 'target', 'es2015');
|
|
587
|
-
if (options.dts === undefined && isTypescript(entryPath)) {
|
|
588
|
-
options.dts = true;
|
|
589
|
-
}
|
|
590
593
|
const pkg = yield getPackageMeta(config.rootDir);
|
|
591
|
-
const
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
if (
|
|
594
|
+
const packageExportsField = pkg.exports || {};
|
|
595
|
+
const isMultiEntries = hasMultiEntryExport(pkg);
|
|
596
|
+
// Handle single entry file
|
|
597
|
+
if (!isMultiEntries) {
|
|
595
598
|
// Use specified string file path if possible, then fallback to the default behavior entry picking logic
|
|
596
599
|
// e.g. "exports": "./dist/index.js" -> use "./index.<ext>" as entry
|
|
597
600
|
entryPath = entryPath || (yield getSourcePathFromExportPath(config.rootDir, '.')) || '';
|
|
@@ -631,25 +634,24 @@ function _bundle() {
|
|
|
631
634
|
}
|
|
632
635
|
return runBundle(rollupConfig, buildMetadata);
|
|
633
636
|
};
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
637
|
+
const hasSpecifiedEntryFile = entryPath ? (yield fileExists(entryPath)) && (yield fs.stat(entryPath)).isFile() : false;
|
|
638
|
+
if (!hasSpecifiedEntryFile && !isMultiEntries) {
|
|
639
|
+
const err = new Error(`Entry file \`${entryPath}\` is not existed`);
|
|
640
|
+
err.name = 'NOT_EXISTED';
|
|
641
|
+
return Promise.reject(err);
|
|
642
|
+
}
|
|
643
|
+
// has `types` field in package.json or has `types` exports in any export condition for multi-entries
|
|
644
|
+
const hasTypings = !!getTypings(pkg) || typeof packageExportsField === 'object' && Array.from(Object.values(packageExportsField || {})).some((condition)=>condition.hasOwnProperty('types'));
|
|
645
|
+
// Enable types generation if it's types field specified in package.json
|
|
646
|
+
if (hasTypings) {
|
|
647
|
+
options.dts = hasTypings;
|
|
648
|
+
}
|
|
649
|
+
if (isMultiEntries) {
|
|
650
|
+
const pkgExports = packageExportsField;
|
|
651
|
+
const buildConfigs = yield buildEntryConfig(pkgExports, false);
|
|
652
|
+
const assetsJobs = buildConfigs.map((rollupConfig)=>bundleOrWatch(rollupConfig));
|
|
653
|
+
const typesJobs = options.dts ? (yield buildEntryConfig(pkgExports, true)).map((rollupConfig)=>bundleOrWatch(rollupConfig)) : [];
|
|
654
|
+
return yield Promise.all(assetsJobs.concat(typesJobs));
|
|
653
655
|
}
|
|
654
656
|
// Generate types
|
|
655
657
|
if (isTypescript(entryPath) && options.dts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": {
|
|
6
6
|
"bunchee": "./dist/cli.js"
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@rollup/plugin-node-resolve": "15.0.2",
|
|
47
47
|
"@rollup/plugin-replace": "5.0.2",
|
|
48
48
|
"@swc/core": "1.3.46",
|
|
49
|
+
"@swc/helpers": "0.5.0",
|
|
49
50
|
"arg": "5.0.2",
|
|
50
51
|
"publint": "0.1.11",
|
|
51
52
|
"rollup": "3.20.2",
|
|
@@ -60,6 +61,9 @@
|
|
|
60
61
|
"peerDependenciesMeta": {
|
|
61
62
|
"typescript": {
|
|
62
63
|
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"@swc/helpers": {
|
|
66
|
+
"optional": true
|
|
63
67
|
}
|
|
64
68
|
},
|
|
65
69
|
"devDependencies": {
|