-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(runtime): minor tweaks #15904
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ export class ModuleCacheMap extends Map<string, ModuleCache> { | |
update(fsPath: string, mod: ModuleCache): this { | ||
fsPath = this.normalize(fsPath) | ||
if (!super.has(fsPath)) this.setByModuleId(fsPath, mod) | ||
else Object.assign(super.get(fsPath) as ModuleCache, mod) | ||
else Object.assign(super.get(fsPath)!, mod) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type of |
||
return this | ||
} | ||
|
||
|
@@ -50,7 +50,7 @@ export class ModuleCacheMap extends Map<string, ModuleCache> { | |
importers: new Set(), | ||
}) | ||
} | ||
return mod as ModuleCache | ||
return mod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
} | ||
|
||
override get(fsPath: string): ModuleCache { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,21 +218,20 @@ export class ViteRuntime { | |
return this.processImport(mod.exports, fetchedModule, metadata) | ||
} | ||
|
||
const getStack = () => | ||
`stack:\n${[...callstack, moduleId] | ||
.reverse() | ||
.map((p) => ` - ${p}`) | ||
.join('\n')}` | ||
|
||
let debugTimer: any | ||
if (this.debug) | ||
debugTimer = setTimeout( | ||
() => | ||
this.debug!( | ||
`[vite-runtime] module ${moduleId} takes over 2s to load.\n${getStack()}`, | ||
), | ||
2000, | ||
) | ||
if (this.debug) { | ||
debugTimer = setTimeout(() => { | ||
const getStack = () => | ||
`stack:\n${[...callstack, moduleId] | ||
.reverse() | ||
.map((p) => ` - ${p}`) | ||
.join('\n')}` | ||
Comment on lines
+224
to
+228
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this |
||
|
||
this.debug!( | ||
`[vite-runtime] module ${moduleId} takes over 2s to load.\n${getStack()}`, | ||
) | ||
}, 2000) | ||
} | ||
|
||
try { | ||
// cached module | ||
|
@@ -266,7 +265,7 @@ export class ViteRuntime { | |
this.debug?.('[vite-runtime] fetching', id) | ||
// fast return for established externalized patterns | ||
const fetchedModule = id.startsWith('data:') | ||
? ({ externalize: id, type: 'builtin' } as FetchResult) | ||
? ({ externalize: id, type: 'builtin' } satisfies FetchResult) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
: await this.options.fetchModule(id, importer) | ||
// base moduleId on "file" and not on id | ||
// if `import(variable)` is called it's possible that it doesn't have an extension for example | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,12 @@ export const ports = { | |
ssr: 9600, | ||
'ssr-deps': 9601, | ||
'ssr-html': 9602, | ||
'ssr-hmr': 9609, // not imported but used in `ssr-hmr/vite.config.js` | ||
'ssr-noexternal': 9603, | ||
'ssr-pug': 9604, | ||
'ssr-webworker': 9605, | ||
'proxy-bypass': 9606, // not imported but used in `proxy-hmr/vite.config.js` | ||
'proxy-bypass/non-existent-app': 9607, // not imported but used in `proxy-hmr/other-app/vite.config.js` | ||
'ssr-hmr': 9609, // not imported but used in `hmr-ssr/__tests__/hmr.spec.ts` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The path was not correct. |
||
'proxy-hmr': 9616, // not imported but used in `proxy-hmr/vite.config.js` | ||
'proxy-hmr/other-app': 9617, // not imported but used in `proxy-hmr/other-app/vite.config.js` | ||
'ssr-conditions': 9620, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC
OTHER_SOURCE_MAP_REGEXP.test(code)
will only betrue
once, so thiswhile
can simply beif
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be several times by mistake :P