Skip to content

Commit 1a5e2a7

Browse files
committed
fix!: export bundled ESM (#816)
1 parent e9635f6 commit 1a5e2a7

10 files changed

+41
-40
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/coverage
2+
/dist
3+
/node_modules

build.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
;(async () => {
2+
const child = require('child_process')
3+
const fs = require('fs')
4+
const {build} = require('esbuild')
5+
6+
await build({
7+
outdir: 'dist',
8+
format: 'esm',
9+
target: 'es6',
10+
bundle: true,
11+
external: ['@testing-library/dom'],
12+
entryPoints: ['src/index.ts'],
13+
})
14+
15+
fs.writeFileSync(
16+
'dist/package.json',
17+
JSON.stringify({
18+
type: 'module',
19+
}),
20+
)
21+
22+
child.execSync('yarn tsc -p tsconfig.build.json')
23+
})()

package.json

+5-29
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "@testing-library/user-event",
33
"version": "0.0.0-semantically-released",
44
"description": "Fire events the same way the user does",
5-
"main": "dist/index.js",
65
"keywords": [
76
"react-testing-library",
87
"dom-testing-library",
@@ -26,8 +25,10 @@
2625
"files": [
2726
"dist"
2827
],
28+
"main": "./dist/index.js",
29+
"exports": "./dist/index.js",
2930
"scripts": {
30-
"build": "kcd-scripts build --no-ts-defs && tsc -p tsconfig.build.json",
31+
"build": "node build.js",
3132
"lint": "kcd-scripts lint",
3233
"setup": "npm install && npm run validate -s",
3334
"test": "kcd-scripts test",
@@ -46,6 +47,7 @@
4647
"@types/estree": "0.0.45",
4748
"@types/jest-in-case": "^1.0.3",
4849
"@types/react": "^17.0.3",
50+
"esbuild": "^0.14.9",
4951
"eslint-import-resolver-typescript": "^2.5.0",
5052
"is-ci": "^2.0.0",
5153
"jest-in-case": "^1.0.2",
@@ -57,31 +59,5 @@
5759
},
5860
"peerDependencies": {
5961
"@testing-library/dom": ">=7.21.4"
60-
},
61-
"eslintConfig": {
62-
"extends": "./node_modules/kcd-scripts/eslint.js",
63-
"rules": {
64-
"jsx-a11y/click-events-have-key-events": "off",
65-
"jsx-a11y/tabindex-no-positive": "off",
66-
"no-func-assign": "off",
67-
"no-return-assign": "off",
68-
"react/prop-types": "off",
69-
"testing-library/no-dom-import": "off"
70-
},
71-
"overrides": [
72-
{
73-
"files": [
74-
"**/__tests__/**"
75-
],
76-
"rules": {
77-
"no-console": "off"
78-
}
79-
}
80-
]
81-
},
82-
"eslintIgnore": [
83-
"node_modules",
84-
"coverage",
85-
"dist"
86-
]
62+
}
8763
}

src/utils/dataTransfer/Clipboard.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,11 @@ export async function writeDataTransferToClipboard(
184184
}
185185

186186
/* istanbul ignore else */
187-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
188-
if (afterEach) {
187+
if (typeof afterEach === 'function') {
189188
afterEach(() => resetClipboardStubOnView(window))
190189
}
191190

192191
/* istanbul ignore else */
193-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
194-
if (afterAll) {
192+
if (typeof afterAll === 'function') {
195193
afterAll(() => detachClipboardStubFromView(window))
196194
}

src/utils/misc/dom-helpers.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
declare module '@testing-library/dom/dist/helpers' {
1+
declare module '@testing-library/dom/dist/helpers.js' {
22
export function getWindowFromNode(node: Node): Window
33
}

src/utils/misc/hasPointerEvents.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getWindowFromNode} from '@testing-library/dom/dist/helpers'
1+
import {getWindowFromNode} from '@testing-library/dom/dist/helpers.js'
22

33
/**
44
* Options that can be passed to any event that relies

src/utils/misc/isVisible.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getWindowFromNode} from '@testing-library/dom/dist/helpers'
1+
import {getWindowFromNode} from '@testing-library/dom/dist/helpers.js'
22

33
export function isVisible(element: Element): boolean {
44
const window = getWindowFromNode(element)

src/utils/pointer/dom-events.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
declare module '@testing-library/dom/dist/event-map' {
1+
declare module '@testing-library/dom/dist/event-map.js' {
22
export const eventMap: Record<string, unknown>
33
}

src/utils/pointer/firePointerEvents.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createEvent, fireEvent} from '@testing-library/dom'
2-
import {eventMap} from '@testing-library/dom/dist/event-map'
2+
import {eventMap} from '@testing-library/dom/dist/event-map.js'
33
import type {pointerState} from '../../pointer/types'
44
import type {keyboardState} from '../../keyboard/types'
55
import {getMouseButton, getMouseButtons, MouseButton} from './mouseButtons'

tsconfig.build.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"extends": "./tsconfig.json",
33
"include": ["./src"],
44
"compilerOptions": {
5-
"outDir": "dist",
5+
"outFile": "dist/index.d.ts",
66
"noEmit": false,
77
"declaration": true,
8-
"emitDeclarationOnly": true
8+
"emitDeclarationOnly": true,
9+
"isolatedModules": false
910
}
1011
}

0 commit comments

Comments
 (0)