Skip to content

Commit

Permalink
feat: add experimental_patchConfig (#7521)
Browse files Browse the repository at this point in the history
* add experimental_readRawConfig and tests

* move printBindings out of /config/index.ts

* add experimental_patchConfig

* fixups

* add tests

* changeset

* more tests

* pr feedback

* allow editing and deleting with `isArrayInsertion` flag

* more tests

* fixups

* update changeset

* fix test
  • Loading branch information
emily-shen authored Dec 19, 2024
1 parent 086a6b8 commit 48e7e10
Show file tree
Hide file tree
Showing 5 changed files with 1,000 additions and 13 deletions.
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

0 comments on commit 48e7e10

Please sign in to comment.