@eagleoutice/flowr 2.16.8 → 2.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +16 -10
  2. package/abstract-interpretation/absint-inference.d.ts +17 -1
  3. package/abstract-interpretation/absint-inference.js +118 -3
  4. package/abstract-interpretation/data-frame/arguments.d.ts +11 -1
  5. package/abstract-interpretation/data-frame/arguments.js +12 -0
  6. package/abstract-interpretation/domains/lattice.d.ts +2 -0
  7. package/abstract-interpretation/domains/lattice.js +0 -6
  8. package/abstract-interpretation/domains/multi-value-state-domain.d.ts +2 -1
  9. package/abstract-interpretation/domains/multi-value-state-domain.js +7 -3
  10. package/abstract-interpretation/domains/partial-product-domain.js +2 -1
  11. package/abstract-interpretation/domains/state-abstract-domain.d.ts +6 -3
  12. package/abstract-interpretation/domains/state-abstract-domain.js +13 -7
  13. package/abstract-interpretation/domains/state-domain.d.ts +4 -0
  14. package/config.d.ts +32 -0
  15. package/config.js +23 -3
  16. package/control-flow/useless-loop.js +10 -8
  17. package/data/r-primitives.generated.d.ts +1 -0
  18. package/data/r-primitives.generated.js +9 -0
  19. package/data/sigdb/sigdb.remote.json +110 -110
  20. package/dataflow/environments/built-in-props.d.ts +16 -2
  21. package/dataflow/environments/built-in-props.js +23 -3
  22. package/dataflow/environments/built-in.js +13 -3
  23. package/dataflow/environments/default-builtin-config.d.ts +268 -7
  24. package/dataflow/environments/default-builtin-config.js +72 -13
  25. package/dataflow/environments/identifier.d.ts +7 -1
  26. package/dataflow/environments/query-fn-props.d.ts +9 -3
  27. package/dataflow/environments/query-fn-props.js +13 -5
  28. package/dataflow/extractor.js +49 -14
  29. package/dataflow/fn/class-declaration.js +1 -8
  30. package/dataflow/fn/function-semantics.d.ts +1 -0
  31. package/dataflow/graph/df-helper.d.ts +2 -0
  32. package/dataflow/graph/df-helper.js +7 -0
  33. package/documentation/wiki-linter.js +29 -0
  34. package/documentation/wiki-query.js +20 -1
  35. package/linter/linter-executor.js +2 -1
  36. package/linter/linter-rules.d.ts +65 -0
  37. package/linter/linter-rules.js +5 -1
  38. package/linter/rules/cmd-check/global-environment-modification.d.ts +14 -1
  39. package/linter/rules/cmd-check/global-environment-modification.js +15 -7
  40. package/linter/rules/network-functions.js +10 -2
  41. package/linter/rules/no-leaked-credentials.d.ts +1 -0
  42. package/linter/rules/no-leaked-credentials.js +3 -3
  43. package/linter/rules/process-state-in-session.d.ts +71 -0
  44. package/linter/rules/process-state-in-session.js +267 -0
  45. package/linter/rules/secret-exfiltration.d.ts +80 -0
  46. package/linter/rules/secret-exfiltration.js +183 -0
  47. package/linter/rules/unused-import.js +11 -1
  48. package/package.json +1 -1
  49. package/project/cache/flowr-analyzer-cache.d.ts +4 -0
  50. package/project/cache/flowr-analyzer-cache.js +11 -0
  51. package/project/context/flowr-analyzer-dependencies-context.d.ts +3 -0
  52. package/project/context/flowr-analyzer-dependencies-context.js +6 -0
  53. package/project/context/flowr-file.d.ts +2 -2
  54. package/project/context/flowr-file.js +2 -2
  55. package/project/flowr-analyzer.d.ts +6 -0
  56. package/project/flowr-analyzer.js +4 -0
  57. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +39 -4
  58. package/project/plugins/file-plugins/files/flowr-manifest-files.js +134 -30
  59. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +2 -0
  60. package/project/plugins/file-plugins/files/flowr-namespace-file.js +22 -3
  61. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -1
  62. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +7 -0
  63. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +14 -1
  64. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
  65. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
  66. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +18 -5
  67. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +43 -15
  68. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +12 -0
  69. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -2
  70. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +58 -0
  71. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +237 -0
  72. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +8 -0
  73. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +8 -0
  74. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +7 -0
  75. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +24 -18
  76. package/project/plugins/plugin-registry.d.ts +5 -4
  77. package/project/plugins/plugin-registry.js +6 -0
  78. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
  79. package/project/sigdb/decode.js +13 -3
  80. package/project/sigdb/decompress.d.ts +4 -0
  81. package/project/sigdb/decompress.js +60 -25
  82. package/project/sigdb/manifest.d.ts +1 -1
  83. package/project/sigdb/manifest.js +2 -5
  84. package/project/sigdb/memory-source.d.ts +6 -4
  85. package/project/sigdb/memory-source.js +6 -5
  86. package/project/sigdb/on-demand/fetch.d.ts +18 -0
  87. package/project/sigdb/on-demand/fetch.js +127 -0
  88. package/project/sigdb/on-demand/package-sources.d.ts +40 -0
  89. package/project/sigdb/on-demand/package-sources.js +263 -0
  90. package/project/sigdb/on-demand/recoverer.d.ts +40 -0
  91. package/project/sigdb/on-demand/recoverer.js +169 -0
  92. package/project/sigdb/on-demand/remote-sources.d.ts +72 -0
  93. package/project/sigdb/on-demand/remote-sources.js +132 -0
  94. package/project/sigdb/on-demand/tar.d.ts +19 -0
  95. package/project/sigdb/on-demand/tar.js +119 -0
  96. package/project/sigdb/reader.js +15 -6
  97. package/project/sigdb/sigdb-download.d.ts +3 -7
  98. package/project/sigdb/sigdb-download.js +71 -72
  99. package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +5 -0
  100. package/queries/catalog/dependencies-query/function-info/derived-functions.js +17 -1
  101. package/queries/catalog/dependencies-query/function-info/read-functions.js +3 -1
  102. package/queries/catalog/dependencies-query/function-info/write-functions.js +11 -1
  103. package/queries/catalog/taint-query/taint-query-executor.d.ts +7 -0
  104. package/queries/catalog/taint-query/taint-query-executor.js +30 -0
  105. package/queries/catalog/taint-query/taint-query-format.d.ts +29 -0
  106. package/queries/catalog/taint-query/taint-query-format.js +124 -0
  107. package/queries/query.d.ts +12 -1
  108. package/queries/query.js +2 -0
  109. package/r-bridge/data/data.d.ts +29 -0
  110. package/r-bridge/data/data.js +23 -0
  111. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +4 -0
  112. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +8 -0
  113. package/taint-analysis/builder/domain.d.ts +14 -0
  114. package/taint-analysis/builder/domain.js +69 -0
  115. package/taint-analysis/builder/report-template.d.ts +50 -0
  116. package/taint-analysis/builder/report-template.js +46 -0
  117. package/taint-analysis/builder/taint-analysis-definition.d.ts +108 -0
  118. package/taint-analysis/builder/taint-analysis-definition.js +128 -0
  119. package/taint-analysis/builder/taint-analysis.d.ts +124 -0
  120. package/taint-analysis/builder/taint-analysis.js +93 -0
  121. package/taint-analysis/builtin-index-bridge.d.ts +20 -0
  122. package/taint-analysis/builtin-index-bridge.js +48 -0
  123. package/taint-analysis/eval/eval.d.ts +1 -0
  124. package/taint-analysis/eval/eval.js +124 -0
  125. package/taint-analysis/eval/instrumentation.d.ts +59 -0
  126. package/taint-analysis/eval/instrumentation.js +124 -0
  127. package/taint-analysis/finite-domain.d.ts +41 -0
  128. package/taint-analysis/finite-domain.js +118 -0
  129. package/taint-analysis/function-categories.d.ts +31 -0
  130. package/taint-analysis/function-categories.js +61 -0
  131. package/taint-analysis/logger.d.ts +1 -0
  132. package/taint-analysis/logger.js +6 -0
  133. package/taint-analysis/predefined/determinism.d.ts +6 -0
  134. package/taint-analysis/predefined/determinism.js +14 -0
  135. package/taint-analysis/predefined/normalization.d.ts +17 -0
  136. package/taint-analysis/predefined/normalization.js +150 -0
  137. package/taint-analysis/predefined/predefined.d.ts +12 -0
  138. package/taint-analysis/predefined/predefined.js +18 -0
  139. package/taint-analysis/predefined/randomness-analysis.d.ts +6 -0
  140. package/taint-analysis/predefined/randomness-analysis.js +124 -0
  141. package/taint-analysis/predefined/secret-analysis.d.ts +77 -0
  142. package/taint-analysis/predefined/secret-analysis.js +170 -0
  143. package/taint-analysis/predefined/security-analysis.d.ts +7 -0
  144. package/taint-analysis/predefined/security-analysis.js +91 -0
  145. package/taint-analysis/taint-mapping.d.ts +89 -0
  146. package/taint-analysis/taint-mapping.js +81 -0
  147. package/taint-analysis/taint-resolve.d.ts +26 -0
  148. package/taint-analysis/taint-resolve.js +86 -0
  149. package/taint-analysis/taint-visitor.d.ts +80 -0
  150. package/taint-analysis/taint-visitor.js +82 -0
  151. package/util/flowr-version.d.ts +1 -1
  152. package/util/flowr-version.js +2 -2
  153. package/util/r-version.js +4 -2
