Skip to content

Commit

Permalink
Fix assets inheritance regression (#7981)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev authored Jan 31, 2025
1 parent 2a59eae commit e2b3306
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-bulldogs-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Fixes a regression introduced in Wrangler 3.107.0 in which `[assets]` was not being inherited from the top-level environment.
148 changes: 148 additions & 0 deletions packages/wrangler/src/__tests__/config/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6396,6 +6396,154 @@ describe("normalizeAndValidateConfig()", () => {
expect(result2.diagnostics.hasWarnings()).toBe(false);
});
});

describe("[assets]", () => {
it("should inherit from top-level assets", () => {
const rawConfig: RawConfig = {
assets: {
directory: "dist",
binding: "ASSETS",
},
env: {
ENV1: {},
},
};

const { config, diagnostics } = normalizeAndValidateConfig(
rawConfig,
undefined,
undefined,
{ env: "ENV1" }
);

expect(config).toEqual(
expect.objectContaining({
assets: {
directory: "dist",
binding: "ASSETS",
},
})
);
expect(diagnostics.hasErrors()).toBe(false);
expect(diagnostics.hasWarnings()).toBe(false);
});

it("should resolve assets in named env with top-level env also including assets", () => {
const rawConfig: RawConfig = {
assets: {
directory: "dist",
binding: "ASSETS",
},
env: {
ENV1: {
assets: {
directory: "public",
binding: "ASSETS",
run_worker_first: true,
},
},
},
};

const { config, diagnostics } = normalizeAndValidateConfig(
rawConfig,
undefined,
undefined,
{ env: "ENV1" }
);

expect(config).toEqual(
expect.objectContaining({
assets: {
directory: "public",
binding: "ASSETS",
run_worker_first: true,
},
})
);
expect(diagnostics.hasErrors()).toBe(false);
expect(diagnostics.hasWarnings()).toBe(false);
});

it("should warn about experimental_serve_directly deprecation from inherited top-level env", () => {
const rawConfig: RawConfig = {
assets: {
directory: "dist",
binding: "ASSETS",
experimental_serve_directly: false,
},
env: {
ENV1: {},
},
};

const { config, diagnostics } = normalizeAndValidateConfig(
rawConfig,
undefined,
undefined,
{ env: "ENV1" }
);

expect(config).toEqual(
expect.objectContaining({
assets: {
directory: "dist",
binding: "ASSETS",
experimental_serve_directly: false,
},
})
);
expect(diagnostics.hasErrors()).toBe(false);
expect(diagnostics.hasWarnings()).toBe(true);
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- Deprecation: \\"assets.experimental_serve_directly\\":
The \\"experimental_serve_directly\\" field is not longer supported. Please use run_worker_first.
Read more: https://developers.cloudflare.com/workers/static-assets/binding/#run_worker_first"
`);
});

it("should warn about experimental_serve_directly deprecation from named env", () => {
const rawConfig: RawConfig = {
env: {
ENV1: {
assets: {
directory: "dist",
binding: "ASSETS",
experimental_serve_directly: false,
},
},
},
};

const { config, diagnostics } = normalizeAndValidateConfig(
rawConfig,
undefined,
undefined,
{ env: "ENV1" }
);

expect(config).toEqual(
expect.objectContaining({
assets: {
directory: "dist",
binding: "ASSETS",
experimental_serve_directly: false,
},
})
);
expect(diagnostics.hasErrors()).toBe(false);
expect(diagnostics.hasWarnings()).toBe(true);
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- \\"env.ENV1\\" environment configuration
- Deprecation: \\"assets.experimental_serve_directly\\":
The \\"experimental_serve_directly\\" field is not longer supported. Please use run_worker_first.
Read more: https://developers.cloudflare.com/workers/static-assets/binding/#run_worker_first"
`);
});
});
});
});

Expand Down
13 changes: 9 additions & 4 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,16 @@ function normalizeAndValidateAssets(
`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`,
false // Leave in for the moment, to be removed in a future release
);

validateAssetsConfig(diagnostics, "assets", rawEnv.assets, topLevelEnv);
return rawEnv.assets;
}
return undefined;

return inheritable(
diagnostics,
topLevelEnv,
rawEnv,
"assets",
validateAssetsConfig,
undefined
);
}

/**
Expand Down

0 comments on commit e2b3306

Please sign in to comment.