github-pages-deploy-action/node_modules/ts-jest/dist/compiler/compiler-utils.js

34 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-04-30 20:40:07 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = require("fs");
var micromatch = require("micromatch");
var path_1 = require("path");
var sha1_1 = require("../util/sha1");
2020-05-15 05:33:08 +08:00
function getResolvedModulesCache(cacheDir) {
return path_1.join(cacheDir, sha1_1.sha1('ts-jest-resolved-modules', '\x00'));
2020-04-30 20:40:07 +08:00
}
exports.getResolvedModulesCache = getResolvedModulesCache;
function cacheResolvedModules(fileName, fileContent, memoryCache, program, cacheDir, logger) {
var importReferences = program.getSourceFile(fileName).imports;
if (importReferences.length) {
2020-05-15 05:33:08 +08:00
logger.debug({ fileName: fileName }, 'cacheResolvedModules(): get resolved modules');
2020-04-30 20:40:07 +08:00
memoryCache.resolvedModules[fileName] = Object.create(null);
memoryCache.resolvedModules[fileName].modulePaths = importReferences
.filter(function (importReference) { var _a; return (_a = importReference.parent.parent.resolvedModules) === null || _a === void 0 ? void 0 : _a.get(importReference.text); })
.map(function (importReference) {
return path_1.normalize(importReference.parent.parent.resolvedModules.get(importReference.text)
.resolvedFileName);
})
.reduce(function (a, b) { return a.concat(b); }, []);
memoryCache.resolvedModules[fileName].testFileContent = fileContent;
fs_1.writeFileSync(getResolvedModulesCache(cacheDir), JSON.stringify(memoryCache.resolvedModules));
}
}
exports.cacheResolvedModules = cacheResolvedModules;
function isTestFile(testMatchPatterns, fileName) {
return testMatchPatterns.some(function (pattern) {
return typeof pattern === 'string' ? micromatch.isMatch(fileName, pattern) : pattern.test(fileName);
});
}
exports.isTestFile = isTestFile;