-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat: support typescript #89
Changes from all commits
dd4302e
ed4453d
975ba18
e5a37cb
645a364
4222b74
a670ca6
4606640
ed00eb0
ef2b479
8f46c16
9de39aa
d4475ac
2f806f3
d2cd77e
1c88d0c
711264e
4d9d882
fff57c3
6505b96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
environment: | ||
matrix: | ||
- nodejs_version: '6' | ||
- nodejs_version: '8' | ||
|
||
install: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
require('ts-node').register({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这些配置和 tsconfig 啥关系 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里提供默认值,应用层 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 那最好只读 tsconfig.json,这个默认配置和 ts-node 的有差异? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里的配置是针对 Node 应用的,ts-node 会考虑到前端应用,所以默认值不一样。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 最新的已经去掉默认值了。开发者自己配置 |
||
typeCheck: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
import { Application } from 'egg'; | ||
|
||
export default (app: Application) => { | ||
console.log(`hi, egg, ${app.config.keys}`); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
import { Application, Context } from 'egg'; | ||
|
||
export default (app: Application) => { | ||
app.router.get('/', function* (this: Context) { | ||
this.body = `hi, egg`; | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
export default () => { | ||
const config: any = {}; | ||
config.keys = '123456'; | ||
return config; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "example-ts" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
import { Application, Context } from 'egg'; | ||
import { default as mock, MockOption, BaseMockApplication } from 'egg-mock'; | ||
import * as path from 'path'; | ||
|
||
describe('test/index.test.ts', () => { | ||
let app: BaseMockApplication<Application, Context>; | ||
before(() => { | ||
app = mock.app({ typescript: true } as MockOption); | ||
return app.ready(); | ||
}); | ||
after(() => app.close()); | ||
it('should work', async () => { | ||
await app | ||
.httpRequest() | ||
.get('/') | ||
.expect('hi, egg') | ||
.expect(200); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"moduleResolution": "node", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"pretty": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"skipLibCheck": true, | ||
"skipDefaultLibCheck": true, | ||
"inlineSourceMap": true, | ||
"importHelpers": true | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
console.log('hey, you require me by --require'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
|
||
module.exports = app => { | ||
app.logger.info('###', require('./test.ts').default.name); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
exports.key = '12345'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "ts", | ||
"egg": { | ||
"framework": "aliyun-egg" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
export default { name: 'egg from ts' }; |
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.
这些 flag 能否支持一下在 package.json 中配置,这样就不需要在每个 scripts 中都去加 --ts 了
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.
其实还期望能否有
--require.once
这种 flag,就是能够在跑 egg 应用前跑一段 js,--require 是每起一个 child_process 也都会运行一次,如果我想在跑 egg 前,跑生成 d.ts 的程序(并且 watch 文件更改重新生成 d.ts),其实是不需要每个子进程都跑一次这个的,不然就起了一堆的 watcher 了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.
--require
是加到 execArgv 的,这个在 fork 里面就会默认继承的,所以肯定会跑一次。package.json
那个可以做,下个 PR 看看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.
是啊,--require 是全部会继承的,就是说能否提供个能力,只运行一次的 require?比如在运行 egg 之前跑一次 tsc,或者跑一次 babel parse,这样就不需要在 scripts 中写
tsc && egg-bin dev
或者tsc && egg-bin test
了,再加上支持配置在 package.json 中的话,那 scripts 中就只需要egg-bin dev
及egg-bin test
了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.
这个 PR 做完后,就不需要 tsc 了啊,不是有 ts-node 了么。
你这个需求感觉更类似于 npm scripts 本身的
beforeTest
/beforeStart
的 hookThere 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.
我知道,只是举个 tsc 的例子,对,就是类似于 beforeTest,但是 npm scripts 没有通用的 before,所以想 egg-bin 能否提供
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.
这个不在这个 PR 的范畴内,等这个完后,考虑如何集成你的 ets 的时候再考虑。
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.
OK
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.
tsc 要的,发布构建需要。
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.
tsc 是构建发布那个流程的,这块是开发期辅助,不冲突。
构建那个不会存在他说的 require