Skip to content

refactor: Improve exports & require statements#233

Merged
brody2consult merged 17 commits into
xmldom:masterfrom
brody2consult:improve-exports-and-require-statements
Aug 24, 2021
Merged

refactor: Improve exports & require statements#233
brody2consult merged 17 commits into
xmldom:masterfrom
brody2consult:improve-exports-and-require-statements

Conversation

@brody2consult

@brody2consult brody2consult commented May 9, 2021

Copy link
Copy Markdown
Member

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

@karfau karfau left a comment

Copy link
Copy Markdown
Member

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

karfau commented May 11, 2021

Copy link
Copy Markdown
Member

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

karfau commented Aug 21, 2021

Copy link
Copy Markdown
Member

@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
@brody2consult

brody2consult commented Aug 24, 2021

Copy link
Copy Markdown
Member Author

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.

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

karfau commented Aug 24, 2021

Copy link
Copy Markdown
Member

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?

@brody2consult brody2consult 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
@brody2consult brody2consult marked this pull request as draft August 24, 2021 20:14
Co-authored-by: Christian Bewernitz <[email protected]>
@karfau karfau changed the title refactor: improve exports and require statements refactor: Improve exports and require statements Aug 24, 2021
@karfau karfau added this to the next release milestone Aug 24, 2021
Comment thread lib/dom-parser.js Outdated
*/
exports.XMLSerializer = dom.XMLSerializer;
exports.DOMParser = DOMParser;
exports.__DOMHandler = DOMHandler;

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

karfau commented Aug 24, 2021

Copy link
Copy Markdown
Member

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

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

Copy link
Copy Markdown
Member Author

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

@karfau karfau left a comment

Copy link
Copy Markdown
Member

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!

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

Copy link
Copy Markdown
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

karfau commented Aug 24, 2021

Copy link
Copy Markdown
Member

@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.

2 participants