Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/async-read-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"wrangler": minor
"@cloudflare/workers-utils": minor
---

Add new async config reading APIs to support future code-based config files.

- `unstable_readConfigAsync` - Async version of `unstable_readConfig` that will support code-based config files (`.ts`, `.js`)
- `experimental_readRawConfigAsync` - Async version of `experimental_readRawConfig`

The existing sync APIs (`unstable_readConfig`, `experimental_readRawConfig`) continue to work unchanged for data file formats (`.toml`, `.json`, `.jsonc`).

In Wrangler v5, the sync APIs will be removed and the async APIs will become the default.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ describe.skipIf(!satisfiesViteVersion("7.2.7"))("shortcuts", () => {
process.stdin.isTTY = false;
});

test("display binding shortcut hint", () => {
test("display binding shortcut hint", async () => {
// Set up the shortcut wrapper (after stubs are in place from beforeAll)
const mockContext = new PluginContext({
hasShownWorkerConfigWarnings: false,
isRestartingDevServer: false,
});
mockContext.setResolvedPluginConfig(
resolvePluginConfig(
await resolvePluginConfig(
{
configPath: path.resolve(__dirname, "../wrangler.jsonc"),
},
Expand Down Expand Up @@ -63,7 +63,7 @@ describe.skipIf(!satisfiesViteVersion("7.2.7"))("shortcuts", () => {
"press b + enter to list configured Cloudflare bindings"
);
});
test("prints bindings with a single Worker", () => {
test("prints bindings with a single Worker", async () => {
// Create a test server with a spy on bindCLIShortcuts
const mockBindCLIShortcuts = vi.spyOn(viteServer, "bindCLIShortcuts");
// Create mock plugin context
Expand All @@ -73,7 +73,7 @@ describe.skipIf(!satisfiesViteVersion("7.2.7"))("shortcuts", () => {
});

mockContext.setResolvedPluginConfig(
resolvePluginConfig(
await resolvePluginConfig(
{
configPath: path.resolve(__dirname, "../wrangler.jsonc"),
},
Expand Down Expand Up @@ -119,7 +119,7 @@ describe.skipIf(!satisfiesViteVersion("7.2.7"))("shortcuts", () => {
`);
});

test("prints bindings with multi Workers", () => {
test("prints bindings with multi Workers", async () => {
// Create a test server with a spy on bindCLIShortcuts
const mockBindCLIShortcuts = vi.spyOn(viteServer, "bindCLIShortcuts");
// Create mock plugin context
Expand All @@ -129,7 +129,7 @@ describe.skipIf(!satisfiesViteVersion("7.2.7"))("shortcuts", () => {
});

mockContext.setResolvedPluginConfig(
resolvePluginConfig(
await resolvePluginConfig(
{
configPath: path.resolve(__dirname, "../wrangler.jsonc"),
auxiliaryWorkers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from "../workers-configs";

describe("readWorkerConfigFromFile", () => {
test("should return a simple raw config", () => {
const { raw } = readWorkerConfigFromFile(
test("should return a simple raw config", async () => {
const { raw } = await readWorkerConfigFromFile(
fileURLToPath(new URL("fixtures/simple-wrangler.jsonc", import.meta.url)),
undefined
);
Expand All @@ -34,8 +34,8 @@ describe("readWorkerConfigFromFile", () => {
expect(raw.tsconfig).toBeUndefined();
});

test("should return a simple config without non-applicable fields", () => {
const { config } = readWorkerConfigFromFile(
test("should return a simple config without non-applicable fields", async () => {
const { config } = await readWorkerConfigFromFile(
fileURLToPath(new URL("fixtures/simple-wrangler.jsonc", import.meta.url)),
undefined
);
Expand All @@ -44,8 +44,8 @@ describe("readWorkerConfigFromFile", () => {
expect("preserve_file_names" in config).toBeFalsy();
});

test("should not return any non-applicable config when there isn't any", () => {
const { nonApplicable } = readWorkerConfigFromFile(
test("should not return any non-applicable config when there isn't any", async () => {
const { nonApplicable } = await readWorkerConfigFromFile(
fileURLToPath(new URL("fixtures/simple-wrangler.jsonc", import.meta.url)),
undefined
);
Expand All @@ -55,8 +55,8 @@ describe("readWorkerConfigFromFile", () => {
});
});

test("should read a simple wrangler config file", () => {
const { config, nonApplicable } = readWorkerConfigFromFile(
test("should read a simple wrangler config file", async () => {
const { config, nonApplicable } = await readWorkerConfigFromFile(
fileURLToPath(new URL("fixtures/simple-wrangler.jsonc", import.meta.url)),
undefined
);
Expand Down Expand Up @@ -84,8 +84,8 @@ describe("readWorkerConfigFromFile", () => {
});
});

test("should collect non applicable configs", () => {
const { config, raw, nonApplicable } = readWorkerConfigFromFile(
test("should collect non applicable configs", async () => {
const { config, raw, nonApplicable } = await readWorkerConfigFromFile(
fileURLToPath(
new URL(
"fixtures/wrangler-with-fields-to-ignore.jsonc",
Expand Down Expand Up @@ -159,11 +159,11 @@ describe("readWorkerConfigFromFile", () => {
});

describe("resolveWorkerType", () => {
test("should throw if the provided main config doesn't point to an existing file", () => {
test("should throw if the provided main config doesn't point to an existing file", async () => {
const configPath = fileURLToPath(
new URL("fixtures/non-existing-main-wrangler.jsonc", import.meta.url)
);
const { config, raw, nonApplicable } = readWorkerConfigFromFile(
const { config, raw, nonApplicable } = await readWorkerConfigFromFile(
configPath,
undefined
);
Expand Down
Loading
Loading