Skip to content

fix: avoid temporal optimize deps dirs - #12582

Merged
patak-cat merged 5 commits into
mainfrom
fix/avoid-temporal-deps-dirs
Mar 26, 2023
Merged

patak-cat merged 5 commits into
mainfrom
fix/avoid-temporal-deps-dirs

Conversation

@patak-cat

@patak-cat patak-cat commented Mar 25, 2023 •

Copy link
Copy Markdown
Member

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

@bolt-new-by-stackblitz

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown
Member Author

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

@patak-cat

Copy link
Copy Markdown
Member Author

Looks like CI is faster in Windows now 👀

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

@sun0day sun0day Mar 26, 2023 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@bluwy bluwy left a comment

Copy link
Copy Markdown
Member

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!

@sapphi-red

Copy link
Copy Markdown
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-cat

Copy link
Copy Markdown
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-cat
patak-cat requested a review from bluwy March 26, 2023 09:16
@patak-cat
patak-cat merged commit ff92f2f into main Mar 26, 2023
@patak-cat
patak-cat deleted the fix/avoid-temporal-deps-dirs branch March 26, 2023 10:56
@mattydono

Copy link
Copy Markdown

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

@patak-cat

Copy link
Copy Markdown
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