MCPcopy
hub / github.com/TypeStrong/ts-node / reset

Function reset

src/repl.ts:367–395  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

365 const resetEval = appendToEvalState(state, '');
366
367 function reset() {
368 resetEval();
369
370 // Hard fix for TypeScript forcing `Object.defineProperty(exports, ...)`.
371 runInContext('exports = module.exports', state.path, context);
372 if (forceToBeModule) {
373 state.input += 'export {};void 0;\n';
374 }
375
376 // Declare node builtins.
377 // Skip the same builtins as `addBuiltinLibsToObject`:
378 // those starting with _
379 // those containing /
380 // those that already exist as globals
381 // Intentionally suppress type errors in case @types/node does not declare any of them, and because
382 // `declare import` is technically invalid syntax.
383 // Avoid this when in transpileOnly, because third-party transpilers may not handle `declare import`.
384 if (!service?.transpileOnly) {
385 state.input += `// @ts-ignore\n${builtinModules
386 .filter(
387 (name) =>
388 !name.startsWith('_') &&
389 !name.includes('/') &&
390 !['console', 'module', 'process'].includes(name)
391 )
392 .map((name) => `declare import ${name} = require('${name}')`)
393 .join(';')}\n`;
394 }
395 }
396
397 reset();
398 repl.on('reset', reset);

Callers 1

startInternalFunction · 0.85

Calls 1

runInContextFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…