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

feat(wrangler): Implement environment inheritance for Pages configuration #5234

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

CarmenPopoviciu
Copy link
Contributor

@CarmenPopoviciu CarmenPopoviciu commented Mar 12, 2024

What this PR solves / how to test

For Pages, Wrangler will not require both of supported named environments ("preview" | "production") to be explicitly defined in the config file. If either [env.production] or [env.preview] is left unspecified, Wrangler will use the top-level environment when targeting that named Pages environment.

Author has addressed the following

@CarmenPopoviciu CarmenPopoviciu requested a review from a team as a code owner March 12, 2024 19:44
Copy link

changeset-bot bot commented Mar 12, 2024

🦋 Changeset detected

Latest commit: 338c044

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

Copy link
Contributor

github-actions bot commented Mar 12, 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/8356206987/npm-package-wrangler-5234

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

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

Or you can use npx with this latest build directly:

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

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


wrangler@3.35.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240314.0
workerd 1.20240314.0 1.20240314.0
workerd --version 1.20240314.0 2024-03-14

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

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.68%. Comparing base (93150aa) to head (338c044).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5234      +/-   ##
==========================================
+ Coverage   71.64%   71.68%   +0.03%     
==========================================
  Files         312      313       +1     
  Lines       16217    16230      +13     
  Branches     4149     4151       +2     
==========================================
+ Hits        11619    11634      +15     
+ Misses       4598     4596       -2     
Files Coverage Δ
.../src/__tests__/helpers/generate-wrangler-config.ts 100.00% <100.00%> (ø)
packages/wrangler/src/config/config.ts 100.00% <ø> (ø)
packages/wrangler/src/config/validation.ts 90.12% <100.00%> (+0.02%) ⬆️

... and 5 files with indirect coverage changes

@CarmenPopoviciu CarmenPopoviciu changed the title [WIP] feat(wrangler): Implement environment inheritance for Pages feat(wrangler): Implement environment inheritance for Pages Mar 17, 2024
@CarmenPopoviciu CarmenPopoviciu changed the title feat(wrangler): Implement environment inheritance for Pages feat(wrangler): Implement environment inheritance for Pages configuration Mar 17, 2024
})
);

/*======================================*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just calling this test out to highlight that this happens because we do the Pages-specific validation after normalizeAndValidateConfig(). But in an e2e flow, this unsupported named env will fail Pages validation and wrangler will err out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// TODO @CarmenPopoviciu add a comment to explain the above, if we decide to keep this test as part of the suite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

comments added ✅

} from "./helpers/generate-wrangler-config";
import type { RawConfig, RawEnvironment } from "../config";

describe("normalizeAndValidateConfig()", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

are we OK with these tests living in a separate file? it's rather unconventional to test the same fn over 2 separate test suites, but:

  • configuration.test.ts is already 5k lines long so had mixed feelings abt adding more to it.
  • this made it easy to write the tests
  • this way we keep Pages specific tests in one place. Granted we could achieve that via a dedicated describe block inside configuration.test.ts

I have no strong opinions, but if anyone else does, happy to readjust.

import type { RawConfig, RawEnvironment } from "../config";

describe("normalizeAndValidateConfig()", () => {
describe("Pages configuration", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this describe() necessary? It seems like describe("normalizeAndValidateConfig()") has no other children

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not necessary per se, it's merely to have some logical grouping in place, and separate the Pages test suite from the suite in configuration.test.ts. We already have a describe("normalizeAndValidateConfig()",...) block in place in configuration.test.ts, and since we're duplicating that suite name here, having an extra grouping layer felt like a clean approach. If this feels like overkill, we could rename to top level grouping to smth like normalizeAndValidateConfig() for Pages and get rid of the secondary grouping layer

Copy link
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.

A few comments, but overall looks good!

To make it easier for users to write config files for Pages,
Wrangler will not require both of those environments to be
explicitly defined in the `wrangler.toml` file. If either
`[env.production]` or `[env.preview]` is left unspecified,
Wrangler will use the top-level Wrangler environment when
targeting that named Pages environment.

This commit implements the aforementioned environment
inheritance logic for Pages projects.
@CarmenPopoviciu CarmenPopoviciu merged commit e739b7f into main Mar 20, 2024
15 checks passed
@CarmenPopoviciu CarmenPopoviciu deleted the carmen/env-inheritance branch March 20, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants