Skip to content

Commit a7e2da8

Browse files
authored
feat: track dependencies when loading config with native (#22602)
1 parent d64a1a5 commit a7e2da8

4 files changed

Lines changed: 54 additions & 5 deletions

File tree

packages/vite/LICENSE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,35 @@ Repository: https://github.com/follow-redirects/follow-redirects
990990
991991
---------------------------------------
992992

993+
## fresh-import
994+
License: MIT
995+
By: sapphi-red
996+
Repository: https://github.com/sapphi-red/fresh-import
997+
998+
> MIT License
999+
>
1000+
> Copyright (c) 2026 sapphi-red
1001+
>
1002+
> Permission is hereby granted, free of charge, to any person obtaining a copy
1003+
> of this software and associated documentation files (the "Software"), to deal
1004+
> in the Software without restriction, including without limitation the rights
1005+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1006+
> copies of the Software, and to permit persons to whom the Software is
1007+
> furnished to do so, subject to the following conditions:
1008+
>
1009+
> The above copyright notice and this permission notice shall be included in all
1010+
> copies or substantial portions of the Software.
1011+
>
1012+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1013+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1014+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1015+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1016+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1017+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1018+
> SOFTWARE.
1019+
1020+
---------------------------------------
1021+
9931022
## generic-names
9941023
License: MIT
9951024
By: Alexey Litvinov

packages/vite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"escape-html": "^1.0.3",
111111
"estree-walker": "^3.0.3",
112112
"etag": "^1.8.1",
113+
"fresh-import": "^0.2.1",
113114
"host-validation-middleware": "^0.1.4",
114115
"http-proxy-3": "^1.23.3",
115116
"launch-editor-middleware": "^2.14.1",

packages/vite/src/node/config.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@voidzero-dev/vite-task-client'
1414
import colors from 'picocolors'
1515
import picomatch from 'picomatch'
16+
import { freshImport } from 'fresh-import'
1617
import {
1718
type NormalizedOutputOptions,
1819
type OutputChunk,
@@ -2355,14 +2356,23 @@ export async function loadConfigFromFile(
23552356
}
23562357
}
23572358

2358-
async function nativeImportConfigFile(resolvedPath: string) {
2359+
async function nativeImportConfigFile(
2360+
resolvedPath: string,
2361+
): Promise<{ configExport: any; dependencies: string[] }> {
2362+
const freshImported = freshImport(pathToFileURL(resolvedPath).href)
2363+
if (freshImported) {
2364+
const { result, dependencies } = await freshImported
2365+
return {
2366+
configExport: (result as { [Symbol.toStringTag]: 'Module'; default: any })
2367+
.default,
2368+
dependencies,
2369+
}
2370+
}
2371+
23592372
const module = await import(
23602373
pathToFileURL(resolvedPath).href + '?t=' + Date.now()
23612374
)
2362-
return {
2363-
configExport: module.default,
2364-
dependencies: [],
2365-
}
2375+
return { configExport: module.default, dependencies: [] }
23662376
}
23672377

23682378
async function runnerImportConfigFile(resolvedPath: string) {

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)