Skip to content

Commit

Permalink
migrate to using jsr @std
Browse files Browse the repository at this point in the history
  • Loading branch information
ycmjason committed Sep 8, 2024
1 parent 035aa6d commit 4c68838
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 35 deletions.
10 changes: 9 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions e2e_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2023-2024 the Deno authors. All rights reserved. MIT license.
/// <reference lib="deno.unstable" />

import { createHandler } from "$fresh/server.ts";
import manifest from "@/fresh.gen.ts";
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion islands/ItemsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion plugins/blog/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions plugins/blog/utils/posts.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface Post {
export async function getPost(slug: string): Promise<Post | null> {
try {
const text = await Deno.readTextFile(join("./posts", `${slug}.md`));
const { attrs, body } = extract<Post>(text);
const { attrs, body } = extractYaml<Post>(text);
return {
...attrs,
slug,
Expand Down
2 changes: 1 addition & 1 deletion plugins/blog/utils/posts_test.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
2 changes: 1 addition & 1 deletion plugins/error_handling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion routes/api/stripe-webhooks.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion routes/api/vote.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion routes/submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions tasks/check_license.ts
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion tasks/db_seed.ts
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down
4 changes: 2 additions & 2 deletions utils/db.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions utils/db_test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions utils/display.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions utils/display_test.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
8 changes: 4 additions & 4 deletions utils/github_test.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion utils/http.ts
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
6 changes: 3 additions & 3 deletions utils/http_test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion utils/stripe.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
2 changes: 1 addition & 1 deletion utils/stripe_test.ts
Original file line number Diff line number Diff line change
@@ -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()", () => {
Expand Down

0 comments on commit 4c68838

Please sign in to comment.