UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

71 lines 4.11 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowrAnalyzerProjectDiscoveryPlugin = void 0; const flowr_analyzer_plugin_1 = require("../flowr-analyzer-plugin"); const semver_1 = require("semver"); const flowr_file_1 = require("../../context/flowr-file"); const files_1 = require("../../../util/files"); const built_in_source_1 = require("../../../dataflow/internal/process/functions/call/built-in/built-in-source"); const path_1 = __importDefault(require("path")); /** * This is the base class for all plugins that discover files in a project for analysis. * These plugins interplay with the {@link FlowrAnalyzerFilesContext} to gather information about the files in the project. * See {@link DefaultFlowrAnalyzerProjectDiscoveryPlugin} for the dummy default implementation. * * In general, these plugins only trigger for a {@link RProjectAnalysisRequest} with the idea to discover all files in a project. */ class FlowrAnalyzerProjectDiscoveryPlugin extends flowr_analyzer_plugin_1.FlowrAnalyzerPlugin { type = flowr_analyzer_plugin_1.PluginType.ProjectDiscovery; static defaultPlugin() { return new DefaultFlowrAnalyzerProjectDiscoveryPlugin(); } } exports.FlowrAnalyzerProjectDiscoveryPlugin = FlowrAnalyzerProjectDiscoveryPlugin; const discoverRSourcesRegex = /\.(r|rmd|ipynb|qmd|rnw)$/i; const ignorePathsWith = /(\.git|\.svn|\.hg|renv|packrat|node_modules|__pycache__|\.Rproj\.user)/i; const excludeRequestsForPaths = /vignettes?|tests?|revdep|inst|data/i; /** * This is the default dummy implementation of the {@link FlowrAnalyzerProjectDiscoveryPlugin}. * It simply collects all files in the given folder and returns them as either {@link RParseRequest} (for R and Rmd files) or {@link FlowrTextFile} (for all other files). */ class DefaultFlowrAnalyzerProjectDiscoveryPlugin extends FlowrAnalyzerProjectDiscoveryPlugin { name = 'default-project-discovery-plugin'; description = 'This is the default project discovery plugin that does nothing.'; version = new semver_1.SemVer('0.0.0'); supportedExtensions; ignorePathsRegex; excludePathsRegex = excludeRequestsForPaths; onlyTraversePaths; /** * Creates a new instance of the default project discovery plugin. * @param triggerOnExtensions - the regex to trigger R source file discovery on (and hence analyze them as R files) * @param ignorePathsRegex - the regex to ignore certain paths entirely * @param excludePathsRegex - the regex to exclude certain paths from being requested as R files (they are still collected as text files) * @param onlyTraversePaths - if set, only paths matching this regex are traversed */ constructor({ triggerOnExtensions = discoverRSourcesRegex, ignorePathsRegex = ignorePathsWith, excludePathsRegex = excludeRequestsForPaths, onlyTraversePaths } = {}) { super(); this.supportedExtensions = triggerOnExtensions; this.ignorePathsRegex = ignorePathsRegex; this.excludePathsRegex = excludePathsRegex; this.onlyTraversePaths = onlyTraversePaths; } process(_context, args) { const requests = []; /* the dummy approach of collecting all files, group R and Rmd files, and be done with it */ for (const file of (0, files_1.getAllFilesSync)(args.content, /.*/, this.ignorePathsRegex)) { const relativePath = path_1.default.relative(args.content, file); if (this.supportedExtensions.test(relativePath) && (!this.onlyTraversePaths || this.onlyTraversePaths.test(relativePath)) && !this.excludePathsRegex.test((0, built_in_source_1.platformDirname)(relativePath))) { requests.push({ content: file, request: 'file' }); } else { requests.push(new flowr_file_1.FlowrTextFile(file)); } } return requests; } } //# sourceMappingURL=flowr-analyzer-project-discovery-plugin.js.map