Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vite/rolldown.dts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const ignoreConfusingTypeNames = [
// temporary variables for types
'parseAst$1',
'parseAstAsync$1',
'resolveTsconfig$1',
]

/**
Expand Down
29 changes: 29 additions & 0 deletions packages/vite/src/node/__tests__/tsconfig.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, test } from 'vitest'
import { resolveTsconfig } from '../tsconfig'

const fixtureDir = path.resolve(
fileURLToPath(import.meta.url),
'../plugins/fixtures/oxc-tsconfigs',
)

describe('resolveTsconfig', () => {
test('resolves the nearest tsconfig for a file', () => {
const result = resolveTsconfig(
path.join(fixtureDir, 'target-es2022', 'index.ts'),
)
expect(result).not.toBeNull()
expect(result!.tsconfig.compilerOptions?.target).toBe('es2022')
expect(
result!.tsconfigFilePaths.some((p) => p.endsWith('tsconfig.json')),
).toBe(true)
})

test('returns null when no tsconfig is found', () => {
const root = path.parse(process.cwd()).root
expect(resolveTsconfig(path.join(root, 'vite-no-tsconfig', 'a.ts'))).toBe(
null,
)
})
})
1 change: 1 addition & 0 deletions packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export { createIdResolver } from './idResolver'
export { formatPostcssSourceMap, preprocessCSS } from './plugins/css'
export { transformWithEsbuild } from './plugins/esbuild'
export { transformWithOxc } from './plugins/oxc'
export { resolveTsconfig, type ResolveTsconfigResult } from './tsconfig'
export { buildErrorMessage } from './server/middlewares/error'

export {
Expand Down
16 changes: 16 additions & 0 deletions packages/vite/src/node/tsconfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { resolveTsconfig as resolveTsconfigImpl } from 'rolldown/experimental'

export type ResolveTsconfigResult = NonNullable<
ReturnType<typeof resolveTsconfigImpl>
>

/**
* Resolve the `tsconfig.json` that applies to a file, using the same resolution
* Vite uses internally. Returns the merged tsconfig and the list of config files
* involved (useful for watching), or `null` if none is found.
*/
export function resolveTsconfig(
filename: string,
): ResolveTsconfigResult | null {
return resolveTsconfigImpl(filename)
}
Loading