Skip to content

Commit

Permalink
feat: add ts check in loadFile
Browse files Browse the repository at this point in the history
  • Loading branch information
whxaxes committed Mar 23, 2018
1 parent 5363b4a commit 46dc810
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/loader/egg_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ class EggLoader {
return null;
}

if (!this.options.typescript && filepath.endsWith('.ts')) {
return null;
}

const ret = utils.loadFile(filepath);
// function(arg1, args, ...) {}
if (inject.length === 0) inject = [ this.app ];
Expand Down
3 changes: 2 additions & 1 deletion lib/loader/mixin/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ module.exports = {
deprecate(`app/extend/${name}/index.js is deprecated, use app/extend/${name}.js instead`);
}

const ext = utils.loadFile(filepath);
const ext = this.loadFile(filepath);
if (!ext) continue;

const properties = Object.getOwnPropertyNames(ext)
.concat(Object.getOwnPropertySymbols(ext));
Expand Down
2 changes: 2 additions & 0 deletions test/egg-ts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ describe('test/egg-ts.test.js', () => {
it('should not load ts files while typescript was false', async () => {
app = utils.createApp('egg-ts-js');

app.loader.loadApplicationExtend();
app.loader.loadService();
assert(!app.appExtend);
assert(app.serviceClasses.lord);
assert(!app.serviceClasses.test);
});
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/egg-ts-js/app/extend/application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
appExtend: 'hello'
}

0 comments on commit 46dc810

Please sign in to comment.