1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var path_1 = require("path");
|
4 | var typescript_1 = require("typescript");
|
5 | var typescript_utils_1 = require("../util/typescript-utils");
|
6 | var logger_1 = require("../logger/logger");
|
7 | var FileSystemCompilerHost = (function () {
|
8 | function FileSystemCompilerHost(options, fileSystem, setParentNodes) {
|
9 | if (setParentNodes === void 0) { setParentNodes = true; }
|
10 | this.options = options;
|
11 | this.fileSystem = fileSystem;
|
12 | this.setParentNodes = setParentNodes;
|
13 | this.diskCompilerHost = typescript_1.createCompilerHost(this.options, this.setParentNodes);
|
14 | }
|
15 | FileSystemCompilerHost.prototype.fileExists = function (filePath) {
|
16 | filePath = path_1.normalize(filePath);
|
17 | var fileContent = this.fileSystem.getFileContent(filePath);
|
18 | if (fileContent) {
|
19 | return true;
|
20 | }
|
21 | return this.diskCompilerHost.fileExists(filePath);
|
22 | };
|
23 | FileSystemCompilerHost.prototype.readFile = function (filePath) {
|
24 | filePath = path_1.normalize(filePath);
|
25 | var fileContent = this.fileSystem.getFileContent(filePath);
|
26 | if (fileContent) {
|
27 | return fileContent;
|
28 | }
|
29 | return this.diskCompilerHost.readFile(filePath);
|
30 | };
|
31 | FileSystemCompilerHost.prototype.directoryExists = function (directoryPath) {
|
32 | directoryPath = path_1.normalize(directoryPath);
|
33 | var stats = this.fileSystem.getDirectoryStats(directoryPath);
|
34 | if (stats) {
|
35 | return true;
|
36 | }
|
37 | return this.diskCompilerHost.directoryExists(directoryPath);
|
38 | };
|
39 | FileSystemCompilerHost.prototype.getFiles = function (directoryPath) {
|
40 | directoryPath = path_1.normalize(directoryPath);
|
41 | return this.fileSystem.getFileNamesInDirectory(directoryPath);
|
42 | };
|
43 | FileSystemCompilerHost.prototype.getDirectories = function (directoryPath) {
|
44 | directoryPath = path_1.normalize(directoryPath);
|
45 | var subdirs = this.fileSystem.getSubDirs(directoryPath);
|
46 | var delegated;
|
47 | try {
|
48 | delegated = this.diskCompilerHost.getDirectories(directoryPath);
|
49 | }
|
50 | catch (e) {
|
51 | delegated = [];
|
52 | }
|
53 | return delegated.concat(subdirs);
|
54 | };
|
55 | FileSystemCompilerHost.prototype.getSourceFile = function (filePath, languageVersion, onError) {
|
56 | filePath = path_1.normalize(filePath);
|
57 |
|
58 | var fileContentFromMemory = this.fileSystem.getFileContent(filePath);
|
59 | if (fileContentFromMemory) {
|
60 | var typescriptSourceFile = typescript_utils_1.getTypescriptSourceFile(filePath, fileContentFromMemory, languageVersion, this.setParentNodes);
|
61 | return typescriptSourceFile;
|
62 | }
|
63 | var diskSourceFile = this.diskCompilerHost.getSourceFile(filePath, languageVersion, onError);
|
64 | return diskSourceFile;
|
65 | };
|
66 | FileSystemCompilerHost.prototype.getCancellationToken = function () {
|
67 | return this.diskCompilerHost.getCancellationToken();
|
68 | };
|
69 | FileSystemCompilerHost.prototype.getDefaultLibFileName = function (options) {
|
70 | return this.diskCompilerHost.getDefaultLibFileName(options);
|
71 | };
|
72 | FileSystemCompilerHost.prototype.writeFile = function (fileName, data, writeByteOrderMark, onError) {
|
73 | fileName = path_1.normalize(fileName);
|
74 | logger_1.Logger.debug("[NgcCompilerHost] writeFile: adding " + fileName + " to virtual file system");
|
75 | this.fileSystem.addVirtualFile(fileName, data);
|
76 | };
|
77 | FileSystemCompilerHost.prototype.getCurrentDirectory = function () {
|
78 | return this.diskCompilerHost.getCurrentDirectory();
|
79 | };
|
80 | FileSystemCompilerHost.prototype.getCanonicalFileName = function (fileName) {
|
81 | return this.diskCompilerHost.getCanonicalFileName(fileName);
|
82 | };
|
83 | FileSystemCompilerHost.prototype.useCaseSensitiveFileNames = function () {
|
84 | return this.diskCompilerHost.useCaseSensitiveFileNames();
|
85 | };
|
86 | FileSystemCompilerHost.prototype.getNewLine = function () {
|
87 | return this.diskCompilerHost.getNewLine();
|
88 | };
|
89 | return FileSystemCompilerHost;
|
90 | }());
|
91 | exports.FileSystemCompilerHost = FileSystemCompilerHost;
|