Skip to content

Add wrangler.toml support in pages deploy#5377

Merged
CarmenPopoviciu merged 3 commits intomainfrom
carmen/pages-config-deploy
Apr 3, 2024
Merged

Add wrangler.toml support in pages deploy#5377
CarmenPopoviciu merged 3 commits intomainfrom
carmen/pages-config-deploy

Conversation

@CarmenPopoviciu
Copy link
Copy Markdown
Contributor

@CarmenPopoviciu CarmenPopoviciu commented Mar 26, 2024

What this PR solves / how to test

This PR adds wrangler.toml support in pages deploy

♫♫♫

Starlight, star bright
First star I see tonight
Starlight, star bright
Make everything alright

♫♫♫

Author has addressed the following

Test Plan 🚀

Apart from unit/integration/fixtures tests, this PR was manually tested based on the following test plan:

  • pages deploy [<directory>] should still work correctly, for Pages projects without a config file
npx wrangler pages deploy public
Screenshot 2024-03-28 at 11 00 36 Screenshot 2024-03-28 at 11 02 07
  • pages deploy should pick up configuration from wrangler.toml, if file exists and pages_build_output_dir is specified
# wrangler.toml

pages_build_output_dir = "./public"
name = "pages-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "celebrate"
// /functions/celebrate.ts

return new Response(
  `[/celebrate]:\n` +
   `🎵 🎵 🎵\n` +
   `You can turn this world around\n` +
   `And bring back all of those happy days\n` +
   `Put your troubles down\n` +
   `It's time to ${context.env.VAR2}\n` +
   `🎵 🎵 🎵`
);
npx wrangler pages deploy
Screenshot 2024-03-31 at 20 15 41 Screenshot 2024-03-31 at 20 17 49
  • pages deploy [<directory>] should warn and ignore the wrangler.toml file, if it exists but pages_build_output_dir is not specified
# wrangler.toml

name = "pages-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "celebrate"
// /functions/celebrate.ts

return new Response(
  `[/celebrate]:\n` +
   `🎵 🎵 🎵\n` +
   `You can turn this world around\n` +
   `And bring back all of those happy days\n` +
   `Put your troubles down\n` +
   `It's time to ${context.env.VAR2}\n` +
   `🎵 🎵 🎵`
);
npx wrangler pages deploy
Screenshot 2024-03-31 at 23 46 18 Screenshot 2024-03-31 at 23 46 43
  • pages deploy with valid wrangler.toml should deploy to new projects
# wrangler.toml

pages_build_output_dir = "./public"
name = "pages-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "celebrate"
// /functions/celebrate.ts

return new Response(
  `[/celebrate]:\n` +
   `🎵 🎵 🎵\n` +
   `You can turn this world around\n` +
   `And bring back all of those happy days\n` +
   `Put your troubles down\n` +
   `It's time to ${context.env.VAR2}\n` +
   `🎵 🎵 🎵`
);
npx wrangler pages deploy
Screenshot 2024-03-31 at 20 15 31 Screenshot 2024-03-31 at 20 15 41 Screenshot 2024-03-31 at 20 17 49
  • pages deploy with valid wrangler.toml should deploy to existing projects
# wrangler.toml

pages_build_output_dir = "./public"
name = "pages-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "celebrate"
// /functions/celebrate.ts

return new Response(
  `[/celebrate]:\n` +
   `🎵 🎵 🎵\n` +
   `You can turn this world around\n` +
   `And bring back all of those happy days\n` +
   `Put your troubles down\n` +
   `It's time to ${context.env.VAR2}\n` +
   `🎵 🎵 🎵`
);
npx wrangler pages deploy
Screenshot 2024-03-31 at 21 55 17 Screenshot 2024-03-31 at 21 57 31
  • pages deploy should fail if no [<directory>] argument was passed and configuration file does not specify pages_build_output_dir
# wrangler.toml

