From 6a0a11024293721fb6cce65f0c2b2a5f679e7bde Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Fri, 28 Feb 2025 10:38:40 -0500 Subject: [PATCH] fixes still broken --- mod.ts | 55 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/mod.ts b/mod.ts index 8ad3c6f..81fea1a 100644 --- a/mod.ts +++ b/mod.ts @@ -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` }; + }); + + }, });