From 4e628a887a095f35a722ae2888575cf11881c286 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Mon, 4 May 2020 12:33:14 -0700 Subject: [PATCH] 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 --- dev-infra/utils/BUILD.bazel | 2 -- dev-infra/utils/config.ts | 25 +++++++++++++------------ package.json | 2 -- yarn.lock | 5 ----- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/dev-infra/utils/BUILD.bazel b/dev-infra/utils/BUILD.bazel index 648ad4adf1..812c20ce99 100644 --- a/dev-infra/utils/BUILD.bazel +++ b/dev-infra/utils/BUILD.bazel @@ -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", ], diff --git a/dev-infra/utils/config.ts b/dev-infra/utils/config.ts index d3893d404c..7f68e247c6 100644 --- a/dev-infra/utils/config.ts +++ b/dev-infra/utils/config.ts @@ -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(): DevInfraConfig { - const configPath = join(getRepoBaseDir(), '.dev-infra.json'); - let rawConfig = ''; +export function getAngularDevConfig(supressError = false): DevInfraConfig { + 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; + } catch (err) { + if (!supressError) { + throw Error(`Unable to load config file at:\n ${configPath}`); + } } - return parse(rawConfig); + return {} as DevInfraConfig; } /** diff --git a/package.json b/package.json index 4e8ceb3a0e..3dad7aa5c1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index abadcbe521..eccbb096bf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"