@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
33 lines • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlowrAnalyzerLoadingOrderRprofilePlugin = void 0;
const semver_1 = require("semver");
const flowr_analyzer_loading_order_plugin_1 = require("./flowr-analyzer-loading-order-plugin");
const flowr_file_1 = require("../../context/flowr-file");
/** `Rprofile.site` is evaluated before the project's `.Rprofile`, mirroring R's startup sequence. */
function startupRank(path) {
return /Rprofile\.site$/i.test(path) ? 0 : 1;
}
/**
* Moves the R startup profiles ({@link FileRole.Startup}, tagged by {@link FlowrAnalyzerRprofileFilePlugin})
* to the front of the loading order, as R evaluates them before any project code.
*
* This refines the orders the other loading-order plugins produced, so register it after them.
*/
class FlowrAnalyzerLoadingOrderRprofilePlugin extends flowr_analyzer_loading_order_plugin_1.FlowrAnalyzerLoadingOrderPlugin {
name = 'flowr-analyzer-loading-order-rprofile-plugin';
description = 'Loads the R startup profiles (.Rprofile, Rprofile.site) before any project code.';
version = new semver_1.SemVer('0.1.0');
process(ctx) {
const startup = new Set(ctx.files.getFilesByRole(flowr_file_1.FileRole.Startup).map(f => f.path()));
if (startup.size === 0) {
return;
}
const requests = ctx.files.loadingOrder.getUnorderedRequests()
.filter((r) => r.request === 'file' && startup.has(r.content))
.sort((a, b) => startupRank(a.content) - startupRank(b.content));
ctx.files.loadingOrder.prependToOrder(requests);
}
}
exports.FlowrAnalyzerLoadingOrderRprofilePlugin = FlowrAnalyzerLoadingOrderRprofilePlugin;
//# sourceMappingURL=flowr-analyzer-loading-order-rprofile-plugin.js.map