Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Refactor to typescript #691
Conversation
The PR is now ready for review + testing |
Thanks I’ll try to take a look this weekend |
Really appreciate it @KhaosT Once you check out the branch, it'd be good to run |
@hassankhan I tired to run the built version and when trying to pair with the accessory, I run into
|
Thanks for taking a look at the branch, @KhaosT |
@hassankhan There isn't a formalized test plan
Then from homebridge side, test with one or two simple plugins, make sure API matches what original implementation is. |
Hi @KhaosT, no worries about a formal test plan So far, I've tried the following and things seem to be working fine:
So far, all of the above worked perfectly. Should I be testing
So with a few minor changes, it seems to work with Homebridge. I've made the changes in the Typescript branch I opened there. |
v0.5.0 is released for this change |
Thank you so much @KhaosT! Do let me know if anything comes up, more than happy to fix any issues I may have introduced |
@hassankhan thank you for converting the project to typescript |
Am one of those ‘rare’ people that still use Core.js but will continue using the older HAP-Node.js version until I truly understand the benefit that typescript brings to HAP-node specifically. Regardless, thanks and respect to all your combined efforts for maintaining this awesome repo. |
Can’t find v0.5.0 under releases ? https://github.com/KhaosT/HAP-NodeJS/releases. I guess you are only labelling some commits using release names but not creating the releases. https://github.com/KhaosT/HAP-NodeJS/commits/master |
@aboulfad For some reasons, |
Thanks, no rush :-) in the meantime one can alway checkout older commits that are labelled using release tags (e.g |
Hi @aboulfad, I just thought I'd address your (valid) concern about TypeScript. Ultimately, to an end-user of this project, it wouldn't bring any direct benefits, at least in the short-term. The groups of people who would see an immediate benefit are (a) HAP-NodeJS contributors, and (b) projects that use HAP-NodeJS as a core component. Thanks to most of the types now being declared (and TypeScript's code-completion functionality) you can now at a glance understand what data types are being passed around. This is extremely useful for new HAP-NodeJS contributors who may never have interacted with the codebase before, and would not otherwise (easily) be able to understand those same data types. It is also very useful for any downstream projects, since any changes/additions/removals are easily communicated through the types file (although obviously they should also be communicated via documentation etc.)
Thank you for your kind words |
Thank you @hassankhan for a nice explanation. Now you peeked my curiously, I read quickly about typescript so maybe I’ll give the master branch a chance and see how easy is to migrate to using ts. From the look of it, it should be transparent in theory ... Ok I spoke too fast, guys there are some API changes that will affect end-users using HAP-NodeJS directly, for example the .set/get/updatevalue. The changes aren't major, but will force those using HAP-Node to understand those changes and learn a bit typescript ... I compared an accessory file from 0.4.53 to master to show the differences. |
I'm also one of those users who run Core.js. Had a look this morning and now unsure what is required to migrate previously developed accessories to this new codebase... Guess now need to understand what is typescript and all that it brings |
@n0rt0nthec4t , actually the impact is independent of |
@aboulfad Thanks. I think for the moment will stay on the pre-ts and see how things shake out. Too may accessories to update and don't quite have the time to learn typescript |
@KhaosT @hassankhan - Dear both, Thanks for the TypeScript version. As I am still new to TS, I have the following challenge. I follow the readme instruction and try to run ts-node Core.ts in the src folder. However, I get the following error: "Could not find a declaration file for module 'buffer-shims'"
Can you give me some hint on how to get this one work? Have I missed something in the readme file? Best, |
@OliverS79 FYI, your issue is referenced twice in this thread but no mention of a fix has been delivered or a workaround. |
Hi @aboulfad, @OliverS79, I've been extremely busy with work during the week, I will try and get a PR to hopefully resolve some of these issues for you. @aboulfad The diff link you posted above does not work for me. If I can get an example of what broke, I can try and fix it As a workaround, can you try running |
@hassankhan , I fixed the differences link in my above post. Example:
becomes using TS:
|
@aboulfad thanks for updating the link. I think I should probably change the documentation somewhat... no-one should need to convert their projects to start using Typescript, you should be able to continue using existing Javascript syntax with no change in behaviour. The only time you should start seeing any differences is when you (re)write your code in Typescript. |
@hassankhan , my bad ... looking at the accessory examples led me to believe that one would have to make those changes. So you changed all accessory files as an example how to write an accessory using TS ? |
@aboulfad Yes, unfortunately I did. Again, totally my fault for not updating the documentation - sorry for the trouble it caused you |
^^^ No trouble at all, it was just a simple quick diff that showed whats going on :-) And now we have examples for those that want to migrate their scripts to TS :-) Your work is very much appreciated as it improves this project's codebase and pushes us junior/hobbyists to learn ! |
Been trying to install this new typescript beast with teh latest code base and still get the error as above. I'm very much in two minds about this change to the code base, from an end-user perspective it seems very much retrograde step. No fast startup for Core.js(ts) amore, as ts-node takes forever to verify everything sigh |
Hi all, sorry for the delay in responding - had some IRL issues to iron out. @n0rt0nthec4t I'm terribly sorry for the issues you're experiencing ... I've got a branch with some documentation updates, hopefully I can help clarify things there. Do you also run your own fork of HAP-NodeJS or are you using it as a dependency? |
@hassankhan
|
Just run as a dependency for my accessories, previously node Core.js would start up instantly but not with the typescript thing, takes around 1+ min on a rpi zero. So for me, this is very much backwards code base. Will be staying on 0.4.x atm |
@n0rt0nthec4t this is the thing with typescript. Before every run it transpiles to javascript and then gets executed (when running with ts-node). You could potentially compile it once and then only run the compiled java script code. Although on every update you need to compile again. |
Guessing then the compile to JS would only be needed if you update the HAP-NodeJS code, and if your accessories are still in JS, then no issue? Perhaps some more documentation/guidance is needed for this? |
Hi there,
As part of homebridge#2266, I wanted to give this project a bit of Typescript love too.
I've converted everything except the😕
lib/gen/import.js
, since I'm not quite sure if that file will continue to live on. I tried running the script, and it didn't generate as many devices as the existing file hadI've also added Jest and started writing some very basic unit tests, which I'll add on later.