chore(internal): remove warnOnDeprecatedApi() and internal folder (#4359)

This commit is contained in:
Asher Gomez 2024-02-20 20:00:58 +11:00 committed by GitHub
parent a828744083
commit ece94b6019
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 1 additions and 150 deletions

View File

@ -8,7 +8,6 @@ import ts from "npm:typescript";
const ROOT = new URL("../", import.meta.url);
const FAIL_FAST = Deno.args.includes("--fail-fast");
const EXCLUDED_PATHS = [
"internal/warn_on_deprecated_api.ts",
"dotenv/load.ts",
"path/glob.ts",
"front_matter/yaml.ts",

View File

@ -12,7 +12,7 @@
"automation/": "https://raw.githubusercontent.com/denoland/automation/0.10.0/"
},
"tasks": {
"test": "DENO_NO_DEPRECATION_WARNINGS=1 deno test --unstable-http --unstable-webgpu --doc --allow-all --parallel --coverage --trace-ops",
"test": "deno test --unstable-http --unstable-webgpu --doc --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",

View File

@ -1,9 +0,0 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/**
* Internal utilities for the public API of the Deno Standard Library.
*
* Note: for internal use only.
*
* @module
*/

View File

@ -1,92 +0,0 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
// deno-lint-ignore no-explicit-any
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.has(ENV_VAR_KEY);
interface WarnDeprecatedApiConfig {
/** The name of the deprecated API. */
apiName: string;
/** The stack trace of the deprecated API. */
stack: string;
/** The version in which the API will be removed. */
removalVersion: string;
/** An optional message to print. */
suggestion?: string;
}
/**
* Prints a warning message to the console for the given deprecated API.
*
* 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) {
if (shouldDisableDeprecatedApiWarning) return;
const key = config.apiName + config.stack;
if (ALREADY_WARNED_DEPRECATED.has(key)) return;
// If we haven't warned yet, let's do some processing of the stack trace
// to make it more useful.
const stackLines = config.stack.split("\n");
stackLines.shift();
let isFromRemoteDependency = false;
const firstStackLine = stackLines[0];
if (firstStackLine && !firstStackLine.includes("file:")) {
isFromRemoteDependency = true;
}
ALREADY_WARNED_DEPRECATED.add(key);
console.log(
"%cWarning",
"color: yellow; font-weight: bold;",
);
console.log(
`%c\u251c Use of deprecated "${config.apiName}" API.`,
"color: yellow;",
);
console.log("%c\u2502", "color: yellow;");
console.log(
`%c\u251c This API will be removed in version ${config.removalVersion} of the Deno Standard Library.`,
"color: yellow;",
);
console.log("%c\u2502", "color: yellow;");
console.log(
`%c\u251c Suggestion: ${config.suggestion}`,
"color: yellow;",
);
if (isFromRemoteDependency) {
console.log("%c\u2502", "color: yellow;");
console.log(
`%c\u251c Suggestion: It appears this API is used by a remote dependency.`,
"color: yellow;",
);
console.log(
"%c\u2502 Try upgrading to the latest version of that dependency.",
"color: yellow;",
);
}
console.log("%c\u2502", "color: yellow;");
console.log("%c\u2514 Stack trace:", "color: yellow;");
for (let i = 0; i < stackLines.length; i++) {
console.log(
`%c ${i == stackLines.length - 1 ? "\u2514" : "\u251c"}\u2500 ${
stackLines[i].trim()
}`,
"color: yellow;",
);
}
console.log();
}

View File

@ -1,47 +0,0 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/assert_equals.ts";
import { warnOnDeprecatedApi } from "./warn_on_deprecated_api.ts";
Deno.test("warnDeprecatedApi()", async () => {
const command = new Deno.Command(Deno.execPath(), {
args: ["run", "--quiet", "--no-lock", import.meta.url],
stderr: "inherit",
});
const { success, stdout } = await command.output();
const output = new TextDecoder().decode(stdout);
assertEquals(success, true);
assertEquals(
output,
`Warning
Use of deprecated "fn()" API.
This API will be removed in version 1.0.0 of the Deno Standard Library.
Suggestion: Do something else instead.
Stack trace:
at fn (${import.meta.url}:37:12)
at ${import.meta.url}:45:31
Hello, world!
Hello, world!
END
`,
);
});
function fn() {
warnOnDeprecatedApi({
apiName: "fn()",
stack: new Error().stack!,
removalVersion: "1.0.0",
suggestion: "Do something else instead.",
});
console.log("Hello, world!");
}
if (import.meta.main) {
for (let i = 0; i < 2; i++) fn();
console.log("END");
}