Skip to content

feat: supercanvas CLI에 --version 플래그 추가 - #4

Merged
tonite31 merged 2 commits into
mainfrom
tonite31/cli-version
Jul 26, 2026
Merged

tonite31 merged 2 commits into
mainfrom
tonite31/cli-version

Conversation

@tonite31

Copy link
Copy Markdown
Contributor

문제

supercanvas --versionunknown command: --version으로 떨어져서, 설치된 CLI가 몇 버전인지 확인할 방법이 없었다.

0.1.2 릴리스 때 실제로 걸렸다. 스코프 레지스트리 설정 탓에 npm i -g @superself/supercanvas@latest가 0.1.2가 아닌 0.1.0을 설치했는데, CLI로는 그 사실을 확인할 수 없어 npm root -g 경로의 package.json을 직접 열어봐야 했다. PR #2에서 dist가 어떤 엔진으로 렌더됐는지는 Canvas info 모달로 볼 수 있게 됐지만, CLI 쪽에는 같은 문제가 남아 있었다.

변경

bin/supercanvas.mjs 한 파일, 9줄 추가.

  • cmdVersionengineRootpackage.json에서 version을 읽어 한 줄 출력한다. engineRoot는 이미 파일 상단에서 path.dirname(fileURLToPath(import.meta.url)) 기준으로 잡아둔 값이라 전역 설치·임의 cwd에서도 같은 경로를 가리키고, render.mjs가 snapshot에 engine 메타를 심을 때 쓰는 계산과 같다. 하드코딩이 아니므로 릴리스 때 버전이 어긋날 일이 없다.
  • 접두어나 장식 없이 버전 문자열만 내보내 스크립트에서 그대로 파싱된다.
  • --version-vcommands 맵에 등록해 기존 디스패치를 그대로 탄다. 맵에 있으므로 unknown command 경로보다 먼저 잡히고, 새 분기 방식을 들이지 않는다.
  • --help에 항목 한 줄 추가.

검증

package.json의 version은 0.1.2.

$ node bin/supercanvas.mjs --version
0.1.2
$ echo $?
0
$ node bin/supercanvas.mjs -v
0.1.2

임의 cwd(전역 설치 상황)에서도 같은 경로를 찾는다.

$ cd / && node /…/supercanvas/bin/supercanvas.mjs --version
0.1.2

--help 항목 노출.

$ node bin/supercanvas.mjs --help
usage: supercanvas <command>
  …
  migrate [target]                             permanently upgrade schemaVersion to the engine latest
  help                                         print this help
  --version, -v                                print the engine version

기존 하위 명령 회귀 없음.

$ node bin/supercanvas.mjs update --all examples
Updated and verified 1 Canvas package(s).   (exit 0)

$ node update.mjs examples/reading-list
Updated and verified 1 Canvas package(s).   (exit 0)

알 수 없는 명령 처리도 그대로다.

$ node bin/supercanvas.mjs bogus
unknown command: bogus
…                                            (exit 1)

Closes #3

tonite31 and others added 2 commits July 26, 2026 17:50
설치된 CLI가 몇 버전인지 확인할 방법이 없었다. 0.1.2 릴리스 때 스코프
레지스트리 설정 탓에 실제로는 0.1.0이 설치됐는데, CLI로는 그 사실을 알 수
없어 npm root -g 경로의 package.json을 직접 열어봐야 했다.

- cmdVersion이 engineRoot의 package.json에서 version을 읽어 한 줄 출력한다.
  engineRoot는 이미 파일 상단에서 import.meta.url 기준으로 잡아둔 값이라
  전역 설치·임의 cwd에서도 같은 경로를 가리키고, render.mjs가 snapshot에
  engine 메타를 심을 때 쓰는 계산과 같다. 하드코딩이 아니므로 릴리스 때
  버전이 어긋날 일이 없다.
- 접두어나 장식 없이 버전 문자열만 내보내 스크립트에서 그대로 파싱된다.
- --version과 -v를 commands 맵에 등록해 기존 디스패치를 그대로 탄다. 맵에
  있으므로 unknown command 경로보다 먼저 잡히고, 새 분기 방식을 들이지
  않는다.
- --help에 항목 한 줄 추가.

Signed-off-by: rayim <rayim@fxy.global>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
commands는 객체 리터럴이라 toString·constructor·valueOf 같은 이름이
상속된 값으로 조회된다. 디스패치가 !commands[command]로 존재 여부를
판단해서, supercanvas toString 같은 오타가 unknown command로 잡히지 않고
아무 일도 하지 않은 채 exit 0으로 끝났다. CI 스크립트는 이것을 성공으로
읽는다.

Object.hasOwn으로 바꿔 자기 자신이 가진 명령만 디스패치한다. 이번에
--version·-v를 commands 맵에 등록하면서 사용자 입력으로 이 맵을
인덱싱하는 경로가 늘어 함께 고친다.

Signed-off-by: rayim <rayim@fxy.global>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tonite31
tonite31 merged commit eb633fa into main Jul 26, 2026
2 of 3 checks passed
@tonite31
tonite31 deleted the tonite31/cli-version branch July 26, 2026 09:05
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.

feat: supercanvas CLI에 --version 플래그 추가

1 participant