Skip to content
Merged
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
54 changes: 0 additions & 54 deletions packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1846,60 +1846,6 @@ Repository: https://github.com/micromatch/to-regex-range

---------------------------------------

## tsconfck
License: MIT
By: dominikg
Repository: https://github.com/dominikg/tsconfck

> MIT License
>
> Copyright (c) 2021-present dominikg and [contributors](https://github.com/dominikg/tsconfck/graphs/contributors)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
>
> -- Licenses for 3rd-party code included in tsconfck --
>
> # strip-bom and strip-json-comments
> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.

---------------------------------------

## unpipe
License: MIT
By: Douglas Christopher Wilson
Expand Down
1 change: 0 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
"sirv": "^3.0.2",
"strip-literal": "^3.1.0",
"terser": "^5.46.0",
"tsconfck": "^3.1.6",
"ufo": "^1.6.3",
"ws": "^8.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export {
minifySync,
type MinifyOptions,
type MinifyResult,
} from 'rolldown/experimental'
} from 'rolldown/utils'

/** @deprecated - use `parse` instead */
export const parseAst: typeof _parseAst = _parseAst
Expand Down
65 changes: 23 additions & 42 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import path from 'node:path'
import colors from 'picocolors'
import type { RawSourceMap } from '@jridgewell/remapping'
import type { InternalModuleFormat, SourceMap } from 'rolldown'
import type { TSConfckParseResult } from 'tsconfck'
import { TSConfckCache, TSConfckParseError, parse } from 'tsconfck'
import { resolveTsconfig } from 'rolldown/experimental'
import { TsconfigCache } from 'rolldown/utils'
import type {
EsbuildLoader,
EsbuildMessage,
Expand Down Expand Up @@ -145,13 +145,19 @@ export async function transformWithEsbuild(
]
const compilerOptionsForFile: TSCompilerOptions = {}
if (loader === 'ts' || loader === 'tsx') {
try {
const { tsconfig: loadedTsconfig, tsconfigFile } =
await loadTsconfigJsonForFile(filename, config)
const result = resolveTsconfig(
filename,
getTSConfigResolutionCache(config),
)
if (result) {
const { tsconfig: loadedTsconfig, tsconfigFilePaths } = result
// tsconfig could be out of root, make sure it is watched on dev
if (watcher && tsconfigFile && config) {
ensureWatchedFile(watcher, tsconfigFile, config.root)
if (watcher && config) {
for (const tsconfigFile of tsconfigFilePaths) {
ensureWatchedFile(watcher, tsconfigFile, config.root)
}
}

const loadedCompilerOptions = loadedTsconfig.compilerOptions ?? {}

for (const field of meaningfulFields) {
Expand All @@ -160,14 +166,6 @@ export async function transformWithEsbuild(
compilerOptionsForFile[field] = loadedCompilerOptions[field]
}
}
} catch (e) {
if (e instanceof TSConfckParseError) {
// tsconfig could be out of root, make sure it is watched on dev
if (watcher && e.tsconfigFile && config) {
ensureWatchedFile(watcher, e.tsconfigFile, config.root)
}
}
throw e
}
}

Expand Down Expand Up @@ -522,47 +520,30 @@ function prettifyMessage(m: EsbuildMessage, code: string): string {
return res + `\n`
}

let globalTSConfckCache: TSConfckCache<TSConfckParseResult> | undefined
const tsconfckCacheMap = new WeakMap<
ResolvedConfig,
TSConfckCache<TSConfckParseResult>
>()
let globalTSConfigResolutionCache: TsconfigCache | undefined
const tsconfigResolutionCacheMap = new WeakMap<ResolvedConfig, TsconfigCache>()

function getTSConfckCache(config?: ResolvedConfig) {
function getTSConfigResolutionCache(config?: ResolvedConfig) {
if (!config) {
return (globalTSConfckCache ??= new TSConfckCache<TSConfckParseResult>())
return (globalTSConfigResolutionCache ??= new TsconfigCache())
}
let cache = tsconfckCacheMap.get(config)
let cache = tsconfigResolutionCacheMap.get(config)
if (!cache) {
cache = new TSConfckCache<TSConfckParseResult>()
tsconfckCacheMap.set(config, cache)
cache = new TsconfigCache()
tsconfigResolutionCacheMap.set(config, cache)
}
return cache
}

export async function loadTsconfigJsonForFile(
filename: string,
config?: ResolvedConfig,
): Promise<{ tsconfigFile: string; tsconfig: TSConfigJSON }> {
const { tsconfig, tsconfigFile } = await parse(filename, {
cache: getTSConfckCache(config),
ignoreNodeModules: true,
})
return { tsconfigFile, tsconfig }
}

export async function reloadOnTsconfigChange(
server: ViteDevServer,
changedFile: string,
): Promise<void> {
// any tsconfig.json that's added in the workspace could be closer to a code file than a previously cached one
// any json file in the tsconfig cache could have been used to compile ts
if (changedFile.endsWith('.json')) {
const cache = getTSConfckCache(server.config)
if (
changedFile.endsWith('/tsconfig.json') ||
cache.hasParseResult(changedFile)
) {
const cache = getTSConfigResolutionCache(server.config)
if (changedFile.endsWith('/tsconfig.json') || cache.size() > 0) {
Comment thread
sapphi-red marked this conversation as resolved.
server.config.logger.info(
`changed tsconfig file detected: ${changedFile} - Clearing cache and forcing full-reload to ensure TypeScript is compiled with updated config values.`,
{ clear: server.config.clearScreen, timestamp: true },
Expand All @@ -575,7 +556,7 @@ export async function reloadOnTsconfigChange(
environment.moduleGraph.invalidateAll()
}

// reset tsconfck cache so that recompile works with up2date configs
// reset the cache so that recompile works with up2date configs
cache.clear()

// reload environments
Expand Down
Loading