Skip to content

Commit

Permalink
Merge pull request #160 from midwayjs/disabled_autoload_js
Browse files Browse the repository at this point in the history
chore: disable auto load in js mode
  • Loading branch information
czy88840616 committed Mar 6, 2019
2 parents 8cd24b8 + 9f9fb03 commit b22ba04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/midway-core/src/loader.ts
Expand Up @@ -57,6 +57,11 @@ export class ContainerLoader {
ignore?: string;
configLocations?: string[];
} = {}) {
if (!this.isTsMode && loadOpts.disableAutoLoad === undefined) {
// disable auto load in js mode by default
loadOpts.disableAutoLoad = true;
}

// 濡傛灉娌℃湁鍏抽棴autoLoad 鍒欒繘琛宭oad
if (!loadOpts.disableAutoLoad) {
const defaultLoadDir = this.isTsMode ? [this.baseDir] : ['app', 'lib'];
Expand Down
28 changes: 28 additions & 0 deletions packages/midway-core/test/loader.test.ts
Expand Up @@ -118,4 +118,32 @@ describe('/test/loader.test.ts', () => {
assert(baseServiceCtx.factory('google'));
});

it('should load js directory and set auto load', async () => {
const loader = new ContainerLoader({
baseDir: path.join(__dirname, './fixtures/js-app-loader'),
isTsMode: false,
});
loader.initialize();
loader.loadDirectory({disableAutoLoad: false});
await loader.refresh();
const appCtx = loader.getApplicationContext();
assert(await appCtx.getAsync('app'));
});

it('should load js directory and auto disable', async () => {
const loader = new ContainerLoader({
baseDir: path.join(__dirname, './fixtures/js-app-loader'),
isTsMode: false,
});
loader.initialize();
loader.loadDirectory();
await loader.refresh();
const appCtx = loader.getApplicationContext();
try {
await appCtx.getAsync('app');
} catch (err) {
assert(err);
}
});

});

0 comments on commit b22ba04

Please sign in to comment.