MCPcopy Index your code
hub / github.com/nodejs/corepack / getLastKnownGood

Function getLastKnownGood

sources/Engine.ts:35–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33}
34
35export async function getLastKnownGood(): Promise<Record<string, string>> {
36 let raw: string;
37 try {
38 raw = await fs.promises.readFile(getLastKnownGoodFilePath(), `utf8`);
39 } catch (err) {
40 if ((err as NodeError)?.code === `ENOENT`) {
41 debugUtils.log(`No LastKnownGood version found in Corepack home.`);
42 return {};
43 }
44 throw err;
45 }
46
47 try {
48 const parsed = JSON.parse(raw);
49 if (!parsed) {
50 debugUtils.log(`Invalid LastKnowGood file in Corepack home (JSON parsable, but falsy)`);
51 return {};
52 }
53 if (typeof parsed !== `object`) {
54 debugUtils.log(`Invalid LastKnowGood file in Corepack home (JSON parsable, but non-object)`);
55 return {};
56 }
57 Object.entries(parsed).forEach(([key, value]) => {
58 if (typeof value !== `string`) {
59 // Ensure that all entries are strings.
60 debugUtils.log(`Ignoring key ${key} in LastKnownGood file as its value is not a string`);
61 delete parsed[key];
62 }
63 });
64 return parsed;
65 } catch {
66 // Ignore errors; too bad
67 debugUtils.log(`Invalid LastKnowGood file in Corepack home (maybe not JSON parsable)`);
68 return {};
69 }
70}
71
72async function createLastKnownGoodFile(lastKnownGood: Record<string, string>) {
73 const content = `${JSON.stringify(lastKnownGood, null, 2)}\n`;

Callers 2

getDefaultVersionMethod · 0.85

Calls 2

getLastKnownGoodFilePathFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…