From 990cae20ed51dcef6901e85f88bc4393986b8434 Mon Sep 17 00:00:00 2001 From: Foster Hangdaan Date: Fri, 8 Nov 2024 05:16:35 -0500 Subject: [PATCH] fix: Error on HTTP import Fixes a relative import path error when importing the package via HTTP. All dependencies have been moved to `deps.ts`. --- deno.json | 8 -------- deno.lock | Bin 23873 -> 23695 bytes deps.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ mod.ts | 9 ++++----- tests/mod.test.ts | 19 +++++++++++-------- tests/utils.ts | 24 ++++++++++++++---------- 6 files changed, 72 insertions(+), 31 deletions(-) create mode 100644 deps.ts diff --git a/deno.json b/deno.json index 8611d4c..c90acde 100644 --- a/deno.json +++ b/deno.json @@ -4,13 +4,5 @@ "tasks": { "check": "deno fmt --check && deno lint && deno check .", "test": "deno test --allow-read=. --allow-write=./tests/site/_site,./tests/__snapshots__ --deny-env" - }, - "imports": { - "@/": "./", - "@std/assert": "jsr:@std/assert@1.0.7", - "@std/path": "jsr:@std/path@1.0.8", - "@std/testing": "jsr:@std/testing@1.0.4", - "@valibot/valibot": "jsr:@valibot/valibot@0.42.1", - "lume/": "https://deno.land/x/lume@v2.4.0/" } } diff --git a/deno.lock b/deno.lock index 1374c8a26b6ddd269e0e84b6aedbaa9cb6163afa..46d0b020948e5cc4a607b8103395cbd92a8f3d84 100644 GIT binary patch delta 13 UcmX@Oi?M$v=#N<>ZD}`#V$%6bc6FbBw?hu;%o|Sd-0amuj ccUgrduVa&$JcnJJ7pOr&Ar?s1a@BGH0GtIDpa1{> diff --git a/deps.ts b/deps.ts new file mode 100644 index 0000000..3860177 --- /dev/null +++ b/deps.ts @@ -0,0 +1,43 @@ +/* + * Copyright 2024 Foster Hangdaan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Lume +export { + default as LumeSite, + type SiteOptions as LumeSiteOptions, +} from "https://deno.land/x/lume@v2.4.0/core/site.ts"; +export { + default as lume, + type PluginOptions as LumePluginOptions, +} from "https://deno.land/x/lume@v2.4.0/mod.ts"; +export { + type DeepPartial as LumeDeepPartial, +} from "https://deno.land/x/lume@v2.4.0/core/utils/object.ts"; +export { + type Writer as LumeWriter, +} from "https://deno.land/x/lume@v2.4.0/core/writer.ts"; + +// STD Assert +export { assertExists, assertInstanceOf } from "jsr:@std/assert@1.0.7"; + +// STD Testing +export { assertSnapshot } from "jsr:@std/testing@1.0.4/snapshot"; + +// STD Path +export { fromFileUrl, join } from "jsr:@std/path@1.0.8"; + +// Valibot +export * as valibot from "jsr:@valibot/valibot@0.42.1"; diff --git a/mod.ts b/mod.ts index 14061aa..1683c75 100644 --- a/mod.ts +++ b/mod.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import * as v from "@valibot/valibot"; -import diagrams from "@/resources/diagrams.json" with { type: "json" }; -import type Site from "lume/core/site.ts"; +import diagrams from "./resources/diagrams.json" with { type: "json" }; +import { LumeSite, valibot as v } from "./deps.ts"; import { deflateSync } from "node:zlib"; const textEncoder = new TextEncoder(); @@ -67,10 +66,10 @@ const OptionsSchema = v.optional( export type Options = v.InferInput; -export default function (options?: Options): (site: Site) => void { +export default function (options?: Options): (site: LumeSite) => void { const opts = v.parse(OptionsSchema, options); - return (site: Site) => { + return (site: LumeSite) => { site.process([".html"], (pages) => { pages.forEach((page) => { diagrams.forEach((diagram) => { diff --git a/tests/mod.test.ts b/tests/mod.test.ts index 1590825..ed44014 100644 --- a/tests/mod.test.ts +++ b/tests/mod.test.ts @@ -14,11 +14,14 @@ * limitations under the License. */ -import mod from "@/mod.ts"; -import { ValiError } from "@valibot/valibot"; -import { assertExists, assertInstanceOf } from "@std/assert"; -import { assertSnapshot } from "@std/testing/snapshot"; -import { getSite } from "@/tests/utils.ts"; +import mod from "../mod.ts"; +import { getSite } from "./utils.ts"; +import { + assertExists, + assertInstanceOf, + assertSnapshot, + valibot, +} from "../deps.ts"; Deno.test("Error thrown on invalid options", async (t) => { await t.step("Invalid server", () => { @@ -29,7 +32,7 @@ Deno.test("Error thrown on invalid options", async (t) => { error = err; } assertExists(error); - assertInstanceOf(error, ValiError); + assertInstanceOf(error, valibot.ValiError); }); await t.step("Invalid enabledDiagrams", () => { @@ -40,7 +43,7 @@ Deno.test("Error thrown on invalid options", async (t) => { error = err; } assertExists(error); - assertInstanceOf(error, ValiError); + assertInstanceOf(error, valibot.ValiError); }); await t.step("Invalid format", () => { @@ -52,7 +55,7 @@ Deno.test("Error thrown on invalid options", async (t) => { error = err; } assertExists(error); - assertInstanceOf(error, ValiError); + assertInstanceOf(error, valibot.ValiError); }); }); diff --git a/tests/utils.ts b/tests/utils.ts index 9294659..f2f22ca 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -14,16 +14,20 @@ * limitations under the License. */ -import lume, { type PluginOptions } from "lume/mod.ts"; -import type Site from "lume/core/site.ts"; -import type { DeepPartial } from "lume/core/utils/object.ts"; -import type { SiteOptions } from "lume/core/site.ts"; -import type { Writer } from "lume/core/writer.ts"; -import { fromFileUrl, join } from "@std/path"; +import { + fromFileUrl, + join, + lume, + type LumeDeepPartial, + type LumePluginOptions, + LumeSite, + type LumeSiteOptions, + type LumeWriter, +} from "../deps.ts"; const cwd = fromFileUrl(import.meta.resolve("./")); -class TestWriter implements Writer { +class TestWriter implements LumeWriter { savePages() { return Promise.resolve([]); } @@ -42,9 +46,9 @@ class TestWriter implements Writer { } export function getSite( - siteOptions: DeepPartial = {}, - pluginOptions: PluginOptions = {}, -): Site { + siteOptions: LumeDeepPartial = {}, + pluginOptions: LumePluginOptions = {}, +): LumeSite { siteOptions.cwd = join(cwd, "site"); const site = lume(