name = "pages-functions-with-config-file-app"
compatibility_date = "2024-01-01"
npx wrangler pages deploy
Screenshot 2024-03-31 at 23 54 33
  • pages deploy should fail if configuration file is not valid
# wrangler.toml

pages_build_output_dir = "./public"
name = "pages-functions-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "celebrate"

[kv_namespaces]
namespace_origin = "invalid"

[env.staging]
[env.staging.vars]
VAR1 = "test"
npx wrangler pages deploy
Screenshot 2024-03-31 at 23 58 59 Screenshot 2024-03-31 at 23 58 02
  • pages deploy should always deploy to the Pages project specified by the top-level name configuration field, regardless of the corresponding env-level configuration
# wrangler.toml

pages_build_output_dir = "./public"
name = "pages-functions-with-config-file-app"
compatibility_date = "2024-01-01"

[env.production]
name = "pages-functions-with-config-file-app-production"
npx wrangler pages deploy
Screenshot 2024-04-01 at 17 28 37 Screenshot 2024-04-01 at 17 28 52
  • pages deploy should fail if top-level name configuration field is not specified, irrespective of the targeted environment, and whether that environment's configuration specififes the name field
# wrangler.toml

pages_build_output_dir = "./public"
compatibility_date = "2024-01-01"

[env.production]
name = "pages-functions-with-config-file-app"
npx wrangler pages deploy --branch=main
Screenshot 2024-04-01 at 17 35 51
  • pages deploy --branch=<name_of_production_branch> should apply production specific configuration when deploying to the production environment, if [env.production] is specified in wrangler.toml
#wrangler.toml

pages_build_output_dir = "./public"
name = "pages-functions-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "celebrate"

[env.preview]
[env.preview.vars]
VAR1 = "🌤️ holiday 🌤️"
VAR2 = "🤸🏻 celebrate 🤸🏻"

[env.production]
[env.production.vars]
VAR1 = "🏖️ holiday 🏖️"
VAR2 = "🥳 celebrate 🥳"
npx wrangler pages deploy --branch=main
Screenshot 2024-04-01 at 00 26 42 Screenshot 2024-04-01 at 00 27 00 Screenshot 2024-04-01 at 00 31 42
  • pages deploy --branch=<name_of_production_branch> should fallback to top-level configuration when deploying to the production environment, if [env.production] is not specified in wrangler.toml
# wrangler.toml

pages_build_output_dir = "./public"
name = "pages-functions-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "🪩 celebrate 🪩"
npx wrangler pages deploy --branch=staging
Screenshot 2024-04-01 at 00 43 08 Screenshot 2024-04-01 at 00 43 24 Screenshot 2024-04-01 at 00 43 33
  • pages deploy --branch=<name_of_non_prod_branch> should apply preview specific configuration when deploying to the preview environment, if [env.preview] is specified in wrangler.toml
# wrangler.toml

pages_build_output_dir = "./public"
name = "pages-functions-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "celebrate"

[env.preview]
[env.preview.vars]
VAR1 = "🌤️ holiday 🌤️"
VAR2 = "🤸🏻 celebrate 🤸🏻"

[env.production]
[env.production.vars]
VAR1 = "🏖️ holiday 🏖️"
VAR2 = "🥳 celebrate 🥳"
npx wrangler pages deploy --branch=staging
Screenshot 2024-04-01 at 00 36 24 Screenshot 2024-04-01 at 00 34 06 Screenshot 2024-04-01 at 00 31 50
  • pages deploy --branch=<name_of_non_prod_branch> should fallback to top-level configuration when deploying to the preview environment, if [env.preview] is not specified in wrangler.toml
# wrangler.toml

