From 3aa0b3a7ff59f79229f694cd8dac06ac70a3569c Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Fri, 5 Jul 2024 08:54:39 -0400 Subject: [PATCH] cleanup --- README.md | 9 ++++++--- introspect.ts | 7 +++++-- jsapi.test.tsx | 11 +++++++++++ jsapi.tsx | 12 ------------ test/deno.json | 4 ++-- 5 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 jsapi.test.tsx delete mode 100644 jsapi.tsx diff --git a/README.md b/README.md index 286dfd7..3dabe8d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,19 @@ # ESBuild Typescript Bunder ## Supports import maps and runs on Deno Deploy -Uses the WASM version of ESBuild for use on Deno Deploy and adds some plugins to allow for import maps. Unfortunately, `npm:*` and `jsr:*` specifiers are not supported currently. +Uses the WASM version of ESBuild for use on Deno Deploy and adds some plugins to allow for import maps. ***Unfortunately, `npm:*` and `jsr:*` specifiers are not supported currently***. ### Manual Bundle API ```typescript import Bundle from "./mod.ts"; Bundle( - // ESBuild configuration: + // directory to work from + "./some_folder", + + // ESBuild configuration (entry points are relative to "directory"): {entry:["./app.tsx"]}, - // import map: + // import map (if omitted, will scan for a deno configuration within "directory" and use that) {"imports": { "react": "https://esm.sh/preact@10.22.0/compat", "react/": "https://esm.sh/preact@10.22.0/compat/" diff --git a/introspect.ts b/introspect.ts index f57f56a..b6c9033 100644 --- a/introspect.ts +++ b/introspect.ts @@ -3,8 +3,11 @@ import { parse as JSONC } from "https://deno.land/x/jsonct@v0.1.0/mod.ts"; type JsonLike = { [key: string]: string | string[] | JsonLike; }; /** A `file://` url version of Deno.cwd() (contains trailing slash) */ -export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString() + "/"; -export default async function HuntConfig(directory=Root) +export const Root:string = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString() + "/"; +export default async function HuntConfig(directory=Root):Promise<{ + imports: JsonLike; + compilerOptions: JsonLike; +}> { let path:string, json:JsonLike|undefined; console.log("searchig in directory", directory) diff --git a/jsapi.test.tsx b/jsapi.test.tsx new file mode 100644 index 0000000..c3b0571 --- /dev/null +++ b/jsapi.test.tsx @@ -0,0 +1,11 @@ +import * as Test from "https://deno.land/std@0.224.0/assert/mod.ts"; +import Bundle, {ESBuild} from "./mod.ts"; + + +const path = await import.meta.resolve("./test/"); +const {outputFiles} = await Bundle(path, {entryPoints:["./app.tsx"]}); + +Deno.test("check", ()=>{ + Test.assert(outputFiles?.length == 1); + Test.assert(outputFiles[0].text.length > 1000); +}) diff --git a/jsapi.tsx b/jsapi.tsx deleted file mode 100644 index c534a27..0000000 --- a/jsapi.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import Bundle from "./mod.ts"; -import Config from "./test/deno.json" with {type:"json"}; - -const path = import.meta.resolve("./test/"); -const {outputFiles} = await Bundle(path, {entryPoints:["./app.tsx"]}, Config); -if(outputFiles) -{ - for(const item of outputFiles) - { - console.log(item.text); - } -} diff --git a/test/deno.json b/test/deno.json index 56ee7b3..5368ab6 100644 --- a/test/deno.json +++ b/test/deno.json @@ -1,7 +1,7 @@ { "imports": { - "react": "npm:preact@10.22.0/compat", - "react/": "npm:preact@10.22.0/compat/" + "react": "https://esm.sh/preact@10.22.0/compat", + "react/": "https://esm.sh/preact@10.22.0/compat/" }, "compilerOptions": { "jsx": "react-jsx",