From 491a52ac0eba89c8af96c3a9a6e06463ad4b023d Mon Sep 17 00:00:00 2001 From: Oli Yu Date: Wed, 4 Sep 2024 22:06:06 -0500 Subject: [PATCH 1/6] Add [[pipelines]] binding in wrangler. --- .changeset/angry-keys-dance.md | 5 + .../src/__tests__/configuration.test.ts | 101 ++++++++++++++++++ .../wrangler/src/__tests__/deploy.test.ts | 41 +++++++ .../pages/create-worker-bundle-contents.ts | 1 + packages/wrangler/src/config/config.ts | 1 + packages/wrangler/src/config/environment.ts | 17 +++ packages/wrangler/src/config/index.ts | 11 ++ packages/wrangler/src/config/validation.ts | 49 +++++++++ packages/wrangler/src/deploy/deploy.ts | 1 + .../create-worker-upload-form.ts | 13 ++- .../wrangler/src/deployment-bundle/worker.ts | 6 ++ packages/wrangler/src/dev.tsx | 1 + packages/wrangler/src/secret/index.ts | 1 + 13 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 .changeset/angry-keys-dance.md diff --git a/.changeset/angry-keys-dance.md b/.changeset/angry-keys-dance.md new file mode 100644 index 000000000000..2f9a87d36969 --- /dev/null +++ b/.changeset/angry-keys-dance.md @@ -0,0 +1,5 @@ +--- +"wrangler": minor +--- + +Added new [[pipelines]] bindings diff --git a/packages/wrangler/src/__tests__/configuration.test.ts b/packages/wrangler/src/__tests__/configuration.test.ts index 4762c4acac71..382538263c9b 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -10,6 +10,8 @@ import type { RawDevConfig, RawEnvironment, } from "../config"; +import { pipeline } from "node:stream"; +import { pipelines } from "../pipelines"; describe("readConfig()", () => { runInTempDir(); @@ -130,6 +132,7 @@ describe("normalizeAndValidateConfig()", () => { upload_source_maps: undefined, placement: undefined, tail_consumers: undefined, + pipelines: [], }); expect(diagnostics.hasErrors()).toBe(false); expect(diagnostics.hasWarnings()).toBe(false); @@ -3181,6 +3184,104 @@ describe("normalizeAndValidateConfig()", () => { }); }); + describe("[pipelines]", () => { + it("should error if pipelines is an object", () => { + const { diagnostics } = normalizeAndValidateConfig( + { pipelines: {} } as unknown as RawConfig, + undefined, + { env: undefined } + ); + + expect(diagnostics.hasWarnings()).toBe(false); + expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` + "Processing wrangler configuration: + - The field \\"pipelines\\" should be an array but got {}." + `); + }); + + it("should error if pipelines is a string", () => { + const { diagnostics } = normalizeAndValidateConfig( + { pipelines: "BAD" } as unknown as RawConfig, + undefined, + { env: undefined } + ); + + expect(diagnostics.hasWarnings()).toBe(false); + expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` + "Processing wrangler configuration: + - The field \\"pipelines\\" should be an array but got \\"BAD\\"." + `); + }); + + it("should error if pipelines is a number", () => { + const { diagnostics } = normalizeAndValidateConfig( + { pipelines: 999 } as unknown as RawConfig, + undefined, + { env: undefined } + ); + + expect(diagnostics.hasWarnings()).toBe(false); + expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` + "Processing wrangler configuration: + - The field \\"pipelines\\" should be an array but got 999." + `); + }); + + it("should error if pipelines is null", () => { + const { diagnostics } = normalizeAndValidateConfig( + { pipelines: null } as unknown as RawConfig, + undefined, + { env: undefined } + ); + + expect(diagnostics.hasWarnings()).toBe(false); + expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` + "Processing wrangler configuration: + - The field \\"pipelines\\" should be an array but got null." + `); + }); + + it("should accept valid bindings", () => { + const { diagnostics } = normalizeAndValidateConfig( + { + pipelines: [ + { binding: "VALID", pipeline: "343cd4f1d58c42fbb5bd082592fd7143" }, + ], + } as unknown as RawConfig, + undefined, + { env: undefined } + ); + + expect(diagnostics.hasErrors()).toBe(false); + }); + + it("should error if pipelines.bindings are not valid", () => { + const { diagnostics } = normalizeAndValidateConfig( + { + pipelines: [ + {}, + { binding: "VALID", pipeline: "343cd4f1d58c42fbb5bd082592fd7143" }, + { binding: 2000, project: 2111 }, + ], + } as unknown as RawConfig, + undefined, + { env: undefined } + ); + expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` + "Processing wrangler configuration: + - Unexpected fields found in pipelines[2] field: \\"project\\"" + `); + expect(diagnostics.hasWarnings()).toBe(true); + expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` + "Processing wrangler configuration: + - \\"pipelines[0]\\" bindings should have a string \\"binding\\" field but got {}. + - \\"pipelines[0]\\" bindings must have a \\"pipeline\\" field but got {}. + - \\"pipelines[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"project\\":2111}. + - \\"pipelines[2]\\" bindings must have a \\"pipeline\\" field but got {\\"binding\\":2000,\\"project\\":2111}." + `); + }); + }); + describe("[unsafe.bindings]", () => { it("should error if unsafe is an array", () => { const { diagnostics } = normalizeAndValidateConfig( diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index 5fd80f7b13b0..f21f6ec2a085 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -10466,6 +10466,47 @@ export default{ }); }); + describe("pipelines", () => { + it("should upload pipelines bindings", async () => { + writeWranglerToml({ + pipelines: [ + { + binding: "MY_PIPELINE", + pipeline: "0123456789ABCDEF0123456789ABCDEF", + }, + ], + }); + await fs.promises.writeFile("index.js", `export default {};`); + mockSubDomainRequest(); + mockUploadWorkerRequest({ + expectedBindings: [ + { + type: "pipelines", + name: "MY_PIPELINE", + id: "0123456789ABCDEF0123456789ABCDEF", + }, + ], + }); + + await runWrangler("deploy index.js"); + expect(std.out).toMatchInlineSnapshot(` + "Total Upload: xx KiB / gzip: xx KiB + Worker Startup Time: 100 ms + Your worker has access to the following bindings: + - Pipelines: + - MY_PIPELINE: 0123456789ABCDEF0123456789ABCDEF + Uploaded test-name (TIMINGS) + Published test-name (TIMINGS) + https://test-name.test-sub-domain.workers.dev + Current Deployment ID: Galaxy-Class + Current Version ID: Galaxy-Class + + + Note: Deployment ID has been renamed to Version ID. Deployment ID is present to maintain compatibility with the previous behavior of this command. This output will change in a future version of Wrangler. To learn more visit: https://developers.cloudflare.com/workers/configuration/versions-and-deployments" + `); + }); + }); + describe("--keep-vars", () => { it("should send keepVars when keep-vars is passed in", async () => { vi.stubEnv("CLOUDFLARE_API_TOKEN", "hunter2"); diff --git a/packages/wrangler/src/api/pages/create-worker-bundle-contents.ts b/packages/wrangler/src/api/pages/create-worker-bundle-contents.ts index b35e1ee482fe..eed323ff419b 100644 --- a/packages/wrangler/src/api/pages/create-worker-bundle-contents.ts +++ b/packages/wrangler/src/api/pages/create-worker-bundle-contents.ts @@ -66,6 +66,7 @@ function createWorkerBundleFormData( text_blobs: undefined, data_blobs: undefined, dispatch_namespaces: undefined, + pipelines: undefined, logfwdr: undefined, unsafe: undefined, experimental_assets: undefined, diff --git a/packages/wrangler/src/config/config.ts b/packages/wrangler/src/config/config.ts index 640743c0de33..80dc47c02c73 100644 --- a/packages/wrangler/src/config/config.ts +++ b/packages/wrangler/src/config/config.ts @@ -402,4 +402,5 @@ export const defaultWranglerConfig: Config = { }, mtls_certificates: [], tail_consumers: undefined, + pipelines: [], }; diff --git a/packages/wrangler/src/config/environment.ts b/packages/wrangler/src/config/environment.ts index 262f21ae1b9f..d3171e21e9df 100644 --- a/packages/wrangler/src/config/environment.ts +++ b/packages/wrangler/src/config/environment.ts @@ -754,6 +754,23 @@ export interface EnvironmentNonInheritable { /** Details about the outbound Worker which will handle outbound requests from your namespace */ outbound?: DispatchNamespaceOutbound; }[]; + + /** + * Specifies list of Pipelines bound to this Worker environment + * + * NOTE: This field is not automatically inherited from the top level environment, + * and so must be specified in every named environment. + * + * @default `[]` + * @nonInheritable + */ + pipelines: { + /** The binding name used to refer to the bound service. */ + binding: string; + + /** Name of the Pipeline to bind */ + pipeline: string; + }[]; } /** diff --git a/packages/wrangler/src/config/index.ts b/packages/wrangler/src/config/index.ts index 6d1c400d5141..a45908ad0434 100644 --- a/packages/wrangler/src/config/index.ts +++ b/packages/wrangler/src/config/index.ts @@ -232,6 +232,7 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) { wasm_modules, dispatch_namespaces, mtls_certificates, + pipelines, } = bindings; if (data_blobs !== undefined && Object.keys(data_blobs).length > 0) { @@ -443,6 +444,16 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) { }); } + if (pipelines != undefined && pipelines.length>0) { + output.push({ + type: "Pipelines", + entries: pipelines.map(({ binding, pipeline }) => ({ + key: binding, + value: pipeline, + })) + }) + } + if (version_metadata !== undefined) { output.push({ type: "Worker Version Metadata", diff --git a/packages/wrangler/src/config/validation.ts b/packages/wrangler/src/config/validation.ts index 1917e80c8380..cb8a65c77c67 100644 --- a/packages/wrangler/src/config/validation.ts +++ b/packages/wrangler/src/config/validation.ts @@ -1444,6 +1444,16 @@ function normalizeAndValidateEnvironment( validateAIBinding(envName), undefined ), + pipelines: notInheritable( + diagnostics, + topLevelEnv, + rawConfig, + rawEnv, + envName, + "pipelines", + validateBindingArray(envName, validatePipelineBinding), + [] + ), version_metadata: notInheritable( diagnostics, topLevelEnv, @@ -2201,6 +2211,7 @@ const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => { "service", "logfwdr", "mtls_certificate", + "pipeline", ]; if (safeBindings.includes(value.type)) { @@ -3103,6 +3114,44 @@ const validateConsumer: ValidatorFn = (diagnostics, field, value, _config) => { return isValid; }; +const validatePipelineBinding: ValidatorFn = (diagnostics, field, value) => { + if (typeof value !== "object" || value === null) { + diagnostics.errors.push( + `"pipeline" bindings should be objects, but got ${JSON.stringify( + value + )}` + ); + return false; + } + let isValid = true; + // Pipelin bindings must have a binding and a pipeline. + if (!isRequiredProperty(value, "binding", "string")) { + diagnostics.errors.push( + `"${field}" bindings should have a string "binding" field but got ${JSON.stringify( + value + )}.` + ); + isValid = false; + } + if (!isRequiredProperty(value, "pipeline", "string")) { + diagnostics.errors.push( + `"${field}" bindings must have a "pipeline" field but got ${JSON.stringify( + value + )}.` + ); + isValid = false; + } + + validateAdditionalProperties(diagnostics, field, Object.keys(value), [ + "binding", + "pipeline", + ]); + + return isValid; +}; + + + function normalizeAndValidateLimits( diagnostics: Diagnostics, topLevelEnv: Environment | undefined, diff --git a/packages/wrangler/src/deploy/deploy.ts b/packages/wrangler/src/deploy/deploy.ts index 04c81a5c4547..b0b9d3b504bb 100644 --- a/packages/wrangler/src/deploy/deploy.ts +++ b/packages/wrangler/src/deploy/deploy.ts @@ -651,6 +651,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m analytics_engine_datasets: config.analytics_engine_datasets, dispatch_namespaces: config.dispatch_namespaces, mtls_certificates: config.mtls_certificates, + pipelines: config.pipelines, logfwdr: config.logfwdr, experimental_assets: config.experimental_assets?.binding ? { binding: config.experimental_assets.binding } diff --git a/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts b/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts index 08b4886cd458..f400e0582dac 100644 --- a/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts +++ b/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts @@ -109,8 +109,9 @@ export type WorkerMetadataBinding = params?: { name: string }[]; }; } - | { type: "mtls_certificate"; name: string; certificate_id: string } - | { + | { type: "mtls_certificate"; name: string; certificate_id: string } + | { type: "pipelines"; name: string; id: string } + | { type: "logfwdr"; name: string; destination: string; @@ -316,6 +317,14 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData { }); }); + bindings.pipelines?.forEach(({ binding, pipeline }) => { + metadataBindings.push({ + name: binding, + type: 'pipelines', + id: pipeline, + }) + }) + bindings.logfwdr?.bindings.forEach(({ name, destination }) => { metadataBindings.push({ name: name, diff --git a/packages/wrangler/src/deployment-bundle/worker.ts b/packages/wrangler/src/deployment-bundle/worker.ts index 37e6478f6579..c2d2d962e45d 100644 --- a/packages/wrangler/src/deployment-bundle/worker.ts +++ b/packages/wrangler/src/deployment-bundle/worker.ts @@ -226,6 +226,11 @@ export interface CfExperimentalAssetBinding { binding: string; } +export interface CfPipeline { + binding: string; + pipeline: string; +} + export interface CfUnsafeBinding { name: string; type: string; @@ -326,6 +331,7 @@ export interface CfWorkerInit { dispatch_namespaces: CfDispatchNamespace[] | undefined; mtls_certificates: CfMTlsCertificate[] | undefined; logfwdr: CfLogfwdr | undefined; + pipelines: CfPipeline[] | undefined; unsafe: CfUnsafe | undefined; experimental_assets: CfExperimentalAssetBinding | undefined; }; diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index 1f87ccf410f6..82a02164f6f1 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -725,6 +725,7 @@ export async function startDev(args: StartDevOptions) { analytics_engine_datasets: undefined, dispatch_namespaces: undefined, mtls_certificates: undefined, + pipelines: undefined, logfwdr: undefined, unsafe: undefined, experimental_assets: undefined, diff --git a/packages/wrangler/src/secret/index.ts b/packages/wrangler/src/secret/index.ts index 0a2c62f620c6..23579f036093 100644 --- a/packages/wrangler/src/secret/index.ts +++ b/packages/wrangler/src/secret/index.ts @@ -92,6 +92,7 @@ async function createDraftWorker({ data_blobs: {}, dispatch_namespaces: [], mtls_certificates: [], + pipelines: [], logfwdr: { bindings: [] }, experimental_assets: undefined, unsafe: { From 8ddee953b89fc65e146b8d3d0a15d8410310475e Mon Sep 17 00:00:00 2001 From: Andy Jessop Date: Mon, 9 Sep 2024 11:27:43 +0200 Subject: [PATCH 2/6] chore: fix lint errors --- .../wrangler/src/__tests__/configuration.test.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/wrangler/src/__tests__/configuration.test.ts b/packages/wrangler/src/__tests__/configuration.test.ts index 382538263c9b..515adb2e3028 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -1,17 +1,15 @@ import path from "node:path"; +import type { + ConfigFields, + RawConfig, + RawDevConfig, + RawEnvironment, +} from "../config"; import { readConfig } from "../config"; import { normalizeAndValidateConfig } from "../config/validation"; import { normalizeSlashes } from "./helpers/mock-console"; import { runInTempDir } from "./helpers/run-in-tmp"; import { writeWranglerToml } from "./helpers/write-wrangler-toml"; -import type { - ConfigFields, - RawConfig, - RawDevConfig, - RawEnvironment, -} from "../config"; -import { pipeline } from "node:stream"; -import { pipelines } from "../pipelines"; describe("readConfig()", () => { runInTempDir(); From 9302e9ed8a36c8b1380881b542bbf0f38f844514 Mon Sep 17 00:00:00 2001 From: Andy Jessop Date: Mon, 9 Sep 2024 11:53:41 +0200 Subject: [PATCH 3/6] chore: fix type errors --- .../wrangler/src/api/startDevWorker/utils.ts | 19 +++-- packages/wrangler/src/dev.tsx | 83 ++++++++++--------- packages/wrangler/src/versions/upload.ts | 31 +++---- 3 files changed, 68 insertions(+), 65 deletions(-) diff --git a/packages/wrangler/src/api/startDevWorker/utils.ts b/packages/wrangler/src/api/startDevWorker/utils.ts index b237ede5814f..524bf0a27286 100644 --- a/packages/wrangler/src/api/startDevWorker/utils.ts +++ b/packages/wrangler/src/api/startDevWorker/utils.ts @@ -2,14 +2,14 @@ import assert from "node:assert"; import { readFile } from "node:fs/promises"; import type { CfWorkerInit } from "../../deployment-bundle/worker"; import type { - AsyncHook, - Binding, - File, - Hook, - HookValues, - ServiceFetch, - StartDevWorkerInput, - StartDevWorkerOptions, + AsyncHook, + Binding, + File, + Hook, + HookValues, + ServiceFetch, + StartDevWorkerInput, + StartDevWorkerOptions, } from "./types"; export type MaybePromise = T | Promise; @@ -245,7 +245,7 @@ export function convertCfWorkerInitBindingstoBindings( break; } default: { - assertNever(type); + assertNever(type as never); } } } @@ -270,6 +270,7 @@ export async function convertBindingsToCfWorkerInitBindings( version_metadata: undefined, data_blobs: undefined, durable_objects: undefined, + pipelines: undefined, queues: undefined, r2_buckets: undefined, d1_databases: undefined, diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index 82a02164f6f1..7096304b9190 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -1,18 +1,34 @@ +import { isWebContainer } from "@webcontainer/env"; +import { watch } from "chokidar"; +import { render } from "ink"; +import type { Json } from "miniflare"; import assert from "node:assert"; import events from "node:events"; import path from "node:path"; import util from "node:util"; -import { isWebContainer } from "@webcontainer/env"; -import { watch } from "chokidar"; -import { render } from "ink"; +import type React from "react"; +import type { + ProxyData, + ReloadCompleteEvent, + StartDevWorkerInput, + Trigger, +} from "./api"; import { DevEnv } from "./api"; import { - convertCfWorkerInitBindingstoBindings, - extractBindingsOfType, + convertCfWorkerInitBindingstoBindings, + extractBindingsOfType, } from "./api/startDevWorker/utils"; +import type { Config, Environment } from "./config"; import { findWranglerToml, printBindings, readConfig } from "./config"; +import type { + EnvironmentNonInheritable, + Route, + Rule, +} from "./config/environment"; import { getEntry } from "./deployment-bundle/entry"; import { getNodeCompatMode } from "./deployment-bundle/node-compat"; +import type { CfModule, CfWorkerInit } from "./deployment-bundle/worker"; +import type { WorkerRegistry } from "./dev-registry"; import { getBoundRegisteredWorkers } from "./dev-registry"; import Dev, { devRegistry } from "./dev/dev"; import { getVarsForDev } from "./dev/dev-vars"; @@ -23,54 +39,38 @@ import { startDevServer } from "./dev/start-server"; import { UserError } from "./errors"; import { processExperimentalAssetsArg } from "./experimental-assets"; import { run } from "./experimental-flags"; +import { + DEFAULT_INSPECTOR_PORT, + DEFAULT_LOCAL_PORT, + getDevCompatibilityDate, + getRules, + getScriptName, + isLegacyEnv, + printWranglerBanner, +} from "./index"; import isInteractive from "./is-interactive"; +import type { LoggerLevel } from "./logger"; import { logger } from "./logger"; import * as metrics from "./metrics"; +import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types"; import { getLegacyAssetPaths, getSiteAssetPaths } from "./sites"; import { - getAccountFromCache, - loginOrRefreshIfRequired, - requireApiToken, - requireAuth, + getAccountFromCache, + loginOrRefreshIfRequired, + requireApiToken, + requireAuth, } from "./user"; import { - collectKeyValues, - collectPlainTextVars, + collectKeyValues, + collectPlainTextVars, } from "./utils/collectKeyValues"; import { memoizeGetPort } from "./utils/memoizeGetPort"; import { mergeWithOverride } from "./utils/mergeWithOverride"; -import { getHostFromRoute, getZoneIdForPreview } from "./zones"; -import { - DEFAULT_INSPECTOR_PORT, - DEFAULT_LOCAL_PORT, - getDevCompatibilityDate, - getRules, - getScriptName, - isLegacyEnv, - printWranglerBanner, -} from "./index"; import type { - ProxyData, - ReloadCompleteEvent, - StartDevWorkerInput, - Trigger, -} from "./api"; -import type { Config, Environment } from "./config"; -import type { - EnvironmentNonInheritable, - Route, - Rule, -} from "./config/environment"; -import type { CfModule, CfWorkerInit } from "./deployment-bundle/worker"; -import type { WorkerRegistry } from "./dev-registry"; -import type { LoggerLevel } from "./logger"; -import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types"; -import type { - CommonYargsArgv, - StrictYargsOptionsToInterface, + CommonYargsArgv, + StrictYargsOptionsToInterface, } from "./yargs-types"; -import type { Json } from "miniflare"; -import type React from "react"; +import { getHostFromRoute, getZoneIdForPreview } from "./zones"; export function devOptions(yargs: CommonYargsArgv) { return ( @@ -1600,6 +1600,7 @@ export function getBindings( experimental_assets: configParam.experimental_assets?.binding ? { binding: configParam.experimental_assets?.binding } : undefined, + pipelines: configParam.pipelines, }; return bindings; diff --git a/packages/wrangler/src/versions/upload.ts b/packages/wrangler/src/versions/upload.ts index c638adf522ed..25c4673f1823 100644 --- a/packages/wrangler/src/versions/upload.ts +++ b/packages/wrangler/src/versions/upload.ts @@ -1,28 +1,33 @@ +import { blue, gray } from "@cloudflare/cli/colors"; import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; -import { blue, gray } from "@cloudflare/cli/colors"; import { fetchResult } from "../cfetch"; +import type { Config } from "../config"; import { printBindings } from "../config"; +import type { Rule } from "../config/environment"; import { bundleWorker } from "../deployment-bundle/bundle"; import { - printBundleSize, - printOffendingDependencies, + printBundleSize, + printOffendingDependencies, } from "../deployment-bundle/bundle-reporter"; import { getBundleType } from "../deployment-bundle/bundle-type"; import { createWorkerUploadForm } from "../deployment-bundle/create-worker-upload-form"; +import type { Entry } from "../deployment-bundle/entry"; import { - findAdditionalModules, - writeAdditionalModules, + findAdditionalModules, + writeAdditionalModules, } from "../deployment-bundle/find-additional-modules"; import { - createModuleCollector, - getWrangler1xLegacyModuleReferences, + createModuleCollector, + getWrangler1xLegacyModuleReferences, } from "../deployment-bundle/module-collection"; import { getNodeCompatMode } from "../deployment-bundle/node-compat"; import { loadSourceMaps } from "../deployment-bundle/source-maps"; +import type { CfPlacement, CfWorkerInit } from "../deployment-bundle/worker"; import { confirm } from "../dialogs"; import { getMigrationsToUpload } from "../durable"; import { UserError } from "../errors"; +import type { ExperimentalAssetsOptions } from "../experimental-assets"; import { syncExperimentalAssets } from "../experimental-assets"; import { logger } from "../logger"; import { getMetricsUsageHeaders } from "../metrics"; @@ -31,16 +36,11 @@ import { ParseError } from "../parse"; import { getWranglerTmpDir } from "../paths"; import { ensureQueuesExistByConfig } from "../queues/client"; import { getWorkersDevSubdomain } from "../routes"; +import type { RetrieveSourceMapFunction } from "../sourcemap"; import { - getSourceMappedString, - maybeRetrieveFileSourceMap, + getSourceMappedString, + maybeRetrieveFileSourceMap, } from "../sourcemap"; -import type { Config } from "../config"; -import type { Rule } from "../config/environment"; -import type { Entry } from "../deployment-bundle/entry"; -import type { CfPlacement, CfWorkerInit } from "../deployment-bundle/worker"; -import type { ExperimentalAssetsOptions } from "../experimental-assets"; -import type { RetrieveSourceMapFunction } from "../sourcemap"; type Props = { config: Config; @@ -376,6 +376,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m text_blobs: config.text_blobs, data_blobs: config.data_blobs, durable_objects: config.durable_objects, + pipelines: config.pipelines, queues: config.queues.producers?.map((producer) => { return { binding: producer.binding, queue_name: producer.queue }; }), From 0d9543ae9a7273ab41f2b479b5005e2cb4d63427 Mon Sep 17 00:00:00 2001 From: Andy Jessop Date: Mon, 9 Sep 2024 11:59:29 +0200 Subject: [PATCH 4/6] chore: fix formatting errors --- .../src/__tests__/configuration.test.ts | 22 +++-- .../wrangler/src/api/startDevWorker/utils.ts | 16 ++-- packages/wrangler/src/config/validation.ts | 6 +- .../create-worker-upload-form.ts | 12 +-- packages/wrangler/src/dev.tsx | 82 +++++++++---------- packages/wrangler/src/versions/upload.ts | 30 +++---- 6 files changed, 85 insertions(+), 83 deletions(-) diff --git a/packages/wrangler/src/__tests__/configuration.test.ts b/packages/wrangler/src/__tests__/configuration.test.ts index 515adb2e3028..091f424f0c1d 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -1,15 +1,15 @@ import path from "node:path"; -import type { - ConfigFields, - RawConfig, - RawDevConfig, - RawEnvironment, -} from "../config"; import { readConfig } from "../config"; import { normalizeAndValidateConfig } from "../config/validation"; import { normalizeSlashes } from "./helpers/mock-console"; import { runInTempDir } from "./helpers/run-in-tmp"; import { writeWranglerToml } from "./helpers/write-wrangler-toml"; +import type { + ConfigFields, + RawConfig, + RawDevConfig, + RawEnvironment, +} from "../config"; describe("readConfig()", () => { runInTempDir(); @@ -3243,7 +3243,10 @@ describe("normalizeAndValidateConfig()", () => { const { diagnostics } = normalizeAndValidateConfig( { pipelines: [ - { binding: "VALID", pipeline: "343cd4f1d58c42fbb5bd082592fd7143" }, + { + binding: "VALID", + pipeline: "343cd4f1d58c42fbb5bd082592fd7143", + }, ], } as unknown as RawConfig, undefined, @@ -3258,7 +3261,10 @@ describe("normalizeAndValidateConfig()", () => { { pipelines: [ {}, - { binding: "VALID", pipeline: "343cd4f1d58c42fbb5bd082592fd7143" }, + { + binding: "VALID", + pipeline: "343cd4f1d58c42fbb5bd082592fd7143", + }, { binding: 2000, project: 2111 }, ], } as unknown as RawConfig, diff --git a/packages/wrangler/src/api/startDevWorker/utils.ts b/packages/wrangler/src/api/startDevWorker/utils.ts index 524bf0a27286..acd608ae1eaa 100644 --- a/packages/wrangler/src/api/startDevWorker/utils.ts +++ b/packages/wrangler/src/api/startDevWorker/utils.ts @@ -2,14 +2,14 @@ import assert from "node:assert"; import { readFile } from "node:fs/promises"; import type { CfWorkerInit } from "../../deployment-bundle/worker"; import type { - AsyncHook, - Binding, - File, - Hook, - HookValues, - ServiceFetch, - StartDevWorkerInput, - StartDevWorkerOptions, + AsyncHook, + Binding, + File, + Hook, + HookValues, + ServiceFetch, + StartDevWorkerInput, + StartDevWorkerOptions, } from "./types"; export type MaybePromise = T | Promise; diff --git a/packages/wrangler/src/config/validation.ts b/packages/wrangler/src/config/validation.ts index cb8a65c77c67..fbe321e37e15 100644 --- a/packages/wrangler/src/config/validation.ts +++ b/packages/wrangler/src/config/validation.ts @@ -3117,9 +3117,7 @@ const validateConsumer: ValidatorFn = (diagnostics, field, value, _config) => { const validatePipelineBinding: ValidatorFn = (diagnostics, field, value) => { if (typeof value !== "object" || value === null) { diagnostics.errors.push( - `"pipeline" bindings should be objects, but got ${JSON.stringify( - value - )}` + `"pipeline" bindings should be objects, but got ${JSON.stringify(value)}` ); return false; } @@ -3150,8 +3148,6 @@ const validatePipelineBinding: ValidatorFn = (diagnostics, field, value) => { return isValid; }; - - function normalizeAndValidateLimits( diagnostics: Diagnostics, topLevelEnv: Environment | undefined, diff --git a/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts b/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts index f400e0582dac..c3a48dc42f37 100644 --- a/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts +++ b/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts @@ -109,9 +109,9 @@ export type WorkerMetadataBinding = params?: { name: string }[]; }; } - | { type: "mtls_certificate"; name: string; certificate_id: string } - | { type: "pipelines"; name: string; id: string } - | { + | { type: "mtls_certificate"; name: string; certificate_id: string } + | { type: "pipelines"; name: string; id: string } + | { type: "logfwdr"; name: string; destination: string; @@ -320,10 +320,10 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData { bindings.pipelines?.forEach(({ binding, pipeline }) => { metadataBindings.push({ name: binding, - type: 'pipelines', + type: "pipelines", id: pipeline, - }) - }) + }); + }); bindings.logfwdr?.bindings.forEach(({ name, destination }) => { metadataBindings.push({ diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index 7096304b9190..e6423913924f 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -1,34 +1,18 @@ -import { isWebContainer } from "@webcontainer/env"; -import { watch } from "chokidar"; -import { render } from "ink"; -import type { Json } from "miniflare"; import assert from "node:assert"; import events from "node:events"; import path from "node:path"; import util from "node:util"; -import type React from "react"; -import type { - ProxyData, - ReloadCompleteEvent, - StartDevWorkerInput, - Trigger, -} from "./api"; +import { isWebContainer } from "@webcontainer/env"; +import { watch } from "chokidar"; +import { render } from "ink"; import { DevEnv } from "./api"; import { - convertCfWorkerInitBindingstoBindings, - extractBindingsOfType, + convertCfWorkerInitBindingstoBindings, + extractBindingsOfType, } from "./api/startDevWorker/utils"; -import type { Config, Environment } from "./config"; import { findWranglerToml, printBindings, readConfig } from "./config"; -import type { - EnvironmentNonInheritable, - Route, - Rule, -} from "./config/environment"; import { getEntry } from "./deployment-bundle/entry"; import { getNodeCompatMode } from "./deployment-bundle/node-compat"; -import type { CfModule, CfWorkerInit } from "./deployment-bundle/worker"; -import type { WorkerRegistry } from "./dev-registry"; import { getBoundRegisteredWorkers } from "./dev-registry"; import Dev, { devRegistry } from "./dev/dev"; import { getVarsForDev } from "./dev/dev-vars"; @@ -39,38 +23,54 @@ import { startDevServer } from "./dev/start-server"; import { UserError } from "./errors"; import { processExperimentalAssetsArg } from "./experimental-assets"; import { run } from "./experimental-flags"; -import { - DEFAULT_INSPECTOR_PORT, - DEFAULT_LOCAL_PORT, - getDevCompatibilityDate, - getRules, - getScriptName, - isLegacyEnv, - printWranglerBanner, -} from "./index"; import isInteractive from "./is-interactive"; -import type { LoggerLevel } from "./logger"; import { logger } from "./logger"; import * as metrics from "./metrics"; -import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types"; import { getLegacyAssetPaths, getSiteAssetPaths } from "./sites"; import { - getAccountFromCache, - loginOrRefreshIfRequired, - requireApiToken, - requireAuth, + getAccountFromCache, + loginOrRefreshIfRequired, + requireApiToken, + requireAuth, } from "./user"; import { - collectKeyValues, - collectPlainTextVars, + collectKeyValues, + collectPlainTextVars, } from "./utils/collectKeyValues"; import { memoizeGetPort } from "./utils/memoizeGetPort"; import { mergeWithOverride } from "./utils/mergeWithOverride"; +import { getHostFromRoute, getZoneIdForPreview } from "./zones"; +import { + DEFAULT_INSPECTOR_PORT, + DEFAULT_LOCAL_PORT, + getDevCompatibilityDate, + getRules, + getScriptName, + isLegacyEnv, + printWranglerBanner, +} from "./index"; import type { - CommonYargsArgv, - StrictYargsOptionsToInterface, + ProxyData, + ReloadCompleteEvent, + StartDevWorkerInput, + Trigger, +} from "./api"; +import type { Config, Environment } from "./config"; +import type { + EnvironmentNonInheritable, + Route, + Rule, +} from "./config/environment"; +import type { CfModule, CfWorkerInit } from "./deployment-bundle/worker"; +import type { WorkerRegistry } from "./dev-registry"; +import type { LoggerLevel } from "./logger"; +import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types"; +import type { + CommonYargsArgv, + StrictYargsOptionsToInterface, } from "./yargs-types"; -import { getHostFromRoute, getZoneIdForPreview } from "./zones"; +import type { Json } from "miniflare"; +import type React from "react"; export function devOptions(yargs: CommonYargsArgv) { return ( diff --git a/packages/wrangler/src/versions/upload.ts b/packages/wrangler/src/versions/upload.ts index 25c4673f1823..cb1b2b0207c6 100644 --- a/packages/wrangler/src/versions/upload.ts +++ b/packages/wrangler/src/versions/upload.ts @@ -1,33 +1,28 @@ -import { blue, gray } from "@cloudflare/cli/colors"; import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; +import { blue, gray } from "@cloudflare/cli/colors"; import { fetchResult } from "../cfetch"; -import type { Config } from "../config"; import { printBindings } from "../config"; -import type { Rule } from "../config/environment"; import { bundleWorker } from "../deployment-bundle/bundle"; import { - printBundleSize, - printOffendingDependencies, + printBundleSize, + printOffendingDependencies, } from "../deployment-bundle/bundle-reporter"; import { getBundleType } from "../deployment-bundle/bundle-type"; import { createWorkerUploadForm } from "../deployment-bundle/create-worker-upload-form"; -import type { Entry } from "../deployment-bundle/entry"; import { - findAdditionalModules, - writeAdditionalModules, + findAdditionalModules, + writeAdditionalModules, } from "../deployment-bundle/find-additional-modules"; import { - createModuleCollector, - getWrangler1xLegacyModuleReferences, + createModuleCollector, + getWrangler1xLegacyModuleReferences, } from "../deployment-bundle/module-collection"; import { getNodeCompatMode } from "../deployment-bundle/node-compat"; import { loadSourceMaps } from "../deployment-bundle/source-maps"; -import type { CfPlacement, CfWorkerInit } from "../deployment-bundle/worker"; import { confirm } from "../dialogs"; import { getMigrationsToUpload } from "../durable"; import { UserError } from "../errors"; -import type { ExperimentalAssetsOptions } from "../experimental-assets"; import { syncExperimentalAssets } from "../experimental-assets"; import { logger } from "../logger"; import { getMetricsUsageHeaders } from "../metrics"; @@ -36,11 +31,16 @@ import { ParseError } from "../parse"; import { getWranglerTmpDir } from "../paths"; import { ensureQueuesExistByConfig } from "../queues/client"; import { getWorkersDevSubdomain } from "../routes"; -import type { RetrieveSourceMapFunction } from "../sourcemap"; import { - getSourceMappedString, - maybeRetrieveFileSourceMap, + getSourceMappedString, + maybeRetrieveFileSourceMap, } from "../sourcemap"; +import type { Config } from "../config"; +import type { Rule } from "../config/environment"; +import type { Entry } from "../deployment-bundle/entry"; +import type { CfPlacement, CfWorkerInit } from "../deployment-bundle/worker"; +import type { ExperimentalAssetsOptions } from "../experimental-assets"; +import type { RetrieveSourceMapFunction } from "../sourcemap"; type Props = { config: Config; From 03eabe8f11a7b3a9367a8b4d1b7ccc18a1c72204 Mon Sep 17 00:00:00 2001 From: Andy Jessop Date: Mon, 9 Sep 2024 12:04:56 +0200 Subject: [PATCH 5/6] chore: type/lint/format fixes --- packages/wrangler/src/__tests__/type-generation.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/wrangler/src/__tests__/type-generation.test.ts b/packages/wrangler/src/__tests__/type-generation.test.ts index df1f416f997c..88fc1cdbfd00 100644 --- a/packages/wrangler/src/__tests__/type-generation.test.ts +++ b/packages/wrangler/src/__tests__/type-generation.test.ts @@ -217,6 +217,7 @@ const bindingsConfigMock: Omit< }, { type: "CompiledWasm", globs: ["**/*.wasm"], fallthrough: true }, ], + pipelines: [], }; describe("generateTypes()", () => { From de604d0c02fc7ed4d2adc6e103429bf925a1674b Mon Sep 17 00:00:00 2001 From: Andy Jessop Date: Mon, 9 Sep 2024 12:15:49 +0200 Subject: [PATCH 6/6] chore: fix formatting --- packages/wrangler/src/config/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/wrangler/src/config/index.ts b/packages/wrangler/src/config/index.ts index a45908ad0434..5dc0e95a2636 100644 --- a/packages/wrangler/src/config/index.ts +++ b/packages/wrangler/src/config/index.ts @@ -444,14 +444,14 @@ export function printBindings(bindings: CfWorkerInit["bindings"]) { }); } - if (pipelines != undefined && pipelines.length>0) { + if (pipelines != undefined && pipelines.length > 0) { output.push({ type: "Pipelines", entries: pipelines.map(({ binding, pipeline }) => ({ key: binding, value: pipeline, - })) - }) + })), + }); } if (version_metadata !== undefined) {