@midwayjs/web 3.0.0-alpha.10 → 3.0.0-alpha.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,17 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- # [3.0.0-alpha.2](https://github.com/midwayjs/midway/compare/v3.0.0-alpha.1...v3.0.0-alpha.2) (2021-08-05)
7
-
8
- **Note:** Version bump only for package @midwayjs/web
9
-
10
-
6
+ ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
11
7
 
12
8
 
9
+ ### Bug Fixes
13
10
 
14
- # [3.0.0-alpha.1](https://github.com/midwayjs/midway/compare/v2.12.1...v3.0.0-alpha.1) (2021-08-04)
15
-
16
- **Note:** Version bump only for package @midwayjs/web
11
+ * task redefine context logger ([#1213](https://github.com/midwayjs/midway/issues/1213)) ([f8887c9](https://github.com/midwayjs/midway/commit/f8887c94b234b0156b8b4c6ad728c97a748c5a4f))
17
12
 
18
13
 
19
14
 
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  const rc = Symbol('Context#RequestContext');
3
+ const ctxLogger = Symbol('Context#ContextLogger');
3
4
  const { MidwayRequestContainer } = require('@midwayjs/core');
4
5
 
5
6
  module.exports = {
@@ -13,4 +14,15 @@ module.exports = {
13
14
  get startTime() {
14
15
  return this['starttime'];
15
16
  },
17
+
18
+ get logger() {
19
+ if (this[ctxLogger]) {
20
+ return this[ctxLogger];
21
+ }
22
+ return this.getLogger('logger');
23
+ },
24
+
25
+ set logger(customLogger) {
26
+ this[ctxLogger] = customLogger;
27
+ },
16
28
  };
package/app.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const pathMatching = require('egg-path-matching');
4
+ const { hasIdentifierMapping } = require('@midwayjs/decorator');
4
5
 
5
6
  class AppBootHook {
6
7
  constructor(app) {
@@ -35,7 +36,7 @@ class AppBootHook {
35
36
  const middlewareNames = this.coreMiddleware.concat(this.appMiddleware);
36
37
  // 等 midway 加载完成后,再去 use 中间件
37
38
  for (const name of middlewareNames) {
38
- if (this.app.getApplicationContext().registry.hasDefinition(name)) {
39
+ if (hasIdentifierMapping(name)) {
39
40
  const mwIns = await this.app.generateMiddleware(name);
40
41
  mwIns._name = name;
41
42
  this.app.use(mwIns);
@@ -5,16 +5,16 @@ const path_1 = require("path");
5
5
  const base_1 = require("./base");
6
6
  const EGG_LOADER = Symbol.for('egg#loader');
7
7
  const EGG_PATH = Symbol.for('egg#eggPath');
8
- const EggAppWorkerLoader = base_1.createAppWorkerLoader();
9
- const BaseEggApplication = base_1.createEggApplication();
10
- const EggAgentWorkerLoader = base_1.createAgentWorkerLoader();
11
- const BaseEggAgent = base_1.createEggAgent();
8
+ const EggAppWorkerLoader = (0, base_1.createAppWorkerLoader)();
9
+ const BaseEggApplication = (0, base_1.createEggApplication)();
10
+ const EggAgentWorkerLoader = (0, base_1.createAgentWorkerLoader)();
11
+ const BaseEggAgent = (0, base_1.createEggAgent)();
12
12
  class EggApplication extends BaseEggApplication {
13
13
  get [EGG_LOADER]() {
14
14
  return EggAppWorkerLoader;
15
15
  }
16
16
  get [EGG_PATH]() {
17
- return path_1.join(__dirname, '../');
17
+ return (0, path_1.join)(__dirname, '../');
18
18
  }
19
19
  }
20
20
  exports.Application = EggApplication;
@@ -23,7 +23,7 @@ class EggAgent extends BaseEggAgent {
23
23
  return EggAgentWorkerLoader;
24
24
  }
25
25
  get [EGG_PATH]() {
26
- return path_1.join(__dirname, '../');
26
+ return (0, path_1.join)(__dirname, '../');
27
27
  }
28
28
  }
29
29
  exports.Agent = EggAgent;
package/dist/base.js CHANGED
@@ -21,8 +21,8 @@ function getFramework() {
21
21
  /**
22
22
  * create real egg loader and application object
23
23
  */
24
- const pkg = core_1.safeRequire(path_1.join(process.env.MIDWAY_PROJECT_APPDIR || process.cwd(), 'package.json'), false);
25
- customFramework = core_1.safelyGet('egg.framework', pkg);
24
+ const pkg = (0, core_1.safeRequire)((0, path_1.join)(process.env.MIDWAY_PROJECT_APPDIR || process.cwd(), 'package.json'), false);
25
+ customFramework = (0, core_1.safelyGet)('egg.framework', pkg);
26
26
  if (customFramework) {
27
27
  return customFramework;
28
28
  }
@@ -44,19 +44,22 @@ const createAppWorkerLoader = () => {
44
44
  if (this.app.options.typescript || this.app.options.isTsMode) {
45
45
  process.env.EGG_TYPESCRIPT = 'true';
46
46
  }
47
- const result = utils_1.parseNormalDir(this.app.options['baseDir'], this.app.options.isTsMode);
47
+ const result = (0, utils_1.parseNormalDir)(this.app.options['baseDir'], this.app.options.isTsMode);
48
48
  this.baseDir = result.baseDir;
49
49
  this.options.baseDir = this.baseDir;
50
50
  this.appDir = this.app.appDir = result.appDir;
51
51
  }
52
52
  const result = super.getEggPaths();
53
- const monorepoRoot = utils_1.findLernaRoot();
53
+ const monorepoRoot = (0, utils_1.findLernaRoot)();
54
54
  if (monorepoRoot) {
55
55
  result.push(monorepoRoot);
56
56
  }
57
57
  if (process.env.MIDWAY_EGG_PLUGIN_PATH) {
58
58
  result.push(process.env.MIDWAY_EGG_PLUGIN_PATH);
59
59
  }
60
+ if (process.cwd() !== this.appDir) {
61
+ result.push(this.appDir);
62
+ }
60
63
  const pathSet = new Set(result);
61
64
  return Array.from(pathSet);
62
65
  }
@@ -76,13 +79,13 @@ const createAppWorkerLoader = () => {
76
79
  getServerEnv() {
77
80
  // 这里和 egg 不同的是,一是修改了根路径,二是增加了环境变量
78
81
  let serverEnv = this.options.env;
79
- let envPath = path_1.join(this.appDir, 'config/env');
80
- if (!serverEnv && fs_1.existsSync(envPath)) {
81
- serverEnv = fs_1.readFileSync(envPath, 'utf8').trim();
82
+ let envPath = (0, path_1.join)(this.appDir, 'config/env');
83
+ if (!serverEnv && (0, fs_1.existsSync)(envPath)) {
84
+ serverEnv = (0, fs_1.readFileSync)(envPath, 'utf8').trim();
82
85
  }
83
- envPath = path_1.join(this.appDir, 'config/serverEnv');
84
- if (!serverEnv && fs_1.existsSync(envPath)) {
85
- serverEnv = fs_1.readFileSync(envPath, 'utf8').trim();
86
+ envPath = (0, path_1.join)(this.appDir, 'config/serverEnv');
87
+ if (!serverEnv && (0, fs_1.existsSync)(envPath)) {
88
+ serverEnv = (0, fs_1.readFileSync)(envPath, 'utf8').trim();
86
89
  }
87
90
  if (!serverEnv) {
88
91
  serverEnv = process.env.MIDWAY_SERVER_ENV || process.env.EGG_SERVER_ENV;
@@ -151,19 +154,22 @@ const createAgentWorkerLoader = () => {
151
154
  if (this.app.options.typescript || this.app.options.isTsMode) {
152
155
  process.env.EGG_TYPESCRIPT = 'true';
153
156
  }
154
- const result = utils_1.parseNormalDir(this.app.options['baseDir'], this.app.options.isTsMode);
157
+ const result = (0, utils_1.parseNormalDir)(this.app.options['baseDir'], this.app.options.isTsMode);
155
158
  this.baseDir = result.baseDir;
156
159
  this.options.baseDir = this.baseDir;
157
160
  this.appDir = this.app.appDir = result.appDir;
158
161
  }
159
162
  const result = super.getEggPaths();
160
- const monorepoRoot = utils_1.findLernaRoot();
163
+ const monorepoRoot = (0, utils_1.findLernaRoot)();
161
164
  if (monorepoRoot) {
162
165
  result.push(monorepoRoot);
163
166
  }
164
167
  if (process.env.MIDWAY_EGG_PLUGIN_PATH) {
165
168
  result.push(process.env.MIDWAY_EGG_PLUGIN_PATH);
166
169
  }
170
+ if (process.cwd() !== this.appDir) {
171
+ result.push(this.appDir);
172
+ }
167
173
  const pathSet = new Set(result);
168
174
  return Array.from(pathSet);
169
175
  }
@@ -183,13 +189,13 @@ const createAgentWorkerLoader = () => {
183
189
  getServerEnv() {
184
190
  // 这里和 egg 不同的是,一是修改了根路径,二是增加了环境变量
185
191
  let serverEnv = this.options.env;
186
- let envPath = path_1.join(this.appDir, 'config/env');
187
- if (!serverEnv && fs_1.existsSync(envPath)) {
188
- serverEnv = fs_1.readFileSync(envPath, 'utf8').trim();
192
+ let envPath = (0, path_1.join)(this.appDir, 'config/env');
193
+ if (!serverEnv && (0, fs_1.existsSync)(envPath)) {
194
+ serverEnv = (0, fs_1.readFileSync)(envPath, 'utf8').trim();
189
195
  }
190
- envPath = path_1.join(this.appDir, 'config/serverEnv');
191
- if (!serverEnv && fs_1.existsSync(envPath)) {
192
- serverEnv = fs_1.readFileSync(envPath, 'utf8').trim();
196
+ envPath = (0, path_1.join)(this.appDir, 'config/serverEnv');
197
+ if (!serverEnv && (0, fs_1.existsSync)(envPath)) {
198
+ serverEnv = (0, fs_1.readFileSync)(envPath, 'utf8').trim();
193
199
  }
194
200
  if (!serverEnv) {
195
201
  serverEnv = process.env.MIDWAY_SERVER_ENV || process.env.EGG_SERVER_ENV;
@@ -244,7 +250,7 @@ const createEggApplication = () => {
244
250
  }
245
251
  get loggers() {
246
252
  if (!this[LOGGERS]) {
247
- this[LOGGERS] = logger_1.createLoggers(this);
253
+ this[LOGGERS] = (0, logger_1.createLoggers)(this);
248
254
  }
249
255
  return this[LOGGERS];
250
256
  }
@@ -275,7 +281,7 @@ const createEggAgent = () => {
275
281
  }
276
282
  get loggers() {
277
283
  if (!this[LOGGERS]) {
278
- this[LOGGERS] = logger_1.createLoggers(this);
284
+ this[LOGGERS] = (0, logger_1.createLoggers)(this);
279
285
  }
280
286
  return this[LOGGERS];
281
287
  }
@@ -43,7 +43,7 @@ class MidwayWebSingleProcessFramework {
43
43
  async initialize(options) {
44
44
  const opts = {
45
45
  baseDir: options.appDir,
46
- framework: path_1.resolve(__dirname, '../application'),
46
+ framework: (0, path_1.resolve)(__dirname, '../application'),
47
47
  plugins: this.configurationOptions.plugins,
48
48
  mode: 'single',
49
49
  isTsMode: this.isTsMode || true,
@@ -62,10 +62,20 @@ class MidwayWebSingleProcessFramework {
62
62
  this.configurationOptions.key = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.key);
63
63
  this.configurationOptions.cert = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.cert);
64
64
  this.configurationOptions.ca = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.ca);
65
- this.server = require('https').createServer(this.configurationOptions, this.app.callback());
65
+ if (this.configurationOptions.http2) {
66
+ this.server = require('http2').createSecureServer(this.configurationOptions, this.app.callback());
67
+ }
68
+ else {
69
+ this.server = require('https').createServer(this.configurationOptions, this.app.callback());
70
+ }
66
71
  }
67
72
  else {
68
- this.server = require('http').createServer(this.app.callback());
73
+ if (this.configurationOptions.http2) {
74
+ this.server = require('http2').createServer(this.app.callback());
75
+ }
76
+ else {
77
+ this.server = require('http').createServer(this.app.callback());
78
+ }
69
79
  }
70
80
  if (options.isMainFramework === undefined) {
71
81
  await this.loadExtension();
@@ -114,7 +114,7 @@ class MidwayWebFramework extends koa_1.MidwayKoaBaseFramework {
114
114
  });
115
115
  // register config
116
116
  this.getApplicationContext().registerDataHandler(decorator_1.CONFIG_KEY, key => {
117
- return key ? core_1.safelyGet(key, this.app.config) : this.app.config;
117
+ return key ? (0, core_1.safelyGet)(key, this.app.config) : this.app.config;
118
118
  });
119
119
  // register logger
120
120
  this.getApplicationContext().registerDataHandler(decorator_1.LOGGER_KEY, key => {
package/dist/logger.js CHANGED
@@ -35,32 +35,32 @@ const levelTransform = level => {
35
35
  }
36
36
  };
37
37
  function isEmptyFile(p) {
38
- const content = fs_1.readFileSync(p, {
38
+ const content = (0, fs_1.readFileSync)(p, {
39
39
  encoding: 'utf8',
40
40
  });
41
41
  return content === null || content === undefined || content === '';
42
42
  }
43
43
  function checkEggLoggerExistsAndBackup(dir, fileName) {
44
- const file = path_1.isAbsolute(fileName) ? fileName : path_1.join(dir, fileName);
45
- if (fs_1.existsSync(file) && !fs_1.lstatSync(file).isSymbolicLink()) {
44
+ const file = (0, path_1.isAbsolute)(fileName) ? fileName : (0, path_1.join)(dir, fileName);
45
+ if ((0, fs_1.existsSync)(file) && !(0, fs_1.lstatSync)(file).isSymbolicLink()) {
46
46
  // 如果是空文件,则直接删了,否则加入备份队列
47
47
  if (isEmptyFile(file)) {
48
48
  // midway 的软链在 windows 底下也不会创建出来,在 windows 底下就不做文件删除了
49
49
  if (!isWindows) {
50
- fs_1.unlinkSync(file);
50
+ (0, fs_1.unlinkSync)(file);
51
51
  }
52
52
  }
53
53
  else {
54
- const timeFormat = utils_1.getCurrentDateString();
55
- fs_1.renameSync(file, file + '.' + timeFormat + '_eggjs_bak');
54
+ const timeFormat = (0, utils_1.getCurrentDateString)();
55
+ (0, fs_1.renameSync)(file, file + '.' + timeFormat + '_eggjs_bak');
56
56
  }
57
57
  }
58
58
  }
59
59
  function removeSymbol(dir, fileName) {
60
- const file = path_1.isAbsolute(fileName) ? fileName : path_1.join(dir, fileName);
61
- if (fs_1.existsSync(file) && fs_1.lstatSync(file).isSymbolicLink()) {
60
+ const file = (0, path_1.isAbsolute)(fileName) ? fileName : (0, path_1.join)(dir, fileName);
61
+ if ((0, fs_1.existsSync)(file) && (0, fs_1.lstatSync)(file).isSymbolicLink()) {
62
62
  if (!isWindows) {
63
- fs_1.unlinkSync(file);
63
+ (0, fs_1.unlinkSync)(file);
64
64
  }
65
65
  }
66
66
  }
package/dist/utils.js CHANGED
@@ -8,19 +8,19 @@ const fs_1 = require("fs");
8
8
  const parseNormalDir = (baseDir, isTypescript = true) => {
9
9
  if (isTypescript) {
10
10
  // 这里要么就是 src 目录,要么就已经是根目录
11
- if (!fs_1.existsSync(path_1.join(baseDir, 'package.json'))) {
12
- baseDir = path_1.basename(baseDir);
11
+ if (!(0, fs_1.existsSync)((0, path_1.join)(baseDir, 'package.json'))) {
12
+ baseDir = (0, path_1.basename)(baseDir);
13
13
  }
14
- const isTypeScriptEnv = bootstrap_1.isTypeScriptEnvironment();
14
+ const isTypeScriptEnv = (0, bootstrap_1.isTypeScriptEnvironment)();
15
15
  if (isTypeScriptEnv) {
16
16
  return {
17
- baseDir: path_1.join(baseDir, 'src'),
17
+ baseDir: (0, path_1.join)(baseDir, 'src'),
18
18
  appDir: baseDir,
19
19
  };
20
20
  }
21
21
  else {
22
22
  return {
23
- baseDir: path_1.join(baseDir, 'dist'),
23
+ baseDir: (0, path_1.join)(baseDir, 'dist'),
24
24
  appDir: baseDir,
25
25
  };
26
26
  }
@@ -36,8 +36,8 @@ const parseNormalDir = (baseDir, isTypescript = true) => {
36
36
  exports.parseNormalDir = parseNormalDir;
37
37
  const findLernaRoot = (findRoot = process.cwd()) => {
38
38
  const userHome = process.env.HOME;
39
- return find_up_1.sync(directory => {
40
- if (find_up_1.sync.exists(path_1.join(directory, 'lerna.json'))) {
39
+ return (0, find_up_1.sync)(directory => {
40
+ if (find_up_1.sync.exists((0, path_1.join)(directory, 'lerna.json'))) {
41
41
  return directory;
42
42
  }
43
43
  if (directory === userHome) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/web",
3
- "version": "3.0.0-alpha.10+f8cccb92",
3
+ "version": "3.0.0-alpha.37+574e016e",
4
4
  "description": "Midway Web Framework for Egg.js",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@midwayjs/decorator": "^3.0.0-alpha.2",
31
- "@midwayjs/mock": "^3.0.0-alpha.10+f8cccb92",
30
+ "@midwayjs/decorator": "^3.0.0-alpha.37+574e016e",
31
+ "@midwayjs/mock": "^3.0.0-alpha.37+574e016e",
32
32
  "dayjs": "^1.10.4",
33
33
  "egg-socket.io": "^4.1.6",
34
34
  "egg-view-nunjucks": "^2.2.0",
@@ -41,17 +41,17 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@eggjs/router": "^2.0.0",
44
- "@midwayjs/bootstrap": "^3.0.0-alpha.10+f8cccb92",
45
- "@midwayjs/core": "^3.0.0-alpha.10+f8cccb92",
46
- "@midwayjs/koa": "^3.0.0-alpha.10+f8cccb92",
47
- "@midwayjs/logger": "^2.11.3",
44
+ "@midwayjs/bootstrap": "^3.0.0-alpha.37+574e016e",
45
+ "@midwayjs/core": "^3.0.0-alpha.37+574e016e",
46
+ "@midwayjs/koa": "^3.0.0-alpha.37+574e016e",
47
+ "@midwayjs/logger": "^2.13.0",
48
48
  "debug": "^4.1.1",
49
49
  "egg": "^2.28.0",
50
50
  "egg-logger": "^2.4.2",
51
51
  "egg-path-matching": "^1.0.1",
52
52
  "extend2": "^1.0.0",
53
53
  "find-up": "^5.0.0",
54
- "midway-schedule": "^3.0.0-alpha.10+f8cccb92",
54
+ "midway-schedule": "^2.12.9",
55
55
  "mkdirp": "^1.0.4"
56
56
  },
57
57
  "author": "Harry Chen <czy88840616@gmail.com>",
@@ -59,5 +59,8 @@
59
59
  "type": "git",
60
60
  "url": "http://github.com/midwayjs/midway.git"
61
61
  },
62
- "gitHead": "f8cccb92aaef82e7c43c6eb5ef2518256ef99a1e"
62
+ "engines": {
63
+ "node": ">=10.10.0"
64
+ },
65
+ "gitHead": "574e016e6bdc4be94f2ee8f82ada1670011911f1"
63
66
  }