@modern-js/plugin-express 1.7.2 → 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,51 @@
1
1
  # @modern-js/plugin-express
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/types@1.16.0
23
+ - @modern-js/bff-core@1.16.0
24
+
25
+ ## 1.15.0
26
+
27
+ ### Minor Changes
28
+
29
+ - 1f8b492: feat: support afterLambdaRegisted hook
30
+
31
+ ### Patch Changes
32
+
33
+ - c0d8dac: fix: remove package adapter-helpers and bff runtime export
34
+ - 4524de6: fix: add server hook and types
35
+ fix: 增加 server hook API
36
+ - Updated dependencies [c0d8dac]
37
+ - Updated dependencies [8658a78]
38
+ - Updated dependencies [05d4a4f]
39
+ - Updated dependencies [7bfaaf9]
40
+ - Updated dependencies [b1f7000]
41
+ - Updated dependencies [ad05af9]
42
+ - Updated dependencies [5d53d1c]
43
+ - Updated dependencies [37cd159]
44
+ - @modern-js/bff-core@1.15.0
45
+ - @modern-js/utils@1.15.0
46
+ - @modern-js/types@1.15.0
47
+ - @modern-js/bff-runtime@1.15.0
48
+
3
49
  ## 1.7.2
4
50
 
5
51
  ### 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-express',
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('express'));
55
- bffExportsUtils.addExport(`const bffRuntime = require('${relativeBffPath}');
56
- const pluginRuntime = require('${relativeRuntimeModulePath}');
45
+ bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
57
46
  const express = require('${relativeFramePath}')
58
47
  module.exports = {
59
48
  express: express,
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
@@ -15,11 +15,11 @@ const findAppModule = async apiDir => {
15
15
  if (await fs.pathExists(filename)) {
16
16
  // 每次获取 app.ts 的时候,避免使用缓存的 app.ts
17
17
  delete require.cache[filename];
18
- return compatRequire(filename);
18
+ return [compatRequire(filename), require(filename)];
19
19
  }
20
20
  }
21
21
 
22
- return null;
22
+ return [];
23
23
  };
24
24
 
25
25
  const initMiddlewares = (middleware, app) => {
@@ -63,7 +63,9 @@ export default (() => ({
63
63
  const apiHandlerInfos = appContext.apiHandlerInfos;
64
64
 
65
65
  if (mode === 'framework') {
66
- app = await findAppModule(apiDir);
66
+ const appModule = await findAppModule(apiDir);
67
+ app = appModule[0];
68
+ const hooks = appModule[1];
67
69
 
68
70
  if (!app || !app.use) {
69
71
  // console.warn('There is not api/app.ts.');
@@ -81,6 +83,13 @@ export default (() => ({
81
83
 
82
84
  useRun(app);
83
85
  registerRoutes(app, apiHandlerInfos);
86
+ const {
87
+ afterLambdaRegisted
88
+ } = hooks;
89
+
90
+ if (afterLambdaRegisted) {
91
+ afterLambdaRegisted(app);
92
+ }
84
93
  } else if (mode === 'function') {
85
94
  app = express();
86
95
  initApp(app);
@@ -0,0 +1 @@
1
+ export const hook = attacher => attacher;
@@ -1,3 +1,4 @@
1
1
  export * from '@modern-js/bff-core';
2
2
  export { useContext } from "../context";
3
+ export { hook } from "./hook";
3
4
  export * from "./operators";
@@ -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('express'));
69
- bffExportsUtils.addExport(`const bffRuntime = require('${relativeBffPath}');
70
- const pluginRuntime = require('${relativeRuntimeModulePath}');
59
+ bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
71
60
  const express = require('${relativeFramePath}')
72
61
  module.exports = {
73
62
  express: express,
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;
@@ -35,11 +35,11 @@ const findAppModule = async apiDir => {
35
35
  if (await _utils.fs.pathExists(filename)) {
36
36
  // 每次获取 app.ts 的时候,避免使用缓存的 app.ts
37
37
  delete require.cache[filename];
38
- return (0, _utils.compatRequire)(filename);
38
+ return [(0, _utils.compatRequire)(filename), require(filename)];
39
39
  }
40
40
  }
41
41
 
42
- return null;
42
+ return [];
43
43
  };
44
44
 
45
45
  const initMiddlewares = (middleware, app) => {
@@ -83,7 +83,9 @@ var _default = () => ({
83
83
  const apiHandlerInfos = appContext.apiHandlerInfos;
84
84
 
85
85
  if (mode === 'framework') {
86
- app = await findAppModule(apiDir);
86
+ const appModule = await findAppModule(apiDir);
87
+ app = appModule[0];
88
+ const hooks = appModule[1];
87
89
 
88
90
  if (!app || !app.use) {
89
91
  // console.warn('There is not api/app.ts.');
@@ -101,6 +103,13 @@ var _default = () => ({
101
103
 
102
104
  useRun(app);
103
105
  (0, _registerRoutes.default)(app, apiHandlerInfos);
106
+ const {
107
+ afterLambdaRegisted
108
+ } = hooks;
109
+
110
+ if (afterLambdaRegisted) {
111
+ afterLambdaRegisted(app);
112
+ }
104
113
  } else if (mode === 'function') {
105
114
  app = (0, _express.default)();
106
115
  initApp(app);
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hook = void 0;
7
+
8
+ const hook = attacher => attacher;
9
+
10
+ exports.hook = hook;
@@ -4,8 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- useContext: true
7
+ useContext: true,
8
+ hook: true
8
9
  };
10
+ Object.defineProperty(exports, "hook", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _hook.hook;
14
+ }
15
+ });
9
16
  Object.defineProperty(exports, "useContext", {
10
17
  enumerable: true,
11
18
  get: function () {
@@ -29,6 +36,8 @@ Object.keys(_bffCore).forEach(function (key) {
29
36
 
30
37
  var _context = require("../context");
31
38
 
39
+ var _hook = require("./hook");
40
+
32
41
  var _operators = require("./operators");
33
42
 
34
43
  Object.keys(_operators).forEach(function (key) {
@@ -0,0 +1,2 @@
1
+ import type { Request, Response, NextFunction } from 'express';
2
+ export declare const hook: (attacher: (req: Request, res: Response, next: NextFunction) => void | Promise<void>) => (req: Request, res: Response, next: NextFunction) => void | Promise<void>;
@@ -1,3 +1,4 @@
1
1
  export * from '@modern-js/bff-core';
2
2
  export { useContext } from '../context';
3
+ export { hook } from './hook';
3
4
  export * from './operators';
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.7.2",
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,11 +34,10 @@
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.2.2",
39
- "@modern-js/bff-runtime": "^1.4.0",
40
- "@modern-js/types": "^1.6.2",
41
- "@modern-js/utils": "^1.9.0",
37
+ "@modern-js/bff-core": "1.16.0",
38
+ "@modern-js/bff-runtime": "1.16.0",
39
+ "@modern-js/types": "1.16.0",
40
+ "@modern-js/utils": "1.16.0",
42
41
  "cookie-parser": "^1.4.5",
43
42
  "finalhandler": "^1.1.2",
44
43
  "formidable": "^1.2.2",
@@ -46,10 +45,10 @@
46
45
  "type-is": "^1.6.18"
47
46
  },
48
47
  "devDependencies": {
49
- "@modern-js/core": "1.14.0",
50
- "@modern-js/server-core": "1.4.1",
51
- "@scripts/build": "0.0.0",
52
- "@scripts/jest-config": "0.0.0",
48
+ "@modern-js/core": "1.16.0",
49
+ "@modern-js/server-core": "1.16.0",
50
+ "@scripts/build": "1.15.0",
51
+ "@scripts/jest-config": "1.15.0",
53
52
  "@types/cookie-parser": "^1.4.2",
54
53
  "@types/express": "^4.17.13",
55
54
  "@types/finalhandler": "^1.1.1",
package/types.d.ts CHANGED
@@ -19,6 +19,4 @@ declare module '@modern-js/runtime/server' {
19
19
  export function hook(attacher: ExpressAttacher): ExpressAttacher;
20
20
 
21
21
  export * from '@modern-js/bff-core';
22
-
23
- export * from '@modern-js/bff-runtime';
24
22
  }