Skip to content

Commit e2b3306

Browse files
authored
Fix assets inheritance regression (#7981)
1 parent 2a59eae commit e2b3306

File tree

3 files changed

+162
-4
lines changed

3 files changed

+162
-4
lines changed

.changeset/long-bulldogs-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fixes a regression introduced in Wrangler 3.107.0 in which `[assets]` was not being inherited from the top-level environment.

packages/wrangler/src/__tests__/config/configuration.test.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6396,6 +6396,154 @@ describe("normalizeAndValidateConfig()", () => {
63966396
expect(result2.diagnostics.hasWarnings()).toBe(false);
63976397
});
63986398
});
6399+
6400+
describe("[assets]", () => {
6401+
it("should inherit from top-level assets", () => {
6402+
const rawConfig: RawConfig = {
6403+
assets: {
6404+
directory: "dist",
6405+
binding: "ASSETS",
6406+
},
6407+
env: {
6408+
ENV1: {},
6409+
},
6410+
};
6411+
6412+
const { config, diagnostics } = normalizeAndValidateConfig(
6413+
rawConfig,
6414+
undefined,
6415+
undefined,
6416+
{ env: "ENV1" }
6417+
);
6418+
6419+
expect(config).toEqual(
6420+
expect.objectContaining({
6421+
assets: {
6422+
directory: "dist",
6423+
binding: "ASSETS",
6424+
},
6425+
})
6426+
);
6427+
expect(diagnostics.hasErrors()).toBe(false);
6428+
expect(diagnostics.hasWarnings()).toBe(false);
6429+
});
6430+
6431+
it("should resolve assets in named env with top-level env also including assets", () => {
6432+
const rawConfig: RawConfig = {
6433+
assets: {
6434+
directory: "dist",
6435+
binding: "ASSETS",
6436+
},
6437+
env: {
6438+
ENV1: {
6439+
assets: {
6440+
directory: "public",
6441+
binding: "ASSETS",
6442+
run_worker_first: true,
6443+
},
6444+
},
6445+
},
6446+
};
6447+
6448+
const { config, diagnostics } = normalizeAndValidateConfig(
6449+
rawConfig,
6450+
undefined,
6451+
undefined,
6452+
{ env: "ENV1" }
6453+
);
6454+
6455+
expect(config).toEqual(
6456+
expect.objectContaining({
6457+
assets: {
6458+
directory: "public",
6459+
binding: "ASSETS",
6460+
run_worker_first: true,
6461+
},
6462+
})
6463+
);
6464+
expect(diagnostics.hasErrors()).toBe(false);
6465+
expect(diagnostics.hasWarnings()).toBe(false);
6466+
});
6467+
6468+
it("should warn about experimental_serve_directly deprecation from inherited top-level env", () => {
6469+
const rawConfig: RawConfig = {
6470+
assets: {
6471+
directory: "dist",
6472+
binding: "ASSETS",
6473+
experimental_serve_directly: false,
6474+
},
6475+
env: {
6476+
ENV1: {},
6477+
},
6478+
};
6479+
6480+
const { config, diagnostics } = normalizeAndValidateConfig(
6481+
rawConfig,
6482+
undefined,
6483+
undefined,
6484+
{ env: "ENV1" }
6485+
);
6486+
6487+
expect(config).toEqual(
6488+
expect.objectContaining({
6489+
assets: {
6490+
directory: "dist",
6491+
binding: "ASSETS",
6492+
experimental_serve_directly: false,
6493+
},
6494+
})
6495+
);
6496+
expect(diagnostics.hasErrors()).toBe(false);
6497+
expect(diagnostics.hasWarnings()).toBe(true);
6498+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
6499+
"Processing wrangler configuration:
6500+
- Deprecation: \\"assets.experimental_serve_directly\\":
6501+
The \\"experimental_serve_directly\\" field is not longer supported. Please use run_worker_first.
6502+
Read more: https://developers.cloudflare.com/workers/static-assets/binding/#run_worker_first"
6503+
`);
6504+
});
6505+
6506+
it("should warn about experimental_serve_directly deprecation from named env", () => {
6507+
const rawConfig: RawConfig = {
6508+
env: {
6509+
ENV1: {
6510+
assets: {
6511+
directory: "dist",
6512+
binding: "ASSETS",
6513+
experimental_serve_directly: false,
6514+
},
6515+
},
6516+
},
6517+
};
6518+
6519+
const { config, diagnostics } = normalizeAndValidateConfig(
6520+
rawConfig,
6521+
undefined,
6522+
undefined,
6523+
{ env: "ENV1" }
6524+
);
6525+
6526+
expect(config).toEqual(
6527+
expect.objectContaining({
6528+
assets: {
6529+
directory: "dist",
6530+
binding: "ASSETS",
6531+
experimental_serve_directly: false,
6532+
},
6533+
})
6534+
);
6535+
expect(diagnostics.hasErrors()).toBe(false);
6536+
expect(diagnostics.hasWarnings()).toBe(true);
6537+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
6538+
"Processing wrangler configuration:
6539+
6540+
- \\"env.ENV1\\" environment configuration
6541+
- Deprecation: \\"assets.experimental_serve_directly\\":
6542+
The \\"experimental_serve_directly\\" field is not longer supported. Please use run_worker_first.
6543+
Read more: https://developers.cloudflare.com/workers/static-assets/binding/#run_worker_first"
6544+
`);
6545+
});
6546+
});
63996547
});
64006548
});
64016549

packages/wrangler/src/config/validation.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,16 @@ function normalizeAndValidateAssets(
596596
`The "experimental_serve_directly" field is not longer supported. Please use run_worker_first.\nRead more: https://developers.cloudflare.com/workers/static-assets/binding/#run_worker_first`,
597597
false // Leave in for the moment, to be removed in a future release
598598
);
599-
600-
validateAssetsConfig(diagnostics, "assets", rawEnv.assets, topLevelEnv);
601-
return rawEnv.assets;
602599
}
603-
return undefined;
600+
601+
return inheritable(
602+
diagnostics,
603+
topLevelEnv,
604+
rawEnv,
605+
"assets",
606+
validateAssetsConfig,
607+
undefined
608+
);
604609
}
605610

606611
/**

0 commit comments

Comments
 (0)