-
Notifications
You must be signed in to change notification settings - Fork 93
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
[DO NOT MERGE] code review #10
Changes from all commits
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 |
---|---|---|
|
@@ -130,6 +130,7 @@ class EggLoader { | |
* | ||
* ``` | ||
* // lib/xx.js | ||
* // 这里需要修改示例, egg-core ? | ||
* const egg = require('egg'); | ||
* class XxApplication extends egg.Application { | ||
* constructor(options) { | ||
|
@@ -190,6 +191,7 @@ class EggLoader { | |
return null; | ||
} | ||
|
||
// 这里调用的是 utils.loadFile, 但同名了, 会让人以为是递归 | ||
const ret = loadFile(filepath); | ||
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. 建议是上面引入 utils, 这里 utils.loadFile 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. loadFile(filepath) {
//...
loadFile(filepath); // utils.loadFile
} 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. 有点洁癖, 不太喜欢同名覆盖, 担心踩坑. @_@ |
||
// function(arg1, args, ...) {} | ||
let inject = Array.prototype.slice.call(arguments, 1); | ||
|
@@ -221,6 +223,7 @@ class EggLoader { | |
|
||
if (this.orderPlugins) { | ||
for (const plugin of this.orderPlugins) { | ||
// 插件是在哪里定义的, 这样要不要暴露出去? | ||
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. 这个单独做吧,改动有点多 |
||
dirs.push({ | ||
path: plugin.path, | ||
type: 'plugin', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ const path = require('path'); | |
const globby = require('globby'); | ||
const is = require('is-type-of'); | ||
const loadFile = require('../utils').loadFile; | ||
// Symbol.for ? | ||
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. 内部实现,尽量少用全局的 |
||
const FULLPATH = Symbol('EGG_LOADER_ITEM_FULLPATH'); | ||
const EXPORTS = Symbol('EGG_LOADER_ITEM_EXPORTS'); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ module.exports = { | |
this.config = target; | ||
}, | ||
|
||
// config 文件会加载两次, 这个到时候文档里面最好注明下 | ||
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. 不会影响吧,有 require 缓存 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.
|
||
_preloadAppConfig() { | ||
const names = [ | ||
'config.default.js', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ module.exports = { | |
const filepaths = this.getLoadUnits() | ||
.map(unit => { | ||
let pluginExtendsPath = path.join(unit.path, 'app/extend'); | ||
// 还需要兼容 app 目录? | ||
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. 这个可以去掉 |
||
if (!fs.existsSync(pluginExtendsPath)) { | ||
pluginExtendsPath = path.join(unit.path, 'app'); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ module.exports = { | |
override: true, | ||
lowercaseFirst: true, | ||
}, opt); | ||
// 感觉很多地方都会执行 map, 是不是加个辅助方法? getLoadDirs('app/middleware') | ||
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. 不想增加太多方法,loader 对性能的要求没那么高 |
||
const middlewarePaths = this.getLoadUnits().map(unit => join(unit.path, 'app/middleware')); | ||
this.loadToApp(middlewarePaths, 'middlewares', opt); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,6 +237,8 @@ module.exports = { | |
debug('Got plugins %j after sequencify', result); | ||
|
||
// catch error when result.sequence is empty | ||
// 场景: plugin 是在应用层引入的, 开发期的 plugin 期望配置为应用的 devDeps, 当 npm install --prod 时不会被安装, 导致报错 | ||
// 建议: 当 plugin 是在应用层 plugin.js 中定义的, 且当前 env 下无需用到该插件, 则 skip 掉. | ||
if (!result.sequence.length) { | ||
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. 也行吧. 不过那是对我们而言, 我们有 tnpm. 对于外部那些还在用 npm 且没用cnpm源的, 装哪些带有 webpack / fis 这类构建工具的插件, 估计会很慢. 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. 如果加 dev 更慢,还有一堆测试库 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. 仅在开发期的 plugin, 放在 app 的 devDeps 里面. 我们速度快是因为:
但外面不一定有这种底层支撑. 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. 静态文件打包和安装不是一起的?现在都是在 dependencies 里面的 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. 举例可能有点不恰当, webpack 和 fis 确实在构建的时候有需要同时安装. 还有, 就是 webpack 和相关插件多大? 会不会导致 zip 包太大了? 可以先无视我吧, 后面开源后在看看有没有被挑战吧 |
||
const err = new Error(`sequencify plugins has problem, missing: [${result.missingTasks}], recursive: [${result.recursiveDependencies}]`); | ||
// find plugins which is required by the missing plugin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ module.exports = { | |
app.use(router.middleware()); | ||
|
||
// 加载 router.js | ||
// 增加对 app/router/index.js 的支持? 当 router 比较多的时候有分文件的需求 | ||
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. 我觉得这里可以自己 require 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. router.js 和 router 目录? 两个在一起有点怪怪的. 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. 这个是自己选择的,放 app 下也可以,router 代码放一个查询起来更方便 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. ok |
||
this.loadFile(path.join(this.options.baseDir, 'app/router.js')); | ||
}, | ||
}; |
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.