-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: generate .assetsignore
file for Cloudflare deployment
#13109
base: main
Are you sure you want to change the base?
feat: generate .assetsignore
file for Cloudflare deployment
#13109
Conversation
.assetsignore
file for Cloudflare deployment
And feature added to the cloudflare adapter must be added to the cloudflare workers adapter as well |
🦋 Changeset detectedLatest commit: 3b27f87 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
I was not completely sure that the |
I misread the original issue. Does this only affect the workers adapter since it's a workers only feature? https://developers.cloudflare.com/workers/static-assets/binding/#ignoring-assets |
@@ -143,6 +143,8 @@ export default function ({ config = 'wrangler.toml', platformProxy = {} } = {}) | |||
); | |||
} | |||
|
|||
copyFileSync(`${files}/.assetsignore`, `${dirname(main)}/.assetsignore`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we would need #13072 to be merged first, then copy the .assetsignore
file to the root of the assets
folder.
https://developers.cloudflare.com/workers/static-assets/binding/#ignoring-assets
In this case, create a .assetsignore file in the root of the assets directory.
I'm also wondering if we would want to simply append / write to a file instead of copying so that a user's .assetsignore
file would be taken into consideration. Similar to
kit/packages/adapter-cloudflare/index.js
Line 69 in 01d2720
writeFileSync(`${dest}/_headers`, generate_headers(builder.getAppPath()), { flag: 'a' }); |
_headers
to the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like #13072 is in a draft state, this PR is ready to use.
The source of the .assetsignore
is https://github.com/cloudflare/workers-sdk/blob/main/packages/create-cloudflare/templates-experimental/svelte/js/static/.assetsignore They created it some way, so it makes sense to keep it the same and copy from there if updated. It is a better point to control the list of server-side-only files. Another approach is adding files like _worker.js
to the .assetsignore
once they are created, but it is probably less clear. Let me know if you have a strong opinion, I will update the PR accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is that Cloudflare's .assetsignore
file is part of a starting template, whereas we need to take into account a user having their own file. I'd recommend that we write using append mode so it's created if it doesn't exist, otherwise it writes to the existing file.
I'm also not sure copying it to main
corresponds to the root of the assets directory. Isn't it currently site.bucket
?
kit/packages/adapter-cloudflare-workers/index.js
Lines 146 to 149 in 33600ee
builder.log.minor('Copying assets...'); | |
const bucket_dir = `${site.bucket}${builder.config.kit.paths.base}`; | |
builder.writeClient(bucket_dir); | |
builder.writePrerendered(bucket_dir); |
But I'm also not sure if copying it to the bucket root would have any effect since it's part of the old Workers sites feature. cc: @petebacondarwin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a shipping update for adapter-cloudflare
only since it would work differently for adapter-cloudflare-workers
and can depend on #13072 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making .assetsignore
based on an existing one can be a good idea, but it looks like adapter-cloudflare
takes responsibility for making the right bundle for the Cloudflare deployment. I am not sure that a user can have a reason to make any non-asset file.
We can show a warning message if .assetsignore
is already present as a current workaround.
I am open to both approaches if maintainers strongly believe either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a shipping update for
adapter-cloudflare
only since it would work differently foradapter-cloudflare-workers
and can depend on #13072 ?
Yeah, I think we can probably split the Workers part into another PR.
Making
.assetsignore
based on an existing one can be a good idea, but it looks likeadapter-cloudflare
takes responsibility for making the right bundle for the Cloudflare deployment. I am not sure that a user can have a reason to make any non-asset file. We can show a warning message if.assetsignore
is already present as a current workaround. I am open to both approaches if maintainers strongly believe either way.
The main purpose of the file is to prevent certain assets from being made public. This can be desirable if the user has server only assets. I think we should append to an existing .assetsignore
file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eltigerchino I have removed the -workers
code from the PR and added .assetsignore
merging. It may be overcomplicated, and we would need to add just one file to another. Let me know your thoughts.
It definitely affects |
Co-authored-by: Tee Ming <[email protected]>
…ers" This reverts commit 0e9b1fc.
remove mention of the unaffected package
It is corresponded to cloudflare/workers-sdk#6640
Resolves #13108
This PR avoids Cloudflare deployment errors like
Uploading a Pages _worker.js file as an asset
by adding.assetsignore
file generation.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Ideally, include a test that fails without this PR but passes with it.These adapters don't appear to have tests.Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits