Skip to content

Commit 1bc60d7

Browse files
authored
Render correct config format from wrangler d1 create (#8119)
* render correct config format from d1 create * fix lint
1 parent 0d2f41e commit 1bc60d7

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

.changeset/tidy-keys-sin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Output correct config format from `wrangler d1 create`. Previously, this command would always output TOML, regardless of the config file format

packages/wrangler/src/__tests__/d1/create.test.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,18 @@ describe("create", () => {
6161
);
6262
await runWrangler("d1 create test --location oc");
6363
expect(std.out).toMatchInlineSnapshot(`
64-
"✅ Successfully created DB 'test' in region OC
65-
Created your new D1 database.
64+
"✅ Successfully created DB 'test' in region OC
65+
Created your new D1 database.
6666
67-
[[d1_databases]]
68-
binding = \\"DB\\"
69-
database_name = \\"test\\"
70-
database_id = \\"51e7c314-456e-4167-b6c3-869ad188fc23\\"
71-
"
72-
`);
67+
{
68+
\\"d1_databases\\": [
69+
{
70+
\\"binding\\": \\"DB\\",
71+
\\"database_name\\": \\"test\\",
72+
\\"database_id\\": \\"51e7c314-456e-4167-b6c3-869ad188fc23\\"
73+
}
74+
]
75+
}"
76+
`);
7377
});
7478
});

packages/wrangler/src/d1/create.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import TOML from "@iarna/toml";
21
import { fetchResult } from "../cfetch";
3-
import { withConfig } from "../config";
2+
import { formatConfigSnippet, withConfig } from "../config";
43
import { UserError } from "../errors";
54
import { logger } from "../logger";
65
import { requireAuth } from "../user";
@@ -83,11 +82,14 @@ export const Handler = withConfig<HandlerOptions>(
8382
);
8483
logger.log("Created your new D1 database.\n");
8584
logger.log(
86-
TOML.stringify({
87-
d1_databases: [
88-
{ binding: "DB", database_name: db.name, database_id: db.uuid },
89-
],
90-
})
85+
formatConfigSnippet(
86+
{
87+
d1_databases: [
88+
{ binding: "DB", database_name: db.name, database_id: db.uuid },
89+
],
90+
},
91+
config.configPath
92+
)
9193
);
9294
}
9395
);

0 commit comments

Comments
 (0)