Skip to content

Commit 0d12508

Browse files
feat(miniflare): add getWorkerdFeatureFlags() for compatibility flag resolution
Add a TypeScript implementation that replicates workerd's C++ compileCompatibilityFlags() function. This computes which compatibility flags are enabled based on: - Compatibility date (flags enabled after their compatEnableDate) - Explicit compatibility flags (enable/disable overrides) - Implied flags (cascading dependencies between flags) Files added: - scripts/build-capnp-compat.mjs: Build script that downloads compatibility-date.capnp from workerd, compiles it with capnp-es, and extracts annotation metadata - src/shared/compatibility-date.ts: Cap'n Proto types generated by capnp-es - src/shared/compatibility-flags-metadata.ts: Extracted annotation metadata - src/shared/compatibility-flags.ts: Main implementation with getWorkerdFeatureFlags() - test/shared/compatibility-flags.spec.ts: Test suite Also updates: - package.json: Added capnp:compat script - tsconfig.json: Include the build script for type checking - GitHub workflow: Auto-regenerate compatibility flags on workerd dependency updates
1 parent c808a6f commit 0d12508

File tree

8 files changed

+4060
-2
lines changed

8 files changed

+4060
-2
lines changed

.github/workflows/miniflare-dependabot-versioning-prs.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions:
1212

1313
jobs:
1414
generate-changeset:
15-
runs-on: ubuntu-slim
15+
runs-on: ubuntu-latest
1616
if: |
1717
github.event.pull_request.user.login == 'dependabot[bot]'
1818
steps:
@@ -26,11 +26,29 @@ jobs:
2626
- name: Install Dependencies
2727
uses: ./.github/actions/install-dependencies
2828

29+
- name: Install Cap'n Proto compiler
30+
run: |
31+
sudo apt-get update
32+
sudo apt-get install -y capnproto
33+
2934
- name: Configure Git
3035
run: |
3136
git config --global user.email wrangler@cloudflare.com
3237
git config --global user.name 'Wrangler automated PR updater'
3338
39+
- name: Regenerate compatibility flags
40+
run: |
41+
pnpm --filter miniflare run capnp:compat
42+
43+
# Commit the regenerated files if there are changes
44+
git add packages/miniflare/src/shared/compatibility-date.ts packages/miniflare/src/shared/compatibility-flags-metadata.ts
45+
if git diff --cached --quiet; then
46+
echo "No changes to compatibility flags files"
47+
else
48+
git commit -m "chore(miniflare): regenerate compatibility flags for workerd update"
49+
git push
50+
fi
51+
3452
- name: Generate Miniflare changesets
3553
# The paremeters to the script are:
3654
# - PR: The number of the current Dependabot PR

packages/miniflare/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
],
3232
"scripts": {
3333
"build": "node scripts/build.mjs && pnpm run types:build",
34+
"capnp:compat": "node scripts/build-capnp-compat.mjs",
3435
"capnp:workerd": "node scripts/build-capnp.mjs",
3536
"check:lint": "eslint --max-warnings=0 \"{src,test}/**/*.ts\" \"types/**/*.ts\"",
3637
"check:type": "tsc",

0 commit comments

Comments
 (0)