rust2.0 #1

Merged
hibas123 merged 13 commits from rust2.0 into main 2024-08-13 10:00:18 +00:00
2 changed files with 12 additions and 14 deletions
Showing only changes of commit 5106424a32 - Show all commits

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/jrpcgen", "name": "@hibas123/jrpcgen",
"version": "1.2.6", "version": "1.2.11",
"main": "lib/index.js", "main": "lib/index.js",
"license": "MIT", "license": "MIT",
"packageManager": "yarn@3.1.1", "packageManager": "yarn@3.1.1",

View File

@ -18,7 +18,7 @@ import { ZIGTarget } from "./targets/zig";
import { DartTarget } from "./targets/dart"; import { DartTarget } from "./targets/dart";
import { URL } from "url"; import { URL } from "url";
class CatchedError extends Error { } class CatchedError extends Error {}
const log = dbg("app"); const log = dbg("app");
@ -46,15 +46,19 @@ function indexToLineAndCol(src: string, index: number) {
return { line, col }; return { line, col };
} }
function resolve(base: string, ...parts: string[]) { function resolve(base: string, sub?: string) {
if (base.startsWith("http://") || base.startsWith("https://")) { if (sub && (sub.startsWith("http://") || sub.startsWith("https://"))) {
let u = new URL(sub);
return u.href;
} else if (base.startsWith("http://") || base.startsWith("https://")) {
let u = new URL(base); let u = new URL(base);
for (const part of parts) { if (sub) {
u = new URL(part, u); u = new URL(sub, u);
} }
return u.href; return u.href;
} else { } else {
return Path.resolve(base, ...parts); if (!sub) return Path.resolve(base);
else return Path.resolve(Path.dirname(base), sub + ".jrpc");
} }
} }
@ -151,13 +155,7 @@ async function processFile(
let resolved: Parsed = []; let resolved: Parsed = [];
for (const statement of parsed) { for (const statement of parsed) {
if (statement.type == "import") { if (statement.type == "import") {
let res: string; let res = resolve(file, statement.path);
if (file.startsWith("http://") || file.startsWith("https://")) {
res = resolve(file, statement.path + ".jrpc");
} else {
const base = Path.dirname(file);
res = resolve(base, statement.path + ".jrpc");
}
resolved.push(...((await processFile(ctx, res)) || [])); resolved.push(...((await processFile(ctx, res)) || []));
} else { } else {
resolved.push(statement); resolved.push(statement);