-
Notifications
You must be signed in to change notification settings - Fork 741
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: add support for redirecting Wrangler to a generated config when running deploy commands #7442
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 3756ab2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
5a91f5b
to
b3bf041
Compare
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/12296073930/npm-package-wrangler-7442 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7442/npm-package-wrangler-7442 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12296073930/npm-package-wrangler-7442 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12296073930/npm-package-create-cloudflare-7442 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12296073930/npm-package-cloudflare-kv-asset-handler-7442 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12296073930/npm-package-miniflare-7442 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12296073930/npm-package-cloudflare-pages-shared-7442 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12296073930/npm-package-cloudflare-vitest-pool-workers-7442 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12296073930/npm-package-cloudflare-workers-editor-shared-7442 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12296073930/npm-package-cloudflare-workers-shared-7442 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12296073930/npm-package-cloudflare-workflows-shared-7442 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
e30d5e1
to
e251387
Compare
… running deploy commands This new feature is designed for build tools and frameworks to provide a deploy-specific configuration, which Wrangler can use instead of user configuration when running deploy commands. It is not expected that developers of Workers will need to use this feature directly. The commands that use this feature are: - `wrangler deploy` - `wrangler dev` - `wrangler versions upload` - `wrangler versions deploy` When running these commands, Wrangler will look up the directory tree from the current working directory for a file at the path `.wrangler/deploy/config.json`. This file must contain only a single JSON object of the form: ```json { "configPath": "../../path/to/wrangler.json" } ``` When this file exists Wrangler will use the `configPath` (relative to the `deploy.json` file) to find an alternative Wrangler configuration file to load and use as part of this command. When this happens Wrangler will display a warning to the user to indicate that the configuration has been redirected to a different file than the user's configuration file. A common approach that a build tool might choose to implement. - The user writes code that uses Cloudflare Workers resources, configured via a user `wrangler.toml` file. ```toml name = "my-worker" main = "src/index.ts" [[kv_namespaces]] binding = "<BINDING_NAME1>" id = "<NAMESPACE_ID1>" ``` Note that this configuration points `main` at user code entry-point. - The user runs a custom build, which might read the `wrangler.toml` to find the entry-point: ```bash > my-tool build ``` - This tool generates a `dist` directory that contains both compiled code and a new deployment configuration file, but also a `.wrangler/deploy/config.json` file that redirects Wrangler to this new deployment configuration file: ```plain - dist - index.js - wrangler.json - .wrangler - deploy - config.json ``` The `dist/wrangler.json` will contain: ```json { "name": "my-worker", "main": "./index.js", "kv_namespaces": [{ "binding": "<BINDING_NAME1>", "id": "<NAMESPACE_ID1>" }] } ``` And the `.wrangler/deploy/config.json` will contain: ```json { "configPath": "../../dist/wrangler.json" } ```
This creates a lot of unwanted logging in the console. The logging is still dumped to the console if the test times out, or if `WRANGLER_LOG=debug` is set as env var.
e251387
to
3756ab2
Compare
Fixes #5579
This feature is designed for build tools and frameworks to provide a deploy-specific configuration, which Wrangler can use instead of user configuration when running deploy commands.
It is not expected that developers of Workers will need to use this feature directly.
Affected commands
The commands that use this feature are:
wrangler deploy
wrangler dev
wrangler versions upload
wrangler versions deploy
Config redirect file
When running these commands, Wrangler will look up the directory tree from the current working directory for a file at the path
.wrangler/deploy/config.json
. This file must contain only a single JSON object of the form:When this file exists Wrangler will use the
configPath
(relative to theconfig.json
file) to find an alternative Wrangler configuration file to load and use as part of this command.When this happens Wrangler will display a warning to the user to indicate that the configuration has been redirected to a different file than the user's configuration file.
Custom build tool example
A common approach that a build tool might choose to implement.
The user writes code that uses Cloudflare Workers resources, configured via a user
wrangler.toml
file.Note that this configuration points
main
at user code entry-point.The user runs a custom build, which might read the
wrangler.toml
to find the entry-point:> my-tool build
This tool generates a
dist
directory that contains both compiled code and a new deployment configuration file, but also a.wrangler/deploy/config.json
file that redirects Wrangler to this new deployment configuration file:The
dist/wrangler.json
will contain:And the
.wrangler/deploy/config.json
will contain: