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

manifest.json file collision #9636

Closed
7 tasks done
benmccann opened this issue Aug 11, 2022 · 16 comments · Fixed by #14230
Closed
7 tasks done

manifest.json file collision #9636

benmccann opened this issue Aug 11, 2022 · 16 comments · Fixed by #14230
Labels
breaking change p2-edge-case Bug, but has workaround or limited in scope (priority)
Milestone

Comments

@benmccann
Copy link
Collaborator

benmccann commented Aug 11, 2022

Describe the bug

If you set build.manifest: true and have a file named manifest.json in the publicDir then the manifest.json file will be overwritten.

As a framework, we can set the name of build.manifest to something else, but it's impossible to know in advance all the possible file names our users may have.

Originally reported in sveltejs/kit#5803

Reproduction

git clone [email protected]:sveltejs/kit.git
cd kit/sites/kit.svelte.dev
git reset --hard 0801e8e942534d3f6c614523f0ee4fe10b602b26
pnpm install
pnpm run dev

Visit http://localhost:5173/manifest.json in the browser and see the Vite manifest rather than the file in static/manifest.json

System Info

Vite 3.0.5

Used Package Manager

pnpm

Logs

No response

Validations

@benmccann benmccann added bug p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) labels Aug 11, 2022
@benmccann
Copy link
Collaborator Author

benmccann commented Aug 11, 2022

This file is written using Rollup's emitFile:

There are two solutions I can think of:

  • don't use emitFile so that we can write the manifest to a location outside the output directory
  • have separate output directories for the client built files and static files

As a workaround, we could potentially generate a random string and name the file something like manifest.ab432c.json. This makes it harder to locate the file, but is probably fine

It's also rather weird for this file to be located in the output directory where it will be served to users. We may end up deleting it at the end of the SvelteKit build to avoid that, but that's annoying for troubleshooting and it'd be nicer if it were located elsewhere

@benmccann benmccann added p2-edge-case Bug, but has workaround or limited in scope (priority) and removed p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) labels Aug 11, 2022
@bluwy
Copy link
Member

bluwy commented Aug 12, 2022

Perhaps we can change the default to __manifest.json instead. Writing outside of the normal build could be a good idea too, but we should probably still output within build.outDir by default to avoid surprises 🤔 I guess a downside is that it can't be read by other plugins through the generateBundle hook.

@ydcjeff
Copy link
Contributor

ydcjeff commented Aug 13, 2022

Or rather should we have a separate _vite-manifest directory. Here's what I mean:
I usually set dist/client for client build and dist/server for server build. And, I would like the manifest files inside dist/_vite-manifest with client.json (client manifest) and server.json (server manifest).

We will write the manifest directory inside the parent dir of outDir (i.e. dist if outDir is dist/client). If outDir doesn't contain a slash /, we will write the manifest directory (_vite-manifest) inside the outDir.

Problem is this is not consistent if outDir contains a slash.

Edit: it seems rollup emitFile doesn't accept relative/absolute paths.

@benmccann
Copy link
Collaborator Author

We could write the manifest with fs.writeFileSync instead of emitFile

@ydcjeff
Copy link
Contributor

ydcjeff commented Aug 13, 2022

We could write the manifest with fs.writeFileSync instead of emitFile

But that won't show up in the build log.

@benmccann
Copy link
Collaborator Author

What's the build log and why should we care about the manifest being there?

The alternative would be to file a report with Rollup and see if they'll change the behavior of emitFile

@ydcjeff
Copy link
Contributor

ydcjeff commented Aug 19, 2022

What about .vite-manifest.json? Usually, static dot files are not served by convention. And SvelteKit also doesn't serve it. Not sure about the impact on backend development tho.

@patak-dev
Copy link
Member

I like the idea of using a . prefix here. Given that we have several files, I think it would be cleaner to go with dist/.vite/manifest.json.

