bunchee 5.3.1 → 5.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # bunchee
2
2
 
3
- > Zero-config bundler for frontend libraries.
3
+ > Zero-config bundler for JS/TS packages.
4
4
 
5
5
  ![bunchee](https://repository-images.githubusercontent.com/154026156/5d132698-0ff5-4644-a4fd-d9570e6229bc)
6
6
 
@@ -326,6 +326,7 @@ import { AppContext } from './app-context.shared-runtime'
326
326
  - Watch (`-w`): Watch for source file changes.
327
327
  - No Clean(`--no-clean`): Do not clean the dist folder before building. (default: `false`)
328
328
  - TSConfig (`--tsconfig <path>`): Specify the path to the TypeScript configuration file. (default: `tsconfig.json`)
329
+ - Bundle Types (`--dts-bundle`): Bundle type declaration files. (default: `false`)
329
330
 
330
331
  ```sh
331
332
  cd <project-root-dir>
package/dist/bin/cli.js CHANGED
@@ -470,7 +470,7 @@ function lint$1(pkg) {
470
470
  }
471
471
  }
472
472
 
473
- var version = "5.3.1";
473
+ var version = "5.4.0";
474
474
 
475
475
  function relativify(path) {
476
476
  return path.startsWith('.') ? path : `./${path}`;
@@ -921,6 +921,7 @@ Options:
921
921
  --sourcemap enable sourcemap generation, default: false
922
922
  --no-dts do not generate types, default: undefined
923
923
  --tsconfig path to tsconfig file, default: tsconfig.json
924
+ --dts-bundle bundle type declaration files, default: false
924
925
  `;
925
926
  function help() {
926
927
  logger.log(helpMessage);
@@ -952,6 +953,7 @@ function parseCliArgs(argv) {
952
953
  '--no-clean': Boolean,
953
954
  '--prepare': Boolean,
954
955
  '--tsconfig': String,
956
+ '--dts-bundle': Boolean,
955
957
  '-h': '--help',
956
958
  '-v': '--version',
957
959
  '-w': '--watch',
@@ -972,6 +974,7 @@ function parseCliArgs(argv) {
972
974
  sourcemap: !!args['--sourcemap'],
973
975
  cwd: args['--cwd'],
974
976
  dts: args['--no-dts'] ? false : undefined,
977
+ dtsBundle: args['--dts-bundle'],
975
978
  help: args['--help'],
976
979
  version: args['--version'],
977
980
  runtime: args['--runtime'],
@@ -986,11 +989,13 @@ function parseCliArgs(argv) {
986
989
  }
987
990
  async function run(args) {
988
991
  var _args_external;
989
- const { source, format, watch, minify, sourcemap, target, runtime, dts, env, clean, tsconfig } = args;
992
+ const { source, format, watch, minify, sourcemap, target, runtime, dts, dtsBundle, env, clean, tsconfig } = args;
990
993
  const cwd = args.cwd || process.cwd();
991
994
  const file = args.file ? path__default.default.resolve(cwd, args.file) : undefined;
992
995
  const bundleConfig = {
993
- dts,
996
+ dts: dts !== false && {
997
+ respectExternal: dtsBundle ? true : undefined
998
+ },
994
999
  file,
995
1000
  format,
996
1001
  cwd,
package/dist/index.d.ts CHANGED
@@ -14,7 +14,9 @@ type BundleConfig = {
14
14
  sourcemap?: boolean;
15
15
  external?: string[] | null;
16
16
  env?: string[];
17
- dts?: boolean;
17
+ dts?: {
18
+ respectExternal?: boolean;
19
+ } | false;
18
20
  runtime?: string;
19
21
  pkg?: PackageMetadata;
20
22
  clean?: boolean;
package/dist/index.js CHANGED
@@ -1282,7 +1282,7 @@ const swcMinifyOptions = {
1282
1282
  toplevel: true
1283
1283
  }
1284
1284
  };
1285
- async function createDtsPlugin(tsCompilerOptions, tsConfigPath, cwd) {
1285
+ async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal, cwd) {
1286
1286
  const enableIncrementalWithoutBuildInfo = tsCompilerOptions.incremental && !tsCompilerOptions.tsBuildInfoFile;
1287
1287
  const incrementalOptions = enableIncrementalWithoutBuildInfo ? {
1288
1288
  incremental: false
@@ -1313,7 +1313,8 @@ async function createDtsPlugin(tsCompilerOptions, tsConfigPath, cwd) {
1313
1313
  });
1314
1314
  const dtsPlugin = require('rollup-plugin-dts').default({
1315
1315
  tsconfig: tsConfigPath,
1316
- compilerOptions: overrideResolvedTsOptions
1316
+ compilerOptions: overrideResolvedTsOptions,
1317
+ respectExternal
1317
1318
  });
1318
1319
  return dtsPlugin;
1319
1320
  }
@@ -1399,7 +1400,7 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1399
1400
  // Each package build should be unique
1400
1401
  // Composing above factors into a unique cache key to retrieve the memoized dts plugin with tsconfigs
1401
1402
  const uniqueProcessId = 'dts-plugin:' + process.pid + tsConfigPath;
1402
- const dtsPlugin = await memoizeDtsPluginByKey(uniqueProcessId)(tsCompilerOptions, tsConfigPath, cwd);
1403
+ const dtsPlugin = await memoizeDtsPluginByKey(uniqueProcessId)(tsCompilerOptions, tsConfigPath, bundleConfig.dts && bundleConfig.dts.respectExternal, cwd);
1403
1404
  typesPlugins.push(dtsPlugin);
1404
1405
  }
1405
1406
  const plugins = (dts ? typesPlugins : [
@@ -1542,7 +1543,7 @@ async function buildOutputConfigs(entry, bundleConfig, exportCondition, buildCon
1542
1543
  const useEsModuleMark = tsCompilerOptions == null ? void 0 : tsCompilerOptions.esModuleInterop // hasEsmExport(exportPaths, tsCompilerOptions)
1543
1544
  ;
1544
1545
  const absoluteOutputFile = path.resolve(cwd, bundleConfig.file);
1545
- const outputFileExtension = path.extname(absoluteOutputFile);
1546
+ const isEsmPkg = isESModulePackage(pkg.type);
1546
1547
  const name = filePathWithoutExtension(absoluteOutputFile);
1547
1548
  var _exportCondition_export_types;
1548
1549
  const dtsFile = path.resolve(cwd, dts ? bundleConfig.file : (_exportCondition_export_types = exportCondition.export.types) != null ? _exportCondition_export_types : getExportFileTypePath(bundleConfig.file));
@@ -1563,7 +1564,8 @@ async function buildOutputConfigs(entry, bundleConfig, exportCondition, buildCon
1563
1564
  sourcemap: bundleConfig.sourcemap,
1564
1565
  manualChunks: createSplitChunks(pluginContext.moduleDirectiveLayerMap, entryFiles),
1565
1566
  chunkFileNames () {
1566
- const ext = format === 'cjs' && outputFileExtension === '.cjs' ? 'cjs' : 'js';
1567
+ const isCjsFormat = format === 'cjs';
1568
+ const ext = dts ? 'd.ts' : isCjsFormat && isEsmPkg ? 'cjs' : !isCjsFormat && !isEsmPkg ? 'mjs' : 'js';
1567
1569
  return '[name]-[hash].' + ext;
1568
1570
  },
1569
1571
  // By default in rollup, when creating multiple chunks, transitive imports of entry chunks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "5.3.1",
3
+ "version": "5.4.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",
@@ -42,14 +42,14 @@
42
42
  "@rollup/plugin-replace": "^5.0.7",
43
43
  "@rollup/plugin-wasm": "^6.2.2",
44
44
  "@rollup/pluginutils": "^5.1.0",
45
- "@swc/core": "^1.6.1",
45
+ "@swc/core": "^1.7.14",
46
46
  "@swc/helpers": "^0.5.11",
47
47
  "arg": "^5.0.2",
48
48
  "clean-css": "^5.3.3",
49
49
  "magic-string": "^0.30.11",
50
50
  "ora": "^8.0.1",
51
51
  "pretty-bytes": "^5.6.0",
52
- "rollup": "^4.19.1",
52
+ "rollup": "^4.19.2",
53
53
  "rollup-plugin-dts": "^6.1.1",
54
54
  "rollup-plugin-swc3": "^0.11.1",
55
55
  "rollup-preserve-directives": "^1.1.1",