From 9e4d8bcb8811b9dc2570de26660baa4361a52749 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Thu, 30 May 2024 14:03:25 +0100 Subject: [PATCH] fix: let "assets" in wrangler.toml be a string (#5938) The experimental "assets" field can be either a string or an object. However the type definition marks it only as an object. This is a problem because we use this to generate the json schema, which gets picked up by vscode's even better toml extension, and shows it to be an error when used with a string (even though it works fine). The fix is to simply change the type definition to add a string variant. --- .changeset/blue-pets-think.md | 7 +++++++ packages/wrangler/src/__tests__/deploy.test.ts | 3 --- packages/wrangler/src/__tests__/dev.test.tsx | 3 --- packages/wrangler/src/config/config.ts | 1 + pnpm-lock.yaml | 18 +++++++++--------- 5 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 .changeset/blue-pets-think.md diff --git a/.changeset/blue-pets-think.md b/.changeset/blue-pets-think.md new file mode 100644 index 000000000000..c14cb5714df3 --- /dev/null +++ b/.changeset/blue-pets-think.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +fix: let "assets" in wrangler.toml be a string + +The experimental "assets" field can be either a string or an object. However the type definition marks it only as an object. This is a problem because we use this to generate the json schema, which gets picked up by vscode's even better toml extension, and shows it to be an error when used with a string (even though it works fine). The fix is to simply change the type definition to add a string variant. diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index d336a2d0ca8b..27599ab0f7ce 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -2293,7 +2293,6 @@ addEventListener('fetch', event => {});` it("should error if config.assets and --site are used together", async () => { writeWranglerToml({ main: "./index.js", - // @ts-expect-error we allow string inputs here assets: "abc", }); writeWorkerSource(); @@ -2323,7 +2322,6 @@ addEventListener('fetch', event => {});` it("should error if config.assets and config.site are used together", async () => { writeWranglerToml({ main: "./index.js", - // @ts-expect-error we allow string inputs here assets: "abc", site: { bucket: "xyz", @@ -2407,7 +2405,6 @@ addEventListener('fetch', event => {});` it("should warn if config.assets is used", async () => { writeWranglerToml({ main: "./index.js", - // @ts-expect-error we allow string inputs here assets: "./assets", }); const assets = [ diff --git a/packages/wrangler/src/__tests__/dev.test.tsx b/packages/wrangler/src/__tests__/dev.test.tsx index e6cd84173516..dbbc59ea39bd 100644 --- a/packages/wrangler/src/__tests__/dev.test.tsx +++ b/packages/wrangler/src/__tests__/dev.test.tsx @@ -1276,7 +1276,6 @@ describe("wrangler dev", () => { it("should error if config.assets and --site are used together", async () => { writeWranglerToml({ main: "./index.js", - // @ts-expect-error we allow string inputs here assets: "abc", }); fs.writeFileSync("index.js", `export default {};`); @@ -1290,7 +1289,6 @@ describe("wrangler dev", () => { it("should error if config.assets and config.site are used together", async () => { writeWranglerToml({ main: "./index.js", - // @ts-expect-error we allow string inputs here assets: "abc", site: { bucket: "xyz", @@ -1342,7 +1340,6 @@ describe("wrangler dev", () => { it("should warn if config.assets is used", async () => { writeWranglerToml({ main: "./index.js", - // @ts-expect-error we allow string inputs here assets: "./assets", }); fs.writeFileSync("index.js", `export default {};`); diff --git a/packages/wrangler/src/config/config.ts b/packages/wrangler/src/config/config.ts index a2ab552e2e36..41f0121f9cb1 100644 --- a/packages/wrangler/src/config/config.ts +++ b/packages/wrangler/src/config/config.ts @@ -149,6 +149,7 @@ export interface ConfigFields { browser_TTL: number | undefined; serve_single_page_app: boolean; } + | string | undefined; /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3b99f5c19851..ca11213e3283 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13695,8 +13695,8 @@ snapshots: '@typescript-eslint/parser': 5.62.0(eslint@8.42.0)(typescript@4.9.5) eslint: 8.42.0 eslint-import-resolver-node: 0.3.7 - eslint-import-resolver-typescript: 3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5)(eslint@8.42.0) - eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-typescript@3.5.5)(eslint@8.42.0) + eslint-import-resolver-typescript: 3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0))(eslint@8.42.0) + eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0))(eslint@8.42.0))(eslint@8.42.0) eslint-plugin-jest: 26.9.0(@typescript-eslint/eslint-plugin@5.62.0(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0)(typescript@4.9.5) eslint-plugin-jest-dom: 4.0.3(eslint@8.42.0) eslint-plugin-jsx-a11y: 6.7.1(eslint@8.42.0) @@ -16651,13 +16651,13 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5)(eslint@8.42.0): + eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0))(eslint@8.42.0): dependencies: debug: 4.3.4(supports-color@9.2.2) enhanced-resolve: 5.14.1 eslint: 8.42.0 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5)(eslint@8.42.0))(eslint@8.42.0) - eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-typescript@3.5.5)(eslint@8.42.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0))(eslint@8.42.0))(eslint@8.42.0) + eslint-plugin-import: 2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0))(eslint@8.42.0))(eslint@8.42.0) get-tsconfig: 4.6.0 globby: 13.1.4 is-core-module: 2.13.0 @@ -16669,14 +16669,14 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-module-utils@2.8.0(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5)(eslint@8.42.0))(eslint@8.42.0): + eslint-module-utils@2.8.0(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0))(eslint@8.42.0))(eslint@8.42.0): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 5.62.0(eslint@8.42.0)(typescript@4.9.5) eslint: 8.42.0 eslint-import-resolver-node: 0.3.7 - eslint-import-resolver-typescript: 3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5)(eslint@8.42.0) + eslint-import-resolver-typescript: 3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0))(eslint@8.42.0) transitivePeerDependencies: - supports-color @@ -16758,7 +16758,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-typescript@3.5.5)(eslint@8.42.0): + eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0))(eslint@8.42.0))(eslint@8.42.0): dependencies: array-includes: 3.1.6 array.prototype.flat: 1.3.1 @@ -16767,7 +16767,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.42.0 eslint-import-resolver-node: 0.3.7 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5)(eslint@8.42.0))(eslint@8.42.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-import-resolver-typescript@3.5.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.7)(eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.62.0(eslint@8.42.0)(typescript@4.9.5))(eslint@8.42.0))(eslint@8.42.0))(eslint@8.42.0) has: 1.0.3 is-core-module: 2.13.0 is-glob: 4.0.3