Skip to content

Commit

Permalink
break: include "exports" map w/ "types" conditions (#57)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
remcohaszing authored Jul 15, 2023
1 parent 4a4eadd commit 3ec8e9f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 6 additions & 0 deletions clsx.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
export type ClassDictionary = Record<string, any>;
export type ClassArray = ClassValue[];

export function clsx(...inputs: ClassValue[]): string;
export default clsx;
14 changes: 9 additions & 5 deletions clsx.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
export type ClassDictionary = Record<string, any>;
export type ClassArray = ClassValue[];
declare namespace clsx {
type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
type ClassDictionary = Record<string, any>;
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;
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 3ec8e9f

Please sign in to comment.