AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(deploy): guard default Cloudflare D1 deployment
tianma-ifbab4c5572068
diff --git a/README.md b/README.mdindex 9eb79c0b..94d30553 100644--- a/README.md+++ b/README.md@@ -89,7 +89,7 @@ Complete setup in 5 simple web steps:2. **Enable Actions**: Open the Fork's **Actions** tab and click **I understand my workflows, go ahead and enable them** so the GitHub Actions workflow named **Update deployed EdgeEver** can run automatically, keeping you up to date with the latest **EdgeEver** features and fixes.3. **Import into Cloudflare**: Log into the Cloudflare Dashboard, navigate to **Workers & Pages**, and choose to import your Fork repository.4. **Create Resources & Credentials**: Create D1 `edgeever` and R2 `edgeever-resources`, then set the Worker Secret `EDGE_EVER_AUTH_PASSWORD` as your admin password. The deploy command creates the bindings; do not edit Fork files.-5. **Build & Verify**: Start the first build with default settings. Once complete, visit `/api/health` to verify a `200` response before logging in.+5. **Build & Verify**: Keep Cloudflare's default deploy command (`npx wrangler deploy`) and start the first build. EdgeEver routes it through the same validated database migration and deployment pipeline automatically. Once complete, visit `/api/health` to verify a `200` response before logging in.> 📖 For full step-by-step instructions and configuration details, see the [Online Deployment Guide](docs/deploy-cloudflare-button.md).diff --git a/README.zh-CN.md b/README.zh-CN.mdindex f72d4fec..57fccf9c 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -89,7 +89,7 @@ Cloudflare 在线部署可以选择以下两种方式之一:2. **启用 Actions**:进入 Fork 的 **Actions** 标签页,点击 **I understand my workflows, go ahead and enable them**,确保名为 **Update deployed EdgeEver** 的 GitHub Actions 工作流能够自动运行,从而持续获得 **EdgeEver** 最新的产品特性和问题修复。3. **导入 Cloudflare**:登录 Cloudflare 控制台,进入 **Workers & Pages**,选择导入该 Fork 仓库。4. **创建资源与登录凭据**:创建 D1 `edgeever` 与 R2 `edgeever-resources`,并添加 Worker Secret `EDGE_EVER_AUTH_PASSWORD` 作为管理员登录密码。binding 由部署命令生成,不要修改 Fork 中的文件。-5. **启动构建与验证**:使用默认构建配置启动首次构建,部署完成后访问 `/api/health` 确认返回 `200` 即可开始使用。+5. **启动构建与验证**:保留 Cloudflare 默认部署命令(`npx wrangler deploy`)并启动首次构建。EdgeEver 会自动将其接入同一套数据库迁移和部署校验流水线。部署完成后访问 `/api/health`,确认返回 `200` 即可开始使用。> 📖 包含具体参数与构建命令的详细步骤,请查看 [在线部署完整文档](docs/deploy-cloudflare-button.zh-CN.md)。diff --git a/apps/site/src/deployment-prompts.ts b/apps/site/src/deployment-prompts.tsindex 224dcdde..e2c1d887 100644--- a/apps/site/src/deployment-prompts.ts+++ b/apps/site/src/deployment-prompts.ts@@ -39,7 +39,7 @@ export const manualDeploymentCopy = {},{title: "Build & Verify",- body: "Start the first build with default settings. Once complete, visit /api/health to verify a 200 response before logging in.",+ body: "Keep Cloudflare's default deploy command (npx wrangler deploy) and start the first build. EdgeEver routes it through the same validated database migration and deployment pipeline automatically. Once complete, visit /api/health to verify a 200 response before logging in.",},],},@@ -64,7 +64,7 @@ export const manualDeploymentCopy = {},{title: "启动构建与验证",- body: "使用默认构建配置启动首次构建,部署完成后访问 /api/health 确认返回 200 即可开始使用。",+ body: "保留 Cloudflare 默认部署命令(npx wrangler deploy)并启动首次构建。EdgeEver 会自动将其接入同一套数据库迁移和部署校验流水线。部署完成后访问 /api/health,确认返回 200 即可开始使用。",},],},diff --git a/bun.lock b/bun.lockindex 67b2f6e6..fd57b1a8 100644--- a/bun.lock+++ b/bun.lock@@ -81,7 +81,7 @@"typescript": "latest","vite": "latest","vite-plugin-pwa": "^1.3.0",- "wrangler": "^4.112.0",+ "wrangler": "workspace:*",},},"apps/api": {@@ -90,7 +90,7 @@},"apps/desktop": {"name": "@edgeever/desktop",- "version": "1.45.0",+ "version": "1.45.2","dependencies": {"electron-updater": "^6.6.2",},@@ -243,6 +243,18 @@"katex": "0.16.22",},},+ "packages/wrangler": {+ "name": "wrangler",+ "version": "4.112.0-edgeever.1",+ "bin": {+ "wrangler": "bin/wrangler.js",+ "wrangler2": "bin/wrangler.js",+ "cf-wrangler": "bin/wrangler.js",+ },+ "dependencies": {+ "edgeever-wrangler-cli": "npm:wrangler@^4.112.0",+ },+ },},"patchedDependencies": {"[email protected]": "patches/[email protected]",@@ -1241,7 +1253,7 @@"@sinclair/typebox": ["@sinclair/[email protected]", "", {}, "sha512-MTBk/3jGLNB2tVxv6uLlFh1iu64iYOQ2PbdOSK3NW8JZsmlaOh2q6sdtKowBhfw8QFLmYNzTW4/oK4uATIi6ZA=="],- "@sindresorhus/is": ["@sindresorhus/[email protected]", "", {}, "sha512-P1Cz1dWaFfR4IR+U13mqqiGsLFf1KbayybWwdd2vfctdV6hDpUkgCY0nKOLLTMSoRd/jJNjtbqzf13K8DCCXQw=="],+ "@sindresorhus/is": ["@sindresorhus/[email protected]", "", {}, "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw=="],"@smithy/core": ["@smithy/[email protected]", "", { "dependencies": { "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-dl2yRglDxfzH9uJ4fSo4zTaAHa0zH7+V7BZMRWy8hEYIKT1BiqMUK/CN6T3ADQ3kbA5N1tmUulroJ2UtONS7Kw=="],@@ -2159,6 +2171,8 @@"ecdsa-sig-formatter": ["[email protected]", "", { "dependencies": { "safe-buffer": "^5.0.1" } }, "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ=="],+ "edgeever-wrangler-cli": ["[email protected]", "", { "dependencies": { "@cloudflare/kv-asset-handler": "0.5.0", "@cloudflare/unenv-preset": "2.16.1", "blake3-wasm": "2.1.5", "esbuild": "0.28.1", "miniflare": "4.20260714.0", "path-to-regexp": "6.3.0", "unenv": "2.0.0-rc.24", "workerd": "1.20260714.1" }, "optionalDependencies": { "fsevents": "2.3.3" }, "peerDependencies": { "@cloudflare/workers-types": "^5.20260714.1" }, "optionalPeers": ["@cloudflare/workers-types"], "bin": { "cf-wrangler": "bin/cf-wrangler.js", "wrangler": "bin/wrangler.js", "wrangler2": "bin/wrangler.js" } }, "sha512-5H+XUD0TySCv1LuktFHDIEOkboH2nTfQs+35L+USt3MtntjDTMVIJprLgQcL2WBjulOyjxpd1vyTiSTJVW5MjQ=="],+"ee-first": ["[email protected]", "", {}, "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="],"ejs": ["[email protected]", "", { "dependencies": { "jake": "^10.8.5" }, "bin": { "ejs": "bin/cli.js" } }, "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA=="],@@ -4091,7 +4105,7 @@"workerd": ["[email protected]", "", { "optionalDependencies": { "@cloudflare/workerd-darwin-64": "1.20260714.1", "@cloudflare/workerd-darwin-arm64": "1.20260714.1", "@cloudflare/workerd-linux-64": "1.20260714.1", "@cloudflare/workerd-linux-arm64": "1.20260714.1", "@cloudflare/workerd-windows-64": "1.20260714.1" }, "bin": { "workerd": "bin/workerd" } }, "sha512-oIbQzfdyl9UQUnG6XLegcSq0Mgt/7WKDbFOoqGgOWCS+/fhyGB460uKEgdAQQ9RHCO/ttcNCX/KiMIQzdoeu3Q=="],- "wrangler": ["[email protected]", "", { "dependencies": { "@cloudflare/kv-asset-handler": "0.5.0", "@cloudflare/unenv-preset": "2.16.1", "blake3-wasm": "2.1.5", "esbuild": "0.28.1", "miniflare": "4.20260714.0", "path-to-regexp": "6.3.0", "unenv": "2.0.0-rc.24", "workerd": "1.20260714.1" }, "optionalDependencies": { "fsevents": "2.3.3" }, "peerDependencies": { "@cloudflare/workers-types": "^5.20260714.1" }, "optionalPeers": ["@cloudflare/workers-types"], "bin": { "cf-wrangler": "bin/cf-wrangler.js", "wrangler": "bin/wrangler.js", "wrangler2": "bin/wrangler.js" } }, "sha512-5H+XUD0TySCv1LuktFHDIEOkboH2nTfQs+35L+USt3MtntjDTMVIJprLgQcL2WBjulOyjxpd1vyTiSTJVW5MjQ=="],+ "wrangler": ["wrangler@workspace:packages/wrangler"],"wrap-ansi": ["[email protected]", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="],@@ -4281,6 +4295,8 @@"@poppinss/colors/kleur": ["[email protected]", "", {}, "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ=="],+ "@poppinss/dumper/@sindresorhus/is": ["@sindresorhus/[email protected]", "", {}, "sha512-P1Cz1dWaFfR4IR+U13mqqiGsLFf1KbayybWwdd2vfctdV6hDpUkgCY0nKOLLTMSoRd/jJNjtbqzf13K8DCCXQw=="],+"@radix-ui/react-tabs/@radix-ui/primitive": ["@radix-ui/[email protected]", "", {}, "sha512-d86WIWFYNtGA0H/d8exstrTRTp7eWJYlYJbtNofxr/3ljupZYn6EFDG/Qgu/0Kc8v7yMUxySagqJsL1+PdYjWg=="],"@radix-ui/react-tabs/@radix-ui/react-context": ["@radix-ui/[email protected]", "", { "peerDependencies": { "@types/react": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-fOE+JtN9rygNZkCnHRBEP0TAvLldlhyOxMsbwFvTP4nAs+nBmfnna+o/Zski2wkmY1YMrFC0aSzsHoLY47iLrg=="],@@ -4519,8 +4535,6 @@"global-directory/ini": ["[email protected]", "", {}, "sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g=="],- "got/@sindresorhus/is": ["@sindresorhus/[email protected]", "", {}, "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw=="],-"h3/cookie-es": ["[email protected]", "", {}, "sha512-lXVyvUvrNXblMqzIRrxHb57UUVmqsSWlxqt3XIjCkUP0wDAf6uicO6KMbEgYrMNtEvWgWHwe42CKxPu9MYAnWw=="],"hoist-non-react-statics/react-is": ["[email protected]", "", {}, "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="],diff --git a/docs/cloudflare-workers-builds.md b/docs/cloudflare-workers-builds.mdindex 6b4983fd..ef495864 100644--- a/docs/cloudflare-workers-builds.md+++ b/docs/cloudflare-workers-builds.md@@ -2,7 +2,7 @@## Setup-Use the build and deploy commands from the [online deployment guide](deploy-cloudflare-button.md), with root directory `/` and production branch `main`.+For a manual repository import, keep Cloudflare's default `npx wrangler deploy` command as described in the [online deployment guide](deploy-cloudflare-button.md), with root directory `/` and production branch `main`. The repository-provided Wrangler compatibility entrypoint routes that default command through the complete EdgeEver deployment pipeline. Existing projects using the explicit build and `bun run deploy:cloudflare-builds` commands remain supported.Authorization:diff --git a/docs/cloudflare-workers-builds.zh-CN.md b/docs/cloudflare-workers-builds.zh-CN.mdindex 071e5369..5789632f 100644--- a/docs/cloudflare-workers-builds.zh-CN.md+++ b/docs/cloudflare-workers-builds.zh-CN.md@@ -2,7 +2,7 @@## 配置-使用[在线部署文档](deploy-cloudflare-button.zh-CN.md)中的构建命令和部署命令,仓库根目录为 `/`,生产分支为 `main`。+手动导入仓库时,按[在线部署文档](deploy-cloudflare-button.zh-CN.md)保留 Cloudflare 默认的 `npx wrangler deploy` 命令,仓库根目录为 `/`,生产分支为 `main`。仓库提供的 Wrangler 兼容入口会把该默认命令接入 EdgeEver 的完整部署流水线。已有项目继续使用显式构建命令与 `bun run deploy:cloudflare-builds` 也受支持。授权:diff --git a/docs/deploy-cloudflare-button.md b/docs/deploy-cloudflare-button.mdindex f767a485..8628b596 100644--- a/docs/deploy-cloudflare-button.md+++ b/docs/deploy-cloudflare-button.md@@ -57,18 +57,24 @@ Existing deployments created from older instructions do not need to rename or mi----### Step 4: Set Build Commands & Start Build+### Step 4: Start the Build-In the Cloudflare project **Build settings**, configure:+Keep the default deploy command filled in by Cloudflare:```text-Build command: bun install --frozen-lockfile && EDGE_EVER_DEPLOYMENT_TRIGGER=main_push EDGE_EVER_DEPLOYMENT_METHOD=cloudflare_workers_builds bun run build:cloudflare-Deploy command: bun run deploy:cloudflare-builds+Deploy command: npx wrangler deploy```-Click **Save and Deploy** to trigger the initial build.+Click **Save and Deploy** to trigger the initial build. The repository's Wrangler compatibility entrypoint detects Workers Builds and routes the default command through EdgeEver's complete build, database migration, deployment, and live verification pipeline. You do not need to copy a custom command, and the D1 placeholder in `wrangler.toml` cannot be submitted to Cloudflare.++The deployment pipeline automatically looks up the D1 UUID by the `edgeever` database name. Keep the tracked `wrangler.toml` unchanged; deployment rejects instance-specific values committed there. The Workers Builds API token must have D1 read/edit permission.++Existing projects may keep using these explicit commands without changing them:-The deploy command automatically looks up the D1 UUID by the `edgeever` database name. Keep the tracked `wrangler.toml` unchanged; deployment rejects instance-specific values committed there. The Workers Builds API token must have D1 read/edit permission.+```text+Build command: bun install --frozen-lockfile && EDGE_EVER_DEPLOYMENT_TRIGGER=main_push EDGE_EVER_DEPLOYMENT_METHOD=cloudflare_workers_builds bun run build:cloudflare+Deploy command: bun run deploy:cloudflare-builds+```After publishing, the CI deployment records the actual public target reported by Wrangler and requests its `/api/health` endpoint. The build fails if the live Worker is missing its `DB` or `RESOURCES` binding, uses an unprepared D1 database, or does not return a healthy response.@@ -117,7 +123,7 @@ Passwords and other credentials remain Worker runtime Secrets and must never be## Troubleshooting-- **Initial build failed**: Check the Worker **Deployments** log. Verify that the standard resources are named exactly `edgeever` and `edgeever-resources`, and that the Workers Builds API token has D1 read/edit permission. For an intentionally different D1 database, set `EDGE_EVER_D1_DATABASE_NAME`; add `EDGE_EVER_D1_DATABASE_ID` only if automatic UUID discovery is unavailable.+- **Initial build failed**: Check the Worker **Deployments** log for “routing it through EdgeEver's validated deployment pipeline”. Verify that the standard resources are named exactly `edgeever` and `edgeever-resources`, and that the Workers Builds API token has D1 read/edit permission. For an intentionally different D1 database, set `EDGE_EVER_D1_DATABASE_NAME`; add `EDGE_EVER_D1_DATABASE_ID` only if automatic UUID discovery is unavailable.- **Updates not syncing**:1. On the Fork **Actions** tab, enable **Update deployed EdgeEver** (scheduled workflows are off by default on public forks).2. Run it once with **Run workflow**. Open the bilingual job **Summary**: it separately reports the upstream target, Git publish result, deployment trigger, and whether the live deployment was verified.diff --git a/docs/deploy-cloudflare-button.zh-CN.md b/docs/deploy-cloudflare-button.zh-CN.mdindex 3a5e472a..c5ffab5f 100644--- a/docs/deploy-cloudflare-button.zh-CN.md+++ b/docs/deploy-cloudflare-button.zh-CN.md@@ -57,18 +57,24 @@----### 步骤 4:设置构建命令并启动构建+### 步骤 4:启动构建-在 Cloudflare 项目的 **Build settings**(构建设置)中配置:+保留 Cloudflare 自动填写的默认部署命令:```text-Build command: bun install --frozen-lockfile && EDGE_EVER_DEPLOYMENT_TRIGGER=main_push EDGE_EVER_DEPLOYMENT_METHOD=cloudflare_workers_builds bun run build:cloudflare-Deploy command: bun run deploy:cloudflare-builds+Deploy command: npx wrangler deploy```-点击 **Save and Deploy** 启动首次构建部署。+点击 **Save and Deploy** 启动首次构建部署。仓库提供的 Wrangler 兼容入口会识别 Workers Builds,并自动将默认命令接入 EdgeEver 的完整构建、数据库迁移、部署及线上验证流水线。因此无需复制自定义命令,也不会把 `wrangler.toml` 中的 D1 占位符提交给 Cloudflare。++部署流水线会根据 `edgeever` 数据库名称自动查询 D1 UUID。受版本控制的 `wrangler.toml` 必须保持不变;若把实例专属配置提交到该文件,部署会直接拒绝。Workers Builds API Token 必须具有 D1 读取和编辑权限。++已有项目继续使用下列显式命令也受支持,无需修改:-部署命令会根据 `edgeever` 数据库名称自动查询 D1 UUID。受版本控制的 `wrangler.toml` 必须保持不变;若把实例专属配置提交到该文件,部署会直接拒绝。Workers Builds API Token 必须具有 D1 读取和编辑权限。+```text+Build command: bun install --frozen-lockfile && EDGE_EVER_DEPLOYMENT_TRIGGER=main_push EDGE_EVER_DEPLOYMENT_METHOD=cloudflare_workers_builds bun run build:cloudflare+Deploy command: bun run deploy:cloudflare-builds+```发布完成后,CI 部署会记录 Wrangler 返回的实际公网入口,并请求该入口的 `/api/health`。如果线上 Worker 缺少 `DB` 或 `RESOURCES` binding、绑定了未初始化的 D1,或没有返回健康状态,构建会直接失败。@@ -117,7 +123,7 @@ EDGE_EVER_UPDATE_CHANNEL=edge## 常见问题与排错-- **首次构建失败**:请检查 Cloudflare 控制台中 Worker 的 **Deployments** 构建日志,确认标准资源名称严格为 `edgeever` 与 `edgeever-resources`,并确认 Workers Builds API Token 具有 D1 读取和编辑权限。如有意使用其他 D1 数据库,请设置 `EDGE_EVER_D1_DATABASE_NAME`;仅在自动查询 UUID 不可用时再添加 `EDGE_EVER_D1_DATABASE_ID`。+- **首次构建失败**:请检查 Cloudflare 控制台中 Worker 的 **Deployments** 构建日志,确认日志包含“routing it through EdgeEver's validated deployment pipeline”,标准资源名称严格为 `edgeever` 与 `edgeever-resources`,并确认 Workers Builds API Token 具有 D1 读取和编辑权限。如有意使用其他 D1 数据库,请设置 `EDGE_EVER_D1_DATABASE_NAME`;仅在自动查询 UUID 不可用时再添加 `EDGE_EVER_D1_DATABASE_ID`。- **无法同步上游更新**:1. 打开 Fork 的 **Actions**,启用 **Update deployed EdgeEver**(公共 Fork 上定时任务默认关闭)。2. 手动 **Run workflow** 一次,打开中英双语 Job **Summary**:会分别展示上游目标、Git 发布结果、部署触发状态,以及线上部署是否已经验证。diff --git a/package.json b/package.jsonindex 82687806..215e9ff4 100644--- a/package.json+++ b/package.json@@ -187,7 +187,7 @@"typescript": "latest","vite": "latest","vite-plugin-pwa": "^1.3.0",- "wrangler": "^4.112.0"+ "wrangler": "workspace:*"},"patchedDependencies": {"[email protected]": "patches/[email protected]",diff --git a/packages/wrangler/bin/wrangler.js b/packages/wrangler/bin/wrangler.jsnew file mode 100755index 00000000..3fcbf8b1--- /dev/null+++ b/packages/wrangler/bin/wrangler.js@@ -0,0 +1,55 @@+#!/usr/bin/env node++import { spawnSync } from "node:child_process";+import { readFileSync } from "node:fs";+import { createRequire } from "node:module";+import { dirname, resolve } from "node:path";+import { fileURLToPath } from "node:url";+import {+ edgeEverDeploymentEnvironment,+ shouldRunEdgeEverDeployment,+} from "../dispatch.mjs";++const args = process.argv.slice(2);+const packageDirectory = resolve(dirname(fileURLToPath(import.meta.url)), "..");+const repositoryRoot = resolve(packageDirectory, "../..");+const repositoryConfig = (() => {+ try {+ return readFileSync(resolve(repositoryRoot, "wrangler.toml"), "utf8");+ } catch {+ return "";+ }+})();++const run = (executable, commandArgs, options = {}) => {+ const result = spawnSync(executable, commandArgs, {+ cwd: repositoryRoot,+ stdio: "inherit",+ shell: false,+ ...options,+ });+ if (result.error) {+ console.error(result.error.message);+ process.exit(1);+ }+ process.exit(result.status ?? 1);+};++if (shouldRunEdgeEverDeployment(args, process.env, repositoryConfig)) {+ console.error(+ "[info] Cloudflare used its default deploy command; routing it through EdgeEver's validated deployment pipeline.",+ );+ run("bun", ["run", "deploy"], {+ env: edgeEverDeploymentEnvironment(),+ });+}++const require = createRequire(import.meta.url);+const officialPackagePath = require.resolve("edgeever-wrangler-cli/package.json");+const officialCliPath = resolve(dirname(officialPackagePath), "bin/wrangler.js");+run("node", [officialCliPath, ...args], {+ env: {+ ...process.env,+ EDGE_EVER_WRANGLER_BYPASS_SHIM: "1",+ },+});diff --git a/packages/wrangler/dispatch.mjs b/packages/wrangler/dispatch.mjsnew file mode 100644index 00000000..2de4b486--- /dev/null+++ b/packages/wrangler/dispatch.mjs@@ -0,0 +1,27 @@+export const PLACEHOLDER_D1_ID = "00000000-0000-0000-0000-000000000000";++export const hasPlaceholderD1Binding = (config) =>+ new RegExp(`^database_id\\s*=\\s*["']${PLACEHOLDER_D1_ID}["']`, "m").test(config);++export const shouldRunEdgeEverDeployment = (+ args,+ env = process.env,+ repositoryConfig = "",+) =>+ env.WORKERS_CI === "1"+ && env.EDGE_EVER_WRANGLER_BYPASS_SHIM !== "1"+ && !env.WRANGLER_CONFIG?.trim()+ // Cloudflare's production default is exactly `npx wrangler deploy`.+ // Preserve every explicit Wrangler customization for existing deployments.+ && args.length === 1+ && args[0] === "deploy"+ // Legacy deployments that committed a real UUID already work with the+ // official CLI and must retain that behavior.+ && hasPlaceholderD1Binding(repositoryConfig);++export const edgeEverDeploymentEnvironment = (env = process.env) => ({+ ...env,+ EDGE_EVER_DEPLOYMENT_TRIGGER: env.EDGE_EVER_DEPLOYMENT_TRIGGER || "main_push",+ EDGE_EVER_DEPLOYMENT_METHOD:+ env.EDGE_EVER_DEPLOYMENT_METHOD || "cloudflare_workers_builds_default",+});diff --git a/packages/wrangler/package.json b/packages/wrangler/package.jsonnew file mode 100644index 00000000..fad1c4ac--- /dev/null+++ b/packages/wrangler/package.json@@ -0,0 +1,14 @@+{+ "name": "wrangler",+ "version": "4.112.0-edgeever.1",+ "private": true,+ "type": "module",+ "bin": {+ "wrangler": "bin/wrangler.js",+ "wrangler2": "bin/wrangler.js",+ "cf-wrangler": "bin/wrangler.js"+ },+ "dependencies": {+ "edgeever-wrangler-cli": "npm:wrangler@^4.112.0"+ }+}diff --git a/scripts/wrangler-runner.mjs b/scripts/wrangler-runner.mjsindex 170bc6e0..e14a6e66 100644--- a/scripts/wrangler-runner.mjs+++ b/scripts/wrangler-runner.mjs@@ -61,6 +61,10 @@ export const isD1MigrationApplyCommand = (args) => {export const buildWranglerEnvironment = (args, env = process.env) => ({...env,+ // The repository installs a Wrangler compatibility shim so Cloudflare's+ // default `npx wrangler deploy` cannot bypass the validated pipeline. Calls+ // originating from our runner must delegate straight to the official CLI.+ EDGE_EVER_WRANGLER_BYPASS_SHIM: "1",...(isD1MigrationApplyCommand(args) ? { CI: "true" } : {}),});diff --git a/tests/deployment-entrypoints.test.ts b/tests/deployment-entrypoints.test.tsindex dd159d7c..0efb497d 100644--- a/tests/deployment-entrypoints.test.ts+++ b/tests/deployment-entrypoints.test.ts@@ -19,6 +19,11 @@ import {shouldRedeploy,} from "../scripts/upstream-sync-plan.mjs";import { repositoryWranglerConfigError } from "../scripts/wrangler-runner.mjs";+import {+ edgeEverDeploymentEnvironment,+ hasPlaceholderD1Binding,+ shouldRunEdgeEverDeployment,+} from "../packages/wrangler/dispatch.mjs";const repositoryRoot = resolve(import.meta.dir, "..");const normalizeLineEndings = (value: string) => value.replace(/\r\n/g, "\n");@@ -112,6 +117,66 @@ describe("Cloudflare deployment entrypoints", () => {expect(wranglerConfig).toContain('globs = ["modules/*.js"]');});+ test("Cloudflare's default Wrangler command cannot bypass the deployment pipeline", () => {+ const packageJson = JSON.parse(readRepositoryFile("package.json"));+ const shimPackage = JSON.parse(readRepositoryFile("packages/wrangler/package.json"));+ const shim = readRepositoryFile("packages/wrangler/bin/wrangler.js");+ const englishGuide = readRepositoryFile("docs/deploy-cloudflare-button.md");+ const chineseGuide = readRepositoryFile("docs/deploy-cloudflare-button.zh-CN.md");++ expect(packageJson.devDependencies.wrangler).toBe("workspace:*");+ expect(shimPackage.name).toBe("wrangler");+ expect(shimPackage.dependencies["edgeever-wrangler-cli"]).toMatch(/^npm:wrangler@/);+ expect(shim).toContain('["run", "deploy"]');+ const placeholderConfig = 'database_id = "00000000-0000-0000-0000-000000000000"';+ const legacyConfig = 'database_id = "11111111-1111-1111-1111-111111111111"';+ expect(hasPlaceholderD1Binding(placeholderConfig)).toBe(true);+ expect(hasPlaceholderD1Binding(legacyConfig)).toBe(false);+ expect(shouldRunEdgeEverDeployment(+ ["deploy"],+ { WORKERS_CI: "1" },+ placeholderConfig,+ )).toBe(true);+ expect(shouldRunEdgeEverDeployment(["deploy"], {}, placeholderConfig)).toBe(false);+ expect(shouldRunEdgeEverDeployment(+ ["deploy"],+ { WORKERS_CI: "1" },+ legacyConfig,+ )).toBe(false);+ expect(shouldRunEdgeEverDeployment(+ ["deploy"],+ { WORKERS_CI: "1", WRANGLER_CONFIG: "custom.toml" },+ placeholderConfig,+ )).toBe(false);+ expect(shouldRunEdgeEverDeployment(+ ["deploy", "--config", "custom.toml"],+ { WORKERS_CI: "1" },+ placeholderConfig,+ )).toBe(false);+ expect(shouldRunEdgeEverDeployment(+ ["deploy", "--env", "production"],+ { WORKERS_CI: "1" },+ placeholderConfig,+ )).toBe(false);+ expect(shouldRunEdgeEverDeployment(+ ["deploy", "--name", "custom-worker"],+ { WORKERS_CI: "1" },+ placeholderConfig,+ )).toBe(false);+ expect(shouldRunEdgeEverDeployment(+ ["deploy"],+ { WORKERS_CI: "1", EDGE_EVER_WRANGLER_BYPASS_SHIM: "1" },+ placeholderConfig,+ )).toBe(false);+ expect(edgeEverDeploymentEnvironment({ WORKERS_CI: "1" }))+ .toMatchObject({+ EDGE_EVER_DEPLOYMENT_TRIGGER: "main_push",+ EDGE_EVER_DEPLOYMENT_METHOD: "cloudflare_workers_builds_default",+ });+ expect(englishGuide).toContain("Deploy command: npx wrangler deploy");+ expect(chineseGuide).toContain("Deploy command: npx wrangler deploy");+ });+test("deployment verification lets piped diagnostics flush before exiting", () => {const verificationScript = readRepositoryFile("scripts/verify-deployment.mjs");