refactor(compiler): split compiler and core (#18683)
After this, neither @angular/compiler nor @angular/comnpiler-cli depend on @angular/core. This add a duplication of some interfaces and enums which is stored in @angular/compiler/src/core.ts BREAKING CHANGE: - `@angular/platform-server` now additionally depends on `@angular/platform-browser-dynamic` as a peer dependency. PR Close #18683
This commit is contained in:

committed by
Miško Hevery

parent
a0ca01d580
commit
0cc77b4a69
@ -10,7 +10,6 @@ ts_library(
|
||||
module_name = "@angular/compiler-cli",
|
||||
deps = [
|
||||
"//packages/compiler",
|
||||
"//packages/core",
|
||||
"//packages/tsc-wrapped",
|
||||
],
|
||||
tsconfig = ":tsconfig-build.json",
|
||||
|
@ -16,8 +16,7 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^2.0.2",
|
||||
"@angular/compiler": "0.0.0-PLACEHOLDER",
|
||||
"@angular/core": "0.0.0-PLACEHOLDER"
|
||||
"@angular/compiler": "0.0.0-PLACEHOLDER"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -11,7 +11,6 @@
|
||||
* Intended to be used in a build step.
|
||||
*/
|
||||
import * as compiler from '@angular/compiler';
|
||||
import {MissingTranslationStrategy} from '@angular/core';
|
||||
import {AngularCompilerOptions, NgcCliOptions} from '@angular/tsc-wrapped';
|
||||
import {readFileSync} from 'fs';
|
||||
import * as ts from 'typescript';
|
||||
@ -78,17 +77,17 @@ export class CodeGenerator {
|
||||
}
|
||||
transContent = readFileSync(cliOptions.i18nFile, 'utf8');
|
||||
}
|
||||
let missingTranslation = MissingTranslationStrategy.Warning;
|
||||
let missingTranslation = compiler.core.MissingTranslationStrategy.Warning;
|
||||
if (cliOptions.missingTranslation) {
|
||||
switch (cliOptions.missingTranslation) {
|
||||
case 'error':
|
||||
missingTranslation = MissingTranslationStrategy.Error;
|
||||
missingTranslation = compiler.core.MissingTranslationStrategy.Error;
|
||||
break;
|
||||
case 'warning':
|
||||
missingTranslation = MissingTranslationStrategy.Warning;
|
||||
missingTranslation = compiler.core.MissingTranslationStrategy.Warning;
|
||||
break;
|
||||
case 'ignore':
|
||||
missingTranslation = MissingTranslationStrategy.Ignore;
|
||||
missingTranslation = compiler.core.MissingTranslationStrategy.Ignore;
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
@ -96,7 +95,7 @@ export class CodeGenerator {
|
||||
}
|
||||
}
|
||||
if (!transContent) {
|
||||
missingTranslation = MissingTranslationStrategy.Ignore;
|
||||
missingTranslation = compiler.core.MissingTranslationStrategy.Ignore;
|
||||
}
|
||||
const {compiler: aotCompiler} = compiler.createAotCompiler(ngCompilerHost, {
|
||||
translations: transContent,
|
||||
|
@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import {AotSummaryResolver, CompileMetadataResolver, CompilePipeSummary, CompilerConfig, DEFAULT_INTERPOLATION_CONFIG, DirectiveNormalizer, DirectiveResolver, DomElementSchemaRegistry, HtmlParser, InterpolationConfig, NgAnalyzedModules, NgModuleResolver, ParseTreeResult, PipeResolver, ResourceLoader, StaticReflector, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, SummaryResolver, analyzeNgModules, extractProgramSymbols} from '@angular/compiler';
|
||||
import {ViewEncapsulation, ɵConsole as Console} from '@angular/core';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
@ -12,8 +12,8 @@
|
||||
* This API should be stable for NG 2. It can be removed in NG 4..., but should be replaced by
|
||||
* something else.
|
||||
*/
|
||||
import {AotCompilerHost, StaticReflector, StaticSymbol} from '@angular/compiler';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {AotCompilerHost, StaticReflector, StaticSymbol, core} from '@angular/compiler';
|
||||
|
||||
|
||||
// We cannot depend directly to @angular/router.
|
||||
type Route = any;
|
||||
@ -168,8 +168,10 @@ function _extractLazyRoutesFromStaticModule(
|
||||
/**
|
||||
* Get the NgModule Metadata of a symbol.
|
||||
*/
|
||||
function _getNgModuleMetadata(staticSymbol: StaticSymbol, reflector: StaticReflector): NgModule {
|
||||
const ngModules = reflector.annotations(staticSymbol).filter((s: any) => s instanceof NgModule);
|
||||
function _getNgModuleMetadata(
|
||||
staticSymbol: StaticSymbol, reflector: StaticReflector): core.NgModule {
|
||||
const ngModules =
|
||||
reflector.annotations(staticSymbol).filter((s: any) => core.createNgModule.isTypeOf(s));
|
||||
if (ngModules.length === 0) {
|
||||
throw new Error(`${staticSymbol.name} is not an NgModule`);
|
||||
}
|
||||
|
@ -6,8 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AotCompiler, AotCompilerHost, AotCompilerOptions, GeneratedFile, NgAnalyzedModules, createAotCompiler, getParseErrors, isSyntaxError, toTypeScript} from '@angular/compiler';
|
||||
import {MissingTranslationStrategy} from '@angular/core';
|
||||
import {AotCompiler, AotCompilerHost, AotCompilerOptions, GeneratedFile, NgAnalyzedModules, core, createAotCompiler, getParseErrors, isSyntaxError, toTypeScript} from '@angular/compiler';
|
||||
import {createBundleIndexHost} from '@angular/tsc-wrapped';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
@ -337,14 +336,14 @@ export function createProgram(
|
||||
|
||||
// Compute the AotCompiler options
|
||||
function getAotCompilerOptions(options: CompilerOptions): AotCompilerOptions {
|
||||
let missingTranslation = MissingTranslationStrategy.Warning;
|
||||
let missingTranslation = core.MissingTranslationStrategy.Warning;
|
||||
|
||||
switch (options.i18nInMissingTranslations) {
|
||||
case 'ignore':
|
||||
missingTranslation = MissingTranslationStrategy.Ignore;
|
||||
missingTranslation = core.MissingTranslationStrategy.Ignore;
|
||||
break;
|
||||
case 'error':
|
||||
missingTranslation = MissingTranslationStrategy.Error;
|
||||
missingTranslation = core.MissingTranslationStrategy.Error;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -358,7 +357,7 @@ function getAotCompilerOptions(options: CompilerOptions): AotCompilerOptions {
|
||||
} else {
|
||||
// No translations are provided, ignore any errors
|
||||
// We still go through i18n to remove i18n attributes
|
||||
missingTranslation = MissingTranslationStrategy.Ignore;
|
||||
missingTranslation = core.MissingTranslationStrategy.Ignore;
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -12,7 +12,7 @@
|
||||
* Entry point for all public APIs of the common package.
|
||||
*/
|
||||
|
||||
import {Version} from '@angular/core';
|
||||
import {Version} from '@angular/compiler';
|
||||
/**
|
||||
* @stable
|
||||
*/
|
||||
|
@ -8,12 +8,7 @@
|
||||
"module": "commonjs",
|
||||
"outDir": "../../dist/packages/compiler-cli",
|
||||
"paths": {
|
||||
"@angular/core": ["../../dist/packages/core"],
|
||||
"@angular/common": ["../../dist/packages/common"],
|
||||
"@angular/compiler": ["../../dist/packages/compiler"],
|
||||
"@angular/http": ["../../dist/packages/http"],
|
||||
"@angular/platform-server": ["../../dist/packages/platform-server"],
|
||||
"@angular/platform-browser": ["../../dist/packages/platform-browser"],
|
||||
"@angular/tsc-wrapped": ["../../dist/packages-dist/tsc-wrapped"]
|
||||
},
|
||||
"rootDir": ".",
|
||||
|
Reference in New Issue
Block a user