diff --git a/src/index.ts b/src/index.ts index ffb858101..719a3e88d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { Module } from 'module'; import * as util from 'util'; import { fileURLToPath } from 'url'; -import sourceMapSupport = require('@cspotcode/source-map-support'); +import type * as _sourceMapSupport from '@cspotcode/source-map-support'; import { BaseError } from 'make-error'; import type * as _ts from 'typescript'; @@ -793,6 +793,8 @@ export function create(rawOptions: CreateOptions = {}): Service { // Install source map support and read from memory cache. installSourceMapSupport(); function installSourceMapSupport() { + const sourceMapSupport = + require('@cspotcode/source-map-support') as typeof _sourceMapSupport; sourceMapSupport.install({ environment: 'node', retrieveFile(pathOrUrl: string) { diff --git a/src/repl.ts b/src/repl.ts index 41776e12e..c6371bdbb 100644 --- a/src/repl.ts +++ b/src/repl.ts @@ -1,4 +1,4 @@ -import { diffLines } from 'diff'; +import type * as _diff from 'diff'; import { homedir } from 'os'; import { join } from 'path'; import { @@ -26,6 +26,13 @@ function getProcessTopLevelAwait() { } return _processTopLevelAwait; } +let diff: typeof _diff; +function getDiffLines() { + if (diff === undefined) { + diff = require('diff'); + } + return diff.diffLines; +} /** @internal */ export const EVAL_FILENAME = `[eval].ts`; @@ -544,7 +551,7 @@ function appendCompileAndEvalInput(options: { ); // Use `diff` to check for new JavaScript to execute. - const changes = diffLines( + const changes = getDiffLines()( oldOutputWithoutSourcemapComment, outputWithoutSourcemapComment );