Skip to content

Commit a466440

Browse files
committed
feat: support ESM, fixes #95
1 parent 1e7071a commit a466440

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
"test:dist:esm": "TEST_DIST=esm node --experimental-vm-modules node_modules/.bin/jest",
6565
"benchmark": "tsx benchmark/benchmark",
6666
"lint": "eslint src/**.ts",
67-
"flow-type-gen": "flowgen --add-flow-header dist/commonjs/index.d.ts -o dist/commonjs/index.js.flow && flowgen --add-flow-header dist/esm/index.d.ts -o dist/esm/index.js.flow",
67+
"flow-type-gen": "flowgen --add-flow-header dist/esm/index.d.ts -o dist/commonjs/index.js.flow",
6868
"remove-unused-declarations": "find dist -type f \\( -name '*.d.ts' ! -name index.d.ts \\) | xargs rm",
69-
"build": "rm -Rf dist && tsc --noEmit && tshy && npm run remove-unused-declarations && npm run flow-type-gen",
69+
"build": "rm -Rf dist && tsc --noEmit && tshy && tsc --declaration --emitDeclarationOnly -p tsconfig.json && tsc --emitDeclarationOnly -p tsconfig.esm.json && npm run remove-unused-declarations && npm run flow-type-gen",
7070
"prepublishOnly": "npm run build && npm run test && npm run test:dist",
7171
"release": "standard-version"
7272
},

test/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ describe('lib', () => {
5050
});
5151
it('should check integration app/package of the type', async () => {
5252
const appPath = `test/test-apps/${process.env.TEST_DIST}`;
53-
if (process.env.TEST_DIST === 'esm') {
54-
await ensureSelfLink(appPath);
55-
}
53+
await ensureSelfLink(appPath);
5654
await exec(`node ${path.join(appPath, 'test.js')}`);
5755
});
5856
});

test/test-apps/commonjs/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-require-imports */
2-
const {encode, decode, decodeEntity} = require('../../..');
32
const assert = require('node:assert');
3+
const {encode, decode, decodeEntity} = require('html-entities');
44

55
assert.equal('&lt;&gt;&amp;&quot;&apos;', encode('<>&"\''));
66
assert.equal('<>&"\'', decode('&lt;&gt;&amp;&quot;&apos;'));

tsconfig.esm.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"compilerOptions": {
44
"module": "esnext",
55
"target": "esnext",
6-
}
6+
"declaration": true,
7+
"skipLibCheck": true,
8+
"outDir": "./dist/esm"
9+
},
710
}

tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
"compilerOptions": {
33
"target": "es5",
44
"module": "commonjs",
5-
"declaration": true,
6-
"outDir": "./dist",
5+
"outDir": "./dist/commonjs",
76
"strict": true,
8-
"resolveJsonModule": true,
97
"sourceMap": true
108
},
119
"include": ["src"],

0 commit comments

Comments
 (0)