Skip to content

Conversation

@vicb
Copy link
Contributor

@vicb vicb commented Dec 4, 2025

This PR adds template substitution for the wrangler config files.

  • <WORKER_NAME> is replaced with the worker name (from the project).
  • <COMPATIBILITY_DATE> is replaced with the latest workerd date

This in in addition to how <TBD> is currently replaced by a context depend value (could be either the worker name or the compatibility date)

Notes:

  • the new template substitution is applied before the legacy one to preserved backward compatibility.
  • <WORKER_NAME> is needed to unblock Open Next (in a follow up PR)
  • <COMPATIBILITY_DATE> is not currently used but will be used to make substitution clearer, see "Future work" below

For .json/.jsonc only the string values are considered.
For .toml it uses a simple string replace - which should be ok if we use uncommon key format.

Note / Future work:

We currently use this pattern for wrangler config / package.json:

{
	"name": "<TBD>",
	"main": "src/entry.py",
	"compatibility_date": "<TBD>",
	"compatibility_flags": ["python_workers"],
	"observability": {
		"enabled": true,
	},
}

IMO we should replace that with the mechanism of this PR for clarity, i.e.

{
	"name": "<WORKER_NAME>",
	"main": "src/entry.py",
	"compatibility_date": "<COMPATIBILITY_DATE>",
	"compatibility_flags": ["python_workers"],
	"observability": {
		"enabled": true,
	},
}

(We should keep the current logic for backward compatibility but update it and the templates)


  • Tests
    • Tests included/updated
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: c3

@vicb vicb requested a review from a team as a code owner December 4, 2025 10:17
@changeset-bot
Copy link

changeset-bot bot commented Dec 4, 2025

🦋 Changeset detected

Latest commit: c9f28a0

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

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 4, 2025

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@11520

wrangler

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

commit: c9f28a0

@vicb vicb force-pushed the vicb/c3-substitution branch from fd037c7 to 13f666c Compare December 4, 2025 15:53
@vicb vicb changed the title [C3] Add template susbsitution [C3] Support template subsitution in wrangler config files Dec 4, 2025
@vicb vicb force-pushed the vicb/c3-substitution branch 2 times, most recently from 83e8243 to c320e96 Compare December 5, 2025 10:25
@vicb vicb changed the title [C3] Support template subsitution in wrangler config files [C3] Support template substitution in wrangler config files Dec 5, 2025
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Great! To be honest, if we are going in this direction we should just get rid of the <TBD> placeholders. All of this is internal API and we have full control over it. Keeping TBD around just adds additional complexity and is confusing.

@vicb
Copy link
Contributor Author

vicb commented Dec 8, 2025

Great! To be honest, if we are going in this direction we should just get rid of the <TBD> placeholders. All of this is internal API and we have full control over it. Keeping TBD around just adds additional complexity and is confusing.

Doesn't c3 support external templates?
I would need to look if it coud be used there

@vicb vicb force-pushed the vicb/c3-substitution branch from 7ecfdb2 to 329dd1c Compare December 9, 2025 06:52
@vicb vicb force-pushed the vicb/c3-substitution branch from bfdbdac to 72133c2 Compare December 9, 2025 10:56
@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Dec 9, 2025
@vicb vicb force-pushed the vicb/c3-substitution branch from a6dca46 to c9f28a0 Compare December 9, 2025 11:24
@vicb vicb merged commit 85ec269 into main Dec 9, 2025
29 checks passed
@vicb vicb deleted the vicb/c3-substitution branch December 9, 2025 11:55
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Dec 9, 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.

2 participants