-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Typescript for only Tests #13
Conversation
.vscode/settings.json
Outdated
@@ -4,5 +4,20 @@ | |||
"editor.insertSpaces": true, | |||
"files.trimTrailingWhitespace": true, | |||
"files.autoSave": "onFocusChange", | |||
"files.exclude": { | |||
"**/.git": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
デフォルト設定も書く必要あります?
excludeしたいものだけを書くと、上書きではなく追加されるように見えますが。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修正しました 🙏 ->
test/resolver.js
Outdated
@@ -0,0 +1,16 @@ | |||
const tsConfigPaths = require('tsconfig-paths'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[eslint]
- Error - Unable to resolve path to module 'tsconfig-paths'. (import/no-unresolved)
test/resolver.js
Outdated
@@ -0,0 +1,16 @@ | |||
const path = require('path'); | |||
const tsConfigPaths = require('tsconfig-paths'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[eslint]
- Error - Unable to resolve path to module 'tsconfig-paths'. (import/no-unresolved)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
package.json
Outdated
"react-dom": "^15.4.1", | ||
"source-map-support": "^0.4.15", | ||
"ts-node": "^3.0.4", | ||
"tsconfig-paths": "^2.1.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tsconfig-pathsはなぜ必要なんですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ts-node
が最初にコンパイルして出力したファイルを実行する時、パス解決をするために必要だからです。
つまり、ts-node
と babel-plugin-resolver
相当の機能(compulerOptions
の baseUrl/paths
を組み合わせて設定する)ために、tsconfig-paths
が必要ということです。
tsconfig-paths is not necessary
拡張子の件はこのコミットでやりました -> |
const originalLoader = Module._load; | ||
const patchedLoader = (request, parent, isMain) => { | ||
try { | ||
return originalLoader.call(null, request, parent, isMain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node.jsの Module.__load
にパッチを当てています https://github.com/nodejs/node/blob/master/lib/module.js#L432
これが見つからなかったら .jsx
拡張子を当てて再度ロードするようにしています。本体であればいくつかのケースに備えて作る必要がありそうですが、本質的にはこのような解決策でいけそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最終的にすべてのファイルが TypeScript 化し、resolveする必要がなくなったらこのファイルをまるっと消せば良さそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど。いずれ消す前提ならこれでいいと思います。
LGTM |
ありがとうございます 🙏 |
👀 |
This PR
tsconfig.json
)ts-node
to transpile TypeScript filesbaseOptions/paths
compilerOptions along withts-ndoe