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

fix: avoid temporal optimize deps dirs #12582

Merged
merged 5 commits into from Mar 26, 2023
Merged

Conversation

patak-dev
Copy link
Member

@patak-dev patak-dev commented Mar 25, 2023

Fixes #9986

Description

Use write: false when optimizing deps, and directly write files to the final deps dir when committed.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@stackblitz
Copy link

stackblitz bot commented Mar 25, 2023

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

@patak-dev patak-dev marked this pull request as ready for review March 25, 2023 16:52
@patak-dev patak-dev added the p3-significant High priority enhancement (priority) label Mar 25, 2023
@patak-dev
Copy link
Member Author

Almost there, windows is having issues. Probably missing a normalizePath

@patak-dev
Copy link
Member Author

Looks like CI is faster in Windows now 👀

files.push(
fsp.writeFile(
path.resolve(depsCacheDir, 'package.json'),
JSON.stringify({ type: 'module' }),
Copy link
Member

@sun0day sun0day Mar 26, 2023

Choose a reason for hiding this comment

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

Would there be duplicated calls of JSON.stringify?

Copy link
Member

Choose a reason for hiding this comment

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

I feel like doing a writeFile instead of checking existence before writing would be a bit faster, though perf doesn't matter a lot I think since these optimized files are only served to the browser.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sun0day changed it to be directly a string so we can have the same formatting as other files in the deps cache. We could use JSON.stringify({ type: 'module' }, null, 2) + '\n' too but the direct string feels better here.

@bluwy I added the check because I think the normal flow would be that this file is already there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I took that back after the latest changes as it was making the code more complex and I don't think it would make a diff

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Tested locally and works great!

packages/vite/src/node/optimizer/index.ts Outdated Show resolved Hide resolved
packages/vite/src/node/optimizer/index.ts Outdated Show resolved Hide resolved
@sapphi-red
Copy link
Member

I found a trivial bug in main branch.

v4.3.0-beta.0: .vite/deps doesn't get keeped unless the page is accessed at least once.
main: .vite/deps_temp_hash is kept and not renamed unless the page is accessed at least once. If you run vite --force multiple times without accessing browser, you'll have multiple .vite/deps_temp_hash.

I guess this PR will fix this bug indirectly. (haven't taken a look yet)

@patak-dev
Copy link
Member Author

Yes, that will be fixed. Any time you were killing the process while processing (or before committing), the temp dir will end up stale.

@patak-dev patak-dev requested a review from bluwy March 26, 2023 09:16
packages/vite/src/node/optimizer/index.ts Outdated Show resolved Hide resolved
packages/vite/src/node/optimizer/index.ts Outdated Show resolved Hide resolved
packages/vite/src/node/optimizer/index.ts Outdated Show resolved Hide resolved
@patak-dev patak-dev merged commit ff92f2f into main Mar 26, 2023
18 checks passed
@patak-dev patak-dev deleted the fix/avoid-temporal-deps-dirs branch March 26, 2023 10:56
@mattydono
Copy link

It looks like the change log could do with updating: 4.3.0-beta.0 (2023-03-23)

@patak-dev
Copy link
Member Author

@mattydono this PR isn't released yet. Only commits that have been in a release are populated in the changelog. We're also reverting back to temporal dirs so we may clean it up #12622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-significant High priority enhancement (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENOENT: no such file or directory, rename ... deps_temp
5 participants