@modern-js/plugin-bff 1.3.8 → 1.4.1
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 +47 -0
- package/dist/js/modern/cli.js +1 -3
- package/dist/js/modern/index.js +0 -1
- package/dist/js/modern/server.js +15 -12
- package/dist/js/node/cli.js +2 -6
- package/dist/js/node/index.js +0 -2
- package/dist/js/node/server.js +17 -15
- package/dist/types/cli.d.ts +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/loader.d.ts +1 -1
- package/jest.config.js +0 -1
- package/package.json +16 -18
- package/types.d.ts +0 -1
- package/dist/js/modern/types.js +0 -1
- package/dist/js/node/types.js +0 -3
- package/dist/types/types.d.ts +0 -11
- package/tests/.eslintrc.js +0 -6
- package/tests/__snapshots__/cli.test.ts.snap +0 -64
- package/tests/__snapshots__/loader.test.ts.snap +0 -43
- package/tests/__snapshots__/server.test.ts.snap +0 -66
- package/tests/cli.test.ts +0 -98
- package/tests/compiler.ts +0 -53
- package/tests/fixtures/function/api/hello.ts +0 -17
- package/tests/fixtures/function/api/upload.ts +0 -3
- package/tests/fixtures/function/api/user/[id].ts +0 -3
- package/tests/fixtures/requestCreator/client.ts +0 -3
- package/tests/fixtures/requestCreator/server.ts +0 -3
- package/tests/fixtures/test-fetcher.ts +0 -3
- package/tests/loader.test.ts +0 -107
- package/tests/server.test.ts +0 -39
- package/tests/tsconfig.json +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @modern-js/plugin-bff
|
|
2
2
|
|
|
3
|
+
## 1.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
|
|
8
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
9
|
+
- e4cec1ce: types: fix config hook type
|
|
10
|
+
- Updated dependencies [b8599d09]
|
|
11
|
+
- Updated dependencies [6cffe99d]
|
|
12
|
+
- Updated dependencies [04ae5262]
|
|
13
|
+
- Updated dependencies [60f7d8bf]
|
|
14
|
+
- Updated dependencies [3bf4f8b0]
|
|
15
|
+
- @modern-js/utils@1.5.0
|
|
16
|
+
- @modern-js/bff-utils@1.2.3
|
|
17
|
+
- @modern-js/server-utils@1.2.3
|
|
18
|
+
- @modern-js/babel-compiler@1.2.3
|
|
19
|
+
- @modern-js/create-request@1.2.4
|
|
20
|
+
|
|
21
|
+
## 1.4.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- d2d1d6b2: feat: support server config
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- d2d1d6b2: feat: add prepare hook
|
|
30
|
+
- Updated dependencies [77ff9754]
|
|
31
|
+
- Updated dependencies [d2d1d6b2]
|
|
32
|
+
- Updated dependencies [07a4887e]
|
|
33
|
+
- Updated dependencies [ea2ae711]
|
|
34
|
+
- Updated dependencies [17d0cc46]
|
|
35
|
+
- Updated dependencies [d2d1d6b2]
|
|
36
|
+
- @modern-js/utils@1.4.0
|
|
37
|
+
- @modern-js/server-utils@1.2.2
|
|
38
|
+
|
|
39
|
+
## 1.3.9
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- bebb39b6: chore: improve devDependencies and peerDependencies
|
|
44
|
+
- 132f7b53: feat: move config declarations to @modern-js/core
|
|
45
|
+
- Updated dependencies [bebb39b6]
|
|
46
|
+
- Updated dependencies [132f7b53]
|
|
47
|
+
- @modern-js/server-utils@1.2.2
|
|
48
|
+
- @modern-js/utils@1.3.7
|
|
49
|
+
|
|
3
50
|
## 1.3.8
|
|
4
51
|
|
|
5
52
|
### Patch Changes
|
package/dist/js/modern/cli.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import "./types";
|
|
2
1
|
import path from 'path';
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
2
|
import { compiler } from '@modern-js/babel-compiler';
|
|
5
|
-
import { PLUGIN_SCHEMAS, normalizeOutputPath
|
|
3
|
+
import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath } from '@modern-js/utils';
|
|
6
4
|
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
7
5
|
const DEFAULT_API_PREFIX = '/api';
|
|
8
6
|
const TS_CONFIG_FILENAME = 'tsconfig.json';
|
package/dist/js/modern/index.js
CHANGED
package/dist/js/modern/server.js
CHANGED
|
@@ -24,22 +24,25 @@ const createTransformAPI = storage => ({
|
|
|
24
24
|
export default (() => ({
|
|
25
25
|
name: '@modern-js/plugin-bff',
|
|
26
26
|
setup: api => {
|
|
27
|
-
const {
|
|
28
|
-
appDirectory,
|
|
29
|
-
distDirectory
|
|
30
|
-
} = api.useAppContext();
|
|
31
|
-
const root = isProd() ? distDirectory : appDirectory;
|
|
32
|
-
const apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
33
|
-
const apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
34
27
|
const storage = new Storage();
|
|
35
28
|
const transformAPI = createTransformAPI(storage);
|
|
36
|
-
|
|
29
|
+
let apiAppPath = '';
|
|
30
|
+
return {
|
|
31
|
+
prepare() {
|
|
32
|
+
const {
|
|
33
|
+
appDirectory,
|
|
34
|
+
distDirectory
|
|
35
|
+
} = api.useAppContext();
|
|
36
|
+
const root = isProd() ? distDirectory : appDirectory;
|
|
37
|
+
const apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
38
|
+
apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
39
|
+
const apiMod = requireExistModule(apiAppPath);
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
if (apiMod && typeof apiMod === 'function') {
|
|
42
|
+
apiMod(transformAPI);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
41
45
|
|
|
42
|
-
return {
|
|
43
46
|
reset() {
|
|
44
47
|
storage.reset();
|
|
45
48
|
const newApiModule = requireExistModule(apiAppPath);
|
package/dist/js/node/cli.js
CHANGED
|
@@ -5,12 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
require("./types");
|
|
9
|
-
|
|
10
8
|
var _path = _interopRequireDefault(require("path"));
|
|
11
9
|
|
|
12
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
13
|
-
|
|
14
10
|
var _babelCompiler = require("@modern-js/babel-compiler");
|
|
15
11
|
|
|
16
12
|
var _utils = require("@modern-js/utils");
|
|
@@ -126,8 +122,8 @@ var _default = () => ({
|
|
|
126
122
|
ignore: [`**/__tests__/**`, '**/typings/**', '*.d.ts', '*.test.ts']
|
|
127
123
|
}, babelConfig);
|
|
128
124
|
|
|
129
|
-
if (await
|
|
130
|
-
await
|
|
125
|
+
if (await _utils.fs.pathExists(rootDir)) {
|
|
126
|
+
await _utils.fs.copy(rootDir, distDir, {
|
|
131
127
|
filter: src => !['.ts', '.js'].includes(_path.default.extname(src)) && src !== tsconfigPath
|
|
132
128
|
});
|
|
133
129
|
}
|
package/dist/js/node/index.js
CHANGED
package/dist/js/node/server.js
CHANGED
|
@@ -36,25 +36,27 @@ const createTransformAPI = storage => ({
|
|
|
36
36
|
var _default = () => ({
|
|
37
37
|
name: '@modern-js/plugin-bff',
|
|
38
38
|
setup: api => {
|
|
39
|
-
const {
|
|
40
|
-
appDirectory,
|
|
41
|
-
distDirectory
|
|
42
|
-
} = api.useAppContext();
|
|
43
|
-
const root = (0, _utils.isProd)() ? distDirectory : appDirectory;
|
|
44
|
-
|
|
45
|
-
const apiPath = _path.default.resolve(root || process.cwd(), _utils.API_DIR);
|
|
46
|
-
|
|
47
|
-
const apiAppPath = _path.default.resolve(apiPath, _constants.API_APP_NAME);
|
|
48
|
-
|
|
49
39
|
const storage = new Storage();
|
|
50
40
|
const transformAPI = createTransformAPI(storage);
|
|
51
|
-
|
|
41
|
+
let apiAppPath = '';
|
|
42
|
+
return {
|
|
43
|
+
prepare() {
|
|
44
|
+
const {
|
|
45
|
+
appDirectory,
|
|
46
|
+
distDirectory
|
|
47
|
+
} = api.useAppContext();
|
|
48
|
+
const root = (0, _utils.isProd)() ? distDirectory : appDirectory;
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
const apiPath = _path.default.resolve(root || process.cwd(), _utils.API_DIR);
|
|
51
|
+
|
|
52
|
+
apiAppPath = _path.default.resolve(apiPath, _constants.API_APP_NAME);
|
|
53
|
+
const apiMod = (0, _utils.requireExistModule)(apiAppPath);
|
|
54
|
+
|
|
55
|
+
if (apiMod && typeof apiMod === 'function') {
|
|
56
|
+
apiMod(transformAPI);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
56
59
|
|
|
57
|
-
return {
|
|
58
60
|
reset() {
|
|
59
61
|
storage.reset();
|
|
60
62
|
const newApiModule = (0, _utils.requireExistModule)(apiAppPath);
|
package/dist/types/cli.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
package/dist/types/loader.d.ts
CHANGED
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.4.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -55,33 +55,31 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@babel/core": "7.16.7",
|
|
57
57
|
"@babel/runtime": "^7",
|
|
58
|
-
"@modern-js/babel-compiler": "^1.2.
|
|
59
|
-
"@modern-js/
|
|
60
|
-
"@modern-js/
|
|
61
|
-
"@modern-js/utils": "^1.3
|
|
62
|
-
"
|
|
63
|
-
"loader-utils": "^2.0.0"
|
|
64
|
-
"@modern-js/bff-utils": "^1.2.2"
|
|
58
|
+
"@modern-js/babel-compiler": "^1.2.3",
|
|
59
|
+
"@modern-js/bff-utils": "^1.2.3",
|
|
60
|
+
"@modern-js/create-request": "^1.2.4",
|
|
61
|
+
"@modern-js/server-utils": "^1.2.3",
|
|
62
|
+
"@modern-js/utils": "^1.5.0",
|
|
63
|
+
"loader-utils": "^2.0.0"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
66
|
+
"@modern-js/core": "1.8.0",
|
|
67
|
+
"@modern-js/plugin-analyze": "^1.4.0",
|
|
68
|
+
"@modern-js/runtime": "^1.2.6",
|
|
69
|
+
"@modern-js/server-core": "1.3.1",
|
|
70
|
+
"@modern-js/types": "^1.5.0",
|
|
67
71
|
"@scripts/build": "0.0.0",
|
|
68
|
-
"@
|
|
69
|
-
"@modern-js/runtime": "^1.2.4",
|
|
70
|
-
"@modern-js/types": "^1.3.4",
|
|
72
|
+
"@scripts/jest-config": "0.0.0",
|
|
71
73
|
"@types/babel__core": "^7.1.15",
|
|
72
|
-
"@types/fs-extra": "^9.0.13",
|
|
73
74
|
"@types/jest": "^26",
|
|
74
75
|
"@types/loader-utils": "^2.0.3",
|
|
75
76
|
"@types/node": "^14",
|
|
77
|
+
"jest": "^27",
|
|
76
78
|
"memfs": "^3.3.0",
|
|
77
79
|
"ts-jest": "^27.0.5",
|
|
78
80
|
"typescript": "^4",
|
|
79
|
-
"webpack": "^5.
|
|
80
|
-
"webpack-chain": "^6.5.1"
|
|
81
|
-
"jest": "^27",
|
|
82
|
-
"@scripts/jest-config": "0.0.0",
|
|
83
|
-
"@modern-js/server-core": "^1.2.4",
|
|
84
|
-
"@modern-js/core": "^1.6.0"
|
|
81
|
+
"webpack": "^5.71.0",
|
|
82
|
+
"webpack-chain": "^6.5.1"
|
|
85
83
|
},
|
|
86
84
|
"sideEffects": false,
|
|
87
85
|
"publishConfig": {
|
package/types.d.ts
CHANGED
package/dist/js/modern/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@modern-js/core';
|
package/dist/js/node/types.js
DELETED
package/dist/types/types.d.ts
DELETED
package/tests/.eslintrc.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`bff cli plugin config 1`] = `
|
|
4
|
-
Array [
|
|
5
|
-
Object {
|
|
6
|
-
"source": Object {
|
|
7
|
-
"moduleScopes": Array [
|
|
8
|
-
"./api",
|
|
9
|
-
/create-request/,
|
|
10
|
-
],
|
|
11
|
-
},
|
|
12
|
-
"tools": Object {
|
|
13
|
-
"webpack": [Function],
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
]
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
exports[`bff cli plugin schema 1`] = `
|
|
20
|
-
Array [
|
|
21
|
-
Array [
|
|
22
|
-
Object {
|
|
23
|
-
"schema": Object {
|
|
24
|
-
"properties": Object {
|
|
25
|
-
"fetcher": Object {
|
|
26
|
-
"type": "string",
|
|
27
|
-
},
|
|
28
|
-
"prefix": Object {
|
|
29
|
-
"items": Object {
|
|
30
|
-
"type": "string",
|
|
31
|
-
},
|
|
32
|
-
"type": Array [
|
|
33
|
-
"string",
|
|
34
|
-
"array",
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
"proxy": Object {
|
|
38
|
-
"type": "object",
|
|
39
|
-
},
|
|
40
|
-
"requestCreator": Object {
|
|
41
|
-
"type": "string",
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
"type": "object",
|
|
45
|
-
},
|
|
46
|
-
"target": "bff",
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
]
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
|
-
exports[`bff cli plugin server routes 1`] = `
|
|
53
|
-
Object {
|
|
54
|
-
"routes": Array [
|
|
55
|
-
Object {
|
|
56
|
-
"entryPath": "",
|
|
57
|
-
"isApi": true,
|
|
58
|
-
"isSPA": false,
|
|
59
|
-
"isSSR": false,
|
|
60
|
-
"urlPath": "/api",
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
}
|
|
64
|
-
`;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`bff loader should work well 1`] = `
|
|
4
|
-
"import { createRequest } from '/packages/server/create-request/src/node.ts';
|
|
5
|
-
|
|
6
|
-
export const get = createRequest('/hello', 'GET', process.env.PORT || 3000);
|
|
7
|
-
export const patch = createRequest('/hello', 'PATCH', process.env.PORT || 3000);
|
|
8
|
-
"
|
|
9
|
-
`;
|
|
10
|
-
|
|
11
|
-
exports[`bff loader should work well with client 1`] = `
|
|
12
|
-
"import { createRequest } from '/packages/server/create-request/src/node.ts';
|
|
13
|
-
|
|
14
|
-
export const get = createRequest('/hello', 'GET', process.env.PORT || 3000);
|
|
15
|
-
export const patch = createRequest('/hello', 'PATCH', process.env.PORT || 3000);
|
|
16
|
-
"
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
exports[`bff loader should work well with fetcher 1`] = `undefined`;
|
|
20
|
-
|
|
21
|
-
exports[`bff loader should work well with port 1`] = `
|
|
22
|
-
"import { createRequest } from '/packages/server/create-request/src/node.ts';
|
|
23
|
-
|
|
24
|
-
export const get = createRequest('/hello', 'GET', process.env.PORT || 80);
|
|
25
|
-
export const patch = createRequest('/hello', 'PATCH', process.env.PORT || 80);
|
|
26
|
-
"
|
|
27
|
-
`;
|
|
28
|
-
|
|
29
|
-
exports[`bff loader should work well with prefix 1`] = `
|
|
30
|
-
"import { createRequest } from '/packages/server/create-request/src/node.ts';
|
|
31
|
-
|
|
32
|
-
export const get = createRequest('api/hello', 'GET', process.env.PORT || 3000);
|
|
33
|
-
export const patch = createRequest('api/hello', 'PATCH', process.env.PORT || 3000);
|
|
34
|
-
"
|
|
35
|
-
`;
|
|
36
|
-
|
|
37
|
-
exports[`bff loader should work well with requestCreator 1`] = `
|
|
38
|
-
"import { createRequest } from '/packages/cli/plugin-bff/tests/fixtures/requestCreator/client';
|
|
39
|
-
|
|
40
|
-
export const get = createRequest('/hello', 'GET', process.env.PORT || 80);
|
|
41
|
-
export const patch = createRequest('/hello', 'PATCH', process.env.PORT || 80);
|
|
42
|
-
"
|
|
43
|
-
`;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`bff server plugin prepareApiServer should work well 1`] = `
|
|
4
|
-
Array [
|
|
5
|
-
Object {
|
|
6
|
-
"handler": [Function],
|
|
7
|
-
"method": "GET",
|
|
8
|
-
"name": "/hello",
|
|
9
|
-
},
|
|
10
|
-
Object {
|
|
11
|
-
"handler": [Function],
|
|
12
|
-
"method": "PATCH",
|
|
13
|
-
"name": "/hello",
|
|
14
|
-
},
|
|
15
|
-
Object {
|
|
16
|
-
"handler": [Function],
|
|
17
|
-
"method": "GET",
|
|
18
|
-
"name": "/upload",
|
|
19
|
-
},
|
|
20
|
-
Object {
|
|
21
|
-
"handler": [Function],
|
|
22
|
-
"method": "GET",
|
|
23
|
-
"name": "/user/:id",
|
|
24
|
-
},
|
|
25
|
-
Object {
|
|
26
|
-
"handler": [Function],
|
|
27
|
-
"method": "GET",
|
|
28
|
-
"name": "/__introspection__",
|
|
29
|
-
},
|
|
30
|
-
]
|
|
31
|
-
`;
|
|
32
|
-
|
|
33
|
-
exports[`bff server plugin prepareApiServer should work well with prefix 1`] = `
|
|
34
|
-
Array [
|
|
35
|
-
Object {
|
|
36
|
-
"handler": [Function],
|
|
37
|
-
"method": "GET",
|
|
38
|
-
"name": "/hello",
|
|
39
|
-
"path": "/api/hello",
|
|
40
|
-
},
|
|
41
|
-
Object {
|
|
42
|
-
"handler": [Function],
|
|
43
|
-
"method": "PATCH",
|
|
44
|
-
"name": "/hello",
|
|
45
|
-
"path": "/api/hello",
|
|
46
|
-
},
|
|
47
|
-
Object {
|
|
48
|
-
"handler": [Function],
|
|
49
|
-
"method": "GET",
|
|
50
|
-
"name": "/upload",
|
|
51
|
-
"path": "/api/upload",
|
|
52
|
-
},
|
|
53
|
-
Object {
|
|
54
|
-
"handler": [Function],
|
|
55
|
-
"method": "GET",
|
|
56
|
-
"name": "/user/:id",
|
|
57
|
-
"path": "/api/user/:id",
|
|
58
|
-
},
|
|
59
|
-
Object {
|
|
60
|
-
"handler": [Function],
|
|
61
|
-
"method": "GET",
|
|
62
|
-
"name": "/__introspection__",
|
|
63
|
-
"path": "/api/__introspection__",
|
|
64
|
-
},
|
|
65
|
-
]
|
|
66
|
-
`;
|
package/tests/cli.test.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { manager, AppContext } from '@modern-js/core';
|
|
3
|
-
import { modifyServerRoutes } from '@modern-js/plugin-analyze';
|
|
4
|
-
import Chain from 'webpack-chain';
|
|
5
|
-
import plugin from '../src/cli';
|
|
6
|
-
|
|
7
|
-
const root = path.normalize(path.resolve(__dirname, '../../../../'));
|
|
8
|
-
expect.addSnapshotSerializer({
|
|
9
|
-
test: val =>
|
|
10
|
-
typeof val === 'string' &&
|
|
11
|
-
(val.includes('modern.js') ||
|
|
12
|
-
val.includes('node_modules') ||
|
|
13
|
-
val.includes(root)),
|
|
14
|
-
print: val =>
|
|
15
|
-
// eslint-disable-next-line no-nested-ternary
|
|
16
|
-
typeof val === 'string'
|
|
17
|
-
? // eslint-disable-next-line no-nested-ternary
|
|
18
|
-
val.includes('node_modules')
|
|
19
|
-
? `"${val.replace(/.+node_modules/, '')}"`
|
|
20
|
-
: val.includes('modern.js')
|
|
21
|
-
? `"${val.replace(/.+modern\.js/, '')}"`
|
|
22
|
-
: `"${val.replace(root, '')}"`
|
|
23
|
-
: (val as string),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('bff cli plugin', () => {
|
|
27
|
-
it('schema', async () => {
|
|
28
|
-
const main = manager.clone().usePlugin(plugin);
|
|
29
|
-
const runner = await main.init();
|
|
30
|
-
const result = await runner.validateSchema();
|
|
31
|
-
|
|
32
|
-
expect(result).toMatchSnapshot();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('config', async () => {
|
|
36
|
-
const main = manager.clone().usePlugin(plugin);
|
|
37
|
-
const runner = await main.init();
|
|
38
|
-
const result = await runner.config();
|
|
39
|
-
|
|
40
|
-
expect(result).toMatchSnapshot();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('config webpack chain', async () => {
|
|
44
|
-
const main = manager.clone().usePlugin(plugin);
|
|
45
|
-
const runner = await main.init();
|
|
46
|
-
const [{ tools }]: any = await runner.config();
|
|
47
|
-
const chain = new Chain();
|
|
48
|
-
manager.run(() => {
|
|
49
|
-
AppContext.set({
|
|
50
|
-
appDirectory: './fixtures/function',
|
|
51
|
-
port: 3000,
|
|
52
|
-
} as any);
|
|
53
|
-
});
|
|
54
|
-
manager.run(() => tools.webpack({}, { chain }));
|
|
55
|
-
|
|
56
|
-
expect(chain.toConfig()).toMatchObject({
|
|
57
|
-
module: {
|
|
58
|
-
rules: [
|
|
59
|
-
{
|
|
60
|
-
oneOf: [
|
|
61
|
-
{
|
|
62
|
-
test: /.\/fixtures\/function\/api\/\.*(\.[tj]s)$/,
|
|
63
|
-
use: [
|
|
64
|
-
{
|
|
65
|
-
loader: require
|
|
66
|
-
.resolve('../src/loader.ts')
|
|
67
|
-
.replace(/\\/g, '/'),
|
|
68
|
-
options: {
|
|
69
|
-
apiDir: path.resolve('./fixtures/function/api'),
|
|
70
|
-
fetcher: undefined,
|
|
71
|
-
port: 3000,
|
|
72
|
-
prefix: '/api',
|
|
73
|
-
target: undefined,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
resolve: {
|
|
83
|
-
alias: {
|
|
84
|
-
'@api': path.resolve('./fixtures/function/api'),
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('server routes', async () => {
|
|
91
|
-
const main = manager.clone().usePlugin(plugin);
|
|
92
|
-
main.registerHook({ modifyServerRoutes });
|
|
93
|
-
const runner = await main.init();
|
|
94
|
-
const result = await runner.modifyServerRoutes({ routes: [] });
|
|
95
|
-
|
|
96
|
-
expect(result).toMatchSnapshot();
|
|
97
|
-
});
|
|
98
|
-
});
|
package/tests/compiler.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import webpack from 'webpack';
|
|
3
|
-
import { createFsFromVolume, Volume } from 'memfs';
|
|
4
|
-
import { APILoaderOptions } from '../src/loader';
|
|
5
|
-
|
|
6
|
-
// globby needs setImmediate
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
global.setImmediate = setTimeout;
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
11
|
-
// @ts-expect-error
|
|
12
|
-
global.clearImmediate = clearTimeout;
|
|
13
|
-
|
|
14
|
-
export const compiler = (fixture: string, options: APILoaderOptions) => {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
16
|
-
const compiler = webpack({
|
|
17
|
-
context: __dirname,
|
|
18
|
-
entry: fixture,
|
|
19
|
-
target: 'node',
|
|
20
|
-
output: {
|
|
21
|
-
path: path.resolve(__dirname),
|
|
22
|
-
filename: 'bundle.js',
|
|
23
|
-
},
|
|
24
|
-
module: {
|
|
25
|
-
rules: [
|
|
26
|
-
{
|
|
27
|
-
test: /\.ts$/,
|
|
28
|
-
use: {
|
|
29
|
-
loader: path.resolve(__dirname, '../src/loader.ts'),
|
|
30
|
-
options,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
resolve: { extensions: ['.ts', '...'] },
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
compiler.outputFileSystem = createFsFromVolume(new Volume());
|
|
39
|
-
compiler.outputFileSystem.join = path.join.bind(path);
|
|
40
|
-
|
|
41
|
-
return new Promise<webpack.Stats | undefined>((resolve, reject) => {
|
|
42
|
-
compiler.run((err, stats) => {
|
|
43
|
-
if (err) {
|
|
44
|
-
reject(err);
|
|
45
|
-
}
|
|
46
|
-
if (stats?.hasErrors()) {
|
|
47
|
-
reject(stats.toJson().errors);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
resolve(stats);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { match } from '@modern-js/runtime/server';
|
|
2
|
-
|
|
3
|
-
export const get = ({ query }: { query: Record<string, unknown> }) => ({
|
|
4
|
-
query,
|
|
5
|
-
});
|
|
6
|
-
export const patch = match(
|
|
7
|
-
{
|
|
8
|
-
request: {
|
|
9
|
-
data: {
|
|
10
|
-
id: Number,
|
|
11
|
-
name: String,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
response: { id: Number },
|
|
15
|
-
},
|
|
16
|
-
({ data: { id } }) => ({ id }),
|
|
17
|
-
);
|
package/tests/loader.test.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { compiler } from './compiler';
|
|
3
|
-
|
|
4
|
-
const apiDir = path.resolve(__dirname, './fixtures/function/api');
|
|
5
|
-
const filepath = path.resolve(__dirname, './fixtures/function/api/hello.ts');
|
|
6
|
-
|
|
7
|
-
// jest.setTimeout(100000);
|
|
8
|
-
|
|
9
|
-
const root = path.resolve(__dirname, '../../../../');
|
|
10
|
-
expect.addSnapshotSerializer({
|
|
11
|
-
test: val =>
|
|
12
|
-
typeof val === 'string' &&
|
|
13
|
-
(val.includes('modern.js') ||
|
|
14
|
-
val.includes('node_modules') ||
|
|
15
|
-
val.includes(root)),
|
|
16
|
-
print: val =>
|
|
17
|
-
// eslint-disable-next-line no-nested-ternary
|
|
18
|
-
typeof val === 'string'
|
|
19
|
-
? // eslint-disable-next-line no-nested-ternary
|
|
20
|
-
val.includes('node_modules')
|
|
21
|
-
? `"${val.replace(/'.+node_modules/, `'`)}"`
|
|
22
|
-
: val.includes('modern.js')
|
|
23
|
-
? `"${val.replace(/'.+modern\.js/, `'`)}"`
|
|
24
|
-
: `"${val.replace(root, '')}"`
|
|
25
|
-
: (val as string),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('bff loader', () => {
|
|
29
|
-
it('should work well', async () => {
|
|
30
|
-
const stats = await compiler(filepath, {
|
|
31
|
-
apiDir,
|
|
32
|
-
prefix: '',
|
|
33
|
-
port: 3000,
|
|
34
|
-
target: 'server',
|
|
35
|
-
});
|
|
36
|
-
const output = stats?.toJson({ source: true }).modules?.[0]?.source;
|
|
37
|
-
|
|
38
|
-
expect(output).toMatchSnapshot();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should work well with prefix', async () => {
|
|
42
|
-
const stats = await compiler(filepath, {
|
|
43
|
-
apiDir,
|
|
44
|
-
prefix: 'api',
|
|
45
|
-
port: 3000,
|
|
46
|
-
target: 'server',
|
|
47
|
-
});
|
|
48
|
-
const output = stats?.toJson({ source: true }).modules?.[0]?.source;
|
|
49
|
-
|
|
50
|
-
expect(output).toMatchSnapshot();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should work well with client', async () => {
|
|
54
|
-
const stats = await compiler(filepath, {
|
|
55
|
-
apiDir,
|
|
56
|
-
prefix: '',
|
|
57
|
-
port: 3000,
|
|
58
|
-
target: 'server',
|
|
59
|
-
});
|
|
60
|
-
const output = stats?.toJson({ source: true }).modules?.[0]?.source;
|
|
61
|
-
|
|
62
|
-
expect(output).toMatchSnapshot();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should work well with port', async () => {
|
|
66
|
-
const stats = await compiler(filepath, {
|
|
67
|
-
apiDir,
|
|
68
|
-
prefix: '',
|
|
69
|
-
port: 80,
|
|
70
|
-
target: 'server',
|
|
71
|
-
});
|
|
72
|
-
const output = stats?.toJson({ source: true }).modules?.[0]?.source;
|
|
73
|
-
|
|
74
|
-
expect(output).toMatchSnapshot();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// TODO: 暂时有问题,先屏蔽这个测试
|
|
78
|
-
xit('should work well with fetcher', async () => {
|
|
79
|
-
const stats = await compiler(filepath, {
|
|
80
|
-
apiDir,
|
|
81
|
-
prefix: '',
|
|
82
|
-
port: 80,
|
|
83
|
-
target: 'client',
|
|
84
|
-
fetcher: path
|
|
85
|
-
.resolve(__dirname, './fixtures/test-fetcher')
|
|
86
|
-
.replace(/\\/g, '/'),
|
|
87
|
-
});
|
|
88
|
-
const output = stats?.toJson({ source: true }).modules?.[0]?.source;
|
|
89
|
-
|
|
90
|
-
expect(output).toMatchSnapshot();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should work well with requestCreator', async () => {
|
|
94
|
-
const stats = await compiler(filepath, {
|
|
95
|
-
apiDir,
|
|
96
|
-
prefix: '',
|
|
97
|
-
port: 80,
|
|
98
|
-
target: 'client',
|
|
99
|
-
requestCreator: path
|
|
100
|
-
.resolve(__dirname, './fixtures/requestCreator')
|
|
101
|
-
.replace(/\\/g, '/'),
|
|
102
|
-
});
|
|
103
|
-
const output = stats?.toJson({ source: true }).modules?.[0]?.source;
|
|
104
|
-
|
|
105
|
-
expect(output).toMatchSnapshot();
|
|
106
|
-
});
|
|
107
|
-
});
|
package/tests/server.test.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { serverManager } from '@modern-js/server-core';
|
|
3
|
-
import { useAPIHandlerInfos } from '@modern-js/bff-utils';
|
|
4
|
-
import plugin from '../src/server';
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
7
|
-
export const noop = () => {};
|
|
8
|
-
|
|
9
|
-
const pwd = path.resolve(__dirname, './fixtures/function');
|
|
10
|
-
|
|
11
|
-
describe('bff server plugin', () => {
|
|
12
|
-
describe('prepareApiServer', () => {
|
|
13
|
-
it('should work well', async () => {
|
|
14
|
-
const main = serverManager.clone().usePlugin(plugin);
|
|
15
|
-
const runner = await main.init();
|
|
16
|
-
|
|
17
|
-
await runner.prepareApiServer(
|
|
18
|
-
{ pwd, mode: 'function' },
|
|
19
|
-
{ onLast: () => noop },
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
const apiHandlerInfos = main.run(useAPIHandlerInfos);
|
|
23
|
-
expect(apiHandlerInfos).toMatchSnapshot();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should work well with prefix', async () => {
|
|
27
|
-
const main = serverManager.clone().usePlugin(plugin);
|
|
28
|
-
const runner = await main.init();
|
|
29
|
-
|
|
30
|
-
await runner.prepareApiServer(
|
|
31
|
-
{ pwd, mode: 'function', prefix: '/api' },
|
|
32
|
-
{ onLast: () => noop },
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const apiHandlerInfos = main.run(useAPIHandlerInfos);
|
|
36
|
-
expect(apiHandlerInfos).toMatchSnapshot();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
package/tests/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@modern-js/tsconfig/base",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"jsx": "preserve",
|
|
6
|
-
"baseUrl": ".",
|
|
7
|
-
"noEmit": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"isolatedModules": true,
|
|
11
|
-
"paths": {},
|
|
12
|
-
"types": ["node", "jest"]
|
|
13
|
-
}
|
|
14
|
-
}
|