@modern-js/plugin-koa 1.5.1-beta.0 → 1.15.0

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
@@ -1,5 +1,47 @@
1
1
  # @modern-js/plugin-koa
2
2
 
3
+ ## 1.15.0
4
+
5
+ ### Patch Changes
6
+
7
+ - c0d8dac: fix: remove package adapter-helpers and bff runtime export
8
+ - 4524de6: fix: add server hook and types
9
+ fix: 增加 server hook API
10
+ - Updated dependencies [c0d8dac]
11
+ - Updated dependencies [8658a78]
12
+ - Updated dependencies [05d4a4f]
13
+ - Updated dependencies [7bfaaf9]
14
+ - Updated dependencies [b1f7000]
15
+ - Updated dependencies [ad05af9]
16
+ - Updated dependencies [5d53d1c]
17
+ - Updated dependencies [37cd159]
18
+ - @modern-js/bff-core@1.15.0
19
+ - @modern-js/utils@1.15.0
20
+ - @modern-js/bff-runtime@1.15.0
21
+
22
+ ## 1.5.2
23
+
24
+ ### Patch Changes
25
+
26
+ - f745969: fix: allow BFF function to return void
27
+ fix: 允许 BFF 函数返回 void
28
+ - Updated dependencies [aadd066]
29
+ - Updated dependencies [4fc801f]
30
+ - Updated dependencies [83660b6]
31
+ - Updated dependencies [c8614b8]
32
+ - @modern-js/bff-core@1.2.0
33
+ - @modern-js/utils@1.8.0
34
+ - @modern-js/bff-runtime@1.4.0
35
+
36
+ ## 1.5.1
37
+
38
+ ### Patch Changes
39
+
40
+ - 74f7fd7: fix: fix bff hot reload not works when has app.ts
41
+ fix: 修复有 app.ts 的时候, bff 热更新不生效的问题
42
+ - Updated dependencies [74f7fd7]
43
+ - @modern-js/bff-core@1.1.3
44
+
3
45
  ## 1.5.0
4
46
 
