From 4c68838074419831234ff2f97c8d8ff0aa0c079b Mon Sep 17 00:00:00 2001 From: Jason Yu Date: Sun, 8 Sep 2024 13:57:23 +0100 Subject: [PATCH] migrate to using jsr @std --- deno.json | 10 +++++++++- e2e_test.ts | 7 ++++--- islands/ItemsList.tsx | 2 +- plugins/blog/mod.ts | 2 +- plugins/blog/utils/posts.ts | 6 +++--- plugins/blog/utils/posts_test.ts | 2 +- plugins/error_handling.ts | 2 +- routes/api/stripe-webhooks.ts | 2 +- routes/api/vote.ts | 2 +- routes/submit.tsx | 2 +- tasks/check_license.ts | 4 ++-- tasks/db_seed.ts | 2 +- utils/db.ts | 4 ++-- utils/db_test.ts | 4 ++-- utils/display.ts | 4 ++-- utils/display_test.ts | 4 ++-- utils/github_test.ts | 8 ++++---- utils/http.ts | 2 +- utils/http_test.ts | 6 +++--- utils/stripe.ts | 2 +- utils/stripe_test.ts | 2 +- 21 files changed, 44 insertions(+), 35 deletions(-) diff --git a/deno.json b/deno.json index d7d9c72e1..323839e36 100644 --- a/deno.json +++ b/deno.json @@ -20,11 +20,19 @@ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }, "imports": { "$fresh/": "https://raw.githubusercontent.com/denoland/fresh/60220dd33b5b0f6b5c72927c933dbc32a3c4734e/", - "$std/": "https://deno.land/std@0.208.0/", "@/": "./", "@deno/gfm": "jsr:@deno/gfm@^0.9.0", "@preact/signals": "https://esm.sh/*@preact/signals@1.2.1", "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.0", + "@std/assert": "jsr:@std/assert@^1.0.4", + "@std/datetime": "jsr:@std/datetime@^0.225.2", + "@std/front-matter": "jsr:@std/front-matter@^1.0.4", + "@std/fs": "jsr:@std/fs@^1.0.3", + "@std/http": "jsr:@std/http@^1.0.5", + "@std/path": "jsr:@std/path@^1.0.4", + "@std/testing": "jsr:@std/testing@^1.0.2", + "@std/ulid": "jsr:@std/ulid@^1.0.0", + "@std/url": "jsr:@std/url@^0.225.1", "fresh_charts/": "https://deno.land/x/fresh_charts@0.3.1/", "kv_oauth/": "https://deno.land/x/deno_kv_oauth@v0.9.1/", "preact": "https://esm.sh/preact@10.19.2", diff --git a/e2e_test.ts b/e2e_test.ts index 7ac8022f0..8d975d689 100644 --- a/e2e_test.ts +++ b/e2e_test.ts @@ -1,4 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. +/// import { createHandler } from "$fresh/server.ts"; import manifest from "@/fresh.gen.ts"; @@ -23,9 +24,9 @@ import { assertNotEquals, assertObjectMatch, assertStringIncludes, -} from "$std/assert/mod.ts"; -import { isRedirectStatus, STATUS_CODE } from "$std/http/status.ts"; -import { resolvesNext, returnsNext, stub } from "$std/testing/mock.ts"; +} from "@std/assert"; +import { isRedirectStatus, STATUS_CODE } from "@std/http"; +import { resolvesNext, returnsNext, stub } from "@std/testing/mock"; import Stripe from "stripe"; import options from "./fresh.config.ts"; import { _internals } from "./plugins/kv_oauth.ts"; diff --git a/islands/ItemsList.tsx b/islands/ItemsList.tsx index f5e3dbca8..db2bdcffe 100644 --- a/islands/ItemsList.tsx +++ b/islands/ItemsList.tsx @@ -4,7 +4,7 @@ import { useEffect } from "preact/hooks"; import { type Item } from "@/utils/db.ts"; import IconInfo from "tabler_icons_tsx/info-circle.tsx"; import { fetchValues } from "@/utils/http.ts"; -import { decodeTime } from "$std/ulid/mod.ts"; +import { decodeTime } from "@std/ulid"; import { timeAgo } from "@/utils/display.ts"; import GitHubAvatarImg from "@/components/GitHubAvatarImg.tsx"; diff --git a/plugins/blog/mod.ts b/plugins/blog/mod.ts index c2f27cb66..d94a444e0 100644 --- a/plugins/blog/mod.ts +++ b/plugins/blog/mod.ts @@ -3,7 +3,7 @@ import type { Plugin } from "$fresh/server.ts"; import BlogIndex from "./routes/blog/index.tsx"; import BlogSlug from "./routes/blog/[slug].tsx"; import Feed from "./routes/feed.ts"; -import { normalize } from "$std/url/normalize.ts"; +import { normalize } from "@std/url"; export function blog(): Plugin { return { diff --git a/plugins/blog/utils/posts.ts b/plugins/blog/utils/posts.ts index 002116488..472a0f90b 100644 --- a/plugins/blog/utils/posts.ts +++ b/plugins/blog/utils/posts.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { extract } from "$std/front_matter/yaml.ts"; -import { join } from "$std/path/join.ts"; +import { extractYaml } from "@std/front-matter"; +import { join } from "@std/path"; /** * This code is based on the @@ -38,7 +38,7 @@ export interface Post { export async function getPost(slug: string): Promise { try { const text = await Deno.readTextFile(join("./posts", `${slug}.md`)); - const { attrs, body } = extract(text); + const { attrs, body } = extractYaml(text); return { ...attrs, slug, diff --git a/plugins/blog/utils/posts_test.ts b/plugins/blog/utils/posts_test.ts index 6d207ee5e..6a018ddb3 100644 --- a/plugins/blog/utils/posts_test.ts +++ b/plugins/blog/utils/posts_test.ts @@ -1,7 +1,7 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import { getPost, getPosts } from "./posts.ts"; -import { assert, assertEquals } from "$std/assert/mod.ts"; +import { assert, assertEquals } from "@std/assert"; Deno.test("[blog] getPost()", async () => { const post = await getPost("first-post"); diff --git a/plugins/error_handling.ts b/plugins/error_handling.ts index 29e3cd36d..880963265 100644 --- a/plugins/error_handling.ts +++ b/plugins/error_handling.ts @@ -2,7 +2,7 @@ import type { Plugin } from "$fresh/server.ts"; import type { State } from "@/plugins/session.ts"; import { BadRequestError, redirect, UnauthorizedError } from "@/utils/http.ts"; -import { STATUS_CODE, STATUS_TEXT } from "$std/http/status.ts"; +import { STATUS_CODE, STATUS_TEXT } from "@std/http"; /** * Returns the HTTP status code corresponding to a given runtime error. By diff --git a/routes/api/stripe-webhooks.ts b/routes/api/stripe-webhooks.ts index e599ae42a..00295941b 100644 --- a/routes/api/stripe-webhooks.ts +++ b/routes/api/stripe-webhooks.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import { type Handlers } from "$fresh/server.ts"; -import { STATUS_CODE } from "$std/http/status.ts"; +import { STATUS_CODE } from "@std/http"; import { isStripeEnabled, stripe } from "@/utils/stripe.ts"; import Stripe from "stripe"; import { getUserByStripeCustomer, updateUser } from "@/utils/db.ts"; diff --git a/routes/api/vote.ts b/routes/api/vote.ts index 698a016f1..4cd7b7efa 100644 --- a/routes/api/vote.ts +++ b/routes/api/vote.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import { type Handlers } from "$fresh/server.ts"; -import { STATUS_CODE } from "$std/http/status.ts"; +import { STATUS_CODE } from "@std/http"; import type { SignedInState } from "@/plugins/session.ts"; import { createVote } from "@/utils/db.ts"; import { BadRequestError } from "@/utils/http.ts"; diff --git a/routes/submit.tsx b/routes/submit.tsx index 83722afd2..70d9d985c 100644 --- a/routes/submit.tsx +++ b/routes/submit.tsx @@ -10,7 +10,7 @@ import { type SignedInState, State, } from "@/plugins/session.ts"; -import { ulid } from "$std/ulid/mod.ts"; +import { ulid } from "@std/ulid"; import IconInfo from "tabler_icons_tsx/info-circle.tsx"; const SUBMIT_STYLES = diff --git a/tasks/check_license.ts b/tasks/check_license.ts index 5eb26b023..63b4819a6 100644 --- a/tasks/check_license.ts +++ b/tasks/check_license.ts @@ -1,8 +1,8 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. // Copied from std/_tools/check_license.ts -import { walk } from "$std/fs/walk.ts"; -import { globToRegExp } from "$std/path/glob_to_regexp.ts"; +import { walk } from "@std/fs"; +import { globToRegExp } from "@std/path"; const EXTENSIONS = [".ts", ".tsx"]; const EXCLUDED_DIRS = [ diff --git a/tasks/db_seed.ts b/tasks/db_seed.ts index 95395c51c..90a581eab 100644 --- a/tasks/db_seed.ts +++ b/tasks/db_seed.ts @@ -1,7 +1,7 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. // Description: Seeds the kv db with Hacker News stories import { createItem, createUser } from "@/utils/db.ts"; -import { ulid } from "$std/ulid/mod.ts"; +import { ulid } from "@std/ulid"; // Reference: https://github.com/HackerNews/API const API_BASE_URL = `https://hacker-news.firebaseio.com/v0`; diff --git a/utils/db.ts b/utils/db.ts index 444d40c7e..93e9ec97f 100644 --- a/utils/db.ts +++ b/utils/db.ts @@ -1,5 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { ulid } from "$std/ulid/mod.ts"; +import { ulid } from "@std/ulid"; const DENO_KV_PATH_KEY = "DENO_KV_PATH"; let path = undefined; @@ -59,7 +59,7 @@ export function randomItem(): Item { * @example * ```ts * import { createItem } from "@/utils/db.ts"; - * import { ulid } from "$std/ulid/mod.ts"; + * import { ulid } from "@std/ulid"; * * await createItem({ * id: ulid(), diff --git a/utils/db_test.ts b/utils/db_test.ts index 7de65ef08..466ed905f 100644 --- a/utils/db_test.ts +++ b/utils/db_test.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "$std/assert/mod.ts"; -import { ulid } from "$std/ulid/mod.ts"; +import { assertEquals, assertRejects } from "@std/assert"; +import { ulid } from "@std/ulid"; import { collectValues, createItem, diff --git a/utils/display.ts b/utils/display.ts index 6139d481a..bc0060804 100644 --- a/utils/display.ts +++ b/utils/display.ts @@ -1,5 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { difference } from "$std/datetime/difference.ts"; +import { difference } from "@std/datetime"; /** * Returns a pluralized string for the given amount and unit. @@ -22,7 +22,7 @@ export function pluralize(amount: number, unit: string) { * @example * ```ts * import { timeAgo } from "@/utils/display.ts"; - * import { SECOND, MINUTE, HOUR } from "$std/datetime/constants.ts"; + * import { SECOND, MINUTE, HOUR } from "@std/datetime"; * * timeAgo(new Date()); // Returns "just now" * timeAgo(new Date(Date.now() - 3 * HOUR)); // Returns "3 hours ago" diff --git a/utils/display_test.ts b/utils/display_test.ts index 7d7842090..455cf1831 100644 --- a/utils/display_test.ts +++ b/utils/display_test.ts @@ -1,7 +1,7 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import { formatCurrency, pluralize, timeAgo } from "./display.ts"; -import { DAY, HOUR, MINUTE, SECOND } from "$std/datetime/constants.ts"; -import { assertEquals, assertThrows } from "$std/assert/mod.ts"; +import { DAY, HOUR, MINUTE, SECOND } from "@std/datetime"; +import { assertEquals, assertThrows } from "@std/assert"; Deno.test("[display] pluralize()", () => { assertEquals(pluralize(0, "item"), "0 items"); diff --git a/utils/github_test.ts b/utils/github_test.ts index 07784cc93..6c82fc1d1 100644 --- a/utils/github_test.ts +++ b/utils/github_test.ts @@ -1,9 +1,9 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { assertRejects } from "$std/assert/assert_rejects.ts"; +import { assertRejects } from "@std/assert"; import { getGitHubUser } from "./github.ts"; -import { returnsNext, stub } from "$std/testing/mock.ts"; -import { assertEquals } from "$std/assert/assert_equals.ts"; -import { STATUS_CODE } from "$std/http/status.ts"; +import { returnsNext, stub } from "@std/testing/mock"; +import { assertEquals } from "@std/assert"; +import { STATUS_CODE } from "@std/http"; import { BadRequestError } from "@/utils/http.ts"; Deno.test("[plugins] getGitHubUser()", async (test) => { diff --git a/utils/http.ts b/utils/http.ts index 084fb5aad..61b333752 100644 --- a/utils/http.ts +++ b/utils/http.ts @@ -1,5 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { RedirectStatus, STATUS_CODE } from "$std/http/status.ts"; +import { RedirectStatus, STATUS_CODE } from "@std/http"; /** * Returns a response that redirects the client to the given location (URL). diff --git a/utils/http_test.ts b/utils/http_test.ts index 621f64516..406e76c99 100644 --- a/utils/http_test.ts +++ b/utils/http_test.ts @@ -1,8 +1,8 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { returnsNext, stub } from "$std/testing/mock.ts"; +import { returnsNext, stub } from "@std/testing/mock"; import { fetchValues, getCursor, redirect } from "./http.ts"; -import { assert, assertEquals, assertRejects } from "$std/assert/mod.ts"; -import { STATUS_CODE } from "$std/http/status.ts"; +import { assert, assertEquals, assertRejects } from "@std/assert"; +import { STATUS_CODE } from "@std/http"; import { Item, randomItem } from "@/utils/db.ts"; Deno.test("[http] redirect() defaults", () => { diff --git a/utils/stripe.ts b/utils/stripe.ts index f63033eeb..71fba3941 100644 --- a/utils/stripe.ts +++ b/utils/stripe.ts @@ -1,6 +1,6 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. import Stripe from "stripe"; -import { AssertionError } from "$std/assert/assertion_error.ts"; +import { AssertionError } from "@std/assert"; const STRIPE_SECRET_KEY = Deno.env.get("STRIPE_SECRET_KEY"); diff --git a/utils/stripe_test.ts b/utils/stripe_test.ts index 22174b59f..4920cce29 100644 --- a/utils/stripe_test.ts +++ b/utils/stripe_test.ts @@ -1,5 +1,5 @@ // Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. -import { AssertionError, assertThrows } from "$std/assert/mod.ts"; +import { AssertionError, assertThrows } from "@std/assert"; import { assertIsPrice } from "./stripe.ts"; Deno.test("[stripe] assertIsPrice()", () => {