@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
52 lines • 2.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlowrAnalyzerLoadingOrderDescriptionFilePlugin = void 0;
const flowr_analyzer_description_file_plugin_1 = require("../file-plugins/flowr-analyzer-description-file-plugin");
const semver_1 = require("semver");
const flowr_analyzer_loading_order_plugin_1 = require("./flowr-analyzer-loading-order-plugin");
/**
* This plugin extracts loading order information from R `DESCRIPTION` files.
* It looks at the `Collate` field to determine the order in which files should be loaded.
* If no `Collate` field is present, it does nothing.
*/
class FlowrAnalyzerLoadingOrderDescriptionFilePlugin extends flowr_analyzer_loading_order_plugin_1.FlowrAnalyzerLoadingOrderPlugin {
name = 'flowr-analyzer-package-version-description-file-plugin';
description = 'Orders the files by the Collate field of a DESCRIPTION file.';
version = new semver_1.SemVer('0.1.0');
process(ctx) {
const deps = flowr_analyzer_description_file_plugin_1.DescriptionFile.single(ctx, 'No description file found, cannot determine loading order from Collate field.');
if (deps === undefined) {
return;
}
const collate = deps.collate();
if (collate) {
/* we probably have to do some more guesswork here */
const unordered = ctx.files.loadingOrder.getUnorderedRequests();
// sort them by their path index in the Collate field
const sorted = unordered.slice().sort((a, b) => {
const aPath = a.request === 'file' ? a.content : undefined;
const bPath = b.request === 'file' ? b.content : undefined;
const aIndex = aPath ? collate.findIndex(c => aPath.endsWith(c.trim())) : -1;
const bIndex = bPath ? collate.findIndex(c => bPath.endsWith(c.trim())) : -1;
if (aIndex === -1 && bIndex === -1) {
return 0; // both not found, keep original order
}
else if (aIndex === -1) {
return 1; // a not found, b found -> a after b
}
else if (bIndex === -1) {
return -1; // b not found, a found -> a before b
}
else {
return aIndex - bIndex; // both found, sort by index
}
});
ctx.files.loadingOrder.addGuess(sorted, true);
}
else {
flowr_analyzer_description_file_plugin_1.descriptionFileLog.info(`No Collate field in DESCRIPTION file ${deps.path().toString()}`);
}
}
}
exports.FlowrAnalyzerLoadingOrderDescriptionFilePlugin = FlowrAnalyzerLoadingOrderDescriptionFilePlugin;
//# sourceMappingURL=flowr-analyzer-loading-order-description-file-plugin.js.map