Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor lint:mod-exports task to use std/path #4503

Merged
merged 11 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ jobs:
run: ./_tools/release/03_release.ts

lint:
runs-on: ubuntu-22.04
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- windows-2022
- macOS-12
steps:
- name: Clone repository
uses: actions/checkout@v4
Expand All @@ -90,6 +98,7 @@ jobs:

- name: Spell-check
uses: crate-ci/typos@master
if: matrix.os == 'ubuntu-22.04'
with:
config: ./.github/typos.toml

Expand Down
66 changes: 32 additions & 34 deletions _tools/check_mod_exports.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { exists } from "../fs/exists.ts";
import { join } from "../path/join.ts";
import { walk } from "../fs/walk.ts";
import { relative } from "../path/relative.ts";
import { dirname } from "../path/dirname.ts";
import * as colors from "../fmt/colors.ts";
import ts from "npm:typescript";

const ROOT = new URL("../", import.meta.url);
const FAIL_FAST = Deno.args.includes("--fail-fast");
const EXCLUDED_PATHS = [
"dotenv/load.ts",
"path/glob.ts",
"front_matter/yaml.ts",
"front_matter/json.ts",
"front_matter/toml.ts",
"front_matter/any.ts",
"yaml/schema.ts",
];

const MOD_FILENAME = "mod.ts";

let shouldFail = false;

for await (const { name: dirName, isDirectory } of Deno.readDir(ROOT)) {
if (!isDirectory || dirName.startsWith(".") || dirName.startsWith("_")) {
continue;
}
const filePath = join(ROOT.pathname, dirName);
const modFilePath = join(filePath, MOD_FILENAME);
if (!await exists(modFilePath)) continue;

for await (
const { path: modFilePath } of walk(ROOT, {
includeDirs: true,
exts: ["ts"],
match: [/mod\.ts$/],
maxDepth: 2,
})
) {
const source = await Deno.readTextFile(modFilePath);
const sourceFile = ts.createSourceFile(
modFilePath,
Expand All @@ -43,19 +33,27 @@ for await (const { name: dirName, isDirectory } of Deno.readDir(ROOT)) {
exportSpecifiers.add(node.moduleSpecifier.text);
});

for await (const { name } of Deno.readDir(filePath)) {
if (
name === MOD_FILENAME ||
!name.endsWith(".ts") ||
name.startsWith(".") ||
name.startsWith("_") ||
name.endsWith("test.ts") ||
name.endsWith(".d.ts")
) continue;
const absoluteFilePath = join(dirName, name);
if (EXCLUDED_PATHS.includes(absoluteFilePath)) continue;

const relativeSpecifier = `./${name}`;
for await (
const { path: filePath } of walk(dirname(modFilePath), {
exts: ["ts"],
includeDirs: false,
maxDepth: 1,
skip: [
/dotenv(\/|\\)load\.ts$/,
/front_matter(\/|\\)yaml\.ts$/,
/front_matter(\/|\\)json\.ts$/,
/front_matter(\/|\\)toml\.ts$/,
/front_matter(\/|\\)any\.ts$/,
/yaml(\/|\\)schema\.ts$/,
/test\.ts$/,
/\.d\.ts$/,
/(\/|\\)_/,
/mod\.ts$/,
],
})
) {
const relativeSpecifier = relative(modFilePath, filePath).slice(1)
.replaceAll("\\", "/");
if (!exportSpecifiers.has(relativeSpecifier)) {
console.warn(
`${
Expand Down
Loading