From 5bbb63ba0f71a3db1d61120ea797a8623d9d536c Mon Sep 17 00:00:00 2001 From: Pranay Kothapalli Date: Thu, 11 Sep 2025 10:45:55 +0530 Subject: [PATCH] chore: verify export map on commit --- .changeset/README.md | 4 ++++ .changeset/config.json | 8 ++++++++ .husky/pre-commit | 1 + package.json | 30 ++++++++++++++++++++++++++---- scripts/generate-exports.cjs | 26 +++++++++++++++++++++++--- 5 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 .changeset/README.md create mode 100644 .changeset/config.json diff --git a/.changeset/README.md b/.changeset/README.md new file mode 100644 index 000000000..c3de3939f --- /dev/null +++ b/.changeset/README.md @@ -0,0 +1,4 @@ +# Changesets + +This directory was generated to track release notes and versioning. +Run `npm run changeset` to add a new changeset when you modify public APIs. diff --git a/.changeset/config.json b/.changeset/config.json new file mode 100644 index 000000000..894ac2ec4 --- /dev/null +++ b/.changeset/config.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", + "changelog": "@changesets/cli/changelog", + "commit": false, + "linked": [], + "access": "public", + "baseBranch": "main" +} diff --git a/.husky/pre-commit b/.husky/pre-commit index f4395c3bc..c2616266c 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,6 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" +npm run check:exports npm test npm run lint:staged diff --git a/package.json b/package.json index 87df19f48..6e91bacc1 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,19 @@ "name": "@radui/ui", "version": "0.0.47", "description": "", - "main": "dist", + "main": "./dist/index.cjs", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", "type": "module", - "exports": {}, + "exports": { + ".": { + "import": "./dist/index.js", + "require": "./dist/index.cjs", + "types": "./dist/index.d.ts" + }, + "./themes/default.css": "./dist/themes/default.css", + "./themes/tailwind-presets/default.js": "./dist/themes/tailwind-presets/default.js" + }, "scripts": { "test": "jest", "coverage": "jest --coverage", @@ -22,6 +32,7 @@ "process-components": "node scripts/process-components.cjs", "prebuild": "npm run test && npm run clean", "build:generate-exports": "node scripts/generate-exports.cjs", + "check:exports": "node scripts/generate-exports.cjs --check", "build:css": "npm run generate-tokens && npm run bundle-tokens && npm run build-css", "build:components": "npm run compile-components && npm run process-components", "build:rollup": "NODE_OPTIONS='--max-old-space-size=8192' npm run build:rollup:process", @@ -30,13 +41,21 @@ "check:types": "tsc --noEmit", "build-components:esbuild": "npm run compile-components:esbuild && npm run process-components", "build:esbuild": "npm run prebuild && npm run build:css && npm run build-components:esbuild", - "release": "npm publish --access public", + "release": "npm run build:generate-exports && changeset publish", + "changeset": "changeset", + "version-packages": "changeset version", + "size": "size-limit", "lint": "eslint --ext .js,.jsx,.ts,.tsx . --fix && stylelint \"**/*.{css,scss,sass}\" --fix", "lint:staged": "lint-staged", "update-rad": "npm update @radui/ui", "setup:dependencies": "npm install --force", "setup": "npm run setup:dependencies" }, + "size-limit": [ + { + "path": "dist/components/*.js" + } + ], "lint-staged": { "*.{js,jsx,ts,tsx}": [ "eslint --fix" @@ -80,6 +99,8 @@ "@types/jest": "^29.5.14", "@types/react": "^18.3.1", "@typescript-eslint/eslint-plugin": "7.0.0", + "@changesets/cli": "^2.27.1", + "@size-limit/preset-small-lib": "^11.1.2", "autoprefixer": "10.4.15", "axe-core": "^4.10.2", "babel-plugin-module-resolver": "5.0.2", @@ -105,6 +126,7 @@ "rollup-plugin-postcss": "^4.0.2", "sass": "^1.77.2", "sass-loader": "16.0.4", + "size-limit": "^11.1.2", "storybook": "^8.6.11", "stylelint": "^16.12.0", "stylelint-config-standard": "^36.0.1", @@ -126,4 +148,4 @@ "react": "^18.2.0", "react-dom": "^18.2.0" } -} +} \ No newline at end of file diff --git a/scripts/generate-exports.cjs b/scripts/generate-exports.cjs index 1aec37ad1..8b2cb1387 100644 --- a/scripts/generate-exports.cjs +++ b/scripts/generate-exports.cjs @@ -40,6 +40,7 @@ const fs = require('fs'); const path = require('path'); const RELEASED_COMPONENTS = require('./RELEASED_COMPONENTS.cjs'); +const isCheck = process.argv.includes('--check'); // Component exports const distPath = path.resolve(__dirname, '../dist/components'); @@ -53,6 +54,13 @@ try { const exportsMap = {}; +// Root export +exportsMap['.'] = { + import: './dist/index.js', + require: './dist/index.cjs', + types: './dist/index.d.ts' +}; + // Add theme exports exportsMap['./themes/default.css'] = './dist/themes/default.css'; exportsMap['./themes/tailwind-presets/default.js'] = './dist/themes/tailwind-presets/default.js'; @@ -72,6 +80,7 @@ files.forEach(file => { exportsMap[`./${name}`] = { import: `./dist/components/${name}.js`, + require: `./dist/components/${name}.cjs`, types: `./dist/components/${name}.d.ts` }; } @@ -85,9 +94,20 @@ const pkgPath = path.resolve(__dirname, '../package.json'); try { const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); - pkg.exports = exportsMap; - fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)); - console.log('✅ package.json exports updated!'); + + if (isCheck) { + const current = JSON.stringify(pkg.exports, null, 2); + const expected = JSON.stringify(exportsMap, null, 2); + if (current !== expected) { + console.error('❌ package.json exports are out of date. Run npm run build:generate-exports to update.'); + process.exit(1); + } + console.log('✅ package.json exports are up to date.'); + } else { + pkg.exports = exportsMap; + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)); + console.log('✅ package.json exports updated!'); + } } catch (error) { console.error('❌ Failed to update package.json exports:', error.message); process.exit(1);