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

refactor: Improve exports & require statements #233

Merged

Conversation

brodybits
Copy link
Member

@brodybits brodybits commented May 9, 2021

by creating a proper main entry file lib/index.js.
NOTE that the following exports have been deprecated in lib/dom-parser.js and will be removed in the next minor release:

  • DOMImplementation
  • XMLSerializer

Copy link
Member

@karfau karfau left a comment

Choose a reason for hiding this comment

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

My understanding of what this change is good for is very limited. Maybe you can elaborate on the problem this solves in the PR description or add a link to something that explains it?

From what I know, such a file can be used to declare the "public API" from the "internal" exports of other modules.
But if that is the goal, I don't really understand why (all) the tests should go through the public API.
We never discussed what thing should be considered "public" and which not. Which is relevant for me when we need to resolve conflicts with the PRs that add exports to some modules in lib.

@karfau
Copy link
Member

karfau commented May 11, 2021

BREAKING CHANGE due to exports removed from lib/dom-parser.js

Just thinking out loud:
Since lib/dom-parser.js was the main entry point when importing/requiring xmldom can we assume that nobody would write xmldom/lib/dom-parser instead?
If that is the case, since all the exports that previously existed an the main entry point also exist on the new one, this is not a breaking change? (Or did I miss something?)
I also think when doing breaking changes we should be more explicit by listing the exports that have been removed.

@karfau karfau added breaking change Some thing that requires a version bump due to breaking changes question Contains open questions that need to be answered labels Aug 21, 2021
@karfau
Copy link
Member

karfau commented Aug 21, 2021

@brodybits
&TLDR; I would love to land this asap, but as long as it's a breaking change, it's not that easy.

  1. Can you please reply to my question?
  2. could you either rebase this branch and resolve the conflicts or push the branch to the xmldom repo, so it's easier for me to continue working on it?

Thx

@karfau karfau linked an issue Aug 21, 2021 that may be closed by this pull request
@brodybits
Copy link
Member Author

brodybits commented Aug 24, 2021

Since lib/dom-parser.js was the main entry point when importing/requiring xmldom can we assume that nobody would write xmldom/lib/dom-parser instead?

probably yes

I also think when doing breaking changes we should be more explicit by listing the exports that have been removed.

Done in the now updated description (it was just XMLSerializer).

Yeah I don't think this would likely break any very many real users, definitely should not be in a patch release though.

2. could you either rebase this branch and resolve the conflicts or [...]

I will resolve merge and/or rebase to resolve the conflicts.

In terms of coding it would probably be easier to start this over. But merge & rebase is better for the PR flow. Coming up.


P.S. Multiple exports were removed, one was behind a var declaration.

@brodybits brodybits force-pushed the improve-exports-and-require-statements branch from 9c73dc2 to d52da16 Compare August 24, 2021 19:28
@karfau
Copy link
Member

karfau commented Aug 24, 2021

The exports that you listed have been removed from lib/dom-parser.js which was the main enrty point, but that are still present on the main entry point, right?

I would argue that importing things from @xmldom/xmldom/lib/dom-parser (instead of just @xmldom/xmldom) should not be considered part of the "public API", so I wouldn't consider it a breaking change.

And if we can not agree on that, we could make it non breaking for now by restoring those exports and marking them as @deprecated, so people can become aware and we can land it and release it as a patch version, and only remove them in a future PR.

What do you think?

@brodybits brodybits removed question Contains open questions that need to be answered breaking change Some thing that requires a version bump due to breaking changes labels Aug 24, 2021
@brodybits brodybits marked this pull request as draft August 24, 2021 20:14
Co-authored-by: Christian Bewernitz <coder@karfau.de>
@karfau karfau changed the title refactor: improve exports and require statements refactor: Improve exports and require statements Aug 24, 2021
Co-authored-by: Christian Bewernitz <coder@karfau.de>
@karfau karfau added this to the next release milestone Aug 24, 2021
Co-authored-by: Christian Bewernitz <coder@karfau.de>
/**
* @deprecated Import/require from main entry point instead
*/
exports.XMLSerializer = dom.XMLSerializer;
exports.DOMParser = DOMParser;
exports.__DOMHandler = DOMHandler;
Copy link
Member Author

Choose a reason for hiding this comment

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

@karfau this PR made me start to wonder why we are exporting DOMHandler with __ prefix. I recall there was some reason for this when we made the security update for 0.5.0 but embarrassed I do not recall exactly. Can you help me understand this again?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, it was my primitive way to indicate a "private API" and to be able to use it in tests.

Now that we have a clear separation of public (lib/index.js) and private (all other modules) API, we could drop the __ and just export/require DOMHandler.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah !!

I am thinking that if we drop the __ here, it could be easy for a reader to confuse between what is exported internally (for internal testing) and what is to be exported externally.

I am also thinking it would be ideal if we could find a way to make the pluggable DOMHandler usable from the external API somehow.

There are some (myself included) who think that test mocking is a kind of code smell: https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70c90a6a

I would like to propose that we just leave it for now and revisit someday later.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with that.
I think mocking needs to be applied with much care, which I hope I did, to avoid brittle and unmaintainable tests.
But of course I'm open to suggestions on how to test those things in a different way.

@karfau
Copy link
Member

karfau commented Aug 24, 2021

I assume you will mark it as ready for review and land it when you are ready :)

@brodybits brodybits self-assigned this Aug 24, 2021
@brodybits brodybits marked this pull request as ready for review August 24, 2021 20:27
@brodybits brodybits changed the title refactor: Improve exports and require statements refactor: Improve exports & require statements Aug 24, 2021
@brodybits
Copy link
Member Author

@karfau can you take one last look at the exports before I merge this?

Copy link
Member

@karfau karfau left a comment

Choose a reason for hiding this comment

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

Perfect, let's merge this!

@brodybits brodybits merged commit dc429ae into xmldom:master Aug 24, 2021
@brodybits brodybits deleted the improve-exports-and-require-statements branch August 24, 2021 20:46
@brodybits
Copy link
Member Author

@karfau I accidentally removed you from co-author credit when I merged this, my apologies. I don't know if there is anything we can do about this in git. Argh!!

@karfau
Copy link
Member

karfau commented Aug 24, 2021

@brodybits 😆 no problem, you did the main work and I have more than enough credit(s?) in this project

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.

None yet

2 participants