release: WRNexusJS 0.8.3
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { existsSync, realpathSync } from "node:fs";
|
||||
import { existsSync, realpathSync, statSync } from "node:fs";
|
||||
import { dirname, extname, join, resolve } from "node:path";
|
||||
import type { StructuredImportDecl } from "@wrnexus/syntax";
|
||||
|
||||
@@ -33,12 +33,29 @@ export function resolveWrnImport(
|
||||
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))
|
||||
const aliases: Record<string, string> = {
|
||||
"@": "./app",
|
||||
...(options.aliases ?? {}),
|
||||
};
|
||||
const alias = Object.keys(aliases)
|
||||
.filter((key) => key.length > 0 && (source === key || source.startsWith(`${key}/`)))
|
||||
.sort((left, right) => right.length - left.length)[0];
|
||||
if (!source.startsWith(".") && !alias) return { declaration, resolved: source };
|
||||
const base = alias
|
||||
? resolve(
|
||||
options.appRoot,
|
||||
aliases[alias]!,
|
||||
source === alias ? "" : source.slice(alias.length + 1),
|
||||
)
|
||||
: resolve(dirname(importer), source);
|
||||
const found = candidates(base).find(existsSync);
|
||||
const found = candidates(base).find((candidate) => {
|
||||
if (!existsSync(candidate)) return false;
|
||||
try {
|
||||
return statSync(candidate).isFile();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (found) return { declaration, resolved: realpathSync(found) };
|
||||
const severity = (options.mode ?? "compatible") === "explicit" ? "error" : "warning";
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user