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

perf: skip windows absolute paths for node resolve #13162

Conversation

sapphi-red
Copy link
Member

Description

I found that C:/non-existent-path goes through this part while debugging #13158.

// bare package imports, perform node resolve
if (bareImportRE.test(id)) {
const external = options.shouldExternalize?.(id)
if (
!external &&
asSrc &&
depsOptimizer &&
!options.scan &&
(res = await tryOptimizedResolve(
depsOptimizer,
id,
importer,
options.preserveSymlinks,
options.packageCache,
))
) {
return res
}
if (
targetWeb &&
options.browserField &&
(res = tryResolveBrowserMapping(
id,
importer,
options,
false,
external,
))
) {
return res
}
if (
(res = tryNodeResolve(
id,
importer,
options,
targetWeb,
depsOptimizer,
ssr,
external,
))
) {
return res
}
// node built-ins.
// externalize if building for SSR, otherwise redirect to empty module
if (isBuiltin(id)) {
if (ssr) {
if (ssrNoExternal === true) {
let message = `Cannot bundle Node.js built-in "${id}"`
if (importer) {
message += ` imported from "${path.relative(
process.cwd(),
importer,
)}"`
}
message += `. Consider disabling ssr.noExternal or remove the built-in dependency.`
this.error(message)
}
return options.idOnly ? id : { id, external: true }
} else {
if (!asSrc) {
debug?.(
`externalized node built-in "${id}" to empty module. ` +
`(imported by: ${colors.white(colors.dim(importer))})`,
)
} else if (isProduction) {
this.warn(
`Module "${id}" has been externalized for browser compatibility, imported by "${importer}". ` +
`See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`,
)
}
return isProduction
? browserExternalId
: `${browserExternalId}:${id}`
}
}
}

vite-tsconfig-paths seems to call this.resolve('C:/project/packageName'). I guess it's for tsconfig.compilerOptions.baseUrl

I'm not sure if this is worth doing. I don't have a good test case for this. I guess it would improve perf for a large project using vite-tsconfig-paths.

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.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • 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).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added p2-nice-to-have Not breaking anything but nice to have (priority) performance Performance related enhancement labels May 11, 2023
@stackblitz
Copy link

stackblitz bot commented May 11, 2023

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

@patak-dev patak-dev merged commit e640939 into vitejs:main May 13, 2023
@sapphi-red sapphi-red deleted the perf/skip-windows-absolute-paths-for-node-resolve branch May 13, 2023 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority) performance Performance related enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants