From a4908c6c640000c7068def57d32052cca15adf47 Mon Sep 17 00:00:00 2001 From: killa Date: Wed, 17 Jan 2024 10:20:01 +0800 Subject: [PATCH] feat: scan framework dependencies as optional module (#184) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ##### Checklist - [x] `npm test` passes - [x] tests and/or benchmarks are included - [ ] documentation is changed or added - [x] commit message follows commit guidelines ##### Affected core subsystem(s) ##### Description of change --- .gitignore | 1 + core/common-util/src/Graph.ts | 11 ++ core/common-util/src/ModuleConfig.ts | 3 + core/metadata/src/model/AppGraph.ts | 3 + core/metadata/test/AppGraph.test.ts | 35 ++++ .../modules/app-graph-modules/root/Root.ts | 7 + .../app-graph-modules/root/package.json | 6 + .../app-graph-modules/unused/Unused.ts | 5 + .../app-graph-modules/unused/package.json | 6 + .../modules/app-graph-modules/used/Used.ts | 7 + .../app-graph-modules/used/package.json | 6 + plugin/config/app.ts | 10 +- plugin/config/lib/ModuleScanner.ts | 41 +++++ plugin/config/package.json | 2 + plugin/config/test/ReadModule.test.ts | 1 + plugin/tegg/lib/AppGraph.ts | 153 ------------------ plugin/tegg/test/OptionalModule.test.ts | 43 +++++ .../optional-module/app/modules/root/Root.ts | 7 + .../app/modules/root/package.json | 6 + .../optional-module/config/config.default.js | 20 +++ .../apps/optional-module/config/plugin.js | 13 ++ .../node_modules/foo/package.json | 7 + .../node_modules/unused/Unused.js | 16 ++ .../node_modules/unused/package.json | 6 + .../optional-module/node_modules/used/Used.js | 18 +++ .../node_modules/used/package.json | 6 + .../apps/optional-module/package.json | 6 + 27 files changed, 289 insertions(+), 156 deletions(-) create mode 100644 core/metadata/test/AppGraph.test.ts create mode 100644 core/metadata/test/fixtures/modules/app-graph-modules/root/Root.ts create mode 100644 core/metadata/test/fixtures/modules/app-graph-modules/root/package.json create mode 100644 core/metadata/test/fixtures/modules/app-graph-modules/unused/Unused.ts create mode 100644 core/metadata/test/fixtures/modules/app-graph-modules/unused/package.json create mode 100644 core/metadata/test/fixtures/modules/app-graph-modules/used/Used.ts create mode 100644 core/metadata/test/fixtures/modules/app-graph-modules/used/package.json create mode 100644 plugin/config/lib/ModuleScanner.ts delete mode 100644 plugin/tegg/lib/AppGraph.ts create mode 100644 plugin/tegg/test/OptionalModule.test.ts create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/app/modules/root/Root.ts create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/app/modules/root/package.json create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/config/config.default.js create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/config/plugin.js create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/node_modules/foo/package.json create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/node_modules/unused/Unused.js create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/node_modules/unused/package.json create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/node_modules/used/Used.js create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/node_modules/used/package.json create mode 100644 plugin/tegg/test/fixtures/apps/optional-module/package.json diff --git a/.gitignore b/.gitignore index 57fbc9fc..3ac962d3 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ plugin/tegg/test/fixtures/apps/**/*.js !benchmark/**/*.js !standalone/standalone/test/fixtures/**/node_modules !standalone/standalone/test/fixtures/**/node_modules/**/*.js +!plugin/tegg/test/fixtures/**/node_modules diff --git a/core/common-util/src/Graph.ts b/core/common-util/src/Graph.ts index 1b9b6faa..3eede879 100644 --- a/core/common-util/src/Graph.ts +++ b/core/common-util/src/Graph.ts @@ -7,6 +7,7 @@ export interface GraphNodeObj { export class GraphNode { val: T; toNodeMap: Map> = new Map(); + fromNodeMap: Map> = new Map(); constructor(val: T) { this.val = val; @@ -24,6 +25,14 @@ export class GraphNode { return true; } + addFromVertex(node: GraphNode) { + if (this.fromNodeMap.has(node.id)) { + return false; + } + this.fromNodeMap.set(node.id, node); + return true; + } + [inspect]() { return this.toJSON(); } @@ -32,6 +41,7 @@ export class GraphNode { return { val: this.val, toNodes: Array.from(this.toNodeMap.values()), + fromNodes: Array.from(this.fromNodeMap.values()), }; } @@ -84,6 +94,7 @@ export class Graph { } addEdge(from: GraphNode, to: GraphNode): boolean { + to.addFromVertex(from); return from.addToVertex(to); } diff --git a/core/common-util/src/ModuleConfig.ts b/core/common-util/src/ModuleConfig.ts index e7f8234b..039e4d48 100644 --- a/core/common-util/src/ModuleConfig.ts +++ b/core/common-util/src/ModuleConfig.ts @@ -9,14 +9,17 @@ import extend from 'extend2'; export interface ModuleReference { name: string; path: string; + optional?: boolean; } export interface InlineModuleReferenceConfig { path: string; + optional?: boolean; } export interface NpmModuleReferenceConfig { package: string; + optional?: boolean; } export type ModuleReferenceConfig = InlineModuleReferenceConfig | NpmModuleReferenceConfig; diff --git a/core/metadata/src/model/AppGraph.ts b/core/metadata/src/model/AppGraph.ts index 461a5516..55403012 100644 --- a/core/metadata/src/model/AppGraph.ts +++ b/core/metadata/src/model/AppGraph.ts @@ -249,6 +249,9 @@ export class AppGraph { throw new Error('module has recursive deps: ' + loopPath); } this.moduleConfigList = this.graph.sort() + .filter(t => { + return t.val.moduleConfig.optional !== true || t.fromNodeMap.size > 0; + }) .map(t => t.val.moduleConfig); } } diff --git a/core/metadata/test/AppGraph.test.ts b/core/metadata/test/AppGraph.test.ts new file mode 100644 index 00000000..a8afe406 --- /dev/null +++ b/core/metadata/test/AppGraph.test.ts @@ -0,0 +1,35 @@ +import assert from 'assert'; +import path from 'path'; +import { AppGraph, ModuleNode } from '../src/model/AppGraph'; +import { RootProto } from './fixtures/modules/app-graph-modules/root/Root'; +import { UsedProto } from './fixtures/modules/app-graph-modules/used/Used'; +import { UnusedProto } from './fixtures/modules/app-graph-modules/unused/Unused'; + +describe('test/LoadUnit/AppGraph.test.ts', () => { + it('optional module dep should work', () => { + const graph = new AppGraph(); + const rootModuleNode = new ModuleNode({ + name: 'foo', + path: path.join(__dirname, './fixtures/modules/app-graph-modules/root'), + }); + rootModuleNode.addClazz(RootProto); + graph.addNode(rootModuleNode); + const usedOptionalModuleNode = new ModuleNode({ + name: 'usedOptionalModuleNode', + path: path.join(__dirname, './fixtures/modules/app-graph-modules/used'), + optional: true, + }); + usedOptionalModuleNode.addClazz(UsedProto); + graph.addNode(usedOptionalModuleNode); + const unusedOptionalModuleNode = new ModuleNode({ + name: 'unusedOptionalModuleNode', + path: path.join(__dirname, './fixtures/modules/app-graph-modules/unused'), + optional: true, + }); + unusedOptionalModuleNode.addClazz(UnusedProto); + graph.addNode(unusedOptionalModuleNode); + graph.build(); + graph.sort(); + assert(graph.moduleConfigList.length === 2); + }); +}); diff --git a/core/metadata/test/fixtures/modules/app-graph-modules/root/Root.ts b/core/metadata/test/fixtures/modules/app-graph-modules/root/Root.ts new file mode 100644 index 00000000..2f03c11c --- /dev/null +++ b/core/metadata/test/fixtures/modules/app-graph-modules/root/Root.ts @@ -0,0 +1,7 @@ +import { SingletonProto, Inject } from '@eggjs/core-decorator'; +import { UsedProto } from '../used/Used'; + +@SingletonProto() +export class RootProto { + @Inject() usedProto: UsedProto; +} diff --git a/core/metadata/test/fixtures/modules/app-graph-modules/root/package.json b/core/metadata/test/fixtures/modules/app-graph-modules/root/package.json new file mode 100644 index 00000000..0f114028 --- /dev/null +++ b/core/metadata/test/fixtures/modules/app-graph-modules/root/package.json @@ -0,0 +1,6 @@ +{ + "name": "root", + "eggModule": { + "name": "root" + } +} diff --git a/core/metadata/test/fixtures/modules/app-graph-modules/unused/Unused.ts b/core/metadata/test/fixtures/modules/app-graph-modules/unused/Unused.ts new file mode 100644 index 00000000..1da9bee5 --- /dev/null +++ b/core/metadata/test/fixtures/modules/app-graph-modules/unused/Unused.ts @@ -0,0 +1,5 @@ +import { SingletonProto } from '@eggjs/core-decorator'; + +@SingletonProto() +export class UnusedProto { +} diff --git a/core/metadata/test/fixtures/modules/app-graph-modules/unused/package.json b/core/metadata/test/fixtures/modules/app-graph-modules/unused/package.json new file mode 100644 index 00000000..4473072a --- /dev/null +++ b/core/metadata/test/fixtures/modules/app-graph-modules/unused/package.json @@ -0,0 +1,6 @@ +{ + "name": "unused", + "eggModule": { + "name": "unused" + } +} diff --git a/core/metadata/test/fixtures/modules/app-graph-modules/used/Used.ts b/core/metadata/test/fixtures/modules/app-graph-modules/used/Used.ts new file mode 100644 index 00000000..9c389849 --- /dev/null +++ b/core/metadata/test/fixtures/modules/app-graph-modules/used/Used.ts @@ -0,0 +1,7 @@ +import { AccessLevel, SingletonProto } from '@eggjs/core-decorator'; + +@SingletonProto({ + accessLevel: AccessLevel.PUBLIC, +}) +export class UsedProto { +} diff --git a/core/metadata/test/fixtures/modules/app-graph-modules/used/package.json b/core/metadata/test/fixtures/modules/app-graph-modules/used/package.json new file mode 100644 index 00000000..efa9b239 --- /dev/null +++ b/core/metadata/test/fixtures/modules/app-graph-modules/used/package.json @@ -0,0 +1,6 @@ +{ + "name": "used", + "eggModule": { + "name": "used" + } +} diff --git a/plugin/config/app.ts b/plugin/config/app.ts index 6e27c539..8e62520c 100644 --- a/plugin/config/app.ts +++ b/plugin/config/app.ts @@ -1,5 +1,6 @@ import { Application } from 'egg'; -import { ModuleConfigUtil } from '@eggjs/tegg-common-util'; +import { ModuleConfigUtil, ModuleReference } from '@eggjs/tegg-common-util'; +import { ModuleScanner } from './lib/ModuleScanner'; export default class App { private readonly app: Application; @@ -10,12 +11,15 @@ export default class App { configWillLoad() { const { readModuleOptions } = this.app.config.tegg || {}; - this.app.moduleReferences = ModuleConfigUtil.readModuleReference(this.app.baseDir, readModuleOptions || {}); + const moduleScanner = new ModuleScanner(this.app.baseDir, readModuleOptions); + this.app.moduleReferences = moduleScanner.loadModuleReferences(); + this.app.moduleConfigs = {}; for (const reference of this.app.moduleReferences) { - const absoluteRef = { + const absoluteRef: ModuleReference = { path: ModuleConfigUtil.resolveModuleDir(reference.path, this.app.baseDir), name: reference.name, + optional: reference.optional, }; const moduleName = ModuleConfigUtil.readModuleNameSync(absoluteRef.path); diff --git a/plugin/config/lib/ModuleScanner.ts b/plugin/config/lib/ModuleScanner.ts new file mode 100644 index 00000000..459ae5ef --- /dev/null +++ b/plugin/config/lib/ModuleScanner.ts @@ -0,0 +1,41 @@ +import { ModuleConfigUtil, ModuleReference, ReadModuleReferenceOptions } from '@eggjs/tegg-common-util'; +import path from 'path'; + +export class ModuleScanner { + private readonly baseDir: string; + private readonly readModuleOptions: ReadModuleReferenceOptions; + + constructor(baseDir: string, readModuleOptions: ReadModuleReferenceOptions) { + this.baseDir = baseDir; + this.readModuleOptions = readModuleOptions; + } + + /** + * - load module references from config or scan from baseDir + * - load framework module as optional module reference + */ + loadModuleReferences(): readonly ModuleReference[] { + const moduleReferences = ModuleConfigUtil.readModuleReference(this.baseDir, this.readModuleOptions || {}); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const appPkg = require(path.join(this.baseDir, 'package.json')); + const framework = appPkg.egg?.framework; + if (!framework) { + return moduleReferences; + } + // eslint-disable-next-line @typescript-eslint/no-var-requires + const frameworkPkg = require.resolve(`${framework}/package.json`, { + paths: [ this.baseDir ], + }); + const frameworkDir = path.dirname(frameworkPkg); + const optionalModuleReferences = ModuleConfigUtil.readModuleReference(frameworkDir, this.readModuleOptions || {}); + return [ + ...moduleReferences, + ...optionalModuleReferences.map(t => { + return { + ...t, + optional: true, + }; + }), + ]; + } +} diff --git a/plugin/config/package.json b/plugin/config/package.json index 17a8160e..d1ec7644 100644 --- a/plugin/config/package.json +++ b/plugin/config/package.json @@ -17,6 +17,8 @@ "app.js", "app.d.ts", "typings/index.d.ts", + "lib/**/*.js", + "lib/**/*.d.ts", "agent.js", "agent.d.ts" ], diff --git a/plugin/config/test/ReadModule.test.ts b/plugin/config/test/ReadModule.test.ts index a62c21f6..da2b2a3b 100644 --- a/plugin/config/test/ReadModule.test.ts +++ b/plugin/config/test/ReadModule.test.ts @@ -32,6 +32,7 @@ describe('test/ReadModule.test.ts', () => { config: {}, name: 'moduleA', reference: { + optional: undefined, name: 'moduleA', path: path.join(fixturesPath, 'app/module-a'), }, diff --git a/plugin/tegg/lib/AppGraph.ts b/plugin/tegg/lib/AppGraph.ts deleted file mode 100644 index 8a344f79..00000000 --- a/plugin/tegg/lib/AppGraph.ts +++ /dev/null @@ -1,153 +0,0 @@ -import assert from 'assert'; -import path from 'path'; -import { Graph, GraphNode, GraphNodeObj } from '@eggjs/tegg-common-util'; -import { - EggProtoImplClass, - EggPrototypeName, - INIT_TYPE_TRY_ORDER, - InitTypeQualifierAttribute, - LoadUnitNameQualifierAttribute, - PrototypeUtil, - QualifierInfo, - QualifierUtil, - AccessLevel, -} from '@eggjs/tegg'; - -export interface ModuleConfig { - path: string; -} - -export class ModuleNode implements GraphNodeObj { - readonly id: string; - readonly name: string; - readonly moduleConfig: ModuleConfig; - private clazzList: EggProtoImplClass[]; - - // TODO refactor to ModuleUtil - static readModuleName(modulePath: string): string { - const pkgPath = path.join(modulePath, 'package.json'); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const pkg = require(pkgPath); - assert(pkg.eggModule, `module config not found in package ${pkgPath}`); - const { name } = pkg.eggModule; - return name; - } - - constructor(moduleConfig: ModuleConfig) { - this.moduleConfig = moduleConfig; - this.id = moduleConfig.path; - this.name = ModuleNode.readModuleName(moduleConfig.path); - this.clazzList = []; - } - - addClazz(clazz: EggProtoImplClass) { - this.clazzList.push(clazz); - } - - getClazzList(): readonly EggProtoImplClass[] { - return this.clazzList; - } - - getPublicClazzList(): readonly EggProtoImplClass[] { - return this.clazzList.filter(clazz => PrototypeUtil.getAccessLevel(clazz, { - unitPath: this.moduleConfig.path, - }) === AccessLevel.PUBLIC); - } - - toString() { - return `${this.name}@${this.moduleConfig.path}`; - } - - verifyQualifiers(clazz: EggProtoImplClass, qualifiers: QualifierInfo[]): boolean { - const clazzQualifiers = QualifierUtil.getProtoQualifiers(clazz); - for (const qualifier of qualifiers) { - if (!this.verifyQualifier(clazzQualifiers, qualifier)) { - return false; - } - } - return true; - } - - verifyQualifier(clazzQualifiers: QualifierInfo[], qualifier: QualifierInfo) { - const selfQualifiers = clazzQualifiers.find(t => t.attribute === qualifier.attribute); - return selfQualifiers?.value === qualifier.value; - } - - findImplementClazzList(objName: EggPrototypeName, qualifiers: QualifierInfo[], innerFind: boolean): EggProtoImplClass[] { - const moduleQualifier = qualifiers.find(t => t.attribute === LoadUnitNameQualifierAttribute); - if (moduleQualifier && moduleQualifier.value !== this.name) { - return []; - } - const clazzList = innerFind ? this.clazzList : this.getPublicClazzList(); - const implList = clazzList - .filter(clazz => PrototypeUtil.getObjNames(clazz, { - unitPath: this.moduleConfig.path, - }).includes(objName)) - .filter(clazz => this.verifyQualifiers(clazz, qualifiers)); - if (implList.length === 1) { - return implList; - } - const initTypeQualifiers = INIT_TYPE_TRY_ORDER.map(type => ({ - attribute: InitTypeQualifierAttribute, - value: type, - })); - for (const initTypeQualifier of initTypeQualifiers) { - const initTypeList = implList.filter(clazz => this.verifyQualifiers(clazz, [ initTypeQualifier ])); - if (initTypeList.length === 1) { - return initTypeList; - } - } - return implList; - } -} - -export class AppGraph { - private graph: Graph; - moduleConfigList: Array; - - constructor() { - this.graph = new Graph(); - } - - addNode(moduleNode: ModuleNode) { - if (!this.graph.addVertex(new GraphNode(moduleNode))) { - throw new Error(`duplicate module: ${moduleNode}`); - } - } - - private findDependencyModule(objName: EggPrototypeName, properqualifiers: QualifierInfo[], protoQualifiers: QualifierInfo[]): Array> { - const nodes: Array> = Array.from(this.graph.nodes.values()); - const hostModuleName = protoQualifiers.find(t => t.attribute === LoadUnitNameQualifierAttribute)?.value; - return nodes.filter(node => { - // private 的类只能在当前 module 中被找到 - const clazzList = node.val.findImplementClazzList(objName, properqualifiers, hostModuleName === node.val.name); - return clazzList.length; - }); - } - - build() { - for (const node of this.graph.nodes.values()) { - for (const clazz of node.val.getClazzList()) { - const injectObjects = PrototypeUtil.getInjectObjects(clazz); - for (const injectObject of injectObjects) { - const properqualifiers = QualifierUtil.getProperQualifiers(clazz, injectObject.refName); - const protoQualifiers = QualifierUtil.getProtoQualifiers(clazz); - const dependencyModules = this.findDependencyModule(injectObject.objName, properqualifiers, protoQualifiers); - for (const moduleNode of dependencyModules) { - if (node !== moduleNode) { - this.graph.addEdge(node, moduleNode); - } - } - } - } - } - } - - sort() { - const loopPath = this.graph.loopPath(); - if (loopPath) { - throw new Error('module has recursive deps: ' + loopPath); - } - this.moduleConfigList = this.graph.sort().map(t => t.val.moduleConfig); - } -} diff --git a/plugin/tegg/test/OptionalModule.test.ts b/plugin/tegg/test/OptionalModule.test.ts new file mode 100644 index 00000000..f9d4eea5 --- /dev/null +++ b/plugin/tegg/test/OptionalModule.test.ts @@ -0,0 +1,43 @@ +import mm from 'egg-mock'; +import assert from 'assert'; +import path from 'path'; +import { RootProto } from './fixtures/apps/optional-module/app/modules/root/Root'; +import { UsedProto } from './fixtures/apps/optional-module/node_modules/used/Used'; +import { UnusedProto } from './fixtures/apps/optional-module/node_modules/unused/Unused'; + +describe('test/OptionalModule.test.ts', () => { + let app; + const fixtureDir = path.join(__dirname, 'fixtures/apps/optional-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 rootProto = await ctx.getEggObject(RootProto); + assert(rootProto); + const usedProto = await ctx.getEggObject(UsedProto); + assert(usedProto); + await assert.rejects(async () => { + await ctx.getEggObject(UnusedProto); + }, /can not get proto for clazz UnusedProto/); + }); + }); +}); diff --git a/plugin/tegg/test/fixtures/apps/optional-module/app/modules/root/Root.ts b/plugin/tegg/test/fixtures/apps/optional-module/app/modules/root/Root.ts new file mode 100644 index 00000000..9d2818a6 --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/app/modules/root/Root.ts @@ -0,0 +1,7 @@ +import { SingletonProto, Inject } from '@eggjs/core-decorator'; +import { UsedProto } from 'used/Used'; + +@SingletonProto() +export class RootProto { + @Inject() usedProto: UsedProto; +} diff --git a/plugin/tegg/test/fixtures/apps/optional-module/app/modules/root/package.json b/plugin/tegg/test/fixtures/apps/optional-module/app/modules/root/package.json new file mode 100644 index 00000000..0f114028 --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/app/modules/root/package.json @@ -0,0 +1,6 @@ +{ + "name": "root", + "eggModule": { + "name": "root" + } +} diff --git a/plugin/tegg/test/fixtures/apps/optional-module/config/config.default.js b/plugin/tegg/test/fixtures/apps/optional-module/config/config.default.js new file mode 100644 index 00000000..6d1b8de5 --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/config/config.default.js @@ -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; +}; diff --git a/plugin/tegg/test/fixtures/apps/optional-module/config/plugin.js b/plugin/tegg/test/fixtures/apps/optional-module/config/plugin.js new file mode 100644 index 00000000..10d5c293 --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/config/plugin.js @@ -0,0 +1,13 @@ +'use strict'; + +exports.tracer = { + package: 'egg-tracer', + enable: true, +}; + +exports.teggConfig = { + package: '@eggjs/tegg-config', + enable: true, +}; + +exports.watcher = false; diff --git a/plugin/tegg/test/fixtures/apps/optional-module/node_modules/foo/package.json b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/foo/package.json new file mode 100644 index 00000000..06d0ea69 --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/foo/package.json @@ -0,0 +1,7 @@ +{ + "name": "foo", + "dependencies": { + "used": "*", + "unused": "*" + } +} diff --git a/plugin/tegg/test/fixtures/apps/optional-module/node_modules/unused/Unused.js b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/unused/Unused.js new file mode 100644 index 00000000..0f47ad6a --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/unused/Unused.js @@ -0,0 +1,16 @@ +"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UnusedProto = void 0; +const tegg_core_decorator_1 = require('../../../../../../../../core/core-decorator'); +let UnusedProto = class UnusedProto { +}; +exports.UnusedProto = UnusedProto; +exports.UnusedProto = UnusedProto = __decorate([ + (0, tegg_core_decorator_1.SingletonProto)() +], UnusedProto); diff --git a/plugin/tegg/test/fixtures/apps/optional-module/node_modules/unused/package.json b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/unused/package.json new file mode 100644 index 00000000..4473072a --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/unused/package.json @@ -0,0 +1,6 @@ +{ + "name": "unused", + "eggModule": { + "name": "unused" + } +} diff --git a/plugin/tegg/test/fixtures/apps/optional-module/node_modules/used/Used.js b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/used/Used.js new file mode 100644 index 00000000..2bb8c288 --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/used/Used.js @@ -0,0 +1,18 @@ +"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UsedProto = void 0; +const tegg_core_decorator_1 = require('../../../../../../../../core/core-decorator'); +let UsedProto = class UsedProto { +}; +exports.UsedProto = UsedProto; +exports.UsedProto = UsedProto = __decorate([ + (0, tegg_core_decorator_1.SingletonProto)({ + accessLevel: tegg_core_decorator_1.AccessLevel.PUBLIC, + }) +], UsedProto); diff --git a/plugin/tegg/test/fixtures/apps/optional-module/node_modules/used/package.json b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/used/package.json new file mode 100644 index 00000000..efa9b239 --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/node_modules/used/package.json @@ -0,0 +1,6 @@ +{ + "name": "used", + "eggModule": { + "name": "used" + } +} diff --git a/plugin/tegg/test/fixtures/apps/optional-module/package.json b/plugin/tegg/test/fixtures/apps/optional-module/package.json new file mode 100644 index 00000000..3b868a43 --- /dev/null +++ b/plugin/tegg/test/fixtures/apps/optional-module/package.json @@ -0,0 +1,6 @@ +{ + "name": "egg-app", + "egg": { + "framework": "foo" + } +}