Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit afe731c

Browse files
authored
BuildPlugin: fix build.watch_dir to allow passing in array (#557)
* Add failing test for build.watch_dir as array * Support passing in array of strings to build.watch_dir
1 parent 3bfd4ab commit afe731c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

packages/core/src/plugins/build.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ export class BuildPlugin extends Plugin<BuildOptions> implements BuildOptions {
4141
description: "Directory to watch for rebuilding on changes",
4242
fromWrangler: ({ build, miniflare }) => {
4343
const watchPaths = miniflare?.build_watch_dirs ?? [];
44-
if (build?.watch_dir) watchPaths.push(build.watch_dir);
44+
if (build?.watch_dir) {
45+
watchPaths.push(
46+
...(Array.isArray(build.watch_dir)
47+
? build.watch_dir
48+
: [build.watch_dir])
49+
);
50+
}
4551
if (watchPaths.length) return watchPaths;
4652

4753
// If build command set and no paths set, fallback to watching "src"

packages/core/test/plugins/build.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ test("BuildPlugin: parses options from wrangler config", (t) => {
9898
buildBasePath: undefined,
9999
buildWatchPaths: undefined,
100100
});
101+
// build.watch_dir should accept an array of strings
102+
options = parsePluginWranglerConfig(BuildPlugin, {
103+
build: {
104+
watch_dir: ["source", "source1"],
105+
},
106+
miniflare: {
107+
build_watch_dirs: ["source2", "source3"],
108+
},
109+
});
110+
t.like(options, {
111+
buildWatchPaths: ["source2", "source3", "source", "source1"],
112+
});
101113
});
102114
test("BuildPlugin: logs options", (t) => {
103115
const logs = logPluginOptions(BuildPlugin, {

packages/shared/src/wrangler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export interface WranglerConfig extends WranglerEnvironmentConfig {
124124
build?: {
125125
command?: string;
126126
cwd?: string;
127-
watch_dir?: string;
127+
watch_dir?: string | string[];
128128
upload?: {
129129
format?: "service-worker" | "modules";
130130
dir?: string;

0 commit comments

Comments
 (0)