ngc-webpack
Version:
A wrapper for the @ngtools/webpack with hooks into the compilation process
75 lines • 3.08 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ts = require("typescript");
var path_1 = require("path");
function denormalizePath(path) {
return path.replace(/\//g, path_1.sep);
}
var CliCompilerHost = (function () {
function CliCompilerHost(options, resourceLoader) {
this.options = options;
this.resourceLoader = resourceLoader;
this.resourceCache = new Map();
this.host = ts.createCompilerHost(this.options, true);
}
CliCompilerHost.prototype.fileExists = function (fileName) {
return this.host.fileExists(fileName);
};
CliCompilerHost.prototype.readFile = function (fileName) {
return this.host.readFile(fileName);
};
CliCompilerHost.prototype.getDirectories = function (path) {
return this.host.getDirectories(path);
};
CliCompilerHost.prototype.getSourceFile = function (fileName, languageVersion, _onError) {
return this.host.getSourceFile(fileName, languageVersion, _onError);
};
CliCompilerHost.prototype.getCancellationToken = function () {
return this.host.getCancellationToken();
};
CliCompilerHost.prototype.getDefaultLibFileName = function (options) {
return this.host.getDefaultLibFileName(options);
};
CliCompilerHost.prototype.writeFile = function (fileName, data, _writeByteOrderMark, _onError, _sourceFiles) {
return this.host.writeFile(fileName, data, _writeByteOrderMark, _onError, _sourceFiles);
};
CliCompilerHost.prototype.getCurrentDirectory = function () {
return this.host.getCurrentDirectory();
};
CliCompilerHost.prototype.getCanonicalFileName = function (fileName) {
return this.host.getCanonicalFileName(fileName);
};
CliCompilerHost.prototype.useCaseSensitiveFileNames = function () {
return this.host.useCaseSensitiveFileNames();
};
CliCompilerHost.prototype.getNewLine = function () {
return this.host.getNewLine();
};
CliCompilerHost.prototype.readResource = function (fileName) {
var _this = this;
if (this.resourceLoader) {
// These paths are meant to be used by the loader so we must denormalize them.
var denormalizedFileName_1 = denormalizePath(fileName);
return this.resourceLoader.get(denormalizedFileName_1)
.then(function (content) {
_this.resourceCache.set(denormalizedFileName_1, content);
return content;
});
}
else {
return this.readFile(fileName);
}
};
/**
* Returns a cached resource, if the resource is not cached returns undefined.
* Will not try to get the resource if it does not exists.
* @param {string} fileName
* @returns {string}
*/
CliCompilerHost.prototype.getResource = function (fileName) {
return this.resourceCache.get(fileName);
};
return CliCompilerHost;
}());
exports.CliCompilerHost = CliCompilerHost;
//# sourceMappingURL=cli-compiler-host.js.map