Innovenergy_trunk/frontend/node_modules/testcafe/lib/compiler/index.js

95 lines
14 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const strip_bom_1 = __importDefault(require("strip-bom"));
const promisified_functions_1 = require("../utils/promisified-functions");
const runtime_1 = require("../errors/runtime");
const types_1 = require("../errors/types");
const compilers_1 = require("./compilers");
const SOURCE_CHUNK_LENGTH = 1000;
class Compiler {
constructor(sources, compilerOptions, { isCompilerServiceMode, baseUrl, experimentalEsm } = {}) {
this.sources = sources;
this.experimentalEsm = experimentalEsm;
(0, compilers_1.initTestFileCompilers)(compilerOptions, { isCompilerServiceMode, baseUrl, experimentalEsm });
}
static getSupportedTestFileExtensions() {
return (0, lodash_1.uniq)((0, lodash_1.flattenDeep)((0, compilers_1.getTestFileCompilers)().map(compiler => compiler.getSupportedExtension())));
}
static async createTestFileInfo(filename) {
let code = null;
try {
code = await (0, promisified_functions_1.readFile)(filename);
}
catch (err) {
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.cannotFindSpecifiedTestSource, filename);
}
code = (0, strip_bom_1.default)(code).toString();
const compiler = (0, lodash_1.find)((0, compilers_1.getTestFileCompilers)(), someCompiler => someCompiler.canCompile(code, filename));
if (!compiler)
return null;
return {
filename,
code,
compiler,
compiledCode: null,
};
}
async _createTestFilesInfo(filenames) {
const testFilesInfo = await Promise.all(filenames.map(filename => Compiler.createTestFileInfo(filename)));
return testFilesInfo.filter(info => !!info);
}
async _precompileFiles(compiler, testFilesInfo) {
if (!compiler.canPrecompile || this.experimentalEsm && compiler.canCompileInEsm)
return;
const precompiledCode = await compiler.precompile(testFilesInfo);
for (let i = 0; i < testFilesInfo.length; i++)
testFilesInfo[i].compiledCode = precompiledCode[i];
}
_getCompilerTasks(testFilesInfo) {
const tasks = new WeakMap();
const compilers = [];
for (const info of testFilesInfo) {
const { compiler } = info;
if (!tasks.has(compiler)) {
compilers.push(compiler);
tasks.set(compiler, []);
}
tasks.get(info.compiler).push(info);
}
return compilers.map(compiler => ({ compiler, compilerTestFilesInfo: tasks.get(compiler) }));
}
async _getTests({ compiler, filename, code, compiledCode }) {
if (compiledCode || this.experimentalEsm && compiler.canCompileInEsm)
return await compiler.execute(compiledCode, filename);
return await compiler.compile(code, filename);
}
async _compileTestFiles(filenames) {
const testFilesInfo = await this._createTestFilesInfo(filenames);
const compilerTasks = this._getCompilerTasks(testFilesInfo);
await Promise.all(compilerTasks.map(({ compiler, compilerTestFilesInfo }) => this._precompileFiles(compiler, compilerTestFilesInfo)));
const tests = [];
for (const info of testFilesInfo)
tests.push(await this._getTests(info));
return tests;
}
async getTests() {
// NOTE: split sources into chunks because the fs module can't read all files
// simultaneously if the number of them is too large (several thousands).
const sourceChunks = (0, lodash_1.chunk)(this.sources, SOURCE_CHUNK_LENGTH);
let tests = [];
while (sourceChunks.length)
tests = tests.concat(await this._compileTestFiles(sourceChunks.shift()));
Compiler.cleanUp();
return (0, lodash_1.flattenDeep)(tests).filter(test => !!test);
}
static cleanUp() {
(0, compilers_1.getTestFileCompilers)().forEach(compiler => compiler.cleanUp());
}
}
exports.default = Compiler;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29tcGlsZXIvaW5kZXguanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxtQ0FLZ0I7QUFFaEIsMERBQWlDO0FBQ2pDLDBFQUEwRDtBQUMxRCwrQ0FBaUQ7QUFDakQsMkNBQWlEO0FBQ2pELDJDQUEwRTtBQUcxRSxNQUFNLG1CQUFtQixHQUFHLElBQUksQ0FBQztBQUVqQyxNQUFxQixRQUFRO0lBQ3pCLFlBQWEsT0FBTyxFQUFFLGVBQWUsRUFB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gICAgICBmb3IgKGNvbnN0IGluZm8gb2YgdGVzdEZpbGVzSW5mbykge1xuICAgICAgICAgICAgY29uc3QgeyBjb21waWxlciB9ID0gaW5mbztcblxuICAgICAgICAgICAgaWYgKCF0YXNrcy5oYXMoY29tcGlsZXIpKSB7XG4gICAgICAgICAgICAgICAgY29tcGlsZXJzLnB1c2goY29tcGlsZXIpO1xuICAgICAgICAgICAgICAgIHRhc2tzLnNldChjb21waWxlciwgW10pO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICB0YXNrcy5nZXQoaW5mby5jb21waWxlcikucHVzaChpbmZvKTtcbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiBjb21waWxlcnMubWFwKGNvbXBpbGVyID0+ICh7IGNvbXBpbGVyLCBjb21waWxlclRlc3RGaWxlc0luZm86IHRhc2tzLmdldChjb21waWxlcikgfSkpO1xuICAgIH1cblxuICAgIGFzeW5jIF9nZXRUZXN0cyAoeyBjb21waWxlciwgZmlsZW5hbWUsIGNvZGUsIGNvbXBpbGVkQ29kZSB9KSB7XG4gICAgICAgIGlmIChjb21waWxlZENvZGUgfHwgdGhpcy5leHBlcmltZW50YWxFc20gJiYgY29tcGlsZXIuY2FuQ29tcGlsZUluRXNtKVxuICAgICAgICAgICAgcmV0dXJuIGF3YWl0IGNvbXBpbGVyLmV4ZWN1dGUoY29tcGlsZWRDb2RlLCBmaWxlbmFtZSk7XG5cbiAgICAgICAgcmV0dXJuIGF3YWl0IGNvbXBpbGVyLmNvbXBpbGUoY29kZSwgZmlsZW5hbWUpO1xuICAgIH1cblxuICAgIGFzeW5jIF9jb21waWxlVGVzdEZpbGVzIChmaWxlbmFtZXMpIHtcbiAgICAgICAgY29uc3QgdGVzdEZpbGVzSW5mbyA9IGF3YWl0IHRoaXMuX2NyZWF0ZVRlc3RGaWxlc0luZm8oZmlsZW5hbWVzKTtcbiAgICAgICAgY29uc3QgY29tcGlsZXJUYXNrcyA9IHRoaXMuX2dldENvbXBpbGVyVGFza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