From 75717d35eb655c43c8a657ea6c0a7d66020fd40f Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Sat, 13 Aug 2022 18:05:03 +0200 Subject: [PATCH 1/4] support mjs files in ESLint overrides --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 3e01a468..2a3a5553 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -161,7 +161,7 @@ "extends": ["plugin:jest/recommended", "plugin:jest/style"] }, { - "files": ["scripts/**/*.js"], + "files": ["scripts/**/*.?(m)js"], "rules": { "no-console": "off" } From 6f5e2d4d6dc24e41fa559fb84f2f295734bcbd49 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Sat, 13 Aug 2022 18:05:30 +0200 Subject: [PATCH 2/4] add smoke tests for package exports in CJS and ESM --- package.json | 1 + scripts/test-built-package-exports.js | 11 +++++++++++ scripts/test-built-package-exports.mjs | 11 +++++++++++ 3 files changed, 23 insertions(+) create mode 100644 scripts/test-built-package-exports.js create mode 100644 scripts/test-built-package-exports.mjs diff --git a/package.json b/package.json index 05730b57..2dda293a 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "scripts": { "build": "dts build", "test": "dts test", + "test:exports": "node scripts/test-built-package-exports.js && node scripts/test-built-package-exports.mjs", "lint": "eslint --max-warnings 0 '**'", "size": "size-limit", "preversion": "if [ -n \"$DANYS_MACHINE\" ]; then git checkout main && git pull; fi", diff --git a/scripts/test-built-package-exports.js b/scripts/test-built-package-exports.js new file mode 100644 index 00000000..e6a8dc16 --- /dev/null +++ b/scripts/test-built-package-exports.js @@ -0,0 +1,11 @@ +const assert = require('assert') + +const { twMerge } = require('..') + +assert(twMerge() === '') +assert( + twMerge('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]') === + 'hover:bg-dark-red p-3 bg-[#B91C1C]' +) + +console.log('[tailwind-merge] Tests for built CJS package exports passed.') diff --git a/scripts/test-built-package-exports.mjs b/scripts/test-built-package-exports.mjs new file mode 100644 index 00000000..e8e2eac7 --- /dev/null +++ b/scripts/test-built-package-exports.mjs @@ -0,0 +1,11 @@ +import assert from 'assert' + +import { twMerge } from '../dist/tailwind-merge.mjs' + +assert(twMerge() === '') +assert( + twMerge('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]') === + 'hover:bg-dark-red p-3 bg-[#B91C1C]' +) + +console.log('[tailwind-merge] Tests for built ESM package exports passed.') From fc7b78e19058fa5487c8102d6dfb9b3eb410bd12 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Sat, 13 Aug 2022 18:06:55 +0200 Subject: [PATCH 3/4] add package export test to GitHub Action workflows --- .github/workflows/npm-publish.yml | 1 + .github/workflows/test.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index ff915a61..04253edb 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -29,6 +29,7 @@ jobs: name: build-output path: dist if-no-files-found: error + - run: yarn test:exports - run: yarn size - uses: JS-DevTools/npm-publish@v1 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 62871e61..f6bc458f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,3 +33,4 @@ jobs: name: build-output path: dist if-no-files-found: error + - run: yarn test:exports From 184234d937bbabd512c04beb68690d0d0cd11239 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Sat, 13 Aug 2022 18:11:54 +0200 Subject: [PATCH 4/4] add comment to ESM test explaining limitations --- scripts/test-built-package-exports.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test-built-package-exports.mjs b/scripts/test-built-package-exports.mjs index e8e2eac7..1be1ebbf 100644 --- a/scripts/test-built-package-exports.mjs +++ b/scripts/test-built-package-exports.mjs @@ -1,5 +1,6 @@ import assert from 'assert' +// Not ideal, but there seems to be no way to point the import resolver to the package.json file if this isn't a npm package. import { twMerge } from '../dist/tailwind-merge.mjs' assert(twMerge() === '')