@@ -36,6 +36,10 @@ export declare class FlowrAnalyzerCache<Parser extends KnownParser> extends Flow
36
36
  reset(): void;
37
37
  private runTapeUntil;
38
38
  private stepTapeUntil;
39
+ /** the normalized AST the dependency plugins already {@link FlowrAnalyzerDependenciesContext#prepare|prepared} for */
40
+ private prepared;
41
+ /** once the AST is there and the dataflow is not, the dependency plugins may wait for what the dataflow asks of them */
42
+ private prepareDataflow;
39
43
  private storeIncrementalSnapshotIfAvailable;
40
44
  /**
41
45
  * Get the parse output for the request, parsing if necessary.
@@ -83,12 +83,23 @@ class FlowrAnalyzerCache extends flowr_cache_1.FlowrCache {
83
83
  async stepTapeUntil(until) {
84
84
  let g;
85
85
  while ((g = until()) === undefined && this.pipeline.hasNextStep()) {
86
+ await this.prepareDataflow();
86
87
  await this.pipeline.nextStep();
87
88
  }
88
89
  this.storeIncrementalSnapshotIfAvailable();
89
90
  (0, assert_1.guard)(g !== undefined, 'Could not reach the desired pipeline step, invalid cache state(?)');
90
91
  return g;
91
92
  }
93
+ /** the normalized AST the dependency plugins already {@link FlowrAnalyzerDependenciesContext#prepare|prepared} for */
94
+ prepared;
95
+ /** once the AST is there and the dataflow is not, the dependency plugins may wait for what the dataflow asks of them */
96
+ async prepareDataflow() {
97
+ const { normalize, dataflow } = this.get();
98
+ if (normalize !== undefined && dataflow === undefined && this.prepared !== normalize) {
99
+ this.prepared = normalize;
100
+ await this.args.context.deps.prepare(normalize);
101
+ }
102
+ }
92
103
  storeIncrementalSnapshotIfAvailable() {
93
104
  if (this.args.parser.name !== 'tree-sitter') {
94
105
  return;
@@ -1,3 +1,4 @@
1
+ import type { NormalizedAst } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
1
2
  import { AbstractFlowrAnalyzerContext } from './abstract-flowr-analyzer-context';
2
3
  import { FlowrAnalyzerPackageVersionsPlugin, type SigDbLoadedInfo } from '../plugins/package-version-plugins/flowr-analyzer-package-versions-plugin';
3
4
  import { Package } from '../plugins/package-version-plugins/package';
@@ -131,6 +132,8 @@ export declare class FlowrAnalyzerDependenciesContext extends AbstractFlowrAnaly
131
132
  baseRSourceFingerprint(): string;
132
133
  /** Mount an additional signature database/source by path (a plain `.sigs.ndjson`, a `.br`, or a manifest). */
133
134
  addDatabaseSource(source: string): Promise<void>;
135
+ /** Lets every version plugin wait for what the dataflow of `ast` will ask of it, see {@link FlowrAnalyzerPackageVersionsPlugin#prepare}. */
136
+ prepare(ast: NormalizedAst): Promise<void>;
134
137
  /** Eagerly mount every version plugin's signature database up front (see `solver.sigdb.eagerlyLoad`). */
135
138
  eagerlyLoadSignatureDatabases(): void;
136
139
  receive(event: InvalidationEvent): void;
@@ -104,6 +104,12 @@ class FlowrAnalyzerDependenciesContext extends abstract_flowr_analyzer_context_1
104
104
  await p.addDatabaseSource(source);
105
105
  }
106
106
  }
