Conversation
|
|
packages/vite/src/node/config.ts
Outdated
| // check and clear legacy Tmp files | ||
| const fileBaseName = path.basename(fileName) | ||
| const fileDir = path.dirname(fileName) | ||
| const timestampFiles = (await fsp.readdir(fileDir)).filter(name=>name.includes(`${fileBaseName}.timestamp-`)) | ||
| timestampFiles.forEach(name=>{ | ||
| fs.unlink(path.resolve(fileDir,name), () => { }); | ||
| }) |
There was a problem hiding this comment.
Two vite processes may be executed using different cache dirs on the same folder at the same time so this may delete a file while it is being used. Maybe we should move the generation of the file to be in ${cacheDir}/temp/${fileNameTmp} so we don't need the clean-up.
There was a problem hiding this comment.
That's a good idea. I'll try to make some modifications.
There was a problem hiding this comment.
When I tried to move the file generation to the ${cacheDir} directory, I found that the value of cacheDir could not be obtained in the loadConfigFromBundledFile method. Therefore, I considered whether it was possible to import directly in base64 format without using a temporary file
|
I think this could work better! I don't see limits affecting using base64 to import the file. Let's queue this for Vite 4.4 just to be on the safe side, and also to give others the opportunity to review the new approach. |
bluwy
left a comment
There was a problem hiding this comment.
This is actually pretty smart. Looking forward to testing this out.
|
are there any downsides to this like extra memory overhead for the b64 string or super strange errors that reference it instead of the config file? |
|
That's a good point @dominikg This is how errors look right now in main: This is the same error after this PR: So if we want to do the change, we'll need to catch the error and rewrite it. Would that still be ok? |
|
As long as we have the |
|
The |
|
I think we can definitely improve those, though editing error stacktraces is always a bit risky. But maybe we can improve that later and get this in first since it helps to remove the temporary file (which I've seen from time-to-time) |
|
I tried this method in an earlier attempt to fix this temp file issue, but ran into the problem of relative import specifiers not working because when node loads a file from a
So I think this method is affected as well. Not that I'd use relative imports in a vite config, but some people surely do. I think VM modules would be the proper solution. |
|
I also tried using VM to solve it, but I don't know what to do. |
|
@silverwind if you can reproduce the issue you mentioned, would you share a reproduction that isn't working with this PR so we have it as a reference here? |
|
If it's true that you rewrite relative paths already and you have test cases confirming relative paths work in both static and dynamic I don't have anything to share, it was just local experimenation that I never commited anywhere. |
|
@patak-dev I don't know how to rewrite the errorstack in order to get line/column and ensure security...... I may be make modification like this: |
|
@s10y10 I think we don't need to support line/column for now. What you propose sounds good 👍🏼 |
|
With this now reverted do we have any other plans to address the temporary file issue? This completely prevents the ability to use vite on limited filesystems |
|
@OllysCoding you can workaround it by using a |
|
if y'all are still having issues just recode the entire thing...painful but it normally starts whenever you start a project and is hard to miss, idk why it happened but it's not a common bug |
If node_modules is not writable, loadConfigFromBundledFile fails to write its temp file and vite aborts with an exception. This was previously fixed in vitejs#13269, but was reverted after several reports of failure to load config with relative imports (see vitejs#13631 and vitejs#13730). Instead of replacing the current code, try to load from string only as a workaround, when the directory doesn't exist. This should solve the case of unwritable node_modules when relative imports are not used without breaking anything that works.
If node_modules is not writable, loadConfigFromBundledFile fails to write its temp file and vite aborts with an exception. This was previously fixed in vitejs#13269, but was reverted after several reports of failure to load config with relative imports (see vitejs#13631 and vitejs#13730). Instead of replacing the current code, try to load from string only as a workaround, when the directory doesn't exist. This should solve the case of unwritable node_modules when relative imports are not used without breaking anything that works.
If node_modules is not writable, loadConfigFromBundledFile fails to write its temp file and vite aborts with an exception. This was previously fixed in vitejs#13269, but was reverted after several reports of failure to load config with relative imports (see vitejs#13631 and vitejs#13730). Instead of replacing the current code, try to load from string only as a workaround, when the directory doesn't exist. This should solve the case of unwritable node_modules when relative imports are not used without breaking anything that works.
If node_modules is not writable, loadConfigFromBundledFile fails to write its temp file and vite aborts with an exception. This was previously fixed in vitejs#13269, but was reverted after several reports of failure to load config with relative imports (see vitejs#13631 and vitejs#13730). Instead of replacing the current code, try to load from string only as a workaround, when the directory doesn't exist. This should solve the case of unwritable node_modules when relative imports are not used without breaking anything that works.
Description
Fixes #13267
Fixes #9470
Check and clean temporary files every time loadConfigFromBundledFile is executed.
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).