pages_build_output_dir = "./public"
name = "pages-functions-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "🪩 celebrate 🪩"
npx wrangler pages deploy --branch=staging
Screenshot 2024-04-01 at 00 40 23 Screenshot 2024-04-01 at 00 40 43 Screenshot 2024-04-01 at 00 40 55
  • pages deploy should apply inheritable environment config specified in wrangler.toml, specific to the environment targeted by the deployment
  • pages deploy should apply non-inheritable environment config specified in wrangler.toml, specific to the environment targeted by the deployment
  • pages deploy should override wrangler.toml config with cmd line args
# wrangler.toml

pages_build_output_dir = "./dist"
name = "pages-functions-app"
compatibility_date = "2024-01-01"
npx wrangler pages deploy public --project-name=pages-functions-with-config-file-app
Screenshot 2024-04-01 at 17 56 12 Screenshot 2024-04-01 at 17 56 33
  • pages deploy should allow existing Pages projects to opt in using a config file
  • deploy new project without wrangler.toml
npx wrangler pages deploy public --project-name=pages-functions-with-config-file-app
Screenshot 2024-04-01 at 17 49 04 Screenshot 2024-04-01 at 17 48 47
  • add wrangler.toml file and re-deploy
# wrangler.toml

pages_build_output_dir = "./public"
name = "pages-functions-with-config-file-app"
compatibility_date = "2024-01-01"

[vars]
VAR1 = "holiday"
VAR2 = "celebrate"
npx wrangler pages deploy
Screenshot 2024-04-01 at 17 52 19 Screenshot 2024-04-01 at 17 52 34
  • pages deploy should allow existing Pages projects to opt out of using a config file

@CarmenPopoviciu CarmenPopoviciu requested review from a team as code owners March 26, 2024 08:04
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 26, 2024

🦋 Changeset detected

Latest commit: 2bde607

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

This PR includes changesets to release 2 packages
Name Type
wrangler Minor
@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

Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 26, 2024

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8541501264/npm-package-wrangler-5377

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5377/npm-package-wrangler-5377

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8541501264/npm-package-wrangler-5377 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8541501264/npm-package-create-cloudflare-5377 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8541501264/npm-package-cloudflare-kv-asset-handler-5377
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8541501264/npm-package-miniflare-5377
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8541501264/npm-package-cloudflare-pages-shared-5377
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8541501264/npm-package-cloudflare-vitest-pool-workers-5377

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.44.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240329.0
workerd 1.20240329.0 1.20240329.0
workerd --version 1.20240329.0 2024-03-29

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/api/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
@petebacondarwin
Copy link
Copy Markdown
Contributor

@CarmenPopoviciu - just realised that we can't error when wrangler.toml has no pages_output_dir field because that would break the flow of projects that currently have a wrangler.toml in place for other purpose (such as getPlatformProxy()). Instead we should warn and continue, ignoring the wrangler.toml config.

@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/pages-config-deploy branch 3 times, most recently from 8f8be4c to 05c9235 Compare March 27, 2024 19:12
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 27, 2024

Codecov Report

Attention: Patch coverage is 67.81609% with 28 lines in your changes are missing coverage. Please review.

Project coverage is 72.28%. Comparing base (489b9c5) to head (2bde607).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #5377   +/-   ##
=======================================
  Coverage   72.28%   72.28%           
=======================================
  Files         331      331           
  Lines       17004    17062   +58     
  Branches     4328     4352   +24     
=======================================
+ Hits        12291    12333   +42     
- Misses       4713     4729   +16     
Files Coverage Δ
packages/wrangler/src/config/index.ts 88.65% <100.00%> (+0.05%) ⬆️
packages/wrangler/src/pages/dev.ts 29.81% <100.00%> (ø)
packages/wrangler/src/api/pages/deploy.tsx 88.88% <96.00%> (+2.52%) ⬆️
packages/wrangler/src/config/validation-pages.ts 97.91% <83.33%> (+0.24%) ⬆️
packages/wrangler/src/pages/deploy.tsx 49.57% <50.94%> (+1.89%) ⬆️

... and 1 file with indirect coverage changes

Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dario-piotrowicz we kept this as a warning, but I changed the message based on our conversation. Let me know what you think of it <3

