posthtml-expressions icon indicating copy to clipboard operation
posthtml-expressions copied to clipboard

Refactor to ESM

Open cossssmin opened this issue 1 year ago • 10 comments

@Scrum I'd like to work on a new major release for posthtml-expressions that would include:

  • refactoring code to ESM-only
  • require Node.js 18+
  • migrate tests to use Vitest
  • switch style linting to eslint
  • add type definitions

Please let me know if you're OK with this and I'll start work on the PR. Thanks!

cossssmin avatar Feb 29 '24 14:02 cossssmin

@cossssmin I'm glad you can do it, thank you!

Scrum avatar Feb 29 '24 14:02 Scrum

Thanks, will get started and let you know when it's ready for review.

Did you have any plans for it? We could add them in this refactor.

cossssmin avatar Feb 29 '24 14:02 cossssmin

Did you have any plans for it? We could add them in this refactor.

There were a couple of ideas:

  • use tsup or vitejs as a collector,
  • use the general prettier rules,
  • use the general rules for typescript,
  • general rules for vscode/idea,
  • configure ci/cd (install, test, optional build, publish by tag or after the merge),
  • consider turborepo

Scrum avatar Mar 01 '24 07:03 Scrum

OK, I'd start on it and when I'm done you could add those maybe? Or do you prefer we launch a major version first and then add those ideas?

cossssmin avatar Mar 01 '24 10:03 cossssmin

OK, I'd start on it and when I'm done you could add those maybe? Or do you prefer we launch a major version first and then add those ideas?

Rather, as you prefer, these are the best ideas)

Scrum avatar Mar 01 '24 10:03 Scrum

Could we take this opportunity to think about what options we have for replacing node:vm so that the plugin could be used in a browser environment? Would Function work?

This would be a game-changer for frameworks like Maizzle, you could run the entire PostHTML build chain right in the browser, no serverless/Lambdas needed.

cossssmin avatar Mar 07 '24 09:03 cossssmin

It is necessary to explore this direction, in the first approximation it looks like vm-browserify

Scrum avatar Mar 18 '24 07:03 Scrum

I was looking at the Alpine.js evaluator the other day, maybe something like this would be enough?

https://github.com/alpinejs/alpine/blob/main/packages/alpinejs/src/evaluator.js

Didn't know about vm-browserify, looks like it's very popular but it's only for the browser and it creates an <iframe> for each code execution which leads to other issues like web workers not working.

cossssmin avatar Mar 18 '24 08:03 cossssmin

This also looks interesting, it uses @babel/parser to parse expressions:

https://github.com/william-yz/ts-expression-evaluator

cossssmin avatar Mar 18 '24 08:03 cossssmin

Another idea would be to create an interface and allow for various templating engine adapters. For example, there's LiquidJS that people could use instead of the default engine.

cossssmin avatar Mar 22 '24 07:03 cossssmin