Skip to content

Commit

Permalink
fix(tsc-wrapped): emit flat module format correctly on Windows (angul…
Browse files Browse the repository at this point in the history
…ar#15215)

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

Fixes angular#15192

PR Close angular#15215
  • Loading branch information
chuckjaz authored and Zhicheng Wang committed Aug 11, 2017
1 parent 5987ebc commit 081bad9
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tools/@angular/tsc-wrapped/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import {writeFileSync} from 'fs';
import {normalize} from 'path';
import * as tsickle from 'tsickle';
import * as ts from 'typescript';

Expand Down Expand Up @@ -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 :
this.delegate.readFile(fileName);
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);
}
Expand All @@ -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');
}
}
}

0 comments on commit 081bad9

Please sign in to comment.