@modern-js/plugin-koa 1.1.4 → 1.3.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,56 @@
1
1
  # @modern-js/plugin-koa
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cfe11628: Make Modern.js self bootstraping
8
+
9
+ ### Patch Changes
10
+
11
+ - 146dcd85: modify server framework plugin hook types and hook context
12
+ - 146dcd85: modify server framework plugin hook types
13
+ - 146dcd85: fix test case in babel compiler
14
+ - Updated dependencies [2da09c69]
15
+ - Updated dependencies [fc71e36f]
16
+ - Updated dependencies [146dcd85]
17
+ - Updated dependencies [c3d46ee4]
18
+ - Updated dependencies [cfe11628]
19
+ - Updated dependencies [146dcd85]
20
+ - Updated dependencies [8e7603ee]
21
+ - Updated dependencies [146dcd85]
22
+ - @modern-js/utils@1.2.0
23
+ - @modern-js/core@1.3.0
24
+ - @modern-js/bff-runtime@1.2.0
25
+ - @modern-js/adapter-helpers@1.2.0
26
+ - @modern-js/bff-utils@1.2.0
27
+ - @modern-js/server-plugin@1.2.0
28
+
29
+ ## 1.2.1
30
+
31
+ ### Patch Changes
32
+
33
+ - ad107726: feat: new action support apppend type define
34
+
35
+ ## 1.2.0
36
+
37
+ ### Minor Changes
38
+
39
+ - 5a4c557e: feat: support bff test
40
+
41
+ ### Patch Changes
42
+
43
+ - a70a62f5: fix: runtime path is broken in development environment
44
+ - Updated dependencies [90eeb72c]
45
+ - Updated dependencies [e04914ce]
46
+ - Updated dependencies [5a4c557e]
47
+ - Updated dependencies [e04914ce]
48
+ - Updated dependencies [ca7dcb32]
49
+ - Updated dependencies [ecb344dc]
50
+ - @modern-js/core@1.2.0
51
+ - @modern-js/server-plugin@1.1.3
52
+ - @modern-js/utils@1.1.5
53
+
3
54
  ## 1.1.4
4
55
 
5
56
  ### Patch Changes
