From ae553603dd38983ad03f54ddf303e2531c2ab22f Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Wed, 27 Apr 2022 20:47:45 -0400 Subject: [PATCH 1/6] Use .mjs extension for esm files --- package.json | 16 +++++++++------- rollup.config.js | 25 ++++++++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 8c7ddfc9..ecf28221 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,17 @@ "name": "@testing-library/jest-dom", "version": "0.0.0-semantically-released", "description": "Custom jest matchers to test the state of the DOM", - "main": "dist/cjs/index.js", - "module": "dist/esm/index.js", + "main": "dist/index.js", + "module": "dist/index.mjs", + "type": "commonjs", "exports": { ".": { - "require": "./dist/cjs/index.js", - "import": "./dist/esm/index.js" + "require": "./dist/index.js", + "import": "./dist/index.mjs" }, "./matchers": { - "require": "./dist/cjs/matchers.js", - "import": "./dist/esm/matchers.js" + "require": "./dist/matchers.js", + "import": "./dist/matchers.mjs" } }, "engines": { @@ -20,7 +21,7 @@ "yarn": ">=1" }, "scripts": { - "build": "rollup -c", + "build": "rimraf dist && rollup -c", "format": "kcd-scripts format", "lint": "kcd-scripts lint", "setup": "npm install && npm run validate -s", @@ -58,6 +59,7 @@ "jsdom": "^16.2.1", "kcd-scripts": "^11.1.0", "pretty-format": "^25.1.0", + "rimraf": "^3.0.2", "rollup": "^2.68.0" }, "eslintConfig": { diff --git a/rollup.config.js b/rollup.config.js index 81b5e042..b10d1724 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,19 +1,30 @@ -import path from 'path' import pkg from './package.json' export default [ { - input: { - index: 'src/index.js', - matchers: 'src/matchers.js', - }, + input: 'src/index.js', output: [ { - dir: path.dirname(pkg.exports['./matchers'].import), + file: pkg.exports['.'].import, format: 'esm', }, { - dir: path.dirname(pkg.exports['./matchers'].require), + file: pkg.exports['.'].require, + format: 'cjs', + }, + ], + external: id => + !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/'), + }, + { + input: 'src/matchers.js', + output: [ + { + file: pkg.exports['./matchers'].import, + format: 'esm', + }, + { + file: pkg.exports['./matchers'].require, format: 'cjs', }, ], From 93a63c08b21162c4cfc9054d55a9adba85699119 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 19 Sep 2022 09:15:32 -0400 Subject: [PATCH 2/6] Use array for `input` --- rollup.config.js | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index b10d1724..11155122 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,33 +1,23 @@ -import pkg from './package.json' +const entries = ['src/index.js', 'src/matchers.js'] export default [ { - input: 'src/index.js', - output: [ - { - file: pkg.exports['.'].import, - format: 'esm', - }, - { - file: pkg.exports['.'].require, - format: 'cjs', - }, - ], + input: entries, + output: { + dir: 'dist', + entryFileNames: '[name].mjs', + format: 'esm', + }, external: id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/'), }, { - input: 'src/matchers.js', - output: [ - { - file: pkg.exports['./matchers'].import, - format: 'esm', - }, - { - file: pkg.exports['./matchers'].require, - format: 'cjs', - }, - ], + input: entries, + output: { + dir: 'dist', + entryFileNames: '[name].js', + format: 'cjs', + }, external: id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/'), }, From 9f02ec04ba0ae02857878744b2fcc8afb3219d53 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 19 Sep 2022 09:46:34 -0400 Subject: [PATCH 3/6] Fix chunk names --- rollup.config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rollup.config.js b/rollup.config.js index 11155122..61162cd2 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -6,6 +6,7 @@ export default [ output: { dir: 'dist', entryFileNames: '[name].mjs', + chunkFileNames: '[name]-[hash].mjs', format: 'esm', }, external: id => @@ -16,6 +17,7 @@ export default [ output: { dir: 'dist', entryFileNames: '[name].js', + chunkFileNames: '[name]-[hash].js', format: 'cjs', }, external: id => From 42cb5b6f28bba07653709818aa98741d54d660b9 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 19 Sep 2022 10:26:33 -0400 Subject: [PATCH 4/6] Handle extend-expect.js This was previously handled as a file in the root of the project that redirected to the built index file. This change removes a layer of indirection by removing src/extend-expect, and using exports to point to the index file rather than using a real file in the project root. --- extend-expect.js | 2 -- package.json | 5 ++++- src/extend-expect.js | 3 --- src/index.js | 4 +++- tests/setup-env.js | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 extend-expect.js delete mode 100644 src/extend-expect.js diff --git a/extend-expect.js b/extend-expect.js deleted file mode 100644 index e7d19c10..00000000 --- a/extend-expect.js +++ /dev/null @@ -1,2 +0,0 @@ -// eslint-disable-next-line -require('./dist/extend-expect') diff --git a/package.json b/package.json index ecf28221..ba875383 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,10 @@ "./matchers": { "require": "./dist/matchers.js", "import": "./dist/matchers.mjs" + }, + "./extend-expect.js": { + "require": "./dist/index.js", + "import": "./dist/index.mjs" } }, "engines": { @@ -31,7 +35,6 @@ }, "files": [ "dist", - "extend-expect.js", "matchers.js" ], "keywords": [ diff --git a/src/extend-expect.js b/src/extend-expect.js deleted file mode 100644 index 3801a1d5..00000000 --- a/src/extend-expect.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as extensions from './matchers' - -expect.extend(extensions) diff --git a/src/index.js b/src/index.js index 8cecbe35..3801a1d5 100644 --- a/src/index.js +++ b/src/index.js @@ -1 +1,3 @@ -import './extend-expect' +import * as extensions from './matchers' + +expect.extend(extensions) diff --git a/tests/setup-env.js b/tests/setup-env.js index a9325d25..151f6e7b 100644 --- a/tests/setup-env.js +++ b/tests/setup-env.js @@ -1,4 +1,4 @@ import {plugins} from 'pretty-format' -import '../src/extend-expect' +import '../src/index' expect.addSnapshotSerializer(plugins.ConvertAnsi) From bb1742fa5f2ee8fd5590276945782cb1e59f97c8 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 19 Sep 2022 10:27:21 -0400 Subject: [PATCH 5/6] Add extensions for packages that need them in node ESM --- src/to-have-form-values.js | 4 ++-- src/to-have-value.js | 2 +- src/utils.js | 4 ++-- 3 files changed, 5 insertions(+), 5 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 2f07fb8e..943f92c2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,6 @@ import redent from 'redent' -import cssParse from 'css/lib/parse' -import isEqual from 'lodash/isEqual' +import cssParse from 'css/lib/parse/index.js' +import isEqual from 'lodash/isEqual.js' class GenericTypeError extends Error { constructor(expectedString, received, matcherFn, context) { From 3edeee3b2f1fce68860c6bf7f5ccf4e30f4bee60 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Wed, 21 Sep 2022 20:17:17 -0400 Subject: [PATCH 6/6] Remove extend-expect export --- package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/package.json b/package.json index ba875383..e6e9217a 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,6 @@ "./matchers": { "require": "./dist/matchers.js", "import": "./dist/matchers.mjs" - }, - "./extend-expect.js": { - "require": "./dist/index.js", - "import": "./dist/index.mjs" } }, "engines": {