Skip to content

Commit 054e7fe

Browse files
authored
fix(ui): improve ui package typechecking (#9675)
1 parent 4ff463a commit 054e7fe

15 files changed

Lines changed: 151 additions & 309 deletions
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

‎eslint.config.mjs‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
14
import eslint from '@eslint/js';
25
import configPrettier from 'eslint-config-prettier';
36
import configTurbo from 'eslint-config-turbo/flat';
@@ -17,10 +20,43 @@ import tseslint from 'typescript-eslint';
1720

1821
import { CUSTOM_BLOCK_TAGS, CUSTOM_MODIFIER_TAGS } from './.typedoc/custom-tags.mjs';
1922

23+
const REPO_ROOT = import.meta.dirname;
2024
const ECMA_VERSION = 2021,
2125
JAVASCRIPT_FILES = ['**/*.cjs', '**/*.js', '**/*.jsx', '**/*.mjs'],
2226
TEST_FILES = ['**/*.test.js', '**/*.test.jsx', '**/*.test.ts', '**/*.test.tsx', '**/test/**', '**/__tests__/**'],
23-
TYPESCRIPT_FILES = ['**/*.cts', '**/*.mts', '**/*.ts', '**/*.tsx'];
27+
TYPESCRIPT_FILES = ['**/*.cts', '**/*.mts', '**/*.ts', '**/*.tsx'],
28+
// turbo lint runs `eslint src` from each package cwd; these must be repo-absolute
29+
IMPORT_RESOLVER_TSCONFIGS = [`${REPO_ROOT}/integration/tsconfig.json`],
30+
IMPORT_RESOLVER_TSCONFIG_NAMES = ['tsconfig.json', 'tsconfig.src.json', 'tsconfig.test.json', 'tsconfig.mosaic.json'];
31+
32+
// Each package must see only its own tsconfigs. Several packages define `@/*`, and a
33+
// shared project list lets the resolver apply clerk-js's alias to UI or shared files.
34+
const PACKAGE_IMPORT_RESOLVER_CONFIGS = fs
35+
.readdirSync(path.join(REPO_ROOT, 'packages'), { withFileTypes: true })
36+
.filter(entry => entry.isDirectory() && fs.existsSync(path.join(REPO_ROOT, 'packages', entry.name, 'package.json')))
37+
.flatMap(entry => {
38+
const project = IMPORT_RESOLVER_TSCONFIG_NAMES.map(name =>
39+
path.join(REPO_ROOT, 'packages', entry.name, name),
40+
).filter(file => fs.existsSync(file));
41+
if (project.length === 0) {
42+
return [];
43+
}
44+
return [
45+
{
46+
name: `packages/${entry.name}/import-resolver`,
47+
files: [`packages/${entry.name}/**/*.{ts,tsx,js,jsx,mts,cts}`],
48+
settings: {
49+
'import/resolver': {
50+
node: true,
51+
typescript: {
52+
alwaysTryTypes: true,
53+
project,
54+
},
55+
},
56+
},
57+
},
58+
];
59+
});
2460

2561
const noNavigateUseClerk = {
2662
meta: {
@@ -339,7 +375,7 @@ export default tseslint.config([
339375
node: true,
340376
typescript: {
341377
alwaysTryTypes: true,
342-
project: ['packages/*/tsconfig.json', 'integration/tsconfig.json'],
378+
project: IMPORT_RESOLVER_TSCONFIGS,
343379
},
344380
},
345381
},
@@ -517,6 +553,7 @@ export default tseslint.config([
517553
'react-hooks/rules-of-hooks': 'warn',
518554
},
519555
},
556+
...PACKAGE_IMPORT_RESOLVER_CONFIGS,
520557
{
521558
name: 'packages/clerk-js',
522559
files: ['packages/clerk-js/src/ui/**/*'],

‎packages/ui/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@
9292
"lint": "eslint src",
9393
"lint:attw": "attw --pack . --exclude-entrypoints themes/shadcn.css --profile esm-only",
9494
"lint:publint": "publint",
95-
"showerrors": "tsc",
95+
"showerrors": "tsc -p tsconfig.src.json",
9696
"test": "vitest run",
9797
"test:ci": "vitest run --maxWorkers=70%",
9898
"test:coverage": "vitest --collectCoverage && open coverage/lcov-report/index.html",
99-
"type-check": "tsc --noEmit"
99+
"type-check": "tsc --noEmit -p tsconfig.src.json"
100100
},
101101
"dependencies": {
102102
"@clerk/localizations": "workspace:^",

0 commit comments

Comments
 (0)