build: remove references to tsc-wrapped
(#19298)
With this commit `ngc` is used instead of `tsc-wrapped` for collecting metadata and tsickle rewriting and `tsc-wrapped` is removed from the repository. `@angular/tsc-wrapped@5` is now deprecated and is no longer used, updated, or maintained as part as of Angular 5.x.x. `@angular/tsc-wrapped@4` is still maintained and required by Angular 4.x.x and will be maintained as long as 4.x.x is in LTS. PR Close #19298
This commit is contained in:

committed by
Igor Minar

parent
4c73b52d5c
commit
f96142cd7c
@ -9,8 +9,7 @@ ts_library(
|
||||
]),
|
||||
module_name = "@angular/compiler-cli",
|
||||
deps = [
|
||||
"//packages/compiler",
|
||||
"//packages/tsc-wrapped",
|
||||
"//packages/compiler"
|
||||
],
|
||||
tsconfig = ":tsconfig-build.json",
|
||||
)
|
||||
|
@ -112,7 +112,7 @@ with the one already used in the plugin for TypeScript typechecking and emit.
|
||||
|
||||
## Design
|
||||
At a high level, this program
|
||||
- collects static metadata about the sources using the `tsc-wrapped` package
|
||||
- collects static metadata about the sources
|
||||
- uses the `OfflineCompiler` from `@angular/compiler` to codegen additional `.ts` files
|
||||
- these `.ts` files are written to the `genDir` path, then compiled together with the application.
|
||||
|
||||
@ -130,7 +130,7 @@ $ ./scripts/ci/offline_compiler_test.sh
|
||||
|
||||
# Recompile @angular/core module (needs to use tsc-ext to keep the metadata)
|
||||
$ export NODE_PATH=${NODE_PATH}:$(pwd)/dist/all:$(pwd)/dist/tools
|
||||
$ node dist/tools/@angular/tsc-wrapped/src/main -p packages/core/tsconfig-build.json
|
||||
$ node dist/tools/@angular/compiler-cli/src/main -p packages/core/tsconfig-build.json
|
||||
|
||||
# Iterate on the test
|
||||
$ cd /tmp/wherever/e2e_test.1464388257/
|
||||
|
@ -17,10 +17,7 @@ var rxjsLocation = normalize('../../node_modules/rxjs');
|
||||
var tslibLocation = normalize('../../node_modules/tslib');
|
||||
var esm = 'esm/';
|
||||
|
||||
var locations = {
|
||||
'tsc-wrapped': normalize('../../dist/tools/@angular') + '/',
|
||||
'compiler-cli': normalize('../../dist/packages') + '/'
|
||||
};
|
||||
var locations = {'compiler-cli': normalize('../../dist/packages') + '/'};
|
||||
|
||||
var esm_suffixes = {};
|
||||
|
||||
@ -30,11 +27,6 @@ function normalize(fileName) {
|
||||
|
||||
function resolve(id, from) {
|
||||
// console.log('Resolve id:', id, 'from', from)
|
||||
if (id == '@angular/tsc-wrapped') {
|
||||
// Hack to restrict the import to not include the index of @angular/tsc-wrapped so we don't
|
||||
// rollup tsickle.
|
||||
return locations['tsc-wrapped'] + 'tsc-wrapped/src/collector.js';
|
||||
}
|
||||
var match = m.exec(id);
|
||||
if (match) {
|
||||
var packageName = match[1];
|
||||
|
@ -14,8 +14,7 @@ import 'reflect-metadata';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
import * as assert from 'assert';
|
||||
import {tsc} from '@angular/tsc-wrapped/src/tsc';
|
||||
import {__NGTOOLS_PRIVATE_API_2} from '@angular/compiler-cli';
|
||||
import {__NGTOOLS_PRIVATE_API_2, readConfiguration} from '@angular/compiler-cli';
|
||||
|
||||
const glob = require('glob');
|
||||
|
||||
@ -50,14 +49,14 @@ function codeGenTest(forceError = false) {
|
||||
const readResources: string[] = [];
|
||||
const wroteFiles: string[] = [];
|
||||
|
||||
const config = tsc.readConfiguration(project, basePath);
|
||||
const delegateHost = ts.createCompilerHost(config.parsed.options, true);
|
||||
const config = readConfiguration(project);
|
||||
const delegateHost = ts.createCompilerHost(config.options, true);
|
||||
const host: ts.CompilerHost = Object.assign(
|
||||
{}, delegateHost,
|
||||
{writeFile: (fileName: string, ...rest: any[]) => { wroteFiles.push(fileName); }});
|
||||
const program = ts.createProgram(config.parsed.fileNames, config.parsed.options, host);
|
||||
const program = ts.createProgram(config.rootNames, config.options, host);
|
||||
|
||||
config.ngOptions.basePath = basePath;
|
||||
config.options.basePath = basePath;
|
||||
|
||||
console.log(`>>> running codegen for ${project}`);
|
||||
if (forceError) {
|
||||
@ -66,9 +65,9 @@ function codeGenTest(forceError = false) {
|
||||
return __NGTOOLS_PRIVATE_API_2
|
||||
.codeGen({
|
||||
basePath,
|
||||
compilerOptions: config.parsed.options, program, host,
|
||||
compilerOptions: config.options, program, host,
|
||||
|
||||
angularCompilerOptions: config.ngOptions,
|
||||
angularCompilerOptions: config.options,
|
||||
|
||||
// i18n options.
|
||||
i18nFormat: 'xlf',
|
||||
@ -129,21 +128,21 @@ function i18nTest() {
|
||||
const readResources: string[] = [];
|
||||
const wroteFiles: string[] = [];
|
||||
|
||||
const config = tsc.readConfiguration(project, basePath);
|
||||
const delegateHost = ts.createCompilerHost(config.parsed.options, true);
|
||||
const config = readConfiguration(project);
|
||||
const delegateHost = ts.createCompilerHost(config.options, true);
|
||||
const host: ts.CompilerHost = Object.assign(
|
||||
{}, delegateHost,
|
||||
{writeFile: (fileName: string, ...rest: any[]) => { wroteFiles.push(fileName); }});
|
||||
const program = ts.createProgram(config.parsed.fileNames, config.parsed.options, host);
|
||||
const program = ts.createProgram(config.rootNames, config.options, host);
|
||||
|
||||
config.ngOptions.basePath = basePath;
|
||||
config.options.basePath = basePath;
|
||||
|
||||
console.log(`>>> running i18n extraction for ${project}`);
|
||||
return __NGTOOLS_PRIVATE_API_2
|
||||
.extractI18n({
|
||||
basePath,
|
||||
compilerOptions: config.parsed.options, program, host,
|
||||
angularCompilerOptions: config.ngOptions,
|
||||
compilerOptions: config.options, program, host,
|
||||
angularCompilerOptions: config.options,
|
||||
i18nFormat: 'xlf',
|
||||
locale: undefined,
|
||||
outFile: undefined,
|
||||
@ -193,18 +192,14 @@ function lazyRoutesTest() {
|
||||
const basePath = path.join(__dirname, '../ngtools_src');
|
||||
const project = path.join(basePath, 'tsconfig-build.json');
|
||||
|
||||
const config = tsc.readConfiguration(project, basePath);
|
||||
const host = ts.createCompilerHost(config.parsed.options, true);
|
||||
const program = ts.createProgram(config.parsed.fileNames, config.parsed.options, host);
|
||||
const config = readConfiguration(project);
|
||||
const host = ts.createCompilerHost(config.options, true);
|
||||
const program = ts.createProgram(config.rootNames, config.options, host);
|
||||
|
||||
config.ngOptions.basePath = basePath;
|
||||
config.options.basePath = basePath;
|
||||
|
||||
const lazyRoutes = __NGTOOLS_PRIVATE_API_2.listLazyRoutes({
|
||||
program,
|
||||
host,
|
||||
angularCompilerOptions: config.ngOptions,
|
||||
entryModule: 'app.module#AppModule'
|
||||
});
|
||||
const lazyRoutes = __NGTOOLS_PRIVATE_API_2.listLazyRoutes(
|
||||
{program, host, angularCompilerOptions: config.options, entryModule: 'app.module#AppModule'});
|
||||
|
||||
const expectations: {[route: string]: string} = {
|
||||
'./lazy.module#LazyModule': 'lazy.module.ts',
|
||||
|
@ -14,8 +14,7 @@ import 'reflect-metadata';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
import * as assert from 'assert';
|
||||
import {tsc} from '@angular/tsc-wrapped/src/tsc';
|
||||
import {CompilerOptions, CodeGenerator, CompilerHostContext, NodeCompilerHostContext} from '@angular/compiler-cli';
|
||||
import {CompilerOptions, CodeGenerator, CompilerHostContext, NodeCompilerHostContext, readConfiguration} from '@angular/compiler-cli';
|
||||
|
||||
/**
|
||||
* Main method.
|
||||
@ -46,10 +45,10 @@ function main() {
|
||||
}
|
||||
}
|
||||
|
||||
const config = tsc.readConfiguration(project, basePath);
|
||||
config.ngOptions.basePath = basePath;
|
||||
const config = readConfiguration(project);
|
||||
config.options.basePath = basePath;
|
||||
// This flag tells ngc do not recompile libraries.
|
||||
config.ngOptions.generateCodeForLibraries = false;
|
||||
config.options.generateCodeForLibraries = false;
|
||||
|
||||
console.log(`>>> running codegen for ${project}`);
|
||||
codegen(
|
||||
@ -86,21 +85,21 @@ function main() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple adaption of tsc-wrapped main to just run codegen with a CompilerHostContext
|
||||
* Simple adaption of main to just run codegen with a CompilerHostContext
|
||||
*/
|
||||
function codegen(
|
||||
config: {parsed: ts.ParsedCommandLine, ngOptions: CompilerOptions},
|
||||
config: {options: CompilerOptions, rootNames: string[]},
|
||||
hostContextFactory: (host: ts.CompilerHost) => CompilerHostContext) {
|
||||
const host = ts.createCompilerHost(config.parsed.options, true);
|
||||
const host = ts.createCompilerHost(config.options, true);
|
||||
|
||||
// HACK: patch the realpath to solve symlink issue here:
|
||||
// https://github.com/Microsoft/TypeScript/issues/9552
|
||||
// todo(misko): remove once facade symlinks are removed
|
||||
host.realpath = (path) => path;
|
||||
|
||||
const program = ts.createProgram(config.parsed.fileNames, config.parsed.options, host);
|
||||
const program = ts.createProgram(config.rootNames, config.options, host);
|
||||
|
||||
return CodeGenerator.create(config.ngOptions, {
|
||||
return CodeGenerator.create(config.options, {
|
||||
} as any, program, host, hostContextFactory(host)).codegen();
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
"ng-xi18n": "./src/extract_i18n.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@angular/tsc-wrapped": "5.0.0-beta.7",
|
||||
"reflect-metadata": "^0.1.2",
|
||||
"minimist": "^1.2.0",
|
||||
"tsickle": "^0.24.0",
|
||||
|
@ -431,6 +431,10 @@ function addReferencesToSourceFile(sf: ts.SourceFile, genFileNames: string[]) {
|
||||
sf.referencedFiles = newReferencedFiles;
|
||||
}
|
||||
|
||||
export function getOriginalReferences(sourceFile: ts.SourceFile): ts.FileReference[]|undefined {
|
||||
return sourceFile && (sourceFile as any).originalReferencedFiles;
|
||||
}
|
||||
|
||||
function dotRelative(from: string, to: string): string {
|
||||
const rPath: string = path.relative(from, to).replace(/\\/g, '/');
|
||||
return rPath.startsWith('.') ? rPath : './' + rPath;
|
||||
|
@ -15,7 +15,7 @@ import {TypeCheckHost, translateDiagnostics} from '../diagnostics/translate_diag
|
||||
import {ModuleMetadata, createBundleIndexHost} from '../metadata/index';
|
||||
|
||||
import {CompilerHost, CompilerOptions, CustomTransformers, DEFAULT_ERROR_CODE, Diagnostic, EmitFlags, Program, SOURCE, TsEmitArguments, TsEmitCallback} from './api';
|
||||
import {TsCompilerAotCompilerTypeCheckHostAdapter} from './compiler_host';
|
||||
import {TsCompilerAotCompilerTypeCheckHostAdapter, getOriginalReferences} from './compiler_host';
|
||||
import {LowerMetadataCache, getExpressionLoweringTransformFactory} from './lower_expressions';
|
||||
import {getAngularEmitterTransformFactory} from './node_emitter_transform';
|
||||
import {GENERATED_FILES, StructureIsReused, tsStructureIsReused} from './util';
|
||||
@ -173,15 +173,34 @@ class AngularCompilerProgram implements Program {
|
||||
};
|
||||
}
|
||||
|
||||
const emitResult = emitCallback({
|
||||
program: this.tsProgram,
|
||||
host: this.host,
|
||||
options: this.options,
|
||||
writeFile: createWriteFileCallback(genFiles, this.host, outSrcMapping),
|
||||
emitOnlyDtsFiles: (emitFlags & (EmitFlags.DTS | EmitFlags.JS)) == EmitFlags.DTS,
|
||||
customTransformers: this.calculateTransforms(genFiles, customTransformers)
|
||||
});
|
||||
// Restore the original references before we emit so TypeScript doesn't emit
|
||||
// a reference to the .d.ts file.
|
||||
const augmentedReferences = new Map<ts.SourceFile, ts.FileReference[]>();
|
||||
for (const sourceFile of this.tsProgram.getSourceFiles()) {
|
||||
const originalReferences = getOriginalReferences(sourceFile);
|
||||
if (originalReferences) {
|
||||
augmentedReferences.set(sourceFile, sourceFile.referencedFiles);
|
||||
sourceFile.referencedFiles = originalReferences;
|
||||
}
|
||||
}
|
||||
|
||||
let emitResult: ts.EmitResult;
|
||||
try {
|
||||
emitResult = emitCallback({
|
||||
program: this.tsProgram,
|
||||
host: this.host,
|
||||
options: this.options,
|
||||
writeFile: createWriteFileCallback(genFiles, this.host, outSrcMapping),
|
||||
emitOnlyDtsFiles: (emitFlags & (EmitFlags.DTS | EmitFlags.JS)) == EmitFlags.DTS,
|
||||
customTransformers: this.calculateTransforms(genFiles, customTransformers)
|
||||
});
|
||||
} finally {
|
||||
// Restore the references back to the augmented value to ensure that the
|
||||
// checks that TypeScript makes for project structure reuse will succeed.
|
||||
for (const [sourceFile, references] of Array.from(augmentedReferences)) {
|
||||
sourceFile.referencedFiles = references;
|
||||
}
|
||||
}
|
||||
|
||||
if (!outSrcMapping.length) {
|
||||
// if no files were emitted by TypeScript, also don't emit .json files
|
||||
@ -464,6 +483,7 @@ function getAotCompilerOptions(options: CompilerOptions): AotCompilerOptions {
|
||||
enableSummariesForJit: true,
|
||||
preserveWhitespaces: options.preserveWhitespaces,
|
||||
fullTemplateTypeCheck: options.fullTemplateTypeCheck,
|
||||
rootDir: options.rootDir,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
import * as ng from '@angular/compiler-cli';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
@ -247,3 +248,12 @@ const LOWERING_QUICKSTART = {
|
||||
export class AppModule { }
|
||||
`
|
||||
};
|
||||
|
||||
const tmpdir = process.env.TEST_TMPDIR || os.tmpdir();
|
||||
|
||||
function makeTempDir(): string {
|
||||
const id = (Math.random() * 1000000).toFixed(0);
|
||||
const dir = path.join(tmpdir, `tmp.${id}`);
|
||||
fs.mkdirSync(dir);
|
||||
return dir;
|
||||
}
|
||||
|
@ -8,8 +8,7 @@
|
||||
"baseUrl": ".",
|
||||
"rootDir": ".",
|
||||
"paths": {
|
||||
"@angular/compiler": ["../../dist/packages/compiler"],
|
||||
"@angular/tsc-wrapped": ["../../dist/packages-dist/tsc-wrapped"]
|
||||
"@angular/compiler": ["../../dist/packages/compiler"]
|
||||
},
|
||||
"outDir": "../../dist/packages/compiler-cli"
|
||||
},
|
||||
|
10
packages/compiler-cli/tsconfig-tools.json
Normal file
10
packages/compiler-cli/tsconfig-tools.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig-build.json",
|
||||
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/tools/@angular/compiler-cli",
|
||||
"paths": {
|
||||
"@angular/compiler": ["../../dist/tools/@angular/compiler"]
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user