@@ -16,7 +16,7 @@ export default createPlugin(() => {
16
16
 
17
17
  let relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
18
18
 
19
- if (process.env.NODE_ENV === 'development') {
19
+ if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
20
20
  relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
21
21
  }
22
22
 
@@ -30,7 +30,7 @@ var _default = (0, _core.createPlugin)(() => {
30
30
 
31
31
  let relativeRuntimePath = path.join('../', path.relative(appDirectory, serverRuntimePath));
32
32
 
33
- if (process.env.NODE_ENV === 'development') {
33
+ if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
34
34
  relativeRuntimePath = `./${path.relative(appDirectory, serverRuntimePath)}`;
35
35
  }
36
36
 
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ };
package/modern.config.js CHANGED
@@ -1,10 +1,2 @@
1
1
  /** @type {import('@modern-js/module-tools').UserConfig} */
2
- module.exports = {
3
- testing: {
4
- jest: {
5
- collectCoverage: true,
6
- collectCoverageFrom: ['src/**/*.ts'],
7
- coveragePathIgnorePatterns: ['/node_modules/'],
8
- },
9
- },
10
- };
2
+ module.exports = {};
package/package.json CHANGED
@@ -11,26 +11,31 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.4",
14
+ "version": "1.3.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
18
18
  "module": "./dist/js/treeshaking/index.js",
19
19
  "jsnext:modern": "./dist/js/modern/index.js",
20
20
  "exports": {
21
+ "./types": "./types.d.ts",
21
22
  ".": {
22
23
  "node": {
24
+ "jsnext:source": "./src/index.ts",
23
25
  "import": "./dist/js/modern/index.js",
24
26
  "require": "./dist/js/node/index.js"
25
27
  },
26
28
  "default": "./dist/js/treeshaking/index.js"
27
29
  },
28
- "./cli": "./dist/js/node/cli/index.js"
30
+ "./cli": {
31
+ "jsnext:source": "./src/cli/index.ts",
32
+ "default": "./dist/js/node/cli/index.js"
33
+ }
29
34
  },
30
35
  "dependencies": {
31
36
  "@babel/runtime": "^7.15.3",
32
- "@modern-js/adapter-helpers": "^1.1.1",
33
- "@modern-js/utils": "^1.1.4",
37
+ "@modern-js/adapter-helpers": "^1.2.0",
38
+ "@modern-js/utils": "^1.2.0",
34
39
  "formidable": "^1.2.2",
35
40
  "koa-body": "^4.2.0",
36
41
  "koa-router": "^10.0.0",
@@ -47,12 +52,13 @@
47
52
  "@types/type-is": "^1.6.3",
48
53
  "supertest": "^6.1.6",
49
54
  "typescript": "^4",
50
- "@modern-js/bff-runtime": "^1.1.1",
51
- "@modern-js/bff-utils": "^1.1.1",
52
- "@modern-js/core": "^1.1.4",
53
- "@modern-js/server-plugin": "^1.1.1",
54
- "@modern-js/plugin-testing": "^1.1.1",
55
- "@modern-js/module-tools": "^1.1.1"
55
+ "@modern-js/bff-runtime": "^1.2.0",
56
+ "@modern-js/bff-utils": "^1.2.0",
57
+ "@modern-js/core": "^1.3.0",
58
+ "@modern-js/server-plugin": "^1.2.0",
59
+ "@scripts/build": "0.0.0",
60
+ "jest": "^27",
61
+ "@scripts/jest-config": "0.0.0"
56
62
  },
57
63
  "modernConfig": {
58
64
  "output": {
@@ -60,20 +66,21 @@
60
66
  }
61
67
  },
62
68
  "peerDependencies": {
63
- "@modern-js/bff-utils": "^1.1.1",
64
- "@modern-js/core": "^1.1.4",
65
- "@modern-js/server-plugin": "^1.1.1",
66
- "@modern-js/bff-runtime": "^1.1.1",
69
+ "@modern-js/bff-utils": "^1.2.0",
70
+ "@modern-js/core": "^1.3.0",
71
+ "@modern-js/server-plugin": "^1.2.0",
72
+ "@modern-js/bff-runtime": "^1.2.0",
67
73
  "koa": "^2.13.3"
68
74
  },
69
75
  "publishConfig": {
70
76
  "registry": "https://registry.npmjs.org/",
71
- "access": "public"
77
+ "access": "public",
78
+ "types": "./dist/types/index.d.ts"
72
79
  },
73
80
  "scripts": {
74
81
  "new": "modern new",
75
82
  "build": "modern build",
76
- "test": "modern test"
83
+ "test": "jest --passWithNoTests"
77
84
  },
78
85
  "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
86
  }
package/src/cli/index.ts CHANGED
@@ -25,7 +25,10 @@ export default createPlugin(
25
25
  path.relative(appDirectory, serverRuntimePath),
26
26
  );
27
27
 
28
- if (process.env.NODE_ENV === 'development') {
28
+ if (
29
+ process.env.NODE_ENV === 'development' ||
30
+ process.env.NODE_ENV === 'test'
31
+ ) {
29
32
  relativeRuntimePath = `./${path.relative(
30
33
  appDirectory,
31
34
  serverRuntimePath,
@@ -1,5 +1,5 @@
1
1
  import { match } from '@modern-js/bff-runtime';
2
- import { useContext } from '@/context';
2
+ import { useContext } from '../../../../../src/context';
3
3
 
4
4
  export const get = ({ query }: { query: Record<string, unknown> }) => ({
5
5
  query,
@@ -1,5 +1,5 @@
1
1
  import { match } from '@modern-js/bff-runtime';
2
- import { useContext } from '@/context';
2
+ import { useContext } from '../../../../../../src/context';
3
3
 
4
4
  export const get = ({ query }: { query: Record<string, unknown> }) => ({
5
5
  query,
@@ -1,6 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import request from 'supertest';
3
- import Koa, { Context, Next } from 'koa';
3
+ import Koa from 'koa';
4
4
  import { serverManager } from '@modern-js/server-plugin';
5
5
  import Router from 'koa-router';
6
6
  import koaBody from 'koa-body';
@@ -111,11 +111,11 @@ describe('add middlewares', () => {
111
111
 
112
112
  test('should works', async () => {
113
113
  const foo = 'foo';
114
- const fakeMiddleware = jest.fn(async (ctx: Context, next: Next) => {
114
+ const fakeMiddleware = jest.fn(async (ctx: any, next: any) => {
115
115
  await next();
116
116
  ctx.body = foo;
117
117
  });
118
- const fakeMiddleware2 = jest.fn(async (ctx: Context, next: Next) => {
118
+ const fakeMiddleware2 = jest.fn(async (ctx: any, next: any) => {
119
119
  await next();
120
120
  });
121
121
 
@@ -7,8 +7,6 @@
7
7
  "isolatedModules": true,
8
8
  "sourceMap": true
9
9
  },
10
- "paths": {
11
- "@/*": ["../src/*"]
12
- },
10
+ "paths": {},
13
11
  "exclude": ["src/__test__/fixtures/**"]
14
12
  }
package/types.d.ts CHANGED
@@ -1,7 +1,17 @@
1
1
  /// <reference path="./dist/types/index.d.ts" />
2
-
3
2
  declare module '@modern-js/runtime/server' {
4
- import { Context } from 'koa';
3
+
4
+ import { Context, Middleware } from 'koa';
5
+
6
+ type KoaOptions = {
7
+ addMiddleware: (...input: Middleware[]) => void;
8
+ };
9
+
10
+ type KoaAttacher = (options: KoaOptions) => void;
5
11
 
6
12
  export function useContext(): Context;
13
+
14
+ export function hook(attacher: KoaAttacher): KoaAttacher;
15
+
16
+ export * from '@modern-js/bff-runtime';
7
17
  }