importly
Version:
importly generates import maps
21 lines • 914 B
JavaScript
import json5 from "json5";
import { readFile } from "fs/promises";
import { determinePackageEntry } from "../utilities/determine-package-entry.js";
export const lookupViaNodeModules = async ({ orders }) => {
return Promise.all(orders.map(async (order) => {
const segments = [...order.parents, order.label];
const directory = "node_modules/" + segments.join("/node_modules/");
const path = `${directory}/package.json`;
try {
const text = await readFile(path, "utf-8");
const json = json5.parse(text);
const entry = determinePackageEntry(json);
return { ...order, entry };
}
catch (error) {
return undefined;
// throw new ImportlyLookupError(`error looking at: "${path}"`)
}
})).then(manifests => manifests.filter(m => !!m));
};
//# sourceMappingURL=lookup-via-node-modules.js.map