fix(dev-infra): update the config file loading for ng-dev to expect js (#36918)

Migrating to a js file for providing a configuration allows for more
extensive configuration at run time.  This allows for configs to include
logic and move beyond static values found in JSON files.

PR Close #36918
This commit is contained in:
Joey Perrott 2020-05-04 12:33:14 -07:00 committed by Alex Rickabaugh
parent b6bc0aeb61
commit 4e628a887a
4 changed files with 13 additions and 21 deletions

View File

@ -9,10 +9,8 @@ ts_library(
module_name = "@angular/dev-infra-private/utils",
visibility = ["//dev-infra:__subpackages__"],
deps = [
"@npm//@types/json5",
"@npm//@types/node",
"@npm//@types/shelljs",
"@npm//json5",
"@npm//shelljs",
"@npm//tslib",
],

View File

@ -5,11 +5,13 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {readFileSync} from 'fs';
import {parse} from 'json5';
import {join} from 'path';
import {exec} from 'shelljs';
// The filename expected for creating the ng-dev config.
const CONFIG_FILE_NAME = '.ng-dev-config.js';
/**
* Gets the path of the directory for the repository base.
*/
@ -25,19 +27,18 @@ export function getRepoBaseDir() {
}
/**
* Retrieve the configuration from the .dev-infra.json file.
* Retrieve the configuration from the .ng-dev-config.js file.
*/
export function getAngularDevConfig<K, T>(): DevInfraConfig<K, T> {
const configPath = join(getRepoBaseDir(), '.dev-infra.json');
let rawConfig = '';
export function getAngularDevConfig<K, T>(supressError = false): DevInfraConfig<K, T> {
const configPath = join(getRepoBaseDir(), CONFIG_FILE_NAME);
try {
rawConfig = readFileSync(configPath, 'utf8');
} catch {
throw Error(
`Unable to find config file at:\n` +
` ${configPath}`);
return require(configPath) as DevInfraConfig<K, T>;
} catch (err) {
if (!supressError) {
throw Error(`Unable to load config file at:\n ${configPath}`);
}
}
return parse(rawConfig);
return {} as DevInfraConfig<K, T>;
}
/**

View File

@ -153,7 +153,6 @@
"@bazel/ibazel": "^0.12.3",
"@octokit/graphql": "^4.3.1",
"@types/cli-progress": "^3.4.2",
"@types/json5": "^0.0.30",
"@types/minimist": "^1.2.0",
"@yarnpkg/lockfile": "^1.1.0",
"browserstacktunnel-wrapper": "2.0.1",
@ -173,7 +172,6 @@
"husky": "^4.2.3",
"inquirer": "^7.1.0",
"jpm": "1.3.1",
"json5": "^2.1.2",
"karma-browserstack-launcher": "^1.3.0",
"karma-sauce-launcher": "^2.0.2",
"madge": "^3.6.0",

View File

@ -1477,11 +1477,6 @@
dependencies:
"@types/jasmine" "*"
"@types/json5@^0.0.30":
version "0.0.30"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.30.tgz#44cb52f32a809734ca562e685c6473b5754a7818"
integrity sha512-sqm9g7mHlPY/43fcSNrCYfOeX9zkTTK+euO5E6+CVijSMm5tTjkVdwdqRkY3ljjIAf8679vps5jKUoJBCLsMDA==
"@types/long@^4.0.0":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9"