Skip to content

Commit

Permalink
chore: Publish ESM and CJS (#519)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
IanVS authored Aug 22, 2023
1 parent bdb34f1 commit 61d17bd
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 9 deletions.
57 changes: 52 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,59 @@
"name": "@testing-library/jest-dom",
"version": "0.0.0-semantically-released",
"description": "Custom jest matchers to test the state of the DOM",
"main": "dist/index.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"require": {
"types": "./types/index.d.ts",
"default": "./dist/index.js"
},
"import": {
"types": "./types/index.d.ts",
"default": "./dist/index.mjs"
}
},
"./jest-globals": {
"require": {
"types": "./types/jest-globals.d.ts",
"default": "./dist/jest-globals.js"
},
"import": {
"types": "./types/jest-globals.d.ts",
"default": "./dist/jest-globals.mjs"
}
},
"./matchers": {
"require": {
"types": "./types/matchers.d.ts",
"default": "./dist/matchers.js"
},
"import": {
"types": "./types/matchers.d.ts",
"default": "./dist/matchers.mjs"
}
},
"./vitest": {
"require": {
"types": "./types/vitest.d.ts",
"default": "./dist/vitest.js"
},
"import": {
"types": "./types/vitest.d.ts",
"default": "./dist/vitest.mjs"
}
},
"./package.json": "./package.json"
},
"types": "types/index.d.ts",
"engines": {
"node": ">=14",
"npm": ">=6",
"yarn": ">=1"
},
"scripts": {
"build": "kcd-scripts build",
"build": "rollup -c",
"format": "kcd-scripts format",
"lint": "kcd-scripts lint",
"setup": "npm install && npm run validate -s",
Expand All @@ -36,25 +80,28 @@
"author": "Ernesto Garcia <gnapse@gmail.com> (http://gnapse.github.io)",
"license": "MIT",
"dependencies": {
"@adobe/css-tools": "^4.0.1",
"@babel/runtime": "^7.9.2",
"aria-query": "^5.0.0",
"chalk": "^3.0.0",
"@adobe/css-tools": "^4.0.1",
"css.escape": "^1.5.1",
"dom-accessibility-api": "^0.5.6",
"lodash": "^4.17.15",
"redent": "^3.0.0"
},
"devDependencies": {
"@jest/globals": "^29.6.2",
"@rollup/plugin-commonjs": "^25.0.4",
"expect": "^29.6.2",
"jest-environment-jsdom-sixteen": "^1.0.3",
"jest-watch-select-projects": "^2.0.0",
"jsdom": "^16.2.1",
"kcd-scripts": "^14.0.0",
"pretty-format": "^25.1.0",
"vitest": "^0.34.1",
"typescript": "^5.1.6"
"rollup": "^3.28.1",
"rollup-plugin-delete": "^2.0.0",
"typescript": "^5.1.6",
"vitest": "^0.34.1"
},
"peerDependencies": {
"@jest/globals": ">= 28",
Expand Down
32 changes: 32 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const del = require('rollup-plugin-delete')
const commonjs = require('@rollup/plugin-commonjs')

const entries = [
'./src/index.js',
'./src/jest-globals.js',
'./src/matchers.js',
'./src/vitest.js',
]

module.exports = [
{
input: entries,
output: [
{
dir: 'dist',
entryFileNames: '[name].mjs',
chunkFileNames: '[name]-[hash].mjs',
format: 'esm',
},
{
dir: 'dist',
entryFileNames: '[name].js',
chunkFileNames: '[name]-[hash].js',
format: 'cjs',
},
],
external: id =>
!id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/'),
plugins: [del({targets: 'dist/*'}), commonjs()],
},
]
6 changes: 6 additions & 0 deletions src/jest-globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* istanbul ignore file */

import globals from '@jest/globals'
import * as extensions from './matchers'

globals.expect.extend(extensions)
4 changes: 2 additions & 2 deletions src/to-have-form-values.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isEqualWith from 'lodash/isEqualWith'
import uniq from 'lodash/uniq'
import isEqualWith from 'lodash/isEqualWith.js'
import uniq from 'lodash/uniq.js'
import escape from 'css.escape'
import {
checkHtmlElement,
Expand Down
2 changes: 1 addition & 1 deletion src/to-have-value.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isEqualWith from 'lodash/isEqualWith'
import isEqualWith from 'lodash/isEqualWith.js'
import {
checkHtmlElement,
compareArraysAsSet,
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import redent from 'redent'
import isEqual from 'lodash/isEqual'
import isEqual from 'lodash/isEqual.js'
import {parse} from '@adobe/css-tools'

class GenericTypeError extends Error {
Expand Down
6 changes: 6 additions & 0 deletions src/vitest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* istanbul ignore file */

import {expect} from 'vitest'
import * as extensions from './matchers'

expect.extend(extensions)

0 comments on commit 61d17bd

Please sign in to comment.