bunchee 6.2.0 → 6.3.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/dist/bin/cli.js CHANGED
@@ -642,7 +642,7 @@ function lint$1(pkg) {
642
642
  }
643
643
  }
644
644
 
645
- var version = "6.2.0";
645
+ var version = "6.3.0";
646
646
 
647
647
  async function writeDefaultTsconfig(tsConfigPath) {
648
648
  await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
package/dist/index.js CHANGED
@@ -159,14 +159,7 @@ const runtimeExportConventionsFallback = new Map([
159
159
  'default'
160
160
  ]
161
161
  ],
162
- [
163
- 'browser',
164
- [
165
- 'import',
166
- 'default'
167
- ]
168
- ],
169
- // it could be CJS or ESM
162
+ // Fallback to default when unsure
170
163
  [
171
164
  'electron',
172
165
  [
@@ -202,6 +195,26 @@ const runtimeExportConventionsFallback = new Map([
202
195
  [
203
196
  'default'
204
197
  ]
198
+ ],
199
+ [
200
+ 'development',
201
+ [
202
+ 'default'
203
+ ]
204
+ ],
205
+ [
206
+ 'production',
207
+ [
208
+ 'default'
209
+ ]
210
+ ],
211
+ [
212
+ 'browser',
213
+ [
214
+ 'import',
215
+ 'require',
216
+ 'default'
217
+ ]
205
218
  ]
206
219
  ]);
207
220
  const optimizeConventions = new Set([
@@ -1289,6 +1302,9 @@ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specia
1289
1302
  const formatCond = format === 'cjs' ? 'require' : 'import';
1290
1303
  const isTypesCondName = conditionNames.has('types');
1291
1304
  const hasFormatCond = conditionNames.has('import') || conditionNames.has('require');
1305
+ // Check if the format condition is matched:
1306
+ // if there's condition existed, check if the format condition is matched;
1307
+ // if there's no condition, just return true, assuming format doesn't matter;
1292
1308
  const isMatchedFormat = hasFormatCond ? conditionNames.has(formatCond) : true;
1293
1309
  const isMatchedConditionWithFormat = conditionNames.has(specialCondition) || !conditionNames.has('default') && hasNoSpecialCondition(conditionNames);
1294
1310
  const match = isMatchedConditionWithFormat && !isTypesCondName && hasBundle && isMatchedFormat;
@@ -1297,7 +1313,11 @@ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specia
1297
1313
  if (!fallback) {
1298
1314
  return false;
1299
1315
  } else {
1300
- return fallback.some((name)=>conditionNames.has(name));
1316
+ // Match its own condition first,
1317
+ // e.g. when import utils.js in index.js
1318
+ // In output: index.browser.js should match util.browser.js, fallback to util.js
1319
+ // The last guard condition is to ensure bundle condition but not types file.
1320
+ return isMatchedFormat && (conditionNames.has(specialCondition) || fallback.some((name)=>conditionNames.has(name))) && !conditionNames.has('types');
1301
1321
  }
1302
1322
  } else {
1303
1323
  return match;
@@ -1557,7 +1577,11 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1557
1577
  ...swcOptions
1558
1578
  }),
1559
1579
  commonjs__default.default({
1560
- exclude: bundleConfig.external || null
1580
+ exclude: bundleConfig.external || null,
1581
+ // Deal with mixed ESM and CJS modules, such as calling require() in ESM.
1582
+ // For relative paths, the module will be bundled;
1583
+ // For external libraries, the module will not be bundled.
1584
+ transformMixedEsModules: true
1561
1585
  })
1562
1586
  ]).filter(isNotNull);
1563
1587
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "6.2.0",
3
+ "version": "6.3.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",
@@ -89,7 +89,7 @@
89
89
  "prettier": "^3.0.0",
90
90
  "react": "^19.0.0",
91
91
  "react-dom": "^19.0.0",
92
- "typescript": "^5.6.2"
92
+ "typescript": "^5.7.2"
93
93
  },
94
94
  "lint-staged": {
95
95
  "*.{js,jsx,ts,tsx,md,json,yml,yaml}": "prettier --write"
@@ -99,7 +99,7 @@
99
99
  "node_modules"
100
100
  ],
101
101
  "moduleNameMapper": {
102
- "bunchee": "<rootDir>/src/index.ts"
102
+ "^bunchee$": "<rootDir>/src/index.ts"
103
103
  },
104
104
  "transform": {
105
105
  "^.+\\.(t|j)sx?$": [
@@ -108,7 +108,8 @@
108
108
  },
109
109
  "testPathIgnorePatterns": [
110
110
  "/node_modules/",
111
- "<rootDir>/test/integration/.*/*src"
111
+ "<rootDir>/test/integration/.*/*src",
112
+ "<rootDir>/test/fixtures"
112
113
  ],
113
114
  "testTimeout": 60000
114
115
  },
@@ -120,6 +121,7 @@
120
121
  "docs:dev": "next dev docs",
121
122
  "docs:build": "next build docs",
122
123
  "clean": "rm -rf ./dist",
124
+ "new-test": "node ./scripts/new-test.js",
123
125
  "typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
124
126
  "prepare-release": "pnpm clean && pnpm build",
125
127
  "publish-local": "pnpm prepare-release && pnpm test && pnpm publish",