bunchee 6.1.3 → 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/README.md CHANGED
@@ -358,7 +358,7 @@ This convention keeps shared modules private while enabling efficient bundling a
358
358
  - External (`--external <dep,>`): Specifying extra external dependencies, by default it is the list of `dependencies` and `peerDependencies` from `package.json`. Values are separate by comma.
359
359
  - Target (`--target <target>`): Set ECMAScript target (default: `'es2015'`).
360
360
  - Runtime (`--runtime <runtime>`): Set build runtime (default: `'browser'`).
361
- - Environment (`--env <env,>`): Define environment variables. (default: `NODE_ENV`, separate by comma)
361
+ - Environment (`--env <env,>`): Define environment variables. (default: `[]`, separate by comma)
362
362
  - Working Directory (`--cwd <cwd>`): Set current working directory where containing `package.json`.
363
363
  - Minify (`-m`): Compress output.
364
364
  - Watch (`-w`): Watch for source file changes.
package/dist/bin/cli.js CHANGED
@@ -642,7 +642,7 @@ function lint$1(pkg) {
642
642
  }
643
643
  }
644
644
 
645
- var version = "6.1.3";
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([
@@ -1068,9 +1081,6 @@ async function writeDefaultTsconfig(tsConfigPath) {
1068
1081
  /**
1069
1082
  * @return {Record<string, string>} env { 'process.env.<key>': '<value>' }
1070
1083
  */ function getDefinedInlineVariables(envs, parsedExportCondition) {
1071
- if (!envs.includes('NODE_ENV')) {
1072
- envs.push('NODE_ENV');
1073
- }
1074
1084
  const envVars = envs.reduce((acc, key)=>{
1075
1085
  const value = process.env[key];
1076
1086
  if (typeof value !== 'undefined') {
@@ -1292,6 +1302,9 @@ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specia
1292
1302
  const formatCond = format === 'cjs' ? 'require' : 'import';
1293
1303
  const isTypesCondName = conditionNames.has('types');
1294
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;
1295
1308
  const isMatchedFormat = hasFormatCond ? conditionNames.has(formatCond) : true;
1296
1309
  const isMatchedConditionWithFormat = conditionNames.has(specialCondition) || !conditionNames.has('default') && hasNoSpecialCondition(conditionNames);
1297
1310
  const match = isMatchedConditionWithFormat && !isTypesCondName && hasBundle && isMatchedFormat;
@@ -1300,7 +1313,11 @@ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specia
1300
1313
  if (!fallback) {
1301
1314
  return false;
1302
1315
  } else {
1303
- 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');
1304
1321
  }
1305
1322
  } else {
1306
1323
  return match;
@@ -1560,7 +1577,11 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1560
1577
  ...swcOptions
1561
1578
  }),
1562
1579
  commonjs__default.default({
1563
- 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
1564
1585
  })
1565
1586
  ]).filter(isNotNull);
1566
1587
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "6.1.3",
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",