Skip to content
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

Merged
merged 6 commits into from
May 18, 2017
Merged

Introduce Typescript for only Tests #13

merged 6 commits into from
May 18, 2017

Conversation

kenju
Copy link
Contributor

@kenju kenju commented May 17, 2017

This PR

  • introduces basic configuration for TypeScript ( tsconfig.json )
  • use ts-node to transpile TypeScript files
  • use baseOptions/paths compilerOptions along with ts-ndoe
  • fix failing test only on CI
  • integrate TypeScript with coverate (nyc)

@kenju kenju changed the title Introduce Typescript for only Tests [WIP] Introduce Typescript for only Tests May 17, 2017
@@ -4,5 +4,20 @@
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
"files.autoSave": "onFocusChange",
"files.exclude": {
"**/.git": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

デフォルト設定も書く必要あります?

excludeしたいものだけを書くと、上書きではなく追加されるように見えますが。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました 🙏 ->

84e590d

test/resolver.js Outdated
@@ -0,0 +1,16 @@
const tsConfigPaths = require('tsconfig-paths');
Copy link
Contributor Author

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');
Copy link
Contributor Author

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)

Copy link
Contributor Author

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsconfig-pathsはなぜ必要なんですか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts-node が最初にコンパイルして出力したファイルを実行する時、パス解決をするために必要だからです。

つまり、ts-nodebabel-plugin-resolver相当の機能(compulerOptionsbaseUrl/paths を組み合わせて設定する)ために、tsconfig-paths が必要ということです。

TypeStrong/ts-node#138 (comment)

@kenju
Copy link
Contributor Author

kenju commented May 18, 2017

拡張子の件はこのコミットでやりました ->
14e77dd

const originalLoader = Module._load;
const patchedLoader = (request, parent, isMain) => {
try {
return originalLoader.call(null, request, parent, isMain);
Copy link
Contributor Author

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 拡張子を当てて再度ロードするようにしています。本体であればいくつかのケースに備えて作る必要がありそうですが、本質的にはこのような解決策でいけそうです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最終的にすべてのファイルが TypeScript 化し、resolveする必要がなくなったらこのファイルをまるっと消せば良さそうです。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど。いずれ消す前提ならこれでいいと思います。

@kenju kenju changed the title [WIP] Introduce Typescript for only Tests Introduce Typescript for only Tests May 18, 2017
@gfx
Copy link
Contributor

gfx commented May 18, 2017

LGTM

@kenju
Copy link
Contributor Author

kenju commented May 18, 2017

ありがとうございます 🙏

@kenju kenju merged commit 8fed1e9 into master May 18, 2017
@michiomochi
Copy link

👀

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.

3 participants