fixes #1

Merged
SethTrowbridge merged 7 commits from fixes into master 2025-02-28 17:10:48 -05:00
Showing only changes of commit 6a0a110242 - Show all commits

55
mod.ts
View File

@ -2,35 +2,13 @@ import * as ESBuild from "https://deno.land/x/esbuild@v0.25.0/wasm.js";
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";
const REG = {
pathRel: RegExp("/^(\.\/|\.\.\/).*/"),
pathAbs: RegExp("^\/.*"),
pathHTTP: RegExp("/^https?:\/\//"),
wildcard: RegExp("/.*/")
};
const prefix = "/_dot_importer_/";
const resolvePlugin =(fullPathDir:string):ESBuild.Plugin=>({
name: "resolve-plugin",
setup(build) {
build.onResolve({ filter: REG.pathHTTP }, args => {
console.log(`LOCAL RESOLVE`, args);
return { path: args.path, namespace:"remote", pluginData:{origin:new URL(args.path).origin} };
});
build.onLoad({ filter: REG.wildcard, namespace:"remote" }, async(args)=> {
console.log(`REMOTE LOADING`, {args}, "\n");
const contents = await fetch(args.path).then(r=>r.text());
return { contents, loader: `tsx` };
});
build.onResolve({ filter: REG.pathRel }, (args)=>
build.onResolve({ /*path relative*/ filter: /^(\.\/|\.\.\/).*/ }, (args)=>
{
let resolveRoot = args.importer||fullPathDir;
if(resolveRoot.startsWith(prefix))
@ -46,7 +24,7 @@ const resolvePlugin =(fullPathDir:string):ESBuild.Plugin=>({
console.log(`LOCAL RESOLVE`, {args, resolveRoot, output}, "\n");
return output;
});
build.onLoad({ filter: REG.wildcard, namespace:"local" }, async(args)=> {
build.onLoad({ /*wildcard*/ filter: /.*/, namespace:"local" }, async(args)=> {
const fetchPath = args.path.substring(prefix.length);
@ -56,6 +34,35 @@ const resolvePlugin =(fullPathDir:string):ESBuild.Plugin=>({
return { contents, loader: `tsx` };
});
build.onResolve({/* path abs */ filter:/^\/.*/}, args=>{
console.log(`ABS RESOLVE`, {args}, "\n");
return {
path:args.path,
namespace:"ABS",
}
});
build.onLoad({/*wildcard*/ filter: /.*/, namespace:"ABS"}, async(args)=>{
console.log(`ABS LOADING`, {args}, "\n");
return { contents:"export default 'IDK';", loader: `tsx` };
});
build.onResolve({ /* path HTTP */ filter: /^https?:\/\// }, args => {
console.log(`REMOTE RESOLVE`, args);
return { path: args.path, namespace:"REMOTE", pluginData:{origin:new URL(args.path).origin} };
});
build.onLoad({ /*wildcard*/ filter: /.*/, namespace:"REMOTE" }, async(args)=> {
console.log(`REMOTE LOADING`, {args}, "\n");
const contents = await fetch(args.path).then(r=>r.text());
return { contents, loader: `tsx` };
});
},
});