Skip to content

Commit

Permalink
fix!: export bundled ESM (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche committed Dec 30, 2021
1 parent e9635f6 commit 1a5e2a7
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/coverage
/dist
/node_modules
23 changes: 23 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -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')
})()
34 changes: 5 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"
]
}
}
6 changes: 2 additions & 4 deletions src/utils/dataTransfer/Clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion src/utils/misc/dom-helpers.d.ts
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion src/utils/misc/hasPointerEvents.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/utils/misc/isVisible.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/pointer/dom-events.d.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>
}
2 changes: 1 addition & 1 deletion src/utils/pointer/firePointerEvents.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 1a5e2a7

Please sign in to comment.