Skip to content

fix(kopis-cli): CJS 듀얼 빌드로 attw 경고 해소 - #24

Merged
yungblud merged 2 commits into
mainfrom
fix/attw-cjs-dual-build
Jul 29, 2026
Merged

yungblud merged 2 commits into
mainfrom
fix/attw-cjs-dual-build

Conversation

@yungblud

Copy link
Copy Markdown
Contributor

Closes #23

배경

@coldsurf/tickets@0.10.1 에서 attw(are the types wrong) 경고가 떴습니다.

node10             🟢
node16 (from CJS)  ⚠️ ESM (dynamic import only)   ← CJSResolvesToESM
node16 (from ESM)  🟢 (ESM)
bundler            🟢

패키지가 "type": "module" + tsup format: ['esm'] 로 ESM 단독 산출물만 내보내고 exports 에 require 조건이 없어서, CJS 소비자가 require('@coldsurf/tickets') 하면 ESM 파일로 해결됩니다. Node에서는 에러가 나고 await import() 로만 쓸 수 있는 상태였습니다.

변경사항

듀얼 빌드

  • tsup.config.ts — SDK 엔트리를 format: ['esm', 'cjs'] 로. CLI/MCP bin 엔트리는 실행 파일이라 ESM 그대로 둡니다.
  • package.json — exports 를 import/require 조건별로 분리하고 각 조건 안에 types 를 최상단 배치. node10 폴백(main/types)은 CJS 산출물로 정렬했습니다(폴백끼리 포맷이 어긋나면 attw가 FalseCJS 를 새로 띄웁니다). 레거시 번들러용 module 필드 추가.

회귀 방지

  • check:attw 스크립트(attw --pack .) 추가 — 임시 tarball을 직접 말아서 검사하므로 실제 배포될 산출물 기준으로 검증됩니다.
  • turbo.json 에 check:attw 태스크 등록(dependsOn: ["build"]), 루트에 pnpm check:attw 연결.

검증

항목 결과
pnpm check:attw node10 / node16-CJS / node16-ESM / bundler 전부 🟢, No problems found
require("@coldsurf/tickets") ✅ createKopisClient 포함 7개 export
import { ... } ✅ KOPIS_AREAS 17개 area
tickets --help ✅ 정상

packed tarball을 실제로 npm i 한 임시 프로젝트에서 bare specifier 해석까지 확인했습니다.

참고

dual package hazard(ESM/CJS 인스턴스가 각각 로드되는 문제)는 이 SDK가 모듈 레벨 싱글턴 없이 createKopisClient 로 객체만 만들어 반환하는 구조라 현재는 무해합니다. 추후 모듈 스코프 캐시나 instanceof 체크(KopisApiError 등)를 도입하면 다시 볼 지점입니다.

🤖 Generated with Claude Code

yungblud and others added 2 commits July 29, 2026 10:45
- tsup에서 SDK 엔트리를 esm/cjs 양쪽으로 빌드
- exports를 import/require 조건별로 분리하고 조건마다 types를 최상단에 배치
- node10 폴백(main/types)을 CJS 산출물(index.cjs/index.d.cts)로 정렬
- attw 검사 스크립트(check:attw)와 turbo 태스크 추가

Closes #23

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
빌드 산출물의 CJS/ESM 해석을 CI에서 검증하도록 `pnpm turbo check:attw` 스텝을
추가했습니다. build 스텝은 명시적으로 남겨 워크플로우만 봐도 흐름이 보이게 했고,
중복 실행은 turbo 캐시가 흡수합니다(두 번째 호출은 build 캐시 히트).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@yungblud
yungblud merged commit c5e1a53 into main Jul 29, 2026
1 check passed
@yungblud
yungblud deleted the fix/attw-cjs-dual-build branch July 29, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

attw issue

1 participant