wrangler] fix: validate types output file at the target path#14583
wrangler] fix: validate types output file at the target path#14583Partha-Shankar wants to merge 3 commits into
Conversation
…onfig fields Add optional string validation checks for database_name, migrations_dir, migrations_table, and database_internal_env inside validateD1Binding. This aligns D1's validation behavior with other bindings (like KV, R2, and Durable Objects) that typecheck all optional parameters.
… database fields Also add changeset for type validation of optional D1 configuration fields.
🦋 Changeset detectedLatest commit: 08ae23f The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
| it("should ignore a non-Wrangler types file in a parent directory", async ({ | ||
| expect, | ||
| }) => { | ||
| const parentDir = path.resolve(".."); | ||
| const parentTypesPath = path.join( | ||
| parentDir, | ||
| "worker-configuration.d.ts" | ||
| ); | ||
|
|
||
| fs.writeFileSync(parentTypesPath, "export interface CustomEnv {}"); | ||
|
|
||
| try { | ||
| fs.writeFileSync( | ||
| "./index.ts", | ||
| "export default { async fetch() {} };" | ||
| ); | ||
| fs.writeFileSync( | ||
| "./wrangler.jsonc", | ||
| JSON.stringify({ | ||
| compatibility_date: "2022-01-12", | ||
| name: "test-name", | ||
| main: "./index.ts", | ||
| }), | ||
| "utf-8" | ||
| ); | ||
|
|
||
| await runWrangler("types"); | ||
|
|
||
| expect(fs.existsSync("./worker-configuration.d.ts")).toBe(true); | ||
| } finally { | ||
| try { | ||
| fs.unlinkSync(parentTypesPath); | ||
| } catch {} | ||
| } | ||
| }); |
There was a problem hiding this comment.
🔍 Test writes to parent of temp directory, potential parallel test interference
The new test at line 3434 writes worker-configuration.d.ts into path.resolve("..") — the parent of the runInTempDir() sandbox. If multiple test shards or parallel runs use sibling temp directories under the same parent (e.g., /tmp/), this file could collide with another test's parent directory check. The finally block cleans it up, but a crash before cleanup or a parallel read could cause flakiness. Consider using a dedicated isolated directory instead of .., or at minimum using a unique filename.
Was this helpful? React with 👍 or 👎 to provide feedback.
@cloudflare/autoconfig
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Fixes a false-positive validation error in
wrangler typeswhen generating types from a subdirectory.Details
Previously,
validateTypesFile()searched parent directories for an existingworker-configuration.d.ts. As a result, runningwrangler typesfrom a subdirectory could incorrectly fail if an unrelated customworker-configuration.d.tsexisted in a parent directory, even though no such file existed at the target output path.This change validates only the target output path, ensuring the validation matches the actual output location.
Adds a regression test covering this scenario.
Tests
Public documentation