@modern-js/plugin-koa 1.5.1 → 1.16.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,59 @@
1
1
  # @modern-js/plugin-koa
2
2
 
3
+ ## 1.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1100dd58c: chore: support react 18
8
+
9
+ chore: 支持 React 18
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [641592f52]
14
+ - Updated dependencies [3904b30a5]
15
+ - Updated dependencies [1100dd58c]
16
+ - Updated dependencies [e04e6e76a]
17
+ - Updated dependencies [81c66e4a4]
18
+ - Updated dependencies [2c305b6f5]
19
+ - Updated dependencies [020b9bd52]
20
+ - @modern-js/utils@1.16.0
21
+ - @modern-js/bff-runtime@1.16.0
22
+ - @modern-js/bff-core@1.16.0
23
+
24
+ ## 1.15.0
25
+
26
+ ### Patch Changes
27
+
28
+ - c0d8dac: fix: remove package adapter-helpers and bff runtime export
29
+ - 4524de6: fix: add server hook and types
30
+ fix: 增加 server hook API
31
+ - Updated dependencies [c0d8dac]
32
+ - Updated dependencies [8658a78]
33
+ - Updated dependencies [05d4a4f]
34
+ - Updated dependencies [7bfaaf9]
35
+ - Updated dependencies [b1f7000]
36
+ - Updated dependencies [ad05af9]
37
+ - Updated dependencies [5d53d1c]
38
+ - Updated dependencies [37cd159]
39
+ - @modern-js/bff-core@1.15.0
40
+ - @modern-js/utils@1.15.0
41
+ - @modern-js/bff-runtime@1.15.0
42
+
43
+ ## 1.5.2
44
+
45
+ ### Patch Changes
46
+
47
+ - f745969: fix: allow BFF function to return void
48
+ fix: 允许 BFF 函数返回 void
49
+ - Updated dependencies [aadd066]
50
+ - Updated dependencies [4fc801f]
51
+ - Updated dependencies [83660b6]
52
+ - Updated dependencies [c8614b8]
53
+ - @modern-js/bff-core@1.2.0
54
+ - @modern-js/utils@1.8.0
55
+ - @modern-js/bff-runtime@1.4.0
56
+
3
57
  ## 1.5.1
4
58
 
5
59
  ### Patch 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
@@ -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;
@@ -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",
14
+ "version": "1.16.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.3",
39
- "@modern-js/bff-runtime": "^1.3.0",
40
- "@modern-js/utils": "^1.7.12",
37
+ "@modern-js/bff-core": "1.16.0",
38
+ "@modern-js/bff-runtime": "1.16.0",
39
+ "@modern-js/utils": "1.16.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.13.0",
47
- "@modern-js/server-core": "1.4.1",
48
- "@scripts/build": "0.0.0",
49
- "@scripts/jest-config": "0.0.0",
45
+ "@modern-js/core": "1.16.0",
46
+ "@modern-js/server-core": "1.16.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",
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
  }