method ReplSession.import
ReplSession.import(
file: string,
callItThis?: string
): Promise<{ name: string; names: string[]; } | string>

Brings a file into the page after the fact, the way the command line brings one in before it.

A module's exports go into scope under their own names AND together under one — ReplHelpers for test/fixtures/repl-helpers.ts, Elixir's rule for turning a path into something typeable — unless callItThis says what to call it. The namespace is the point: ReplHelpers at the prompt prints everything the file has in one line, which is the question .import is usually asked in service of.

JSON arrives parsed and anything else arrives as a string, because those are the two things a file that is not code can usefully be.

Resolves to what went into scope, or to the reason nothing did.

Parameters

file: string
optional
callItThis: string

Return Type

Promise<{ name: string; names: string[]; } | string>

Usage

import { type ReplSession } from "lib/repl/session.ts";