From 3ec8e9fa2f6eef3911cb47f656ab761fc1030812 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Sun, 16 Jul 2023 00:45:51 +0200 Subject: [PATCH] =?UTF-8?q?break:=20include=20"exports"=20map=C2=A0w/=20"t?= =?UTF-8?q?ypes"=20conditions=20(#57)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The non-standard `package.json` field `module` was used. This pointed to a faux ESM file (Uses ESM syntax, but has a `.js` file extension in a package which doesn’t specify `"type": "module"`. ESM support was fixed by using the `.mjs` file extension for the ESM export and defining a proper `exports` field in `package.json. The types reflected a package that has the `module.exports.default` field. This was incorrect. The CommonJS types have now been fixed to use `export =`, which is the correct way to type modules that use `module.exports` assignments. Additional types were added for ESM support. --- clsx.d.mts | 6 ++++++ clsx.d.ts | 14 +++++++++----- package.json | 12 +++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 clsx.d.mts diff --git a/clsx.d.mts b/clsx.d.mts new file mode 100644 index 0000000..2220c93 --- /dev/null +++ b/clsx.d.mts @@ -0,0 +1,6 @@ +export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined; +export type ClassDictionary = Record; +export type ClassArray = ClassValue[]; + +export function clsx(...inputs: ClassValue[]): string; +export default clsx; diff --git a/clsx.d.ts b/clsx.d.ts index f557360..b86650a 100644 --- a/clsx.d.ts +++ b/clsx.d.ts @@ -1,6 +1,10 @@ -export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined; -export type ClassDictionary = Record; -export type ClassArray = ClassValue[]; +declare namespace clsx { + type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined; + type ClassDictionary = Record; + type ClassArray = ClassValue[]; + function clsx(...inputs: ClassValue[]): string; +} -export declare function clsx(...inputs: ClassValue[]): string; -export default clsx; +declare function clsx(...inputs: clsx.ClassValue[]): string; + +export = clsx; diff --git a/package.json b/package.json index 8f2f743..bf411e9 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,19 @@ "version": "1.2.1", "repository": "lukeed/clsx", "description": "A tiny (228B) utility for constructing className strings conditionally.", - "module": "dist/clsx.m.js", + "module": "dist/clsx.mjs", "unpkg": "dist/clsx.min.js", "main": "dist/clsx.js", + "exports": { + "import": { + "types": "./clsx.d.mts", + "default": "./dist/clsx.mjs" + }, + "default": { + "types": "./clsx.d.ts", + "default": "./dist/clsx.js" + } + }, "types": "clsx.d.ts", "license": "MIT", "author": {