5
47
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import { createRuntimeExportsUtils } from '@modern-js/utils';
3
- import { getRelativeRuntimePath } from '@modern-js/adapter-helpers';
3
+ import { getRelativeRuntimePath } from '@modern-js/bff-core';
4
4
  export default (() => ({
5
5
  name: '@modern-js/plugin-koa',
6
6
  setup: api => {
@@ -39,25 +39,13 @@ export default (() => ({
39
39
  },
40
40
 
41
41
  addRuntimeExports(input) {
42
- const {
43
- appDirectory
44
- } = useAppContext();
45
-
46
- const runtimePath = require.resolve(`@modern-js/runtime`, {
47
- paths: [appDirectory]
48
- });
49
-
50
42
  const currentFile = bffExportsUtils.getPath();
51
- const runtimeDir = path.dirname(runtimePath);
52
- const relativeBffPath = path.relative(path.dirname(currentFile), path.join(runtimeDir, './exports/server'));
53
43
  const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
54
44
  const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve('koa'));
55
- bffExportsUtils.addExport(`const bffRuntime = require('${relativeBffPath}');
56
- const pluginRuntime = require('${relativeRuntimeModulePath}');
45
+ bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
57
46
  const Koa = require('${relativeFramePath}')
58
47
  module.exports = {
59
48
  Koa: Koa,
60
- ...bffRuntime,
61
49
  ...pluginRuntime
62
50
  }
63
51
  `);
@@ -1,4 +1,4 @@
1
- import { createStorage } from '@modern-js/adapter-helpers';
1
+ import { createStorage } from '@modern-js/bff-core';
2
2
  const {
3
3
  run,
4
4
  useContext
@@ -12,6 +12,7 @@ const findAppModule = async apiDir => {
12
12
 
13
13
  for (const filename of paths) {
14
14
  if (await fs.pathExists(filename)) {
15
+ // 每次获取 app.ts 的时候,避免使用缓存的 app.ts
15
16
  delete require.cache[filename];
16
17
  return compatRequire(filename);
17
18
  }
@@ -1,2 +1,3 @@
1
+ export const hook = attacher => attacher;
1
2
  export { useContext } from "./context";
2
3
  export * from '@modern-js/bff-core';
@@ -50,10 +50,10 @@ export const createRouteHandler = handler => {
50
50
  if (isWithMetaHandler(handler)) {
51
51
  try {
52
52
  handleResponseMeta(ctx, handler);
53
- const result = await handler(input);
53
+ const body = await handler(input);
54
54
 
55
- if (result) {
56
- ctx.body = result;
55
+ if (typeof body !== 'undefined') {
56
+ ctx.body = body;
57
57
  }
58
58
  } catch (error) {
59
59
  if (error instanceof Error) {
@@ -85,7 +85,11 @@ export const createRouteHandler = handler => {
85
85
  }
86
86
  } else {
87
87
  const args = Object.values(input.params).concat(input);
88
- ctx.body = await handler(...args);
88
+ const body = await handler(...args);
89
+
90
+ if (typeof body !== 'undefined') {
91
+ ctx.body = body;
92
+ }
89
93
  }
90
94
  };
91
95
 
@@ -9,7 +9,7 @@ var path = _interopRequireWildcard(require("path"));
9
9
 
10
10
  var _utils = require("@modern-js/utils");
11
11
 
12
- var _adapterHelpers = require("@modern-js/adapter-helpers");
12
+ var _bffCore = require("@modern-js/bff-core");
13
13
 
14
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
15
 
@@ -31,7 +31,7 @@ var _default = () => ({
31
31
  } = appContext;
32
32
  bffExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'server');
33
33
  const serverRuntimePath = bffExportsUtils.getPath();
34
- const relativeRuntimePath = (0, _adapterHelpers.getRelativeRuntimePath)(appDirectory, serverRuntimePath);
34
+ const relativeRuntimePath = (0, _bffCore.getRelativeRuntimePath)(appDirectory, serverRuntimePath);
35
35
 
36
36
  if (process.env.NODE_ENV === 'production') {
37
37
  return {
@@ -53,25 +53,13 @@ var _default = () => ({
53
53
  },
54
54
 
55
55
  addRuntimeExports(input) {
56
- const {
57
- appDirectory
58
- } = useAppContext();
59
-
60
- const runtimePath = require.resolve(`@modern-js/runtime`, {
61
- paths: [appDirectory]
62
- });
63
-
64
56
  const currentFile = bffExportsUtils.getPath();
65
- const runtimeDir = path.dirname(runtimePath);
66
- const relativeBffPath = path.relative(path.dirname(currentFile), path.join(runtimeDir, './exports/server'));
67
57
  const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
68
58
  const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve('koa'));
69
- bffExportsUtils.addExport(`const bffRuntime = require('${relativeBffPath}');
70
- const pluginRuntime = require('${relativeRuntimeModulePath}');
59
+ bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
71
60
  const Koa = require('${relativeFramePath}')
72
61
  module.exports = {
73
62
  Koa: Koa,
74
- ...bffRuntime,
75
63
  ...pluginRuntime
76
64
  }
77
65
  `);
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useContext = exports.run = void 0;
7
7
 
8
- var _adapterHelpers = require("@modern-js/adapter-helpers");
8
+ var _bffCore = require("@modern-js/bff-core");
9
9
 
10
10
  const {
11
11
  run,
12
12
  useContext
13
- } = (0, _adapterHelpers.createStorage)();
13
+ } = (0, _bffCore.createStorage)();
14
14
  exports.useContext = useContext;
15
15
  exports.run = run;
@@ -31,6 +31,7 @@ const findAppModule = async apiDir => {
31
31
 
32
32
  for (const filename of paths) {
33
33
  if (await _utils.fs.pathExists(filename)) {
34
+ // 每次获取 app.ts 的时候,避免使用缓存的 app.ts
34
35
  delete require.cache[filename];
35
36
  return (0, _utils.compatRequire)(filename);
36
37
  }
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
+ hook: true,
7
8
  useContext: true
8
9
  };
10
+ exports.hook = void 0;
9
11
  Object.defineProperty(exports, "useContext", {
10
12
  enumerable: true,
11
13
  get: function () {
@@ -27,4 +29,8 @@ Object.keys(_bffCore).forEach(function (key) {
27
29
  return _bffCore[key];
28
30
  }
29
31
  });
30
- });
32
+ });
33
+
34
+ const hook = attacher => attacher;
35
+
36
+ exports.hook = hook;
@@ -61,10 +61,10 @@ const createRouteHandler = handler => {
61
61
  if ((0, _bffCore.isWithMetaHandler)(handler)) {
62
62
  try {
63
63
  handleResponseMeta(ctx, handler);
64
- const result = await handler(input);
64
+ const body = await handler(input);
65
65
 
66
- if (result) {
67
- ctx.body = result;
66
+ if (typeof body !== 'undefined') {
67
+ ctx.body = body;
68
68
  }
69
69
  } catch (error) {
70
70
  if (error instanceof Error) {
@@ -96,7 +96,11 @@ const createRouteHandler = handler => {
96
96
  }
97
97
  } else {
98
98
  const args = Object.values(input.params).concat(input);
99
- ctx.body = await handler(...args);
99
+ const body = await handler(...args);
100
+
101
+ if (typeof body !== 'undefined') {
102
+ ctx.body = body;
103
+ }
100
104
  }
101
105
  };
102
106
 
@@ -1,2 +1,4 @@
1
+ import type { Middleware } from 'koa';
2
+ export declare const hook: (attacher: Middleware) => Middleware<import("koa").DefaultState, import("koa").DefaultContext, any>;
1
3
  export { useContext } from './context';
2
4
  export * from '@modern-js/bff-core';
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.5.1-beta.0",
14
+ "version": "1.15.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -34,19 +34,18 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@babel/runtime": "^7.18.0",
37
- "@modern-js/adapter-helpers": "^1.3.0",
38
- "@modern-js/bff-core": "^1.1.0",
39
- "@modern-js/bff-runtime": "^1.3.0",
40
- "@modern-js/utils": "^1.7.11",
37
+ "@modern-js/bff-core": "1.15.0",
38
+ "@modern-js/bff-runtime": "1.15.0",
39
+ "@modern-js/utils": "1.15.0",
41
40
  "koa-body": "^4.2.0",
42
41
  "koa-router": "^10.0.0",
43
42
  "type-is": "^1.6.18"
44
43
  },
45
44
  "devDependencies": {
46
- "@modern-js/core": "1.12.4",
47
- "@modern-js/server-core": "1.4.0",
48
- "@scripts/build": "0.0.0",
49
- "@scripts/jest-config": "0.0.0",
45
+ "@modern-js/core": "1.15.0",
46
+ "@modern-js/server-core": "1.15.0",
47
+ "@scripts/build": "1.15.0",
48
+ "@scripts/jest-config": "1.15.0",
50
49
  "@types/jest": "^27",
51
50
  "@types/koa": "^2.13.4",
52
51
  "@types/koa-router": "^7.4.4",
@@ -69,8 +68,7 @@
69
68
  },
70
69
  "publishConfig": {
71
70
  "registry": "https://registry.npmjs.org/",
72
- "access": "public",
73
- "types": "./dist/types/index.d.ts"
71
+ "access": "public"
74
72
  },
75
73
  "wireit": {
76
74
  "build": {
package/types.d.ts CHANGED
@@ -14,6 +14,4 @@ declare module '@modern-js/runtime/server' {
14
14
  export function hook(attacher: KoaAttacher): KoaAttacher;
15
15
 
16
16
  export * from '@modern-js/bff-core';
17
-
18
- export * from '@modern-js/bff-runtime';
19
17
  }