Skip to content

Commit 62c1605

Browse files
Add config redirect support for Pages commands
1 parent 1de3c3f commit 62c1605

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

.changeset/thin-pots-camp.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"wrangler": minor
33
---
44

5-
feat: add support for redirecting Wrangler to a generated config when running deploy commands
5+
feat: add support for redirecting Wrangler to a generated config when running deploy-related commands
66

77
This new feature is designed for build tools and frameworks to provide a deploy-specific configuration,
8-
which Wrangler can use instead of user configuration when running deploy commands.
8+
which Wrangler can use instead of user configuration when running deploy-related commands.
99
It is not expected that developers of Workers will need to use this feature directly.
1010

1111
### Affected commands
@@ -16,6 +16,9 @@ The commands that use this feature are:
1616
- `wrangler dev`
1717
- `wrangler versions upload`
1818
- `wrangler versions deploy`
19+
- `wrangler pages deploy`
20+
- `wrangler pages build`
21+
- `wrangler pages build-env`
1922

2023
### Config redirect file
2124

@@ -25,7 +28,7 @@ When running these commands, Wrangler will look up the directory tree from the c
2528
{ "configPath": "../../path/to/wrangler.json" }
2629
```
2730

28-
When this file exists Wrangler will use the `configPath` (relative to the `deploy.json` file) to find an alternative Wrangler configuration file to load and use as part of this command.
31+
When this file exists Wrangler will follow the `configPath` (relative to the `.wrangler/deploy/config.json` file) to find an alternative Wrangler configuration file to load and use as part of this command.
2932

3033
When this happens Wrangler will display a warning to the user to indicate that the configuration has been redirected to a different file than the user's configuration file.
3134

packages/wrangler/src/api/pages/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export async function deploy({
160160
let config: Config | undefined;
161161

162162
try {
163-
config = readPagesConfig({ ...args, env });
163+
config = readPagesConfig({ ...args, env }, { useRedirect: true });
164164
} catch (err) {
165165
if (
166166
!(

packages/wrangler/src/pages/build-env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const Handler = async (args: PagesBuildEnvArgs) => {
4242
"Checking for configuration in a Wrangler configuration file (BETA)\n"
4343
);
4444

45-
const configPath = findWranglerConfig(args.projectDir);
45+
const configPath = findWranglerConfig(args.projectDir, { useRedirect: true });
4646
if (!configPath || !existsSync(configPath)) {
4747
logger.debug("No Wrangler configuration file found. Exiting.");
4848
process.exitCode = EXIT_CODE_NO_CONFIG_FOUND;

packages/wrangler/src/pages/build.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ async function maybeReadPagesConfig(
354354
if (!args.projectDirectory || !args.buildMetadataPath) {
355355
return;
356356
}
357-
const configPath = findWranglerConfig(args.projectDirectory);
357+
const configPath = findWranglerConfig(args.projectDirectory, {
358+
useRedirect: true,
359+
});
358360
// Fail early if the config file doesn't exist
359361
if (!configPath || !existsSync(configPath)) {
360362
return undefined;

packages/wrangler/src/pages/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const Handler = async (args: PagesDeployArgs) => {
115115
}
116116

117117
let config: Config | undefined;
118-
const configPath = findWranglerConfig(process.cwd());
118+
const configPath = findWranglerConfig(process.cwd(), { useRedirect: true });
119119

120120
try {
121121
/*

0 commit comments

Comments
 (0)