Skip to content

Commit

Permalink
feat: set plugin module optional false if be enabled as a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Feb 19, 2024
1 parent 8156bb9 commit fe62058
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugin/tegg/lib/EggModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export class EggModuleLoader {

private buildAppGraph(loaderCache: Map<string, Loader>) {
const appGraph = new AppGraph();
for (const plugin of Object.values(this.app.plugins)) {
const modulePlugin = this.app.moduleReferences.find(t => t.path === plugin.path);
if (modulePlugin) {
modulePlugin.optional = false;
}
}
for (const moduleConfig of this.app.moduleReferences) {
const modulePath = moduleConfig.path;
const moduleNode = new ModuleNode(moduleConfig);
Expand Down
36 changes: 36 additions & 0 deletions plugin/tegg/test/OptionalPluginModule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import mm from 'egg-mock';
import assert from 'assert';
import path from 'path';
import { UsedProto } from './fixtures/apps/plugin-module/node_modules/foo-plugin/Used';

describe.only('test/OptionalPluginModule.test.ts', () => {

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (20)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (18)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (16)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (20)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (14)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (16)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (18)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (16)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (14)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (18)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (14)

describe.only not permitted

Check warning on line 6 in plugin/tegg/test/OptionalPluginModule.test.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (20)

describe.only not permitted
let app;
const fixtureDir = path.join(__dirname, 'fixtures/apps/plugin-module');

after(async () => {
await app.close();
});

afterEach(() => {
mm.restore();
});

before(async () => {
mm(process.env, 'EGG_TYPESCRIPT', true);
mm(process, 'cwd', () => {
return path.join(__dirname, '..');
});
app = mm.app({
baseDir: fixtureDir,
framework: require.resolve('egg'),
});
await app.ready();
});

it('should work', async () => {
await app.mockModuleContextScope(async ctx => {
const usedProto = await ctx.getEggObject(UsedProto);
assert(usedProto);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const path = require('path');

module.exports = function(appInfo) {
const config = {
keys: 'test key',
customLogger: {
xxLogger: {
file: path.join(appInfo.root, 'logs/xx.log'),
},
},
security: {
csrf: {
ignoreJSON: false,
}
},
};
return config;
};
18 changes: 18 additions & 0 deletions plugin/tegg/test/fixtures/apps/plugin-module/config/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

exports.tracer = {
package: 'egg-tracer',
enable: true,
};

exports.teggConfig = {
package: '@eggjs/tegg-config',
enable: true,
};

exports.eggFooPlugin = {
package: 'foo-plugin',
enable: true,
};

exports.watcher = false;

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.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions plugin/tegg/test/fixtures/apps/plugin-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "egg-app",
"egg": {
"framework": "foo"
}
}

0 comments on commit fe62058

Please sign in to comment.