(dir: string)
| 30 | // Reads and parses <dir>/component.json. Throws a path-tagged error on a missing |
| 31 | // file or malformed JSON, for the caller to turn into a clean exit. |
| 32 | export async function readComponentJson(dir: string): Promise<unknown> { |
| 33 | const file = path.join(dir, "component.json"); |
| 34 | let raw: string; |
| 35 | try { |
| 36 | raw = await fs.readFile(file, "utf-8"); |
| 37 | } catch (err) { |
| 38 | if ((err as NodeJS.ErrnoException).code === "ENOENT") { |
| 39 | throw new Error(`custom component: no component.json in ${dir}`, { cause: err }); |
| 40 | } |
| 41 | throw err; |
| 42 | } |
| 43 | try { |
| 44 | return JSON.parse(raw); |
| 45 | } catch (err) { |
| 46 | throw new Error(`${file}: invalid JSON: ${err instanceof Error ? err.message : String(err)}`, { cause: err }); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | let cachedValidator: ValidateFunction | undefined; |
| 51 |
no outgoing calls
no test coverage detected