Skip to content

Commit 5321c8a

Browse files
committed
fix(exe): use runtime semver check for ESM SEA default format
Instead of always defaulting to CJS when exe is enabled, check the Node.js version at runtime to determine ESM SEA support (>= v25.7.0).
1 parent 43b96ce commit 5321c8a

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

docs/reference/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ This will bundle the output into a single executable file using Node.js SEA. Req
254254

255255
When `exe` is enabled:
256256

257-
- The default output format changes from `esm` to `cjs` (unless ESM SEA is supported).
257+
- The default output format changes from `esm` to `cjs` (unless ESM SEA is supported, i.e., Node.js >= v25.7.0).
258258
- Declaration file generation (`dts`) is disabled by default.
259259
- Code splitting is disabled.
260260
- Only single entry points are supported.

docs/zh-CN/reference/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ tsdown --copy public
254254

255255
启用 `exe` 时:
256256

257-
- 默认输出格式从 `esm` 变更为 `cjs`(除非支持 ESM SEA)。
257+
- 默认输出格式从 `esm` 变更为 `cjs`(除非支持 ESM SEA,即 Node.js >= v25.7.0)。
258258
- 默认禁用声明文件生成(`dts`)。
259259
- 禁用代码分割。
260260
- 仅支持单入口。

src/config/options.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import satisfies from 'semver/functions/satisfies.js'
12
import { readFile } from 'node:fs/promises'
23
import path from 'node:path'
34
import process from 'node:process'
@@ -290,14 +291,18 @@ export async function resolveUserConfig(
290291
write,
291292
}
292293

294+
let defaultFormat: Format = 'esm'
293295
if (exe) {
294296
validateSea(config)
297+
if (satisfies(process.version, '<25.7.0')) {
298+
defaultFormat = 'cjs'
299+
}
295300
}
296301

297302
const objectFormat = typeof format === 'object' && !Array.isArray(format)
298303
const formats = objectFormat
299304
? (Object.keys(format) as Format[])
300-
: resolveComma(toArray<Format>(format, exe ? 'cjs' : 'es'))
305+
: resolveComma(toArray<Format>(format, defaultFormat))
301306

302307
return formats.map((fmt, idx): ResolvedConfig => {
303308
const once = idx === 0

src/config/types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,17 @@ export interface UserConfig {
329329
//#region Output Options
330330

331331
/**
332-
* Output format(s). Defaults to ESM.
332+
* Output format(s). Available formats are
333+
* - `esm`: ESM
334+
* - `cjs`: CommonJS
335+
* - `iife`: IIFE
336+
* - `umd`: UMD
337+
*
338+
* Defaults to ESM.
333339
*
334340
* ### Usage with {@link exe}
335341
* If `exe` is enabled, the default format will depend on support level of SEA in the target Node.js version:
336-
* - If ESM SEA is supported, the default format will be ESM.
342+
* - If ESM SEA is supported (Node.js > v25.7), the default format will be ESM.
337343
* - If only CJS SEA is supported, the default format will be CJS.
338344
*/
339345
format?: Format | Format[] | Partial<Record<Format, Partial<ResolvedConfig>>>

0 commit comments

Comments
 (0)