fix(packages): use ES modules for primary build (#11120)
This commit is contained in:

committed by
Victor Berchet

parent
8cb1046ce9
commit
979657989b
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @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 './init';
|
||||
import './animate_spec';
|
||||
import './basic_spec';
|
||||
import './entry_components_spec';
|
||||
import './i18n_spec';
|
||||
import './ng_module_spec';
|
||||
import './projection_spec';
|
||||
import './query_spec';
|
@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
target: 'node',
|
||||
entry: './test/all_spec.js',
|
||||
output: {
|
||||
filename: './all_spec.js'
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.js']
|
||||
},
|
||||
};
|
@ -16,9 +16,9 @@ import {AngularCompilerOptions, NgcCliOptions} from '@angular/tsc-wrapped';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {CompileMetadataResolver, DirectiveNormalizer, DomElementSchemaRegistry, HtmlParser, Lexer, NgModuleCompiler, Parser, StyleCompiler, TemplateParser, TypeScriptEmitter, ViewCompiler} from './compiler_private';
|
||||
import {Console} from './core_private';
|
||||
import {PathMappedReflectorHost} from './path_mapped_reflector_host';
|
||||
import {CompileMetadataResolver, DirectiveNormalizer, DomElementSchemaRegistry, HtmlParser, Lexer, NgModuleCompiler, Parser, StyleCompiler, TemplateParser, TypeScriptEmitter, ViewCompiler} from './private_import_compiler';
|
||||
import {Console} from './private_import_core';
|
||||
import {ReflectorHost, ReflectorHostContext} from './reflector_host';
|
||||
import {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabilities';
|
||||
import {StaticReflector, StaticSymbol} from './static_reflector';
|
||||
@ -159,7 +159,7 @@ export class CodeGenerator {
|
||||
const staticReflector = new StaticReflector(reflectorHost);
|
||||
StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
||||
const htmlParser =
|
||||
new compiler.i18n.HtmlParser(new HtmlParser(), transContent, cliOptions.i18nFormat);
|
||||
new compiler.I18NHtmlParser(new HtmlParser(), transContent, cliOptions.i18nFormat);
|
||||
const config = new compiler.CompilerConfig({
|
||||
genDebugInfo: options.debug === true,
|
||||
defaultEncapsulation: ViewEncapsulation.Emulated,
|
||||
|
@ -1,55 +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 {__compiler_private__ as _c} from '@angular/compiler';
|
||||
|
||||
export type AssetUrl = _c.AssetUrl;
|
||||
export var AssetUrl: typeof _c.AssetUrl = _c.AssetUrl;
|
||||
|
||||
export type ImportGenerator = _c.ImportGenerator;
|
||||
export var ImportGenerator: typeof _c.ImportGenerator = _c.ImportGenerator;
|
||||
|
||||
export type CompileMetadataResolver = _c.CompileMetadataResolver;
|
||||
export var CompileMetadataResolver: typeof _c.CompileMetadataResolver = _c.CompileMetadataResolver;
|
||||
|
||||
export type HtmlParser = _c.HtmlParser;
|
||||
export var HtmlParser: typeof _c.HtmlParser = _c.HtmlParser;
|
||||
|
||||
export type ParseError = _c.ParseError;
|
||||
export var ParseError: typeof _c.ParseError = _c.ParseError;
|
||||
|
||||
export type InterpolationConfig = _c.InterpolationConfig;
|
||||
export var InterpolationConfig: typeof _c.InterpolationConfig = _c.InterpolationConfig;
|
||||
|
||||
export type DirectiveNormalizer = _c.DirectiveNormalizer;
|
||||
export var DirectiveNormalizer: typeof _c.DirectiveNormalizer = _c.DirectiveNormalizer;
|
||||
|
||||
export type Lexer = _c.Lexer;
|
||||
export var Lexer: typeof _c.Lexer = _c.Lexer;
|
||||
|
||||
export type Parser = _c.Parser;
|
||||
export var Parser: typeof _c.Parser = _c.Parser;
|
||||
|
||||
export type TemplateParser = _c.TemplateParser;
|
||||
export var TemplateParser: typeof _c.TemplateParser = _c.TemplateParser;
|
||||
|
||||
export type DomElementSchemaRegistry = _c.DomElementSchemaRegistry;
|
||||
export var DomElementSchemaRegistry: typeof _c.DomElementSchemaRegistry =
|
||||
_c.DomElementSchemaRegistry;
|
||||
|
||||
export type StyleCompiler = _c.StyleCompiler;
|
||||
export var StyleCompiler: typeof _c.StyleCompiler = _c.StyleCompiler;
|
||||
|
||||
export type ViewCompiler = _c.ViewCompiler;
|
||||
export var ViewCompiler: typeof _c.ViewCompiler = _c.ViewCompiler;
|
||||
|
||||
export type NgModuleCompiler = _c.NgModuleCompiler;
|
||||
export var NgModuleCompiler: typeof _c.NgModuleCompiler = _c.NgModuleCompiler;
|
||||
|
||||
export type TypeScriptEmitter = _c.TypeScriptEmitter;
|
||||
export var TypeScriptEmitter: typeof _c.TypeScriptEmitter = _c.TypeScriptEmitter;
|
@ -21,8 +21,8 @@ import {ComponentMetadata, NgModuleMetadata, ViewEncapsulation} from '@angular/c
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
import * as tsc from '@angular/tsc-wrapped';
|
||||
import {CompileMetadataResolver, DirectiveNormalizer, DomElementSchemaRegistry, HtmlParser, Lexer, NgModuleCompiler, Parser, StyleCompiler, TemplateParser, TypeScriptEmitter, ViewCompiler, ParseError} from './compiler_private';
|
||||
import {Console} from './core_private';
|
||||
import {CompileMetadataResolver, DirectiveNormalizer, DomElementSchemaRegistry, HtmlParser, Lexer, NgModuleCompiler, Parser, StyleCompiler, TemplateParser, TypeScriptEmitter, ViewCompiler, ParseError} from './private_import_compiler';
|
||||
import {Console} from './private_import_core';
|
||||
import {ReflectorHost, ReflectorHostContext} from './reflector_host';
|
||||
import {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabilities';
|
||||
import {StaticReflector, StaticSymbol} from './static_reflector';
|
||||
@ -30,25 +30,25 @@ import {StaticReflector, StaticSymbol} from './static_reflector';
|
||||
function extract(
|
||||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
|
||||
program: ts.Program, host: ts.CompilerHost) {
|
||||
const htmlParser = new compiler.i18n.HtmlParser(new HtmlParser());
|
||||
const htmlParser = new compiler.I18NHtmlParser(new HtmlParser());
|
||||
const extractor = Extractor.create(ngOptions, cliOptions.i18nFormat, program, host, htmlParser);
|
||||
const bundlePromise: Promise<compiler.i18n.MessageBundle> = extractor.extract();
|
||||
const bundlePromise: Promise<compiler.MessageBundle> = extractor.extract();
|
||||
|
||||
return (bundlePromise).then(messageBundle => {
|
||||
let ext: string;
|
||||
let serializer: compiler.i18n.Serializer;
|
||||
let serializer: compiler.Serializer;
|
||||
const format = (cliOptions.i18nFormat || 'xlf').toLowerCase();
|
||||
|
||||
switch (format) {
|
||||
case 'xmb':
|
||||
ext = 'xmb';
|
||||
serializer = new compiler.i18n.Xmb();
|
||||
serializer = new compiler.Xmb();
|
||||
break;
|
||||
case 'xliff':
|
||||
case 'xlf':
|
||||
default:
|
||||
ext = 'xlf';
|
||||
serializer = new compiler.i18n.Xliff(htmlParser, compiler.DEFAULT_INTERPOLATION_CONFIG);
|
||||
serializer = new compiler.Xliff(htmlParser, compiler.DEFAULT_INTERPOLATION_CONFIG);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ const GENERATED_FILES = /\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/;
|
||||
export class Extractor {
|
||||
constructor(
|
||||
private program: ts.Program, public host: ts.CompilerHost,
|
||||
private staticReflector: StaticReflector, private messageBundle: compiler.i18n.MessageBundle,
|
||||
private staticReflector: StaticReflector, private messageBundle: compiler.MessageBundle,
|
||||
private reflectorHost: ReflectorHost, private metadataResolver: CompileMetadataResolver,
|
||||
private directiveNormalizer: DirectiveNormalizer,
|
||||
private compiler: compiler.OfflineCompiler) {}
|
||||
@ -97,7 +97,7 @@ export class Extractor {
|
||||
return result;
|
||||
}
|
||||
|
||||
extract(): Promise<compiler.i18n.MessageBundle> {
|
||||
extract(): Promise<compiler.MessageBundle> {
|
||||
const filePaths =
|
||||
this.program.getSourceFiles().map(sf => sf.fileName).filter(f => !GENERATED_FILES.test(f));
|
||||
const fileMetas = filePaths.map((filePath) => this.readFileMetadata(filePath));
|
||||
@ -145,7 +145,7 @@ export class Extractor {
|
||||
|
||||
static create(
|
||||
options: tsc.AngularCompilerOptions, translationsFormat: string, program: ts.Program,
|
||||
compilerHost: ts.CompilerHost, htmlParser: compiler.i18n.HtmlParser,
|
||||
compilerHost: ts.CompilerHost, htmlParser: compiler.I18NHtmlParser,
|
||||
reflectorHostContext?: ReflectorHostContext): Extractor {
|
||||
const resourceLoader: compiler.ResourceLoader = {
|
||||
get: (s: string) => {
|
||||
@ -184,7 +184,7 @@ export class Extractor {
|
||||
new NgModuleCompiler(), new TypeScriptEmitter(reflectorHost), null, null);
|
||||
|
||||
// TODO(vicb): implicit tags & attributes
|
||||
let messageBundle = new compiler.i18n.MessageBundle(htmlParser, [], {});
|
||||
let messageBundle = new compiler.MessageBundle(htmlParser, [], {});
|
||||
|
||||
return new Extractor(
|
||||
program, compilerHost, staticReflector, messageBundle, reflectorHost, resolver, normalizer,
|
||||
|
54
modules/@angular/compiler-cli/src/private_import_compiler.ts
Normal file
54
modules/@angular/compiler-cli/src/private_import_compiler.ts
Normal file
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @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 {__compiler_private__ as _} from '@angular/compiler';
|
||||
|
||||
export type AssetUrl = typeof _._AssetUrl;
|
||||
export var AssetUrl: typeof _.AssetUrl = _.AssetUrl;
|
||||
|
||||
export type ImportGenerator = typeof _._ImportGenerator;
|
||||
export var ImportGenerator: typeof _.ImportGenerator = _.ImportGenerator;
|
||||
|
||||
export type CompileMetadataResolver = typeof _._CompileMetadataResolver;
|
||||
export var CompileMetadataResolver: typeof _.CompileMetadataResolver = _.CompileMetadataResolver;
|
||||
|
||||
export type HtmlParser = typeof _._HtmlParser;
|
||||
export var HtmlParser: typeof _.HtmlParser = _.HtmlParser;
|
||||
|
||||
export type ParseError = typeof _._ParseError;
|
||||
export var ParseError: typeof _.ParseError = _.ParseError;
|
||||
|
||||
export type InterpolationConfig = typeof _._InterpolationConfig;
|
||||
export var InterpolationConfig: typeof _.InterpolationConfig = _.InterpolationConfig;
|
||||
|
||||
export type DirectiveNormalizer = typeof _._DirectiveNormalizer;
|
||||
export var DirectiveNormalizer: typeof _.DirectiveNormalizer = _.DirectiveNormalizer;
|
||||
|
||||
export type Lexer = typeof _._Lexer;
|
||||
export var Lexer: typeof _.Lexer = _.Lexer;
|
||||
|
||||
export type Parser = typeof _._Parser;
|
||||
export var Parser: typeof _.Parser = _.Parser;
|
||||
|
||||
export type TemplateParser = typeof _._TemplateParser;
|
||||
export var TemplateParser: typeof _.TemplateParser = _.TemplateParser;
|
||||
|
||||
export type DomElementSchemaRegistry = typeof _._DomElementSchemaRegistry;
|
||||
export var DomElementSchemaRegistry: typeof _.DomElementSchemaRegistry = _.DomElementSchemaRegistry;
|
||||
|
||||
export type StyleCompiler = typeof _._StyleCompiler;
|
||||
export var StyleCompiler: typeof _.StyleCompiler = _.StyleCompiler;
|
||||
|
||||
export type ViewCompiler = typeof _._ViewCompiler;
|
||||
export var ViewCompiler: typeof _.ViewCompiler = _.ViewCompiler;
|
||||
|
||||
export type NgModuleCompiler = typeof _._NgModuleCompiler;
|
||||
export var NgModuleCompiler: typeof _.NgModuleCompiler = _.NgModuleCompiler;
|
||||
|
||||
export type TypeScriptEmitter = typeof _._TypeScriptEmitter;
|
||||
export var TypeScriptEmitter: typeof _.TypeScriptEmitter = _.TypeScriptEmitter;
|
@ -6,17 +6,19 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {__core_private__ as r, __core_private_types__ as types} from '@angular/core';
|
||||
import {__core_private__ as r} from '@angular/core';
|
||||
|
||||
export declare let _compiler_cli_core_private_types: types;
|
||||
|
||||
export type ReflectorReader = typeof _compiler_cli_core_private_types.ReflectorReader;
|
||||
export type ReflectorReader = typeof r._ReflectorReader;
|
||||
export var ReflectorReader: typeof r.ReflectorReader = r.ReflectorReader;
|
||||
|
||||
export type ReflectionCapabilities = typeof _compiler_cli_core_private_types.ReflectionCapabilities;
|
||||
export type ReflectionCapabilities = typeof r._ReflectionCapabilities;
|
||||
export var ReflectionCapabilities: typeof r.ReflectionCapabilities = r.ReflectionCapabilities;
|
||||
|
||||
export type Console = typeof _compiler_cli_core_private_types.Console;
|
||||
export type Console = typeof r._Console;
|
||||
export var Console: typeof r.Console = r.Console;
|
||||
|
||||
export var reflector: typeof r.reflector = r.reflector;
|
||||
|
||||
export type SetterFn = typeof r._SetterFn;
|
||||
export type GetterFn = typeof r._GetterFn;
|
||||
export type MethodFn = typeof r._MethodFn;
|
@ -11,7 +11,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AssetUrl, ImportGenerator} from './compiler_private';
|
||||
import {AssetUrl, ImportGenerator} from './private_import_compiler';
|
||||
import {StaticReflectorHost, StaticSymbol} from './static_reflector';
|
||||
|
||||
const EXT = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
||||
@ -59,6 +59,7 @@ export class ReflectorHost implements StaticReflectorHost, ImportGenerator {
|
||||
getCanonicalFileName(fileName: string): string { return fileName; }
|
||||
|
||||
protected resolve(m: string, containingFile: string) {
|
||||
m = m.replace(EXT, '');
|
||||
const resolved =
|
||||
ts.resolveModuleName(m, containingFile.replace(/\\/g, '/'), this.options, this.context)
|
||||
.resolvedModule;
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ReflectionCapabilities, reflector} from './core_private';
|
||||
import {GetterFn, MethodFn, ReflectionCapabilities, SetterFn, reflector} from './private_import_core';
|
||||
import {StaticReflector} from './static_reflector';
|
||||
|
||||
export class StaticAndDynamicReflectionCapabilities {
|
||||
@ -38,9 +38,9 @@ export class StaticAndDynamicReflectionCapabilities {
|
||||
return isStaticType(typeOrFunc) ? this.staticDelegate.propMetadata(typeOrFunc) :
|
||||
this.dynamicDelegate.propMetadata(typeOrFunc);
|
||||
}
|
||||
getter(name: string) { return this.dynamicDelegate.getter(name); }
|
||||
setter(name: string) { return this.dynamicDelegate.setter(name); }
|
||||
method(name: string) { return this.dynamicDelegate.method(name); }
|
||||
getter(name: string): GetterFn { return this.dynamicDelegate.getter(name); }
|
||||
setter(name: string): SetterFn { return this.dynamicDelegate.setter(name); }
|
||||
method(name: string): MethodFn { return this.dynamicDelegate.method(name); }
|
||||
importUri(type: any): string { return this.staticDelegate.importUri(type); }
|
||||
resolveIdentifier(name: string, moduleUrl: string, runtime: any) {
|
||||
return this.staticDelegate.resolveIdentifier(name, moduleUrl, runtime);
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {AttributeMetadata, ComponentMetadata, ContentChildMetadata, ContentChildrenMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, HostMetadata, InjectMetadata, InjectableMetadata, InputMetadata, NgModuleMetadata, OptionalMetadata, OutputMetadata, PipeMetadata, QueryMetadata, SelfMetadata, SkipSelfMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
||||
|
||||
import {ReflectorReader} from './core_private';
|
||||
import {ReflectorReader} from './private_import_core';
|
||||
|
||||
const SUPPORTED_SCHEMA_VERSION = 1;
|
||||
|
||||
|
@ -6,10 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ReflectorHostContext} from '@angular/compiler-cli/src/reflector_host';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {ReflectorHostContext} from '../src/reflector_host';
|
||||
|
||||
export type Entry = string | Directory;
|
||||
|
||||
export interface Directory { [name: string]: Entry; }
|
||||
@ -61,6 +60,15 @@ export class MockContext implements ReflectorHostContext {
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
getDirectories(path: string): string[] {
|
||||
const dir = this.getEntry(path);
|
||||
if (typeof dir !== 'object') {
|
||||
return [];
|
||||
} else {
|
||||
return Object.keys(dir).filter(key => typeof dir[key] === 'object');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function normalize(parts: string[]): string[] {
|
||||
@ -117,4 +125,6 @@ export class MockCompilerHost implements ts.CompilerHost {
|
||||
useCaseSensitiveFileNames(): boolean { return false; }
|
||||
|
||||
getNewLine(): string { return '\n'; }
|
||||
|
||||
getDirectories(path: string): string[] { return this.context.getDirectories(path); }
|
||||
}
|
||||
|
@ -176,28 +176,28 @@ describe('StaticReflector', () => {
|
||||
expect(simplify(noContext, ({__symbolic: 'binop', operator: '==', left: 0x22, right: 0x22})))
|
||||
.toBe(0x22 == 0x22);
|
||||
expect(simplify(noContext, ({__symbolic: 'binop', operator: '==', left: 0x22, right: 0xF0})))
|
||||
.toBe(0x22 == 0xF0);
|
||||
.toBe(0x22 as any == 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify !=', () => {
|
||||
expect(simplify(noContext, ({__symbolic: 'binop', operator: '!=', left: 0x22, right: 0x22})))
|
||||
.toBe(0x22 != 0x22);
|
||||
expect(simplify(noContext, ({__symbolic: 'binop', operator: '!=', left: 0x22, right: 0xF0})))
|
||||
.toBe(0x22 != 0xF0);
|
||||
.toBe(0x22 as any != 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify ===', () => {
|
||||
expect(simplify(noContext, ({__symbolic: 'binop', operator: '===', left: 0x22, right: 0x22})))
|
||||
.toBe(0x22 === 0x22);
|
||||
expect(simplify(noContext, ({__symbolic: 'binop', operator: '===', left: 0x22, right: 0xF0})))
|
||||
.toBe(0x22 === 0xF0);
|
||||
.toBe(0x22 as any === 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify !==', () => {
|
||||
expect(simplify(noContext, ({__symbolic: 'binop', operator: '!==', left: 0x22, right: 0x22})))
|
||||
.toBe(0x22 !== 0x22);
|
||||
expect(simplify(noContext, ({__symbolic: 'binop', operator: '!==', left: 0x22, right: 0xF0})))
|
||||
.toBe(0x22 !== 0xF0);
|
||||
.toBe(0x22 as any !== 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify >', () => {
|
||||
|
@ -18,7 +18,8 @@
|
||||
"rootDir": ".",
|
||||
"sourceRoot": ".",
|
||||
"outDir": "../../../dist/packages-dist/compiler-cli",
|
||||
"declaration": true
|
||||
"declaration": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["integrationtest"],
|
||||
"files": [
|
Reference in New Issue
Block a user