Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua committed Jan 19, 2024
1 parent 425294f commit 91cd789
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"automation/": "https://raw.githubusercontent.com/denoland/automation/0.10.0/"
},
"tasks": {
"test": "NO_DEPRECATION_WARNINGS=1 deno test --doc --unstable --allow-all --parallel --coverage --trace-ops",
"test": "DENO_NO_DEPRECATION_WARNINGS=1 deno test --doc --unstable --allow-all --parallel --coverage --trace-ops",
"test:browser": "git grep --name-only \"This module is browser compatible.\" | grep -v deno.json | grep -v .github/workflows | grep -v _tools | xargs deno check --config browser-compat.tsconfig.json",
"fmt:licence-headers": "deno run --allow-read --allow-write ./_tools/check_licence.ts",
"lint:deprecations": "deno run --allow-read --allow-net --allow-env=HOME ./_tools/check_deprecation.ts",
Expand Down
17 changes: 10 additions & 7 deletions internal/warn_on_deprecated_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
const { Deno } = globalThis as any;

const ALREADY_WARNED_DEPRECATED = new Set<string>();
const ENV_VAR_KEY = "DENO_NO_DEPRECATION_WARNINGS";
const shouldDisableDeprecatedApiWarning =
Deno?.permissions.querySync({ name: "env", variable: ENV_VAR_KEY })
.state === "granted" && Deno?.env.get(ENV_VAR_KEY) === "1";

interface WarnDeprecatedApiConfig {
/** The name of the deprecated API. */
Expand All @@ -20,15 +24,14 @@ interface WarnDeprecatedApiConfig {
/**
* Prints a warning message to the console for the given deprecated API.
*
* These warnings can be disabled by setting `NO_DEPRECATION_WARNINGS=1`
* These warnings can be disabled by setting `DENO_NO_DEPRECATION_WARNINGS=1`
* in the current process.
*
* Mostly copied from
* {@link https://github.com/denoland/deno/blob/c62615bfe5a070c2517f3af3208d4308c72eb054/runtime/js/99_main.js#L101}.
*/
export function warnOnDeprecatedApi(config: WarnDeprecatedApiConfig) {
const variable = "NO_DEPRECATION_WARNINGS";
if (
Deno?.permissions.querySync({ name: "env", variable }).state ===
"granted" && Deno?.env.get(variable) === "1"
) return;
if (shouldDisableDeprecatedApiWarning) return;

const key = config.apiName + config.stack;
if (ALREADY_WARNED_DEPRECATED.has(key)) return;

Check warning on line 37 in internal/warn_on_deprecated_api.ts

View check run for this annotation

Codecov / codecov/patch

internal/warn_on_deprecated_api.ts#L36-L37

Added lines #L36 - L37 were not covered by tests
Expand Down Expand Up @@ -78,7 +81,7 @@ export function warnOnDeprecatedApi(config: WarnDeprecatedApiConfig) {
console.log("%c\u2502", "color: yellow;");
console.log("%c\u2502", "color: yellow;");
console.log(
"%c\u251c Set `NO_DEPRECATION_WARNINGS=1` to disable these deprecation warnings.",
"%c\u251c Set `DENO_NO_DEPRECATION_WARNINGS=1` to disable these deprecation warnings.",
"color: yellow;",

Check warning on line 85 in internal/warn_on_deprecated_api.ts

View check run for this annotation

Codecov / codecov/patch

internal/warn_on_deprecated_api.ts#L81-L85

Added lines #L81 - L85 were not covered by tests
);
console.log("%c\u2514 Stack trace:", "color: yellow;");
Expand Down
2 changes: 1 addition & 1 deletion internal/warn_on_deprecated_api_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Deno.test("warnDeprecatedApi()", async () => {
├ Suggestion: Do something else instead.
├ Set \`NO_DEPRECATION_WARNINGS=1\` to disable these deprecation warnings.
├ Set \`DENO_NO_DEPRECATION_WARNINGS=1\` to disable these deprecation warnings.
└ Stack trace:
├─ at fn (${import.meta.url}:39:12)
└─ at ${import.meta.url}:47:31
Expand Down

0 comments on commit 91cd789

Please sign in to comment.