Repository navigation
[wrangler] Lazily resolve WRANGLER_LOG_PATH on first write - #16947
umeraamir69 wants to merge 1 commit into
Conversation
Setting the env var in vite.config.ts after a static import of @cloudflare/vite-plugin was ignored because debugLogFilepath was computed at module evaluation time. Resolve and memoize on first access instead, matching WRANGLER_WRITE_LOGS.
🦋 Changeset detectedLatest commit: 6495b44 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 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 |
|
Hi @umeraamir69. Thanks for taking the time to contribute to Workers SDK. This PR has been automatically closed because you are not currently a registered (vouched) collaborator for this repository. AI tools now let our team generate proposed code changes quickly. Reviewing changes, checking that they solve the right problem, and maintaining code quality over time still take substantial care and effort. We therefore limit PRs to registered collaborators so we can focus that effort where it is most useful. For the majority of external contributors, the most effective way to help is through issues: describing a problem or use case, providing a minimal reproduction, investigating its cause, or helping us verify a fix. Those contributions help us understand what needs to change and are very welcome. We will take an initial look at this PR and decide whether it is something we want to invest time in reviewing and maintaining. We may reopen it if we decide to proceed, but we cannot guarantee that it will be reopened or receive a full review. |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
| * `@cloudflare/vite-plugin` — is still respected. Matches the lazy read of | ||
| * `WRANGLER_WRITE_LOGS` in `shouldLogToDisk()`. | ||
| */ | ||
| let cachedDebugLogFilepath: string | undefined; |
There was a problem hiding this comment.
🟡 New module-wide mutable log-path cache
cachedDebugLogFilepath introduces mutable module-wide state shared by the getter and test reset function. The code-quality rule prohibits introducing global variables.
Learn more
The memoized path is now stored in a mutable module-level binding. Both the production getter and the exported test helper modify it, which conflicts with the repository's prohibition on new global variables.
Example: The first getter call fills the shared binding; resetDebugLogFilepathForTests() later clears that same binding for every caller.
Recommended fix: Encapsulate the cached value in a closure or logging-state instance, preserving lazy resolution and a stable path across writes. Keep test reset access within that encapsulation.
Was this helpful? React with 👍 or 👎 to provide feedback.
| export function getDebugLogFilepath(): string { | ||
| return (cachedDebugLogFilepath ??= getDebugFilepath()); | ||
| } |
There was a problem hiding this comment.
🔍 Exported getter lacks attached JSDoc
getDebugLogFilepath has no attached JSDoc; the preceding documentation belongs to the cache declaration. The implementation conventions require JSDoc for exported functions.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
|
||
| Fix `WRANGLER_LOG_PATH` being ignored when set in `vite.config.ts` after a static import of `@cloudflare/vite-plugin` | ||
|
|
||
| The debug log filepath is now resolved lazily on first write (memoized), matching how `WRANGLER_WRITE_LOGS` is read. Setting `process.env.WRANGLER_LOG_PATH` in the Vite config body after importing the plugin now writes logs to the configured path instead of the global default directory. |
There was a problem hiding this comment.
🔍 Changeset includes internal caching details
The memoization explanation and WRANGLER_WRITE_LOGS comparison describe implementation details excluded by the changeset guidance. The following sentence already explains the user-facing benefit.
Was this helpful? React with 👍 or 👎 to provide feedback.
Fixes #16925.
debugLogFilepathwas computed once at module evaluation time, so settingprocess.env.WRANGLER_LOG_PATHinvite.config.tsafter a staticimport { cloudflare } from "@cloudflare/vite-plugin"had no effect. Resolve and memoize the path on first access viagetDebugLogFilepath(), matching howWRANGLER_WRITE_LOGSis read lazily inshouldLogToDisk().