release: WRNexusJS 0.6.0

This commit is contained in:
2026-08-01 01:09:58 +05:30
parent 3e565e8d03
commit 687d345882
502 changed files with 33038 additions and 11358 deletions
+60
View File
@@ -0,0 +1,60 @@
import { existsSync, realpathSync } from "node:fs";
import { dirname, extname, join, resolve } from "node:path";
import type { StructuredImportDecl } from "@wrnexus/syntax";
export type ImportMode = "legacy" | "compatible" | "explicit";
export interface ImportResolverOptions {
appRoot: string;
mode?: ImportMode;
aliases?: Record<string, string>;
}
export interface ResolvedImport {
declaration: StructuredImportDecl;
resolved?: string;
diagnostic?: { code: string; message: string; severity: "error" | "warning" };
}
function candidates(path: string): string[] {
return extname(path)
? [path]
: [
path,
`${path}.wrn`,
`${path}.ts`,
`${path}.d.ts`,
join(path, "index.wrn"),
join(path, "index.ts"),
];
}
export function resolveWrnImport(
declaration: StructuredImportDecl,
importer: string,
options: ImportResolverOptions,
): ResolvedImport {
const source = declaration.source;
if (!source.startsWith(".") && !source.startsWith("@/")) return { declaration, resolved: source };
const aliasRoot = options.aliases?.["@"] ?? "./app";
const base = source.startsWith("@/")
? resolve(options.appRoot, aliasRoot, source.slice(2))
: resolve(dirname(importer), source);
const found = candidates(base).find(existsSync);
if (found) return { declaration, resolved: realpathSync(found) };
const severity = (options.mode ?? "compatible") === "explicit" ? "error" : "warning";
return {
declaration,
diagnostic: {
code: "WRN-IMPORT-NOT-FOUND",
message: `Cannot resolve import '${source}' from ${importer}`,
severity,
},
};
}
export function resolveWrnImports(
declarations: StructuredImportDecl[],
importer: string,
options: ImportResolverOptions,
): ResolvedImport[] {
return declarations.map((declaration) => resolveWrnImport(declaration, importer, options));
}