-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
base: master
Are you sure you want to change the base?
Conversation
Thank you for the great work done, but unfortunately we are now systematically migrating to TS |
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 |
There is a wonderful tool tsup |
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. |
@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. |
@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. |
@Scrum How's that related to this pull request? |
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. |
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. |
we appreciate your input, thank you, unfortunately, as I wrote earlier, I already had developments in this direction. thank you anyway. |
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)