refactor(ivy): move the flat module index generator to its own package (#27743)

This commit moves the FlatIndexGenerator to its own package, in preparation
to expand its capabilities and support re-exporting of private declarations
from NgModules.

PR Close #27743
This commit is contained in:
Alex Rickabaugh 2018-12-07 14:37:32 -08:00 committed by Kara Erickson
parent f6c91c5a5a
commit 37b716b298
10 changed files with 60 additions and 19 deletions

View File

@ -26,6 +26,7 @@ ts_library(
"//packages/compiler", "//packages/compiler",
"//packages/compiler-cli/src/ngtsc/annotations", "//packages/compiler-cli/src/ngtsc/annotations",
"//packages/compiler-cli/src/ngtsc/diagnostics", "//packages/compiler-cli/src/ngtsc/diagnostics",
"//packages/compiler-cli/src/ngtsc/entry_point",
"//packages/compiler-cli/src/ngtsc/metadata", "//packages/compiler-cli/src/ngtsc/metadata",
"//packages/compiler-cli/src/ngtsc/shims", "//packages/compiler-cli/src/ngtsc/shims",
"//packages/compiler-cli/src/ngtsc/switch", "//packages/compiler-cli/src/ngtsc/switch",

View File

@ -0,0 +1,18 @@
package(default_visibility = ["//visibility:public"])
load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "entry_point",
srcs = glob([
"index.ts",
"src/**/*.ts",
]),
module_name = "@angular/compiler-cli/src/ngtsc/entry_point",
deps = [
"//packages/compiler-cli/src/ngtsc/shims",
"//packages/compiler-cli/src/ngtsc/util",
"@ngdeps//@types/node",
"@ngdeps//typescript",
],
)

View File

@ -0,0 +1,9 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export {FlatIndexGenerator} from './src/generator';

View File

@ -6,11 +6,13 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
/// <reference types="node" />
import * as path from 'path'; import * as path from 'path';
import * as ts from 'typescript'; import * as ts from 'typescript';
import {ShimGenerator} from './host'; import {ShimGenerator} from '../../shims';
import {isNonDeclarationTsFile} from './util'; import {isNonDeclarationTsPath} from '../../util/src/typescript';
export class FlatIndexGenerator implements ShimGenerator { export class FlatIndexGenerator implements ShimGenerator {
readonly flatIndexPath: string; readonly flatIndexPath: string;
@ -28,7 +30,7 @@ export class FlatIndexGenerator implements ShimGenerator {
// If there's only one .ts file in the program, it's the entry. Otherwise, look for the shortest // If there's only one .ts file in the program, it's the entry. Otherwise, look for the shortest
// (in terms of characters in the filename) file that ends in /index.ts. The second behavior is // (in terms of characters in the filename) file that ends in /index.ts. The second behavior is
// deprecated; users should always explicitly specify a single .ts entrypoint. // deprecated; users should always explicitly specify a single .ts entrypoint.
const tsFiles = files.filter(isNonDeclarationTsFile); const tsFiles = files.filter(file => isNonDeclarationTsPath(file));
if (tsFiles.length === 1) { if (tsFiles.length === 1) {
return new FlatIndexGenerator(flatIndexPath, tsFiles[0], moduleName); return new FlatIndexGenerator(flatIndexPath, tsFiles[0], moduleName);
} else { } else {

View File

@ -15,9 +15,10 @@ import {nocollapseHack} from '../transformers/nocollapse_hack';
import {ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, NoopReferencesRegistry, PipeDecoratorHandler, ResourceLoader, SelectorScopeRegistry} from './annotations'; import {ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, NoopReferencesRegistry, PipeDecoratorHandler, ResourceLoader, SelectorScopeRegistry} from './annotations';
import {BaseDefDecoratorHandler} from './annotations/src/base_def'; import {BaseDefDecoratorHandler} from './annotations/src/base_def';
import {FlatIndexGenerator} from './entry_point';
import {TypeScriptReflectionHost} from './metadata'; import {TypeScriptReflectionHost} from './metadata';
import {FileResourceLoader, HostResourceLoader} from './resource_loader'; import {FileResourceLoader, HostResourceLoader} from './resource_loader';
import {FactoryGenerator, FactoryInfo, FlatIndexGenerator, GeneratedShimsHostWrapper, ShimGenerator, SummaryGenerator, generatedFactoryTransform} from './shims'; import {FactoryGenerator, FactoryInfo, GeneratedShimsHostWrapper, ShimGenerator, SummaryGenerator, generatedFactoryTransform} from './shims';
import {ivySwitchTransform} from './switch'; import {ivySwitchTransform} from './switch';
import {IvyCompilation, ivyTransformFactory} from './transform'; import {IvyCompilation, ivyTransformFactory} from './transform';
import {TypeCheckContext, TypeCheckProgramHost} from './typecheck'; import {TypeCheckContext, TypeCheckProgramHost} from './typecheck';

View File

@ -9,6 +9,5 @@
/// <reference types="node" /> /// <reference types="node" />
export {FactoryGenerator, FactoryInfo, generatedFactoryTransform} from './src/factory_generator'; export {FactoryGenerator, FactoryInfo, generatedFactoryTransform} from './src/factory_generator';
export {FlatIndexGenerator} from './src/flat_index_generator';
export {GeneratedShimsHostWrapper, ShimGenerator} from './src/host'; export {GeneratedShimsHostWrapper, ShimGenerator} from './src/host';
export {SummaryGenerator} from './src/summary_generator'; export {SummaryGenerator} from './src/summary_generator';

View File

@ -10,9 +10,10 @@ import * as path from 'path';
import * as ts from 'typescript'; import * as ts from 'typescript';
import {relativePathBetween} from '../../util/src/path'; import {relativePathBetween} from '../../util/src/path';
import {isNonDeclarationTsPath} from '../../util/src/typescript';
import {ShimGenerator} from './host'; import {ShimGenerator} from './host';
import {generatedModuleName, isNonDeclarationTsFile} from './util'; import {generatedModuleName} from './util';
const TS_DTS_SUFFIX = /(\.d)?\.ts$/; const TS_DTS_SUFFIX = /(\.d)?\.ts$/;
const STRIP_NG_FACTORY = /(.*)NgFactory$/; const STRIP_NG_FACTORY = /(.*)NgFactory$/;
@ -87,7 +88,7 @@ export class FactoryGenerator implements ShimGenerator {
static forRootFiles(files: ReadonlyArray<string>): FactoryGenerator { static forRootFiles(files: ReadonlyArray<string>): FactoryGenerator {
const map = new Map<string, string>(); const map = new Map<string, string>();
files.filter(sourceFile => isNonDeclarationTsFile(sourceFile)) files.filter(sourceFile => isNonDeclarationTsPath(sourceFile))
.forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngfactory.ts'), sourceFile)); .forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngfactory.ts'), sourceFile));
return new FactoryGenerator(map); return new FactoryGenerator(map);
} }

View File

@ -8,8 +8,10 @@
import * as ts from 'typescript'; import * as ts from 'typescript';
import {isNonDeclarationTsPath} from '../../util/src/typescript';
import {ShimGenerator} from './host'; import {ShimGenerator} from './host';
import {generatedModuleName, isNonDeclarationTsFile} from './util'; import {generatedModuleName} from './util';
export class SummaryGenerator implements ShimGenerator { export class SummaryGenerator implements ShimGenerator {
private constructor(private map: Map<string, string>) {} private constructor(private map: Map<string, string>) {}
@ -61,7 +63,7 @@ export class SummaryGenerator implements ShimGenerator {
static forRootFiles(files: ReadonlyArray<string>): SummaryGenerator { static forRootFiles(files: ReadonlyArray<string>): SummaryGenerator {
const map = new Map<string, string>(); const map = new Map<string, string>();
files.filter(sourceFile => isNonDeclarationTsFile(sourceFile)) files.filter(sourceFile => isNonDeclarationTsPath(sourceFile))
.forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngsummary.ts'), sourceFile)); .forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngsummary.ts'), sourceFile));
return new SummaryGenerator(map); return new SummaryGenerator(map);
} }

View File

@ -6,16 +6,6 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import * as path from 'path';
import * as ts from 'typescript';
const TS_FILE = /\.tsx?$/;
const D_TS_FILE = /\.d\.ts$/;
export function isNonDeclarationTsFile(file: string): boolean {
return TS_FILE.exec(file) !== null && D_TS_FILE.exec(file) === null;
}
export function generatedModuleName( export function generatedModuleName(
originalModuleName: string, originalFileName: string, genSuffix: string): string { originalModuleName: string, originalFileName: string, genSuffix: string): string {
let moduleName: string; let moduleName: string;

View File

@ -0,0 +1,18 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
const TS = /\.tsx?$/i;
const D_TS = /\.d\.ts$/i;
export function isDtsPath(filePath: string): boolean {
return D_TS.test(filePath);
}
export function isNonDeclarationTsPath(filePath: string): boolean {
return TS.test(filePath) && !D_TS.test(filePath);
}