From c39173bb3eb9ab74e6f9cb7a34243c432f35d50d Mon Sep 17 00:00:00 2001 From: James Date: Mon, 3 Jul 2023 18:32:02 +0100 Subject: [PATCH] fix template resolution for wrangler --- .changeset/mighty-suits-run.md | 5 +++++ src/cli/index.ts | 10 ++++++++-- src/cli/{template.ts => template/_worker.ts} | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .changeset/mighty-suits-run.md rename src/cli/{template.ts => template/_worker.ts} (97%) diff --git a/.changeset/mighty-suits-run.md b/.changeset/mighty-suits-run.md new file mode 100644 index 0000000..835d18f --- /dev/null +++ b/.changeset/mighty-suits-run.md @@ -0,0 +1,5 @@ +--- +'cf-bindings-proxy': minor +--- + +Initial support for running a proxy for bindings with D1/KV/R2. diff --git a/src/cli/index.ts b/src/cli/index.ts index 3f70c60..2829463 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,5 +1,11 @@ import { spawn } from 'node:child_process'; -import { resolve } from 'node:path'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// eslint-disable-next-line @typescript-eslint/naming-convention +const __filename = fileURLToPath(import.meta.url); +// eslint-disable-next-line @typescript-eslint/naming-convention +const __dirname = dirname(__filename); /** * Spawns wrangler dev mode with the binding proxy template. @@ -12,7 +18,7 @@ export const spawnDevMode = async () => { const wrangler = spawn( executor, - ['wrangler', 'pages', 'dev', resolve('./template'), '--port=8799', ...passThroughArgs], + ['wrangler', 'pages', 'dev', resolve(__dirname, 'template'), '--port=8799', ...passThroughArgs], { stdio: 'inherit' }, ); diff --git a/src/cli/template.ts b/src/cli/template/_worker.ts similarity index 97% rename from src/cli/template.ts rename to src/cli/template/_worker.ts index 47b6809..b3f8b49 100644 --- a/src/cli/template.ts +++ b/src/cli/template/_worker.ts @@ -1,5 +1,5 @@ -import type { BindingRequest, BindingResponse, PropertyCall } from '../proxy'; -import { transformData } from '../transform'; +import type { BindingRequest, BindingResponse, PropertyCall } from '../../proxy'; +import { transformData } from '../../transform'; // eslint-disable-next-line @typescript-eslint/no-explicit-any type Env = { [key: string]: any };