2024-04-29 23:37:05 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
const workspaces = JSON.parse(await Deno.readTextFile("deno.json"))
|
2024-07-11 00:24:30 +00:00
|
|
|
.workspace as string[];
|
2024-04-29 23:37:05 +00:00
|
|
|
// deno-lint-ignore no-explicit-any
|
|
|
|
const denoConfig = {} as Record<string, any>;
|
|
|
|
for (const workspace of workspaces) {
|
|
|
|
const { default: config } = await import("../" + workspace + "/deno.json", {
|
|
|
|
with: { type: "json" },
|
|
|
|
});
|
|
|
|
denoConfig[config.name.replace("@std/", "")] = config;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function resolveWorkspaceSpecifiers(
|
|
|
|
specifier: string,
|
|
|
|
referrer: string,
|
|
|
|
) {
|
|
|
|
if (specifier.startsWith("../") || specifier.startsWith("./")) {
|
|
|
|
return new URL(specifier, referrer).href;
|
|
|
|
} else if (specifier.startsWith("@std/")) {
|
|
|
|
let [_std, pkg, exp] = specifier.split("/");
|
|
|
|
if (exp === undefined) {
|
|
|
|
exp = ".";
|
|
|
|
} else {
|
|
|
|
exp = "./" + exp;
|
|
|
|
}
|
|
|
|
const pkgPath = "../" + pkg!.replaceAll("-", "_") + "/";
|
|
|
|
const config = denoConfig[pkg!];
|
|
|
|
if (typeof config.exports === "string") {
|
|
|
|
return new URL(pkgPath + config.exports, import.meta.url).href;
|
|
|
|
}
|
|
|
|
return new URL(pkgPath + config.exports[exp], import.meta.url).href;
|
|
|
|
} else {
|
|
|
|
return new URL(specifier).href;
|
|
|
|
}
|
|
|
|
}
|