(cc @jessarcher @ElMassimo @brillout maybe this is interesting to you too, specially if you see an issue with us changing the default in the next major)

@patak-dev patak-dev moved this to Discussing in Team Board Aug 19, 2022
@bluwy
Copy link
Member

bluwy commented Aug 19, 2022

To confirm, we probably want to output dist/client/.vite/manifest.json instead so it stays within the outDir? Not so sure about writing outside of outDir yet even if we can support it 🤔

@patak-dev
Copy link
Member

@bluwy yes, I think we should keep it in the outDir. I think it is easier to handle the build if all the artifacts end up in a single folder. I'm not sure why you added the extra /client there though, it that a typo?

@brillout
Copy link
Contributor

How about this?

Without SSR:

${outDir}/client/
${outDir}/client-manifest.json

With SSR:

${outDir}/client/
${outDir}/client-manifest.json
${outDir}/server/
${outDir}/server-manifest.json

This means Vite always writes the client to ${outDir}/client/, even if the app doesn't have any SSR.

I know that some will find it "ugly" (because is some cases the extra client/ directory is unnecessary), but I believe the advantages to significantly outweight this slight aesthetic drawback.

@bluwy
Copy link
Member

bluwy commented Aug 19, 2022

@bluwy yes, I think we should keep it in the outDir. I think it is easier to handle the build if all the artifacts end up in a single folder. I'm not sure why you added the extra /client there though, it that a typo?

Oh I added the /client since that's the usual convention for manifest in client build + ssr, since I thought you might be implying that we output in dist/client, but emit the file outside dist/client.

This means Vite always writes the client to ${outDir}/client/, even if the app doesn't have any SSR.

This could be tricky with the build.emptyOutDir option though, unless we want the user to turn that option off for ssr case.

@patak-dev
Copy link
Member

I was thinking of only one top-level hidden folder for Vite artifacts:

dist/.vite/manifest.json
dist/.vite/ssr-manifest.json

And maybe others in the future. This is independent of the way users do their dist setup.

@ydcjeff
Copy link
Contributor

ydcjeff commented Aug 19, 2022

I agree with the idea of @patak-dev using .vite. And I think those manifest files are only the files generated by Vite, and the rest of the output are from user's code, so it makes sense to put them under .vite.

I also think .vite should be written at the same level (not inside) of outDir if it contains a slash, otherwise directly inside outDir.

  • outDir: dist

    • dist/.vite
    • dist/assets
  • outDir: dist/client

    • dist/.vite
    • dist/client
  • outDir: .svelte-kit/output/client

    • .svelte-kit/output/.vite
    • .svelte-kit/output/client

It might be confusing at first, but the output directories looks good tho.

@ElMassimo
Copy link
Contributor

ElMassimo commented Aug 19, 2022

Making that exception when it contains a slash might make it harder for tooling to infer the correct location.


I prefer the simpler proposal of using ${outDir}/.vite/manifest.json, which would make it easier for the ecosystem to upgrade:

  • Look for ${outDir}/.vite/manifest.json:
    • If the file exists (vite@4), use it
    • If it doesn't exist (vite@3), look for the manifest in the old location, ${outDir}/manifest.json

@patak-dev
Copy link
Member

We discussed this issue with the team and we think it is a good idea to move forward with scoping vite build artifacts to a new .vite folder:

dist/.vite/manifest.json
dist/.vite/ssr-manifest.json

We should do this in Vite 5 to avoid disruption in the ecosystem. But projects could start configuring the manifest name already to be .vite/manifest.json.

A side effect of this change could be that some servers are going to refuse to serve these files. We see this as a positive outcome (it could avoid the need for manually deleting these files), but the ecosystem as a whole should test that this change doesn't have other unintended consequences.

@patak-dev patak-dev added this to the 5.0 milestone Feb 23, 2023
@patak-dev patak-dev moved this from P2 - 5 to Approved in Team Board Feb 23, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking change p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants