-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ts-node eval public for node REPL consumption (#1121)
* Add createReplEval function * Add a test * Fix a couple of typos * Actually test the evaluator * Try removing spec * Use service creation pattern * Move REPL code to its own file * - Reorder repl.ts declarations to match the original order from bin.ts - promote createReplService to top of the file since it will hopefully be the main entrypoint to any REPL functionality * Expand ReplService API; use new API in bin.ts, which further decouples bin.ts from repl.ts * Add brief, internal docs for REPL API * Add support for DI of alternative stdio streams into REPL * export REPL from index.ts * remove unnecessary export * Add test for new REPL API * API surface, naming, docs tweaks * tweak identifiers * fix name * Tweak repl API test to match REPL CLI test, allowing it to pass on Windows Co-authored-by: Andrew Bradley <cspotcode@gmail.com>
- Loading branch information
1 parent
ded513d
commit 657de4a
Showing
7 changed files
with
411 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## How to create your own ts-node powered REPL | ||
|
||
- Create ts-node REPL service which includes EvalState | ||
- Create ts-node compiler service using EvalState-aware `readFile` and `fileExists` implementations from REPL | ||
- Bind REPL service to compiler service (chicken-and-egg problem necessitates late binding) | ||
- Either: | ||
- call REPL method start() to start a REPL | ||
- create your own node repl but pass it REPL service's nodeEval() function | ||
|
||
``` | ||
import * as tsnode from 'ts-node'; | ||
const repl = tsnode.createRepl(); | ||
const service = tsnode.register({ | ||
... options, | ||
...repl.evalAwarePartialHost | ||
}); | ||
repl.setService(service); | ||
// Start it | ||
repl.start(); | ||
// or | ||
const nodeRepl = require('repl').start({ | ||
...options, | ||
eval: repl.nodeEval | ||
}); | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.