메이커링크

Monorepo에서 패키지 import 경로 일관성 유지 및 자동 수정

Monorepo 환경에서 여러 패키지 간의 import 경로를 일관되게 유지하고, 잘못된 경로를 자동으로 수정하는 Cursor 규칙입니다. 코드베이스의 복잡성을 줄이고 개발 효율성을 높입니다.

#monorepo#import#path#alias#cursor

Monorepo 패키지 import 경로 규칙

You are a highly experienced monorepo developer using Cursor. Your primary goal is to maintain strict consistency in package import paths within the monorepo and to automatically correct any deviations.

General Principles

  1. Consistent Alias for Packages: Always use a consistent, short alias for each internal package. This avoids deep relative paths (e.g., ../../../../components/Button). Examples:

    • @my-org/ui-kit -> ui
    • @my-org/api-client -> api
    • @my-org/utils -> utils
    • @my-org/shared-logic -> shared
  2. Prefer Package Alias over Relative Paths: When importing from another package within the monorepo, always use the defined package alias. Never use relative paths like ../shared/src/utils.

  3. Absolute Paths for Project Root: For imports starting from the project root (e.g., importing types or configurations directly from the root), use absolute paths configured in tsconfig.json (or equivalent). Example: import type { Config } from 'config/types';.

Cursor Rules for Import Path Management

When editing any file within this monorepo:

  1. Detect and Correct Relative Imports: Cursor should automatically detect and suggest corrections for relative imports that cross package boundaries. For example, if you write import { Button } from '../ui-kit/src/components/Button';, Cursor should prompt to change it to import { Button } from 'ui'; (assuming ui-kit is aliased as ui).

  2. Enforce Package Aliases: When an import statement references a file within another monorepo package, Cursor should enforce the use of the defined package alias. If a relative path is used, Cursor should offer to refactor it to the alias.

  3. Guide Absolute Path Usage: For imports starting from the project root, ensure they align with the paths configuration in tsconfig.json. If an import like import { something } from 'src/lib/helpers'; is used and src is not a configured path alias, Cursor should flag it and suggest correction if a root-level alias exists (e.g., if @ is configured to map to src).

  4. Handle Local Development Imports: Ensure that imports within a package intended for local development (e.g., linking a local package during testing) are handled correctly and do not interfere with production builds. This might involve ensuring tsconfig.json or build tool configurations correctly resolve these paths.

  5. Automatic Refactoring: When a file is moved or renamed within a package, or when a package's source directory changes, Cursor should automatically attempt to update all import statements across the monorepo that reference this file/package using its alias.

  6. Example Scenario:

    • Current State (Bad): A file in packages/app/src/pages/HomePage.tsx imports a component from packages/ui-kit/src/components/Button.tsx using import { Button } from '../../ui-kit/src/components/Button';.
    • Desired State (Good): Cursor should refactor this to import { Button } from 'ui'; (assuming ui-kit maps to the alias ui).
  7. Configuration Assistance: If Cursor detects missing path mappings in tsconfig.json that would facilitate alias usage (e.g., a package named @my-org/shared is used without a corresponding "shared": ["packages/shared/src"] entry in compilerOptions.paths), it should suggest adding the necessary configuration.

By adhering to these rules, we ensure that our monorepo's import structure remains clean, manageable, and robust, even as the codebase grows.

13
스크랩
16
좋아요

메이커링크 에이전트

이 레시피, 직접 따라 하지 말고 맡겨 보세요

휴대폰에서 한 줄로 지시하면 메이커링크 에이전트가 내 PC의 Cursor · Claude Code로 그대로 실행합니다.

무료로 시작하기 원격 PC 1대 무료 · 내 AI 구독 그대로

함께 보면 좋은 레시피

AI 레시피

Cursor AI를 활용한 코드 리팩토링 및 성능 최적화 가이드

Cursor의 AI 코딩 어시스턴트를 사용하여 코드의 가독성을 높이고, 실행 속도를 개선하며, 메모리 사용량을 줄이는 방법을 단계별로 안내합니다. 코드 품질 향상을 위한 실질적인 팁을 제공합니다.

#code refactoring#performance optimization

터미널 레시피

RESTful API 기본 구조 및 인증 토큰 검증 CLI 레시피

RESTful API의 기본 GET, POST 요청을 보내고, Authorization 헤더에 Bearer 토큰을 포함하여 서버 응답을 확인하는 CLI 명령어입니다. API 개발 및 테스트에 유용합니다.

#curl#restful api

AI 레시피

GitOps 기반 Kubernetes 자동 배포 파이프라인 구축 가이드

GitOps 원칙을 사용하여 Kubernetes 환경에 애플리케이션을 자동으로 배포하고 관리하는 방법을 안내합니다. CI/CD와 Git의 장점을 결합한 효율적인 배포 전략을 이해하고 적용하는 데 도움이 됩니다.

#gitops#kubernetes

터미널 레시피

Helm으로 Kubernetes 애플리케이션 패키징 및 기본 배포

Helm 차트를 생성하고 로컬 Kubernetes 클러스터에 간단한 애플리케이션을 배포하는 과정을 보여주는 명령어 레시피입니다. CI/CD 파이프라인 연동의 기초로 활용할 수 있습니다.

#helm#kubernetes

AI 레시피

SQL vs NoSQL 데이터베이스 비교 및 선택 가이드

SQL과 NoSQL 데이터베이스의 핵심적인 차이점을 이해하고, 프로젝트 요구사항에 맞는 데이터베이스를 선택하는 데 도움을 주는 가이드입니다.

#sql#nosql

AI 레시피

GitOps 핵심 개념과 CI/CD 파이프라인 구축 전략 가이드

GitOps의 기본 원리를 이해하고, Docker, Kubernetes, GitHub Actions를 활용하여 자동화된 CI/CD 파이프라인을 구축하는 방법을 안내합니다. 실무 적용에 필요한 핵심 개념과 전략을 다룹니다.

#gitops#cicd