-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
refactor: migrate library to TypeScript #40
Conversation
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
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.
Thanks again for the great work 🙌
This LGTM for the first step towards v2. One question on the top of my mind: do you expect to convert tests to Typescript as well in a follow-up PR?
Also at this point, I think it would make sense to add you as a collaborator to this project. I'm going to do that right now 🚀
import readingTime from './reading-time' | ||
import ReadingTimeStream from './stream' | ||
|
||
// Wacky way to support const readingTime = require('reading-time') :( | ||
// Basically we can't use ES import/export anymore because re-assigning module.exports | ||
// decouples it from the exports object, which TS export compiles to | ||
module.exports = readingTime | ||
module.exports.default = readingTime | ||
module.exports.ReadingTimeStream = ReadingTimeStream |
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 think this should work:
import readingTime from './reading-time' | |
import ReadingTimeStream from './stream' | |
// Wacky way to support const readingTime = require('reading-time') :( | |
// Basically we can't use ES import/export anymore because re-assigning module.exports | |
// decouples it from the exports object, which TS export compiles to | |
module.exports = readingTime | |
module.exports.default = readingTime | |
module.exports.ReadingTimeStream = ReadingTimeStream | |
import readingTimeFn from "./reading-time"; | |
export default readingTimeFn; | |
export const readingTime = readingTimeFn; | |
export { default as ReadingTimeStream } from "./stream"; | |
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.
The problem with export default readingTimeFn;
is it's transpiled to module.exports.default = readingTimeFn
. I need to support the require()
without .default
because that seems less straightforward.
I've asked the TS community if they have anything good and let's wait for a couple of days to see 👀
Yes, I do😁 Not so experienced with Mocha so I'll do it when I'm migrating to Jest Thanks for inviting! Feel honored |
@ngryman So let's merge this for now, and you can make another |
So here it is—a library completely in TypeScript! This will be the first step towards v2.
What I did:
src/
the TS root anddist/
the output;ReadingTimeStream
as a class;How is publishing different?
The
dist
andsrc
folders should both be published, and since the former is now gitignore-d, it won't be available until you runnpm run build
. I've configured theprepublishOnly
script to runbuild
every time when runningnpm publish
.Expected output:
Note: after merging, please publish it as
2.0.0-alpha.0
, because we're only halfway through the v2 milestone, but I'd still like to have a published version to test the current changes in other projects.Breaking Changes
IOptions
andIReadTimeResults
no longer exist, in favor of theOptions
andReadTimeResults
types;I
.ReadingTimeStream
is no longer instantiable without explicitly usingnew
;ReadingTimeStream
is a class rather than a function. In year 2021, we should embrace strict type enforcement and stay away from the wackiness of weak typing.