Skip to content

Commit c8b3b3d

Browse files
committed
enforce that @clerk/shared cannot reference self through imports
1 parent 16c213b commit c8b3b3d

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

eslint.config.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,29 @@ export default tseslint.config([
374374
'@typescript-eslint/unbound-method': 'off',
375375
},
376376
},
377+
{
378+
name: 'packages/shared',
379+
files: ['packages/shared/src/**/*'],
380+
rules: {
381+
'no-restricted-imports': [
382+
'error',
383+
{
384+
patterns: [
385+
{
386+
group: ['@clerk/shared', '@clerk/shared/*'],
387+
message:
388+
'Do not import from @clerk/shared package exports within the package itself. Use the @/ alias or relative imports from source files instead (e.g., import from "@/types" or "../../types").',
389+
},
390+
{
391+
group: ['../../../*'],
392+
message:
393+
'Relative imports should not traverse more than 2 levels up (../../). Use the @/ path alias instead (e.g., import from "@/types").',
394+
},
395+
],
396+
},
397+
],
398+
},
399+
},
377400
{
378401
name: 'packages/expo-passkeys',
379402
files: ['packages/expo-passkeys/src/**/*'],

packages/shared/src/internal/clerk-js/url.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export function getSearchParameterFromHash({
227227
return dummyUrlForHash.searchParams.get(paramName);
228228
}
229229

230-
export function isValidUrl<T extends string | URL | undefined>(val: T): val is NonNullable<T> {
230+
export function isValidUrl(val: string | URL | undefined | null): boolean {
231231
if (!val) {
232232
return false;
233233
}
@@ -275,7 +275,7 @@ export function isProblematicUrl(url: URL): boolean {
275275
}
276276

277277
export function isDataUri(val?: string): val is string {
278-
if (!isValidUrl(val)) {
278+
if (!val || !isValidUrl(val)) {
279279
return false;
280280
}
281281

packages/shared/src/internal/clerk-js/warnings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Serializable } from '../../types';
1+
import type { Serializable } from '@/types';
22

33
const formatWarning = (msg: string) => {
44
return `🔒 Clerk:\n${msg.trim()}\n(This notice only appears in development)`;

packages/shared/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"declarationMap": true,
2424
"allowJs": true,
2525
"paths": {
26+
"@/*": ["./src/*"],
2627
"virtual:data-hooks/useSubscription": ["./src/react/hooks/useSubscription.swr.tsx"],
2728
"virtual:data-hooks/SWRConfigCompat": ["./src/react/providers/SWRConfigCompat.swr.tsx"]
2829
}

0 commit comments

Comments
 (0)