developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.67k stars 170 forks source link

Support node v13 with es modules #164

Closed vikerman closed 4 years ago

vikerman commented 4 years ago

Creates conditional export that points "import" conditional exports to mjs files. This lets node load the esm version without having to set "type": "module" on the main package.json.

This is similar to the approach in the main preact repo - https://github.com/preactjs/preact/pull/2451

jkrems commented 4 years ago

One note of caution is that this is a breaking change: People who currently require or import ./dist/ paths directly would no longer be able to. This can be softened by adding an export of “./“.

Excited to see this added to htm!

vikerman commented 4 years ago

Looks like the node version changed and the test is failing because npm cache has older version of compiled iltorb. Clearing the npm cache in Travis could help

developit commented 4 years ago

@vikerman - just switched to Actions, hopefully that addresses it.

developit commented 4 years ago

Everything looks good. I'm wondering if there's a way to test this though. Something like:

{
  "scripts": {
    "test:dist": "npm pack && mv htm*.tgz test/fixtures/dist/htm.tgz && cd test/fixtures/dist && node ."
  }
}

... where dist/ would be:

// package.json
{ "dependencies": {"htm": "file:htm.tgz" } }
// index.mjs
import 'htm';
import 'htm/preact';
import 'htm/preact/standalone';
import 'htm/react';
vikerman commented 4 years ago

Added the test. It's not hooked up to CI though. Would work for node versions >=13. [Edit: It's hooked up to the CI now]

vikerman commented 4 years ago

Hooked up the ESM dist test to CI when node version is 14.x.

developit commented 4 years ago

Wow, thanks @vikerman that is absolutely perfect!