Skip to content

Commit 03d6a84

Browse files
alxhubkara
authored andcommitted
build: activate experimental Angular Ivy build of the demo app
See scripts/ivy/README.md for instructions.
1 parent 1dce080 commit 03d6a84

File tree

87 files changed

+923
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+923
-357
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
"sorcery": "^0.10.0",
135135
"source-map-support": "^0.5.9",
136136
"stylelint": "^9.9.0",
137+
"stylelint": "^8.4.0",
138+
"systemjs-builder": "^0.16.13",
137139
"ts-node": "^3.0.4",
138140
"tsconfig-paths": "^2.3.0",
139141
"tslint": "^5.12.0",

scripts/ivy/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Experimental Ivy Scripts
2+
3+
These scripts exist for the testing of Ivy in the Material repo, pre-launch. This is uncharted
4+
territory, so building Material this way may or may not work, and depending on the output is
5+
non-trivial.
6+
7+
## Usage
8+
9+
For the first execution, a version of Angular must be built with `ngtsc`. To do this, a current
10+
Angular repo is passed to `install-angular.sh`.
11+
12+
```bash
13+
$ ./scripts/ivy/install-angular.sh /path/to/angular
14+
```
15+
16+
This will replace `node_modules/@angular` with `ngtsc`-built versions of Angular packages.
17+
18+
Once that step is complete, the demo application can be built.
19+
20+
```bash
21+
# Build the demo-app with Ivy
22+
$ ./scripts/ivy/build.sh
23+
# And serve it
24+
$ cd dist/demo && http-server
25+
```
26+
27+
## Known issues
28+
* Much of the compilation will fail without commits in the Angular repo not yet in `master`.
29+
* Ivy does not support the `ViewContainerRef.createComponent()` API yet, so the demo-app is unable to get past starting the Angular Router.
30+
31+
## Maintaining tsconfig files
32+
33+
The `ivy` branch has a lot of updated tsconfig files. These were mutated via script, which can
34+
be re-run if needed
35+
36+
```bash
37+
# Update tsconfigs
38+
./scripts/ivy/update-tsconfigs.sh
39+
```

scripts/ivy/build.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo ">>> Build Material"
6+
rm -rf dist
7+
gulp build:devapp
8+
9+
echo ">>> Rebuild demo-app with ngtsc"
10+
node_modules/.bin/ngc -p src/demo-app/tsconfig-build.json
11+
12+
echo ">>> Bundle demo-app with SystemJS"
13+
node ./src/demo-app/systemjs-bundle.js
14+
15+
echo ">>> Assembling app"
16+
mkdir dist/demo
17+
cp dist/packages/demo-app/bundle.js dist/demo
18+
cp src/demo-app/index.html dist/demo
19+
cp dist/packages/demo-app/theme.css dist/demo
20+
cp 'node_modules/@webcomponents/custom-elements/custom-elements.min.js' dist/demo
21+
cp node_modules/core-js/client/core.js dist/demo
22+
cp node_modules/systemjs/dist/system.src.js dist/demo
23+
cp node_modules/zone.js/dist/zone.js dist/demo
24+
cp node_modules/hammerjs/hammer.min.js dist/demo
25+
26+
echo ">>> Done."
27+
echo "Output: $(pwd)/dist/demo"

scripts/ivy/fix-tsconfig.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
/*
10+
* This script updates a tsconfig-build.json file for Ivy compilation. It has 3 main goals:
11+
*
12+
* 1. Change "public-api.ts" to "index.ts" in the files array.
13+
* 2. Add "enableIvy": "ngtsc" to "angularCompilerOptions".
14+
* 3. Turn "annotateForClosureCompiler" off (so decorators will tree-shake properly).
15+
*/
16+
17+
const fs = require('fs');
18+
19+
function replacePublicApiTs(file) {
20+
if (file === 'public-api.ts') {
21+
return 'index.ts';
22+
} else {
23+
return file;
24+
}
25+
}
26+
27+
28+
// Read in the tsconfig json file.
29+
let source = fs.readFileSync(process.argv[2], 'utf8')
30+
.split(/\n/)
31+
.filter(line => !line.trim().startsWith('/') && !line.trim().startsWith('*'))
32+
.join('\n')
33+
.replace(/,(\s+)]/g, '$1]')
34+
.replace(/,(\s+)}/g, '$1}');
35+
36+
let json = null;
37+
try {
38+
json = JSON.parse(source);
39+
} catch (e) {
40+
console.error(`Error parsing tsconfig ${process.argv[2]}:`);
41+
console.error(source);
42+
console.error(`Error was:`, e);
43+
process.exit(1);
44+
}
45+
46+
if (json['files'] && Array.isArray(json['files'])) {
47+
json['files'] = json['files'].map(replacePublicApiTs);
48+
}
49+
50+
if (json['angularCompilerOptions']) {
51+
if (json['angularCompilerOptions']['annotateForClosureCompiler']) {
52+
delete json['angularCompilerOptions']['annotateForClosureCompiler']
53+
}
54+
json['angularCompilerOptions']['enableIvy'] = 'ngtsc';
55+
}
56+
57+
fs.writeFileSync(process.argv[2], JSON.stringify(json, null, 2));

