@vforsh/argus 0.1.14 → 0.1.16
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/dist/.tsbuildinfo +1 -1
- package/dist/argus.js +1861 -1171
- package/dist/cli/defineWatcherCommand.d.ts +17 -0
- package/dist/cli/defineWatcherCommand.d.ts.map +1 -1
- package/dist/cli/defineWatcherCommand.js +19 -2
- package/dist/cli/defineWatcherCommand.js.map +1 -1
- package/dist/cli/plugins/pluginAliases.d.ts +6 -0
- package/dist/cli/plugins/pluginAliases.d.ts.map +1 -0
- package/dist/cli/plugins/pluginAliases.js +10 -0
- package/dist/cli/plugins/pluginAliases.js.map +1 -0
- package/dist/cli/plugins/pluginHost.d.ts +3 -0
- package/dist/cli/plugins/pluginHost.d.ts.map +1 -0
- package/dist/cli/plugins/pluginHost.js +30 -0
- package/dist/cli/plugins/pluginHost.js.map +1 -0
- package/dist/cli/plugins/registerPlugins.d.ts +32 -1
- package/dist/cli/plugins/registerPlugins.d.ts.map +1 -1
- package/dist/cli/plugins/registerPlugins.js +102 -12
- package/dist/cli/plugins/registerPlugins.js.map +1 -1
- package/dist/cli/program.d.ts.map +1 -1
- package/dist/cli/program.js +2 -0
- package/dist/cli/program.js.map +1 -1
- package/dist/cli/register/index.d.ts.map +1 -1
- package/dist/cli/register/index.js +2 -0
- package/dist/cli/register/index.js.map +1 -1
- package/dist/cli/register/registerAuth.d.ts.map +1 -1
- package/dist/cli/register/registerAuth.js +13 -8
- package/dist/cli/register/registerAuth.js.map +1 -1
- package/dist/cli/register/registerEval.d.ts.map +1 -1
- package/dist/cli/register/registerEval.js +12 -0
- package/dist/cli/register/registerEval.js.map +1 -1
- package/dist/cli/register/registerExtension.d.ts.map +1 -1
- package/dist/cli/register/registerExtension.js +24 -1
- package/dist/cli/register/registerExtension.js.map +1 -1
- package/dist/cli/register/registerPlugin.d.ts +3 -0
- package/dist/cli/register/registerPlugin.d.ts.map +1 -0
- package/dist/cli/register/registerPlugin.js +34 -0
- package/dist/cli/register/registerPlugin.js.map +1 -0
- package/dist/cli/register/registerWatcher.d.ts.map +1 -1
- package/dist/cli/register/registerWatcher.js +1 -0
- package/dist/cli/register/registerWatcher.js.map +1 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +4 -9
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/authCookieSupport.d.ts.map +1 -1
- package/dist/commands/authCookieSupport.js +4 -6
- package/dist/commands/authCookieSupport.js.map +1 -1
- package/dist/commands/authCookies.d.ts +4 -4
- package/dist/commands/authCookies.d.ts.map +1 -1
- package/dist/commands/authCookies.js +85 -105
- package/dist/commands/authCookies.js.map +1 -1
- package/dist/commands/code.js +3 -25
- package/dist/commands/code.js.map +1 -1
- package/dist/commands/codeEdit.js +3 -3
- package/dist/commands/codeEdit.js.map +1 -1
- package/dist/commands/configInit.d.ts.map +1 -1
- package/dist/commands/configInit.js +1 -0
- package/dist/commands/configInit.js.map +1 -1
- package/dist/commands/domAdd.d.ts +1 -1
- package/dist/commands/domAdd.d.ts.map +1 -1
- package/dist/commands/domAdd.js +26 -30
- package/dist/commands/domAdd.js.map +1 -1
- package/dist/commands/domInfo.d.ts +1 -1
- package/dist/commands/domInfo.d.ts.map +1 -1
- package/dist/commands/domInfo.js +18 -23
- package/dist/commands/domInfo.js.map +1 -1
- package/dist/commands/domKeydown.d.ts +1 -1
- package/dist/commands/domKeydown.d.ts.map +1 -1
- package/dist/commands/domKeydown.js +22 -43
- package/dist/commands/domKeydown.js.map +1 -1
- package/dist/commands/domModify.js +27 -30
- package/dist/commands/domModify.js.map +1 -1
- package/dist/commands/domScroll.d.ts +1 -1
- package/dist/commands/domScroll.d.ts.map +1 -1
- package/dist/commands/domScroll.js +18 -24
- package/dist/commands/domScroll.js.map +1 -1
- package/dist/commands/domScrollTo.d.ts +1 -1
- package/dist/commands/domScrollTo.d.ts.map +1 -1
- package/dist/commands/domScrollTo.js +15 -24
- package/dist/commands/domScrollTo.js.map +1 -1
- package/dist/commands/domTree.d.ts +1 -1
- package/dist/commands/domTree.d.ts.map +1 -1
- package/dist/commands/domTree.js +18 -24
- package/dist/commands/domTree.js.map +1 -1
- package/dist/commands/eval.d.ts +4 -0
- package/dist/commands/eval.d.ts.map +1 -1
- package/dist/commands/eval.js +43 -62
- package/dist/commands/eval.js.map +1 -1
- package/dist/commands/evalBundle.d.ts +17 -0
- package/dist/commands/evalBundle.d.ts.map +1 -0
- package/dist/commands/evalBundle.js +119 -0
- package/dist/commands/evalBundle.js.map +1 -0
- package/dist/commands/evalPolling.d.ts +55 -0
- package/dist/commands/evalPolling.d.ts.map +1 -0
- package/dist/commands/evalPolling.js +59 -0
- package/dist/commands/evalPolling.js.map +1 -0
- package/dist/commands/evalShared.d.ts +14 -0
- package/dist/commands/evalShared.d.ts.map +1 -1
- package/dist/commands/evalShared.js +75 -10
- package/dist/commands/evalShared.js.map +1 -1
- package/dist/commands/evalUntil.d.ts +4 -0
- package/dist/commands/evalUntil.d.ts.map +1 -1
- package/dist/commands/evalUntil.js +47 -70
- package/dist/commands/evalUntil.js.map +1 -1
- package/dist/commands/extension/attach.d.ts +12 -0
- package/dist/commands/extension/attach.d.ts.map +1 -0
- package/dist/commands/extension/attach.js +175 -0
- package/dist/commands/extension/attach.js.map +1 -0
- package/dist/commands/extension/info.d.ts.map +1 -1
- package/dist/commands/extension/info.js +13 -33
- package/dist/commands/extension/info.js.map +1 -1
- package/dist/commands/extension/nativeHost.d.ts +35 -5
- package/dist/commands/extension/nativeHost.d.ts.map +1 -1
- package/dist/commands/extension/nativeHost.js +95 -12
- package/dist/commands/extension/nativeHost.js.map +1 -1
- package/dist/commands/extension/remove.d.ts.map +1 -1
- package/dist/commands/extension/remove.js +18 -38
- package/dist/commands/extension/remove.js.map +1 -1
- package/dist/commands/extension/resolveExtensionWatcher.d.ts +1 -1
- package/dist/commands/extension/resolveExtensionWatcher.d.ts.map +1 -1
- package/dist/commands/extension/resolveExtensionWatcher.js +15 -29
- package/dist/commands/extension/resolveExtensionWatcher.js.map +1 -1
- package/dist/commands/extension/setup.d.ts.map +1 -1
- package/dist/commands/extension/setup.js +20 -35
- package/dist/commands/extension/setup.js.map +1 -1
- package/dist/commands/extension/status.d.ts.map +1 -1
- package/dist/commands/extension/status.js +12 -38
- package/dist/commands/extension/status.js.map +1 -1
- package/dist/commands/locate.js +2 -2
- package/dist/commands/locate.js.map +1 -1
- package/dist/commands/logs.d.ts +1 -1
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +18 -27
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/net.d.ts +1 -1
- package/dist/commands/net.d.ts.map +1 -1
- package/dist/commands/net.js +14 -19
- package/dist/commands/net.js.map +1 -1
- package/dist/commands/netClear.d.ts +1 -1
- package/dist/commands/netClear.d.ts.map +1 -1
- package/dist/commands/netClear.js +7 -19
- package/dist/commands/netClear.js.map +1 -1
- package/dist/commands/netSse.js +2 -2
- package/dist/commands/netSse.js.map +1 -1
- package/dist/commands/netWebSocket.js +3 -3
- package/dist/commands/netWebSocket.js.map +1 -1
- package/dist/commands/pageEmulation.d.ts +3 -3
- package/dist/commands/pageEmulation.d.ts.map +1 -1
- package/dist/commands/pageEmulation.js +72 -143
- package/dist/commands/pageEmulation.js.map +1 -1
- package/dist/commands/pluginConfig.d.ts +7 -0
- package/dist/commands/pluginConfig.d.ts.map +1 -0
- package/dist/commands/pluginConfig.js +199 -0
- package/dist/commands/pluginConfig.js.map +1 -0
- package/dist/commands/pluginList.d.ts +5 -0
- package/dist/commands/pluginList.d.ts.map +1 -0
- package/dist/commands/pluginList.js +26 -0
- package/dist/commands/pluginList.js.map +1 -0
- package/dist/commands/screenshot.d.ts +1 -1
- package/dist/commands/screenshot.d.ts.map +1 -1
- package/dist/commands/screenshot.js +12 -18
- package/dist/commands/screenshot.js.map +1 -1
- package/dist/commands/watcherNativeHost.d.ts +1 -0
- package/dist/commands/watcherNativeHost.d.ts.map +1 -1
- package/dist/commands/watcherNativeHost.js +8 -2
- package/dist/commands/watcherNativeHost.js.map +1 -1
- package/dist/commands/watcherStatus.d.ts +1 -1
- package/dist/commands/watcherStatus.d.ts.map +1 -1
- package/dist/commands/watcherStatus.js +8 -21
- package/dist/commands/watcherStatus.js.map +1 -1
- package/dist/config/argusConfig.d.ts +5 -0
- package/dist/config/argusConfig.d.ts.map +1 -1
- package/dist/config/argusConfig.js +33 -2
- package/dist/config/argusConfig.js.map +1 -1
- package/package.json +3 -2
- package/schemas/argus.config.schema.json +16 -0
package/dist/commands/eval.js
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
import { evalWithRetries } from '../eval/evalClient.js';
|
|
2
2
|
import { createOutput } from '../output/io.js';
|
|
3
3
|
import { resolveWatcherOrExit } from '../watchers/requestWatcher.js';
|
|
4
|
-
import {
|
|
4
|
+
import { pollEval } from './evalPolling.js';
|
|
5
|
+
import { formatError, parseCount, parseIntervalMs, parseNumber, parseRetryCount, prepareEvalExpression, printError, printSuccess, } from './evalShared.js';
|
|
5
6
|
/** Execute the eval command for a watcher id. */
|
|
6
7
|
export const runEval = async (id, rawExpression, options) => {
|
|
7
8
|
const output = createOutput(options);
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
output.writeWarn(evalArgs.error);
|
|
9
|
+
const prepared = await prepareEvalExpression(rawExpression, options, output);
|
|
10
|
+
if (prepared == null) {
|
|
11
11
|
process.exitCode = 2;
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const resolvedExpression = await resolveExpression(rawExpression, options, output);
|
|
15
|
-
if (resolvedExpression == null) {
|
|
16
|
-
process.exitCode = 2;
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const requestArgs = !options.iframe && hasEvalArgs(evalArgs.value) ? evalArgs.value : undefined;
|
|
20
|
-
const expression = options.iframe
|
|
21
|
-
? wrapForIframeEval(wrapExpressionWithArgs(resolvedExpression, evalArgs.value), {
|
|
22
|
-
selector: options.iframe,
|
|
23
|
-
namespace: options.iframeNamespace ?? 'argus',
|
|
24
|
-
timeoutMs: parseNumber(options.iframeTimeout) ?? 5000,
|
|
25
|
-
})
|
|
26
|
-
: resolvedExpression;
|
|
27
14
|
const retryCount = parseRetryCount(options.retry);
|
|
28
15
|
if (retryCount.error) {
|
|
29
16
|
output.writeWarn(retryCount.error);
|
|
@@ -66,8 +53,8 @@ export const runEval = async (id, rawExpression, options) => {
|
|
|
66
53
|
if (intervalMs.value == null) {
|
|
67
54
|
const singleResult = await evalWithRetries({
|
|
68
55
|
watcher,
|
|
69
|
-
expression,
|
|
70
|
-
args:
|
|
56
|
+
expression: prepared.expression,
|
|
57
|
+
args: prepared.args,
|
|
71
58
|
awaitPromise: options.await ?? true,
|
|
72
59
|
returnByValue: options.returnByValue ?? true,
|
|
73
60
|
timeoutMs,
|
|
@@ -82,51 +69,45 @@ export const runEval = async (id, rawExpression, options) => {
|
|
|
82
69
|
printSuccess(singleResult.response, options, output, false);
|
|
83
70
|
return;
|
|
84
71
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
if (!iterationResult.ok) {
|
|
105
|
-
printError(iterationResult, options, output);
|
|
106
|
-
process.exitCode = 1;
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
printSuccess(iterationResult.response, options, output, true);
|
|
110
|
-
if (untilEvaluator.evaluator) {
|
|
72
|
+
const pollResult = await pollEval({
|
|
73
|
+
watcher,
|
|
74
|
+
expression: prepared.expression,
|
|
75
|
+
args: prepared.args,
|
|
76
|
+
awaitPromise: options.await ?? true,
|
|
77
|
+
returnByValue: options.returnByValue ?? true,
|
|
78
|
+
timeoutMs,
|
|
79
|
+
failOnException: options.failOnException ?? true,
|
|
80
|
+
retryCount: retryCount.value,
|
|
81
|
+
intervalMs: intervalMs.value,
|
|
82
|
+
count: countValue.value,
|
|
83
|
+
onResult: (response) => {
|
|
84
|
+
printSuccess(response, options, output, true);
|
|
85
|
+
},
|
|
86
|
+
shouldStop: (context) => {
|
|
87
|
+
if (!untilEvaluator.evaluator) {
|
|
88
|
+
return { ok: true, matched: false };
|
|
89
|
+
}
|
|
111
90
|
const untilResult = untilEvaluator.evaluator({
|
|
112
|
-
result:
|
|
113
|
-
exception:
|
|
114
|
-
iteration,
|
|
115
|
-
attempt:
|
|
91
|
+
result: context.response.result,
|
|
92
|
+
exception: context.response.exception ?? null,
|
|
93
|
+
iteration: context.iteration,
|
|
94
|
+
attempt: context.attempt,
|
|
116
95
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
96
|
+
return untilResult.ok ? { ok: true, matched: untilResult.matched } : { ok: false, error: untilResult.error };
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
if (pollResult.kind === 'eval-error') {
|
|
100
|
+
printError(pollResult.failure, options, output);
|
|
101
|
+
process.exitCode = 1;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (pollResult.kind === 'condition-error') {
|
|
105
|
+
printError({ kind: 'until', error: pollResult.error }, options, output);
|
|
106
|
+
process.exitCode = 1;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (pollResult.kind === 'interrupted') {
|
|
110
|
+
process.exitCode = 130;
|
|
130
111
|
}
|
|
131
112
|
};
|
|
132
113
|
const compileUntil = (condition) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval.js","sourceRoot":"","sources":["../../src/commands/eval.ts"],"names":[],"mappings":"AACA,O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;IACvB,CAAC;AACF,CAAC,CAAA;AAWD,MAAM,YAAY,GAAG,CAAC,SAAkB,EAAkD,EAAE;IAC3F,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACvB,OAAO,EAAE,CAAA;IACV,CAAC;IAED,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,EAAE,CAAA;IAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,OAAO,EAAE,KAAK,EAAE,yCAAyC,EAAE,CAAA;IAC5D,CAAC;IAED,IAAI,QAA4C,CAAA;IAChD,IAAI,CAAC;QACJ,QAAQ,GAAG,IAAI,QAAQ,CAAC,SAAS,EAAE,6EAA6E,OAAO,IAAI,CAE/G,CAAA;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,EAAE,KAAK,EAAE,0BAA0B,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;IACjE,CAAC;IAED,OAAO;QACN,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE;YACtB,IAAI,CAAC;gBACJ,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAA;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,yCAAyC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;YAC3F,CAAC;QACF,CAAC;KACD,CAAA;AACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type BundleEvalEntryResult = {
|
|
2
|
+
ok: true;
|
|
3
|
+
code: string;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
error: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Bundle a local `--file` entry and its relative imports into one browser-evaluable script.
|
|
10
|
+
*
|
|
11
|
+
* - Only files under the entry file's directory are allowed (no package or Node imports).
|
|
12
|
+
* - TypeScript is transpiled without typechecking.
|
|
13
|
+
* - Output is REPL-compatible: one script, no top-level `export`.
|
|
14
|
+
* - Static and dynamic `import()` of local files are inlined into one script.
|
|
15
|
+
*/
|
|
16
|
+
export declare const bundleEvalEntry: (entryPath: string) => Promise<BundleEvalEntryResult>;
|
|
17
|
+
//# sourceMappingURL=evalBundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evalBundle.d.ts","sourceRoot":"","sources":["../../src/commands/evalBundle.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,qBAAqB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAW7F;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,qBAAqB,CAoCtF,CAAA"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { realpath } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
let esbuildModulePromise;
|
|
4
|
+
const nodeModulesSegment = `${path.sep}node_modules${path.sep}`;
|
|
5
|
+
/** Load esbuild on demand so non-eval CLI commands avoid the native binary startup cost. */
|
|
6
|
+
const loadEsbuild = () => (esbuildModulePromise ??= import('esbuild'));
|
|
7
|
+
/**
|
|
8
|
+
* Bundle a local `--file` entry and its relative imports into one browser-evaluable script.
|
|
9
|
+
*
|
|
10
|
+
* - Only files under the entry file's directory are allowed (no package or Node imports).
|
|
11
|
+
* - TypeScript is transpiled without typechecking.
|
|
12
|
+
* - Output is REPL-compatible: one script, no top-level `export`.
|
|
13
|
+
* - Static and dynamic `import()` of local files are inlined into one script.
|
|
14
|
+
*/
|
|
15
|
+
export const bundleEvalEntry = async (entryPath) => {
|
|
16
|
+
let entryPoint;
|
|
17
|
+
try {
|
|
18
|
+
entryPoint = await realpath(path.resolve(entryPath));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return { ok: false, error: `Failed to read entry file: ${entryPath}` };
|
|
22
|
+
}
|
|
23
|
+
const bundleRoot = path.dirname(entryPoint);
|
|
24
|
+
try {
|
|
25
|
+
const esbuild = await loadEsbuild();
|
|
26
|
+
const result = await esbuild.build({
|
|
27
|
+
absWorkingDir: bundleRoot,
|
|
28
|
+
entryPoints: [entryPoint],
|
|
29
|
+
bundle: true,
|
|
30
|
+
write: false,
|
|
31
|
+
splitting: false,
|
|
32
|
+
format: 'esm',
|
|
33
|
+
platform: 'browser',
|
|
34
|
+
target: 'es2022',
|
|
35
|
+
sourcemap: false,
|
|
36
|
+
logLevel: 'silent',
|
|
37
|
+
plugins: [createLocalFilesPlugin(bundleRoot)],
|
|
38
|
+
});
|
|
39
|
+
const output = result.outputFiles[0];
|
|
40
|
+
if (output == null) {
|
|
41
|
+
return { ok: false, error: 'Bundle produced no output.' };
|
|
42
|
+
}
|
|
43
|
+
const code = `${output.text.trimEnd()}\n//# sourceURL=argus-file://${entryPoint}\n`;
|
|
44
|
+
return { ok: true, code };
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return { ok: false, error: formatBundleFailure(error) };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/** Restrict imports to the entry directory and ensure the bundle is REPL-safe. */
|
|
51
|
+
const createLocalFilesPlugin = (bundleRoot) => {
|
|
52
|
+
const bundleRootPrefix = bundleRoot.endsWith(path.sep) ? bundleRoot : `${bundleRoot}${path.sep}`;
|
|
53
|
+
return {
|
|
54
|
+
name: 'argus-eval-bundle',
|
|
55
|
+
setup(build) {
|
|
56
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
57
|
+
if (args.kind === 'entry-point') {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
if (args.path.startsWith('node:')) {
|
|
61
|
+
return bundleError(`Node built-in import ${JSON.stringify(args.path)} is not allowed in page eval.`);
|
|
62
|
+
}
|
|
63
|
+
if (!args.path.startsWith('.') && !path.isAbsolute(args.path)) {
|
|
64
|
+
return bundleError(`Import ${JSON.stringify(args.path)} is not allowed. Use relative local files under ${bundleRoot}.`);
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
});
|
|
68
|
+
build.onLoad({ filter: /.*/ }, async (args) => {
|
|
69
|
+
let resolvedPath;
|
|
70
|
+
try {
|
|
71
|
+
resolvedPath = await realpath(args.path);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return bundleError(`Failed to read file: ${args.path}`);
|
|
75
|
+
}
|
|
76
|
+
if (resolvedPath !== bundleRoot && !resolvedPath.startsWith(bundleRootPrefix)) {
|
|
77
|
+
return bundleError(`Import escapes the entry directory: ${args.path}`);
|
|
78
|
+
}
|
|
79
|
+
if (resolvedPath.includes(nodeModulesSegment)) {
|
|
80
|
+
return bundleError(`Import from node_modules is not allowed: ${args.path}`);
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
});
|
|
84
|
+
build.onEnd((result) => {
|
|
85
|
+
if (result.errors.length > 0) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const outputs = result.outputFiles ?? [];
|
|
89
|
+
if (outputs.length !== 1) {
|
|
90
|
+
return bundleError(`Bundle produced ${outputs.length} outputs; expected exactly one script.`);
|
|
91
|
+
}
|
|
92
|
+
if (/\bexport\b/.test(outputs[0]?.text ?? '')) {
|
|
93
|
+
return bundleError('Bundled script contains top-level export statements, which page eval cannot run. ' +
|
|
94
|
+
'Remove exports from the entry file (helpers may still export symbols for import).');
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
const bundleError = (text) => ({ errors: [{ text }] });
|
|
101
|
+
const formatBundleFailure = (error) => {
|
|
102
|
+
if (isEsbuildFailure(error)) {
|
|
103
|
+
return error.errors.map(formatEsbuildMessage).join('\n');
|
|
104
|
+
}
|
|
105
|
+
return error instanceof Error ? error.message : String(error);
|
|
106
|
+
};
|
|
107
|
+
const isEsbuildFailure = (error) => error instanceof Error && 'errors' in error && Array.isArray(error.errors) && error.errors.length > 0;
|
|
108
|
+
const formatEsbuildMessage = (issue) => {
|
|
109
|
+
const message = issue.text || 'Bundle failed.';
|
|
110
|
+
const { file, line, column } = issue.location ?? {};
|
|
111
|
+
if (!file) {
|
|
112
|
+
return message;
|
|
113
|
+
}
|
|
114
|
+
if (line == null || column == null) {
|
|
115
|
+
return `${file}: ${message}`;
|
|
116
|
+
}
|
|
117
|
+
return `${file}:${line}:${column}: ${message}`;
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=evalBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evalBundle.js","sourceRoot":"","sources":["../../src/commands/evalBundle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAA;AAM5B,IAAI,oBAAwD,CAAA;AAE5D,MAAM,kBAAkB,GAAG,GAAG,IAAI,CAAC,GAAG,eAAe,IAAI,CAAC,GAAG,EAAE,CAAA;AAE/D,4FAA4F;AAC5F,MAAM,WAAW,GAAG,GAA2B,EAAE,CAAC,CAAC,oBAAoB,KAAK,MAAM,CAAC,SAAS,CAAC,CAAC,CAAA;AAE9F;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,SAAiB,EAAkC,EAAE;IAC1F,IAAI,UAAkB,CAAA;IACtB,IAAI,CAAC;QACJ,UAAU,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IACrD,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,8BAA8B,SAAS,EAAE,EAAE,CAAA;IAC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KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC9D,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAkC,EAAE,CAC3E,KAAK,YAAY,KAAK,IAAI,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;AAEtG,MAAM,oBAAoB,GAAG,CAAC,KAAc,EAAU,EAAE;IACvD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,IAAI,gBAAgB,CAAA;IAC9C,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAA;IACnD,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,OAAO,OAAO,CAAA;IACf,CAAC;IAED,IAAI,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACpC,OAAO,GAAG,IAAI,KAAK,OAAO,EAAE,CAAA;IAC7B,CAAC;IAED,OAAO,GAAG,IAAI,IAAI,IAAI,IAAI,MAAM,KAAK,OAAO,EAAE,CAAA;AAC/C,CAAC,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { EvalResponse, WatcherRecord } from '@vforsh/argus-core';
|
|
2
|
+
import { type EvalAttemptResult } from '../eval/evalClient.js';
|
|
3
|
+
type PollStopContext = {
|
|
4
|
+
response: EvalResponse;
|
|
5
|
+
iteration: number;
|
|
6
|
+
attempt: number;
|
|
7
|
+
};
|
|
8
|
+
type PollStopResult = {
|
|
9
|
+
ok: true;
|
|
10
|
+
matched: boolean;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
error: string;
|
|
14
|
+
};
|
|
15
|
+
export type EvalPollInput = {
|
|
16
|
+
watcher: Pick<WatcherRecord, 'id' | 'host' | 'port'>;
|
|
17
|
+
expression: string;
|
|
18
|
+
args?: Record<string, string>;
|
|
19
|
+
awaitPromise: boolean;
|
|
20
|
+
returnByValue: boolean;
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
failOnException: boolean;
|
|
23
|
+
retryCount: number;
|
|
24
|
+
intervalMs: number;
|
|
25
|
+
count?: number;
|
|
26
|
+
totalTimeoutMs?: number;
|
|
27
|
+
shouldStop?: (context: PollStopContext) => PollStopResult;
|
|
28
|
+
onResult?: (response: EvalResponse, context: PollStopContext) => void;
|
|
29
|
+
};
|
|
30
|
+
export type EvalPollOutcome = {
|
|
31
|
+
kind: 'matched';
|
|
32
|
+
response: EvalResponse;
|
|
33
|
+
iteration: number;
|
|
34
|
+
attempt: number;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'exhausted';
|
|
37
|
+
iterations: number;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'timeout';
|
|
40
|
+
elapsedMs: number;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'interrupted';
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'eval-error';
|
|
45
|
+
failure: Extract<EvalAttemptResult, {
|
|
46
|
+
ok: false;
|
|
47
|
+
}>;
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'condition-error';
|
|
50
|
+
error: string;
|
|
51
|
+
};
|
|
52
|
+
/** Shared polling engine for `eval --interval` and `eval-until` so loop semantics stay identical. */
|
|
53
|
+
export declare const pollEval: (input: EvalPollInput) => Promise<EvalPollOutcome>;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=evalPolling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evalPolling.d.ts","sourceRoot":"","sources":["../../src/commands/evalPolling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAmB,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAG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AE,GACtC;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC,iBAAiB,EAAE;QAAE,EAAE,EAAE,KAAK,CAAA;KAAE,CAAC,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAE7C,qGAAqG;AACrG,eAAO,MAAM,QAAQ,GAAU,OAAO,aAAa,KAAG,OAAO,CAAC,eAAe,CA+D5E,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { evalWithRetries } from '../eval/evalClient.js';
|
|
2
|
+
import { sleep } from './evalShared.js';
|
|
3
|
+
/** Shared polling engine for `eval --interval` and `eval-until` so loop semantics stay identical. */
|
|
4
|
+
export const pollEval = async (input) => {
|
|
5
|
+
let running = true;
|
|
6
|
+
const stop = () => {
|
|
7
|
+
running = false;
|
|
8
|
+
};
|
|
9
|
+
process.on('SIGINT', stop);
|
|
10
|
+
process.on('SIGTERM', stop);
|
|
11
|
+
try {
|
|
12
|
+
const startTime = Date.now();
|
|
13
|
+
let iteration = 0;
|
|
14
|
+
while (running) {
|
|
15
|
+
if (input.totalTimeoutMs != null) {
|
|
16
|
+
const elapsed = Date.now() - startTime;
|
|
17
|
+
if (elapsed >= input.totalTimeoutMs) {
|
|
18
|
+
return { kind: 'timeout', elapsedMs: elapsed };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
iteration += 1;
|
|
22
|
+
const result = await evalWithRetries({
|
|
23
|
+
watcher: input.watcher,
|
|
24
|
+
expression: input.expression,
|
|
25
|
+
args: input.args,
|
|
26
|
+
awaitPromise: input.awaitPromise,
|
|
27
|
+
returnByValue: input.returnByValue,
|
|
28
|
+
timeoutMs: input.timeoutMs,
|
|
29
|
+
failOnException: input.failOnException,
|
|
30
|
+
retryCount: input.retryCount,
|
|
31
|
+
});
|
|
32
|
+
if (!result.ok) {
|
|
33
|
+
return { kind: 'eval-error', failure: result };
|
|
34
|
+
}
|
|
35
|
+
const context = { response: result.response, iteration, attempt: result.attempt };
|
|
36
|
+
// Streaming commands print the matched iteration too, so emit before checking stop conditions.
|
|
37
|
+
input.onResult?.(result.response, context);
|
|
38
|
+
const stopResult = input.shouldStop?.(context);
|
|
39
|
+
if (stopResult) {
|
|
40
|
+
if (!stopResult.ok) {
|
|
41
|
+
return { kind: 'condition-error', error: stopResult.error };
|
|
42
|
+
}
|
|
43
|
+
if (stopResult.matched) {
|
|
44
|
+
return { kind: 'matched', response: result.response, iteration, attempt: result.attempt };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (input.count != null && iteration >= input.count) {
|
|
48
|
+
return { kind: 'exhausted', iterations: iteration };
|
|
49
|
+
}
|
|
50
|
+
await sleep(input.intervalMs);
|
|
51
|
+
}
|
|
52
|
+
return { kind: 'interrupted' };
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
process.off('SIGINT', stop);
|
|
56
|
+
process.off('SIGTERM', stop);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=evalPolling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evalPolling.js","sourceRoot":"","sources":["../../src/commands/evalPolling.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA0B,MAAM,uBAAuB,CAAA;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAkCvC,qGAAqG;AACrG,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,KAAoB,EAA4B,EAAE;IAChF,IAAI,OAAO,GAAG,IAAI,CAAA;IAClB,MAAM,IAAI,GAAG,GAAS,EAAE;QACvB,OAAO,GAAG,KAAK,CAAA;IAChB,CAAC,CAAA;IAED,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IAC1B,OAAO,CAAC,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,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAA;YAC9C,IAAI,UAAU,EAAE,CAAC;gBAChB,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;oBACpB,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,CAAA;gBAC5D,CAAC;gBACD,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;oBACxB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAA;gBAC1F,CAAC;YACF,CAAC;YAED,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,IAAI,SAAS,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBACrD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,CAAA;YACpD,CAAC;YAED,MAAM,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QAC9B,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;IAC/B,CAAC;YAAS,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QAC3B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;IAC7B,CAAC;AACF,CAAC,CAAA"}
|
|
@@ -4,9 +4,23 @@ export { formatError, parseNumber } from '../cli/parse.js';
|
|
|
4
4
|
type ExpressionSourceOptions = {
|
|
5
5
|
file?: string;
|
|
6
6
|
stdin?: boolean;
|
|
7
|
+
inject?: string;
|
|
8
|
+
bundle?: boolean;
|
|
7
9
|
};
|
|
8
10
|
/** String-only argument map exposed to eval scripts as `args`. */
|
|
9
11
|
export type EvalArgMap = Record<string, string>;
|
|
12
|
+
type EvalExpressionOptions = ExpressionSourceOptions & {
|
|
13
|
+
iframe?: string;
|
|
14
|
+
iframeNamespace?: string;
|
|
15
|
+
iframeTimeout?: string;
|
|
16
|
+
arg?: string[];
|
|
17
|
+
};
|
|
18
|
+
export type PreparedEvalExpression = {
|
|
19
|
+
expression: string;
|
|
20
|
+
args?: EvalArgMap;
|
|
21
|
+
};
|
|
22
|
+
/** Resolve script input, eval args, and iframe wrapping into the payload sent to the watcher. */
|
|
23
|
+
export declare const prepareEvalExpression: (inline: string | undefined, options: EvalExpressionOptions, output: Output) => Promise<PreparedEvalExpression | null>;
|
|
10
24
|
/**
|
|
11
25
|
* Resolve the JS expression from inline argument, --file, or --stdin.
|
|
12
26
|
* Returns `null` (and writes a warning) when the input is invalid.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evalShared.d.ts","sourceRoot":"","sources":["../../src/commands/evalShared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAItD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"evalShared.d.ts","sourceRoot":"","sources":["../../src/commands/evalShared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAItD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAK7C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAM1D,KAAK,uBAAuB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,kEAAkE;AAClE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE/C,KAAK,qBAAqB,GAAG,uBAAuB,GAAG;IACtD,MAAM,CAAC,EAAE,MAAM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,KAAG,MA6B1E,CAAA"}
|
|
@@ -2,8 +2,35 @@ import { previewStringify } from '@vforsh/argus-core';
|
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { formatError, parseNumber } from '../cli/parse.js';
|
|
4
4
|
import { parseDurationMs } from '../time.js';
|
|
5
|
+
import { bundleEvalEntry } from './evalBundle.js';
|
|
5
6
|
// Re-export shared parsers so existing eval imports keep working
|
|
6
7
|
export { formatError, parseNumber } from '../cli/parse.js';
|
|
8
|
+
/** Resolve script input, eval args, and iframe wrapping into the payload sent to the watcher. */
|
|
9
|
+
export const prepareEvalExpression = async (inline, options, output) => {
|
|
10
|
+
const evalArgs = parseEvalArgs(options.arg);
|
|
11
|
+
if (evalArgs.error) {
|
|
12
|
+
output.writeWarn(evalArgs.error);
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const resolvedExpression = await resolveExpression(inline, options, output);
|
|
16
|
+
if (resolvedExpression == null) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const args = evalArgs.value;
|
|
20
|
+
if (!options.iframe) {
|
|
21
|
+
return {
|
|
22
|
+
expression: resolvedExpression,
|
|
23
|
+
args: hasEvalArgs(args) ? args : undefined,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
expression: wrapForIframeEval(wrapExpressionWithArgs(resolvedExpression, args), {
|
|
28
|
+
selector: options.iframe,
|
|
29
|
+
namespace: options.iframeNamespace ?? 'argus',
|
|
30
|
+
timeoutMs: parseNumber(options.iframeTimeout) ?? 5000,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
7
34
|
/**
|
|
8
35
|
* Resolve the JS expression from inline argument, --file, or --stdin.
|
|
9
36
|
* Returns `null` (and writes a warning) when the input is invalid.
|
|
@@ -11,7 +38,8 @@ export { formatError, parseNumber } from '../cli/parse.js';
|
|
|
11
38
|
export const resolveExpression = async (inline, options, output) => {
|
|
12
39
|
const wantsStdin = options.stdin === true || inline === '-';
|
|
13
40
|
const hasInline = inline != null && inline !== '-';
|
|
14
|
-
const
|
|
41
|
+
const filePath = options.file;
|
|
42
|
+
const hasFile = filePath != null;
|
|
15
43
|
if (hasInline && hasFile) {
|
|
16
44
|
output.writeWarn('Cannot combine an inline expression with --file');
|
|
17
45
|
return null;
|
|
@@ -24,43 +52,80 @@ export const resolveExpression = async (inline, options, output) => {
|
|
|
24
52
|
output.writeWarn('Cannot combine --file with stdin input');
|
|
25
53
|
return null;
|
|
26
54
|
}
|
|
27
|
-
if (hasFile) {
|
|
55
|
+
if (options.bundle && !hasFile) {
|
|
56
|
+
output.writeWarn('--bundle requires --file');
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
let expression;
|
|
60
|
+
if (hasFile && options.bundle) {
|
|
61
|
+
const bundled = await bundleEvalEntry(filePath);
|
|
62
|
+
if (!bundled.ok) {
|
|
63
|
+
output.writeWarn(`Failed to bundle --file: ${bundled.error}`);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
if (!bundled.code.trim()) {
|
|
67
|
+
output.writeWarn(`Bundled file is empty: ${options.file}`);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
expression = bundled.code;
|
|
71
|
+
}
|
|
72
|
+
else if (hasFile) {
|
|
28
73
|
try {
|
|
29
|
-
const content = await readFile(
|
|
74
|
+
const content = await readFile(filePath, 'utf8');
|
|
30
75
|
if (!content.trim()) {
|
|
31
76
|
output.writeWarn(`File is empty: ${options.file}`);
|
|
32
77
|
return null;
|
|
33
78
|
}
|
|
34
|
-
|
|
79
|
+
expression = content;
|
|
35
80
|
}
|
|
36
81
|
catch (error) {
|
|
37
82
|
output.writeWarn(`Failed to read --file: ${formatError(error)}`);
|
|
38
83
|
return null;
|
|
39
84
|
}
|
|
40
85
|
}
|
|
41
|
-
if (wantsStdin) {
|
|
86
|
+
else if (wantsStdin) {
|
|
42
87
|
try {
|
|
43
88
|
const content = await readStdin();
|
|
44
89
|
if (!content.trim()) {
|
|
45
90
|
output.writeWarn('Stdin input is empty');
|
|
46
91
|
return null;
|
|
47
92
|
}
|
|
48
|
-
|
|
93
|
+
expression = content;
|
|
49
94
|
}
|
|
50
95
|
catch (error) {
|
|
51
96
|
output.writeWarn(`Failed to read stdin: ${formatError(error)}`);
|
|
52
97
|
return null;
|
|
53
98
|
}
|
|
54
99
|
}
|
|
55
|
-
if (hasInline) {
|
|
100
|
+
else if (hasInline) {
|
|
56
101
|
if (!inline.trim()) {
|
|
57
102
|
output.writeWarn('Expression is empty');
|
|
58
103
|
return null;
|
|
59
104
|
}
|
|
60
|
-
|
|
105
|
+
expression = inline;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
output.writeWarn('Expression is required. Provide an inline expression, --file, or --stdin (or pass - as expression).');
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return await prependInjectSource(expression, options.inject, output);
|
|
112
|
+
};
|
|
113
|
+
const prependInjectSource = async (expression, injectPath, output) => {
|
|
114
|
+
if (injectPath == null) {
|
|
115
|
+
return expression;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
const injectSource = await readFile(injectPath, 'utf8');
|
|
119
|
+
if (!injectSource.trim()) {
|
|
120
|
+
output.writeWarn(`Inject file is empty: ${injectPath}`);
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return `${injectSource}\n${expression}`;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
output.writeWarn(`Failed to read --inject: ${formatError(error)}`);
|
|
127
|
+
return null;
|
|
61
128
|
}
|
|
62
|
-
output.writeWarn('Expression is required. Provide an inline expression, --file, or --stdin (or pass - as expression).');
|
|
63
|
-
return null;
|
|
64
129
|
};
|
|
65
130
|
/** Read all of stdin into a string. */
|
|
66
131
|
export const readStdin = async () => new Promise((resolve, reject) => {
|