simplify: call runScript directly in CLI path, no cancellation wrapper needed

Cancellation is only ever triggered via cancelRequestById, which calls
window.main.completeExecutionStep — a renderer-only IPC call. There is no
mechanism in the CLI/Node path that can abort the AbortController, so the
cancellation wrapper was dead code.

Replace require('./run-script').cancellableRunScript with a direct call to
require('../script-executor').runScript. Revert cancelRequestFunctionMap
back to unexported. run-script.ts is removed.
This commit is contained in:
jackkav
2026-05-28 04:53:06 +02:00
parent 410e74eb24
commit bc33fb26e2
3 changed files with 2 additions and 36 deletions

View File

@@ -1,6 +1,6 @@
import type { CurlRequestOptions } from '../main/network/libcurl-promise';
export const cancelRequestFunctionMap = new Map<string, () => void>();
const cancelRequestFunctionMap = new Map<string, () => void>();
export async function cancelRequestById(requestId: string) {
window.main.completeExecutionStep({ requestId });

View File

@@ -61,7 +61,6 @@ import { addSetCookiesToToughCookieJar } from './set-cookie-util';
const { isRequest } = models.request;
const { isRequestGroup } = models.requestGroup;
export interface SendActionRuntime {
appendTimeline: (timelinePath: string, logs: string[]) => Promise<void>;
}
@@ -521,7 +520,7 @@ const tryToExecuteScript = async (context: RequestAndContextAndOptionalResponse)
const fn =
process.type === 'renderer'
? runScriptConcurrently
: (require(/* @vite-ignore */ './run-script') as typeof import('./run-script')).cancellableRunScript;
: (require(/* @vite-ignore */ '../script-executor') as typeof import('../script-executor')).runScript;
const output = await fn({
script,
context: {

View File

@@ -1,33 +0,0 @@
// Node/CLI-only module. Loaded via require(/* @vite-ignore */ './run-script') in
// network.ts so the renderer Vite build never bundles this file.
import type { RequestContext } from '../../../insomnia-scripting-environment/src/objects';
import { runScript as nodejsRunScript } from '../script-executor';
import { cancelRequestFunctionMap, cancellablePromise } from './cancellation';
export const cancellableRunScript = async (options: { script: string; context: RequestContext }) => {
const request = options.context.request;
const requestId = request._id;
const controller = new AbortController();
const cancelRequest = () => {
// TODO: implement cancelPreRequestScript on hiddenBrowserWindow side?
controller.abort();
};
cancelRequestFunctionMap.set(requestId, cancelRequest);
try {
const result = await cancellablePromise({
signal: controller.signal,
fn: nodejsRunScript(options),
});
return result;
} catch (err) {
if ((err as Error).name === 'AbortError') {
throw new Error('Request was cancelled');
}
console.log('[network] Error', err);
throw err;
} finally {
cancelRequestFunctionMap.delete(requestId);
}
};