Repository navigation
[RFC] Expose CLI programmatically - #2168
Closed
josephfrazier wants to merge 21 commits into
Closed
josephfrazier wants to merge 21 commits into
josephfrazier wants to merge 21 commits into
Conversation
This makes it easier to extend later if needed.
This makes it easier to export other things later if needed.
This is so it will run in Node.js 4.
Member
|
I'm a bit confused, how does exposing the CLI as a node module offer performance gains versus just keeping a node.js process open and calling The actual formatting doesn't support streaming output. I might be missing something. |
Collaborator
Author
|
The original motivation for this was to help |
josephfrazier
added a commit
to josephfrazier/prettier_d
that referenced
this pull request
Jul 9, 2017
This is a port of prettier/prettier#2168 at https://github.com/prettier/prettier/pull/2168/files/50291f95627d68075c1b6c65864945fe81c4c755 Note that the cli() function is prettier-ignore'd to make merging upstream easier.
josephfrazier
added a commit
to josephfrazier/prettier
that referenced
this pull request
Jul 9, 2017
This is a port of prettier#2168 at https://github.com/prettier/prettier/pull/2168/files/50291f95627d68075c1b6c65864945fe81c4c755 Note that the cli() function is prettier-ignore'd to make merging upstream easier. (cherry picked from josephfrazier/prettier_d@4efc302)
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(This diff is best viewed ignoring whitespace changes: https://github.com/prettier/prettier/pull/2168/files?w=true)
These changes make
./bin/prettier.jsexport an object with aclimethod that takes the following parameters:
and returns a Promise resolving to an object with an
exitCodeproperty. The object may be an Error.
This allows
prettierwrappers likeprettier_dto simply pass the arguments/streams to a preloaded prettier instance,
which handles all the CLI parsing and subsequent processing.
There is an example of using the new API in
tests/cli/jsfmt.spec.js.