feat: supercanvas CLI에 --version 플래그 추가 - #4
Merged
Merged
Conversation
설치된 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
문제
supercanvas --version이unknown 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줄 추가.cmdVersion이engineRoot의package.json에서 version을 읽어 한 줄 출력한다.engineRoot는 이미 파일 상단에서path.dirname(fileURLToPath(import.meta.url))기준으로 잡아둔 값이라 전역 설치·임의 cwd에서도 같은 경로를 가리키고,render.mjs가 snapshot에 engine 메타를 심을 때 쓰는 계산과 같다. 하드코딩이 아니므로 릴리스 때 버전이 어긋날 일이 없다.--version과-v를commands맵에 등록해 기존 디스패치를 그대로 탄다. 맵에 있으므로unknown command경로보다 먼저 잡히고, 새 분기 방식을 들이지 않는다.--help에 항목 한 줄 추가.검증
package.json의 version은
0.1.2.임의 cwd(전역 설치 상황)에서도 같은 경로를 찾는다.
--help항목 노출.기존 하위 명령 회귀 없음.
알 수 없는 명령 처리도 그대로다.
Closes #3