diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..ae409af0 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +/coverage +/dist +/node_modules diff --git a/build.js b/build.js new file mode 100644 index 00000000..92f03a40 --- /dev/null +++ b/build.js @@ -0,0 +1,23 @@ +;(async () => { + const child = require('child_process') + const fs = require('fs') + const {build} = require('esbuild') + + await build({ + outdir: 'dist', + format: 'esm', + target: 'es6', + bundle: true, + external: ['@testing-library/dom'], + entryPoints: ['src/index.ts'], + }) + + fs.writeFileSync( + 'dist/package.json', + JSON.stringify({ + type: 'module', + }), + ) + + child.execSync('yarn tsc -p tsconfig.build.json') +})() diff --git a/package.json b/package.json index 24bf3237..f976b054 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "@testing-library/user-event", "version": "0.0.0-semantically-released", "description": "Fire events the same way the user does", - "main": "dist/index.js", "keywords": [ "react-testing-library", "dom-testing-library", @@ -26,8 +25,10 @@ "files": [ "dist" ], + "main": "./dist/index.js", + "exports": "./dist/index.js", "scripts": { - "build": "kcd-scripts build --no-ts-defs && tsc -p tsconfig.build.json", + "build": "node build.js", "lint": "kcd-scripts lint", "setup": "npm install && npm run validate -s", "test": "kcd-scripts test", @@ -46,6 +47,7 @@ "@types/estree": "0.0.45", "@types/jest-in-case": "^1.0.3", "@types/react": "^17.0.3", + "esbuild": "^0.14.9", "eslint-import-resolver-typescript": "^2.5.0", "is-ci": "^2.0.0", "jest-in-case": "^1.0.2", @@ -57,31 +59,5 @@ }, "peerDependencies": { "@testing-library/dom": ">=7.21.4" - }, - "eslintConfig": { - "extends": "./node_modules/kcd-scripts/eslint.js", - "rules": { - "jsx-a11y/click-events-have-key-events": "off", - "jsx-a11y/tabindex-no-positive": "off", - "no-func-assign": "off", - "no-return-assign": "off", - "react/prop-types": "off", - "testing-library/no-dom-import": "off" - }, - "overrides": [ - { - "files": [ - "**/__tests__/**" - ], - "rules": { - "no-console": "off" - } - } - ] - }, - "eslintIgnore": [ - "node_modules", - "coverage", - "dist" - ] + } } diff --git a/src/utils/dataTransfer/Clipboard.ts b/src/utils/dataTransfer/Clipboard.ts index 05ca1b31..cfc19a2f 100644 --- a/src/utils/dataTransfer/Clipboard.ts +++ b/src/utils/dataTransfer/Clipboard.ts @@ -184,13 +184,11 @@ export async function writeDataTransferToClipboard( } /* istanbul ignore else */ -// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -if (afterEach) { +if (typeof afterEach === 'function') { afterEach(() => resetClipboardStubOnView(window)) } /* istanbul ignore else */ -// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -if (afterAll) { +if (typeof afterAll === 'function') { afterAll(() => detachClipboardStubFromView(window)) } diff --git a/src/utils/misc/dom-helpers.d.ts b/src/utils/misc/dom-helpers.d.ts index a1945225..fd0b3f29 100644 --- a/src/utils/misc/dom-helpers.d.ts +++ b/src/utils/misc/dom-helpers.d.ts @@ -1,3 +1,3 @@ -declare module '@testing-library/dom/dist/helpers' { +declare module '@testing-library/dom/dist/helpers.js' { export function getWindowFromNode(node: Node): Window } diff --git a/src/utils/misc/hasPointerEvents.ts b/src/utils/misc/hasPointerEvents.ts index 3403ac37..7e862a24 100644 --- a/src/utils/misc/hasPointerEvents.ts +++ b/src/utils/misc/hasPointerEvents.ts @@ -1,4 +1,4 @@ -import {getWindowFromNode} from '@testing-library/dom/dist/helpers' +import {getWindowFromNode} from '@testing-library/dom/dist/helpers.js' /** * Options that can be passed to any event that relies diff --git a/src/utils/misc/isVisible.ts b/src/utils/misc/isVisible.ts index 3770dbc7..41be011c 100644 --- a/src/utils/misc/isVisible.ts +++ b/src/utils/misc/isVisible.ts @@ -1,4 +1,4 @@ -import {getWindowFromNode} from '@testing-library/dom/dist/helpers' +import {getWindowFromNode} from '@testing-library/dom/dist/helpers.js' export function isVisible(element: Element): boolean { const window = getWindowFromNode(element) diff --git a/src/utils/pointer/dom-events.d.ts b/src/utils/pointer/dom-events.d.ts index fa78d697..7c3e7abd 100644 --- a/src/utils/pointer/dom-events.d.ts +++ b/src/utils/pointer/dom-events.d.ts @@ -1,3 +1,3 @@ -declare module '@testing-library/dom/dist/event-map' { +declare module '@testing-library/dom/dist/event-map.js' { export const eventMap: Record } diff --git a/src/utils/pointer/firePointerEvents.ts b/src/utils/pointer/firePointerEvents.ts index d0691fdf..a4502280 100644 --- a/src/utils/pointer/firePointerEvents.ts +++ b/src/utils/pointer/firePointerEvents.ts @@ -1,5 +1,5 @@ import {createEvent, fireEvent} from '@testing-library/dom' -import {eventMap} from '@testing-library/dom/dist/event-map' +import {eventMap} from '@testing-library/dom/dist/event-map.js' import type {pointerState} from '../../pointer/types' import type {keyboardState} from '../../keyboard/types' import {getMouseButton, getMouseButtons, MouseButton} from './mouseButtons' diff --git a/tsconfig.build.json b/tsconfig.build.json index 2051f712..0836fd9a 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -2,9 +2,10 @@ "extends": "./tsconfig.json", "include": ["./src"], "compilerOptions": { - "outDir": "dist", + "outFile": "dist/index.d.ts", "noEmit": false, "declaration": true, - "emitDeclarationOnly": true + "emitDeclarationOnly": true, + "isolatedModules": false } }