107
+ /** Lets every version plugin wait for what the dataflow of `ast` will ask of it, see {@link FlowrAnalyzerPackageVersionsPlugin#prepare}. */
108
+ async prepare(ast) {
109
+ await Promise.all(this.plugins.map(p => p.prepare(this.ctx, ast)));
110
+ /* a package a plugin could not name before may resolve now */
111
+ this.resolvedMisses.clear();
112
+ }
107
113
  /** Eagerly mount every version plugin's signature database up front (see `solver.sigdb.eagerlyLoad`). */
108
114
  eagerlyLoadSignatureDatabases() {
109
115
  for (const p of this.plugins) {
@@ -36,9 +36,9 @@ export declare enum FileRole {
36
36
  Documentation = "documentation",
37
37
  /** Signals separate license files, but please note, that DESCRIPTION files may contain license info too */
38
38
  License = "license",
39
- /** Files describing a project's virtual/pinned package environment, e.g., `renv.lock`, `rv.lock` or `uvr.lock`. */
39
+ /** Files describing a project's virtual/pinned package environment, e.g., `renv.lock`, `rv.lock`, `uvr.lock` or rig's `rproj.lock`. */
40
40
  VirtualEnv = "virtual-env",
41
- /** A project manifest that is no `DESCRIPTION`, e.g. the `rproject.toml` of an rv project or the `uvr.toml` of a uvr project. */
41
+ /** A project manifest that is no `DESCRIPTION`, e.g. the `rproject.toml` of an rv project, the `uvr.toml` of a uvr project or the `rproj.toml` of a rig project. */
42
42
  Manifest = "manifest",
43
43
  /**
44
44
  * R sources evaluated at startup, before any project code (`.Rprofile`, `Rprofile.site`).
@@ -36,9 +36,9 @@ var FileRole;
36
36
  FileRole["Documentation"] = "documentation";
37
37
  /** Signals separate license files, but please note, that DESCRIPTION files may contain license info too */
38
38
  FileRole["License"] = "license";
39
- /** Files describing a project's virtual/pinned package environment, e.g., `renv.lock`, `rv.lock` or `uvr.lock`. */
39
+ /** Files describing a project's virtual/pinned package environment, e.g., `renv.lock`, `rv.lock`, `uvr.lock` or rig's `rproj.lock`. */
40
40
  FileRole["VirtualEnv"] = "virtual-env";
41
- /** A project manifest that is no `DESCRIPTION`, e.g. the `rproject.toml` of an rv project or the `uvr.toml` of a uvr project. */
41
+ /** A project manifest that is no `DESCRIPTION`, e.g. the `rproject.toml` of an rv project, the `uvr.toml` of a uvr project or the `rproj.toml` of a rig project. */
42
42
  FileRole["Manifest"] = "manifest";
43
43
  /**
44
44
  * R sources evaluated at startup, before any project code (`.Rprofile`, `Rprofile.site`).
@@ -17,6 +17,7 @@ import { fileProtocol } from '../r-bridge/retriever';
17
17
  import type { FlowrFileProvider } from './context/flowr-file';
18
18
  import type { Tree } from 'web-tree-sitter';
19
19
  import type { CallGraph } from '../dataflow/graph/call-graph';
20
+ import { type TaintAnalysisBuilder } from '../taint-analysis/builder/taint-analysis';
20
21
  import type { InvalidationEvent } from './cache/flowr-cache';
21
22
  import type { GasOverrides } from '../gas';
22
23
  import type { FnInfo } from '../dataflow/environments/query-fn-props';
@@ -160,6 +161,10 @@ export interface ReadonlyFlowrAnalysisProvider<Parser extends KnownParser = Know
160
161
  * @param options - Bounds for this call, see {@link FlowrAnalysisOptions}.
161
162
  */
162
163
  query<Types extends SupportedQueryTypes = SupportedQueryTypes>(query: Queries<Types>, options?: FlowrAnalysisOptions): Promise<QueryResults<Types>>;
164
+ /**
165
+ * Access the taint analysis API for the request.
166
+ */
167
+ taint<Names extends readonly string[] = []>(): TaintAnalysisBuilder<Names>;
163
168
  /**
164
169
  * Run a search on the current analysis.
165
170
  * @param search - The search to run.
@@ -240,6 +245,7 @@ export declare class FlowrAnalyzer<Parser extends KnownParser = KnownParser> imp
240
245
  peekCallGraph(): CallGraph | undefined;
241
246
  query<Types extends SupportedQueryTypes = SupportedQueryTypes>(query: Queries<Types>, options?: FlowrAnalysisOptions): Promise<QueryResults<Types>>;
242
247
  runSearch<Search extends FlowrSearchLike>(search: Search, options?: FlowrAnalysisOptions): Promise<GetSearchElements<SearchOutput<Search>>>;
248
+ taint<Names extends readonly string[] = []>(): TaintAnalysisBuilder<Names>;
243
249
  /**
244
250
  * Free the cached analyses (including any WASM-backed parse trees) and close the parser.
245
251
  * Closing is only required for an RShell/remote engine, but this also frees the cached parse trees.
@@ -8,6 +8,7 @@ const retriever_1 = require("../r-bridge/retriever");
8
8
  const files_1 = require("../util/files");
9
9
  const tree_sitter_normalize_1 = require("../r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize");
10
10
  const tree_sitter_executor_1 = require("../r-bridge/lang-4.x/tree-sitter/tree-sitter-executor");
11
+ const taint_analysis_1 = require("../taint-analysis/builder/taint-analysis");
11
12
  const vertex_1 = require("../dataflow/graph/vertex");
12
13
  const df_helper_1 = require("../dataflow/graph/df-helper");
13
14
  /**
@@ -169,6 +170,9 @@ class FlowrAnalyzer {
169
170
  async runSearch(search, options) {
170
171
  return this.ctx.gas.withGas(options?.gas, () => (0, flowr_search_executor_1.runSearch)(search, this));
171
172
  }
173
+ taint() {
174
+ return taint_analysis_1.TaintAnalysis.create(this);
175
+ }
172
176
  /**
173
177
  * Free the cached analyses (including any WASM-backed parse trees) and close the parser.
174
178
  * Closing is only required for an RShell/remote engine, but this also frees the cached parse trees.
@@ -3,11 +3,20 @@ import type { DeepReadonly } from 'ts-essentials';
3
3
  import type { DeclaredPackages } from '../../../context/flowr-analyzer-meta-context';
4
4
  import { Package } from '../../package-version-plugins/package';
5
5
  export declare const manifestFileLog: import("tslog").Logger<import("tslog").ILogObj>;
6
+ /** what a project manifest declares, whether it is a file of its own or a block within a script */
7
+ export interface ProjectManifest {
8
+ /** unlike the `Package` of a `DESCRIPTION` this is no namespace, such a project is no package */
9
+ projectName(): string | undefined;
10
+ /** `undefined` if the manifest only states a requirement like `>=4.0.0` */
11
+ rVersion(): string | undefined;
12
+ /** grouped as a `DESCRIPTION` groups them */
13
+ declares(): DeclaredPackages;
14
+ }
6
15
  /**
7
- * A project manifest that is no `DESCRIPTION` (an rv `rproject.toml`, a uvr `uvr.toml`).
16
+ * A project manifest that is no `DESCRIPTION` (an rv `rproject.toml`, a uvr `uvr.toml`, a rig `rproj.toml`).
8
17
  * Prefer the static `from` method of the concrete subclass, which avoids re-wrapping and handles roles.
9
18
  */
10
- export declare abstract class FlowrManifestFile<Content extends StringableContent = StringableContent> extends FlowrWrappedFile<Content> {
19
+ export declare abstract class FlowrManifestFile<Content extends StringableContent = StringableContent> extends FlowrWrappedFile<Content> implements ProjectManifest {
11
20
  /** unlike the `Package` of a `DESCRIPTION` this is no namespace, such a project is no package */
12
21
  abstract projectName(): string | undefined;
13
22
  /** `undefined` if the manifest only states a requirement like `>=4.0.0` */
@@ -50,7 +59,33 @@ export declare class FlowrUvrManifestFile extends FlowrManifestFile<DeepReadonly
50
59
  /** uvr usually states a requirement (`>=4.0.0`), which pins nothing; the `uvr.lock` holds the resolved version */
51
60
  rVersion(): string | undefined;
52
61
  declares(): DeclaredPackages;
53
- /** a table mapping the name to a bare requirement (`">=3.0.0"`, `"*"`) or to one with its origin (`{ version = ..., git = ... }`) */
54
- private packagesOf;
55
62
  }
63
+ /**
64
+ * The tables of a [rig](https://rig.r-lib.org/proj-guide.html) project manifest (`src/rproj.rs` of rig), of which a
65
+ * script states `[dependencies]` in its inline block.
66
+ */
67
+ interface RigManifest {
68
+ project?: {
69
+ name?: unknown;
70
+ };
71
+ dependencies?: unknown;
72
+ 'linking-dependencies'?: unknown;
73
+ 'dependency-groups'?: unknown;
74
+ 'optional-dependencies'?: unknown;
75
+ }
76
+ /** The `rproj.toml` of a [rig](https://rig.r-lib.org/proj-guide.html) project, lifted by {@link FlowrRigProjectFile.from}. */
77
+ export declare class FlowrRigProjectFile extends FlowrManifestFile<DeepReadonly<RigManifest>> {
78
+ protected loadContent(): RigManifest;
79
+ projectName(): string | undefined;
80
+ rVersion(): string | undefined;
81
+ declares(): DeclaredPackages;
82
+ }
83
+ /**
84
+ * The manifest a rig script states inline, read as rig reads it (`src/script_meta.rs` of rig): the one comment block
85
+ * opened by a line that is exactly `# /// script` (or `## /// script`), anywhere in the file, and closed by `# ///`
86
+ * with the same marker. Every line in between starts with that marker, and without it (and one space) the lines are
87
+ * TOML holding `[dependencies]`, `[[repository]]` and `[tool]`. As rig refuses to run the script otherwise, a second
88
+ * block, an unclosed block, a line without the marker, broken TOML or any other table declare nothing.
89
+ */
90
+ export declare function rigScriptManifest(code: string, origin: string): ProjectManifest | undefined;
56
91
  export {};
@@ -1,28 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlowrUvrManifestFile = exports.FlowrRProjectFile = exports.FlowrManifestFile = exports.manifestFileLog = void 0;
3
+ exports.FlowrRigProjectFile = exports.FlowrUvrManifestFile = exports.FlowrRProjectFile = exports.FlowrManifestFile = exports.manifestFileLog = void 0;
4
+ exports.rigScriptManifest = rigScriptManifest;
4
5
  const flowr_file_1 = require("../../../context/flowr-file");
5
6
  const package_1 = require("../../package-version-plugins/package");
6
7
  const smol_toml_1 = require("smol-toml");
7
8
  const log_1 = require("../../../../util/log");
8
9
  exports.manifestFileLog = log_1.log.getSubLogger({ name: 'flowr-manifest-file' });
9
10
  /**
10
- * A project manifest that is no `DESCRIPTION` (an rv `rproject.toml`, a uvr `uvr.toml`).
11
+ * A project manifest that is no `DESCRIPTION` (an rv `rproject.toml`, a uvr `uvr.toml`, a rig `rproj.toml`).
11
12
  * Prefer the static `from` method of the concrete subclass, which avoids re-wrapping and handles roles.
12
13
  */
13
14
  class FlowrManifestFile extends flowr_file_1.FlowrWrappedFile {
14
15
  /** the parsed TOML of the wrapped file, empty (with a warning) if it does not parse */
15
16
  parseTomlContent() {
16
- try {
17
- return (0, smol_toml_1.parse)(this.wrapped.content().toString());
18
- }
19
- catch (e) {
20
- exports.manifestFileLog.warn(`Could not parse ${this.wrapped.path()}: ${e.message}`);
21
- return {};
22
- }
17
+ return parseTomlOrEmpty(this.wrapped.content().toString(), this.wrapped.path());
23
18
  }
24
19
  }
25
20
  exports.FlowrManifestFile = FlowrManifestFile;
21
+ function parseTomlOrEmpty(toml, origin) {
22
+ try {
23
+ return (0, smol_toml_1.parse)(toml);
24
+ }
25
+ catch (e) {
26
+ exports.manifestFileLog.warn(`Could not parse ${origin}: ${e.message}`);
27
+ return {};
28
+ }
29
+ }
30
+ /** a requirement that starts with a version (`4.4`) pins one; `>= 4.4` or `*` only constrains */
31
+ function pinnedVersion(version) {
32
+ const trimmed = typeof version === 'string' ? version.trim() : '';
33
+ return /^\d/.test(trimmed) ? trimmed : undefined;
34
+ }
35
+ /**
36
+ * The entries of a table mapping a package name to a bare requirement (`">=3.0.0"`, `"*"`, `">= 1.0, < 2.0"`) or to
37
+ * one with its origin (`{ version = ..., git = ... }`), as uvr and rig write them. Anything else (an array such as
38
+ * rig's `include-groups`) names no package.
39
+ */
40
+ function dependencyEntries(table) {
41
+ // an array is no such table, and its indices would pass as package names
42
+ if (!isTable(table)) {
43
+ return [];
44
+ }
45
+ return Object.entries(table).filter((e) => e[0].length > 0 && (typeof e[1] === 'string' || isTable(e[1])));
46
+ }
47
+ function isTable(value) {
48
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
49
+ }
50
+ function packageOf([name, spec]) {
51
+ const version = typeof spec === 'string' ? spec : spec.version;
52
+ // `*` accepts anything, so it constrains nothing
53
+ const range = typeof version === 'string' && version !== '*' ? package_1.Package.parsePkgVersionRange(undefined, version) : undefined;
54
+ return new package_1.Package({ name, type: 'package', versionConstraints: range ? [range] : undefined });
55
+ }
56
+ function packagesOf(table) {
57
+ return dependencyEntries(table).map(packageOf);
58
+ }
59
+ /** the packages of every table in `groups` (`[dependency-groups.dev]`, `[optional-dependencies.plot]`) */
60
+ function packagesOfGroups(groups) {
61
+ return isTable(groups) ? Object.values(groups).flatMap(packagesOf) : [];
62
+ }
26
63
  /** The `rproject.toml` of an [rv](https://a2-ai.github.io/rv-docs/) project, lifted by {@link FlowrRProjectFile.from}. */
27
64
  class FlowrRProjectFile extends FlowrManifestFile {
28
65
  loadContent() {
@@ -69,34 +106,101 @@ class FlowrUvrManifestFile extends FlowrManifestFile {
69
106
  }
70
107
  /** uvr usually states a requirement (`>=4.0.0`), which pins nothing; the `uvr.lock` holds the resolved version */
71
108
  rVersion() {
72
- const version = this.content().project?.r_version;
73
- const trimmed = typeof version === 'string' ? version.trim() : '';
74
- return /^\d/.test(trimmed) ? trimmed : undefined;
109
+ return pinnedVersion(this.content().project?.r_version);
75
110
  }
76
111
  declares() {
77
112
  return {
78
- imports: this.packagesOf(this.content().dependencies),
79
- suggests: this.packagesOf(this.content()['dev-dependencies'])
113
+ imports: packagesOf(this.content().dependencies),
114
+ suggests: packagesOf(this.content()['dev-dependencies'])
80
115
  };
81
116
  }
82
- /** a table mapping the name to a bare requirement (`">=3.0.0"`, `"*"`) or to one with its origin (`{ version = ..., git = ... }`) */
83
- packagesOf(table) {
84
- // an array is no such table, and its indices would pass as package names
85
- if (typeof table !== 'object' || table === null || Array.isArray(table)) {
86
- return [];
117
+ }
118
+ exports.FlowrUvrManifestFile = FlowrUvrManifestFile;
119
+ function rigRVersion(manifest) {
120
+ const deps = manifest.dependencies;
121
+ return isTable(deps) ? pinnedVersion(deps.R) : undefined;
122
+ }
123
+ /**
124
+ * Grouped as a `DESCRIPTION` groups them: `R` in `[dependencies]` is the requirement on R itself (`Depends`), an entry
125
+ * marked `enhances = true` is an `Enhances`, `[linking-dependencies]` is `LinkingTo`. Dependency groups and optional
126
+ * dependencies are reported but not needed to run the project, like `Suggests`.
127
+ */
128
+ function rigDeclares(manifest) {
129
+ const deps = dependencyEntries(manifest.dependencies);
130
+ const enhances = (e) => typeof e[1] !== 'string' && e[1].enhances === true;
131
+ return {
132
+ depends: deps.filter(e => e[0] === 'R').map(packageOf),
133
+ imports: deps.filter(e => e[0] !== 'R' && !enhances(e)).map(packageOf),
134
+ enhances: deps.filter(enhances).map(packageOf),
135
+ linkingTo: packagesOf(manifest['linking-dependencies']),
136
+ suggests: [...packagesOfGroups(manifest['dependency-groups']), ...packagesOfGroups(manifest['optional-dependencies'])]
137
+ };
138
+ }
139
+ /** The `rproj.toml` of a [rig](https://rig.r-lib.org/proj-guide.html) project, lifted by {@link FlowrRigProjectFile.from}. */
140
+ class FlowrRigProjectFile extends FlowrManifestFile {
141
+ loadContent() {
142
+ return this.parseTomlContent();
143
+ }
144
+ projectName() {
145
+ const name = this.content().project?.name;
146
+ return typeof name === 'string' ? name : undefined;
147
+ }
148
+ rVersion() {
149
+ return rigRVersion(this.content());
150
+ }
151
+ declares() {
152
+ return rigDeclares(this.content());
153
+ }
154
+ }
155
+ exports.FlowrRigProjectFile = FlowrRigProjectFile;
156
+ /** the comment markers a rig script block may use, `##` first as `#` is its prefix */
157
+ const RigBlockMarkers = ['##', '#'];
158
+ /** the only tables a script block may hold, rig rejects the script for any other */
159
+ const RigScriptTables = new Set(['dependencies', 'repository', 'tool']);
160
+ /**
161
+ * The manifest a rig script states inline, read as rig reads it (`src/script_meta.rs` of rig): the one comment block
162
+ * opened by a line that is exactly `# /// script` (or `## /// script`), anywhere in the file, and closed by `# ///`
163
+ * with the same marker. Every line in between starts with that marker, and without it (and one space) the lines are
164
+ * TOML holding `[dependencies]`, `[[repository]]` and `[tool]`. As rig refuses to run the script otherwise, a second
165
+ * block, an unclosed block, a line without the marker, broken TOML or any other table declare nothing.
166
+ */
167
+ function rigScriptManifest(code, origin) {
168
+ const lines = code.split('\n').map(l => l.replace(/\r$/, ''));
169
+ const opens = lines.flatMap((line, i) => {
170
+ const marker = RigBlockMarkers.find(m => line.trimEnd() === `${m} /// script`);
171
+ return marker === undefined ? [] : [{ i, marker }];
172
+ });
173
+ if (opens.length !== 1) {
174
+ return undefined;
175
+ }
176
+ const { i: start, marker } = opens[0];
177
+ const body = [];
178
+ for (const line of lines.slice(start + 1)) {
179
+ if (line.trimEnd() === `${marker} ///`) {
180
+ return rigScriptOf(body.join('\n'), origin);
87
181
  }
88
- const out = [];
89
- for (const [name, spec] of Object.entries(table)) {
90
- if (name.length === 0) {
91
- continue;
92
- }
93
- const version = typeof spec === 'string' ? spec : spec?.version;
94
- // `*` accepts anything, so it constrains nothing
95
- const range = typeof version === 'string' && version !== '*' ? package_1.Package.parsePkgVersionRange(undefined, version) : undefined;
96
- out.push(new package_1.Package({ name, type: 'package', versionConstraints: range ? [range] : undefined }));
182
+ if (!line.startsWith(marker)) {
183
+ return undefined;
97
184
  }
98
- return out;
185
+ const rest = line.slice(marker.length);
186
+ body.push(rest.startsWith(' ') ? rest.slice(1) : rest);
99
187
  }
188
+ return undefined;
189
+ }
190
+ function rigScriptOf(toml, origin) {
191
+ let parsed;
192
+ try {
193
+ parsed = (0, smol_toml_1.parse)(toml);
194
+ }
195
+ catch (e) {
196
+ exports.manifestFileLog.warn(`Could not parse the rig script block of ${origin}: ${e.message}`);
197
+ return undefined;
198
+ }
199
+ if (Object.keys(parsed).some(k => !RigScriptTables.has(k))) {
200
+ exports.manifestFileLog.warn(`The rig script block of ${origin} holds a table rig does not allow, rig would not run it`);
201
+ return undefined;
202
+ }
203
+ const manifest = { dependencies: parsed.dependencies };
204
+ return { projectName: () => undefined, rVersion: () => rigRVersion(manifest), declares: () => rigDeclares(manifest) };
100
205
  }
101
- exports.FlowrUvrManifestFile = FlowrUvrManifestFile;
102
206
  //# sourceMappingURL=flowr-manifest-files.js.map
@@ -9,6 +9,8 @@ export interface NamespaceInfo {
9
9
  /**
10
10
  * Names listed by `exportMethods()`: S4 methods the package registered for one of its classes, which is a
11
11
  * different claim than an ordinary export (the package answers a generic, it does not define the function).
12
+ * As R's `loadNamespace`, this keeps only the non-primitive generics: a method on a primitive such as `+` or `[`
13
+ * binds nothing in the namespace, so `pkg::"+"` does not exist and the call stays with base.
12
14
  * Only the context-parsed path ({@link parseNamespaceComplex}) tells these apart; the regex fallback folds
13
15
  * them into {@link exportedFunctions}.
14
16
  */
@@ -14,6 +14,7 @@ const fold_1 = require("../../../../r-bridge/lang-4.x/ast/model/processing/fold"
14
14
  const identifier_1 = require("../../../../dataflow/environments/identifier");
15
15
  const assert_1 = require("../../../../util/assert");
16
16
  const type_1 = require("../../../../r-bridge/lang-4.x/ast/model/type");
17
+ const r_primitives_generated_1 = require("../../../../data/r-primitives.generated");
17
18
  const make_argument_1 = require("../../../../dataflow/internal/process/functions/call/argument/make-argument");
18
19
  const range_1 = require("../../../../util/range");
19
20
  const r_regex_1 = require("../../../../util/r-regex");
@@ -334,9 +335,15 @@ function handleUseDynLibCall(g, args) {
334
335
  }
335
336
  /** `exportClasses(A, B)` / `exportMethods(show, summary)`: a directive may list several names, and each goes to `into`. */
336
337
  function handleS4ExportCall(g, args, into) {
337
- pushUnquotedLexemes(g.current[into], args, r_string_1.RString.unquote);
338
+ const names = [];
339
+ pushUnquotedLexemes(names, args, r_string_1.RString.unquote);
340
+ g.current[into].push(...(into === 'exportedS4Methods' ? exportedGenerics(names) : names));
338
341
  return g;
339
342
  }
343
+ /** The `exportMethods()` names R exports: methods on a primitive generic bind nothing in the namespace. */
344
+ function exportedGenerics(names) {
345
+ return names.filter(n => !r_primitives_generated_1.RPrimitives.has(n));
346
+ }
340
347
  const cleanLineCommentRegex = /^#.*$/gm;
341
348
  /** A namespace that neither exports nor imports anything yet. */
342
349
  function emptyNamespaceInfo() {
@@ -439,9 +446,21 @@ function splitNamespaceArgs(args) {
439
446
  const names = [];
440
447
  let depth = 0;
441
448
  let start = 0;
449
+ let quote;
442
450
  for (let i = 0; i <= args.length; i++) {
443
451
  const c = args[i];
444
- if (c === '(' || c === '[') {
452
+ if (quote !== undefined) {
453
+ if (c === '\\') {
454
+ i++;
455
+ }
456
+ else if (c === quote) {
457
+ quote = undefined;
458
+ }
459
+ }
460
+ else if (c === '"' || c === '\'' || c === '`') {
461
+ quote = c;
462
+ }
463
+ else if (c === '(' || c === '[') {
445
464
  depth++;
446
465
  }
447
466
  else if (c === ')' || c === ']') {
@@ -474,7 +493,7 @@ function parseNamespaceSimple(file) {
474
493
  case 'exportClasses':
475
494
  case 'exportMethods':
476
495
  // a single directive may list several symbols, e.g. `exportMethods(show, summary)`
477
- result.current.exportedFunctions.push(...splitNamespaceArgs(args));
496
+ result.current.exportedFunctions.push(...exportedGenerics(splitNamespaceArgs(args)));
478
497
  break;
479
498
  case 'S3method':
480
499
  {
@@ -77,7 +77,7 @@ class FlowrRMarkdownFile extends flowr_file_1.FlowrFile {
77
77
  ctx: this.context,
78
78
  referenceChain: [this.path()]
79
79
  });
80
- if (childPath === undefined) {
80
+ if (childPath === undefined || childPath.length === 0) {
81
81
  continue;
82
82
  }
83
83
  if (childPath.length > 1) {
@@ -23,4 +23,11 @@ export declare class FlowrAnalyzerUvrManifestFilePlugin extends FlowrAnalyzerMan
23
23
  constructor(pathPattern?: RegExp);
24
24
  process(_ctx: FlowrAnalyzerContext, file: FlowrFileProvider): [FlowrFileProvider, true];
25
25
  }
26
+ /** Lifts a rig `rproj.toml` to a {@link FlowrRigProjectFile}. */
27
+ export declare class FlowrAnalyzerRigProjectFilePlugin extends FlowrAnalyzerManifestFilePlugin {
28
+ readonly name = "flowr-analyzer-rig-project-file-plugin";
29
+ readonly description = "Marks the rproj.toml manifest of a rig project.";
30
+ constructor(pathPattern?: RegExp);
31
+ process(_ctx: FlowrAnalyzerContext, file: FlowrFileProvider): [FlowrFileProvider, true];
32
+ }
26
33
  export {};
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlowrAnalyzerUvrManifestFilePlugin = exports.FlowrAnalyzerRProjectFilePlugin = void 0;
3
+ exports.FlowrAnalyzerRigProjectFilePlugin = exports.FlowrAnalyzerUvrManifestFilePlugin = exports.FlowrAnalyzerRProjectFilePlugin = void 0;
4
4
  const flowr_analyzer_file_plugin_1 = require("./flowr-analyzer-file-plugin");
5
5
  const semver_1 = require("semver");
6
6
  const flowr_file_1 = require("../../context/flowr-file");
7
7
  const flowr_manifest_files_1 = require("./files/flowr-manifest-files");
8
8
  const RProjectFilePattern = /^rproject\.toml$/i;
9
9
  const UvrManifestFilePattern = /^uvr\.toml$/i;
10
+ const RigProjectFilePattern = /^rproj\.toml$/i;
10
11
  /**
11
12
  * Tags a project manifest with the {@link FileRole.Manifest} role and lifts it, so the meta plugins reading it
12
13
  * can look it up by role.
@@ -38,4 +39,16 @@ class FlowrAnalyzerUvrManifestFilePlugin extends FlowrAnalyzerManifestFilePlugin
38
39
  }
39
40
  }
40
41
  exports.FlowrAnalyzerUvrManifestFilePlugin = FlowrAnalyzerUvrManifestFilePlugin;
42
+ /** Lifts a rig `rproj.toml` to a {@link FlowrRigProjectFile}. */
43
+ class FlowrAnalyzerRigProjectFilePlugin extends FlowrAnalyzerManifestFilePlugin {
44
+ name = 'flowr-analyzer-rig-project-file-plugin';
45
+ description = 'Marks the rproj.toml manifest of a rig project.';
46
+ constructor(pathPattern = RigProjectFilePattern) {
47
+ super(pathPattern);
48
+ }
49
+ process(_ctx, file) {
50
+ return [flowr_manifest_files_1.FlowrRigProjectFile.from(file, flowr_file_1.FileRole.Manifest), true];
51
+ }
52
+ }
53
+ exports.FlowrAnalyzerRigProjectFilePlugin = FlowrAnalyzerRigProjectFilePlugin;
41
54
  //# sourceMappingURL=flowr-analyzer-manifest-file-plugin.js.map
@@ -7,7 +7,7 @@ import { FileRole } from '../../context/flowr-file';
7
7
  */
8
8
  export declare class FlowrAnalyzerVirtualEnvFilePlugin extends FlowrAnalyzerRoleFilePlugin {
9
9
  readonly name = "flowr-analyzer-virtualenv-files-plugin";
10
- readonly description = "Marks virtual-environment lockfiles (renv.lock, rv.lock, uvr.lock).";
10
+ readonly description = "Marks virtual-environment lockfiles (renv.lock, rv.lock, uvr.lock, packrat.lock, rig lockfiles).";
11
11
  readonly version: SemVer;
12
12
  protected readonly roles: FileRole[];
13
13
  /**
@@ -4,15 +4,15 @@ exports.FlowrAnalyzerVirtualEnvFilePlugin = void 0;
4
4
  const flowr_analyzer_file_plugin_1 = require("./flowr-analyzer-file-plugin");
5
5
  const semver_1 = require("semver");
6
6
  const flowr_file_1 = require("../../context/flowr-file");
7
- /** Lockfiles pinning a project's package environment (`renv.lock`, `rv.lock`, `uvr.lock`, `packrat.lock`). */
8
- const VirtualEnvFilePattern = /^(renv|rv|uvr|packrat)\.lock$/i;
7
+ /** Lockfiles pinning a project's package environment (`renv.lock`, `rv.lock`, `uvr.lock`, `packrat.lock`, rig's `rproj.lock` and `<script>.R.lock`). */
8
+ const VirtualEnvFilePattern = /^(renv|rv|uvr|packrat|rproj|.+\.r)\.lock$/i;
9
9
  /**
10
10
  * Tags a project's virtual-environment lockfiles with the {@link FileRole.VirtualEnv} role, so the version
11
11
  * plugins that read them can look them up by role instead of scanning every project file.
12
12
  */
13
13
  class FlowrAnalyzerVirtualEnvFilePlugin extends flowr_analyzer_file_plugin_1.FlowrAnalyzerRoleFilePlugin {
14
14
  name = 'flowr-analyzer-virtualenv-files-plugin';
15
- description = 'Marks virtual-environment lockfiles (renv.lock, rv.lock, uvr.lock).';
15
+ description = 'Marks virtual-environment lockfiles (renv.lock, rv.lock, uvr.lock, packrat.lock, rig lockfiles).';
16
16
  version = new semver_1.SemVer('0.1.0');
17
17
  roles = [flowr_file_1.FileRole.VirtualEnv];
18
18
  /**
@@ -1,11 +1,8 @@
1
1
  import { FlowrAnalyzerPackageVersionsPlugin } from './flowr-analyzer-package-versions-plugin';
2
2
  import { SemVer } from 'semver';
3
3
  import type { FlowrAnalyzerContext } from '../../context/flowr-analyzer-context';
4
- import { FlowrRProjectFile, FlowrUvrManifestFile } from '../file-plugins/files/flowr-manifest-files';
5
- /**
6
- * Extracts the project metadata and the declared dependencies from a project manifest. The name is contributed
7
- * without a namespace: such a project is no package, so `a::b` must not resolve against it.
8
- */
4
+ import { FlowrRigProjectFile, FlowrRProjectFile, FlowrUvrManifestFile } from '../file-plugins/files/flowr-manifest-files';
5
+ /** Extracts the project metadata and the declared dependencies from a project manifest. */
9
6
  declare abstract class FlowrAnalyzerMetaManifestFilePlugin extends FlowrAnalyzerPackageVersionsPlugin {
10
7
  readonly version: SemVer;
11
8
  /** the manifest flavor this plugin reads, the others are left to their own plugin */
@@ -24,4 +21,20 @@ export declare class FlowrAnalyzerMetaUvrManifestFilePlugin extends FlowrAnalyze
24
21
  readonly description = "Extracts project meta information and dependencies from a uvr.toml.";
25
22
  protected readonly reads: typeof FlowrUvrManifestFile;
26
23
  }
24
+ /** Reads a rig `rproj.toml`, whose dependency groups and optional dependencies land in `suggests`. */
25
+ export declare class FlowrAnalyzerMetaRigProjectFilePlugin extends FlowrAnalyzerMetaManifestFilePlugin {
26
+ readonly name = "flowr-analyzer-meta-rig-project-file-plugin";
27
+ readonly description = "Extracts project meta information and dependencies from a rig rproj.toml.";
28
+ protected readonly reads: typeof FlowrRigProjectFile;
29
+ }
30
+ /**
31
+ * Reads the inline `# /// script` block a rig script states its dependencies in (see {@link rigScriptManifest}),
32
+ * in R scripts and notebooks alike, as the code of a notebook is what its top is checked for.
33
+ */
34
+ export declare class FlowrAnalyzerMetaRigScriptPlugin extends FlowrAnalyzerPackageVersionsPlugin {
35
+ readonly name = "flowr-analyzer-meta-rig-script-plugin";
36
+ readonly description = "Extracts the dependencies a rig script declares in its inline # /// script block.";
37
+ readonly version: SemVer;
38
+ process(ctx: FlowrAnalyzerContext): void;
39
+ }
27
40
  export {};