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

Ignore Vite timestamp files by default in create-svelte templates (added to .gitignore) #7660

Merged

Conversation

Tal500
Copy link
Contributor

@Tal500 Tal500 commented Nov 15, 2022

Because why new SvelteKit users need to figure this out by themselves?

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Nov 15, 2022

🦋 Changeset detected

Latest commit: c82a99d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

I see these from time to time - what are these files about, anyway? FWIW they aren't ignored by the Vite starter templates either, so I'm hesitant to put them in there.

@bluwy
Copy link
Member

bluwy commented Nov 15, 2022

Vite bundles the config files with esbuild by default and writes them to disk to import() it. Usually it's removed after it's evaluated so it's only temporary, so I don't think we need to gitignore them (?)

@dominikg
Copy link
Member

vite creates a micro bundle of vite config to load it. thats it. they can sometimes be left as residue if the process crashes / terminates at the wrong moment. ignoring them is the right call and should be done in vite too cc @bluwy

@Tal500
Copy link
Contributor Author

Tal500 commented Nov 15, 2022

Vite bundles the config files with esbuild by default and writes them to disk to import() it. Usually it's removed after it's evaluated so it's only temporary, so I don't think we need to gitignore them (?)

Sometimes you cancel vite build process, and then they stuck there, and you may commit them by mistake (it happened also here in this repo!)
Both SvelteKit repo and my personal repos decided to ignore this files in .gitignore, so I just thought it is a consensus to ignore them.

Additional context of Vite: vitejs/vite#9470 (comment)

@dominikg
Copy link
Member

alternatively vite could instead put that file into node_modules/.vite/config.timestamp-xxx.mjs that is already ignored and the dir is used by vite for other generated things

@bluwy
Copy link
Member

bluwy commented Nov 15, 2022

Writing to a different directory would require rewriting the import paths. I think Vite should make sure the config files are removed instead on process exit to make it transparent.

@dominikg
Copy link
Member

messing with process.onExit at least used to have implications for signal handling and it only lessens the impact. you could still end up with it staged when you run git add . at the wrong point in time. If moving it to an ignored directory is not an option, these patterns here are the next best solution 🤔

@bluwy
Copy link
Member

bluwy commented Nov 15, 2022

The issue is that we don't want to leak an implementation detail into a user file though, i think deleting on process exit is probably good enough in most case to prevent another point of configuration.

@Rich-Harris
Copy link
Member

I guess the question is whether this change is likely to land in Vite any time soon? I've definitely been bitten by this in the past, adding a couple of lines to a .gitignore feels fairly harmless, but if we expect it to make it into a patch release in the next few days then it's probably not worth it

@Tal500
Copy link
Contributor Author

Tal500 commented Nov 15, 2022

Vite bundles the config files with esbuild by default and writes them to disk to import() it. Usually it's removed after it's evaluated so it's only temporary, so I don't think we need to gitignore them (?)

Can't you emulate them and pass the content of a virtual file to ESBuild instead of writing to the disk? Is this possible in ESBuild?

@Rich-Harris
Copy link
Member

IIUC the timestamped file is the output of esbuild rather than the input — it's the thing that Vite imports.

I'm personally of the view that esbuild shouldn't be involved at all here — just require vite.config.js to be a normal module that adheres to normal module rules, avoiding this whole song and dance (and preventing the spurious warnings that appear when you first start a SvelteKit project before the types have been generated), but I don't expect the Vite team to agree with me :)

@Rich-Harris
Copy link
Member

Added a note to the Vite 4 discussion proposing removing the config bundling step vitejs/vite#10570 (comment)

@bluwy
Copy link
Member

bluwy commented Nov 17, 2022

I tried to make a fix to clean the files but nodejs makes it incredibly hard to detect process exit without caveats ☹️ I would also prefer not bundling them in most case, but there will be tradeoffs and it would be a big change that we might want to defer for Vite 5. We'll be discussing this more in the next Vite team meeting though.

Can't you emulate them and pass the content of a virtual file to ESBuild instead of writing to the disk? Is this possible in ESBuild?

We are writing the result of the esbuild output to disk for nodejs to evaluate it.

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

If the change is non-trivial then I'm ok with adding these to ignore

@Rich-Harris Rich-Harris merged commit 78615fd into sveltejs:master Nov 17, 2022
@Tal500 Tal500 deleted the gitignore-vite-timestamp-in-templates branch November 17, 2022 19:30
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

5 participants