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

use jsr modules where possible and upgrade fresh version #684

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
27 changes: 17 additions & 10 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,28 @@
},
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" },
"imports": {
"@/": "./",
"$fresh/": "https://raw.githubusercontent.com/denoland/fresh/60220dd33b5b0f6b5c72927c933dbc32a3c4734e/",
"preact": "https://esm.sh/preact@10.19.2",
"preact/": "https://esm.sh/preact@10.19.2/",
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.2",
"@/": "./",
"@deno/gfm": "jsr:@deno/gfm@^0.9",
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.1",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.0",
"tailwindcss": "npm:tailwindcss@3.4.1",
"tailwindcss/": "npm:/tailwindcss@3.4.1/",
"tailwindcss/plugin": "npm:/tailwindcss@3.4.1/plugin.js",
"$std/": "https://deno.land/std@0.208.0/",
"stripe": "npm:/stripe@13.5.0",
"@std/assert": "jsr:@std/assert@^1.0",
"@std/datetime": "jsr:@std/datetime@^0.225",
"@std/front-matter": "jsr:@std/front-matter@^1.0",
"@std/fs": "jsr:@std/fs@^1.0",
"@std/http": "jsr:@std/http@^1.0",
"@std/path": "jsr:@std/path@^1.0",
"@std/testing": "jsr:@std/testing@^1.0",
"@std/ulid": "jsr:@std/ulid@^1.0",
"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",
"preact/": "https://esm.sh/preact@10.19.2/",
"stripe": "npm:/stripe@13.5.0",
"tabler_icons_tsx/": "https://deno.land/x/tabler_icons_tsx@0.0.4/tsx/",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also a note on this, we can switch this to:

"@tabler/icons-preact": "npm:@tabler/icons-preact@^3.14.0",

The module we are using is deprecated: https://github.com/hashrock/tabler-icons-tsx?tab=readme-ov-file#deprecated

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to do this in this PR or a seperate one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do that in a separate PR 🙂

"fresh_charts/": "https://deno.land/x/fresh_charts@0.3.1/"
"tailwindcss": "npm:tailwindcss@3.4.1",
"tailwindcss/": "npm:/tailwindcss@3.4.1/",
"tailwindcss/plugin": "npm:/tailwindcss@3.4.1/plugin.js"
},
"exclude": ["coverage/", "_fresh/", "**/_fresh/*"],
"lint": { "rules": { "tags": ["fresh", "recommended"] } }
Expand Down
20 changes: 9 additions & 11 deletions e2e_test.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify my previous statement, importing from root modules (i.e. @std/assert) for test code is fine. It's usually production code that we want to keep trim. It's no big deal, either way.

Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ import {
User,
} from "@/utils/db.ts";
import { stripe } from "@/utils/stripe.ts";
import {
assert,
assertArrayIncludes,
assertEquals,
assertInstanceOf,
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";
import { assert } from "@std/assert/assert";
import { assertArrayIncludes } from "@std/assert/array-includes";
import { assertEquals } from "@std/assert/equals";
import { assertInstanceOf } from "@std/assert/instance-of";
import { assertNotEquals } from "@std/assert/not-equals";
import { assertObjectMatch } from "@std/assert/object-match";
import { assertStringIncludes } from "@std/assert/string-includes";
import { isRedirectStatus, STATUS_CODE } from "@std/http/status";
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/decode-time";
import { timeAgo } from "@/utils/display.ts";
import GitHubAvatarImg from "@/components/GitHubAvatarImg.tsx";

Expand Down
4 changes: 2 additions & 2 deletions 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/path/normalize";

export function blog(): Plugin {
return {
Expand All @@ -19,6 +19,6 @@ export function blog(): Plugin {
component: Feed,
}],
location: import.meta.url,
projectLocation: normalize(import.meta.url + "../../../").href,
projectLocation: normalize(import.meta.url + "../../../"),
};
}
2 changes: 1 addition & 1 deletion plugins/blog/routes/blog/[slug].tsx
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 { defineRoute } from "$fresh/server.ts";
import { CSS, render } from "https://deno.land/x/gfm@0.2.5/mod.ts";
import { CSS, render } from "@deno/gfm";
import { getPost } from "../../utils/posts.ts";
import Head from "@/components/Head.tsx";
import Share from "../../components/Share.tsx";
Expand Down
4 changes: 2 additions & 2 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 { extract } from "@std/front-matter/yaml";
import { join } from "@std/path/join";

/**
* This code is based on the
Expand Down
3 changes: 2 additions & 1 deletion plugins/blog/utils/posts_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// 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 } from "@std/assert/assert";
import { assertEquals } from "@std/assert/equals";

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/status";

/**
* 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/status";
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/status";
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/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/walk";
import { globToRegExp } from "@std/path/glob-to-regexp";

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/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/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/ulid";
*
* await createItem({
* id: ulid(),
Expand Down
5 changes: 3 additions & 2 deletions utils/db_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 } from "@std/assert/equals";
import { assertRejects } from "@std/assert/rejects";
import { ulid } from "@std/ulid/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/difference";

/**
* 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/contstants";
*
* timeAgo(new Date()); // Returns "just now"
* timeAgo(new Date(Date.now() - 3 * HOUR)); // Returns "3 hours ago"
Expand Down
5 changes: 3 additions & 2 deletions utils/display_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// 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/constants";
import { assertEquals } from "@std/assert/equals";
import { assertThrows } from "@std/assert/throws";

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/rejects";
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/equals";
import { STATUS_CODE } from "@std/http/status";
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/status";

/**
* Returns a response that redirects the client to the given location (URL).
Expand Down
8 changes: 5 additions & 3 deletions utils/http_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// 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 } from "@std/assert/assert";
import { assertEquals } from "@std/assert/equals";
import { assertRejects } from "@std/assert/rejects";
import { STATUS_CODE } from "@std/http/status";
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/assertion-error";

const STRIPE_SECRET_KEY = Deno.env.get("STRIPE_SECRET_KEY");

Expand Down
3 changes: 2 additions & 1 deletion utils/stripe_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2023-2024 the Deno authors. All rights reserved. MIT license.
import { AssertionError, assertThrows } from "$std/assert/mod.ts";
import { AssertionError } from "@std/assert/assertion-error";
import { assertThrows } from "@std/assert/throws";
import { assertIsPrice } from "./stripe.ts";

Deno.test("[stripe] assertIsPrice()", () => {
Expand Down
Loading