Skip to content

Commit

Permalink
add experimental-vectorize-bind-to-prod argument
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettgu10 committed Oct 15, 2024
1 parent 7f3ee7a commit 1f0eb23
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/wrangler/e2e/dev-with-resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,9 @@ describe.sequential.each(RUNTIMES)("Bindings: $flags", ({ runtime, flags }) => {

await helper.run(`wrangler vectorize insert ${name} --file samples.ndjson`);

const worker = helper.runLongLived(`wrangler dev ${flags}`);
const worker = helper.runLongLived(
`wrangler dev ${flags} --experimental-vectorize-bind-to-prod`
);
const { url } = await worker.waitForReady();
const res = await fetch(url);

Expand Down
3 changes: 3 additions & 0 deletions packages/wrangler/src/api/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface UnstableDevOptions {
watch?: boolean; // unstable_dev doesn't support watch-mode yet in testMode
devEnv?: boolean;
fileBasedRegistry?: boolean;
vectorizeBindToProd?: boolean;
};
}

Expand Down Expand Up @@ -128,6 +129,7 @@ export async function unstable_dev(
testScheduled,
devEnv = false,
fileBasedRegistry = false,
vectorizeBindToProd,
// 2. options for alpha/beta products/libs
d1Databases,
enablePagesAssetsServiceBinding,
Expand Down Expand Up @@ -223,6 +225,7 @@ export async function unstable_dev(
experimentalVersions: undefined,
experimentalDevEnv: devEnv,
experimentalRegistry: fileBasedRegistry,
experimentalVectorizeBindToProd: vectorizeBindToProd ?? false,
};

//due to Pages adoption of unstable_dev, we can't *just* disable rebuilds and watching. instead, we'll have two versions of startDev, which will converge.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ async function resolveDevConfig(
// absolute resolved path
persist: localPersistencePath,
registry: input.dev?.registry,
bindVectorizeToProd: input.dev?.bindVectorizeToProd ?? false,
} satisfies StartDevWorkerOptions["dev"];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ async function convertToConfigBundle(
inspect: true,
services: bindings.services,
serviceBindings: fetchers,
bindVectorizeToProd: event.config.dev?.bindVectorizeToProd ?? false,
};
}

Expand Down
3 changes: 3 additions & 0 deletions packages/wrangler/src/api/startDevWorker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ export interface StartDevWorkerInput {
registry?: WorkerRegistry;

testScheduled?: boolean;

/** Whether to use Vectorize mixed mode -- the worker is run locally but accesses to Vectorize are made remotely */
bindVectorizeToProd?: boolean;
};
legacy?: {
site?: Hook<Config["site"], [Config]>;
Expand Down
9 changes: 9 additions & 0 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ export function devOptions(yargs: CommonYargsArgv) {
"Use the experimental file based dev registry for multi-worker development",
default: false,
})
.option("experimental-vectorize-bind-to-prod", {
alias: ["x-vectorize-bind-to-prod"],
type: "boolean",
describe: "Bind to production Vectorize indexes in local development mode",
default: false,
})
);
}

Expand Down Expand Up @@ -747,6 +753,7 @@ export async function startDev(args: StartDevOptions) {
testScheduled: args.testScheduled,
logLevel: args.logLevel,
registry: devEnv.config.latestConfig?.dev.registry,
bindVectorizeToProd: args.experimentalVectorizeBindToProd,
},
legacy: {
site: (configParam) => {
Expand Down Expand Up @@ -1006,6 +1013,7 @@ export async function startDev(args: StartDevOptions) {
rawArgs={args}
rawConfig={configParam}
devEnv={devEnv}
bindVectorizeToProd={args.experimentalVectorizeBindToProd}
/>
);
}
Expand Down Expand Up @@ -1205,6 +1213,7 @@ export async function startApiDev(args: StartDevOptions) {
rawArgs: args,
rawConfig: configParam,
devEnv,
bindVectorizeToProd: args.experimentalVectorizeBindToProd,
});
}

Expand Down
3 changes: 3 additions & 0 deletions packages/wrangler/src/dev/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export type DevProps = {
rawConfig: Config;
rawArgs: StartDevOptions;
devEnv: DevEnv;
bindVectorizeToProd: boolean;
};

export function DevImplementation(props: DevProps): JSX.Element {
Expand Down Expand Up @@ -398,6 +399,7 @@ function DevSession(props: DevSessionProps) {
liveReload: props.liveReload,
testScheduled: props.testScheduled,
persist: "",
bindVectorizeToProd: props.bindVectorizeToProd,
},
legacy: {
site:
Expand Down Expand Up @@ -655,6 +657,7 @@ function DevSession(props: DevSessionProps) {
enablePagesAssetsServiceBinding={props.enablePagesAssetsServiceBinding}
sourceMapPath={bundle?.sourceMapPath}
services={props.bindings.services}
bindVectorizeToProd={props.bindVectorizeToProd}
/>
) : (
<Remote
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/dev/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface LocalProps {
testScheduled?: boolean;
sourceMapPath: string | undefined;
services: Config["services"] | undefined;
bindVectorizeToProd: boolean;
}

// TODO(soon): we should be able to remove this function when we fully migrate
Expand Down Expand Up @@ -110,6 +111,7 @@ export async function localPropsToConfigBundle(
inspect: props.inspect,
services: props.services,
serviceBindings,
bindVectorizeToProd: props.bindVectorizeToProd,
};
}

Expand Down
8 changes: 8 additions & 0 deletions packages/wrangler/src/dev/miniflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export interface ConfigBundle {
inspect: boolean;
services: Config["services"] | undefined;
serviceBindings: Record<string, ServiceFetch>;
bindVectorizeToProd: boolean;
}

export class WranglerLog extends Log {
Expand Down Expand Up @@ -920,6 +921,13 @@ export async function buildMiniflareOptions(
}
}

if (!config.bindVectorizeToProd && config.bindings.vectorize?.length) {
logger.warn(
"Vectorize local bindings are not supported yet. You may use the `--experimental-vectorize-bind-to-prod` flag to bind to your production index in local dev mode."
);
config.bindings.vectorize = [];
}

if (config.bindings.vectorize?.length) {
if (!didWarnMiniflareVectorizeSupport) {
didWarnMiniflareVectorizeSupport = true;
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/dev/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export async function startDevServer(
persist: props.localPersistencePath ?? undefined,
testScheduled: props.testScheduled,
registry: workerDefinitions,
bindVectorizeToProd: props.bindVectorizeToProd,
},
build: {
bundle: !props.noBundle,
Expand Down Expand Up @@ -317,6 +318,7 @@ export async function startDevServer(
sourceMapPath: bundle?.sourceMapPath,
services: props.bindings.services,
experimentalDevEnv: props.experimentalDevEnv,
bindVectorizeToProd: props.bindVectorizeToProd,
});

return {
Expand Down
5 changes: 5 additions & 0 deletions packages/wrangler/src/pages/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ export function Options(yargs: CommonYargsArgv) {
"Use the experimental file based dev registry for multi-worker development",
default: false,
},
"experimental-vectorize-bind-to-prod": {
type: "boolean",
describe: "Bind to production Vectorize indexes in local development mode",
default: false,
}
});
}

Expand Down

0 comments on commit 1f0eb23

Please sign in to comment.