Skip to content
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

Merged
merged 1 commit into from Feb 14, 2024

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Feb 14, 2024

Description

Small refactors.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines, especially the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added the p1-chore Doesn't change code behavior (priority) label Feb 14, 2024
Copy link

stackblitz bot commented Feb 14, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

)
while (OTHER_SOURCE_MAP_REGEXP.test(code))
OTHER_SOURCE_MAP_REGEXP.lastIndex = 0
if (OTHER_SOURCE_MAP_REGEXP.test(code))
code = code.replace(OTHER_SOURCE_MAP_REGEXP, '')
Copy link
Member Author

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 be true once, so this while can simply be if.

Copy link
Member

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

@@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of super.get(fsPath) is ModuleCache | undefined.

@@ -50,7 +50,7 @@ export class ModuleCacheMap extends Map<string, ModuleCache> {
importers: new Set(),
})
}
return mod as ModuleCache
return mod
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This as ModuleCache is not needed because super.get(modulePath)! is already ModuleCache type.

Comment on lines +224 to +228
const getStack = () =>
`stack:\n${[...callstack, moduleId]
.reverse()
.map((p) => ` - ${p}`)
.join('\n')}`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this getStack function inside to avoid creating this function when this.debug is false.

@@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This as is not needed. Instead of satisfies, { externalize: id, type: 'builtin' as const } can be used as well. But I chose satisfies because I thought that would represent the intent more accurately.

'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`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path was not correct.

@patak-dev patak-dev added the feat: runtime Vite Runtime API label Feb 14, 2024
@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 4a76374: Open

suite result latest scheduled
analogjs success success
astro success success
histoire failure failure
ladle success success
laravel success success
marko success success
nuxt success success
nx failure failure
previewjs success success
qwik failure failure
rakkas success success
sveltekit success success
unocss success success
vike failure failure
vite-plugin-pwa success success
vite-plugin-react success success
vite-plugin-react-pages success success
vite-plugin-react-swc success success
vite-plugin-svelte success success
vite-plugin-vue success success
vite-setup-catalogue success success
vitepress success success
vitest success success

@patak-dev patak-dev merged commit 63a39c2 into vitejs:main Feb 14, 2024
11 checks passed
@sapphi-red sapphi-red deleted the refactor/runtime-cleanup branch February 15, 2024 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: runtime Vite Runtime API p1-chore Doesn't change code behavior (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants