@eagleoutice/flowr 2.10.9 → 2.10.10
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.
- package/README.md +103 -33
- package/abstract-interpretation/absint-visitor.js +6 -3
- package/abstract-interpretation/domains/abstract-domain.d.ts +1 -1
- package/abstract-interpretation/domains/bounded-set-domain.d.ts +1 -1
- package/abstract-interpretation/domains/bounded-set-domain.js +1 -1
- package/abstract-interpretation/domains/interval-domain.d.ts +1 -1
- package/abstract-interpretation/domains/interval-domain.js +1 -1
- package/abstract-interpretation/domains/lattice.d.ts +1 -1
- package/abstract-interpretation/domains/partial-product-domain.d.ts +1 -1
- package/abstract-interpretation/domains/partial-product-domain.js +2 -2
- package/abstract-interpretation/domains/set-range-domain.d.ts +1 -1
- package/abstract-interpretation/domains/set-range-domain.js +1 -1
- package/abstract-interpretation/domains/set-upper-bound-domain.d.ts +1 -1
- package/abstract-interpretation/domains/set-upper-bound-domain.js +1 -1
- package/abstract-interpretation/domains/singleton-domain.d.ts +1 -1
- package/abstract-interpretation/domains/singleton-domain.js +1 -1
- package/abstract-interpretation/domains/state-abstract-domain.d.ts +1 -1
- package/abstract-interpretation/domains/state-abstract-domain.js +2 -2
- package/abstract-interpretation/unsupported-functions.d.ts +3 -2
- package/abstract-interpretation/unsupported-functions.js +38 -28
- package/cli/benchmark-app.js +2 -1
- package/cli/common/script.js +3 -2
- package/cli/flowr.js +47 -10
- package/cli/repl/commands/repl-cfg.js +9 -9
- package/cli/repl/commands/repl-commands.js +5 -0
- package/cli/repl/commands/repl-dataflow.js +31 -24
- package/cli/repl/commands/repl-main.d.ts +6 -0
- package/cli/repl/commands/repl-normalize.js +15 -12
- package/cli/repl/commands/repl-parse.js +1 -1
- package/cli/repl/commands/repl-query.js +4 -5
- package/cli/repl/commands/repl-quit.js +2 -1
- package/cli/repl/core.d.ts +11 -0
- package/cli/repl/core.js +101 -3
- package/cli/repl/execute.js +3 -2
- package/cli/repl/parser/slice-query-parser.d.ts +16 -0
- package/cli/repl/parser/slice-query-parser.js +52 -0
- package/cli/repl/server/connection.d.ts +1 -0
- package/cli/repl/server/connection.js +25 -0
- package/cli/repl/server/messages/message-analysis.d.ts +10 -0
- package/cli/repl/server/messages/message-analysis.js +6 -2
- package/cli/repl/server/messages/message-slice.d.ts +1 -1
- package/cli/script-core/statistics-core.js +2 -1
- package/cli/script-core/statistics-helper-core.js +2 -1
- package/cli/wiki.d.ts +2 -1
- package/cli/wiki.js +4 -1
- package/config.d.ts +9 -10
- package/config.js +25 -7
- package/control-flow/diff-cfg.d.ts +1 -1
- package/control-flow/diff-cfg.js +1 -1
- package/control-flow/semantic-cfg-guided-visitor.js +1 -0
- package/control-flow/simple-visitor.js +6 -5
- package/control-flow/useless-loop.js +2 -2
- package/core/print/dataflow-printer.d.ts +2 -2
- package/core/print/dataflow-printer.js +2 -2
- package/core/steps/all/static-slicing/00-slice.js +1 -1
- package/core/steps/pipeline/default-pipelines.d.ts +146 -146
- package/dataflow/environments/append.d.ts +2 -1
- package/dataflow/environments/append.js +2 -1
- package/dataflow/environments/built-in-proc-name.d.ts +2 -0
- package/dataflow/environments/built-in-proc-name.js +2 -0
- package/dataflow/environments/built-in.d.ts +2 -0
- package/dataflow/environments/built-in.js +2 -0
- package/dataflow/environments/default-builtin-config.d.ts +122 -66
- package/dataflow/environments/default-builtin-config.js +324 -145
- package/dataflow/environments/environment.d.ts +2 -1
- package/dataflow/environments/environment.js +13 -9
- package/dataflow/environments/identifier.d.ts +55 -2
- package/dataflow/environments/identifier.js +14 -2
- package/dataflow/environments/reference-to-maybe.d.ts +2 -0
- package/dataflow/environments/reference-to-maybe.js +56 -11
- package/dataflow/environments/resolve-by-name.js +13 -7
- package/dataflow/eval/values/general.js +4 -0
- package/dataflow/extractor.js +12 -2
- package/dataflow/graph/df-helper.d.ts +6 -0
- package/dataflow/graph/df-helper.js +33 -0
- package/dataflow/graph/graph.js +1 -1
- package/dataflow/info.d.ts +1 -1
- package/dataflow/internal/linker.d.ts +5 -1
- package/dataflow/internal/linker.js +34 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +53 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.d.ts +13 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.js +58 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +38 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +9 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +1 -1
- package/dataflow/internal/process/functions/call/known-call-handling.js +4 -3
- package/dataflow/internal/process/functions/call/named-call-handling.js +6 -0
- package/dataflow/origin/dfg-get-origin.d.ts +1 -1
- package/dataflow/origin/dfg-get-origin.js +1 -1
- package/dataflow/processor.d.ts +6 -0
- package/documentation/data/faq/faqs.d.ts +2 -1
- package/documentation/data/faq/faqs.js +75 -57
- package/documentation/data/server/doc-data-server-messages.d.ts +2 -1
- package/documentation/data/server/doc-data-server-messages.js +15 -7
- package/documentation/doc-readme.js +15 -15
- package/documentation/doc-util/doc-cfg.d.ts +3 -1
- package/documentation/doc-util/doc-cfg.js +3 -3
- package/documentation/doc-util/doc-dfg.d.ts +3 -1
- package/documentation/doc-util/doc-dfg.js +3 -3
- package/documentation/doc-util/doc-files.d.ts +3 -1
- package/documentation/doc-util/doc-files.js +9 -6
- package/documentation/doc-util/doc-normalized-ast.d.ts +3 -1
- package/documentation/doc-util/doc-normalized-ast.js +2 -2
- package/documentation/doc-util/doc-query.d.ts +2 -1
- package/documentation/doc-util/doc-query.js +2 -2
- package/documentation/doc-util/doc-repl.js +1 -0
- package/documentation/doc-util/doc-types.d.ts +6 -6
- package/documentation/doc-util/doc-types.js +11 -9
- package/documentation/issue-linting-rule.js +1 -2
- package/documentation/wiki-analyzer.js +9 -9
- package/documentation/wiki-cfg.js +40 -41
- package/documentation/wiki-core.js +119 -31
- package/documentation/wiki-create-linting-rules.d.ts +6 -0
- package/documentation/wiki-create-linting-rules.js +95 -0
- package/documentation/wiki-dataflow-graph.js +77 -76
- package/documentation/wiki-engine.js +1 -2
- package/documentation/wiki-faq.d.ts +2 -1
- package/documentation/wiki-faq.js +4 -4
- package/documentation/wiki-interface.js +19 -6
- package/documentation/wiki-linter.d.ts +1 -1
- package/documentation/wiki-linter.js +14 -6
- package/documentation/wiki-linting-and-testing.js +2 -2
- package/documentation/wiki-mk/doc-context.d.ts +3 -3
- package/documentation/wiki-mk/doc-maker.d.ts +2 -0
- package/documentation/wiki-mk/doc-maker.js +7 -1
- package/documentation/wiki-normalized-ast.js +5 -5
- package/documentation/wiki-onboarding.d.ts +2 -1
- package/documentation/wiki-onboarding.js +5 -5
- package/documentation/wiki-overview.js +3 -3
- package/documentation/wiki-query.js +85 -84
- package/documentation/wiki-search.js +4 -5
- package/documentation/wiki-setup.js +6 -7
- package/gas.d.ts +74 -0
- package/gas.js +18 -0
- package/linter/linter-executor.js +2 -8
- package/linter/linter-format.d.ts +4 -11
- package/linter/linter-rules.d.ts +88 -86
- package/linter/linter-rules.js +7 -1
- package/linter/rules/absolute-path.d.ts +2 -7
- package/linter/rules/absolute-path.js +6 -4
- package/linter/rules/dataframe-access-validation.d.ts +1 -6
- package/linter/rules/dataframe-access-validation.js +8 -6
- package/linter/rules/dead-code.d.ts +2 -11
- package/linter/rules/dead-code.js +16 -11
- package/linter/rules/deprecated-functions.d.ts +3 -3
- package/linter/rules/file-path-validity.d.ts +1 -6
- package/linter/rules/file-path-validity.js +5 -5
- package/linter/rules/function-finder-util.d.ts +7 -11
- package/linter/rules/function-finder-util.js +9 -6
- package/linter/rules/naming-convention.d.ts +2 -7
- package/linter/rules/naming-convention.js +3 -2
- package/linter/rules/network-functions.d.ts +2 -7
- package/linter/rules/network-functions.js +14 -12
- package/linter/rules/no-leaked-credentials.d.ts +36 -0
- package/linter/rules/no-leaked-credentials.js +75 -0
- package/linter/rules/problematic-inputs.d.ts +1 -8
- package/linter/rules/problematic-inputs.js +5 -4
- package/linter/rules/roxygen-arguments.d.ts +2 -7
- package/linter/rules/roxygen-arguments.js +13 -20
- package/linter/rules/seeded-randomness.d.ts +2 -7
- package/linter/rules/seeded-randomness.js +7 -4
- package/linter/rules/software-has-license.d.ts +31 -0
- package/linter/rules/software-has-license.js +46 -0
- package/linter/rules/software-has-tests.d.ts +38 -0
- package/linter/rules/software-has-tests.js +48 -0
- package/linter/rules/stop-with-call-arg.d.ts +2 -7
- package/linter/rules/stop-with-call-arg.js +3 -2
- package/linter/rules/unused-definition.d.ts +3 -8
- package/linter/rules/unused-definition.js +7 -5
- package/linter/rules/useless-loop.d.ts +2 -7
- package/linter/rules/useless-loop.js +5 -2
- package/package.json +3 -2
- package/project/context/flowr-analyzer-context.d.ts +13 -14
- package/project/context/flowr-analyzer-context.js +4 -0
- package/project/context/flowr-analyzer-files-context.d.ts +12 -0
- package/project/context/flowr-analyzer-files-context.js +12 -2
- package/project/context/flowr-analyzer-gas-context.d.ts +28 -0
- package/project/context/flowr-analyzer-gas-context.js +101 -0
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +13 -7
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +56 -11
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.d.ts +1 -1
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.js +2 -2
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.d.ts +2 -1
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.js +5 -5
- package/project/plugins/flowr-analyzer-plugin.d.ts +15 -8
- package/project/plugins/flowr-analyzer-plugin.js +14 -7
- package/project/plugins/gas-plugins/flowr-analyzer-gas-plugin.d.ts +19 -0
- package/project/plugins/gas-plugins/flowr-analyzer-gas-plugin.js +35 -0
- package/project/plugins/plugin-registry.d.ts +2 -1
- package/project/plugins/plugin-registry.js +3 -1
- package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.d.ts +22 -0
- package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.js +47 -0
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +1 -1
- package/queries/catalog/call-context-query/call-context-query-executor.js +54 -8
- package/queries/catalog/call-context-query/call-context-query-format.d.ts +2 -2
- package/queries/catalog/dependencies-query/function-info/test-functions.d.ts +2 -0
- package/queries/catalog/dependencies-query/function-info/test-functions.js +18 -177
- package/queries/catalog/df-shape-query/df-shape-query-format.js +1 -1
- package/queries/catalog/dice-query/dice-query-executor.d.ts +8 -0
- package/queries/catalog/dice-query/dice-query-executor.js +52 -0
- package/queries/catalog/dice-query/dice-query-format.d.ts +53 -0
- package/queries/catalog/dice-query/dice-query-format.js +102 -0
- package/queries/catalog/happens-before-query/happens-before-query-executor.js +2 -2
- package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +2 -0
- package/queries/catalog/input-sources-query/input-sources-query-format.js +1 -0
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.d.ts +2 -0
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +1 -0
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.d.ts +2 -0
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +1 -0
- package/queries/catalog/linter-query/linter-query-executor.js +7 -0
- package/queries/catalog/location-map-query/location-map-query-format.d.ts +2 -0
- package/queries/catalog/location-map-query/location-map-query-format.js +1 -0
- package/queries/catalog/origin-query/origin-query-format.d.ts +2 -0
- package/queries/catalog/origin-query/origin-query-format.js +1 -0
- package/queries/catalog/provenance-query/provenance-query-format.d.ts +2 -0
- package/queries/catalog/provenance-query/provenance-query-format.js +1 -0
- package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +2 -0
- package/queries/catalog/resolve-value-query/resolve-value-query-format.js +1 -0
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +2 -0
- package/queries/catalog/static-slice-query/static-slice-query-format.js +1 -0
- package/queries/query.d.ts +18 -1
- package/queries/query.js +3 -1
- package/r-bridge/data/data.d.ts +5 -0
- package/r-bridge/data/data.js +6 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +0 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-number.d.ts +1 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-number.js +1 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-string.d.ts +1 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-string.js +1 -1
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +55 -44
- package/r-bridge/parser.js +2 -9
- package/r-bridge/shell.d.ts +8 -1
- package/r-bridge/shell.js +26 -7
- package/search/flowr-search-builder.d.ts +2 -2
- package/search/flowr-search-builder.js +1 -1
- package/search/flowr-search-filters.d.ts +30 -9
- package/search/flowr-search-filters.js +26 -21
- package/search/search-executor/search-enrichers.d.ts +600 -0
- package/search/search-executor/search-enrichers.js +23 -2
- package/slicing/static/static-slicer.d.ts +39 -11
- package/slicing/static/static-slicer.js +44 -14
- package/util/collections/queue.d.ts +16 -0
- package/util/collections/queue.js +38 -0
- package/util/log.d.ts +1 -1
- package/util/log.js +1 -1
- package/util/mermaid/dfg.d.ts +2 -2
- package/util/mermaid/dfg.js +2 -2
- package/util/objects.d.ts +9 -0
- package/util/objects.js +54 -0
- package/util/proc.d.ts +6 -0
- package/util/proc.js +20 -0
- package/util/version.js +1 -1
package/cli/benchmark-app.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const proc_1 = require("../util/proc");
|
|
7
8
|
const path_1 = __importDefault(require("path"));
|
|
8
9
|
const seedrandom_1 = __importDefault(require("seedrandom"));
|
|
9
10
|
const assert_1 = require("../util/assert");
|
|
@@ -20,7 +21,7 @@ const options = (0, script_1.processCommandLineArgs)('benchmark', [], {
|
|
|
20
21
|
});
|
|
21
22
|
if (options.input.length === 0) {
|
|
22
23
|
console.error('No input files given. Nothing to do. See \'--help\' if this is an error.');
|
|
23
|
-
|
|
24
|
+
(0, proc_1.exitSafe)(0);
|
|
24
25
|
}
|
|
25
26
|
const numberRegex = /^\d+$/;
|
|
26
27
|
(0, assert_1.guard)(options.slice === 'all' || options.slice === 'no' || numberRegex.test(options.slice), 'slice must be either all, no, or a number');
|
package/cli/common/script.js
CHANGED
|
@@ -14,6 +14,7 @@ const command_line_usage_1 = __importDefault(require("command-line-usage"));
|
|
|
14
14
|
const command_line_args_1 = __importDefault(require("command-line-args"));
|
|
15
15
|
const ansi_1 = require("../../util/text/ansi");
|
|
16
16
|
const log_1 = require("../../util/log");
|
|
17
|
+
const proc_1 = require("../../util/proc");
|
|
17
18
|
/**
|
|
18
19
|
* Automatically generates a uniform help from a given script (see {@link scripts}).
|
|
19
20
|
* Additionally, you can pass usage examples that may make use of the formatting instructions `{italic x}` and `{bold x}`.
|
|
@@ -41,7 +42,7 @@ function processCommandLineArgs(script, requireAdditionally, help) {
|
|
|
41
42
|
const options = (0, command_line_args_1.default)(scripts_info_1.scripts[script].options);
|
|
42
43
|
if (options.help) {
|
|
43
44
|
console.log(helpForOptions(script, help));
|
|
44
|
-
|
|
45
|
+
(0, proc_1.exitSafe)(0);
|
|
45
46
|
}
|
|
46
47
|
else if (requireAdditionally.length > 0) {
|
|
47
48
|
const keys = new Set(Object.keys(options));
|
|
@@ -49,7 +50,7 @@ function processCommandLineArgs(script, requireAdditionally, help) {
|
|
|
49
50
|
if (missing.length > 0) {
|
|
50
51
|
console.error((0, ansi_1.italic)(`Missing required arguments: ${missing.join(', ')}. Showing help.`));
|
|
51
52
|
console.log(helpForOptions(script, help));
|
|
52
|
-
|
|
53
|
+
(0, proc_1.exitSafe)(0);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
log_1.log.updateSettings(l => l.settings.minLevel = options.verbose ? 1 /* LogLevel.Trace */ : 5 /* LogLevel.Error */);
|
package/cli/flowr.js
CHANGED
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.optionHelp = exports.toolName = void 0;
|
|
7
|
-
const server_1 = require("./repl/server/server");
|
|
8
|
-
const net_1 = require("./repl/server/net");
|
|
9
40
|
const version_1 = require("../util/version");
|
|
10
41
|
const command_line_usage_1 = __importDefault(require("command-line-usage"));
|
|
11
42
|
const log_1 = require("../util/log");
|
|
@@ -17,6 +48,7 @@ const scripts_info_1 = require("./common/scripts-info");
|
|
|
17
48
|
const execute_1 = require("./repl/execute");
|
|
18
49
|
const repl_main_1 = require("./repl/commands/repl-main");
|
|
19
50
|
const core_1 = require("./repl/core");
|
|
51
|
+
const proc_1 = require("../util/proc");
|
|
20
52
|
const print_version_1 = require("./repl/print-version");
|
|
21
53
|
const flowr_main_options_1 = require("./flowr-main-options");
|
|
22
54
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -97,7 +129,7 @@ function hookSignalHandlers(engines) {
|
|
|
97
129
|
console.log(`\n${(0, ansi_1.italic)('Exiting...')}`);
|
|
98
130
|
}
|
|
99
131
|
Object.values(engines.engines).forEach(e => e?.close());
|
|
100
|
-
|
|
132
|
+
(0, proc_1.exitSafe)(0);
|
|
101
133
|
};
|
|
102
134
|
process.on('SIGINT', end);
|
|
103
135
|
process.on('SIGTERM', end);
|
|
@@ -121,11 +153,11 @@ async function mainRepl() {
|
|
|
121
153
|
console.log(`Running script '${ansi_1.formatter.format(options.script, { style: 1 /* FontStyles.Bold */ })}'`);
|
|
122
154
|
log_1.log.debug(`Script maps to "${target}"`);
|
|
123
155
|
await (0, execute_1.waitOnScript)(`${__dirname}/${target}`, process.argv.slice(3), undefined, true);
|
|
124
|
-
|
|
156
|
+
return (0, proc_1.exitSafe)(0);
|
|
125
157
|
}
|
|
126
158
|
if (options.help) {
|
|
127
159
|
console.log((0, command_line_usage_1.default)(exports.optionHelp));
|
|
128
|
-
|
|
160
|
+
return (0, proc_1.exitSafe)(0);
|
|
129
161
|
}
|
|
130
162
|
const engines = await (0, engines_1.retrieveEngineInstances)(config);
|
|
131
163
|
const defaultEngine = engines.engines[engines.default];
|
|
@@ -134,7 +166,7 @@ async function mainRepl() {
|
|
|
134
166
|
await (0, version_1.printVersionInformation)(repl_main_1.standardReplOutput, engine);
|
|
135
167
|
engine?.close();
|
|
136
168
|
}
|
|
137
|
-
|
|
169
|
+
return (0, proc_1.exitSafe)(0);
|
|
138
170
|
}
|
|
139
171
|
hookSignalHandlers(engines);
|
|
140
172
|
const analyzer = new flowr_analyzer_builder_1.FlowrAnalyzerBuilder(false)
|
|
@@ -152,16 +184,21 @@ async function mainRepl() {
|
|
|
152
184
|
console.log(w('use ') + ansi_1.ansiFormatter.format(':help', { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground, style: 1 /* FontStyles.Bold */ }) + w(' to get a list of available commands.'));
|
|
153
185
|
await (0, core_1.repl)({ analyzer, allowRSessionAccess });
|
|
154
186
|
}
|
|
155
|
-
|
|
187
|
+
(0, proc_1.exitSafe)(0);
|
|
156
188
|
}
|
|
157
|
-
async function mainServer(
|
|
189
|
+
async function mainServer(useWebSocket) {
|
|
158
190
|
const config = createConfig();
|
|
159
191
|
const engines = await (0, engines_1.retrieveEngineInstances)(config);
|
|
160
192
|
hookSignalHandlers(engines);
|
|
161
|
-
|
|
193
|
+
// the server stack (incl. the `ws` websocket library) is only loaded when actually running a server,
|
|
194
|
+
// so the common one-shot analysis path does not pay for evaluating it
|
|
195
|
+
const { FlowRServer } = await Promise.resolve().then(() => __importStar(require('./repl/server/server')));
|
|
196
|
+
const { NetServer, WebSocketServerWrapper } = await Promise.resolve().then(() => __importStar(require('./repl/server/net')));
|
|
197
|
+
const backend = useWebSocket ? new WebSocketServerWrapper() : new NetServer();
|
|
198
|
+
await new FlowRServer(engines.engines, engines.default, options['r-session-access'], config, backend).start(options.port);
|
|
162
199
|
}
|
|
163
200
|
if (options.server) {
|
|
164
|
-
void mainServer(options.ws
|
|
201
|
+
void mainServer(options.ws);
|
|
165
202
|
}
|
|
166
203
|
else {
|
|
167
204
|
void mainRepl();
|
|
@@ -34,7 +34,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.controlflowBbStarCommand = exports.controlflowBbCommand = exports.controlflowStarCommand = exports.controlflowCommand = void 0;
|
|
37
|
-
const retriever_1 = require("../../../r-bridge/retriever");
|
|
38
37
|
const cfg_1 = require("../../../util/mermaid/cfg");
|
|
39
38
|
const ansi_1 = require("../../../util/text/ansi");
|
|
40
39
|
const cfg_simplification_1 = require("../../../control-flow/cfg-simplification");
|
|
@@ -47,16 +46,17 @@ async function produceAndPrintCfg(analyzer, output, simplifications, cfgConverte
|
|
|
47
46
|
const normalizedAst = await analyzer.normalize();
|
|
48
47
|
const mermaid = cfgConverter(cfg, normalizedAst);
|
|
49
48
|
output.stdout(mermaid);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
if (output.allowClipboard !== false) {
|
|
50
|
+
try {
|
|
51
|
+
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
|
|
52
|
+
clipboard.default.writeSync(mermaid);
|
|
53
|
+
output.stdout(formatInfo(output, 'mermaid code'));
|
|
54
|
+
}
|
|
55
|
+
catch { /* do nothing this is a service thing */ }
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
exports.controlflowCommand = {
|
|
59
|
-
description:
|
|
59
|
+
description: 'Get mermaid code for the control-flow graph of R code',
|
|
60
60
|
isCodeCommand: true,
|
|
61
61
|
usageExample: ':controlflow',
|
|
62
62
|
aliases: ['cfg', 'cf'],
|
|
@@ -78,7 +78,7 @@ exports.controlflowStarCommand = {
|
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
80
|
exports.controlflowBbCommand = {
|
|
81
|
-
description:
|
|
81
|
+
description: 'Get mermaid code for the control-flow graph with basic blocks',
|
|
82
82
|
isCodeCommand: true,
|
|
83
83
|
usageExample: ':controlflowbb',
|
|
84
84
|
aliases: ['cfgb', 'cfb'],
|
|
@@ -65,6 +65,11 @@ Furthermore, you can directly call the following scripts which accept arguments.
|
|
|
65
65
|
${Array.from(Object.entries(getReplCommands())).filter(([, { script }]) => script).map(([command, { description }]) => ` ${(0, ansi_1.bold)(padCmd(':' + command), output.formatter)}${description}`).sort().join('\n')}
|
|
66
66
|
|
|
67
67
|
You can combine commands by separating them with a semicolon ${(0, ansi_1.bold)(';', output.formatter)}.
|
|
68
|
+
|
|
69
|
+
Commands that accept a file path support two path prefixes:
|
|
70
|
+
${(0, ansi_1.bold)('file://<path>', output.formatter)} run the command once on the given file or folder
|
|
71
|
+
${(0, ansi_1.bold)('watch://<path>', output.formatter)} re-run the command whenever the file (or any file in the folder) changes
|
|
72
|
+
Press Ctrl+C or enter any other command to leave watch mode.
|
|
68
73
|
`);
|
|
69
74
|
}
|
|
70
75
|
};
|
|
@@ -34,7 +34,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.dataflowSimpleStarCommand = exports.dataflowSimplifiedCommand = exports.dataflowSilentCommand = exports.dataflowAsciiCommand = exports.dataflowStarCommand = exports.dataflowCommand = void 0;
|
|
37
|
-
const retriever_1 = require("../../../r-bridge/retriever");
|
|
38
37
|
const ansi_1 = require("../../../util/text/ansi");
|
|
39
38
|
const core_1 = require("../core");
|
|
40
39
|
const vertex_1 = require("../../../dataflow/graph/vertex");
|
|
@@ -44,7 +43,7 @@ function formatInfo(out, type, meta) {
|
|
|
44
43
|
return out.formatter.format(`Copied ${type} to clipboard (dataflow: ${meta['.meta'].timing + 'ms'}).`, { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground, style: 3 /* FontStyles.Italic */ });
|
|
45
44
|
}
|
|
46
45
|
exports.dataflowCommand = {
|
|
47
|
-
description:
|
|
46
|
+
description: 'Get mermaid code for the dataflow graph',
|
|
48
47
|
isCodeCommand: true,
|
|
49
48
|
usageExample: ':dataflow',
|
|
50
49
|
aliases: ['d', 'df'],
|
|
@@ -54,12 +53,14 @@ exports.dataflowCommand = {
|
|
|
54
53
|
const result = await analyzer.dataflow();
|
|
55
54
|
const mermaid = df_helper_1.Dataflow.visualize.mermaid.convert({ graph: result.graph, includeEnvironments: false }).string;
|
|
56
55
|
output.stdout(mermaid);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
if (output.allowClipboard !== false) {
|
|
57
|
+
try {
|
|
58
|
+
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
|
|
59
|
+
clipboard.default.writeSync(mermaid);
|
|
60
|
+
output.stdout(formatInfo(output, 'mermaid code', result));
|
|
61
|
+
}
|
|
62
|
+
catch { /* do nothing this is a service thing */
|
|
63
|
+
}
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
};
|
|
@@ -74,12 +75,14 @@ exports.dataflowStarCommand = {
|
|
|
74
75
|
const result = await analyzer.dataflow();
|
|
75
76
|
const mermaid = df_helper_1.Dataflow.visualize.mermaid.url(result.graph, false);
|
|
76
77
|
output.stdout(mermaid);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
if (output.allowClipboard !== false) {
|
|
79
|
+
try {
|
|
80
|
+
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
|
|
81
|
+
clipboard.default.writeSync(mermaid);
|
|
82
|
+
output.stdout(formatInfo(output, 'mermaid url', result));
|
|
83
|
+
}
|
|
84
|
+
catch { /* do nothing this is a service thing */ }
|
|
81
85
|
}
|
|
82
|
-
catch { /* do nothing this is a service thing */ }
|
|
83
86
|
}
|
|
84
87
|
};
|
|
85
88
|
exports.dataflowAsciiCommand = {
|
|
@@ -118,7 +121,7 @@ exports.dataflowSilentCommand = {
|
|
|
118
121
|
}
|
|
119
122
|
};
|
|
120
123
|
exports.dataflowSimplifiedCommand = {
|
|
121
|
-
description:
|
|
124
|
+
description: 'Get mermaid code for the simplified dataflow graph',
|
|
122
125
|
isCodeCommand: true,
|
|
123
126
|
usageExample: ':dataflowsimple',
|
|
124
127
|
aliases: ['ds', 'dfs'],
|
|
@@ -128,12 +131,14 @@ exports.dataflowSimplifiedCommand = {
|
|
|
128
131
|
const result = await analyzer.dataflow();
|
|
129
132
|
const mermaid = df_helper_1.Dataflow.visualize.mermaid.convert({ graph: result.graph, includeEnvironments: false, simplified: true }).string;
|
|
130
133
|
output.stdout(mermaid);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
if (output.allowClipboard !== false) {
|
|
135
|
+
try {
|
|
136
|
+
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
|
|
137
|
+
clipboard.default.writeSync(mermaid);
|
|
138
|
+
output.stdout(formatInfo(output, 'mermaid code', result));
|
|
139
|
+
}
|
|
140
|
+
catch { /* do nothing this is a service thing */ }
|
|
135
141
|
}
|
|
136
|
-
catch { /* do nothing this is a service thing */ }
|
|
137
142
|
}
|
|
138
143
|
};
|
|
139
144
|
exports.dataflowSimpleStarCommand = {
|
|
@@ -147,12 +152,14 @@ exports.dataflowSimpleStarCommand = {
|
|
|
147
152
|
const result = await analyzer.dataflow();
|
|
148
153
|
const mermaid = df_helper_1.Dataflow.visualize.mermaid.url(result.graph, false, undefined, true);
|
|
149
154
|
output.stdout(mermaid);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
if (output.allowClipboard !== false) {
|
|
156
|
+
try {
|
|
157
|
+
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
|
|
158
|
+
clipboard.default.writeSync(mermaid);
|
|
159
|
+
output.stdout(formatInfo(output, 'mermaid url', result));
|
|
160
|
+
}
|
|
161
|
+
catch { /* do nothing this is a service thing */ }
|
|
154
162
|
}
|
|
155
|
-
catch { /* do nothing this is a service thing */ }
|
|
156
163
|
}
|
|
157
164
|
};
|
|
158
165
|
//# sourceMappingURL=repl-dataflow.js.map
|
|
@@ -11,6 +11,12 @@ export interface ReplOutput {
|
|
|
11
11
|
formatter: OutputFormatter;
|
|
12
12
|
stdout(msg: string): void;
|
|
13
13
|
stderr(msg: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* When `false`, REPL commands must skip clipboard operations and must not emit
|
|
16
|
+
* "Copied to clipboard" messages. Defaults to `true` (clipboard allowed).
|
|
17
|
+
* Set to `false` in non-interactive contexts such as wiki generation or tests.
|
|
18
|
+
*/
|
|
19
|
+
allowClipboard?: boolean;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* Default repl output that redirects everything to the stdout and stderror channels (linked to `console`).
|
|
@@ -34,7 +34,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.normalizeHashCommand = exports.normalizeStarCommand = exports.normalizeCommand = void 0;
|
|
37
|
-
const retriever_1 = require("../../../r-bridge/retriever");
|
|
38
37
|
const ast_1 = require("../../../util/mermaid/ast");
|
|
39
38
|
const ansi_1 = require("../../../util/text/ansi");
|
|
40
39
|
const core_1 = require("../core");
|
|
@@ -44,7 +43,7 @@ function formatInfo(out, type, meta) {
|
|
|
44
43
|
return out.formatter.format(`Copied ${type} to clipboard (normalize: ${meta['.meta'].timing + 'ms'}).`, { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground, style: 3 /* FontStyles.Italic */ });
|
|
45
44
|
}
|
|
46
45
|
exports.normalizeCommand = {
|
|
47
|
-
description:
|
|
46
|
+
description: 'Get mermaid code for the normalized AST of R code',
|
|
48
47
|
isCodeCommand: true,
|
|
49
48
|
usageExample: ':normalize',
|
|
50
49
|
aliases: ['n'],
|
|
@@ -54,12 +53,14 @@ exports.normalizeCommand = {
|
|
|
54
53
|
const result = await analyzer.normalize();
|
|
55
54
|
const mermaid = (0, ast_1.normalizedAstToMermaid)(result.ast);
|
|
56
55
|
output.stdout(mermaid);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
if (output.allowClipboard !== false) {
|
|
57
|
+
try {
|
|
58
|
+
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
|
|
59
|
+
clipboard.default.writeSync(mermaid);
|
|
60
|
+
output.stdout(formatInfo(output, 'mermaid url', result));
|
|
61
|
+
}
|
|
62
|
+
catch { /* do nothing this is a service thing */ }
|
|
61
63
|
}
|
|
62
|
-
catch { /* do nothing this is a service thing */ }
|
|
63
64
|
}
|
|
64
65
|
};
|
|
65
66
|
exports.normalizeStarCommand = {
|
|
@@ -73,12 +74,14 @@ exports.normalizeStarCommand = {
|
|
|
73
74
|
const result = await analyzer.normalize();
|
|
74
75
|
const mermaid = (0, ast_1.normalizedAstToMermaidUrl)(result.ast);
|
|
75
76
|
output.stdout(mermaid);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
if (output.allowClipboard !== false) {
|
|
78
|
+
try {
|
|
79
|
+
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
|
|
80
|
+
clipboard.default.writeSync(mermaid);
|
|
81
|
+
output.stdout(formatInfo(output, 'mermaid url', result));
|
|
82
|
+
}
|
|
83
|
+
catch { /* do nothing this is a service thing */ }
|
|
80
84
|
}
|
|
81
|
-
catch { /* do nothing this is a service thing */ }
|
|
82
85
|
}
|
|
83
86
|
};
|
|
84
87
|
exports.normalizeHashCommand = {
|
|
@@ -126,7 +126,7 @@ function depthListToTextTree(list, f) {
|
|
|
126
126
|
return result;
|
|
127
127
|
}
|
|
128
128
|
exports.parseCommand = {
|
|
129
|
-
description:
|
|
129
|
+
description: 'Prints ASCII Art of the parsed, unmodified AST',
|
|
130
130
|
isCodeCommand: true,
|
|
131
131
|
usageExample: ':parse',
|
|
132
132
|
aliases: ['p'],
|
|
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.queryStarCommand = exports.queryCommand = void 0;
|
|
4
4
|
const ansi_1 = require("../../../util/text/ansi");
|
|
5
5
|
const query_1 = require("../../../queries/query");
|
|
6
|
-
const retriever_1 = require("../../../r-bridge/retriever");
|
|
7
6
|
const query_print_1 = require("../../../queries/query-print");
|
|
8
7
|
const json_1 = require("../../../util/json");
|
|
9
8
|
const args_1 = require("../../../util/text/args");
|
|
9
|
+
const record_1 = require("../../../util/record");
|
|
10
10
|
function printHelp(output) {
|
|
11
11
|
output.stderr(`Format: ${(0, ansi_1.italic)(':query <query> <code>', output.formatter)}`);
|
|
12
12
|
output.stdout('Queries starting with \'@<type>\' are interpreted as a query of the given type.');
|
|
13
13
|
output.stdout(`With this, ${(0, ansi_1.bold)(':query @config', output.formatter)} prints the result of the config query.`);
|
|
14
|
-
output.stdout(`If you want to run the linter on a project use:\n ${(0, ansi_1.bold)(':query @linter file://<path>', output.formatter)}.`);
|
|
14
|
+
output.stdout(`If you want to run the linter on a project use:\n ${(0, ansi_1.bold)(':query @linter file://<path>', output.formatter)} (or ${(0, ansi_1.bold)('watch://<path>', output.formatter)} to re-run on changes).`);
|
|
15
15
|
output.stdout((0, ansi_1.ansiInfo)('Otherwise, you can also directly pass the query json. Then, the query is an array of query objects to represent multiple queries.'));
|
|
16
16
|
output.stdout((0, ansi_1.ansiInfo)('The example') + (0, ansi_1.italic)(String.raw `:query "[{\"type\": \"call-context\", \"callName\": \"mean\" }]" mean(1:10)`, output.formatter, { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground }) + (0, ansi_1.ansiInfo)('would return the call context of the mean function.'));
|
|
17
17
|
output.stdout('Please have a look at the wiki for more info: https://github.com/flowr-analysis/flowr/wiki/Query-API');
|
|
@@ -98,7 +98,7 @@ function parseArgs(line) {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
exports.queryCommand = {
|
|
101
|
-
description:
|
|
101
|
+
description: 'Query the given R code (use \'help\' for more information)',
|
|
102
102
|
isCodeCommand: true,
|
|
103
103
|
usageExample: ':query "<query>" <code>',
|
|
104
104
|
aliases: [],
|
|
@@ -123,8 +123,7 @@ exports.queryStarCommand = {
|
|
|
123
123
|
fn: async ({ output, analyzer, remainingArgs }) => {
|
|
124
124
|
const results = await processQueryArgs(output, analyzer, remainingArgs);
|
|
125
125
|
if (results) {
|
|
126
|
-
const json =
|
|
127
|
-
.map(([query, queryResults]) => [query, query_1.SupportedQueries[query]?.jsonFormatter?.(queryResults) ?? queryResults]));
|
|
126
|
+
const json = record_1.Record.map(results.query, ([query, queryResults]) => [query, query_1.SupportedQueries[query]?.jsonFormatter?.(queryResults) ?? queryResults]);
|
|
128
127
|
output.stdout(JSON.stringify(json, json_1.jsonReplacer));
|
|
129
128
|
}
|
|
130
129
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.quitCommand = void 0;
|
|
4
4
|
const log_1 = require("../../../util/log");
|
|
5
|
+
const proc_1 = require("../../../util/proc");
|
|
5
6
|
exports.quitCommand = {
|
|
6
7
|
description: 'End the repl',
|
|
7
8
|
isCodeCommand: false,
|
|
@@ -10,7 +11,7 @@ exports.quitCommand = {
|
|
|
10
11
|
script: false,
|
|
11
12
|
fn: () => {
|
|
12
13
|
log_1.log.info('bye');
|
|
13
|
-
|
|
14
|
+
(0, proc_1.exitSafe)(0);
|
|
14
15
|
}
|
|
15
16
|
};
|
|
16
17
|
//# sourceMappingURL=repl-quit.js.map
|
package/cli/repl/core.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as readline from 'readline';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
import { type ReplOutput } from './commands/repl-main';
|
|
3
4
|
import type { MergeableRecord } from '../../util/objects';
|
|
4
5
|
import type { FlowrConfig } from '../../config';
|
|
@@ -30,6 +31,16 @@ export declare function handleString(code: string): {
|
|
|
30
31
|
rCode: string | undefined;
|
|
31
32
|
remaining: never[];
|
|
32
33
|
};
|
|
34
|
+
/** Path prefix that activates watch mode; use instead of {@link fileProtocol} to re-run on every file change. */
|
|
35
|
+
export declare const watchProtocol = "watch://";
|
|
36
|
+
/** Convert a statement containing {@link watchProtocol} into one using {@link fileProtocol} so it can be executed. */
|
|
37
|
+
export declare function toFileStatement(statement: string): string;
|
|
38
|
+
/** Return the watch path from the first `watch://<path>` token in `statement`, or `undefined` if none is present. */
|
|
39
|
+
export declare function extractWatchPath(statement: string): string | undefined;
|
|
40
|
+
/** Stop the active watcher. Pass `notify = false` when silently switching to a new watch target. */
|
|
41
|
+
export declare function stopWatching(output: ReplOutput, notify?: boolean): void;
|
|
42
|
+
/** `watchImpl` is injectable so tests can pass a fake `fs.watch`. */
|
|
43
|
+
export declare function startWatching(watchPath: string, output: ReplOutput, onFire: () => void, watchImpl?: typeof fs.watch): fs.FSWatcher;
|
|
33
44
|
/**
|
|
34
45
|
* This function interprets the given `expr` as a REPL command (see {@link repl} for more on the semantics).
|
|
35
46
|
* @param analyzer - The flowR analyzer to use.
|
package/cli/repl/core.js
CHANGED
|
@@ -36,9 +36,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.watchProtocol = void 0;
|
|
39
40
|
exports.replCompleter = replCompleter;
|
|
40
41
|
exports.makeDefaultReplReadline = makeDefaultReplReadline;
|
|
41
42
|
exports.handleString = handleString;
|
|
43
|
+
exports.toFileStatement = toFileStatement;
|
|
44
|
+
exports.extractWatchPath = extractWatchPath;
|
|
45
|
+
exports.stopWatching = stopWatching;
|
|
46
|
+
exports.startWatching = startWatching;
|
|
42
47
|
exports.replProcessAnswer = replProcessAnswer;
|
|
43
48
|
exports.repl = repl;
|
|
44
49
|
exports.loadReplHistory = loadReplHistory;
|
|
@@ -62,6 +67,7 @@ const log_1 = require("../../util/log");
|
|
|
62
67
|
const query_1 = require("../../queries/query");
|
|
63
68
|
const strings_1 = require("../../util/text/strings");
|
|
64
69
|
const instrument_dataflow_count_1 = require("../../dataflow/instrument/instrument-dataflow-count");
|
|
70
|
+
const proc_1 = require("../../util/proc");
|
|
65
71
|
let _replCompleterKeywords = undefined;
|
|
66
72
|
function replCompleterKeywords() {
|
|
67
73
|
if (_replCompleterKeywords === undefined) {
|
|
@@ -98,8 +104,8 @@ function replCompleter(line, config) {
|
|
|
98
104
|
completions = completions.concat(queryCompletions);
|
|
99
105
|
}
|
|
100
106
|
else {
|
|
101
|
-
// autocomplete command arguments (specifically, autocomplete the file:// protocol)
|
|
102
107
|
completions.push(retriever_1.fileProtocol);
|
|
108
|
+
completions.push(exports.watchProtocol);
|
|
103
109
|
}
|
|
104
110
|
return [completions.filter(a => a.startsWith(currentArg)), currentArg];
|
|
105
111
|
}
|
|
@@ -145,7 +151,46 @@ function handleString(code) {
|
|
|
145
151
|
remaining: []
|
|
146
152
|
};
|
|
147
153
|
}
|
|
148
|
-
|
|
154
|
+
/** Path prefix that activates watch mode; use instead of {@link fileProtocol} to re-run on every file change. */
|
|
155
|
+
exports.watchProtocol = 'watch://';
|
|
156
|
+
/** Convert a statement containing {@link watchProtocol} into one using {@link fileProtocol} so it can be executed. */
|
|
157
|
+
function toFileStatement(statement) {
|
|
158
|
+
return statement.replaceAll(exports.watchProtocol, retriever_1.fileProtocol);
|
|
159
|
+
}
|
|
160
|
+
/** Return the watch path from the first `watch://<path>` token in `statement`, or `undefined` if none is present. */
|
|
161
|
+
function extractWatchPath(statement) {
|
|
162
|
+
return /watch:\/\/(\S+)/.exec(statement)?.[1];
|
|
163
|
+
}
|
|
164
|
+
let activeWatcher;
|
|
165
|
+
/** Stop the active watcher. Pass `notify = false` when silently switching to a new watch target. */
|
|
166
|
+
function stopWatching(output, notify = true) {
|
|
167
|
+
if (activeWatcher !== undefined) {
|
|
168
|
+
try {
|
|
169
|
+
activeWatcher.close();
|
|
170
|
+
}
|
|
171
|
+
catch { /* already closed */ }
|
|
172
|
+
activeWatcher = undefined;
|
|
173
|
+
if (notify) {
|
|
174
|
+
output.stdout('Watch mode stopped.');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** `watchImpl` is injectable so tests can pass a fake `fs.watch`. */
|
|
179
|
+
function startWatching(watchPath, output, onFire, watchImpl = fs_1.default.watch) {
|
|
180
|
+
const faint = (s) => output.formatter.format(s, { style: 2 /* FontStyles.Faint */ });
|
|
181
|
+
const isDir = fs_1.default.existsSync(watchPath) && fs_1.default.statSync(watchPath).isDirectory();
|
|
182
|
+
let debounce;
|
|
183
|
+
const watcher = watchImpl(watchPath, { recursive: isDir }, () => {
|
|
184
|
+
clearTimeout(debounce);
|
|
185
|
+
debounce = setTimeout(() => {
|
|
186
|
+
output.stdout(faint(`\nChange detected in '${watchPath}', re-running...`));
|
|
187
|
+
onFire();
|
|
188
|
+
}, 50);
|
|
189
|
+
});
|
|
190
|
+
output.stdout(faint(`Watching ${isDir ? 'folder' : 'file'} '${watchPath}'. Press Ctrl+C or enter another command to stop.`));
|
|
191
|
+
return watcher;
|
|
192
|
+
}
|
|
193
|
+
async function executeStatement(output, statement, analyzer, allowRSessionAccess) {
|
|
149
194
|
const time = Date.now();
|
|
150
195
|
const heatMap = new Map();
|
|
151
196
|
if (analyzer.inspectContext().config.repl.dfProcessorHeat) {
|
|
@@ -224,6 +269,31 @@ async function replProcessStatement(output, statement, analyzer, allowRSessionAc
|
|
|
224
269
|
}
|
|
225
270
|
}
|
|
226
271
|
}
|
|
272
|
+
async function replProcessStatement(output, statement, analyzer, allowRSessionAccess) {
|
|
273
|
+
stopWatching(output, !statement.includes(exports.watchProtocol));
|
|
274
|
+
if (statement.includes(exports.watchProtocol)) {
|
|
275
|
+
const watchPath = extractWatchPath(statement);
|
|
276
|
+
const effective = toFileStatement(statement);
|
|
277
|
+
await executeStatement(output, effective, analyzer, allowRSessionAccess);
|
|
278
|
+
if (watchPath) {
|
|
279
|
+
try {
|
|
280
|
+
activeWatcher = startWatching(watchPath, output, () => {
|
|
281
|
+
void executeStatement(output, effective, analyzer, allowRSessionAccess);
|
|
282
|
+
});
|
|
283
|
+
activeWatcher.unref();
|
|
284
|
+
activeWatcher.on('error', (err) => {
|
|
285
|
+
output.stderr(`Watch error for '${watchPath}': ${err.message}`);
|
|
286
|
+
stopWatching(output, false);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
catch (e) {
|
|
290
|
+
output.stderr(`Cannot watch '${watchPath}': ${e.message}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
await executeStatement(output, statement, analyzer, allowRSessionAccess);
|
|
296
|
+
}
|
|
227
297
|
/**
|
|
228
298
|
* This function interprets the given `expr` as a REPL command (see {@link repl} for more on the semantics).
|
|
229
299
|
* @param analyzer - The flowR analyzer to use.
|
|
@@ -251,11 +321,39 @@ async function repl({ analyzer, rl = readline.createInterface(makeDefaultReplRea
|
|
|
251
321
|
if (historyFile) {
|
|
252
322
|
rl.on('history', h => fs_1.default.writeFileSync(historyFile, h.join('\n'), { encoding: 'utf-8' }));
|
|
253
323
|
}
|
|
324
|
+
let sigintCount = 0;
|
|
325
|
+
rl.on('SIGINT', () => {
|
|
326
|
+
process.stdout.write('\n');
|
|
327
|
+
if (activeWatcher !== undefined) {
|
|
328
|
+
stopWatching(output);
|
|
329
|
+
rl.setPrompt((0, prompt_1.prompt)());
|
|
330
|
+
sigintCount = 0;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
sigintCount++;
|
|
334
|
+
if (sigintCount >= 2) {
|
|
335
|
+
stopWatching(output, false);
|
|
336
|
+
(0, proc_1.exitSafe)(0);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
output.stdout('(Press Ctrl+C again or type :quit to exit)');
|
|
340
|
+
setTimeout(() => {
|
|
341
|
+
sigintCount = 0;
|
|
342
|
+
}, 2000).unref();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
rl.prompt();
|
|
346
|
+
});
|
|
347
|
+
rl.on('close', () => {
|
|
348
|
+
stopWatching(output, false);
|
|
349
|
+
(0, proc_1.exitSafe)(0);
|
|
350
|
+
});
|
|
254
351
|
// the incredible repl :D, we kill it with ':quit'
|
|
255
352
|
// noinspection InfiniteLoopJS
|
|
256
353
|
while (true) {
|
|
257
354
|
await new Promise((resolve, reject) => {
|
|
258
|
-
rl.question((0, prompt_1.prompt)(), answer => {
|
|
355
|
+
rl.question(activeWatcher !== undefined ? '' : (0, prompt_1.prompt)(), answer => {
|
|
356
|
+
sigintCount = 0;
|
|
259
357
|
rl.pause();
|
|
260
358
|
replProcessAnswer(analyzer, output, answer, allowRSessionAccess).then(() => {
|
|
261
359
|
rl.resume();
|