From fbfcd24f41d17db54fb8271ed339bfae1d39a11f Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 5 Jun 2024 11:39:33 +1000 Subject: [PATCH] refactor(fs): cleanup use of `@std/assert` (#4948) * refactor(fs): cleanup use of `@std/assert` * tweaks * update --- .github/dependency_graph.svg | 476 +++++++++++++++++------------------ fs/copy.ts | 31 ++- fs/expand_glob.ts | 9 +- 3 files changed, 259 insertions(+), 257 deletions(-) diff --git a/.github/dependency_graph.svg b/.github/dependency_graph.svg index 56348368db85..136b0acca8c9 100644 --- a/.github/dependency_graph.svg +++ b/.github/dependency_graph.svg @@ -4,561 +4,555 @@ - + std_deps - + archive - -archive + +archive io - -io + +io archive->io - - + + assert - - -assert + + +assert archive->assert - - + + - + io->assert - - + + bytes - - -bytes + + +bytes - + io->bytes - - + + internal - - -internal + + +internal assert->internal - - + + async - - -async + + +async cli - -cli + +cli cli->assert - - + + collections - - -collections + + +collections crypto - - -crypto + + +crypto csv - - -csv + + +csv csv->assert - - + + streams - - -streams + + +streams csv->streams - - + + - + streams->io - - + + - + streams->assert - - + + - + streams->bytes - - + + data_\nstructures - -data_ -structures + +data_ +structures datetime - -datetime + +datetime dotenv - -dotenv + +dotenv encoding - - -encoding + + +encoding expect - -expect + +expect expect->assert - - + + expect->internal - - + + fmt - - -fmt + + +fmt front_\nmatter - - -front_ -matter + + +front_ +matter toml - - -toml + + +toml front_\nmatter->toml - - + + yaml - - -yaml + + +yaml front_\nmatter->yaml - - + + - + toml->collections - - + + fs - - -fs - - - -fs->assert - - + + +fs path - - -path + + +path fs->path - - + + html - -html + +html http - -http + +http - + http->assert - - + + - + http->async - - + + - + http->cli - - + + - + http->streams - - + + - + http->encoding - - + + - + http->fmt - - + + - + http->path - - + + media_types - -media_types + +media_types - + http->media_types - - + + net - -net + +net - + http->net - - + + ini - -ini + +ini json - - -json + + +json - + json->streams - - + + jsonc - - -jsonc + + +jsonc - + jsonc->assert - - + + - + jsonc->json - - + + log - -log + +log - + log->io - - + + - + log->assert - - + + - + log->fmt - - + + - + log->fs - - + + media_\ntypes - - -media_ -types + + +media_ +types msgpack - -msgpack + +msgpack - + msgpack->bytes - - + + regexp - -regexp + +regexp semver - -semver + +semver testing - - -testing + + +testing - + testing->assert - - + + - + testing->internal - - + + - + testing->async - - + + - + testing->fmt - - + + - + testing->fs - - + + - + testing->path - - + + data_structures - -data_structures + +data_structures - + testing->data_structures - - + + text - -text + +text - + text->assert - - + + ulid - -ulid + +ulid url - -url + +url - + url->path - - + + uuid - - -uuid + + +uuid - + uuid->bytes - - + + - + uuid->crypto - - + + webgpu - -webgpu + +webgpu - + webgpu->assert - - + + diff --git a/fs/copy.ts b/fs/copy.ts index 94ec78b6074c..0072f192332d 100644 --- a/fs/copy.ts +++ b/fs/copy.ts @@ -4,7 +4,6 @@ import { basename } from "@std/path/basename"; import { join } from "@std/path/join"; import { resolve } from "@std/path/resolve"; import { ensureDir, ensureDirSync } from "./ensure_dir.ts"; -import { assert } from "@std/assert/assert"; import { getFileInfoType } from "./_get_file_info_type.ts"; import { toPathString } from "./_to_path_string.ts"; import { isSubdir } from "./_is_subdir.ts"; @@ -34,6 +33,12 @@ interface InternalCopyOptions extends CopyOptions { isFolder?: boolean; } +function assertIsDate(date: Date | null, name: string): asserts date is Date { + if (date === null) { + throw new Error(`${name} is unavailable`); + } +} + async function ensureValidCopy( src: string | URL, dest: string | URL, @@ -99,8 +104,8 @@ async function copyFile( await Deno.copyFile(src, dest); if (options.preserveTimestamps) { const statInfo = await Deno.stat(src); - assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`); - assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`); + assertIsDate(statInfo.atime, "statInfo.atime"); + assertIsDate(statInfo.mtime, "statInfo.mtime"); await Deno.utime(dest, statInfo.atime, statInfo.mtime); } } @@ -114,8 +119,8 @@ function copyFileSync( Deno.copyFileSync(src, dest); if (options.preserveTimestamps) { const statInfo = Deno.statSync(src); - assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`); - assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`); + assertIsDate(statInfo.atime, "statInfo.atime"); + assertIsDate(statInfo.mtime, "statInfo.mtime"); Deno.utimeSync(dest, statInfo.atime, statInfo.mtime); } } @@ -138,8 +143,8 @@ async function copySymLink( } if (options.preserveTimestamps) { const statInfo = await Deno.lstat(src); - assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`); - assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`); + assertIsDate(statInfo.atime, "statInfo.atime"); + assertIsDate(statInfo.mtime, "statInfo.mtime"); await Deno.utime(dest, statInfo.atime, statInfo.mtime); } } @@ -163,8 +168,8 @@ function copySymlinkSync( if (options.preserveTimestamps) { const statInfo = Deno.lstatSync(src); - assert(statInfo.atime instanceof Date, `statInfo.atime is unavailable`); - assert(statInfo.mtime instanceof Date, `statInfo.mtime is unavailable`); + assertIsDate(statInfo.atime, "statInfo.atime"); + assertIsDate(statInfo.mtime, "statInfo.mtime"); Deno.utimeSync(dest, statInfo.atime, statInfo.mtime); } } @@ -186,8 +191,8 @@ async function copyDir( if (options.preserveTimestamps) { const srcStatInfo = await Deno.stat(src); - assert(srcStatInfo.atime instanceof Date, `statInfo.atime is unavailable`); - assert(srcStatInfo.mtime instanceof Date, `statInfo.mtime is unavailable`); + assertIsDate(srcStatInfo.atime, "statInfo.atime"); + assertIsDate(srcStatInfo.mtime, "statInfo.mtime"); await Deno.utime(dest, srcStatInfo.atime, srcStatInfo.mtime); } @@ -228,8 +233,8 @@ function copyDirSync( if (options.preserveTimestamps) { const srcStatInfo = Deno.statSync(src); - assert(srcStatInfo.atime instanceof Date, `statInfo.atime is unavailable`); - assert(srcStatInfo.mtime instanceof Date, `statInfo.mtime is unavailable`); + assertIsDate(srcStatInfo.atime, "statInfo.atime"); + assertIsDate(srcStatInfo.mtime, "statInfo.mtime"); Deno.utimeSync(dest, srcStatInfo.atime, srcStatInfo.mtime); } diff --git a/fs/expand_glob.ts b/fs/expand_glob.ts index ce761afe4d21..c5bd647a9ce9 100644 --- a/fs/expand_glob.ts +++ b/fs/expand_glob.ts @@ -6,7 +6,6 @@ import { isAbsolute } from "@std/path/is-absolute"; import { resolve } from "@std/path/resolve"; import { SEPARATOR_PATTERN } from "@std/path/constants"; import { walk, walkSync } from "./walk.ts"; -import { assert } from "@std/assert/assert"; import { toPathString } from "./_to_path_string.ts"; import { createWalkEntry, @@ -158,7 +157,9 @@ export async function* expandGlob( : absRoot; while (segments.length > 0 && !isGlob(segments[0]!)) { const seg = segments.shift(); - assert(seg !== undefined); + if (seg === undefined) { + throw new TypeError("Unexpected undefined segment"); + } fixedRoot = joinGlobs([fixedRoot, seg], globOptions); } @@ -316,7 +317,9 @@ export function* expandGlobSync( : absRoot; while (segments.length > 0 && !isGlob(segments[0]!)) { const seg = segments.shift(); - assert(seg !== undefined); + if (seg === undefined) { + throw new TypeError("Unexpected undefined segment"); + } fixedRoot = joinGlobs([fixedRoot, seg], globOptions); }