Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): enable debug logging in edge and fix process.env access (#…
…14537) - Forward `process.env.DEBUG` or `global.DEBUG` from the entry point of the edge client to the runtime bundle as `process.env.DEBUG`. This makes it possible to enable the debug logs during development using an environment variable. - Patch the debug logger to make it work in the edge environment and use `console.debug` or `console.log` instead of `process.stderr.write`. - Use uniform way of accessing the environment variables in the entry point both for `DATABASE_URL` and `DEBUG` and fix incorrect unconditional access to the `process` object which might not be present. Fixes #12681 Fixes #14536 Fixes #13771
- Loading branch information
Showing
6 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/client/src/generation/utils/buildDebugInitialization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getRuntimeEdgeEnvVar } from './buildInjectableEdgeEnv' | ||
|
||
/** | ||
* Builds the code to initialize the `debug` package. | ||
* | ||
* The code running in the Edge Client entry point has access to `process.env` | ||
* if it's defined, but the code in the runtime bundle doesn't. Furthermore, in | ||
* some environments `DEBUG` may be defined as a global variable rather than | ||
* available in `process.env`. The entry point fetches the value of `DEBUG` and | ||
* passes in to the `debug` package. | ||
* | ||
* @param edge Whether the edge runtime is used | ||
*/ | ||
export function buildDebugInitialization(edge: boolean) { | ||
if (!edge) { | ||
return '' | ||
} | ||
|
||
const debugVar = getRuntimeEdgeEnvVar('DEBUG') | ||
|
||
return `\ | ||
if (${debugVar}) { | ||
Debug.enable(${debugVar}) | ||
} | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters