fix(tsc-wrapped): emit flat module format correctly on Windows (#15215)

File name needed to be normalized before comparison when using
synthetic file names.

Fixes #15192

PR Close #15215
This commit is contained in:
Chuck Jazdzewski 2017-03-16 13:45:25 -07:00 committed by Miško Hevery
parent a6fb78ee3c
commit 6e9264a79c
1 changed files with 18 additions and 8 deletions

View File

@ -7,6 +7,7 @@
*/
import {writeFileSync} from 'fs';
import {normalize} from 'path';
import * as tsickle from 'tsickle';
import * as ts from 'typescript';
@ -121,28 +122,37 @@ export class MetadataWriterHost extends DelegatingHost {
}
export class SyntheticIndexHost extends DelegatingHost {
private normalSyntheticIndexName: string;
private indexContent: string;
private indexMetadata: string;
constructor(
delegate: ts.CompilerHost,
private syntheticIndex: {name: string, content: string, metadata: string}) {
syntheticIndex: {name: string, content: string, metadata: string}) {
super(delegate);
this.normalSyntheticIndexName = normalize(syntheticIndex.name);
this.indexContent = syntheticIndex.content;
this.indexMetadata = syntheticIndex.metadata;
}
fileExists = (fileName: string):
boolean => {
return fileName == this.syntheticIndex.name || this.delegate.fileExists(fileName);
return normalize(fileName) == this.normalSyntheticIndexName ||
this.delegate.fileExists(fileName);
}
readFile =
(fileName: string) => {
return fileName == this.syntheticIndex.name ? this.syntheticIndex.content :
return normalize(fileName) == this.normalSyntheticIndexName ?
this.indexContent :
this.delegate.readFile(fileName);
}
getSourceFile =
(fileName: string, languageVersion: ts.ScriptTarget,
onError?: (message: string) => void) => {
if (fileName == this.syntheticIndex.name) {
return ts.createSourceFile(fileName, this.syntheticIndex.content, languageVersion, true);
if (normalize(fileName) == this.normalSyntheticIndexName) {
return ts.createSourceFile(fileName, this.indexContent, languageVersion, true);
}
return this.delegate.getSourceFile(fileName, languageVersion, onError);
}
@ -152,10 +162,10 @@ export class SyntheticIndexHost extends DelegatingHost {
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
if (fileName.match(DTS) && sourceFiles && sourceFiles.length == 1 &&
sourceFiles[0].fileName == this.syntheticIndex.name) {
normalize(sourceFiles[0].fileName) == this.normalSyntheticIndexName) {
// If we are writing the synthetic index, write the metadata along side.
const metadataName = fileName.replace(DTS, '.metadata.json');
writeFileSync(metadataName, this.syntheticIndex.metadata, 'utf8');
writeFileSync(metadataName, this.indexMetadata, 'utf8');
}
}
}