function runUserModule
runUserModule(
modulePath: string,
params: unknown,
scriptPosition: string
): Task<void, UserScriptFailedFailure>

Dynamically imports modulePath and calls its default export with params.

A user script that throws is a declared failure, not a process exit. It used to console.trace and process.exit(1) from inside a library function — which no caller could test or override, and which took the daemon down over one client's bad hook.

import { runUserModule } from './run-user-module.ts';
import * as Failure from '../result/failure.ts';

// Defined, not invoked: imports and runs an arbitrary user script.
async function runBeforeHook(config: { before?: string }) {
  if (!config.before) return null;
  const outcome = await runUserModule(config.before, config, 'before').result();
  return Failure.is(outcome) ? outcome.code : null; // 'UserScriptFailed', or null
}

Parameters

modulePath: string
params: unknown
scriptPosition: string

Return Type

Usage

import { runUserModule } from "lib/utils/run-user-module.ts";