@eagleoutice/flowr 2.13.5 → 2.13.7

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 (28) hide show
  1. package/README.md +28 -28
  2. package/config.d.ts +1 -1
  3. package/config.js +1 -0
  4. package/dataflow/environments/built-in-props.d.ts +1 -1
  5. package/dataflow/environments/built-in-props.js +1 -1
  6. package/dataflow/environments/default-builtin-config.d.ts +22 -2
  7. package/dataflow/environments/default-builtin-config.js +64 -3
  8. package/dataflow/eval/resolve/alias-tracking.d.ts +6 -5
  9. package/dataflow/eval/resolve/alias-tracking.js +41 -11
  10. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +1 -4
  11. package/documentation/wiki-core.js +34 -18
  12. package/linter/rules/seeded-randomness.js +1 -1
  13. package/linter/rules/unused-definition.js +29 -17
  14. package/package.json +2 -1
  15. package/project/context/classify-project-kind.js +1 -1
  16. package/project/context/flowr-analyzer-dependencies-context.d.ts +4 -0
  17. package/project/context/flowr-analyzer-dependencies-context.js +28 -10
  18. package/project/context/flowr-analyzer-loading-order-context.d.ts +6 -0
  19. package/project/context/flowr-analyzer-loading-order-context.js +21 -0
  20. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +15 -0
  21. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +113 -16
  22. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.js +2 -1
  23. package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-included-files-plugin.d.ts +15 -0
  24. package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-included-files-plugin.js +33 -0
  25. package/project/plugins/plugin-registry.d.ts +2 -1
  26. package/project/plugins/plugin-registry.js +2 -0
  27. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +1 -1
  28. package/util/version.js +1 -1