scripts/ivy/install-angular.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
6+
function prep() {
7+
echo ">>> Preparing node_modules"
8+
chmod -R u+w node_modules/@angular
9+
rm -rf node_modules/@angular/*
10+
}
11+
12+
function buildNgPackages() {
13+
ngDir=$1
14+
echo ">>> Building @angular packages (from $ngDir)"
15+
pushd $ngDir
16+
bazel build --define=compile=local //packages/{animations,common,compiler,compiler-cli,core,elements,forms,platform-browser,platform-browser-dynamic,router,upgrade}:npm_package
17+
outputPath=`bazel info 2>&1 | grep output_path | cut -d ':' -f 2 | cut -c 2-`/darwin-fastbuild/bin/packages
18+
popd
19+
}
20+
21+
function installNgPackage() {
22+
name=$1
23+
echo " @angular/$name"
24+
cp -r $outputPath/$name/npm_package node_modules/@angular/$name
25+
}
26+
27+
function buildPackage() {
28+
name=$1
29+
echo " $name"
30+
31+
# First, fix the build definition.
32+
# Update the tsconfig to compile from index.ts instead of public-api.ts, and turn on Ivy options.
33+
node scripts/ivy/fix-tsconfig.js src/$name/tsconfig-build.json
34+
35+
# If no index.ts exists, rename public-api.ts.
36+
if [ ! -f src/$name/index.ts -a -f src/$name/public-api.ts ]
37+
then
38+
mv src/$name/public-api.ts src/$name/index.ts
39+
fi
40+
41+
node_modules/.bin/ngc -p src/$name/tsconfig-build.json
42+
}
43+
44+
if [ "$1" != "" ]
45+
then
46+
prep
47+
buildNgPackages $1
48+
49+
echo ">>> Installing @angular packages"
50+
installNgPackage "animations"
51+
installNgPackage "common"
52+
installNgPackage "compiler"
53+
installNgPackage "compiler-cli"
54+
installNgPackage "core"
55+
installNgPackage "elements"
56+
installNgPackage "forms"
57+
installNgPackage "platform-browser"
58+
installNgPackage "platform-browser-dynamic"
59+
installNgPackage "router"
60+
installNgPackage "upgrade"
61+
62+
chmod -R u+w node_modules/@angular
63+
else
64+
echo "Usage: $0 /path/to/angular/repo"
65+
fi

scripts/ivy/update-tsconfigs.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
find src | grep /tsconfig.*json | grep -v '/tsconfig.json' | while read tsconfig; do
6+
dir=`dirname $tsconfig`
7+
echo "Updating $tsconfig"
8+
9+
# If no index.ts exists, rename public-api.ts.
10+
if [ ! -f $dir/index.ts -a -f $dir/public-api.ts ]
11+
then
12+
echo "export * from './public_api';" > $dir/index.ts
13+
fi
14+
node scripts/ivy/fix-tsconfig.js $tsconfig
15+
done

src/a11y-demo/menu/menu-a11y.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ <h2>Menu with Icons</h2>
3636

3737
<section>
3838
<h2>Menu with links</h2>
39-
<button mat-icon-button [matMenuTriggerFor]="menu2" aria-label="Learn more about Angular">
39+
<button mat-icon-button [matMenuTriggerFor]="menu3" aria-label="Learn more about Angular">
4040
<mat-icon>more_vert</mat-icon>
4141
</button>
4242

43-
<mat-menu #menu2="matMenu">
43+
<mat-menu #menu3="matMenu">
4444
<a href="http://angular.io" mat-menu-item>
4545
Angular
4646
</a>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"extends": "../tsconfig-build",
33
"files": [
4-
"public-api.ts",
4+
"index.ts",
55
"../typings.d.ts"
66
],
77
"angularCompilerOptions": {
8-
"annotateForClosureCompiler": true,
98
"strictMetadataEmit": true,
109
"flatModuleOutFile": "index.js",
1110
"flatModuleId": "@angular/cdk-experimental/dialog",
1211
"skipTemplateCodegen": true,
13-
"fullTemplateTypeCheck": true
12+
"fullTemplateTypeCheck": true,
13+
"enableIvy": "ngtsc"
1414
}
15-
}
15+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"extends": "../tsconfig-build",
33
"files": [
4-
"public-api.ts"
4+
"index.ts"
55
],
66
"angularCompilerOptions": {
7-
"annotateForClosureCompiler": true,
87
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk-experimental/scrolling",
1110
"skipTemplateCodegen": true,
12-
"fullTemplateTypeCheck": true
11+
"fullTemplateTypeCheck": true,
12+
"enableIvy": "ngtsc"
1313
}
14-
}
14+
}

src/cdk-experimental/tsconfig-build.json

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// TypeScript config file that is used to compile the experimental package into ES2015.
21
{
32
"compilerOptions": {
43
"baseUrl": ".",
@@ -24,27 +23,37 @@
2423
"sourceMap": true,
2524
"inlineSources": true,
2625
"target": "es2015",
27-
"lib": ["es2015", "dom"],
26+
"lib": [
27+
"es2015",
28+
"dom"
29+
],
2830
"skipLibCheck": true,
29-
"types": ["jasmine", "tslib"],
31+
"types": [
32+
"jasmine",
33+
"tslib"
34+
],
3035
"paths": {
31-
"@angular/cdk/*": ["../../dist/packages/cdk/*"],
32-
"@angular/cdk-experimental/*": ["../../dist/packages/cdk-experimental/*"]
36+
"@angular/cdk/*": [
37+
"../../dist/packages/cdk/*"
38+
],
39+
"@angular/cdk-experimental/*": [
40+
"../../dist/packages/cdk-experimental/*"
41+
]
3342
}
3443
},
3544
"files": [
36-
"public-api.ts",
45+
"index.ts",
3746
"typings.d.ts"
3847
],
3948
"angularCompilerOptions": {
40-
"annotateForClosureCompiler": true,
4149
"strictMetadataEmit": true,
4250
"flatModuleOutFile": "index.js",
4351
"flatModuleId": "@angular/cdk-experimental",
4452
"skipTemplateCodegen": true,
45-
"fullTemplateTypeCheck": true
53+
"fullTemplateTypeCheck": true,
54+
"enableIvy": "ngtsc"
4655
},
4756
"bazelOptions": {
4857
"suppressTsconfigOverrideWarnings": true
4958
}
50-
}
59+
}
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
// TypeScript config file that extends the default build tsconfig file. This config is used to
2-
// also compile the unit-test files. Since the code will run inside of the browser, the target is
3-
// set to ES5. Also the format needs to be CommonJS for Karma.
41
{
52
"extends": "./tsconfig-build",
63
"compilerOptions": {
74
"importHelpers": false,
85
"module": "commonjs",
96
"target": "es5",
10-
"types": ["jasmine"],
7+
"types": [
8+
"jasmine"
9+
],
1110
"paths": {
12-
"@angular/cdk/*": ["../../dist/packages/cdk/*/public-api"],
13-
"@angular/cdk-experimental/*": ["./*"]
11+
"@angular/cdk/*": [
12+
"../../dist/packages/cdk/*/public-api"
13+
],
14+
"@angular/cdk-experimental/*": [
15+
"./*"
16+
]
1417
}
1518
},
1619
"angularCompilerOptions": {
@@ -22,10 +25,10 @@
2225
"annotateForClosureCompiler": false,
2326
"flatModuleOutFile": null,
2427
"flatModuleId": null,
28+
"enableIvy": "ngtsc"
2529
},
2630
"include": [
27-
// Include the index.ts for each secondary entry-point
2831
"./*/index.ts",
2932
"**/*.spec.ts"
3033
]
31-
}
34+
}

src/cdk/a11y/tsconfig-build.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"extends": "../tsconfig-build",
33
"files": [
4-
"public-api.ts"
4+
"index.ts"
55
],
66
"angularCompilerOptions": {
7-
"annotateForClosureCompiler": true,
87
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/a11y",
1110
"skipTemplateCodegen": true,
12-
"fullTemplateTypeCheck": true
11+
"fullTemplateTypeCheck": true,
12+
"enableIvy": "ngtsc"
1313
}
14-
}
14+
}

0 commit comments

Comments
 (0)