@modern-js/plugin-express 1.4.1 → 1.4.4

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,34 @@
1
1
  # @modern-js/plugin-express
2
2
 
3
+ ## 1.4.4
4
+
5
+ ### Patch Changes
6
+
7
+ - bebb39b6: chore: improve devDependencies and peerDependencies
8
+ - Updated dependencies [132f7b53]
9
+ - @modern-js/utils@1.3.7
10
+
11
+ ## 1.4.3
12
+
13
+ ### Patch Changes
14
+
15
+ - c1b8fa0a: feat: convert to new server plugin
16
+ - Updated dependencies [c2046f37]
17
+ - @modern-js/utils@1.3.6
18
+
19
+ ## 1.4.2
20
+
21
+ ### Patch Changes
22
+
23
+ - ef7b0a54: feat: convert to new plugin
24
+ - Updated dependencies [5bf5868d]
25
+ - Updated dependencies [d95f28c3]
26
+ - Updated dependencies [2e8dec93]
27
+ - Updated dependencies [2008fdbd]
28
+ - Updated dependencies [2e8dec93]
29
+ - @modern-js/utils@1.3.5
30
+ - @modern-js/server-core@1.2.3
31
+
3
32
  ## 1.4.1
4
33
 
5
34
  ### Patch Changes
@@ -1,50 +1,54 @@
1
1
  import * as path from 'path';
2
- import { useAppContext, createPlugin } from '@modern-js/core';
3
2
  import { createRuntimeExportsUtils } from '@modern-js/utils';
