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

__STATIC_CONTENT_MANIFEST is empty - can't list files in the Workers Site #233

Closed
ItalyPaleAle opened this issue Apr 4, 2022 · 5 comments
Labels
behaviour mismatch Different behaviour to Workers runtime
Milestone

Comments

@ItalyPaleAle
Copy link

When using Workers Site, import manifestJSON from '__STATIC_CONTENT_MANIFEST' imports a variable manifestJSON that contains the JSON manifest, encoded as string, which lists all files in the Site.

Using Miniflare, that manifest is empty.

I understand from the docs that this is by design, however there are situations where accessing the manifest is needed. My app does that to match the correct file to return (e.g. if the extension is missing)

Svelte Kit's adapter cloudflare-workers is another app (more popular/relevant than what I'm building :) ) that needs that.

Currently, this behavior is preventing me from being able to use Miniflare.

@mrbbot
Copy link
Contributor

mrbbot commented Apr 6, 2022

Hey! 👋 Thanks for raising this. As mentioned in the docs you linked, the reason I did this was to disable caching, which would serve outdated files. Wrangler solves this problem by uploading files with a content hash appended to their name.
I can think of a couple potential solutions:

  1. Don't store hashes in the manifest ({ "index.html": "index.html" }), but purge site files from the cache on reload
  2. Store hashes in the manifest ({ "index.html": "index.abcde.html" }), but remove them when performing file lookups (i.e. __STATIC_CONTENT.get("index.abcde.html") would actually lookup index.html). If we went with this option, we could add a magic string to make removing the hash easier (e.g. index.$MF_HASH:abcde$.html).

I'm tempted to go with option 1, even though I don't like the idea of deleting cached files especially with the --cache-persist flag enabled, but am open to suggestions.

@mrbbot mrbbot added the behaviour mismatch Different behaviour to Workers runtime label Apr 6, 2022
@mrbbot mrbbot added this to the 2.5.0 milestone Apr 6, 2022
@ItalyPaleAle
Copy link
Author

Thanks for responding and acknowledging the issue!

I'll be honest that I am not familiar enough with the inner workings of Wrangler. I will trust your judgement on this!

@koistya
Copy link

koistya commented May 27, 2022

@ItalyPaleAle are you passing sitePath value when initializing Miniflare?

const mf = new Miniflare({
  scriptPath: "index.js",
  sitePath: "public",
  modules: true,
});

See Cloudflare Starter Kitsite/index.ts, test/test.ts

@mrbbot mrbbot modified the milestones: 2.5.0, 2.6.0 May 27, 2022
@ItalyPaleAle
Copy link
Author

@koistya I'm using the CLI and I'm passing the --site flag.

@koistya
Copy link

koistya commented Jun 18, 2022

Oh, I see, it works with Miniflare server, but not with jest-environment-miniflare (VM linker).

I had to add a stub for __STATIC_CONTENT_MANIFEST to make it work with jest-environment-miniflare:

jest.config.js

export default {
  ...
  moduleNameMapper: {
    __STATIC_CONTENT_MANIFEST: "<rootDir>/test/manifest.ts",
  },
  ...
};

test/manifest.ts

/**
 * __STATIC_CONTENT_MANIFEST stub
 */
export default "{}";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
behaviour mismatch Different behaviour to Workers runtime
Projects
None yet
Development

No branches or pull requests

3 participants