Add support for processors over http
This commit is contained in:
parent
b5136c5d02
commit
3682a7a763
7 changed files with 52 additions and 12 deletions
|
@ -7,10 +7,7 @@
|
||||||
},
|
},
|
||||||
"files": {
|
"files": {
|
||||||
"ignoreUnknown": false,
|
"ignoreUnknown": false,
|
||||||
"ignore": [
|
"ignore": ["*.d.ts", "*.json"],
|
||||||
"*.d.ts",
|
|
||||||
"*.json"
|
|
||||||
],
|
|
||||||
"include": [
|
"include": [
|
||||||
"./src/**/*.ts",
|
"./src/**/*.ts",
|
||||||
"./src/**/*.tsx",
|
"./src/**/*.tsx",
|
||||||
|
|
1
bunfig.toml
Normal file
1
bunfig.toml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
preload = ["./src/preload/http-plugin.js"]
|
|
@ -1,6 +1,6 @@
|
||||||
import path, { dirname } from "node:path";
|
import path, { dirname } from "node:path";
|
||||||
import { Glob } from "bun";
|
import { Glob } from "bun";
|
||||||
import { MuseFileNotFoundError, MuseError } from "./errors";
|
import { MuseError, MuseFileNotFoundError } from "./errors";
|
||||||
import { parseMuseFile } from "./parse";
|
import { parseMuseFile } from "./parse";
|
||||||
import {
|
import {
|
||||||
type Binding,
|
type Binding,
|
||||||
|
@ -14,7 +14,9 @@ async function loadProcessor(
|
||||||
bindingDirname: string,
|
bindingDirname: string,
|
||||||
processorPath: string,
|
processorPath: string,
|
||||||
): Promise<MuseProcessor> {
|
): Promise<MuseProcessor> {
|
||||||
const resolvedProcessorPath = path.resolve(bindingDirname, processorPath);
|
const resolvedProcessorPath = processorPath.startsWith("http")
|
||||||
|
? processorPath
|
||||||
|
: path.resolve(bindingDirname, processorPath);
|
||||||
const { process, name, description } = await import(resolvedProcessorPath);
|
const { process, name, description } = await import(resolvedProcessorPath);
|
||||||
|
|
||||||
if (!process || typeof process !== "function") {
|
if (!process || typeof process !== "function") {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { parseArgs } from "node:util";
|
import { parseArgs } from "node:util";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { MuseError } from "./errors";
|
|
||||||
import { loadBinding } from "./binding";
|
|
||||||
import { version } from "../package.json";
|
import { version } from "../package.json";
|
||||||
|
import { loadBinding } from "./binding";
|
||||||
|
import { MuseError } from "./errors";
|
||||||
import type { Binding, CLIArguments } from "./types";
|
import type { Binding, CLIArguments } from "./types";
|
||||||
|
|
||||||
interface Loggers {
|
interface Loggers {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { normalize, extname } from "node:path";
|
import { extname, normalize } from "node:path";
|
||||||
import YAML from "yaml";
|
|
||||||
import TOML from "smol-toml";
|
|
||||||
import EMDY from "@endeavorance/emdy";
|
import EMDY from "@endeavorance/emdy";
|
||||||
|
import TOML from "smol-toml";
|
||||||
|
import YAML from "yaml";
|
||||||
import type { MuseEntry, UnknownRecord } from "./types";
|
import type { MuseEntry, UnknownRecord } from "./types";
|
||||||
|
|
||||||
function parseYAMLEntries(text: string): UnknownRecord[] {
|
function parseYAMLEntries(text: string): UnknownRecord[] {
|
||||||
|
|
40
src/preload/http-plugin.js
Normal file
40
src/preload/http-plugin.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
const rx_any = /./;
|
||||||
|
const rx_http = /^https?:\/\//;
|
||||||
|
const rx_relative_path = /^\.\.?\//;
|
||||||
|
const rx_absolute_path = /^\//;
|
||||||
|
|
||||||
|
async function load_http_module(href) {
|
||||||
|
return fetch(href).then((response) =>
|
||||||
|
response
|
||||||
|
.text()
|
||||||
|
.then((text) =>
|
||||||
|
response.ok
|
||||||
|
? { contents: text, loader: "js" }
|
||||||
|
: Promise.reject(
|
||||||
|
new Error(`Failed to load module '${href}'': ${text}`),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bun.plugin({
|
||||||
|
name: "http_imports",
|
||||||
|
setup(build) {
|
||||||
|
build.onResolve({ filter: rx_relative_path }, (args) => {
|
||||||
|
if (rx_http.test(args.importer)) {
|
||||||
|
return { path: new URL(args.path, args.importer).href };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
build.onResolve({ filter: rx_absolute_path }, (args) => {
|
||||||
|
if (rx_http.test(args.importer)) {
|
||||||
|
return { path: new URL(args.path, args.importer).href };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
build.onLoad({ filter: rx_any, namespace: "http" }, (args) =>
|
||||||
|
load_http_module(`http:${args.path}`),
|
||||||
|
);
|
||||||
|
build.onLoad({ filter: rx_any, namespace: "https" }, (args) =>
|
||||||
|
load_http_module(`https:${args.path}`),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue