-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Migrating project to Typescript #2476
Conversation
Okay, so to further improve the process of code review I try to create a commit for every migrated file. Don't know how well this is gonna be for the bigger ones, but works for all the util files. The current idea for merging would be, that alle commits get squashed into two commits. The first one contains all configuration and renaming of files. And the second one the actual changes inside the source code files. This way we can preserve git blame history. |
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 don't have any experience with TypeScript yet. I'm a bit worried about the increased footprint, but I understand run-time, you'd only use the JavaScript files generated by the TypeScript compiler. I'm happy to test my plugins against a beta, but I'm afraid I won't be of much value in a code review.
I haven't yet decided whether to migrate my own plugins to TypeScript. I'm a big fan of strong typing, and hate JavaScript for not supporting it. I'm currently using standard
as style (no semi-columns); that doesn't seem compatible with TypeScript. Still busy migrating to the dynamic platform plugin model, I think I want to finish that before picking up another big migration.
I'm happy to help if you got any questions. Nonetheless it could be helpful if you try to check changes made, to maybe spot any errors made in logic (not necessarily in language). But you could also run Typescript directly using |
What IDE do you use or recommend? I currently use Atom with the |
e6f6d00
to
6554897
Compare
I'm currently using WebStorm. Has some pretty nice auto completion and some decent default linting, but also adopts dynamically if project specifies an eslint configuration for example. I know that VSCode does the same AFAIK. |
Just wanted to thank you @Supereg 👍 |
BridgeSetupManager was hell to type 🙃 |
615b1c4
to
351542c
Compare
Last thing to migrate is server.ts |
Some quick question, If it's okay I would move some of the stuff inside server.ts to places they suite better. For example some of the plugin loading stuff inside server.ts would get move into plugin.ts. Don't know what's better for review. Otherwise I would just do a migration while trying to keep most of the current structure and do all the refactoring in another PR or in a follow up commit in this PR. @oznu |
62d1cbb
to
9462a55
Compare
It might be easier to keep the structure similar to the current code for now. Maybe we can do an initial beta rerelease with these changes (once complete) then a follow up beta with the restructure - all before 1.0.0? |
Okay great. Thought readability could definitely be improved just my moving some config loading and plugin loading into the respective plugin.ts and user.ts (which is basically a config.ts). |
Okay migration should be complete. I tested it on a basic installation with homebridge-dummy enabled. Would want to run/test it on my local instance before merging it. You all are welcome to do your own tests though. |
Nice work! Thanks @Supereg. I'll test this out tonight. |
53d4f09
to
578a178
Compare
Should we include https://github.com/evanw/node-source-map-support ? This will make stack traces alot easier to follow. eg.
Note it provides the typescript line number in the stack trace. I just added this to the top of
|
f6f3d87 needs to go in to prevent these errors:
|
scoped module paths are not resolved correctly. Example: https://www.npmjs.com/package/@kacepe/homebridge-shelly Homebridge tried to load the plugin from
The layout of scoped npm modules on disk looks like this:
|
.eslintrc
Outdated
], | ||
"rules": { | ||
"quotes": ["error", "double"], | ||
"indent": ["error", 4, { "SwitchCase": 1 }], |
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.
HAPNodeJS uses two, not sure if we want to follow in style.
(Disclaimer: I like two 😬)
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.
That is exactly one of the things I wanted to be discussed with my initial commit.
HAP-NodeJS is basically using both 😅 It's not quite consistent.
I personally grew up using four so that's where the default values is coming from. But idk, as long we can be consistent on one.
Oh that's where this part of the code is coming from I was surprisingly unfamiliar with. You may made the error go away, but HAP-NodeJSs getCharacteristic is a bit odd in the way that it will forcefully add the characteristic anyway (not just if it is contained in the optionalCharacteristics). I rather think my original PR was passing the wrong type. Your fix makes the error go away but also prevents the characteristics ever get copied. |
Added two commits to add source-map support and fixing scoped plugins. @oznu |
Okay this is actually somewhat of a bigger problem. The |
c4b3274
to
0e9ff3a
Compare
Okay, so the current state of the PR is now feature complete. It runs already the latest HAP-NodeJS beta (with the revamped Camera controllers and stuff, but support for this will be moved to another PR). Currently runs smooth for me on my personal instance (with some cameras and some basic plugins). Besides that I'm just waiting for everyone doing a code review to finish with that. Testers are welcome too. If I get the okay, I will restructure this commit as above explained to only consist of two commits. Only after that I would suggest to merge into the beta branch. |
Thanks @Supereg, the new update are working well. I'm happy for this to be merged into the |
Okay, squashed all changes into two commits (which should be preserved when merging). I'm ready to merge (into beta!). I would address any further changes to the exposure of the types for plugin developers in a follow up PR if that's okay. |
Okay, so. I think that's the third pull request regarding a typescript migration on this project (#2266, #2393). Both of them a currently not able to get merged and both of them don't seem to work (at least that is what I've been told).
[Edit: had a look at them, and there are some not so got parts about them]
This PR aims to finally migrate this project. And I think with the ongoing beta phase we have a higher confidence to release it to the public (without backtracking on prior testing and code review!).
Currently this PR only contains configuration changes for the new project. The idea was to split configuration changes and actual code changes into (at least) two commits, to improve code review. As I don't know what exact project configuration is preferred, I wanted to use this as a starting point to propose some configurations and let them be discussed here. Any requested changes can currently be incorporated into the now ongoing process of migration.
Ideally this PR should suggest to other contributors to maybe delay some of their PRs, if they plan to make bigger changes in the Code, as otherwise this will result in a big ass merge conflict 🙃
The plan is to squash all commits when the PR is ready, as I currently do not guarantee a working project on every commit
Changes
Project Configuration
src/
and moved contents oflib/
into it (lib/
will be the output dir so backwards compatibility for project structure is provided)Current PR Status: READY TO MERGE