From 5124b5da4f8c12bbb6192f2d89241a9c54ab73c7 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Wed, 18 Dec 2024 02:08:56 +0000 Subject: [PATCH 01/53] Allow Workers Assets to be configured on a path (#7476) --- .changeset/early-baboons-fly.md | 7 + .../asset-worker/tests/handler.test.ts | 50 +++ .../wrangler/src/__tests__/deploy.test.ts | 387 ++++++++++++++---- packages/wrangler/src/__tests__/dev.test.ts | 61 +-- packages/wrangler/src/deploy/deploy.ts | 51 ++- packages/wrangler/src/dev.ts | 8 +- packages/wrangler/src/triggers/deploy.ts | 2 +- 7 files changed, 425 insertions(+), 141 deletions(-) create mode 100644 .changeset/early-baboons-fly.md diff --git a/.changeset/early-baboons-fly.md b/.changeset/early-baboons-fly.md new file mode 100644 index 000000000000..c57ab56ee712 --- /dev/null +++ b/.changeset/early-baboons-fly.md @@ -0,0 +1,7 @@ +--- +"wrangler": minor +--- + +feat: allow routing to Workers with Assets on any HTTP route, not just the root. For example, `example.com/blog/*` can now be used to serve assets. +These assets will be served as though the assets directly were mounted to the root. +For example, if you have `assets = { directory = "./public/" }`, a route like `"example.com/blog/*"` and a file `./public/blog/logo.png`, this will be available at `example.com/blog/logo.png`. Assets outside of directories which match the configured HTTP routes can still be accessed with the [Assets binding](https://developers.cloudflare.com/workers/static-assets/binding/#binding) or with a [Service binding](https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/) to this Worker. diff --git a/packages/workers-shared/asset-worker/tests/handler.test.ts b/packages/workers-shared/asset-worker/tests/handler.test.ts index 9d01d635b071..84b1f251843c 100644 --- a/packages/workers-shared/asset-worker/tests/handler.test.ts +++ b/packages/workers-shared/asset-worker/tests/handler.test.ts @@ -1,4 +1,5 @@ import { vi } from "vitest"; +import { applyConfigurationDefaults } from "../src/configuration"; import { handleRequest } from "../src/handler"; import type { AssetConfig } from "../../utils/types"; @@ -100,4 +101,53 @@ describe("[Asset Worker] `handleRequest`", () => { expect(response.status).toBe(200); }); + + it("cannot fetch assets outside of configured path", async () => { + const assets: Record = { + "/blog/test.html": "aaaaaaaaaa", + "/blog/index.html": "bbbbbbbbbb", + "/index.html": "cccccccccc", + "/test.html": "dddddddddd", + }; + + // Attempt to path traverse down to the root /test within asset-server + let response = await handleRequest( + new Request("https://example.com/blog/../test"), + applyConfigurationDefaults({}), + async (pathname: string) => { + if (pathname.startsWith("/blog/")) { + // our route + return assets[pathname] ?? null; + } else { + return null; + } + }, + async (_: string) => ({ + readableStream: new ReadableStream(), + contentType: "text/html", + }) + ); + + expect(response.status).toBe(404); + + // Attempt to path traverse down to the root /test within asset-server + response = await handleRequest( + new Request("https://example.com/blog/%2E%2E/test"), + applyConfigurationDefaults({}), + async (pathname: string) => { + if (pathname.startsWith("/blog/")) { + // our route + return assets[pathname] ?? null; + } else { + return null; + } + }, + async (_: string) => ({ + readableStream: new ReadableStream(), + contentType: "text/html", + }) + ); + + expect(response.status).toBe(404); + }); }); diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index 263aeec98eef..5488768ef321 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -1602,95 +1602,336 @@ Update them to point to this script instead?`, }); }); - it("should error on routes with paths if assets are present", async () => { - writeWranglerConfig({ - routes: [ - "simple.co.uk/path", - "simple.co.uk/path/*", - "simple.co.uk/", - "simple.co.uk/*", - "simple.co.uk", - { pattern: "route.co.uk/path", zone_id: "asdfadsf" }, - { pattern: "route.co.uk/path/*", zone_id: "asdfadsf" }, - { pattern: "route.co.uk/*", zone_id: "asdfadsf" }, - { pattern: "route.co.uk/", zone_id: "asdfadsf" }, - { pattern: "route.co.uk", zone_id: "asdfadsf" }, - { pattern: "custom.co.uk/path", custom_domain: true }, - { pattern: "custom.co.uk/*", custom_domain: true }, - { pattern: "custom.co.uk", custom_domain: true }, - ], + describe("deploy asset routes", () => { + it("shouldn't error on routes with paths if there are no assets", async () => { + writeWranglerConfig({ + routes: [ + "simple.co.uk/path", + "simple.co.uk/path/*", + "simple.co.uk/", + "simple.co.uk/*", + "simple.co.uk", + { pattern: "route.co.uk/path", zone_id: "asdfadsf" }, + { pattern: "route.co.uk/path/*", zone_id: "asdfadsf" }, + { pattern: "route.co.uk/*", zone_id: "asdfadsf" }, + { pattern: "route.co.uk/", zone_id: "asdfadsf" }, + { pattern: "route.co.uk", zone_id: "asdfadsf" }, + { pattern: "custom.co.uk/path", custom_domain: true }, + { pattern: "custom.co.uk/*", custom_domain: true }, + { pattern: "custom.co.uk", custom_domain: true }, + ], + }); + writeWorkerSource(); + + await expect(runWrangler(`deploy ./index`)).rejects + .toThrowErrorMatchingInlineSnapshot(` + [Error: Invalid Routes: + custom.co.uk/path: + Paths are not allowed in Custom Domains + + custom.co.uk/*: + Wildcard operators (*) are not allowed in Custom Domains + Paths are not allowed in Custom Domains] + `); }); - writeWorkerSource(); - writeAssets([{ filePath: "asset.txt", content: "Content of file-1" }]); - await expect(runWrangler(`deploy --assets="assets"`)).rejects - .toThrowErrorMatchingInlineSnapshot(` - [Error: Invalid Routes: - simple.co.uk/path: - Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /path with /* + it("should warn on mounted paths", async () => { + writeWranglerConfig({ + routes: [ + "simple.co.uk/path/*", + "simple.co.uk/*", + "*/*", + "*/blog/*", + { pattern: "example.com/blog/*", zone_id: "asdfadsf" }, + { pattern: "example.com/*", zone_id: "asdfadsf" }, + { pattern: "example.com/abc/def/*", zone_id: "asdfadsf" }, + ], + }); + await mockAUSRequest([]); + mockSubDomainRequest(); + mockUpdateWorkerSubdomain({ enabled: false, previews_enabled: true }); + mockUploadWorkerRequest({ + expectedAssets: { + jwt: "<>", + config: {}, + }, + expectedType: "none", + }); + mockPublishRoutesRequest({ + routes: [ + // @ts-expect-error - this is what is expected + { + pattern: "simple.co.uk/path/*", + }, + // @ts-expect-error - this is what is expected + { + pattern: "simple.co.uk/*", + }, + // @ts-expect-error - this is what is expected + { + pattern: "*/*", + }, + // @ts-expect-error - this is what is expected + { + pattern: "*/blog/*", + }, + { + pattern: "example.com/blog/*", + zone_id: "asdfadsf", + }, + { + pattern: "example.com/*", + zone_id: "asdfadsf", + }, + { + pattern: "example.com/abc/def/*", + zone_id: "asdfadsf", + }, + ], + }); + + writeWorkerSource(); + writeAssets([{ filePath: "asset.txt", content: "Content of file-1" }]); - simple.co.uk/path/*: - Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /path/* with /* + await runWrangler(`deploy --assets assets`); - simple.co.uk/: - Workers which have static assets must end with a wildcard path. Update the route to end with /* + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] Warning: The following routes will attempt to serve Assets on a configured path: - simple.co.uk: - Workers which have static assets must end with a wildcard path. Update the route to end with /* + • simple.co.uk/path/* (Will match assets: assets/path/*) + • */blog/* (Will match assets: assets/blog/*) + • example.com/blog/* (Will match assets: assets/blog/*) + • example.com/abc/def/* (Will match assets: assets/abc/def/*) - route.co.uk/path: - Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /path with /* + " + `); + expect(std.out).toMatchInlineSnapshot(` + "Total Upload: xx KiB / gzip: xx KiB + Worker Startup Time: 100 ms + Uploaded test-name (TIMINGS) + Deployed test-name triggers (TIMINGS) + simple.co.uk/path/* + simple.co.uk/* + */* + */blog/* + example.com/blog/* (zone id: asdfadsf) + example.com/* (zone id: asdfadsf) + example.com/abc/def/* (zone id: asdfadsf) + Current Version ID: Galaxy-Class" + `); + }); - route.co.uk/path/*: - Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /path/* with /* + it("does not mention 404s hit a Worker if it's assets only", async () => { + writeWranglerConfig({ + routes: [ + { pattern: "example.com/blog/*", zone_id: "asdfadsf" }, + { pattern: "example.com/*", zone_id: "asdfadsf" }, + { pattern: "example.com/abc/def/*", zone_id: "asdfadsf" }, + ], + assets: { + directory: "assets", + }, + }); + await mockAUSRequest([]); + mockSubDomainRequest(); + mockUpdateWorkerSubdomain({ enabled: false, previews_enabled: true }); + mockUploadWorkerRequest({ + expectedAssets: { + jwt: "<>", + config: {}, + }, + expectedType: "none", + }); + mockPublishRoutesRequest({ + routes: [ + { + pattern: "example.com/blog/*", + zone_id: "asdfadsf", + }, + { + pattern: "example.com/*", + zone_id: "asdfadsf", + }, + { + pattern: "example.com/abc/def/*", + zone_id: "asdfadsf", + }, + ], + }); - route.co.uk/: - Workers which have static assets must end with a wildcard path. Update the route to end with /* + writeAssets([{ filePath: "asset.txt", content: "Content of file-1" }]); - route.co.uk: - Workers which have static assets must end with a wildcard path. Update the route to end with /* + await runWrangler(`deploy`); - custom.co.uk/path: - Paths are not allowed in Custom Domains + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] Warning: The following routes will attempt to serve Assets on a configured path: - custom.co.uk/*: - Wildcard operators (*) are not allowed in Custom Domains - Paths are not allowed in Custom Domains] - `); - }); + • example.com/blog/* (Will match assets: assets/blog/*) + • example.com/abc/def/* (Will match assets: assets/abc/def/*) - it("shouldn't error on routes with paths if there are no assets", async () => { - writeWranglerConfig({ - routes: [ - "simple.co.uk/path", - "simple.co.uk/path/*", - "simple.co.uk/", - "simple.co.uk/*", - "simple.co.uk", - { pattern: "route.co.uk/path", zone_id: "asdfadsf" }, - { pattern: "route.co.uk/path/*", zone_id: "asdfadsf" }, - { pattern: "route.co.uk/*", zone_id: "asdfadsf" }, - { pattern: "route.co.uk/", zone_id: "asdfadsf" }, - { pattern: "route.co.uk", zone_id: "asdfadsf" }, - { pattern: "custom.co.uk/path", custom_domain: true }, - { pattern: "custom.co.uk/*", custom_domain: true }, - { pattern: "custom.co.uk", custom_domain: true }, - ], + " + `); + expect(std.out).toMatchInlineSnapshot(` + "Total Upload: xx KiB / gzip: xx KiB + Worker Startup Time: 100 ms + Uploaded test-name (TIMINGS) + Deployed test-name triggers (TIMINGS) + example.com/blog/* (zone id: asdfadsf) + example.com/* (zone id: asdfadsf) + example.com/abc/def/* (zone id: asdfadsf) + Current Version ID: Galaxy-Class" + `); }); - writeWorkerSource(); - await expect(runWrangler(`deploy ./index`)).rejects - .toThrowErrorMatchingInlineSnapshot(` - [Error: Invalid Routes: - custom.co.uk/path: - Paths are not allowed in Custom Domains + it("does mention hitting the Worker on 404 if there is one", async () => { + writeWranglerConfig({ + routes: [ + { pattern: "example.com/blog/*", zone_id: "asdfadsf" }, + { pattern: "example.com/*", zone_id: "asdfadsf" }, + { pattern: "example.com/abc/def/*", zone_id: "asdfadsf" }, + ], + assets: { + directory: "assets", + }, + }); + writeWorkerSource(); + await mockAUSRequest([]); + mockSubDomainRequest(); + mockUpdateWorkerSubdomain({ enabled: false, previews_enabled: true }); + mockUploadWorkerRequest({ + expectedAssets: { + jwt: "<>", + config: {}, + }, + expectedType: "esm", + expectedMainModule: "index.js", + }); + mockPublishRoutesRequest({ + routes: [ + { + pattern: "example.com/blog/*", + zone_id: "asdfadsf", + }, + { + pattern: "example.com/*", + zone_id: "asdfadsf", + }, + { + pattern: "example.com/abc/def/*", + zone_id: "asdfadsf", + }, + ], + }); - custom.co.uk/*: - Wildcard operators (*) are not allowed in Custom Domains - Paths are not allowed in Custom Domains] - `); - }); + writeAssets([{ filePath: "asset.txt", content: "Content of file-1" }]); + + await runWrangler(`deploy ./index`); + + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] Warning: The following routes will attempt to serve Assets on a configured path: + + • example.com/blog/* (Will match assets: assets/blog/*) + • example.com/abc/def/* (Will match assets: assets/abc/def/*) + + Requests not matching an asset will be forwarded to the Worker's code. + + " + `); + expect(std.out).toMatchInlineSnapshot(` + "Total Upload: xx KiB / gzip: xx KiB + Worker Startup Time: 100 ms + Uploaded test-name (TIMINGS) + Deployed test-name triggers (TIMINGS) + example.com/blog/* (zone id: asdfadsf) + example.com/* (zone id: asdfadsf) + example.com/abc/def/* (zone id: asdfadsf) + Current Version ID: Galaxy-Class" + `); + }); + + it("should not warn on mounted paths if serve_directly = true", async () => { + writeWranglerConfig({ + routes: [ + "simple.co.uk/path/*", + "simple.co.uk/*", + "*/*", + "*/blog/*", + { pattern: "example.com/blog/*", zone_id: "asdfadsf" }, + { pattern: "example.com/*", zone_id: "asdfadsf" }, + { pattern: "example.com/abc/def/*", zone_id: "asdfadsf" }, + ], + assets: { + directory: "assets", + experimental_serve_directly: true, + }, + }); + await mockAUSRequest([]); + mockSubDomainRequest(); + mockUpdateWorkerSubdomain({ enabled: false, previews_enabled: true }); + mockUploadWorkerRequest({ + expectedAssets: { + jwt: "<>", + config: { + serve_directly: true, + }, + }, + expectedType: "none", + }); + mockPublishRoutesRequest({ + routes: [ + // @ts-expect-error - this is what is expected + { + pattern: "simple.co.uk/path/*", + }, + // @ts-expect-error - this is what is expected + { + pattern: "simple.co.uk/*", + }, + // @ts-expect-error - this is what is expected + { + pattern: "*/*", + }, + // @ts-expect-error - this is what is expected + { + pattern: "*/blog/*", + }, + { + pattern: "example.com/blog/*", + zone_id: "asdfadsf", + }, + { + pattern: "example.com/*", + zone_id: "asdfadsf", + }, + { + pattern: "example.com/abc/def/*", + zone_id: "asdfadsf", + }, + ], + }); + + writeWorkerSource(); + writeAssets([{ filePath: "asset.txt", content: "Content of file-1" }]); + + await runWrangler(`deploy`); + expect(std.warn).toMatchInlineSnapshot(`""`); + expect(std.out).toMatchInlineSnapshot(` + "Total Upload: xx KiB / gzip: xx KiB + Worker Startup Time: 100 ms + Uploaded test-name (TIMINGS) + Deployed test-name triggers (TIMINGS) + simple.co.uk/path/* + simple.co.uk/* + */* + */blog/* + example.com/blog/* (zone id: asdfadsf) + example.com/* (zone id: asdfadsf) + example.com/abc/def/* (zone id: asdfadsf) + Current Version ID: Galaxy-Class" + `); + }); + }); it.todo("should error if it's a workers.dev route"); }); diff --git a/packages/wrangler/src/__tests__/dev.test.ts b/packages/wrangler/src/__tests__/dev.test.ts index f4125b907417..23d77e47ea01 100644 --- a/packages/wrangler/src/__tests__/dev.test.ts +++ b/packages/wrangler/src/__tests__/dev.test.ts @@ -374,6 +374,7 @@ describe.sequential("wrangler dev", () => { ], }); }); + it("should error if custom domains with paths are passed in but allow paths on normal routes", async () => { fs.writeFileSync("index.js", `export default {};`); writeWranglerConfig({ @@ -401,61 +402,33 @@ describe.sequential("wrangler dev", () => { Paths are not allowed in Custom Domains] `); }); - it("should error on routes with paths if assets are present", async () => { + + it("should warn on mounted paths in dev", async () => { writeWranglerConfig({ routes: [ - "simple.co.uk/path", "simple.co.uk/path/*", - "simple.co.uk/", "simple.co.uk/*", - "simple.co.uk", - { pattern: "route.co.uk/path", zone_id: "asdfadsf" }, - { pattern: "route.co.uk/path/*", zone_id: "asdfadsf" }, - { pattern: "route.co.uk/*", zone_id: "asdfadsf" }, - { pattern: "route.co.uk/", zone_id: "asdfadsf" }, - { pattern: "route.co.uk", zone_id: "asdfadsf" }, - { pattern: "custom.co.uk/path", custom_domain: true }, - { pattern: "custom.co.uk/*", custom_domain: true }, - { pattern: "custom.co.uk", custom_domain: true }, + "*/*", + "*/blog/*", + { pattern: "example.com/blog/*", zone_id: "asdfadsf" }, + { pattern: "example.com/*", zone_id: "asdfadsf" }, + { pattern: "example.com/abc/def/*", zone_id: "asdfadsf" }, ], - assets: { - directory: "assets", - }, }); - fs.mkdirSync("assets"); - await expect(runWrangler(`dev`)).rejects - .toThrowErrorMatchingInlineSnapshot(` - [Error: Invalid Routes: - simple.co.uk/path: - Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /path with /* - - simple.co.uk/path/*: - Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /path/* with /* - - simple.co.uk/: - Workers which have static assets must end with a wildcard path. Update the route to end with /* - simple.co.uk: - Workers which have static assets must end with a wildcard path. Update the route to end with /* - - route.co.uk/path: - Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /path with /* - - route.co.uk/path/*: - Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /path/* with /* + fs.mkdirSync("assets"); - route.co.uk/: - Workers which have static assets must end with a wildcard path. Update the route to end with /* + await runWranglerUntilConfig("dev --assets assets"); - route.co.uk: - Workers which have static assets must end with a wildcard path. Update the route to end with /* + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] Warning: The following routes will attempt to serve Assets on a configured path: - custom.co.uk/path: - Paths are not allowed in Custom Domains + • simple.co.uk/path/* (Will match assets: assets/path/*) + • */blog/* (Will match assets: assets/blog/*) + • example.com/blog/* (Will match assets: assets/blog/*) + • example.com/abc/def/* (Will match assets: assets/abc/def/*) - custom.co.uk/*: - Wildcard operators (*) are not allowed in Custom Domains - Paths are not allowed in Custom Domains] + " `); }); }); diff --git a/packages/wrangler/src/deploy/deploy.ts b/packages/wrangler/src/deploy/deploy.ts index a5e3c88c25bd..5c24b2492cdf 100644 --- a/packages/wrangler/src/deploy/deploy.ts +++ b/packages/wrangler/src/deploy/deploy.ts @@ -174,8 +174,10 @@ function errIsStartupErr(err: unknown): err is ParseError & { code: 10021 } { return false; } -export const validateRoutes = (routes: Route[], hasAssets: boolean) => { +export const validateRoutes = (routes: Route[], assets?: AssetsOptions) => { const invalidRoutes: Record = {}; + const mountedAssetRoutes: string[] = []; + for (const route of routes) { if (typeof route !== "string" && route.custom_domain) { if (route.pattern.includes("*")) { @@ -190,26 +192,17 @@ export const validateRoutes = (routes: Route[], hasAssets: boolean) => { `Paths are not allowed in Custom Domains` ); } - } else if (hasAssets) { + // If we have Assets but we're not always hitting the Worker then validate + } else if ( + assets?.directory !== undefined && + assets.assetConfig.serve_directly !== true + ) { const pattern = typeof route === "string" ? route : route.pattern; const components = pattern.split("/"); - if ( - // = ["route.com"] bare domains are invalid as it would only match exactly that - components.length === 1 || - // = ["route.com",""] as above - (components.length === 2 && components[1] === "") - ) { - invalidRoutes[pattern] ??= []; - invalidRoutes[pattern].push( - `Workers which have static assets must end with a wildcard path. Update the route to end with /*` - ); - // ie it doesn't match exactly "route.com/*" = [route.com, *] - } else if (!(components.length === 2 && components[1] === "*")) { - invalidRoutes[pattern] ??= []; - invalidRoutes[pattern].push( - `Workers which have static assets cannot be routed on a URL which has a path component. Update the route to replace /${components.slice(1).join("/")} with /*` - ); + // If this isn't `domain.com/*` then we're mounting to a path + if (!(components.length === 2 && components[1] === "*")) { + mountedAssetRoutes.push(pattern); } } } @@ -221,6 +214,26 @@ export const validateRoutes = (routes: Route[], hasAssets: boolean) => { .join(`\n\n`) ); } + + if (mountedAssetRoutes.length > 0 && assets?.directory !== undefined) { + const relativeAssetsDir = path.relative(process.cwd(), assets.directory); + + logger.once.warn( + `Warning: The following routes will attempt to serve Assets on a configured path:\n${mountedAssetRoutes + .map((route) => { + const routeNoScheme = route.replace(/https?:\/\//g, ""); + const assetPath = path.join( + relativeAssetsDir, + routeNoScheme.substring(routeNoScheme.indexOf("/")) + ); + return ` • ${route} (Will match assets: ${assetPath})`; + }) + .join("\n")}` + + (assets?.routingConfig.has_user_worker + ? "\n\nRequests not matching an asset will be forwarded to the Worker's code." + : "") + ); + } }; export function renderRoute(route: Route): string { @@ -435,7 +448,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m const routes = props.routes ?? config.routes ?? (config.route ? [config.route] : []) ?? []; - validateRoutes(routes, Boolean(props.assetsOptions)); + validateRoutes(routes, props.assetsOptions); const jsxFactory = props.jsxFactory || config.jsx_factory; const jsxFragment = props.jsxFragment || config.jsx_fragment; diff --git a/packages/wrangler/src/dev.ts b/packages/wrangler/src/dev.ts index 7d48269ec2d3..f2b029641f60 100644 --- a/packages/wrangler/src/dev.ts +++ b/packages/wrangler/src/dev.ts @@ -10,6 +10,7 @@ import { convertCfWorkerInitBindingstoBindings, extractBindingsOfType, } from "./api/startDevWorker/utils"; +import { getAssetsOptions } from "./assets"; import { configFileName, formatConfigSnippet } from "./config"; import { resolveWranglerConfigPath } from "./config/config-helpers"; import { createCommand } from "./core/create-command"; @@ -868,9 +869,7 @@ export async function getHostAndRoutes( routes?: Extract[]; assets?: string; }, - config: Pick & { - dev: Pick; - } + config: Config ) { // TODO: if worker_dev = false and no routes, then error (only for dev) // Compute zone info from the `host` and `route` args and config; @@ -891,7 +890,8 @@ export async function getHostAndRoutes( } }); if (routes) { - validateRoutes(routes, Boolean(args.assets || config.assets)); + const assetOptions = getAssetsOptions({ assets: args.assets }, config); + validateRoutes(routes, assetOptions); } return { host, routes }; } diff --git a/packages/wrangler/src/triggers/deploy.ts b/packages/wrangler/src/triggers/deploy.ts index 64c46ca04bb3..946a9d4c74c7 100644 --- a/packages/wrangler/src/triggers/deploy.ts +++ b/packages/wrangler/src/triggers/deploy.ts @@ -42,7 +42,7 @@ export default async function triggersDeploy( props.routes ?? config.routes ?? (config.route ? [config.route] : []) ?? []; const routesOnly: Array = []; const customDomainsOnly: Array = []; - validateRoutes(routes, Boolean(props.assetsOptions)); + validateRoutes(routes, props.assetsOptions); for (const route of routes) { if (typeof route !== "string" && route.custom_domain) { customDomainsOnly.push(route); From fb819f9970285d3fc4ca8e98d652238c554d568b Mon Sep 17 00:00:00 2001 From: emily-shen <69125074+emily-shen@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:11:05 +0000 Subject: [PATCH 02/53] feat: add experimental_readRawConfig() (#7573) * add experimental_readRawConfig and tests * move printBindings out of /config/index.ts * fixups * changeset * actually export --- .changeset/blue-laws-bathe.md | 7 + .../wrangler/docs/how-to/add-a-binding.md | 2 +- .../src/__tests__/configuration.test.ts | 54 +- .../api/startDevWorker/ConfigController.ts | 3 +- packages/wrangler/src/cli.ts | 2 + .../wrangler/src/config/config-helpers.ts | 1 - packages/wrangler/src/config/index.ts | 506 +----------------- packages/wrangler/src/config/validation.ts | 3 +- packages/wrangler/src/deploy/deploy.ts | 3 +- .../src/deployment-bundle/bindings.ts | 2 +- packages/wrangler/src/index.ts | 6 +- packages/wrangler/src/utils/print-bindings.ts | 488 +++++++++++++++++ packages/wrangler/src/versions/upload.ts | 3 +- 13 files changed, 573 insertions(+), 507 deletions(-) create mode 100644 .changeset/blue-laws-bathe.md create mode 100644 packages/wrangler/src/utils/print-bindings.ts diff --git a/.changeset/blue-laws-bathe.md b/.changeset/blue-laws-bathe.md new file mode 100644 index 000000000000..9b65d75318fc --- /dev/null +++ b/.changeset/blue-laws-bathe.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +feat: add experimental_readRawConfig() + +Adds a Wrangler API to find and read a config file diff --git a/packages/wrangler/docs/how-to/add-a-binding.md b/packages/wrangler/docs/how-to/add-a-binding.md index 9cabb2d6d52b..669fd845a055 100644 --- a/packages/wrangler/docs/how-to/add-a-binding.md +++ b/packages/wrangler/docs/how-to/add-a-binding.md @@ -7,7 +7,7 @@ - `CfWorkerInit` in: `packages/wrangler/src/deployment-bundle/worker.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/deployment-bundle/worker.ts#L79C1-L85C2) - `WorkerMetadataBinding` in: `packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts` [ref-1](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts#L65) [ref-2](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts#L219-L225) 1. Add type to DevEnv `Binding` union in: `packages/wrangler/src/api/startDevWorker/types.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/api/startDevWorker/types.ts#L246) -1. Add user-friendly output for `printBindings` in: `packages/wrangler/src/config/index.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/config/index.ts#L270-L280) +1. Add user-friendly output for `printBindings` in: `packages/wrangler/src/utils/print-bindings.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/utils/print-bindings.ts) 1. Add mapping functions to: - `createWorkerUploadForm` in: `packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts#L219-L225) - `convertCfWorkerInitBindingstoBindings` in: `packages/wrangler/src/api/startDevWorker/utils.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/api/startDevWorker/utils.ts#L118-L123) diff --git a/packages/wrangler/src/__tests__/configuration.test.ts b/packages/wrangler/src/__tests__/configuration.test.ts index f20b25fbb28e..01d2b05185ef 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -1,5 +1,6 @@ +import * as fs from "fs"; import path from "node:path"; -import { readConfig } from "../config"; +import { experimental_readRawConfig, readConfig } from "../config"; import { normalizeAndValidateConfig } from "../config/validation"; import { run } from "../experimental-flags"; import { normalizeString } from "./helpers/normalize"; @@ -6037,6 +6038,57 @@ describe("normalizeAndValidateConfig()", () => { }); }); +describe("experimental_readRawConfig()", () => { + describe.each(["json", "jsonc", "toml"])( + `with %s config files`, + (configType) => { + runInTempDir(); + it(`should find a ${configType} config file given a specific path`, () => { + fs.mkdirSync("../folder", { recursive: true }); + writeWranglerConfig({}, `../folder/config.${configType}`); + + const result = experimental_readRawConfig({ + config: `../folder/config.${configType}`, + }); + expect(result.rawConfig).toEqual({ + compatibility_date: "2022-01-12", + name: "test-name", + }); + }); + + it("should find a config file given a specific script", () => { + fs.mkdirSync("./path/to", { recursive: true }); + writeWranglerConfig( + { name: "config-one" }, + `./path/wrangler.${configType}` + ); + + fs.mkdirSync("../folder", { recursive: true }); + writeWranglerConfig( + { name: "config-two" }, + `../folder/wrangler.${configType}` + ); + + let result = experimental_readRawConfig({ + script: "./path/to/index.js", + }); + expect(result.rawConfig).toEqual({ + compatibility_date: "2022-01-12", + name: "config-one", + }); + + result = experimental_readRawConfig({ + script: "../folder/index.js", + }); + expect(result.rawConfig).toEqual({ + compatibility_date: "2022-01-12", + name: "config-two", + }); + }); + } + ); +}); + function normalizePath(text: string): string { return text .replace("project\\wrangler.toml", "project/wrangler.toml") diff --git a/packages/wrangler/src/api/startDevWorker/ConfigController.ts b/packages/wrangler/src/api/startDevWorker/ConfigController.ts index 6395f3706327..2b085db269e2 100644 --- a/packages/wrangler/src/api/startDevWorker/ConfigController.ts +++ b/packages/wrangler/src/api/startDevWorker/ConfigController.ts @@ -10,7 +10,7 @@ import { isLegacyEnv, } from "../.."; import { getAssetsOptions, validateAssetsArgsAndConfig } from "../../assets"; -import { printBindings, readConfig } from "../../config"; +import { readConfig } from "../../config"; import { getEntry } from "../../deployment-bundle/entry"; import { getBindings, @@ -24,6 +24,7 @@ import { UserError } from "../../errors"; import { logger } from "../../logger"; import { requireApiToken, requireAuth } from "../../user"; import { memoizeGetPort } from "../../utils/memoizeGetPort"; +import { printBindings } from "../../utils/print-bindings"; import { getZoneIdForPreview } from "../../zones"; import { Controller } from "./BaseController"; import { castErrorCause } from "./events"; diff --git a/packages/wrangler/src/cli.ts b/packages/wrangler/src/cli.ts index e9e0ae4b50bd..6da850958a54 100644 --- a/packages/wrangler/src/cli.ts +++ b/packages/wrangler/src/cli.ts @@ -58,3 +58,5 @@ const generateASSETSBinding: ( // eslint-disable-next-line @typescript-eslint/no-var-requires require("./miniflare-cli/assets").default; export { generateASSETSBinding as unstable_generateASSETSBinding }; + +export { experimental_readRawConfig } from "./config"; diff --git a/packages/wrangler/src/config/config-helpers.ts b/packages/wrangler/src/config/config-helpers.ts index 15e5247f6c6f..a02b6a47bf26 100644 --- a/packages/wrangler/src/config/config-helpers.ts +++ b/packages/wrangler/src/config/config-helpers.ts @@ -17,7 +17,6 @@ export function resolveWranglerConfigPath({ } const leafPath = script !== undefined ? path.dirname(script) : process.cwd(); - return findWranglerConfig(leafPath); } diff --git a/packages/wrangler/src/config/index.ts b/packages/wrangler/src/config/index.ts index 6b369bacbe94..b1b73f933ad6 100644 --- a/packages/wrangler/src/config/index.ts +++ b/packages/wrangler/src/config/index.ts @@ -1,17 +1,13 @@ import fs from "node:fs"; import TOML from "@iarna/toml"; -import chalk from "chalk"; import dotenv from "dotenv"; import { FatalError, UserError } from "../errors"; -import { getFlag } from "../experimental-flags"; import { logger } from "../logger"; import { EXIT_CODE_INVALID_PAGES_CONFIG } from "../pages/errors"; import { parseJSONC, parseTOML, readFileSync } from "../parse"; import { resolveWranglerConfigPath } from "./config-helpers"; import { isPagesConfig, normalizeAndValidateConfig } from "./validation"; import { validatePagesConfig } from "./validation-pages"; -import type { CfWorkerInit } from "../deployment-bundle/worker"; -import type { WorkerRegistry } from "../dev-registry"; import type { CommonYargsOptions } from "../yargs-types"; import type { Config, OnlyCamelCase, RawConfig } from "./config"; import type { NormalizeAndValidateConfigArgs } from "./validation"; @@ -82,8 +78,7 @@ export function readConfig( args: ReadConfigCommandArgs, { hideWarnings = false }: { hideWarnings?: boolean } = {} ): Config { - const configPath = resolveWranglerConfigPath(args); - const rawConfig = readRawConfig(configPath); + const { rawConfig, configPath } = experimental_readRawConfig(args); const { config, diagnostics } = normalizeAndValidateConfig( rawConfig, @@ -105,11 +100,10 @@ export function readPagesConfig( args: ReadConfigCommandArgs, { hideWarnings = false }: { hideWarnings?: boolean } = {} ): Omit & { pages_build_output_dir: string } { - const configPath = resolveWranglerConfigPath(args); - let rawConfig: RawConfig; + let configPath: string | undefined; try { - rawConfig = readRawConfig(configPath); + ({ rawConfig, configPath } = experimental_readRawConfig(args)); } catch (e) { logger.error(e); throw new FatalError( @@ -158,498 +152,20 @@ export function readPagesConfig( }; } -export const readRawConfig = (configPath: string | undefined): RawConfig => { +export const experimental_readRawConfig = ( + args: ReadConfigCommandArgs +): { rawConfig: RawConfig; configPath: string | undefined } => { // Load the configuration from disk if available + const configPath = resolveWranglerConfigPath(args); + let rawConfig: RawConfig = {}; if (configPath?.endsWith("toml")) { - return parseTOML(readFileSync(configPath), configPath); + rawConfig = parseTOML(readFileSync(configPath), configPath); } else if (configPath?.endsWith("json") || configPath?.endsWith("jsonc")) { - return parseJSONC(readFileSync(configPath), configPath); + rawConfig = parseJSONC(readFileSync(configPath), configPath); } - return {}; + return { rawConfig, configPath }; }; -function addLocalSuffix( - id: string | symbol | undefined, - local: boolean = false -) { - if (id === undefined || typeof id === "symbol") { - id = ""; - } - return `${id}${local ? " (local)" : ""}`; -} - -export const friendlyBindingNames: Record< - keyof CfWorkerInit["bindings"], - string -> = { - data_blobs: "Data Blobs", - durable_objects: "Durable Objects", - kv_namespaces: "KV Namespaces", - send_email: "Send Email", - queues: "Queues", - d1_databases: "D1 Databases", - vectorize: "Vectorize Indexes", - hyperdrive: "Hyperdrive Configs", - r2_buckets: "R2 Buckets", - logfwdr: "logfwdr", - services: "Services", - analytics_engine_datasets: "Analytics Engine Datasets", - text_blobs: "Text Blobs", - browser: "Browser", - ai: "AI", - version_metadata: "Worker Version Metadata", - unsafe: "Unsafe Metadata", - vars: "Vars", - wasm_modules: "Wasm Modules", - dispatch_namespaces: "Dispatch Namespaces", - mtls_certificates: "mTLS Certificates", - workflows: "Workflows", - pipelines: "Pipelines", - assets: "Assets", -} as const; - -/** - * Print all the bindings a worker using a given config would have access to - */ -export function printBindings( - bindings: Partial, - context: { - registry?: WorkerRegistry | null; - local?: boolean; - name?: string; - provisioning?: boolean; - } = {} -) { - let hasConnectionStatus = false; - const truncate = (item: string | Record) => { - const s = typeof item === "string" ? item : JSON.stringify(item); - const maxLength = 40; - if (s.length < maxLength) { - return s; - } - - return `${s.substring(0, maxLength - 3)}...`; - }; - - const output: { - name: string; - entries: { key: string; value: string | boolean }[]; - }[] = []; - - const { - data_blobs, - durable_objects, - workflows, - kv_namespaces, - send_email, - queues, - d1_databases, - vectorize, - hyperdrive, - r2_buckets, - logfwdr, - services, - analytics_engine_datasets, - text_blobs, - browser, - ai, - version_metadata, - unsafe, - vars, - wasm_modules, - dispatch_namespaces, - mtls_certificates, - pipelines, - } = bindings; - - if (data_blobs !== undefined && Object.keys(data_blobs).length > 0) { - output.push({ - name: friendlyBindingNames.data_blobs, - entries: Object.entries(data_blobs).map(([key, value]) => ({ - key, - value: typeof value === "string" ? truncate(value) : "", - })), - }); - } - - if (durable_objects !== undefined && durable_objects.bindings.length > 0) { - output.push({ - name: friendlyBindingNames.durable_objects, - entries: durable_objects.bindings.map( - ({ name, class_name, script_name }) => { - let value = class_name; - if (script_name) { - if (context.local && context.registry !== null) { - const registryDefinition = context.registry?.[script_name]; - - hasConnectionStatus = true; - if ( - registryDefinition && - registryDefinition.durableObjects.some( - (d) => d.className === class_name - ) - ) { - value += ` (defined in ${script_name} ${chalk.green("[connected]")})`; - } else { - value += ` (defined in ${script_name} ${chalk.red("[not connected]")})`; - } - } else { - value += ` (defined in ${script_name})`; - } - } - - return { - key: name, - value, - }; - } - ), - }); - } - - if (workflows !== undefined && workflows.length > 0) { - output.push({ - name: friendlyBindingNames.workflows, - entries: workflows.map(({ class_name, script_name, binding }) => { - let value = class_name; - if (script_name) { - value += ` (defined in ${script_name})`; - } - - return { - key: binding, - value, - }; - }), - }); - } - - if (kv_namespaces !== undefined && kv_namespaces.length > 0) { - output.push({ - name: friendlyBindingNames.kv_namespaces, - entries: kv_namespaces.map(({ binding, id }) => { - return { - key: binding, - value: addLocalSuffix(id, context.local), - }; - }), - }); - } - - if (send_email !== undefined && send_email.length > 0) { - output.push({ - name: friendlyBindingNames.send_email, - entries: send_email.map( - ({ name, destination_address, allowed_destination_addresses }) => { - return { - key: name, - value: - destination_address || - allowed_destination_addresses?.join(", ") || - "unrestricted", - }; - } - ), - }); - } - - if (queues !== undefined && queues.length > 0) { - output.push({ - name: friendlyBindingNames.queues, - entries: queues.map(({ binding, queue_name }) => { - return { - key: binding, - value: addLocalSuffix(queue_name, context.local), - }; - }), - }); - } - - if (d1_databases !== undefined && d1_databases.length > 0) { - output.push({ - name: friendlyBindingNames.d1_databases, - entries: d1_databases.map( - ({ binding, database_name, database_id, preview_database_id }) => { - const remoteDatabaseId = - typeof database_id === "string" ? database_id : null; - let databaseValue = - remoteDatabaseId && database_name - ? `${database_name} (${remoteDatabaseId})` - : remoteDatabaseId ?? database_name; - - //database_id is local when running `wrangler dev --local` - if (preview_database_id && database_id !== "local") { - databaseValue = `${databaseValue ? `${databaseValue}, ` : ""}Preview: (${preview_database_id})`; - } - return { - key: binding, - value: addLocalSuffix(databaseValue, context.local), - }; - } - ), - }); - } - - if (vectorize !== undefined && vectorize.length > 0) { - output.push({ - name: friendlyBindingNames.vectorize, - entries: vectorize.map(({ binding, index_name }) => { - return { - key: binding, - value: addLocalSuffix(index_name, context.local), - }; - }), - }); - } - - if (hyperdrive !== undefined && hyperdrive.length > 0) { - output.push({ - name: friendlyBindingNames.hyperdrive, - entries: hyperdrive.map(({ binding, id }) => { - return { - key: binding, - value: addLocalSuffix(id, context.local), - }; - }), - }); - } - - if (r2_buckets !== undefined && r2_buckets.length > 0) { - output.push({ - name: friendlyBindingNames.r2_buckets, - entries: r2_buckets.map(({ binding, bucket_name, jurisdiction }) => { - let name = typeof bucket_name === "string" ? bucket_name : ""; - - if (jurisdiction !== undefined) { - name += ` (${jurisdiction})`; - } - - return { - key: binding, - value: addLocalSuffix(name, context.local), - }; - }), - }); - } - - if (logfwdr !== undefined && logfwdr.bindings.length > 0) { - output.push({ - name: friendlyBindingNames.logfwdr, - entries: logfwdr.bindings.map((binding) => { - return { - key: binding.name, - value: binding.destination, - }; - }), - }); - } - - if (services !== undefined && services.length > 0) { - output.push({ - name: friendlyBindingNames.services, - entries: services.map(({ binding, service, entrypoint }) => { - let value = service; - if (entrypoint) { - value += `#${entrypoint}`; - } - - if (context.local && context.registry !== null) { - const registryDefinition = context.registry?.[service]; - hasConnectionStatus = true; - - if ( - registryDefinition && - (!entrypoint || - registryDefinition.entrypointAddresses?.[entrypoint]) - ) { - value = value + " " + chalk.green("[connected]"); - } else { - value = value + " " + chalk.red("[not connected]"); - } - } - return { - key: binding, - value, - }; - }), - }); - } - - if ( - analytics_engine_datasets !== undefined && - analytics_engine_datasets.length > 0 - ) { - output.push({ - name: friendlyBindingNames.analytics_engine_datasets, - entries: analytics_engine_datasets.map(({ binding, dataset }) => { - return { - key: binding, - value: dataset ?? binding, - }; - }), - }); - } - - if (text_blobs !== undefined && Object.keys(text_blobs).length > 0) { - output.push({ - name: friendlyBindingNames.text_blobs, - entries: Object.entries(text_blobs).map(([key, value]) => ({ - key, - value: truncate(value), - })), - }); - } - - if (browser !== undefined) { - output.push({ - name: friendlyBindingNames.browser, - entries: [{ key: "Name", value: browser.binding }], - }); - } - - if (ai !== undefined) { - const entries: [{ key: string; value: string | boolean }] = [ - { key: "Name", value: ai.binding }, - ]; - if (ai.staging) { - entries.push({ key: "Staging", value: ai.staging }); - } - - output.push({ - name: friendlyBindingNames.ai, - entries: entries, - }); - } - - if (pipelines?.length) { - output.push({ - name: friendlyBindingNames.pipelines, - entries: pipelines.map(({ binding, pipeline }) => ({ - key: binding, - value: pipeline, - })), - }); - } - - if (version_metadata !== undefined) { - output.push({ - name: friendlyBindingNames.version_metadata, - entries: [{ key: "Name", value: version_metadata.binding }], - }); - } - - if (unsafe?.bindings !== undefined && unsafe.bindings.length > 0) { - output.push({ - name: friendlyBindingNames.unsafe, - entries: unsafe.bindings.map(({ name, type }) => ({ - key: type, - value: name, - })), - }); - } - - if (vars !== undefined && Object.keys(vars).length > 0) { - output.push({ - name: friendlyBindingNames.vars, - entries: Object.entries(vars).map(([key, value]) => { - let parsedValue; - if (typeof value === "string") { - parsedValue = `"${truncate(value)}"`; - } else if (typeof value === "object") { - parsedValue = JSON.stringify(value, null, 1); - } else { - parsedValue = `${truncate(`${value}`)}`; - } - return { - key, - value: parsedValue, - }; - }), - }); - } - - if (wasm_modules !== undefined && Object.keys(wasm_modules).length > 0) { - output.push({ - name: friendlyBindingNames.wasm_modules, - entries: Object.entries(wasm_modules).map(([key, value]) => ({ - key, - value: typeof value === "string" ? truncate(value) : "", - })), - }); - } - - if (dispatch_namespaces !== undefined && dispatch_namespaces.length > 0) { - output.push({ - name: friendlyBindingNames.dispatch_namespaces, - entries: dispatch_namespaces.map(({ binding, namespace, outbound }) => { - return { - key: binding, - value: outbound - ? `${namespace} (outbound -> ${outbound.service})` - : namespace, - }; - }), - }); - } - - if (mtls_certificates !== undefined && mtls_certificates.length > 0) { - output.push({ - name: friendlyBindingNames.mtls_certificates, - entries: mtls_certificates.map(({ binding, certificate_id }) => { - return { - key: binding, - value: certificate_id, - }; - }), - }); - } - - if (unsafe?.metadata !== undefined) { - output.push({ - name: friendlyBindingNames.unsafe, - entries: Object.entries(unsafe.metadata).map(([key, value]) => ({ - key, - value: JSON.stringify(value), - })), - }); - } - - if (output.length === 0) { - return; - } - - let title: string; - if (context.provisioning) { - title = "The following bindings need to be provisioned:"; - } else if (context.name && getFlag("MULTIWORKER")) { - title = `${chalk.blue(context.name)} has access to the following bindings:`; - } else { - title = "Your worker has access to the following bindings:"; - } - - const message = [ - title, - ...output - .map((bindingGroup) => { - return [ - `- ${bindingGroup.name}:`, - bindingGroup.entries.map( - ({ key, value }) => ` - ${key}${value ? ":" : ""} ${value}` - ), - ]; - }) - .flat(2), - ].join("\n"); - - logger.log(message); - - if (hasConnectionStatus) { - logger.once.info( - `\nService bindings & durable object bindings connect to other \`wrangler dev\` processes running locally, with their connection status indicated by ${chalk.green("[connected]")} or ${chalk.red("[not connected]")}. For more details, refer to https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#local-development\n` - ); - } -} - export function withConfig( handler: ( args: OnlyCamelCase & { config: Config } diff --git a/packages/wrangler/src/config/validation.ts b/packages/wrangler/src/config/validation.ts index b4f2f8343b1b..a36826ed1cc1 100644 --- a/packages/wrangler/src/config/validation.ts +++ b/packages/wrangler/src/config/validation.ts @@ -4,6 +4,7 @@ import TOML from "@iarna/toml"; import { dedent } from "ts-dedent"; import { UserError } from "../errors"; import { getFlag } from "../experimental-flags"; +import { friendlyBindingNames } from "../utils/print-bindings"; import { Diagnostics } from "./diagnostics"; import { all, @@ -32,7 +33,7 @@ import { validateRequiredProperty, validateTypedArray, } from "./validation-helpers"; -import { configFileName, formatConfigSnippet, friendlyBindingNames } from "."; +import { configFileName, formatConfigSnippet } from "."; import type { CreateApplicationRequest, UserDeploymentConfiguration, diff --git a/packages/wrangler/src/deploy/deploy.ts b/packages/wrangler/src/deploy/deploy.ts index 5c24b2492cdf..a7c343b4c1fd 100644 --- a/packages/wrangler/src/deploy/deploy.ts +++ b/packages/wrangler/src/deploy/deploy.ts @@ -5,7 +5,7 @@ import { URLSearchParams } from "node:url"; import { cancel } from "@cloudflare/cli"; import { syncAssets } from "../assets"; import { fetchListResult, fetchResult } from "../cfetch"; -import { configFileName, formatConfigSnippet, printBindings } from "../config"; +import { configFileName, formatConfigSnippet } from "../config"; import { getBindings, provisionBindings } from "../deployment-bundle/bindings"; import { bundleWorker } from "../deployment-bundle/bundle"; import { @@ -47,6 +47,7 @@ import { maybeRetrieveFileSourceMap, } from "../sourcemap"; import triggersDeploy from "../triggers/deploy"; +import { printBindings } from "../utils/print-bindings"; import { retryOnError } from "../utils/retry"; import { createDeployment, diff --git a/packages/wrangler/src/deployment-bundle/bindings.ts b/packages/wrangler/src/deployment-bundle/bindings.ts index 1773c2041c8b..a9a90516564d 100644 --- a/packages/wrangler/src/deployment-bundle/bindings.ts +++ b/packages/wrangler/src/deployment-bundle/bindings.ts @@ -1,7 +1,6 @@ import chalk from "chalk"; import { isLegacyEnv } from ".."; import { fetchResult } from "../cfetch"; -import { printBindings } from "../config"; import { createD1Database } from "../d1/create"; import { listDatabases } from "../d1/list"; import { prompt, select } from "../dialogs"; @@ -9,6 +8,7 @@ import { FatalError, UserError } from "../errors"; import { createKVNamespace, listKVNamespaces } from "../kv/helpers"; import { logger } from "../logger"; import { createR2Bucket, listR2Buckets } from "../r2/helpers"; +import { printBindings } from "../utils/print-bindings"; import type { Config } from "../config"; import type { WorkerMetadataBinding } from "./create-worker-upload-form"; import type { diff --git a/packages/wrangler/src/index.ts b/packages/wrangler/src/index.ts index 80ea83c4723f..2adb350657a4 100644 --- a/packages/wrangler/src/index.ts +++ b/packages/wrangler/src/index.ts @@ -10,11 +10,10 @@ import { ai } from "./ai"; import { cloudchamber } from "./cloudchamber"; import { configFileName, + experimental_readRawConfig, formatConfigSnippet, loadDotEnv, - readRawConfig, } from "./config"; -import { resolveWranglerConfigPath } from "./config/config-helpers"; import { demandSingleValue } from "./core"; import { CommandRegistry } from "./core/CommandRegistry"; import { createRegisterYargsCommand } from "./core/register-yargs-command"; @@ -1153,8 +1152,7 @@ export async function main(argv: string[]): Promise { // key to fetch) or flags try { - const configPath = resolveWranglerConfigPath(args); - const rawConfig = readRawConfig(configPath); + const { rawConfig, configPath } = experimental_readRawConfig(args); dispatcher = getMetricsDispatcher({ sendMetrics: rawConfig.send_metrics, configPath, diff --git a/packages/wrangler/src/utils/print-bindings.ts b/packages/wrangler/src/utils/print-bindings.ts new file mode 100644 index 000000000000..9d42c24e42aa --- /dev/null +++ b/packages/wrangler/src/utils/print-bindings.ts @@ -0,0 +1,488 @@ +import chalk from "chalk"; +import { getFlag } from "../experimental-flags"; +import { logger } from "../logger"; +import type { CfWorkerInit } from "../deployment-bundle/worker"; +import type { WorkerRegistry } from "../dev-registry"; + +function addLocalSuffix( + id: string | symbol | undefined, + local: boolean = false +) { + if (!id || typeof id === "symbol") { + id = ""; + } + + return `${id}${local ? " (local)" : ""}`; +} + +export const friendlyBindingNames: Record< + keyof CfWorkerInit["bindings"], + string +> = { + data_blobs: "Data Blobs", + durable_objects: "Durable Objects", + kv_namespaces: "KV Namespaces", + send_email: "Send Email", + queues: "Queues", + d1_databases: "D1 Databases", + vectorize: "Vectorize Indexes", + hyperdrive: "Hyperdrive Configs", + r2_buckets: "R2 Buckets", + logfwdr: "logfwdr", + services: "Services", + analytics_engine_datasets: "Analytics Engine Datasets", + text_blobs: "Text Blobs", + browser: "Browser", + ai: "AI", + version_metadata: "Worker Version Metadata", + unsafe: "Unsafe Metadata", + vars: "Vars", + wasm_modules: "Wasm Modules", + dispatch_namespaces: "Dispatch Namespaces", + mtls_certificates: "mTLS Certificates", + workflows: "Workflows", + pipelines: "Pipelines", + assets: "Assets", +} as const; + +/** + * Print all the bindings a worker using a given config would have access to + */ +export function printBindings( + bindings: Partial, + context: { + registry?: WorkerRegistry | null; + local?: boolean; + name?: string; + provisioning?: boolean; + } = {} +) { + let hasConnectionStatus = false; + const truncate = (item: string | Record) => { + const s = typeof item === "string" ? item : JSON.stringify(item); + const maxLength = 40; + if (s.length < maxLength) { + return s; + } + + return `${s.substring(0, maxLength - 3)}...`; + }; + + const output: { + name: string; + entries: { key: string; value: string | boolean }[]; + }[] = []; + + const { + data_blobs, + durable_objects, + workflows, + kv_namespaces, + send_email, + queues, + d1_databases, + vectorize, + hyperdrive, + r2_buckets, + logfwdr, + services, + analytics_engine_datasets, + text_blobs, + browser, + ai, + version_metadata, + unsafe, + vars, + wasm_modules, + dispatch_namespaces, + mtls_certificates, + pipelines, + } = bindings; + + if (data_blobs !== undefined && Object.keys(data_blobs).length > 0) { + output.push({ + name: friendlyBindingNames.data_blobs, + entries: Object.entries(data_blobs).map(([key, value]) => ({ + key, + value: typeof value === "string" ? truncate(value) : "", + })), + }); + } + + if (durable_objects !== undefined && durable_objects.bindings.length > 0) { + output.push({ + name: friendlyBindingNames.durable_objects, + entries: durable_objects.bindings.map( + ({ name, class_name, script_name }) => { + let value = class_name; + if (script_name) { + if (context.local && context.registry !== null) { + const registryDefinition = context.registry?.[script_name]; + + hasConnectionStatus = true; + if ( + registryDefinition && + registryDefinition.durableObjects.some( + (d) => d.className === class_name + ) + ) { + value += ` (defined in ${script_name} ${chalk.green("[connected]")})`; + } else { + value += ` (defined in ${script_name} ${chalk.red("[not connected]")})`; + } + } else { + value += ` (defined in ${script_name})`; + } + } + + return { + key: name, + value, + }; + } + ), + }); + } + + if (workflows !== undefined && workflows.length > 0) { + output.push({ + name: friendlyBindingNames.workflows, + entries: workflows.map(({ class_name, script_name, binding }) => { + let value = class_name; + if (script_name) { + value += ` (defined in ${script_name})`; + } + + return { + key: binding, + value, + }; + }), + }); + } + + if (kv_namespaces !== undefined && kv_namespaces.length > 0) { + output.push({ + name: friendlyBindingNames.kv_namespaces, + entries: kv_namespaces.map(({ binding, id }) => { + return { + key: binding, + value: addLocalSuffix(id, context.local), + }; + }), + }); + } + + if (send_email !== undefined && send_email.length > 0) { + output.push({ + name: friendlyBindingNames.send_email, + entries: send_email.map( + ({ name, destination_address, allowed_destination_addresses }) => { + return { + key: name, + value: + destination_address || + allowed_destination_addresses?.join(", ") || + "unrestricted", + }; + } + ), + }); + } + + if (queues !== undefined && queues.length > 0) { + output.push({ + name: friendlyBindingNames.queues, + entries: queues.map(({ binding, queue_name }) => { + return { + key: binding, + value: addLocalSuffix(queue_name, context.local), + }; + }), + }); + } + + if (d1_databases !== undefined && d1_databases.length > 0) { + output.push({ + name: friendlyBindingNames.d1_databases, + entries: d1_databases.map( + ({ binding, database_name, database_id, preview_database_id }) => { + const remoteDatabaseId = + typeof database_id === "string" ? database_id : null; + let databaseValue = + remoteDatabaseId && database_name + ? `${database_name} (${remoteDatabaseId})` + : remoteDatabaseId ?? database_name; + + //database_id is local when running `wrangler dev --local` + if (preview_database_id && database_id !== "local") { + databaseValue = `${databaseValue ? `${databaseValue}, ` : ""}Preview: (${preview_database_id})`; + } + return { + key: binding, + value: addLocalSuffix(databaseValue, context.local), + }; + } + ), + }); + } + + if (vectorize !== undefined && vectorize.length > 0) { + output.push({ + name: friendlyBindingNames.vectorize, + entries: vectorize.map(({ binding, index_name }) => { + return { + key: binding, + value: addLocalSuffix(index_name, context.local), + }; + }), + }); + } + + if (hyperdrive !== undefined && hyperdrive.length > 0) { + output.push({ + name: friendlyBindingNames.hyperdrive, + entries: hyperdrive.map(({ binding, id }) => { + return { + key: binding, + value: addLocalSuffix(id, context.local), + }; + }), + }); + } + + if (r2_buckets !== undefined && r2_buckets.length > 0) { + output.push({ + name: friendlyBindingNames.r2_buckets, + entries: r2_buckets.map(({ binding, bucket_name, jurisdiction }) => { + let name = typeof bucket_name === "string" ? bucket_name : ""; + + if (jurisdiction !== undefined) { + name += ` (${jurisdiction})`; + } + + return { + key: binding, + value: addLocalSuffix(name, context.local), + }; + }), + }); + } + + if (logfwdr !== undefined && logfwdr.bindings.length > 0) { + output.push({ + name: friendlyBindingNames.logfwdr, + entries: logfwdr.bindings.map((binding) => { + return { + key: binding.name, + value: binding.destination, + }; + }), + }); + } + + if (services !== undefined && services.length > 0) { + output.push({ + name: friendlyBindingNames.services, + entries: services.map(({ binding, service, entrypoint }) => { + let value = service; + if (entrypoint) { + value += `#${entrypoint}`; + } + + if (context.local && context.registry !== null) { + const registryDefinition = context.registry?.[service]; + hasConnectionStatus = true; + + if ( + registryDefinition && + (!entrypoint || + registryDefinition.entrypointAddresses?.[entrypoint]) + ) { + value = value + " " + chalk.green("[connected]"); + } else { + value = value + " " + chalk.red("[not connected]"); + } + } + return { + key: binding, + value, + }; + }), + }); + } + + if ( + analytics_engine_datasets !== undefined && + analytics_engine_datasets.length > 0 + ) { + output.push({ + name: friendlyBindingNames.analytics_engine_datasets, + entries: analytics_engine_datasets.map(({ binding, dataset }) => { + return { + key: binding, + value: dataset ?? binding, + }; + }), + }); + } + + if (text_blobs !== undefined && Object.keys(text_blobs).length > 0) { + output.push({ + name: friendlyBindingNames.text_blobs, + entries: Object.entries(text_blobs).map(([key, value]) => ({ + key, + value: truncate(value), + })), + }); + } + + if (browser !== undefined) { + output.push({ + name: friendlyBindingNames.browser, + entries: [{ key: "Name", value: browser.binding }], + }); + } + + if (ai !== undefined) { + const entries: [{ key: string; value: string | boolean }] = [ + { key: "Name", value: ai.binding }, + ]; + if (ai.staging) { + entries.push({ key: "Staging", value: ai.staging }); + } + + output.push({ + name: friendlyBindingNames.ai, + entries: entries, + }); + } + + if (pipelines?.length) { + output.push({ + name: friendlyBindingNames.pipelines, + entries: pipelines.map(({ binding, pipeline }) => ({ + key: binding, + value: pipeline, + })), + }); + } + + if (version_metadata !== undefined) { + output.push({ + name: friendlyBindingNames.version_metadata, + entries: [{ key: "Name", value: version_metadata.binding }], + }); + } + + if (unsafe?.bindings !== undefined && unsafe.bindings.length > 0) { + output.push({ + name: friendlyBindingNames.unsafe, + entries: unsafe.bindings.map(({ name, type }) => ({ + key: type, + value: name, + })), + }); + } + + if (vars !== undefined && Object.keys(vars).length > 0) { + output.push({ + name: friendlyBindingNames.vars, + entries: Object.entries(vars).map(([key, value]) => { + let parsedValue; + if (typeof value === "string") { + parsedValue = `"${truncate(value)}"`; + } else if (typeof value === "object") { + parsedValue = JSON.stringify(value, null, 1); + } else { + parsedValue = `${truncate(`${value}`)}`; + } + return { + key, + value: parsedValue, + }; + }), + }); + } + + if (wasm_modules !== undefined && Object.keys(wasm_modules).length > 0) { + output.push({ + name: friendlyBindingNames.wasm_modules, + entries: Object.entries(wasm_modules).map(([key, value]) => ({ + key, + value: typeof value === "string" ? truncate(value) : "", + })), + }); + } + + if (dispatch_namespaces !== undefined && dispatch_namespaces.length > 0) { + output.push({ + name: friendlyBindingNames.dispatch_namespaces, + entries: dispatch_namespaces.map(({ binding, namespace, outbound }) => { + return { + key: binding, + value: outbound + ? `${namespace} (outbound -> ${outbound.service})` + : namespace, + }; + }), + }); + } + + if (mtls_certificates !== undefined && mtls_certificates.length > 0) { + output.push({ + name: friendlyBindingNames.mtls_certificates, + entries: mtls_certificates.map(({ binding, certificate_id }) => { + return { + key: binding, + value: certificate_id, + }; + }), + }); + } + + if (unsafe?.metadata !== undefined) { + output.push({ + name: friendlyBindingNames.unsafe, + entries: Object.entries(unsafe.metadata).map(([key, value]) => ({ + key, + value: JSON.stringify(value), + })), + }); + } + + if (output.length === 0) { + return; + } + + let title: string; + if (context.provisioning) { + title = "The following bindings need to be provisioned:"; + } else if (context.name && getFlag("MULTIWORKER")) { + title = `${chalk.blue(context.name)} has access to the following bindings:`; + } else { + title = "Your worker has access to the following bindings:"; + } + + const message = [ + title, + ...output + .map((bindingGroup) => { + return [ + `- ${bindingGroup.name}:`, + bindingGroup.entries.map( + ({ key, value }) => ` - ${key}${value ? ":" : ""} ${value}` + ), + ]; + }) + .flat(2), + ].join("\n"); + + logger.log(message); + + if (hasConnectionStatus) { + logger.once.info( + `\nService bindings & durable object bindings connect to other \`wrangler dev\` processes running locally, with their connection status indicated by ${chalk.green("[connected]")} or ${chalk.red("[not connected]")}. For more details, refer to https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#local-development\n` + ); + } +} diff --git a/packages/wrangler/src/versions/upload.ts b/packages/wrangler/src/versions/upload.ts index 36dce73addea..94f6d2e2c56f 100644 --- a/packages/wrangler/src/versions/upload.ts +++ b/packages/wrangler/src/versions/upload.ts @@ -8,7 +8,7 @@ import { validateAssetsArgsAndConfig, } from "../assets"; import { fetchResult } from "../cfetch"; -import { configFileName, formatConfigSnippet, printBindings } from "../config"; +import { configFileName, formatConfigSnippet } from "../config"; import { createCommand } from "../core/create-command"; import { getBindings } from "../deployment-bundle/bindings"; import { bundleWorker } from "../deployment-bundle/bundle"; @@ -50,6 +50,7 @@ import { } from "../sourcemap"; import { requireAuth } from "../user"; import { collectKeyValues } from "../utils/collectKeyValues"; +import { printBindings } from "../utils/print-bindings"; import { retryOnError } from "../utils/retry"; import type { AssetsOptions } from "../assets"; import type { Config } from "../config"; From c74195c62494cbbdecc921abaaca2e1003f3caf7 Mon Sep 17 00:00:00 2001 From: Carmen Popoviciu Date: Wed, 18 Dec 2024 16:16:03 +0100 Subject: [PATCH 03/53] chore(wrangler): Fix failing e2e tests (#7585) This commit fixed some e2e tests that started failing after https://github.com/cloudflare/workers-sdk/pull/7476 --- packages/wrangler/e2e/dev.test.ts | 91 ++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 25 deletions(-) diff --git a/packages/wrangler/e2e/dev.test.ts b/packages/wrangler/e2e/dev.test.ts index 9c5e58456a26..423ae226a8af 100644 --- a/packages/wrangler/e2e/dev.test.ts +++ b/packages/wrangler/e2e/dev.test.ts @@ -1158,7 +1158,7 @@ describe("watch mode", () => { describe.each([{ cmd: "wrangler dev" }])( "Workers + Assets watch mode: $cmd", ({ cmd }) => { - it(`supports modifying existing assets during dev session and errors when invalid routes are added`, async () => { + it(`supports modifying existing assets during dev session`, async () => { const helper = new WranglerE2ETestHelper(); await helper.seed({ "wrangler.toml": dedent` @@ -1199,19 +1199,6 @@ describe("watch mode", () => { ); // expect a new eTag back because the content for this path has changed expect(response.headers.get("etag")).not.toBe(originalETag); - - // changes to routes should error while in watch mode - await helper.seed({ - "wrangler.toml": dedent` - name = "${workerName}" - compatibility_date = "2023-01-01" - route = "example.com/path/*" - - [assets] - directory = "./public" - `, - }); - await worker.readUntil(/Invalid Routes:/); }); it(`supports adding new assets during dev session`, async () => { @@ -1662,13 +1649,48 @@ describe("watch mode", () => { // now check assets are still fetchable await expect(fetchText(url)).resolves.toBe("Hello from Assets"); }); + + it(`warns on mounted paths when routes are configured in the configuration file`, async () => { + const helper = new WranglerE2ETestHelper(); + await helper.seed({ + "wrangler.toml": dedent` + name = "${workerName}" + compatibility_date = "2023-01-01" + + [assets] + directory = "./public" + `, + "public/index.html": dedent` +

Hello Workers + Assets

`, + }); + + const worker = helper.runLongLived(cmd); + const { url } = await worker.waitForReady(); + + const { response } = await fetchWithETag(`${url}/index.html`, {}); + expect(await response.text()).toBe("

Hello Workers + Assets

"); + + await helper.seed({ + "wrangler.toml": dedent` + name = "${workerName}" + compatibility_date = "2023-01-01" + route = "example.com/path/*" + + [assets] + directory = "./public" + `, + }); + await worker.readUntil( + /Warning: The following routes will attempt to serve Assets on a configured path:/ + ); + }); } ); describe.each([{ cmd: "wrangler dev --assets=dist" }])( "Workers + Assets watch mode: $cmd", ({ cmd }) => { - it(`supports modifying assets during dev session and errors when invalid routes are added`, async () => { + it(`supports modifying assets during dev session`, async () => { const helper = new WranglerE2ETestHelper(); await helper.seed({ "wrangler.toml": dedent` @@ -1749,16 +1771,6 @@ describe("watch mode", () => { } )); expect(response.status).toBe(404); - - // changes to routes should error while in watch mode - await helper.seed({ - "wrangler.toml": dedent` - name = "${workerName}" - compatibility_date = "2023-01-01" - route = "example.com/path/*" - `, - }); - await worker.readUntil(/Invalid Routes:/); }); it(`supports switching from assets-only Workers to Workers with assets during the current dev session`, async () => { @@ -1859,6 +1871,35 @@ describe("watch mode", () => { response = await fetch(`${url}/hey`); expect(response.status).toBe(404); }); + + it(`warns on mounted paths when routes are configured in the configuration file`, async () => { + const helper = new WranglerE2ETestHelper(); + await helper.seed({ + "wrangler.toml": dedent` + name = "${workerName}" + compatibility_date = "2023-01-01" + `, + "dist/index.html": dedent` +

Hello Workers + Assets

`, + }); + + const worker = helper.runLongLived(cmd); + const { url } = await worker.waitForReady(); + + const { response } = await fetchWithETag(`${url}/index.html`, {}); + expect(await response.text()).toBe("

Hello Workers + Assets

"); + + await helper.seed({ + "wrangler.toml": dedent` + name = "${workerName}" + compatibility_date = "2023-01-01" + route = "example.com/path/*" + `, + }); + await worker.readUntil( + /Warning: The following routes will attempt to serve Assets on a configured path:/ + ); + }); } ); }); From 8def8c99e1f74f313a3771c827133c59e1b1032b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Somhairle=20MacLe=C3=B2id?= Date: Wed, 18 Dec 2024 16:00:29 +0000 Subject: [PATCH 04/53] Revert "feat: add support for custom unenv resolve path" (#7583) * Revert "feat: add support for custom unenv resolve path (#7522)" This reverts commit 6403e41b809a20db59ecfd55362368926750c62d. * Create thick-ties-glow.md * Revert "chore(wrangler): update unenv dependency version (#7541)" This reverts commit ca9410a4f92a61abc0d759a3abe29da05cedeaed. * fix lockfile --- .changeset/thick-ties-glow.md | 5 ++ .../nodejs-hybrid-app/tests/index.test.ts | 2 +- packages/wrangler/package.json | 2 +- .../wrangler/src/__tests__/deploy.test.ts | 4 +- .../wrangler/src/deployment-bundle/bundle.ts | 8 +-- .../esbuild-plugins/hybrid-nodejs-compat.ts | 66 +++++++------------ .../esbuild-plugins/nodejs-plugins.ts | 10 +-- .../src/environment-variables/factory.ts | 1 - .../environment-variables/misc-variables.ts | 13 ---- pnpm-lock.yaml | 19 ++---- 10 files changed, 41 insertions(+), 89 deletions(-) create mode 100644 .changeset/thick-ties-glow.md diff --git a/.changeset/thick-ties-glow.md b/.changeset/thick-ties-glow.md new file mode 100644 index 000000000000..7932bced48bb --- /dev/null +++ b/.changeset/thick-ties-glow.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Revert support for custom unenv resolve path to address an issue with Wrangler failing to deploy Pages projects with `nodejs_compat_v2` in some cases diff --git a/fixtures/nodejs-hybrid-app/tests/index.test.ts b/fixtures/nodejs-hybrid-app/tests/index.test.ts index da7e2f26f0ec..fb46992c03c9 100644 --- a/fixtures/nodejs-hybrid-app/tests/index.test.ts +++ b/fixtures/nodejs-hybrid-app/tests/index.test.ts @@ -64,7 +64,7 @@ describe("nodejs compat", () => { } }); - test("require unenv aliased packages", async ({ expect }) => { + test("import unenv aliased packages", async ({ expect }) => { const { ip, port, stop } = await runWranglerDev( resolve(__dirname, "../src"), ["--port=0", "--inspector-port=0"] diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 7f222f6c64e2..3a49ac019072 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -83,7 +83,7 @@ "resolve": "^1.22.8", "selfsigned": "^2.0.1", "source-map": "^0.6.1", - "unenv": "npm:unenv-nightly@2.0.0-20241212-153011-af71c96", + "unenv": "npm:unenv-nightly@2.0.0-20241204-140205-a5d5190", "workerd": "1.20241205.0", "xxhash-wasm": "^1.0.1" }, diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index 5488768ef321..9c8089be5392 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -10310,7 +10310,7 @@ export default{ fs.writeFileSync( "index.js", ` - import path from 'node:path'; + import path from 'path'; console.log(path); export default {} ` @@ -10331,7 +10331,7 @@ export default{ } `); expect(fs.readFileSync("dist/index.js", { encoding: "utf-8" })).toContain( - `import path from "node:path";` + `import path from "path";` ); }); diff --git a/packages/wrangler/src/deployment-bundle/bundle.ts b/packages/wrangler/src/deployment-bundle/bundle.ts index bb35d4519de8..c5f920d03d0a 100644 --- a/packages/wrangler/src/deployment-bundle/bundle.ts +++ b/packages/wrangler/src/deployment-bundle/bundle.ts @@ -5,7 +5,6 @@ import * as esbuild from "esbuild"; import { getBuildConditionsFromEnv, getBuildPlatformFromEnv, - getUnenvResolvePathsFromEnv, } from "../environment-variables/misc-variables"; import { UserError } from "../errors"; import { getFlag } from "../experimental-flags"; @@ -391,8 +390,6 @@ export async function bundleWorker( }, }; - const unenvResolvePaths = getUnenvResolvePathsFromEnv()?.split(","); - const buildOptions: esbuild.BuildOptions & { metafile: true } = { // Don't use entryFile here as the file may have been changed when applying the middleware entryPoints: [entry.file], @@ -438,10 +435,7 @@ export async function bundleWorker( plugins: [ aliasPlugin, moduleCollector.plugin, - ...getNodeJSCompatPlugins({ - mode: nodejsCompatMode ?? null, - unenvResolvePaths, - }), + ...getNodeJSCompatPlugins(nodejsCompatMode ?? null), cloudflareInternalPlugin, buildResultPlugin, ...(plugins || []), diff --git a/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts b/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts index 052039086953..e5a6ff9960f8 100644 --- a/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts +++ b/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts @@ -1,45 +1,25 @@ import { builtinModules } from "node:module"; import nodePath from "node:path"; import dedent from "ts-dedent"; -import { cloudflare, defineEnv } from "unenv"; +import { cloudflare, env, nodeless } from "unenv"; import { getBasePath } from "../../paths"; import type { Plugin, PluginBuild } from "esbuild"; const REQUIRED_NODE_BUILT_IN_NAMESPACE = "node-built-in-modules"; const REQUIRED_UNENV_ALIAS_NAMESPACE = "required-unenv-alias"; -/** - * ESBuild plugin to apply the unenv preset. - * - * @param unenvResolvePaths Root paths used to resolve absolute paths. - * @returns ESBuild plugin - */ -export function nodejsHybridPlugin(unenvResolvePaths?: string[]): Plugin { - // Get the resolved environment. - const { env } = defineEnv({ - nodeCompat: true, - presets: [cloudflare], - resolve: { - paths: unenvResolvePaths, - }, - }); - const { alias, inject, external } = env; - // Get the unresolved alias. - const unresolvedAlias = defineEnv({ - nodeCompat: true, - presets: [cloudflare], - resolve: false, - }).env.alias; +export const nodejsHybridPlugin: () => Plugin = () => { + const { alias, inject, external } = env(nodeless, cloudflare); return { name: "hybrid-nodejs_compat", setup(build) { errorOnServiceWorkerFormat(build); handleRequireCallsToNodeJSBuiltins(build); - handleUnenvAliasedPackages(build, unresolvedAlias, alias, external); + handleUnenvAliasedPackages(build, alias, external); handleNodeJSGlobals(build, inject); }, }; -} +}; const NODEJS_MODULES_RE = new RegExp(`^(node:)?(${builtinModules.join("|")})$`); @@ -107,41 +87,45 @@ function handleRequireCallsToNodeJSBuiltins(build: PluginBuild) { ); } -/** - * Handles aliased NPM packages. - * - * @param build ESBuild PluginBuild. - * @param unresolvedAlias Unresolved aliases from the presets. - * @param alias Aliases resolved to absolute paths. - * @param external external modules. - */ function handleUnenvAliasedPackages( build: PluginBuild, - unresolvedAlias: Record, alias: Record, external: string[] ) { - const UNENV_ALIAS_RE = new RegExp(`^(${Object.keys(alias).join("|")})$`); + // esbuild expects alias paths to be absolute + const aliasAbsolute: Record = {}; + for (const [module, unresolvedAlias] of Object.entries(alias)) { + try { + aliasAbsolute[module] = require + .resolve(unresolvedAlias) + .replace(/\.cjs$/, ".mjs"); + } catch (e) { + // this is an alias for package that is not installed in the current app => ignore + } + } + + const UNENV_ALIAS_RE = new RegExp( + `^(${Object.keys(aliasAbsolute).join("|")})$` + ); build.onResolve({ filter: UNENV_ALIAS_RE }, (args) => { - const unresolved = unresolvedAlias[args.path]; + const unresolvedAlias = alias[args.path]; // Convert `require()` calls for NPM packages to a virtual ES Module that can be imported avoiding the require calls. // Note: Does not apply to Node.js packages that are handled in `handleRequireCallsToNodeJSBuiltins` if ( args.kind === "require-call" && - (unresolved.startsWith("unenv/runtime/npm/") || - unresolved.startsWith("unenv/runtime/mock/")) + (unresolvedAlias.startsWith("unenv/runtime/npm/") || + unresolvedAlias.startsWith("unenv/runtime/mock/")) ) { return { path: args.path, namespace: REQUIRED_UNENV_ALIAS_NAMESPACE, }; } - // Resolve the alias to its absolute path and potentially mark it as external return { - path: alias[args.path], - external: external.includes(unresolved), + path: aliasAbsolute[args.path], + external: external.includes(unresolvedAlias), }; }); diff --git a/packages/wrangler/src/deployment-bundle/esbuild-plugins/nodejs-plugins.ts b/packages/wrangler/src/deployment-bundle/esbuild-plugins/nodejs-plugins.ts index 30448b347f9f..b59d8fa190d7 100644 --- a/packages/wrangler/src/deployment-bundle/esbuild-plugins/nodejs-plugins.ts +++ b/packages/wrangler/src/deployment-bundle/esbuild-plugins/nodejs-plugins.ts @@ -10,13 +10,7 @@ import type { NodeJSCompatMode } from "miniflare"; /** * Returns the list of ESBuild plugins to use for a given compat mode. */ -export function getNodeJSCompatPlugins({ - mode, - unenvResolvePaths, -}: { - mode: NodeJSCompatMode; - unenvResolvePaths?: string[]; -}): Plugin[] { +export function getNodeJSCompatPlugins(mode: NodeJSCompatMode): Plugin[] { switch (mode) { case "als": return [asyncLocalStoragePlugin, nodejsCompatPlugin(mode)]; @@ -30,7 +24,7 @@ export function getNodeJSCompatPlugins({ case "v1": return [nodejsCompatPlugin(mode)]; case "v2": - return [nodejsHybridPlugin(unenvResolvePaths)]; + return [nodejsHybridPlugin()]; case null: return [nodejsCompatPlugin(mode)]; } diff --git a/packages/wrangler/src/environment-variables/factory.ts b/packages/wrangler/src/environment-variables/factory.ts index 8a2124386ff7..91d481ed3a6f 100644 --- a/packages/wrangler/src/environment-variables/factory.ts +++ b/packages/wrangler/src/environment-variables/factory.ts @@ -25,7 +25,6 @@ type VariableNames = | "WRANGLER_CI_MATCH_TAG" | "WRANGLER_BUILD_CONDITIONS" | "WRANGLER_BUILD_PLATFORM" - | "WRANGLER_UNENV_RESOLVE_PATHS" | "WRANGLER_REGISTRY_PATH"; type DeprecatedNames = diff --git a/packages/wrangler/src/environment-variables/misc-variables.ts b/packages/wrangler/src/environment-variables/misc-variables.ts index 3af8754f4664..a19426a316c0 100644 --- a/packages/wrangler/src/environment-variables/misc-variables.ts +++ b/packages/wrangler/src/environment-variables/misc-variables.ts @@ -126,19 +126,6 @@ export const getBuildPlatformFromEnv = getEnvironmentVariableFactory({ variableName: "WRANGLER_BUILD_PLATFORM", }); -/** - * `WRANGLER_UNENV_RESOLVE_PATHS` lists the paths used to resolve unenv. - * - * Note: multiple comma separated paths can be specified. - * - * By default wrangler uses the unenv preset version installed from the package.json. - * - * Setting root paths allow to use a different version of the preset. - */ -export const getUnenvResolvePathsFromEnv = getEnvironmentVariableFactory({ - variableName: "WRANGLER_UNENV_RESOLVE_PATHS", -}); - /** * `WRANGLER_REGISTRY_PATH` specifies the file based dev registry folder */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index abb9fdfa83b8..82e4e781d402 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1812,8 +1812,8 @@ importers: specifier: ^0.6.1 version: 0.6.1 unenv: - specifier: npm:unenv-nightly@2.0.0-20241212-153011-af71c96 - version: unenv-nightly@2.0.0-20241212-153011-af71c96 + specifier: npm:unenv-nightly@2.0.0-20241204-140205-a5d5190 + version: unenv-nightly@2.0.0-20241204-140205-a5d5190 workerd: specifier: 1.20241205.0 version: 1.20241205.0 @@ -9602,9 +9602,6 @@ packages: unenv-nightly@2.0.0-20241204-140205-a5d5190: resolution: {integrity: sha512-jpmAytLeiiW01pl5bhVn9wYJ4vtiLdhGe10oXlJBuQEX8mxjxO8BlEXGHU4vr4yEikjFP1wsomTHt/CLU8kUwg==} - unenv-nightly@2.0.0-20241212-153011-af71c96: - resolution: {integrity: sha512-Yugb9yPs/EZsPOY+IHloqVVEcZeJ0uwwViTedsZjOtVeYO8I29B1rzU/p84FMT0R1Ht3bHsKkNV/rzrjSd07QA==} - unenv-nightly@2.0.0-20241216-144314-7e05819: resolution: {integrity: sha512-HpRspwDDxEwb6f9jOJYdL8iuZ054GIJ61LWHui7FPcgSVUPIXjZ3Nf0bh0qVIEqSGb3bNU/C1Zcw6fKHVl4lDg==} @@ -16181,7 +16178,7 @@ snapshots: miniflare@3.20241205.0: dependencies: '@cspotcode/source-map-support': 0.8.1 - acorn: 8.14.0 + acorn: 8.11.3 acorn-walk: 8.3.2 capnp-ts: 0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii) exit-hook: 2.2.1 @@ -18502,7 +18499,7 @@ snapshots: mkdist: 1.6.0(typescript@5.6.3)(vue-tsc@2.0.29(typescript@5.6.3)) mlly: 1.7.3 pathe: 1.1.2 - pkg-types: 1.2.1 + pkg-types: 1.0.3 pretty-bytes: 6.1.1 rollup: 3.29.5 rollup-plugin-dts: 6.1.1(rollup@3.29.5)(typescript@5.6.3) @@ -18545,14 +18542,6 @@ snapshots: pathe: 1.1.2 ufo: 1.5.4 - unenv-nightly@2.0.0-20241212-153011-af71c96: - dependencies: - defu: 6.1.4 - mlly: 1.7.3 - ohash: 1.1.4 - pathe: 1.1.2 - ufo: 1.5.4 - unenv-nightly@2.0.0-20241216-144314-7e05819: dependencies: defu: 6.1.4 From c4cf040dce7804c14670c7a7da1fceb9daef998b Mon Sep 17 00:00:00 2001 From: ANT Bot <116369605+workers-devprod@users.noreply.github.com> Date: Thu, 19 Dec 2024 08:47:06 +0000 Subject: [PATCH 05/53] Version Packages (#7574) Co-authored-by: github-actions[bot] --- .changeset/blue-laws-bathe.md | 7 ------ .changeset/early-baboons-fly.md | 7 ------ .changeset/selfish-yaks-hope.md | 8 ------- .changeset/strange-tips-lick.md | 5 ---- .changeset/thick-ties-glow.md | 5 ---- .changeset/thirty-windows-prove.md | 5 ---- .../CHANGELOG.md | 6 +++++ .../package.json | 2 +- packages/vitest-pool-workers/CHANGELOG.md | 7 ++++++ packages/vitest-pool-workers/package.json | 2 +- packages/wrangler/CHANGELOG.md | 23 +++++++++++++++++++ packages/wrangler/package.json | 2 +- 12 files changed, 39 insertions(+), 40 deletions(-) delete mode 100644 .changeset/blue-laws-bathe.md delete mode 100644 .changeset/early-baboons-fly.md delete mode 100644 .changeset/selfish-yaks-hope.md delete mode 100644 .changeset/strange-tips-lick.md delete mode 100644 .changeset/thick-ties-glow.md delete mode 100644 .changeset/thirty-windows-prove.md diff --git a/.changeset/blue-laws-bathe.md b/.changeset/blue-laws-bathe.md deleted file mode 100644 index 9b65d75318fc..000000000000 --- a/.changeset/blue-laws-bathe.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"wrangler": patch ---- - -feat: add experimental_readRawConfig() - -Adds a Wrangler API to find and read a config file diff --git a/.changeset/early-baboons-fly.md b/.changeset/early-baboons-fly.md deleted file mode 100644 index c57ab56ee712..000000000000 --- a/.changeset/early-baboons-fly.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"wrangler": minor ---- - -feat: allow routing to Workers with Assets on any HTTP route, not just the root. For example, `example.com/blog/*` can now be used to serve assets. -These assets will be served as though the assets directly were mounted to the root. -For example, if you have `assets = { directory = "./public/" }`, a route like `"example.com/blog/*"` and a file `./public/blog/logo.png`, this will be available at `example.com/blog/logo.png`. Assets outside of directories which match the configured HTTP routes can still be accessed with the [Assets binding](https://developers.cloudflare.com/workers/static-assets/binding/#binding) or with a [Service binding](https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/) to this Worker. diff --git a/.changeset/selfish-yaks-hope.md b/.changeset/selfish-yaks-hope.md deleted file mode 100644 index f4325b5dd866..000000000000 --- a/.changeset/selfish-yaks-hope.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"wrangler": patch ---- - -Expand metrics collection to: - -- Detect Pages & Workers CI -- Filter out default args (e.g. `--x-versions`, `--x-dev-env`, and `--latest`) by only including args that were in `argv` diff --git a/.changeset/strange-tips-lick.md b/.changeset/strange-tips-lick.md deleted file mode 100644 index f3f7d0c25d80..000000000000 --- a/.changeset/strange-tips-lick.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"wrangler": minor ---- - -Add Workers + Assets support in `wrangler dev --remote` diff --git a/.changeset/thick-ties-glow.md b/.changeset/thick-ties-glow.md deleted file mode 100644 index 7932bced48bb..000000000000 --- a/.changeset/thick-ties-glow.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"wrangler": patch ---- - -Revert support for custom unenv resolve path to address an issue with Wrangler failing to deploy Pages projects with `nodejs_compat_v2` in some cases diff --git a/.changeset/thirty-windows-prove.md b/.changeset/thirty-windows-prove.md deleted file mode 100644 index 7f8212348424..000000000000 --- a/.changeset/thirty-windows-prove.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"cloudflare-workers-bindings-extension": patch ---- - -Load Wrangler in extension diff --git a/packages/cloudflare-workers-bindings-extension/CHANGELOG.md b/packages/cloudflare-workers-bindings-extension/CHANGELOG.md index 61a67465daf7..ca9f2fa2be9b 100644 --- a/packages/cloudflare-workers-bindings-extension/CHANGELOG.md +++ b/packages/cloudflare-workers-bindings-extension/CHANGELOG.md @@ -1,5 +1,11 @@ # cloudflare-workers-bindings-extension +## 0.0.7 + +### Patch Changes + +- [#7560](https://github.com/cloudflare/workers-sdk/pull/7560) [`59eef4f`](https://github.com/cloudflare/workers-sdk/commit/59eef4fe5b3fc0a730fe6c8db318e94db72425ed) Thanks [@penalosa](https://github.com/penalosa)! - Load Wrangler in extension + ## 0.0.6 ### Patch Changes diff --git a/packages/cloudflare-workers-bindings-extension/package.json b/packages/cloudflare-workers-bindings-extension/package.json index 89a95931cbbc..640d3bc74247 100644 --- a/packages/cloudflare-workers-bindings-extension/package.json +++ b/packages/cloudflare-workers-bindings-extension/package.json @@ -1,7 +1,7 @@ { "name": "cloudflare-workers-bindings-extension", "displayName": "Cloudflare Workers", - "version": "0.0.6", + "version": "0.0.7", "description": "Manage your Cloudflare Worker's bindings", "categories": [ "Other" diff --git a/packages/vitest-pool-workers/CHANGELOG.md b/packages/vitest-pool-workers/CHANGELOG.md index 15b6ec469503..6d2106fde456 100644 --- a/packages/vitest-pool-workers/CHANGELOG.md +++ b/packages/vitest-pool-workers/CHANGELOG.md @@ -1,5 +1,12 @@ # @cloudflare/vitest-pool-workers +## 0.5.39 + +### Patch Changes + +- Updated dependencies [[`fb819f9`](https://github.com/cloudflare/workers-sdk/commit/fb819f9970285d3fc4ca8e98d652238c554d568b), [`5124b5d`](https://github.com/cloudflare/workers-sdk/commit/5124b5da4f8c12bbb6192f2d89241a9c54ab73c7), [`42b9429`](https://github.com/cloudflare/workers-sdk/commit/42b942916efbd4eb8060e4d61c2e805ec78a1a89), [`72935f9`](https://github.com/cloudflare/workers-sdk/commit/72935f9b25416ff6d1d350e058f0d2a11864fb36), [`8def8c9`](https://github.com/cloudflare/workers-sdk/commit/8def8c99e1f74f313a3771c827133c59e1b1032b)]: + - wrangler@3.98.0 + ## 0.5.38 ### Patch Changes diff --git a/packages/vitest-pool-workers/package.json b/packages/vitest-pool-workers/package.json index fccbc7089b6f..0f6b120c9440 100644 --- a/packages/vitest-pool-workers/package.json +++ b/packages/vitest-pool-workers/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflare/vitest-pool-workers", - "version": "0.5.38", + "version": "0.5.39", "description": "Workers Vitest integration for writing Vitest unit and integration tests that run inside the Workers runtime", "keywords": [ "cloudflare", diff --git a/packages/wrangler/CHANGELOG.md b/packages/wrangler/CHANGELOG.md index 51a6ac28618a..8d5e9adb7169 100644 --- a/packages/wrangler/CHANGELOG.md +++ b/packages/wrangler/CHANGELOG.md @@ -1,5 +1,28 @@ # wrangler +## 3.98.0 + +### Minor Changes + +- [#7476](https://github.com/cloudflare/workers-sdk/pull/7476) [`5124b5d`](https://github.com/cloudflare/workers-sdk/commit/5124b5da4f8c12bbb6192f2d89241a9c54ab73c7) Thanks [@WalshyDev](https://github.com/WalshyDev)! - feat: allow routing to Workers with Assets on any HTTP route, not just the root. For example, `example.com/blog/*` can now be used to serve assets. + These assets will be served as though the assets directly were mounted to the root. + For example, if you have `assets = { directory = "./public/" }`, a route like `"example.com/blog/*"` and a file `./public/blog/logo.png`, this will be available at `example.com/blog/logo.png`. Assets outside of directories which match the configured HTTP routes can still be accessed with the [Assets binding](https://developers.cloudflare.com/workers/static-assets/binding/#binding) or with a [Service binding](https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/) to this Worker. + +- [#7380](https://github.com/cloudflare/workers-sdk/pull/7380) [`72935f9`](https://github.com/cloudflare/workers-sdk/commit/72935f9b25416ff6d1d350e058f0d2a11864fb36) Thanks [@CarmenPopoviciu](https://github.com/CarmenPopoviciu)! - Add Workers + Assets support in `wrangler dev --remote` + +### Patch Changes + +- [#7573](https://github.com/cloudflare/workers-sdk/pull/7573) [`fb819f9`](https://github.com/cloudflare/workers-sdk/commit/fb819f9970285d3fc4ca8e98d652238c554d568b) Thanks [@emily-shen](https://github.com/emily-shen)! - feat: add experimental_readRawConfig() + + Adds a Wrangler API to find and read a config file + +- [#7549](https://github.com/cloudflare/workers-sdk/pull/7549) [`42b9429`](https://github.com/cloudflare/workers-sdk/commit/42b942916efbd4eb8060e4d61c2e805ec78a1a89) Thanks [@penalosa](https://github.com/penalosa)! - Expand metrics collection to: + + - Detect Pages & Workers CI + - Filter out default args (e.g. `--x-versions`, `--x-dev-env`, and `--latest`) by only including args that were in `argv` + +- [#7583](https://github.com/cloudflare/workers-sdk/pull/7583) [`8def8c9`](https://github.com/cloudflare/workers-sdk/commit/8def8c99e1f74f313a3771c827133c59e1b1032b) Thanks [@penalosa](https://github.com/penalosa)! - Revert support for custom unenv resolve path to address an issue with Wrangler failing to deploy Pages projects with `nodejs_compat_v2` in some cases + ## 3.97.0 ### Minor Changes diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 3a49ac019072..d1f0d9944334 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -1,6 +1,6 @@ { "name": "wrangler", - "version": "3.97.0", + "version": "3.98.0", "description": "Command-line interface for all things Cloudflare Workers", "keywords": [ "wrangler", From 5ccad7d6b95651c75fce30e5ad4eddf7c64bd467 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 19 Dec 2024 10:53:03 +0100 Subject: [PATCH 06/53] cleanup(fixtures): add missing dependencies to package.json (#7580) --- fixtures/additional-modules/package.json | 2 + fixtures/ai-app/package.json | 2 + fixtures/asset-config/package.json | 3 +- fixtures/durable-objects-app/package.json | 7 +- fixtures/entrypoints-rpc-tests/package.json | 1 + fixtures/get-platform-proxy/package.json | 2 + fixtures/import-wasm-example/package.json | 2 + fixtures/interactive-dev-tests/package.json | 3 +- fixtures/local-mode-tests/package.json | 2 + fixtures/no-bundle-import/package.json | 1 + fixtures/node-app-pages/package.json | 4 +- fixtures/nodejs-als-app/package.json | 1 + fixtures/nodejs-hybrid-app/package.json | 1 + fixtures/pages-d1-shim/package.json | 4 +- .../pages-dev-proxy-with-script/package.json | 4 +- fixtures/pages-functions-app/package.json | 2 + .../pages-functions-wasm-app/package.json | 6 +- .../package.json | 4 +- .../package.json | 4 +- fixtures/pages-nodejs-v2-compat/package.json | 8 +- .../package.json | 2 + fixtures/pages-proxy-app/package.json | 4 +- fixtures/pages-simple-assets/package.json | 4 +- .../package.json | 4 +- fixtures/pages-workerjs-app/package.json | 4 +- .../pages-workerjs-directory/package.json | 4 +- fixtures/pages-workerjs-wasm-app/package.json | 6 +- .../package.json | 4 +- .../package.json | 4 +- fixtures/pages-ws-app/package.json | 4 +- fixtures/ratelimit-app/package.json | 2 + fixtures/type-generation/package.json | 1 + fixtures/worker-app/package.json | 2 + .../workers-with-assets-only/package.json | 4 +- .../package.json | 4 +- fixtures/workers-with-assets/package.json | 4 +- fixtures/workflow-multiple/package.json | 2 + fixtures/workflow/package.json | 2 + pnpm-lock.yaml | 206 +++++++++++++++++- 39 files changed, 301 insertions(+), 29 deletions(-) diff --git a/fixtures/additional-modules/package.json b/fixtures/additional-modules/package.json index 418e5b7ee271..c4d192e635e9 100644 --- a/fixtures/additional-modules/package.json +++ b/fixtures/additional-modules/package.json @@ -13,7 +13,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/ai-app/package.json b/fixtures/ai-app/package.json index 027b4055f5b5..f984dd4fdef3 100644 --- a/fixtures/ai-app/package.json +++ b/fixtures/ai-app/package.json @@ -13,7 +13,9 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:^", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/asset-config/package.json b/fixtures/asset-config/package.json index e93e6548ceae..c34e5c0f2ae9 100644 --- a/fixtures/asset-config/package.json +++ b/fixtures/asset-config/package.json @@ -2,7 +2,7 @@ "name": "workers-assets-config-test", "private": true, "scripts": { - "dev": "npx wrangler dev", + "dev": "wrangler dev", "test:ci": "run-script-os", "test:ci:default": "true", "test:ci:nix": "vitest run", @@ -14,6 +14,7 @@ "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", "run-script-os": "^1.1.6", + "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", "wrangler": "workspace:*" diff --git a/fixtures/durable-objects-app/package.json b/fixtures/durable-objects-app/package.json index dec49bc388c6..f198f3589d33 100644 --- a/fixtures/durable-objects-app/package.json +++ b/fixtures/durable-objects-app/package.json @@ -7,13 +7,14 @@ "main": "src/index.js", "scripts": { "dev": "wrangler deploy --dry-run", - "test": "npx vitest run", - "test:ci": "npx vitest run", - "test:watch": "npx vitest" + "test": "vitest run", + "test:ci": "vitest run", + "test:watch": "vitest" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:^", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/entrypoints-rpc-tests/package.json b/fixtures/entrypoints-rpc-tests/package.json index af0c26bea4c8..bb521ac63774 100644 --- a/fixtures/entrypoints-rpc-tests/package.json +++ b/fixtures/entrypoints-rpc-tests/package.json @@ -9,6 +9,7 @@ "@cloudflare/workers-tsconfig": "workspace:*", "ts-dedent": "^2.2.0", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/get-platform-proxy/package.json b/fixtures/get-platform-proxy/package.json index 0eae6a952138..71e5259e2397 100644 --- a/fixtures/get-platform-proxy/package.json +++ b/fixtures/get-platform-proxy/package.json @@ -10,7 +10,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/import-wasm-example/package.json b/fixtures/import-wasm-example/package.json index 9996c571350e..5f2e8569d3a6 100644 --- a/fixtures/import-wasm-example/package.json +++ b/fixtures/import-wasm-example/package.json @@ -15,7 +15,9 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:^", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/interactive-dev-tests/package.json b/fixtures/interactive-dev-tests/package.json index 1860547c161a..a86300c5240d 100644 --- a/fixtures/interactive-dev-tests/package.json +++ b/fixtures/interactive-dev-tests/package.json @@ -8,7 +8,8 @@ "devDependencies": { "fixtures-shared": "workspace:*", "strip-ansi": "^7.1.0", - "undici": "catalog:default" + "undici": "catalog:default", + "vitest": "catalog:default" }, "optionalDependencies": { "@cdktf/node-pty-prebuilt-multiarch": "0.10.1-pre.11" diff --git a/fixtures/local-mode-tests/package.json b/fixtures/local-mode-tests/package.json index d6e6e6c59b96..ad649f984e92 100644 --- a/fixtures/local-mode-tests/package.json +++ b/fixtures/local-mode-tests/package.json @@ -17,6 +17,8 @@ "@cloudflare/workers-types": "^4.20241205.0", "@types/node": "catalog:default", "buffer": "^6.0.3", + "typescript": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/no-bundle-import/package.json b/fixtures/no-bundle-import/package.json index ca8cb4800364..f8d9f113a399 100644 --- a/fixtures/no-bundle-import/package.json +++ b/fixtures/no-bundle-import/package.json @@ -9,6 +9,7 @@ }, "devDependencies": { "get-port": "^7.0.0", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/node-app-pages/package.json b/fixtures/node-app-pages/package.json index 46857450542e..f4a1d7d06a74 100644 --- a/fixtures/node-app-pages/package.json +++ b/fixtures/node-app-pages/package.json @@ -5,7 +5,7 @@ "main": "dist/worker.js", "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev public --port 12345 --node-compat", + "dev": "wrangler pages dev public --port 12345 --node-compat", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" @@ -16,7 +16,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/nodejs-als-app/package.json b/fixtures/nodejs-als-app/package.json index a950b63cbc44..c13302a4cf87 100644 --- a/fixtures/nodejs-als-app/package.json +++ b/fixtures/nodejs-als-app/package.json @@ -11,6 +11,7 @@ "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" } } diff --git a/fixtures/nodejs-hybrid-app/package.json b/fixtures/nodejs-hybrid-app/package.json index ee88e4ba8e3a..dd1d25b32401 100644 --- a/fixtures/nodejs-hybrid-app/package.json +++ b/fixtures/nodejs-hybrid-app/package.json @@ -14,6 +14,7 @@ "pg": "8.11.3", "pg-cloudflare": "^1.1.1", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" } } diff --git a/fixtures/pages-d1-shim/package.json b/fixtures/pages-d1-shim/package.json index 583d38c17a02..e2392a8c0829 100644 --- a/fixtures/pages-d1-shim/package.json +++ b/fixtures/pages-d1-shim/package.json @@ -4,14 +4,16 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev ./public --d1 foobar --port 8777", + "dev": "wrangler pages dev ./public --d1 foobar --port 8777", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-dev-proxy-with-script/package.json b/fixtures/pages-dev-proxy-with-script/package.json index 80b36795d234..62158377ea25 100644 --- a/fixtures/pages-dev-proxy-with-script/package.json +++ b/fixtures/pages-dev-proxy-with-script/package.json @@ -3,7 +3,7 @@ "private": true, "sideEffects": false, "scripts": { - "dev": "npx wrangler pages dev public", + "dev": "wrangler pages dev public", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" @@ -11,7 +11,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-functions-app/package.json b/fixtures/pages-functions-app/package.json index 73a9bbb0968c..9863d450c24d 100644 --- a/fixtures/pages-functions-app/package.json +++ b/fixtures/pages-functions-app/package.json @@ -17,7 +17,9 @@ "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", "pages-plugin-example": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-functions-wasm-app/package.json b/fixtures/pages-functions-wasm-app/package.json index e20613dec070..26b3c7f36900 100644 --- a/fixtures/pages-functions-wasm-app/package.json +++ b/fixtures/pages-functions-wasm-app/package.json @@ -4,15 +4,17 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev public --port 8776", - "publish": "npx wrangler pages deploy public", + "dev": "wrangler pages dev public --port 8776", + "publish": "wrangler pages deploy public", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-functions-with-config-file-app/package.json b/fixtures/pages-functions-with-config-file-app/package.json index 87aae0a62644..dd53964df35f 100644 --- a/fixtures/pages-functions-with-config-file-app/package.json +++ b/fixtures/pages-functions-with-config-file-app/package.json @@ -4,14 +4,16 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev", + "dev": "wrangler pages dev", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-functions-with-routes-app/package.json b/fixtures/pages-functions-with-routes-app/package.json index 8f3db3e8bf02..cb4ba9195b8c 100644 --- a/fixtures/pages-functions-with-routes-app/package.json +++ b/fixtures/pages-functions-with-routes-app/package.json @@ -4,7 +4,7 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev public --port 8776", + "dev": "wrangler pages dev public --port 8776", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" @@ -12,7 +12,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-nodejs-v2-compat/package.json b/fixtures/pages-nodejs-v2-compat/package.json index ff0254e8b4da..a0851b21074c 100644 --- a/fixtures/pages-nodejs-v2-compat/package.json +++ b/fixtures/pages-nodejs-v2-compat/package.json @@ -4,16 +4,18 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev:functions-app": "npx wrangler pages dev ./apps/functions --port 8792", - "dev:workerjs-directory": "npx wrangler pages dev ./apps/workerjs-directory --port 8792", - "dev:workerjs-file": "npx wrangler pages dev ./apps/workerjs-file --port 8792", + "dev:functions-app": "wrangler pages dev ./apps/functions --port 8792", + "dev:workerjs-directory": "wrangler pages dev ./apps/workerjs-directory --port 8792", + "dev:workerjs-file": "wrangler pages dev ./apps/workerjs-file --port 8792", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:^", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-plugin-mounted-on-root-app/package.json b/fixtures/pages-plugin-mounted-on-root-app/package.json index ed535365bb90..1adad8589539 100644 --- a/fixtures/pages-plugin-mounted-on-root-app/package.json +++ b/fixtures/pages-plugin-mounted-on-root-app/package.json @@ -17,7 +17,9 @@ "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", "pages-plugin-example": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-proxy-app/package.json b/fixtures/pages-proxy-app/package.json index f1d8cd46b490..e5594274f7be 100644 --- a/fixtures/pages-proxy-app/package.json +++ b/fixtures/pages-proxy-app/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "esbuild --bundle --platform=node server/index.ts --outfile=dist/index.js", "check:type": "tsc", - "dev": "npx wrangler pages dev --compatibility-date=2024-01-17 --port 8790 --proxy 8791 -- pnpm run server", + "dev": "wrangler pages dev --compatibility-date=2024-01-17 --port 8790 --proxy 8791 -- pnpm run server", "server": "node dist/index.js", "test:ci": "vitest run", "test:watch": "vitest", @@ -15,7 +15,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "miniflare": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-simple-assets/package.json b/fixtures/pages-simple-assets/package.json index 91d9aad4afcb..ae7fc9d05b26 100644 --- a/fixtures/pages-simple-assets/package.json +++ b/fixtures/pages-simple-assets/package.json @@ -5,7 +5,7 @@ "main": "dist/worker.js", "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev public", + "dev": "wrangler pages dev public", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" @@ -13,7 +13,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-workerjs-and-functions-app/package.json b/fixtures/pages-workerjs-and-functions-app/package.json index f7cdf5915e9d..01b3dbf44de4 100644 --- a/fixtures/pages-workerjs-and-functions-app/package.json +++ b/fixtures/pages-workerjs-and-functions-app/package.json @@ -4,14 +4,16 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev public --port 8955", + "dev": "wrangler pages dev public --port 8955", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-workerjs-app/package.json b/fixtures/pages-workerjs-app/package.json index 823bbc986276..5c66abbf275d 100644 --- a/fixtures/pages-workerjs-app/package.json +++ b/fixtures/pages-workerjs-app/package.json @@ -4,14 +4,16 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev ./workerjs-test --port 8792", + "dev": "wrangler pages dev ./workerjs-test --port 8792", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:^", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-workerjs-directory/package.json b/fixtures/pages-workerjs-directory/package.json index 3543ef17fdb9..2cb1b86a2583 100644 --- a/fixtures/pages-workerjs-directory/package.json +++ b/fixtures/pages-workerjs-directory/package.json @@ -4,13 +4,15 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev public --d1=D1 --d1=PUT=elsewhere --kv KV --kv KV_REF=other_kv --r2 R2 --r2=R2_REF=other_r2 --port 8794", + "dev": "wrangler pages dev public --d1=D1 --d1=PUT=elsewhere --kv KV --kv KV_REF=other_kv --r2 R2 --r2=R2_REF=other_r2 --port 8794", "test:ci": "vitest run", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-workerjs-wasm-app/package.json b/fixtures/pages-workerjs-wasm-app/package.json index 1cc8a75da4e0..9cbc55f27f9f 100644 --- a/fixtures/pages-workerjs-wasm-app/package.json +++ b/fixtures/pages-workerjs-wasm-app/package.json @@ -4,15 +4,17 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev public --port 8776", - "publish": "npx wrangler pages deploy public", + "dev": "wrangler pages dev public --port 8776", + "publish": "wrangler pages deploy public", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-workerjs-with-config-file-app/package.json b/fixtures/pages-workerjs-with-config-file-app/package.json index 4ee4e9a5f962..b90e9ce0012f 100644 --- a/fixtures/pages-workerjs-with-config-file-app/package.json +++ b/fixtures/pages-workerjs-with-config-file-app/package.json @@ -4,14 +4,16 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev", + "dev": "wrangler pages dev", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-workerjs-with-routes-app/package.json b/fixtures/pages-workerjs-with-routes-app/package.json index aa706cbd004d..6e31d5e6f2bf 100644 --- a/fixtures/pages-workerjs-with-routes-app/package.json +++ b/fixtures/pages-workerjs-with-routes-app/package.json @@ -4,14 +4,16 @@ "sideEffects": false, "scripts": { "check:type": "tsc", - "dev": "npx wrangler pages dev public --port 8751", + "dev": "wrangler pages dev public --port 8751", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "engines": { diff --git a/fixtures/pages-ws-app/package.json b/fixtures/pages-ws-app/package.json index c77ea482ab42..705556eaa1bc 100644 --- a/fixtures/pages-ws-app/package.json +++ b/fixtures/pages-ws-app/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "esbuild --bundle --platform=node server/index.ts --outfile=dist/index.js", "check:type": "tsc", - "dev": "npx wrangler pages dev --port 8790 --proxy 8791 -- pnpm run server", + "dev": "wrangler pages dev --port 8790 --proxy 8791 -- pnpm run server", "server": "node dist/index.js", "test:ci": "vitest run", "test:watch": "vitest", @@ -15,6 +15,8 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "miniflare": "workspace:*", + "typescript": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*", "ws": "^8.18.0" }, diff --git a/fixtures/ratelimit-app/package.json b/fixtures/ratelimit-app/package.json index 2525a0d80bf9..f79239282999 100644 --- a/fixtures/ratelimit-app/package.json +++ b/fixtures/ratelimit-app/package.json @@ -13,7 +13,9 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:^", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/type-generation/package.json b/fixtures/type-generation/package.json index 62698990d8e9..024cc20872d6 100644 --- a/fixtures/type-generation/package.json +++ b/fixtures/type-generation/package.json @@ -7,6 +7,7 @@ "test:watch": "vitest" }, "devDependencies": { + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/worker-app/package.json b/fixtures/worker-app/package.json index 84525a3bd9f7..fa2bf1a36935 100644 --- a/fixtures/worker-app/package.json +++ b/fixtures/worker-app/package.json @@ -17,7 +17,9 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:^", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/workers-with-assets-only/package.json b/fixtures/workers-with-assets-only/package.json index 6506632d5bb4..d5770856abe9 100644 --- a/fixtures/workers-with-assets-only/package.json +++ b/fixtures/workers-with-assets-only/package.json @@ -2,7 +2,7 @@ "name": "workers-assets-only", "private": true, "scripts": { - "dev": "npx wrangler dev", + "dev": "wrangler dev", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" @@ -10,7 +10,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/workers-with-assets-serve-directly/package.json b/fixtures/workers-with-assets-serve-directly/package.json index 08adb218918e..bb326102e7e5 100644 --- a/fixtures/workers-with-assets-serve-directly/package.json +++ b/fixtures/workers-with-assets-serve-directly/package.json @@ -3,7 +3,7 @@ "private": true, "scripts": { "check:type": "tsc", - "dev": "npx wrangler dev", + "dev": "wrangler dev", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" @@ -11,7 +11,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/workers-with-assets/package.json b/fixtures/workers-with-assets/package.json index 28bc58865621..5a0610fe354e 100644 --- a/fixtures/workers-with-assets/package.json +++ b/fixtures/workers-with-assets/package.json @@ -3,7 +3,7 @@ "private": true, "scripts": { "check:type": "tsc", - "dev": "npx wrangler dev", + "dev": "wrangler dev", "test:ci": "vitest run", "test:watch": "vitest", "type:tests": "tsc -p ./tests/tsconfig.json" @@ -11,7 +11,9 @@ "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/workflow-multiple/package.json b/fixtures/workflow-multiple/package.json index b4b8c1893ce8..ea68094744ce 100644 --- a/fixtures/workflow-multiple/package.json +++ b/fixtures/workflow-multiple/package.json @@ -8,7 +8,9 @@ }, "devDependencies": { "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/workflow/package.json b/fixtures/workflow/package.json index 40bbd42ebea9..eb7bc10f1967 100644 --- a/fixtures/workflow/package.json +++ b/fixtures/workflow/package.json @@ -8,7 +8,9 @@ }, "devDependencies": { "@cloudflare/workers-types": "^4.20241205.0", + "typescript": "catalog:default", "undici": "catalog:default", + "vitest": "catalog:default", "wrangler": "workspace:*" }, "volta": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 82e4e781d402..1e1adb66c697 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -130,9 +130,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -142,9 +148,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:^ version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -163,6 +175,9 @@ importers: run-script-os: specifier: ^1.1.6 version: 1.1.6 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 @@ -187,6 +202,9 @@ importers: undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -202,6 +220,9 @@ importers: undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -214,9 +235,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -232,9 +259,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:^ version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -256,6 +289,9 @@ importers: undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) fixtures/isomorphic-random-example: {} @@ -275,6 +311,12 @@ importers: buffer: specifier: ^6.0.3 version: 6.0.3 + typescript: + specifier: catalog:default + version: 5.6.3 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -284,6 +326,9 @@ importers: get-port: specifier: ^7.0.0 version: 7.0.0 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -300,9 +345,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -318,6 +369,9 @@ importers: undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -342,6 +396,9 @@ importers: undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -351,9 +408,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -366,9 +429,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -388,9 +457,15 @@ importers: pages-plugin-example: specifier: workspace:* version: link:../pages-plugin-example + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -400,9 +475,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -412,9 +493,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -427,9 +514,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -439,9 +532,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:^ version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -470,9 +569,15 @@ importers: pages-plugin-example: specifier: workspace:* version: link:../pages-plugin-example + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -485,9 +590,15 @@ importers: miniflare: specifier: workspace:* version: link:../../packages/miniflare + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -500,9 +611,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -512,9 +629,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -524,9 +647,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:^ version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -536,9 +665,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -548,9 +683,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -560,9 +701,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -572,9 +719,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -587,6 +740,12 @@ importers: miniflare: specifier: workspace:* version: link:../../packages/miniflare + typescript: + specifier: catalog:default + version: 5.6.3 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -599,9 +758,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:^ version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -624,6 +789,9 @@ importers: fixtures/type-generation: devDependencies: + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -684,9 +852,15 @@ importers: '@cloudflare/workers-tsconfig': specifier: workspace:^ version: link:../../packages/workers-tsconfig + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -710,9 +884,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -725,9 +905,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -740,9 +926,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -752,9 +944,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -764,9 +962,15 @@ importers: '@cloudflare/workers-types': specifier: ^4.20241205.0 version: 4.20241205.0 + typescript: + specifier: catalog:default + version: 5.6.3 undici: specifier: catalog:default version: 5.28.4 + vitest: + specifier: catalog:default + version: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -13441,7 +13645,7 @@ snapshots: assertion-error: 2.0.1 check-error: 2.1.1 deep-eql: 5.0.2 - loupe: 3.1.1 + loupe: 3.1.2 pathval: 2.0.0 chainsaw@0.1.0: From 086a6b8c613b9c8f0f7c4933ffd68f38f7771c3f Mon Sep 17 00:00:00 2001 From: WillTaylorDev Date: Thu, 19 Dec 2024 05:09:03 -0500 Subject: [PATCH 07/53] Provide validation around experimental_serve_directly usage (#7537) * Provide validation around experimental_serve_directly usage in dev and deploy * Update based on PR feedback * Update packages/wrangler/src/assets.ts * Update packages/wrangler/src/__tests__/dev.test.ts * Update packages/wrangler/src/__tests__/deploy.test.ts * fix --------- Co-authored-by: Carmen Popoviciu --- .changeset/swift-zebras-guess.md | 5 ++ .../wrangler/src/__tests__/deploy.test.ts | 61 +++++++++++++++++++ packages/wrangler/src/__tests__/dev.test.ts | 41 +++++++++++++ packages/wrangler/src/assets.ts | 29 +++++++++ 4 files changed, 136 insertions(+) create mode 100644 .changeset/swift-zebras-guess.md diff --git a/.changeset/swift-zebras-guess.md b/.changeset/swift-zebras-guess.md new file mode 100644 index 000000000000..91e2232cc577 --- /dev/null +++ b/.changeset/swift-zebras-guess.md @@ -0,0 +1,5 @@ +--- +"wrangler": minor +--- + +Provide validation around assets.experimental_serve_directly diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index 9c8089be5392..e74ab2ee5282 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -4687,6 +4687,67 @@ addEventListener('fetch', event => {});` `); }); + it("should warn if experimental_serve_directly=false but no binding is provided", async () => { + const assets = [ + { filePath: ".assetsignore", content: "*.bak\nsub-dir" }, + { filePath: "file-1.txt", content: "Content of file-1" }, + { filePath: "file-2.bak", content: "Content of file-2" }, + { filePath: "file-3.txt", content: "Content of file-3" }, + { filePath: "sub-dir/file-4.bak", content: "Content of file-4" }, + { filePath: "sub-dir/file-5.txt", content: "Content of file-5" }, + ]; + writeAssets(assets, "assets"); + writeWorkerSource({ format: "js" }); + writeWranglerConfig({ + main: "index.js", + assets: { + directory: "assets", + experimental_serve_directly: false, + }, + }); + const bodies: AssetManifest[] = []; + await mockAUSRequest(bodies); + mockSubDomainRequest(); + mockUploadWorkerRequest({ + expectedAssets: { + jwt: "<>", + config: { + serve_directly: false, + }, + }, + expectedMainModule: "index.js", + }); + + await runWrangler("deploy"); + + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] experimental_serve_directly=false set without an assets binding + + Setting experimental_serve_directly to false will always invoke your Worker script. + To fetch your assets from your Worker, please set the [assets.binding] key in your configuration + file. + + Read more: https://developers.cloudflare.com/workers/static-assets/binding/#binding + + " + `); + }); + + it("should error if experimental_serve_directly is false and no user Worker is provided", async () => { + writeWranglerConfig({ + assets: { + directory: "xyz", + experimental_serve_directly: false, + }, + }); + + await expect(runWrangler("deploy")).rejects + .toThrowErrorMatchingInlineSnapshot(` + [Error: Cannot set experimental_serve_directly=false without a Worker script. + Please remove experimental_serve_directly from your configuration file, or provide a Worker script in your configuration file (\`main\`).] + `); + }); + it("should be able to upload files with special characters in filepaths", async () => { // NB windows will disallow these characters in file paths anyway < > : " / \ | ? * const assets = [ diff --git a/packages/wrangler/src/__tests__/dev.test.ts b/packages/wrangler/src/__tests__/dev.test.ts index 23d77e47ea01..a3d063658acb 100644 --- a/packages/wrangler/src/__tests__/dev.test.ts +++ b/packages/wrangler/src/__tests__/dev.test.ts @@ -1679,6 +1679,47 @@ describe.sequential("wrangler dev", () => { ); }); + it("should warn if experimental_serve_directly=false but no binding is provided", async () => { + writeWranglerConfig({ + main: "index.js", + assets: { + directory: "assets", + experimental_serve_directly: false, + }, + }); + fs.mkdirSync("assets"); + fs.writeFileSync("index.js", `export default {};`); + + await runWranglerUntilConfig("dev"); + + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] experimental_serve_directly=false set without an assets binding + + Setting experimental_serve_directly to false will always invoke your Worker script. + To fetch your assets from your Worker, please set the [assets.binding] key in your configuration + file. + + Read more: https://developers.cloudflare.com/workers/static-assets/binding/#binding + + " + `); + }); + + it("should error if experimental_serve_directly is false and no user Worker is provided", async () => { + writeWranglerConfig({ + assets: { directory: "assets", experimental_serve_directly: false }, + }); + fs.mkdirSync("assets"); + await expect( + runWrangler("dev") + ).rejects.toThrowErrorMatchingInlineSnapshot( + ` + [Error: Cannot set experimental_serve_directly=false without a Worker script. + Please remove experimental_serve_directly from your configuration file, or provide a Worker script in your configuration file (\`main\`).] + ` + ); + }); + it("should error if directory specified by '--assets' command line argument does not exist", async () => { writeWranglerConfig({ main: "./index.js", diff --git a/packages/wrangler/src/assets.ts b/packages/wrangler/src/assets.ts index 999f2dca6f52..f3f8802e0891 100644 --- a/packages/wrangler/src/assets.ts +++ b/packages/wrangler/src/assets.ts @@ -443,6 +443,35 @@ export function validateAssetsArgsAndConfig( "Please remove the asset binding from your configuration file, or provide a Worker script in your configuration file (`main`)." ); } + + // User Worker ahead of assets, but no assets binding provided + if ( + "legacy" in args + ? args.assets?.assetConfig?.serve_directly === false && + !args.assets?.binding + : config?.assets?.experimental_serve_directly === false && + !config?.assets?.binding + ) { + logger.warn( + "experimental_serve_directly=false set without an assets binding\n" + + "Setting experimental_serve_directly to false will always invoke your Worker script.\n" + + "To fetch your assets from your Worker, please set the [assets.binding] key in your configuration file.\n\n" + + "Read more: https://developers.cloudflare.com/workers/static-assets/binding/#binding" + ); + } + + // Using serve_directly=false, but didn't provide a Worker script + if ( + "legacy" in args + ? args.entrypoint === noOpEntrypoint && + args.assets?.assetConfig?.serve_directly === false + : !config?.main && config?.assets?.experimental_serve_directly === false + ) { + throw new UserError( + "Cannot set experimental_serve_directly=false without a Worker script.\n" + + "Please remove experimental_serve_directly from your configuration file, or provide a Worker script in your configuration file (`main`)." + ); + } } const CF_ASSETS_IGNORE_FILENAME = ".assetsignore"; From 48e7e1035f489639564948edd3789b1740a7873d Mon Sep 17 00:00:00 2001 From: emily-shen <69125074+emily-shen@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:36:08 +0000 Subject: [PATCH 08/53] feat: add experimental_patchConfig (#7521) * add experimental_readRawConfig and tests * move printBindings out of /config/index.ts * add experimental_patchConfig * fixups * add tests * changeset * more tests * pr feedback * allow editing and deleting with `isArrayInsertion` flag * more tests * fixups * update changeset * fix test --- .changeset/lovely-rats-live.md | 7 + .../src/__tests__/configuration.test.ts | 32 +- .../src/__tests__/patch-config.test.ts | 876 ++++++++++++++++++ packages/wrangler/src/cli.ts | 1 + packages/wrangler/src/config/patch-config.ts | 97 ++ 5 files changed, 1000 insertions(+), 13 deletions(-) create mode 100644 .changeset/lovely-rats-live.md create mode 100644 packages/wrangler/src/__tests__/patch-config.test.ts create mode 100644 packages/wrangler/src/config/patch-config.ts diff --git a/.changeset/lovely-rats-live.md b/.changeset/lovely-rats-live.md new file mode 100644 index 000000000000..2b08b4e9ed48 --- /dev/null +++ b/.changeset/lovely-rats-live.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +feat: add experimental_patchConfig() + +`experimental_patchConfig()` can add to a user's config file. It preserves comments if its a `wrangler.jsonc`. However, it is not suitable for `wrangler.toml` with comments as we cannot preserve comments on write. diff --git a/packages/wrangler/src/__tests__/configuration.test.ts b/packages/wrangler/src/__tests__/configuration.test.ts index 01d2b05185ef..5083e0a84602 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -6045,15 +6045,19 @@ describe("experimental_readRawConfig()", () => { runInTempDir(); it(`should find a ${configType} config file given a specific path`, () => { fs.mkdirSync("../folder", { recursive: true }); - writeWranglerConfig({}, `../folder/config.${configType}`); + writeWranglerConfig( + { name: "config-one" }, + `../folder/config.${configType}` + ); const result = experimental_readRawConfig({ config: `../folder/config.${configType}`, }); - expect(result.rawConfig).toEqual({ - compatibility_date: "2022-01-12", - name: "test-name", - }); + expect(result.rawConfig).toEqual( + expect.objectContaining({ + name: "config-one", + }) + ); }); it("should find a config file given a specific script", () => { @@ -6072,18 +6076,20 @@ describe("experimental_readRawConfig()", () => { let result = experimental_readRawConfig({ script: "./path/to/index.js", }); - expect(result.rawConfig).toEqual({ - compatibility_date: "2022-01-12", - name: "config-one", - }); + expect(result.rawConfig).toEqual( + expect.objectContaining({ + name: "config-one", + }) + ); result = experimental_readRawConfig({ script: "../folder/index.js", }); - expect(result.rawConfig).toEqual({ - compatibility_date: "2022-01-12", - name: "config-two", - }); + expect(result.rawConfig).toEqual( + expect.objectContaining({ + name: "config-two", + }) + ); }); } ); diff --git a/packages/wrangler/src/__tests__/patch-config.test.ts b/packages/wrangler/src/__tests__/patch-config.test.ts new file mode 100644 index 000000000000..1f12784883f7 --- /dev/null +++ b/packages/wrangler/src/__tests__/patch-config.test.ts @@ -0,0 +1,876 @@ +import { writeFileSync } from "node:fs"; +import dedent from "ts-dedent"; +import { experimental_patchConfig } from "../config/patch-config"; +import { runInTempDir } from "./helpers/run-in-tmp"; +import { writeWranglerConfig } from "./helpers/write-wrangler-config"; +import type { RawConfig } from "../config"; + +type TestCase = { + name: string; + original: RawConfig; + additivePatch: RawConfig; + replacingPatch: RawConfig; + expectedToml: string; + expectedJson: string; +}; +const testCases: TestCase[] = [ + { + name: "add a binding", + original: {}, + additivePatch: { + kv_namespaces: [ + { + binding: "KV", + }, + ], + }, + replacingPatch: { + kv_namespaces: [ + { + binding: "KV", + }, + ], + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + + [[kv_namespaces]] + binding = "KV" + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name", + "kv_namespaces": [ + { + "binding": "KV" + } + ] + } + `, + }, + { + name: "add a second binding of the same type", + original: { + kv_namespaces: [ + { + binding: "KV", + }, + ], + }, + additivePatch: { + kv_namespaces: [ + { + binding: "KV2", + }, + ], + }, + replacingPatch: { + kv_namespaces: [ + { + binding: "KV", + }, + { + binding: "KV2", + }, + ], + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + + [[kv_namespaces]] + binding = "KV" + + [[kv_namespaces]] + binding = "KV2" + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name", + "kv_namespaces": [ + { + "binding": "KV" + }, + { + "binding": "KV2" + } + ] + } + `, + }, + { + name: "add a new D1 binding when only KV bindings exist", + original: { + kv_namespaces: [ + { + binding: "KV", + }, + ], + }, + additivePatch: { + d1_databases: [ + { + binding: "DB", + }, + ], + }, + replacingPatch: { + d1_databases: [ + { + binding: "DB", + }, + ], + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + + [[kv_namespaces]] + binding = "KV" + + [[d1_databases]] + binding = "DB" + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name", + "kv_namespaces": [ + { + "binding": "KV" + } + ], + "d1_databases": [ + { + "binding": "DB" + } + ] + } + `, + }, + { + name: "add a new field", + original: { + kv_namespaces: [ + { + binding: "KV", + }, + ], + }, + additivePatch: { + compatibility_flags: ["nodejs_compat"], + }, + replacingPatch: { + compatibility_flags: ["nodejs_compat"], + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + compatibility_flags = [ "nodejs_compat" ] + + [[kv_namespaces]] + binding = "KV" + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name", + "kv_namespaces": [ + { + "binding": "KV" + } + ], + "compatibility_flags": [ + "nodejs_compat" + ] + } + `, + }, + { + name: "make multiple edits at the same time", + original: { + kv_namespaces: [ + { + binding: "KV", + }, + ], + d1_databases: [ + { + binding: "DB", + }, + ], + }, + additivePatch: { + kv_namespaces: [ + { + binding: "KV2", + }, + { + binding: "KV3", + }, + ], + d1_databases: [ + { + binding: "DB2", + }, + ], + }, + replacingPatch: { + kv_namespaces: [ + { + binding: "KV", + }, + { + binding: "KV2", + }, + { + binding: "KV3", + }, + ], + d1_databases: [ + { + binding: "DB", + }, + { + binding: "DB2", + }, + ], + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + + [[kv_namespaces]] + binding = "KV" + + [[kv_namespaces]] + binding = "KV2" + + [[kv_namespaces]] + binding = "KV3" + + [[d1_databases]] + binding = "DB" + + [[d1_databases]] + binding = "DB2" + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name", + "kv_namespaces": [ + { + "binding": "KV" + }, + { + "binding": "KV2" + }, + { + "binding": "KV3" + } + ], + "d1_databases": [ + { + "binding": "DB" + }, + { + "binding": "DB2" + } + ] + } + `, + }, +]; + +const replacingOnlyTestCases: Omit[] = [ + { + name: "edit a binding", + original: {}, + replacingPatch: { + kv_namespaces: [ + { + binding: "KV2", + }, + ], + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + + [[kv_namespaces]] + binding = "KV2" + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name", + "kv_namespaces": [ + { + "binding": "KV2" + } + ] + } + `, + }, + { + name: "add a field to an existing binding", + original: { + kv_namespaces: [ + { + binding: "KV", + }, + ], + }, + replacingPatch: { + kv_namespaces: [ + { + binding: "KV", + id: "1234", + }, + ], + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + + [[kv_namespaces]] + binding = "KV" + id = "1234" + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name", + "kv_namespaces": [ + { + "binding": "KV", + "id": "1234" + } + ] + } + `, + }, + { + name: "delete an existing binding so that none are left", + original: { + compatibility_flags: ["test-flag"], + }, + replacingPatch: { + compatibility_flags: undefined, + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name" + } + `, + }, + // This one doesn't work because the jsonc-parser leaves behind a stray bracket when deleting + // there are possibly solutions that I am not inclined to solve right now + // e.g. passing in {binding: undefined} in the patch instead and cleaning up empty objects + // { + // name: "delete an existing binding (but some bindings of that type are still left)", + // original: { + // kv_namespaces: [ + // { + // binding: "KV", + // }, + // { + // binding: "KV2", + // }, + // ], + // }, + // replacingPatch: { + // kv_namespaces: [ + // { + // binding: "KV", + // }, + // undefined, + // ], + // }, + // expectedToml: dedent` + // compatibility_date = "2022-01-12" + // name = "test-name" + + // [[kv_namespaces]] + // binding = "KV" + + // `, + // expectedJson: dedent` + // { + // "compatibility_date": "2022-01-12", + // "name": "test-name", + // "kv_namespaces": [ + // { + // "binding": "KV" + // } + // ] + // } + // `, + // }, + { + name: "edit a compat flag", + original: {}, + replacingPatch: { + compatibility_flags: ["no_nodejs_compat"], + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + compatibility_flags = [ "no_nodejs_compat" ] + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name", + "compatibility_flags": [ + "no_nodejs_compat" + ] + } + `, + }, + { + name: "add a compat flag", + original: { compatibility_flags: ["nodejs_compat"] }, + replacingPatch: { + compatibility_flags: ["nodejs_compat", "flag"], + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + compatibility_flags = [ "nodejs_compat", "flag" ] + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name", + "compatibility_flags": [ + "nodejs_compat", + "flag" + ] + } + `, + }, + { + name: "delete a compat flag", + original: {}, + replacingPatch: { + compatibility_flags: undefined, + }, + expectedToml: dedent` + compatibility_date = "2022-01-12" + name = "test-name" + + `, + expectedJson: dedent` + { + "compatibility_date": "2022-01-12", + "name": "test-name" + } + `, + }, +]; + +describe("experimental_patchConfig()", () => { + runInTempDir(); + describe.each([true, false])("isArrayInsertion = %o", (isArrayInsertion) => { + describe.each(testCases)( + `$name`, + ({ + original, + replacingPatch, + additivePatch, + expectedJson, + expectedToml, + }) => { + it.each(["json", "toml"])("%s", (configType) => { + writeWranglerConfig( + original, + configType === "json" ? "./wrangler.json" : "./wrangler.toml" + ); + const result = experimental_patchConfig( + configType === "json" ? "./wrangler.json" : "./wrangler.toml", + isArrayInsertion ? additivePatch : replacingPatch, + isArrayInsertion + ); + expect(result).not.toBeFalsy(); + expect(result).toEqual( + `${configType === "json" ? expectedJson : expectedToml}` + ); + }); + } + ); + }); + describe("isArrayInsertion = false", () => { + describe.each(replacingOnlyTestCases)( + `$name`, + ({ original, replacingPatch, expectedJson, expectedToml }) => { + it.each(["json", "toml"])("%s", (configType) => { + writeWranglerConfig( + original, + configType === "json" ? "./wrangler.json" : "./wrangler.toml" + ); + const result = experimental_patchConfig( + configType === "json" ? "./wrangler.json" : "./wrangler.toml", + replacingPatch, + false + ); + expect(result).not.toBeFalsy(); + expect(result).toEqual( + `${configType === "json" ? expectedJson : expectedToml}` + ); + }); + } + ); + }); + + describe("jsonc", () => { + describe("add multiple bindings", () => { + it("isArrayInsertion = true", () => { + const jsonc = ` + { + // a comment + "compatibility_date": "2022-01-12", + "name": "test-name", + "kv_namespaces": [ + { + // more comments! + "binding": "KV" + } + ], + "d1_databases": [ + /** + * multiline comment + */ + { + "binding": "DB" + } + ] + } + `; + writeFileSync("./wrangler.jsonc", jsonc); + const patch = { + kv_namespaces: [ + { + binding: "KV2", + }, + { + binding: "KV3", + }, + ], + d1_databases: [ + { + binding: "DB2", + }, + ], + }; + const result = experimental_patchConfig("./wrangler.jsonc", patch); + expect(result).not.toBeFalsy(); + expect(result).toMatchInlineSnapshot(` + "{ + // a comment + \\"compatibility_date\\": \\"2022-01-12\\", + \\"name\\": \\"test-name\\", + \\"kv_namespaces\\": [ + { + // more comments! + \\"binding\\": \\"KV\\" + }, + { + \\"binding\\": \\"KV2\\" + }, + { + \\"binding\\": \\"KV3\\" + } + ], + \\"d1_databases\\": [ + /** + * multiline comment + */ + { + \\"binding\\": \\"DB\\" + }, + { + \\"binding\\": \\"DB2\\" + } + ] + }" + `); + }); + it("isArrayInsertion = false ", () => { + const jsonc = dedent` + { + // a comment + "compatibility_date": "2022-01-12", + "name": "test-name", + "kv_namespaces": [ + { + // more comments! + "binding": "KV" + } + ], + "d1_databases": [ + /** + * multiline comment + */ + { + "binding": "DB" + } + ] + } + `; + writeFileSync("./wrangler.jsonc", jsonc); + const patch = { + kv_namespaces: [ + { + binding: "KV", + }, + { + binding: "KV2", + }, + { + binding: "KV3", + }, + ], + d1_databases: [ + { + binding: "DB", + }, + { + binding: "DB2", + }, + ], + }; + const result = experimental_patchConfig( + "./wrangler.jsonc", + patch, + false + ); + expect(result).not.toBeFalsy(); + expect(result).toMatchInlineSnapshot(` + "{ + // a comment + \\"compatibility_date\\": \\"2022-01-12\\", + \\"name\\": \\"test-name\\", + \\"kv_namespaces\\": [ + { + // more comments! + \\"binding\\": \\"KV\\" + }, + { + \\"binding\\": \\"KV2\\" + }, + { + \\"binding\\": \\"KV3\\" + } + ], + \\"d1_databases\\": [ + /** + * multiline comment + */ + { + \\"binding\\": \\"DB\\" + }, + { + \\"binding\\": \\"DB2\\" + } + ] + }" + `); + }); + }); + describe("edit existing bindings", () => { + it("isArrayInsertion = false", () => { + const jsonc = ` + { + // comment one + "compatibility_date": "2022-01-12", + // comment two + "name": "test-name", + "kv_namespaces": [ + { + // comment three + "binding": "KV" + // comment four + }, + { + // comment five + "binding": "KV2" + // comment six + } + ] + } + `; + writeFileSync("./wrangler.jsonc", jsonc); + const patch = { + compatibility_date: "2024-27-09", + kv_namespaces: [ + { + binding: "KV", + id: "hello-id", + }, + { + binding: "KV2", + }, + ], + }; + const result = experimental_patchConfig( + "./wrangler.jsonc", + patch, + false + ); + expect(result).not.toBeFalsy(); + expect(result).toMatchInlineSnapshot(` + "{ + // comment one + \\"compatibility_date\\": \\"2024-27-09\\", + // comment two + \\"name\\": \\"test-name\\", + \\"kv_namespaces\\": [ + { + // comment three + \\"binding\\": \\"KV\\", + \\"id\\": \\"hello-id\\" + // comment four + }, + { + // comment five + \\"binding\\": \\"KV2\\" + // comment six + } + ] + }" + `); + }); + }); + + describe("edit existing bindings with patch array in a different order (will mess up comments)", () => { + it("isArrayInsertion = false", () => { + const jsonc = ` + { + // comment one + "compatibility_date": "2022-01-12", + // comment two + "name": "test-name", + "kv_namespaces": [ + { + // comment three + "binding": "KV" + // comment four + }, + { + // comment five + "binding": "KV2" + // comment six + } + ] + } + `; + writeFileSync("./wrangler.jsonc", jsonc); + const patch = { + compatibility_date: "2024-27-09", + kv_namespaces: [ + { + binding: "KV2", + }, + { + binding: "KV", + id: "hello-id", + }, + ], + }; + const result = experimental_patchConfig( + "./wrangler.jsonc", + patch, + false + ); + expect(result).not.toBeFalsy(); + // Note that the comments have stayed in place! + // However, I don't think we can reasonably expect to bring comments along when an array has been reordered + expect(result).toMatchInlineSnapshot(` + "{ + // comment one + \\"compatibility_date\\": \\"2024-27-09\\", + // comment two + \\"name\\": \\"test-name\\", + \\"kv_namespaces\\": [ + { + // comment three + \\"binding\\": \\"KV2\\" + // comment four + }, + { + // comment five + \\"binding\\": \\"KV\\", + \\"id\\": \\"hello-id\\" + // comment six + } + ] + }" + `); + }); + }); + + describe("delete existing bindings (cannot preserve comments)", () => { + it("isArrayInsertion = false", () => { + const jsonc = ` + { + // comment one + "compatibility_date": "2022-01-12", + // comment two + "name": "test-name", + "kv_namespaces": [ + { + // comment three + "binding": "KV" + // comment four + }, + { + // comment five + "binding": "KV2" + // comment six + } + ] + } + `; + writeFileSync("./wrangler.jsonc", jsonc); + const patch = { + compatibility_date: "2024-27-09", + kv_namespaces: undefined, + }; + const result = experimental_patchConfig( + "./wrangler.jsonc", + patch, + false + ); + expect(result).not.toBeFalsy(); + expect(result).toMatchInlineSnapshot(` + "{ + // comment one + \\"compatibility_date\\": \\"2024-27-09\\", + // comment two + \\"name\\": \\"test-name\\" + }" + `); + }); + }); + }); +}); diff --git a/packages/wrangler/src/cli.ts b/packages/wrangler/src/cli.ts index 6da850958a54..f3139526b21f 100644 --- a/packages/wrangler/src/cli.ts +++ b/packages/wrangler/src/cli.ts @@ -60,3 +60,4 @@ const generateASSETSBinding: ( export { generateASSETSBinding as unstable_generateASSETSBinding }; export { experimental_readRawConfig } from "./config"; +export { experimental_patchConfig } from "./config/patch-config"; diff --git a/packages/wrangler/src/config/patch-config.ts b/packages/wrangler/src/config/patch-config.ts new file mode 100644 index 000000000000..38b09ce2b4e3 --- /dev/null +++ b/packages/wrangler/src/config/patch-config.ts @@ -0,0 +1,97 @@ +import { writeFileSync } from "fs"; +import TOML from "@iarna/toml"; +import { applyEdits, format, modify } from "jsonc-parser"; +import { parseJSONC, parseTOML, readFileSync } from "../parse"; +import type { RawConfig } from "./config"; +import type { JSONPath } from "jsonc-parser"; + +export const experimental_patchConfig = ( + configPath: string, + /** + * if you want to add something new, e.g. a binding, you can just provide that {kv_namespace:[{binding:"KV"}]} + * and set isArrayInsertion = true + * + * if you want to edit or delete existing array elements, you have to provide the whole array + * e.g. {kv_namespace:[{binding:"KV", id:"new-id"}, {binding:"KV2", id:"untouched"}]} + * and set isArrayInsertion = false + */ + patch: RawConfig, + isArrayInsertion: boolean = true +) => { + let configString = readFileSync(configPath); + + if (configPath.endsWith("toml")) { + // the TOML parser we use does not preserve comments + if (configString.includes("#")) { + throw new PatchConfigError( + "cannot patch .toml config if comments are present" + ); + } else { + // for simplicity, use the JSONC editor to make all edits + // toml -> js object -> json string -> edits -> js object -> toml + configString = JSON.stringify(parseTOML(configString)); + } + } + + const patchPaths: JSONPath[] = []; + getJSONPath(patch, patchPaths, isArrayInsertion); + for (const patchPath of patchPaths) { + const value = patchPath.pop(); + const edit = modify(configString, patchPath, value, { + isArrayInsertion, + }); + configString = applyEdits(configString, edit); + } + const formatEdit = format(configString, undefined, {}); + configString = applyEdits(configString, formatEdit); + + if (configPath.endsWith(".toml")) { + configString = TOML.stringify(parseJSONC(configString)); + } + writeFileSync(configPath, configString); + return configString; +}; + +/** + * + * Gets all the JSON paths for a given object by recursing through the object, recording the properties encountered. + * e.g. {a : { b: "c", d: ["e", "f"]}} -> [["a", "b", "c"], ["a", "d", 0], ["a", "d", 1]] + * The jsonc-parser library requires JSON paths for each edit. + * Note the final 'path' segment is the value we want to insert, + * so in the above example,["a", "b"] would be the path and we would insert "c" + * + * If isArrayInsertion = false, when we encounter an array, we use the item index as part of the path and continue + * If isArrayInsertion = false, we stop recursing down and treat the whole array item as the final path segment/value. + * + */ +const getJSONPath = ( + obj: RawConfig, + allPaths: JSONPath[], + isArrayInsertion: boolean, + prevPath: JSONPath = [] +) => { + for (const [k, v] of Object.entries(obj)) { + const currentPath = [...prevPath, k]; + if (Array.isArray(v)) { + v.forEach((x, i) => { + if (isArrayInsertion) { + // makes sure we insert new array items at the end + allPaths.push([...currentPath, -1, x]); + } else if (typeof x === "object") { + getJSONPath(x, allPaths, isArrayInsertion, [...currentPath, i]); + } else { + allPaths.push([...currentPath, i, x]); + } + }); + } else if (typeof v === "object") { + getJSONPath(v, allPaths, isArrayInsertion, currentPath); + } else { + allPaths.push([...currentPath, v]); + } + } +}; + +/** + * Custom error class for config patching errors + */ +export class PatchConfigError extends Error {} From ab0ac94849b8cabe6b29340bc5d539a8a9d61ab8 Mon Sep 17 00:00:00 2001 From: Edmund Hung Date: Thu, 19 Dec 2024 11:09:55 +0000 Subject: [PATCH 09/53] feat(cloudflare-workers-bindings-extensions): list bindings on the sidebar (#7582) --- .changeset/warm-squids-visit.md | 5 + .../.vscode-test.mjs | 5 - .../package.json | 44 +- .../src/bindings.ts | 225 ++++++++++ .../src/extension.ts | 49 ++- .../src/test/runTest.ts | 42 ++ .../src/test/suite/extension.test.ts | 395 ++++++++++++++++++ .../src/test/suite/index.ts | 37 ++ .../tsconfig.json | 3 +- pnpm-lock.yaml | 199 ++------- 10 files changed, 794 insertions(+), 210 deletions(-) create mode 100644 .changeset/warm-squids-visit.md delete mode 100644 packages/cloudflare-workers-bindings-extension/.vscode-test.mjs create mode 100644 packages/cloudflare-workers-bindings-extension/src/bindings.ts create mode 100644 packages/cloudflare-workers-bindings-extension/src/test/runTest.ts create mode 100644 packages/cloudflare-workers-bindings-extension/src/test/suite/extension.test.ts create mode 100644 packages/cloudflare-workers-bindings-extension/src/test/suite/index.ts diff --git a/.changeset/warm-squids-visit.md b/.changeset/warm-squids-visit.md new file mode 100644 index 000000000000..313a249bc4f1 --- /dev/null +++ b/.changeset/warm-squids-visit.md @@ -0,0 +1,5 @@ +--- +"cloudflare-workers-bindings-extension": patch +--- + +Introduce a bindings view that lists all the KV, D1 and R2 bindings on the wrangler config (e.g. `wrangler.toml`, `wrangler.jsonc`) diff --git a/packages/cloudflare-workers-bindings-extension/.vscode-test.mjs b/packages/cloudflare-workers-bindings-extension/.vscode-test.mjs deleted file mode 100644 index 8bf881e70716..000000000000 --- a/packages/cloudflare-workers-bindings-extension/.vscode-test.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import { defineConfig } from "@vscode/test-cli"; - -export default defineConfig({ - files: "out/test/**/*.test.js", -}); diff --git a/packages/cloudflare-workers-bindings-extension/package.json b/packages/cloudflare-workers-bindings-extension/package.json index 640d3bc74247..94b1b21f76c8 100644 --- a/packages/cloudflare-workers-bindings-extension/package.json +++ b/packages/cloudflare-workers-bindings-extension/package.json @@ -19,6 +19,7 @@ "package": "pnpm run check:type && pnpm run check:lint && node esbuild.js --production", "compile-tests": "tsc -p . --outDir out", "watch-tests": "tsc -p . -w --outDir out", + "test": "node ./out/test/runTest.js", "check:type": "tsc --noEmit", "check:lint": "eslint src --ext ts", "build": "vsce package", @@ -27,46 +28,61 @@ "contributes": { "commands": [ { - "command": "cloudflare-workers-bindings-extension.testCommand", - "title": "Test command", - "icon": { - "light": "resources/light/edit.svg", - "dark": "resources/dark/edit.svg" - } + "command": "cloudflare-workers-bindings.refresh", + "title": "Cloudflare Workers: Refresh bindings", + "icon": "$(refresh)" } ], + "menus": { + "view/title": [ + { + "command": "cloudflare-workers-bindings.refresh", + "when": "view == cloudflare-workers-bindings", + "group": "navigation" + } + ] + }, "views": { - "cloudflare-workers-bindings": [ + "cloudflare-workers": [ { - "id": "cloudflare-workers-bindings-extension", + "id": "cloudflare-workers-bindings", "name": "Bindings", - "icon": "resources/icons/cf-workers-logo.svg" + "icon": "media/cf-workers-logo.svg", + "contextualTitle": "Cloudflare Workers Bindings" } ] }, "viewsContainers": { "activitybar": [ { - "id": "cloudflare-workers-bindings", + "id": "cloudflare-workers", "title": "Cloudflare Workers", "icon": "media/cf-workers-logo.svg" } ] - } + }, + "viewsWelcome": [ + { + "view": "cloudflare-workers-bindings", + "contents": "Welcome to Cloudflare Workers! [Learn more](https://workers.cloudflare.com).\n[Refresh Bindings](command:cloudflare-workers-bindings.refresh)" + } + ] }, "activationEvents": [ - "workspaceContains:{**/wrangler.json,**/wrangler.jsonc,**/wrangler.toml}" + "workspaceContains:**/wrangler.{json,jsonc,toml}" ], "devDependencies": { + "@types/glob": "^7.1.1", "@types/mocha": "^10.0.7", "@types/node": "20.x", "@types/vscode": "^1.92.0", "@typescript-eslint/eslint-plugin": "^7.14.1", "@typescript-eslint/parser": "^7.11.0", - "@vscode/test-cli": "^0.0.9", - "@vscode/test-electron": "^2.4.0", + "@vscode/test-electron": "^2.4.1", "esbuild": "^0.21.5", "eslint": "^8.57.0", + "glob": "^7.1.4", + "mocha": "^10.2.0", "npm-run-all": "^4.1.5", "typescript": "^5.4.5", "vsce": "^2.15.0", diff --git a/packages/cloudflare-workers-bindings-extension/src/bindings.ts b/packages/cloudflare-workers-bindings-extension/src/bindings.ts new file mode 100644 index 000000000000..817b39fdebbd --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/src/bindings.ts @@ -0,0 +1,225 @@ +import * as vscode from "vscode"; +import { importWrangler } from "./wrangler"; + +type Config = ReturnType< + ReturnType["experimental_readRawConfig"] +>["rawConfig"]; + +type Node = + | { + type: "env"; + config: Config; + env: string | null; + } + | { + type: "binding"; + config: Config; + env: string | null; + binding: string; + } + | { + type: "resource"; + config: Config; + env: string | null; + binding: string; + name: string; + description?: string; + }; + +export class BindingsProvider implements vscode.TreeDataProvider { + // Event emitter for refreshing the tree + private _onDidChangeTreeData: vscode.EventEmitter< + Node | undefined | null | void + > = new vscode.EventEmitter(); + + // To notify the TreeView that the tree data has changed + readonly onDidChangeTreeData: vscode.Event = + this._onDidChangeTreeData.event; + + // To manually refresh the tree + refresh(): void { + this._onDidChangeTreeData.fire(); + } + + getTreeItem(node: Node): vscode.TreeItem { + switch (node.type) { + case "env": { + const item = new vscode.TreeItem( + node.env ?? "Top-level env", + vscode.TreeItemCollapsibleState.Expanded + ); + + return item; + } + case "binding": { + return new vscode.TreeItem( + node.binding, + vscode.TreeItemCollapsibleState.Expanded + ); + } + case "resource": { + const item = new vscode.TreeItem( + node.name, + vscode.TreeItemCollapsibleState.None + ); + + if (node.description) { + item.description = node.description; + } + + return item; + } + } + } + + async getChildren(node?: Node): Promise { + if (!node) { + const config = await getWranglerConfig(); + + if (!config) { + return []; + } + + const topLevelEnvNode: Node = { + type: "env", + config, + env: null, + }; + const children: Node[] = []; + + for (const env of Object.keys(config.env ?? {})) { + const node: Node = { + ...topLevelEnvNode, + env, + }; + const grandChildren = await this.getChildren(node); + + // Include the environment only if it has any bindings + if (grandChildren.length > 0) { + children.push({ + ...topLevelEnvNode, + env, + }); + } + } + + const topLevelEnvChildren = await this.getChildren(topLevelEnvNode); + + if (children.length > 0) { + // Include top level env only if it has any bindings too + if (topLevelEnvChildren.length > 0) { + children.unshift(topLevelEnvNode); + } + + return children; + } + + // Skip the top level env if there are no environments + return topLevelEnvChildren; + } + + switch (node.type) { + case "env": { + const children: Node[] = []; + const env = node.env ? node.config.env?.[node.env] : node.config; + + if (env?.kv_namespaces && env.kv_namespaces.length > 0) { + children.push({ + ...node, + type: "binding", + binding: "KV Namespaces", + }); + } + + if (env?.r2_buckets && env.r2_buckets.length > 0) { + children.push({ + ...node, + type: "binding", + binding: "R2 Buckets", + }); + } + + if (env?.d1_databases && env.d1_databases.length > 0) { + children.push({ + ...node, + type: "binding", + binding: "D1 Databases", + }); + } + + return children; + } + case "binding": { + const children: Node[] = []; + const env = node.env ? node.config.env?.[node.env] : node.config; + + switch (node.binding) { + case "KV Namespaces": { + for (const kv of env?.kv_namespaces ?? []) { + children.push({ + ...node, + type: "resource", + name: kv.binding, + description: kv.id, + }); + } + break; + } + case "R2 Buckets": { + for (const r2 of env?.r2_buckets ?? []) { + children.push({ + ...node, + type: "resource", + name: r2.binding, + description: r2.bucket_name, + }); + } + + break; + } + case "D1 Databases": { + for (const d1 of env?.d1_databases ?? []) { + children.push({ + ...node, + type: "resource", + name: d1.binding, + description: d1.database_id, + }); + } + break; + } + } + + return children; + } + case "resource": + return []; + } + } +} + +// Finds the first wrangler config file in the workspace and parse it +export async function getWranglerConfig(): Promise { + const [configUri] = await vscode.workspace.findFiles( + "wrangler.{toml,jsonc,json}", + null, + 1 + ); + + if (!configUri) { + return null; + } + + const workspaceFolder = vscode.workspace.getWorkspaceFolder(configUri); + + if (!workspaceFolder) { + return null; + } + + const wrangler = await importWrangler(workspaceFolder.uri.fsPath); + const { rawConfig } = wrangler.experimental_readRawConfig({ + config: configUri.fsPath, + }); + + return rawConfig; +} diff --git a/packages/cloudflare-workers-bindings-extension/src/extension.ts b/packages/cloudflare-workers-bindings-extension/src/extension.ts index 3c930f3d6cd3..9da94758ee44 100644 --- a/packages/cloudflare-workers-bindings-extension/src/extension.ts +++ b/packages/cloudflare-workers-bindings-extension/src/extension.ts @@ -1,24 +1,41 @@ import * as vscode from "vscode"; -import { importWrangler } from "./wrangler"; +import { BindingsProvider } from "./bindings"; -export async function activate(context: vscode.ExtensionContext) { - vscode.commands.registerCommand( - "cloudflare-workers-bindings-extension.testCommand", - () => - vscode.window.showInformationMessage(`Successfully called test command.`) +export type Result = { + bindingsProvider: BindingsProvider; +}; + +export async function activate( + context: vscode.ExtensionContext +): Promise { + // A tree data provider that returns all the bindings data from the workspace + const bindingsProvider = new BindingsProvider(); + // Register the tree view to list bindings + const bindingsView = vscode.window.registerTreeDataProvider( + "cloudflare-workers-bindings", + bindingsProvider + ); + + // Watch for config file changes + const watcher = vscode.workspace.createFileSystemWatcher( + "**/wrangler.{toml,jsonc,json}" ); - const rootPath = - vscode.workspace.workspaceFolders && - vscode.workspace.workspaceFolders.length > 0 - ? vscode.workspace.workspaceFolders[0].uri.fsPath - : undefined; + // Refresh the bindings when the wrangler config file changes + watcher.onDidChange(() => bindingsProvider.refresh()); + watcher.onDidCreate(() => bindingsProvider.refresh()); + watcher.onDidDelete(() => bindingsProvider.refresh()); - if (!rootPath) { - return; - } + // Register the refresh command, which is also used by the bindings view + const refreshCommand = vscode.commands.registerCommand( + "cloudflare-workers-bindings.refresh", + () => bindingsProvider.refresh() + ); - const wrangler = importWrangler(rootPath); + // Cleanup when the extension is deactivated + context.subscriptions.push(bindingsView, watcher, refreshCommand); - // Do stuff with Wrangler + return { + bindingsProvider, + }; } diff --git a/packages/cloudflare-workers-bindings-extension/src/test/runTest.ts b/packages/cloudflare-workers-bindings-extension/src/test/runTest.ts new file mode 100644 index 000000000000..7341da81780a --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/src/test/runTest.ts @@ -0,0 +1,42 @@ +import * as fs from "node:fs/promises"; +import * as os from "node:os"; +import * as path from "node:path"; +import { runTests } from "@vscode/test-electron"; + +async function main() { + try { + // The folder containing the Extension Manifest package.json + // Passed to `--extensionDevelopmentPath` + const extensionDevelopmentPath = path.resolve(__dirname, "../../"); + // The path to the extension test script + // Passed to --extensionTestsPath + const extensionTestsPath = path.resolve(__dirname, "./suite/index"); + const workspaceDir = await fs.mkdtemp( + path.join(os.tmpdir(), "vscode-workspace") + ); + const userDataDir = await fs.mkdtemp( + path.join(os.tmpdir(), "vscode-extension") + ); + + // Download VS Code, unzip it and run the integration test + await runTests({ + extensionDevelopmentPath, + extensionTestsPath, + extensionTestsEnv: { + VSCODE_WORKSPACE_PATH: workspaceDir, + }, + launchArgs: [ + workspaceDir, + // It will fail to save the user data and crash the next test run if the path is longer than 103 chars + `--user-data-dir=${userDataDir}`, + // This disables all extensions except the one being tested + "--disable-extensions", + ], + }); + } catch { + console.error("Failed to run tests"); + process.exit(1); + } +} + +main(); diff --git a/packages/cloudflare-workers-bindings-extension/src/test/suite/extension.test.ts b/packages/cloudflare-workers-bindings-extension/src/test/suite/extension.test.ts new file mode 100644 index 000000000000..41d0b986ada5 --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/src/test/suite/extension.test.ts @@ -0,0 +1,395 @@ +import assert from "node:assert"; +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import * as vscode from "vscode"; +import type { Result } from "../../extension"; + +// Environment variable set by the test runner (See packages/cloudflare-workers-bindings-extension/src/test/runTest.ts) +assert( + process.env.VSCODE_WORKSPACE_PATH, + "process.env.VSCODE_WORKSPACE_PATH is not available" +); + +describe("Extension Test Suite", () => { + before(async () => { + await symlinkWranglerNodeModule(); + }); + + describe("BindingsProvider", () => { + it("shows no bindings if there is no wrangler config", async () => { + const extension = getExtension(); + const { bindingsProvider } = await extension.activate(); + + const children = await bindingsProvider.getChildren(); + + assert.deepEqual(children, []); + }); + + it("lists bindings based on the wrangler config", async () => { + const config = { + name: "test", + kv_namespaces: [ + { + binding: "cache", + id: "xx-yyyy-zzz", + }, + ], + r2_buckets: [ + { + binding: "images", + bucket_name: "something", + }, + ], + d1_databases: [ + { + binding: "db", + database_id: "xxxxyyyyzzzzz", + }, + ], + }; + const cleanup = await seed({ + "wrangler.json": JSON.stringify(config), + }); + + try { + const extension = getExtension(); + const { bindingsProvider } = await extension.activate(); + + const children = await bindingsProvider.getChildren(); + + assert.deepEqual( + children.map((child) => bindingsProvider.getTreeItem(child)), + [ + { + label: "KV Namespaces", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: "R2 Buckets", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: "D1 Databases", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + ] + ); + + const [kv, r2, d1] = children; + + const kvChildren = await bindingsProvider.getChildren(kv); + assert.deepEqual( + kvChildren.map((child) => bindingsProvider.getTreeItem(child)), + [ + { + label: "cache", + description: "xx-yyyy-zzz", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ] + ); + + const r2Children = await bindingsProvider.getChildren(r2); + assert.deepEqual( + r2Children.map((child) => bindingsProvider.getTreeItem(child)), + [ + { + label: "images", + description: "something", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ] + ); + + const d1Children = await bindingsProvider.getChildren(d1); + assert.deepEqual( + d1Children.map((child) => bindingsProvider.getTreeItem(child)), + [ + { + label: "db", + description: "xxxxyyyyzzzzz", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ] + ); + } finally { + await cleanup(); + } + }); + + it("groups bindings by environment if available", async () => { + const config = { + name: "test", + d1_databases: [ + { + binding: "db", + database_id: "xxxxyyyyzzzzz", + }, + ], + env: { + development: {}, + staging: { + kv_namespaces: [ + { + binding: "kv", + id: "aa-bb-cc", + }, + ], + }, + production: { + r2_buckets: [ + { + binding: "r2", + bucket_name: "something else", + }, + ], + }, + }, + }; + const cleanup = await seed({ + "wrangler.json": JSON.stringify(config), + }); + + try { + const extension = getExtension(); + const { bindingsProvider } = await extension.activate(); + + const children = await bindingsProvider.getChildren(); + + assert.deepEqual( + children.map((child) => bindingsProvider.getTreeItem(child)), + [ + { + label: "Top-level env", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: "staging", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: "production", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + ] + ); + + const [topLevelEnv, staging, production] = children; + + const topLevelEnvChildren = + await bindingsProvider.getChildren(topLevelEnv); + assert.deepEqual( + topLevelEnvChildren.map((child) => + bindingsProvider.getTreeItem(child) + ), + [ + { + label: "D1 Databases", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + ] + ); + + const stagingChildren = await bindingsProvider.getChildren(staging); + assert.deepEqual( + stagingChildren.map((child) => bindingsProvider.getTreeItem(child)), + [ + { + label: "KV Namespaces", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + ] + ); + + const productionChildren = + await bindingsProvider.getChildren(production); + assert.deepEqual( + productionChildren.map((child) => + bindingsProvider.getTreeItem(child) + ), + [ + { + label: "R2 Buckets", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + ] + ); + } finally { + await cleanup(); + } + }); + + it("hides top level env if there is no bindings", async () => { + const config = { + name: "test", + env: { + production: { + r2_buckets: [ + { + binding: "r2", + bucket_name: "something else", + }, + ], + }, + }, + }; + const cleanup = await seed({ + "wrangler.json": JSON.stringify(config), + }); + + try { + const extension = getExtension(); + const { bindingsProvider } = await extension.activate(); + + const children = await bindingsProvider.getChildren(); + + assert.deepEqual( + children.map((child) => bindingsProvider.getTreeItem(child)), + [ + { + label: "production", + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + ] + ); + } finally { + await cleanup(); + } + }); + + it("watch for config file changes", async () => { + const cleanups: Array<() => Promise> = []; + + try { + const extension = getExtension(); + const { bindingsProvider } = await extension.activate(); + + await assert.doesNotReject(() => + Promise.all([ + // This should be resolved when the config file is created + new Promise((resolve) => { + bindingsProvider.onDidChangeTreeData(resolve); + }), + // Test creating config file + seed({ + "wrangler.json": JSON.stringify({ + name: "test", + kv_namespaces: [ + { + binding: "cache", + id: "xx-yyyy-zzz", + }, + ], + }), + }).then((cleanup) => { + cleanups.push(cleanup); + }), + ]) + ); + + await assert.doesNotReject(() => + Promise.all([ + // This should be resolved when the config file changes + new Promise((resolve) => { + bindingsProvider.onDidChangeTreeData(resolve); + }), + // Test changing the config file + seed({ + "wrangler.json": JSON.stringify({ + name: "test", + kv_namespaces: [ + { + binding: "cache", + id: "xx-yyyy-zzz", + }, + ], + r2_buckets: [ + { + binding: "images", + bucket_name: "something", + }, + ], + }), + }).then((cleanup) => { + cleanups.push(cleanup); + }), + ]) + ); + + await assert.doesNotReject(() => + Promise.all([ + // This should be resolved when the config file is deleted + new Promise((resolve) => { + bindingsProvider.onDidChangeTreeData(resolve); + }), + // Test deleting the config file + Promise.all(cleanups.map((cleanup) => cleanup())), + ]) + ); + } finally { + await Promise.all(cleanups.map((cleanup) => cleanup())); + } + }); + }); +}); + +function getExtension() { + const extension = vscode.extensions.getExtension( + "cloudflare.cloudflare-workers-bindings-extension" + ); + + if (!extension) { + throw new Error("Extension not found"); + } + + return extension; +} + +async function symlinkWranglerNodeModule() { + const nodeModulesPath = path.join( + process.env.VSCODE_WORKSPACE_PATH ?? "", + "node_modules" + ); + const wranglerNodeModulePath = path.resolve( + __dirname, + "..", + "..", + "..", + "..", + "wrangler" + ); + + await fs.mkdir(nodeModulesPath, { recursive: true }); + await fs.symlink( + wranglerNodeModulePath, + path.join(nodeModulesPath, "wrangler"), + "dir" + ); +} + +async function seed(files: Record) { + const root = process.env.VSCODE_WORKSPACE_PATH ?? ""; + + for (const [name, contents] of Object.entries(files)) { + const filePath = path.resolve(root, name); + + await fs.mkdir(path.dirname(filePath), { recursive: true }); + await fs.writeFile(filePath, contents); + } + + let cleanedUp = false; + + return async () => { + if (cleanedUp) { + return; + } + + for (const name of Object.keys(files)) { + const filePath = path.resolve(root, name); + + await fs.rm(filePath, { recursive: true }); + } + + cleanedUp = true; + }; +} diff --git a/packages/cloudflare-workers-bindings-extension/src/test/suite/index.ts b/packages/cloudflare-workers-bindings-extension/src/test/suite/index.ts new file mode 100644 index 000000000000..31aa9a3c8f7c --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/src/test/suite/index.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import glob from "glob"; +import Mocha from "mocha"; + +export function run(): Promise { + // Create the mocha test + const mocha = new Mocha({ + ui: "bdd", + }); + + const testsRoot = path.resolve(__dirname, ".."); + + return new Promise((c, e) => { + glob("**/**.test.js", { cwd: testsRoot }, (err, files) => { + if (err) { + return e(err); + } + + // Add files to the test suite + files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); + + try { + // Run the mocha test + mocha.run((failures) => { + if (failures > 0) { + e(new Error(`${failures} tests failed.`)); + } else { + c(); + } + }); + } catch (err) { + console.error(err); + e(err); + } + }); + }); +} diff --git a/packages/cloudflare-workers-bindings-extension/tsconfig.json b/packages/cloudflare-workers-bindings-extension/tsconfig.json index 652e8b8ef6e5..d0bbf7267825 100644 --- a/packages/cloudflare-workers-bindings-extension/tsconfig.json +++ b/packages/cloudflare-workers-bindings-extension/tsconfig.json @@ -6,7 +6,8 @@ "sourceMap": true, "rootDir": "src", "strict": true, - "noEmit": true /* enable all strict type-checking options */, + // We need to emit the file for tests to work + // "noEmit": true /* enable all strict type-checking options */, "skipLibCheck": true /* Additional Checks */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e1adb66c697..8691388cebb6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1019,6 +1019,9 @@ importers: packages/cloudflare-workers-bindings-extension: devDependencies: + '@types/glob': + specifier: ^7.1.1 + version: 7.2.0 '@types/mocha': specifier: ^10.0.7 version: 10.0.10 @@ -1034,11 +1037,8 @@ importers: '@typescript-eslint/parser': specifier: ^7.11.0 version: 7.18.0(eslint@8.57.0)(typescript@5.6.3) - '@vscode/test-cli': - specifier: ^0.0.9 - version: 0.0.9 '@vscode/test-electron': - specifier: ^2.4.0 + specifier: ^2.4.1 version: 2.4.1 esbuild: specifier: ^0.21.5 @@ -1046,6 +1046,12 @@ importers: eslint: specifier: ^8.57.0 version: 8.57.0 + glob: + specifier: ^7.1.4 + version: 7.2.3 + mocha: + specifier: ^10.2.0 + version: 10.8.2 npm-run-all: specifier: ^4.1.5 version: 4.1.5 @@ -2549,9 +2555,6 @@ packages: resolution: {integrity: sha512-vN5p+1kl59GVKMvTHt55NzzmYVxprfJD+ql7U9NFIfKCBkYE55LYtS+WtPlaYOyzydrKI8Nezd+aZextrd+FMA==} engines: {node: '>=6.9.0'} - '@bcoe/v8-coverage@0.2.3': - resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} - '@bundled-es-modules/cookie@2.0.0': resolution: {integrity: sha512-Or6YHg/kamKHpxULAdSqhGqnWFneIXu1NKvvfBBzKGwpVsYuFIQ5aBPHDnnoR3ghW1nvSkALd+EF9iMtY7Vjxw==} @@ -3695,10 +3698,6 @@ packages: resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} - '@istanbuljs/schema@0.1.3': - resolution: {integrity: sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==} - engines: {node: '>=8'} - '@jridgewell/gen-mapping@0.1.1': resolution: {integrity: sha512-sQXCasFk+U8lWYEe66WxRDOE9PjVz4vSM51fTu3Hw+ClTpUSQb718772vH3pyS5pShp6lvQM7SxgIDXXXmOX7w==} engines: {node: '>=6.0.0'} @@ -4353,9 +4352,6 @@ packages: '@types/is-ci@3.0.0': resolution: {integrity: sha512-Q0Op0hdWbYd1iahB+IFNQcWXFq4O0Q5MwQP7uN0souuQ4rPg1vEYcnIOfr1gY+M+6rc8FGoRaBO1mOOvL29sEQ==} - '@types/istanbul-lib-coverage@2.0.6': - resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==} - '@types/javascript-time-ago@2.0.3': resolution: {integrity: sha512-G6SdYh6gHxgCTU0s4cMIRHwRO4p3f7jQSZbDPfUOZpUAG1od3rTjT0e8rxGThUiTTWQHwpBRws8eHO8D2QqfkA==} @@ -4695,11 +4691,6 @@ packages: '@volar/typescript@2.4.0-alpha.18': resolution: {integrity: sha512-sXh5Y8sqGUkgxpMWUGvRXggxYHAVxg0Pa1C42lQZuPDrW6vHJPR0VCK8Sr7WJsAW530HuNQT/ZIskmXtxjybMQ==} - '@vscode/test-cli@0.0.9': - resolution: {integrity: sha512-vsl5/ueE3Jf0f6XzB0ECHHMsd5A0Yu6StElb8a+XsubZW7kHNAOw4Y3TSSuDzKEpLnJ92nbMy1Zl+KLGCE6NaA==} - engines: {node: '>=18'} - hasBin: true - '@vscode/test-electron@2.4.1': resolution: {integrity: sha512-Gc6EdaLANdktQ1t+zozoBVRynfIsMKMc94Svu1QreOBC8y76x4tvaK32TljrLi1LI2+PK58sDVbL7ALdqf3VRQ==} engines: {node: '>=16'} @@ -5135,11 +5126,6 @@ packages: resolution: {integrity: sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==} engines: {node: '>= 0.8'} - c8@9.1.0: - resolution: {integrity: sha512-mBWcT5iqNir1zIkzSPyI3NCR9EZCVI3WUD+AVO17MVWTSFNyUueXE82qTeampNtTr+ilN/5Ua3j24LgbCKjDVg==} - engines: {node: '>=14.14.0'} - hasBin: true - cac@6.7.14: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} @@ -5909,10 +5895,6 @@ packages: end-of-stream@1.4.4: resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==} - enhanced-resolve@5.17.1: - resolution: {integrity: sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==} - engines: {node: '>=10.13.0'} - enquirer@2.3.6: resolution: {integrity: sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==} engines: {node: '>=8.6'} @@ -6553,11 +6535,6 @@ packages: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} deprecated: Glob versions prior to v9 are no longer supported - glob@8.0.3: - resolution: {integrity: sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==} - engines: {node: '>=12'} - deprecated: Glob versions prior to v9 are no longer supported - glob@8.1.0: resolution: {integrity: sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==} engines: {node: '>=12'} @@ -6725,9 +6702,6 @@ packages: resolution: {integrity: sha512-kyCuEOWjJqZuDbRHzL8V93NzQhwIB71oFWSyzVo+KPZI+pnQPPxucdkrOZvkLRnrf5URsQM+IJ09Dw29cRALIA==} engines: {node: '>=10'} - html-escaper@2.0.2: - resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} - html-rewriter-wasm@0.4.1: resolution: {integrity: sha512-lNovG8CMCCmcVB1Q7xggMSf7tqPCijZXaH4gL6iE8BFghdQCbaY5Met9i1x2Ex8m/cZHDUtXK9H6/znKamRP8Q==} @@ -6741,10 +6715,6 @@ packages: resolution: {integrity: sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==} engines: {node: '>= 0.8'} - http-proxy-agent@7.0.0: - resolution: {integrity: sha512-+ZT+iBxVUQ1asugqnD6oWoRiS25AkjNfG085dKJGtGxkdwLQrMKU5wJr2bOOFAXzKcTuqq+7fZlTMgG3SRfIYQ==} - engines: {node: '>= 14'} - http-proxy-agent@7.0.2: resolution: {integrity: sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==} engines: {node: '>= 14'} @@ -7155,18 +7125,6 @@ packages: resolution: {integrity: sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==} engines: {node: '>=0.10.0'} - istanbul-lib-coverage@3.2.2: - resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} - engines: {node: '>=8'} - - istanbul-lib-report@3.0.1: - resolution: {integrity: sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==} - engines: {node: '>=10'} - - istanbul-reports@3.1.7: - resolution: {integrity: sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==} - engines: {node: '>=8'} - iterator.prototype@1.1.2: resolution: {integrity: sha512-DR33HMMr8EzwuRL8Y9D3u2BMj8+RqSE850jfGu59kS7tbmPLzGkZmVSfyCFSDxuZiEY6Rzt3T2NA/qU+NwVj1w==} @@ -7493,10 +7451,6 @@ packages: resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==} engines: {node: '>=8'} - make-dir@4.0.0: - resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==} - engines: {node: '>=10'} - make-error@1.3.6: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} @@ -9390,10 +9344,6 @@ packages: resolution: {integrity: sha512-XC6g/Kgux+rJXmwokjm9ECpD6k/smUoS5LKlUCcsYr4IY3rW0XyAympon2RmxGrlnZURMpg5T18gWDP9CsHXFA==} engines: {node: '>=12'} - supports-color@9.4.0: - resolution: {integrity: sha512-VL+lNrEoIXww1coLPOmiEmK/0sGigko5COxI09KzHc2VJXJsQ37UaQ+8quuxjDeA7+KnLGTWRyOXSLLR2Wb4jw==} - engines: {node: '>=12'} - supports-preserve-symlinks-flag@1.0.0: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} engines: {node: '>= 0.4'} @@ -9415,10 +9365,6 @@ packages: resolution: {integrity: sha512-L1dapNV6vu2s/4Sputv8xGsCdAVlb5nRDMFU/E27D44l5U6cw1g0dGd45uLc+OXjNMmF4ntiMdCimzcjFKQI8Q==} engines: {node: ^14.18.0 || >=16.0.0} - tapable@2.2.1: - resolution: {integrity: sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==} - engines: {node: '>=6'} - tar-fs@2.1.1: resolution: {integrity: sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==} @@ -9438,10 +9384,6 @@ packages: resolution: {integrity: sha512-wK0Ri4fOGjv/XPy8SBHZChl8CM7uMc5VML7SqiQ0zG7+J5Vr+RMQDoHa2CNT6KHUnTGIXH34UDMkPzAUyapBZg==} engines: {node: '>=8'} - test-exclude@6.0.0: - resolution: {integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==} - engines: {node: '>=8'} - text-table@0.2.0: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} @@ -9912,10 +9854,6 @@ packages: v8-compile-cache-lib@3.0.1: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} - v8-to-istanbul@9.3.0: - resolution: {integrity: sha512-kiGUalWN+rgBJ/1OHZsBtU4rXZOfj/7rKQxULKlIzwzQSvMJUUNgPwJEEh7gU6xEVxC0ahoOBvN2YI8GH6FNgA==} - engines: {node: '>=10.12.0'} - validate-npm-package-license@3.0.4: resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==} @@ -10739,8 +10677,6 @@ snapshots: '@babel/helper-string-parser': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 - '@bcoe/v8-coverage@0.2.3': {} - '@bundled-es-modules/cookie@2.0.0': dependencies: cookie: 0.5.0 @@ -10774,7 +10710,7 @@ snapshots: outdent: 0.5.0 prettier: 2.7.1 resolve-from: 5.0.0 - semver: 7.5.4 + semver: 7.6.3 '@changesets/assemble-release-plan@6.0.0': dependencies: @@ -10783,7 +10719,7 @@ snapshots: '@changesets/get-dependents-graph': 2.0.0 '@changesets/types': 6.0.0 '@manypkg/get-packages': 1.1.3 - semver: 7.5.4 + semver: 7.6.3 '@changesets/changelog-git@0.2.0': dependencies: @@ -10852,7 +10788,7 @@ snapshots: '@manypkg/get-packages': 1.1.3 chalk: 2.4.2 fs-extra: 7.0.1 - semver: 7.5.4 + semver: 7.6.3 '@changesets/get-github-info@0.6.0(encoding@0.1.13)': dependencies: @@ -11724,8 +11660,6 @@ snapshots: wrap-ansi: 8.1.0 wrap-ansi-cjs: wrap-ansi@7.0.0 - '@istanbuljs/schema@0.1.3': {} - '@jridgewell/gen-mapping@0.1.1': dependencies: '@jridgewell/set-array': 1.2.1 @@ -11812,7 +11746,7 @@ snapshots: nopt: 5.0.0 npmlog: 5.0.1 rimraf: 3.0.2 - semver: 7.5.4 + semver: 7.6.3 tar: 6.1.13 transitivePeerDependencies: - encoding @@ -12441,7 +12375,7 @@ snapshots: js-yaml: 4.1.0 ora: 4.1.1 rimraf: 3.0.2 - semver: 7.5.4 + semver: 7.6.3 update-check: 1.5.4 '@types/argparse@1.0.38': {} @@ -12539,8 +12473,6 @@ snapshots: dependencies: ci-info: 3.9.0 - '@types/istanbul-lib-coverage@2.0.6': {} - '@types/javascript-time-ago@2.0.3': {} '@types/json-schema@7.0.13': {} @@ -12959,18 +12891,6 @@ snapshots: path-browserify: 1.0.1 vscode-uri: 3.0.8 - '@vscode/test-cli@0.0.9': - dependencies: - '@types/mocha': 10.0.10 - c8: 9.1.0 - chokidar: 3.6.0 - enhanced-resolve: 5.17.1 - glob: 10.3.10 - minimatch: 9.0.5 - mocha: 10.8.2 - supports-color: 9.4.0 - yargs: 17.7.2 - '@vscode/test-electron@2.4.1': dependencies: http-proxy-agent: 7.0.2 @@ -13517,7 +13437,7 @@ snapshots: builtins@5.0.1: dependencies: - semver: 7.5.4 + semver: 7.6.3 bundle-name@3.0.0: dependencies: @@ -13529,20 +13449,6 @@ snapshots: bytes@3.1.2: {} - c8@9.1.0: - dependencies: - '@bcoe/v8-coverage': 0.2.3 - '@istanbuljs/schema': 0.1.3 - find-up: 5.0.0 - foreground-child: 3.1.1 - istanbul-lib-coverage: 3.2.2 - istanbul-lib-report: 3.0.1 - istanbul-reports: 3.1.7 - test-exclude: 6.0.0 - v8-to-istanbul: 9.3.0 - yargs: 17.7.2 - yargs-parser: 21.1.1 - cac@6.7.14: {} cacheable-lookup@7.0.0: {} @@ -14352,11 +14258,6 @@ snapshots: dependencies: once: 1.4.0 - enhanced-resolve@5.17.1: - dependencies: - graceful-fs: 4.2.10 - tapable: 2.2.1 - enquirer@2.3.6: dependencies: ansi-colors: 4.1.3 @@ -15334,14 +15235,6 @@ snapshots: once: 1.4.0 path-is-absolute: 1.0.1 - glob@8.0.3: - dependencies: - fs.realpath: 1.0.0 - inflight: 1.0.6 - inherits: 2.0.4 - minimatch: 5.1.1 - once: 1.4.0 - glob@8.1.0: dependencies: fs.realpath: 1.0.0 @@ -15530,8 +15423,6 @@ snapshots: dependencies: lru-cache: 6.0.0 - html-escaper@2.0.2: {} - html-rewriter-wasm@0.4.1: {} htmlparser2@9.1.0: @@ -15551,16 +15442,9 @@ snapshots: statuses: 2.0.1 toidentifier: 1.0.1 - http-proxy-agent@7.0.0: - dependencies: - agent-base: 7.1.0(supports-color@9.2.2) - debug: 4.3.7(supports-color@9.2.2) - transitivePeerDependencies: - - supports-color - http-proxy-agent@7.0.2: dependencies: - agent-base: 7.1.0(supports-color@9.2.2) + agent-base: 7.1.3 debug: 4.3.7(supports-color@9.2.2) transitivePeerDependencies: - supports-color @@ -15939,19 +15823,6 @@ snapshots: isobject@3.0.1: {} - istanbul-lib-coverage@3.2.2: {} - - istanbul-lib-report@3.0.1: - dependencies: - istanbul-lib-coverage: 3.2.2 - make-dir: 4.0.0 - supports-color: 7.2.0 - - istanbul-reports@3.1.7: - dependencies: - html-escaper: 2.0.2 - istanbul-lib-report: 3.0.1 - iterator.prototype@1.1.2: dependencies: define-properties: 1.2.1 @@ -16262,10 +16133,6 @@ snapshots: dependencies: semver: 6.3.1 - make-dir@4.0.0: - dependencies: - semver: 7.5.4 - make-error@1.3.6: {} map-obj@1.0.1: {} @@ -16585,7 +16452,7 @@ snapshots: node-abi@3.62.0: dependencies: - semver: 7.5.4 + semver: 7.6.3 node-addon-api@4.3.0: {} @@ -16675,7 +16542,7 @@ snapshots: dependencies: execa: 6.1.0 parse-package-name: 1.0.0 - semver: 7.5.4 + semver: 7.6.3 validate-npm-package-name: 4.0.0 nth-check@2.1.1: @@ -16889,7 +16756,7 @@ snapshots: agent-base: 7.1.0(supports-color@9.2.2) debug: 4.3.7(supports-color@9.2.2) get-uri: 6.0.1 - http-proxy-agent: 7.0.0 + http-proxy-agent: 7.0.2 https-proxy-agent: 7.0.2(supports-color@9.2.2) pac-resolver: 7.0.0 socks-proxy-agent: 8.0.2 @@ -16914,7 +16781,7 @@ snapshots: got: 12.6.1 registry-auth-token: 5.0.2 registry-url: 6.0.1 - semver: 7.5.4 + semver: 7.6.3 packet-reader@1.0.0: {} @@ -17410,7 +17277,7 @@ snapshots: dependencies: agent-base: 7.1.0(supports-color@9.2.2) debug: 4.3.7(supports-color@9.2.2) - http-proxy-agent: 7.0.0 + http-proxy-agent: 7.0.2 https-proxy-agent: 7.0.2(supports-color@9.2.2) lru-cache: 7.18.3 pac-proxy-agent: 7.0.1 @@ -17594,7 +17461,7 @@ snapshots: readdir-glob@1.1.3: dependencies: - minimatch: 5.1.1 + minimatch: 5.1.6 readdirp@3.6.0: dependencies: @@ -18300,8 +18167,6 @@ snapshots: supports-color@9.2.2: {} - supports-color@9.4.0: {} - supports-preserve-symlinks-flag@1.0.0: {} svgo@3.3.2: @@ -18330,8 +18195,6 @@ snapshots: '@pkgr/utils': 2.4.1 tslib: 2.5.3 - tapable@2.2.1: {} - tar-fs@2.1.1: dependencies: chownr: 1.1.4 @@ -18360,12 +18223,6 @@ snapshots: term-size@2.2.1: {} - test-exclude@6.0.0: - dependencies: - '@istanbuljs/schema': 0.1.3 - glob: 7.2.3 - minimatch: 3.1.2 - text-table@0.2.0: {} through@2.3.8: {} @@ -18455,7 +18312,7 @@ snapshots: dependencies: '@types/json-schema': 7.0.13 commander: 11.1.0 - glob: 8.0.3 + glob: 8.1.0 json5: 2.2.3 normalize-path: 3.0.0 safe-stable-stringify: 2.4.3 @@ -18852,12 +18709,6 @@ snapshots: v8-compile-cache-lib@3.0.1: {} - v8-to-istanbul@9.3.0: - dependencies: - '@jridgewell/trace-mapping': 0.3.25 - '@types/istanbul-lib-coverage': 2.0.6 - convert-source-map: 2.0.0 - validate-npm-package-license@3.0.4: dependencies: spdx-correct: 3.1.1 @@ -19004,7 +18855,7 @@ snapshots: dependencies: '@volar/typescript': 2.4.0-alpha.18 '@vue/language-core': 2.0.29(typescript@5.6.3) - semver: 7.5.4 + semver: 7.6.3 typescript: 5.6.3 w3c-hr-time@1.0.2: From 8757579a47d675909230a51f8e09d1611d5cadb1 Mon Sep 17 00:00:00 2001 From: Carmen Popoviciu Date: Thu, 19 Dec 2024 13:07:54 +0100 Subject: [PATCH 10/53] feat(wrangler): DX improvements for `wrangler dev --remote` (#7425) Workers + Assets projects have, in certain situations, a relatively degraded `wrangler dev --remote` developer experience, as opposed to Workers proper projects. This is due to the fact that, for Workers + Assets, we need to make extra API calls to: 1. check for asset files changes 2. upload the changed assets, if any This commit improves the `wrangler dev --remote` DX for Workers + Assets, for use cases when the User Worker/assets change while the API calls for previous changes are still in flight. For such use cases, we have put an exit early strategy in place, that drops the event handler execution of the previous changes, in favour of the handler triggered by the new changes. --- .changeset/quick-wombats-battle.md | 12 +++++++ .../startDevWorker/RemoteRuntimeController.ts | 36 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .changeset/quick-wombats-battle.md diff --git a/.changeset/quick-wombats-battle.md b/.changeset/quick-wombats-battle.md new file mode 100644 index 000000000000..100d6a157676 --- /dev/null +++ b/.changeset/quick-wombats-battle.md @@ -0,0 +1,12 @@ +--- +"wrangler": minor +--- + +feat: Make DX improvements in `wrangler dev --remote` + +Workers + Assets projects have, in certain situations, a relatively degraded `wrangler dev --remote` developer experience, as opposed to Workers proper projects. This is due to the fact that, for Workers + Assets, we need to make extra API calls to: + +1. check for asset files changes +2. upload the changed assets, if any + +This commit improves the `wrangler dev --remote` DX for Workers + Assets, for use cases when the User Worker/assets change while the API calls for previous changes are still in flight. For such use cases, we have put an exit early strategy in place, that drops the event handler execution of the previous changes, in favour of the handler triggered by the new changes. diff --git a/packages/wrangler/src/api/startDevWorker/RemoteRuntimeController.ts b/packages/wrangler/src/api/startDevWorker/RemoteRuntimeController.ts index 0b77371402a2..fdff4625e3eb 100644 --- a/packages/wrangler/src/api/startDevWorker/RemoteRuntimeController.ts +++ b/packages/wrangler/src/api/startDevWorker/RemoteRuntimeController.ts @@ -64,13 +64,29 @@ export class RemoteRuntimeController extends RuntimeController { async #previewToken( props: Omit & Partial> & - Parameters[0] + Parameters[0] & { bundleId: number } ): Promise { if (!this.#session) { return; } try { + /* + * Since `getWorkerAccountAndContext`, `createRemoteWorkerInit` and + * `createWorkerPreview` are all async functions, it is technically + * possible that new `bundleComplete` events are trigerred while those + * functions are still executing. In such cases we want to drop the + * current bundle and exit early, to avoid unnecessarily executing any + * further expensive API calls. + * + * For this purpose, we want perform a check before each of these + * functions, to ensure no new `bundleComplete` was triggered. + */ + // If we received a new `bundleComplete` event before we were able to + // dispatch a `reloadComplete` for this bundle, ignore this bundle. + if (props.bundleId !== this.#currentBundleId) { + return; + } const { workerAccount, workerContext } = await getWorkerAccountAndContext( { accountId: props.accountId, @@ -89,6 +105,11 @@ export class RemoteRuntimeController extends RuntimeController { ? this.#session.id : this.#session.host.split(".")[0]); + // If we received a new `bundleComplete` event before we were able to + // dispatch a `reloadComplete` for this bundle, ignore this bundle. + if (props.bundleId !== this.#currentBundleId) { + return; + } const init = await createRemoteWorkerInit({ bundle: props.bundle, modules: props.modules, @@ -105,6 +126,11 @@ export class RemoteRuntimeController extends RuntimeController { compatibilityFlags: props.compatibilityFlags, }); + // If we received a new `bundleComplete` event before we were able to + // dispatch a `reloadComplete` for this bundle, ignore this bundle. + if (props.bundleId !== this.#currentBundleId) { + return; + } const workerPreviewToken = await createWorkerPreview( init, workerAccount, @@ -175,6 +201,13 @@ export class RemoteRuntimeController extends RuntimeController { const { bindings } = await convertBindingsToCfWorkerInitBindings( config.bindings ); + + // If we received a new `bundleComplete` event before we were able to + // dispatch a `reloadComplete` for this bundle, ignore this bundle. + if (id !== this.#currentBundleId) { + return; + } + const token = await this.#previewToken({ bundle, modules: bundle.modules, @@ -201,6 +234,7 @@ export class RemoteRuntimeController extends RuntimeController { host: config.dev.origin?.hostname, sendMetrics: config.sendMetrics, configPath: config.config, + bundleId: id, }); // If we received a new `bundleComplete` event before we were able to From 1488e118b4a43d032e4f2e69afa1c16c2e54aff6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:22:04 +0000 Subject: [PATCH 11/53] chore(deps): bump the workerd-and-workers-types group across 1 directory with 2 updates (#7589) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): bump the workerd-and-workers-types group across 1 directory with 2 updates Bumps the workerd-and-workers-types group with 2 updates in the / directory: [@cloudflare/workers-types](https://github.com/cloudflare/workerd) and [workerd](https://github.com/cloudflare/workerd). Updates `@cloudflare/workers-types` from 4.20241205.0 to 4.20241218.0 - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/RELEASE.md) - [Commits](https://github.com/cloudflare/workerd/commits) Updates `workerd` from 1.20241205.0 to 1.20241218.0 - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/RELEASE.md) - [Commits](https://github.com/cloudflare/workerd/compare/v1.20241205.0...v1.20241218.0) --- updated-dependencies: - dependency-name: "@cloudflare/workers-types" dependency-type: direct:production update-type: version-update:semver-minor dependency-group: workerd-and-workers-types - dependency-name: workerd dependency-type: direct:production update-type: version-update:semver-minor dependency-group: workerd-and-workers-types ... Signed-off-by: dependabot[bot] * chore: update dependencies of "miniflare" package The following dependency versions have been updated: | Dependency | From | To | | ------------------------- | ------------- | ------------- | | workerd | 1.20241205.0 | 1.20241218.0 | | @cloudflare/workers-types | ^4.20241205.0 | ^4.20241218.0 | * Add tailStream reserved key * Pass through instanceId * remove unused WorkflowEvent --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater Co-authored-by: Samuel Macleod Co-authored-by: Luís Duarte --- .changeset/dependabot-update-7589.md | 12 + fixtures/additional-modules/package.json | 2 +- fixtures/asset-config/package.json | 2 +- fixtures/get-platform-proxy/package.json | 2 +- fixtures/local-mode-tests/package.json | 2 +- fixtures/node-app-pages/package.json | 2 +- fixtures/nodejs-als-app/package.json | 2 +- fixtures/nodejs-hybrid-app/package.json | 2 +- .../pages-dev-proxy-with-script/package.json | 2 +- fixtures/pages-functions-app/package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- fixtures/pages-simple-assets/package.json | 2 +- .../vitest-pool-workers-examples/package.json | 2 +- fixtures/worker-ts/package.json | 2 +- .../workers-with-assets-only/package.json | 2 +- .../package.json | 2 +- fixtures/workers-with-assets/package.json | 2 +- fixtures/workflow-multiple/package.json | 2 +- fixtures/workflow/package.json | 2 +- package.json | 2 +- packages/create-cloudflare/package.json | 2 +- .../package.json | 2 +- packages/format-errors/package.json | 2 +- packages/kv-asset-handler/package.json | 2 +- packages/miniflare/package.json | 4 +- packages/pages-shared/package.json | 2 +- .../playground-preview-worker/package.json | 2 +- packages/prerelease-registry/package.json | 2 +- packages/quick-edit-extension/package.json | 2 +- packages/vitest-pool-workers/package.json | 2 +- packages/workers-shared/package.json | 2 +- packages/workers.new/package.json | 2 +- packages/workflows-shared/package.json | 2 +- packages/workflows-shared/src/binding.ts | 1 + packages/wrangler/package.json | 6 +- packages/wrangler/src/dev/miniflare.ts | 11 +- pnpm-lock.yaml | 224 +++++++++++------- 38 files changed, 197 insertions(+), 125 deletions(-) create mode 100644 .changeset/dependabot-update-7589.md diff --git a/.changeset/dependabot-update-7589.md b/.changeset/dependabot-update-7589.md new file mode 100644 index 000000000000..6ff3425502c2 --- /dev/null +++ b/.changeset/dependabot-update-7589.md @@ -0,0 +1,12 @@ +--- +"miniflare": patch +--- + +chore: update dependencies of "miniflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ------------------------- | ------------- | ------------- | +| workerd | 1.20241205.0 | 1.20241218.0 | +| @cloudflare/workers-types | ^4.20241205.0 | ^4.20241218.0 | diff --git a/fixtures/additional-modules/package.json b/fixtures/additional-modules/package.json index c4d192e635e9..0fdc48a07bcf 100644 --- a/fixtures/additional-modules/package.json +++ b/fixtures/additional-modules/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/asset-config/package.json b/fixtures/asset-config/package.json index c34e5c0f2ae9..735bcb5856ed 100644 --- a/fixtures/asset-config/package.json +++ b/fixtures/asset-config/package.json @@ -12,7 +12,7 @@ "devDependencies": { "@cloudflare/vitest-pool-workers": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "run-script-os": "^1.1.6", "typescript": "catalog:default", "undici": "catalog:default", diff --git a/fixtures/get-platform-proxy/package.json b/fixtures/get-platform-proxy/package.json index 71e5259e2397..a547e6e2c514 100644 --- a/fixtures/get-platform-proxy/package.json +++ b/fixtures/get-platform-proxy/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/local-mode-tests/package.json b/fixtures/local-mode-tests/package.json index ad649f984e92..0fa361e80c85 100644 --- a/fixtures/local-mode-tests/package.json +++ b/fixtures/local-mode-tests/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/node": "catalog:default", "buffer": "^6.0.3", "typescript": "catalog:default", diff --git a/fixtures/node-app-pages/package.json b/fixtures/node-app-pages/package.json index f4a1d7d06a74..d9b1beba44ee 100644 --- a/fixtures/node-app-pages/package.json +++ b/fixtures/node-app-pages/package.json @@ -15,7 +15,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/nodejs-als-app/package.json b/fixtures/nodejs-als-app/package.json index c13302a4cf87..3cbd73bd9beb 100644 --- a/fixtures/nodejs-als-app/package.json +++ b/fixtures/nodejs-als-app/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "undici": "catalog:default", "vitest": "catalog:default", "wrangler": "workspace:*" diff --git a/fixtures/nodejs-hybrid-app/package.json b/fixtures/nodejs-hybrid-app/package.json index dd1d25b32401..12de46cbb6fa 100644 --- a/fixtures/nodejs-hybrid-app/package.json +++ b/fixtures/nodejs-hybrid-app/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/pg": "^8.11.2", "pg": "8.11.3", "pg-cloudflare": "^1.1.1", diff --git a/fixtures/pages-dev-proxy-with-script/package.json b/fixtures/pages-dev-proxy-with-script/package.json index 62158377ea25..378ba9982c9c 100644 --- a/fixtures/pages-dev-proxy-with-script/package.json +++ b/fixtures/pages-dev-proxy-with-script/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/pages-functions-app/package.json b/fixtures/pages-functions-app/package.json index 9863d450c24d..fcf83b9bf7ce 100644 --- a/fixtures/pages-functions-app/package.json +++ b/fixtures/pages-functions-app/package.json @@ -15,7 +15,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "pages-plugin-example": "workspace:*", "typescript": "catalog:default", "undici": "catalog:default", diff --git a/fixtures/pages-functions-with-routes-app/package.json b/fixtures/pages-functions-with-routes-app/package.json index cb4ba9195b8c..0659113ffd32 100644 --- a/fixtures/pages-functions-with-routes-app/package.json +++ b/fixtures/pages-functions-with-routes-app/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/pages-plugin-mounted-on-root-app/package.json b/fixtures/pages-plugin-mounted-on-root-app/package.json index 1adad8589539..1cfa3c2c2660 100644 --- a/fixtures/pages-plugin-mounted-on-root-app/package.json +++ b/fixtures/pages-plugin-mounted-on-root-app/package.json @@ -15,7 +15,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "pages-plugin-example": "workspace:*", "typescript": "catalog:default", "undici": "catalog:default", diff --git a/fixtures/pages-simple-assets/package.json b/fixtures/pages-simple-assets/package.json index ae7fc9d05b26..119bfbf797d2 100644 --- a/fixtures/pages-simple-assets/package.json +++ b/fixtures/pages-simple-assets/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/vitest-pool-workers-examples/package.json b/fixtures/vitest-pool-workers-examples/package.json index d80481ab7f55..e9bdeeeddb91 100644 --- a/fixtures/vitest-pool-workers-examples/package.json +++ b/fixtures/vitest-pool-workers-examples/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@cloudflare/vitest-pool-workers": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/node": "catalog:default", "ext-dep": "file:./internal-module-resolution/vendor/ext-dep", "jose": "^5.2.2", diff --git a/fixtures/worker-ts/package.json b/fixtures/worker-ts/package.json index f0ff0c8f8cdd..591c0bdbaa56 100644 --- a/fixtures/worker-ts/package.json +++ b/fixtures/worker-ts/package.json @@ -6,7 +6,7 @@ "start": "wrangler dev" }, "devDependencies": { - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/workers-with-assets-only/package.json b/fixtures/workers-with-assets-only/package.json index d5770856abe9..934984b91196 100644 --- a/fixtures/workers-with-assets-only/package.json +++ b/fixtures/workers-with-assets-only/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/workers-with-assets-serve-directly/package.json b/fixtures/workers-with-assets-serve-directly/package.json index bb326102e7e5..52e597e8e5a0 100644 --- a/fixtures/workers-with-assets-serve-directly/package.json +++ b/fixtures/workers-with-assets-serve-directly/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/workers-with-assets/package.json b/fixtures/workers-with-assets/package.json index 5a0610fe354e..bdb550788e88 100644 --- a/fixtures/workers-with-assets/package.json +++ b/fixtures/workers-with-assets/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/workflow-multiple/package.json b/fixtures/workflow-multiple/package.json index ea68094744ce..b9355a2413d9 100644 --- a/fixtures/workflow-multiple/package.json +++ b/fixtures/workflow-multiple/package.json @@ -7,7 +7,7 @@ "test:ci": "vitest run" }, "devDependencies": { - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/workflow/package.json b/fixtures/workflow/package.json index eb7bc10f1967..0f8d252922e2 100644 --- a/fixtures/workflow/package.json +++ b/fixtures/workflow/package.json @@ -7,7 +7,7 @@ "test:ci": "vitest run" }, "devDependencies": { - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/package.json b/package.json index 7c2d00001c20..2b01bf28ba73 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.1", "@changesets/parse": "^0.4.0", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@ianvs/prettier-plugin-sort-imports": "4.2.1", "@manypkg/cli": "^0.21.4", "@turbo/gen": "^1.10.13", diff --git a/packages/create-cloudflare/package.json b/packages/create-cloudflare/package.json index 1a29eefa5e70..31fb01707350 100644 --- a/packages/create-cloudflare/package.json +++ b/packages/create-cloudflare/package.json @@ -49,7 +49,7 @@ "@cloudflare/cli": "workspace:*", "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@iarna/toml": "^3.0.0", "@types/command-exists": "^1.2.0", "@types/cross-spawn": "^6.0.2", diff --git a/packages/edge-preview-authenticated-proxy/package.json b/packages/edge-preview-authenticated-proxy/package.json index c4c222fe471b..ce0940d97bea 100644 --- a/packages/edge-preview-authenticated-proxy/package.json +++ b/packages/edge-preview-authenticated-proxy/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/cookie": "^0.6.0", "cookie": "^0.6.0", "promjs": "^0.4.2", diff --git a/packages/format-errors/package.json b/packages/format-errors/package.json index 64b89b1b9543..0838789dcda6 100644 --- a/packages/format-errors/package.json +++ b/packages/format-errors/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "mustache": "^4.2.0", "promjs": "^0.4.2", "toucan-js": "^3.3.1", diff --git a/packages/kv-asset-handler/package.json b/packages/kv-asset-handler/package.json index 5ae71d2f887c..b0e277877ccf 100644 --- a/packages/kv-asset-handler/package.json +++ b/packages/kv-asset-handler/package.json @@ -42,7 +42,7 @@ }, "devDependencies": { "@ava/typescript": "^4.1.0", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/mime": "^3.0.4", "@types/node": "catalog:default", "@types/service-worker-mock": "^2.0.1", diff --git a/packages/miniflare/package.json b/packages/miniflare/package.json index ab862ae6bf88..d8824142482d 100644 --- a/packages/miniflare/package.json +++ b/packages/miniflare/package.json @@ -50,7 +50,7 @@ "glob-to-regexp": "^0.4.1", "stoppable": "^1.1.0", "undici": "catalog:default", - "workerd": "1.20241205.0", + "workerd": "1.20241218.0", "ws": "^8.18.0", "youch": "^3.2.2", "zod": "^3.22.3" @@ -59,7 +59,7 @@ "@ava/typescript": "^4.1.0", "@cloudflare/kv-asset-handler": "workspace:*", "@cloudflare/workers-shared": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@cloudflare/workflows-shared": "workspace:*", "@microsoft/api-extractor": "^7.47.0", "@types/debug": "^4.1.7", diff --git a/packages/pages-shared/package.json b/packages/pages-shared/package.json index 6a9b9febe49b..57c9cb982cd4 100644 --- a/packages/pages-shared/package.json +++ b/packages/pages-shared/package.json @@ -23,7 +23,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@miniflare/cache": "^2.14.2", "@miniflare/core": "^2.14.2", "@miniflare/html-rewriter": "^2.14.2", diff --git a/packages/playground-preview-worker/package.json b/packages/playground-preview-worker/package.json index 712b3620a691..44379d2c9fff 100644 --- a/packages/playground-preview-worker/package.json +++ b/packages/playground-preview-worker/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/cookie": "^0.6.0", "cookie": "^0.6.0", "itty-router": "^4.0.13", diff --git a/packages/prerelease-registry/package.json b/packages/prerelease-registry/package.json index 78e75fb5089e..52a137406025 100644 --- a/packages/prerelease-registry/package.json +++ b/packages/prerelease-registry/package.json @@ -18,7 +18,7 @@ "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "wrangler": "workspace:*" }, "volta": { diff --git a/packages/quick-edit-extension/package.json b/packages/quick-edit-extension/package.json index 666af482b1db..4bfa6629d29e 100644 --- a/packages/quick-edit-extension/package.json +++ b/packages/quick-edit-extension/package.json @@ -43,7 +43,7 @@ ], "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:^", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "esbuild": "0.17.19", "esbuild-register": "^3.5.0" }, diff --git a/packages/vitest-pool-workers/package.json b/packages/vitest-pool-workers/package.json index 0f6b120c9440..a1799f180b46 100644 --- a/packages/vitest-pool-workers/package.json +++ b/packages/vitest-pool-workers/package.json @@ -64,7 +64,7 @@ "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/node": "catalog:default", "@types/semver": "^7.5.1", "@vitest/runner": "catalog:default", diff --git a/packages/workers-shared/package.json b/packages/workers-shared/package.json index d40763ac1e67..fd63b25bacf2 100644 --- a/packages/workers-shared/package.json +++ b/packages/workers-shared/package.json @@ -50,7 +50,7 @@ "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/vitest-pool-workers": "^0.5.31", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/mime": "^3.0.4", "concurrently": "^8.2.2", "esbuild": "0.17.19", diff --git a/packages/workers.new/package.json b/packages/workers.new/package.json index e7b161c8ec8d..817a80a229df 100644 --- a/packages/workers.new/package.json +++ b/packages/workers.new/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@cloudflare/vitest-pool-workers": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/node": "catalog:default", "miniflare": "workspace:*", "typescript": "catalog:default", diff --git a/packages/workflows-shared/package.json b/packages/workflows-shared/package.json index 09ef52ca0ad8..fc31d6ce1d2e 100644 --- a/packages/workflows-shared/package.json +++ b/packages/workflows-shared/package.json @@ -41,7 +41,7 @@ "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@types/mime": "^3.0.4", "esbuild": "0.17.19", "rimraf": "^6.0.1", diff --git a/packages/workflows-shared/src/binding.ts b/packages/workflows-shared/src/binding.ts index 785f99c2a91d..0e7a44ab6c7d 100644 --- a/packages/workflows-shared/src/binding.ts +++ b/packages/workflows-shared/src/binding.ts @@ -28,6 +28,7 @@ export class WorkflowBinding extends WorkerEntrypoint implements Workflow { { timestamp: new Date(), payload: params as Readonly, + instanceId: id, } ); diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index d1f0d9944334..056ebb8b70f6 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -84,7 +84,7 @@ "selfsigned": "^2.0.1", "source-map": "^0.6.1", "unenv": "npm:unenv-nightly@2.0.0-20241204-140205-a5d5190", - "workerd": "1.20241205.0", + "workerd": "1.20241218.0", "xxhash-wasm": "^1.0.1" }, "devDependencies": { @@ -94,7 +94,7 @@ "@cloudflare/types": "6.18.4", "@cloudflare/workers-shared": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241205.0", + "@cloudflare/workers-types": "^4.20241218.0", "@cspotcode/source-map-support": "0.8.1", "@iarna/toml": "^3.0.0", "@microsoft/api-extractor": "^7.47.0", @@ -163,7 +163,7 @@ "yargs": "^17.7.2" }, "peerDependencies": { - "@cloudflare/workers-types": "^4.20241205.0" + "@cloudflare/workers-types": "^4.20241218.0" }, "peerDependenciesMeta": { "@cloudflare/workers-types": { diff --git a/packages/wrangler/src/dev/miniflare.ts b/packages/wrangler/src/dev/miniflare.ts index 5ffcc23906db..d5c16274f57b 100644 --- a/packages/wrangler/src/dev/miniflare.ts +++ b/packages/wrangler/src/dev/miniflare.ts @@ -59,15 +59,16 @@ const HEADER_ID = "X-Miniflare-Durable-Object-Id"; const HEADER_CF_BLOB = "X-Miniflare-Durable-Object-Cf-Blob"; const HANDLER_RESERVED_KEYS = new Set([ - "tail", - "trace", - "scheduled", "alarm", + "scheduled", + "self", + "tail", + "tailStream", "test", - "webSocketMessage", + "trace", "webSocketClose", "webSocketError", - "self", + "webSocketMessage", ]); function createProxyPrototypeClass(handlerSuperKlass, getUnknownPrototypeKey) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8691388cebb6..e7401f08a847 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,8 +65,8 @@ importers: specifier: ^0.4.0 version: 0.4.0 '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@ianvs/prettier-plugin-sort-imports': specifier: 4.2.1 version: 4.2.1(@vue/compiler-sfc@3.3.4)(prettier@3.2.5) @@ -128,8 +128,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -170,8 +170,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 run-script-os: specifier: ^1.1.6 version: 1.1.6 @@ -233,8 +233,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -303,8 +303,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/node': specifier: ^18.19.59 version: 18.19.59 @@ -343,8 +343,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -364,8 +364,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 undici: specifier: catalog:default version: 5.28.4 @@ -382,8 +382,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/pg': specifier: ^8.11.2 version: 8.11.6 @@ -427,8 +427,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -452,8 +452,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 pages-plugin-example: specifier: workspace:* version: link:../pages-plugin-example @@ -512,8 +512,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -564,8 +564,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 pages-plugin-example: specifier: workspace:* version: link:../pages-plugin-example @@ -609,8 +609,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -808,8 +808,8 @@ importers: specifier: workspace:* version: link:../../packages/vitest-pool-workers '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/node': specifier: ^18.19.59 version: 18.19.59 @@ -868,8 +868,8 @@ importers: fixtures/worker-ts: devDependencies: '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -882,8 +882,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -903,8 +903,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -924,8 +924,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -942,8 +942,8 @@ importers: fixtures/workflow: devDependencies: '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -960,8 +960,8 @@ importers: fixtures/workflow-multiple: devDependencies: '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 typescript: specifier: catalog:default version: 5.6.3 @@ -1086,8 +1086,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@iarna/toml': specifier: ^3.0.0 version: 3.0.0 @@ -1215,8 +1215,8 @@ importers: specifier: workspace:* version: link:../eslint-config-worker '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/cookie': specifier: ^0.6.0 version: 0.6.0 @@ -1270,8 +1270,8 @@ importers: specifier: workspace:* version: link:../eslint-config-worker '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 mustache: specifier: ^4.2.0 version: 4.2.0 @@ -1301,8 +1301,8 @@ importers: specifier: ^4.1.0 version: 4.1.0 '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/mime': specifier: ^3.0.4 version: 3.0.4 @@ -1346,8 +1346,8 @@ importers: specifier: catalog:default version: 5.28.4 workerd: - specifier: 1.20241205.0 - version: 1.20241205.0 + specifier: 1.20241218.0 + version: 1.20241218.0 ws: specifier: ^8.18.0 version: 8.18.0 @@ -1368,8 +1368,8 @@ importers: specifier: workspace:* version: link:../workers-shared '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@cloudflare/workflows-shared': specifier: workspace:* version: link:../workflows-shared @@ -1483,8 +1483,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@miniflare/cache': specifier: ^2.14.2 version: 2.14.2 @@ -1517,8 +1517,8 @@ importers: specifier: workspace:* version: link:../eslint-config-worker '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/cookie': specifier: ^0.6.0 version: 0.6.0 @@ -1554,8 +1554,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 wrangler: specifier: workspace:* version: link:../wrangler @@ -1585,8 +1585,8 @@ importers: specifier: workspace:^ version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 esbuild: specifier: 0.17.19 version: 0.17.19 @@ -1635,7 +1635,7 @@ importers: version: 2.0.0(typescript@5.6.3)(vue-tsc@2.0.29(typescript@5.6.3)) wrangler: specifier: 3.95.0 - version: 3.95.0(@cloudflare/workers-types@4.20241205.0) + version: 3.95.0(@cloudflare/workers-types@4.20241218.0) packages/vitest-pool-workers: dependencies: @@ -1671,8 +1671,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/node': specifier: ^18.19.59 version: 18.19.59 @@ -1882,13 +1882,13 @@ importers: version: link:../eslint-config-worker '@cloudflare/vitest-pool-workers': specifier: ^0.5.31 - version: 0.5.31(@cloudflare/workers-types@4.20241205.0)(@vitest/runner@2.1.8)(@vitest/snapshot@2.1.8)(vitest@2.1.8) + version: 0.5.31(@cloudflare/workers-types@4.20241218.0)(@vitest/runner@2.1.8)(@vitest/snapshot@2.1.8)(vitest@2.1.8) '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/mime': specifier: ^3.0.4 version: 3.0.4 @@ -1919,8 +1919,8 @@ importers: specifier: workspace:* version: link:../vitest-pool-workers '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/node': specifier: ^18.19.59 version: 18.19.59 @@ -1959,8 +1959,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@types/mime': specifier: ^3.0.4 version: 3.0.4 @@ -2025,8 +2025,8 @@ importers: specifier: npm:unenv-nightly@2.0.0-20241204-140205-a5d5190 version: unenv-nightly@2.0.0-20241204-140205-a5d5190 workerd: - specifier: 1.20241205.0 - version: 1.20241205.0 + specifier: 1.20241218.0 + version: 1.20241218.0 xxhash-wasm: specifier: ^1.0.1 version: 1.0.1 @@ -2054,8 +2054,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241205.0 - version: 4.20241205.0 + specifier: ^4.20241218.0 + version: 4.20241218.0 '@cspotcode/source-map-support': specifier: 0.8.1 version: 0.8.1 @@ -2821,6 +2821,12 @@ packages: cpu: [x64] os: [darwin] + '@cloudflare/workerd-darwin-64@1.20241218.0': + resolution: {integrity: sha512-8rveQoxtUvlmORKqTWgjv2ycM8uqWox0u9evn3zd2iWKdou5sncFwH517ZRLI3rq9P31ZLmCQBZ0gloFsTeY6w==} + engines: {node: '>=16'} + cpu: [x64] + os: [darwin] + '@cloudflare/workerd-darwin-arm64@1.20241106.1': resolution: {integrity: sha512-j3dg/42D/bPgfNP3cRUBxF+4waCKO/5YKwXNj+lnVOwHxDu+ne5pFw9TIkKYcWTcwn0ZUkbNZNM5rhJqRn4xbg==} engines: {node: '>=16'} @@ -2839,6 +2845,12 @@ packages: cpu: [arm64] os: [darwin] + '@cloudflare/workerd-darwin-arm64@1.20241218.0': + resolution: {integrity: sha512-be59Ad9nmM9lCkhHqmTs/uZ3JVZt8NJ9Z0PY+B0xnc5z6WwmV2lj0RVLtq7xJhQsQJA189zt5rXqDP6J+2mu7Q==} + engines: {node: '>=16'} + cpu: [arm64] + os: [darwin] + '@cloudflare/workerd-linux-64@1.20241106.1': resolution: {integrity: sha512-Ih+Ye8E1DMBXcKrJktGfGztFqHKaX1CeByqshmTbODnWKHt6O65ax3oTecUwyC0+abuyraOpAtdhHNpFMhUkmw==} engines: {node: '>=16'} @@ -2857,6 +2869,12 @@ packages: cpu: [x64] os: [linux] + '@cloudflare/workerd-linux-64@1.20241218.0': + resolution: {integrity: sha512-MzpSBcfZXRxrYWxQ4pVDYDrUbkQuM62ssl4ZtHH8J35OAeGsWFAYji6MkS2SpVwVcvacPwJXIF4JSzp4xKImKw==} + engines: {node: '>=16'} + cpu: [x64] + os: [linux] + '@cloudflare/workerd-linux-arm64@1.20241106.1': resolution: {integrity: sha512-mdQFPk4+14Yywn7n1xIzI+6olWM8Ybz10R7H3h+rk0XulMumCWUCy1CzIDauOx6GyIcSgKIibYMssVHZR30ObA==} engines: {node: '>=16'} @@ -2875,6 +2893,12 @@ packages: cpu: [arm64] os: [linux] + '@cloudflare/workerd-linux-arm64@1.20241218.0': + resolution: {integrity: sha512-RIuJjPxpNqvwIs52vQsXeRMttvhIjgg9NLjjFa3jK8Ijnj8c3ZDru9Wqi48lJP07yDFIRr4uDMMqh/y29YQi2A==} + engines: {node: '>=16'} + cpu: [arm64] + os: [linux] + '@cloudflare/workerd-windows-64@1.20241106.1': resolution: {integrity: sha512-4rtcss31E/Rb/PeFocZfr+B9i1MdrkhsTBWizh8siNR4KMmkslU2xs2wPaH1z8+ErxkOsHrKRa5EPLh5rIiFeg==} engines: {node: '>=16'} @@ -2893,6 +2917,12 @@ packages: cpu: [x64] os: [win32] + '@cloudflare/workerd-windows-64@1.20241218.0': + resolution: {integrity: sha512-tO1VjlvK3F6Yb2d1jgEy/QBYl//9Pyv3K0j+lq8Eu7qdfm0IgKwSRgDWLept84/qmNsQfausZ4JdNGxTf9xsxQ==} + engines: {node: '>=16'} + cpu: [x64] + os: [win32] + '@cloudflare/workers-shared@0.11.0': resolution: {integrity: sha512-A+lQ8xp7992qSeMmuQ0ssL6CPmm+ZmAv6Ddikan0n1jjpMAic+97l7xtVIsswSn9iLMFPYQ9uNN/8Fl0AgARIQ==} engines: {node: '>=16.7.0'} @@ -2901,8 +2931,8 @@ packages: resolution: {integrity: sha512-1OvFkNtslaMZAJsaocTmbACApgmWv55uLpNj50Pn2MGcxdAjpqykXJFQw5tKc+lGV9TDZh9oO3Rsk17IEQDzIg==} engines: {node: '>=16.7.0'} - '@cloudflare/workers-types@4.20241205.0': - resolution: {integrity: sha512-pj1VKRHT/ScQbHOIMFODZaNAlJHQHdBSZXNIdr9ebJzwBff9Qz8VdqhbhggV7f+aUEh8WSbrsPIo4a+WtgjUvw==} + '@cloudflare/workers-types@4.20241218.0': + resolution: {integrity: sha512-Y0brjmJHcAZBXOPI7lU5hbiXglQWniA1kQjot2ata+HFimyjPPcz+4QWBRrmWcMPo0OadR2Vmac7WStDLpvz0w==} '@colors/colors@1.5.0': resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==} @@ -10072,6 +10102,11 @@ packages: engines: {node: '>=16'} hasBin: true + workerd@1.20241218.0: + resolution: {integrity: sha512-7Z3D4vOVChMz9mWDffE299oQxUWm/pbkeAWx1btVamPcAK/2IuoNBhwflWo3jyuKuxvYuFAdIucgYxc8ICqXiA==} + engines: {node: '>=16'} + hasBin: true + workerpool@6.5.1: resolution: {integrity: sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==} @@ -11111,7 +11146,7 @@ snapshots: lodash.memoize: 4.1.2 marked: 0.3.19 - '@cloudflare/vitest-pool-workers@0.5.31(@cloudflare/workers-types@4.20241205.0)(@vitest/runner@2.1.8)(@vitest/snapshot@2.1.8)(vitest@2.1.8)': + '@cloudflare/vitest-pool-workers@0.5.31(@cloudflare/workers-types@4.20241218.0)(@vitest/runner@2.1.8)(@vitest/snapshot@2.1.8)(vitest@2.1.8)': dependencies: '@vitest/runner': 2.1.8 '@vitest/snapshot': 2.1.8 @@ -11122,7 +11157,7 @@ snapshots: miniflare: 3.20241106.1 semver: 7.5.4 vitest: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) - wrangler: 3.90.0(@cloudflare/workers-types@4.20241205.0) + wrangler: 3.90.0(@cloudflare/workers-types@4.20241218.0) zod: 3.22.3 transitivePeerDependencies: - '@cloudflare/workers-types' @@ -11139,6 +11174,9 @@ snapshots: '@cloudflare/workerd-darwin-64@1.20241216.0': optional: true + '@cloudflare/workerd-darwin-64@1.20241218.0': + optional: true + '@cloudflare/workerd-darwin-arm64@1.20241106.1': optional: true @@ -11148,6 +11186,9 @@ snapshots: '@cloudflare/workerd-darwin-arm64@1.20241216.0': optional: true + '@cloudflare/workerd-darwin-arm64@1.20241218.0': + optional: true + '@cloudflare/workerd-linux-64@1.20241106.1': optional: true @@ -11157,6 +11198,9 @@ snapshots: '@cloudflare/workerd-linux-64@1.20241216.0': optional: true + '@cloudflare/workerd-linux-64@1.20241218.0': + optional: true + '@cloudflare/workerd-linux-arm64@1.20241106.1': optional: true @@ -11166,6 +11210,9 @@ snapshots: '@cloudflare/workerd-linux-arm64@1.20241216.0': optional: true + '@cloudflare/workerd-linux-arm64@1.20241218.0': + optional: true + '@cloudflare/workerd-windows-64@1.20241106.1': optional: true @@ -11175,6 +11222,9 @@ snapshots: '@cloudflare/workerd-windows-64@1.20241216.0': optional: true + '@cloudflare/workerd-windows-64@1.20241218.0': + optional: true + '@cloudflare/workers-shared@0.11.0': dependencies: mime: 3.0.0 @@ -11185,7 +11235,7 @@ snapshots: mime: 3.0.0 zod: 3.22.3 - '@cloudflare/workers-types@4.20241205.0': {} + '@cloudflare/workers-types@4.20241218.0': {} '@colors/colors@1.5.0': optional: true @@ -19008,9 +19058,17 @@ snapshots: '@cloudflare/workerd-linux-arm64': 1.20241216.0 '@cloudflare/workerd-windows-64': 1.20241216.0 + workerd@1.20241218.0: + optionalDependencies: + '@cloudflare/workerd-darwin-64': 1.20241218.0 + '@cloudflare/workerd-darwin-arm64': 1.20241218.0 + '@cloudflare/workerd-linux-64': 1.20241218.0 + '@cloudflare/workerd-linux-arm64': 1.20241218.0 + '@cloudflare/workerd-windows-64': 1.20241218.0 + workerpool@6.5.1: {} - wrangler@3.90.0(@cloudflare/workers-types@4.20241205.0): + wrangler@3.90.0(@cloudflare/workers-types@4.20241218.0): dependencies: '@cloudflare/kv-asset-handler': 0.3.4 '@cloudflare/workers-shared': 0.8.0 @@ -19032,14 +19090,14 @@ snapshots: workerd: 1.20241106.1 xxhash-wasm: 1.0.1 optionalDependencies: - '@cloudflare/workers-types': 4.20241205.0 + '@cloudflare/workers-types': 4.20241218.0 fsevents: 2.3.3 transitivePeerDependencies: - bufferutil - supports-color - utf-8-validate - wrangler@3.95.0(@cloudflare/workers-types@4.20241205.0): + wrangler@3.95.0(@cloudflare/workers-types@4.20241218.0): dependencies: '@cloudflare/kv-asset-handler': 0.3.4 '@cloudflare/workers-shared': 0.11.0 @@ -19060,7 +19118,7 @@ snapshots: workerd: 1.20241205.0 xxhash-wasm: 1.0.1 optionalDependencies: - '@cloudflare/workers-types': 4.20241205.0 + '@cloudflare/workers-types': 4.20241218.0 fsevents: 2.3.3 transitivePeerDependencies: - bufferutil From 004fd33d62ab3a77888ffb5538f92135a15d2d3f Mon Sep 17 00:00:00 2001 From: Greg Brimble Date: Thu, 19 Dec 2024 14:25:01 +0000 Subject: [PATCH 12/53] Check If-None-Match before fulfilling preservation cache (#7546) * Refactor ETag handling * Check if-none-match before fulfilling preservation cache --- .changeset/fuzzy-nails-invent.md | 5 ++ .../__tests__/asset-server/handler.test.ts | 28 +++++++--- packages/pages-shared/asset-server/handler.ts | 51 +++++++++++++++---- 3 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 .changeset/fuzzy-nails-invent.md diff --git a/.changeset/fuzzy-nails-invent.md b/.changeset/fuzzy-nails-invent.md new file mode 100644 index 000000000000..e21d23648c10 --- /dev/null +++ b/.changeset/fuzzy-nails-invent.md @@ -0,0 +1,5 @@ +--- +"@cloudflare/pages-shared": minor +--- + +feat: Return a 304 Not Modified response when matching an asset preservation cache request if appropriate diff --git a/packages/pages-shared/__tests__/asset-server/handler.test.ts b/packages/pages-shared/__tests__/asset-server/handler.test.ts index b1ba50cb35ea..b97c1a8e91f0 100644 --- a/packages/pages-shared/__tests__/asset-server/handler.test.ts +++ b/packages/pages-shared/__tests__/asset-server/handler.test.ts @@ -572,11 +572,25 @@ describe("asset-server handler", () => { '"asset-key-foo.html"' ); - // Delete the asset from the manifest and ensure it's served from preservation cache + // Delete the asset from the manifest and ensure it's served from preservation cache with a 304 when if-none-match is present findAssetEntryForPath = async (_path: string) => { return null; }; const { response: response2 } = await getTestResponse({ + request: new Request("https://example.com/foo", { + headers: { "if-none-match": expectedHeaders.etag }, + }), + metadata, + findAssetEntryForPath, + caches, + fetchAsset: () => + Promise.resolve(Object.assign(new Response("hello world!"))), + }); + expect(response2.status).toBe(304); + expect(await response2.text()).toMatchInlineSnapshot('""'); + + // Ensure the asset is served from preservation cache with a 200 if if-none-match is not present + const { response: response3 } = await getTestResponse({ request: new Request("https://example.com/foo"), metadata, findAssetEntryForPath, @@ -584,10 +598,10 @@ describe("asset-server handler", () => { fetchAsset: () => Promise.resolve(Object.assign(new Response("hello world!"))), }); - expect(response2.status).toBe(200); - expect(await response2.text()).toMatchInlineSnapshot('"hello world!"'); + expect(response3.status).toBe(200); + expect(await response3.text()).toMatchInlineSnapshot('"hello world!"'); // Cached responses have the same headers with a few changes/additions: - expect(Object.fromEntries(response2.headers)).toStrictEqual({ + expect(Object.fromEntries(response3.headers)).toStrictEqual({ ...expectedHeaders, "cache-control": "public, s-maxage=604800", "x-robots-tag": "noindex", @@ -595,15 +609,15 @@ describe("asset-server handler", () => { }); // Serve with a fresh cache and ensure we don't get a response - const { response: response3 } = await getTestResponse({ + const { response: response4 } = await getTestResponse({ request: new Request("https://example.com/foo"), metadata, findAssetEntryForPath, fetchAsset: () => Promise.resolve(Object.assign(new Response("hello world!"))), }); - expect(response3.status).toBe(404); - expect(Object.fromEntries(response3.headers)).toMatchInlineSnapshot(` + expect(response4.status).toBe(404); + expect(Object.fromEntries(response4.headers)).toMatchInlineSnapshot(` { "access-control-allow-origin": "*", "cache-control": "no-store", diff --git a/packages/pages-shared/asset-server/handler.ts b/packages/pages-shared/asset-server/handler.ts index be8b5ae84e32..d1f68e33e7c9 100644 --- a/packages/pages-shared/asset-server/handler.ts +++ b/packages/pages-shared/asset-server/handler.ts @@ -72,6 +72,25 @@ type FindAssetEntryForPath = ( path: string ) => Promise; +function generateETagHeader(assetKey: string) { + // https://support.cloudflare.com/hc/en-us/articles/218505467-Using-ETag-Headers-with-Cloudflare + // We sometimes remove etags unless they are wrapped in quotes + const strongETag = `"${assetKey}"`; + const weakETag = `W/"${assetKey}"`; + return { strongETag, weakETag }; +} + +function checkIfNoneMatch( + request: Request, + strongETag: string, + weakETag: string +) { + const ifNoneMatch = request.headers.get("if-none-match"); + + // We sometimes downgrade strong etags to a weak ones, so we need to check for both + return ifNoneMatch === weakETag || ifNoneMatch === strongETag; +} + type ServeAsset = ( assetEntry: AssetEntry, options?: { preserve: boolean } @@ -80,7 +99,10 @@ type ServeAsset = ( type CacheStatus = "hit" | "miss"; type CacheResult = `${A}-${CacheStatus}`; export type HandlerMetrics = { - preservationCacheResult?: CacheResult<"checked"> | "disabled"; + preservationCacheResult?: + | CacheResult<"checked"> + | "not-modified" + | "disabled"; earlyHintsResult?: CacheResult<"used" | "notused"> | "disabled"; }; @@ -518,22 +540,16 @@ export async function generateHandler< const assetKey = getAssetKey(servingAssetEntry, content); - // https://support.cloudflare.com/hc/en-us/articles/218505467-Using-ETag-Headers-with-Cloudflare - // We sometimes remove etags unless they are wrapped in quotes - const etag = `"${assetKey}"`; - const weakEtag = `W/${etag}`; - - const ifNoneMatch = request.headers.get("if-none-match"); - - // We sometimes downgrade strong etags to a weak ones, so we need to check for both - if (ifNoneMatch === weakEtag || ifNoneMatch === etag) { + const { strongETag, weakETag } = generateETagHeader(assetKey); + const isIfNoneMatch = checkIfNoneMatch(request, strongETag, weakETag); + if (isIfNoneMatch) { return new NotModifiedResponse(); } try { const asset = await fetchAsset(assetKey); const headers: Record = { - etag, + etag: strongETag, "content-type": asset.contentType, }; let encodeBody: BodyEncoding = "automatic"; @@ -654,6 +670,19 @@ export async function generateHandler< return new Response(null, preservedResponse); } if (assetKey) { + const { strongETag, weakETag } = generateETagHeader(assetKey); + const isIfNoneMatch = checkIfNoneMatch( + request, + strongETag, + weakETag + ); + if (isIfNoneMatch) { + if (setMetrics) { + setMetrics({ preservationCacheResult: "not-modified" }); + } + return new NotModifiedResponse(); + } + const asset = await fetchAsset(assetKey); if (asset) { From 2bbcb938b1e14cf21da5dc20ce0c8b9bea0f6aad Mon Sep 17 00:00:00 2001 From: WillTaylorDev Date: Thu, 19 Dec 2024 09:59:50 -0500 Subject: [PATCH 13/53] Add warning for smart placement w/assets (#7568) * Provide validation around experimental_serve_directly usage in dev and deploy * Update based on PR feedback --- .changeset/tidy-kiwis-arrive.md | 5 ++ .../wrangler/src/__tests__/deploy.test.ts | 49 +++++++++++++++++++ packages/wrangler/src/assets.ts | 12 +++++ 3 files changed, 66 insertions(+) create mode 100644 .changeset/tidy-kiwis-arrive.md diff --git a/.changeset/tidy-kiwis-arrive.md b/.changeset/tidy-kiwis-arrive.md new file mode 100644 index 000000000000..2a11e8133230 --- /dev/null +++ b/.changeset/tidy-kiwis-arrive.md @@ -0,0 +1,5 @@ +--- +"wrangler": minor +--- + +Warn users when using smart placement with Workers + Assets and `serve_directly` is set to `false` diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index e74ab2ee5282..ee73d119c714 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -4687,6 +4687,55 @@ addEventListener('fetch', event => {});` `); }); + it("should warn when using smart placement with Worker first", async () => { + const assets = [ + { filePath: ".assetsignore", content: "*.bak\nsub-dir" }, + { filePath: "file-1.txt", content: "Content of file-1" }, + { filePath: "file-2.bak", content: "Content of file-2" }, + { filePath: "file-3.txt", content: "Content of file-3" }, + { filePath: "sub-dir/file-4.bak", content: "Content of file-4" }, + { filePath: "sub-dir/file-5.txt", content: "Content of file-5" }, + ]; + writeAssets(assets, "assets"); + writeWorkerSource({ format: "js" }); + writeWranglerConfig({ + main: "index.js", + assets: { + directory: "assets", + experimental_serve_directly: false, + binding: "ASSETS", + }, + placement: { + mode: "smart", + }, + }); + const bodies: AssetManifest[] = []; + await mockAUSRequest(bodies); + mockSubDomainRequest(); + mockUploadWorkerRequest({ + expectedAssets: { + jwt: "<>", + config: { + serve_directly: false, + }, + }, + expectedMainModule: "index.js", + expectedBindings: [{ name: "ASSETS", type: "assets" }], + }); + + await runWrangler("deploy"); + + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] Turning on Smart Placement in a Worker that is using assets and serve_directly set to false means that your entire Worker could be moved to run closer to your data source, and all requests will go to that Worker before serving assets. + + This could result in poor performance as round trip times could increase when serving assets. + + Read more: https://developers.cloudflare.com/workers/static-assets/binding/#smart-placement + + " + `); + }); + it("should warn if experimental_serve_directly=false but no binding is provided", async () => { const assets = [ { filePath: ".assetsignore", content: "*.bak\nsub-dir" }, diff --git a/packages/wrangler/src/assets.ts b/packages/wrangler/src/assets.ts index f3f8802e0891..e22c6e95703e 100644 --- a/packages/wrangler/src/assets.ts +++ b/packages/wrangler/src/assets.ts @@ -444,6 +444,18 @@ export function validateAssetsArgsAndConfig( ); } + // Smart placement turned on when using assets + if ( + config?.placement?.mode === "smart" && + config?.assets?.experimental_serve_directly === false + ) { + logger.warn( + "Turning on Smart Placement in a Worker that is using assets and serve_directly set to false means that your entire Worker could be moved to run closer to your data source, and all requests will go to that Worker before serving assets.\n" + + "This could result in poor performance as round trip times could increase when serving assets.\n\n" + + "Read more: https://developers.cloudflare.com/workers/static-assets/binding/#smart-placement" + ); + } + // User Worker ahead of assets, but no assets binding provided if ( "legacy" in args From 1c4988a6b87723d9c7ed37810eb531c91609ec3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Somhairle=20MacLe=C3=B2id?= Date: Thu, 19 Dec 2024 15:00:08 +0000 Subject: [PATCH 14/53] Update bug-template.yaml (#7490) --- .github/ISSUE_TEMPLATE/bug-template.yaml | 39 ++++++------------------ 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-template.yaml b/.github/ISSUE_TEMPLATE/bug-template.yaml index 2c11b6936284..27abc2efd88b 100644 --- a/.github/ISSUE_TEMPLATE/bug-template.yaml +++ b/.github/ISSUE_TEMPLATE/bug-template.yaml @@ -34,50 +34,29 @@ body: required: true - type: input attributes: - label: What version(s) of the tool(s) are you using? - placeholder: 0.0.0 [Wrangler], 0.0.0 [C3], etc. + label: What versions are you using? + placeholder: 0.0.0 [Wrangler], 0.0.0 [C3], 0.0.0 [Node.js], etc. validations: required: true - - type: input - attributes: - label: What version of Node are you using? - placeholder: 0.0.0 - validations: - required: false - type: input attributes: label: What operating system and version are you using? placeholder: Mac Sonoma 14.2.1, Windows 11, Linux (or WSL) Debian Bookworm, etc. validations: required: true - - type: textarea - attributes: - label: Describe the Bug - description: Please describe the bug and include steps to reproduce. - value: | - ### Observed behavior - Please describe. - - ### Expected behavior - Please describe. - - ### Steps to reproduce - Please provide the following: - - A minimal working subset of your worker code - - A minimal working subset of your `wrangler.toml` - - Commands used to start your local dev server, including custom env and cli args - - Steps to be performed in the browser, curl commands, or a test we can run that reliably fails (at least a percent of the time) - - A git repo we can clone and run a test suite on, or which has a README with step-by-step instructions, is even better. In this case, please use the field below to provide a link to the minimal repro. - validations: - required: true - type: input attributes: label: Please provide a link to a minimal reproduction - description: Although not required, we often request a minimal reproduction to help troubleshoot the issue, so providing this up-front streamlines the process towards resolution. placeholder: https://github.com/foobar-user/minimal-repro validations: required: false + - type: textarea + attributes: + label: Describe the Bug + description: Please describe the bug in as much detail as possible, including steps to reproduce, the behaviour you're seeing, and the behaviour you expect. + validations: + required: true + - type: textarea attributes: label: Please provide any relevant error logs From 4ab7ffcad7d7824a9d9737c78c3eccf4bcf764d8 Mon Sep 17 00:00:00 2001 From: emily-shen <69125074+emily-shen@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:00:47 +0000 Subject: [PATCH 15/53] feat: add "add binding" ui to vscode extension (#7591) * add 'add binding' command * cleanup * changeset * pr feedback * fixup --- .changeset/slimy-dots-hope.md | 5 + .../package.json | 12 +- .../resources/icons/d1.svg | 1 + .../resources/icons/kv.svg | 1 + .../resources/icons/r2.svg | 1 + .../src/add-binding.ts | 334 ++++++++++++++++++ .../src/extension.ts | 17 +- .../src/{bindings.ts => show-bindings.ts} | 19 +- 8 files changed, 379 insertions(+), 11 deletions(-) create mode 100644 .changeset/slimy-dots-hope.md create mode 100644 packages/cloudflare-workers-bindings-extension/resources/icons/d1.svg create mode 100644 packages/cloudflare-workers-bindings-extension/resources/icons/kv.svg create mode 100644 packages/cloudflare-workers-bindings-extension/resources/icons/r2.svg create mode 100644 packages/cloudflare-workers-bindings-extension/src/add-binding.ts rename packages/cloudflare-workers-bindings-extension/src/{bindings.ts => show-bindings.ts} (96%) diff --git a/.changeset/slimy-dots-hope.md b/.changeset/slimy-dots-hope.md new file mode 100644 index 000000000000..f1a05aca9503 --- /dev/null +++ b/.changeset/slimy-dots-hope.md @@ -0,0 +1,5 @@ +--- +"cloudflare-workers-bindings-extension": minor +--- + +feat: add ui to add a binding via the extension diff --git a/packages/cloudflare-workers-bindings-extension/package.json b/packages/cloudflare-workers-bindings-extension/package.json index 94b1b21f76c8..1891f9ff2625 100644 --- a/packages/cloudflare-workers-bindings-extension/package.json +++ b/packages/cloudflare-workers-bindings-extension/package.json @@ -31,6 +31,11 @@ "command": "cloudflare-workers-bindings.refresh", "title": "Cloudflare Workers: Refresh bindings", "icon": "$(refresh)" + }, + { + "command": "cloudflare-workers-bindings.addBinding", + "title": "Cloudflare Workers: Add binding", + "icon": "$(add)" } ], "menus": { @@ -39,6 +44,11 @@ "command": "cloudflare-workers-bindings.refresh", "when": "view == cloudflare-workers-bindings", "group": "navigation" + }, + { + "command": "cloudflare-workers-bindings.addBinding", + "when": "view == cloudflare-workers-bindings", + "group": "navigation" } ] }, @@ -64,7 +74,7 @@ "viewsWelcome": [ { "view": "cloudflare-workers-bindings", - "contents": "Welcome to Cloudflare Workers! [Learn more](https://workers.cloudflare.com).\n[Refresh Bindings](command:cloudflare-workers-bindings.refresh)" + "contents": "Welcome to Cloudflare Workers! [Learn more](https://workers.cloudflare.com).\n[Add a binding](command:cloudflare-workers-bindings.addBinding)" } ] }, diff --git a/packages/cloudflare-workers-bindings-extension/resources/icons/d1.svg b/packages/cloudflare-workers-bindings-extension/resources/icons/d1.svg new file mode 100644 index 000000000000..e1943befd6f4 --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/resources/icons/d1.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/cloudflare-workers-bindings-extension/resources/icons/kv.svg b/packages/cloudflare-workers-bindings-extension/resources/icons/kv.svg new file mode 100644 index 000000000000..aa5283cba381 --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/resources/icons/kv.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/cloudflare-workers-bindings-extension/resources/icons/r2.svg b/packages/cloudflare-workers-bindings-extension/resources/icons/r2.svg new file mode 100644 index 000000000000..7eb01e06b7cd --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/resources/icons/r2.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/cloudflare-workers-bindings-extension/src/add-binding.ts b/packages/cloudflare-workers-bindings-extension/src/add-binding.ts new file mode 100644 index 000000000000..ec3e387c5561 --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/src/add-binding.ts @@ -0,0 +1,334 @@ +import { + Disposable, + env, + ExtensionContext, + QuickInput, + QuickInputButton, + QuickInputButtons, + QuickPickItem, + Uri, + window, + workspace, +} from "vscode"; +import { getConfigUri } from "./show-bindings"; +import { importWrangler } from "./wrangler"; + +class BindingType implements QuickPickItem { + constructor( + public label: string, + public configKey?: string, + public detail?: string, + public iconPath?: Uri + ) {} +} + +export async function addBindingFlow(context: ExtensionContext) { + const bindingTypes: BindingType[] = [ + new BindingType( + "KV", + "kv_namespaces", + "Global, low-latency, key-value data storage", + Uri.file(context.asAbsolutePath("resources/icons/kv.svg")) + ), + new BindingType( + "R2", + "r2_buckets", + "Object storage for all your data", + Uri.file(context.asAbsolutePath("resources/icons/r2.svg")) + ), + new BindingType( + "D1", + "d1_databases", + "Serverless SQL databases", + Uri.file(context.asAbsolutePath("resources/icons/d1.svg")) + ), + ]; + + interface State { + title: string; + step: number; + totalSteps: number; + bindingType: BindingType; + name: string; + runtime: QuickPickItem; + id: string; + } + + async function collectInputs() { + const state = {} as Partial; + await MultiStepInput.run((input) => pickBindingType(input, state)); + return state as State; + } + + const title = "Add binding"; + + async function pickBindingType(input: MultiStepInput, state: Partial) { + const pick = await input.showQuickPick({ + title, + step: 1, + totalSteps: 2, + placeholder: "Choose a binding type", + items: bindingTypes, + activeItem: + typeof state.bindingType !== "string" ? state.bindingType : undefined, + }); + state.bindingType = pick as BindingType; + return (input: MultiStepInput) => inputBindingName(input, state); + } + + async function inputBindingName( + input: MultiStepInput, + state: Partial + ) { + let name = await input.showInputBox({ + title, + step: 2, + totalSteps: 2, + value: state.name || "", + prompt: "Choose a binding name", + validate: validateNameIsUnique, + placeholder: `e.g. MY_BINDING`, + }); + state.name = name; + return () => addToConfig(state); + } + + async function addToConfig(state: Partial) { + const configUri = await getConfigUri(); + if (!configUri) { + // for some reason, if we just throw an error it doesn't surface properly when triggered by the button in the welcome view + window.showErrorMessage( + "Unable to locate Wrangler configuration file — have you opened a project with a wrangler.json(c) or wrangler.toml file?", + {} + ); + return null; + } + const workspaceFolder = workspace.getWorkspaceFolder(configUri); + + if (!workspaceFolder) { + return null; + } + + const wrangler = importWrangler(workspaceFolder.uri.fsPath); + + workspace.openTextDocument(configUri).then((doc) => { + window.showTextDocument(doc); + try { + wrangler.experimental_patchConfig(configUri.path, { + [state.bindingType?.configKey!]: [{ binding: state.name! }], + }); + window.showInformationMessage(`Created binding '${state.name}'`); + } catch { + window.showErrorMessage( + `Unable to directly add binding to config file. A snippet has been copied to clipboard - please paste this into your config file.` + ); + + const patch = `[[${state.bindingType?.configKey!}]] +binding = "${state.name}" +`; + + env.clipboard.writeText(patch); + } + }); + } + + async function validateNameIsUnique(name: string) { + // TODO: actually validate uniqueness + return name === "SOME_KV_BINDING" ? "Name not unique" : undefined; + } + + await collectInputs(); +} + +// ------------------------------------------------------- +// Helper code that wraps the API for the multi-step case. +// ------------------------------------------------------- + +class InputFlowAction { + static back = new InputFlowAction(); + static cancel = new InputFlowAction(); + static resume = new InputFlowAction(); +} + +type InputStep = (input: MultiStepInput) => Thenable; + +interface QuickPickParameters { + title: string; + step: number; + totalSteps: number; + items: T[]; + activeItem?: T; + ignoreFocusOut?: boolean; + placeholder: string; + buttons?: QuickInputButton[]; +} + +interface InputBoxParameters { + title: string; + step: number; + totalSteps: number; + value: string; + prompt: string; + validate: (value: string) => Promise; + buttons?: QuickInputButton[]; + ignoreFocusOut?: boolean; + placeholder?: string; +} + +export class MultiStepInput { + static async run(start: InputStep) { + const input = new MultiStepInput(); + return input.stepThrough(start); + } + + private current?: QuickInput; + private steps: InputStep[] = []; + + private async stepThrough(start: InputStep) { + let step: InputStep | void = start; + while (step) { + this.steps.push(step); + if (this.current) { + this.current.enabled = false; + this.current.busy = true; + } + try { + step = await step(this); + } catch (err) { + if (err === InputFlowAction.back) { + this.steps.pop(); + step = this.steps.pop(); + } else if (err === InputFlowAction.resume) { + step = this.steps.pop(); + } else if (err === InputFlowAction.cancel) { + step = undefined; + } else { + throw err; + } + } + } + if (this.current) { + this.current.dispose(); + } + } + + async showQuickPick< + T extends QuickPickItem, + P extends QuickPickParameters, + >({ + title, + step, + totalSteps, + items, + activeItem, + ignoreFocusOut, + placeholder, + buttons, + }: P) { + const disposables: Disposable[] = []; + try { + return await new Promise< + T | (P extends { buttons: (infer I)[] } ? I : never) + >((resolve, reject) => { + const input = window.createQuickPick(); + input.title = title; + input.step = step; + input.totalSteps = totalSteps; + input.ignoreFocusOut = ignoreFocusOut ?? false; + input.placeholder = placeholder; + input.items = items; + if (activeItem) { + input.activeItems = [activeItem]; + } + input.buttons = [ + ...(this.steps.length > 1 ? [QuickInputButtons.Back] : []), + ...(buttons || []), + ]; + disposables.push( + input.onDidTriggerButton((item) => { + if (item === QuickInputButtons.Back) { + reject(InputFlowAction.back); + } else { + resolve(item); + } + }), + input.onDidChangeSelection((items) => resolve(items[0])) + ); + if (this.current) { + this.current.dispose(); + } + this.current = input; + this.current.show(); + }); + } finally { + disposables.forEach((d) => d.dispose()); + } + } + + async showInputBox

({ + title, + step, + totalSteps, + value, + prompt, + validate, + buttons, + ignoreFocusOut, + placeholder, + }: P) { + const disposables: Disposable[] = []; + try { + return await new Promise< + string | (P extends { buttons: (infer I)[] } ? I : never) + >((resolve, reject) => { + const input = window.createInputBox(); + input.title = title; + input.step = step; + input.totalSteps = totalSteps; + input.value = value || ""; + input.prompt = prompt; + input.ignoreFocusOut = ignoreFocusOut ?? false; + input.placeholder = placeholder; + input.buttons = [ + ...(this.steps.length > 1 ? [QuickInputButtons.Back] : []), + ...(buttons || []), + ]; + let validating = validate(""); + disposables.push( + input.onDidTriggerButton((item) => { + if (item === QuickInputButtons.Back) { + reject(InputFlowAction.back); + } else { + resolve(item); + } + }), + input.onDidAccept(async () => { + const value = input.value; + input.enabled = false; + input.busy = true; + if (!(await validate(value))) { + resolve(value); + } + input.enabled = true; + input.busy = false; + }), + input.onDidChangeValue(async (text) => { + const current = validate(text); + validating = current; + const validationMessage = await current; + if (current === validating) { + input.validationMessage = validationMessage; + } + }) + ); + if (this.current) { + this.current.dispose(); + } + this.current = input; + this.current.show(); + }); + } finally { + disposables.forEach((d) => d.dispose()); + } + } +} diff --git a/packages/cloudflare-workers-bindings-extension/src/extension.ts b/packages/cloudflare-workers-bindings-extension/src/extension.ts index 9da94758ee44..d10f1dfc6742 100644 --- a/packages/cloudflare-workers-bindings-extension/src/extension.ts +++ b/packages/cloudflare-workers-bindings-extension/src/extension.ts @@ -1,5 +1,6 @@ import * as vscode from "vscode"; -import { BindingsProvider } from "./bindings"; +import { addBindingFlow } from "./add-binding"; +import { BindingsProvider } from "./show-bindings"; export type Result = { bindingsProvider: BindingsProvider; @@ -32,8 +33,20 @@ export async function activate( () => bindingsProvider.refresh() ); + // Register the add bindings command + const addBindingCommand = vscode.commands.registerCommand( + "cloudflare-workers-bindings.addBinding", + async () => { + await addBindingFlow(context); + } + ); // Cleanup when the extension is deactivated - context.subscriptions.push(bindingsView, watcher, refreshCommand); + context.subscriptions.push( + bindingsView, + watcher, + refreshCommand, + addBindingCommand + ); return { bindingsProvider, diff --git a/packages/cloudflare-workers-bindings-extension/src/bindings.ts b/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts similarity index 96% rename from packages/cloudflare-workers-bindings-extension/src/bindings.ts rename to packages/cloudflare-workers-bindings-extension/src/show-bindings.ts index 817b39fdebbd..5e4c7f715daf 100644 --- a/packages/cloudflare-workers-bindings-extension/src/bindings.ts +++ b/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts @@ -200,26 +200,29 @@ export class BindingsProvider implements vscode.TreeDataProvider { // Finds the first wrangler config file in the workspace and parse it export async function getWranglerConfig(): Promise { - const [configUri] = await vscode.workspace.findFiles( - "wrangler.{toml,jsonc,json}", - null, - 1 - ); - + const configUri = await getConfigUri(); if (!configUri) { return null; } - const workspaceFolder = vscode.workspace.getWorkspaceFolder(configUri); if (!workspaceFolder) { return null; } - const wrangler = await importWrangler(workspaceFolder.uri.fsPath); + const wrangler = importWrangler(workspaceFolder.uri.fsPath); const { rawConfig } = wrangler.experimental_readRawConfig({ config: configUri.fsPath, }); return rawConfig; } + +export async function getConfigUri(): Promise { + const [configUri] = await vscode.workspace.findFiles( + "wrangler.{toml,jsonc,json}", + null, + 1 + ); + return configUri; +} From 178fd0123d8d4baf9f395bd8aade2cf1dccb6aa8 Mon Sep 17 00:00:00 2001 From: Carmen Popoviciu Date: Thu, 19 Dec 2024 17:26:18 +0100 Subject: [PATCH 16/53] chore(workers-shared): Dummy `workers-shared` version bump (#7598) The Router Worker and Asset Worker of `workers-shared` are currently in a weird state that prevents us to redeploy them. This commit performs a dummy `workers-shared` version bump to unlock us from this blocked state. --- .changeset/sharp-crabs-beg.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changeset/sharp-crabs-beg.md diff --git a/.changeset/sharp-crabs-beg.md b/.changeset/sharp-crabs-beg.md new file mode 100644 index 000000000000..46139e9e7024 --- /dev/null +++ b/.changeset/sharp-crabs-beg.md @@ -0,0 +1,9 @@ +--- +"@cloudflare/workers-shared": patch +--- + +Dummy workers-shared version bump + +The Router Worker and Asset Worker of `workers-shared` are currently in a weird state that prevents us to redeploy them. The current versions of these workers are developer modified due to adding secrets. We want a CI controlled version to safely use these secrets. + +This commit performs a dummy `workers-shared` version bump to unlock us from this blocked state. From 7216835bf7489804905751c6b52e75a8945e7974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 19 Dec 2024 16:45:25 +0000 Subject: [PATCH 17/53] Make workflow `instance.status()` return output equal to production workflows (#7575) * feat: Make `instance.status()` return output equal to production Previously,in local dev, the `output` field would return the list of successful steps outputs in the workflow. This is not expected behaviour compared to production workflows (where the output is the actual return of the `run` function), probably just a implementation detail not set left-over from before beta. This commit makes it so that `output` is equal to production behaviour. For observability sake, I kept the old step output list in a different field `__LOCAL_DEV_STEP_OUTPUTS` - I think this is a good enough compromise right now since we want local dev to be correct against prod first. We can remove `__LOCAL_DEV_STEP_OUTPUTS` later, once we figure out on how to add custom stuff to the devtools page. * fix types * fix tests * chore: add better types for readLogs --- .changeset/great-flowers-compete.md | 6 ++++ fixtures/workflow-multiple/src/index.ts | 4 +-- .../workflow-multiple/tests/index.test.ts | 12 ++++--- fixtures/workflow/src/index.ts | 2 +- fixtures/workflow/tests/index.test.ts | 12 ++++--- .../test/plugins/workflows/index.spec.ts | 15 +++++++-- packages/workflows-shared/src/binding.ts | 33 +++++++++++++++---- packages/workflows-shared/src/engine.ts | 33 ++++++++++++------- 8 files changed, 85 insertions(+), 32 deletions(-) create mode 100644 .changeset/great-flowers-compete.md diff --git a/.changeset/great-flowers-compete.md b/.changeset/great-flowers-compete.md new file mode 100644 index 000000000000..96160dec4121 --- /dev/null +++ b/.changeset/great-flowers-compete.md @@ -0,0 +1,6 @@ +--- +"@cloudflare/workflows-shared": patch +"miniflare": patch +--- + +Make `Instance.status()` return type the same as production diff --git a/fixtures/workflow-multiple/src/index.ts b/fixtures/workflow-multiple/src/index.ts index 3498d07e2f24..adaf369e8e93 100644 --- a/fixtures/workflow-multiple/src/index.ts +++ b/fixtures/workflow-multiple/src/index.ts @@ -29,7 +29,7 @@ export class Demo extends WorkflowEntrypoint<{}, Params> { }; }); - return [result, result2, timestamp, payload, "workflow1"]; + return "i'm workflow1"; } } @@ -53,7 +53,7 @@ export class Demo2 extends WorkflowEntrypoint<{}, Params> { }; }); - return [result, result2, timestamp, payload, "workflow2"]; + return "i'm workflow2"; } } diff --git a/fixtures/workflow-multiple/tests/index.test.ts b/fixtures/workflow-multiple/tests/index.test.ts index 29268cd0ea29..4a986f4111cf 100644 --- a/fixtures/workflow-multiple/tests/index.test.ts +++ b/fixtures/workflow-multiple/tests/index.test.ts @@ -48,7 +48,8 @@ describe("Workflows", () => { id: "test", status: { status: "running", - output: [], + __LOCAL_DEV_STEP_OUTPUTS: [], + output: null, }, }; @@ -65,7 +66,8 @@ describe("Workflows", () => { id: "test", status: { status: "running", - output: [{ output: "First step result" }], + __LOCAL_DEV_STEP_OUTPUTS: [{ output: "First step result" }], + output: null, }, }; await Promise.all([ @@ -96,10 +98,11 @@ describe("Workflows", () => { id: "test", status: { status: "complete", - output: [ + __LOCAL_DEV_STEP_OUTPUTS: [ { output: "First step result" }, { output: "workflow1" }, ], + output: "i'm workflow1", }, }); }, @@ -113,10 +116,11 @@ describe("Workflows", () => { id: "test", status: { status: "complete", - output: [ + __LOCAL_DEV_STEP_OUTPUTS: [ { output: "First step result" }, { output: "workflow2" }, ], + output: "i'm workflow2", }, }); }, diff --git a/fixtures/workflow/src/index.ts b/fixtures/workflow/src/index.ts index 8d84551cefe6..1a62c4b33cb6 100644 --- a/fixtures/workflow/src/index.ts +++ b/fixtures/workflow/src/index.ts @@ -27,7 +27,7 @@ export class Demo extends WorkflowEntrypoint<{}, Params> { }; }); - return [result, result2, timestamp, payload]; + return "i'm a workflow output"; } } diff --git a/fixtures/workflow/tests/index.test.ts b/fixtures/workflow/tests/index.test.ts index cb81a544c637..046f8190f425 100644 --- a/fixtures/workflow/tests/index.test.ts +++ b/fixtures/workflow/tests/index.test.ts @@ -46,7 +46,8 @@ describe("Workflows", () => { fetchJson(`http://${ip}:${port}/create?workflowName=test`) ).resolves.toEqual({ status: "running", - output: [], + __LOCAL_DEV_STEP_OUTPUTS: [], + output: null, }); await vi.waitFor( @@ -55,7 +56,8 @@ describe("Workflows", () => { fetchJson(`http://${ip}:${port}/status?workflowName=test`) ).resolves.toEqual({ status: "running", - output: [{ output: "First step result" }], + __LOCAL_DEV_STEP_OUTPUTS: [{ output: "First step result" }], + output: null, }); }, { timeout: 5000 } @@ -67,10 +69,11 @@ describe("Workflows", () => { fetchJson(`http://${ip}:${port}/status?workflowName=test`) ).resolves.toEqual({ status: "complete", - output: [ + __LOCAL_DEV_STEP_OUTPUTS: [ { output: "First step result" }, { output: "Second step result" }, ], + output: "i'm a workflow output", }); }, { timeout: 5000 } @@ -80,7 +83,8 @@ describe("Workflows", () => { it("creates a workflow without id", async ({ expect }) => { await expect(fetchJson(`http://${ip}:${port}/create`)).resolves.toEqual({ status: "running", - output: [], + __LOCAL_DEV_STEP_OUTPUTS: [], + output: null, }); }); diff --git a/packages/miniflare/test/plugins/workflows/index.spec.ts b/packages/miniflare/test/plugins/workflows/index.spec.ts index ac19a418e868..0c8d9ddccb32 100644 --- a/packages/miniflare/test/plugins/workflows/index.spec.ts +++ b/packages/miniflare/test/plugins/workflows/index.spec.ts @@ -40,7 +40,10 @@ test("persists Workflow data on file-system between runs", async (t) => { t.teardown(() => mf.dispose()); let res = await mf.dispatchFetch("http://localhost"); - t.is(await res.text(), '{"status":"running","output":[]}'); + t.is( + await res.text(), + '{"status":"running","__LOCAL_DEV_STEP_OUTPUTS":[],"output":null}' + ); // there's no waitUntil in ava haha const begin = performance.now(); @@ -50,7 +53,10 @@ test("persists Workflow data on file-system between runs", async (t) => { const res = await mf.dispatchFetch("http://localhost"); console.log(test); test = await res.text(); - if (test === '{"status":"complete","output":["yes you are"]}') { + if ( + test === + '{"status":"complete","__LOCAL_DEV_STEP_OUTPUTS":["yes you are"],"output":"I\'m a output string"}' + ) { success = true; break; } @@ -68,5 +74,8 @@ test("persists Workflow data on file-system between runs", async (t) => { // state should be persisted now res = await mf.dispatchFetch("http://localhost"); - t.is(await res.text(), '{"status":"complete","output":["yes you are"]}'); + t.is( + await res.text(), + '{"status":"complete","__LOCAL_DEV_STEP_OUTPUTS":["yes you are"],"output":"I\'m a output string"}' + ); }); diff --git a/packages/workflows-shared/src/binding.ts b/packages/workflows-shared/src/binding.ts index 0e7a44ab6c7d..f10dd0981bb8 100644 --- a/packages/workflows-shared/src/binding.ts +++ b/packages/workflows-shared/src/binding.ts @@ -5,6 +5,7 @@ import type { DatabaseVersion, DatabaseWorkflow, Engine, + EngineLogs, } from "./engine"; type Env = { @@ -93,16 +94,34 @@ export class WorkflowHandle extends RpcTarget implements WorkflowInstance { throw new Error("Not implemented yet"); } - public async status(): Promise { + public async status(): Promise< + InstanceStatus & { __LOCAL_DEV_STEP_OUTPUTS: unknown[] } + > { const status = await this.stub.getStatus(0, this.id); - const { logs } = await this.stub.readLogs(); - // @ts-expect-error TODO: Fix this + + // NOTE(lduarte): for some reason, sync functions over RPC are typed as never instead of Promise + const { logs } = + await (this.stub.readLogs() as unknown as Promise); + + const workflowSuccessEvent = logs + .filter((log) => log.event === InstanceEvent.WORKFLOW_SUCCESS) + .at(0); + const filteredLogs = logs.filter( - // @ts-expect-error TODO: Fix this (log) => log.event === InstanceEvent.STEP_SUCCESS ); - // @ts-expect-error TODO: Fix this - const output = filteredLogs.map((log) => log.metadata.result); - return { status: instanceStatusName(status), output }; // output, error + const stepOutputs = filteredLogs.map((log) => log.metadata.result); + + const workflowOutput = + workflowSuccessEvent !== undefined + ? workflowSuccessEvent.metadata.result + : null; + + return { + status: instanceStatusName(status), + __LOCAL_DEV_STEP_OUTPUTS: stepOutputs, + // @ts-expect-error types are wrong, will remove this expect-error once I fix them + output: workflowOutput, + }; // output, error } } diff --git a/packages/workflows-shared/src/engine.ts b/packages/workflows-shared/src/engine.ts index 08dd14a0b9b2..d2002b9d08f6 100644 --- a/packages/workflows-shared/src/engine.ts +++ b/packages/workflows-shared/src/engine.ts @@ -12,11 +12,7 @@ import { startGracePeriod, } from "./lib/gracePeriodSemaphore"; import { TimePriorityQueue } from "./lib/timePriorityQueue"; -import type { - InstanceLogsResponse, - InstanceMetadata, - RawInstanceLog, -} from "./instance"; +import type { InstanceMetadata, RawInstanceLog } from "./instance"; import type { WorkflowEntrypoint, WorkflowEvent } from "cloudflare:workers"; export interface Env { @@ -53,6 +49,19 @@ export type DatabaseInstance = { ended_on: string | null; }; +export type Log = { + event: InstanceEvent; + group: string | null; + target: string | null; + metadata: { + result: unknown; + }; +}; + +export type EngineLogs = { + logs: Log[]; +}; + const ENGINE_STATUS_KEY = "ENGINE_STATUS"; export class Engine extends DurableObject { @@ -121,18 +130,20 @@ export class Engine extends DurableObject { return []; } - readLogs(): InstanceLogsResponse { + readLogs(): EngineLogs { const logs = [ - ...this.ctx.storage.sql.exec>( - "SELECT event, groupKey, target, metadata FROM states" - ), + ...this.ctx.storage.sql.exec<{ + event: InstanceEvent; + groupKey: string | null; + target: string | null; + metadata: string; + }>("SELECT event, groupKey, target, metadata FROM states"), ]; return { - // @ts-expect-error TODO: Fix this logs: logs.map((log) => ({ ...log, - metadata: JSON.parse(log.metadata as string), + metadata: JSON.parse(log.metadata), group: log.groupKey, })), }; From 18af481c7c5c41d2566a211856a23eb327dc69e9 Mon Sep 17 00:00:00 2001 From: emily-shen <69125074+emily-shen@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:53:02 +0000 Subject: [PATCH 18/53] Update slimy-dots-hope.md (#7599) --- .changeset/slimy-dots-hope.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/slimy-dots-hope.md b/.changeset/slimy-dots-hope.md index f1a05aca9503..af417c16df64 100644 --- a/.changeset/slimy-dots-hope.md +++ b/.changeset/slimy-dots-hope.md @@ -1,5 +1,5 @@ --- -"cloudflare-workers-bindings-extension": minor +"cloudflare-workers-bindings-extension": patch --- feat: add ui to add a binding via the extension From aa9ec0ff279e7a4cbfcd35232aa2e706b7c8ec68 Mon Sep 17 00:00:00 2001 From: ANT Bot <116369605+workers-devprod@users.noreply.github.com> Date: Thu, 19 Dec 2024 19:04:03 +0000 Subject: [PATCH 19/53] Version Packages (#7595) Co-authored-by: github-actions[bot] --- .changeset/dependabot-update-7589.md | 12 --------- .changeset/fuzzy-nails-invent.md | 5 ---- .changeset/great-flowers-compete.md | 6 ----- .changeset/lovely-rats-live.md | 7 ----- .changeset/quick-wombats-battle.md | 12 --------- .changeset/sharp-crabs-beg.md | 9 ------- .changeset/slimy-dots-hope.md | 5 ---- .changeset/swift-zebras-guess.md | 5 ---- .changeset/tidy-kiwis-arrive.md | 5 ---- .changeset/warm-squids-visit.md | 5 ---- .../CHANGELOG.md | 8 ++++++ .../package.json | 2 +- packages/miniflare/CHANGELOG.md | 15 +++++++++++ packages/miniflare/package.json | 2 +- packages/pages-shared/CHANGELOG.md | 11 ++++++++ packages/pages-shared/package.json | 2 +- packages/vitest-pool-workers/CHANGELOG.md | 8 ++++++ packages/vitest-pool-workers/package.json | 2 +- packages/workers-shared/CHANGELOG.md | 10 +++++++ packages/workers-shared/package.json | 2 +- packages/workflows-shared/CHANGELOG.md | 6 +++++ packages/workflows-shared/package.json | 2 +- packages/wrangler/CHANGELOG.md | 26 +++++++++++++++++++ packages/wrangler/package.json | 2 +- 24 files changed, 91 insertions(+), 78 deletions(-) delete mode 100644 .changeset/dependabot-update-7589.md delete mode 100644 .changeset/fuzzy-nails-invent.md delete mode 100644 .changeset/great-flowers-compete.md delete mode 100644 .changeset/lovely-rats-live.md delete mode 100644 .changeset/quick-wombats-battle.md delete mode 100644 .changeset/sharp-crabs-beg.md delete mode 100644 .changeset/slimy-dots-hope.md delete mode 100644 .changeset/swift-zebras-guess.md delete mode 100644 .changeset/tidy-kiwis-arrive.md delete mode 100644 .changeset/warm-squids-visit.md diff --git a/.changeset/dependabot-update-7589.md b/.changeset/dependabot-update-7589.md deleted file mode 100644 index 6ff3425502c2..000000000000 --- a/.changeset/dependabot-update-7589.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -"miniflare": patch ---- - -chore: update dependencies of "miniflare" package - -The following dependency versions have been updated: - -| Dependency | From | To | -| ------------------------- | ------------- | ------------- | -| workerd | 1.20241205.0 | 1.20241218.0 | -| @cloudflare/workers-types | ^4.20241205.0 | ^4.20241218.0 | diff --git a/.changeset/fuzzy-nails-invent.md b/.changeset/fuzzy-nails-invent.md deleted file mode 100644 index e21d23648c10..000000000000 --- a/.changeset/fuzzy-nails-invent.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@cloudflare/pages-shared": minor ---- - -feat: Return a 304 Not Modified response when matching an asset preservation cache request if appropriate diff --git a/.changeset/great-flowers-compete.md b/.changeset/great-flowers-compete.md deleted file mode 100644 index 96160dec4121..000000000000 --- a/.changeset/great-flowers-compete.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@cloudflare/workflows-shared": patch -"miniflare": patch ---- - -Make `Instance.status()` return type the same as production diff --git a/.changeset/lovely-rats-live.md b/.changeset/lovely-rats-live.md deleted file mode 100644 index 2b08b4e9ed48..000000000000 --- a/.changeset/lovely-rats-live.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"wrangler": patch ---- - -feat: add experimental_patchConfig() - -`experimental_patchConfig()` can add to a user's config file. It preserves comments if its a `wrangler.jsonc`. However, it is not suitable for `wrangler.toml` with comments as we cannot preserve comments on write. diff --git a/.changeset/quick-wombats-battle.md b/.changeset/quick-wombats-battle.md deleted file mode 100644 index 100d6a157676..000000000000 --- a/.changeset/quick-wombats-battle.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -"wrangler": minor ---- - -feat: Make DX improvements in `wrangler dev --remote` - -Workers + Assets projects have, in certain situations, a relatively degraded `wrangler dev --remote` developer experience, as opposed to Workers proper projects. This is due to the fact that, for Workers + Assets, we need to make extra API calls to: - -1. check for asset files changes -2. upload the changed assets, if any - -This commit improves the `wrangler dev --remote` DX for Workers + Assets, for use cases when the User Worker/assets change while the API calls for previous changes are still in flight. For such use cases, we have put an exit early strategy in place, that drops the event handler execution of the previous changes, in favour of the handler triggered by the new changes. diff --git a/.changeset/sharp-crabs-beg.md b/.changeset/sharp-crabs-beg.md deleted file mode 100644 index 46139e9e7024..000000000000 --- a/.changeset/sharp-crabs-beg.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -"@cloudflare/workers-shared": patch ---- - -Dummy workers-shared version bump - -The Router Worker and Asset Worker of `workers-shared` are currently in a weird state that prevents us to redeploy them. The current versions of these workers are developer modified due to adding secrets. We want a CI controlled version to safely use these secrets. - -This commit performs a dummy `workers-shared` version bump to unlock us from this blocked state. diff --git a/.changeset/slimy-dots-hope.md b/.changeset/slimy-dots-hope.md deleted file mode 100644 index af417c16df64..000000000000 --- a/.changeset/slimy-dots-hope.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"cloudflare-workers-bindings-extension": patch ---- - -feat: add ui to add a binding via the extension diff --git a/.changeset/swift-zebras-guess.md b/.changeset/swift-zebras-guess.md deleted file mode 100644 index 91e2232cc577..000000000000 --- a/.changeset/swift-zebras-guess.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"wrangler": minor ---- - -Provide validation around assets.experimental_serve_directly diff --git a/.changeset/tidy-kiwis-arrive.md b/.changeset/tidy-kiwis-arrive.md deleted file mode 100644 index 2a11e8133230..000000000000 --- a/.changeset/tidy-kiwis-arrive.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"wrangler": minor ---- - -Warn users when using smart placement with Workers + Assets and `serve_directly` is set to `false` diff --git a/.changeset/warm-squids-visit.md b/.changeset/warm-squids-visit.md deleted file mode 100644 index 313a249bc4f1..000000000000 --- a/.changeset/warm-squids-visit.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"cloudflare-workers-bindings-extension": patch ---- - -Introduce a bindings view that lists all the KV, D1 and R2 bindings on the wrangler config (e.g. `wrangler.toml`, `wrangler.jsonc`) diff --git a/packages/cloudflare-workers-bindings-extension/CHANGELOG.md b/packages/cloudflare-workers-bindings-extension/CHANGELOG.md index ca9f2fa2be9b..69304f03a8c2 100644 --- a/packages/cloudflare-workers-bindings-extension/CHANGELOG.md +++ b/packages/cloudflare-workers-bindings-extension/CHANGELOG.md @@ -1,5 +1,13 @@ # cloudflare-workers-bindings-extension +## 0.0.8 + +### Patch Changes + +- [#7591](https://github.com/cloudflare/workers-sdk/pull/7591) [`4ab7ffc`](https://github.com/cloudflare/workers-sdk/commit/4ab7ffcad7d7824a9d9737c78c3eccf4bcf764d8) Thanks [@emily-shen](https://github.com/emily-shen)! - feat: add ui to add a binding via the extension + +- [#7582](https://github.com/cloudflare/workers-sdk/pull/7582) [`ab0ac94`](https://github.com/cloudflare/workers-sdk/commit/ab0ac94849b8cabe6b29340bc5d539a8a9d61ab8) Thanks [@edmundhung](https://github.com/edmundhung)! - Introduce a bindings view that lists all the KV, D1 and R2 bindings on the wrangler config (e.g. `wrangler.toml`, `wrangler.jsonc`) + ## 0.0.7 ### Patch Changes diff --git a/packages/cloudflare-workers-bindings-extension/package.json b/packages/cloudflare-workers-bindings-extension/package.json index 1891f9ff2625..6a9b34d2770f 100644 --- a/packages/cloudflare-workers-bindings-extension/package.json +++ b/packages/cloudflare-workers-bindings-extension/package.json @@ -1,7 +1,7 @@ { "name": "cloudflare-workers-bindings-extension", "displayName": "Cloudflare Workers", - "version": "0.0.7", + "version": "0.0.8", "description": "Manage your Cloudflare Worker's bindings", "categories": [ "Other" diff --git a/packages/miniflare/CHANGELOG.md b/packages/miniflare/CHANGELOG.md index 16c0a98dc624..048dbcc42a4f 100644 --- a/packages/miniflare/CHANGELOG.md +++ b/packages/miniflare/CHANGELOG.md @@ -1,5 +1,20 @@ # miniflare +## 3.20241218.0 + +### Patch Changes + +- [#7589](https://github.com/cloudflare/workers-sdk/pull/7589) [`1488e11`](https://github.com/cloudflare/workers-sdk/commit/1488e118b4a43d032e4f2e69afa1c16c2e54aff6) Thanks [@dependabot](https://github.com/apps/dependabot)! - chore: update dependencies of "miniflare" package + + The following dependency versions have been updated: + + | Dependency | From | To | + | ------------------------- | ------------- | ------------- | + | workerd | 1.20241205.0 | 1.20241218.0 | + | @cloudflare/workers-types | ^4.20241205.0 | ^4.20241218.0 | + +- [#7575](https://github.com/cloudflare/workers-sdk/pull/7575) [`7216835`](https://github.com/cloudflare/workers-sdk/commit/7216835bf7489804905751c6b52e75a8945e7974) Thanks [@LuisDuarte1](https://github.com/LuisDuarte1)! - Make `Instance.status()` return type the same as production + ## 3.20241205.0 ### Patch Changes diff --git a/packages/miniflare/package.json b/packages/miniflare/package.json index d8824142482d..be6716c02d15 100644 --- a/packages/miniflare/package.json +++ b/packages/miniflare/package.json @@ -1,6 +1,6 @@ { "name": "miniflare", - "version": "3.20241205.0", + "version": "3.20241218.0", "description": "Fun, full-featured, fully-local simulator for Cloudflare Workers", "keywords": [ "cloudflare", diff --git a/packages/pages-shared/CHANGELOG.md b/packages/pages-shared/CHANGELOG.md index 72dd42c29087..f474d1cb0a24 100644 --- a/packages/pages-shared/CHANGELOG.md +++ b/packages/pages-shared/CHANGELOG.md @@ -1,5 +1,16 @@ # @cloudflare/pages-shared +## 0.12.0 + +### Minor Changes + +- [#7546](https://github.com/cloudflare/workers-sdk/pull/7546) [`004fd33`](https://github.com/cloudflare/workers-sdk/commit/004fd33d62ab3a77888ffb5538f92135a15d2d3f) Thanks [@GregBrimble](https://github.com/GregBrimble)! - feat: Return a 304 Not Modified response when matching an asset preservation cache request if appropriate + +### Patch Changes + +- Updated dependencies [[`1488e11`](https://github.com/cloudflare/workers-sdk/commit/1488e118b4a43d032e4f2e69afa1c16c2e54aff6), [`7216835`](https://github.com/cloudflare/workers-sdk/commit/7216835bf7489804905751c6b52e75a8945e7974)]: + - miniflare@3.20241218.0 + ## 0.11.72 ### Patch Changes diff --git a/packages/pages-shared/package.json b/packages/pages-shared/package.json index 57c9cb982cd4..aee1ff835fd0 100644 --- a/packages/pages-shared/package.json +++ b/packages/pages-shared/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflare/pages-shared", - "version": "0.11.72", + "version": "0.12.0", "repository": { "type": "git", "url": "https://github.com/cloudflare/workers-sdk.git", diff --git a/packages/vitest-pool-workers/CHANGELOG.md b/packages/vitest-pool-workers/CHANGELOG.md index 6d2106fde456..af5be2daa0d8 100644 --- a/packages/vitest-pool-workers/CHANGELOG.md +++ b/packages/vitest-pool-workers/CHANGELOG.md @@ -1,5 +1,13 @@ # @cloudflare/vitest-pool-workers +## 0.5.40 + +### Patch Changes + +- Updated dependencies [[`1488e11`](https://github.com/cloudflare/workers-sdk/commit/1488e118b4a43d032e4f2e69afa1c16c2e54aff6), [`7216835`](https://github.com/cloudflare/workers-sdk/commit/7216835bf7489804905751c6b52e75a8945e7974), [`48e7e10`](https://github.com/cloudflare/workers-sdk/commit/48e7e1035f489639564948edd3789b1740a7873d), [`8757579`](https://github.com/cloudflare/workers-sdk/commit/8757579a47d675909230a51f8e09d1611d5cadb1), [`086a6b8`](https://github.com/cloudflare/workers-sdk/commit/086a6b8c613b9c8f0f7c4933ffd68f38f7771c3f), [`2bbcb93`](https://github.com/cloudflare/workers-sdk/commit/2bbcb938b1e14cf21da5dc20ce0c8b9bea0f6aad)]: + - miniflare@3.20241218.0 + - wrangler@3.99.0 + ## 0.5.39 ### Patch Changes diff --git a/packages/vitest-pool-workers/package.json b/packages/vitest-pool-workers/package.json index a1799f180b46..bd1740da036b 100644 --- a/packages/vitest-pool-workers/package.json +++ b/packages/vitest-pool-workers/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflare/vitest-pool-workers", - "version": "0.5.39", + "version": "0.5.40", "description": "Workers Vitest integration for writing Vitest unit and integration tests that run inside the Workers runtime", "keywords": [ "cloudflare", diff --git a/packages/workers-shared/CHANGELOG.md b/packages/workers-shared/CHANGELOG.md index 7833e90343dc..2e44f3416542 100644 --- a/packages/workers-shared/CHANGELOG.md +++ b/packages/workers-shared/CHANGELOG.md @@ -1,5 +1,15 @@ # @cloudflare/workers-shared +## 0.11.1 + +### Patch Changes + +- [#7598](https://github.com/cloudflare/workers-sdk/pull/7598) [`178fd01`](https://github.com/cloudflare/workers-sdk/commit/178fd0123d8d4baf9f395bd8aade2cf1dccb6aa8) Thanks [@CarmenPopoviciu](https://github.com/CarmenPopoviciu)! - Dummy workers-shared version bump + + The Router Worker and Asset Worker of `workers-shared` are currently in a weird state that prevents us to redeploy them. The current versions of these workers are developer modified due to adding secrets. We want a CI controlled version to safely use these secrets. + + This commit performs a dummy `workers-shared` version bump to unlock us from this blocked state. + ## 0.11.0 ### Minor Changes diff --git a/packages/workers-shared/package.json b/packages/workers-shared/package.json index fd63b25bacf2..be368edff415 100644 --- a/packages/workers-shared/package.json +++ b/packages/workers-shared/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflare/workers-shared", - "version": "0.11.0", + "version": "0.11.1", "description": "Package that is used at Cloudflare to power some internal features of Cloudflare Workers.", "keywords": [ "cloudflare", diff --git a/packages/workflows-shared/CHANGELOG.md b/packages/workflows-shared/CHANGELOG.md index 507b64437714..5f1bc3f5ba36 100644 --- a/packages/workflows-shared/CHANGELOG.md +++ b/packages/workflows-shared/CHANGELOG.md @@ -1,5 +1,11 @@ # @cloudflare/workflows-shared +## 0.2.2 + +### Patch Changes + +- [#7575](https://github.com/cloudflare/workers-sdk/pull/7575) [`7216835`](https://github.com/cloudflare/workers-sdk/commit/7216835bf7489804905751c6b52e75a8945e7974) Thanks [@LuisDuarte1](https://github.com/LuisDuarte1)! - Make `Instance.status()` return type the same as production + ## 0.2.1 ### Patch Changes diff --git a/packages/workflows-shared/package.json b/packages/workflows-shared/package.json index fc31d6ce1d2e..7750ebd6e0b9 100644 --- a/packages/workflows-shared/package.json +++ b/packages/workflows-shared/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflare/workflows-shared", - "version": "0.2.1", + "version": "0.2.2", "private": true, "description": "Package that is used at Cloudflare to power some internal features of Cloudflare Workflows.", "keywords": [ diff --git a/packages/wrangler/CHANGELOG.md b/packages/wrangler/CHANGELOG.md index 8d5e9adb7169..f60800d3f8bd 100644 --- a/packages/wrangler/CHANGELOG.md +++ b/packages/wrangler/CHANGELOG.md @@ -1,5 +1,31 @@ # wrangler +## 3.99.0 + +### Minor Changes + +- [#7425](https://github.com/cloudflare/workers-sdk/pull/7425) [`8757579`](https://github.com/cloudflare/workers-sdk/commit/8757579a47d675909230a51f8e09d1611d5cadb1) Thanks [@CarmenPopoviciu](https://github.com/CarmenPopoviciu)! - feat: Make DX improvements in `wrangler dev --remote` + + Workers + Assets projects have, in certain situations, a relatively degraded `wrangler dev --remote` developer experience, as opposed to Workers proper projects. This is due to the fact that, for Workers + Assets, we need to make extra API calls to: + + 1. check for asset files changes + 2. upload the changed assets, if any + + This commit improves the `wrangler dev --remote` DX for Workers + Assets, for use cases when the User Worker/assets change while the API calls for previous changes are still in flight. For such use cases, we have put an exit early strategy in place, that drops the event handler execution of the previous changes, in favour of the handler triggered by the new changes. + +- [#7537](https://github.com/cloudflare/workers-sdk/pull/7537) [`086a6b8`](https://github.com/cloudflare/workers-sdk/commit/086a6b8c613b9c8f0f7c4933ffd68f38f7771c3f) Thanks [@WillTaylorDev](https://github.com/WillTaylorDev)! - Provide validation around assets.experimental_serve_directly + +- [#7568](https://github.com/cloudflare/workers-sdk/pull/7568) [`2bbcb93`](https://github.com/cloudflare/workers-sdk/commit/2bbcb938b1e14cf21da5dc20ce0c8b9bea0f6aad) Thanks [@WillTaylorDev](https://github.com/WillTaylorDev)! - Warn users when using smart placement with Workers + Assets and `serve_directly` is set to `false` + +### Patch Changes + +- [#7521](https://github.com/cloudflare/workers-sdk/pull/7521) [`48e7e10`](https://github.com/cloudflare/workers-sdk/commit/48e7e1035f489639564948edd3789b1740a7873d) Thanks [@emily-shen](https://github.com/emily-shen)! - feat: add experimental_patchConfig() + + `experimental_patchConfig()` can add to a user's config file. It preserves comments if its a `wrangler.jsonc`. However, it is not suitable for `wrangler.toml` with comments as we cannot preserve comments on write. + +- Updated dependencies [[`1488e11`](https://github.com/cloudflare/workers-sdk/commit/1488e118b4a43d032e4f2e69afa1c16c2e54aff6), [`7216835`](https://github.com/cloudflare/workers-sdk/commit/7216835bf7489804905751c6b52e75a8945e7974)]: + - miniflare@3.20241218.0 + ## 3.98.0 ### Minor Changes diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 056ebb8b70f6..32ed9d2bd7c8 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -1,6 +1,6 @@ { "name": "wrangler", - "version": "3.98.0", + "version": "3.99.0", "description": "Command-line interface for all things Cloudflare Workers", "keywords": [ "wrangler", From dbf7aac6f58c7dbd7de6d6fd1fb9dc562e36c11b Mon Sep 17 00:00:00 2001 From: Edmund Hung Date: Thu, 19 Dec 2024 19:19:45 +0000 Subject: [PATCH 20/53] feat(cloudflare-workers-bindings-extension): list all binding types (#7597) * feat(cloudflare-workers-bindings-extension): list all binding types * add changeset * add logfwdr, pipelines & send_email * replace getBindingName with friendlyBindingNames --- .changeset/five-poems-own.md | 5 + .../src/show-bindings.ts | 525 +++++++++++++++-- .../src/test/suite/extension.test.ts | 538 ++++++++++++++---- 3 files changed, 908 insertions(+), 160 deletions(-) create mode 100644 .changeset/five-poems-own.md diff --git a/.changeset/five-poems-own.md b/.changeset/five-poems-own.md new file mode 100644 index 000000000000..2b6644db1ab5 --- /dev/null +++ b/.changeset/five-poems-own.md @@ -0,0 +1,5 @@ +--- +"cloudflare-workers-bindings-extension": patch +--- + +Updates the bindings view to list all binding types diff --git a/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts b/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts index 5e4c7f715daf..0c83d6426efa 100644 --- a/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts +++ b/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts @@ -1,30 +1,60 @@ import * as vscode from "vscode"; import { importWrangler } from "./wrangler"; -type Config = ReturnType< +export type Config = ReturnType< ReturnType["experimental_readRawConfig"] >["rawConfig"]; -type Node = - | { - type: "env"; - config: Config; - env: string | null; - } - | { +export type Environment = Required["env"][string]; + +export type BindingType = + | "kv_namespaces" + | "durable_objects" + | "r2_buckets" + | "d1_databases" + | "ai" + | "analytics_engine_datasets" + | "assets" + | "dispatch_namespaces" + | "queues" + | "browser" + | "hyperdrive" + | "mtls_certificates" + | "services" + | "tail_consumers" + | "vectorize" + | "version_metadata" + | "workflows" + | "pipelines" + | "send_email" + | "logfwdr" + | "vars" + | "unsafe"; + +type EnvNode = { + type: "env"; + config: Environment; + name: string | null; +}; + +type BindingNode = Exclude< + { + [Name in BindingType]: { type: "binding"; - config: Config; - env: string | null; - binding: string; - } - | { - type: "resource"; - config: Config; - env: string | null; - binding: string; - name: string; - description?: string; - }; + name: Name; + config: Required[Name]; + }; + }[BindingType], + undefined +>; + +type ResourceNode = { + type: "resource"; + name: string; + description?: string; +}; + +type Node = EnvNode | BindingNode | ResourceNode; export class BindingsProvider implements vscode.TreeDataProvider { // Event emitter for refreshing the tree @@ -45,7 +75,7 @@ export class BindingsProvider implements vscode.TreeDataProvider { switch (node.type) { case "env": { const item = new vscode.TreeItem( - node.env ?? "Top-level env", + node.name ?? "Top-level env", vscode.TreeItemCollapsibleState.Expanded ); @@ -53,7 +83,7 @@ export class BindingsProvider implements vscode.TreeDataProvider { } case "binding": { return new vscode.TreeItem( - node.binding, + friendlyBindingNames[node.name], vscode.TreeItemCollapsibleState.Expanded ); } @@ -74,32 +104,30 @@ export class BindingsProvider implements vscode.TreeDataProvider { async getChildren(node?: Node): Promise { if (!node) { - const config = await getWranglerConfig(); + const wranglerConfig = await getWranglerConfig(); - if (!config) { + if (!wranglerConfig) { return []; } const topLevelEnvNode: Node = { type: "env", - config, - env: null, + name: null, + config: wranglerConfig, }; const children: Node[] = []; - for (const env of Object.keys(config.env ?? {})) { + for (const [name, config] of Object.entries(wranglerConfig.env ?? {})) { const node: Node = { - ...topLevelEnvNode, - env, + type: "env", + name, + config, }; const grandChildren = await this.getChildren(node); // Include the environment only if it has any bindings if (grandChildren.length > 0) { - children.push({ - ...topLevelEnvNode, - env, - }); + children.push(node); } } @@ -120,74 +148,402 @@ export class BindingsProvider implements vscode.TreeDataProvider { switch (node.type) { case "env": { - const children: Node[] = []; - const env = node.env ? node.config.env?.[node.env] : node.config; + const children: BindingNode[] = []; + + if (hasBinding(node.config.kv_namespaces)) { + children.push({ + type: "binding", + name: "kv_namespaces", + config: node.config.kv_namespaces, + }); + } + + if (hasBinding(node.config.r2_buckets)) { + children.push({ + type: "binding", + name: "r2_buckets", + config: node.config.r2_buckets, + }); + } + + if (hasBinding(node.config.d1_databases)) { + children.push({ + type: "binding", + name: "d1_databases", + config: node.config.d1_databases, + }); + } + + if (hasBinding(node.config.durable_objects?.bindings)) { + children.push({ + type: "binding", + name: "durable_objects", + config: node.config.durable_objects, + }); + } - if (env?.kv_namespaces && env.kv_namespaces.length > 0) { + if (hasBinding(node.config.ai)) { children.push({ - ...node, type: "binding", - binding: "KV Namespaces", + name: "ai", + config: node.config.ai, }); } - if (env?.r2_buckets && env.r2_buckets.length > 0) { + if (hasBinding(node.config.analytics_engine_datasets)) { children.push({ - ...node, type: "binding", - binding: "R2 Buckets", + name: "analytics_engine_datasets", + config: node.config.analytics_engine_datasets, }); } - if (env?.d1_databases && env.d1_databases.length > 0) { + if (hasBinding(node.config.browser)) { children.push({ - ...node, type: "binding", - binding: "D1 Databases", + name: "browser", + config: node.config.browser, + }); + } + + if (hasBinding(node.config.hyperdrive)) { + children.push({ + type: "binding", + name: "hyperdrive", + config: node.config.hyperdrive, + }); + } + + if (hasBinding(node.config.mtls_certificates)) { + children.push({ + type: "binding", + name: "mtls_certificates", + config: node.config.mtls_certificates, + }); + } + + if (hasBinding(node.config.services)) { + children.push({ + type: "binding", + name: "services", + config: node.config.services, + }); + } + + if (hasBinding(node.config.assets)) { + children.push({ + type: "binding", + name: "assets", + config: node.config.assets, + }); + } + + if (hasBinding(node.config.tail_consumers)) { + children.push({ + type: "binding", + name: "tail_consumers", + config: node.config.tail_consumers, + }); + } + + if (hasBinding(node.config.vectorize)) { + children.push({ + type: "binding", + name: "vectorize", + config: node.config.vectorize, + }); + } + + if (hasBinding(node.config.version_metadata)) { + children.push({ + type: "binding", + name: "version_metadata", + config: node.config.version_metadata, + }); + } + + if (hasBinding(node.config.dispatch_namespaces)) { + children.push({ + type: "binding", + name: "dispatch_namespaces", + config: node.config.dispatch_namespaces, + }); + } + + if (hasBinding(node.config.queues?.producers)) { + children.push({ + type: "binding", + name: "queues", + config: node.config.queues, + }); + } + + if (hasBinding(node.config.workflows)) { + children.push({ + type: "binding", + name: "workflows", + config: node.config.workflows, + }); + } + + if (hasBinding(node.config.send_email)) { + children.push({ + type: "binding", + name: "send_email", + config: node.config.send_email, + }); + } + + if (hasBinding(node.config.logfwdr)) { + children.push({ + type: "binding", + name: "logfwdr", + config: node.config.logfwdr, + }); + } + + if (hasBinding(node.config.pipelines)) { + children.push({ + type: "binding", + name: "pipelines", + config: node.config.pipelines, + }); + } + + if (hasBinding(node.config.vars)) { + children.push({ + type: "binding", + name: "vars", + config: node.config.vars, + }); + } + + if (hasBinding(node.config.unsafe?.bindings)) { + children.push({ + type: "binding", + name: "unsafe", + config: node.config.unsafe, }); } return children; } case "binding": { - const children: Node[] = []; - const env = node.env ? node.config.env?.[node.env] : node.config; + const children: ResourceNode[] = []; - switch (node.binding) { - case "KV Namespaces": { - for (const kv of env?.kv_namespaces ?? []) { + switch (node.name) { + case "kv_namespaces": { + for (const item of node.config) { children.push({ - ...node, type: "resource", - name: kv.binding, - description: kv.id, + name: item.binding, + description: item.id, }); } break; } - case "R2 Buckets": { - for (const r2 of env?.r2_buckets ?? []) { + case "r2_buckets": { + for (const item of node.config) { children.push({ - ...node, type: "resource", - name: r2.binding, - description: r2.bucket_name, + name: item.binding, + description: item.bucket_name, }); } - break; } - case "D1 Databases": { - for (const d1 of env?.d1_databases ?? []) { + case "d1_databases": { + for (const item of node.config) { children.push({ - ...node, type: "resource", - name: d1.binding, - description: d1.database_id, + name: item.binding, + description: item.database_id, }); } break; } + case "assets": { + children.push({ + type: "resource", + name: node.config.binding ?? "n/a", + description: node.config.directory, + }); + break; + } + case "ai": { + children.push({ + type: "resource", + name: node.config.binding, + }); + break; + } + case "analytics_engine_datasets": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.binding, + description: item.dataset, + }); + } + break; + } + case "durable_objects": { + for (const item of node.config.bindings) { + children.push({ + type: "resource", + name: item.name, + description: item.class_name, + }); + } + break; + } + case "browser": { + children.push({ + type: "resource", + name: node.config.binding, + }); + break; + } + case "hyperdrive": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.binding, + description: item.id, + }); + } + break; + } + case "mtls_certificates": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.binding, + description: item.certificate_id, + }); + } + break; + } + case "services": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.binding, + description: item.service, + }); + } + break; + } + case "tail_consumers": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.service, + description: item.environment, + }); + } + break; + } + case "vars": { + for (const [name, value] of Object.entries(node.config)) { + children.push({ + type: "resource", + name, + description: JSON.stringify(value), + }); + } + break; + } + case "vectorize": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.binding, + description: item.index_name, + }); + } + break; + } + case "version_metadata": { + children.push({ + type: "resource", + name: node.config.binding, + }); + break; + } + case "workflows": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.binding, + description: item.class_name, + }); + } + break; + } + case "logfwdr": { + for (const item of node.config.bindings ?? []) { + children.push({ + type: "resource", + name: item.name, + description: item.destination, + }); + } + break; + } + case "pipelines": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.binding, + description: item.pipeline, + }); + } + break; + } + case "send_email": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.name, + description: item.destination_address, + }); + } + break; + } + case "dispatch_namespaces": { + for (const item of node.config) { + children.push({ + type: "resource", + name: item.binding, + description: item.namespace, + }); + } + break; + } + case "queues": { + for (const item of node.config.producers ?? []) { + children.push({ + type: "resource", + name: item.binding, + description: item.queue, + }); + } + break; + } + case "unsafe": { + for (const item of node.config.bindings ?? []) { + children.push({ + type: "resource", + name: item.name, + description: item.type, + }); + } + break; + } + default: { + throw new Error(`Unknown binding type: ${node}`); + } } return children; @@ -198,6 +554,49 @@ export class BindingsProvider implements vscode.TreeDataProvider { } } +// Copied from https://github.com/cloudflare/workers-sdk/blob/178fd0123d8d4baf9f395bd8aade2cf1dccb6aa8/packages/wrangler/src/utils/print-bindings.ts#L18-L46 +// With `tail_consumers` added and legacy bindings removed (`data_blobs`, `text_blobs`, `wasm_modules`) +export const friendlyBindingNames: Record = { + durable_objects: "Durable Objects", + kv_namespaces: "KV Namespaces", + send_email: "Send Email", + queues: "Queues", + d1_databases: "D1 Databases", + vectorize: "Vectorize Indexes", + hyperdrive: "Hyperdrive Configs", + r2_buckets: "R2 Buckets", + logfwdr: "logfwdr", + services: "Services", + analytics_engine_datasets: "Analytics Engine Datasets", + browser: "Browser", + ai: "AI", + version_metadata: "Worker Version Metadata", + unsafe: "Unsafe Metadata", + vars: "Vars", + dispatch_namespaces: "Dispatch Namespaces", + mtls_certificates: "mTLS Certificates", + workflows: "Workflows", + pipelines: "Pipelines", + assets: "Assets", + tail_consumers: "Tail Consumers", +} as const; + +// Check if the binding has any items +// This is used to filter out empty bindings +function hasBinding | Array>( + config: Config | undefined +): config is Config { + if (!config) { + return false; + } + + if (Array.isArray(config)) { + return config.length > 0; + } + + return Object.keys(config).length > 0; +} + // Finds the first wrangler config file in the workspace and parse it export async function getWranglerConfig(): Promise { const configUri = await getConfigUri(); diff --git a/packages/cloudflare-workers-bindings-extension/src/test/suite/extension.test.ts b/packages/cloudflare-workers-bindings-extension/src/test/suite/extension.test.ts index 41d0b986ada5..0d3b4cc9437f 100644 --- a/packages/cloudflare-workers-bindings-extension/src/test/suite/extension.test.ts +++ b/packages/cloudflare-workers-bindings-extension/src/test/suite/extension.test.ts @@ -2,7 +2,9 @@ import assert from "node:assert"; import * as fs from "node:fs/promises"; import * as path from "node:path"; import * as vscode from "vscode"; +import { friendlyBindingNames } from "../../show-bindings"; import type { Result } from "../../extension"; +import type { BindingType, Config } from "../../show-bindings"; // Environment variable set by the test runner (See packages/cloudflare-workers-bindings-extension/src/test/runTest.ts) assert( @@ -26,29 +28,140 @@ describe("Extension Test Suite", () => { }); it("lists bindings based on the wrangler config", async () => { - const config = { - name: "test", - kv_namespaces: [ - { - binding: "cache", - id: "xx-yyyy-zzz", + const cleanup = await seed({ + "wrangler.json": generateWranglerConfig({ + ai: { + binding: "AI", }, - ], - r2_buckets: [ - { - binding: "images", - bucket_name: "something", + analytics_engine_datasets: [ + { + binding: "ANALYTICS", + dataset: "", + }, + ], + assets: { + binding: "ASSETS", + directory: "./public/", }, - ], - d1_databases: [ - { - binding: "db", - database_id: "xxxxyyyyzzzzz", + browser: { + binding: "MYBROWSER", }, - ], - }; - const cleanup = await seed({ - "wrangler.json": JSON.stringify(config), + d1_databases: [ + { + binding: "DB", + database_id: "", + }, + ], + dispatch_namespaces: [ + { + binding: "DISPATCHER", + namespace: "testing", + }, + ], + durable_objects: { + bindings: [ + { + name: "MY_DURABLE_OBJECT", + class_name: "MyDurableObject", + }, + ], + }, + vars: { + API_HOST: "example.com", + API_ACCOUNT_ID: "example_user", + SERVICE_X_DATA: { + URL: "service-x-api.dev.example", + MY_ID: 123, + }, + }, + hyperdrive: [ + { + binding: "HYPERDRIVE", + id: "", + }, + ], + kv_namespaces: [ + { + binding: "CACHE", + id: "", + }, + ], + mtls_certificates: [ + { + binding: "MY_CERT", + certificate_id: "", + }, + ], + queues: { + producers: [ + { + queue: "MY-QUEUE-NAME", + binding: "MY_QUEUE", + }, + ], + }, + r2_buckets: [ + { + binding: "IMAGES", + bucket_name: "", + }, + ], + logfwdr: { + bindings: [ + { + name: "LOG", + destination: "", + }, + ], + }, + pipelines: [ + { + binding: "PIPELINE", + pipeline: "", + }, + ], + send_email: [ + { + name: "EMAIL", + destination_address: "", + }, + ], + services: [ + { + binding: "", + service: "", + }, + ], + vectorize: [ + { + binding: "VECTORIZE", + index_name: "embeddings-index", + }, + ], + version_metadata: { + binding: "CF_VERSION_METADATA", + }, + workflows: [ + { + name: "workflows-starter", + binding: "MY_WORKFLOW", + class_name: "MyWorkflow", + }, + ], + unsafe: { + bindings: [ + { + name: "MY_RATE_LIMITER", + type: "ratelimit", + namespace_id: "1001", + simple: { + limit: 100, + period: 60, + }, + }, + ], + }, + }), }); try { @@ -61,93 +174,322 @@ describe("Extension Test Suite", () => { children.map((child) => bindingsProvider.getTreeItem(child)), [ { - label: "KV Namespaces", + label: friendlyBindingNames.kv_namespaces, collapsibleState: vscode.TreeItemCollapsibleState.Expanded, }, { - label: "R2 Buckets", + label: friendlyBindingNames.r2_buckets, collapsibleState: vscode.TreeItemCollapsibleState.Expanded, }, { - label: "D1 Databases", + label: friendlyBindingNames.d1_databases, collapsibleState: vscode.TreeItemCollapsibleState.Expanded, }, - ] - ); - - const [kv, r2, d1] = children; - - const kvChildren = await bindingsProvider.getChildren(kv); - assert.deepEqual( - kvChildren.map((child) => bindingsProvider.getTreeItem(child)), - [ { - label: "cache", - description: "xx-yyyy-zzz", - collapsibleState: vscode.TreeItemCollapsibleState.None, + label: friendlyBindingNames.durable_objects, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, }, - ] - ); - - const r2Children = await bindingsProvider.getChildren(r2); - assert.deepEqual( - r2Children.map((child) => bindingsProvider.getTreeItem(child)), - [ { - label: "images", - description: "something", - collapsibleState: vscode.TreeItemCollapsibleState.None, + label: friendlyBindingNames.ai, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.analytics_engine_datasets, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.browser, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.hyperdrive, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.mtls_certificates, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.services, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.assets, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.vectorize, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.version_metadata, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.dispatch_namespaces, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.queues, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.workflows, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.send_email, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.logfwdr, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.pipelines, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.vars, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + }, + { + label: friendlyBindingNames.unsafe, + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, }, ] ); - const d1Children = await bindingsProvider.getChildren(d1); + async function getBindingChildren(binding: BindingType) { + const bindingNode = children.find( + (child) => child.type === "binding" && child.name === binding + ); + + if (!bindingNode) { + return []; + } + + const grandChildren = await bindingsProvider.getChildren(bindingNode); + + return grandChildren.map((child) => + bindingsProvider.getTreeItem(child) + ); + } + + assert.deepEqual(await getBindingChildren("kv_namespaces"), [ + { + label: "CACHE", + description: "", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("r2_buckets"), [ + { + label: "IMAGES", + description: "", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("d1_databases"), [ + { + label: "DB", + description: "", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("durable_objects"), [ + { + label: "MY_DURABLE_OBJECT", + description: "MyDurableObject", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("ai"), [ + { + label: "AI", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + assert.deepEqual( - d1Children.map((child) => bindingsProvider.getTreeItem(child)), + await getBindingChildren("analytics_engine_datasets"), [ { - label: "db", - description: "xxxxyyyyzzzzz", + label: "ANALYTICS", + description: "", collapsibleState: vscode.TreeItemCollapsibleState.None, }, ] ); + + assert.deepEqual(await getBindingChildren("browser"), [ + { + label: "MYBROWSER", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("hyperdrive"), [ + { + label: "HYPERDRIVE", + description: "", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("mtls_certificates"), [ + { + label: "MY_CERT", + description: "", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("services"), [ + { + label: "", + description: "", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("assets"), [ + { + label: "ASSETS", + description: "./public/", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("vectorize"), [ + { + label: "VECTORIZE", + description: "embeddings-index", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("version_metadata"), [ + { + label: "CF_VERSION_METADATA", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("dispatch_namespaces"), [ + { + label: "DISPATCHER", + description: "testing", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("queues"), [ + { + label: "MY_QUEUE", + description: "MY-QUEUE-NAME", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("workflows"), [ + { + label: "MY_WORKFLOW", + description: "MyWorkflow", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("send_email"), [ + { + label: "EMAIL", + description: "", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("logfwdr"), [ + { + label: "LOG", + description: "", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("pipelines"), [ + { + label: "PIPELINE", + description: "", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("vars"), [ + { + label: "API_HOST", + description: JSON.stringify("example.com"), + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + { + label: "API_ACCOUNT_ID", + description: JSON.stringify("example_user"), + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + { + label: "SERVICE_X_DATA", + description: JSON.stringify({ + URL: "service-x-api.dev.example", + MY_ID: 123, + }), + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); + + assert.deepEqual(await getBindingChildren("unsafe"), [ + { + label: "MY_RATE_LIMITER", + description: "ratelimit", + collapsibleState: vscode.TreeItemCollapsibleState.None, + }, + ]); } finally { await cleanup(); } }); it("groups bindings by environment if available", async () => { - const config = { - name: "test", - d1_databases: [ - { - binding: "db", - database_id: "xxxxyyyyzzzzz", - }, - ], - env: { - development: {}, - staging: { - kv_namespaces: [ - { - binding: "kv", - id: "aa-bb-cc", - }, - ], - }, - production: { - r2_buckets: [ - { - binding: "r2", - bucket_name: "something else", - }, - ], - }, - }, - }; const cleanup = await seed({ - "wrangler.json": JSON.stringify(config), + "wrangler.json": generateWranglerConfig({ + d1_databases: [ + { + binding: "db", + database_id: "xxxxyyyyzzzzz", + }, + ], + env: { + development: {}, + staging: { + kv_namespaces: [ + { + binding: "kv", + id: "aa-bb-cc", + }, + ], + }, + production: { + r2_buckets: [ + { + binding: "r2", + bucket_name: "something else", + }, + ], + }, + }, + }), }); try { @@ -184,7 +526,7 @@ describe("Extension Test Suite", () => { ), [ { - label: "D1 Databases", + label: friendlyBindingNames.d1_databases, collapsibleState: vscode.TreeItemCollapsibleState.Expanded, }, ] @@ -195,7 +537,7 @@ describe("Extension Test Suite", () => { stagingChildren.map((child) => bindingsProvider.getTreeItem(child)), [ { - label: "KV Namespaces", + label: friendlyBindingNames.kv_namespaces, collapsibleState: vscode.TreeItemCollapsibleState.Expanded, }, ] @@ -209,7 +551,7 @@ describe("Extension Test Suite", () => { ), [ { - label: "R2 Buckets", + label: friendlyBindingNames.r2_buckets, collapsibleState: vscode.TreeItemCollapsibleState.Expanded, }, ] @@ -220,21 +562,19 @@ describe("Extension Test Suite", () => { }); it("hides top level env if there is no bindings", async () => { - const config = { - name: "test", - env: { - production: { - r2_buckets: [ - { - binding: "r2", - bucket_name: "something else", - }, - ], - }, - }, - }; const cleanup = await seed({ - "wrangler.json": JSON.stringify(config), + "wrangler.json": generateWranglerConfig({ + env: { + production: { + r2_buckets: [ + { + binding: "r2", + bucket_name: "something else", + }, + ], + }, + }, + }), }); try { @@ -272,7 +612,7 @@ describe("Extension Test Suite", () => { }), // Test creating config file seed({ - "wrangler.json": JSON.stringify({ + "wrangler.json": generateWranglerConfig({ name: "test", kv_namespaces: [ { @@ -295,7 +635,7 @@ describe("Extension Test Suite", () => { }), // Test changing the config file seed({ - "wrangler.json": JSON.stringify({ + "wrangler.json": generateWranglerConfig({ name: "test", kv_namespaces: [ { @@ -345,6 +685,10 @@ function getExtension() { return extension; } +function generateWranglerConfig(config: Config) { + return JSON.stringify(config); +} + async function symlinkWranglerNodeModule() { const nodeModulesPath = path.join( process.env.VSCODE_WORKSPACE_PATH ?? "", From e3791f7d83dd5ad8cdbff5f0afae3625d39391ed Mon Sep 17 00:00:00 2001 From: emily-shen <69125074+emily-shen@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:00:06 +0000 Subject: [PATCH 21/53] feat: add validation to binding name input in vscode extension (#7600) * add validation --- .changeset/tender-cats-hammer.md | 5 + .../src/add-binding.ts | 92 +++++++++++++++++-- .../src/show-bindings.ts | 50 +++++----- 3 files changed, 115 insertions(+), 32 deletions(-) create mode 100644 .changeset/tender-cats-hammer.md diff --git a/.changeset/tender-cats-hammer.md b/.changeset/tender-cats-hammer.md new file mode 100644 index 000000000000..e79de6b2cd16 --- /dev/null +++ b/.changeset/tender-cats-hammer.md @@ -0,0 +1,5 @@ +--- +"cloudflare-workers-bindings-extension": patch +--- + +feat: add validation to binding name input in vscode extension diff --git a/packages/cloudflare-workers-bindings-extension/src/add-binding.ts b/packages/cloudflare-workers-bindings-extension/src/add-binding.ts index ec3e387c5561..cbe4d3af2657 100644 --- a/packages/cloudflare-workers-bindings-extension/src/add-binding.ts +++ b/packages/cloudflare-workers-bindings-extension/src/add-binding.ts @@ -10,7 +10,12 @@ import { window, workspace, } from "vscode"; -import { getConfigUri } from "./show-bindings"; +import { + bindingKeys, + Config, + getConfigUri, + getWranglerConfig, +} from "./show-bindings"; import { importWrangler } from "./wrangler"; class BindingType implements QuickPickItem { @@ -80,6 +85,12 @@ export async function addBindingFlow(context: ExtensionContext) { input: MultiStepInput, state: Partial ) { + const config = await getWranglerConfig(); + if (!config) { + throw new Error("No config found"); + } + const allBindingNames = getAllBindingNames(config); + let name = await input.showInputBox({ title, step: 2, @@ -87,7 +98,10 @@ export async function addBindingFlow(context: ExtensionContext) { value: state.name || "", prompt: "Choose a binding name", validate: validateNameIsUnique, + // so that we only have to get all binding names once, rather than on each validation + preExistingBindingNames: allBindingNames, placeholder: `e.g. MY_BINDING`, + required: true, }); state.name = name; return () => addToConfig(state); @@ -132,9 +146,8 @@ binding = "${state.name}" }); } - async function validateNameIsUnique(name: string) { - // TODO: actually validate uniqueness - return name === "SOME_KV_BINDING" ? "Name not unique" : undefined; + async function validateNameIsUnique(name: string, allBindingNames: string[]) { + return allBindingNames.includes(name) ? "Name not unique" : undefined; } await collectInputs(); @@ -169,10 +182,15 @@ interface InputBoxParameters { totalSteps: number; value: string; prompt: string; - validate: (value: string) => Promise; + validate: ( + value: string, + existingNames: string[] + ) => Promise; buttons?: QuickInputButton[]; ignoreFocusOut?: boolean; placeholder?: string; + required?: boolean; + preExistingBindingNames: string[]; } export class MultiStepInput { @@ -275,6 +293,8 @@ export class MultiStepInput { buttons, ignoreFocusOut, placeholder, + required, + preExistingBindingNames, }: P) { const disposables: Disposable[] = []; try { @@ -293,7 +313,7 @@ export class MultiStepInput { ...(this.steps.length > 1 ? [QuickInputButtons.Back] : []), ...(buttons || []), ]; - let validating = validate(""); + let validating = validate("", preExistingBindingNames); disposables.push( input.onDidTriggerButton((item) => { if (item === QuickInputButtons.Back) { @@ -306,14 +326,16 @@ export class MultiStepInput { const value = input.value; input.enabled = false; input.busy = true; - if (!(await validate(value))) { + if (required && !value) { + input.validationMessage = "You must provide a binding name"; + } else if (!(await validate(value, preExistingBindingNames))) { resolve(value); } input.enabled = true; input.busy = false; }), input.onDidChangeValue(async (text) => { - const current = validate(text); + const current = validate(text, preExistingBindingNames); validating = current; const validationMessage = await current; if (current === validating) { @@ -332,3 +354,57 @@ export class MultiStepInput { } } } + +const getAllBindingNames = (config: Config) => { + return bindingKeys + .map((key) => { + const bindingsByType = config[key]; + return getBindingNames(bindingsByType); + }) + .flat(); +}; +const getBindingNames = (value: unknown): string[] => { + if (typeof value !== "object" || value === null) { + return []; + } + if (isBindingList(value)) { + return value.bindings.map(({ name }) => name); + } else if (isNamespaceList(value)) { + return value.map(({ binding }) => binding); + } else if (isRecord(value)) { + // browser and AI bindings are single values with a similar shape + // { binding = "name" } + if (value["binding"] !== undefined) { + return [value["binding"] as string]; + } + return Object.keys(value).filter((k) => value[k] !== undefined); + } else { + return []; + } +}; +const isBindingList = ( + value: unknown +): value is { + bindings: { + name: string; + }[]; +} => + isRecord(value) && + "bindings" in value && + Array.isArray(value.bindings) && + value.bindings.every( + (binding) => + isRecord(binding) && "name" in binding && typeof binding.name === "string" + ); + +const isNamespaceList = (value: unknown): value is { binding: string }[] => + Array.isArray(value) && + value.every( + (entry) => + isRecord(entry) && "binding" in entry && typeof entry.binding === "string" + ); + +const isRecord = ( + value: unknown +): value is Record => + typeof value === "object" && value !== null && !Array.isArray(value); diff --git a/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts b/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts index 0c83d6426efa..a5e449539a9b 100644 --- a/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts +++ b/packages/cloudflare-workers-bindings-extension/src/show-bindings.ts @@ -6,30 +6,32 @@ export type Config = ReturnType< >["rawConfig"]; export type Environment = Required["env"][string]; - -export type BindingType = - | "kv_namespaces" - | "durable_objects" - | "r2_buckets" - | "d1_databases" - | "ai" - | "analytics_engine_datasets" - | "assets" - | "dispatch_namespaces" - | "queues" - | "browser" - | "hyperdrive" - | "mtls_certificates" - | "services" - | "tail_consumers" - | "vectorize" - | "version_metadata" - | "workflows" - | "pipelines" - | "send_email" - | "logfwdr" - | "vars" - | "unsafe"; +export const bindingKeys = [ + "kv_namespaces", + "durable_objects", + "r2_buckets", + "d1_databases", + "ai", + "analytics_engine_datasets", + "assets", + "dispatch_namespaces", + "queues", + "browser", + "hyperdrive", + "mtls_certificates", + "services", + "tail_consumers", + "vectorize", + "version_metadata", + "workflows", + "pipelines", + "send_email", + "logfwdr", + "vars", + "unsafe", +] as const; + +export type BindingType = (typeof bindingKeys)[number]; type EnvNode = { type: "env"; From 697f166afb279d494279259460e93cd0aa37e7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Somhairle=20MacLe=C3=B2id?= Date: Thu, 19 Dec 2024 20:22:30 +0000 Subject: [PATCH 22/53] Add JSON schema for Wrangler (#7602) * Add JSON schema for Wrangler * Create tough-tables-sleep.md * Use new icon --- .changeset/tough-tables-sleep.md | 5 +++++ .../media/cloudflare-workers-outline.svg | 11 +++++++++++ .../package.json | 10 ++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .changeset/tough-tables-sleep.md create mode 100644 packages/cloudflare-workers-bindings-extension/media/cloudflare-workers-outline.svg diff --git a/.changeset/tough-tables-sleep.md b/.changeset/tough-tables-sleep.md new file mode 100644 index 000000000000..d1877ac6dfe4 --- /dev/null +++ b/.changeset/tough-tables-sleep.md @@ -0,0 +1,5 @@ +--- +"cloudflare-workers-bindings-extension": patch +--- + +Add JSON schema for Wrangler config files diff --git a/packages/cloudflare-workers-bindings-extension/media/cloudflare-workers-outline.svg b/packages/cloudflare-workers-bindings-extension/media/cloudflare-workers-outline.svg new file mode 100644 index 000000000000..51fc58572cf0 --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/media/cloudflare-workers-outline.svg @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/packages/cloudflare-workers-bindings-extension/package.json b/packages/cloudflare-workers-bindings-extension/package.json index 6a9b34d2770f..aa71267aad99 100644 --- a/packages/cloudflare-workers-bindings-extension/package.json +++ b/packages/cloudflare-workers-bindings-extension/package.json @@ -38,6 +38,12 @@ "icon": "$(add)" } ], + "jsonValidation": [ + { + "fileMatch": "**/wrangler.{json,jsonc,toml}", + "url": "https://www.unpkg.com/wrangler/config-schema.json" + } + ], "menus": { "view/title": [ { @@ -57,7 +63,7 @@ { "id": "cloudflare-workers-bindings", "name": "Bindings", - "icon": "media/cf-workers-logo.svg", + "icon": "media/cloudflare-workers-outline.svg", "contextualTitle": "Cloudflare Workers Bindings" } ] @@ -67,7 +73,7 @@ { "id": "cloudflare-workers", "title": "Cloudflare Workers", - "icon": "media/cf-workers-logo.svg" + "icon": "media/cloudflare-workers-outline.svg" } ] }, From e4c79bba8f93aa3b29caae21befa8c45722fde51 Mon Sep 17 00:00:00 2001 From: ANT Bot <116369605+workers-devprod@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:21:45 +0000 Subject: [PATCH 23/53] Version Packages (#7601) * Version Packages * Fix publishing * Add publish secret --------- Co-authored-by: github-actions[bot] Co-authored-by: Samuel Macleod --- .changeset/five-poems-own.md | 5 ----- .changeset/tender-cats-hammer.md | 5 ----- .changeset/tough-tables-sleep.md | 5 ----- .github/workflows/changesets.yml | 1 + .../cloudflare-workers-bindings-extension/CHANGELOG.md | 10 ++++++++++ .../cloudflare-workers-bindings-extension/package.json | 6 ++++-- .../__tests__/deploy-non-npm-packages.test.ts | 1 + 7 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 .changeset/five-poems-own.md delete mode 100644 .changeset/tender-cats-hammer.md delete mode 100644 .changeset/tough-tables-sleep.md diff --git a/.changeset/five-poems-own.md b/.changeset/five-poems-own.md deleted file mode 100644 index 2b6644db1ab5..000000000000 --- a/.changeset/five-poems-own.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"cloudflare-workers-bindings-extension": patch ---- - -Updates the bindings view to list all binding types diff --git a/.changeset/tender-cats-hammer.md b/.changeset/tender-cats-hammer.md deleted file mode 100644 index e79de6b2cd16..000000000000 --- a/.changeset/tender-cats-hammer.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"cloudflare-workers-bindings-extension": patch ---- - -feat: add validation to binding name input in vscode extension diff --git a/.changeset/tough-tables-sleep.md b/.changeset/tough-tables-sleep.md deleted file mode 100644 index d1877ac6dfe4..000000000000 --- a/.changeset/tough-tables-sleep.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"cloudflare-workers-bindings-extension": patch ---- - -Add JSON schema for Wrangler config files diff --git a/.github/workflows/changesets.yml b/.github/workflows/changesets.yml index 603d008f5c58..987d6a77f9a0 100644 --- a/.github/workflows/changesets.yml +++ b/.github/workflows/changesets.yml @@ -60,3 +60,4 @@ jobs: WORKERS_NEW_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.WORKERS_NEW_CLOUDFLARE_ACCOUNT_ID }} WORKERS_NEW_CLOUDFLARE_API_TOKEN: ${{ secrets.WORKERS_NEW_CLOUDFLARE_API_TOKEN }} WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN: ${{ secrets.WORKERS_DEPLOY_AND_CONFIG_CLOUDFLARE_API_TOKEN }} + VSCE_PAT: ${{ secrets.VSCE_PAT }} diff --git a/packages/cloudflare-workers-bindings-extension/CHANGELOG.md b/packages/cloudflare-workers-bindings-extension/CHANGELOG.md index 69304f03a8c2..dbb11c826999 100644 --- a/packages/cloudflare-workers-bindings-extension/CHANGELOG.md +++ b/packages/cloudflare-workers-bindings-extension/CHANGELOG.md @@ -1,5 +1,15 @@ # cloudflare-workers-bindings-extension +## 0.0.9 + +### Patch Changes + +- [#7597](https://github.com/cloudflare/workers-sdk/pull/7597) [`dbf7aac`](https://github.com/cloudflare/workers-sdk/commit/dbf7aac6f58c7dbd7de6d6fd1fb9dc562e36c11b) Thanks [@edmundhung](https://github.com/edmundhung)! - Updates the bindings view to list all binding types + +- [#7600](https://github.com/cloudflare/workers-sdk/pull/7600) [`e3791f7`](https://github.com/cloudflare/workers-sdk/commit/e3791f7d83dd5ad8cdbff5f0afae3625d39391ed) Thanks [@emily-shen](https://github.com/emily-shen)! - feat: add validation to binding name input in vscode extension + +- [#7602](https://github.com/cloudflare/workers-sdk/pull/7602) [`697f166`](https://github.com/cloudflare/workers-sdk/commit/697f166afb279d494279259460e93cd0aa37e7a9) Thanks [@penalosa](https://github.com/penalosa)! - Add JSON schema for Wrangler config files + ## 0.0.8 ### Patch Changes diff --git a/packages/cloudflare-workers-bindings-extension/package.json b/packages/cloudflare-workers-bindings-extension/package.json index aa71267aad99..b33e44a88f4a 100644 --- a/packages/cloudflare-workers-bindings-extension/package.json +++ b/packages/cloudflare-workers-bindings-extension/package.json @@ -1,7 +1,8 @@ { "name": "cloudflare-workers-bindings-extension", "displayName": "Cloudflare Workers", - "version": "0.0.8", + "version": "0.0.9", + "private": true, "description": "Manage your Cloudflare Worker's bindings", "categories": [ "Other" @@ -113,6 +114,7 @@ }, "workers-sdk": { "prerelease": true, - "type": "extension" + "type": "extension", + "deploy": true } } diff --git a/tools/deployments/__tests__/deploy-non-npm-packages.test.ts b/tools/deployments/__tests__/deploy-non-npm-packages.test.ts index 1e3265fbf5ca..b940e62bbedf 100644 --- a/tools/deployments/__tests__/deploy-non-npm-packages.test.ts +++ b/tools/deployments/__tests__/deploy-non-npm-packages.test.ts @@ -98,6 +98,7 @@ describe("findDeployablePackageNames()", () => { expect(findDeployablePackageNames()).toMatchInlineSnapshot(` Set { "@cloudflare/chrome-devtools-patches", + "cloudflare-workers-bindings-extension", "devprod-status-bot", "edge-preview-authenticated-proxy", "format-errors", From 6c2f17341037962bdf675e7008a4d91059465e16 Mon Sep 17 00:00:00 2001 From: Carmen Popoviciu Date: Fri, 20 Dec 2024 18:27:30 +0100 Subject: [PATCH 24/53] feat(wrangler): Capture Workers with static assets in the telemetry data (#7604) * feat(wrangler): Capture Workers with static assets in the telemetry data * add changeset --- .changeset/long-houses-mate.md | 11 ++++ .../wrangler/src/__tests__/metrics.test.ts | 54 +++++++++++++++++++ packages/wrangler/src/index.ts | 1 + .../wrangler/src/metrics/metrics-config.ts | 4 ++ .../src/metrics/metrics-dispatcher.ts | 1 + packages/wrangler/src/metrics/types.ts | 4 ++ 6 files changed, 75 insertions(+) create mode 100644 .changeset/long-houses-mate.md diff --git a/.changeset/long-houses-mate.md b/.changeset/long-houses-mate.md new file mode 100644 index 000000000000..e3a4f88391c4 --- /dev/null +++ b/.changeset/long-houses-mate.md @@ -0,0 +1,11 @@ +--- +"wrangler": minor +--- + +feat: Capture Workers with static assets in the telemetry data + +We want to measure accurately what this number of Workers + Assets projects running in remote mode is, as this number will be a very helpful data point down the road, when more decisions around remote mode will have to be taken. + +These changes add this kind of insight to our telemetry data, by capturing whether the command running is in the context of a Workers + Assets project. + +N.B. With these changes in place we will be capturing the Workers + Assets context for all commands, not just wrangler dev --remote. diff --git a/packages/wrangler/src/__tests__/metrics.test.ts b/packages/wrangler/src/__tests__/metrics.test.ts index ffccf2e75a9a..4dfa9f580013 100644 --- a/packages/wrangler/src/__tests__/metrics.test.ts +++ b/packages/wrangler/src/__tests__/metrics.test.ts @@ -1,3 +1,4 @@ +import * as fs from "node:fs"; import { http, HttpResponse } from "msw"; import { vi } from "vitest"; import { CI } from "../is-ci"; @@ -189,6 +190,7 @@ describe("metrics", () => { isPagesCI: false, isWorkersCI: false, isInteractive: true, + hasAssets: false, argsUsed: [], argsCombination: "", command: "wrangler docs", @@ -359,6 +361,58 @@ describe("metrics", () => { expect(std.debug).toContain('isWorkersCI":true'); }); + it("should capture Workers + Assets projects", async () => { + writeWranglerConfig({ assets: { directory: "./public" } }); + + // set up empty static assets directory + fs.mkdirSync("./public"); + + const requests = mockMetricRequest(); + + await runWrangler("docs arg"); + expect(requests.count).toBe(2); + + // command started + const expectedStartReq = { + deviceId: "f82b1f46-eb7b-4154-aa9f-ce95f23b2288", + event: "wrangler command started", + timestamp: 1733961600000, + properties: { + amplitude_session_id: 1733961600000, + amplitude_event_id: 0, + ...{ ...reused, hasAssets: true }, + }, + }; + expect(std.debug).toContain( + `Posting data ${JSON.stringify(expectedStartReq)}` + ); + + // command completed + const expectedCompleteReq = { + deviceId: "f82b1f46-eb7b-4154-aa9f-ce95f23b2288", + event: "wrangler command completed", + timestamp: 1733961606000, + properties: { + amplitude_session_id: 1733961600000, + amplitude_event_id: 1, + ...{ ...reused, hasAssets: true }, + durationMs: 6000, + durationSeconds: 6, + durationMinutes: 0.1, + }, + }; + expect(std.debug).toContain( + `Posting data ${JSON.stringify(expectedCompleteReq)}` + ); + expect(std.out).toMatchInlineSnapshot(` + " + Cloudflare collects anonymous telemetry about your usage of Wrangler. Learn more at https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md + Opening a link in your default browser: FAKE_DOCS_URL:{\\"params\\":\\"query=arg&hitsPerPage=1&getRankingInfo=0\\"}" + `); + expect(std.warn).toMatchInlineSnapshot(`""`); + expect(std.err).toMatchInlineSnapshot(`""`); + }); + it("should not send arguments with wrangler login", async () => { const requests = mockMetricRequest(); diff --git a/packages/wrangler/src/index.ts b/packages/wrangler/src/index.ts index 2adb350657a4..0a8f6e8d894c 100644 --- a/packages/wrangler/src/index.ts +++ b/packages/wrangler/src/index.ts @@ -1155,6 +1155,7 @@ export async function main(argv: string[]): Promise { const { rawConfig, configPath } = experimental_readRawConfig(args); dispatcher = getMetricsDispatcher({ sendMetrics: rawConfig.send_metrics, + hasAssets: !!rawConfig.assets?.directory, configPath, }); } catch (e) { diff --git a/packages/wrangler/src/metrics/metrics-config.ts b/packages/wrangler/src/metrics/metrics-config.ts index 9cdb3766f96e..adf0cf4529af 100644 --- a/packages/wrangler/src/metrics/metrics-config.ts +++ b/packages/wrangler/src/metrics/metrics-config.ts @@ -23,6 +23,10 @@ export interface MetricsConfigOptions { * Otherwise, infer the enabled value from the user configuration. */ sendMetrics?: boolean; + /** + * Captures whether this is a Worker with static assets + */ + hasAssets?: boolean; /** * Path to wrangler configuration file, if it exists. Used for configFileType property */ diff --git a/packages/wrangler/src/metrics/metrics-dispatcher.ts b/packages/wrangler/src/metrics/metrics-dispatcher.ts index 53f2e32b3a00..97d5e62c626f 100644 --- a/packages/wrangler/src/metrics/metrics-dispatcher.ts +++ b/packages/wrangler/src/metrics/metrics-dispatcher.ts @@ -111,6 +111,7 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) { isPagesCI: isPagesCI(), isWorkersCI: isWorkersCI(), isInteractive: isInteractive(), + hasAssets: options.hasAssets ?? false, argsUsed, argsCombination, }; diff --git a/packages/wrangler/src/metrics/types.ts b/packages/wrangler/src/metrics/types.ts index d2b514824fbb..28ebdf2c2396 100644 --- a/packages/wrangler/src/metrics/types.ts +++ b/packages/wrangler/src/metrics/types.ts @@ -52,6 +52,10 @@ export type CommonEventProperties = { * Whether the Wrangler client is running in an interactive instance */ isInteractive: boolean; + /** + * Whether this is a Worker with static assets + */ + hasAssets: boolean; /** * A list of normalised argument names/flags that were passed in or are set by default. * Excludes boolean flags set to false. From cac7fa6160ecc70d8f188de1f494a07c0e1e9626 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Sun, 22 Dec 2024 12:49:19 +0100 Subject: [PATCH 25/53] Update unenv preset (#7581) --- .changeset/chilled-mugs-fail.md | 8 + fixtures/nodejs-hybrid-app/src/index.ts | 15 +- .../nodejs-hybrid-app/src/unenv-preset.ts | 123 +++++++++++++++ .../nodejs-hybrid-app/tests/index.test.ts | 13 ++ packages/unenv-preset/package.json | 3 +- packages/wrangler/package.json | 2 +- pnpm-lock.yaml | 148 +----------------- 7 files changed, 159 insertions(+), 153 deletions(-) create mode 100644 .changeset/chilled-mugs-fail.md create mode 100644 fixtures/nodejs-hybrid-app/src/unenv-preset.ts diff --git a/.changeset/chilled-mugs-fail.md b/.changeset/chilled-mugs-fail.md new file mode 100644 index 000000000000..570d40f6d857 --- /dev/null +++ b/.changeset/chilled-mugs-fail.md @@ -0,0 +1,8 @@ +--- +"wrangler": patch +--- + +chore(wrangler): update unenv dependency version + +unenv now uses the workerd implementation on node:dns +See the [unjs/unenv#376](https://github.com/unjs/unenv/pull/376) diff --git a/fixtures/nodejs-hybrid-app/src/index.ts b/fixtures/nodejs-hybrid-app/src/index.ts index 3f16b94fb2e1..a7acfc1005eb 100644 --- a/fixtures/nodejs-hybrid-app/src/index.ts +++ b/fixtures/nodejs-hybrid-app/src/index.ts @@ -6,6 +6,7 @@ import { Stream } from "node:stream"; import { Context } from "vm"; import { Client } from "pg"; import { s } from "./dep.cjs"; +import { testUnenvPreset } from "./unenv-preset"; testBasicNodejsProperties(); @@ -28,14 +29,18 @@ export default { return testX509Certificate(); case "/test-require-alias": return testRequireUenvAliasedPackages(); + case "/test-unenv-preset": + return await testUnenvPreset(); } return new Response( - 'Postgres query | ' + - 'Test process global | ' + - 'Test getRandomValues() | ' + - 'Test X509Certificate' + - 'Test require unenv aliased packages', + `Postgres query +Test process global +Test getRandomValues() +Test X509Certificate +Test require unenv aliased packages +Test unenv preset +`, { headers: { "Content-Type": "text/html; charset=utf-8" } } ); }, diff --git a/fixtures/nodejs-hybrid-app/src/unenv-preset.ts b/fixtures/nodejs-hybrid-app/src/unenv-preset.ts new file mode 100644 index 000000000000..6b5bed213d0d --- /dev/null +++ b/fixtures/nodejs-hybrid-app/src/unenv-preset.ts @@ -0,0 +1,123 @@ +import assert from "node:assert"; + +// TODO: move to `@cloudflare/unenv-preset` +// See: https://github.com/cloudflare/workers-sdk/issues/7579 +export async function testUnenvPreset() { + try { + await testCryptoGetRandomValues(); + await testWorkerdImplementsBuffer(); + await testWorkerdModules(); + await testUtilImplements(); + await testWorkerdPath(); + await testWorkerdDns(); + } catch (e) { + return new Response(String(e)); + } + + return new Response("OK!"); +} + +async function testCryptoGetRandomValues() { + const crypto = await import("node:crypto"); + + const array = new Uint32Array(10); + crypto.getRandomValues(array); + assert.strictEqual(array.length, 10); + assert(array.every((v) => v >= 0 && v <= 0xff_ff_ff_ff)); +} + +async function testWorkerdImplementsBuffer() { + const encoder = new TextEncoder(); + const buffer = await import("node:buffer"); + const Buffer = buffer.Buffer; + assert.strictEqual(buffer.isAscii(encoder.encode("hello world")), true); + assert.strictEqual(buffer.isUtf8(encoder.encode("Yağız")), true); + assert.strictEqual(buffer.btoa("hello"), "aGVsbG8="); + assert.strictEqual(buffer.atob("aGVsbG8="), "hello"); + { + const dest = buffer.transcode( + Buffer.from([ + 0x74, 0x00, 0x1b, 0x01, 0x73, 0x00, 0x74, 0x00, 0x20, 0x00, 0x15, 0x26, + ]), + "ucs2", + "utf8" + ); + assert.strictEqual( + dest.toString(), + Buffer.from("těst ☕", "utf8").toString() + ); + } + assert.ok(new buffer.File([], "file")); + assert.ok(new buffer.Blob([])); + assert.strictEqual(typeof buffer.INSPECT_MAX_BYTES, "number"); + assert.strictEqual(typeof buffer.resolveObjectURL, "function"); +} + +async function testWorkerdModules() { + const module = await import("node:module"); + // @ts-expect-error exposed by workerd + const require = module.createRequire("/"); + const modules = [ + "assert", + "assert/strict", + "buffer", + "diagnostics_channel", + "dns", + "dns/promises", + "events", + "path", + "path/posix", + "path/win32", + "querystring", + "stream", + "stream/consumers", + "stream/promises", + "stream/web", + "string_decoder", + "url", + "util/types", + "zlib", + ]; + for (const m of modules) { + assert.strictEqual(await import(m), require(m)); + } +} + +async function testUtilImplements() { + const { types } = await import("node:util"); + assert.strictEqual(types.isExternal("hello world"), false); + assert.strictEqual(types.isAnyArrayBuffer(new ArrayBuffer(0)), true); +} + +async function testWorkerdPath() { + const pathWin32 = await import("node:path/win32"); + assert.strictEqual(pathWin32.sep, "\\"); + assert.strictEqual(pathWin32.delimiter, ";"); + const pathPosix = await import("node:path/posix"); + assert.strictEqual(pathPosix.sep, "/"); + assert.strictEqual(pathPosix.delimiter, ":"); +} + +async function testWorkerdDns() { + const dns = await import("node:dns"); + await new Promise((resolve, reject) => { + dns.resolveTxt("nodejs.org", (error, results) => { + if (error) { + reject(error); + return; + } + assert.ok(Array.isArray(results[0])); + assert.strictEqual(results.length, 1); + assert.ok(results[0][0].startsWith("v=spf1")); + resolve(null); + }); + }); + + const dnsPromises = await import("node:dns/promises"); + const results = await dnsPromises.resolveCaa("google.com"); + assert.ok(Array.isArray(results)); + assert.strictEqual(results.length, 1); + assert.strictEqual(typeof results[0].critical, "number"); + assert.strictEqual(results[0].critical, 0); + assert.strictEqual(results[0].issue, "pki.goog"); +} diff --git a/fixtures/nodejs-hybrid-app/tests/index.test.ts b/fixtures/nodejs-hybrid-app/tests/index.test.ts index fb46992c03c9..d9fbda7f1b67 100644 --- a/fixtures/nodejs-hybrid-app/tests/index.test.ts +++ b/fixtures/nodejs-hybrid-app/tests/index.test.ts @@ -76,4 +76,17 @@ describe("nodejs compat", () => { await stop(); } }); + + test("unenv preset", async ({ expect }) => { + const { ip, port, stop } = await runWranglerDev( + resolve(__dirname, "../src"), + ["--port=0", "--inspector-port=0"] + ); + try { + const response = await fetch(`http://${ip}:${port}/test-unenv-preset`); + await expect(response.text()).resolves.toBe("OK!"); + } finally { + await stop(); + } + }); }); diff --git a/packages/unenv-preset/package.json b/packages/unenv-preset/package.json index 760086247659..538d198473f1 100644 --- a/packages/unenv-preset/package.json +++ b/packages/unenv-preset/package.json @@ -47,8 +47,7 @@ "devDependencies": { "@types/node": "*", "typescript": "catalog:default", - "unbuild": "^2.0.0", - "wrangler": "3.95.0" + "unbuild": "^2.0.0" }, "peerDependencies": { "unenv": "npm:unenv-nightly@*", diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 32ed9d2bd7c8..47d8b58cd07f 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -83,7 +83,7 @@ "resolve": "^1.22.8", "selfsigned": "^2.0.1", "source-map": "^0.6.1", - "unenv": "npm:unenv-nightly@2.0.0-20241204-140205-a5d5190", + "unenv": "npm:unenv-nightly@2.0.0-20241216-144314-7e05819", "workerd": "1.20241218.0", "xxhash-wasm": "^1.0.1" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e7401f08a847..b4f58baf8b96 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1633,9 +1633,6 @@ importers: unbuild: specifier: ^2.0.0 version: 2.0.0(typescript@5.6.3)(vue-tsc@2.0.29(typescript@5.6.3)) - wrangler: - specifier: 3.95.0 - version: 3.95.0(@cloudflare/workers-types@4.20241218.0) packages/vitest-pool-workers: dependencies: @@ -2022,8 +2019,8 @@ importers: specifier: ^0.6.1 version: 0.6.1 unenv: - specifier: npm:unenv-nightly@2.0.0-20241204-140205-a5d5190 - version: unenv-nightly@2.0.0-20241204-140205-a5d5190 + specifier: npm:unenv-nightly@2.0.0-20241216-144314-7e05819 + version: unenv-nightly@2.0.0-20241216-144314-7e05819 workerd: specifier: 1.20241218.0 version: 1.20241218.0 @@ -2809,12 +2806,6 @@ packages: cpu: [x64] os: [darwin] - '@cloudflare/workerd-darwin-64@1.20241205.0': - resolution: {integrity: sha512-TArEZkSZkHJyEwnlWWkSpCI99cF6lJ14OVeEoI9Um/+cD9CKZLM9vCmsLeKglKheJ0KcdCnkA+DbeD15t3VaWg==} - engines: {node: '>=16'} - cpu: [x64] - os: [darwin] - '@cloudflare/workerd-darwin-64@1.20241216.0': resolution: {integrity: sha512-GreuUuvd1tp34i/I8rv9I6tJTGkLIdUZfPd4Gq7glRntWhZSfeJOlhFHOa/tIil1SrWi1UzXmWeW22DCcUIprA==} engines: {node: '>=16'} @@ -2833,12 +2824,6 @@ packages: cpu: [arm64] os: [darwin] - '@cloudflare/workerd-darwin-arm64@1.20241205.0': - resolution: {integrity: sha512-u5eqKa9QRdA8MugfgCoD+ADDjY6EpKbv3hSYJETmmUh17l7WXjWBzv4pUvOKIX67C0UzMUy4jZYwC53MymhX3w==} - engines: {node: '>=16'} - cpu: [arm64] - os: [darwin] - '@cloudflare/workerd-darwin-arm64@1.20241216.0': resolution: {integrity: sha512-wGtzIWx4a8uu4y601Zq/x+5fPoSfJoXEEPkqxhcTs2g22Py60wnG91vAeVa8pZe9SipBozYczXh2OwoeCO1QVg==} engines: {node: '>=16'} @@ -2857,12 +2842,6 @@ packages: cpu: [x64] os: [linux] - '@cloudflare/workerd-linux-64@1.20241205.0': - resolution: {integrity: sha512-OYA7S5zpumMamWEW+IhhBU6YojIEocyE5X/YFPiTOCrDE3dsfr9t6oqNE7hxGm1VAAu+Irtl+a/5LwmBOU681w==} - engines: {node: '>=16'} - cpu: [x64] - os: [linux] - '@cloudflare/workerd-linux-64@1.20241216.0': resolution: {integrity: sha512-HRkePwhnb/4r2Bd6SS3n8VWLPnczh2ApKo3j5N0YSVOz/bEJlqEbEnKAUivCb79C3zptTsbsb0tJ4b5uZsaHtw==} engines: {node: '>=16'} @@ -2881,12 +2860,6 @@ packages: cpu: [arm64] os: [linux] - '@cloudflare/workerd-linux-arm64@1.20241205.0': - resolution: {integrity: sha512-qAzecONjFJGIAVJZKExQ5dlbic0f3d4A+GdKa+H6SoUJtPaWiE3K6WuePo4JOT7W3/Zfh25McmX+MmpMUUcM5Q==} - engines: {node: '>=16'} - cpu: [arm64] - os: [linux] - '@cloudflare/workerd-linux-arm64@1.20241216.0': resolution: {integrity: sha512-5U99Iaj18BEJAEpKr+n2kdOyzCITbmzV0Ld4zMpIw5ZW0R2MHCo1swra84Q+bvElVOK6+7KGhjKQSqyZUF1WWA==} engines: {node: '>=16'} @@ -2905,12 +2878,6 @@ packages: cpu: [x64] os: [win32] - '@cloudflare/workerd-windows-64@1.20241205.0': - resolution: {integrity: sha512-BEab+HiUgCdl6GXAT7EI2yaRtDPiRJlB94XLvRvXi1ZcmQqsrq6awGo6apctFo4WUL29V7c09LxmN4HQ3X2Tvg==} - engines: {node: '>=16'} - cpu: [x64] - os: [win32] - '@cloudflare/workerd-windows-64@1.20241216.0': resolution: {integrity: sha512-6UtbWgZNFuVyq6d3nKsp3Eb53Ghm2EYObCKTs9TSzV2ZHbovgOIU8BKIlbfJvmkEbG4Q8bbfZkb3QJpG/IwchQ==} engines: {node: '>=16'} @@ -2923,10 +2890,6 @@ packages: cpu: [x64] os: [win32] - '@cloudflare/workers-shared@0.11.0': - resolution: {integrity: sha512-A+lQ8xp7992qSeMmuQ0ssL6CPmm+ZmAv6Ddikan0n1jjpMAic+97l7xtVIsswSn9iLMFPYQ9uNN/8Fl0AgARIQ==} - engines: {node: '>=16.7.0'} - '@cloudflare/workers-shared@0.8.0': resolution: {integrity: sha512-1OvFkNtslaMZAJsaocTmbACApgmWv55uLpNj50Pn2MGcxdAjpqykXJFQw5tKc+lGV9TDZh9oO3Rsk17IEQDzIg==} engines: {node: '>=16.7.0'} @@ -7607,11 +7570,6 @@ packages: engines: {node: '>=16.13'} hasBin: true - miniflare@3.20241205.0: - resolution: {integrity: sha512-Z0cTtIf6ZrcAJ3SrOI9EUM3s4dkGhNeU6Ubl8sroYhsPVD+rtz3m5+p6McHFWCkcMff1o60X5XEKVTmkz0gbpA==} - engines: {node: '>=16.13'} - hasBin: true - minimatch@10.0.1: resolution: {integrity: sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==} engines: {node: 20 || >=22} @@ -9775,9 +9733,6 @@ packages: unenv-nightly@2.0.0-20241111-080453-894aa31: resolution: {integrity: sha512-0W39QQOQ9VE8kVVUpGwEG+pZcsCXk5wqNG6rDPE6Gr+fiA69LR0qERM61hW5KCOkC1/ArCFrfCGjwHyyv/bI0Q==} - unenv-nightly@2.0.0-20241204-140205-a5d5190: - resolution: {integrity: sha512-jpmAytLeiiW01pl5bhVn9wYJ4vtiLdhGe10oXlJBuQEX8mxjxO8BlEXGHU4vr4yEikjFP1wsomTHt/CLU8kUwg==} - unenv-nightly@2.0.0-20241216-144314-7e05819: resolution: {integrity: sha512-HpRspwDDxEwb6f9jOJYdL8iuZ054GIJ61LWHui7FPcgSVUPIXjZ3Nf0bh0qVIEqSGb3bNU/C1Zcw6fKHVl4lDg==} @@ -10092,11 +10047,6 @@ packages: engines: {node: '>=16'} hasBin: true - workerd@1.20241205.0: - resolution: {integrity: sha512-vso/2n0c5SdBDWiD+Sx5gM7unA6SiZXRVUHDqH1euoP/9mFVHZF8icoYsNLB87b/TX8zNgpae+I5N/xFpd9v0g==} - engines: {node: '>=16'} - hasBin: true - workerd@1.20241216.0: resolution: {integrity: sha512-q92hkfZ0ZmH6DrcQ426AqJR0KyG6NRAUNUT3Kvpzk76rLHzw6pvVeU9exATkqnwk5K3LQK6l1asuSsBDdXsPpw==} engines: {node: '>=16'} @@ -10120,16 +10070,6 @@ packages: '@cloudflare/workers-types': optional: true - wrangler@3.95.0: - resolution: {integrity: sha512-3w5852i3FNyDz421K2Qk4v5L8jjwegO5O8E1+VAQmjnm82HFNxpIRUBq0bmM7CTLvOPI/Jjcmj/eAWjQBL7QYg==} - engines: {node: '>=16.17.0'} - hasBin: true - peerDependencies: - '@cloudflare/workers-types': ^4.20241205.0 - peerDependenciesMeta: - '@cloudflare/workers-types': - optional: true - wrap-ansi@6.2.0: resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==} engines: {node: '>=8'} @@ -11168,9 +11108,6 @@ snapshots: '@cloudflare/workerd-darwin-64@1.20241106.1': optional: true - '@cloudflare/workerd-darwin-64@1.20241205.0': - optional: true - '@cloudflare/workerd-darwin-64@1.20241216.0': optional: true @@ -11180,9 +11117,6 @@ snapshots: '@cloudflare/workerd-darwin-arm64@1.20241106.1': optional: true - '@cloudflare/workerd-darwin-arm64@1.20241205.0': - optional: true - '@cloudflare/workerd-darwin-arm64@1.20241216.0': optional: true @@ -11192,9 +11126,6 @@ snapshots: '@cloudflare/workerd-linux-64@1.20241106.1': optional: true - '@cloudflare/workerd-linux-64@1.20241205.0': - optional: true - '@cloudflare/workerd-linux-64@1.20241216.0': optional: true @@ -11204,9 +11135,6 @@ snapshots: '@cloudflare/workerd-linux-arm64@1.20241106.1': optional: true - '@cloudflare/workerd-linux-arm64@1.20241205.0': - optional: true - '@cloudflare/workerd-linux-arm64@1.20241216.0': optional: true @@ -11216,20 +11144,12 @@ snapshots: '@cloudflare/workerd-windows-64@1.20241106.1': optional: true - '@cloudflare/workerd-windows-64@1.20241205.0': - optional: true - '@cloudflare/workerd-windows-64@1.20241216.0': optional: true '@cloudflare/workerd-windows-64@1.20241218.0': optional: true - '@cloudflare/workers-shared@0.11.0': - dependencies: - mime: 3.0.0 - zod: 3.22.3 - '@cloudflare/workers-shared@0.8.0': dependencies: mime: 3.0.0 @@ -16296,25 +16216,6 @@ snapshots: - supports-color - utf-8-validate - miniflare@3.20241205.0: - dependencies: - '@cspotcode/source-map-support': 0.8.1 - acorn: 8.11.3 - acorn-walk: 8.3.2 - capnp-ts: 0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii) - exit-hook: 2.2.1 - glob-to-regexp: 0.4.1 - stoppable: 1.1.0 - undici: 5.28.4 - workerd: 1.20241205.0 - ws: 8.18.0 - youch: 3.2.3 - zod: 3.22.3 - transitivePeerDependencies: - - bufferutil - - supports-color - - utf-8-validate - minimatch@10.0.1: dependencies: brace-expansion: 2.0.1 @@ -18610,7 +18511,7 @@ snapshots: mkdist: 1.6.0(typescript@5.6.3)(vue-tsc@2.0.29(typescript@5.6.3)) mlly: 1.7.3 pathe: 1.1.2 - pkg-types: 1.0.3 + pkg-types: 1.2.1 pretty-bytes: 6.1.1 rollup: 3.29.5 rollup-plugin-dts: 6.1.1(rollup@3.29.5)(typescript@5.6.3) @@ -18646,13 +18547,6 @@ snapshots: pathe: 1.1.2 ufo: 1.5.4 - unenv-nightly@2.0.0-20241204-140205-a5d5190: - dependencies: - defu: 6.1.4 - ohash: 1.1.4 - pathe: 1.1.2 - ufo: 1.5.4 - unenv-nightly@2.0.0-20241216-144314-7e05819: dependencies: defu: 6.1.4 @@ -19042,14 +18936,6 @@ snapshots: '@cloudflare/workerd-linux-arm64': 1.20241106.1 '@cloudflare/workerd-windows-64': 1.20241106.1 - workerd@1.20241205.0: - optionalDependencies: - '@cloudflare/workerd-darwin-64': 1.20241205.0 - '@cloudflare/workerd-darwin-arm64': 1.20241205.0 - '@cloudflare/workerd-linux-64': 1.20241205.0 - '@cloudflare/workerd-linux-arm64': 1.20241205.0 - '@cloudflare/workerd-windows-64': 1.20241205.0 - workerd@1.20241216.0: optionalDependencies: '@cloudflare/workerd-darwin-64': 1.20241216.0 @@ -19097,34 +18983,6 @@ snapshots: - supports-color - utf-8-validate - wrangler@3.95.0(@cloudflare/workers-types@4.20241218.0): - dependencies: - '@cloudflare/kv-asset-handler': 0.3.4 - '@cloudflare/workers-shared': 0.11.0 - '@esbuild-plugins/node-globals-polyfill': 0.2.3(esbuild@0.17.19) - '@esbuild-plugins/node-modules-polyfill': 0.2.2(esbuild@0.17.19) - blake3-wasm: 2.1.5 - chokidar: 4.0.1 - date-fns: 4.1.0 - esbuild: 0.17.19 - itty-time: 1.0.6 - miniflare: 3.20241205.0 - nanoid: 3.3.7 - path-to-regexp: 6.3.0 - resolve: 1.22.8 - selfsigned: 2.1.1 - source-map: 0.6.1 - unenv: unenv-nightly@2.0.0-20241204-140205-a5d5190 - workerd: 1.20241205.0 - xxhash-wasm: 1.0.1 - optionalDependencies: - '@cloudflare/workers-types': 4.20241218.0 - fsevents: 2.3.3 - transitivePeerDependencies: - - bufferutil - - supports-color - - utf-8-validate - wrap-ansi@6.2.0: dependencies: ansi-styles: 4.3.0 From 6e6922e1f575df802392629030b7919769f7966b Mon Sep 17 00:00:00 2001 From: James Ross Date: Mon, 23 Dec 2024 09:03:47 +0000 Subject: [PATCH 26/53] fix: bug issue template (#7610) --- .github/ISSUE_TEMPLATE/bug-template.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug-template.yaml b/.github/ISSUE_TEMPLATE/bug-template.yaml index 27abc2efd88b..b628f42a83b8 100644 --- a/.github/ISSUE_TEMPLATE/bug-template.yaml +++ b/.github/ISSUE_TEMPLATE/bug-template.yaml @@ -54,7 +54,7 @@ body: attributes: label: Describe the Bug description: Please describe the bug in as much detail as possible, including steps to reproduce, the behaviour you're seeing, and the behaviour you expect. - validations: + validations: required: true - type: textarea From 8abb43fcdf0c506fa6268a7f07aa31b398b7daf2 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 23 Dec 2024 10:21:19 +0100 Subject: [PATCH 27/53] chore(wrangler): update unenv dependency version (#7614) --- .changeset/nice-pandas-wait.md | 10 +++++++++ packages/wrangler/package.json | 2 +- .../src/__tests__/unenv/unenv.test.ts | 22 +++++++++++++++++++ pnpm-lock.yaml | 15 +++++++++++-- 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 .changeset/nice-pandas-wait.md create mode 100644 packages/wrangler/src/__tests__/unenv/unenv.test.ts diff --git a/.changeset/nice-pandas-wait.md b/.changeset/nice-pandas-wait.md new file mode 100644 index 000000000000..b267aeb133e1 --- /dev/null +++ b/.changeset/nice-pandas-wait.md @@ -0,0 +1,10 @@ +--- +"wrangler": patch +--- + +chore(wrangler): update unenv dependency version + +The updated unenv contains a fix for the module resolution, +see . +That bug prevented us from using unenv module resolution, +see . diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 47d8b58cd07f..88e0bab76609 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -83,7 +83,7 @@ "resolve": "^1.22.8", "selfsigned": "^2.0.1", "source-map": "^0.6.1", - "unenv": "npm:unenv-nightly@2.0.0-20241216-144314-7e05819", + "unenv": "npm:unenv-nightly@2.0.0-20241218-183400-5d6aec3", "workerd": "1.20241218.0", "xxhash-wasm": "^1.0.1" }, diff --git a/packages/wrangler/src/__tests__/unenv/unenv.test.ts b/packages/wrangler/src/__tests__/unenv/unenv.test.ts new file mode 100644 index 000000000000..3caff6f0fc70 --- /dev/null +++ b/packages/wrangler/src/__tests__/unenv/unenv.test.ts @@ -0,0 +1,22 @@ +import { cloudflare, defineEnv } from "unenv"; + +describe("unenv", () => { + test("module resolution does not throw", async () => { + const env = { + alias: {}, + ...cloudflare, + }; + + env.alias["should/no/throw"] = "if/this/is/not/valid"; + + // Throws "Error: ENOTDIR: not a directory, open '.../node_modules/.pnpm/unenv-nightly@2.0.0-20241216-144314-7e05819/node_modules/unenv-nightly/dist/index.mjs/package.json'" + // before https://github.com/unjs/unenv/pull/378 is integrated via 2.0.0-20241218-183400-5d6aec3 + expect(() => { + defineEnv({ + nodeCompat: true, + presets: [env], + resolve: true, + }); + }).not.toThrow(); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b4f58baf8b96..f598fd8d1d5a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2019,8 +2019,8 @@ importers: specifier: ^0.6.1 version: 0.6.1 unenv: - specifier: npm:unenv-nightly@2.0.0-20241216-144314-7e05819 - version: unenv-nightly@2.0.0-20241216-144314-7e05819 + specifier: npm:unenv-nightly@2.0.0-20241218-183400-5d6aec3 + version: unenv-nightly@2.0.0-20241218-183400-5d6aec3 workerd: specifier: 1.20241218.0 version: 1.20241218.0 @@ -9736,6 +9736,9 @@ packages: unenv-nightly@2.0.0-20241216-144314-7e05819: resolution: {integrity: sha512-HpRspwDDxEwb6f9jOJYdL8iuZ054GIJ61LWHui7FPcgSVUPIXjZ3Nf0bh0qVIEqSGb3bNU/C1Zcw6fKHVl4lDg==} + unenv-nightly@2.0.0-20241218-183400-5d6aec3: + resolution: {integrity: sha512-7Xpi29CJRbOV1/IrC03DawMJ0hloklDLq/cigSe+J2jkcC+iDres2Cy0r4ltj5f0x7DqsaGaB4/dLuCPPFZnZA==} + unicorn-magic@0.1.0: resolution: {integrity: sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==} engines: {node: '>=18'} @@ -18555,6 +18558,14 @@ snapshots: pathe: 1.1.2 ufo: 1.5.4 + unenv-nightly@2.0.0-20241218-183400-5d6aec3: + dependencies: + defu: 6.1.4 + mlly: 1.7.3 + ohash: 1.1.4 + pathe: 1.1.2 + ufo: 1.5.4 + unicorn-magic@0.1.0: {} universal-user-agent@6.0.1: {} From 11cd30dead642ffadb8413f27add9f4d722543ed Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 23 Dec 2024 11:18:13 +0100 Subject: [PATCH 28/53] chore: pin `@opennextjs/cloudflare` to 0.2.x (#7616) Release 0.3 requires updating the template. We'll do that in a follow up PR --- packages/create-cloudflare/templates-experimental/next/c3.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/create-cloudflare/templates-experimental/next/c3.ts b/packages/create-cloudflare/templates-experimental/next/c3.ts index 3447e5fbb699..74195c25e1ad 100644 --- a/packages/create-cloudflare/templates-experimental/next/c3.ts +++ b/packages/create-cloudflare/templates-experimental/next/c3.ts @@ -18,7 +18,10 @@ const generate = async (ctx: C3Context) => { }; const configure = async () => { - const packages = ["@opennextjs/cloudflare", "@cloudflare/workers-types"]; + const packages = [ + "@opennextjs/cloudflare@0.2.x", + "@cloudflare/workers-types", + ]; await installPackages(packages, { dev: true, startText: "Adding the Cloudflare adapter", From 75393d67d04fae1d674b7b2fc0b751384b02103b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:28:26 +0000 Subject: [PATCH 29/53] [C3] bump create-vite from 6.0.1 to 6.1.0 in /packages/create-cloudflare/src/frameworks (#7617) * [C3] bump create-vite in /packages/create-cloudflare/src/frameworks Bumps [create-vite](https://github.com/vitejs/vite/tree/HEAD/packages/create-vite) from 6.0.1 to 6.1.0. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/main/packages/create-vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/create-vite@6.1.0/packages/create-vite) --- updated-dependencies: - dependency-name: create-vite dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ----------- | ----- | ----- | | create-vite | 6.0.1 | 6.1.0 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7617.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7617.md diff --git a/.changeset/c3-frameworks-update-7617.md b/.changeset/c3-frameworks-update-7617.md new file mode 100644 index 000000000000..4d886587610f --- /dev/null +++ b/.changeset/c3-frameworks-update-7617.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ----------- | ----- | ----- | +| create-vite | 6.0.1 | 6.1.0 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 41e92c8cba78..9ad562147457 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -12,7 +12,7 @@ "create-hono": "0.14.3", "create-next-app": "15.1.0", "create-qwik": "1.11.0", - "create-vite": "6.0.1", + "create-vite": "6.1.0", "create-remix": "2.15.1", "create-solid": "0.5.14", "create-vue": "3.12.2", From e5b9a9a9d7363acf8ac7fa45f88294d879a3e996 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:29:07 +0000 Subject: [PATCH 30/53] [C3] bump sv from 0.6.7 to 0.6.9 in /packages/create-cloudflare/src/frameworks (#7618) * [C3] bump sv in /packages/create-cloudflare/src/frameworks Bumps [sv](https://github.com/sveltejs/cli/tree/HEAD/packages/cli) from 0.6.7 to 0.6.9. - [Release notes](https://github.com/sveltejs/cli/releases) - [Changelog](https://github.com/sveltejs/cli/blob/main/packages/cli/CHANGELOG.md) - [Commits](https://github.com/sveltejs/cli/commits/sv@0.6.9/packages/cli) --- updated-dependencies: - dependency-name: sv dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ---------- | ----- | ----- | | sv | 0.6.7 | 0.6.9 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7618.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7618.md diff --git a/.changeset/c3-frameworks-update-7618.md b/.changeset/c3-frameworks-update-7618.md new file mode 100644 index 000000000000..d41821a15419 --- /dev/null +++ b/.changeset/c3-frameworks-update-7618.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ---------- | ----- | ----- | +| sv | 0.6.7 | 0.6.9 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 9ad562147457..f4ad8112f39f 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -17,7 +17,7 @@ "create-solid": "0.5.14", "create-vue": "3.12.2", "gatsby": "5.14.0", - "sv": "0.6.7", + "sv": "0.6.9", "nuxi": "3.16.0" } } From 05cc18889d604145d68ff0a306926ebb9380ea3b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:44:21 +0000 Subject: [PATCH 31/53] [C3] bump @angular/create from 19.0.5 to 19.0.6 in /packages/create-cloudflare/src/frameworks (#7621) * [C3] bump @angular/create in /packages/create-cloudflare/src/frameworks Bumps [@angular/create](https://github.com/angular/angular-cli) from 19.0.5 to 19.0.6. - [Release notes](https://github.com/angular/angular-cli/releases) - [Changelog](https://github.com/angular/angular-cli/blob/main/CHANGELOG.md) - [Commits](https://github.com/angular/angular-cli/compare/19.0.5...19.0.6) --- updated-dependencies: - dependency-name: "@angular/create" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | --------------- | ------ | ------ | | @angular/create | 19.0.5 | 19.0.6 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7621.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7621.md diff --git a/.changeset/c3-frameworks-update-7621.md b/.changeset/c3-frameworks-update-7621.md new file mode 100644 index 000000000000..267fd1e4fa94 --- /dev/null +++ b/.changeset/c3-frameworks-update-7621.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| --------------- | ------ | ------ | +| @angular/create | 19.0.5 | 19.0.6 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index f4ad8112f39f..8e62af8c62dc 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -7,7 +7,7 @@ "dependencies": { "create-astro": "4.11.0", "create-analog": "1.8.1", - "@angular/create": "19.0.5", + "@angular/create": "19.0.6", "create-docusaurus": "3.6.3", "create-hono": "0.14.3", "create-next-app": "15.1.0", From a29b1c2c58f59a0e9891f1d30eb1c2c0fd68e42d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:04:56 +0000 Subject: [PATCH 32/53] [C3] bump create-remix from 2.15.1 to 2.15.2 in /packages/create-cloudflare/src/frameworks (#7622) --- .changeset/c3-frameworks-update-7622.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7622.md diff --git a/.changeset/c3-frameworks-update-7622.md b/.changeset/c3-frameworks-update-7622.md new file mode 100644 index 000000000000..5e98547324cd --- /dev/null +++ b/.changeset/c3-frameworks-update-7622.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ------------ | ------ | ------ | +| create-remix | 2.15.1 | 2.15.2 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 8e62af8c62dc..1102829a1c11 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -13,7 +13,7 @@ "create-next-app": "15.1.0", "create-qwik": "1.11.0", "create-vite": "6.1.0", - "create-remix": "2.15.1", + "create-remix": "2.15.2", "create-solid": "0.5.14", "create-vue": "3.12.2", "gatsby": "5.14.0", From c448a57a23052d0fb75f06a282b735f452ddb8c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:19:21 +0000 Subject: [PATCH 33/53] [C3] bump create-qwik from 1.11.0 to 1.12.0 in /packages/create-cloudflare/src/frameworks (#7623) * [C3] bump create-qwik in /packages/create-cloudflare/src/frameworks Bumps [create-qwik](https://github.com/QwikDev/qwik/tree/HEAD/packages/create-qwik) from 1.11.0 to 1.12.0. - [Release notes](https://github.com/QwikDev/qwik/releases) - [Changelog](https://github.com/QwikDev/qwik/blob/main/packages/create-qwik/CHANGELOG.md) - [Commits](https://github.com/QwikDev/qwik/commits/create-qwik@1.12.0/packages/create-qwik) --- updated-dependencies: - dependency-name: create-qwik dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ----------- | ------ | ------ | | create-qwik | 1.11.0 | 1.12.0 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7623.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7623.md diff --git a/.changeset/c3-frameworks-update-7623.md b/.changeset/c3-frameworks-update-7623.md new file mode 100644 index 000000000000..76c430cd10d2 --- /dev/null +++ b/.changeset/c3-frameworks-update-7623.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ----------- | ------ | ------ | +| create-qwik | 1.11.0 | 1.12.0 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 1102829a1c11..c0c1394ed678 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -11,7 +11,7 @@ "create-docusaurus": "3.6.3", "create-hono": "0.14.3", "create-next-app": "15.1.0", - "create-qwik": "1.11.0", + "create-qwik": "1.12.0", "create-vite": "6.1.0", "create-remix": "2.15.2", "create-solid": "0.5.14", From 4a38b9b1f9d4249f0d6756c22593a168ab4149bc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:51:11 +0000 Subject: [PATCH 34/53] [C3] bump nuxi from 3.16.0 to 3.17.1 in /packages/create-cloudflare/src/frameworks (#7620) * [C3] bump nuxi in /packages/create-cloudflare/src/frameworks Bumps [nuxi](https://github.com/nuxt/cli) from 3.16.0 to 3.17.1. - [Release notes](https://github.com/nuxt/cli/releases) - [Changelog](https://github.com/nuxt/cli/blob/main/CHANGELOG.md) - [Commits](https://github.com/nuxt/cli/compare/v3.16.0...v3.17.1) --- updated-dependencies: - dependency-name: nuxi dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ---------- | ------ | ------ | | nuxi | 3.16.0 | 3.17.1 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7620.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7620.md diff --git a/.changeset/c3-frameworks-update-7620.md b/.changeset/c3-frameworks-update-7620.md new file mode 100644 index 000000000000..e7b737e50a83 --- /dev/null +++ b/.changeset/c3-frameworks-update-7620.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ---------- | ------ | ------ | +| nuxi | 3.16.0 | 3.17.1 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index c0c1394ed678..68065f9c7d7b 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -18,6 +18,6 @@ "create-vue": "3.12.2", "gatsby": "5.14.0", "sv": "0.6.9", - "nuxi": "3.16.0" + "nuxi": "3.17.1" } } From d4d8df1356df66b09f18abff09b201537373b839 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:51:26 +0000 Subject: [PATCH 35/53] [C3] bump create-next-app from 15.1.0 to 15.1.2 in /packages/create-cloudflare/src/frameworks (#7624) * [C3] bump create-next-app in /packages/create-cloudflare/src/frameworks Bumps [create-next-app](https://github.com/vercel/next.js/tree/HEAD/packages/create-next-app) from 15.1.0 to 15.1.2. - [Release notes](https://github.com/vercel/next.js/releases) - [Changelog](https://github.com/vercel/next.js/blob/canary/release.js) - [Commits](https://github.com/vercel/next.js/commits/v15.1.2/packages/create-next-app) --- updated-dependencies: - dependency-name: create-next-app dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | --------------- | ------ | ------ | | create-next-app | 15.1.0 | 15.1.2 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7624.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7624.md diff --git a/.changeset/c3-frameworks-update-7624.md b/.changeset/c3-frameworks-update-7624.md new file mode 100644 index 000000000000..e3bfa3a8cac4 --- /dev/null +++ b/.changeset/c3-frameworks-update-7624.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| --------------- | ------ | ------ | +| create-next-app | 15.1.0 | 15.1.2 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 68065f9c7d7b..31cdde7b5749 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -10,7 +10,7 @@ "@angular/create": "19.0.6", "create-docusaurus": "3.6.3", "create-hono": "0.14.3", - "create-next-app": "15.1.0", + "create-next-app": "15.1.2", "create-qwik": "1.12.0", "create-vite": "6.1.0", "create-remix": "2.15.2", From 998902238552c860cf9dd9f629e8f351352ae3c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:51:43 +0000 Subject: [PATCH 36/53] [C3] bump gatsby from 5.14.0 to 5.14.1 in /packages/create-cloudflare/src/frameworks (#7619) * [C3] bump gatsby in /packages/create-cloudflare/src/frameworks Bumps [gatsby](https://github.com/gatsbyjs/gatsby) from 5.14.0 to 5.14.1. - [Release notes](https://github.com/gatsbyjs/gatsby/releases) - [Changelog](https://github.com/gatsbyjs/gatsby/blob/master/CHANGELOG.md) - [Commits](https://github.com/gatsbyjs/gatsby/compare/gatsby@5.14.0...gatsby@5.14.1) --- updated-dependencies: - dependency-name: gatsby dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ---------- | ------ | ------ | | gatsby | 5.14.0 | 5.14.1 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7619.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7619.md diff --git a/.changeset/c3-frameworks-update-7619.md b/.changeset/c3-frameworks-update-7619.md new file mode 100644 index 000000000000..e102a9563173 --- /dev/null +++ b/.changeset/c3-frameworks-update-7619.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ---------- | ------ | ------ | +| gatsby | 5.14.0 | 5.14.1 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 31cdde7b5749..e4bbad44a5be 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -16,7 +16,7 @@ "create-remix": "2.15.2", "create-solid": "0.5.14", "create-vue": "3.12.2", - "gatsby": "5.14.0", + "gatsby": "5.14.1", "sv": "0.6.9", "nuxi": "3.17.1" } From acbea32c6df82269b435e34d8c51fe8a26c973f1 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Mon, 30 Dec 2024 11:10:45 +0100 Subject: [PATCH 37/53] fix and update experimental Next.js template to work on `@opennextjs/cloudflare@0.3.x` (#7638) * update the experimental Next.js template to work on `@opennextjs/cloudflare@0.3.x` * include `.dev.vars` template file * skip bun and yarn experimental e2es --- .changeset/gorgeous-kids-protect.md | 5 ++++ packages/create-cloudflare/.gitignore | 3 ++ .../e2e-tests/frameworks.test.ts | 5 ++++ .../templates-experimental/next/c3.ts | 6 ++-- .../next/templates/.dev.vars | 2 ++ .../next/templates/.gitignore | 7 ++--- .../next/templates/open-next.config.ts | 28 +++++++++++++++++++ .../next/templates/wrangler.toml | 4 +-- 8 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 .changeset/gorgeous-kids-protect.md create mode 100644 packages/create-cloudflare/templates-experimental/next/templates/.dev.vars create mode 100644 packages/create-cloudflare/templates-experimental/next/templates/open-next.config.ts diff --git a/.changeset/gorgeous-kids-protect.md b/.changeset/gorgeous-kids-protect.md new file mode 100644 index 000000000000..9386ce52c15d --- /dev/null +++ b/.changeset/gorgeous-kids-protect.md @@ -0,0 +1,5 @@ +--- +"create-cloudflare": patch +--- + +fix and update experimental Next.js template to work on `@opennextjs/cloudflare@0.3.x` diff --git a/packages/create-cloudflare/.gitignore b/packages/create-cloudflare/.gitignore index db7dbd67a7c7..1152fa6a605e 100644 --- a/packages/create-cloudflare/.gitignore +++ b/packages/create-cloudflare/.gitignore @@ -13,5 +13,8 @@ templates*/**/pnpm-lock.yaml # the build step renames .gitignore files to __dot__gitignore templates*/**/__dot__gitignore +# include .dev.vars template files +!templates*/**/.dev.vars + scripts/snippets !scripts/snippets/.gitkeep diff --git a/packages/create-cloudflare/e2e-tests/frameworks.test.ts b/packages/create-cloudflare/e2e-tests/frameworks.test.ts index 7bc9edcca872..c17d23480ab3 100644 --- a/packages/create-cloudflare/e2e-tests/frameworks.test.ts +++ b/packages/create-cloudflare/e2e-tests/frameworks.test.ts @@ -188,6 +188,11 @@ function getFrameworkTests(opts: { expectedText: "Create Next App", }, unsupportedOSs: ["win32"], + unsupportedPms: [ + // bun and yarn are failing in CI + "bun", + "yarn", + ], }, nuxt: { testCommitMessage: true, diff --git a/packages/create-cloudflare/templates-experimental/next/c3.ts b/packages/create-cloudflare/templates-experimental/next/c3.ts index 74195c25e1ad..80f0959f68ac 100644 --- a/packages/create-cloudflare/templates-experimental/next/c3.ts +++ b/packages/create-cloudflare/templates-experimental/next/c3.ts @@ -19,7 +19,7 @@ const generate = async (ctx: C3Context) => { const configure = async () => { const packages = [ - "@opennextjs/cloudflare@0.2.x", + "@opennextjs/cloudflare@0.3.x", "@cloudflare/workers-types", ]; await installPackages(packages, { @@ -47,8 +47,8 @@ export default { configure, transformPackageJson: async () => ({ scripts: { - deploy: `cloudflare && wrangler deploy`, - preview: `cloudflare && wrangler dev`, + deploy: `opennextjs-cloudflare && wrangler deploy`, + preview: `opennextjs-cloudflare && wrangler dev`, "cf-typegen": `wrangler types --env-interface CloudflareEnv env.d.ts`, }, }), diff --git a/packages/create-cloudflare/templates-experimental/next/templates/.dev.vars b/packages/create-cloudflare/templates-experimental/next/templates/.dev.vars new file mode 100644 index 000000000000..96d720bda5ef --- /dev/null +++ b/packages/create-cloudflare/templates-experimental/next/templates/.dev.vars @@ -0,0 +1,2 @@ +# Load .env.development* files when running `wrangler dev` +NEXTJS_ENV=development diff --git a/packages/create-cloudflare/templates-experimental/next/templates/.gitignore b/packages/create-cloudflare/templates-experimental/next/templates/.gitignore index 0b418115f12a..76107d8b80c9 100644 --- a/packages/create-cloudflare/templates-experimental/next/templates/.gitignore +++ b/packages/create-cloudflare/templates-experimental/next/templates/.gitignore @@ -35,8 +35,5 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts - -# Cloudflare related -/.save.next -/.worker-next -/.wrangler +# OpenNext +/.open-next diff --git a/packages/create-cloudflare/templates-experimental/next/templates/open-next.config.ts b/packages/create-cloudflare/templates-experimental/next/templates/open-next.config.ts new file mode 100644 index 000000000000..30889ac44a49 --- /dev/null +++ b/packages/create-cloudflare/templates-experimental/next/templates/open-next.config.ts @@ -0,0 +1,28 @@ +import cache from "@opennextjs/cloudflare/kvCache"; + +const config = { + default: { + override: { + wrapper: "cloudflare-node", + converter: "edge", + incrementalCache: async () => cache, + tagCache: "dummy", + queue: "dummy", + }, + }, + + middleware: { + external: true, + override: { + wrapper: "cloudflare-edge", + converter: "edge", + proxyExternalRequest: "fetch", + }, + }, + + dangerous: { + enableCacheInterception: false, + }, +}; + +export default config; diff --git a/packages/create-cloudflare/templates-experimental/next/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/next/templates/wrangler.toml index 4f7e9f1324c4..10aaf705902c 100644 --- a/packages/create-cloudflare/templates-experimental/next/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/next/templates/wrangler.toml @@ -1,6 +1,6 @@ #:schema node_modules/wrangler/config-schema.json name = "" -main = ".worker-next/index.mjs" +main = ".open-next/worker.js" compatibility_date = "2024-09-26" compatibility_flags = ["nodejs_compat"] @@ -9,4 +9,4 @@ compatibility_flags = ["nodejs_compat"] minify = true # Use the new Workers + Assets to host the static frontend files -assets = { directory = ".worker-next/assets", binding = "ASSETS" } +assets = { directory = ".open-next/assets", binding = "ASSETS" } From 8b6f6e633eda4c85f7e84144846bb83f0450d955 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:19:04 +0100 Subject: [PATCH 38/53] [C3] Bump create-next-app from 15.1.2 to 15.1.3 in /packages/create-cloudflare/src/frameworks (#7645) * [C3] Bump create-next-app in /packages/create-cloudflare/src/frameworks Bumps [create-next-app](https://github.com/vercel/next.js/tree/HEAD/packages/create-next-app) from 15.1.2 to 15.1.3. - [Release notes](https://github.com/vercel/next.js/releases) - [Changelog](https://github.com/vercel/next.js/blob/canary/release.js) - [Commits](https://github.com/vercel/next.js/commits/v15.1.3/packages/create-next-app) --- updated-dependencies: - dependency-name: create-next-app dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | --------------- | ------ | ------ | | create-next-app | 15.1.2 | 15.1.3 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7645.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7645.md diff --git a/.changeset/c3-frameworks-update-7645.md b/.changeset/c3-frameworks-update-7645.md new file mode 100644 index 000000000000..44ca5e677226 --- /dev/null +++ b/.changeset/c3-frameworks-update-7645.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| --------------- | ------ | ------ | +| create-next-app | 15.1.2 | 15.1.3 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index e4bbad44a5be..35ceff72ae74 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -10,7 +10,7 @@ "@angular/create": "19.0.6", "create-docusaurus": "3.6.3", "create-hono": "0.14.3", - "create-next-app": "15.1.2", + "create-next-app": "15.1.3", "create-qwik": "1.12.0", "create-vite": "6.1.0", "create-remix": "2.15.2", From df06a9592e8ce721da9b9b048f1db759826a6983 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:39:50 +0100 Subject: [PATCH 39/53] [C3] Bump sv from 0.6.9 to 0.6.10 in /packages/create-cloudflare/src/frameworks (#7647) * [C3] Bump sv in /packages/create-cloudflare/src/frameworks Bumps [sv](https://github.com/sveltejs/cli/tree/HEAD/packages/cli) from 0.6.9 to 0.6.10. - [Release notes](https://github.com/sveltejs/cli/releases) - [Changelog](https://github.com/sveltejs/cli/blob/main/packages/cli/CHANGELOG.md) - [Commits](https://github.com/sveltejs/cli/commits/sv@0.6.10/packages/cli) --- updated-dependencies: - dependency-name: sv dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ---------- | ----- | ------ | | sv | 0.6.9 | 0.6.10 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7647.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7647.md diff --git a/.changeset/c3-frameworks-update-7647.md b/.changeset/c3-frameworks-update-7647.md new file mode 100644 index 000000000000..3d076e79018c --- /dev/null +++ b/.changeset/c3-frameworks-update-7647.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ---------- | ----- | ------ | +| sv | 0.6.9 | 0.6.10 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 35ceff72ae74..512130647f8d 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -17,7 +17,7 @@ "create-solid": "0.5.14", "create-vue": "3.12.2", "gatsby": "5.14.1", - "sv": "0.6.9", + "sv": "0.6.10", "nuxi": "3.17.1" } } From 42e8ba1d5a130742d7d94ee9b0b42e0cba78a352 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:45:09 +0100 Subject: [PATCH 40/53] [C3] Bump create-vite from 6.1.0 to 6.1.1 in /packages/create-cloudflare/src/frameworks (#7644) * [C3] Bump create-vite in /packages/create-cloudflare/src/frameworks Bumps [create-vite](https://github.com/vitejs/vite/tree/HEAD/packages/create-vite) from 6.1.0 to 6.1.1. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/main/packages/create-vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/create-vite@6.1.1/packages/create-vite) --- updated-dependencies: - dependency-name: create-vite dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ----------- | ----- | ----- | | create-vite | 6.1.0 | 6.1.1 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7644.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7644.md diff --git a/.changeset/c3-frameworks-update-7644.md b/.changeset/c3-frameworks-update-7644.md new file mode 100644 index 000000000000..f572b8bf7de5 --- /dev/null +++ b/.changeset/c3-frameworks-update-7644.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ----------- | ----- | ----- | +| create-vite | 6.1.0 | 6.1.1 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 512130647f8d..4a40c389b85f 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -12,7 +12,7 @@ "create-hono": "0.14.3", "create-next-app": "15.1.3", "create-qwik": "1.12.0", - "create-vite": "6.1.0", + "create-vite": "6.1.1", "create-remix": "2.15.2", "create-solid": "0.5.14", "create-vue": "3.12.2", From ab7204a6eb8f5bab00172a6a2623251ba2d757ba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:56:23 +0100 Subject: [PATCH 41/53] [C3] Bump create-vue from 3.12.2 to 3.13.0 in /packages/create-cloudflare/src/frameworks (#7643) * [C3] Bump create-vue in /packages/create-cloudflare/src/frameworks Bumps [create-vue](https://github.com/vuejs/create-vue) from 3.12.2 to 3.13.0. - [Release notes](https://github.com/vuejs/create-vue/releases) - [Commits](https://github.com/vuejs/create-vue/compare/v3.12.2...v3.13.0) --- updated-dependencies: - dependency-name: create-vue dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ---------- | ------ | ------ | | create-vue | 3.12.2 | 3.13.0 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7643.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7643.md diff --git a/.changeset/c3-frameworks-update-7643.md b/.changeset/c3-frameworks-update-7643.md new file mode 100644 index 000000000000..d00ddb867f1f --- /dev/null +++ b/.changeset/c3-frameworks-update-7643.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ---------- | ------ | ------ | +| create-vue | 3.12.2 | 3.13.0 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 4a40c389b85f..6fe5ed867aff 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -15,7 +15,7 @@ "create-vite": "6.1.1", "create-remix": "2.15.2", "create-solid": "0.5.14", - "create-vue": "3.12.2", + "create-vue": "3.13.0", "gatsby": "5.14.1", "sv": "0.6.10", "nuxi": "3.17.1" From f785f128b6530b61d2a9e59e7bbeb22189a5b722 Mon Sep 17 00:00:00 2001 From: Edmund Hung Date: Mon, 30 Dec 2024 17:09:01 +0000 Subject: [PATCH 42/53] chore: update workflow default node version (#7649) --- .github/actions/install-dependencies/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/install-dependencies/action.yml b/.github/actions/install-dependencies/action.yml index 1451269cc95a..b4e8d9987310 100644 --- a/.github/actions/install-dependencies/action.yml +++ b/.github/actions/install-dependencies/action.yml @@ -3,7 +3,7 @@ description: "Install dependencies, fetching from cache when possible" inputs: node-version: description: the version of Node.js to install - default: 18.20.2 + default: 18.20.5 turbo-api: description: the api URL for connecting to the turbo remote cache turbo-team: From b9533a375e25407251145dd94a0496faf5a16a4a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Dec 2024 11:41:49 +0000 Subject: [PATCH 43/53] [C3] Bump nuxi from 3.17.1 to 3.17.2 in /packages/create-cloudflare/src/frameworks (#7646) * [C3] Bump nuxi in /packages/create-cloudflare/src/frameworks Bumps [nuxi](https://github.com/nuxt/cli) from 3.17.1 to 3.17.2. - [Release notes](https://github.com/nuxt/cli/releases) - [Changelog](https://github.com/nuxt/cli/blob/main/CHANGELOG.md) - [Commits](https://github.com/nuxt/cli/compare/v3.17.1...v3.17.2) --- updated-dependencies: - dependency-name: nuxi dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ---------- | ------ | ------ | | nuxi | 3.17.1 | 3.17.2 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7646.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7646.md diff --git a/.changeset/c3-frameworks-update-7646.md b/.changeset/c3-frameworks-update-7646.md new file mode 100644 index 000000000000..13cd1a002de1 --- /dev/null +++ b/.changeset/c3-frameworks-update-7646.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ---------- | ------ | ------ | +| nuxi | 3.17.1 | 3.17.2 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 6fe5ed867aff..1842e749198c 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -18,6 +18,6 @@ "create-vue": "3.13.0", "gatsby": "5.14.1", "sv": "0.6.10", - "nuxi": "3.17.1" + "nuxi": "3.17.2" } } From 2e78812ade7cd7361b023c90afe06221a52b79eb Mon Sep 17 00:00:00 2001 From: James Ross Date: Wed, 1 Jan 2025 03:43:34 +0000 Subject: [PATCH 44/53] fix: better handler malformed paths (#7612) * fix: better handler malformed paths * chore: changeset * fix: pass-through malformed paths better --- .changeset/empty-cars-provide.md | 5 +++ .../asset-worker/src/handler.ts | 18 ++++++++- .../asset-worker/tests/handler.test.ts | 38 +++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 .changeset/empty-cars-provide.md diff --git a/.changeset/empty-cars-provide.md b/.changeset/empty-cars-provide.md new file mode 100644 index 000000000000..2b6f0d28a121 --- /dev/null +++ b/.changeset/empty-cars-provide.md @@ -0,0 +1,5 @@ +--- +"@cloudflare/workers-shared": patch +--- + +fix: resolves an issue where a malformed path such as `https://example.com/%A0` would cause an unhandled error diff --git a/packages/workers-shared/asset-worker/src/handler.ts b/packages/workers-shared/asset-worker/src/handler.ts index 6e78aaf9cc58..e789e7ee3f5b 100644 --- a/packages/workers-shared/asset-worker/src/handler.ts +++ b/packages/workers-shared/asset-worker/src/handler.ts @@ -682,7 +682,14 @@ const safeRedirect = async ( export const decodePath = (pathname: string) => { return pathname .split("/") - .map((x) => decodeURIComponent(x)) + .map((x) => { + try { + const decoded = decodeURIComponent(x); + return decoded; + } catch { + return x; + } + }) .join("/"); }; /** @@ -692,6 +699,13 @@ export const decodePath = (pathname: string) => { const encodePath = (pathname: string) => { return pathname .split("/") - .map((x) => encodeURIComponent(x)) + .map((x) => { + try { + const encoded = encodeURIComponent(x); + return encoded; + } catch { + return x; + } + }) .join("/"); }; diff --git a/packages/workers-shared/asset-worker/tests/handler.test.ts b/packages/workers-shared/asset-worker/tests/handler.test.ts index 84b1f251843c..96b4cc74a355 100644 --- a/packages/workers-shared/asset-worker/tests/handler.test.ts +++ b/packages/workers-shared/asset-worker/tests/handler.test.ts @@ -150,4 +150,42 @@ describe("[Asset Worker] `handleRequest`", () => { expect(response.status).toBe(404); }); + + it("returns expected responses for malformed path", async () => { + const assets: Record = { + "/index.html": "aaaaaaaaaa", + "/%A0%A0.html": "bbbbbbbbbb", + }; + const configuration: Required = { + html_handling: "drop-trailing-slash", + not_found_handling: "none", + serve_directly: true, + }; + + const exists = async (pathname: string) => { + return assets[pathname] ?? null; + }; + const getByEtag = async (_: string) => ({ + readableStream: new ReadableStream(), + contentType: "text/html", + }); + + // first malformed URL should return 404 as no match above + const response = await handleRequest( + new Request("https://example.com/%A0"), + configuration, + exists, + getByEtag + ); + expect(response.status).toBe(404); + + // but second malformed URL should return 307 as it matches and then redirects + const response2 = await handleRequest( + new Request("https://example.com/%A0%A0"), + configuration, + exists, + getByEtag + ); + expect(response2.status).toBe(307); + }); }); From 5d90f4eca5293bc48151d20e5511427f419b9327 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Fri, 3 Jan 2025 00:20:23 +0100 Subject: [PATCH 45/53] cleanup unnecessary nullish coalescing operation (#7658) --- packages/create-cloudflare/src/helpers/compatDate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-cloudflare/src/helpers/compatDate.ts b/packages/create-cloudflare/src/helpers/compatDate.ts index 1a4bca731924..6f83faa44278 100644 --- a/packages/create-cloudflare/src/helpers/compatDate.ts +++ b/packages/create-cloudflare/src/helpers/compatDate.ts @@ -27,7 +27,7 @@ export async function getWorkerdCompatibilityDate() { const match = latestWorkerdVersion.match(/\d+\.(\d{4})(\d{2})(\d{2})\.\d+/); if (match) { - const [, year, month, date] = match ?? []; + const [, year, month, date] = match; const compatDate = `${year}-${month}-${date}`; s.stop(`${brandColor("compatibility date")} ${dim(compatDate)}`); From b4e0af163548ee8cc0aefc9165f67a0f83ea94d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 3 Jan 2025 14:25:07 +0000 Subject: [PATCH 46/53] chore(deps): bump the workerd-and-workers-types group across 1 directory with 2 updates (#7652) * chore(deps): bump the workerd-and-workers-types group across 1 directory with 2 updates Bumps the workerd-and-workers-types group with 2 updates in the / directory: [@cloudflare/workers-types](https://github.com/cloudflare/workerd) and [workerd](https://github.com/cloudflare/workerd). Updates `@cloudflare/workers-types` from 4.20241218.0 to 4.20241230.0 - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/RELEASE.md) - [Commits](https://github.com/cloudflare/workerd/commits) Updates `workerd` from 1.20241218.0 to 1.20241230.0 - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/RELEASE.md) - [Commits](https://github.com/cloudflare/workerd/compare/v1.20241218.0...v1.20241230.0) --- updated-dependencies: - dependency-name: "@cloudflare/workers-types" dependency-type: direct:production update-type: version-update:semver-minor dependency-group: workerd-and-workers-types - dependency-name: workerd dependency-type: direct:production update-type: version-update:semver-minor dependency-group: workerd-and-workers-types ... Signed-off-by: dependabot[bot] * chore: update dependencies of "miniflare" package The following dependency versions have been updated: | Dependency | From | To | | ------------------------- | ------------- | ------------- | | workerd | 1.20241218.0 | 1.20241230.0 | | @cloudflare/workers-types | ^4.20241218.0 | ^4.20241230.0 | * fix ai tests --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com> --- .changeset/dependabot-update-7652.md | 12 + fixtures/additional-modules/package.json | 2 +- fixtures/ai-app/tests/index.test.ts | 2 + fixtures/asset-config/package.json | 2 +- fixtures/get-platform-proxy/package.json | 2 +- fixtures/local-mode-tests/package.json | 2 +- fixtures/node-app-pages/package.json | 2 +- fixtures/nodejs-als-app/package.json | 2 +- fixtures/nodejs-hybrid-app/package.json | 2 +- .../pages-dev-proxy-with-script/package.json | 2 +- fixtures/pages-functions-app/package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- fixtures/pages-simple-assets/package.json | 2 +- .../vitest-pool-workers-examples/package.json | 2 +- fixtures/worker-ts/package.json | 2 +- .../workers-with-assets-only/package.json | 2 +- .../package.json | 2 +- fixtures/workers-with-assets/package.json | 2 +- fixtures/workflow-multiple/package.json | 2 +- fixtures/workflow/package.json | 2 +- package.json | 2 +- packages/create-cloudflare/package.json | 2 +- .../package.json | 2 +- packages/format-errors/package.json | 2 +- packages/kv-asset-handler/package.json | 2 +- packages/miniflare/package.json | 4 +- packages/pages-shared/package.json | 2 +- .../playground-preview-worker/package.json | 2 +- packages/prerelease-registry/package.json | 2 +- packages/quick-edit-extension/package.json | 2 +- packages/vitest-pool-workers/package.json | 2 +- packages/workers-shared/package.json | 2 +- packages/workers.new/package.json | 2 +- packages/workflows-shared/package.json | 2 +- packages/wrangler/package.json | 6 +- pnpm-lock.yaml | 206 +++++++++--------- 37 files changed, 154 insertions(+), 140 deletions(-) create mode 100644 .changeset/dependabot-update-7652.md diff --git a/.changeset/dependabot-update-7652.md b/.changeset/dependabot-update-7652.md new file mode 100644 index 000000000000..a7a4e87acfbb --- /dev/null +++ b/.changeset/dependabot-update-7652.md @@ -0,0 +1,12 @@ +--- +"miniflare": patch +--- + +chore: update dependencies of "miniflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ------------------------- | ------------- | ------------- | +| workerd | 1.20241218.0 | 1.20241230.0 | +| @cloudflare/workers-types | ^4.20241218.0 | ^4.20241230.0 | diff --git a/fixtures/additional-modules/package.json b/fixtures/additional-modules/package.json index 0fdc48a07bcf..50c543085cea 100644 --- a/fixtures/additional-modules/package.json +++ b/fixtures/additional-modules/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/ai-app/tests/index.test.ts b/fixtures/ai-app/tests/index.test.ts index 7202daf5fabb..3eb4ff54ca80 100644 --- a/fixtures/ai-app/tests/index.test.ts +++ b/fixtures/ai-app/tests/index.test.ts @@ -33,7 +33,9 @@ describe("'wrangler dev' correctly renders pages", () => { expect((content as Record).binding).toEqual({ aiGatewayLogId: null, fetcher: {}, + lastRequestHttpStatusCode: null, lastRequestId: null, + lastRequestInternalStatusCode: null, logs: [], options: {}, }); diff --git a/fixtures/asset-config/package.json b/fixtures/asset-config/package.json index 735bcb5856ed..cbeebc40885e 100644 --- a/fixtures/asset-config/package.json +++ b/fixtures/asset-config/package.json @@ -12,7 +12,7 @@ "devDependencies": { "@cloudflare/vitest-pool-workers": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "run-script-os": "^1.1.6", "typescript": "catalog:default", "undici": "catalog:default", diff --git a/fixtures/get-platform-proxy/package.json b/fixtures/get-platform-proxy/package.json index a547e6e2c514..91544bfac66b 100644 --- a/fixtures/get-platform-proxy/package.json +++ b/fixtures/get-platform-proxy/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/local-mode-tests/package.json b/fixtures/local-mode-tests/package.json index 0fa361e80c85..6f2e6efeda6b 100644 --- a/fixtures/local-mode-tests/package.json +++ b/fixtures/local-mode-tests/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/node": "catalog:default", "buffer": "^6.0.3", "typescript": "catalog:default", diff --git a/fixtures/node-app-pages/package.json b/fixtures/node-app-pages/package.json index d9b1beba44ee..aeccf8b2147a 100644 --- a/fixtures/node-app-pages/package.json +++ b/fixtures/node-app-pages/package.json @@ -15,7 +15,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/nodejs-als-app/package.json b/fixtures/nodejs-als-app/package.json index 3cbd73bd9beb..e516fc81519a 100644 --- a/fixtures/nodejs-als-app/package.json +++ b/fixtures/nodejs-als-app/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "undici": "catalog:default", "vitest": "catalog:default", "wrangler": "workspace:*" diff --git a/fixtures/nodejs-hybrid-app/package.json b/fixtures/nodejs-hybrid-app/package.json index 12de46cbb6fa..1927e8159350 100644 --- a/fixtures/nodejs-hybrid-app/package.json +++ b/fixtures/nodejs-hybrid-app/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/pg": "^8.11.2", "pg": "8.11.3", "pg-cloudflare": "^1.1.1", diff --git a/fixtures/pages-dev-proxy-with-script/package.json b/fixtures/pages-dev-proxy-with-script/package.json index 378ba9982c9c..1c7f00d2a074 100644 --- a/fixtures/pages-dev-proxy-with-script/package.json +++ b/fixtures/pages-dev-proxy-with-script/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/pages-functions-app/package.json b/fixtures/pages-functions-app/package.json index fcf83b9bf7ce..cf17f4fe3be8 100644 --- a/fixtures/pages-functions-app/package.json +++ b/fixtures/pages-functions-app/package.json @@ -15,7 +15,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "pages-plugin-example": "workspace:*", "typescript": "catalog:default", "undici": "catalog:default", diff --git a/fixtures/pages-functions-with-routes-app/package.json b/fixtures/pages-functions-with-routes-app/package.json index 0659113ffd32..497d99d3f7a5 100644 --- a/fixtures/pages-functions-with-routes-app/package.json +++ b/fixtures/pages-functions-with-routes-app/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/pages-plugin-mounted-on-root-app/package.json b/fixtures/pages-plugin-mounted-on-root-app/package.json index 1cfa3c2c2660..41497ef9b41d 100644 --- a/fixtures/pages-plugin-mounted-on-root-app/package.json +++ b/fixtures/pages-plugin-mounted-on-root-app/package.json @@ -15,7 +15,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "pages-plugin-example": "workspace:*", "typescript": "catalog:default", "undici": "catalog:default", diff --git a/fixtures/pages-simple-assets/package.json b/fixtures/pages-simple-assets/package.json index 119bfbf797d2..1f54692ea300 100644 --- a/fixtures/pages-simple-assets/package.json +++ b/fixtures/pages-simple-assets/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/vitest-pool-workers-examples/package.json b/fixtures/vitest-pool-workers-examples/package.json index e9bdeeeddb91..76250bbcdccf 100644 --- a/fixtures/vitest-pool-workers-examples/package.json +++ b/fixtures/vitest-pool-workers-examples/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@cloudflare/vitest-pool-workers": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/node": "catalog:default", "ext-dep": "file:./internal-module-resolution/vendor/ext-dep", "jose": "^5.2.2", diff --git a/fixtures/worker-ts/package.json b/fixtures/worker-ts/package.json index 591c0bdbaa56..1f266750d58f 100644 --- a/fixtures/worker-ts/package.json +++ b/fixtures/worker-ts/package.json @@ -6,7 +6,7 @@ "start": "wrangler dev" }, "devDependencies": { - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "wrangler": "workspace:*" }, "volta": { diff --git a/fixtures/workers-with-assets-only/package.json b/fixtures/workers-with-assets-only/package.json index 934984b91196..aec408b7200c 100644 --- a/fixtures/workers-with-assets-only/package.json +++ b/fixtures/workers-with-assets-only/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/workers-with-assets-serve-directly/package.json b/fixtures/workers-with-assets-serve-directly/package.json index 52e597e8e5a0..690871d78acd 100644 --- a/fixtures/workers-with-assets-serve-directly/package.json +++ b/fixtures/workers-with-assets-serve-directly/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/workers-with-assets/package.json b/fixtures/workers-with-assets/package.json index bdb550788e88..6c2e8b619c32 100644 --- a/fixtures/workers-with-assets/package.json +++ b/fixtures/workers-with-assets/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/workflow-multiple/package.json b/fixtures/workflow-multiple/package.json index b9355a2413d9..81826bf5506b 100644 --- a/fixtures/workflow-multiple/package.json +++ b/fixtures/workflow-multiple/package.json @@ -7,7 +7,7 @@ "test:ci": "vitest run" }, "devDependencies": { - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/fixtures/workflow/package.json b/fixtures/workflow/package.json index 0f8d252922e2..26d59b42f53d 100644 --- a/fixtures/workflow/package.json +++ b/fixtures/workflow/package.json @@ -7,7 +7,7 @@ "test:ci": "vitest run" }, "devDependencies": { - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "typescript": "catalog:default", "undici": "catalog:default", "vitest": "catalog:default", diff --git a/package.json b/package.json index 2b01bf28ba73..f55ce9f5970c 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.1", "@changesets/parse": "^0.4.0", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@ianvs/prettier-plugin-sort-imports": "4.2.1", "@manypkg/cli": "^0.21.4", "@turbo/gen": "^1.10.13", diff --git a/packages/create-cloudflare/package.json b/packages/create-cloudflare/package.json index 31fb01707350..589a13b50829 100644 --- a/packages/create-cloudflare/package.json +++ b/packages/create-cloudflare/package.json @@ -49,7 +49,7 @@ "@cloudflare/cli": "workspace:*", "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@iarna/toml": "^3.0.0", "@types/command-exists": "^1.2.0", "@types/cross-spawn": "^6.0.2", diff --git a/packages/edge-preview-authenticated-proxy/package.json b/packages/edge-preview-authenticated-proxy/package.json index ce0940d97bea..cf5527319039 100644 --- a/packages/edge-preview-authenticated-proxy/package.json +++ b/packages/edge-preview-authenticated-proxy/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/cookie": "^0.6.0", "cookie": "^0.6.0", "promjs": "^0.4.2", diff --git a/packages/format-errors/package.json b/packages/format-errors/package.json index 0838789dcda6..5db78cbb4415 100644 --- a/packages/format-errors/package.json +++ b/packages/format-errors/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "mustache": "^4.2.0", "promjs": "^0.4.2", "toucan-js": "^3.3.1", diff --git a/packages/kv-asset-handler/package.json b/packages/kv-asset-handler/package.json index b0e277877ccf..b5846483da8c 100644 --- a/packages/kv-asset-handler/package.json +++ b/packages/kv-asset-handler/package.json @@ -42,7 +42,7 @@ }, "devDependencies": { "@ava/typescript": "^4.1.0", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/mime": "^3.0.4", "@types/node": "catalog:default", "@types/service-worker-mock": "^2.0.1", diff --git a/packages/miniflare/package.json b/packages/miniflare/package.json index be6716c02d15..e0ba14dd5dce 100644 --- a/packages/miniflare/package.json +++ b/packages/miniflare/package.json @@ -50,7 +50,7 @@ "glob-to-regexp": "^0.4.1", "stoppable": "^1.1.0", "undici": "catalog:default", - "workerd": "1.20241218.0", + "workerd": "1.20241230.0", "ws": "^8.18.0", "youch": "^3.2.2", "zod": "^3.22.3" @@ -59,7 +59,7 @@ "@ava/typescript": "^4.1.0", "@cloudflare/kv-asset-handler": "workspace:*", "@cloudflare/workers-shared": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@cloudflare/workflows-shared": "workspace:*", "@microsoft/api-extractor": "^7.47.0", "@types/debug": "^4.1.7", diff --git a/packages/pages-shared/package.json b/packages/pages-shared/package.json index aee1ff835fd0..de77ffe1871b 100644 --- a/packages/pages-shared/package.json +++ b/packages/pages-shared/package.json @@ -23,7 +23,7 @@ }, "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@miniflare/cache": "^2.14.2", "@miniflare/core": "^2.14.2", "@miniflare/html-rewriter": "^2.14.2", diff --git a/packages/playground-preview-worker/package.json b/packages/playground-preview-worker/package.json index 44379d2c9fff..f804f277618d 100644 --- a/packages/playground-preview-worker/package.json +++ b/packages/playground-preview-worker/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/cookie": "^0.6.0", "cookie": "^0.6.0", "itty-router": "^4.0.13", diff --git a/packages/prerelease-registry/package.json b/packages/prerelease-registry/package.json index 52a137406025..25537de1acf1 100644 --- a/packages/prerelease-registry/package.json +++ b/packages/prerelease-registry/package.json @@ -18,7 +18,7 @@ "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "wrangler": "workspace:*" }, "volta": { diff --git a/packages/quick-edit-extension/package.json b/packages/quick-edit-extension/package.json index 4bfa6629d29e..d01ce7e113f7 100644 --- a/packages/quick-edit-extension/package.json +++ b/packages/quick-edit-extension/package.json @@ -43,7 +43,7 @@ ], "devDependencies": { "@cloudflare/workers-tsconfig": "workspace:^", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "esbuild": "0.17.19", "esbuild-register": "^3.5.0" }, diff --git a/packages/vitest-pool-workers/package.json b/packages/vitest-pool-workers/package.json index bd1740da036b..a36d42389c0f 100644 --- a/packages/vitest-pool-workers/package.json +++ b/packages/vitest-pool-workers/package.json @@ -64,7 +64,7 @@ "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/node": "catalog:default", "@types/semver": "^7.5.1", "@vitest/runner": "catalog:default", diff --git a/packages/workers-shared/package.json b/packages/workers-shared/package.json index be368edff415..df42eb511749 100644 --- a/packages/workers-shared/package.json +++ b/packages/workers-shared/package.json @@ -50,7 +50,7 @@ "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/vitest-pool-workers": "^0.5.31", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/mime": "^3.0.4", "concurrently": "^8.2.2", "esbuild": "0.17.19", diff --git a/packages/workers.new/package.json b/packages/workers.new/package.json index 817a80a229df..c9dc02f673e9 100644 --- a/packages/workers.new/package.json +++ b/packages/workers.new/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@cloudflare/vitest-pool-workers": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/node": "catalog:default", "miniflare": "workspace:*", "typescript": "catalog:default", diff --git a/packages/workflows-shared/package.json b/packages/workflows-shared/package.json index 7750ebd6e0b9..ba8e5fea429a 100644 --- a/packages/workflows-shared/package.json +++ b/packages/workflows-shared/package.json @@ -41,7 +41,7 @@ "devDependencies": { "@cloudflare/eslint-config-worker": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@types/mime": "^3.0.4", "esbuild": "0.17.19", "rimraf": "^6.0.1", diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 88e0bab76609..f589c93b6f12 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -84,7 +84,7 @@ "selfsigned": "^2.0.1", "source-map": "^0.6.1", "unenv": "npm:unenv-nightly@2.0.0-20241218-183400-5d6aec3", - "workerd": "1.20241218.0", + "workerd": "1.20241230.0", "xxhash-wasm": "^1.0.1" }, "devDependencies": { @@ -94,7 +94,7 @@ "@cloudflare/types": "6.18.4", "@cloudflare/workers-shared": "workspace:*", "@cloudflare/workers-tsconfig": "workspace:*", - "@cloudflare/workers-types": "^4.20241218.0", + "@cloudflare/workers-types": "^4.20241230.0", "@cspotcode/source-map-support": "0.8.1", "@iarna/toml": "^3.0.0", "@microsoft/api-extractor": "^7.47.0", @@ -163,7 +163,7 @@ "yargs": "^17.7.2" }, "peerDependencies": { - "@cloudflare/workers-types": "^4.20241218.0" + "@cloudflare/workers-types": "^4.20241230.0" }, "peerDependenciesMeta": { "@cloudflare/workers-types": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f598fd8d1d5a..465591eb467b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,8 +65,8 @@ importers: specifier: ^0.4.0 version: 0.4.0 '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@ianvs/prettier-plugin-sort-imports': specifier: 4.2.1 version: 4.2.1(@vue/compiler-sfc@3.3.4)(prettier@3.2.5) @@ -128,8 +128,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -170,8 +170,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 run-script-os: specifier: ^1.1.6 version: 1.1.6 @@ -233,8 +233,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -303,8 +303,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/node': specifier: ^18.19.59 version: 18.19.59 @@ -343,8 +343,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -364,8 +364,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 undici: specifier: catalog:default version: 5.28.4 @@ -382,8 +382,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/pg': specifier: ^8.11.2 version: 8.11.6 @@ -427,8 +427,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -452,8 +452,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 pages-plugin-example: specifier: workspace:* version: link:../pages-plugin-example @@ -512,8 +512,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -564,8 +564,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 pages-plugin-example: specifier: workspace:* version: link:../pages-plugin-example @@ -609,8 +609,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -808,8 +808,8 @@ importers: specifier: workspace:* version: link:../../packages/vitest-pool-workers '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/node': specifier: ^18.19.59 version: 18.19.59 @@ -868,8 +868,8 @@ importers: fixtures/worker-ts: devDependencies: '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 wrangler: specifier: workspace:* version: link:../../packages/wrangler @@ -882,8 +882,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -903,8 +903,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -924,8 +924,8 @@ importers: specifier: workspace:* version: link:../../packages/workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -942,8 +942,8 @@ importers: fixtures/workflow: devDependencies: '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -960,8 +960,8 @@ importers: fixtures/workflow-multiple: devDependencies: '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 typescript: specifier: catalog:default version: 5.6.3 @@ -1086,8 +1086,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@iarna/toml': specifier: ^3.0.0 version: 3.0.0 @@ -1215,8 +1215,8 @@ importers: specifier: workspace:* version: link:../eslint-config-worker '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/cookie': specifier: ^0.6.0 version: 0.6.0 @@ -1270,8 +1270,8 @@ importers: specifier: workspace:* version: link:../eslint-config-worker '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 mustache: specifier: ^4.2.0 version: 4.2.0 @@ -1301,8 +1301,8 @@ importers: specifier: ^4.1.0 version: 4.1.0 '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/mime': specifier: ^3.0.4 version: 3.0.4 @@ -1346,8 +1346,8 @@ importers: specifier: catalog:default version: 5.28.4 workerd: - specifier: 1.20241218.0 - version: 1.20241218.0 + specifier: 1.20241230.0 + version: 1.20241230.0 ws: specifier: ^8.18.0 version: 8.18.0 @@ -1368,8 +1368,8 @@ importers: specifier: workspace:* version: link:../workers-shared '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@cloudflare/workflows-shared': specifier: workspace:* version: link:../workflows-shared @@ -1483,8 +1483,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@miniflare/cache': specifier: ^2.14.2 version: 2.14.2 @@ -1517,8 +1517,8 @@ importers: specifier: workspace:* version: link:../eslint-config-worker '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/cookie': specifier: ^0.6.0 version: 0.6.0 @@ -1554,8 +1554,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 wrangler: specifier: workspace:* version: link:../wrangler @@ -1585,8 +1585,8 @@ importers: specifier: workspace:^ version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 esbuild: specifier: 0.17.19 version: 0.17.19 @@ -1668,8 +1668,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/node': specifier: ^18.19.59 version: 18.19.59 @@ -1879,13 +1879,13 @@ importers: version: link:../eslint-config-worker '@cloudflare/vitest-pool-workers': specifier: ^0.5.31 - version: 0.5.31(@cloudflare/workers-types@4.20241218.0)(@vitest/runner@2.1.8)(@vitest/snapshot@2.1.8)(vitest@2.1.8) + version: 0.5.31(@cloudflare/workers-types@4.20241230.0)(@vitest/runner@2.1.8)(@vitest/snapshot@2.1.8)(vitest@2.1.8) '@cloudflare/workers-tsconfig': specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/mime': specifier: ^3.0.4 version: 3.0.4 @@ -1916,8 +1916,8 @@ importers: specifier: workspace:* version: link:../vitest-pool-workers '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/node': specifier: ^18.19.59 version: 18.19.59 @@ -1956,8 +1956,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@types/mime': specifier: ^3.0.4 version: 3.0.4 @@ -2022,8 +2022,8 @@ importers: specifier: npm:unenv-nightly@2.0.0-20241218-183400-5d6aec3 version: unenv-nightly@2.0.0-20241218-183400-5d6aec3 workerd: - specifier: 1.20241218.0 - version: 1.20241218.0 + specifier: 1.20241230.0 + version: 1.20241230.0 xxhash-wasm: specifier: ^1.0.1 version: 1.0.1 @@ -2051,8 +2051,8 @@ importers: specifier: workspace:* version: link:../workers-tsconfig '@cloudflare/workers-types': - specifier: ^4.20241218.0 - version: 4.20241218.0 + specifier: ^4.20241230.0 + version: 4.20241230.0 '@cspotcode/source-map-support': specifier: 0.8.1 version: 0.8.1 @@ -2812,8 +2812,8 @@ packages: cpu: [x64] os: [darwin] - '@cloudflare/workerd-darwin-64@1.20241218.0': - resolution: {integrity: sha512-8rveQoxtUvlmORKqTWgjv2ycM8uqWox0u9evn3zd2iWKdou5sncFwH517ZRLI3rq9P31ZLmCQBZ0gloFsTeY6w==} + '@cloudflare/workerd-darwin-64@1.20241230.0': + resolution: {integrity: sha512-BZHLg4bbhNQoaY1Uan81O3FV/zcmWueC55juhnaI7NAobiQth9RppadPNpxNAmS9fK2mR5z8xrwMQSQrHmztyQ==} engines: {node: '>=16'} cpu: [x64] os: [darwin] @@ -2830,8 +2830,8 @@ packages: cpu: [arm64] os: [darwin] - '@cloudflare/workerd-darwin-arm64@1.20241218.0': - resolution: {integrity: sha512-be59Ad9nmM9lCkhHqmTs/uZ3JVZt8NJ9Z0PY+B0xnc5z6WwmV2lj0RVLtq7xJhQsQJA189zt5rXqDP6J+2mu7Q==} + '@cloudflare/workerd-darwin-arm64@1.20241230.0': + resolution: {integrity: sha512-lllxycj7EzYoJ0VOJh8M3palUgoonVrILnzGrgsworgWlIpgjfXGS7b41tEGCw6AxSxL9prmTIGtfSPUvn/rjg==} engines: {node: '>=16'} cpu: [arm64] os: [darwin] @@ -2848,8 +2848,8 @@ packages: cpu: [x64] os: [linux] - '@cloudflare/workerd-linux-64@1.20241218.0': - resolution: {integrity: sha512-MzpSBcfZXRxrYWxQ4pVDYDrUbkQuM62ssl4ZtHH8J35OAeGsWFAYji6MkS2SpVwVcvacPwJXIF4JSzp4xKImKw==} + '@cloudflare/workerd-linux-64@1.20241230.0': + resolution: {integrity: sha512-Y3mHcW0KghOmWdNZyHYpEOG4Ba/ga8tht5vj1a+WXfagEjMO8Y98XhZUlCaYa9yB7Wh5jVcK5LM2jlO/BLgqpA==} engines: {node: '>=16'} cpu: [x64] os: [linux] @@ -2866,8 +2866,8 @@ packages: cpu: [arm64] os: [linux] - '@cloudflare/workerd-linux-arm64@1.20241218.0': - resolution: {integrity: sha512-RIuJjPxpNqvwIs52vQsXeRMttvhIjgg9NLjjFa3jK8Ijnj8c3ZDru9Wqi48lJP07yDFIRr4uDMMqh/y29YQi2A==} + '@cloudflare/workerd-linux-arm64@1.20241230.0': + resolution: {integrity: sha512-IAjhsWPlHzhhkJ6I49sDG6XfMnhPvv0szKGXxTWQK/IWMrbGdHm4RSfNKBSoLQm67jGMIzbmcrX9UIkms27Y1g==} engines: {node: '>=16'} cpu: [arm64] os: [linux] @@ -2884,8 +2884,8 @@ packages: cpu: [x64] os: [win32] - '@cloudflare/workerd-windows-64@1.20241218.0': - resolution: {integrity: sha512-tO1VjlvK3F6Yb2d1jgEy/QBYl//9Pyv3K0j+lq8Eu7qdfm0IgKwSRgDWLept84/qmNsQfausZ4JdNGxTf9xsxQ==} + '@cloudflare/workerd-windows-64@1.20241230.0': + resolution: {integrity: sha512-y5SPIk9iOb2gz+yWtHxoeMnjPnkYQswiCJ480oHC6zexnJLlKTpcmBCjDH1nWCT4pQi8F25gaH8thgElf4NvXQ==} engines: {node: '>=16'} cpu: [x64] os: [win32] @@ -2894,8 +2894,8 @@ packages: resolution: {integrity: sha512-1OvFkNtslaMZAJsaocTmbACApgmWv55uLpNj50Pn2MGcxdAjpqykXJFQw5tKc+lGV9TDZh9oO3Rsk17IEQDzIg==} engines: {node: '>=16.7.0'} - '@cloudflare/workers-types@4.20241218.0': - resolution: {integrity: sha512-Y0brjmJHcAZBXOPI7lU5hbiXglQWniA1kQjot2ata+HFimyjPPcz+4QWBRrmWcMPo0OadR2Vmac7WStDLpvz0w==} + '@cloudflare/workers-types@4.20241230.0': + resolution: {integrity: sha512-dtLD4jY35Lb750cCVyO1i/eIfdZJg2Z0i+B1RYX6BVeRPlgaHx/H18ImKAkYmy0g09Ow8R2jZy3hIxMgXun0WQ==} '@colors/colors@1.5.0': resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==} @@ -10055,8 +10055,8 @@ packages: engines: {node: '>=16'} hasBin: true - workerd@1.20241218.0: - resolution: {integrity: sha512-7Z3D4vOVChMz9mWDffE299oQxUWm/pbkeAWx1btVamPcAK/2IuoNBhwflWo3jyuKuxvYuFAdIucgYxc8ICqXiA==} + workerd@1.20241230.0: + resolution: {integrity: sha512-EgixXP0JGXGq6J9lz17TKIZtfNDUvJNG+cl9paPMfZuYWT920fFpBx+K04YmnbQRLnglsivF1GT9pxh1yrlWhg==} engines: {node: '>=16'} hasBin: true @@ -11089,7 +11089,7 @@ snapshots: lodash.memoize: 4.1.2 marked: 0.3.19 - '@cloudflare/vitest-pool-workers@0.5.31(@cloudflare/workers-types@4.20241218.0)(@vitest/runner@2.1.8)(@vitest/snapshot@2.1.8)(vitest@2.1.8)': + '@cloudflare/vitest-pool-workers@0.5.31(@cloudflare/workers-types@4.20241230.0)(@vitest/runner@2.1.8)(@vitest/snapshot@2.1.8)(vitest@2.1.8)': dependencies: '@vitest/runner': 2.1.8 '@vitest/snapshot': 2.1.8 @@ -11100,7 +11100,7 @@ snapshots: miniflare: 3.20241106.1 semver: 7.5.4 vitest: 2.1.8(@types/node@18.19.59)(@vitest/ui@2.1.8)(msw@2.4.3(typescript@5.6.3))(supports-color@9.2.2) - wrangler: 3.90.0(@cloudflare/workers-types@4.20241218.0) + wrangler: 3.90.0(@cloudflare/workers-types@4.20241230.0) zod: 3.22.3 transitivePeerDependencies: - '@cloudflare/workers-types' @@ -11114,7 +11114,7 @@ snapshots: '@cloudflare/workerd-darwin-64@1.20241216.0': optional: true - '@cloudflare/workerd-darwin-64@1.20241218.0': + '@cloudflare/workerd-darwin-64@1.20241230.0': optional: true '@cloudflare/workerd-darwin-arm64@1.20241106.1': @@ -11123,7 +11123,7 @@ snapshots: '@cloudflare/workerd-darwin-arm64@1.20241216.0': optional: true - '@cloudflare/workerd-darwin-arm64@1.20241218.0': + '@cloudflare/workerd-darwin-arm64@1.20241230.0': optional: true '@cloudflare/workerd-linux-64@1.20241106.1': @@ -11132,7 +11132,7 @@ snapshots: '@cloudflare/workerd-linux-64@1.20241216.0': optional: true - '@cloudflare/workerd-linux-64@1.20241218.0': + '@cloudflare/workerd-linux-64@1.20241230.0': optional: true '@cloudflare/workerd-linux-arm64@1.20241106.1': @@ -11141,7 +11141,7 @@ snapshots: '@cloudflare/workerd-linux-arm64@1.20241216.0': optional: true - '@cloudflare/workerd-linux-arm64@1.20241218.0': + '@cloudflare/workerd-linux-arm64@1.20241230.0': optional: true '@cloudflare/workerd-windows-64@1.20241106.1': @@ -11150,7 +11150,7 @@ snapshots: '@cloudflare/workerd-windows-64@1.20241216.0': optional: true - '@cloudflare/workerd-windows-64@1.20241218.0': + '@cloudflare/workerd-windows-64@1.20241230.0': optional: true '@cloudflare/workers-shared@0.8.0': @@ -11158,7 +11158,7 @@ snapshots: mime: 3.0.0 zod: 3.22.3 - '@cloudflare/workers-types@4.20241218.0': {} + '@cloudflare/workers-types@4.20241230.0': {} '@colors/colors@1.5.0': optional: true @@ -18955,17 +18955,17 @@ snapshots: '@cloudflare/workerd-linux-arm64': 1.20241216.0 '@cloudflare/workerd-windows-64': 1.20241216.0 - workerd@1.20241218.0: + workerd@1.20241230.0: optionalDependencies: - '@cloudflare/workerd-darwin-64': 1.20241218.0 - '@cloudflare/workerd-darwin-arm64': 1.20241218.0 - '@cloudflare/workerd-linux-64': 1.20241218.0 - '@cloudflare/workerd-linux-arm64': 1.20241218.0 - '@cloudflare/workerd-windows-64': 1.20241218.0 + '@cloudflare/workerd-darwin-64': 1.20241230.0 + '@cloudflare/workerd-darwin-arm64': 1.20241230.0 + '@cloudflare/workerd-linux-64': 1.20241230.0 + '@cloudflare/workerd-linux-arm64': 1.20241230.0 + '@cloudflare/workerd-windows-64': 1.20241230.0 workerpool@6.5.1: {} - wrangler@3.90.0(@cloudflare/workers-types@4.20241218.0): + wrangler@3.90.0(@cloudflare/workers-types@4.20241230.0): dependencies: '@cloudflare/kv-asset-handler': 0.3.4 '@cloudflare/workers-shared': 0.8.0 @@ -18987,7 +18987,7 @@ snapshots: workerd: 1.20241106.1 xxhash-wasm: 1.0.1 optionalDependencies: - '@cloudflare/workers-types': 4.20241218.0 + '@cloudflare/workers-types': 4.20241230.0 fsevents: 2.3.3 transitivePeerDependencies: - bufferutil From 755a27c7a5d7f35cb5f05ab2e12af6d64ce323fb Mon Sep 17 00:00:00 2001 From: Daniel Leal Date: Fri, 3 Jan 2025 19:26:20 +0000 Subject: [PATCH 47/53] Add Warning about browser rendering when running locally (#7533) * Warn about browser rendering when running locally * fix warning check * update snapshot --------- Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com> --- .changeset/moody-suns-chew.md | 5 +++++ packages/wrangler/src/__tests__/dev.test.ts | 17 +++++++++++++++++ .../src/api/startDevWorker/ConfigController.ts | 15 +++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 .changeset/moody-suns-chew.md diff --git a/.changeset/moody-suns-chew.md b/.changeset/moody-suns-chew.md new file mode 100644 index 000000000000..ec0576218e19 --- /dev/null +++ b/.changeset/moody-suns-chew.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Add warning about the browser rendering not available on local diff --git a/packages/wrangler/src/__tests__/dev.test.ts b/packages/wrangler/src/__tests__/dev.test.ts index a3d063658acb..b53e14a1f226 100644 --- a/packages/wrangler/src/__tests__/dev.test.ts +++ b/packages/wrangler/src/__tests__/dev.test.ts @@ -1879,6 +1879,23 @@ describe.sequential("wrangler dev", () => { }); }); + describe("`browser rendering binding", () => { + it("should show error when running locally", async () => { + writeWranglerConfig({ + browser: { + binding: "MYBROWSER", + }, + }); + fs.writeFileSync("index.js", `export default {};`); + + await expect( + runWrangler("dev index.js") + ).rejects.toThrowErrorMatchingInlineSnapshot( + "[Error: Browser Rendering is not supported locally. Please use `wrangler dev --remote` instead.]" + ); + }); + }); + it("should error helpfully if pages_build_output_dir is set", async () => { writeWranglerConfig({ pages_build_output_dir: "dist", name: "test" }); await expect(runWrangler("dev")).rejects.toThrowErrorMatchingInlineSnapshot( diff --git a/packages/wrangler/src/api/startDevWorker/ConfigController.ts b/packages/wrangler/src/api/startDevWorker/ConfigController.ts index 2b085db269e2..eae79d2fa377 100644 --- a/packages/wrangler/src/api/startDevWorker/ConfigController.ts +++ b/packages/wrangler/src/api/startDevWorker/ConfigController.ts @@ -315,6 +315,21 @@ async function resolveConfig( ); } + if (resolved.assets && resolved.dev.remote) { + throw new UserError( + "Cannot use assets in remote mode. Workers with assets are only supported in local mode. Please use `wrangler dev`." + ); + } + + if ( + extractBindingsOfType("browser", resolved.bindings).length && + !resolved.dev.remote + ) { + throw new UserError( + "Browser Rendering is not supported locally. Please use `wrangler dev --remote` instead." + ); + } + validateAssetsArgsAndConfig(resolved); const services = extractBindingsOfType("service", resolved.bindings); From 00b8dfbfcbc2d08f38aa1fcbb7e035efa3624181 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 6 Jan 2025 11:54:50 +0100 Subject: [PATCH 48/53] test(nodejs-hybrid-app): factor test setup (#7628) --- .../nodejs-hybrid-app/tests/index.test.ts | 109 +++++++----------- 1 file changed, 42 insertions(+), 67 deletions(-) diff --git a/fixtures/nodejs-hybrid-app/tests/index.test.ts b/fixtures/nodejs-hybrid-app/tests/index.test.ts index d9fbda7f1b67..4b379b4821ca 100644 --- a/fixtures/nodejs-hybrid-app/tests/index.test.ts +++ b/fixtures/nodejs-hybrid-app/tests/index.test.ts @@ -1,92 +1,67 @@ import { resolve } from "node:path"; import { fetch } from "undici"; -import { describe, it, test } from "vitest"; +import { afterAll, beforeAll, describe, it, test } from "vitest"; import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived"; describe("nodejs compat", () => { + let wrangler: Awaited>; + + beforeAll(async () => { + wrangler = await runWranglerDev(resolve(__dirname, "../src"), [ + "--port=0", + "--inspector-port=0", + ]); + }); + + afterAll(async () => { + await wrangler.stop(); + }); it("should work when running code requiring polyfills", async ({ expect, }) => { - const { ip, port, stop } = await runWranglerDev( - resolve(__dirname, "../src"), - ["--port=0", "--inspector-port=0"] - ); - try { - const response = await fetch(`http://${ip}:${port}/test-process`); - const body = await response.text(); - expect(body).toMatchInlineSnapshot(`"OK!"`); + const { ip, port } = wrangler; + const response = await fetch(`http://${ip}:${port}/test-process`); + const body = await response.text(); + expect(body).toMatchInlineSnapshot(`"OK!"`); - // Disabling actually querying the database since we are getting this error: - // > too many connections for role 'reader' - // const response = await fetch(`http://${ip}:${port}/query`); - // const body = await response.text(); - // console.log(body); - // const result = JSON.parse(body) as { id: string }; - // expect(result.id).toEqual("1"); - } finally { - await stop(); - } + // Disabling actually querying the database since we are getting this error: + // > too many connections for role 'reader' + // const response = await fetch(`http://${ip}:${port}/query`); + // const body = await response.text(); + // console.log(body); + // const result = JSON.parse(body) as { id: string }; + // expect(result.id).toEqual("1"); }); it("should be able to call `getRandomValues()` bound to any object", async ({ expect, }) => { - const { ip, port, stop } = await runWranglerDev( - resolve(__dirname, "../src"), - ["--port=0", "--inspector-port=0"] - ); - try { - const response = await fetch(`http://${ip}:${port}/test-random`); - const body = await response.json(); - expect(body).toEqual([ - expect.any(String), - expect.any(String), - expect.any(String), - expect.any(String), - ]); - } finally { - await stop(); - } + const { ip, port } = wrangler; + const response = await fetch(`http://${ip}:${port}/test-random`); + const body = await response.json(); + expect(body).toEqual([ + expect.any(String), + expect.any(String), + expect.any(String), + expect.any(String), + ]); }); test("crypto.X509Certificate is implemented", async ({ expect }) => { - const { ip, port, stop } = await runWranglerDev( - resolve(__dirname, "../src"), - ["--port=0", "--inspector-port=0"] - ); - try { - const response = await fetch( - `http://${ip}:${port}/test-x509-certificate` - ); - await expect(response.text()).resolves.toBe(`"OK!"`); - } finally { - await stop(); - } + const { ip, port } = wrangler; + const response = await fetch(`http://${ip}:${port}/test-x509-certificate`); + await expect(response.text()).resolves.toBe(`"OK!"`); }); test("import unenv aliased packages", async ({ expect }) => { - const { ip, port, stop } = await runWranglerDev( - resolve(__dirname, "../src"), - ["--port=0", "--inspector-port=0"] - ); - try { - const response = await fetch(`http://${ip}:${port}/test-require-alias`); - await expect(response.text()).resolves.toBe(`"OK!"`); - } finally { - await stop(); - } + const { ip, port } = wrangler; + const response = await fetch(`http://${ip}:${port}/test-require-alias`); + await expect(response.text()).resolves.toBe(`"OK!"`); }); test("unenv preset", async ({ expect }) => { - const { ip, port, stop } = await runWranglerDev( - resolve(__dirname, "../src"), - ["--port=0", "--inspector-port=0"] - ); - try { - const response = await fetch(`http://${ip}:${port}/test-unenv-preset`); - await expect(response.text()).resolves.toBe("OK!"); - } finally { - await stop(); - } + const { ip, port } = wrangler; + const response = await fetch(`http://${ip}:${port}/test-unenv-preset`); + await expect(response.text()).resolves.toBe("OK!"); }); }); From 8ab13b2d7b397010532939bb9ba804c7dc84ea37 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:27:45 +0000 Subject: [PATCH 49/53] [C3] bump create-docusaurus from 3.6.3 to 3.7.0 in /packages/create-cloudflare/src/frameworks (#7673) * [C3] bump create-docusaurus Bumps [create-docusaurus](https://github.com/facebook/docusaurus/tree/HEAD/packages/create-docusaurus) from 3.6.3 to 3.7.0. - [Release notes](https://github.com/facebook/docusaurus/releases) - [Changelog](https://github.com/facebook/docusaurus/blob/main/CHANGELOG.md) - [Commits](https://github.com/facebook/docusaurus/commits/v3.7.0/packages/create-docusaurus) --- updated-dependencies: - dependency-name: create-docusaurus dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * chore: update dependencies of "create-cloudflare" package The following dependency versions have been updated: | Dependency | From | To | | ----------------- | ----- | ----- | | create-docusaurus | 3.6.3 | 3.7.0 | --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater --- .changeset/c3-frameworks-update-7673.md | 11 +++++++++++ .../create-cloudflare/src/frameworks/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/c3-frameworks-update-7673.md diff --git a/.changeset/c3-frameworks-update-7673.md b/.changeset/c3-frameworks-update-7673.md new file mode 100644 index 000000000000..792ff77c485d --- /dev/null +++ b/.changeset/c3-frameworks-update-7673.md @@ -0,0 +1,11 @@ +--- +"create-cloudflare": patch +--- + +chore: update dependencies of "create-cloudflare" package + +The following dependency versions have been updated: + +| Dependency | From | To | +| ----------------- | ----- | ----- | +| create-docusaurus | 3.6.3 | 3.7.0 | diff --git a/packages/create-cloudflare/src/frameworks/package.json b/packages/create-cloudflare/src/frameworks/package.json index 1842e749198c..0f65ae7035d2 100644 --- a/packages/create-cloudflare/src/frameworks/package.json +++ b/packages/create-cloudflare/src/frameworks/package.json @@ -8,7 +8,7 @@ "create-astro": "4.11.0", "create-analog": "1.8.1", "@angular/create": "19.0.6", - "create-docusaurus": "3.6.3", + "create-docusaurus": "3.7.0", "create-hono": "0.14.3", "create-next-app": "15.1.3", "create-qwik": "1.12.0", From f5b3fb5117fc341c442d119713c667204f7b8d2e Mon Sep 17 00:00:00 2001 From: emily-shen <69125074+emily-shen@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:19:13 +0000 Subject: [PATCH 50/53] remove old assets remote check (#7675) --- .../wrangler/src/api/startDevWorker/ConfigController.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/wrangler/src/api/startDevWorker/ConfigController.ts b/packages/wrangler/src/api/startDevWorker/ConfigController.ts index eae79d2fa377..d8a71ed43cb0 100644 --- a/packages/wrangler/src/api/startDevWorker/ConfigController.ts +++ b/packages/wrangler/src/api/startDevWorker/ConfigController.ts @@ -315,12 +315,6 @@ async function resolveConfig( ); } - if (resolved.assets && resolved.dev.remote) { - throw new UserError( - "Cannot use assets in remote mode. Workers with assets are only supported in local mode. Please use `wrangler dev`." - ); - } - if ( extractBindingsOfType("browser", resolved.bindings).length && !resolved.dev.remote From 94f650eaa1c25b626a05c1a0c2b107910656dcf7 Mon Sep 17 00:00:00 2001 From: Romeu Palos de Gouvea Date: Mon, 6 Jan 2025 07:49:14 -0800 Subject: [PATCH 51/53] fix(vitest-pool-workers): fix support for query params with repeated keys (#7668) --- .changeset/moody-bikes-cross.md | 7 +++++++ .../misc/test/fetch-mock.test.ts | 11 +++++++++++ packages/vitest-pool-workers/src/worker/fetch-mock.ts | 3 +-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 .changeset/moody-bikes-cross.md diff --git a/.changeset/moody-bikes-cross.md b/.changeset/moody-bikes-cross.md new file mode 100644 index 000000000000..595919ab6b90 --- /dev/null +++ b/.changeset/moody-bikes-cross.md @@ -0,0 +1,7 @@ +--- +"@cloudflare/vitest-pool-workers": patch +--- + +fix: Add support interception of URLs with repeated key/name in its query params. + +e.g., `https://example.com/foo/bar?a=1&a=2` diff --git a/fixtures/vitest-pool-workers-examples/misc/test/fetch-mock.test.ts b/fixtures/vitest-pool-workers-examples/misc/test/fetch-mock.test.ts index 9c181bcb2f50..08c04be5d740 100644 --- a/fixtures/vitest-pool-workers-examples/misc/test/fetch-mock.test.ts +++ b/fixtures/vitest-pool-workers-examples/misc/test/fetch-mock.test.ts @@ -32,6 +32,17 @@ it("falls through to global fetch() if unmatched", async () => { expect(await response.text()).toBe("fallthrough:GET https://example.com/bad"); }); +it("intercepts URLs with query parameters with repeated keys", async () => { + fetchMock + .get("https://example.com") + .intercept({ path: "/foo/bar?a=1&a=2" }) + .reply(200, "body"); + + let response = await fetch("https://example.com/foo/bar?a=1&a=2"); + expect(response.url).toEqual("https://example.com/foo/bar?a=1&a=2"); + expect(await response.text()).toBe("body"); +}); + describe("AbortSignal", () => { let abortSignalTimeoutMock: MockInstance; diff --git a/packages/vitest-pool-workers/src/worker/fetch-mock.ts b/packages/vitest-pool-workers/src/worker/fetch-mock.ts index e0b89b0b995a..3c5e64e0cd30 100644 --- a/packages/vitest-pool-workers/src/worker/fetch-mock.ts +++ b/packages/vitest-pool-workers/src/worker/fetch-mock.ts @@ -93,11 +93,10 @@ globalThis.fetch = async (input, init) => { const bodyText = bodyArray === null ? "" : DECODER.decode(bodyArray); const dispatchOptions: Dispatcher.DispatchOptions = { origin: url.origin, - path: url.pathname, + path: url.pathname + url.search, method: request.method as Dispatcher.HttpMethod, body: bodyText, headers: requestHeaders, - query: Object.fromEntries(url.searchParams), }; requests.set(dispatchOptions, { request, body: bodyArray }); From d8fb032ba24ac284147dc481c28ab8dbcf7a9d72 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 6 Jan 2025 16:55:51 +0100 Subject: [PATCH 52/53] feat(wrangler): use unenv bulitin dependency resolution (#7625) --- .changeset/chilled-needles-notice.md | 5 ++ .../wrangler/src/__tests__/deploy.test.ts | 4 +- .../esbuild-plugins/hybrid-nodejs-compat.ts | 54 +++++++++++-------- 3 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 .changeset/chilled-needles-notice.md diff --git a/.changeset/chilled-needles-notice.md b/.changeset/chilled-needles-notice.md new file mode 100644 index 000000000000..07d7407e3592 --- /dev/null +++ b/.changeset/chilled-needles-notice.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +feat(wrangler): use unenv bulitin dependency resolution diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index ee73d119c714..eea34c238892 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -10420,7 +10420,7 @@ export default{ fs.writeFileSync( "index.js", ` - import path from 'path'; + import path from 'node:path'; console.log(path); export default {} ` @@ -10441,7 +10441,7 @@ export default{ } `); expect(fs.readFileSync("dist/index.js", { encoding: "utf-8" })).toContain( - `import path from "path";` + `import path from "node:path";` ); }); diff --git a/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts b/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts index e5a6ff9960f8..55a2fbcea2c7 100644 --- a/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts +++ b/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts @@ -1,7 +1,7 @@ import { builtinModules } from "node:module"; import nodePath from "node:path"; import dedent from "ts-dedent"; -import { cloudflare, env, nodeless } from "unenv"; +import { cloudflare, defineEnv } from "unenv"; import { getBasePath } from "../../paths"; import type { Plugin, PluginBuild } from "esbuild"; @@ -9,13 +9,25 @@ const REQUIRED_NODE_BUILT_IN_NAMESPACE = "node-built-in-modules"; const REQUIRED_UNENV_ALIAS_NAMESPACE = "required-unenv-alias"; export const nodejsHybridPlugin: () => Plugin = () => { - const { alias, inject, external } = env(nodeless, cloudflare); + // Get the resolved environment. + const { env } = defineEnv({ + nodeCompat: true, + presets: [cloudflare], + resolve: true, + }); + const { alias, inject, external } = env; + // Get the unresolved alias. + const unresolvedAlias = defineEnv({ + nodeCompat: true, + presets: [cloudflare], + resolve: false, + }).env.alias; return { name: "hybrid-nodejs_compat", setup(build) { errorOnServiceWorkerFormat(build); handleRequireCallsToNodeJSBuiltins(build); - handleUnenvAliasedPackages(build, alias, external); + handleUnenvAliasedPackages(build, unresolvedAlias, alias, external); handleNodeJSGlobals(build, inject); }, }; @@ -87,45 +99,41 @@ function handleRequireCallsToNodeJSBuiltins(build: PluginBuild) { ); } +/** + * Handles aliased NPM packages. + * + * @param build ESBuild PluginBuild. + * @param unresolvedAlias Unresolved aliases from the presets. + * @param alias Aliases resolved to absolute paths. + * @param external external modules. + */ function handleUnenvAliasedPackages( build: PluginBuild, + unresolvedAlias: Record, alias: Record, external: string[] ) { - // esbuild expects alias paths to be absolute - const aliasAbsolute: Record = {}; - for (const [module, unresolvedAlias] of Object.entries(alias)) { - try { - aliasAbsolute[module] = require - .resolve(unresolvedAlias) - .replace(/\.cjs$/, ".mjs"); - } catch (e) { - // this is an alias for package that is not installed in the current app => ignore - } - } - - const UNENV_ALIAS_RE = new RegExp( - `^(${Object.keys(aliasAbsolute).join("|")})$` - ); + const UNENV_ALIAS_RE = new RegExp(`^(${Object.keys(alias).join("|")})$`); build.onResolve({ filter: UNENV_ALIAS_RE }, (args) => { - const unresolvedAlias = alias[args.path]; + const unresolved = unresolvedAlias[args.path]; // Convert `require()` calls for NPM packages to a virtual ES Module that can be imported avoiding the require calls. // Note: Does not apply to Node.js packages that are handled in `handleRequireCallsToNodeJSBuiltins` if ( args.kind === "require-call" && - (unresolvedAlias.startsWith("unenv/runtime/npm/") || - unresolvedAlias.startsWith("unenv/runtime/mock/")) + (unresolved.startsWith("unenv/runtime/npm/") || + unresolved.startsWith("unenv/runtime/mock/")) ) { return { path: args.path, namespace: REQUIRED_UNENV_ALIAS_NAMESPACE, }; } + // Resolve the alias to its absolute path and potentially mark it as external return { - path: aliasAbsolute[args.path], - external: external.includes(unresolvedAlias), + path: alias[args.path], + external: external.includes(unresolved), }; }); From 6c5306d9da1841ba5d28a55276e357625000ded9 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 6 Jan 2025 17:03:35 +0100 Subject: [PATCH 53/53] chore: add details to #7625 changeset (#7678) --- .changeset/chilled-needles-notice.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.changeset/chilled-needles-notice.md b/.changeset/chilled-needles-notice.md index 07d7407e3592..92298bb402ec 100644 --- a/.changeset/chilled-needles-notice.md +++ b/.changeset/chilled-needles-notice.md @@ -2,4 +2,8 @@ "wrangler": patch --- -feat(wrangler): use unenv bulitin dependency resolution +feat(wrangler): use unenv builtin dependency resolution + +Moving away from `require.resolve()` to handle unenv aliased packages. +Using the unenv builtin resolution will allow us to drop the .cjs file from the preset +and to override the base path so that we can test the dev version of the preset.