Compare commits
No commits in common. "jsr-prep" and "main" have entirely different histories.
@ -3,9 +3,7 @@
|
|||||||
## Supports import maps and runs on Deno Deploy
|
## 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
|
### Manual Bundle API
|
||||||
|
|
||||||
#### API
|
|
||||||
```typescript
|
```typescript
|
||||||
import Bundle from "./mod.ts";
|
import Bundle from "./mod.ts";
|
||||||
Bundle(
|
Bundle(
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
"exports": "./mod.ts",
|
"exports": "./mod.ts",
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"serve": "deno run -A --no-lock serve.tsx --path=./test --html=index.html",
|
"serve": "deno run -A --no-lock serve.tsx --path=./test --html=index.html",
|
||||||
"test": "deno test -A"
|
"jsapi": "deno run -A --no-lock jsapi.tsx"
|
||||||
}
|
}
|
||||||
}
|
}
|
66
deno.lock
66
deno.lock
@ -1,66 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "3",
|
|
||||||
"packages": {
|
|
||||||
"specifiers": {
|
|
||||||
"jsr:@std/json@^1.0.0-rc.1": "jsr:@std/json@1.0.0-rc.2",
|
|
||||||
"jsr:@std/jsonc": "jsr:@std/jsonc@0.224.3",
|
|
||||||
"npm:@types/node": "npm:@types/node@18.16.19"
|
|
||||||
},
|
|
||||||
"jsr": {
|
|
||||||
"@std/json@1.0.0-rc.2": {
|
|
||||||
"integrity": "f48870c4471e5ff3157ca4c51bf9a71351c2bac2ba2e1615321254b4d081e84a"
|
|
||||||
},
|
|
||||||
"@std/jsonc@0.224.3": {
|
|
||||||
"integrity": "c10770a31489f5b85a3562d9b107c497666d8b6a49291ee2711d84da2616c2d6",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@std/json@^1.0.0-rc.1"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"npm": {
|
|
||||||
"@types/node@18.16.19": {
|
|
||||||
"integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==",
|
|
||||||
"dependencies": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"remote": {
|
|
||||||
"https://deno.land/std@0.224.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert.ts": "09d30564c09de846855b7b071e62b5974b001bb72a4b797958fe0660e7849834",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_almost_equals.ts": "9e416114322012c9a21fa68e187637ce2d7df25bcbdbfd957cd639e65d3cf293",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_array_includes.ts": "14c5094471bc8e4a7895fc6aa5a184300d8a1879606574cb1cd715ef36a4a3c7",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_equals.ts": "3bbca947d85b9d374a108687b1a8ba3785a7850436b5a8930d81f34a32cb8c74",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_exists.ts": "43420cf7f956748ae6ed1230646567b3593cb7a36c5a5327269279c870c5ddfd",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_false.ts": "3e9be8e33275db00d952e9acb0cd29481a44fa0a4af6d37239ff58d79e8edeff",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_greater.ts": "5e57b201fd51b64ced36c828e3dfd773412c1a6120c1a5a99066c9b261974e46",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_greater_or_equal.ts": "9870030f997a08361b6f63400273c2fb1856f5db86c0c3852aab2a002e425c5b",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_instance_of.ts": "e22343c1fdcacfaea8f37784ad782683ec1cf599ae9b1b618954e9c22f376f2c",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_is_error.ts": "f856b3bc978a7aa6a601f3fec6603491ab6255118afa6baa84b04426dd3cc491",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_less.ts": "60b61e13a1982865a72726a5fa86c24fad7eb27c3c08b13883fb68882b307f68",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_less_or_equal.ts": "d2c84e17faba4afe085e6c9123a63395accf4f9e00150db899c46e67420e0ec3",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_match.ts": "ace1710dd3b2811c391946954234b5da910c5665aed817943d086d4d4871a8b7",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_not_equals.ts": "78d45dd46133d76ce624b2c6c09392f6110f0df9b73f911d20208a68dee2ef29",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_not_instance_of.ts": "3434a669b4d20cdcc5359779301a0588f941ffdc2ad68803c31eabdb4890cf7a",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_not_match.ts": "df30417240aa2d35b1ea44df7e541991348a063d9ee823430e0b58079a72242a",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_not_strict_equals.ts": "37f73880bd672709373d6dc2c5f148691119bed161f3020fff3548a0496f71b8",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_object_match.ts": "411450fd194fdaabc0089ae68f916b545a49d7b7e6d0026e84a54c9e7eed2693",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_rejects.ts": "4bee1d6d565a5b623146a14668da8f9eb1f026a4f338bbf92b37e43e0aa53c31",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_strict_equals.ts": "b4f45f0fd2e54d9029171876bd0b42dd9ed0efd8f853ab92a3f50127acfa54f5",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_string_includes.ts": "496b9ecad84deab72c8718735373feb6cdaa071eb91a98206f6f3cb4285e71b8",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assert_throws.ts": "c6508b2879d465898dab2798009299867e67c570d7d34c90a2d235e4553906eb",
|
|
||||||
"https://deno.land/std@0.224.0/assert/assertion_error.ts": "ba8752bd27ebc51f723702fac2f54d3e94447598f54264a6653d6413738a8917",
|
|
||||||
"https://deno.land/std@0.224.0/assert/equal.ts": "bddf07bb5fc718e10bb72d5dc2c36c1ce5a8bdd3b647069b6319e07af181ac47",
|
|
||||||
"https://deno.land/std@0.224.0/assert/fail.ts": "0eba674ffb47dff083f02ced76d5130460bff1a9a68c6514ebe0cdea4abadb68",
|
|
||||||
"https://deno.land/std@0.224.0/assert/mod.ts": "48b8cb8a619ea0b7958ad7ee9376500fe902284bb36f0e32c598c3dc34cbd6f3",
|
|
||||||
"https://deno.land/std@0.224.0/assert/unimplemented.ts": "8c55a5793e9147b4f1ef68cd66496b7d5ba7a9e7ca30c6da070c1a58da723d73",
|
|
||||||
"https://deno.land/std@0.224.0/assert/unreachable.ts": "5ae3dbf63ef988615b93eb08d395dda771c96546565f9e521ed86f6510c29e19",
|
|
||||||
"https://deno.land/std@0.224.0/fmt/colors.ts": "508563c0659dd7198ba4bbf87e97f654af3c34eb56ba790260f252ad8012e1c5",
|
|
||||||
"https://deno.land/std@0.224.0/internal/diff.ts": "6234a4b493ebe65dc67a18a0eb97ef683626a1166a1906232ce186ae9f65f4e6",
|
|
||||||
"https://deno.land/std@0.224.0/internal/format.ts": "0a98ee226fd3d43450245b1844b47003419d34d210fa989900861c79820d21c2",
|
|
||||||
"https://deno.land/std@0.224.0/internal/mod.ts": "534125398c8e7426183e12dc255bb635d94e06d0f93c60a297723abe69d3b22e",
|
|
||||||
"https://deno.land/x/esbuild@v0.19.2/wasm.js": "5ffeb3d973e57351eb4d2d03ffafc8ce5672e946d0f0a786c4aed2ca29cec004",
|
|
||||||
"https://esm.sh/esbuild-plugin-importmaps@1.0.0": "ab9e79660ff4d57d2ed7ef5e8516fbe0e79305267f22e1e7270d0a17ae0c2029",
|
|
||||||
"https://esm.sh/v135/@jspm/import-map@1.0.8/denonext/import-map.mjs": "fc291e729df6bef849df47df8893b64749785ca65fd5fe1d0e7969db5d3b63ea",
|
|
||||||
"https://esm.sh/v135/esbuild-plugin-importmaps@1.0.0/denonext/esbuild-plugin-importmaps.mjs": "08b603d074dd2861345f7d224c255c46d7f7213a283026552c492f465fe595ce"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
import { parse as JSONC } from "jsr:@std/jsonc";
|
import { parse as JSONC } from "https://deno.land/x/jsonct@v0.1.0/mod.ts";
|
||||||
|
|
||||||
type JsonLike = { [key: string]: string | string[] | JsonLike; };
|
type JsonLike = { [key: string]: string | string[] | JsonLike; };
|
||||||
|
|
||||||
@ -16,51 +16,65 @@ export default async function HuntConfig(directory=Root):Promise<{
|
|||||||
const path = new URL(inPath, directory);
|
const path = new URL(inPath, directory);
|
||||||
console.log("looking at", path.href);
|
console.log("looking at", path.href);
|
||||||
const resp = await fetch(path);
|
const resp = await fetch(path);
|
||||||
if(inPath.endsWith(".jsonc"))
|
if(inPath.endsWith("./.jsonc"))
|
||||||
{
|
{
|
||||||
const text = await resp.text();
|
const text = await resp.text();
|
||||||
json = JSONC(text) as JsonLike;
|
json = JSONC(text) as JsonLike;
|
||||||
} else {
|
}
|
||||||
json = await resp.json() as JsonLike
|
else
|
||||||
|
{
|
||||||
|
json = await resp.json();
|
||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
} catch (e) {
|
|
||||||
console.error(`Error loading JSON from ${inPath}:`, e.message);
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
};
|
catch(_e)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try// look for `deno.json`
|
||||||
|
{
|
||||||
json = await loadJSON("./deno.json");
|
json = await loadJSON("./deno.json");
|
||||||
} catch (_e) {
|
|
||||||
try {
|
|
||||||
json = await loadJSON("./deno.jsonc");
|
|
||||||
} catch (_e) {
|
|
||||||
try {
|
|
||||||
json = await loadJSON("./.vscode/settings.json");
|
|
||||||
path = json?.["deno.config"] as string || "";
|
|
||||||
json = undefined;
|
|
||||||
if (path) {
|
|
||||||
json = await loadJSON(path);
|
|
||||||
}
|
}
|
||||||
} catch (_e) {
|
catch(_e)
|
||||||
console.warn("Cannot find a config in .vscode/ ");
|
{
|
||||||
|
|
||||||
|
try // look for `deno.jsonc`
|
||||||
|
{
|
||||||
|
json = await loadJSON("./deno.jsonc");
|
||||||
|
}
|
||||||
|
catch(_e)
|
||||||
|
{
|
||||||
|
try // look in the vscode plugin settings
|
||||||
|
{
|
||||||
|
json = await loadJSON("./.vscode/settings.json")
|
||||||
|
path = json ? json["deno.config"] as string : "";
|
||||||
|
json = undefined;
|
||||||
|
if(path)
|
||||||
|
{
|
||||||
|
json = await loadJSON(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(_e)
|
||||||
|
{
|
||||||
|
// cant find a config using the vscode plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!json) {
|
if(!json)
|
||||||
|
{
|
||||||
json = {};
|
json = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
path = json.importMap as string || "";
|
|
||||||
if (!json.imports && path) {
|
path = json.importMap as string;
|
||||||
|
if(!json.imports && path)
|
||||||
|
{
|
||||||
json.imports = await loadJSON(path) as JsonLike;
|
json.imports = await loadJSON(path) as JsonLike;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the return type always includes imports and compilerOptions
|
return json as {imports:JsonLike, compilerOptions:JsonLike};
|
||||||
return {
|
|
||||||
imports: json.imports || {},
|
|
||||||
compilerOptions: json.compilerOptions || {}
|
|
||||||
} as { imports: JsonLike, compilerOptions: JsonLike };
|
|
||||||
}
|
}
|
24
mod.ts
24
mod.ts
@ -2,18 +2,10 @@ import * as ESBuild from "https://deno.land/x/esbuild@v0.19.2/wasm.js";
|
|||||||
import * as Mapper from "https://esm.sh/esbuild-plugin-importmaps@1.0.0"; // https://github.com/andstellar/esbuild-plugin-importmaps
|
import * as Mapper from "https://esm.sh/esbuild-plugin-importmaps@1.0.0"; // https://github.com/andstellar/esbuild-plugin-importmaps
|
||||||
import Introspect from "./introspect.ts";
|
import Introspect from "./introspect.ts";
|
||||||
|
|
||||||
|
const prefix = "/_dot_importer_/";
|
||||||
const resolvePlugin =(fullPathDir:string):ESBuild.Plugin=>({
|
const resolvePlugin =(fullPathDir:string):ESBuild.Plugin=>({
|
||||||
name: "resolve-plugin",
|
name: "resolve-plugin",
|
||||||
setup(build) {
|
setup(build) {
|
||||||
const namespace = "http";
|
|
||||||
const prefix = "/_dot_importer_/";
|
|
||||||
build.onResolve({ filter: /^npm:/ }, (args) =>
|
|
||||||
{
|
|
||||||
const moduleName = args.path.substring(4); // Remove the "npm:" prefix
|
|
||||||
const path = prefix+`https://esm.sh/${moduleName}`;
|
|
||||||
return {path,namespace} as ESBuild.OnResolveResult;
|
|
||||||
});
|
|
||||||
build.onResolve({ filter: /^(\.\/|\.\.\/).*/ }, (args)=>
|
build.onResolve({ filter: /^(\.\/|\.\.\/).*/ }, (args)=>
|
||||||
{
|
{
|
||||||
let resolveRoot = args.importer||fullPathDir;
|
let resolveRoot = args.importer||fullPathDir;
|
||||||
@ -21,13 +13,15 @@ const resolvePlugin =(fullPathDir:string):ESBuild.Plugin=>({
|
|||||||
{
|
{
|
||||||
resolveRoot = resolveRoot.substring(prefix.length);
|
resolveRoot = resolveRoot.substring(prefix.length);
|
||||||
}
|
}
|
||||||
return {
|
const output:ESBuild.OnResolveResult = {
|
||||||
path:prefix + new URL(args.path, resolveRoot).href,
|
path:prefix + new URL(args.path, resolveRoot).href,
|
||||||
namespace,
|
namespace:"http",
|
||||||
} as ESBuild.OnResolveResult;
|
}
|
||||||
|
return output;
|
||||||
});
|
});
|
||||||
build.onLoad({ filter: /.*/, namespace }, async(args)=> {
|
build.onLoad({ filter: /.*/, namespace:"http" }, async(args)=> {
|
||||||
const fetchPath = args.path.substring(prefix.length);
|
const fetchPath = args.path.substring(prefix.length);
|
||||||
|
console.log("fetch path", fetchPath);
|
||||||
const result = await fetch(fetchPath);
|
const result = await fetch(fetchPath);
|
||||||
const contents = await result.text();
|
const contents = await result.text();
|
||||||
return { contents, loader: `tsx` };
|
return { contents, loader: `tsx` };
|
||||||
@ -40,8 +34,8 @@ export type ImportMap = Parameters<typeof Mapper.importmapPlugin>[0];
|
|||||||
export type BuildOptions = ESBuild.BuildOptions;
|
export type BuildOptions = ESBuild.BuildOptions;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param directory Full "file:///..." or "http(s)://..." url to the directory containing assets you want to build (needed to resolve relative imports)
|
* @param directory Full file:// or http(s):// path to the directory containing assets you want to build (needed to resolve relative imports)
|
||||||
* @param buildOptions ESBuild "build" options (will be merged with "reasonable defaults") official docs: https://esbuild.github.io/api/#general-options
|
* @param buildOptions ESBuild "build" options (will be merged with "reasonable defaults") for docs: https://esbuild.github.io/api/#general-options
|
||||||
* @param importMap An object to act as the import map ({imports:Record<string, string>}). If this is left blank, a configuration will be scanned for in the "directory"
|
* @param importMap An object to act as the import map ({imports:Record<string, string>}). If this is left blank, a configuration will be scanned for in the "directory"
|
||||||
* @returns build result
|
* @returns build result
|
||||||
*/
|
*/
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as mime from "jsr:@std/media-types";
|
import mime from "https://esm.sh/mime@4.0.3";
|
||||||
import { parseArgs } from "jsr:@std/cli/parse-args";
|
import { parseArgs } from "jsr:@std/cli/parse-args";
|
||||||
import bundler, {type ESBuild, type ImportMap} from "./mod.ts";
|
import bundler, {type ESBuild, type ImportMap} from "./mod.ts";
|
||||||
import Introspect from "./introspect.ts";
|
import Introspect from "./introspect.ts";
|
||||||
@ -24,7 +24,7 @@ async function serve(settings:ServeArgs):Promise<void>
|
|||||||
let type:string|null = null
|
let type:string|null = null
|
||||||
if(extension)
|
if(extension)
|
||||||
{
|
{
|
||||||
type = (ExtensionsJS.includes(extension)) ? "application/javascript" : mime.contentType(extension);
|
type = (ExtensionsJS.includes(extension)) ? "application/javascript" : mime.getType(extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {path, extension, type};
|
return {path, extension, type};
|
||||||
@ -98,7 +98,6 @@ async function serve(settings:ServeArgs):Promise<void>
|
|||||||
///// go
|
///// go
|
||||||
Deno.serve({port:parseInt(settings.port as string)||8000}, async(req)=>
|
Deno.serve({port:parseInt(settings.port as string)||8000}, async(req)=>
|
||||||
{
|
{
|
||||||
console.log("new request", req.url)
|
|
||||||
const checkHash = req.headers.get("if-none-match")
|
const checkHash = req.headers.get("if-none-match")
|
||||||
if(checkHash === ETag){
|
if(checkHash === ETag){
|
||||||
return resp304;
|
return resp304;
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "3",
|
|
||||||
"packages": {
|
|
||||||
"specifiers": {
|
|
||||||
"npm:preact@10.22.0": "npm:preact@10.22.0"
|
|
||||||
},
|
|
||||||
"npm": {
|
|
||||||
"preact@10.22.0": {
|
|
||||||
"integrity": "sha512-RRurnSjJPj4rp5K6XoP45Ui33ncb7e4H7WiOHVpjbkvqvA3U+N8Z6Qbo0AE6leGYBV66n8EhEaFixvIu3SkxFw==",
|
|
||||||
"dependencies": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"remote": {
|
|
||||||
"https://esm.sh/preact@10.22.0/compat/jsx-runtime": "a2f6ddc2ce374813df1c13826a9ad010e90b5a70a989f1069a367ef60dd52eb0",
|
|
||||||
"https://esm.sh/stable/preact@10.22.0/denonext/compat.js": "7c0b206984707cfef58efae492ea8d5212b8f620dd8c83294a5c832fb422c766",
|
|
||||||
"https://esm.sh/stable/preact@10.22.0/denonext/compat/jsx-runtime.js": "fecfa3df69d580507801575175087de9a2a9fc23bb4900004a1f4cbd5b362634",
|
|
||||||
"https://esm.sh/stable/preact@10.22.0/denonext/hooks.js": "09230113132c216bbc3847aaad11289771e088be1b0eb9e49cbc724faaeac205",
|
|
||||||
"https://esm.sh/stable/preact@10.22.0/denonext/jsx-runtime.js": "de60943799b1cbe6066c4f83f4ca71ef37011d7f5be7bef58ed980e8ff3f996a",
|
|
||||||
"https://esm.sh/stable/preact@10.22.0/denonext/preact.mjs": "20c9563e051dd66e053d3afb450f61b48f2fa0d0ce4f69f8f0a2f23c1ef090da"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user