Skip to content

Commit

Permalink
build(docs-infra): make tsconfig path detection in switch-to-ivy mo…
Browse files Browse the repository at this point in the history
…re robust (angular#29989)

In light of angular#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 angular#29989
  • Loading branch information
gkalpak authored and BioPhoton committed May 21, 2019
1 parent 139af5f commit 478e5b1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions aio/scripts/switch-to-ivy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
Expand All @@ -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\`.)`);
}

0 comments on commit 478e5b1

Please sign in to comment.