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" } 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 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..1be1ebbf --- /dev/null +++ b/scripts/test-built-package-exports.mjs @@ -0,0 +1,12 @@ +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() === '') +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.')