-
-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ts-node eval public for node REPL consumption #1121
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1121 +/- ##
==========================================
+ Coverage 79.33% 79.87% +0.53%
==========================================
Files 11 12 +1
Lines 755 780 +25
Branches 157 165 +8
==========================================
+ Hits 599 623 +24
- Misses 101 102 +1
Partials 55 55
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@MarcManiez thanks for tackling this. I hope to make a proper review today. If for some reason I forget by Monday, feel free to ping me about it. I appreciate the effort to respect existing conventions even when you had to move so much around. Our existing API has a
Also, I don't know how @blakeembrey feels about this, but I'm in favor of moving the REPL functionality to a new file: |
Thanks for taking a peep @cspotcode :) I took a stab at what you suggested with I also moved the REPL code to its own file like you suggested. Happy to revert it if it's not to everyone's liking. From my newcomer's perspective, I agree with concision in that splitting the code into more files could help understand the code's structure a little better. |
Very cool, I'll take a look later.
Are you comfortable with me pushing changes to your branch when I review?
Sometimes there are small nitpicks I can fix, or I can propose changes that
we can always revert if there's disagreement. I figure it's easier than
asking you to do all the work.
…On Fri, Sep 4, 2020, 6:30 PM Marc Maniez ***@***.***> wrote:
Thanks for taking a peep @cspotcode <https://github.com/cspotcode> :)
I took a stab at what you suggested with createReplService: 9ab7eca
<9ab7eca>.
Did you see that including any properties other than eval?
I also moved the REPL code to its own file like you suggested. Happy to
revert it if it's not to everyone's liking. From my newcomer's perspective,
I agree with concision in that splitting the code into more files could
help understand the code's structure a little better.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1121 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OCWVCQGWVYSVCQOVT3SEFTBLANCNFSM4QWJL2DQ>
.
|
Absolutely no worries with that, thanks for checking in! |
Hello! Any progress on this? I was about to make a fork in order to allow exactly this, and would like to use this feature in my current project. Would like to help on what it would be needed :) |
Looking forward to this! Thank you @MarcManiez |
No blockers, no update. I've had a busy week with other priorities.
In the meantime, you can install ts-node directly off of a git branch using
npm's git support. So you can start installing and using this feature
today. And when we are able to publish and merge it (in the next couple
weeks I expect) you can switch from the git dependency back to the npm
package.
…On Mon, Sep 14, 2020, 12:40 PM John S. Dvorak ***@***.***> wrote:
Looking forward to this! Thank you @MarcManiez
<https://github.com/MarcManiez>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1121 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OE7ONKQF4IS6BYET6TSFZBQDANCNFSM4QWJL2DQ>
.
|
I am finally getting around to reviewing this. I'm not quite done yet. Because of the refactoring, which I think is a good thing, it's taking me a tad longer to verify that I understand all the changes and that nothing has accidentally broken when merging upstream changes from master. |
That's exciting, thank you for handling the merge 🙏 I see codecov/patch is off the mark. If you have advice on how to best address that, I'm happy to help! |
- promote createReplService to top of the file since it will hopefully be the main entrypoint to any REPL functionality
…s bin.ts from repl.ts
15a1749
to
95375d5
Compare
I'm not sure why codecov/patch is off. Hopefully it ... fixes itself by the time we merge? I reordered the declarations in I also wanted to see if I could reduce coupling between repl.ts and bin.ts. So I expanded the API of I'm not 100% done -- there are a couple TODOs in the code and I need to add tests for the new APIs -- but if you feel like taking a look, I welcome any review feedback. |
I think this is good enough to merge, pending a review. Added a test and a I don't love the naming on Some of the |
development-docs/repl-api.md
Outdated
|
||
``` | ||
const tsNodeReplService = tsNode.createReplService() | ||
const {readFile, fileExists} = repl.getStateAwareHostFunctions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks off - should it be tsNodeReplService.getStateAwareHostFunctions()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like getStateAwareHostFunctions
was left over from the previous commit which renamed getStateAwareHostFunctions
to createEvalAwarePartialHost
. So maybe this was the intent?
const {readFile, fileExists} = repl.getStateAwareHostFunctions() | |
const {readFile, fileExists} = tsNodeReplService.evalAwarePartialHost |
src/index.spec.ts
Outdated
stdout, | ||
stderr | ||
}) | ||
const service = create(replService.evalStateAwareHostFunctions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a newcomer, I experienced some confusion seeing the replService
juxtaposed with the service
. I noticed that the Register
type applies to the service and that naming discrepancy was also a head-scratcher for me. With some digging, I kind of see what they represent.
Nothing immediately applicable, but just sharing some thoughts, as I recall y'all considering what might make the repo easier on newbies!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't like the name of Register
. IMO it should be Service
so that if you do import {Service} from 'ts-node';
then it's intuitive. I'm guessing the Register
name made more sense in the past. We can rename it to Service
and export by the legacy Register
name for backwards-compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another question:
Given that our create()
function returns a Register
, which I'd like to rename to Service
, does it make sense to rename createReplService()
to createRepl()
for consistency? create(): Service
, createRepl(): ReplService
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that would make a lot more sense! I might even rename the ReplService
type to TsRepl
, or TsNodeRepl
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking it's best to avoid putting TsNode
into the names of exports, to match TypeScript and node's APIs. For example:
import {Duplex} from 'streams';
(it's called Duplex, not DuplexStream)import {LanguageService} from 'typescript';
It's named LanguageService instead of TsLanguageService, and lots of usages I've seen do a wildcard import to add thets
prefix:import * as ts from 'typescript'; ts.LanguageService
Anybody know why the tests are failing on Windows? Maybe related to #1126 |
stdin.end() | ||
await promisify(setTimeout)(100) | ||
await promisify(setTimeout)(1e3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯
Fixes #983
I took the second approach suggested by @cspotcode in #983:
This necessitates moving quite a few things around. I've done my best to respect the conventions I could discern, but please let me know if I've missed something.