Skip to content

Commit d7aa20d

Browse files
petebacondarwinIgorMinar
authored andcommitted
feat(ivy): ngcc project skeleton (angular#24897)
PR Close angular#24897
1 parent a673494 commit d7aa20d

10 files changed

Lines changed: 241 additions & 2 deletions

File tree

packages/compiler-cli/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ npm_package(
4141
"ivy-local",
4242
"release-with-framework",
4343
],
44-
deps = [":compiler-cli"],
44+
deps = [
45+
":compiler-cli",
46+
"//packages/compiler-cli/src/ngcc",
47+
],
4548
)

packages/compiler-cli/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
"main": "index.js",
66
"typings": "index.d.ts",
77
"bin": {
8+
"ivy-ngcc": "./src/ngcc/main-ngcc.js",
89
"ngc": "./src/main.js",
910
"ng-xi18n": "./src/extract_i18n.js"
1011
},
1112
"dependencies": {
1213
"reflect-metadata": "^0.1.2",
1314
"minimist": "^1.2.0",
1415
"tsickle": "^0.32.1",
15-
"chokidar": "^1.4.2"
16+
"chokidar": "^1.4.2",
17+
"convert-source-map": "^1.5.1",
18+
"magic-string": "^0.25.0",
19+
"source-map": "^0.6.1"
1620
},
1721
"peerDependencies": {
1822
"typescript": ">=2.7.2 <2.10",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
5+
6+
ts_library(
7+
name = "ngcc",
8+
srcs = glob([
9+
"*.ts",
10+
"**/*.ts",
11+
]),
12+
module_name = "@angular/compiler-cli/src/ngcc",
13+
deps = [
14+
"//packages:types",
15+
"//packages/compiler",
16+
"//packages/compiler-cli/src/ngtsc/annotations",
17+
"//packages/compiler-cli/src/ngtsc/host",
18+
"//packages/compiler-cli/src/ngtsc/metadata",
19+
"//packages/compiler-cli/src/ngtsc/transform",
20+
],
21+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Angular Compatibility Compiler (ngcc)
2+
3+
This compiler will convert `node_modules` compiled with `ngc`, into `node_modules` which
4+
appear to have been compiled with `ngtsc`.
5+
6+
This conversion will allow such "legacy" packages to be used by the Ivy rendering engine.
7+
8+
## Building
9+
10+
The project is built using Bazel:
11+
12+
```bash
13+
bazel build //packages/compiler-cli/src/ngcc
14+
```
15+
16+
## Unit Testing
17+
18+
The unit tests are built and run using Bazel:
19+
20+
```bash
21+
bazel test //packages/compiler-cli/src/ngcc/test
22+
```
23+
24+
## Integration Testing
25+
26+
There are tests that check the behaviour of the overall executable:
27+
28+
```bash
29+
bazel test //packages/compiler-cli/test/ngcc
30+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. 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+
export {mainNgcc} from './src/main';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env node
2+
/**
3+
* @license
4+
* Copyright Google Inc. All Rights Reserved.
5+
*
6+
* Use of this source code is governed by an MIT-style license that can be
7+
* found in the LICENSE file at https://angular.io/license
8+
*/
9+
10+
import {mainNgcc} from './src/main';
11+
12+
// CLI entry point
13+
if (require.main === module) {
14+
const args = process.argv.slice(2);
15+
process.exitCode = mainNgcc(args);
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. 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+
import {resolve} from 'path';
9+
10+
export function mainNgcc(args: string[]): number {
11+
const packagePath = resolve(args[0]);
12+
13+
return 0;
14+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
5+
6+
ts_library(
7+
name = "test_lib",
8+
testonly = 1,
9+
srcs = glob([
10+
"**/*.ts",
11+
]),
12+
deps = [
13+
"//packages/compiler-cli/src/ngcc",
14+
"//packages/compiler-cli/src/ngtsc/host",
15+
"//packages/compiler-cli/src/ngtsc/testing",
16+
],
17+
)
18+
19+
jasmine_node_test(
20+
name = "test",
21+
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
22+
deps = [
23+
":test_lib",
24+
"//tools/testing:node_no_angular",
25+
],
26+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("//tools:defaults.bzl", "ts_library")
2+
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
3+
4+
# Integration tests
5+
ts_library(
6+
name = "ngcc_lib",
7+
testonly = 1,
8+
srcs = glob([
9+
"**/*_spec.ts",
10+
]),
11+
deps = [
12+
"//packages/compiler-cli/src/ngcc",
13+
"//packages/compiler-cli/test:test_utils",
14+
],
15+
)
16+
17+
jasmine_node_test(
18+
name = "ngcc",
19+
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
20+
data = [
21+
"//packages/common:npm_package",
22+
"//packages/core:npm_package",
23+
],
24+
deps = [
25+
":ngcc_lib",
26+
"//tools/testing:node_no_angular",
27+
],
28+
)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. 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+
import * as fs from 'fs';
10+
import * as path from 'path';
11+
import {cat, find} from 'shelljs';
12+
13+
import {mainNgcc} from '../../src/ngcc/src/main';
14+
15+
import {TestSupport, isInBazel, setup} from '../test_support';
16+
17+
function setupNodeModules(support: TestSupport): void {
18+
const corePath = path.join(process.env.TEST_SRCDIR, 'angular/packages/core/npm_package');
19+
const commonPath = path.join(process.env.TEST_SRCDIR, 'angular/packages/common/npm_package');
20+
21+
const nodeModulesPath = path.join(support.basePath, 'node_modules');
22+
const angularCoreDirectory = path.join(nodeModulesPath, '@angular/core');
23+
const angularCommonDirectory = path.join(nodeModulesPath, '@angular/common');
24+
25+
// fs.symlinkSync(corePath, angularCoreDirectory);
26+
// fs.symlinkSync(commonPath, angularCommonDirectory);
27+
}
28+
29+
describe('ngcc behavioral tests', () => {
30+
if (!isInBazel()) {
31+
// These tests should be excluded from the non-Bazel build.
32+
return;
33+
}
34+
35+
let basePath: string;
36+
let outDir: string;
37+
let write: (fileName: string, content: string) => void;
38+
let errorSpy: jasmine.Spy&((s: string) => void);
39+
40+
function shouldExist(fileName: string) {
41+
if (!fs.existsSync(path.resolve(outDir, fileName))) {
42+
throw new Error(`Expected ${fileName} to be emitted (outDir: ${outDir})`);
43+
}
44+
}
45+
46+
function shouldNotExist(fileName: string) {
47+
if (fs.existsSync(path.resolve(outDir, fileName))) {
48+
throw new Error(`Did not expect ${fileName} to be emitted (outDir: ${outDir})`);
49+
}
50+
}
51+
52+
function getContents(fileName: string): string {
53+
shouldExist(fileName);
54+
const modulePath = path.resolve(outDir, fileName);
55+
return fs.readFileSync(modulePath, 'utf8');
56+
}
57+
58+
function writeConfig(
59+
tsconfig: string =
60+
'{"extends": "./tsconfig-base.json", "angularCompilerOptions": {"enableIvy": "ngtsc"}}') {
61+
write('tsconfig.json', tsconfig);
62+
}
63+
64+
beforeEach(() => {
65+
errorSpy = jasmine.createSpy('consoleError').and.callFake(console.error);
66+
const support = setup();
67+
basePath = support.basePath;
68+
outDir = path.join(basePath, 'built');
69+
process.chdir(basePath);
70+
write = (fileName: string, content: string) => { support.write(fileName, content); };
71+
72+
setupNodeModules(support);
73+
});
74+
75+
it('should run ngcc without errors', () => {
76+
const nodeModulesPath = path.join(basePath, 'node_modules');
77+
console.error(nodeModulesPath);
78+
const commonPath = path.join(nodeModulesPath, '@angular/common');
79+
const exitCode = mainNgcc([commonPath]);
80+
81+
console.warn(find('node_modules_ngtsc').filter(p => p.endsWith('.js') || p.endsWith('map')));
82+
83+
console.warn(cat('node_modules_ngtsc/@angular/common/fesm2015/common.js').stdout);
84+
console.warn(cat('node_modules_ngtsc/@angular/common/fesm2015/common.js.map').stdout);
85+
86+
expect(exitCode).toBe(0);
87+
});
88+
});

0 commit comments

Comments
 (0)