Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(build): pin client target so the intentional CJS bundle stops failing tsdown under CI

yingtianlan387c2ae9b303
diff --git a/packages/dsh-tauri-tsdown/src/index.ts b/packages/dsh-tauri-tsdown/src/index.ts
index 5ebeb154..0c7e98ce 100644
--- a/packages/dsh-tauri-tsdown/src/index.ts
+++ b/packages/dsh-tauri-tsdown/src/index.ts
@@ -2,8 +2,21 @@ import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import process from 'node:process'
-/** tsdown 单条构建配置(宽松面;运行时由 tsdown 校验)。 */
-type TsdownOptions = Record<string, unknown> & { noExternal?: Array<string | RegExp> }
+/**
+ * tsdown 单条构建配置(宽松面;运行时由 tsdown 校验)。
+ *
+ * `target` 需要显式透出:tsdown 的 `warnLegacyCJS`(features/cjs.ts)会对
+ * format 含 cjs 且解析出 Node >= 22.12 target(由 package.json `engines.node`
+ * 推断)的配置发出 "We recommend using the ESM format instead of CommonJS"
+ * 警告,默认 `failOnWarn: 'ci-only'` 在 CI 下把它升级为 exit 1 的 ERROR。
+ * client bundle 并不运行在 Node 上(见下方 client 配置注释),声明了
+ * `engines.node` 的插件应在 client 侧给定一个 ES/web target 来修正该推断,
+ * 而不是关掉 failOnWarn 让其余所有警告失去 CI 约束力。
+ */
+type TsdownOptions = Record<string, unknown> & {
+ noExternal?: Array<string | RegExp>
+ target?: string | string[] | false
+}
/** 是否处于 watch/dev 模式(dev:plugins → `tsdown --watch` 常驻):跳过 minify 加速热重建。 */
const isWatchMode = process.argv.includes('--watch') || process.argv.includes('-w')
@@ -107,7 +120,13 @@ export function defineDshConfig(options: DshConfigOptions = {}) {
define: { 'process.env.NODE_ENV': JSON.stringify('production') },
...clientBundleRegistration(),
// The client entry is deliberately a classic CJS script wrapped by ModuleLoader;
- // publint's ESM/CJS default-export heuristic is inapplicable.
+ // publint's ESM/CJS default-export heuristic is inapplicable. This CJS is
+ // intentional and NOT a Node-published format: the bundle runs inside the DSH Web
+ // ModuleLoader (Chromium webview). tsdown's warnLegacyCJS only fires when the
+ // resolved target claims Node >= 22.12 (its default inference from
+ // `engines.node`), so packages declaring `engines.node` keep all warnings
+ // CI-fatal by pinning an explicit client `target` (ES/web) via `client.target`
+ // instead of disabling `failOnWarn`.
publint: false,
dts: false,
sourcemap: true,
diff --git a/packages/dsh-tauri-turnrewind-ts/test/ci-build.test.js b/packages/dsh-tauri-turnrewind-ts/test/ci-build.test.js
new file mode 100644
index 00000000..e16b2913
--- /dev/null
+++ b/packages/dsh-tauri-turnrewind-ts/test/ci-build.test.js
@@ -0,0 +1,32 @@
+import { spawnSync } from 'node:child_process'
+import { existsSync } from 'node:fs'
+import { resolve } from 'node:path'
+import { describe, expect, it } from 'vitest'
+
+// Regression: `CI=true tsdown` used to exit 1 with
+// "ERROR We recommend using the ESM format instead of CommonJS" because tsdown
+// inferred target node22.15.0 from this package's `engines.node` and its default
+// `failOnWarn: 'ci-only'` escalated warnLegacyCJS into a CI failure. The client
+// half pins an explicit es2022 target (see tsdown.config.ts); this test guards
+// the whole contract: CI mode must build cleanly, the legacy-CJS notice must be
+// gone at the source, and dist/client.cjs (the DSH ModuleLoader CJS contract)
+// must still be produced.
+const pkgDir = resolve(import.meta.dirname, '..')
+const tsdownCli = resolve(pkgDir, 'node_modules/tsdown/dist/run.mjs')
+
+describe('cI build (tsdown failOnWarn: ci-only)', () => {
+ it('builds with CI=true without the legacy-CJS error and keeps client.cjs', () => {
+ const result = spawnSync(process.execPath, [tsdownCli], {
+ cwd: pkgDir,
+ env: { ...process.env, CI: 'true' },
+ encoding: 'utf8',
+ timeout: 90_000,
+ windowsHide: true,
+ })
+
+ expect(result.status).toBe(0)
+ expect(result.stderr).not.toContain('We recommend using the ESM format')
+ expect(result.stdout).toContain('Build complete')
+ expect(existsSync(resolve(pkgDir, 'dist/client.cjs'))).toBe(true)
+ }, 120_000)
+})
diff --git a/packages/dsh-tauri-turnrewind-ts/tsdown.config.ts b/packages/dsh-tauri-turnrewind-ts/tsdown.config.ts
index db7f42c0..58ba9a4f 100644
--- a/packages/dsh-tauri-turnrewind-ts/tsdown.config.ts
+++ b/packages/dsh-tauri-turnrewind-ts/tsdown.config.ts
@@ -1,3 +1,14 @@
import { defineDshConfig } from 'dsh-tauri-tsdown'
-export default defineDshConfig()
+export default defineDshConfig({
+ // The client half runs inside the DSH Web ModuleLoader (Chromium webview),
+ // never on Node. Without an explicit target, tsdown infers node22.15.0 from
+ // this package's `engines.node`, and warnLegacyCJS then flags the intentional
+ // CJS client bundle as a legacy CommonJS package — escalated to an
+ // "We recommend using the ESM format" ERROR (exit 1) by tsdown's default
+ // `failOnWarn: 'ci-only'` under CI=true. Pin the client bundle to its real
+ // runtime floor (es2022; WebView2 is evergreen Chromium) so the CJS contract
+ // stays intact and the warning is corrected at the source. The host half
+ // keeps its Node target, and every other warning remains CI-fatal.
+ client: { target: 'es2022' },
+})