diff --git a/.changeset/five-birds-cheer.md b/.changeset/five-birds-cheer.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/five-birds-cheer.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/.prettierignore b/.prettierignore index 76c30f72670..51265795595 100644 --- a/.prettierignore +++ b/.prettierignore @@ -8,9 +8,11 @@ .vscode .yalc /**/scripts/info.js +*.map +*.min.js +*.bundle.js build coverage -coverage dist /packages/nextjs/examples node_modules diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index b49961d93e7..00000000000 --- a/.prettierrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "arrowParens": "avoid", - "bracketSpacing": true, - "jsxSingleQuote": true, - "plugins": ["prettier-plugin-packagejson", "prettier-plugin-tailwindcss", "prettier-plugin-astro"], - "printWidth": 120, - "semi": true, - "singleAttributePerLine": true, - "singleQuote": true, - "tabWidth": 2, - "trailingComma": "all" -} diff --git a/package.json b/package.json index fd1f0ebccaa..06bb5d04967 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "clean": "turbo clean", "dev": "TURBO_UI=0 FORCE_COLOR=1 turbo dev --filter=@clerk/* --filter=!@clerk/clerk-expo --filter=!@clerk/tanstack-react-start --filter=!@clerk/elements --filter=!@clerk/remix --filter=!@clerk/chrome-extension", "dev:js": "TURBO_UI=0 FORCE_COLOR=1 turbo dev:current --filter=@clerk/clerk-js", - "format": "prettier --write .", - "format:check": "prettier --cache --check .", + "format": "turbo format && node scripts/format-non-workspace.mjs", + "format:check": "turbo format:check && node scripts/format-non-workspace.mjs --check", "preinstall": "npx only-allow pnpm", "integration:secrets": "node ./scripts/1password-keys.mjs", "lint": "node ./scripts/lint.mjs", diff --git a/packages/agent-toolkit/package.json b/packages/agent-toolkit/package.json index 867a643782a..102d4837744 100644 --- a/packages/agent-toolkit/package.json +++ b/packages/agent-toolkit/package.json @@ -39,6 +39,8 @@ "build": "tsup --env.NODE_ENV production", "clean": "rimraf ./dist", "dev": "tsup --watch", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile esm-only", "lint:publint": "publint", diff --git a/packages/astro/package.json b/packages/astro/package.json index 3b626863358..e2e4343674a 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -80,6 +80,8 @@ "build:dts": "tsc --emitDeclarationOnly --declaration", "copy:components": "rm -rf ./components && mkdir -p ./components/ && cp -r ./src/astro-components/* ./components/ && cp ./src/types.ts ./", "dev": "tsup --watch --onSuccess \"pnpm build:dts\"", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src env.d.ts", "lint:attw": "attw --pack . --profile esm-only --ignore-rules internal-resolution-error", "lint:publint": "pnpm copy:components && publint", diff --git a/packages/backend/package.json b/packages/backend/package.json index fdc132b7b42..20601854619 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -93,6 +93,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev -- --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16 --ignore-rules false-cjs", "lint:publint": "publint", diff --git a/packages/chrome-extension/package.json b/packages/chrome-extension/package.json index 427dc4cab3b..1023845617f 100644 --- a/packages/chrome-extension/package.json +++ b/packages/chrome-extension/package.json @@ -38,6 +38,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev -- --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16", "lint:publint": "publint", diff --git a/packages/clerk-js/package.json b/packages/clerk-js/package.json index 685dec04987..83926f87f40 100644 --- a/packages/clerk-js/package.json +++ b/packages/clerk-js/package.json @@ -44,6 +44,8 @@ "dev:headless": "rspack serve --config rspack.config.js --env variant=\"clerk.headless.browser\"", "dev:origin": "rspack serve --config rspack.config.js --env devOrigin=http://localhost:${PORT:-4000}", "dev:sandbox": "rspack serve --config rspack.config.js --env devOrigin=http://localhost:${PORT:-4000} --env sandbox=1", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16 --ignore-rules named-exports", "lint:publint": "publint || true", diff --git a/packages/dev-cli/package.json b/packages/dev-cli/package.json index 04da8c94481..32b95b7cd32 100644 --- a/packages/dev-cli/package.json +++ b/packages/dev-cli/package.json @@ -19,6 +19,8 @@ "clerk-dev": "bin/cli.js" }, "scripts": { + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src" }, "dependencies": { diff --git a/packages/elements/package.json b/packages/elements/package.json index 99c7e42b783..97072b64c55 100644 --- a/packages/elements/package.json +++ b/packages/elements/package.json @@ -63,6 +63,8 @@ "build:declarations": "tsc -p tsconfig.declarations.json", "dev": "tsup --env.NODE_ENV development --watch", "dev:example": "concurrently \"pnpm dev\" \"pnpm app:dev\"", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16", "lint:publint": "publint", diff --git a/packages/expo-passkeys/package.json b/packages/expo-passkeys/package.json index 86a3760116f..c8aa541cd92 100644 --- a/packages/expo-passkeys/package.json +++ b/packages/expo-passkeys/package.json @@ -25,6 +25,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev -- --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "open:android": "open -a \"Android Studio\" example/android", "open:ios": "xed example/ios", diff --git a/packages/expo/package.json b/packages/expo/package.json index 064a77804f7..ed82150d4e2 100644 --- a/packages/expo/package.json +++ b/packages/expo/package.json @@ -71,6 +71,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev -- --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "publish:local": "pnpm yalc push --replace --sig", "test": "vitest run", diff --git a/packages/express/package.json b/packages/express/package.json index e773937e483..12d5e761a4d 100644 --- a/packages/express/package.json +++ b/packages/express/package.json @@ -57,6 +57,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev -- --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16", "lint:publint": "publint", diff --git a/packages/fastify/package.json b/packages/fastify/package.json index 3ad6b5cd140..67f6c750d69 100644 --- a/packages/fastify/package.json +++ b/packages/fastify/package.json @@ -55,6 +55,8 @@ "build": "tsup --env.NODE_ENV production", "clean": "rimraf ./dist", "dev": "tsup --watch", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16 --ignore-rules unexpected-module-syntax", "lint:publint": "publint", diff --git a/packages/localizations/package.json b/packages/localizations/package.json index a2e6c37cfa3..b174477e86e 100644 --- a/packages/localizations/package.json +++ b/packages/localizations/package.json @@ -100,6 +100,8 @@ "postbuild": "node ../../scripts/subpath-workaround.mjs localizations", "clean": "rimraf ./dist", "dev": "tsup --watch", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "generate": "tsc src/utils/generate.ts && node src/utils/generate.js && prettier --write src/*.ts", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16" diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 9aa8fb4c0cc..6ecb77d2a2f 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -69,6 +69,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev -- --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16 --ignore-rules unexpected-module-syntax", "lint:publint": "publint", diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index f0b01edb61b..f183561ec19 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -59,6 +59,8 @@ "scripts": { "build": "tsup", "dev": "tsup --watch", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile esm-only", "lint:publint": "publint", diff --git a/packages/react-router/package.json b/packages/react-router/package.json index e0aed65e092..de92fd9212b 100644 --- a/packages/react-router/package.json +++ b/packages/react-router/package.json @@ -72,6 +72,8 @@ "scripts": { "build": "tsup", "dev": "tsup --watch", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile esm-only", "lint:publint": "publint", diff --git a/packages/react/package.json b/packages/react/package.json index 17db52e3b33..92000848553 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -79,6 +79,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16", "lint:publint": "publint", diff --git a/packages/remix/package.json b/packages/remix/package.json index 6e1f5dfeff3..4eaf89dba98 100644 --- a/packages/remix/package.json +++ b/packages/remix/package.json @@ -67,6 +67,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev -- --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16", "lint:publint": "publint", diff --git a/packages/shared/package.json b/packages/shared/package.json index eb8379bf5a7..8b682279432 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -131,6 +131,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev -- --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "postinstall": "node ./scripts/postinstall.mjs", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16", diff --git a/packages/tanstack-react-start/package.json b/packages/tanstack-react-start/package.json index 133f7c54bed..be156d9abfe 100644 --- a/packages/tanstack-react-start/package.json +++ b/packages/tanstack-react-start/package.json @@ -59,6 +59,8 @@ "clean": "rimraf ./dist", "dev": "tsup --watch", "dev:publish": "pnpm dev -- --env.publish", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile esm-only", "lint:publint": "publint", diff --git a/packages/testing/package.json b/packages/testing/package.json index aece110b341..aeb2f52ff0d 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -69,6 +69,8 @@ "build": "tsup --env.NODE_ENV production", "clean": "rimraf ./dist", "dev": "tsup --watch", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src" }, "dependencies": { diff --git a/packages/themes/package.json b/packages/themes/package.json index 054dc37638a..52dbcc14705 100644 --- a/packages/themes/package.json +++ b/packages/themes/package.json @@ -34,6 +34,8 @@ "build": "tsc -p tsconfig.build.json", "clean": "rimraf ./dist", "dev": "tsc -p tsconfig.build.json --watch", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16" }, diff --git a/packages/types/package.json b/packages/types/package.json index 123209fe30d..7521aa0a9b1 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -34,6 +34,8 @@ "build:declarations": "tsc -p tsconfig.declarations.json", "clean": "rimraf ./dist", "dev": "tsup --watch", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile node16", "publish:local": "pnpm yalc push --replace --sig" diff --git a/packages/upgrade/package.json b/packages/upgrade/package.json index 062162c869c..5489f4afcaf 100644 --- a/packages/upgrade/package.json +++ b/packages/upgrade/package.json @@ -19,6 +19,8 @@ "build": "pnpm clean && NODE_ENV=production babel --keep-file-extension --out-dir=dist src --copy-files", "clean": "rm -rf dist/*", "dev": "babel --keep-file-extension --out-dir=dist --watch src --copy-files", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src/", "lint:publint": "publint", "test": "vitest run", diff --git a/packages/vue/package.json b/packages/vue/package.json index ce9e03ff193..f98f0191a46 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -48,6 +48,8 @@ "build": "tsup --onSuccess \"pnpm build:dts\"", "build:dts": "vue-tsc --declaration --emitDeclarationOnly -p tsconfig.build.json", "dev": "tsup --watch", + "format": "node ../../scripts/format-package.mjs", + "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", "lint:attw": "attw --pack . --profile esm-only --ignore-rules internal-resolution-error", "lint:publint": "publint", diff --git a/prettier.config.mjs b/prettier.config.mjs new file mode 100644 index 00000000000..0c399854540 --- /dev/null +++ b/prettier.config.mjs @@ -0,0 +1,12 @@ +export default { + arrowParens: 'avoid', + bracketSpacing: true, + jsxSingleQuote: true, + plugins: ['prettier-plugin-packagejson', 'prettier-plugin-tailwindcss', 'prettier-plugin-astro'], + printWidth: 120, + semi: true, + singleAttributePerLine: true, + singleQuote: true, + tabWidth: 2, + trailingComma: 'all', +}; diff --git a/scripts/1password-keys.mjs b/scripts/1password-keys.mjs index 8484d274de4..c6ffd90123c 100644 --- a/scripts/1password-keys.mjs +++ b/scripts/1password-keys.mjs @@ -2,6 +2,7 @@ import { writeFile } from 'node:fs/promises'; import { join } from 'node:path'; + import { $ } from 'zx'; const is1PasswordInstalled = await $`op --version`.then(res => res.exitCode === 0).catch(() => false); @@ -19,7 +20,7 @@ const envItem = await $`op read 'op://Shared/JS SDKs integration tests/add more/ return null; }) - .catch(err => { + .catch(() => { return null; }); @@ -31,7 +32,7 @@ const keysItem = await $`op read 'op://Shared/JS SDKs integration tests/add more return null; }) - .catch(err => { + .catch(() => { return null; }); diff --git a/scripts/format-non-workspace.mjs b/scripts/format-non-workspace.mjs new file mode 100644 index 00000000000..7c0c85ecde4 --- /dev/null +++ b/scripts/format-non-workspace.mjs @@ -0,0 +1,90 @@ +#!/usr/bin/env node + +import { globby } from 'globby'; +import { $ } from 'zx'; + +const ROOT_FILE_PATTERNS = ['*.cjs', '*.js', '*.json', '*.md', '*.mjs', '*.ts', '*.yaml']; +const NON_WORKSPACE_PATTERNS = [ + 'docs/**/*.{js,jsx,ts,tsx,json,md,mdx}', + 'integration/**/*.{js,jsx,ts,tsx,json,md,mdx}', + 'playground/**/*.{js,jsx,ts,tsx,json,md,mdx}', + 'scripts/**/*.{js,jsx,ts,tsx,json,md,mdx}', +]; + +async function getExistingFiles() { + const existingFiles = []; + + for (const pattern of ROOT_FILE_PATTERNS) { + try { + const matches = await globby(pattern, { + ignore: ['node_modules/**', '**/node_modules/**', 'packages/**'], + }); + existingFiles.push(...matches); + } catch { + // Pattern didn't match any files, skip it + } + } + + for (const pattern of NON_WORKSPACE_PATTERNS) { + try { + const matches = await globby(pattern, { + ignore: [ + 'node_modules/**', + '**/node_modules/**', + '**/dist/**', + '**/build/**', + '**/coverage/**', + '**/.turbo/**', + '**/.next/**', + '**/.tsup/**', + '**/.cache/**', + ], + }); + existingFiles.push(...matches); + } catch { + // Pattern didn't match any files, skip it + } + } + + return existingFiles.filter(Boolean); +} + +async function formatNonWorkspaceFiles() { + const isCheck = process.argv.includes('--check'); + const isVerbose = process.argv.includes('--verbose'); + const baseArgs = isCheck + ? ['prettier', '--cache', '--check', '--ignore-unknown', '--ignore-path', '.prettierignore'] + : ['prettier', '--write', '--ignore-unknown', '--ignore-path', '.prettierignore']; + + console.log(`${isCheck ? 'Checking' : 'Formatting'} non-workspace files...`); + + try { + const existingFiles = await getExistingFiles(); + + if (existingFiles.length === 0) { + console.log('ā„¹ļø No non-workspace files found to format'); + return; + } + + console.log(`šŸ“ Found ${existingFiles.length} files/directories to format`); + + if (isVerbose) { + console.log('\nšŸ“„ Files to be formatted:'); + existingFiles.forEach((file, index) => { + console.log(` ${index + 1}. ${file}`); + }); + console.log(''); + } + + await $`pnpm ${baseArgs} ${existingFiles}`; + console.log(`āœ… Non-workspace files ${isCheck ? 'check passed' : 'formatted successfully'}`); + } catch (error) { + console.error(`āŒ Non-workspace files ${isCheck ? 'check failed' : 'formatting failed'}`); + if (error.stderr) { + console.error(error.stderr); + } + process.exit(1); + } +} + +formatNonWorkspaceFiles().catch(console.error); diff --git a/scripts/format-package.mjs b/scripts/format-package.mjs new file mode 100644 index 00000000000..34b349d87b8 --- /dev/null +++ b/scripts/format-package.mjs @@ -0,0 +1,23 @@ +#!/usr/bin/env node + +import { $ } from 'zx'; + +async function formatPackage() { + const isCheck = process.argv.includes('--check'); + const baseArgs = isCheck + ? ['prettier', '--cache', '--check', '--ignore-path', '../../.prettierignore'] + : ['prettier', '--write', '--ignore-path', '../../.prettierignore']; + + try { + await $`pnpm ${baseArgs} .`; + console.log(`āœ… Package files ${isCheck ? 'check passed' : 'formatted successfully'}`); + } catch (error) { + console.error(`āŒ Package files ${isCheck ? 'check failed' : 'formatting failed'}`); + if (error.stderr) { + console.error(error.stderr); + } + process.exit(1); + } +} + +formatPackage().catch(console.error); diff --git a/turbo.json b/turbo.json index 0e3eeac08d7..5a651d02495 100644 --- a/turbo.json +++ b/turbo.json @@ -143,7 +143,54 @@ ], "outputs": [] }, + "format": { + "inputs": [ + "**/*.js", + "**/*.jsx", + "**/*.ts", + "**/*.tsx", + "**/*.json", + "**/*.md", + "**/*.mdx", + "**/*.vue", + "**/*.astro", + "**/*.css", + "**/*.scss", + "**/*.html", + ".prettierignore", + "prettier.config.mjs", + "!**/__snapshots__/**", + "!CHANGELOG.md", + "!coverage/**", + "!dist/**", + "!examples/**", + "!node_modules/**" + ], + "outputs": [] + }, "format:check": { + "inputs": [ + "**/*.js", + "**/*.jsx", + "**/*.ts", + "**/*.tsx", + "**/*.json", + "**/*.md", + "**/*.mdx", + "**/*.vue", + "**/*.astro", + "**/*.css", + "**/*.scss", + "**/*.html", + ".prettierignore", + "prettier.config.mjs", + "!**/__snapshots__/**", + "!CHANGELOG.md", + "!coverage/**", + "!dist/**", + "!examples/**", + "!node_modules/**" + ], "outputs": [] }, "//#test:integration:ap-flows": {