From 7995bda1c9bcd64648bf172f744c4f5266d345b4 Mon Sep 17 00:00:00 2001 From: hzgotb Date: Wed, 24 Jul 2019 14:51:45 +0800 Subject: [PATCH 1/8] fix(boilerplate) update plugin declaration --- .../midway-demo-boilerplate/boilerplate/src/config/plugin.ts | 4 ++-- .../boilerplate/server/src/config/plugin.ts | 4 ++-- .../midway-ts-boilerplate/boilerplate/src/config/plugin.ts | 4 ++-- .../boilerplate/src/config/plugin.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/config/plugin.ts b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/config/plugin.ts index 5fb12de1ad5b..da7ce53a9f1e 100755 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/config/plugin.ts +++ b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/config/plugin.ts @@ -1,4 +1,4 @@ - +import { EggPlugin } from 'midway' export default { static: true, // default is true -} +} as EggPlugin diff --git a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/plugin.ts b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/plugin.ts index 4fdb24548c76..37b849fc5445 100755 --- a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/plugin.ts +++ b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/plugin.ts @@ -1,4 +1,4 @@ - +import { EggPlugin } from 'midway' export default { static: true, // default is true @@ -11,4 +11,4 @@ export default { enable: true, package: 'egg-view-assets', }, -} +} as EggPlugin diff --git a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/config/plugin.ts b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/config/plugin.ts index 5fb12de1ad5b..da7ce53a9f1e 100755 --- a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/config/plugin.ts +++ b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/config/plugin.ts @@ -1,4 +1,4 @@ - +import { EggPlugin } from 'midway' export default { static: true, // default is true -} +} as EggPlugin diff --git a/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/src/config/plugin.ts b/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/src/config/plugin.ts index 5fb12de1ad5b..da7ce53a9f1e 100644 --- a/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/src/config/plugin.ts +++ b/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/src/config/plugin.ts @@ -1,4 +1,4 @@ - +import { EggPlugin } from 'midway' export default { static: true, // default is true -} +} as EggPlugin From 2970743d7f1f1cc14344fd7be75373a25775c9e6 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Wed, 24 Jul 2019 16:48:22 +0800 Subject: [PATCH 2/8] chore(deps): update deps for midway-bin, midway-core, midway-init - eslint to ^6.1.0 - fs-extra to ^8.1.0 - globby to ^10.0.1 --- packages/midway-bin/package.json | 6 +++--- packages/midway-core/package.json | 2 +- packages/midway-init/package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/midway-bin/package.json b/packages/midway-bin/package.json index 2cb3e44194ff..648f5b7fc661 100644 --- a/packages/midway-bin/package.json +++ b/packages/midway-bin/package.json @@ -24,15 +24,15 @@ "license": "MIT", "dependencies": { "egg-bin": "^4.11.1", - "fs-extra": "^7.0.1", - "globby": "^9.1.0", + "fs-extra": "^8.1.0", + "globby": "^10.0.1", "mz-modules": "^2.1.0", "typedoc": "^0.14.2" }, "devDependencies": { "co-mocha": "^1.2.2", "coffee": "^5.2.1", - "eslint": "^5.14.1", + "eslint": "^6.1.0", "eslint-config-egg": "^7.0.0", "mm": "^2.5.0" }, diff --git a/packages/midway-core/package.json b/packages/midway-core/package.json index 0f7d082e1809..90607bab4043 100644 --- a/packages/midway-core/package.json +++ b/packages/midway-core/package.json @@ -31,7 +31,7 @@ "@midwayjs/decorator": "^1.10.2", "camelcase": "^5.2.0", "debug": "^4.1.1", - "globby": "^9.1.0", + "globby": "^10.0.1", "injection": "^1.4.2", "is-type-of": "^1.2.1" }, diff --git a/packages/midway-init/package.json b/packages/midway-init/package.json index de3214f4d253..b62545e7b9b2 100644 --- a/packages/midway-init/package.json +++ b/packages/midway-init/package.json @@ -10,7 +10,7 @@ "main": "lib/command.js", "devDependencies": { "coffee": "^5.2.1", - "eslint": "^5.14.1", + "eslint": "^6.1.0", "eslint-config-egg": "^7.0.0", "intelli-espower-loader": "^1.0.1", "midway-bin": "^1.10.2", From 732fee1db41cb19883c375658cb4783cab8d7b43 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Sun, 28 Jul 2019 18:17:31 +0800 Subject: [PATCH 3/8] chore(boilerplate): fix building issue cause of .tsbuildinfo It will no output during tsc incremental build if outDir is empty and .tsbuildinfo exists. Add scripts `npm run clean` to unlink files in outDir and file .tsbuildinfo . --- .../boilerplate/midway-ts-boilerplate/boilerplate/_.gitignore | 1 + .../boilerplate/midway-ts-boilerplate/boilerplate/_package.json | 2 ++ .../midway-ts-strict-boilerplate/boilerplate/_.gitignore | 1 + .../midway-ts-strict-boilerplate/boilerplate/_package.json | 2 ++ 4 files changed, 6 insertions(+) diff --git a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_.gitignore b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_.gitignore index 2957c0deba38..13bc3a68db3f 100755 --- a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_.gitignore +++ b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_.gitignore @@ -12,3 +12,4 @@ run/ *.sw* *.un~ .tsbuildinfo +.tsbuildinfo.* diff --git a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_package.json b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_package.json index b0d659e212aa..142fed23f8b1 100755 --- a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_package.json +++ b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_package.json @@ -14,6 +14,7 @@ "egg-ci": "^1.8.0", "midway-bin": "1", "midway-mock": "1", + "rimraf": "^2.6.2", "tslib": "^1.8.1", "tslint-midway-contrib": "1", "ts-node": "^8.3.0", @@ -27,6 +28,7 @@ "start": "egg-scripts start --daemon --title=egg-server-{{name}} --framework=midway", "stop": "egg-scripts stop --title=egg-server-{{name}}", "start_build": "npm run build && cross-env NODE_ENV=development midway-bin dev", + "clean": "rm -rf dist/* .vscode/.tsbuildinfo .vscode/.tsbuildinfo.* ", "dev": "cross-env NODE_ENV=local midway-bin dev --ts", "debug": "cross-env NODE_ENV=local midway-bin debug --ts", "test": "npm run lint && midway-bin test --ts", diff --git a/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/_.gitignore b/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/_.gitignore index 2957c0deba38..13bc3a68db3f 100644 --- a/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/_.gitignore +++ b/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/_.gitignore @@ -12,3 +12,4 @@ run/ *.sw* *.un~ .tsbuildinfo +.tsbuildinfo.* diff --git a/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/_package.json b/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/_package.json index 81149b6dee44..a4390586ae95 100644 --- a/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/_package.json +++ b/packages/midway-init/boilerplate/midway-ts-strict-boilerplate/boilerplate/_package.json @@ -16,6 +16,7 @@ "eslint": "^6.0.0", "midway-bin": "1", "midway-mock": "1", + "rimraf": "^2.6.2", "tslib": "^1.8.1", "ts-node": "^8.3.0", "typescript": "^3.5.0" @@ -27,6 +28,7 @@ "start": "egg-scripts start --daemon --title=egg-server-{{name}} --framework=midway", "stop": "egg-scripts stop --title=egg-server-{{name}}", "start_build": "npm run build && cross-env NODE_ENV=development midway-bin dev", + "clean": "rm -rf dist/* .vscode/.tsbuildinfo .vscode/.tsbuildinfo.* ", "dev": "cross-env NODE_ENV=local midway-bin dev --ts", "debug": "cross-env NODE_ENV=local midway-bin debug --ts", "test": "npm run lint && cross-env TS_NODE_PROJECT=test/tsconfig.json midway-bin test --ts", From d738b7f206c725c8552b18b0f3288e2376c41792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=9D=E5=BF=A0?= Date: Mon, 29 Jul 2019 15:12:18 +0800 Subject: [PATCH 4/8] fix: compatible with midway mock --- packages/midway-mock/src/index.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/midway-mock/src/index.ts b/packages/midway-mock/src/index.ts index 4284e86b2049..6aa31a33acd2 100644 --- a/packages/midway-mock/src/index.ts +++ b/packages/midway-mock/src/index.ts @@ -20,6 +20,18 @@ function mockContainer(options: MidwayApplicationOptions) { return new MockContainer(options); } +function findFramework(module) { + try { + if (require.resolve(module)) { + return module; + } + } catch (err) { + console.log(`[midway-bin] Not found framework ${module} and skip.`); + } +} + +const defaultFramework = findFramework('midway') || findFramework('midway-mirror'); + const mm2: MidwayMock = Object.assign({}, mock, { container: mockContainer, }); @@ -28,7 +40,7 @@ mm2.app = (options): MidwayMockApplication => { if (process.env.MIDWAY_BASE_DIR && !options.baseDir) { options.baseDir = process.env.MIDWAY_BASE_DIR; } if (process.env.MIDWAY_FRAMEWORK_PATH && !options.framework) { options.framework = process.env.MIDWAY_FRAMEWORK_PATH; } return mock.app(Object.assign({ - framework: options.framework || 'midway', + framework: options.framework || defaultFramework, typescript: !!require.extensions['.ts'], }, options)); }; @@ -37,7 +49,7 @@ mm2.cluster = (options) => { if (process.env.MIDWAY_BASE_DIR && !options.baseDir) { options.baseDir = process.env.MIDWAY_BASE_DIR; } if (process.env.MIDWAY_FRAMEWORK_PATH && !options.framework) { options.framework = process.env.MIDWAY_FRAMEWORK_PATH; } return mock.cluster(Object.assign({ - framework: options.framework || 'midway', + framework: options.framework || defaultFramework, typescript: !!require.extensions['.ts'], }, options)); }; From a1803b31d2910bd41fe6aa2c24c840dbc8fb0951 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Mon, 29 Jul 2019 23:03:04 +0800 Subject: [PATCH 5/8] chore: update template --- .../boilerplate/.vscode/launch.json | 34 ---------- .../boilerplate/.vscode/settings.json | 64 ------------------- .../boilerplate/.vscode/tasks.json | 50 --------------- .../boilerplate/src/config/plugin.ts | 5 +- .../server/src/config/config.default.ts | 13 ++-- .../boilerplate/server/src/config/plugin.ts | 4 +- .../boilerplate/_package.json | 2 +- .../boilerplate/procfile.js | 32 ---------- .../boilerplate/src/config/plugin.ts | 4 +- 9 files changed, 12 insertions(+), 196 deletions(-) delete mode 100644 packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/launch.json delete mode 100644 packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/settings.json delete mode 100644 packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/tasks.json delete mode 100644 packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/procfile.js diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/launch.json b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/launch.json deleted file mode 100644 index 31c5b5faf782..000000000000 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/launch.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Midway Debug", - "type": "node", - "autoAttachChildProcesses": true, - "console": "integratedTerminal", - "env": { - "NODE_ENV": "local" - }, - "port": 9229, - "preLaunchTask": "TypeScript compile", - "protocol": "auto", - "request": "launch", - "restart": true, - "runtimeArgs": [ - "run", - "debug", - "--", - "--inspect-brk" - ], - "runtimeExecutable": "npm", - "skipFiles": [ - // "${workspaceFolder}/node_modules/**/*.js", - "${workspaceFolder}/node_modules/rxjs/**/*.js", - "/**/*.js" - ] - } - ] -} diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/settings.json b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/settings.json deleted file mode 100644 index e04d371956f7..000000000000 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/settings.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "files.eol": "\n", - "files.exclude": { - "**/*.js": { - "when": "$(basename).ts" - }, - ".build": true, - ".dockerignore": true, - ".editorconfig": true, - ".eslint*": true, - ".gitignore": true, - ".githooks": true, - ".npmignore": true, - ".nyc_output": true, - ".sourcemaps": true, - ".travis.yml": true, - "appveyor.yml": true, - "build": true, - "commitlint.*": true, - "coverage": true, - "dist": true, - "logs": true, - "out": true, - "package-lock.json": true, - "rollup.*": true, - "run": true, - "**/*.map": true, - "**/*.swp": true, - "**/.DS_Store": true, - "**/.git": true, - "**/.vscode": true, - "**/node_modules*": true - }, - "files.insertFinalNewline": true, - "files.watcherExclude": { - "coverage/**": true, - "dist/**": true, - "run/**": true, - "**/.git/objects/**": true, - "**/.git/subtree-cache/**": true, - "**/.tsbuildinfo": true, - "**/.tsbuildinfo.*": true, - "**/logs/**": true, - "**/node_modules/**": true, - "**/node_modules*/**": true, - "**/temp/**": true, - "**/tmp/**": true - }, - "files.trimTrailingWhitespace": true, - "search.exclude": { - "i18n/**": true, - "library/": true, - "node_modules": true, - "platforms/": true, - "www/": true, - "**/node_modules*": true, - "**/bower_components": true - }, - "search.useIgnoreFiles": true - "[markdown]": { - "files.trimTrailingWhitespace": false - }, - "tslint.configFile": "./tslint.json" -} diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/tasks.json b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/tasks.json deleted file mode 100644 index 95684c98d80e..000000000000 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/.vscode/tasks.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - // 有关 tasks.json 格式的文档,请参见 - // https://go.microsoft.com/fwlink/?LinkId=733558 - "version": "2.0.0", - "tasks": [ - { - "label": "TypeScript compile", - "command": "tsc", - "args": [ - "-p", - "." - ], - "problemMatcher": [ - "$tsc" - ], - "type": "shell" - }, - { - "label": "watch", - "command": "tsc", - "args": [ - "-w", - "-p", - "." - ], - "isBackground": true, - "problemMatcher": [ - "$tsc-watch" - ], - "type": "shell" - }, - { - // Ctrl+Shift+B - "type": "npm", - "group": { - "kind": "build", - "isDefault": true - }, - "presentation": { - "reveal": "silent" - }, - "problemMatcher": [ - "$eslint-stylish", - "$tsc", - "$tslint5" - ], - "script": "build" - } - ] -} diff --git a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/config/plugin.ts b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/config/plugin.ts index da7ce53a9f1e..33a9edf6742c 100755 --- a/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/config/plugin.ts +++ b/packages/midway-init/boilerplate/midway-demo-boilerplate/boilerplate/src/config/plugin.ts @@ -1,4 +1,3 @@ -import { EggPlugin } from 'midway' export default { - static: true, // default is true -} as EggPlugin + static: false, // default is true +}; diff --git a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/config.default.ts b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/config.default.ts index 2bb441a838a4..d368f688f787 100755 --- a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/config.default.ts +++ b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/config.default.ts @@ -1,10 +1,7 @@ -import { EggAppConfig, EggAppInfo, PowerPartial } from 'midway'; import * as path from 'path'; -export type DefaultConfig = PowerPartial - -export default (appInfo: EggAppInfo) => { - const config = {}; +export default (appInfo: any) => { + const config: any = {}; // use for cookie sign key, should change to your own and keep security config.keys = appInfo.name + '_1541510581780_3944'; @@ -15,12 +12,12 @@ export default (appInfo: EggAppInfo) => { templateViewEngine: 'nunjucks', root: path.join(appInfo.appDir, 'src/app/view'), mapping: { - '.html': 'nunjucks' - } + '.html': 'nunjucks', + }, }; config.assets = { - publicPath: 'public' + publicPath: 'public', }; return config; diff --git a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/plugin.ts b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/plugin.ts index 37b849fc5445..3d78822f951b 100755 --- a/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/plugin.ts +++ b/packages/midway-init/boilerplate/midway-ts-ant-design-pro-boilerplate/boilerplate/server/src/config/plugin.ts @@ -1,4 +1,4 @@ -import { EggPlugin } from 'midway' +import { EggPlugin } from 'midway'; export default { static: true, // default is true @@ -11,4 +11,4 @@ export default { enable: true, package: 'egg-view-assets', }, -} as EggPlugin +} as EggPlugin; diff --git a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_package.json b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_package.json index 142fed23f8b1..1a25e468baed 100755 --- a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_package.json +++ b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/_package.json @@ -38,7 +38,7 @@ "build": "midway-bin build -c" }, "ci": { - "version": "8, 10" + "version": "10" }, "repository": { "type": "git", diff --git a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/procfile.js b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/procfile.js deleted file mode 100644 index c9f858e49067..000000000000 --- a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/procfile.js +++ /dev/null @@ -1,32 +0,0 @@ -// you can use this file to deploy by pandora -// please use 'npm i pandora --save' first - -'use strict'; - -module.exports = pandora => { - - /** - * default is fork mode - */ - pandora - .fork('{{name}}', require.resolve('midway/server')); - - /** - * you can use cluster mode to start application - */ - // pandora - // .cluster('./cluster.js'); - - /** - * you can create another process here - */ - // pandora - // .process('background') - // .argv(['--expose-gc']); - - /** - * more features please visit our document. - * https://github.com/midwayjs/pandora/ - */ - -}; diff --git a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/config/plugin.ts b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/config/plugin.ts index da7ce53a9f1e..c0d6b2b26107 100755 --- a/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/config/plugin.ts +++ b/packages/midway-init/boilerplate/midway-ts-boilerplate/boilerplate/src/config/plugin.ts @@ -1,4 +1,4 @@ -import { EggPlugin } from 'midway' +import { EggPlugin } from 'midway'; export default { static: true, // default is true -} as EggPlugin +} as EggPlugin; From 1eecb45f7ba91304b99e710bf5479b22fc115220 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Mon, 29 Jul 2019 23:15:38 +0800 Subject: [PATCH 6/8] refactor: add dump method to midway-core --- packages/midway-core/package.json | 1 + packages/midway-core/src/container.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/midway-core/package.json b/packages/midway-core/package.json index 90607bab4043..0634e6c6079d 100644 --- a/packages/midway-core/package.json +++ b/packages/midway-core/package.json @@ -32,6 +32,7 @@ "camelcase": "^5.2.0", "debug": "^4.1.1", "globby": "^10.0.1", + "graphviz": "^0.0.8", "injection": "^1.4.2", "is-type-of": "^1.2.1" }, diff --git a/packages/midway-core/src/container.ts b/packages/midway-core/src/container.ts index 0f734086cc96..253b402c112d 100644 --- a/packages/midway-core/src/container.ts +++ b/packages/midway-core/src/container.ts @@ -24,6 +24,7 @@ import * as path from 'path'; import * as globby from 'globby'; import * as is from 'is-type-of'; +const graphviz = require('graphviz'); const camelcase = require('camelcase'); const debug = require('debug')('midway:container'); const CONTROLLERS = 'controllers'; @@ -383,4 +384,27 @@ export class MidwayContainer extends Container implements IContainer { } } + dumpDependency() { + const g = graphviz.digraph('G'); + + for (const [ id, module ] of this.dependencyMap.entries()) { + + g.addNode(id, { label: `${id}(${module.name})\nscope:${module.scope}`, fontsize: '10' }); + + module.properties.forEach((depId) => { + g.addEdge(id, depId, { label: `properties`, fontsize: '8' }); + }); + + module.constructorArgs.forEach((depId) => { + g.addEdge(id, depId, { label: 'constructor', fontsize: '8' }); + }); + } + + try { + return g.to_dot(); + } catch (err) { + console.error('generate injection dependency tree fail, err = ', err.message); + } + } + } From bdcd2e27962667a015ba7bc4bcf0ddbc0b33b04f Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Mon, 29 Jul 2019 23:24:18 +0800 Subject: [PATCH 7/8] test: add test case --- .../test/fixtures/complex_injection/dbAPI.ts | 34 +++++++++++++++++++ .../complex_injection/userController.ts | 22 ++++++++++++ .../fixtures/complex_injection/userService.ts | 13 +++++++ .../midway-core/test/midwayContainer.test.ts | 31 +++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 packages/midway-core/test/fixtures/complex_injection/dbAPI.ts create mode 100644 packages/midway-core/test/fixtures/complex_injection/userController.ts create mode 100644 packages/midway-core/test/fixtures/complex_injection/userService.ts diff --git a/packages/midway-core/test/fixtures/complex_injection/dbAPI.ts b/packages/midway-core/test/fixtures/complex_injection/dbAPI.ts new file mode 100644 index 000000000000..9d6ee41b037e --- /dev/null +++ b/packages/midway-core/test/fixtures/complex_injection/dbAPI.ts @@ -0,0 +1,34 @@ +import { inject, provide, scope, ScopeEnum } from 'injection'; + +@provide() +export class A { + config = { + c: 1 + }; +} + +@provide() +export class B { + config = { + c: 2 + }; +} + +@scope(ScopeEnum.Singleton) +@provide('newKey') +export class DbAPI { + + private config; + + constructor( + @inject() a, + hello, + @inject() b, + ) { + this.config = a.config.c + b.config.c; + } + + output() { + console.log(this.config); + } +} diff --git a/packages/midway-core/test/fixtures/complex_injection/userController.ts b/packages/midway-core/test/fixtures/complex_injection/userController.ts new file mode 100644 index 000000000000..16839a351146 --- /dev/null +++ b/packages/midway-core/test/fixtures/complex_injection/userController.ts @@ -0,0 +1,22 @@ +import { UserService } from './userService'; +import { inject, scope, ScopeEnum } from 'injection'; + +@scope(ScopeEnum.Request) +export class UserController { + + @inject('ctx') + ctx; + + @inject('newKey') + dbApi; + + @inject() + userService: UserService; + + async index() { + const {ctx} = this; + ctx.body = await this.userService.getUsers(); + ctx.status = 200; + } + +} diff --git a/packages/midway-core/test/fixtures/complex_injection/userService.ts b/packages/midway-core/test/fixtures/complex_injection/userService.ts new file mode 100644 index 000000000000..c3fae373e4ab --- /dev/null +++ b/packages/midway-core/test/fixtures/complex_injection/userService.ts @@ -0,0 +1,13 @@ +import { scope, ScopeEnum } from 'injection'; + +@scope(ScopeEnum.Request) +export class UserService { + + async getUsers() { + return new Promise(resolve => { + setTimeout(() => { + resolve(['harry', 'jiakun.du']); + }, 100); + }); + } +} diff --git a/packages/midway-core/test/midwayContainer.test.ts b/packages/midway-core/test/midwayContainer.test.ts index be2d1e47effa..0844f73250b6 100644 --- a/packages/midway-core/test/midwayContainer.test.ts +++ b/packages/midway-core/test/midwayContainer.test.ts @@ -4,6 +4,10 @@ import * as path from 'path'; import { MidwayContainer, MidwayHandlerKey } from '../src'; import { App } from './fixtures/ts-app-inject/app'; +import { UserService } from './fixtures/complex_injection/userService'; +import { UserController } from './fixtures/complex_injection/userController'; +import { A, B, DbAPI } from './fixtures/complex_injection/dbAPI'; + describe('/test/midwayContainer.test.ts', () => { it('should scan app dir and inject automatic', () => { @@ -55,4 +59,31 @@ describe('/test/midwayContainer.test.ts', () => { expect(my.$$mytest).eq('this is my test'); expect(my.$plugin2).deep.eq({text: 't'}); }); + + describe('dependency tree', () => { + + it('should generate dependency dot in requestContainer', async () => { + const applicationContext = new MidwayContainer(); + applicationContext.bind(UserService); + applicationContext.bind(UserController); + applicationContext.bind(DbAPI); + const newTree = await applicationContext.dumpDependency(); + expect(/userController/.test(newTree)).to.be.true; + expect(/newKey\(DbAPI\)/.test(newTree)).to.be.true; + }); + + it('should skip empty properties', async () => { + const applicationContext = new MidwayContainer(); + applicationContext.bind(UserService); + applicationContext.bind(UserController); + applicationContext.bind(DbAPI); + applicationContext.bind(A); + applicationContext.bind(B); + const newTree = await applicationContext.dumpDependency(); + expect(/userController/.test(newTree)).to.be.true; + expect(/newKey\(DbAPI\)/.test(newTree)).to.be.true; + expect(/"newKey" -> "b"/.test(newTree)).to.be.true; + }); + + }); }); From f4481b4cf2f80717c45ee02894042c4f91e47973 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Tue, 30 Jul 2019 10:27:24 +0800 Subject: [PATCH 8/8] v1.10.5 --- CHANGELOG.md | 11 +++++++++++ lerna.json | 2 +- packages/midway-bin/CHANGELOG.md | 8 ++++++++ packages/midway-bin/package.json | 2 +- packages/midway-core/CHANGELOG.md | 8 ++++++++ packages/midway-core/package.json | 6 +++--- packages/midway-decorator/CHANGELOG.md | 8 ++++++++ packages/midway-decorator/package.json | 4 ++-- packages/midway-definition/CHANGELOG.md | 8 ++++++++ packages/midway-definition/package.json | 4 ++-- packages/midway-init/CHANGELOG.md | 8 ++++++++ packages/midway-init/package.json | 4 ++-- packages/midway-mock/CHANGELOG.md | 11 +++++++++++ packages/midway-mock/package.json | 6 +++--- packages/midway-schedule/CHANGELOG.md | 8 ++++++++ packages/midway-schedule/package.json | 8 ++++---- packages/midway-web/CHANGELOG.md | 8 ++++++++ packages/midway-web/package.json | 12 ++++++------ packages/midway/CHANGELOG.md | 8 ++++++++ packages/midway/package.json | 6 +++--- 20 files changed, 113 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ccb072bc013..0edb77bfccc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + + +### Bug Fixes + +* compatible with midway mock ([d738b7f](https://github.com/midwayjs/midway/commit/d738b7f)) + + + + + ## [1.10.4](https://github.com/midwayjs/midway/compare/v1.10.3...v1.10.4) (2019-07-24) diff --git a/lerna.json b/lerna.json index a4b2868cde67..e05020cad857 100644 --- a/lerna.json +++ b/lerna.json @@ -15,5 +15,5 @@ } }, "npmClient": "npm", - "version": "1.10.4" + "version": "1.10.5" } diff --git a/packages/midway-bin/CHANGELOG.md b/packages/midway-bin/CHANGELOG.md index 9a9c83cb2ee1..3e67eea88038 100644 --- a/packages/midway-bin/CHANGELOG.md +++ b/packages/midway-bin/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + +**Note:** Version bump only for package midway-bin + + + + + ## [1.10.2](https://github.com/midwayjs/midway/compare/v1.10.1...v1.10.2) (2019-07-20) **Note:** Version bump only for package midway-bin diff --git a/packages/midway-bin/package.json b/packages/midway-bin/package.json index 648f5b7fc661..b3bc5bc5c73a 100644 --- a/packages/midway-bin/package.json +++ b/packages/midway-bin/package.json @@ -1,6 +1,6 @@ { "name": "midway-bin", - "version": "1.10.2", + "version": "1.10.5", "description": "Midway Command Tools", "main": "index.js", "bin": { diff --git a/packages/midway-core/CHANGELOG.md b/packages/midway-core/CHANGELOG.md index d463e333686f..f447068cba26 100644 --- a/packages/midway-core/CHANGELOG.md +++ b/packages/midway-core/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + +**Note:** Version bump only for package midway-core + + + + + ## [1.10.2](https://github.com/midwayjs/midway/compare/v1.10.1...v1.10.2) (2019-07-20) **Note:** Version bump only for package midway-core diff --git a/packages/midway-core/package.json b/packages/midway-core/package.json index 0634e6c6079d..5c4724635c88 100644 --- a/packages/midway-core/package.json +++ b/packages/midway-core/package.json @@ -1,6 +1,6 @@ { "name": "midway-core", - "version": "1.10.2", + "version": "1.10.5", "description": "midway core", "main": "dist/index", "typings": "dist/index.d.ts", @@ -24,11 +24,11 @@ "license": "MIT", "devDependencies": { "chai": "^4.2.0", - "midway-bin": "^1.10.2", + "midway-bin": "^1.10.5", "xmldom": "^0.1.27" }, "dependencies": { - "@midwayjs/decorator": "^1.10.2", + "@midwayjs/decorator": "^1.10.5", "camelcase": "^5.2.0", "debug": "^4.1.1", "globby": "^10.0.1", diff --git a/packages/midway-decorator/CHANGELOG.md b/packages/midway-decorator/CHANGELOG.md index 39003ebcb15b..0a1dbd6d9e5e 100644 --- a/packages/midway-decorator/CHANGELOG.md +++ b/packages/midway-decorator/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + +**Note:** Version bump only for package @midwayjs/decorator + + + + + ## [1.10.2](https://github.com/midwayjs/midway/compare/v1.10.1...v1.10.2) (2019-07-20) **Note:** Version bump only for package @midwayjs/decorator diff --git a/packages/midway-decorator/package.json b/packages/midway-decorator/package.json index 0fc1ab71dafb..7226c8866a7e 100644 --- a/packages/midway-decorator/package.json +++ b/packages/midway-decorator/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/decorator", - "version": "1.10.2", + "version": "1.10.5", "description": "definition decorator for midway project", "main": "dist/index", "typings": "dist/index.d.ts", @@ -16,7 +16,7 @@ "injection": "^1.4.2" }, "devDependencies": { - "midway-bin": "^1.10.2" + "midway-bin": "^1.10.5" }, "keywords": [ "midway", diff --git a/packages/midway-definition/CHANGELOG.md b/packages/midway-definition/CHANGELOG.md index 174260b7ae16..98057de7af81 100644 --- a/packages/midway-definition/CHANGELOG.md +++ b/packages/midway-definition/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + +**Note:** Version bump only for package @midwayjs/definition + + + + + ## [1.10.2](https://github.com/midwayjs/midway/compare/v1.10.1...v1.10.2) (2019-07-20) **Note:** Version bump only for package @midwayjs/definition diff --git a/packages/midway-definition/package.json b/packages/midway-definition/package.json index 01525531dc6d..a836db8648d8 100644 --- a/packages/midway-definition/package.json +++ b/packages/midway-definition/package.json @@ -1,6 +1,6 @@ { "name": "@midwayjs/definition", - "version": "1.10.2", + "version": "1.10.5", "description": "declare all midway dependencies by typescript definition", "typings": "dist/index.d.ts", "scripts": { @@ -16,7 +16,7 @@ "egg-logger": "^2.3.2" }, "devDependencies": { - "midway-bin": "^1.10.2" + "midway-bin": "^1.10.5" }, "keywords": [ "midway", diff --git a/packages/midway-init/CHANGELOG.md b/packages/midway-init/CHANGELOG.md index d8e1649ee549..1ac576cd23ad 100644 --- a/packages/midway-init/CHANGELOG.md +++ b/packages/midway-init/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + +**Note:** Version bump only for package midway-init + + + + + ## [1.10.4](https://github.com/midwayjs/midway/compare/v1.10.3...v1.10.4) (2019-07-24) diff --git a/packages/midway-init/package.json b/packages/midway-init/package.json index b62545e7b9b2..058c4d572179 100644 --- a/packages/midway-init/package.json +++ b/packages/midway-init/package.json @@ -1,6 +1,6 @@ { "name": "midway-init", - "version": "1.10.4", + "version": "1.10.5", "dependencies": { "co": "^4.6.0", "egg-init": "^1.16.1", @@ -13,7 +13,7 @@ "eslint": "^6.1.0", "eslint-config-egg": "^7.0.0", "intelli-espower-loader": "^1.0.1", - "midway-bin": "^1.10.2", + "midway-bin": "^1.10.5", "mm": "^2.5.0", "mz-modules": "^2.1.0", "power-assert": "^1.6.1", diff --git a/packages/midway-mock/CHANGELOG.md b/packages/midway-mock/CHANGELOG.md index 1bdd3f088cff..b55df1e1b545 100644 --- a/packages/midway-mock/CHANGELOG.md +++ b/packages/midway-mock/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + + +### Bug Fixes + +* compatible with midway mock ([d738b7f](https://github.com/midwayjs/midway/commit/d738b7f)) + + + + + ## [1.10.2](https://github.com/midwayjs/midway/compare/v1.10.1...v1.10.2) (2019-07-20) **Note:** Version bump only for package midway-mock diff --git a/packages/midway-mock/package.json b/packages/midway-mock/package.json index 7fd9cc2833be..27342da7594b 100644 --- a/packages/midway-mock/package.json +++ b/packages/midway-mock/package.json @@ -1,6 +1,6 @@ { "name": "midway-mock", - "version": "1.10.2", + "version": "1.10.5", "eggPlugin": { "name": "midway-mock" }, @@ -31,9 +31,9 @@ ], "license": "MIT", "devDependencies": { - "@midwayjs/decorator": "^1.10.2", + "@midwayjs/decorator": "^1.10.5", "injection": "^1.4.2", - "midway-bin": "^1.10.2" + "midway-bin": "^1.10.5" }, "dependencies": { "egg-mock": "^3.21.0", diff --git a/packages/midway-schedule/CHANGELOG.md b/packages/midway-schedule/CHANGELOG.md index 71e965446e2d..350d90ab5c85 100644 --- a/packages/midway-schedule/CHANGELOG.md +++ b/packages/midway-schedule/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + +**Note:** Version bump only for package midway-schedule + + + + + ## [1.10.2](https://github.com/midwayjs/midway/compare/v1.10.1...v1.10.2) (2019-07-20) **Note:** Version bump only for package midway-schedule diff --git a/packages/midway-schedule/package.json b/packages/midway-schedule/package.json index c83d80ce9b12..bd4478efd1d8 100644 --- a/packages/midway-schedule/package.json +++ b/packages/midway-schedule/package.json @@ -1,6 +1,6 @@ { "name": "midway-schedule", - "version": "1.10.2", + "version": "1.10.5", "description": "", "main": "index.js", "directories": { @@ -21,11 +21,11 @@ "keywords": [], "license": "MIT", "devDependencies": { - "midway-bin": "^1.10.2", - "midway-mock": "^1.10.2" + "midway-bin": "^1.10.5", + "midway-mock": "^1.10.5" }, "dependencies": { - "@midwayjs/decorator": "^1.10.2", + "@midwayjs/decorator": "^1.10.5", "injection": "^1.4.2", "is-type-of": "^1.2.1" }, diff --git a/packages/midway-web/CHANGELOG.md b/packages/midway-web/CHANGELOG.md index 66ee8a22e7a4..b8b83eec7afc 100644 --- a/packages/midway-web/CHANGELOG.md +++ b/packages/midway-web/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + +**Note:** Version bump only for package midway-web + + + + + ## [1.10.2](https://github.com/midwayjs/midway/compare/v1.10.1...v1.10.2) (2019-07-20) **Note:** Version bump only for package midway-web diff --git a/packages/midway-web/package.json b/packages/midway-web/package.json index 7a4feea987b1..20a9b5485df8 100644 --- a/packages/midway-web/package.json +++ b/packages/midway-web/package.json @@ -1,6 +1,6 @@ { "name": "midway-web", - "version": "1.10.2", + "version": "1.10.5", "description": "Midway Web Scene", "main": "dist/index", "typings": "dist/index.d.ts", @@ -30,8 +30,8 @@ "@types/react": "^16.0.38", "@types/react-dom": "^16.0.4", "is-type-of": "^1.2.1", - "midway-bin": "^1.10.2", - "midway-mock": "^1.10.2", + "midway-bin": "^1.10.5", + "midway-mock": "^1.10.5", "mz-modules": "^2.1.0", "pedding": "^1.1.0", "react": "^16.2.0", @@ -39,15 +39,15 @@ }, "dependencies": { "@eggjs/router": "^2.0.0", - "@midwayjs/decorator": "^1.10.2", + "@midwayjs/decorator": "^1.10.5", "debug": "^4.1.1", "egg": "^2.20.0", "egg-core": "^4.15.0", "egg-logger": "^2.3.2", "extend2": "^1.0.0", "injection": "^1.4.2", - "midway-core": "^1.10.2", - "midway-schedule": "^1.10.2", + "midway-core": "^1.10.5", + "midway-schedule": "^1.10.5", "mkdirp": "^0.5.1" }, "author": "Harry Chen ", diff --git a/packages/midway/CHANGELOG.md b/packages/midway/CHANGELOG.md index 3af3c7eb1c8f..97dae859ec54 100644 --- a/packages/midway/CHANGELOG.md +++ b/packages/midway/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.10.5](https://github.com/midwayjs/midway/compare/v1.10.4...v1.10.5) (2019-07-30) + +**Note:** Version bump only for package midway + + + + + ## [1.10.2](https://github.com/midwayjs/midway/compare/v1.10.1...v1.10.2) (2019-07-20) **Note:** Version bump only for package midway diff --git a/packages/midway/package.json b/packages/midway/package.json index 68e52e471307..846f6b5ba5c2 100644 --- a/packages/midway/package.json +++ b/packages/midway/package.json @@ -1,6 +1,6 @@ { "name": "midway", - "version": "1.10.2", + "version": "1.10.5", "description": "Midway Main Package", "main": "dist/index", "typings": "dist/index.d.ts", @@ -19,11 +19,11 @@ ], "license": "MIT", "devDependencies": { - "midway-bin": "^1.10.2" + "midway-bin": "^1.10.5" }, "dependencies": { "egg-cluster": "^1.23.0", - "midway-web": "^1.10.2" + "midway-web": "^1.10.5" }, "files": [ "bin",