From 03d92f75e696ccdceaa16d2df7f01e505dde3907 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Sat, 20 Feb 2021 16:23:46 +0000 Subject: [PATCH] build(docs-infra): enable Ivy in StackBlitz examples (#40930) We need to explicitly set the `enableIvy` option in a tsconfig file to tell StackBlitz not to use ViewEngine. This commit will generate an appropriate tsconfig.json file in the example data that is sent to StackBlitz, which matches the Ivy setting of the AIO project itself. PR Close #40930 --- .../boilerplate/viewengine/cli/tsconfig.json | 3 +-- aio/tools/stackblitz-builder/builder.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/aio/tools/examples/shared/boilerplate/viewengine/cli/tsconfig.json b/aio/tools/examples/shared/boilerplate/viewengine/cli/tsconfig.json index 2394d7fc83..2c974301ff 100644 --- a/aio/tools/examples/shared/boilerplate/viewengine/cli/tsconfig.json +++ b/aio/tools/examples/shared/boilerplate/viewengine/cli/tsconfig.json @@ -26,7 +26,6 @@ "enableIvy": false, "strictInjectionParameters": true, "strictInputAccessModifiers": true, - // TODO(gkalpak): Fix the code and enable this (i.e. switch from `fullTemplateTypeCheck` to `strictTemplates`). - "fullTemplateTypeCheck": true,// "strictTemplates": true + "strictTemplates": true } } diff --git a/aio/tools/stackblitz-builder/builder.js b/aio/tools/stackblitz-builder/builder.js index b087c906cc..52fc3b1f1e 100644 --- a/aio/tools/stackblitz-builder/builder.js +++ b/aio/tools/stackblitz-builder/builder.js @@ -5,6 +5,7 @@ const path = require('canonical-path'); const fs = require('fs-extra'); const globby = require('globby'); const jsdom = require('jsdom'); +const json5 = require('json5'); const regionExtractor = require('../transforms/examples-package/services/region-parser'); @@ -226,6 +227,18 @@ class StackblitzBuilder { postData[`files[${relativeFileName}]`] = content; }); + // Stackblitz defaults to ViewEngine unless `"enableIvy": true` + // So if there is a tsconfig.json file and there is no `enableIvy` property, we need to + // explicitly set it. + const tsConfigJSON = postData['files[tsconfig.json]']; + if (tsConfigJSON !== undefined) { + const tsConfig = json5.parse(tsConfigJSON); + if (tsConfig.angularCompilerOptions.enableIvy === undefined) { + tsConfig.angularCompilerOptions.enableIvy = true; + postData['files[tsconfig.json]'] = JSON.stringify(tsConfig, null, 2); + } + } + const tags = ['angular', 'example', ...config.tags || []]; tags.forEach((tag, ix) => postData[`tags[${ix}]`] = tag); @@ -263,7 +276,7 @@ class StackblitzBuilder { const config = this._parseConfig(configFileName); const defaultIncludes = ['**/*.ts', '**/*.js', '**/*.css', '**/*.html', '**/*.md', '**/*.json', '**/*.png', '**/*.svg']; - const boilerplateIncludes = ['src/environments/*.*', 'angular.json', 'src/polyfills.ts']; + const boilerplateIncludes = ['src/environments/*.*', 'angular.json', 'src/polyfills.ts', 'tsconfig.json']; if (config.files) { if (config.files.length > 0) { if (config.files[0][0] === '!') { @@ -288,7 +301,6 @@ class StackblitzBuilder { const defaultExcludes = [ '!**/e2e/**/*.*', - '!**/tsconfig.json', '!**/package.json', '!**/example-config.json', '!**/tslint.json',