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

Support imports #43

Merged
merged 4 commits into from
Feb 11, 2020
Merged

Support imports #43

merged 4 commits into from
Feb 11, 2020

Conversation

Nevon
Copy link
Member

@Nevon Nevon commented Feb 10, 2020

This allows you to share types across multiple protocols without having to duplicate them in each file. Imports are relative to the current schema (the paths are essentially just passed to fs.readFile), so you could imagine referencing shared types from NPM packages by doing something like import idl '../../node_modules/@company/schemas/metadata.avdl'.

The main gist of it is that the async version of avdlToAVSC uses assembleProtocol instead of readProtocol. This is because readProtocol doesn't support imports.

See the tests or documentation for examples.

I had some problems with vscode not getting the types for avsc, as I wanted to augment the module with a type for the error that assembleProtocol can give you in the callback. I think it works now, but it was weird.

Adds async versions of readAVSC and avdlToAVSC in order to support importing
other schemas from within AVDL files.
Async versions are preferred as otherwise imports will fail.
Copy link
Collaborator

@erikengervall erikengervall left a comment

Choose a reason for hiding this comment

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

Nice 👍

@Nevon Nevon merged commit 80263ec into master Feb 11, 2020
@Nevon Nevon deleted the support-imports branch February 11, 2020 15:28
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.

2 participants