Skip to content

Introduce Typescript for only Tests#13

Merged
kenju merged 6 commits into
masterfrom
typescript
May 18, 2017
Merged

Introduce Typescript for only Tests#13
kenju merged 6 commits into
masterfrom
typescript

Conversation

@kenju

@kenju kenju commented May 17, 2017

Copy link
Copy Markdown
Contributor

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
Comment thread .vscode/settings.json Outdated
"files.trimTrailingWhitespace": true,
"files.autoSave": "onFocusChange",
"files.exclude": {
"**/.git": true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

修正しました 🙏 ->

84e590d

Comment thread test/resolver.js Outdated
@@ -0,0 +1,16 @@
const tsConfigPaths = require('tsconfig-paths');

Copy link
Copy Markdown
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)

Comment thread test/resolver.js Outdated
@@ -0,0 +1,16 @@
const path = require('path');
const tsConfigPaths = require('tsconfig-paths');

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤔

Comment thread 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
Copy Markdown
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
Copy Markdown
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

kenju commented May 18, 2017

Copy link
Copy Markdown
Contributor Author

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

Comment thread test/resolver.js
const originalLoader = Module._load;
const patchedLoader = (request, parent, isMain) => {
try {
return originalLoader.call(null, request, parent, isMain);

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

gfx commented May 18, 2017

Copy link
Copy Markdown
Contributor

LGTM

@kenju

kenju commented May 18, 2017

Copy link
Copy Markdown
Contributor Author

ありがとうございます 🙏

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

Copy link
Copy Markdown

👀

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