From 11eef85133529f78bf6d5e16dd3704f0c4b5a05c Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Tue, 2 Apr 2019 21:53:49 +0300 Subject: [PATCH] build(docs-infra): change `build-with-ivy` script to `switch-to-ivy` (#29989) Previously, the `build-with-ivy` script could be used to build the `aio` project with Ivy (once it had been prepared with `ivy-ngcc`, etc.) and then restored the configuration (e.g. `tsconfig.json`) to non-ivy mode. As a result, it was not useful for running other commands (e.g. unit/e2e tests) in Ivy mode. This commit renames the script to `switch-to-ivy` and employs a different model (similar to `ng-packages-installer`), where the project is setup to run in Ivy mode and then all subsequent commands are executed in that mode (until restored). Since this is currently only used on CI, there is no automatic way to switch back to non-ivy mode (but it could be implemented in the future if needed). Finally, the script now modifies `src/tsconfig.app/json` instead of `tsconfig.json` to ensure that the `angularCompilerOptions` are not ignored/overwritten. This is also closer to what the cli generates with the `--enable-ivy` option. PR Close #29989 --- aio/package.json | 4 +-- .../{build-with-ivy.js => switch-to-ivy.js} | 29 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) rename aio/scripts/{build-with-ivy.js => switch-to-ivy.js} (53%) diff --git a/aio/package.json b/aio/package.json index c6529a06b6..ac59d7f59f 100644 --- a/aio/package.json +++ b/aio/package.json @@ -17,8 +17,8 @@ "build": "yarn ~~build", "prebuild-local": "yarn setup-local", "build-local": "yarn ~~build", - "prebuild-with-ivy": "yarn setup-local && yarn ivy-ngcc --properties module es2015", - "build-with-ivy": "node scripts/build-with-ivy", + "prebuild-with-ivy": "yarn setup-local && node scripts/switch-to-ivy", + "build-with-ivy": "yarn ~~build", "extract-cli-command-docs": "node tools/transforms/cli-docs-package/extract-cli-commands.js 664990cad", "lint": "yarn check-env && yarn docs-lint && ng lint && yarn example-lint && yarn tools-lint", "test": "yarn check-env && ng test", diff --git a/aio/scripts/build-with-ivy.js b/aio/scripts/switch-to-ivy.js similarity index 53% rename from aio/scripts/build-with-ivy.js rename to aio/scripts/switch-to-ivy.js index 8c159970f5..9e53e244c1 100644 --- a/aio/scripts/build-with-ivy.js +++ b/aio/scripts/switch-to-ivy.js @@ -10,12 +10,12 @@ set('-e'); // Constants const ROOT_DIR = resolve(__dirname, '..'); -const TS_CONFIG_PATH = join(ROOT_DIR, 'tsconfig.json'); +const TS_CONFIG_PATH = join(ROOT_DIR, 'src/tsconfig.app.json'); const NG_COMPILER_OPTS = { angularCompilerOptions: { // Related Jira issue: FW-737 allowEmptyCodegenFiles: true, - enableIvy: 'ngtsc', + enableIvy: true, }, }; @@ -23,24 +23,23 @@ const NG_COMPILER_OPTS = { _main(process.argv.slice(2)); // Functions - Definitions -function _main(buildArgs) { - console.log('\nModifying `tsconfig.json`...'); +function _main() { + // Enable Ivy in TS config. + console.log(`\nModifying \`${TS_CONFIG_PATH}\`...`); const oldTsConfigStr = readFileSync(TS_CONFIG_PATH, '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); - console.log(newTsConfigStr); - try { - const buildArgsStr = buildArgs.join(' '); + // Run ngcc. + const ngccArgs = '--loglevel debug --properties es2015 module'; + console.log(`\nRunning ngcc (with args: ${ngccArgs})...`); + exec(`yarn ivy-ngcc ${ngccArgs}`); - console.log(`\nBuilding${buildArgsStr && ` with args \`${buildArgsStr}\``}...`); - exec(`yarn ~~build ${buildArgsStr}`, {cwd: ROOT_DIR}); - } finally { - console.log('\nRestoring `tsconfig.json`...'); - writeFileSync(TS_CONFIG_PATH, oldTsConfigStr); - } - - console.log('\nDone!'); + // 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\`.)`); }