Compare commits
No commits in common. "0cc2d914e1ed879619de6d10a88e34f9fdef4190" and "023b9a647463096999bc46a47dcdc8c288cf9191" have entirely different histories.
0cc2d914e1
...
023b9a6474
@ -1,8 +1,13 @@
|
||||
import Bundler from "./mod.ts";
|
||||
import B from "./mod.ts";
|
||||
|
||||
const results = await Bundler();
|
||||
const results = await B({
|
||||
imports: {
|
||||
"react": "https://esm.sh/preact@10.22.0/compat",
|
||||
"react/": "https://esm.sh/preact@10.22.0/compat/"
|
||||
}
|
||||
});
|
||||
|
||||
for await(const file of results.outputFiles)
|
||||
{
|
||||
console.log(file.text);
|
||||
console.log(file.path);
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
import "../app.tsx";
|
||||
console.log("we deep!");
|
@ -6,16 +6,14 @@ type JsonLike = JsonDeep
|
||||
|
||||
type Configuration = {imports:JsonDeep, compilerOptions:JsonDeep};
|
||||
|
||||
|
||||
/** A `file://` url version of Deno.cwd() */
|
||||
export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString() + "/";
|
||||
export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString();
|
||||
export default async function HuntConfig()
|
||||
{
|
||||
let path:string, json:JsonLike|undefined;
|
||||
|
||||
const loadJSON =async(inPath:string)=>{
|
||||
try{
|
||||
const resp = await fetch(Root + inPath);
|
||||
const resp = await fetch(Root + "/" + inPath);
|
||||
if(inPath.endsWith(".jsonc"))
|
||||
{
|
||||
const text = await resp.text();
|
85
mod.ts
85
mod.ts
@ -1,64 +1,65 @@
|
||||
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 Introspect, {Root} from "./introspect.ts";
|
||||
|
||||
|
||||
const prefix = "/_dot_importer_/";
|
||||
export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString()+"/";
|
||||
console.log("running at", Root);
|
||||
const resolvePlugin:ESBuild.Plugin = {
|
||||
name: "resolve-plugin",
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^(\.\/|\.\.\/).*/ }, (args)=>
|
||||
{
|
||||
let resolveRoot = args.importer||Root;
|
||||
if(resolveRoot.startsWith(prefix))
|
||||
{
|
||||
resolveRoot = resolveRoot.substring(prefix.length);
|
||||
}
|
||||
const output:ESBuild.OnResolveResult = {
|
||||
path:prefix + new URL(args.path, resolveRoot).href,
|
||||
namespace:"http",
|
||||
}
|
||||
build.onResolve({ filter: /^\.\/.*$/ }, args => {
|
||||
console.log("RESOLVE")
|
||||
console.log("in:", args)
|
||||
const path = new URL(args.path, Root).pathname
|
||||
const output = {
|
||||
path,
|
||||
namespace: 'file',
|
||||
};
|
||||
console.log("out:", output)
|
||||
return output;
|
||||
});
|
||||
build.onLoad({ filter: /.*/, namespace:"http" }, async(args)=> {
|
||||
const fetchPath = args.path.substring(prefix.length);
|
||||
const result = await fetch(fetchPath);
|
||||
const contents = await result.text();
|
||||
return { contents, loader: `tsx` };
|
||||
|
||||
build.onLoad({ filter: /.*/, namespace:"file" }, async (args) => {
|
||||
console.log("LOAD")
|
||||
console.log(args)
|
||||
let contents;
|
||||
try
|
||||
{
|
||||
const result = await fetch("file://"+args.path);
|
||||
contents = await result.text();
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.log("deno fs access error:", e)
|
||||
}
|
||||
|
||||
return {
|
||||
contents,
|
||||
loader: args.path.endsWith('.tsx') ? 'tsx' : 'default',
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export type ImportMap = Parameters<typeof Mapper.importmapPlugin>[0];
|
||||
export type BuildOptions = ESBuild.BuildOptions;
|
||||
export default async function(buildOptions={} as BuildOptions, importMap:ImportMap|false = false)
|
||||
{
|
||||
if(importMap === false)
|
||||
{
|
||||
importMap = await Introspect() as ImportMap;
|
||||
}
|
||||
type ImportMap = Parameters<typeof Mapper.importmapPlugin>[0];
|
||||
|
||||
const configuration:ESBuild.BuildOptions = {
|
||||
//entryPoints: ["./app.tsx"],
|
||||
entryPoints: ["entry"],
|
||||
//entryPoints: ["./deep/deep.tsx"],
|
||||
//entryPoints: ["http://localhost:4507/deep/deep.tsx"],
|
||||
await ESBuild.initialize({ worker: false });
|
||||
const result = await ESBuild.build({
|
||||
entryPoints: ["./app.tsx"],
|
||||
bundle: true,
|
||||
minify: true,
|
||||
format: "esm",
|
||||
jsx: "automatic",
|
||||
jsxImportSource: "react",
|
||||
...buildOptions,
|
||||
plugins: [
|
||||
plugins:[
|
||||
resolvePlugin,
|
||||
Mapper.importmapPlugin(importMap) as ESBuild.Plugin,
|
||||
...buildOptions.plugins||[]
|
||||
Mapper.importmapPlugin({
|
||||
imports:{"react":"https://esm.sh/preact@10.22.0/compat"}
|
||||
}) as ESBuild.Plugin
|
||||
]
|
||||
};
|
||||
await ESBuild.initialize({ worker: false });
|
||||
const result = await ESBuild.build(configuration);
|
||||
});
|
||||
ESBuild.stop();
|
||||
return result;
|
||||
}
|
||||
|
||||
export { ESBuild };
|
||||
for(const item of result.outputFiles)
|
||||
{
|
||||
console.log(item.text)
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
//import React from "react";
|
||||
//console.log(React.createElement("div", {}, "hey"));
|
||||
import React from "react";
|
||||
console.log(React.createElement("div", {}, "hey"));
|
||||
export default "TEST STRING";
|
26
serve.tsx
26
serve.tsx
@ -1,4 +1,9 @@
|
||||
import bundler from "./mod.ts";
|
||||
import Introspect, {Root} from "./introspect.tsx";
|
||||
|
||||
const Config = await Introspect();
|
||||
|
||||
console.log(Config.imports);
|
||||
|
||||
const transpiled:Map<string, string> = new Map();
|
||||
|
||||
@ -8,31 +13,18 @@ Deno.serve(async(req)=>{
|
||||
if(index > -1)
|
||||
{
|
||||
const ext = url.pathname.substring(index+1, index+3);
|
||||
|
||||
console.log(ext);
|
||||
console.log(url.pathname);
|
||||
|
||||
if(ext === "ts")
|
||||
{
|
||||
const results = await bundler({
|
||||
entryPoints:["."+url.pathname],
|
||||
const results = await bundler({imports:Config.imports}, {
|
||||
entryPoints:[Root+url.pathname],
|
||||
outfile:"bundle.js",
|
||||
entryNames: `[dir][name]`,
|
||||
});
|
||||
results.outputFiles?.forEach(output=>{
|
||||
transpiled.set(output.path, output.text);
|
||||
})
|
||||
return new Response(`
|
||||
path: ${results.outputFiles[0].path}
|
||||
hash: ${results.outputFiles[0].hash}
|
||||
`, {headers:{"content-type":"application/javascript"}});
|
||||
return new Response(results.outputFiles[0].text, {headers:{"content-type":"application/javascript"}});
|
||||
}
|
||||
|
||||
if(ext == "js")
|
||||
{
|
||||
return new Response(transpiled.get(url.pathname)||"---", {headers:{"content-type":"application/javascript"}});
|
||||
}
|
||||
|
||||
}
|
||||
return new Response(url.pathname);
|
||||
return new Response(Root+url.pathname);
|
||||
});
|
Loading…
Reference in New Issue
Block a user