@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
53 lines • 2.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlowrAnalyzerLoadingOrderImplicitSourcesPlugin = exports.implicitSourcesLog = void 0;
const semver_1 = require("semver");
const flowr_analyzer_loading_order_plugin_1 = require("./flowr-analyzer-loading-order-plugin");
const log_1 = require("../../../util/log");
const glob_1 = require("../../../util/glob");
exports.implicitSourcesLog = log_1.log.getSubLogger({ name: 'loading-order-implicit-sources' });
/**
* Orders the files given by `project.implicitSources`, which is already specialized for the project kind.
* Files that are no implicit sources stay in front, as the implicit entry points consume them.
*/
class FlowrAnalyzerLoadingOrderImplicitSourcesPlugin extends flowr_analyzer_loading_order_plugin_1.FlowrAnalyzerLoadingOrderPlugin {
name = 'flowr-analyzer-loading-order-implicit-sources-plugin';
description = 'Orders the files a framework loads implicitly, as configured by project.implicitSources.';
version = new semver_1.SemVer('0.1.0');
process(ctx) {
const kind = ctx.projectKind();
const implicit = ctx.config.project.implicitSources;
if (!implicit || implicit.length === 0) {
return;
}
const unordered = ctx.files.loadingOrder.getUnorderedRequests();
const files = unordered.filter(r => r.request === 'file');
/* node sets keep insertion order! */
const ordered = new Set();
const unmatched = [];
for (const entry of implicit) {
const matches = (0, glob_1.globMatcher)(entry);
let matched = false;
for (const file of files) {
if (matches(file.content)) {
ordered.add(file);
matched = true;
}
}
if (!matched) {
unmatched.push(`'${entry}'`);
}
}
if (unmatched.length > 0) {
exports.implicitSourcesLog.warn(`No file of the ${kind} project matches the implicit source(s) ${unmatched.join(', ')}, ignoring them.`);
}
if (ordered.size === 0) {
return;
}
const rest = unordered.filter(r => !ordered.has(r));
exports.implicitSourcesLog.debug(`Ordering implicit sources of ${kind} project: ${[...ordered].map(s => s.content).join(', ')}`);
ctx.files.loadingOrder.addGuess([...rest, ...ordered]);
}
}
exports.FlowrAnalyzerLoadingOrderImplicitSourcesPlugin = FlowrAnalyzerLoadingOrderImplicitSourcesPlugin;
//# sourceMappingURL=flowr-analyzer-loading-order-implicit-sources-plugin.js.map