fix(tsc-wrapped): emit js files in all cases
This commit is contained in:
parent
73a46205a0
commit
c0e05e6f03
|
@ -56,7 +56,10 @@ const DTS = /\.d\.ts$/;
|
||||||
export class MetadataWriterHost extends DelegatingHost {
|
export class MetadataWriterHost extends DelegatingHost {
|
||||||
private metadataCollector = new MetadataCollector({quotedNames: true});
|
private metadataCollector = new MetadataCollector({quotedNames: true});
|
||||||
private metadataCollector1 = new MetadataCollector({version: 1});
|
private metadataCollector1 = new MetadataCollector({version: 1});
|
||||||
constructor(delegate: ts.CompilerHost, private ngOptions: NgOptions) { super(delegate); }
|
constructor(
|
||||||
|
delegate: ts.CompilerHost, private ngOptions: NgOptions, private emitAllFiles: boolean) {
|
||||||
|
super(delegate);
|
||||||
|
}
|
||||||
|
|
||||||
private writeMetadata(emitFilePath: string, sourceFile: ts.SourceFile) {
|
private writeMetadata(emitFilePath: string, sourceFile: ts.SourceFile) {
|
||||||
// TODO: replace with DTS filePath when https://github.com/Microsoft/TypeScript/pull/8412 is
|
// TODO: replace with DTS filePath when https://github.com/Microsoft/TypeScript/pull/8412 is
|
||||||
|
@ -87,10 +90,12 @@ export class MetadataWriterHost extends DelegatingHost {
|
||||||
writeFile: ts.WriteFileCallback =
|
writeFile: ts.WriteFileCallback =
|
||||||
(fileName: string, data: string, writeByteOrderMark: boolean,
|
(fileName: string, data: string, writeByteOrderMark: boolean,
|
||||||
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
|
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
|
||||||
if (/\.d\.ts$/.test(fileName)) {
|
const isDts = /\.d\.ts$/.test(fileName);
|
||||||
|
if (this.emitAllFiles || isDts) {
|
||||||
// Let the original file be written first; this takes care of creating parent directories
|
// Let the original file be written first; this takes care of creating parent directories
|
||||||
this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
||||||
|
}
|
||||||
|
if (isDts) {
|
||||||
// TODO: remove this early return after https://github.com/Microsoft/TypeScript/pull/8412
|
// TODO: remove this early return after https://github.com/Microsoft/TypeScript/pull/8412
|
||||||
// is
|
// is
|
||||||
// released
|
// released
|
||||||
|
|
|
@ -117,7 +117,11 @@ export function main(
|
||||||
if (diagnostics) console.timeEnd('NG codegen');
|
if (diagnostics) console.timeEnd('NG codegen');
|
||||||
let definitionsHost: ts.CompilerHost = tsickleCompilerHost;
|
let definitionsHost: ts.CompilerHost = tsickleCompilerHost;
|
||||||
if (!ngOptions.skipMetadataEmit) {
|
if (!ngOptions.skipMetadataEmit) {
|
||||||
definitionsHost = new MetadataWriterHost(tsickleCompilerHost, ngOptions);
|
// if tsickle is not not used for emitting, but we do use the MetadataWriterHost,
|
||||||
|
// it also needs to emit the js files.
|
||||||
|
const emitJsFiles =
|
||||||
|
ngOptions.annotationsAs === 'decorators' && !ngOptions.annotateForClosureCompiler;
|
||||||
|
definitionsHost = new MetadataWriterHost(tsickleCompilerHost, ngOptions, emitJsFiles);
|
||||||
}
|
}
|
||||||
// Create a new program since codegen files were created after making the old program
|
// Create a new program since codegen files were created after making the old program
|
||||||
let programWithCodegen = createProgram(definitionsHost, program);
|
let programWithCodegen = createProgram(definitionsHost, program);
|
||||||
|
|
|
@ -153,6 +153,40 @@ describe('tsc-wrapped', () => {
|
||||||
.catch(e => done.fail(e));
|
.catch(e => done.fail(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow all options disabled with metadata emit', (done) => {
|
||||||
|
write('tsconfig.json', `{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"types": [],
|
||||||
|
"outDir": "built",
|
||||||
|
"declaration": false,
|
||||||
|
"module": "es2015",
|
||||||
|
"moduleResolution": "node"
|
||||||
|
},
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"annotateForClosureCompiler": false,
|
||||||
|
"annotationsAs": "decorators",
|
||||||
|
"skipMetadataEmit": false,
|
||||||
|
"skipTemplateCodegen": true
|
||||||
|
},
|
||||||
|
"files": ["test.ts"]
|
||||||
|
}`);
|
||||||
|
|
||||||
|
main(basePath, {basePath})
|
||||||
|
.then(() => {
|
||||||
|
const out = readOut('js');
|
||||||
|
// TypeScript's decorator emit
|
||||||
|
expect(out).toContain('__decorate');
|
||||||
|
// Not annotated for Closure compiler
|
||||||
|
expect(out).not.toContain('* @param {?} x');
|
||||||
|
expect(() => fs.accessSync(path.join(basePath, 'built', 'test.d.ts'))).toThrow();
|
||||||
|
const metadata = readOut('metadata.json');
|
||||||
|
expect(metadata).toContain('"Comp":{"__symbolic":"class"');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(e => done.fail(e));
|
||||||
|
});
|
||||||
|
|
||||||
it('should allow JSDoc annotations without decorator downleveling', (done) => {
|
it('should allow JSDoc annotations without decorator downleveling', (done) => {
|
||||||
write('tsconfig.json', `{
|
write('tsconfig.json', `{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
|
Loading…
Reference in New Issue