镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit e60c775

Browse files
chrisbbreuerclaude
andcommitted
fix(cli): use the native engine for a plain dtsx generate
With no flags the argument parser leaves --import-order as its raw default string 'bun', and the native engine only runs for the import order ['bun'], so `dtsx generate` alone fell back to the TypeScript engine. The option now goes through normalizeListOption like --entrypoints. Adds CLI tests for the no-flag native path and comma-separated --import-order patterns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d46bebb commit e60c775

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎packages/dtsx/bin/cli.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ cli
431431
keepComments: options.keepComments ?? fileConfig.keepComments ?? defaultOptions.keepComments,
432432
clean: options.clean ?? fileConfig.clean ?? defaultOptions.clean,
433433
verbose: options.verbose ?? fileConfig.verbose ?? defaultOptions.verbose,
434-
importOrder: options.importOrder || fileConfig.importOrder || defaultOptions.importOrder,
434+
importOrder: normalizeListOption(options.importOrder) ?? fileConfig.importOrder ?? defaultOptions.importOrder,
435435
dryRun: options.dryRun ?? fileConfig.dryRun ?? defaultOptions.dryRun,
436436
stats: options.stats ?? fileConfig.stats ?? defaultOptions.stats,
437437
continueOnError: options.continueOnError ?? fileConfig.continueOnError ?? defaultOptions.continueOnError,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { afterEach, describe, expect, test } from 'bun:test'
2+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
3+
import { tmpdir } from 'node:os'
4+
import { join, resolve } from 'node:path'
5+
import { nativeEngineAvailable } from '../src/native-engine'
6+
7+
const CLI_PATH = resolve(import.meta.dir, '../bin/cli.ts')
8+
const projects: string[] = []
9+
10+
/** Runs `dtsx <args>` in a fresh project holding `src/index.ts`, and returns the declaration. */
11+
function generate(source: string, args: string[]): string {
12+
const dir = mkdtempSync(join(tmpdir(), 'dtsx-cli-defaults-'))
13+
projects.push(dir)
14+
mkdirSync(join(dir, 'src'))
15+
writeFileSync(join(dir, 'src', 'index.ts'), source)
16+
const run = Bun.spawnSync([process.execPath, CLI_PATH, ...args], { cwd: dir })
17+
expect(run.exitCode).toBe(0)
18+
return readFileSync(join(dir, 'dist', 'index.d.ts'), 'utf8')
19+
}
20+
21+
afterEach(() => {
22+
for (const dir of projects.splice(0))
23+
rmSync(dir, { recursive: true, force: true })
24+
})
25+
26+
describe('dtsx generate defaults', () => {
27+
// The argument parser leaves an untouched list option as its raw default
28+
// string, so `dtsx generate` alone once passed importOrder 'bun' and skipped
29+
// the native engine, which only implements the import order ['bun'].
30+
test.skipIf(!nativeEngineAvailable())('with no flags it emits with the native engine', () => {
31+
const awaited = 'export const value = await Promise.resolve(1)\n'
32+
expect(generate(awaited, ['generate'])).toContain('export declare const value: number;')
33+
expect(generate(awaited, ['generate', '--stats'])).toContain('export declare const value: number;')
34+
})
35+
36+
test('--import-order takes comma-separated patterns', () => {
37+
const source = [
38+
`import type { BunFile } from 'bun'`,
39+
`import type { Stats } from 'node:fs'`,
40+
'export function read(file: BunFile, stats: Stats): void {}',
41+
'',
42+
].join('\n')
43+
const output = generate(source, ['generate', '--import-order', 'node:,bun'])
44+
expect(output.indexOf(`from 'node:fs'`)).toBeGreaterThanOrEqual(0)
45+
expect(output.indexOf(`from 'node:fs'`)).toBeLessThan(output.indexOf(`from 'bun'`))
46+
})
47+
})

0 commit comments

Comments
 (0)