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: normalize cache package dir #15546

Merged
merged 2 commits into from
Mar 12, 2024
Merged

Conversation

btea
Copy link
Collaborator

@btea btea commented Jan 9, 2024

Description

image

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.

Copy link

stackblitz bot commented Jan 9, 2024

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

patak-dev
patak-dev previously approved these changes Jan 9, 2024
@bluwy
Copy link
Member

bluwy commented Jan 10, 2024

Is there a reason to do so? It's going to affect this:

const pkgDir = path.dirname(pkgPath)
packageCache.forEach((pkg, cacheKey) => {
if (pkg.dir === pkgDir) {

There's also code that will normalize it later:

idPkgDir = resolvePackageData(
pkgName,
importer,
preserveSymlinks,
packageCache,
)?.dir
// if still null, it likely means that this id isn't a dep for importer.
// break to bail early
if (idPkgDir == null) break
idPkgDir = normalizePath(idPkgDir)

@patak-dev
Copy link
Member

I think it will be good to move to normalizing all paths in our (resolved) configs and public APIs. We have a confusing situation right now with some paths normalized and others that aren't. It would also be good to define a standard regarding trailing slashes for directories.

@btea
Copy link
Collaborator Author

btea commented Jan 10, 2024

Is there a reason to do so? It's going to affect this:

const pkgDir = path.dirname(pkgPath)
packageCache.forEach((pkg, cacheKey) => {
if (pkg.dir === pkgDir) {

I just think it's better to keep all path information formatted consistent. I did forget to edit it here, I will add it.

There's also code that will normalize it later:

idPkgDir = resolvePackageData(
pkgName,
importer,
preserveSymlinks,
packageCache,
)?.dir
// if still null, it likely means that this id isn't a dep for importer.
// break to bail early
if (idPkgDir == null) break
idPkgDir = normalizePath(idPkgDir)

It certainly seems so. However, as in the picture I provided, when debug information is output, the path at this time is not normalized.

@bluwy bluwy merged commit e030f4b into vitejs:main Mar 12, 2024
9 of 10 checks passed
@btea btea deleted the refactor/normalize-dir branch March 12, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants