From 739c38e1c1ebea8e03f55bf0e8b1436f35b0be26 Mon Sep 17 00:00:00 2001 From: Yo Iwamoto Date: Sat, 21 Sep 2024 18:05:07 +0900 Subject: [PATCH] use subpath imports instead of tsc path alias --- .storybook/preview.ts | 2 +- .vscode/settings.json | 3 +-- components.json | 4 ++-- package.json | 8 +++++--- pnpm-lock.yaml | 6 +++--- src/app/_internal/post-card-list/post-card-list.tsx | 6 +++--- src/app/_internal/root-layout/nav-link.tsx | 2 +- src/app/_internal/root-layout/root-layout.tsx | 4 ++-- src/app/layout.tsx | 4 ++-- src/app/page.tsx | 4 ++-- src/app/posts/[slug]/generate-metadata.ts | 4 ++-- src/app/posts/[slug]/generate-static-params.ts | 2 +- src/app/posts/[slug]/page.tsx | 8 ++++---- src/app/tags/[slug]/generate-static-params.ts | 2 +- src/app/tags/[slug]/page.tsx | 6 +++--- src/app/tags/page.tsx | 6 +++--- src/components/sized-box/sized-box.tsx | 2 +- src/components/text/text.tsx | 2 +- src/components/ui/button.tsx | 2 +- tsconfig.json | 5 +---- 20 files changed, 40 insertions(+), 42 deletions(-) diff --git a/.storybook/preview.ts b/.storybook/preview.ts index 1cacbfa..67e6ab8 100644 --- a/.storybook/preview.ts +++ b/.storybook/preview.ts @@ -1,4 +1,4 @@ -import "@/styles/global.scss"; +import "#src/styles/global.scss"; import type { Preview } from "@storybook/react"; const preview: Preview = { diff --git a/.vscode/settings.json b/.vscode/settings.json index cc4db33..bb34a4d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,5 @@ "source.fixAll.eslint": "explicit" }, "eslint.validate": ["typescript", "typescriptreact"], - "typescript.tsdk": "node_modules/.pnpm/typescript@5.0.4/node_modules/typescript/lib", - "typescript.enablePromptUseWorkspaceTsdk": true + "biome.enabled": true } diff --git a/components.json b/components.json index 9116397..00bf1c1 100644 --- a/components.json +++ b/components.json @@ -10,7 +10,7 @@ "cssVariables": true }, "aliases": { - "components": "@/components", - "utils": "@/lib/utils" + "components": "#src/components", + "utils": "#src/lib/utils" } } diff --git a/package.json b/package.json index 72976dc..94d36b8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "blog.yoiw.dev", "license": "MIT", - "packageManager": "pnpm@8.15.6", + "packageManager": "pnpm@9.11.0", "scripts": { "prepare": "git config core.hooksPath .githooks", "dev": "pnpm run '/^dev:.*/'", @@ -22,6 +22,9 @@ "build-storybook": "storybook build", "chromatic": "chromatic" }, + "imports": { + "#*": ["./*", "./*.ts", "./*.tsx", "./*/index.ts", "./*/index.tsx"] + }, "dependencies": { "@radix-ui/react-slot": "1.1.0", "class-variance-authority": "0.7.0", @@ -73,6 +76,5 @@ "unified": "11.0.5", "vite-plugin-environment": "1.1.3", "vitest": "2.1.1" - }, - "version": "" + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cb82717..0d8d5f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -83,7 +83,7 @@ importers: version: 6.5.0 '@testing-library/react': specifier: 16.0.1 - version: 16.0.1(@testing-library/dom@9.3.4)(@types/react-dom@18.3.0)(@types/react@18.3.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + version: 16.0.1(@testing-library/dom@10.4.0)(@types/react-dom@18.3.0)(@types/react@18.3.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@types/jsdom': specifier: 21.1.7 version: 21.1.7 @@ -6849,10 +6849,10 @@ snapshots: lodash: 4.17.21 redent: 3.0.0 - '@testing-library/react@16.0.1(@testing-library/dom@9.3.4)(@types/react-dom@18.3.0)(@types/react@18.3.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@testing-library/react@16.0.1(@testing-library/dom@10.4.0)(@types/react-dom@18.3.0)(@types/react@18.3.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: '@babel/runtime': 7.25.6 - '@testing-library/dom': 9.3.4 + '@testing-library/dom': 10.4.0 react: 18.3.1 react-dom: 18.3.1(react@18.3.1) optionalDependencies: diff --git a/src/app/_internal/post-card-list/post-card-list.tsx b/src/app/_internal/post-card-list/post-card-list.tsx index c19dfae..9a84244 100644 --- a/src/app/_internal/post-card-list/post-card-list.tsx +++ b/src/app/_internal/post-card-list/post-card-list.tsx @@ -1,6 +1,6 @@ -import { Link } from "@/components/link"; -import { Text } from "@/components/text"; -import { cn } from "@/lib/utils"; +import { Link } from "#src/components/link"; +import { Text } from "#src/components/text/text.jsx"; +import { cn } from "#src/lib/utils"; import type { PropsWithChildren } from "react"; function PostCardListRoot({ children }: PropsWithChildren) { diff --git a/src/app/_internal/root-layout/nav-link.tsx b/src/app/_internal/root-layout/nav-link.tsx index f192c55..53cbd29 100644 --- a/src/app/_internal/root-layout/nav-link.tsx +++ b/src/app/_internal/root-layout/nav-link.tsx @@ -1,6 +1,6 @@ "use client"; -import { cn } from "@/lib/utils"; +import { cn } from "#src/lib/utils"; import Link from "next/link"; import { usePathname } from "next/navigation"; import type { PropsWithChildren } from "react"; diff --git a/src/app/_internal/root-layout/root-layout.tsx b/src/app/_internal/root-layout/root-layout.tsx index 89dec28..6d00f38 100644 --- a/src/app/_internal/root-layout/root-layout.tsx +++ b/src/app/_internal/root-layout/root-layout.tsx @@ -1,5 +1,5 @@ -import { Link } from "@/components/link"; -import { SizedBox } from "@/components/sized-box"; +import { Link } from "#src/components/link"; +import { SizedBox } from "#src/components/sized-box"; import type { PropsWithChildren } from "react"; import { NavLink } from "./nav-link"; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 68b940b..167e693 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,5 +1,5 @@ -import { getServerSideEnv } from "@/config/env"; -import "@/styles/global.scss"; +import { getServerSideEnv } from "#src/config/env"; +import "#src/styles/global.scss"; import type { Metadata } from "next"; import type { PropsWithChildren } from "react"; import { RootLayout } from "./_internal/root-layout"; diff --git a/src/app/page.tsx b/src/app/page.tsx index 78eb37c..0c865f4 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,5 @@ -import { Text } from "@/components/text"; -import { allEntries } from "@/data/contents"; +import { Text } from "#src/components/text"; +import { allEntries } from "../data/contents"; import { PostCardList } from "./_internal/post-card-list"; export const dynamic = "force-static"; diff --git a/src/app/posts/[slug]/generate-metadata.ts b/src/app/posts/[slug]/generate-metadata.ts index 5de82e9..9870efe 100644 --- a/src/app/posts/[slug]/generate-metadata.ts +++ b/src/app/posts/[slug]/generate-metadata.ts @@ -1,5 +1,5 @@ -import { allEntries } from "@/data/contents"; -import { extractTextFromArticleHtml } from "@/lib/extract-text-from-article-html"; +import { allEntries } from "#src/data/contents"; +import { extractTextFromArticleHtml } from "#src/lib/extract-text-from-article-html"; import type { Metadata } from "next"; import { notFound } from "next/navigation"; diff --git a/src/app/posts/[slug]/generate-static-params.ts b/src/app/posts/[slug]/generate-static-params.ts index 19226c1..dd00d8c 100644 --- a/src/app/posts/[slug]/generate-static-params.ts +++ b/src/app/posts/[slug]/generate-static-params.ts @@ -1,4 +1,4 @@ -import { allEntries } from "@/data/contents"; +import { allEntries } from "#src/data/contents"; export function generateStaticParams() { const articles = allEntries; diff --git a/src/app/posts/[slug]/page.tsx b/src/app/posts/[slug]/page.tsx index ca84f3e..ec65c19 100644 --- a/src/app/posts/[slug]/page.tsx +++ b/src/app/posts/[slug]/page.tsx @@ -1,7 +1,7 @@ -import { Link } from "@/components/link"; -import { Text } from "@/components/text"; -import { allEntries } from "@/data/contents"; -import "@/styles/post-body.scss"; +import { Link } from "#src/components/link"; +import { Text } from "#src/components/text"; +import { allEntries } from "#src/data/contents"; +import "#src/styles/post-body.scss"; import { notFound } from "next/navigation"; import HighlightNode from "./_internal/highlight-node-internal"; diff --git a/src/app/tags/[slug]/generate-static-params.ts b/src/app/tags/[slug]/generate-static-params.ts index 9a232bb..8ae2dbb 100644 --- a/src/app/tags/[slug]/generate-static-params.ts +++ b/src/app/tags/[slug]/generate-static-params.ts @@ -1,4 +1,4 @@ -import { allEntries } from "@/data/contents"; +import { allEntries } from "#src/data/contents"; export function generateStaticParams() { const tags = new Set(); diff --git a/src/app/tags/[slug]/page.tsx b/src/app/tags/[slug]/page.tsx index 340794b..7c84c50 100644 --- a/src/app/tags/[slug]/page.tsx +++ b/src/app/tags/[slug]/page.tsx @@ -1,6 +1,6 @@ -import { PostCardList } from "@/app/_internal/post-card-list"; -import { Text } from "@/components/text"; -import { allEntries } from "@/data/contents"; +import { PostCardList } from "#src/app/_internal/post-card-list"; +import { Text } from "#src/components/text"; +import { allEntries } from "#src/data/contents"; import { notFound } from "next/navigation"; export { generateMetadata } from "./generate-metadata"; diff --git a/src/app/tags/page.tsx b/src/app/tags/page.tsx index 63f2c96..574e32d 100644 --- a/src/app/tags/page.tsx +++ b/src/app/tags/page.tsx @@ -1,6 +1,6 @@ -import { Link } from "@/components/link"; -import { Text } from "@/components/text"; -import { allEntries } from "@/data/contents"; +import { Link } from "#src/components/link"; +import { Text } from "#src/components/text"; +import { allEntries } from "#src/data/contents"; import type { Metadata } from "next"; export const metadata = { diff --git a/src/components/sized-box/sized-box.tsx b/src/components/sized-box/sized-box.tsx index 0f6c51b..c01bc21 100644 --- a/src/components/sized-box/sized-box.tsx +++ b/src/components/sized-box/sized-box.tsx @@ -1,4 +1,4 @@ -import { cn } from "@/lib/utils"; +import { cn } from "#src/lib/utils"; import type { ElementType, PropsWithChildren } from "react"; type Props = PropsWithChildren & { diff --git a/src/components/text/text.tsx b/src/components/text/text.tsx index 620de1d..cbe52b3 100644 --- a/src/components/text/text.tsx +++ b/src/components/text/text.tsx @@ -1,4 +1,4 @@ -import { cn } from "@/lib/utils"; +import { cn } from "#src/lib/utils.js"; import type { PropsWithChildren } from "react"; import type { ComponentPropsWithoutRef, ElementType } from "react"; diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx index 84f9ec9..bea281c 100644 --- a/src/components/ui/button.tsx +++ b/src/components/ui/button.tsx @@ -1,4 +1,4 @@ -import { cn } from "@/lib/utils"; +import { cn } from "#src/lib/utils"; import { Slot } from "@radix-ui/react-slot"; import { type VariantProps, cva } from "class-variance-authority"; import * as React from "react"; diff --git a/tsconfig.json b/tsconfig.json index 57b7a5f..2ff46ee 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "ESNext", "lib": ["ESNext", "DOM", "DOM.Iterable"], - "moduleResolution": "Node", + "moduleResolution": "Bundler", "strict": true, "esModuleInterop": true, "noEmit": true, @@ -16,9 +16,6 @@ "isolatedModules": true, "incremental": false, "baseUrl": ".", - "paths": { - "@/*": ["src/*"] - }, "module": "esnext", "resolveJsonModule": true, "types": ["vitest/globals"],