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.
Closes #301.
The diff is annoyingly misleading so here's exactly what happened:
supports-color
fromsource/index.js
in lieu of a generic factory functionChalk
function and references toChalk.prototype
(a regular object works fine instead).chalkFactory
insource/index.js instead of the nicely wrapped
chalk` instancesource/index.js
tosource/factory.js
, which becomes the basis for both stderr and stdout instancessource/index.js
andstderr.js
, both of which are small glue wrappers around the factory function (virtually the identical code removed from the now-renamedsource/index.js
) that also pass their respectivesupports-color
objects.Caveat 1: npm
There's no seemingly elegant way to be able to have
require('chalk/stderr')
pull fromsource/stderr.js
so I pulledstderr.js
into the root. It might make sense to also pullindex.js
into the root for consistency, which would allow us to removemain
from package.json. It might also make sense to renamesource
->lib
in that case, too.Seems like a giant step back but unfortunately npm is very limiting when it comes to this kind of thing.
Caveat 2: Typescript
Typescript type definition files are a nightmare, I couldn't figure out how to get typescript to recognize them. Perhaps @blakeembrey can help - as is, types do not import correctly using a tsserver instance even before these changes (on master) so something was broken beforehand.
Unless I'm mistaken, only an
stderr.d.ts
would have to be created with a///<reference path="./index.d.ts" />
at the very top since the returned "types" from bothindex.js
andstderr.js
are the same.However, none of that seems to be working. I have no idea how to debug the issue, so I'm keeping this PR strictly changes to the functional code. We should investigate typescript types before releasing chalk 3.