Skip to content

Commit 452e1b3

Browse files
authored
Merge pull request #164 from vikerman/master
Support node v13 with es modules
2 parents ae45408 + f4bec0a commit 452e1b3

File tree

5 files changed

+74
-11
lines changed

5 files changed

+74
-11
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10+
# Change the condition for ESM Dist Test below when changing this.
1011
node-version: [10.x, 12.x, 14.x]
1112
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v2
14-
- name: Use Node.js ${{ matrix.node-version }}
15-
uses: actions/setup-node@v1
16-
with:
17-
node-version: ${{ matrix.node-version }}
18-
- name: Install
19-
run: npm install
20-
- name: Build and Test
21-
run: npm test
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- name: Install
20+
run: npm install
21+
- name: Build and Test
22+
run: npm test
23+
- if: matrix.node-version == '14.x'
24+
name: ESM Dist Test
25+
run: npm run test:dist

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ package-lock.json
55
dist
66
mini
77
yarn.lock
8+
htm.tgz

package.json

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,39 @@
66
"umd:main": "dist/htm.umd.js",
77
"module": "dist/htm.module.js",
88
"types": "dist/htm.d.ts",
9+
"exports": {
10+
".": {
11+
"import": "./dist/htm.mjs",
12+
"require": "./dist/htm.js",
13+
"browser": "./dist/htm.module.js",
14+
"umd": "./dist/htm.umd.js"
15+
},
16+
"./": "./",
17+
"./preact": {
18+
"import": "./preact/index.mjs",
19+
"require": "./preact/index.js",
20+
"browser": "./preact/index.module.js",
21+
"umd": "./preact/index.umd.js"
22+
},
23+
"./preact/standalone": {
24+
"import": "./preact/standalone.mjs",
25+
"require": "./preact/standalone.js",
26+
"browser": "./preact/standalone.module.js",
27+
"umd": "./preact/standalone.umd.js"
28+
},
29+
"./react": {
30+
"import": "./react/index.mjs",
31+
"require": "./react/index.js",
32+
"browser": "./react/index.module.js",
33+
"umd": "./react/index.umd.js"
34+
},
35+
"./mini": {
36+
"import": "./mini/index.mjs",
37+
"require": "./mini/index.js",
38+
"browser": "./mini/index.module.js",
39+
"umd": "./mini/index.umd.js"
40+
}
41+
},
942
"scripts": {
1043
"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",
1144
"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",
@@ -15,8 +48,9 @@
1548
"build:babel": "cd packages/babel-plugin-htm && npm run build",
1649
"build:babel-transform-jsx": "cd packages/babel-plugin-transform-jsx-to-htm && npm run build",
1750
"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",
18-
"test": "eslint src/**/*.mjs test/**/*.mjs && npm run build && jest test",
51+
"test": "eslint src/**/*.mjs test/**/*.mjs --ignore-path .gitignore && npm run build && jest test",
1952
"test:perf": "v8 test/__perftest.mjs",
53+
"test:dist": "npm pack && mv htm*.tgz test/fixtures/esm/htm.tgz && cd test/fixtures/esm && npm install && node index.js",
2054
"release": "npm t && git commit -am \"$npm_package_version\" && git tag $npm_package_version && git push && git push --tags && npm publish"
2155
},
2256
"files": [

test/fixtures/esm/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import assert from 'assert';
2+
import htm from 'htm';
3+
import * as preact from 'htm/preact';
4+
import * as standalone from 'htm/preact/standalone';
5+
// TODO: Enable once react distro is ESM compatible.
6+
// import * as react 'htm/react';
7+
8+
assert(typeof htm === 'function', 'import htm from "htm"');
9+
10+
assert(typeof preact.html === 'function', 'import { html } from "preact"');
11+
12+
assert(typeof standalone.html === 'function', 'import { html } from "preact/standalone"');
13+
14+
console.log('✅ Dist Tests Passed');

test/fixtures/esm/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "htm_dist_test",
3+
"type": "module",
4+
"private": true,
5+
"description": "A package to test importing htm as ES modules in Node",
6+
"dependencies": {
7+
"htm": "file:htm.tgz",
8+
"preact": "^10.4.1"
9+
}
10+
}

0 commit comments

Comments
 (0)