/
githubmirror
/
angular-cli
Обзор
Документация
Войти
/
githubmirror
/
angular-cli
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/angular_devkit/schematics/tools/file-system-utility.ts
38 строк
1 KB
Joey Perrott
refactor: move builtin module imports to use node: prefix imports
14 фев 2025, 22:09
14 фев 2025, 22:09
33ed6e8
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import { JsonValue } from '@angular-devkit/core'; import { ParseError, parse, printParseErrorCode } from 'jsonc-parser'; import { readFileSync } from 'node:fs'; import { FileDoesNotExistException } from '../src/exception/exception'; export function readJsonFile(path: string): JsonValue { let data; try { data = readFileSync(path, 'utf-8'); } catch (e) { if (e && typeof e === 'object' && 'code' in e && e.code === 'ENOENT') { throw new FileDoesNotExistException(path); } throw e; } const errors: ParseError[] = []; const content = parse(data, errors, { allowTrailingComma: true }) as JsonValue; if (errors.length) { const { error, offset } = errors[0]; throw new Error( `Failed to parse "${path}" as JSON AST Object. ${printParseErrorCode( error, )} at location: ${offset}.`, ); } return content; }