refactor(ivy): move ngcc into a higher level folder (#29092)

PR Close #29092
This commit is contained in:
Pete Bacon Darwin 2019-03-20 13:47:58 +00:00 committed by Matias Niemelä
parent cf4718c366
commit a770aa231d
55 changed files with 108 additions and 95 deletions

View File

@ -34,9 +34,9 @@ ng_package(
visibility = [
"//packages/bazel/test/ng_package:__pkg__",
"//packages/compiler-cli/integrationtest:__pkg__",
"//packages/compiler-cli/ngcc/test:__pkg__",
"//packages/compiler-cli/test:__pkg__",
"//packages/compiler-cli/test/diagnostics:__pkg__",
"//packages/compiler-cli/test/ngcc:__pkg__",
"//packages/compiler-cli/test/transformers:__pkg__",
"//packages/compiler/test:__pkg__",
"//packages/language-service/test:__pkg__",

View File

@ -60,6 +60,6 @@ npm_package(
],
deps = [
":compiler-cli",
"//packages/compiler-cli/src/ngcc",
"//packages/compiler-cli/ngcc",
],
)

View File

@ -10,7 +10,7 @@ This conversion will allow such "legacy" packages to be used by the Ivy renderin
The project is built using Bazel:
```bash
yarn bazel build //packages/compiler-cli/src/ngcc
yarn bazel build //packages/compiler-cli/ngcc
```
## Unit Testing
@ -18,7 +18,7 @@ yarn bazel build //packages/compiler-cli/src/ngcc
The unit tests are built and run using Bazel:
```bash
yarn bazel test //packages/compiler-cli/src/ngcc/test
yarn bazel test //packages/compiler-cli/ngcc/test
```
## Integration Testing
@ -26,5 +26,5 @@ yarn bazel test //packages/compiler-cli/src/ngcc/test
There are tests that check the behavior of the overall executable:
```bash
yarn bazel test //packages/compiler-cli/test/ngcc
yarn bazel test //packages/compiler-cli/ngcc/test:integration
```

View File

@ -10,13 +10,13 @@ import * as path from 'canonical-path';
import * as fs from 'fs';
import * as ts from 'typescript';
import {BaseDefDecoratorHandler, ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, PipeDecoratorHandler, ReferencesRegistry, ResourceLoader} from '../../../ngtsc/annotations';
import {CycleAnalyzer, ImportGraph} from '../../../ngtsc/cycles';
import {AbsoluteModuleStrategy, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, NOOP_DEFAULT_IMPORT_RECORDER, ReferenceEmitter} from '../../../ngtsc/imports';
import {PartialEvaluator} from '../../../ngtsc/partial_evaluator';
import {AbsoluteFsPath, LogicalFileSystem} from '../../../ngtsc/path';
import {LocalModuleScopeRegistry, MetadataDtsModuleScopeResolver} from '../../../ngtsc/scope';
import {CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../../ngtsc/transform';
import {BaseDefDecoratorHandler, ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, PipeDecoratorHandler, ReferencesRegistry, ResourceLoader} from '../../../src/ngtsc/annotations';
import {CycleAnalyzer, ImportGraph} from '../../../src/ngtsc/cycles';
import {AbsoluteModuleStrategy, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, NOOP_DEFAULT_IMPORT_RECORDER, ReferenceEmitter} from '../../../src/ngtsc/imports';
import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator';
import {AbsoluteFsPath, LogicalFileSystem} from '../../../src/ngtsc/path';
import {LocalModuleScopeRegistry, MetadataDtsModuleScopeResolver} from '../../../src/ngtsc/scope';
import {CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../../src/ngtsc/transform';
import {DecoratedClass} from '../host/decorated_class';
import {NgccReflectionHost} from '../host/ngcc_host';
import {isDefined} from '../utils';

View File

@ -7,9 +7,9 @@
*/
import * as ts from 'typescript';
import {ReferencesRegistry} from '../../../ngtsc/annotations';
import {Reference} from '../../../ngtsc/imports';
import {Declaration} from '../../../ngtsc/reflection';
import {ReferencesRegistry} from '../../../src/ngtsc/annotations';
import {Reference} from '../../../src/ngtsc/imports';
import {Declaration} from '../../../src/ngtsc/reflection';
import {NgccReflectionHost} from '../host/ngcc_host';
import {isDefined} from '../utils';

View File

@ -7,9 +7,9 @@
*/
import * as ts from 'typescript';
import {ReferencesRegistry} from '../../../ngtsc/annotations';
import {Reference} from '../../../ngtsc/imports';
import {Declaration, ReflectionHost} from '../../../ngtsc/reflection';
import {ReferencesRegistry} from '../../../src/ngtsc/annotations';
import {Reference} from '../../../src/ngtsc/imports';
import {Declaration, ReflectionHost} from '../../../src/ngtsc/reflection';
import {hasNameIdentifier} from '../utils';
/**

View File

@ -7,7 +7,7 @@
*/
import * as ts from 'typescript';
import {Declaration} from '../../../ngtsc/reflection';
import {Declaration} from '../../../src/ngtsc/reflection';
import {NgccReflectionHost} from '../host/ngcc_host';
import {hasNameIdentifier, isDefined} from '../utils';
import {NgccReferencesRegistry} from './ngcc_references_registry';

View File

@ -7,7 +7,7 @@
*/
import * as ts from 'typescript';
import {Decorator} from '../../../ngtsc/reflection';
import {Decorator} from '../../../src/ngtsc/reflection';
/**
* A simple container that holds the details of a decorated class that has been

View File

@ -8,7 +8,7 @@
import * as ts from 'typescript';
import {ClassMember, ClassMemberKind, CtorParameter, Decorator, Import, TypeScriptReflectionHost, reflectObjectLiteral} from '../../../ngtsc/reflection';
import {ClassMember, ClassMemberKind, CtorParameter, Decorator, Import, TypeScriptReflectionHost, reflectObjectLiteral} from '../../../src/ngtsc/reflection';
import {BundleProgram} from '../packages/bundle_program';
import {findAll, getNameText, isDefined} from '../utils';

View File

@ -8,7 +8,7 @@
import * as ts from 'typescript';
import {ClassMember, ClassMemberKind, Declaration, Decorator, FunctionDefinition, Parameter, reflectObjectLiteral} from '../../../ngtsc/reflection';
import {ClassMember, ClassMemberKind, Declaration, Decorator, FunctionDefinition, Parameter, reflectObjectLiteral} from '../../../src/ngtsc/reflection';
import {getNameText, hasNameIdentifier} from '../utils';
import {Esm2015ReflectionHost, ParamInfo, getPropertyValueFromSymbol, isAssignmentStatement} from './esm2015_host';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as ts from 'typescript';
import {ReflectionHost} from '../../../ngtsc/reflection';
import {ReflectionHost} from '../../../src/ngtsc/reflection';
import {DecoratedClass} from './decorated_class';
export const PRE_R3_MARKER = '__PRE_R3__';

View File

@ -7,7 +7,7 @@
*/
import * as ts from 'typescript';
import {AbsoluteFsPath} from '../../../ngtsc/path';
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
import {BundleProgram, makeBundleProgram} from './bundle_program';
import {EntryPoint, EntryPointFormat} from './entry_point';

View File

@ -13,7 +13,7 @@ import {CompiledClass} from '../analysis/decoration_analyzer';
import {RedundantDecoratorMap, Renderer, stripExtension} from './renderer';
import {EntryPointBundle} from '../packages/entry_point_bundle';
import {ExportInfo} from '../analysis/private_declarations_analyzer';
import {isDtsPath} from '../../../ngtsc/util/src/typescript';
import {isDtsPath} from '../../../src/ngtsc/util/src/typescript';
export class EsmRenderer extends Renderer {
constructor(

View File

@ -7,7 +7,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ImportRewriter, validateAndRewriteCoreSymbol} from '../../../ngtsc/imports';
import {ImportRewriter, validateAndRewriteCoreSymbol} from '../../../src/ngtsc/imports';
export class NgccFlatImportRewriter implements ImportRewriter {
shouldImportSymbol(symbol: string, specifier: string): boolean {

View File

@ -15,7 +15,7 @@ import * as ts from 'typescript';
import {NoopImportRewriter, ImportRewriter, R3SymbolsImportRewriter, NOOP_DEFAULT_IMPORT_RECORDER} from '@angular/compiler-cli/src/ngtsc/imports';
import {CompileResult} from '@angular/compiler-cli/src/ngtsc/transform';
import {translateStatement, translateType, ImportManager} from '../../../ngtsc/translator';
import {translateStatement, translateType, ImportManager} from '../../../src/ngtsc/translator';
import {NgccFlatImportRewriter} from './ngcc_import_rewriter';
import {CompiledClass, CompiledFile, DecorationAnalyses} from '../analysis/decoration_analyzer';
import {ModuleWithProvidersInfo, ModuleWithProvidersAnalyses} from '../analysis/module_with_providers_analyzer';

View File

@ -5,17 +5,19 @@ package(default_visibility = ["//visibility:public"])
ts_library(
name = "test_lib",
testonly = True,
srcs = glob([
"**/*.ts",
]),
srcs = glob(
["**/*.ts"],
exclude = ["integration/**/*.ts"],
),
deps = [
"//packages/compiler-cli/src/ngcc",
"//packages/compiler-cli/ngcc",
"//packages/compiler-cli/src/ngtsc/imports",
"//packages/compiler-cli/src/ngtsc/partial_evaluator",
"//packages/compiler-cli/src/ngtsc/path",
"//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/testing",
"//packages/compiler-cli/src/ngtsc/transform",
"//packages/compiler-cli/test:test_utils",
"@npm//@types/convert-source-map",
"@npm//@types/mock-fs",
"@npm//canonical-path",
@ -34,3 +36,34 @@ jasmine_node_test(
"@npm//convert-source-map",
],
)
ts_library(
name = "integration_lib",
testonly = True,
srcs = glob(
["integration/**/*.ts"],
),
deps = [
"//packages/compiler-cli/ngcc",
"//packages/compiler-cli/test:test_utils",
"@npm//@types/mock-fs",
],
)
jasmine_node_test(
name = "integration",
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
data = [
"//packages/common:npm_package",
"//packages/core:npm_package",
"@npm//rxjs",
],
deps = [
":integration_lib",
"//packages/common",
"//tools/testing:node_no_angular",
"@npm//canonical-path",
"@npm//convert-source-map",
"@npm//shelljs",
],
)

View File

@ -7,9 +7,9 @@
*/
import * as ts from 'typescript';
import {AbsoluteFsPath} from '../../../ngtsc/path';
import {Decorator} from '../../../ngtsc/reflection';
import {DecoratorHandler, DetectResult} from '../../../ngtsc/transform';
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
import {Decorator} from '../../../src/ngtsc/reflection';
import {DecoratorHandler, DetectResult} from '../../../src/ngtsc/transform';
import {CompiledClass, DecorationAnalyses, DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';

View File

@ -8,7 +8,7 @@
import * as ts from 'typescript';
import {Reference} from '../../../ngtsc/imports';
import {Reference} from '../../../src/ngtsc/imports';
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
import {PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer';
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';

View File

@ -8,10 +8,10 @@
import * as ts from 'typescript';
import {Reference} from '../../../ngtsc/imports';
import {PartialEvaluator} from '../../../ngtsc/partial_evaluator';
import {TypeScriptReflectionHost} from '../../../ngtsc/reflection';
import {getDeclaration, makeProgram} from '../../../ngtsc/testing/in_memory_typescript';
import {Reference} from '../../../src/ngtsc/imports';
import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator';
import {TypeScriptReflectionHost} from '../../../src/ngtsc/reflection';
import {getDeclaration, makeProgram} from '../../../src/ngtsc/testing/in_memory_typescript';
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
describe('NgccReferencesRegistry', () => {

View File

@ -7,13 +7,13 @@
*/
import * as ts from 'typescript';
import {AbsoluteFsPath} from '../../../ngtsc/path';
import {makeProgram} from '../../../ngtsc/testing/in_memory_typescript';
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
import {makeProgram} from '../../../src/ngtsc/testing/in_memory_typescript';
import {BundleProgram} from '../../src/packages/bundle_program';
import {EntryPointFormat} from '../../src/packages/entry_point';
import {EntryPointBundle} from '../../src/packages/entry_point_bundle';
export {getDeclaration} from '../../../ngtsc/testing/in_memory_typescript';
export {getDeclaration} from '../../../src/ngtsc/testing/in_memory_typescript';

View File

@ -8,7 +8,7 @@
import * as ts from 'typescript';
import {ClassMemberKind, Import} from '../../../ngtsc/reflection';
import {ClassMemberKind, Import} from '../../../src/ngtsc/reflection';
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils';

View File

@ -8,7 +8,7 @@
import * as ts from 'typescript';
import {ClassMemberKind, Import} from '../../../ngtsc/reflection';
import {ClassMemberKind, Import} from '../../../src/ngtsc/reflection';
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';

View File

@ -8,7 +8,7 @@
import * as ts from 'typescript';
import {ClassMemberKind, Import} from '../../../ngtsc/reflection';
import {ClassMemberKind, Import} from '../../../src/ngtsc/reflection';
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils';

View File

@ -8,7 +8,7 @@
import * as ts from 'typescript';
import {ClassMemberKind, Import} from '../../../ngtsc/reflection';
import {ClassMemberKind, Import} from '../../../src/ngtsc/reflection';
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';

View File

@ -9,7 +9,7 @@
import * as ts from 'typescript';
import {CtorParameter} from '../../../ngtsc/reflection';
import {CtorParameter} from '../../../src/ngtsc/reflection';
/**
* Check that a given list of `CtorParameter`s has `typeValueReference`s of specific `ts.Identifier`

View File

@ -11,8 +11,8 @@ import * as mockFs from 'mock-fs';
import {join} from 'path';
const Module = require('module');
import {mainNgcc} from '../../src/ngcc/src/main';
import {getAngularPackagesFromRunfiles} from '../runfile_helpers';
import {mainNgcc} from '../../src/main';
import {getAngularPackagesFromRunfiles, resolveNpmTreeArtifact} from '../../../test/runfile_helpers';
describe('ngcc main()', () => {
beforeEach(createMockFileSystem);
@ -41,7 +41,10 @@ describe('ngcc main()', () => {
function createMockFileSystem() {
mockFs({'/node_modules/@angular': loadAngularPackages()});
mockFs({
'/node_modules/@angular': loadAngularPackages(),
'/node_modules/rxjs': loadDirectory(resolveNpmTreeArtifact('rxjs', 'index.js')),
});
spyOn(Module, '_resolveFilename').and.callFake(mockResolve);
}
@ -84,22 +87,31 @@ interface Directory {
[pathSegment: string]: string|Directory;
}
function mockResolve(p: string): string|null {
if (existsSync(p)) {
const stat = statSync(p);
function mockResolve(request: string): string|null {
if (existsSync(request)) {
const stat = statSync(request);
if (stat.isFile()) {
return p;
return request;
} else if (stat.isDirectory()) {
const pIndex = mockResolve(p + '/index');
const pIndex = mockResolve(request + '/index');
if (pIndex && existsSync(pIndex)) {
return pIndex;
}
}
}
for (const ext of ['.js', '.d.ts']) {
if (existsSync(p + ext)) {
return p + ext;
if (existsSync(request + ext)) {
return request + ext;
}
}
if (request.indexOf('/node_modules') === 0) {
// We already tried adding node_modules so give up.
return null;
} else {
return mockResolve(join('/node_modules', request));
}
}
function loadPackage(packageName: string) {
return JSON.parse(readFileSync(`/node_modules/${packageName}/package.json`, 'utf8'));
}

View File

@ -8,7 +8,7 @@
import {dirname} from 'canonical-path';
import MagicString from 'magic-string';
import * as ts from 'typescript';
import {AbsoluteFsPath} from '../../../ngtsc/path';
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';

View File

@ -8,7 +8,7 @@
import {dirname} from 'canonical-path';
import MagicString from 'magic-string';
import * as ts from 'typescript';
import {AbsoluteFsPath} from '../../../ngtsc/path';
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
import {DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
import {SwitchMarkerAnalyzer} from '../../src/analysis/switch_marker_analyzer';

View File

@ -5,7 +5,7 @@
"main": "index.js",
"typings": "index.d.ts",
"bin": {
"ivy-ngcc": "./src/ngcc/main-ngcc.js",
"ivy-ngcc": "./ngcc/main-ngcc.js",
"ngc": "./src/main.js",
"ng-xi18n": "./src/extract_i18n.js"
},

View File

@ -12,6 +12,7 @@ ts_library(
],
visibility = [
":__subpackages__",
"//packages/compiler-cli/ngcc/test:__subpackages__",
"//packages/language-service/test:__subpackages__",
],
deps = [

View File

@ -1,33 +0,0 @@
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
# Integration tests
ts_library(
name = "ngcc_lib",
testonly = True,
srcs = glob([
"**/*_spec.ts",
]),
deps = [
"//packages/compiler-cli/src/ngcc",
"//packages/compiler-cli/test:test_utils",
"@npm//@types/mock-fs",
],
)
jasmine_node_test(
name = "ngcc",
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
data = [
"//packages/common:npm_package",
"//packages/core:npm_package",
],
deps = [
":ngcc_lib",
"//tools/testing:node_no_angular",
"@npm//@types/mock-fs",
"@npm//canonical-path",
"@npm//convert-source-map",
"@npm//shelljs",
"@npm//yargs",
],
)

View File

@ -40,9 +40,9 @@ ng_package(
visibility = [
"//packages/bazel/test/ng_package:__pkg__",
"//packages/compiler-cli/integrationtest:__pkg__",
"//packages/compiler-cli/ngcc/test:__pkg__",
"//packages/compiler-cli/test:__pkg__",
"//packages/compiler-cli/test/diagnostics:__pkg__",
"//packages/compiler-cli/test/ngcc:__pkg__",
"//packages/compiler-cli/test/transformers:__pkg__",
"//packages/compiler/test:__pkg__",
"//packages/language-service/test:__pkg__",