Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829// Module resolution: LOAD_AS_FILE then LOAD_AS_DIRECTORY then NODE_MODULES.// Uses the kernel's `resolve` syscall in step 1, so the pure algorithm here only// handles specifier classification (the part that must not be duplicated on the wire).export type Specifier = | { kind: "relative"; path: string } | { kind: "absolute"; path: string } | { kind: "builtin"; id: string } | { kind: "package"; name: string; subpath: string | null };
export function classify(specifier: string): Specifier { if (specifier.startsWith("node:")) return { kind: "builtin", id: specifier.slice(5) }; if (specifier.startsWith("./") || specifier.startsWith("../")) return { kind: "relative", path: specifier }; if (specifier.startsWith("/")) return { kind: "absolute", path: specifier }; const slash = specifier.indexOf("/"); const name = slash === -1 || specifier.startsWith("@") ? specifier : specifier.slice(0, slash); return { kind: "package", name, subpath: slash === -1 ? null : specifier.slice(slash + 1) };}
/** join a parent dir + relative specifier lexically (kernel does the physical walk). */export function join(parentDir: string, rel: string): string { const segs = parentDir.split("/").filter(Boolean); for (const seg of rel.split("/")) { if (seg === "." || seg === "") continue; if (seg === "..") segs.pop(); else segs.push(seg); } return "/" + segs.join("/");}