-
Notifications
You must be signed in to change notification settings - Fork 92
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 ts by env #158
Conversation
Codecov Report
@@ Coverage Diff @@
## master #158 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 17 17
Lines 893 891 -2
=====================================
- Hits 893 891 -2
Continue to review full report at Codecov.
|
原来的逻辑删了? |
@popomore 原来的不能删,因为之前的版本 egg-bin 不是所有 command 都设置了环境变量,如果原来的删了就 break 了 |
@whxaxes 只要开发者同时升级 egg-bin 和 egg-core 后不 break 就不算吧 删除原来逻辑指的是删除哪些? |
@atian25 是指删除 option,统一由 env 来控制 |
应该不会不兼容吧,原来也就兼容了 dev、test、cov 这些命令,现在所有都支持了这个配置了。所以在 egg-core 只要根据这个环境变量来判断就好了。 |
你改一下原来的用例,入口都换成这个变量,看是否有问题。 |
@popomore 原来 egg-bin 只在 test 命令下才会设置 env |
所以我才提了这个 PR:eggjs/bin#98 给所有 command 加上 env |
或者就先发了 egg-bin 的这个版本,然后我再把 egg-core 改成基于 env ? |
egg-bin 已经发了 |
好,我改一下 |
删除 options 的话, egg-scripts, egg-cluster 等地方岂不是也要改? |
@atian25 break 倒不会,只是要改一下 unittest,把 option 全部去掉,ts 开启的链路就会变得比之前简单很多,就是 egg-bin 开启 env,egg-core 读取 env 启用 ts |
已经移除 option 了 |
还有其他问题么? |
egg-scripts 应该不会传 typescript 吧 |
@popomore
|
好像只是加了个 sourcemap,和 egg-core 没关系 |
egg-mock 和 egg-scripts 的再评估一下?这里没啥问题了。 |
https://github.com/eggjs/egg-mock/pull/73/files 这里之前就已经干掉 options 了,再优化下写法应该就 ok 了。 @whxaxes 跟进下。 |
egg-scripts 那个没有传递东西,只是自己 require,应该没事。 |
那等 egg-mock 先发? |
看了下,egg-mock 不需要做任何处理,所以我在 eggjs/mock#73 里面把所有的 ts 相关逻辑删除了。 |
那合并了,你来发吧 |
发好去 example 测下 |
4.7.0 我让 examples 的 travis 重跑了,等会看看结果 |
examples travis 过了。 |
* feat: support ts by env * feat: check ts in options * feat: remove typescript option
@@ -415,7 +408,7 @@ class EggLoader { | |||
return undefined; | |||
} | |||
|
|||
if (!this.options.typescript && fullPath.endsWith('.ts')) { | |||
if (process.env.EGG_TYPESCRIPT !== 'true' && fullPath.endsWith('.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.
为什么只有 EGG_TYPESCRIPT true 才会加载 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.
因为只有在本地开发才需要加载 ts ,这个环境变量是 egg-bin 控制,如果不通过这个环境变量控制,在部署的时候也会去加载 ts 文件了,但是部署的时候没有 ts-node 就报错了
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.resolve('/foo/bar') 之后去找 .js 后缀,不会去加载 .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.
我记得扫文件会扫出带后缀的
Checklist
npm test
passesAffected core subsystem(s)
Description of change
支持从 env 中读取 typescript 配置,配合 egg-bin 的 eggjs/bin#98 ,从而能够支持在 egg-schedule 等插件中,直接实例化 FileLoader 的时候,也能加载 ts