4
- export default createPlugin(() => {
5
- let bffExportsUtils;
6
- const runtimeModulePath = path.resolve(__dirname, '../runtime');
7
- return {
8
- config() {
9
- // eslint-disable-next-line react-hooks/rules-of-hooks
10
- const appContext = useAppContext();
11
- const {
12
- appDirectory
13
- } = appContext;
14
- bffExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'server');
15
- const serverRuntimePath = bffExportsUtils.getPath(); // Look up one level, because the artifacts after build have dist directories
3
+ export default (() => ({
4
+ name: '@modern-js/plugin-express',
5
+ setup: api => {
6
+ let bffExportsUtils;
7
+ const {
8
+ useAppContext
9
+ } = api;
10
+ const runtimeModulePath = path.resolve(__dirname, '../runtime');
11
+ return {
12
+ config() {
13
+ // eslint-disable-next-line react-hooks/rules-of-hooks
14
+ const appContext = useAppContext();
15
+ const {
16
+ appDirectory
17
+ } = appContext;
18
+ bffExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'server');
19
+ const serverRuntimePath = bffExportsUtils.getPath(); // Look up one level, because the artifacts after build have dist directories
16
20
 
17
- let relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
21
+ let relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
18
22
 
19
- if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
20
- relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
21
- }
23
+ if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
24
+ relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
25
+ }
22
26
 
23
- return {
24
- source: {
25
- alias: {
26
- '@modern-js/runtime/server': relativeRuntimePath
27
+ return {
28
+ source: {
29
+ alias: {
30
+ '@modern-js/runtime/server': relativeRuntimePath
31
+ }
27
32
  }
28
- }
29
- };
30
- },
33
+ };
34
+ },
31
35
 
32
- addRuntimeExports(input) {
33
- // eslint-disable-next-line react-hooks/rules-of-hooks
34
- const {
35
- appDirectory
36
- } = useAppContext();
36
+ addRuntimeExports(input) {
37
+ // eslint-disable-next-line react-hooks/rules-of-hooks
38
+ const {
39
+ appDirectory
40
+ } = useAppContext();
37
41
 
38
- const runtimePath = require.resolve(`@modern-js/runtime`, {
39
- paths: [appDirectory]
40
- });
42
+ const runtimePath = require.resolve(`@modern-js/runtime`, {
43
+ paths: [appDirectory]
44
+ });
41
45
 
42
- const currentFile = bffExportsUtils.getPath();
43
- const runtimeDir = path.dirname(runtimePath);
44
- const relativeBffPath = path.relative(path.dirname(currentFile), path.join(runtimeDir, './exports/server'));
45
- const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
46
- const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve('express'));
47
- bffExportsUtils.addExport(`const bffRuntime = require('${relativeBffPath}');
46
+ const currentFile = bffExportsUtils.getPath();
47
+ const runtimeDir = path.dirname(runtimePath);
48
+ const relativeBffPath = path.relative(path.dirname(currentFile), path.join(runtimeDir, './exports/server'));
49
+ const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
50
+ const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve('express'));
51
+ bffExportsUtils.addExport(`const bffRuntime = require('${relativeBffPath}');
48
52
  const pluginRuntime = require('${relativeRuntimeModulePath}');
49
53
  const express = require('${relativeFramePath}')
50
54
  module.exports = {
@@ -53,10 +57,9 @@ export default createPlugin(() => {
53
57
  ...pluginRuntime
54
58
  }
55
59
  `);
56
- return input;
57
- }
60
+ return input;
61
+ }
58
62
 
59
- };
60
- }, {
61
- name: '@modern-js/plugin-express'
62
- });
63
+ };
64
+ }
65
+ }));
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line filenames/match-exported
2
1
  import plugin from "./plugin";
3
2
  export * from "./context";
4
3
  export default plugin;
@@ -1,7 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import express from 'express';
3
3
  import cookieParser from 'cookie-parser';
4
- import { createPlugin } from '@modern-js/server-core';
5
4
  import { requireModule } from '@modern-js/bff-utils';
6
5
  import { fs, createDebugger } from '@modern-js/utils';
7
6
  import finalhandler from 'finalhandler';
@@ -48,115 +47,115 @@ const initApp = app => {
48
47
  return app;
49
48
  };
50
49
 
51
- export default createPlugin(() => ({
52
- // eslint-disable-next-line max-statements
53
- async prepareApiServer({
54
- pwd,
55
- mode,
56
- config
57
- }) {
58
- let app;
59
- const apiDir = path.join(pwd, './api');
60
-
61
- if (mode === 'framework') {
62
- app = await findAppModule(apiDir);
63
-
64
- if (!app || !app.use) {
65
- // console.warn('There is not api/app.ts.');
50
+ export default (() => ({
51
+ name: '@modern-js/plugin-express',
52
+ pre: ['@modern-js/plugin-bff'],
53
+ setup: () => ({
54
+ async prepareApiServer({
55
+ pwd,
56
+ mode,
57
+ config
58
+ }) {
59
+ let app;
60
+ const apiDir = path.join(pwd, './api');
61
+
62
+ if (mode === 'framework') {
63
+ app = await findAppModule(apiDir);
64
+
65
+ if (!app || !app.use) {
66
+ // console.warn('There is not api/app.ts.');
67
+ app = express();
68
+ }
69
+
70
+ initApp(app);
71
+
72
+ if (config) {
73
+ const {
74
+ middleware
75
+ } = config;
76
+ initMiddlewares(middleware, app);
77
+ } // eslint-disable-next-line react-hooks/rules-of-hooks
78
+
79
+
80
+ useRun(app);
81
+ registerRoutes(app);
82
+ } else if (mode === 'function') {
66
83
  app = express();
84
+ initApp(app);
85
+
86
+ if (config) {
87
+ const {
88
+ middleware
89
+ } = config;
90
+ initMiddlewares(middleware, app);
91
+ } // eslint-disable-next-line react-hooks/rules-of-hooks
92
+
93
+
94
+ useRun(app);
95
+ registerRoutes(app);
96
+ } else {
97
+ throw new Error(`mode must be function or framework`);
67
98
  }
68
99
 
69
- initApp(app);
100
+ return (req, res) => new Promise((resolve, reject) => {
101
+ const handler = err => {
102
+ if (err) {
103
+ return reject(err);
104
+ } // finalhanlder will trigger 'finish' event
70
105
 
71
- if (config) {
72
- const {
73
- middleware
74
- } = config;
75
- initMiddlewares(middleware, app);
76
- } // eslint-disable-next-line react-hooks/rules-of-hooks
77
106
 
107
+ return finalhandler(req, res, {})(null); // return resolve();
108
+ };
109
+
110
+ res.on('finish', err => {
111
+ if (err) {
112
+ return reject(err);
113
+ }
114
+
115
+ return resolve();
116
+ });
117
+ return app(req, res, handler);
118
+ });
119
+ },
78
120
 
79
- useRun(app);
80
- registerRoutes(app);
81
- } else if (mode === 'function') {
82
- app = express();
121
+ prepareWebServer({
122
+ config
123
+ }) {
124
+ const app = express();
83
125
  initApp(app);
84
126
 
85
127
  if (config) {
86
128
  const {
87
129
  middleware
88
130
  } = config;
131
+ debug('web middleware', middleware);
89
132
  initMiddlewares(middleware, app);
90
- } // eslint-disable-next-line react-hooks/rules-of-hooks
133
+ }
91
134
 
135
+ return (req, res) => new Promise((resolve, reject) => {
136
+ const handler = err => {
137
+ if (err) {
138
+ return reject(err);
139
+ }
92
140
 
93
- useRun(app);
94
- registerRoutes(app);
95
- } else {
96
- throw new Error(`mode must be function or framework`);
97
- }
141
+ if (res.headersSent && res.statusCode !== 200) {
142
+ finalhandler(req, res, {})(null);
143
+ }
98
144
 
99
- return (req, res) => new Promise((resolve, reject) => {
100
- const handler = err => {
101
- if (err) {
102
- return reject(err);
103
- } // finalhanlder will trigger 'finish' event
145
+ return resolve();
146
+ }; // when user call res.send
104
147
 
105
148
 
106
- return finalhandler(req, res, {})(null); // return resolve();
107
- };
108
-
109
- res.on('finish', err => {
110
- if (err) {
111
- return reject(err);
112
- }
149
+ res.on('finish', err => {
150
+ if (err) {
151
+ return reject(err);
152
+ }
113
153
 
114
- return resolve();
154
+ return resolve();
155
+ });
156
+ return app(req, res, handler);
115
157
  });
116
- return app(req, res, handler);
117
- });
118
- },
119
-
120
- prepareWebServer({
121
- config
122
- }) {
123
- const app = express();
124
- initApp(app);
125
-
126
- if (config) {
127
- const {
128
- middleware
129
- } = config;
130
- debug('web middleware', middleware);
131
- initMiddlewares(middleware, app);
132
158
  }
133
159
 
134
- return (req, res) => new Promise((resolve, reject) => {
135
- const handler = err => {
136
- if (err) {
137
- return reject(err);
138
- }
139
-
140
- if (res.headersSent && res.statusCode !== 200) {
141
- finalhandler(req, res, {})(null);
142
- }
143
-
144
- return resolve();
145
- }; // when user call res.send
146
-
147
-
148
- res.on('finish', err => {
149
- if (err) {
150
- return reject(err);
151
- }
152
-
153
- return resolve();
154
- });
155
- return app(req, res, handler);
156
- });
157
- }
158
-
159
- }), {
160
- name: '@modern-js/plugin-express',
161
- pre: ['@modern-js/plugin-bff']
162
- });
160
+ })
161
+ }));
@@ -7,58 +7,61 @@ exports.default = void 0;
7
7
 
8
8
  var path = _interopRequireWildcard(require("path"));
9
9
 
10
- var _core = require("@modern-js/core");
11
-
12
10
  var _utils = require("@modern-js/utils");
13
11
 
14
12
  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
13
 
16
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
15
 
18
- var _default = (0, _core.createPlugin)(() => {
19
- let bffExportsUtils;
20
- const runtimeModulePath = path.resolve(__dirname, '../runtime');
21
- return {
22
- config() {
23
- // eslint-disable-next-line react-hooks/rules-of-hooks
24
- const appContext = (0, _core.useAppContext)();
25
- const {
26
- appDirectory
27
- } = appContext;
28
- bffExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'server');
29
- const serverRuntimePath = bffExportsUtils.getPath(); // Look up one level, because the artifacts after build have dist directories
16
+ var _default = () => ({
17
+ name: '@modern-js/plugin-express',
18
+ setup: api => {
19
+ let bffExportsUtils;
20
+ const {
21
+ useAppContext
22
+ } = api;
23
+ const runtimeModulePath = path.resolve(__dirname, '../runtime');
24
+ return {
25
+ config() {
26
+ // eslint-disable-next-line react-hooks/rules-of-hooks
27
+ const appContext = useAppContext();
28
+ const {
29
+ appDirectory
30
+ } = appContext;
31
+ bffExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'server');
32
+ const serverRuntimePath = bffExportsUtils.getPath(); // Look up one level, because the artifacts after build have dist directories
30
33
 
31
- let relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
34
+ let relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
32
35
 
33
- if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
34
- relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
35
- }
36
+ if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
37
+ relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
38
+ }
36
39
 
37
- return {
38
- source: {
39
- alias: {
40
- '@modern-js/runtime/server': relativeRuntimePath
40
+ return {
41
+ source: {
42
+ alias: {
43
+ '@modern-js/runtime/server': relativeRuntimePath
44
+ }
41
45
  }
42
- }
43
- };
44
- },
46
+ };
47
+ },
45
48
 
46
- addRuntimeExports(input) {
47
- // eslint-disable-next-line react-hooks/rules-of-hooks
48
- const {
49
- appDirectory
50
- } = (0, _core.useAppContext)();
49
+ addRuntimeExports(input) {
50
+ // eslint-disable-next-line react-hooks/rules-of-hooks
51
+ const {
52
+ appDirectory
53
+ } = useAppContext();
51
54
 
52
- const runtimePath = require.resolve(`@modern-js/runtime`, {
53
- paths: [appDirectory]
54
- });
55
+ const runtimePath = require.resolve(`@modern-js/runtime`, {
56
+ paths: [appDirectory]
57
+ });
55
58
 
56
- const currentFile = bffExportsUtils.getPath();
57
- const runtimeDir = path.dirname(runtimePath);
58
- const relativeBffPath = path.relative(path.dirname(currentFile), path.join(runtimeDir, './exports/server'));
59
- const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
60
- const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve('express'));
61
- bffExportsUtils.addExport(`const bffRuntime = require('${relativeBffPath}');
59
+ const currentFile = bffExportsUtils.getPath();
60
+ const runtimeDir = path.dirname(runtimePath);
61
+ const relativeBffPath = path.relative(path.dirname(currentFile), path.join(runtimeDir, './exports/server'));
62
+ const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
63
+ const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve('express'));
64
+ bffExportsUtils.addExport(`const bffRuntime = require('${relativeBffPath}');
62
65
  const pluginRuntime = require('${relativeRuntimeModulePath}');
63
66
  const express = require('${relativeFramePath}')
64
67
  module.exports = {
@@ -67,12 +70,11 @@ var _default = (0, _core.createPlugin)(() => {
67
70
  ...pluginRuntime
68
71
  }
69
72
  `);
70
- return input;
71
- }
73
+ return input;
74
+ }
72
75
 
73
- };
74
- }, {
75
- name: '@modern-js/plugin-express'
76
+ };
77
+ }
76
78
  });
77
79
 
78
80
  exports.default = _default;
@@ -24,6 +24,5 @@ Object.keys(_context).forEach(function (key) {
24
24
 
25
25
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
26
 
27
- // eslint-disable-next-line filenames/match-exported
28
27
  var _default = _plugin.default;
29
28
  exports.default = _default;
@@ -11,8 +11,6 @@ var _express = _interopRequireDefault(require("express"));
11
11
 
12
12
  var _cookieParser = _interopRequireDefault(require("cookie-parser"));
13
13
 
14
- var _serverCore = require("@modern-js/server-core");
15
-
16
14
  var _bffUtils = require("@modern-js/bff-utils");
17
15
 
18
16
  var _utils = require("@modern-js/utils");
@@ -70,117 +68,117 @@ const initApp = app => {
70
68
  return app;
71
69
  };
72
70
 
73
- var _default = (0, _serverCore.createPlugin)(() => ({
74
- // eslint-disable-next-line max-statements
75
- async prepareApiServer({
76
- pwd,
77
- mode,
78
- config
79
- }) {
80
- let app;
81
- const apiDir = path.join(pwd, './api');
82
-
83
- if (mode === 'framework') {
84
- app = await findAppModule(apiDir);
85
-
86
- if (!app || !app.use) {
87
- // console.warn('There is not api/app.ts.');
71
+ var _default = () => ({
72
+ name: '@modern-js/plugin-express',
73
+ pre: ['@modern-js/plugin-bff'],
74
+ setup: () => ({
75
+ async prepareApiServer({
76
+ pwd,
77
+ mode,
78
+ config
79
+ }) {
80
+ let app;
81
+ const apiDir = path.join(pwd, './api');
82
+
83
+ if (mode === 'framework') {
84
+ app = await findAppModule(apiDir);
85
+
86
+ if (!app || !app.use) {
87
+ // console.warn('There is not api/app.ts.');
88
+ app = (0, _express.default)();
89
+ }
90
+
91
+ initApp(app);
92
+
93
+ if (config) {
94
+ const {
95
+ middleware
96
+ } = config;
97
+ initMiddlewares(middleware, app);
98
+ } // eslint-disable-next-line react-hooks/rules-of-hooks
99
+
100
+
101
+ useRun(app);
102
+ (0, _registerRoutes.default)(app);
103
+ } else if (mode === 'function') {
88
104
  app = (0, _express.default)();
105
+ initApp(app);
106
+
107
+ if (config) {
108
+ const {
109
+ middleware
110
+ } = config;
111
+ initMiddlewares(middleware, app);
112
+ } // eslint-disable-next-line react-hooks/rules-of-hooks
113
+
114
+
115
+ useRun(app);
116
+ (0, _registerRoutes.default)(app);
117
+ } else {
118
+ throw new Error(`mode must be function or framework`);
89
119
  }
90
120
 
91
- initApp(app);
121
+ return (req, res) => new Promise((resolve, reject) => {
122
+ const handler = err => {
123
+ if (err) {
124
+ return reject(err);
125
+ } // finalhanlder will trigger 'finish' event
92
126
 
93
- if (config) {
94
- const {
95
- middleware
96
- } = config;
97
- initMiddlewares(middleware, app);
98
- } // eslint-disable-next-line react-hooks/rules-of-hooks
99
127
 
128
+ return (0, _finalhandler.default)(req, res, {})(null); // return resolve();
129
+ };
100
130
 
101
- useRun(app);
102
- (0, _registerRoutes.default)(app);
103
- } else if (mode === 'function') {
104
- app = (0, _express.default)();
131
+ res.on('finish', err => {
132
+ if (err) {
133
+ return reject(err);
134
+ }
135
+
136
+ return resolve();
137
+ });
138
+ return app(req, res, handler);
139
+ });
140
+ },
141
+
142
+ prepareWebServer({
143
+ config
144
+ }) {
145
+ const app = (0, _express.default)();
105
146
  initApp(app);
106
147
 
107
148
  if (config) {
108
149
  const {
109
150
  middleware
110
151
  } = config;
152
+ debug('web middleware', middleware);
111
153
  initMiddlewares(middleware, app);
112
- } // eslint-disable-next-line react-hooks/rules-of-hooks
154
+ }
113
155
 
156
+ return (req, res) => new Promise((resolve, reject) => {
157
+ const handler = err => {
158
+ if (err) {
159
+ return reject(err);
160
+ }
114
161
 
115
- useRun(app);
116
- (0, _registerRoutes.default)(app);
117
- } else {
118
- throw new Error(`mode must be function or framework`);
119
- }
162
+ if (res.headersSent && res.statusCode !== 200) {
163
+ (0, _finalhandler.default)(req, res, {})(null);
164
+ }
120
165
 
121
- return (req, res) => new Promise((resolve, reject) => {
122
- const handler = err => {
123
- if (err) {
124
- return reject(err);
125
- } // finalhanlder will trigger 'finish' event
166
+ return resolve();
167
+ }; // when user call res.send
126
168
 
127
169
 
128
- return (0, _finalhandler.default)(req, res, {})(null); // return resolve();
129
- };
130
-
131
- res.on('finish', err => {
132
- if (err) {
133
- return reject(err);
134
- }
170
+ res.on('finish', err => {
171
+ if (err) {
172
+ return reject(err);
173
+ }
135
174
 
136
- return resolve();
175
+ return resolve();
176
+ });
177
+ return app(req, res, handler);
137
178
  });
138
- return app(req, res, handler);
139
- });
140
- },
141
-
142
- prepareWebServer({
143
- config
144
- }) {
145
- const app = (0, _express.default)();
146
- initApp(app);
147
-
148
- if (config) {
149
- const {
150
- middleware
151
- } = config;
152
- debug('web middleware', middleware);
153
- initMiddlewares(middleware, app);
154
179
  }
155
180
 
156
- return (req, res) => new Promise((resolve, reject) => {
157
- const handler = err => {
158
- if (err) {
159
- return reject(err);
160
- }
161
-
162
- if (res.headersSent && res.statusCode !== 200) {
163
- (0, _finalhandler.default)(req, res, {})(null);
164
- }
165
-
166
- return resolve();
167
- }; // when user call res.send
168
-
169
-
170
- res.on('finish', err => {
171
- if (err) {
172
- return reject(err);
173
- }
174
-
175
- return resolve();
176
- });
177
- return app(req, res, handler);
178
- });
179
- }
180
-
181
- }), {
182
- name: '@modern-js/plugin-express',
183
- pre: ['@modern-js/plugin-bff']
181
+ })
184
182
  });
185
183
 
186
184
  exports.default = _default;
@@ -1,20 +1,5 @@
1
- declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@modern-js/core").Progresses2Threads<{
2
- config: import("@modern-js/core").ParallelWorkflow<void, unknown>;
3
- resolvedConfig: import("@modern-js/core").AsyncWaterfall<{
4
- resolved: import("@modern-js/core").NormalizedConfig;
5
- }>;
6
- validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
7
- prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
8
- commands: import("@modern-js/core").AsyncWorkflow<{
9
- program: import("commander").Command;
10
- }, void>;
11
- watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
12
- fileChange: import("@modern-js/core").AsyncWorkflow<{
13
- filename: string;
14
- eventType: "add" | "unlink" | "change";
15
- }, void>;
16
- beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
17
- beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
18
- } & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
1
+ import type { CliPlugin } from '@modern-js/core';
2
+
3
+ declare const _default: () => CliPlugin;
19
4
 
20
5
  export default _default;
@@ -1,5 +1,6 @@
1
+ import type { ServerPlugin } from '@modern-js/server-core';
1
2
  export declare type Mode = 'function' | 'framework';
2
3
 
3
- declare const _default: any;
4
+ declare const _default: () => ServerPlugin;
4
5
 
5
6
  export default _default;
package/jest.config.js CHANGED
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
2
2
 
3
3
  /** @type {import('@jest/types').Config.InitialOptions} */
4
4
  module.exports = {
5
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
5
  ...sharedConfig,
7
6
  rootDir: __dirname,
8
7
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.4.1",
14
+ "version": "1.4.4",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -35,19 +35,17 @@
35
35
  "dependencies": {
36
36
  "@babel/runtime": "^7.15.3",
37
37
  "@modern-js/adapter-helpers": "^1.2.1",
38
- "@modern-js/utils": "^1.3.4",
38
+ "@modern-js/utils": "^1.3.7",
39
39
  "cookie-parser": "^1.4.5",
40
40
  "finalhandler": "^1.1.2",
41
41
  "formidable": "^1.2.2",
42
42
  "type-is": "^1.6.18",
43
- "@modern-js/core": "^1.4.6",
44
43
  "@modern-js/bff-utils": "^1.2.2",
45
- "@modern-js/server-core": "^1.2.2",
46
44
  "@modern-js/bff-runtime": "^1.2.1"
47
45
  },
48
46
  "devDependencies": {
49
47
  "express": "^4.17.1",
50
- "@modern-js/server-utils": "^1.2.1",
48
+ "@modern-js/server-utils": "^1.2.2",
51
49
  "@types/cookie-parser": "^1.4.2",
52
50
  "@types/express": "^4.17.13",
53
51
  "@types/finalhandler": "^1.1.1",
@@ -58,9 +56,10 @@
58
56
  "@types/type-is": "^1.6.3",
59
57
  "supertest": "^6.1.6",
60
58
  "typescript": "^4",
61
- "@modern-js/core": "^1.4.6",
59
+ "@modern-js/core": "1.6.1",
62
60
  "@scripts/build": "0.0.0",
63
61
  "jest": "^27",
62
+ "@modern-js/server-core": "1.2.5",
64
63
  "@scripts/jest-config": "0.0.0"
65
64
  },
66
65
  "modernConfig": {
@@ -3,7 +3,6 @@
3
3
  import { match } from '@modern-js/bff-runtime';
4
4
  import { useContext } from '../../../../../src/context';
5
5
 
6
- // eslint-disable-next-line arrow-body-style
7
6
  export const get = ({ query }: { query: Record<string, unknown> }) => {
8
7
  return { query };
9
8
  };
@@ -0,0 +1,4 @@
1
+ export const post = ({ formData }) => ({
2
+ message: 'success',
3
+ formData,
4
+ });
@@ -0,0 +1,4 @@
1
+ export const post = ({ formData }) => ({
2
+ message: 'success',
3
+ formData,
4
+ });
@@ -90,4 +90,19 @@ describe('function-mode', () => {
90
90
  expect(res.status).toBe(200);
91
91
  expect(res.body.protocol).toBe('Farrow-API');
92
92
  });
93
+
94
+ test('should support upload file', done => {
95
+ request(apiHandler)
96
+ .post('/upload')
97
+ .field('my_field', 'value')
98
+ .attach('file', __filename)
99
+ .end(async (err, res) => {
100
+ if (err) {
101
+ throw err;
102
+ }
103
+ expect(res.statusCode).toBe(200);
104
+ expect(res.body.message).toBe('success');
105
+ done();
106
+ });
107
+ });
93
108
  });
@@ -13,6 +13,7 @@ const API_DIR = './api';
13
13
  describe('lambda-mode', () => {
14
14
  const id = '666';
15
15
  const name = 'modern';
16
+ const prefix = '/api';
16
17
  const foo = { id, name };
17
18
  let apiHandler: any;
18
19
 
@@ -21,40 +22,41 @@ describe('lambda-mode', () => {
21
22
  .clone()
22
23
  .usePlugin(APIPlugin, plugin)
23
24
  .init();
25
+
24
26
  apiHandler = await runner.prepareApiServer({
25
27
  pwd,
26
28
  mode: 'framework',
27
- prefix: '/api',
29
+ prefix,
28
30
  });
29
31
  });
30
32
 
31
33
  test('should works', async () => {
32
- const res = await request(apiHandler).get('/api/hello');
34
+ const res = await request(apiHandler).get(`${prefix}/hello`);
33
35
  expect(res.status).toBe(200);
34
36
  expect(res.body).toEqual({ message: 'hello' });
35
37
  });
36
38
 
37
39
  test('should works with query', async () => {
38
- const res = await request(apiHandler).get(`/api/nest/user?id=${id}`);
40
+ const res = await request(apiHandler).get(`${prefix}/nest/user?id=${id}`);
39
41
  expect(res.status).toBe(200);
40
42
  expect(res.body.query.id).toBe(id);
41
43
  });
42
44
 
43
45
  test('should works with body', async () => {
44
- const res = await request(apiHandler).post('/api/nest/user').send(foo);
46
+ const res = await request(apiHandler).post(`${prefix}/nest/user`).send(foo);
45
47
  expect(res.status).toBe(200);
46
48
  expect(res.body.data).toEqual(foo);
47
49
  });
48
50
 
49
51
  test('should works with dynamic route ', async () => {
50
- const res = await request(apiHandler).post(`/api/nest/${id}`);
52
+ const res = await request(apiHandler).post(`${prefix}/nest/${id}`);
51
53
  expect(res.status).toBe(200);
52
54
  expect(res.body).toEqual({ id });
53
55
  });
54
56
 
55
57
  test('should works with context', async () => {
56
58
  const res = await request(apiHandler)
57
- .post(`/api/nest/user?id=${id}`)
59
+ .post(`${prefix}/nest/user?id=${id}`)
58
60
  .send(foo);
59
61
  expect(res.status).toBe(200);
60
62
  expect(res.body.data).toEqual(foo);
@@ -63,7 +65,7 @@ describe('lambda-mode', () => {
63
65
 
64
66
  test('should support cookies', async () => {
65
67
  const res = await request(apiHandler)
66
- .post(`/api/nest/user?id=${id}`)
68
+ .post(`${prefix}/nest/user?id=${id}`)
67
69
  .set('Cookie', [`id=${id};name=${name}`]);
68
70
  expect(res.status).toBe(200);
69
71
  expect(res.body.cookies.id).toBe(id);
@@ -71,19 +73,19 @@ describe('lambda-mode', () => {
71
73
  });
72
74
 
73
75
  test('should works with schema', async () => {
74
- const res = await request(apiHandler).patch('/api/nest/user').send({
76
+ const res = await request(apiHandler).patch(`${prefix}/nest/user`).send({
75
77
  id: 777,
76
78
  name: 'xxx',
77
79
  });
78
80
  expect(res.status).toBe(200);
79
81
 
80
- const res2 = await request(apiHandler).patch('/api/nest/user').send({
82
+ const res2 = await request(apiHandler).patch(`${prefix}/nest/user`).send({
81
83
  id: 'aaa',
82
84
  name: 'xxx',
83
85
  });
84
86
  expect(res2.status).toBe(400);
85
87
 
86
- const res3 = await request(apiHandler).patch('/api/nest/user').send({
88
+ const res3 = await request(apiHandler).patch(`${prefix}/nest/user`).send({
87
89
  id: '777',
88
90
  name: 'xxx',
89
91
  });
@@ -97,6 +99,21 @@ describe('lambda-mode', () => {
97
99
  expect(res.status).toBe(200);
98
100
  expect(res.body.protocol).toBe('Farrow-API');
99
101
  });
102
+
103
+ test('should support upload file', done => {
104
+ request(apiHandler)
105
+ .post(`${prefix}/upload`)
106
+ .field('my_field', 'value')
107
+ .attach('file', __filename)
108
+ .end(async (err, res) => {
109
+ if (err) {
110
+ throw err;
111
+ }
112
+ expect(res.statusCode).toBe(200);
113
+ expect(res.body.message).toBe('success');
114
+ done();
115
+ });
116
+ });
100
117
  });
101
118
 
102
119
  describe('add middwares', () => {