This commit is contained in:
David Kale
2020-09-08 13:25:36 -04:00
parent e4246d2b5b
commit 91fcbb0108
4227 changed files with 416837 additions and 457884 deletions

View File

@@ -10,15 +10,16 @@ var __assign = (this && this.__assign) || function () {
};
return __assign.apply(this, arguments);
};
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
return {
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
@@ -36,14 +37,12 @@ var __read = (this && this.__read) || function (o, n) {
}
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var bs_logger_1 = require("bs-logger");
var buffer_from_1 = __importDefault(require("buffer-from"));
var bufferFrom = require("buffer-from");
var stableStringify = require("fast-json-stable-stringify");
var fs_1 = require("fs");
var memoize = require("lodash.memoize");
var mkdirp = require("mkdirp");
var path_1 = require("path");
var messages_1 = require("./util/messages");
@@ -112,30 +111,33 @@ function createCompiler(configs) {
_b.namespace = 'ts:serviceHost',
_b.call = null,
_b);
var serviceHostTraceCtx = __assign({}, serviceHostDebugCtx, (_c = {}, _c[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace, _c));
var serviceHostTraceCtx = __assign(__assign({}, serviceHostDebugCtx), (_c = {}, _c[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace, _c));
var serviceHost = {
getScriptFileNames: function () { return Object.keys(memoryCache.versions); },
getScriptVersion: function (fileName) {
var version = memoryCache.versions[fileName];
var normalizedFileName = path_1.normalize(fileName);
var version = memoryCache.versions[normalizedFileName];
return version === undefined ? undefined : String(version);
},
getScriptSnapshot: function (fileName) {
var hit = hasOwn.call(memoryCache.contents, fileName);
logger.trace({ fileName: fileName, cacheHit: hit }, "getScriptSnapshot():", 'cache', hit ? 'hit' : 'miss');
var normalizedFileName = path_1.normalize(fileName);
var hit = hasOwn.call(memoryCache.contents, normalizedFileName);
logger.trace({ normalizedFileName: normalizedFileName, cacheHit: hit }, "getScriptSnapshot():", 'cache', hit ? 'hit' : 'miss');
if (!hit) {
memoryCache.contents[fileName] = ts.sys.readFile(fileName);
memoryCache.contents[normalizedFileName] = ts.sys.readFile(normalizedFileName);
}
var contents = memoryCache.contents[fileName];
var contents = memoryCache.contents[normalizedFileName];
if (contents === undefined) {
return;
}
return ts.ScriptSnapshot.fromString(contents);
},
fileExists: ts.sys.fileExists,
readFile: logger.wrap(serviceHostTraceCtx, 'readFile', ts.sys.readFile),
readDirectory: ts.sys.readDirectory,
getDirectories: ts.sys.getDirectories,
directoryExists: ts.sys.directoryExists,
fileExists: memoize(ts.sys.fileExists),
readFile: logger.wrap(serviceHostTraceCtx, 'readFile', memoize(ts.sys.readFile)),
readDirectory: memoize(ts.sys.readDirectory),
getDirectories: memoize(ts.sys.getDirectories),
directoryExists: memoize(ts.sys.directoryExists),
realpath: memoize(ts.sys.realpath),
getNewLine: function () { return '\n'; },
getCurrentDirectory: function () { return cwd; },
getCompilationSettings: function () { return compilerOptions; },
@@ -213,7 +215,7 @@ function readThrough(cachedir, memoryCache, compile, getExtension, cwd, logger)
}
function updateOutput(outputText, fileName, sourceMap, getExtension, sourceRoot) {
var base = path_1.basename(fileName);
var base64Map = buffer_from_1.default(updateSourceMap(sourceMap, fileName, sourceRoot), 'utf8').toString('base64');
var base64Map = bufferFrom(updateSourceMap(sourceMap, fileName, sourceRoot), 'utf8').toString('base64');
var sourceMapContent = "data:application/json;charset=utf-8;base64," + base64Map;
var sourceMapLength = (base + ".map").length + (getExtension(fileName).length - path_1.extname(fileName).length);
return outputText.slice(0, -sourceMapLength) + sourceMapContent;
@@ -226,7 +228,7 @@ function updateSourceMap(sourceMapText, fileName, _sourceRoot) {
return stableStringify(sourceMap);
}
function getCacheName(sourceCode, fileName) {
return sha1_1.sha1(path_1.extname(fileName), '\x00', sourceCode);
return sha1_1.sha1(fileName, '\x00', sourceCode);
}
function isValidCacheContent(contents) {
return /(?:9|0=|Q==)$/.test(contents.slice(-3));