Skip to content

Commit 61d17bd

Browse files
authored
chore: Publish ESM and CJS (#519)
* Add rollup config * Sort dependencies in package.json * Clean output folder before build * Use relative paths for entries * Convert cjs to esm if needed * Add extensions to lodash imports To support node16 resolution * Ignore coverage for vitest and jest-globals
1 parent bdb34f1 commit 61d17bd

7 files changed

+100
-9
lines changed

package.json

+52-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,59 @@
22
"name": "@testing-library/jest-dom",
33
"version": "0.0.0-semantically-released",
44
"description": "Custom jest matchers to test the state of the DOM",
5-
"main": "dist/index.js",
5+
"main": "dist/cjs/index.js",
6+
"module": "dist/esm/index.js",
7+
"exports": {
8+
".": {
9+
"require": {
10+
"types": "./types/index.d.ts",
11+
"default": "./dist/index.js"
12+
},
13+
"import": {
14+
"types": "./types/index.d.ts",
15+
"default": "./dist/index.mjs"
16+
}
17+
},
18+
"./jest-globals": {
19+
"require": {
20+
"types": "./types/jest-globals.d.ts",
21+
"default": "./dist/jest-globals.js"
22+
},
23+
"import": {
24+
"types": "./types/jest-globals.d.ts",
25+
"default": "./dist/jest-globals.mjs"
26+
}
27+
},
28+
"./matchers": {
29+
"require": {
30+
"types": "./types/matchers.d.ts",
31+
"default": "./dist/matchers.js"
32+
},
33+
"import": {
34+
"types": "./types/matchers.d.ts",
35+
"default": "./dist/matchers.mjs"
36+
}
37+
},
38+
"./vitest": {
39+
"require": {
40+
"types": "./types/vitest.d.ts",
41+
"default": "./dist/vitest.js"
42+
},
43+
"import": {
44+
"types": "./types/vitest.d.ts",
45+
"default": "./dist/vitest.mjs"
46+
}
47+
},
48+
"./package.json": "./package.json"
49+
},
650
"types": "types/index.d.ts",
751
"engines": {
852
"node": ">=14",
953
"npm": ">=6",
1054
"yarn": ">=1"
1155
},
1256
"scripts": {
13-
"build": "kcd-scripts build",
57+
"build": "rollup -c",
1458
"format": "kcd-scripts format",
1559
"lint": "kcd-scripts lint",
1660
"setup": "npm install && npm run validate -s",
@@ -36,25 +80,28 @@
3680
"author": "Ernesto Garcia <[email protected]> (http://gnapse.github.io)",
3781
"license": "MIT",
3882
"dependencies": {
83+
"@adobe/css-tools": "^4.0.1",
3984
"@babel/runtime": "^7.9.2",
4085
"aria-query": "^5.0.0",
4186
"chalk": "^3.0.0",
42-
"@adobe/css-tools": "^4.0.1",
4387
"css.escape": "^1.5.1",
4488
"dom-accessibility-api": "^0.5.6",
4589
"lodash": "^4.17.15",
4690
"redent": "^3.0.0"
4791
},
4892
"devDependencies": {
4993
"@jest/globals": "^29.6.2",
94+
"@rollup/plugin-commonjs": "^25.0.4",
5095
"expect": "^29.6.2",
5196
"jest-environment-jsdom-sixteen": "^1.0.3",
5297
"jest-watch-select-projects": "^2.0.0",
5398
"jsdom": "^16.2.1",
5499
"kcd-scripts": "^14.0.0",
55100
"pretty-format": "^25.1.0",
56-
"vitest": "^0.34.1",
57-
"typescript": "^5.1.6"
101+
"rollup": "^3.28.1",
102+
"rollup-plugin-delete": "^2.0.0",
103+
"typescript": "^5.1.6",
104+
"vitest": "^0.34.1"
58105
},
59106
"peerDependencies": {
60107
"@jest/globals": ">= 28",

rollup.config.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const del = require('rollup-plugin-delete')
2+
const commonjs = require('@rollup/plugin-commonjs')
3+
4+
const entries = [
5+
'./src/index.js',
6+
'./src/jest-globals.js',
7+
'./src/matchers.js',
8+
'./src/vitest.js',
9+
]
10+
11+
module.exports = [
12+
{
13+
input: entries,
14+
output: [
15+
{
16+
dir: 'dist',
17+
entryFileNames: '[name].mjs',
18+
chunkFileNames: '[name]-[hash].mjs',
19+
format: 'esm',
20+
},
21+
{
22+
dir: 'dist',
23+
entryFileNames: '[name].js',
24+
chunkFileNames: '[name]-[hash].js',
25+
format: 'cjs',
26+
},
27+
],
28+
external: id =>
29+
!id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/'),
30+
plugins: [del({targets: 'dist/*'}), commonjs()],
31+
},
32+
]

src/jest-globals.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* istanbul ignore file */
2+
3+
import globals from '@jest/globals'
4+
import * as extensions from './matchers'
5+
6+
globals.expect.extend(extensions)

src/to-have-form-values.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import isEqualWith from 'lodash/isEqualWith'
2-
import uniq from 'lodash/uniq'
1+
import isEqualWith from 'lodash/isEqualWith.js'
2+
import uniq from 'lodash/uniq.js'
33
import escape from 'css.escape'
44
import {
55
checkHtmlElement,

src/to-have-value.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import isEqualWith from 'lodash/isEqualWith'
1+
import isEqualWith from 'lodash/isEqualWith.js'
22
import {
33
checkHtmlElement,
44
compareArraysAsSet,

src/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import redent from 'redent'
2-
import isEqual from 'lodash/isEqual'
2+
import isEqual from 'lodash/isEqual.js'
33
import {parse} from '@adobe/css-tools'
44

55
class GenericTypeError extends Error {

src/vitest.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* istanbul ignore file */
2+
3+
import {expect} from 'vitest'
4+
import * as extensions from './matchers'
5+
6+
expect.extend(extensions)

0 commit comments

Comments
 (0)