UNPKG

@syntest/core

Version:

The common core of the SynTest Framework

111 lines 3.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TargetPool = void 0; const path = require("path"); const globby = require("globby"); const Configuration_1 = require("../../Configuration"); class TargetPool { constructor(eventManager) { this.eventManager = eventManager; } loadTargets() { this.eventManager.emitEvent("onTargetLoadStart"); let includes = Configuration_1.CONFIG.include; let excludes = Configuration_1.CONFIG.exclude; if (typeof includes === "string") { includes = [includes]; } if (typeof excludes === "string") { excludes = [excludes]; } // Mapping filepath -> targets const includedMap = new Map(); const excludedMap = new Map(); includes.forEach((include) => { let _path; let target; if (include.includes(":")) { _path = include.split(":")[0]; target = include.split(":")[1]; } else { _path = include; target = "*"; } const actualPaths = globby.sync(_path); for (let _path of actualPaths) { _path = path.resolve(_path); if (!includedMap.has(_path)) { includedMap.set(_path, []); } includedMap.get(_path).push(target); } }); // only exclude files if all contracts are excluded excludes.forEach((exclude) => { let _path; let target; if (exclude.includes(":")) { _path = exclude.split(":")[0]; target = exclude.split(":")[1]; } else { _path = exclude; target = "*"; } const actualPaths = globby.sync(_path); for (let _path of actualPaths) { _path = path.resolve(_path); if (!excludedMap.has(_path)) { excludedMap.set(_path, []); } excludedMap.get(_path).push(target); } }); for (const key of excludedMap.keys()) { if (includedMap.has(key)) { if (excludedMap.get(key).includes("*")) { // exclude all targets of the file includedMap.delete(key); } else { // exclude specific targets in the file includedMap.set(key, includedMap .get(key) .filter((target) => !excludedMap.get(key).includes(target))); } } } const targets = []; for (const _path of includedMap.keys()) { const includedTargets = includedMap.get(_path); const targetMap = this.getTargetMap(_path); for (const target of targetMap.keys()) { // check if included if (!includedTargets.includes("*") && !includedTargets.includes(target)) { continue; } // check if excluded if (excludedMap.has(_path)) { const excludedTargets = excludedMap.get(_path); if (excludedTargets.includes("*") || excludedTargets.includes(target)) { continue; } } targets.push({ canonicalPath: _path, targetName: target, }); } } this._targets = targets; this.eventManager.emitEvent("onTargetLoadComplete"); } get targets() { return this._targets; } } exports.TargetPool = TargetPool; //# sourceMappingURL=TargetPool.js.map