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:
parent
b6bc0aeb61
commit
4e628a887a
|
@ -9,10 +9,8 @@ ts_library(
|
||||||
module_name = "@angular/dev-infra-private/utils",
|
module_name = "@angular/dev-infra-private/utils",
|
||||||
visibility = ["//dev-infra:__subpackages__"],
|
visibility = ["//dev-infra:__subpackages__"],
|
||||||
deps = [
|
deps = [
|
||||||
"@npm//@types/json5",
|
|
||||||
"@npm//@types/node",
|
"@npm//@types/node",
|
||||||
"@npm//@types/shelljs",
|
"@npm//@types/shelljs",
|
||||||
"@npm//json5",
|
|
||||||
"@npm//shelljs",
|
"@npm//shelljs",
|
||||||
"@npm//tslib",
|
"@npm//tslib",
|
||||||
],
|
],
|
||||||
|
|
|
@ -5,11 +5,13 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {readFileSync} from 'fs';
|
|
||||||
import {parse} from 'json5';
|
|
||||||
import {join} from 'path';
|
import {join} from 'path';
|
||||||
import {exec} from 'shelljs';
|
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.
|
* 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> {
|
export function getAngularDevConfig<K, T>(supressError = false): DevInfraConfig<K, T> {
|
||||||
const configPath = join(getRepoBaseDir(), '.dev-infra.json');
|
const configPath = join(getRepoBaseDir(), CONFIG_FILE_NAME);
|
||||||
let rawConfig = '';
|
|
||||||
try {
|
try {
|
||||||
rawConfig = readFileSync(configPath, 'utf8');
|
return require(configPath) as DevInfraConfig<K, T>;
|
||||||
} catch {
|
} catch (err) {
|
||||||
throw Error(
|
if (!supressError) {
|
||||||
`Unable to find config file at:\n` +
|
throw Error(`Unable to load config file at:\n ${configPath}`);
|
||||||
` ${configPath}`);
|
|
||||||
}
|
}
|
||||||
return parse(rawConfig);
|
}
|
||||||
|
return {} as DevInfraConfig<K, T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -153,7 +153,6 @@
|
||||||
"@bazel/ibazel": "^0.12.3",
|
"@bazel/ibazel": "^0.12.3",
|
||||||
"@octokit/graphql": "^4.3.1",
|
"@octokit/graphql": "^4.3.1",
|
||||||
"@types/cli-progress": "^3.4.2",
|
"@types/cli-progress": "^3.4.2",
|
||||||
"@types/json5": "^0.0.30",
|
|
||||||
"@types/minimist": "^1.2.0",
|
"@types/minimist": "^1.2.0",
|
||||||
"@yarnpkg/lockfile": "^1.1.0",
|
"@yarnpkg/lockfile": "^1.1.0",
|
||||||
"browserstacktunnel-wrapper": "2.0.1",
|
"browserstacktunnel-wrapper": "2.0.1",
|
||||||
|
@ -173,7 +172,6 @@
|
||||||
"husky": "^4.2.3",
|
"husky": "^4.2.3",
|
||||||
"inquirer": "^7.1.0",
|
"inquirer": "^7.1.0",
|
||||||
"jpm": "1.3.1",
|
"jpm": "1.3.1",
|
||||||
"json5": "^2.1.2",
|
|
||||||
"karma-browserstack-launcher": "^1.3.0",
|
"karma-browserstack-launcher": "^1.3.0",
|
||||||
"karma-sauce-launcher": "^2.0.2",
|
"karma-sauce-launcher": "^2.0.2",
|
||||||
"madge": "^3.6.0",
|
"madge": "^3.6.0",
|
||||||
|
|
|
@ -1477,11 +1477,6 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/jasmine" "*"
|
"@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":
|
"@types/long@^4.0.0":
|
||||||
version "4.0.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9"
|
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9"
|
||||||
|
|
Loading…
Reference in New Issue