Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# Change the condition for ESM Dist Test below when changing this.
node-version: [10.x, 12.x, 14.x]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm install
- name: Build and Test
run: npm test
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm install
- name: Build and Test
run: npm test
- if: matrix.node-version == '14.x'
name: ESM Dist Test
run: npm run test:dist
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ package-lock.json
dist
mini
yarn.lock
htm.tgz
36 changes: 35 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@
"umd:main": "dist/htm.umd.js",
"module": "dist/htm.module.js",
"types": "dist/htm.d.ts",
"exports": {
".": {
"import": "./dist/htm.mjs",
"require": "./dist/htm.js",
"browser": "./dist/htm.module.js",
"umd": "./dist/htm.umd.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a good opportunity to consider dropping umd for the export map? Or perhaps in a separate PR.

I'm not sure I see the value in specifying a umd format output in export maps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just following the pattern from the main preact repo. I can do the change if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I think this is a good followup item to consider. Not blocking for this PR.

Thanks for doing the work!

},
"./": "./",
"./preact": {
"import": "./preact/index.mjs",
"require": "./preact/index.js",
"browser": "./preact/index.module.js",
"umd": "./preact/index.umd.js"
},
"./preact/standalone": {
"import": "./preact/standalone.mjs",
"require": "./preact/standalone.js",
"browser": "./preact/standalone.module.js",
"umd": "./preact/standalone.umd.js"
},
"./react": {
"import": "./react/index.mjs",
"require": "./react/index.js",
"browser": "./react/index.module.js",
"umd": "./react/index.umd.js"
},
"./mini": {
"import": "./mini/index.mjs",
"require": "./mini/index.js",
"browser": "./mini/index.module.js",
"umd": "./mini/index.umd.js"
}
},
"scripts": {
"build": "npm run -s build:main && npm run -s build:mini && npm run -s build:preact && npm run -s build:react && npm run -s build:babel && npm run -s build:babel-transform-jsx && npm run -s build:mjsalias",
"build:main": "microbundle src/index.mjs -f es,umd --no-sourcemap --target web && microbundle src/cjs.mjs -f iife --no-sourcemap --target web && cp src/index.d.ts dist/htm.d.ts",
Expand All @@ -15,8 +48,9 @@
"build:babel": "cd packages/babel-plugin-htm && npm run build",
"build:babel-transform-jsx": "cd packages/babel-plugin-transform-jsx-to-htm && npm run build",
"build:mjsalias": "cp dist/htm.module.js dist/htm.mjs && cp mini/index.module.js mini/index.mjs && cp preact/index.module.js preact/index.mjs && cp preact/standalone.module.js preact/standalone.mjs && cp react/index.module.js react/index.mjs",
"test": "eslint src/**/*.mjs test/**/*.mjs && npm run build && jest test",
"test": "eslint src/**/*.mjs test/**/*.mjs --ignore-path .gitignore && npm run build && jest test",
"test:perf": "v8 test/__perftest.mjs",
"test:dist": "npm pack && mv htm*.tgz test/fixtures/esm/htm.tgz && cd test/fixtures/esm && npm install && node index.js",
"release": "npm t && git commit -am \"$npm_package_version\" && git tag $npm_package_version && git push && git push --tags && npm publish"
},
"files": [
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/esm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import assert from 'assert';
import htm from 'htm';
import * as preact from 'htm/preact';
import * as standalone from 'htm/preact/standalone';
// TODO: Enable once react distro is ESM compatible.
// import * as react 'htm/react';

assert(typeof htm === 'function', 'import htm from "htm"');

assert(typeof preact.html === 'function', 'import { html } from "preact"');

assert(typeof standalone.html === 'function', 'import { html } from "preact/standalone"');

console.log('✅ Dist Tests Passed');
10 changes: 10 additions & 0 deletions test/fixtures/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "htm_dist_test",
"type": "module",
"private": true,
"description": "A package to test importing htm as ES modules in Node",
"dependencies": {
"htm": "file:htm.tgz",
"preact": "^10.4.1"
}
}