fix(compiler-cli): remove unused CLI private exports (#33242)

These exports are no longer used by the CLI since 7.1.0.  Since major versions of the CLI are now locked to major versions of the framework, a CLI user will not be able to use FW 9.0+ on an outdated version (<7.1.0) of the CLI that uses these old APIs.

PR Close #33242
This commit is contained in:
Charles Lyding 2019-10-17 11:36:04 -04:00 committed by atscott
parent feb5f27d09
commit fc8eecad3f
8 changed files with 2 additions and 417 deletions

View File

@ -21,10 +21,8 @@ export * from './src/transformers/entry_points';
export * from './src/perform_compile';
export * from './src/tooling';
// TODO(tbosch): remove this once cli 1.5 is fully released,
// and usages in G3 are changed to `CompilerOptions`.
// TODO(tbosch): remove this once usages in G3 are changed to `CompilerOptions`
export {CompilerOptions as AngularCompilerOptions} from './src/transformers/api';
export {NgTools_InternalApi_NG_2 as __NGTOOLS_PRIVATE_API_2} from './src/ngtools_api';
export {ngToTsDiagnostic} from './src/transformers/util';
export {NgTscPlugin} from './src/ngtsc/tsc_plugin';

View File

@ -1,8 +0,0 @@
/**
* @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 {CompilerHost, CustomTransformers, Diagnostic, EmitFlags, Program, createCompilerHost, createProgram, formatDiagnostics} from './src/ngtools_api2';

View File

@ -1,133 +0,0 @@
/**
* @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
*/
/**
* This is a private API for the ngtools toolkit.
*
* This API should be stable for NG 2. It can be removed in NG 4..., but should be replaced by
* something else.
*/
/**
*********************************************************************
* Changes to this file need to be approved by the Angular CLI team. *
*********************************************************************
*/
import * as ts from 'typescript';
import {CompilerOptions} from './transformers/api';
import {getOriginalReferences} from './transformers/compiler_host';
import {createProgram} from './transformers/entry_points';
export interface NgTools_InternalApi_NG2_CodeGen_Options {
basePath: string;
compilerOptions: ts.CompilerOptions;
program: ts.Program;
host: ts.CompilerHost;
angularCompilerOptions: CompilerOptions;
// i18n options.
i18nFormat?: string;
i18nFile?: string;
locale?: string;
missingTranslation?: string;
readResource: (fileName: string) => Promise<string>;
// Every new property under this line should be optional.
}
export interface NgTools_InternalApi_NG2_ListLazyRoutes_Options {
program: ts.Program;
host: ts.CompilerHost;
angularCompilerOptions: CompilerOptions;
entryModule: string;
// Every new property under this line should be optional.
}
export interface NgTools_InternalApi_NG_2_LazyRouteMap { [route: string]: string; }
export interface NgTools_InternalApi_NG2_ExtractI18n_Options {
basePath: string;
compilerOptions: ts.CompilerOptions;
program: ts.Program;
host: ts.CompilerHost;
angularCompilerOptions: CompilerOptions;
i18nFormat?: string;
readResource: (fileName: string) => Promise<string>;
// Every new property under this line should be optional.
locale?: string;
outFile?: string;
}
/**
* @internal
* @deprecatd Use ngtools_api2 instead!
*/
export class NgTools_InternalApi_NG_2 {
/**
* @internal
*/
static codeGen(options: NgTools_InternalApi_NG2_CodeGen_Options): Promise<any> {
throw throwNotSupportedError();
}
/**
* @internal
*/
static listLazyRoutes(options: NgTools_InternalApi_NG2_ListLazyRoutes_Options):
NgTools_InternalApi_NG_2_LazyRouteMap {
// TODO(tbosch): Also throwNotSupportedError once Angular CLI 1.5.1 ships,
// as we only needed this to support Angular CLI 1.5.0 rc.*
const ngProgram = createProgram({
rootNames: options.program.getRootFileNames(),
options: {...options.angularCompilerOptions, collectAllErrors: true},
host: options.host
});
const lazyRoutes = ngProgram.listLazyRoutes(options.entryModule);
// reset the referencedFiles that the ng.Program added to the SourceFiles
// as the host might be caching the source files!
for (const sourceFile of options.program.getSourceFiles()) {
const originalReferences = getOriginalReferences(sourceFile);
if (originalReferences) {
sourceFile.referencedFiles = originalReferences;
}
}
const result: NgTools_InternalApi_NG_2_LazyRouteMap = {};
lazyRoutes.forEach(lazyRoute => {
const route = lazyRoute.route;
const referencedFilePath = lazyRoute.referencedModule.filePath;
if (result[route] && result[route] != referencedFilePath) {
throw new Error(
`Duplicated path in loadChildren detected: "${route}" is used in 2 loadChildren, ` +
`but they point to different modules "(${result[route]} and ` +
`"${referencedFilePath}"). Webpack cannot distinguish on context and would fail to ` +
'load the proper one.');
}
result[route] = referencedFilePath;
});
return result;
}
/**
* @internal
*/
static extractI18n(options: NgTools_InternalApi_NG2_ExtractI18n_Options): Promise<any> {
throw throwNotSupportedError();
}
}
function throwNotSupportedError() {
throw new Error(`Please update @angular/cli. Angular 5+ requires at least Angular CLI 1.5+`);
}

View File

@ -1,149 +0,0 @@
/**
* @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
*/
/**
* This is a private API for @ngtools/webpack. This API should be stable for NG 5.
*
* It contains copies of the interfaces needed and wrapper functions to ensure that
* they are not broken accidentally.
*
* Once the ngc api is public and stable, this can be removed.
*/
/**
*********************************************************************
* Changes to this file need to be approved by the Angular CLI team. *
*********************************************************************
*/
import {ParseSourceSpan} from '@angular/compiler';
import * as ts from 'typescript';
import {formatDiagnostics as formatDiagnosticsOrig} from './perform_compile';
import {createCompilerHost as createCompilerOrig} from './transformers/compiler_host';
import {createProgram as createProgramOrig} from './transformers/program';
// Interfaces from ./transformers/api;
export interface Diagnostic {
messageText: string;
span?: ParseSourceSpan;
category: ts.DiagnosticCategory;
code: number;
source: 'angular';
}
export interface CompilerOptions extends ts.CompilerOptions {
basePath?: string;
skipMetadataEmit?: boolean;
strictMetadataEmit?: boolean;
skipTemplateCodegen?: boolean;
flatModuleOutFile?: string;
flatModuleId?: string;
generateCodeForLibraries?: boolean;
annotateForClosureCompiler?: boolean;
annotationsAs?: 'decorators'|'static fields';
trace?: boolean;
disableExpressionLowering?: boolean;
i18nOutLocale?: string;
i18nOutFormat?: string;
i18nOutFile?: string;
i18nInFormat?: string;
i18nInLocale?: string;
i18nInFile?: string;
i18nInMissingTranslations?: 'error'|'warning'|'ignore';
preserveWhitespaces?: boolean;
disableTypeScriptVersionCheck?: boolean;
}
export interface CompilerHost extends ts.CompilerHost {
moduleNameToFileName?(moduleName: string, containingFile?: string): string|null;
fileNameToModuleName?(importedFilePath: string, containingFilePath: string): string;
resourceNameToFileName?(resourceName: string, containingFilePath: string): string|null;
toSummaryFileName?(fileName: string, referringSrcFileName: string): string;
fromSummaryFileName?(fileName: string, referringLibFileName: string): string;
readResource?(fileName: string): Promise<string>|string;
}
export enum EmitFlags {
DTS = 1 << 0,
JS = 1 << 1,
Metadata = 1 << 2,
I18nBundle = 1 << 3,
Codegen = 1 << 4,
Default = DTS | JS | Codegen,
All = DTS | JS | Metadata | I18nBundle | Codegen,
}
export interface CustomTransformers {
beforeTs?: ts.TransformerFactory<ts.SourceFile>[];
afterTs?: ts.TransformerFactory<ts.SourceFile>[];
}
export interface TsEmitArguments {
program: ts.Program;
host: CompilerHost;
options: CompilerOptions;
targetSourceFile?: ts.SourceFile;
writeFile?: ts.WriteFileCallback;
cancellationToken?: ts.CancellationToken;
emitOnlyDtsFiles?: boolean;
customTransformers?: ts.CustomTransformers;
}
export interface TsEmitCallback { (args: TsEmitArguments): ts.EmitResult; }
export interface LazyRoute {
module: {name: string, filePath: string};
route: string;
referencedModule: {name: string, filePath: string};
}
export interface Program {
getTsProgram(): ts.Program;
getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken):
ReadonlyArray<ts.Diagnostic|Diagnostic>;
getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
ReadonlyArray<ts.Diagnostic>;
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<Diagnostic>;
getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
ReadonlyArray<ts.Diagnostic>;
getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken):
ReadonlyArray<ts.Diagnostic|Diagnostic>;
loadNgStructureAsync(): Promise<void>;
listLazyRoutes(entryRoute?: string): LazyRoute[];
emit({emitFlags, cancellationToken, customTransformers, emitCallback}: {
emitFlags?: EmitFlags,
cancellationToken?: ts.CancellationToken,
customTransformers?: CustomTransformers,
emitCallback?: TsEmitCallback
}): ts.EmitResult;
}
// Wrapper for createProgram.
export function createProgram(
{rootNames, options, host, oldProgram}:
{rootNames: string[], options: CompilerOptions, host: CompilerHost, oldProgram?: Program}):
Program {
return createProgramOrig({rootNames, options, host, oldProgram: oldProgram as any});
}
// Wrapper for createCompilerHost.
export function createCompilerHost(
{options, tsHost = ts.createCompilerHost(options, true)}:
{options: CompilerOptions, tsHost?: ts.CompilerHost}): CompilerHost {
return createCompilerOrig({options, tsHost});
}
// Wrapper for formatDiagnostics.
export type Diagnostics = ReadonlyArray<ts.Diagnostic|Diagnostic>;
export function formatDiagnostics(diags: Diagnostics): string {
return formatDiagnosticsOrig(diags);
}

