From 5650e3847b662c1b6f9c2e8d996955d4ab2d7a17 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 19 Apr 2019 15:42:56 +0300 Subject: [PATCH] build(docs-infra): make tsconfig path detection in `switch-to-ivy` more robust (#29989) In light of #29926, that will change the path of `tsconfig.app.json`, this commit switches from a hard-coded `tsconfig.app.json` path to looking it up in `angular.json` (to be more future-proof). PR Close #29989 --- aio/scripts/switch-to-ivy.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/aio/scripts/switch-to-ivy.js b/aio/scripts/switch-to-ivy.js index 9e53e244c1..bafbbe3431 100644 --- a/aio/scripts/switch-to-ivy.js +++ b/aio/scripts/switch-to-ivy.js @@ -10,7 +10,7 @@ set('-e'); // Constants const ROOT_DIR = resolve(__dirname, '..'); -const TS_CONFIG_PATH = join(ROOT_DIR, 'src/tsconfig.app.json'); +const NG_JSON = join(ROOT_DIR, 'angular.json'); const NG_COMPILER_OPTS = { angularCompilerOptions: { // Related Jira issue: FW-737 @@ -24,14 +24,18 @@ _main(process.argv.slice(2)); // Functions - Definitions function _main() { + // Detect path to `tsconfig.app.json`. + const ngConfig = parse(readFileSync(NG_JSON, 'utf8')); + const tsConfigPath = join(ROOT_DIR, ngConfig.projects.site.architect.build.options.tsConfig); + // Enable Ivy in TS config. - console.log(`\nModifying \`${TS_CONFIG_PATH}\`...`); - const oldTsConfigStr = readFileSync(TS_CONFIG_PATH, 'utf8'); + console.log(`\nModifying \`${tsConfigPath}\`...`); + const oldTsConfigStr = readFileSync(tsConfigPath, 'utf8'); const oldTsConfigObj = parse(oldTsConfigStr); const newTsConfigObj = extend(true, oldTsConfigObj, NG_COMPILER_OPTS); const newTsConfigStr = JSON.stringify(newTsConfigObj, null, 2); console.log(`\nNew config: ${newTsConfigStr}`); - writeFileSync(TS_CONFIG_PATH, newTsConfigStr); + writeFileSync(tsConfigPath, newTsConfigStr); // Run ngcc. const ngccArgs = '--loglevel debug --properties es2015 module'; @@ -41,5 +45,5 @@ function _main() { // Done. console.log('\nReady to build with Ivy!'); console.log('(To switch back to ViewEngine (with packages from npm), undo the changes in ' + - `\`${TS_CONFIG_PATH}\` and run \`yarn aio-use-npm && yarn example-use-npm\`.)`); + `\`${tsConfigPath}\` and run \`yarn aio-use-npm && yarn example-use-npm\`.)`); }