diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-26 16:41:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-26 16:41:16 +0100 |
commit | 9e0495baa7565737b8f1d66348b45bbed14831e0 (patch) | |
tree | 34bdb85953a4821b8f66bd08874fb8147f931d6b /runtime/js/99_main.js | |
parent | c66f7b6d8d1d7481eee91d9ff898fd4eaddfdeea (diff) |
fix: make deprecation warnings less verbose (#22128)
This commit makes deprecation warnings less verbose by default.
Only a single warnings is issued per deprecated API use.
`DENO_VERBOSE_WARNINGS` env var can be provided to enable more detailed
logging for each use of API including a stack trace.
https://github.com/denoland/deno/assets/13602871/9c036c84-0044-4cb6-9c8e-deb641f43712
Diffstat (limited to 'runtime/js/99_main.js')
-rw-r--r-- | runtime/js/99_main.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index c03ed2f8c..ac6161d8d 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -96,6 +96,7 @@ ObjectDefineProperties(Symbol, { let windowIsClosing = false; let globalThis_; +let verboseDeprecatedApiWarning = false; let deprecatedApiWarningDisabled = false; const ALREADY_WARNED_DEPRECATED = new SafeSet(); @@ -104,6 +105,19 @@ function warnOnDeprecatedApi(apiName, stack, ...suggestions) { return; } + if (!verboseDeprecatedApiWarning) { + if (ALREADY_WARNED_DEPRECATED.has(apiName)) { + return; + } + ALREADY_WARNED_DEPRECATED.add(apiName); + console.error( + `%cwarning: %cUse of deprecated "${apiName}" API. This API will be removed in Deno 2. Run again with DENO_VERBOSE_WARNINGS=1 to get more details.`, + "color: yellow;", + "font-weight: bold;", + ); + return; + } + if (ALREADY_WARNED_DEPRECATED.has(apiName + stack)) { return; } @@ -563,9 +577,11 @@ function bootstrapMainRuntime(runtimeOptions) { 5: hasNodeModulesDir, 6: maybeBinaryNpmCommandName, 7: shouldDisableDeprecatedApiWarning, + 8: shouldUseVerboseDeprecatedApiWarning, } = runtimeOptions; deprecatedApiWarningDisabled = shouldDisableDeprecatedApiWarning; + verboseDeprecatedApiWarning = shouldUseVerboseDeprecatedApiWarning; performance.setTimeOrigin(DateNow()); globalThis_ = globalThis; @@ -703,9 +719,11 @@ function bootstrapWorkerRuntime( 5: hasNodeModulesDir, 6: maybeBinaryNpmCommandName, 7: shouldDisableDeprecatedApiWarning, + 8: shouldUseVerboseDeprecatedApiWarning, } = runtimeOptions; deprecatedApiWarningDisabled = shouldDisableDeprecatedApiWarning; + verboseDeprecatedApiWarning = shouldUseVerboseDeprecatedApiWarning; performance.setTimeOrigin(DateNow()); globalThis_ = globalThis; |