Skip to content
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

Export frequently used things from the main entry point #762

Merged
merged 9 commits into from
Apr 16, 2020

Conversation

AlCalzone
Copy link
Member

@AlCalzone AlCalzone commented Apr 12, 2020

With this PR we now export the most frequently used things from the main entry point.

@RoboPhred please take a look if you're missing something. The CCs and their enums etc. are not exported yet, I'll need to automate this.

My plan is to have a clear structure of the exports that loosely matches the lib directory. If you have some input on this, I'd like to know:

  • zwave-js: Like before, only the most basic stuff (Driver, Node, maybe Controller)
  • zwave-js/CommandClass: Everything related to CCs (including the CommandClasses enum)
  • zwave-js/Values: ValueID, Metadata, ...
  • ...

And since my use case for the library is pretty unspecific, I could use some help understanding how others use this library. What do you need exported from the CC files? My intention with the node API (node.commandClasses.xyz.abc()) was that you don't need to have access to the CC classes directly.

fixes: #761

@AlCalzone AlCalzone self-assigned this Apr 12, 2020
@RoboPhred
Copy link
Contributor

Most of the data coming out of the CCs I need access to are enums and types related to the CC. For example, CentralSceneKeys from CentralScene, or ColorTable from my Color Switch MR

@AlCalzone
Copy link
Member Author

Man, I love TypeScript. You can now just add a JSDoc comment containing @publicAPI to any CC-related enum or interface you need in the public API and it will automatically be added to the API exports when building the project. I'll need to extend this to more locations.

@AlCalzone AlCalzone marked this pull request as ready for review April 13, 2020 17:09
@AlCalzone AlCalzone marked this pull request as draft April 13, 2020 17:10
@AlCalzone
Copy link
Member Author

Ok, I think I like it now. Additionally to the main entry point, there are now the following entry points:

  • "zwave-js/CommandClass"
  • "zwave-js/Controller"
  • "zwave-js/Driver"
  • "zwave-js/Error"
  • "zwave-js/Node"
  • "zwave-js/Values"

All their contents are also exported by the main entry point if you prefer that. Once this is merged, you can consider the internal structure ("build/...") deprecated. After 3.0.0, I will likely make changes to it.

@AlCalzone AlCalzone marked this pull request as ready for review April 14, 2020 18:48
@RoboPhred
Copy link
Contributor

I checked out and built this branch, but it does not seem to be generating any top level index.js or index.d.ts as specified by its package.json, so I was unable to make use of it.

@@ -131,13 +137,6 @@ function getTargetColorValueID(
};
}

export interface ColorSwitchGetResult {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intended to be the return type of ColorSwitchCCAPI.get, looks like I forgot to specify it in my earlier MR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've resorted to turning off the explicit return type check for the more complicated API methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its still useful to have, so that typescript users can know what to expect from the return type. At least keep the interface and let typescript users cast it on their own.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The information is still there in the generated .d.ts files - its just not explicitly specified in the source file.
grafik

@AlCalzone
Copy link
Member Author

The top level entry points are only generated for the npm package and cleaned up afterwards to keep the directory and git clean. If you want to work with a locally linked copy, just run gulp prepack. To go back to the git structure, run gulp postpack.

@AlCalzone AlCalzone merged commit 06acc67 into master Apr 16, 2020
@AlCalzone AlCalzone deleted the more-exports branch April 16, 2020 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export more public api interfaces / consts through main entrypoint.
2 participants