8000 feat: convert PostHTML to TypeScript and Es Modules by aminya · Pull Request #396 · posthtml/posthtml · GitHub
[go: up one dir, main page]

Skip to content

feat: convert PostHTML to TypeScript and Es Modules #396

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

aminya
Copy link
@aminya aminya commented Oct 16, 2023

PostHTML has been converted to TypeScript. The available types were added to the functions themselves and the typing errors are fixed in the code. The tests use the compiled code.

This also modernizes PostHTML to use the standard Es Modules while preserving backward compatibility with CommonJS (achieved via Babel). I added EsLint rules to prevent incorrect usage of Es modules. The modernization helps the adoption of posthtml in newer tools.

All the tests pass (including the Commonjs backward compatibility test)

image

@Scrum
Copy link
Member
Scrum commented Oct 17, 2023

Thank you for the great work done, but unfortunately we are now systematically migrating to TS

@aminya
Copy link
Author
aminya commented Oct 17, 2023

You're welcome! That's great. This PR should put you on the right track. The ESM changes are idiomatic TypeScript.

Also, if you want to be backward compatible, you would need to use the Babel compilation I added here on top of TypeScript. Since via TypeScript, you cannot directly generate both pure mjs and cjs builds. You would need the Babel plugin for import extensions and the addition of module.exports.

@Scrum
Copy link
Member
Scrum commented Oct 17, 2023

There is a wonderful tool tsup

@aminya
Copy link
Author
aminya commented Oct 17, 2023

That's an interesting tool. Yeah, bundling bypasses parts of backward compatibility, but it doesn't allow you to run your unit tests in pure ESM. You would still need the proper ESM usage I added here.

I'll update this PR to convert the library to TypeScript.

@aminya aminya changed the title feat: convert PostHTML to Es Modules feat: convert PostHTML to TypeScript and Es Modules Oct 19, 2023
@aminya
Copy link
Author
aminya commented Oct 19, 2023

@Scrum Converted the code to TypeScript. 🚀

I kept the conversion in the same branch, but if you prefer to first support ES modules, I can move TypeScript conversion to a new pull request.

All the tests still pass after this even the Commonjs backwards compatibility would work in the oldest Node versions without any modification.

@Scrum
Copy link
Member
Scrum commented Oct 20, 2023

@aminya use a posthtml@0.16.7-beta.0 it should suit your needs. Let me know if something doesn't work right. Thank you.

@aminya
Copy link
Author
aminya commented Oct 20, 2023

@Scrum How's that related to this pull request?

@Scrum
Copy link
Member
Scrum commented Oct 20, 2023

it provides the ability to include modules like cjs mjs like your pr. I made a separate branch from the branch where I am currently working on rewriting the project and it will be more convenient for me to merge them with my pr in the future.

@aminya
Copy link
Author
aminya commented Oct 21, 2023

Sorry, I could not find the source for this, and I prefer not to use a closed-source build. I don't actually need these changes. I am just trying to help the project as it looked like open-source. If this is not the case, let me know. I can channel my contributions to other projects.

Also, in the build you sent, the types for the project have regressed compared to previous versions unlike my branch.

@Scrum
Copy link
Member
Scrum commented Oct 21, 2023

we appreciate your input, thank you, unfortunately, as I wrote earlier, I already had developments in this direction. thank you anyway.

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
0