@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.
Files changed (91) hide show
  1. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/.wireit/6275696c64/stdout +9 -0
  2. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/cli/index.js +60 -0
  3. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/context.js +6 -0
  4. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/index.js +3 -0
  5. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/plugin.js +129 -0
  6. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/registerRoutes.js +82 -0
  7. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/modern/runtime.js +1 -0
  8. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/cli/index.js +76 -0
  9. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/context.js +15 -0
  10. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/index.js +28 -0
  11. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/plugin.js +151 -0
  12. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/registerRoutes.js +97 -0
  13. package/.wireit/6275696c64/cache/5a7fd1190b57f273bbfc05fc04fa99ef67c54e4eac07712cccd97346c9903534/dist/js/node/runtime.js +13 -0
  14. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/cli/index.js +60 -0
  15. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/context.js +6 -0
  16. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/index.js +3 -0
  17. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/plugin.js +129 -0
  18. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/registerRoutes.js +82 -0
  19. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/modern/runtime.js +1 -0
  20. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/cli/index.js +76 -0
  21. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/context.js +15 -0
  22. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/index.js +28 -0
  23. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/plugin.js +151 -0
  24. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/registerRoutes.js +97 -0
  25. package/.wireit/6275696c64/cache/a48cd57db6d78fbc9aca74c669a12325d8d6adee3602be60b39b7f0aee775e0e/dist/js/node/runtime.js +13 -0
  26. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/cli/index.js +60 -0
  27. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/context.js +6 -0
  28. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/index.js +3 -0
  29. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/plugin.js +129 -0
  30. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/registerRoutes.js +82 -0
  31. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/modern/runtime.js +1 -0
  32. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/cli/index.js +76 -0
  33. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/context.js +15 -0
  34. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/index.js +28 -0
  35. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/plugin.js +151 -0
  36. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/registerRoutes.js +97 -0
  37. package/.wireit/6275696c64/cache/c2bcc9f69d6e88cab5556c7e21d2d96caf864704311f42923d5aac9d76903c09/dist/js/node/runtime.js +13 -0
  38. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/.wireit/6275696c64/stdout +9 -0
  39. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/cli/index.js +62 -0
  40. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/context.js +6 -0
  41. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/index.js +3 -0
  42. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/plugin.js +129 -0
  43. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/registerRoutes.js +82 -0
  44. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/modern/runtime.js +1 -0
  45. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/cli/index.js +78 -0
  46. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/context.js +15 -0
  47. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/index.js +28 -0
  48. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/plugin.js +151 -0
  49. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/registerRoutes.js +97 -0
  50. package/.wireit/6275696c64/cache/c702551e9ac5f99417b3d7904cde2a76ea272e9a04c27fe6afd33e73b7c25856/dist/js/node/runtime.js +13 -0
  51. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/cli/index.js +60 -0
  52. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/context.js +6 -0
  53. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/index.js +3 -0
  54. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/plugin.js +129 -0
  55. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/registerRoutes.js +82 -0
  56. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/modern/runtime.js +1 -0
  57. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/cli/index.js +76 -0
  58. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/context.js +15 -0
  59. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/index.js +28 -0
  60. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/plugin.js +151 -0
  61. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/registerRoutes.js +97 -0
  62. package/.wireit/6275696c64/cache/fceab7422ff46c3bc400017a31f179fd20fb88539c1968876d37bec188823945/dist/js/node/runtime.js +13 -0
  63. package/{tests/fixtures/function-mode/api/_app.ts → .wireit/6275696c64/lock} +0 -0
  64. package/.wireit/6275696c64/state +1 -0
  65. package/.wireit/6275696c64/stdout +9 -0
  66. package/CHANGELOG.md +28 -0
  67. package/dist/js/modern/cli/index.js +6 -9
  68. package/dist/js/modern/registerRoutes.js +3 -3
  69. package/dist/js/node/cli/index.js +6 -8
  70. package/dist/js/node/registerRoutes.js +3 -3
  71. package/package.json +34 -10
  72. package/.eslintrc.js +0 -7
  73. package/jest.config.js +0 -7
  74. package/modern.config.js +0 -2
  75. package/tests/.eslintrc.js +0 -6
  76. package/tests/common.ts +0 -9
  77. package/tests/fixtures/assets/index.html +0 -12
  78. package/tests/fixtures/function-mode/api/hello.ts +0 -1
  79. package/tests/fixtures/function-mode/api/nest/user.ts +0 -33
  80. package/tests/fixtures/function-mode/api/upload.ts +0 -4
  81. package/tests/fixtures/lambda-mode/api/app.ts +0 -1
  82. package/tests/fixtures/lambda-mode/api/lambda/hello.ts +0 -1
  83. package/tests/fixtures/lambda-mode/api/lambda/nest/[id].ts +0 -1
  84. package/tests/fixtures/lambda-mode/api/lambda/nest/user.ts +0 -33
  85. package/tests/fixtures/lambda-mode/api/lambda/upload.ts +0 -4
  86. package/tests/functionMode.test.ts +0 -69
  87. package/tests/helpers.ts +0 -14
  88. package/tests/lambdaMode.test.ts +0 -318
  89. package/tests/tsconfig.json +0 -12
  90. package/tests/webServer.test.ts +0 -81
  91. 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
- const serverRuntimePath = bffExportsUtils.getPath(); // Look up one level, because the artifacts after build have dist directories
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
- let relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
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': relativeRuntimePath
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 wrapedHandler = async ctx => {
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(wrapedHandler, Object.getOwnPropertyDescriptors(handler));
48
+ Object.defineProperties(wrappedHandler, Object.getOwnPropertyDescriptors(handler));
49
49
 
50
50
  if (isNormalMethod(method)) {
51
51
  const routeName = method.toLowerCase();
52
- router[routeName](name, wrapedHandler);
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
- const serverRuntimePath = bffExportsUtils.getPath(); // Look up one level, because the artifacts after build have dist directories
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 === 'development' || process.env.NODE_ENV === 'test') {
37
- relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
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': relativeRuntimePath
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 wrapedHandler = async ctx => {
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(wrapedHandler, Object.getOwnPropertyDescriptors(handler));
62
+ Object.defineProperties(wrappedHandler, Object.getOwnPropertyDescriptors(handler));
63
63
 
64
64
  if (isNormalMethod(method)) {
65
65
  const routeName = method.toLowerCase();
66
- router[routeName](name, wrapedHandler);
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.5",
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.1",
38
- "@modern-js/bff-runtime": "^1.2.1",
39
- "@modern-js/bff-utils": "^1.2.2",
40
- "@modern-js/utils": "^1.3.7",
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.2.5",
56
- "@modern-js/core": "1.6.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
- "build": "modern build",
76
- "test": "jest --passWithNoTests"
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
@@ -1,7 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- ignorePatterns: ['types.d.ts'],
7
- };
package/jest.config.js DELETED
@@ -1,7 +0,0 @@
1
- const sharedConfig = require('@scripts/jest-config');
2
-
3
- /** @type {import('@jest/types').Config.InitialOptions} */
4
- module.exports = {
5
- ...sharedConfig,
6
- rootDir: __dirname,
7
- };
package/modern.config.js DELETED
@@ -1,2 +0,0 @@
1
- /** @type {import('@modern-js/module-tools').UserConfig} */
2
- module.exports = {};
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
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,4 +0,0 @@
1
- export const post = ({ formData }) => ({
2
- message: 'success',
3
- formData,
4
- });
@@ -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,4 +0,0 @@
1
- export const post = ({ formData }) => ({
2
- message: 'success',
3
- formData,
4
- });
@@ -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
- }));