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:

committed by
Alex Rickabaugh

parent
d1b3af697c
commit
fbdd282e7c
@ -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",
|
||||
],
|
||||
|
@ -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>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user