Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add experimental_patchConfig #7521

Merged
merged 13 commits into from
Dec 19, 2024
7 changes: 7 additions & 0 deletions .changeset/lovely-rats-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

feat: add experimental_patchConfig()

`experimental_patchConfig()` can add to a user's config file. It preserves comments if its a `wrangler.jsonc`. However, it is not suitable for `wrangler.toml` with comments as we cannot preserve comments on write.
32 changes: 19 additions & 13 deletions packages/wrangler/src/__tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6045,15 +6045,19 @@ describe("experimental_readRawConfig()", () => {
runInTempDir();
it(`should find a ${configType} config file given a specific path`, () => {
fs.mkdirSync("../folder", { recursive: true });
writeWranglerConfig({}, `../folder/config.${configType}`);
writeWranglerConfig(
{ name: "config-one" },
`../folder/config.${configType}`
);

const result = experimental_readRawConfig({
config: `../folder/config.${configType}`,
});
expect(result.rawConfig).toEqual({
compatibility_date: "2022-01-12",
name: "test-name",
});
expect(result.rawConfig).toEqual(
expect.objectContaining({
name: "config-one",
})
);
});

it("should find a config file given a specific script", () => {
Expand All @@ -6072,18 +6076,20 @@ describe("experimental_readRawConfig()", () => {
let result = experimental_readRawConfig({
script: "./path/to/index.js",
});
expect(result.rawConfig).toEqual({
compatibility_date: "2022-01-12",
name: "config-one",
});
expect(result.rawConfig).toEqual(
expect.objectContaining({
name: "config-one",
})
);

result = experimental_readRawConfig({
script: "../folder/index.js",
});
expect(result.rawConfig).toEqual({
compatibility_date: "2022-01-12",
name: "config-two",
});
expect(result.rawConfig).toEqual(
expect.objectContaining({
name: "config-two",
})
);
});
}
);
Expand Down
Loading
Loading