UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

45 lines 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowrAnalyzerRprofileFilePlugin = exports.RenvironFilePattern = exports.RprofileFilePattern = void 0; const flowr_analyzer_file_plugin_1 = require("./flowr-analyzer-file-plugin"); const semver_1 = require("semver"); const flowr_file_1 = require("../../context/flowr-file"); const built_in_source_1 = require("../../../dataflow/internal/process/functions/call/built-in/built-in-source"); /** `Rprofile.site` is the site-wide, `.Rprofile` the user/project profile. */ exports.RprofileFilePattern = /^(\.Rprofile|Rprofile\.site)$/i; /** `.Renviron` is the user/project environment file, `Renviron.site` the site-wide one. */ exports.RenvironFilePattern = /^(\.Renviron|Renviron\.site)$/i; /** * Marks R startup files: profiles (`.Rprofile`, `Rprofile.site`) are R source, so they get * {@link FileRole.Startup} and {@link FileRole.Source}; environment files (`.Renviron`, `Renviron.site`) hold * `KEY=value` definitions rather than R code, so they only get {@link FileRole.Environment}. * The {@link FlowrAnalyzerLoadingOrderRprofilePlugin} moves the profile files to the front of the loading order. */ class FlowrAnalyzerRprofileFilePlugin extends flowr_analyzer_file_plugin_1.FlowrAnalyzerFilePlugin { name = 'flowr-analyzer-rprofile-file-plugin'; description = 'Marks R startup files (.Rprofile, Rprofile.site, .Renviron, Renviron.site).'; version = new semver_1.SemVer('0.2.0'); profilePattern; environPattern; constructor(profilePattern = exports.RprofileFilePattern, environPattern = exports.RenvironFilePattern) { super(); this.profilePattern = profilePattern; this.environPattern = environPattern; } applies(file) { const base = (0, built_in_source_1.platformBasename)(file.toString()); return this.profilePattern.test(base) || this.environPattern.test(base); } process(_ctx, file) { if (this.environPattern.test((0, built_in_source_1.platformBasename)(file.path()))) { file.assignRole(flowr_file_1.FileRole.Environment); } else { file.assignRole(flowr_file_1.FileRole.Startup); file.assignRole(flowr_file_1.FileRole.Source); } return [file, true]; } } exports.FlowrAnalyzerRprofileFilePlugin = FlowrAnalyzerRprofileFilePlugin; //# sourceMappingURL=flowr-analyzer-rprofile-file-plugin.js.map