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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # bunchee
2
2
  > zero config bundler for JavaScript/TypeScript/JSX library
3
3
 
4
- ![bunchee](https://user-images.githubusercontent.com/4800338/98430015-7ce64f00-20e5-11eb-8c64-41addfbd4ede.png)
4
+ ![bunchee](https://repository-images.githubusercontent.com/154026156/5d132698-0ff5-4644-a4fd-d9570e6229bc)
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 only (`--dts`): Generate TypeScript declaration files without assets.
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
@@ -65,7 +65,7 @@ const logger = {
65
65
  }
66
66
  };
67
67
 
68
- var version = "3.0.0";
68
+ var version = "3.0.1";
69
69
 
70
70
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
71
71
  try {
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 packageExports = pkg.exports || {};
592
- const isSingleEntry = typeof packageExports === 'string';
593
- const hasMultiEntries = packageExports && !isSingleEntry && Object.keys(packageExports).length > 0;
594
- if (isSingleEntry) {
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
- if (!(yield fileExists(entryPath))) {
635
- const hasSpecifiedEntryFile = entryPath === '' ? false : (yield fs.stat(entryPath)).isFile();
636
- if (!hasSpecifiedEntryFile && !hasMultiEntries) {
637
- const err = new Error(`Entry file \`${entryPath}\` is not existed`);
638
- err.name = 'NOT_EXISTED';
639
- return Promise.reject(err);
640
- }
641
- // has `types` field in package.json or has `types` exports in any export condition for multi-entries
642
- const hasTypings = !!getTypings(pkg) || typeof packageExports === 'object' && Array.from(Object.values(packageExports || {})).some((condition)=>condition.hasOwnProperty('types'));
643
- // If there's no entry file specified, should enable dts bundling based on package.json exports info
644
- if (!hasSpecifiedEntryFile && hasTypings) {
645
- options.dts = hasTypings;
646
- }
647
- if (hasMultiEntries) {
648
- const buildConfigs = yield buildEntryConfig(packageExports, false);
649
- const assetsJobs = buildConfigs.map((rollupConfig)=>bundleOrWatch(rollupConfig));
650
- const typesJobs = options.dts ? (yield buildEntryConfig(packageExports, true)).map((rollupConfig)=>bundleOrWatch(rollupConfig)) : [];
651
- return yield Promise.all(assetsJobs.concat(typesJobs));
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.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": {