1+ import fs from 'node:fs' ;
2+ import path from 'node:path' ;
3+
14import eslint from '@eslint/js' ;
25import configPrettier from 'eslint-config-prettier' ;
36import configTurbo from 'eslint-config-turbo/flat' ;
@@ -17,10 +20,43 @@ import tseslint from 'typescript-eslint';
1720
1821import { CUSTOM_BLOCK_TAGS , CUSTOM_MODIFIER_TAGS } from './.typedoc/custom-tags.mjs' ;
1922
23+ const REPO_ROOT = import . meta. dirname ;
2024const 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
2561const 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/**/*' ] ,
0 commit comments