Skip to content

Commit 48e7e10

Browse files
authored
feat: add experimental_patchConfig (#7521)
* 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
1 parent 086a6b8 commit 48e7e10

File tree

5 files changed

+1000
-13
lines changed

5 files changed

+1000
-13
lines changed

.changeset/lovely-rats-live.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
feat: add experimental_patchConfig()
6+
7+
`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.

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6045,15 +6045,19 @@ describe("experimental_readRawConfig()", () => {
60456045
runInTempDir();
60466046
it(`should find a ${configType} config file given a specific path`, () => {
60476047
fs.mkdirSync("../folder", { recursive: true });
6048-
writeWranglerConfig({}, `../folder/config.${configType}`);
6048+
writeWranglerConfig(
6049+
{ name: "config-one" },
6050+
`../folder/config.${configType}`
6051+
);
60496052

60506053
const result = experimental_readRawConfig({
60516054
config: `../folder/config.${configType}`,
60526055
});
6053-
expect(result.rawConfig).toEqual({
6054-
compatibility_date: "2022-01-12",
6055-
name: "test-name",
6056-
});
6056+
expect(result.rawConfig).toEqual(
6057+
expect.objectContaining({
6058+
name: "config-one",
6059+
})
6060+
);
60576061
});
60586062

60596063
it("should find a config file given a specific script", () => {
@@ -6072,18 +6076,20 @@ describe("experimental_readRawConfig()", () => {
60726076
let result = experimental_readRawConfig({
60736077
script: "./path/to/index.js",
60746078
});
6075-
expect(result.rawConfig).toEqual({
6076-
compatibility_date: "2022-01-12",
6077-
name: "config-one",
6078-
});
6079+
expect(result.rawConfig).toEqual(
6080+
expect.objectContaining({
6081+
name: "config-one",
6082+
})
6083+
);
60796084

60806085
result = experimental_readRawConfig({
60816086
script: "../folder/index.js",
60826087
});
6083-
expect(result.rawConfig).toEqual({
6084-
compatibility_date: "2022-01-12",
6085-
name: "config-two",
6086-
});
6088+
expect(result.rawConfig).toEqual(
6089+
expect.objectContaining({
6090+
name: "config-two",
6091+
})
6092+
);
60876093
});
60886094
}
60896095
);

0 commit comments

Comments
 (0)