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
This commit is contained in:
Pete Bacon Darwin 2021-02-20 16:23:46 +00:00 committed by Zach Arend
parent 272b5645c4
commit 03d92f75e6
2 changed files with 15 additions and 4 deletions

View File

@ -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
}
}

View File

@ -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',