From 1e91d3de1413df128d7a40365ed29a08f04bef75 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 27 Nov 2023 15:46:24 +0200 Subject: [PATCH] fix(clerk-react): ESM bundle with vite / rollup --- .changeset/new-points-turn.md | 7 ++++++ packages/react/package.json | 25 +++++++++---------- packages/react/tsconfig.declarations.json | 12 --------- packages/react/tsup.config.ts | 30 +++++++++-------------- 4 files changed, 30 insertions(+), 44 deletions(-) create mode 100644 .changeset/new-points-turn.md delete mode 100644 packages/react/tsconfig.declarations.json diff --git a/.changeset/new-points-turn.md b/.changeset/new-points-turn.md new file mode 100644 index 00000000000..2c3ec4cf7c5 --- /dev/null +++ b/.changeset/new-points-turn.md @@ -0,0 +1,7 @@ +--- +'@clerk/clerk-react': minor +--- + +Fix `@clerk/clerk-react` bundle output to resolve issues with vite / rollup ESM module imports. +We have also used the `bundle` output to export a single index.ts and dropped the unnecessary +published files / folders (eg `__tests__`). diff --git a/packages/react/package.json b/packages/react/package.json index ff7d0bd8462..dd14c80d888 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -22,28 +22,27 @@ }, "license": "MIT", "author": "Clerk", - "sideEffects": [ - "./dist/cjs/index.js", - "./dist/cjs/polyfills.js", - "./dist/esm/index.js", - "./dist/esm/polyfills.js" - ], "exports": { + "./package.json": "./package.json", ".": { - "types": "./dist/types/index.d.ts", - "import": "./dist/esm/index.js", - "require": "./dist/cjs/index.js" + "import": { + "types": "./dist/index.d.mts", + "default": "./dist/index.mjs" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } } }, - "main": "./dist/cjs/index.js", - "module": "./dist/esm/index.js", - "types": "./dist/types/index.d.ts", + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", "files": [ "dist" ], "scripts": { "build": "tsup", - "build:declarations": "tsc -p tsconfig.declarations.json", "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "npm run dev -- --env.publish", diff --git a/packages/react/tsconfig.declarations.json b/packages/react/tsconfig.declarations.json deleted file mode 100644 index c42a5efd18e..00000000000 --- a/packages/react/tsconfig.declarations.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "skipLibCheck": true, - "noEmit": false, - "declaration": true, - "emitDeclarationOnly": true, - "declarationMap": true, - "sourceMap": false, - "declarationDir": "./dist/types" - } -} diff --git a/packages/react/tsup.config.ts b/packages/react/tsup.config.ts index 36498142370..e2b4da48307 100644 --- a/packages/react/tsup.config.ts +++ b/packages/react/tsup.config.ts @@ -1,21 +1,26 @@ -import type { Options } from 'tsup'; import { defineConfig } from 'tsup'; -import { runAfterLast } from '../../scripts/utils'; +// @ts-expect-error for `import module with '.json' extension` import { version as clerkJsVersion } from '../clerk-js/package.json'; +// @ts-expect-error for `import module with '.json' extension` import { name, version } from './package.json'; export default defineConfig(overrideOptions => { const isWatch = !!overrideOptions.watch; const shouldPublish = !!overrideOptions.env?.publish; - const common: Options = { - entry: ['./src/**/*.{ts,tsx,js,jsx}', '!./src/**/*.test.{ts,tsx}'], - bundle: false, + return { + entry: { + index: 'src/index.ts', + }, + onSuccess: shouldPublish ? 'npm run publish:local' : undefined, + format: ['cjs', 'esm'], + bundle: true, clean: true, minify: false, sourcemap: true, - legacyOutput: true, + dts: true, + external: ['react', 'react-dom'], define: { PACKAGE_NAME: `"${name}"`, PACKAGE_VERSION: `"${version}"`, @@ -23,17 +28,4 @@ export default defineConfig(overrideOptions => { __DEV__: `${isWatch}`, }, }; - - const esm: Options = { - ...common, - format: 'esm', - }; - - const cjs: Options = { - ...common, - format: 'cjs', - outDir: './dist/cjs', - }; - - return runAfterLast(['npm run build:declarations', shouldPublish && 'npm run publish:local'])(esm, cjs); });