From bbfccdf471c1d50b9aaeefc585cb17e472c6dc9c Mon Sep 17 00:00:00 2001 From: Ivan Vasilov Date: Tue, 30 Dec 2025 18:46:24 +0200 Subject: [PATCH] chore: Use `@/*` as an alias for importing in-package files (#41607) * Remove extra file. * Remove unneeded tsconfig.jsons. * Add @/* alias for importing in-package files to all apps. * Remove baseUrl from all apps except studio (it'll require changes in almost all files). * Fix baseUrl issues in docs, ui-library and design-system. * Fix the typecheck for cms app. Fix all baseUrl errors in the cms app. * Add deprecated flag to baseUrl in www. --- apps/cms/package.json | 2 +- apps/cms/src/blocks/Banner/Component.tsx | 2 +- apps/cms/src/blocks/Quote/Component.tsx | 2 +- apps/cms/src/blocks/YouTube/Component.tsx | 2 +- apps/cms/src/utilities/getDocument.ts | 2 +- apps/cms/src/utilities/getGlobals.ts | 2 +- apps/cms/tsconfig.json | 1 - apps/design-system/config/docs.ts | 2 +- apps/design-system/contentlayer.config.js | 1 + apps/design-system/lib/rehype-component.ts | 2 +- apps/design-system/lib/rehype-npm-command.ts | 2 +- apps/design-system/tsconfig.json | 1 - .../features/command/DocsCommandProvider.tsx | 2 +- apps/docs/generator/tsconfig.json | 13 ------------- apps/docs/hooks/useDocsCommandMenuTelemetry.ts | 2 +- apps/docs/hooks/useFlag.ts | 2 +- apps/docs/internals/tsconfig.json | 15 --------------- apps/docs/scripts/tsconfig.json | 17 ----------------- apps/docs/tsconfig.json | 3 ++- apps/studio/tsconfig.json | 2 ++ .../components/command-copy-button.tsx | 2 +- apps/ui-library/config/docs.ts | 2 +- apps/ui-library/contentlayer.config.js | 1 + apps/ui-library/lib/telemetry.ts | 2 +- apps/ui-library/tsconfig.json | 1 - apps/www/tsconfig.json | 3 +++ blocks/vue/tsconfig.json | 1 - data.sql | 0 28 files changed, 24 insertions(+), 65 deletions(-) delete mode 100644 apps/docs/generator/tsconfig.json delete mode 100644 apps/docs/internals/tsconfig.json delete mode 100644 apps/docs/scripts/tsconfig.json delete mode 100644 data.sql diff --git a/apps/cms/package.json b/apps/cms/package.json index ddc5d7dc5d6..7be1e1b4c31 100644 --- a/apps/cms/package.json +++ b/apps/cms/package.json @@ -17,7 +17,7 @@ "payload": "cross-env NODE_OPTIONS=--no-deprecation payload", "start": "cross-env NODE_OPTIONS=--no-deprecation next start", "vercel-build": "pnpm migrate && pnpm build", - "typecheck_IGNORED": "tsc --noEmit" + "typecheck": "tsc --noEmit" }, "dependencies": { "@payloadcms/admin-bar": "^3.52.0", diff --git a/apps/cms/src/blocks/Banner/Component.tsx b/apps/cms/src/blocks/Banner/Component.tsx index 6abb8ad09a6..c395d687801 100644 --- a/apps/cms/src/blocks/Banner/Component.tsx +++ b/apps/cms/src/blocks/Banner/Component.tsx @@ -1,4 +1,4 @@ -import type { BannerBlock as BannerBlockProps } from 'src/payload-types' +import type { BannerBlock as BannerBlockProps } from '@/payload-types' import { cn } from '@/utilities/ui' import React from 'react' diff --git a/apps/cms/src/blocks/Quote/Component.tsx b/apps/cms/src/blocks/Quote/Component.tsx index 90717fa1e6d..1689a82a535 100644 --- a/apps/cms/src/blocks/Quote/Component.tsx +++ b/apps/cms/src/blocks/Quote/Component.tsx @@ -1,4 +1,4 @@ -import type { QuoteBlock as QuoteBlockProps } from 'src/payload-types' +import type { QuoteBlock as QuoteBlockProps } from '@/payload-types' import React from 'react' diff --git a/apps/cms/src/blocks/YouTube/Component.tsx b/apps/cms/src/blocks/YouTube/Component.tsx index 0704f2f7757..2d903a2a6ca 100644 --- a/apps/cms/src/blocks/YouTube/Component.tsx +++ b/apps/cms/src/blocks/YouTube/Component.tsx @@ -1,4 +1,4 @@ -import type { YouTubeBlock as YouTubeBlockProps } from 'src/payload-types' +import type { YouTubeBlock as YouTubeBlockProps } from '@/payload-types' import { cn } from '@/utilities/ui' import React from 'react' diff --git a/apps/cms/src/utilities/getDocument.ts b/apps/cms/src/utilities/getDocument.ts index 31e79ed4ead..f63a9c8db66 100644 --- a/apps/cms/src/utilities/getDocument.ts +++ b/apps/cms/src/utilities/getDocument.ts @@ -1,4 +1,4 @@ -import type { Config } from 'src/payload-types' +import type { Config } from '@/payload-types' import configPromise from '@payload-config' import { getPayload } from 'payload' diff --git a/apps/cms/src/utilities/getGlobals.ts b/apps/cms/src/utilities/getGlobals.ts index 39d6830b195..aaae4c15f0b 100644 --- a/apps/cms/src/utilities/getGlobals.ts +++ b/apps/cms/src/utilities/getGlobals.ts @@ -1,4 +1,4 @@ -import type { Config } from 'src/payload-types' +import type { Config } from '@/payload-types' import configPromise from '@payload-config' import { getPayload } from 'payload' diff --git a/apps/cms/tsconfig.json b/apps/cms/tsconfig.json index 5a66dbfae8e..b9a9542387c 100644 --- a/apps/cms/tsconfig.json +++ b/apps/cms/tsconfig.json @@ -3,7 +3,6 @@ "strict": true, "noUncheckedIndexedAccess": true, "noImplicitOverride": true, - "baseUrl": ".", "esModuleInterop": true, "target": "ES2022", "lib": ["DOM", "DOM.Iterable", "ES2022"], diff --git a/apps/design-system/config/docs.ts b/apps/design-system/config/docs.ts index 4bc1a355151..6db89889ee2 100644 --- a/apps/design-system/config/docs.ts +++ b/apps/design-system/config/docs.ts @@ -1,4 +1,4 @@ -import { MainNavItem, SidebarNavItem } from 'types/nav' +import { MainNavItem, SidebarNavItem } from '@/types/nav' interface DocsConfig { mainNav?: MainNavItem[] diff --git a/apps/design-system/contentlayer.config.js b/apps/design-system/contentlayer.config.js index 4d12b6a0886..f57e01f20db 100644 --- a/apps/design-system/contentlayer.config.js +++ b/apps/design-system/contentlayer.config.js @@ -110,6 +110,7 @@ export const Doc = defineDocumentType(() => ({ export default makeSource({ contentDirPath: './content', + disableImportAliasWarning: true, documentTypes: [Doc], mdx: { remarkPlugins: [remarkGfm, codeImport], diff --git a/apps/design-system/lib/rehype-component.ts b/apps/design-system/lib/rehype-component.ts index 111fee0b42d..9efbc93cc93 100644 --- a/apps/design-system/lib/rehype-component.ts +++ b/apps/design-system/lib/rehype-component.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import { UnistNode, UnistTree } from 'types/unist' +import { UnistNode, UnistTree } from '@/types/unist' import { u } from 'unist-builder' import { visit } from 'unist-util-visit' diff --git a/apps/design-system/lib/rehype-npm-command.ts b/apps/design-system/lib/rehype-npm-command.ts index aaa3792922f..7b50e4ee696 100644 --- a/apps/design-system/lib/rehype-npm-command.ts +++ b/apps/design-system/lib/rehype-npm-command.ts @@ -1,4 +1,4 @@ -import { UnistNode, UnistTree } from 'types/unist' +import { UnistNode, UnistTree } from '@/types/unist' import { visit } from 'unist-util-visit' export function rehypeNpmCommand() { diff --git a/apps/design-system/tsconfig.json b/apps/design-system/tsconfig.json index f4adac07463..85f33731c8b 100644 --- a/apps/design-system/tsconfig.json +++ b/apps/design-system/tsconfig.json @@ -16,7 +16,6 @@ "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", - "baseUrl": ".", "paths": { "@/*": ["./*"], "@ui/*": ["./../../packages/ui/src/*"], // handle ui package paths diff --git a/apps/docs/features/command/DocsCommandProvider.tsx b/apps/docs/features/command/DocsCommandProvider.tsx index 62e300fdda4..e5608a22da4 100644 --- a/apps/docs/features/command/DocsCommandProvider.tsx +++ b/apps/docs/features/command/DocsCommandProvider.tsx @@ -3,7 +3,7 @@ import type { PropsWithChildren } from 'react' import { CommandProvider } from 'ui-patterns/CommandMenu' -import { useDocsCommandMenuTelemetry } from 'hooks/useDocsCommandMenuTelemetry' +import { useDocsCommandMenuTelemetry } from '@/hooks/useDocsCommandMenuTelemetry' export function DocsCommandProvider({ children }: PropsWithChildren) { const { onTelemetry } = useDocsCommandMenuTelemetry() diff --git a/apps/docs/generator/tsconfig.json b/apps/docs/generator/tsconfig.json deleted file mode 100644 index 8615cb5639e..00000000000 --- a/apps/docs/generator/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -// generator files need their own tsconfig.json because they don't like "module": "esnext" setting that nextjs requires in the main tsconfig -{ - "compilerOptions": { - "incremental": true, - "noImplicitAny": false, - "baseUrl": ".", - "paths": { - "~/*": ["./*"] - } - }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"] -} diff --git a/apps/docs/hooks/useDocsCommandMenuTelemetry.ts b/apps/docs/hooks/useDocsCommandMenuTelemetry.ts index 6514699fc7a..2a471cbc1a3 100644 --- a/apps/docs/hooks/useDocsCommandMenuTelemetry.ts +++ b/apps/docs/hooks/useDocsCommandMenuTelemetry.ts @@ -7,7 +7,7 @@ import type { CommandMenuCommandClickedEvent, CommandMenuSearchSubmittedEvent, } from 'common/telemetry-constants' -import { useSendTelemetryEvent } from 'lib/telemetry' +import { useSendTelemetryEvent } from '@/lib/telemetry' export function useDocsCommandMenuTelemetry() { const sendTelemetryEvent = useSendTelemetryEvent() diff --git a/apps/docs/hooks/useFlag.ts b/apps/docs/hooks/useFlag.ts index 3e990f6b3a8..066a097a768 100644 --- a/apps/docs/hooks/useFlag.ts +++ b/apps/docs/hooks/useFlag.ts @@ -1,5 +1,5 @@ import { useContext } from 'react' -import FlagContext from 'components/Flag/FlagContext' +import FlagContext from '@/components/Flag/FlagContext' export function useFlag(name: string) { const store: any = useContext(FlagContext) diff --git a/apps/docs/internals/tsconfig.json b/apps/docs/internals/tsconfig.json deleted file mode 100644 index de1ecb67a32..00000000000 --- a/apps/docs/internals/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -// generator files need their own tsconfig.json because they don't like "module": "esnext" setting that nextjs requires in the main tsconfig -{ - "compilerOptions": { - "incremental": true, - "noImplicitAny": false, - "esModuleInterop": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "~/*": ["./*"] - } - }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"] -} diff --git a/apps/docs/scripts/tsconfig.json b/apps/docs/scripts/tsconfig.json deleted file mode 100644 index 821a210c5e5..00000000000 --- a/apps/docs/scripts/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -// generator files need their own tsconfig.json because they don't like "module": "esnext" setting that nextjs requires in the main tsconfig -{ - "compilerOptions": { - "module": "NodeNext", - "moduleResolution": "NodeNext", - "incremental": true, - "noImplicitAny": false, - "esModuleInterop": true, - "resolveJsonModule": true, - "baseUrl": ".", - "paths": { - "~/*": ["./*"] - } - }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], - "exclude": ["node_modules"] -} diff --git a/apps/docs/tsconfig.json b/apps/docs/tsconfig.json index 28a4aae0fed..60c3e71bc23 100644 --- a/apps/docs/tsconfig.json +++ b/apps/docs/tsconfig.json @@ -2,9 +2,10 @@ "compilerOptions": { "incremental": true, "noImplicitAny": false, - "baseUrl": ".", "paths": { + // @deprecated: use @/ instead of ~/ "~/*": ["./*"], + "@/*": ["./*"], "@ui/*": ["./../../packages/ui/src/*"] }, "target": "ES2021", diff --git a/apps/studio/tsconfig.json b/apps/studio/tsconfig.json index 81d9b7877f8..4ae881822a2 100644 --- a/apps/studio/tsconfig.json +++ b/apps/studio/tsconfig.json @@ -13,10 +13,12 @@ "resolveJsonModule": true, "isolatedModules": true, "jsx": "react-jsx", + // @deprecated: use @/ instead of importing from root "baseUrl": ".", "downlevelIteration": true, "incremental": true, "paths": { + "@/*": ["./*"], "@ui/*": ["./../../packages/ui/src/*"] // handle ui package paths }, "useDefineForClassFields": true, diff --git a/apps/ui-library/components/command-copy-button.tsx b/apps/ui-library/components/command-copy-button.tsx index 0b832fa0547..369695c8c53 100644 --- a/apps/ui-library/components/command-copy-button.tsx +++ b/apps/ui-library/components/command-copy-button.tsx @@ -3,7 +3,7 @@ import { Check, Copy } from 'lucide-react' import { useEffect, useState } from 'react' -import { useSendTelemetryEvent } from 'lib/telemetry' +import { useSendTelemetryEvent } from '@/lib/telemetry' import { Button_Shadcn_ } from 'ui' export function CommandCopyButton({ command }: { command: string }) { diff --git a/apps/ui-library/config/docs.ts b/apps/ui-library/config/docs.ts index df6701749d0..98a90cb62f1 100644 --- a/apps/ui-library/config/docs.ts +++ b/apps/ui-library/config/docs.ts @@ -1,4 +1,4 @@ -import { SidebarNavGroup } from 'types/nav' +import { SidebarNavGroup } from '@/types/nav' export const gettingStarted: SidebarNavGroup = { title: 'Getting Started', diff --git a/apps/ui-library/contentlayer.config.js b/apps/ui-library/contentlayer.config.js index 3b54addb42b..970780a7548 100644 --- a/apps/ui-library/contentlayer.config.js +++ b/apps/ui-library/contentlayer.config.js @@ -104,6 +104,7 @@ export const Doc = defineDocumentType(() => ({ export default makeSource({ contentDirPath: './content', + disableImportAliasWarning: true, documentTypes: [Doc], mdx: { remarkPlugins: [remarkGfm, codeImport], diff --git a/apps/ui-library/lib/telemetry.ts b/apps/ui-library/lib/telemetry.ts index 804549688cc..07b7fd6e012 100644 --- a/apps/ui-library/lib/telemetry.ts +++ b/apps/ui-library/lib/telemetry.ts @@ -5,7 +5,7 @@ import { useCallback } from 'react' import { sendTelemetryEvent } from 'common' import { TelemetryEvent } from 'common/telemetry-constants' -import { API_URL } from 'lib/constants' +import { API_URL } from '@/lib/constants' export function useSendTelemetryEvent() { const pathname = usePathname() diff --git a/apps/ui-library/tsconfig.json b/apps/ui-library/tsconfig.json index 9e21bf5ea57..7173489db3f 100644 --- a/apps/ui-library/tsconfig.json +++ b/apps/ui-library/tsconfig.json @@ -16,7 +16,6 @@ "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", - "baseUrl": ".", "paths": { "@/*": ["./*"], "@ui/*": ["./../../packages/ui/src/*"], // handle ui package paths diff --git a/apps/www/tsconfig.json b/apps/www/tsconfig.json index 280df54026b..b301eeef9b0 100644 --- a/apps/www/tsconfig.json +++ b/apps/www/tsconfig.json @@ -1,9 +1,12 @@ { "compilerOptions": { + // @deprecated: use @/ instead of importing from root "baseUrl": ".", "paths": { "contentlayer/generated": ["./.contentlayer/generated"], + // ~/ is deprecated, use @/ instead "~/*": ["./*"], + "@/*": ["./*"], "@ui/*": ["./../../packages/ui/src/*"] }, "downlevelIteration": true, diff --git a/blocks/vue/tsconfig.json b/blocks/vue/tsconfig.json index e4e203e6a02..7d0123109ec 100644 --- a/blocks/vue/tsconfig.json +++ b/blocks/vue/tsconfig.json @@ -16,7 +16,6 @@ "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", - "baseUrl": ".", "paths": { "@/*": ["./*"] }, diff --git a/data.sql b/data.sql deleted file mode 100644 index e69de29bb2d..00000000000