From a57988ada31b6d9adfd18f580bbfe9e5267b2059 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Fri, 28 Feb 2025 11:30:02 -0500 Subject: [PATCH] it works?? --- mod.ts | 74 ++++++++++++++----------------------------------- what/include.ts | 4 +-- 2 files changed, 23 insertions(+), 55 deletions(-) diff --git a/mod.ts b/mod.ts index 81fea1a..7efe48d 100644 --- a/mod.ts +++ b/mod.ts @@ -2,67 +2,35 @@ 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 prefix = "/_dot_importer_/"; const resolvePlugin =(fullPathDir:string):ESBuild.Plugin=>({ name: "resolve-plugin", setup(build) { - build.onResolve({ /*path relative*/ filter: /^(\.\/|\.\.\/).*/ }, (args)=> - { - let resolveRoot = args.importer||fullPathDir; - if(resolveRoot.startsWith(prefix)) - { - resolveRoot = resolveRoot.substring(prefix.length); - } + build.onResolve( {/* `/`, `./`, and `../` */ filter:/^(\/|\.\/|\.\.\/).*/}, args=>{ + const resolveRoot = args.importer||fullPathDir; const url = new URL(args.path, resolveRoot).href; - const output:ESBuild.OnResolveResult = { - path:prefix + url, - namespace:"local", - } - console.log(`LOCAL RESOLVE`, {args, resolveRoot, output}, "\n"); - return output; - }); - build.onLoad({ /*wildcard*/ filter: /.*/, namespace:"local" }, async(args)=> { - const fetchPath = args.path.substring(prefix.length); - - console.log(`LOCAL LOADING`, {args, fetchPath}, "\n"); - - const contents = await fetch(fetchPath).then(r=>r.text()); - - 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` }; - }); + const out = { path:url, namespace:"FULLPATH" }; + console.log(`SLASHPATH=>FULLPATH RESOLVE`, {args, out}, "\n"); + return out; + } ); + build.onResolve( {/* `file://`, `http://`, and `https://` */ filter:/^(file:\/\/|http:\/\/|https:\/\/).*/}, args=>{ + const out = { path:args.path, namespace:"FULLPATH" }; + console.log(`FULLPATH RESOLVE`, {args, out}, "\n"); + return out; + } ); + build.onLoad( + {/* `file://`, `http://`, and `https://` */ filter:/^(file:\/\/|http:\/\/|https:\/\/).*/}, + async(args)=> + { + const contents = await fetch(args.path).then(r=>r.text()); + const out = { contents, loader: `tsx` }; + console.log(`FULLPATH LOAD`, {args, out:{...out, contents:contents.substring(0, 100)}}, "\n"); + return out; + } ); }, }); @@ -94,7 +62,7 @@ export default async function(directory, buildOptions={}, importMap) ...buildOptions, plugins: [ resolvePlugin(directory), - //Mapper.importmapPlugin(importMap) as ESBuild.Plugin, + Mapper.importmapPlugin(importMap) as ESBuild.Plugin, ...buildOptions.plugins||[] ] }; diff --git a/what/include.ts b/what/include.ts index b0e3f76..79dff95 100644 --- a/what/include.ts +++ b/what/include.ts @@ -1,5 +1,5 @@ -import * as LO from "https://esm.sh/lodash@4.17.21"; +import * as React from "react"; -console.log(LO); +console.log(React); export default "HELLO"; \ No newline at end of file