Skip to content

Commit

Permalink
chore(tools): improved web-compatibility checks (denoland#3263)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua committed Mar 18, 2023
1 parent 8708618 commit cf14c9b
Show file tree
Hide file tree
Showing 110 changed files with 191 additions and 7 deletions.
48 changes: 48 additions & 0 deletions _tools/check_browser_compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

/**
* Running this script provides a list of suggested files that might be browser-compatible.
* It skips test code, benchmark code, internal code and `version.ts` at the root.
*
* Run using: deno run --allow-read --allow-run _tools/check_browser_compat.ts
*/
import { walkSync } from "../fs/walk.ts";

const ROOT = new URL("../", import.meta.url);
const SKIP = [/(test|bench|\/_|\\_|testdata|version.ts)/];
const DECLARATION = "// This module is browser compatible.";

function isBrowserCompatible(filePath: string): boolean {
const command = new Deno.Command(Deno.execPath(), {
args: [
"check",
"--config",
"browser-compat.tsconfig.json",
filePath,
],
});
const { success } = command.outputSync();
return success;
}

function hasBrowserCompatibleComment(path: string): boolean {
const output = Deno.readTextFileSync(path);
return output.includes(DECLARATION);
}

const maybeBrowserCompatibleFiles: string[] = [];

for (const { path } of walkSync(ROOT, { exts: [".ts"], skip: SKIP })) {
if (isBrowserCompatible(path) && !hasBrowserCompatibleComment(path)) {
maybeBrowserCompatibleFiles.push(path);
}
}

if (maybeBrowserCompatibleFiles.length) {
console.log(
`The following files are likely browser-compatible and can have the "${DECLARATION}" comment added:`,
);
maybeBrowserCompatibleFiles.forEach((path, index) =>
console.log(`${index + 1}. ${path}`)
);
}
2 changes: 2 additions & 0 deletions async/abortable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { deferred } from "./deferred.ts";

/**
Expand Down
1 change: 1 addition & 0 deletions async/retry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

export class RetryError extends Error {
constructor(cause: unknown, count: number) {
Expand Down
2 changes: 1 addition & 1 deletion collections/binary_heap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
/** This module is browser compatible. */
// This module is browser compatible.

import { descend } from "./_comparators.ts";

Expand Down
2 changes: 1 addition & 1 deletion collections/binary_search_node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
/** This module is browser compatible. */
// This module is browser compatible.

export type Direction = "left" | "right";

Expand Down
2 changes: 1 addition & 1 deletion collections/binary_search_tree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
/** This module is browser compatible. */
// This module is browser compatible.

import { ascend } from "./_comparators.ts";
import { BinarySearchNode, Direction } from "./binary_search_node.ts";
Expand Down
1 change: 1 addition & 0 deletions collections/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/** Functions for specific common tasks around collection types like `Array` and
* `Record`. This module is heavily inspired by `kotlin`s stdlib.
Expand Down
2 changes: 1 addition & 1 deletion collections/red_black_node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
/** This module is browser compatible. */
// This module is browser compatible.

import { BinarySearchNode, Direction } from "./binary_search_node.ts";
export type { Direction };
Expand Down
2 changes: 1 addition & 1 deletion collections/red_black_tree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
/** This module is browser compatible. */
// This module is browser compatible.

import { ascend, BinarySearchTree } from "./binary_search_tree.ts";
import { Direction, RedBlackNode } from "./red_black_node.ts";
Expand Down
1 change: 1 addition & 0 deletions crypto/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Extensions to the
Expand Down
1 change: 1 addition & 0 deletions crypto/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Extensions to the
Expand Down
1 change: 1 addition & 0 deletions crypto/timing_safe_equal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { assert } from "../_util/asserts.ts";

Expand Down
2 changes: 2 additions & 0 deletions crypto/to_hash_string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { encode as hexEncode } from "../encoding/hex.ts";
import { encode as base64Encode } from "../encoding/base64.ts";

Expand Down
2 changes: 2 additions & 0 deletions csv/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

export * from "./stringify.ts";
export * from "./parse.ts";
export * from "./stream.ts";
2 changes: 2 additions & 0 deletions csv/parse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import {
convertRowToObject,
ERR_BARE_QUOTE,
Expand Down
2 changes: 2 additions & 0 deletions csv/stream.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import {
convertRowToObject,
defaultReadOptions,
Expand Down
2 changes: 2 additions & 0 deletions csv/stringify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

type PropertyAccessor = number | string;
type ObjectWithStringPropertyKeys = Record<string, unknown>;

Expand Down
2 changes: 2 additions & 0 deletions datetime/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* The number of milliseconds in a second.
*
Expand Down
2 changes: 2 additions & 0 deletions datetime/day_of_year.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { DAY } from "./constants.ts";

/**
Expand Down
2 changes: 2 additions & 0 deletions datetime/difference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { DAY, HOUR, MINUTE, SECOND, WEEK } from "./constants.ts";

export type Unit =
Expand Down
2 changes: 2 additions & 0 deletions datetime/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { DateTimeFormatter } from "./_common.ts";

/**
Expand Down
2 changes: 2 additions & 0 deletions datetime/is_leap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Returns whether the given date or year (in number) is a leap year or not.
* based on: https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year
Expand Down
1 change: 1 addition & 0 deletions datetime/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Utilities for dealing with {@linkcode Date} objects.
Expand Down
2 changes: 2 additions & 0 deletions datetime/parse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { DateTimeFormatter } from "./_common.ts";

/**
Expand Down
2 changes: 2 additions & 0 deletions datetime/to_imf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Formats the given date to IMF date time format. (Reference:
* https://tools.ietf.org/html/rfc7231#section-7.1.1.1).
Expand Down
2 changes: 2 additions & 0 deletions datetime/week_of_year.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { DAY, WEEK } from "./constants.ts";

const DAYS_PER_WEEK = 7;
Expand Down
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
}
},
"tasks": {
"test": "deno test --doc --unstable --allow-all --coverage=./cov --ignore=_tools/testdata",
"test:browser": "git grep --name-only \"This module is browser compatible.\" | grep -v deno.json | grep -v .github/workflows | xargs deno cache --check --reload --config browser-compat.tsconfig.json",
"test": "deno test --doc --unstable --allow-all --coverage=./cov",
"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 ./_tools/check_deprecation.ts",
"lint:doc-imports": "deno run --allow-env --allow-read ./_tools/check_doc_imports.ts",
Expand Down
1 change: 1 addition & 0 deletions encoding/ascii85.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* {@linkcode encode} and {@linkcode decode} for
Expand Down
1 change: 1 addition & 0 deletions encoding/base32.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// Copyright (c) 2014 Jameson Little. MIT License.
// This module is browser compatible.

/**
* {@linkcode encode} and {@linkcode decode} for
Expand Down
1 change: 1 addition & 0 deletions encoding/base58.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* {@linkcode encode} and {@linkcode decode} for
Expand Down
1 change: 1 addition & 0 deletions encoding/base64.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* {@linkcode encode} and {@linkcode decode} for
Expand Down
1 change: 1 addition & 0 deletions encoding/base64url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* {@linkcode encode} and {@linkcode decode} for
Expand Down
2 changes: 2 additions & 0 deletions encoding/csv/stream.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

export {
/** @deprecated (will be removed after 0.182.0) Import from `csv/stream.ts` instead. */
CsvStream,
Expand Down
1 change: 1 addition & 0 deletions encoding/hex.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2009 The Go Authors. All rights reserved.
// https://github.com/golang/go/blob/master/LICENSE
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/** Port of the Go
* [encoding/hex](https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go)
Expand Down
1 change: 1 addition & 0 deletions encoding/jsonc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* @deprecated (will be removed after 0.182.0) Import from `std/jsonc` instead.
Expand Down
1 change: 1 addition & 0 deletions encoding/toml.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* @deprecated (will be removed after 0.182.0) Import from `std/toml` instead.
Expand Down
1 change: 1 addition & 0 deletions encoding/varint/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Functions for encoding typed integers in array buffers.
Expand Down
1 change: 1 addition & 0 deletions encoding/yaml.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* @deprecated (will be removed after 0.182.0) Import from `std/yaml` instead.
Expand Down
1 change: 1 addition & 0 deletions examples/welcome.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/** Welcome to Deno!
*
Expand Down
2 changes: 2 additions & 0 deletions flags/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Command line arguments parser based on
* [minimist](https://github.com/minimistjs/minimist).
Expand Down
1 change: 1 addition & 0 deletions fmt/bytes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2014-2021 Sindre Sorhus. All rights reserved. MIT license.
// Copyright 2021 Yoshiya Hinosawa. All rights reserved. MIT license.
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/** Pretty print bytes.
*
Expand Down
1 change: 1 addition & 0 deletions fmt/colors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
// A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
// on npm.

Expand Down
1 change: 1 addition & 0 deletions fmt/duration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Format milliseconds to time duration.
Expand Down
1 change: 1 addition & 0 deletions http/cookie_map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/** Provides a iterable map interfaces for managing cookies server side.
*
Expand Down
1 change: 1 addition & 0 deletions http/http_errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/** A collection of HTTP errors and utilities.
*
Expand Down
1 change: 1 addition & 0 deletions http/negotiation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Contains the functions {@linkcode accepts}, {@linkcode acceptsEncodings}, and
Expand Down
1 change: 1 addition & 0 deletions http/server_sent_event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* Provides {@linkcode ServerSentEvent} and
Expand Down
2 changes: 2 additions & 0 deletions http/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { Status, STATUS_TEXT } from "./http_status.ts";
import { deepMerge } from "../collections/deep_merge.ts";

Expand Down
1 change: 1 addition & 0 deletions io/buf_reader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { assert } from "../_util/asserts.ts";
import { copy } from "../bytes/copy.ts";
Expand Down
1 change: 1 addition & 0 deletions io/buf_writer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { copy } from "../bytes/copy.ts";
import type { Writer, WriterSync } from "../types.d.ts";
Expand Down
2 changes: 2 additions & 0 deletions io/buffer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { assert } from "../_util/asserts.ts";
import { copy } from "../bytes/copy.ts";
import type { Reader, ReaderSync } from "../types.d.ts";
Expand Down
1 change: 1 addition & 0 deletions io/copy_n.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { assert } from "../_util/asserts.ts";
import type { Reader, Writer } from "../types.d.ts";
Expand Down
2 changes: 2 additions & 0 deletions io/limited_reader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
* A `LimitedReader` reads from `reader` but limits the amount of data returned to just `limit` bytes.
* Each call to `read` updates `limit` to reflect the new amount remaining.
Expand Down
Loading

0 comments on commit cf14c9b

Please sign in to comment.