From 24dd330c8acc2529d86b5b8a3e7a031bd41ed64f Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 22 Aug 2023 10:03:39 -0400 Subject: [PATCH 1/7] Add rollup config --- package.json | 49 +++++++++++++++++++++++++++++++++++++++++++-- rollup.config.js | 28 ++++++++++++++++++++++++++ src/jest-globals.js | 4 ++++ src/vitest.js | 4 ++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 rollup.config.js create mode 100644 src/jest-globals.js create mode 100644 src/vitest.js diff --git a/package.json b/package.json index c329a7d3..f8a4b4a6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,51 @@ "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", @@ -10,7 +54,7 @@ "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", @@ -54,6 +98,7 @@ "kcd-scripts": "^14.0.0", "pretty-format": "^25.1.0", "vitest": "^0.34.1", + "rollup": "^3.28.1", "typescript": "^5.1.6" }, "peerDependencies": { diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000..cc27e949 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,28 @@ +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('/'), + }, +] diff --git a/src/jest-globals.js b/src/jest-globals.js new file mode 100644 index 00000000..153145ac --- /dev/null +++ b/src/jest-globals.js @@ -0,0 +1,4 @@ +import globals from '@jest/globals' +import * as extensions from './matchers' + +globals.expect.extend(extensions) diff --git a/src/vitest.js b/src/vitest.js new file mode 100644 index 00000000..2030c472 --- /dev/null +++ b/src/vitest.js @@ -0,0 +1,4 @@ +import {expect} from 'vitest' +import * as extensions from './matchers' + +expect.extend(extensions) From 4da8ae768e4fbaf5cd6aee510bd6f9d15f432f23 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 22 Aug 2023 10:23:12 -0400 Subject: [PATCH 2/7] Sort dependencies in package.json --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f8a4b4a6..8b70177d 100644 --- a/package.json +++ b/package.json @@ -80,10 +80,10 @@ "author": "Ernesto Garcia (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", @@ -97,9 +97,9 @@ "jsdom": "^16.2.1", "kcd-scripts": "^14.0.0", "pretty-format": "^25.1.0", - "vitest": "^0.34.1", "rollup": "^3.28.1", - "typescript": "^5.1.6" + "typescript": "^5.1.6", + "vitest": "^0.34.1" }, "peerDependencies": { "@jest/globals": ">= 28", From 6df833ea9545c714a0686dc123ffdcaf743ae09e Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 22 Aug 2023 10:23:42 -0400 Subject: [PATCH 3/7] Clean output folder before build --- package.json | 1 + rollup.config.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/package.json b/package.json index 8b70177d..a5c08163 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ "kcd-scripts": "^14.0.0", "pretty-format": "^25.1.0", "rollup": "^3.28.1", + "rollup-plugin-delete": "^2.0.0", "typescript": "^5.1.6", "vitest": "^0.34.1" }, diff --git a/rollup.config.js b/rollup.config.js index cc27e949..353fc893 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,3 +1,5 @@ +const del = require('rollup-plugin-delete') + const entries = [ 'src/index.js', 'src/jest-globals.js', @@ -24,5 +26,6 @@ module.exports = [ ], external: id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/'), + plugins: [del({targets: 'dist/*'})], }, ] From 3e2cf12598ffdf5bff396041b439cd5b014b5f20 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 22 Aug 2023 10:29:31 -0400 Subject: [PATCH 4/7] Use relative paths for entries --- rollup.config.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 353fc893..6afdd7ef 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,10 +1,10 @@ const del = require('rollup-plugin-delete') const entries = [ - 'src/index.js', - 'src/jest-globals.js', - 'src/matchers.js', - 'src/vitest.js', + './src/index.js', + './src/jest-globals.js', + './src/matchers.js', + './src/vitest.js', ] module.exports = [ From 17700fbab76bd0d72f8f30e6aa44d25b04be8d56 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 22 Aug 2023 10:32:31 -0400 Subject: [PATCH 5/7] Convert cjs to esm if needed --- package.json | 1 + rollup.config.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a5c08163..4ef94b17 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ }, "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", diff --git a/rollup.config.js b/rollup.config.js index 6afdd7ef..80afe641 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,5 @@ const del = require('rollup-plugin-delete') +const commonjs = require('@rollup/plugin-commonjs') const entries = [ './src/index.js', @@ -26,6 +27,6 @@ module.exports = [ ], external: id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/'), - plugins: [del({targets: 'dist/*'})], + plugins: [del({targets: 'dist/*'}), commonjs()], }, ] From 769a89c304ad8fc6687f8fe8c49f0ea02f886528 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 22 Aug 2023 10:32:45 -0400 Subject: [PATCH 6/7] Add extensions to lodash imports To support node16 resolution --- src/to-have-form-values.js | 4 ++-- src/to-have-value.js | 2 +- src/utils.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/to-have-form-values.js b/src/to-have-form-values.js index c3fddcc0..fe8c890a 100644 --- a/src/to-have-form-values.js +++ b/src/to-have-form-values.js @@ -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, diff --git a/src/to-have-value.js b/src/to-have-value.js index 0b24e165..da79e416 100644 --- a/src/to-have-value.js +++ b/src/to-have-value.js @@ -1,4 +1,4 @@ -import isEqualWith from 'lodash/isEqualWith' +import isEqualWith from 'lodash/isEqualWith.js' import { checkHtmlElement, compareArraysAsSet, diff --git a/src/utils.js b/src/utils.js index 2b45be02..903f24c0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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 { From d494ce48e347b1c248ec40d46ce34b19246f29a9 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 22 Aug 2023 11:16:43 -0400 Subject: [PATCH 7/7] Ignore coverage for vitest and jest-globals --- src/jest-globals.js | 2 ++ src/vitest.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/jest-globals.js b/src/jest-globals.js index 153145ac..e23def7d 100644 --- a/src/jest-globals.js +++ b/src/jest-globals.js @@ -1,3 +1,5 @@ +/* istanbul ignore file */ + import globals from '@jest/globals' import * as extensions from './matchers' diff --git a/src/vitest.js b/src/vitest.js index 2030c472..a6b56cef 100644 --- a/src/vitest.js +++ b/src/vitest.js @@ -1,3 +1,5 @@ +/* istanbul ignore file */ + import {expect} from 'vitest' import * as extensions from './matchers'