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