@modern-js/plugin-koa 1.4.5 → 1.4.8-canary.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/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/.wireit/6275696c64/stdout +9 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/cli/index.js +60 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/context.js +6 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/index.js +3 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/plugin.js +129 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/registerRoutes.js +82 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/runtime.js +1 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/cli/index.js +76 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/context.js +15 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/index.js +28 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/plugin.js +151 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/registerRoutes.js +97 -0
- package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/runtime.js +13 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/cli/index.js +60 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/context.js +6 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/index.js +3 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/plugin.js +129 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/registerRoutes.js +82 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/runtime.js +1 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/cli/index.js +76 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/context.js +15 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/index.js +28 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/plugin.js +151 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/registerRoutes.js +97 -0
- package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/runtime.js +13 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/cli/index.js +60 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/context.js +6 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/index.js +3 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/plugin.js +129 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/registerRoutes.js +82 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/runtime.js +1 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/cli/index.js +76 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/context.js +15 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/index.js +28 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/plugin.js +151 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/registerRoutes.js +97 -0
- package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/runtime.js +13 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/.wireit/6275696c64/stdout +9 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/cli/index.js +62 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/context.js +6 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/index.js +3 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/plugin.js +129 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/registerRoutes.js +82 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/runtime.js +1 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/cli/index.js +78 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/context.js +15 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/index.js +28 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/plugin.js +151 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/registerRoutes.js +97 -0
- package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/runtime.js +13 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/cli/index.js +60 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/context.js +6 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/index.js +3 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/plugin.js +129 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/registerRoutes.js +82 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/runtime.js +1 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/cli/index.js +76 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/context.js +15 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/index.js +28 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/plugin.js +151 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/registerRoutes.js +97 -0
- package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/runtime.js +13 -0
- package/{tests/fixtures/function-mode/api/_app.ts → .wireit/6275696c64/lock} +0 -0
- package/.wireit/6275696c64/state +1 -0
- package/.wireit/6275696c64/stdout +9 -0
- package/CHANGELOG.md +28 -0
- package/dist/js/modern/cli/index.js +6 -9
- package/dist/js/modern/registerRoutes.js +3 -3
- package/dist/js/node/cli/index.js +6 -8
- package/dist/js/node/registerRoutes.js +3 -3
- package/package.json +34 -10
- package/.eslintrc.js +0 -7
- package/jest.config.js +0 -7
- package/modern.config.js +0 -2
- package/tests/.eslintrc.js +0 -6
- package/tests/common.ts +0 -9
- package/tests/fixtures/assets/index.html +0 -12
- package/tests/fixtures/function-mode/api/hello.ts +0 -1
- package/tests/fixtures/function-mode/api/nest/user.ts +0 -33
- package/tests/fixtures/function-mode/api/upload.ts +0 -4
- package/tests/fixtures/lambda-mode/api/app.ts +0 -1
- package/tests/fixtures/lambda-mode/api/lambda/hello.ts +0 -1
- package/tests/fixtures/lambda-mode/api/lambda/nest/[id].ts +0 -1
- package/tests/fixtures/lambda-mode/api/lambda/nest/user.ts +0 -33
- package/tests/fixtures/lambda-mode/api/lambda/upload.ts +0 -4
- package/tests/functionMode.test.ts +0 -69
- package/tests/helpers.ts +0 -14
- package/tests/lambdaMode.test.ts +0 -318
- package/tests/tsconfig.json +0 -12
- package/tests/webServer.test.ts +0 -81
- package/tsconfig.json +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @modern-js/plugin-koa
|
|
2
2
|
|
|
3
|
+
## 1.4.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 69a728375: fix: remove exports.jsnext:source after publish
|
|
8
|
+
- Updated dependencies [cd7346b0d]
|
|
9
|
+
- Updated dependencies [69a728375]
|
|
10
|
+
- @modern-js/utils@1.7.2
|
|
11
|
+
- @modern-js/bff-utils@1.2.5
|
|
12
|
+
|
|
13
|
+
## 1.4.6
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
|
|
18
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
19
|
+
- befd9e5b: fix: compatible with babel-plugin-resolver's handling of relative paths on windows
|
|
20
|
+
- Updated dependencies [b8599d09]
|
|
21
|
+
- Updated dependencies [6cffe99d]
|
|
22
|
+
- Updated dependencies [04ae5262]
|
|
23
|
+
- Updated dependencies [60f7d8bf]
|
|
24
|
+
- Updated dependencies [befd9e5b]
|
|
25
|
+
- Updated dependencies [3bf4f8b0]
|
|
26
|
+
- @modern-js/utils@1.5.0
|
|
27
|
+
- @modern-js/adapter-helpers@1.2.3
|
|
28
|
+
- @modern-js/bff-runtime@1.2.2
|
|
29
|
+
- @modern-js/bff-utils@1.2.3
|
|
30
|
+
|
|
3
31
|
## 1.4.5
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
|
-
import { createRuntimeExportsUtils } from '@modern-js/utils';
|
|
2
|
+
import { createRuntimeExportsUtils, TEST_ENV } from '@modern-js/utils';
|
|
3
|
+
import { getRelativeRuntimePath } from '@modern-js/adapter-helpers';
|
|
3
4
|
export default (() => ({
|
|
4
5
|
name: '@modern-js/plugin-koa',
|
|
5
6
|
setup: api => {
|
|
@@ -10,31 +11,27 @@ export default (() => ({
|
|
|
10
11
|
const runtimeModulePath = path.resolve(__dirname, '../runtime');
|
|
11
12
|
return {
|
|
12
13
|
config() {
|
|
13
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
14
14
|
const appContext = useAppContext();
|
|
15
15
|
const {
|
|
16
16
|
appDirectory
|
|
17
17
|
} = appContext;
|
|
18
18
|
bffExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'server');
|
|
19
|
-
|
|
19
|
+
let serverRuntimePath = bffExportsUtils.getPath(); // Basedir is not a fixed path when the test is executed,so server runtime path must be absolute path.
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
|
|
24
|
-
relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
|
|
21
|
+
if (process.env.NODE_ENV !== TEST_ENV) {
|
|
22
|
+
serverRuntimePath = getRelativeRuntimePath(appDirectory, serverRuntimePath);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
return {
|
|
28
26
|
source: {
|
|
29
27
|
alias: {
|
|
30
|
-
'@modern-js/runtime/server':
|
|
28
|
+
'@modern-js/runtime/server': serverRuntimePath
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
};
|
|
34
32
|
},
|
|
35
33
|
|
|
36
34
|
addRuntimeExports(input) {
|
|
37
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
38
35
|
const {
|
|
39
36
|
appDirectory
|
|
40
37
|
} = useAppContext();
|
|
@@ -20,7 +20,7 @@ const registerRoutes = (router, prefix) => {
|
|
|
20
20
|
method,
|
|
21
21
|
name
|
|
22
22
|
}) => {
|
|
23
|
-
const
|
|
23
|
+
const wrappedHandler = async ctx => {
|
|
24
24
|
const input = await getInputFromRequest(ctx);
|
|
25
25
|
|
|
26
26
|
if (isSchemaHandler(handler)) {
|
|
@@ -45,11 +45,11 @@ const registerRoutes = (router, prefix) => {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
Object.defineProperties(
|
|
48
|
+
Object.defineProperties(wrappedHandler, Object.getOwnPropertyDescriptors(handler));
|
|
49
49
|
|
|
50
50
|
if (isNormalMethod(method)) {
|
|
51
51
|
const routeName = method.toLowerCase();
|
|
52
|
-
router[routeName](name,
|
|
52
|
+
router[routeName](name, wrappedHandler);
|
|
53
53
|
} else {
|
|
54
54
|
throw new Error(`Unknown HTTP Method: ${method}`);
|
|
55
55
|
}
|
|
@@ -9,6 +9,8 @@ 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");
|
|
13
|
+
|
|
12
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); }
|
|
13
15
|
|
|
14
16
|
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; }
|
|
@@ -23,31 +25,27 @@ var _default = () => ({
|
|
|
23
25
|
const runtimeModulePath = path.resolve(__dirname, '../runtime');
|
|
24
26
|
return {
|
|
25
27
|
config() {
|
|
26
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
27
28
|
const appContext = useAppContext();
|
|
28
29
|
const {
|
|
29
30
|
appDirectory
|
|
30
31
|
} = appContext;
|
|
31
32
|
bffExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'server');
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
|
|
33
|
+
let serverRuntimePath = bffExportsUtils.getPath(); // Basedir is not a fixed path when the test is executed,so server runtime path must be absolute path.
|
|
35
34
|
|
|
36
|
-
if (process.env.NODE_ENV
|
|
37
|
-
|
|
35
|
+
if (process.env.NODE_ENV !== _utils.TEST_ENV) {
|
|
36
|
+
serverRuntimePath = (0, _adapterHelpers.getRelativeRuntimePath)(appDirectory, serverRuntimePath);
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
return {
|
|
41
40
|
source: {
|
|
42
41
|
alias: {
|
|
43
|
-
'@modern-js/runtime/server':
|
|
42
|
+
'@modern-js/runtime/server': serverRuntimePath
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
};
|
|
47
46
|
},
|
|
48
47
|
|
|
49
48
|
addRuntimeExports(input) {
|
|
50
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
51
49
|
const {
|
|
52
50
|
appDirectory
|
|
53
51
|
} = useAppContext();
|
|
@@ -34,7 +34,7 @@ const registerRoutes = (router, prefix) => {
|
|
|
34
34
|
method,
|
|
35
35
|
name
|
|
36
36
|
}) => {
|
|
37
|
-
const
|
|
37
|
+
const wrappedHandler = async ctx => {
|
|
38
38
|
const input = await getInputFromRequest(ctx);
|
|
39
39
|
|
|
40
40
|
if ((0, _bffRuntime.isSchemaHandler)(handler)) {
|
|
@@ -59,11 +59,11 @@ const registerRoutes = (router, prefix) => {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
Object.defineProperties(
|
|
62
|
+
Object.defineProperties(wrappedHandler, Object.getOwnPropertyDescriptors(handler));
|
|
63
63
|
|
|
64
64
|
if (isNormalMethod(method)) {
|
|
65
65
|
const routeName = method.toLowerCase();
|
|
66
|
-
router[routeName](name,
|
|
66
|
+
router[routeName](name, wrappedHandler);
|
|
67
67
|
} else {
|
|
68
68
|
throw new Error(`Unknown HTTP Method: ${method}`);
|
|
69
69
|
}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.
|
|
14
|
+
"version": "1.4.8-canary.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,10 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/runtime": "^7.15.3",
|
|
37
|
-
"@modern-js/adapter-helpers": "^1.2.
|
|
38
|
-
"@modern-js/bff-runtime": "^1.2.
|
|
39
|
-
"@modern-js/bff-utils": "^1.2.
|
|
40
|
-
"@modern-js/utils": "^1.
|
|
37
|
+
"@modern-js/adapter-helpers": "^1.2.3",
|
|
38
|
+
"@modern-js/bff-runtime": "^1.2.2",
|
|
39
|
+
"@modern-js/bff-utils": "^1.2.5",
|
|
40
|
+
"@modern-js/utils": "^1.7.2",
|
|
41
41
|
"koa-body": "^4.2.0",
|
|
42
42
|
"koa-router": "^10.0.0",
|
|
43
43
|
"type-is": "^1.6.18"
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"@types/supertest": "^2.0.11",
|
|
53
53
|
"@types/type-is": "^1.6.3",
|
|
54
54
|
"jest": "^27",
|
|
55
|
-
"@modern-js/server-core": "1.
|
|
56
|
-
"@modern-js/core": "1.
|
|
55
|
+
"@modern-js/server-core": "1.3.4",
|
|
56
|
+
"@modern-js/core": "1.10.1",
|
|
57
57
|
"supertest": "^6.1.6",
|
|
58
58
|
"koa": "^2.13.3",
|
|
59
59
|
"typescript": "^4"
|
|
@@ -68,12 +68,36 @@
|
|
|
68
68
|
},
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"registry": "https://registry.npmjs.org/",
|
|
71
|
-
"access": "public"
|
|
71
|
+
"access": "public",
|
|
72
|
+
"types": "./dist/types/index.d.ts"
|
|
73
|
+
},
|
|
74
|
+
"wireit": {
|
|
75
|
+
"build": {
|
|
76
|
+
"command": "modern build",
|
|
77
|
+
"files": [
|
|
78
|
+
"src/**/*.ts",
|
|
79
|
+
"tsconfig.json",
|
|
80
|
+
"package.json"
|
|
81
|
+
],
|
|
82
|
+
"output": [
|
|
83
|
+
"dist/**/*.js"
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
"test": {
|
|
87
|
+
"command": "jest --passWithNoTests",
|
|
88
|
+
"files": [
|
|
89
|
+
"src/**/*.ts",
|
|
90
|
+
"tsconfig.json",
|
|
91
|
+
"package.json"
|
|
92
|
+
],
|
|
93
|
+
"output": []
|
|
94
|
+
}
|
|
72
95
|
},
|
|
73
96
|
"scripts": {
|
|
74
97
|
"new": "modern new",
|
|
75
|
-
"
|
|
76
|
-
"
|
|
98
|
+
"dev": "modern build --watch",
|
|
99
|
+
"build": "wireit",
|
|
100
|
+
"test": "wireit"
|
|
77
101
|
},
|
|
78
102
|
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
79
103
|
}
|
package/.eslintrc.js
DELETED
package/jest.config.js
DELETED
package/modern.config.js
DELETED
package/tests/.eslintrc.js
DELETED
package/tests/common.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// globby needs setImmediate
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
-
// @ts-expect-error
|
|
4
|
-
global.setImmediate = setTimeout;
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
-
// @ts-expect-error
|
|
7
|
-
global.clearImmediate = clearTimeout;
|
|
8
|
-
|
|
9
|
-
export const INTROSPECTION_ROUTE_PATH = '/__introspection__';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<title>Document</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
hello koa plugin
|
|
11
|
-
</body>
|
|
12
|
-
</html>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const get = () => ({ message: 'hello koa' });
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { match } from '@modern-js/bff-runtime';
|
|
2
|
-
import { useContext } from '../../../../../src/context';
|
|
3
|
-
|
|
4
|
-
export const get = ({ query }: { query: Record<string, unknown> }) => ({
|
|
5
|
-
query,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export const post = ({ data }: { data: Record<string, unknown> }) => {
|
|
9
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
10
|
-
const ctx = useContext();
|
|
11
|
-
const { cookies } = ctx;
|
|
12
|
-
return {
|
|
13
|
-
query: ctx.query,
|
|
14
|
-
data,
|
|
15
|
-
cookies: {
|
|
16
|
-
id: cookies.get('id'),
|
|
17
|
-
name: cookies.get('name'),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const patch = match(
|
|
23
|
-
{
|
|
24
|
-
request: {
|
|
25
|
-
data: {
|
|
26
|
-
id: Number,
|
|
27
|
-
name: String,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
response: { id: Number },
|
|
31
|
-
},
|
|
32
|
-
({ data: { id } }) => ({ id }),
|
|
33
|
-
);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// used by the test, empty file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const get = () => ({ message: 'hello koa' });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const post = (id: string) => ({ id });
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { match } from '@modern-js/bff-runtime';
|
|
2
|
-
import { useContext } from '../../../../../../src/context';
|
|
3
|
-
|
|
4
|
-
export const get = ({ query }: { query: Record<string, unknown> }) => ({
|
|
5
|
-
query,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export const post = ({ data }: { data: Record<string, unknown> }) => {
|
|
9
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
10
|
-
const ctx = useContext();
|
|
11
|
-
const { cookies } = ctx;
|
|
12
|
-
return {
|
|
13
|
-
query: ctx.query,
|
|
14
|
-
data,
|
|
15
|
-
cookies: {
|
|
16
|
-
id: cookies.get('id'),
|
|
17
|
-
name: cookies.get('name'),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const patch = match(
|
|
23
|
-
{
|
|
24
|
-
request: {
|
|
25
|
-
data: {
|
|
26
|
-
id: Number,
|
|
27
|
-
name: String,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
response: { id: Number },
|
|
31
|
-
},
|
|
32
|
-
({ data: { id } }) => ({ id }),
|
|
33
|
-
);
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import request from 'supertest';
|
|
3
|
-
import { serverManager } from '@modern-js/server-core';
|
|
4
|
-
import plugin from '../src/plugin';
|
|
5
|
-
import { APIPlugin } from './helpers';
|
|
6
|
-
import './common';
|
|
7
|
-
|
|
8
|
-
const pwd = path.join(__dirname, './fixtures/function-mode');
|
|
9
|
-
|
|
10
|
-
describe('function-mode', () => {
|
|
11
|
-
const id = '666';
|
|
12
|
-
const name = 'foo';
|
|
13
|
-
const foo = { id, name };
|
|
14
|
-
let apiHandler: any;
|
|
15
|
-
|
|
16
|
-
beforeAll(async () => {
|
|
17
|
-
const runner = await serverManager
|
|
18
|
-
.clone()
|
|
19
|
-
.usePlugin(APIPlugin, plugin)
|
|
20
|
-
.init();
|
|
21
|
-
apiHandler = await runner.prepareApiServer({
|
|
22
|
-
pwd,
|
|
23
|
-
mode: 'function',
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('should works with body', async () => {
|
|
28
|
-
const res = await request(apiHandler).post('/nest/user').send(foo);
|
|
29
|
-
expect(res.status).toBe(200);
|
|
30
|
-
expect(res.body.data).toEqual(foo);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('should works with schema', async () => {
|
|
34
|
-
const res = await request(apiHandler).patch('/nest/user').send({
|
|
35
|
-
id: 777,
|
|
36
|
-
name: 'xxx',
|
|
37
|
-
});
|
|
38
|
-
expect(res.status).toBe(200);
|
|
39
|
-
expect(res.body.id).toBe(777);
|
|
40
|
-
|
|
41
|
-
const res2 = await request(apiHandler).patch('/nest/user').send({
|
|
42
|
-
id: 'aaa',
|
|
43
|
-
name: 'xxx',
|
|
44
|
-
});
|
|
45
|
-
expect(res2.status).toBe(400);
|
|
46
|
-
|
|
47
|
-
const res3 = await request(apiHandler).patch('/nest/user').send({
|
|
48
|
-
id: '777',
|
|
49
|
-
name: 'xxx',
|
|
50
|
-
});
|
|
51
|
-
expect(res3.status).toBe(500);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('should support upload file', done => {
|
|
55
|
-
request(apiHandler)
|
|
56
|
-
.post('/upload')
|
|
57
|
-
.field('my_field', 'value')
|
|
58
|
-
.attach('file', path.join(__dirname, './fixtures/assets/index.html'))
|
|
59
|
-
.end(async (err, res) => {
|
|
60
|
-
if (err) {
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
63
|
-
expect(res.statusCode).toBe(200);
|
|
64
|
-
expect(res.body.message).toBe('success');
|
|
65
|
-
expect(res.body.formData).not.toBeUndefined();
|
|
66
|
-
done();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
package/tests/helpers.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { createPlugin } from '@modern-js/server-core';
|
|
3
|
-
import { injectAPIHandlerInfos, API_DIR } from '@modern-js/bff-utils';
|
|
4
|
-
|
|
5
|
-
export const APIPlugin = createPlugin(() => ({
|
|
6
|
-
prepareApiServer(props, next) {
|
|
7
|
-
const { pwd, prefix } = props;
|
|
8
|
-
const apiDir = path.resolve(pwd, API_DIR);
|
|
9
|
-
|
|
10
|
-
injectAPIHandlerInfos(apiDir, prefix);
|
|
11
|
-
|
|
12
|
-
return next(props);
|
|
13
|
-
},
|
|
14
|
-
}));
|