@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/pages-config-deploy branch from 05c9235 to 81b21ec Compare March 28, 2024 16:22
const accountId = await requireAuth(configCache);

projectName ??= config.project_name;
let projectName =
Copy link
Copy Markdown
Contributor Author

@CarmenPopoviciu CarmenPopoviciu Mar 28, 2024

Choose a reason for hiding this comment

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

// TODO @CarmenPopoviciu
if the project specified by wrangler.toml's name does not exist, pages deploy will fail, because we're attempting to get the project here. In combination with the name field being mandatory, and Pages toml validation throwing an err if field is missing, this basically puts us in the position where we can not deploy new Pages projects with a wrangler.toml file, only existing ones.

We should instead warn that the project doesn't exist and offer users the option of us creating the project for them, like we do for projects without a config file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed, YAY 🎉 😍 ! Will add some comprehensive tests tomorrow and link here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

turns out writing tests for interactive pages deploy is not as trivial as I thought, mainly because we're doing some funky prompting that is hard to mock. Will address this as a followup

@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/pages-config-deploy branch from 81b21ec to 73bef08 Compare April 1, 2024 18:06
@CarmenPopoviciu CarmenPopoviciu changed the title [WIP] Add wrangler.toml support in pages deploy Add wrangler.toml support in pages deploy Apr 1, 2024
Comment thread packages/wrangler/src/api/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/config/index.ts Outdated
Comment thread packages/wrangler/src/__tests__/pages/deploy.test.ts Outdated
Comment thread packages/wrangler/src/__tests__/pages/deploy.test.ts Outdated
@CarmenPopoviciu CarmenPopoviciu added the ldw-exempt PRs marked with this label can be included in releases during LDW. label Apr 1, 2024
@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/pages-config-deploy branch from 73bef08 to e1902e3 Compare April 1, 2024 18:56
Comment thread packages/wrangler/src/pages/dev.ts
Comment thread packages/wrangler/src/api/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/config/index.ts Outdated
Comment thread packages/wrangler/src/config/index.ts Outdated
@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/pages-config-deploy branch 2 times, most recently from 2c587bb to e945b6d Compare April 3, 2024 13:06
Copy link
Copy Markdown
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

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

One nit, but LGTM!

Comment thread packages/wrangler/src/api/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/config/validation-pages.ts Outdated
Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
Comment thread packages/wrangler/src/pages/deploy.tsx Outdated
@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/pages-config-deploy branch from e945b6d to 2bde607 Compare April 3, 2024 15:35
@CarmenPopoviciu CarmenPopoviciu merged commit 5d68744 into main Apr 3, 2024
@CarmenPopoviciu CarmenPopoviciu deleted the carmen/pages-config-deploy branch April 3, 2024 16:24
@workers-devprod workers-devprod mentioned this pull request Apr 3, 2024
@hrueger
Copy link
Copy Markdown

hrueger commented Apr 4, 2024

Hi all,
very excited for this feature 😃🎉 Is that expected to already work? I tried it yesterday right after the release and while it did guide me through updating the wrangler.toml file accordingly, created the project and uploaded the content just fine, it did not set my bindings...

PS: pages_build_output_diris missing in the json schema from the json schema store which makes usage with the Even Better Toml extension in VSCode a bit annoying 😉 (probably linked to #3166)

@petebacondarwin
Copy link
Copy Markdown
Contributor

Hey @hrueger - thanks for your interest in trying this out!

We had not released all the pieces of the backend to this last night.
The announcement (look out for a CF blog post!) later today.
Once that is out, then it should all start working.

Please do give it a full work out and report any problems you have to us as GH issues, so that we can follow up and fix.

@petebacondarwin
Copy link
Copy Markdown
Contributor

Good call on the json schema - we'll look into fixing that up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ldw-exempt PRs marked with this label can be included in releases during LDW.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants