build(tsconfig): introduce tsconfig.build.json#463
build(tsconfig): introduce tsconfig.build.json#463jjangga0214 wants to merge 13 commits intostorycraft:devfrom
Conversation
일시적인 이용자 보호 조치 상태일 시 해당 코드 반환
Update index.ts
Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 5.1.1 to 5.1.2. - [Release notes](https://github.com/gulpjs/glob-parent/releases) - [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md) - [Commits](gulpjs/glob-parent@v5.1.1...v5.1.2) --- updated-dependencies: - dependency-name: glob-parent dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
chore(examples): fix comment about device uuid api usage
package.json
Outdated
| "promise-socket": "^7.0.0" | ||
| }, | ||
| "ts-node": { | ||
| "transpileOnly": true, |
There was a problem hiding this comment.
https://typestrong.org/ts-node/docs/transpilers/#bundled-swc-integration
- In transpile-only mode, we skip type checking to speed up execution time.
swc를 사용하기 위함외에, 트랜스파일링 전용 모드로 설정해야만 하는 이유가 있나요?
There was a problem hiding this comment.
문서에는 명확하게 명시되어 있지 않지만, --transpiler 옵션은 --transpileOnly=true 여야만 가능합니다.
/**
* Specify a custom transpiler for use with transpileOnly
*/
transpiler?: string | [string, object]; if (options.transpiler) {
if (!transpileOnly)
throw new Error(
'Custom transpiler can only be used when transpileOnly is enabled.'
);ts-node 공식 문서에서는 다음과 같이 표현하고 있습니다.
What is the difference between a compiler and a transpiler?For our purposes, a compiler implements TypeScript's API and can perform typechecking. A third-party transpiler does not. Both transform TypeScript into JavaScript.
비록 일반적으론 tsc 같은 경우도 transpiler 라고 해도 이론상 문제는 없지만, ts-node 에서 사용하는 용어 정의에 따라면 transpiler 란 type-check 기능이 없는 프로그램을 뜻합니다. 그래서 애초에 3rd party compiler/transpiler 설정을 나눠놓았습니다.
(앞서 서술했다시피 swc 는 type-checking 기능을 구현중이고, 적어도 수개월 후 완성가능할 것으로 보이며, 아직 제공하지는 않습니다. swc-project/swc#571)
따라서 용어 그대로 --transpiler 와 --transpileOnly=false 를 동시 설정가능하려면 compiler 에게는 type checking 을 맡기고(e.g. tsc --noEmit), transpiler 에게 transpiling 을 맡겨야 합니다.
그런데, tsc 의 type checking 은 너무 느립니다. 얼마나 느리냐면 (벤치마크는 없지만 기억상 제 이전 프로젝트에서는) tsc --noEmit + swc 조합과 tsc 를 비교해서 차이가 나긴 해도 크지 않습니다. 따라서 사실상 incremental 하게 type 을 check 해야 하는데 (--incremental option 과 --noEmit 의 병용), 최근까지는 tsc 가 지원하지 않다가 얼마 전 가능해졌습니다. (microsoft/TypeScript#39122).
따라서 --transpiler 와 --transpileOnly=false 의 병용이 개인적으로는 이론적으로 가능하다보는데, 안타깝게도 ts-node 가 --incremental 옵션 자체를 지원하지 않습니다. (TypeStrong/ts-node#817) .tsbuildinfo 파일 자체를 저장하지 않는거죠.
Workaround 로 type-checking 을 transpiling+execution 과 병렬적으로(e.g. npm:concurrently 돌리는 방법이 있으나 터미널이 지저분해지는 단점이 있고, IDE 에서 type-checking 이 다 되는 이상 굳이 "매번" 실행할 필요는 느끼지 못하였습니다.
그래서, 개인적으로 CI 에서 type checking 을 실행하는 것을 추천드립니다.
From package.json to tsconfig.json
|
94bf42f: ts-node 설정이 tsconfig.json 에 있어야 하는데, 실수로 package.json 에 적었던 문제를 수정했습니다. |
|
여담) 본 PR 을 긍정적으로 평가(good) 하시는 뜻으로 사용해주셨다면 정말로 감사합니다. |
This enables importing not only from "node-kakao" but also "node-kakao/another/different/module.ts".
안녕하세요.
examples 를 보던 중 다음과 같은 오류를 발견했습니다.
(node_modules 에 node-kakao 가 있을리 없으니) 해당 모듈을 찾을 수 없다는 오류였습니다.
examples 은 사용 예시일 뿐이고 publish 대상도 아니므로, 오류의 여부와 관계없이 로컬에서 그냥 snippet 을 작성하여 commit 하셨을 줄로 짐작합니다.
하지만 장기적으로 유지보수해가는 측면에서, 아무리 examples 이라도
라는 점은 꽤나 불편하다고 생각했습니다. 코드를 검증하려면 항상 따로 파일을 생생해봐야 한다는 뜻이니까요.
1번과 같은 경우도 CI 나 로컬에서
tsc --noEmit정도만 해줘도 #458 과 같은 변경이 필요함을 훨씬 빨리 알아챌 수 있었을 텐데요.해서, 이 문제들을 해결하기 위해
A.
baseUrl과paths를 도입했습니다. 따라서 node_modules 에node-kakao가 존재하지 않아도 컴파일러 차원에서 module resolution 이 가능합니다.B.
ts-node가 (매번 CLI option 입력없이도)tsconfig-paths/register를--require하도록 했습니다 (ts-node 설정 문서). tsconfig.json 의 paths 를 보고 인식할 수 있습니다.C. tsconfig.json 에서
include와exclude를 삭제했습니다. 대개 IDE 는 (특히 vscode 는 절대적으로) tsconfig.json 를 바라봅니다.개발환경에서는 examples 가
exclude되지 않아야 (include되어야) IDE 가 타입 검증을 할 수 있습니다. 이는 tests 도 마찬가지 입니다. 따라서 tsconfig.json 은 프로젝트의 모든 .ts 파일을 아우르도록 했습니다.D. tsconfig.build.json 을 생성했습니다. build 시에는 해당 설정을 이용하도록 했습니다.
P.S. 테스트 파일은
tests/**/*.test.ts인데, tsconfig.json 은**/*.spec.ts을exclude하더군요. 그래서**/*.test.ts와tests를 추가했습니다. (tests/**/*.test.ts와 같이 하나의 경로만 추가하거나**/*.spec.ts을 삭제하지 않은 이유는 나중에 test 파일 배치 규칙이 변경되었을때에도 유연하게 대응하도록 하기 위함입니다.) (include가 명시되었을시,exclude는 include 대상에서 filtering 하는 방식이라 이미include에src/**/*가 명시된 이상 최상위 디렉토리인tests등을exclude하는 것이 무의미하긴 하지만, 그래도dist도 동일한 입장에도 이미exclude에 존재하고 있었으므로 변경의 유연성 측면에서 추가하였습니다.)P.S.2.
ts-node설정에swc사용을 추가했습니다 (ts-node 설정 문서). 해당 설정으로ts-node는 내부적으로tsc대신swc를 사ㅇ합니다.swc는 Rust 로 쓰인 (그래서 빠른) babel 로 생각하면 됩니다. 아무래도 개발환경에서는 소스를 수정하고 다양한 (수동, 자동) 테스트를 여러번 거치게 되므로 해당 설정이 유용하다 생각합니다.swc는 아직(미정) type checking 을 지원하지 않으므로, IDE 가 있음에도 한번 더 검증하고자 하는 경우tsc --noEmit한번 실행해주면 됩니다.