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

feat: bundle references into components #46

Merged
merged 15 commits into from Sep 12, 2022

Conversation

Souvikns
Copy link
Member

@Souvikns Souvikns commented May 4, 2022

Description

Since we are using json-schema-ref-parser for referencing external refs we could use it to reference all the external references and keep internal references intact, which results in documents having only internal references, but to bundle external references to correct properties we need to write our custom resolving logic. This is what PR aims to add, a way to update the external references to point to an internal object and successfully bring only the part of the object needed from the external file.

Related issue(s)

Fixes #34

@Souvikns Souvikns marked this pull request as ready for review June 28, 2022 10:56
@Souvikns
Copy link
Member Author

Souvikns commented Jul 5, 2022

Copy link
Sponsor Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

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

As I understand your implementation, you only bundle messages right? So schema payloads are never bundled into schemas component? Do you plan on doing this at a later stage? 🤔

Some general comments:

  • Would be great to introduce a linter, as otherwise there can be quite the discrepancies between implementations 🙂 For example, it will catch those extra new lines and missing ;.
  • Remember to add tests (really good you have examples as well!) as they are to be executed on each PR/change, feel free to ping me if they cause any issues.
  • Remember JSDoc function comments, rarely comments inside the function necessary, but it's always nice to have an explanation of what the function is intended to do 🙂

Otherwise it looks great with the messages being bundled 👍

example/package.json Outdated Show resolved Hide resolved
example/package.json Outdated Show resolved Hide resolved
lib/parser.js Outdated Show resolved Hide resolved
lib/parser.js Outdated Show resolved Hide resolved
lib/parser.js Outdated Show resolved Hide resolved
@Souvikns
Copy link
Member Author

As of now, we are only moving the messages, I think we can create an interface for adding rules for these operations and then reuse it to just add custom rules for schemas and anything in the future.

Should I do this in this PR or in the next one? I also think this would be the right time to move to typescript

cc @jonaslagoni @derberg

@jonaslagoni
Copy link
Sponsor Member

jonaslagoni commented Jul 20, 2022

Should I do this in this PR or in the next one? I also think this would be the right time to move to typescript

Always split up the PRs into smaller ones, each with it's own feature when possible 🙂 It is much easier for the reviwers and for anyone else interrested.

@Souvikns
Copy link
Member Author

Souvikns commented Aug 2, 2022

@jonaslagoni

I have made all the changes you have suggested in this PR

In the next PR, I will

  • Convert the project to Typescript
  • add linting
  • make an interface where adding rules for different bundling logic will be easier

jonaslagoni
jonaslagoni previously approved these changes Aug 2, 2022
Copy link
Sponsor Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

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

Did you consider keeping the old logic so the user could decide whether they wanted inline or component references? 🤔

Otherwise it looks fine to me! Still could use some tests 😉

example/bundle.js Outdated Show resolved Hide resolved
@Souvikns
Copy link
Member Author

I have added an option, so now to resolve external messages references into components the users can just pass in a flag otherwise it works as usual. I have also updated the readme, I think I am ready for review 🤞🏼.

jonaslagoni
jonaslagoni previously approved these changes Aug 17, 2022
Copy link
Sponsor Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

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

Just a few comments, but LGTM 👍

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
jonaslagoni
jonaslagoni previously approved these changes Sep 12, 2022
@Souvikns
Copy link
Member Author

Need approval from @derberg to merge

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

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

only small typo to fix

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@aeworxet
Copy link
Collaborator

const fs = requrie('fs')
https://github.com/asyncapi/bundler/pull/46/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R245

because users will most probably copypaste it.

@Souvikns
Copy link
Member Author

because users will most probably copypaste it.

Shall I remove it, if people are going to copy/paste won't having the import help?

@aeworxet
Copy link
Collaborator

because users will most probably copypaste it.

Shall I remove it, if people are going to copy/paste won't having the import help?

No, it simply is a one more typo.

- const fs = requrie('fs')
+ const fs = require('fs')

I meant that users will most probably copypaste it, and copypaste it with the error it contains.

Also, there are typos here:

const bundle = requrie('@asyncapi/bundler');
const path = requrie('path');

It might be a good idea to go through all PR proofreading it.

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

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

LGTM, merge when you want

@Souvikns
Copy link
Member Author

/rtm

@asyncapi-bot asyncapi-bot merged commit e73b9b9 into asyncapi:master Sep 12, 2022
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 0.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bundle references into components
5 participants