bunchee 5.1.4 → 5.1.6

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/dist/bin/cli.js CHANGED
@@ -474,7 +474,7 @@ function lint$1(pkg) {
474
474
  }
475
475
  }
476
476
 
477
- var version = "5.1.4";
477
+ var version = "5.1.6";
478
478
 
479
479
  function relativify(path) {
480
480
  return path.startsWith('.') ? path : `./${path}`;
package/dist/index.js CHANGED
@@ -312,7 +312,17 @@ function resolveTypescript(cwd) {
312
312
  const m = new module$1.Module('', undefined);
313
313
  m.paths = module$1.Module._nodeModulePaths(cwd);
314
314
  try {
315
- ts = m.require('typescript');
315
+ // Bun does not yet support the `Module` class properly.
316
+ if (typeof (m == null ? void 0 : m.require) === 'undefined') {
317
+ const tsPath = require.resolve('typescript', {
318
+ paths: [
319
+ cwd
320
+ ]
321
+ });
322
+ ts = require(tsPath);
323
+ } else {
324
+ ts = m.require('typescript');
325
+ }
316
326
  } catch (e) {
317
327
  console.error(e);
318
328
  if (!hasLoggedTsWarning) {
@@ -477,34 +487,40 @@ function inlineCss(options) {
477
487
  // Follow up for rollup 4 for better support of assertion support https://github.com/rollup/rollup/issues/4818
478
488
  return {
479
489
  name: 'inline-css',
480
- transform (code, id) {
481
- if (!filter(id)) return;
482
- if (options.skip) return '';
483
- const cssCode = minify(code);
484
- cssIds.add(id);
485
- return {
486
- code: helpers.cssImport.create(cssCode),
487
- map: {
488
- mappings: ''
489
- }
490
- };
490
+ transform: {
491
+ order: 'post',
492
+ handler (code, id) {
493
+ if (!filter(id)) return;
494
+ if (options.skip) return '';
495
+ const cssCode = minify(code);
496
+ cssIds.add(id);
497
+ return {
498
+ code: helpers.cssImport.create(cssCode),
499
+ map: {
500
+ mappings: ''
501
+ }
502
+ };
503
+ }
491
504
  },
492
- renderChunk (code) {
493
- const dependenciesIds = this.getModuleIds();
494
- let foundCss = false;
495
- for (const depId of dependenciesIds){
496
- if (depId && cssIds.has(depId)) {
497
- foundCss = true;
498
- break;
505
+ renderChunk: {
506
+ order: 'pre',
507
+ handler (code) {
508
+ const dependenciesIds = this.getModuleIds();
509
+ let foundCss = false;
510
+ for (const depId of dependenciesIds){
511
+ if (depId && cssIds.has(depId)) {
512
+ foundCss = true;
513
+ break;
514
+ }
499
515
  }
516
+ if (!foundCss) return;
517
+ return {
518
+ code: `${helpers.cssImport.global}\n${code}`,
519
+ map: {
520
+ mappings: ''
521
+ }
522
+ };
500
523
  }
501
- if (!foundCss) return;
502
- return {
503
- code: `${helpers.cssImport.global}\n${code}`,
504
- map: {
505
- mappings: ''
506
- }
507
- };
508
524
  }
509
525
  };
510
526
  }
@@ -1469,22 +1485,25 @@ async function buildOutputConfigs(entry, bundleConfig, exportCondition, buildCon
1469
1485
  output: outputOptions
1470
1486
  };
1471
1487
  }
1472
- async function buildEntryConfig(bundleConfig, pluginContext, dts) {
1488
+ async function buildEntryConfig(bundleConfig, pluginContext, bundleEntryOptions) {
1473
1489
  const configs = [];
1474
1490
  const { entries } = pluginContext;
1475
1491
  for (const exportCondition of Object.values(entries)){
1476
- const rollupConfigs = await buildConfig(bundleConfig, exportCondition, pluginContext, dts);
1492
+ const rollupConfigs = await buildConfig(bundleConfig, exportCondition, pluginContext, bundleEntryOptions);
1477
1493
  configs.push(...rollupConfigs);
1478
1494
  }
1479
1495
  return configs;
1480
1496
  }
1481
- async function buildConfig(bundleConfig, exportCondition, pluginContext, dts) {
1497
+ async function buildConfig(bundleConfig, exportCondition, pluginContext, bundleEntryOptions) {
1482
1498
  const { file } = bundleConfig;
1483
1499
  const { pkg, cwd } = pluginContext;
1500
+ const { dts, isFromCli } = bundleEntryOptions;
1484
1501
  const entry = exportCondition.source;
1485
1502
  const outputExports = getExportsDistFilesOfCondition(pkg, exportCondition, cwd, dts);
1486
- // If there's nothing found, give a default output
1487
- if (outputExports.length === 0 && !pkg.bin) {
1503
+ // If it's CLI generation for JS asset and there's nothing found,
1504
+ // give a default output dist/index.js.
1505
+ // We don't do it for types generation or non-CLI bundle generation.
1506
+ if (!dts && isFromCli && outputExports.length === 0 && !pkg.bin) {
1488
1507
  const isEsmPkg = isESModulePackage(pkg.type);
1489
1508
  const defaultFormat = isEsmPkg ? 'esm' : 'cjs';
1490
1509
  outputExports.push({
@@ -1673,9 +1692,16 @@ function logOutputState(sizeCollector) {
1673
1692
  });
1674
1693
  }
1675
1694
 
1676
- async function createAssetRollupJobs(options, buildContext, { isFromCli, generateTypes }) {
1677
- const assetsConfigs = await buildEntryConfig(options, buildContext, false);
1678
- const typesConfigs = generateTypes ? await buildEntryConfig(options, buildContext, true) : [];
1695
+ async function createAssetRollupJobs(options, buildContext, bundleJobOptions) {
1696
+ const { isFromCli, generateTypes } = bundleJobOptions;
1697
+ const assetsConfigs = await buildEntryConfig(options, buildContext, {
1698
+ dts: false,
1699
+ isFromCli
1700
+ });
1701
+ const typesConfigs = generateTypes ? await buildEntryConfig(options, buildContext, {
1702
+ dts: true,
1703
+ isFromCli
1704
+ }) : [];
1679
1705
  const allConfigs = assetsConfigs.concat(typesConfigs);
1680
1706
  for (const config of allConfigs){
1681
1707
  if (options.clean && !isFromCli) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "5.1.4",
3
+ "version": "5.1.6",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": "./dist/bin/cli.js",
6
6
  "main": "./dist/index.js",
@@ -74,16 +74,16 @@
74
74
  "@types/jest": "29.0.0",
75
75
  "@types/node": "^20.4.1",
76
76
  "bunchee": "link:./",
77
- "husky": "^8.0.3",
77
+ "husky": "^9.0.11",
78
78
  "jest": "29.0.1",
79
- "lint-staged": "^13.2.3",
79
+ "lint-staged": "^15.2.2",
80
80
  "picocolors": "^1.0.0",
81
81
  "prettier": "^3.0.0",
82
82
  "react": "^18.2.0",
83
83
  "typescript": "^5.3.2"
84
84
  },
85
85
  "lint-staged": {
86
- "*.{ts,tsx,js,jsx,md,json,yml}": "prettier --write"
86
+ "*.{js,jsx,ts,tsx,md,json,yml,yaml}": "prettier --write"
87
87
  },
88
88
  "jest": {
89
89
  "moduleDirectories": [