@@ -14,26 +14,37 @@ const flowr_namespace_file_1 = require("../../project/plugins/file-plugins/files
14
14
  const identifier_1 = require("../../dataflow/environments/identifier");
15
15
  const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
16
16
  const retriever_1 = require("../../r-bridge/retriever");
17
+ const query_fn_props_1 = require("../../dataflow/environments/query-fn-props");
18
+ const built_in_props_1 = require("../../dataflow/environments/built-in-props");
19
+ const default_builtin_config_1 = require("../../dataflow/environments/default-builtin-config");
17
20
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
18
21
  const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
19
22
  /**
20
23
  * The dots parameter is a special parameter and must never be reported as an unused definition.
21
24
  */
22
25
  const DotsParameter = '...';
26
+ /** the standard-library S3 generics flowR models no built-in for, so the store cannot state them */
27
+ const OtherKnownS3Generics = new Set([
28
+ 'summary', 'coef', 'vcov', 'residuals', 'fitted', 'predict', 'as.vector', 'str', 'toString', 'all.equal',
29
+ 'aggregate', 'update', 'anova', 'confint', 'logLik', 'AIC', 'BIC', 'deviance', 'df.residual',
30
+ 'model.matrix', 'terms', 'weights', 'merge', 'split', 'window'
31
+ ]);
32
+ let knownS3Generics;
23
33
  /**
24
- * Common base/standard-library S3 generics. A definition named `generic.class` where `generic` is one of these
25
- * is an S3 method dispatched indirectly (e.g. `print(x)` on an object of class `class`), so it is used even
26
- * without a direct textual call.
34
+ * Whether a definition named `name.class` may be an S3 method: `name` is a built-in flowR labels
35
+ * {@link CallProp.Generic} or one of {@link OtherKnownS3Generics}. Such a method is dispatched indirectly
36
+ * (`print(x)` on an object of that class), so it is used without a textual call.
27
37
  */
28
- const KnownS3Generics = new Set([
29
- 'print', 'format', 'summary', 'plot', 'coef', 'vcov', 'residuals', 'fitted', 'predict',
30
- 'as.character', 'as.data.frame', 'as.list', 'as.matrix', 'as.vector', 'as.numeric',
31
- 'length', 'dim', 'dimnames', 'names', 'str', 'toString', 'all.equal', 'aggregate',
32
- 'update', 'anova', 'confint', 'logLik', 'AIC', 'BIC', 'deviance', 'df.residual',
33
- 'model.matrix', 'terms', 'weights', 'simulate', 'lines', 'points', 'head', 'tail',
34
- 'merge', 'rbind', 'cbind', 'split', 'window', 'subset', 'sort', 'rev', 'unique',
35
- 'mean', 'median', 'quantile', 'range', 'diff', 't'
36
- ]);
38
+ function isKnownS3Generic(name) {
39
+ knownS3Generics ??= new Set([...OtherKnownS3Generics, ...Object.keys(default_builtin_config_1.RGroupGenerics),
40
+ ...query_fn_props_1.BuiltInIndex.default().with(built_in_props_1.CallProp.Generic).map(g => identifier_1.Identifier.getName(g))]);
41
+ return knownS3Generics.has(name);
42
+ }
43
+ /** Whether `generic`, or any member of it when it is a group generic (`Ops.cls` dispatches on `+`), is called. */
44
+ function isDispatched(generic, called) {
45
+ const group = default_builtin_config_1.RGroupGenerics[generic];
46
+ return called.has(generic) || (group?.some(member => called.has(member)) ?? false);
47
+ }
37
48
  /**
38
49
  * R package lifecycle hooks called automatically by R's package machinery.
39
50
  * These functions are invoked by the package system, so they are used even without textual callers.
@@ -104,8 +115,9 @@ function isConsideredUsed(lexeme, config, pkg, called) {
104
115
  if (lexeme === undefined) {
105
116
  return false;
106
117
  }
107
- // non-syntactic definition names (e.g. S3 methods like `"[.irts"`) carry their R quotes in the lexeme
108
- const name = (0, retriever_1.removeRQuotes)(lexeme);
118
+ // non-syntactic definition names (e.g. S3 methods like `"[.irts"`) carry their R quotes or backticks in the lexeme
119
+ const unquoted = (0, retriever_1.removeRQuotes)(lexeme);
120
+ const name = unquoted.length > 1 && unquoted.startsWith('`') && unquoted.endsWith('`') ? unquoted.slice(1, -1) : unquoted;
109
121
  // the dots are a special parameter and must never be reported
110
122
  if (name === DotsParameter) {
111
123
  return true;
@@ -114,10 +126,10 @@ function isConsideredUsed(lexeme, config, pkg, called) {
114
126
  if (PackageHookFunctions.has(name)) {
115
127
  return true;
116
128
  }
117
- const dot = name.indexOf('.');
118
- if (dot > 0) {
129
+ // every dot may be the one splitting method from class, as the generic may carry dots itself (`as.character.foo`)
130
+ for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
119
131
  const generic = name.slice(0, dot);
120
- if (KnownS3Generics.has(generic) || pkg.s3Generics.has(generic) || called.has(generic)) {
132
+ if (isKnownS3Generic(generic) || pkg.s3Generics.has(generic) || isDispatched(generic, called)) {
121
133
  return true;
122
134
  }
123
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.13.5",
3
+ "version": "2.13.7",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {
@@ -30,6 +30,7 @@
30
30
  "build": "npm run gen:base-packages && tsc --project . && npm run build:copy-data",
31
31
  "gen:base-packages": "ts-node --transpile-only scripts/gen-base-packages.ts",
32
32
  "sync:sigdb": "ts-node --transpile-only scripts/sigdb-sync.ts",
33
+ "check:generic-labels": "ts-node --transpile-only scripts/check-generic-labels.ts",
33
34
  "gen:sigdb-remote": "ts-node --transpile-only scripts/sigdb-remote.ts",
34
35
  "publish:sigdb": "ts-node scripts/publish-sigdb.ts",
35
36
  "build:copy-data": "ts-node --transpile-only scripts/sigdb-copy.ts",
@@ -11,7 +11,7 @@ const shinyEntryFiles = new Set(['app.r', 'ui.r', 'server.r', 'global.r']);
11
11
  /** default evidence that a file is part of a shiny app (a load of the shiny stack or a call to one of its entry points) */
12
12
  const shinyUsage = /(?:library|require|requireNamespace|loadNamespace)\s*\(\s*['"]?(?:shiny|bslib|shinydashboard|shinyMobile|golem|flexdashboard)\b|\b(?:shinyApp|shinyServer|shinyUI|runApp|fluidPage|fluidRow|navbarPage|bootstrapPage|fillPage|dashboardPage|page_fluid|page_sidebar|page_navbar|pageWithSidebar)\s*\(/;
13
13
  /** default extensions marking a notebook / literate document */
14
- const notebookExtension = /\.(ipynb|rmd|qmd|rnw)$/;
14
+ const notebookExtension = /\.(ipynb|rmd|rmarkdown|qmd|rnw)$/;
15
15
  /** Resolve {@link ClassificationConfig} into {@link ResolvedClassifyOptions}, using the built-in defaults for unset fields. */
16
16
  function resolveClassifyOptions(cfg) {
17
17
  return {
@@ -89,6 +89,8 @@ export declare class FlowrAnalyzerDependenciesContext extends AbstractFlowrAnaly
89
89
  readonly name = "flowr-analyzer-dependencies-context";
90
90
  readonly functionsContext: FlowrAnalyzerFunctionsContext;
91
91
  private dependencies;
92
+ /** what {@link getDependency} resolved for a package the project does not depend on, so a lookup never makes it one */
93
+ private resolvedOnly;
92
94
  private staticsLoaded;
93
95
  /** resolvers consulted lazily to fill in exports; `existing` carries version info from other plugins */
94
96
  private lazyResolvers;
@@ -124,6 +126,8 @@ export declare class FlowrAnalyzerDependenciesContext extends AbstractFlowrAnaly
124
126
  addDeclaredDependency(pkg: Package): this;
125
127
  addDependency(pkg: Package): this;
126
128
  getDependency(name: string, version?: string | Range): Package | undefined;
129
+ /** Like {@link getDependency}, but for a package the code pulls in (`library(p)`): the result joins the project's {@link getDependencies|dependencies}. */
130
+ loadDependency(name: string): Package | undefined;
127
131
  /** Resolve `name` constrained to `range` via the plugins (uncached); falls back to the cached dependency. */
128
132
  private resolvePinnedDependency;
129
133
  inferredRange(name: string): Range | undefined;
@@ -15,12 +15,15 @@ class FlowrAnalyzerDependenciesContext extends abstract_flowr_analyzer_context_1
15
15
  name = 'flowr-analyzer-dependencies-context';
16
16
  functionsContext;
17
17
  dependencies = new Map();
18
+ /** what {@link getDependency} resolved for a package the project does not depend on, so a lookup never makes it one */
19
+ resolvedOnly = new Map();
18
20
  staticsLoaded = false;
19
21
  /** resolvers consulted lazily to fill in exports; `existing` carries version info from other plugins */
20
22
  lazyResolvers = [];
21
23
  resolvedMisses = new Set();
22
24
  reset() {
23
25
  this.dependencies = new Map();
26
+ this.resolvedOnly = new Map();
24
27
  this.staticsLoaded = false;
25
28
  this.lazyResolvers = [];
26
29
  this.resolvedMisses = new Set();
@@ -142,13 +145,7 @@ class FlowrAnalyzerDependenciesContext extends abstract_flowr_analyzer_context_1
142
145
  return this.addDependency(pkg);
143
146
  }
144
147
  addDependency(pkg) {
145
- const p = this.dependencies.get(pkg.name);
146
- if (p) {
147
- p.mergeInPlace(pkg);
148
- }
149
- else {
150
- this.dependencies.set(pkg.name, pkg);
151
- }
148
+ mergeIntoMap(this.dependencies, pkg);
152
149
  return this;
153
150
  }
154
151
  getDependency(name, version) {
@@ -158,7 +155,7 @@ class FlowrAnalyzerDependenciesContext extends abstract_flowr_analyzer_context_1
158
155
  if (version !== undefined) {
159
156
  return this.resolvePinnedDependency(name, typeof version === 'string' ? r_version_1.RRange.parse('=' + version) : version);
160
157
  }
161
- const existing = this.dependencies.get(name);
158
+ const existing = this.dependencies.get(name) ?? this.resolvedOnly.get(name);
162
159
  // a package already carrying exports is complete; a version-only one is still enriched below
163
160
  if (existing?.namespaceInfo || (!existing && this.resolvedMisses.has(name))) {
164
161
  return existing;
@@ -167,14 +164,26 @@ class FlowrAnalyzerDependenciesContext extends abstract_flowr_analyzer_context_1
167
164
  for (const resolve of this.lazyResolvers) {
168
165
  const resolved = resolve(name, existing);
169
166
  if (resolved) {
170
- this.addDependency(resolved); // merges exports into any existing version info
171
- return this.dependencies.get(name);
167
+ // merges exports into any existing version info, of a dependency or of a mere lookup
168
+ const into = this.dependencies.has(name) ? this.dependencies : this.resolvedOnly;
169
+ mergeIntoMap(into, resolved);
170
+ return into.get(name);
172
171
  }
173
172
  }
174
173
  this.resolvedMisses.add(name);
175
174
  }
176
175
  return existing;
177
176
  }
177
+ /** Like {@link getDependency}, but for a package the code pulls in (`library(p)`): the result joins the project's {@link getDependencies|dependencies}. */
178
+ loadDependency(name) {
179
+ const found = this.getDependency(name);
180
+ const cached = this.resolvedOnly.get(name);
181
+ if (cached !== undefined) {
182
+ this.resolvedOnly.delete(name);
183
+ mergeIntoMap(this.dependencies, cached);
184
+ }
185
+ return this.dependencies.get(name) ?? found;
186
+ }
178
187
  /** Resolve `name` constrained to `range` via the plugins (uncached); falls back to the cached dependency. */
179
188
  resolvePinnedDependency(name, range) {
180
189
  const pin = new package_1.Package({ name, versionConstraints: range ? [range] : [] });
@@ -203,4 +212,13 @@ class FlowrAnalyzerDependenciesContext extends abstract_flowr_analyzer_context_1
203
212
  }
204
213
  }
205
214
  exports.FlowrAnalyzerDependenciesContext = FlowrAnalyzerDependenciesContext;
215
+ function mergeIntoMap(map, pkg) {
216
+ const existing = map.get(pkg.name);
217
+ if (existing) {
218
+ existing.mergeInPlace(pkg);
219
+ }
220
+ else {
221
+ map.set(pkg.name, pkg);
222
+ }
223
+ }
206
224
  //# sourceMappingURL=flowr-analyzer-dependencies-context.js.map
@@ -75,6 +75,12 @@ export declare class FlowrAnalyzerLoadingOrderContext extends AbstractFlowrAnaly
75
75
  * existing orders instead of competing with them like {@link addGuess} would.
76
76
  */
77
77
  prependToOrder(requests: readonly RParseRequest[]): void;
78
+ /**
79
+ * Drop `requests` from every order known so far. Use this for files another file already
80
+ * contains (e.g. the target of an Rmd `child` chunk), as it refines the existing orders instead
81
+ * of competing with them like {@link addGuess} would.
82
+ */
83
+ removeFromOrder(requests: readonly RParseRequest[]): void;
78
84
  currentGuesses(): readonly (readonly RParseRequest[])[];
79
85
  currentKnownOrder(): readonly RParseRequest[] | undefined;
80
86
  peekLoadingOrder(): readonly RParseRequest[] | undefined;
@@ -96,6 +96,27 @@ class FlowrAnalyzerLoadingOrderContext extends abstract_flowr_analyzer_context_1
96
96
  this.addGuess(front(this.unordered));
97
97
  }
98
98
  }
99
+ /**
100
+ * Drop `requests` from every order known so far. Use this for files another file already
101
+ * contains (e.g. the target of an Rmd `child` chunk), as it refines the existing orders instead
102
+ * of competing with them like {@link addGuess} would.
103
+ */
104
+ removeFromOrder(requests) {
105
+ if (requests.length === 0) {
106
+ return;
107
+ }
108
+ const drop = new Set(requests);
109
+ const without = (order) => order.filter(r => !drop.has(r));
110
+ if (this.knownOrder) {
111
+ this.knownOrder = without(this.knownOrder);
112
+ }
113
+ for (let i = 0; i < this.guesses.length; i++) {
114
+ this.guesses[i] = without(this.guesses[i]);
115
+ }
116
+ if (!this.knownOrder && this.guesses.length === 0) {
117
+ this.addGuess(without(this.unordered));
118
+ }
119
+ }
99
120
  currentGuesses() {
100
121
  return this.guesses;
101
122
  }
@@ -11,6 +11,7 @@ export declare class FlowrRMarkdownFile extends FlowrFile {
11
11
  private mergedCode?;
12
12
  private readonly wrapped;
13
13
  private readonly context;
14
+ private readonly included;
14
15
  /**
15
16
  * Prefer the static {@link FlowrRMarkdownFile.from} method
16
17
  * @param file - the file to load as R Markdown
@@ -30,6 +31,8 @@ export declare class FlowrRMarkdownFile extends FlowrFile {
30
31
  * Postprocess blocks with options like child='other.Rmd'
31
32
  */
32
33
  private postProcessCodeBlocks;
34
+ /** The paths this document splices into itself, only known once the content is loaded */
35
+ get includedFiles(): readonly string[];
33
36
  static from(file: FlowrFileProvider<string> | FlowrRMarkdownFile, ctx: FlowrAnalyzerContext): FlowrRMarkdownFile;
34
37
  }
35
38
  export type CodeBlockOptions = Map<string, string>;
@@ -46,6 +49,18 @@ export interface RmdInfo {
46
49
  blocks: CodeBlock[];
47
50
  options: object;
48
51
  }
52
+ /**
53
+ * Checks whether a code block is evaluated when the document is knitted (i.e. not `eval=FALSE`),
54
+ * falling back to the document-wide default of {@link globalChunkOptions} if the chunk says nothing
55
+ */
56
+ export declare function isExecutableCell(block: CodeBlock, defaults: CodeBlockOptions): boolean;
57
+ /** Checks whether knitr keeps going when the chunk raises an error (i.e. `error=TRUE`) */
58
+ export declare function continuesAfterError(block: CodeBlock, defaults: CodeBlockOptions): boolean;
59
+ /**
60
+ * The chunk option defaults of the document, which quarto collects under `execute:` in the
61
+ * frontmatter and rmarkdown under `knitr: opts_chunk:`
62
+ */
63
+ export declare function globalChunkOptions(frontmatter: object): CodeBlockOptions;
49
64
  /**
50
65
  * Parse the contents of a RMarkdown file into complete code and blocks
51
66
  * @param raw - the raw file content
@@ -4,6 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FlowrRMarkdownFile = void 0;
7
+ exports.isExecutableCell = isExecutableCell;
8
+ exports.continuesAfterError = continuesAfterError;
9
+ exports.globalChunkOptions = globalChunkOptions;
7
10
  exports.parseRMarkdownFile = parseRMarkdownFile;
8
11
  exports.isRCodeBlock = isRCodeBlock;
9
12
  exports.restoreBlocksWithoutMd = restoreBlocksWithoutMd;
@@ -23,6 +26,7 @@ class FlowrRMarkdownFile extends flowr_file_1.FlowrFile {
23
26
  mergedCode;
24
27
  wrapped;
25
28
  context;
29
+ included = [];
26
30
  /**
27
31
  * Prefer the static {@link FlowrRMarkdownFile.from} method
28
32
  * @param file - the file to load as R Markdown
@@ -43,10 +47,8 @@ class FlowrRMarkdownFile extends flowr_file_1.FlowrFile {
43
47
  return this.data;
44
48
  }
45
49
  get executableCells() {
46
- return this.rmd.blocks.filter(b => {
47
- const opt = b.options.get('eval');
48
- return opt !== 'F' && opt !== 'FALSE';
49
- });
50
+ const defaults = globalChunkOptions(this.rmd.options);
51
+ return this.rmd.blocks.filter(b => isExecutableCell(b, defaults));
50
52
  }
51
53
  /**
52
54
  * Loads and parses the content of the wrapped file.
@@ -56,7 +58,8 @@ class FlowrRMarkdownFile extends flowr_file_1.FlowrFile {
56
58
  const raw = this.wrapped.content();
57
59
  this.data = parseRMarkdownFile(raw);
58
60
  this.postProcessCodeBlocks();
59
- this.mergedCode = restoreBlocksWithoutMd(this.data.blocks, countNewlines(raw));
61
+ const defaults = globalChunkOptions(this.data.options);
62
+ this.mergedCode = restoreBlocksWithoutMd(this.executableCells.map(b => continuesAfterError(b, defaults) ? { ...b, code: wrapErrorTolerant(b.code) } : b), countNewlines(raw));
60
63
  (0, assert_1.guard)(this.mergedCode !== undefined);
61
64
  return this.mergedCode;
62
65
  }
@@ -80,12 +83,11 @@ class FlowrRMarkdownFile extends flowr_file_1.FlowrFile {
80
83
  if (childPath.length > 1) {
81
84
  log_1.log.warn(`Found more than one path for child '${childOpt}' in rmd file '${this.path()}'. Only using the first path: '${childPath[0]}'`);
82
85
  }
83
- this.context.files.resolveRequest({
84
- request: 'file',
85
- content: childPath[0]
86
- });
87
- const rawChildFile = this.context.files.getFileByPath(childPath[0]);
86
+ // register but do not request, the content is spliced in here
87
+ const rawChildFile = (this.context.files.getFileByPath(childPath[0])
88
+ ?? this.context.files.addFile(childPath[0]));
88
89
  if (rawChildFile !== undefined) {
90
+ this.included.push(childPath[0]);
89
91
  block.code = FlowrRMarkdownFile.from(rawChildFile, this.context).content().toString();
90
92
  }
91
93
  else {
@@ -93,11 +95,55 @@ class FlowrRMarkdownFile extends flowr_file_1.FlowrFile {
93
95
  }
94
96
  }
95
97
  }
98
+ /** The paths this document splices into itself, only known once the content is loaded */
99
+ get includedFiles() {
100
+ (0, assert_1.guard)(this.rmd !== undefined);
101
+ return this.included;
102
+ }
96
103
  static from(file, ctx) {
97
104
  return file instanceof FlowrRMarkdownFile ? file : new FlowrRMarkdownFile(file, ctx);
98
105
  }
99
106
  }
100
107
  exports.FlowrRMarkdownFile = FlowrRMarkdownFile;
108
+ /* knitr accepts R literals (`FALSE`, `F`), quarto yaml options accept `false` */
109
+ const NonExecutableEvalValues = new Set(['F', 'FALSE', 'false', 'False']);
110
+ /**
111
+ * Checks whether a code block is evaluated when the document is knitted (i.e. not `eval=FALSE`),
112
+ * falling back to the document-wide default of {@link globalChunkOptions} if the chunk says nothing
113
+ */
114
+ function isExecutableCell(block, defaults) {
115
+ const opt = block.options.get('eval') ?? defaults.get('eval');
116
+ return opt === undefined || !NonExecutableEvalValues.has(opt);
117
+ }
118
+ const ErrorTolerantValues = new Set(['T', 'TRUE', 'true', 'True']);
119
+ /** Checks whether knitr keeps going when the chunk raises an error (i.e. `error=TRUE`) */
120
+ function continuesAfterError(block, defaults) {
121
+ const opt = block.options.get('error') ?? defaults.get('error');
122
+ return opt !== undefined && ErrorTolerantValues.has(opt);
123
+ }
124
+ /** As `error=TRUE` keeps knitting, the chunk must not cut the document short. Adds no lines, so all following positions hold. */
125
+ function wrapErrorTolerant(code) {
126
+ return `tryCatch({${code}}, error = function(e) NULL)`;
127
+ }
128
+ /**
129
+ * The chunk option defaults of the document, which quarto collects under `execute:` in the
130
+ * frontmatter and rmarkdown under `knitr: opts_chunk:`
131
+ */
132
+ function globalChunkOptions(frontmatter) {
133
+ const knitr = frontmatter.knitr;
134
+ const options = new Map();
135
+ for (const source of [frontmatter.execute, knitr?.opts_chunk]) {
136
+ if (typeof source !== 'object' || source === null) {
137
+ continue;
138
+ }
139
+ for (const [key, value] of Object.entries(source)) {
140
+ if (value !== null && typeof value !== 'object') {
141
+ options.set(key, String(value));
142
+ }
143
+ }
144
+ }
145
+ return options;
146
+ }
101
147
  /**
102
148
  * Parse the contents of a RMarkdown file into complete code and blocks
103
149
  * @param raw - the raw file content
@@ -137,11 +183,31 @@ function parseRMarkdownFile(raw) {
137
183
  startpos: { line: node.sourcepos[0][0] + 1, col: 0 }
138
184
  });
139
185
  }
186
+ blocks.push(...parseIncludeShortcodes(raw));
187
+ blocks.sort((a, b) => a.startpos.line - b.startpos.line);
140
188
  return {
141
189
  blocks: blocks,
142
190
  options: frontmatter?.data ?? {}
143
191
  };
144
192
  }
193
+ const IncludeShortcodeRegex = /{{<\s*include\s+["']?(.+?)["']?\s*>}}/;
194
+ /** Collects quarto's `{{< include other.qmd >}}` as blocks carrying a `child`, resolved like knitr's option */
195
+ function parseIncludeShortcodes(raw) {
196
+ const blocks = [];
197
+ const lines = raw.split(LineRegex);
198
+ for (let i = 0; i < lines.length; i++) {
199
+ const match = IncludeShortcodeRegex.exec(lines[i]);
200
+ if (match) {
201
+ blocks.push({
202
+ code: '',
203
+ options: new Map([['child', match[1]]]),
204
+ header: '',
205
+ startpos: { line: i + 1, col: 0 }
206
+ });
207
+ }
208
+ }
209
+ return blocks;
210
+ }
145
211
  // We need the [\s,] part, otherwise {rust} would also match
146
212
  const RTagRegex = /{[rR](?:[\s,][^}]*)?}/;
