Skip to content

Commit ebf4aa9

Browse files
committed
Fix AOT task
1 parent d6bc532 commit ebf4aa9

File tree

5 files changed

+35
-200
lines changed

5 files changed

+35
-200
lines changed

src/demo-app/tsconfig-aot.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"compilerOptions": {
55
"experimentalDecorators": true,
66
"paths": {
7-
"@angular/material": ["../material"]
7+
"@angular/material": ["./material"]
88
}
99
},
1010
"files": [

tools/gulp/tasks/aot.ts

+14-25
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
import {task} from 'gulp';
2-
import {DIST_DEMOAPP, SOURCE_ROOT} from '../constants';
3-
import {sequenceTask} from '../util/task_helpers';
2+
import {copySync} from 'fs-extra';
3+
import {DIST_DEMOAPP, DIST_RELEASE} from '../constants';
4+
import {sequenceTask, execNodeTask} from '../util/task_helpers';
45
import {join} from 'path';
5-
import {Program, CompilerHost} from 'typescript';
6-
import {
7-
main as tsc, CodeGenerator, AngularCompilerOptions, NgcCliOptions
8-
} from '@angular/compiler-cli';
96

10-
const tsconfigFile = join(SOURCE_ROOT, 'demo-app', 'tsconfig-aot.json');
7+
const tsconfigFile = join(DIST_DEMOAPP, 'tsconfig-aot.json');
118

129
/** Builds the demo-app and library. To be able to run NGC, apply the metadata workaround. */
13-
task('aot:deps', sequenceTask('build:devapp', 'library:build:fix-metadata'));
10+
task('aot:deps', sequenceTask('build:devapp', ':package:release', 'aot:copy-release'));
1411

15-
/** After building the demo-app, run the Angular compiler to verify that all components work. */
16-
task('aot:build', ['aot:deps'], () => runAngularCompiler());
12+
// As a workaround for https://github.com/angular/angular/issues/12249, we need to
13+
// copy the Material ESM output inside of the demo-app output.
14+
task('aot:copy-release', () => {
15+
copySync(DIST_RELEASE, join(DIST_DEMOAPP, 'material'));
16+
});
1717

18-
/**
19-
* Angular does not expose a public function to run the Angular compiler.
20-
* Creating the CodeGenerator from NGC and using it inside of tsc-wrapped is the same. */
21-
function runAngularCompiler() {
22-
return tsc(tsconfigFile, {basePath: DIST_DEMOAPP}, codegen);
23-
}
24-
25-
/**
26-
* Codgen function from the @angular/compiler-cli package.
27-
* See: https://github.com/angular/angular/blob/master/packages/compiler-cli/src/main.ts
28-
*/
29-
function codegen(ngOptions: AngularCompilerOptions, cliOptions: NgcCliOptions, program: Program,
30-
host: CompilerHost) {
31-
return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
32-
}
18+
/** Build the demo-app and a release to confirm that the library is AOT-compatible. */
19+
task('aot:build', ['aot:deps'], execNodeTask(
20+
'@angular/compiler-cli', 'ngc', ['-p', tsconfigFile]
21+
));

tools/gulp/tasks/components.ts

-154
This file was deleted.

tools/gulp/tasks/library.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {task, watch, src, dest} from 'gulp';
1+
import {task, watch} from 'gulp';
22
import {join} from 'path';
33
import {main as tsc} from '@angular/tsc-wrapped';
44
import {SOURCE_ROOT, DIST_BUNDLES, DIST_MATERIAL, UGLIFYJS_OPTIONS} from '../constants';
@@ -10,7 +10,6 @@ import {writeFileSync} from 'fs';
1010

1111
// There are no type definitions available for these imports.
1212
const inlineResources = require('../../../scripts/release/inline-resources');
13-
const gulpRename = require('gulp-rename');
1413
const uglify = require('uglify-js');
1514

1615
const libraryRoot = join(SOURCE_ROOT, 'lib');
@@ -38,17 +37,6 @@ task('library:watch', () => {
3837
watch(join(libraryRoot, '**/*.html'), ['library:build', triggerLivereload]);
3938
});
4039

41-
/**
42-
* Workaround for a @angular/tsc-wrapped issue, where the compiler looks for component assets
43-
* in the wrong folder. This issue only appears for bundled metadata files.
44-
* As a workaround, we just copy all assets next to the metadata bundle.
45-
**/
46-
task('library:build:fix-metadata', () => {
47-
return src('**/*.+(html|css)', { cwd: materialDir })
48-
.pipe(gulpRename({dirname: ''}))
49-
.pipe(dest(materialDir));
50-
});
51-
5240
/**
5341
* TypeScript compilation tasks. Tasks are creating ESM, FESM, UMD bundles for releases.
5442
**/

tools/gulp/tasks/release.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ import {
88
} from '../constants';
99
import * as minimist from 'minimist';
1010

11+
// There are no type definitions available for these imports.
12+
const gulpRename = require('gulp-rename');
13+
1114
/** Parse command-line arguments for release task. */
1215
const argv = minimist(process.argv.slice(3));
1316

14-
// Capture all d.ts files output by typescript compilation.
15-
const typingsGlob = join(DIST_MATERIAL, '**', '*.d.ts');
16-
17+
// Matches all Typescript definition files for Material.
18+
const typingsGlob = join(DIST_MATERIAL, '**/*.d.ts');
19+
// Matches the "package.json" and "README.md" file that needs to be shipped.
1720
const assetsGlob = join(COMPONENTS_DIR, '+(package.json|README.md)');
18-
19-
// Capture all UMD bundles.
21+
// Matches all UMD bundles inside of the bundles distribution.
2022
const umdGlob = join(DIST_BUNDLES, '*.umd.*');
21-
22-
// Capture all flat ESM bunldes (e.g., "material.js" and "material.es5.js")
23+
// Matches all flat ESM bundles (e.g material.js and material.es5.js)
2324
const fesmGlob = [join(DIST_BUNDLES, '*.js'), `!${umdGlob}`];
2425

2526
task('build:release', sequenceTask(
@@ -29,13 +30,24 @@ task('build:release', sequenceTask(
2930

3031
/** Task that combines intermediate build artifacts into the release package structure. */
3132
task(':package:release', [
33+
':package:fix-metadata',
3234
':package:metadata',
3335
':package:typings',
3436
':package:umd',
3537
':package:fesm',
3638
':package:assets'
3739
]);
3840

41+
/**
42+
* Workaround for a @angular/tsc-wrapped issue, where the compiler looks for component assets
43+
* in the wrong folder. This issue only appears for bundled metadata files.
44+
* As a workaround, we just copy all assets next to the metadata bundle.
45+
**/
46+
task(':package:fix-metadata', () => {
47+
return src('**/*.+(html|css)', { cwd: DIST_MATERIAL })
48+
.pipe(gulpRename({dirname: ''}))
49+
.pipe(dest(DIST_RELEASE));
50+
});
3951

4052
/** Copy metatadata.json and associated d.ts files to the root of the package structure. */
4153
task(':package:metadata', () => {

0 commit comments

Comments
 (0)