View File

@ -98,36 +98,6 @@ jasmine_node_test(
],
)
# ngctools_api_spec
ts_library(
name = "ngtools_api_lib",
testonly = True,
srcs = [
"ngtools_api_spec.ts",
],
deps = [
":test_utils",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/private/testing",
"@npm//typescript",
],
)
jasmine_node_test(
name = "ngtools_api",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
"//packages/core:npm_package",
"//packages/router:npm_package",
],
deps = [
":ngtools_api_lib",
"//packages/core",
"//tools/testing:node",
],
)
# perform_watch_spec
ts_library(
name = "perform_watch_lib",

View File

@ -1,92 +0,0 @@
/**
* @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
*/
import {__NGTOOLS_PRIVATE_API_2 as NgTools_InternalApi_NG_2} from '@angular/compiler-cli';
import {ivyEnabled} from '@angular/private/testing';
import * as path from 'path';
import * as ts from 'typescript';
import {TestSupport, setup} from './test_support';
describe('ngtools_api (deprecated)', () => {
let testSupport: TestSupport;
beforeEach(() => { testSupport = setup(); });
function createProgram(rootNames: string[]) {
const options = testSupport.createCompilerOptions({enableIvy: ivyEnabled});
const host = ts.createCompilerHost(options, true);
const program =
ts.createProgram(rootNames.map(p => path.resolve(testSupport.basePath, p)), options, host);
return {program, host, options};
}
function writeSomeRoutes() {
testSupport.writeFiles({
'src/main.ts': `
import {NgModule, Component} from '@angular/core';
import {RouterModule} from '@angular/router';
// Component with metadata errors.
@Component(() => {if (1==1) return null as any;})
export class ErrorComp2 {}
@NgModule({
declarations: [ErrorComp2],
imports: [RouterModule.forRoot([{loadChildren: './child#ChildModule'}])]
})
export class MainModule {}
`,
'src/child.ts': `
import {NgModule} from '@angular/core';
import {RouterModule} from '@angular/router';
@NgModule({
imports: [RouterModule.forChild([{loadChildren: './child2#ChildModule2'}])]
})
export class ChildModule {}
`,
'src/child2.ts': `
import {NgModule} from '@angular/core';
@NgModule()
export class ChildModule2 {}
`,
});
}
it('should list lazy routes recursively', () => {
writeSomeRoutes();
const {program, host, options} =
createProgram(['src/main.ts', 'src/child.ts', 'src/child2.ts']);
const routes = NgTools_InternalApi_NG_2.listLazyRoutes({
program,
host,
angularCompilerOptions: options,
entryModule: 'src/main#MainModule',
});
expect(routes).toEqual({
'./child#ChildModule': path.posix.join(testSupport.basePath, 'src/child.ts'),
'./child2#ChildModule2': path.posix.join(testSupport.basePath, 'src/child2.ts'),
});
});
it('should allow to emit the program after analyzing routes', () => {
writeSomeRoutes();
const {program, host, options} =
createProgram(['src/main.ts', 'src/child.ts', 'src/child2.ts']);
NgTools_InternalApi_NG_2.listLazyRoutes({
program,
host,
angularCompilerOptions: options,
entryModule: 'src/main#MainModule',
});
program.emit();
testSupport.shouldExist('built/src/main.js');
});
});

View File

@ -10,7 +10,7 @@ import {CustomTransformers, Program, defaultGatherDiagnostics} from '@angular/co
import * as api from '@angular/compiler-cli/src/transformers/api';
import * as ts from 'typescript';
import {createCompilerHost, createProgram} from '../../ngtools2';
import {createCompilerHost, createProgram} from '../../index';
import {main, mainDiagnosticsForTest, readNgcCommandLineAndConfiguration} from '../../src/main';
import {AbsoluteFsPath, FileSystem, NgtscCompilerHost, absoluteFrom, getFileSystem} from '../../src/ngtsc/file_system';
import {Folder, MockFileSystem} from '../../src/ngtsc/file_system/testing';

View File

@ -30,7 +30,6 @@
"files": [
"index.ts",
"ngtools2.ts",
"src/main.ts",
"src/extract_i18n.ts",
"src/language_services.ts",