147
213
  /**
@@ -179,23 +245,54 @@ const OptionsRegex = /([\w_.-]*)\s*[:=]\s*["']?([^,"']*)/g;
179
245
  * Parses the options of an R code block from its header and content
180
246
  */
181
247
  function parseCodeBlockOptions(header, content) {
182
- let opts = header.length === 3 // '{r}' => header.length=3 (no options in header)
248
+ const headerOpts = header.length === 3 // '{r}' => header.length=3 (no options in header)
183
249
  ? ''
184
250
  : header.substring(3, header.length - 1).trim();
185
- const lines = content.split('\n');
186
- for (const line of lines) {
251
+ const cellLines = [];
252
+ for (const line of content.split('\n')) {
187
253
  if (!line.trim().startsWith('#|')) {
188
254
  break;
189
255
  }
190
- const opt = line.substring(2).trim();
191
- opts += opts.length === 0 ? opt : `, ${opt}`;
256
+ // keep the indentation, yaml block scalars rely on it
257
+ cellLines.push(line.trim().substring(2).replace(/^ /, ''));
258
+ }
259
+ const options = parseOptionString(headerOpts);
260
+ for (const [key, value] of parseCellOptions(cellLines)) {
261
+ options.set(key, value);
192
262
  }
263
+ return options;
264
+ }
265
+ /** Parses knitr's `key=value` option syntax as used in the chunk header */
266
+ function parseOptionString(opts) {
193
267
  const parsedOptions = new Map();
194
268
  for (const match of opts.matchAll(OptionsRegex)) {
195
269
  if (match[1] && match[2] !== undefined) { // key must not be empty, but value can be empty string for example
196
- parsedOptions.set(match[1], match[2]);
270
+ parsedOptions.set(match[1], match[2].trim());
197
271
  }
198
272
  }
199
273
  return parsedOptions;
200
274
  }
275
+ /** Parses the `#|` options quarto writes as yaml, falling back to knitr's `key=value` syntax */
276
+ function parseCellOptions(lines) {
277
+ if (lines.length === 0) {
278
+ return new Map();
279
+ }
280
+ try {
281
+ const parsed = (0, gray_matter_1.default)(`---\n${lines.join('\n')}\n---\n`).data;
282
+ // a bare scalar is knitr's `key=value` syntax, not yaml
283
+ if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) && Object.keys(parsed).length > 0) {
284
+ const options = new Map();
285
+ for (const [key, value] of Object.entries(parsed)) {
286
+ if (value !== null && typeof value !== 'object') {
287
+ options.set(key, String(value));
288
+ }
289
+ }
290
+ return options;
291
+ }
292
+ }
293
+ catch (e) {
294
+ log_1.log.warn(`Failed to parse cell options as yaml, falling back to the header syntax. Error was: ${JSON.stringify(e)}`);
295
+ }
296
+ return parseOptionString(lines.join(', '));
297
+ }
201
298
  //# sourceMappingURL=flowr-rmarkdown-file.js.map
