Skip to content

Commit 06fbfe8

Browse files
committed
feat: Worker run and redwood plugin improvements (#661)
## Problem Currently, one is able to specify a custom config path for their wrangler config in our vite plugin, but not with `worker-run` scripts. We need to be able to specifying the wrangler config in both cases. ## Solution Change both the vite pugin and `worker-run` to make use of a `RWSDK_WRANGLER_CONFIG` env var to specify the wrangler config path. Went fr env var instead of a cli arg, so that it can be propagated more easily to the different parts that need to know the worker config path. ```bash RWSDK_WRANGLER_CONFIG=... pnpm dev:init RWSDK_WRANGLER_CONFIG=... pnpm dev ``` Solves #636
1 parent 04fc778 commit 06fbfe8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

sdk/src/scripts/worker-run.mts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,24 @@ export const runWorkerScript = async (relativeScriptPath: string) => {
1919
console.error("Error: Script path is required");
2020
console.log("\nUsage:");
2121
console.log(" npm run worker:run <script-path>");
22-
console.log("\nExample:");
23-
console.log(" npm run worker:run src/scripts/seed.ts\n");
22+
console.log("\nOptions:");
23+
console.log(
24+
" RWSDK_WRANGLER_CONFIG Environment variable for config path",
25+
);
26+
console.log("\nExamples:");
27+
console.log(" npm run worker:run src/scripts/seed.ts");
28+
console.log(
29+
" RWSDK_WRANGLER_CONFIG=custom.toml npm run worker:run src/scripts/seed.ts\n",
30+
);
2431
process.exit(1);
2532
}
2633

2734
const scriptPath = resolve(process.cwd(), relativeScriptPath);
2835
debug("Running worker script: %s", scriptPath);
2936

30-
const workerConfigPath = await findWranglerConfig(process.cwd());
37+
const workerConfigPath = process.env.RWSDK_WRANGLER_CONFIG
38+
? resolve(process.cwd(), process.env.RWSDK_WRANGLER_CONFIG)
39+
: await findWranglerConfig(process.cwd());
3140
debug("Using wrangler config: %s", workerConfigPath);
3241

3342
const workerConfig = unstable_readConfig({

sdk/src/vite/redwoodPlugin.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export const redwoodPlugin = async (
5858
const projectRootDir = process.cwd();
5959

6060
const workerConfigPath =
61-
options.configPath ?? (await findWranglerConfig(projectRootDir));
61+
options.configPath ??
62+
(process.env.RWSDK_WRANGLER_CONFIG
63+
? resolve(projectRootDir, process.env.RWSDK_WRANGLER_CONFIG)
64+
: await findWranglerConfig(projectRootDir));
6265

6366
const workerEntryPathname = await determineWorkerEntryPathname(
6467
projectRootDir,

0 commit comments

Comments
 (0)