fixes #1
74
mod.ts
74
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||[]
|
||||
]
|
||||
};
|
||||
|
@ -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";
|
Loading…
Reference in New Issue
Block a user