@@ -5,7 +5,8 @@ const semver_1 = require("semver");
5
5
  const flowr_analyzer_file_plugin_1 = require("../flowr-analyzer-file-plugin");
6
6
  const flowr_rmarkdown_file_1 = require("../files/flowr-rmarkdown-file");
7
7
  const built_in_source_1 = require("../../../../dataflow/internal/process/functions/call/built-in/built-in-source");
8
- exports.RmdPattern = /\.rmd$/i;
8
+ /* `.Rmarkdown` is the knitr-only variant used by blogdown and quarto */
9
+ exports.RmdPattern = /\.(rmd|rmarkdown)$/i;
9
10
  /**
10
11
  * The plugin provides support for R Markdown (`.rmd`) files
11
12
  */
@@ -0,0 +1,15 @@
1
+ import { SemVer } from 'semver';
2
+ import { FlowrAnalyzerLoadingOrderPlugin } from './flowr-analyzer-loading-order-plugin';
3
+ import type { FlowrAnalyzerContext } from '../../context/flowr-analyzer-context';
4
+ /**
5
+ * Drops the files an R Markdown document splices into itself ({@link FlowrRMarkdownFile#includedFiles})
6
+ * from the loading order, as the including document already carries their content.
7
+ *
8
+ * This refines the orders the other loading-order plugins produced, so register it after them.
9
+ */
10
+ export declare class FlowrAnalyzerLoadingOrderIncludedFilesPlugin extends FlowrAnalyzerLoadingOrderPlugin {
11
+ readonly name = "flowr-analyzer-loading-order-included-files-plugin";
12
+ readonly description = "Drops files that another document includes from the loading order.";
13
+ readonly version: SemVer;
14
+ process(ctx: FlowrAnalyzerContext): void;
15
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowrAnalyzerLoadingOrderIncludedFilesPlugin = void 0;
4
+ const semver_1 = require("semver");
5
+ const flowr_analyzer_loading_order_plugin_1 = require("./flowr-analyzer-loading-order-plugin");
6
+ const flowr_rmarkdown_file_1 = require("../file-plugins/files/flowr-rmarkdown-file");
7
+ /**
8
+ * Drops the files an R Markdown document splices into itself ({@link FlowrRMarkdownFile#includedFiles})
9
+ * from the loading order, as the including document already carries their content.
10
+ *
11
+ * This refines the orders the other loading-order plugins produced, so register it after them.
12
+ */
13
+ class FlowrAnalyzerLoadingOrderIncludedFilesPlugin extends flowr_analyzer_loading_order_plugin_1.FlowrAnalyzerLoadingOrderPlugin {
14
+ name = 'flowr-analyzer-loading-order-included-files-plugin';
15
+ description = 'Drops files that another document includes from the loading order.';
16
+ version = new semver_1.SemVer('0.1.0');
17
+ process(ctx) {
18
+ const files = ctx.files.loadingOrder.getUnorderedRequests()
19
+ .filter((r) => r.request === 'file');
20
+ const included = new Set();
21
+ for (const request of files) {
22
+ const file = ctx.files.resolveFile(request.content);
23
+ if (file instanceof flowr_rmarkdown_file_1.FlowrRMarkdownFile) {
24
+ for (const path of file.includedFiles) {
25
+ included.add(path);
26
+ }
27
+ }
28
+ }
29
+ ctx.files.loadingOrder.removeFromOrder(files.filter(r => included.has(r.content)));
30
+ }
31
+ }
32
+ exports.FlowrAnalyzerLoadingOrderIncludedFilesPlugin = FlowrAnalyzerLoadingOrderIncludedFilesPlugin;
33
+ //# sourceMappingURL=flowr-analyzer-loading-order-included-files-plugin.js.map
@@ -26,10 +26,11 @@ import { FlowrAnalyzerGitignoreProjectDiscoveryPlugin, FlowrAnalyzerIgnoreFilePr
26
26
  import { FlowrAnalyzerDefaultProjectDiscoveryPlugin, FlowrAnalyzerFullProjectDiscoveryPlugin } from './project-discovery/flowr-analyzer-project-discovery-plugin';
27
27
  import { FlowrAnalyzerRprofileFilePlugin } from './file-plugins/flowr-analyzer-rprofile-file-plugin';
28
28
  import { FlowrAnalyzerLoadingOrderRprofilePlugin } from './loading-order-plugins/flowr-analyzer-loading-order-rprofile-plugin';
29
+ import { FlowrAnalyzerLoadingOrderIncludedFilesPlugin } from './loading-order-plugins/flowr-analyzer-loading-order-included-files-plugin';
29
30
  /**
30
31
  * The built-in Flowr Analyzer plugins that are always available.
31
32
  */
32
- export declare const BuiltInPlugins: [["file:description", typeof FlowrAnalyzerDescriptionFilePlugin], ["versions:description", typeof FlowrAnalyzerPackageVersionsDescriptionFilePlugin], ["versions:sigdb", typeof FlowrAnalyzerPackageVersionsSigDbPlugin], ["versions:renv", typeof FlowrAnalyzerPackageVersionsRenvPlugin], ["versions:rv", typeof FlowrAnalyzerPackageVersionsRvPlugin], ["versions:uvr", typeof FlowrAnalyzerPackageVersionsUvrPlugin], ["versions:packrat", typeof FlowrAnalyzerPackageVersionsPackratPlugin], ["versions:session-info", typeof FlowrAnalyzerPackageVersionsSessionInfoPlugin], ["loading-order:description", typeof FlowrAnalyzerLoadingOrderDescriptionFilePlugin], ["loading-order:implicit-sources", typeof FlowrAnalyzerLoadingOrderImplicitSourcesPlugin], ["loading-order:rprofile", typeof FlowrAnalyzerLoadingOrderRprofilePlugin], ["meta:description", typeof FlowrAnalyzerMetaDescriptionFilePlugin], ["meta:rproject", typeof FlowrAnalyzerMetaRProjectFilePlugin], ["meta:uvr", typeof FlowrAnalyzerMetaUvrManifestFilePlugin], ["file-roles:vignette", typeof FlowrAnalyzerMetaVignetteFilesPlugin], ["file-roles:test", typeof FlowrAnalyzerMetaTestFilesPlugin], ["file-roles:inst", typeof FlowrAnalyzerMetaInstFilesPlugin], ["file:rmd", typeof FlowrAnalyzerRmdFilePlugin], ["file:qmd", typeof FlowrAnalyzerQmdFilePlugin], ["file:rnw", typeof FlowrAnalyzerSweaveFilePlugin], ["file:ipynb", typeof FlowrAnalyzerJupyterFilePlugin], ["file:namespace", typeof FlowrAnalyzerNamespaceFilesPlugin], ["versions:namespace", typeof FlowrAnalyzerPackageVersionsNamespaceFilePlugin], ["file:news", typeof FlowrAnalyzerNewsFilePlugin], ["file:rda", typeof FlowrAnalyzerRdaFilePlugin], ["file:license", typeof FlowrAnalyzerLicenseFilePlugin], ["file:virtualenv", typeof FlowrAnalyzerVirtualEnvFilePlugin], ["file:rproject", typeof FlowrAnalyzerRProjectFilePlugin], ["file:uvr", typeof FlowrAnalyzerUvrManifestFilePlugin], ["file:rprofile", typeof FlowrAnalyzerRprofileFilePlugin], ["project-discovery:gitignore", typeof FlowrAnalyzerGitignoreProjectDiscoveryPlugin], ["project-discovery:rbuildignore", typeof FlowrAnalyzerRbuildignoreProjectDiscoveryPlugin], ["project-discovery:ignore-files", typeof FlowrAnalyzerIgnoreFileProjectDiscoveryPlugin], ["project-discovery:default", typeof FlowrAnalyzerDefaultProjectDiscoveryPlugin], ["project-discovery:full", typeof FlowrAnalyzerFullProjectDiscoveryPlugin]];
33
+ export declare const BuiltInPlugins: [["file:description", typeof FlowrAnalyzerDescriptionFilePlugin], ["versions:description", typeof FlowrAnalyzerPackageVersionsDescriptionFilePlugin], ["versions:sigdb", typeof FlowrAnalyzerPackageVersionsSigDbPlugin], ["versions:renv", typeof FlowrAnalyzerPackageVersionsRenvPlugin], ["versions:rv", typeof FlowrAnalyzerPackageVersionsRvPlugin], ["versions:uvr", typeof FlowrAnalyzerPackageVersionsUvrPlugin], ["versions:packrat", typeof FlowrAnalyzerPackageVersionsPackratPlugin], ["versions:session-info", typeof FlowrAnalyzerPackageVersionsSessionInfoPlugin], ["loading-order:description", typeof FlowrAnalyzerLoadingOrderDescriptionFilePlugin], ["loading-order:implicit-sources", typeof FlowrAnalyzerLoadingOrderImplicitSourcesPlugin], ["loading-order:rprofile", typeof FlowrAnalyzerLoadingOrderRprofilePlugin], ["loading-order:included-files", typeof FlowrAnalyzerLoadingOrderIncludedFilesPlugin], ["meta:description", typeof FlowrAnalyzerMetaDescriptionFilePlugin], ["meta:rproject", typeof FlowrAnalyzerMetaRProjectFilePlugin], ["meta:uvr", typeof FlowrAnalyzerMetaUvrManifestFilePlugin], ["file-roles:vignette", typeof FlowrAnalyzerMetaVignetteFilesPlugin], ["file-roles:test", typeof FlowrAnalyzerMetaTestFilesPlugin], ["file-roles:inst", typeof FlowrAnalyzerMetaInstFilesPlugin], ["file:rmd", typeof FlowrAnalyzerRmdFilePlugin], ["file:qmd", typeof FlowrAnalyzerQmdFilePlugin], ["file:rnw", typeof FlowrAnalyzerSweaveFilePlugin], ["file:ipynb", typeof FlowrAnalyzerJupyterFilePlugin], ["file:namespace", typeof FlowrAnalyzerNamespaceFilesPlugin], ["versions:namespace", typeof FlowrAnalyzerPackageVersionsNamespaceFilePlugin], ["file:news", typeof FlowrAnalyzerNewsFilePlugin], ["file:rda", typeof FlowrAnalyzerRdaFilePlugin], ["file:license", typeof FlowrAnalyzerLicenseFilePlugin], ["file:virtualenv", typeof FlowrAnalyzerVirtualEnvFilePlugin], ["file:rproject", typeof FlowrAnalyzerRProjectFilePlugin], ["file:uvr", typeof FlowrAnalyzerUvrManifestFilePlugin], ["file:rprofile", typeof FlowrAnalyzerRprofileFilePlugin], ["project-discovery:gitignore", typeof FlowrAnalyzerGitignoreProjectDiscoveryPlugin], ["project-discovery:rbuildignore", typeof FlowrAnalyzerRbuildignoreProjectDiscoveryPlugin], ["project-discovery:ignore-files", typeof FlowrAnalyzerIgnoreFileProjectDiscoveryPlugin], ["project-discovery:default", typeof FlowrAnalyzerDefaultProjectDiscoveryPlugin], ["project-discovery:full", typeof FlowrAnalyzerFullProjectDiscoveryPlugin]];
33
34
  export type BuiltInFlowrPluginName = typeof BuiltInPlugins[number][0];
34
35
  export type BuiltInFlowrPluginArgs<N extends BuiltInFlowrPluginName> = N extends typeof BuiltInPlugins[number][0] ? ConstructorParameters<Extract<typeof BuiltInPlugins[number], [N, PluginProducer]>[1]> : never;
35
36
  type PluginProducer = new (...args: never[]) => FlowrAnalyzerPlugin;
@@ -32,6 +32,7 @@ const flowr_analyzer_ignore_file_project_discovery_plugin_1 = require("./project
32
32
  const flowr_analyzer_project_discovery_plugin_1 = require("./project-discovery/flowr-analyzer-project-discovery-plugin");
33
33
  const flowr_analyzer_rprofile_file_plugin_1 = require("./file-plugins/flowr-analyzer-rprofile-file-plugin");
34
34
  const flowr_analyzer_loading_order_rprofile_plugin_1 = require("./loading-order-plugins/flowr-analyzer-loading-order-rprofile-plugin");
35
+ const flowr_analyzer_loading_order_included_files_plugin_1 = require("./loading-order-plugins/flowr-analyzer-loading-order-included-files-plugin");
35
36
  /**
36
37
  * The built-in Flowr Analyzer plugins that are always available.
37
38
  */
@@ -47,6 +48,7 @@ exports.BuiltInPlugins = [
47
48
  ['loading-order:description', flowr_analyzer_loading_order_description_file_plugin_1.FlowrAnalyzerLoadingOrderDescriptionFilePlugin],
48
49
  ['loading-order:implicit-sources', flowr_analyzer_loading_order_implicit_sources_plugin_1.FlowrAnalyzerLoadingOrderImplicitSourcesPlugin],
49
50
  ['loading-order:rprofile', flowr_analyzer_loading_order_rprofile_plugin_1.FlowrAnalyzerLoadingOrderRprofilePlugin],
51
+ ['loading-order:included-files', flowr_analyzer_loading_order_included_files_plugin_1.FlowrAnalyzerLoadingOrderIncludedFilesPlugin],
50
52
  ['meta:description', flowr_analyzer_meta_description_file_plugin_1.FlowrAnalyzerMetaDescriptionFilePlugin],
51
53
  ['meta:rproject', flowr_analyzer_meta_manifest_file_plugin_1.FlowrAnalyzerMetaRProjectFilePlugin],
52
54
  ['meta:uvr', flowr_analyzer_meta_manifest_file_plugin_1.FlowrAnalyzerMetaUvrManifestFilePlugin],
@@ -30,7 +30,7 @@ class FlowrAnalyzerProjectDiscoveryPlugin extends flowr_analyzer_plugin_1.FlowrA
30
30
  }
31
31
  exports.FlowrAnalyzerProjectDiscoveryPlugin = FlowrAnalyzerProjectDiscoveryPlugin;
32
32
  // `.Rprofile`/`Rprofile.site` carry no extension but are plain R sources
33
- exports.discoverRSourcesRegex = /(\.(r|rmd|ipynb|qmd|rnw)|(^|[\\/])\.?Rprofile(\.site)?)$/i;
33
+ exports.discoverRSourcesRegex = /(\.(r|rmd|rmarkdown|ipynb|qmd|rnw)|(^|[\\/])\.?Rprofile(\.site)?)$/i;
34
34
  // matched against the posix path relative to the project root
35
35
  exports.ignorePathsWith = /(^|\/)(\.git|\.svn|\.hg|node_modules|__pycache__|\.Rproj\.user|\.uvr|Rtmp[^/]*|(packrat|renv|rv)\/(lib|library|src|staging|sandbox|bundles)[^/]*)(\/|$)/i;
36
36
  exports.excludeRequestsForPaths = /vignettes?|tests?|revdep|inst|data/i;
package/util/version.js CHANGED
@@ -42,7 +42,7 @@ const assert_1 = require("./assert");
42
42
  const sigdb_download_1 = require("../project/sigdb/sigdb-download");
43
43
  const doc_files_1 = require("../documentation/doc-util/doc-files");
44
44
  // this is automatically replaced with the current version by release-it
45
- const version = '2.13.5';
45
+ const version = '2.13.7';
46
46
  // this is automatically replaced with the release date by release-it (regex-bumper, see package.json)
47
47
  const versionDate = '2026-07-15T07:13:44Z';
48
48
  /**