Skip to content

feat: interactively handle wonky asset deploy commands #10016

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

Merged
merged 2 commits into from
Jul 23, 2025

Conversation

emily-shen
Copy link
Contributor

@emily-shen emily-shen commented Jul 18, 2025

Interactively handle wrangler deploys that are probably assets-only, where there is no config file found and flags are incorrect or missing.

For example:

npx wrangler deploy ./public will now ask if you meant to deploy an folder of assets only, ask for a name, set the compat date and then ask to write your choices out to wrangler.json for subsequent deployments.

npx wrangler deploy --assets=./public will now ask for a name, set the compat date and then ask to write your choices out to wrangler.json for subsequent deployments.

In non-interactive contexts, we will error as we currently do.

Out of scope (for this PR) are worker or worker and asset deploys.

Screenshot 2025-07-18 at 14 31 26
  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: self-documenting?
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: new

@emily-shen emily-shen requested a review from a team as a code owner July 18, 2025 13:33
Copy link

changeset-bot bot commented Jul 18, 2025

🦋 Changeset detected

Latest commit: 8c6c672

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

This PR includes changesets to release 3 packages
Name Type
wrangler Minor
@cloudflare/vite-plugin Major
@cloudflare/vitest-pool-workers 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

pkg-pr-new bot commented Jul 18, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@10016

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@10016

miniflare

npm i https://pkg.pr.new/miniflare@10016

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@10016

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@10016

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@10016

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@10016

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@10016

wrangler

npm i https://pkg.pr.new/wrangler@10016

commit: 8c6c672

@emily-shen emily-shen force-pushed the emily/assets-interactive-deploy branch from 2984c23 to 164b6fd Compare July 18, 2025 13:47
try {
const stats = statSync(args.script);
if (stats.isDirectory()) {
args = await handleMaybeAssetsDeployment(args);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider moving the dir check inside handleMaybeAssetsDeployment ?

Maybe comment on handleMaybeAssetsDeployment what the req are (i.e. directory)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the dir check here is correct but the signature on handleMaybeAssetsDeployment() should be something like (assetDirectory: string, args: DeployArgs) to make it clear that this function expects a directory of some kind.

const projectName = await prompt("What do you want to name your project?", {
defaultValue: process.cwd().split(path.sep).pop(),
});
args.name = projectName;
Copy link
Contributor

Choose a reason for hiding this comment

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

validate the name?

Copy link
Contributor

Choose a reason for hiding this comment

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

Will it not get validated later in the normal deploy validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll validate that the default we suggest is valid, at least.

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Jul 18, 2025
try {
const stats = statSync(args.script);
if (stats.isDirectory()) {
args = await handleMaybeAssetsDeployment(args);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the dir check here is correct but the signature on handleMaybeAssetsDeployment() should be something like (assetDirectory: string, args: DeployArgs) to make it clear that this function expects a directory of some kind.

const projectName = await prompt("What do you want to name your project?", {
defaultValue: process.cwd().split(path.sep).pop(),
});
args.name = projectName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it not get validated later in the normal deploy validation?

);

if (writeConfig) {
const configPath = path.join(process.cwd(), "wrangler.json");
Copy link
Contributor

Choose a reason for hiding this comment

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

We definitely encourage JSONC.

Moreover, we could actually create a JSONC file with comments in if we felt inclined.

Suggested change
const configPath = path.join(process.cwd(), "wrangler.json");
const configPath = path.join(process.cwd(), "wrangler.jsonc");

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to use jsonc. i can't really think of a useful comment to add though, so i might just leave it as is. since its assets only, linking to the full wrangler config docs might just cause more confusion.

@emily-shen emily-shen force-pushed the emily/assets-interactive-deploy branch from 164b6fd to 8c6c672 Compare July 23, 2025 11:21
@emily-shen emily-shen merged commit c5b291d into main Jul 23, 2025
36 of 37 checks passed
@emily-shen emily-shen deleted the emily/assets-interactive-deploy branch July 23, 2025 15:03
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants