-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also fix `emitBOM`.
- Loading branch information
Showing
15 changed files
with
310 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { ProjectContext } from "../../../ProjectContext"; | ||
import { ts } from "../../../typescript"; | ||
import { EmitResult } from "./EmitResult"; | ||
|
||
/** | ||
* The emitted file in memory. | ||
*/ | ||
export interface MemoryEmitResultFile { | ||
/** | ||
* File path that was emitted to. | ||
*/ | ||
filePath: string; | ||
/** | ||
* The text that was emitted. | ||
*/ | ||
text: string; | ||
/** | ||
* Whether the byte order mark should be written. | ||
*/ | ||
writeByteOrderMark: boolean; | ||
} | ||
|
||
/** | ||
* Result of an emit to memory. | ||
*/ | ||
export class MemoryEmitResult extends EmitResult { | ||
/** | ||
* @private | ||
*/ | ||
constructor(context: ProjectContext, compilerObject: ts.EmitResult, private readonly _files: ReadonlyArray<MemoryEmitResultFile>) { | ||
super(context, compilerObject); | ||
} | ||
|
||
/** | ||
* Gets the files that were emitted to memory. | ||
*/ | ||
getFiles() { | ||
return this._files as MemoryEmitResultFile[]; // assert mutable array | ||
} | ||
|
||
/** | ||
* Asynchronously writes the files to the file system. | ||
*/ | ||
saveFiles() { | ||
const fileSystem = this._context.fileSystemWrapper; | ||
const promises = this._files.map(f => fileSystem.writeFile(f.filePath, f.writeByteOrderMark ? "\uFEFF" + f.text : f.text)); | ||
return Promise.all(promises); | ||
} | ||
|
||
/** | ||
* Synchronously writes the files to the file system. | ||
* @remarks Use `saveFiles()` as the asynchronous version will be much faster. | ||
*/ | ||
saveFilesSync() { | ||
const fileSystem = this._context.fileSystemWrapper; | ||
for (const file of this._files) | ||
fileSystem.writeFileSync(file.filePath, file.writeByteOrderMark ? "\uFEFF" + file.text : file.text); | ||
} | ||
} |
Oops, something went wrong.