@modern-js/plugin-bff 1.3.9 → 1.4.2

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,62 @@
1
1
  # @modern-js/plugin-bff
2
2
 
3
+ ## 1.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 895fa0ff: chore: using "workspace:\*" in devDependencies
8
+ - Updated dependencies [2d155c4c]
9
+ - Updated dependencies [123e432d]
10
+ - Updated dependencies [e5a9b26d]
11
+ - Updated dependencies [0b26b93b]
12
+ - Updated dependencies [123e432d]
13
+ - Updated dependencies [f9f66ef9]
14
+ - Updated dependencies [592edabc]
15
+ - Updated dependencies [895fa0ff]
16
+ - Updated dependencies [3578913e]
17
+ - Updated dependencies [0fccff68]
18
+ - Updated dependencies [1c3beab3]
19
+ - @modern-js/utils@1.6.0
20
+ - @modern-js/bff-utils@1.2.4
21
+ - @modern-js/server-utils@1.2.4
22
+ - @modern-js/create-request@1.2.5
23
+
24
+ ## 1.4.1
25
+
26
+ ### Patch Changes
27
+
28
+ - 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
29
+ - 60f7d8bf: feat: add tests dir to npmignore
30
+ - e4cec1ce: types: fix config hook type
31
+ - Updated dependencies [b8599d09]
32
+ - Updated dependencies [6cffe99d]
33
+ - Updated dependencies [04ae5262]
34
+ - Updated dependencies [60f7d8bf]
35
+ - Updated dependencies [3bf4f8b0]
36
+ - @modern-js/utils@1.5.0
37
+ - @modern-js/bff-utils@1.2.3
38
+ - @modern-js/server-utils@1.2.3
39
+ - @modern-js/babel-compiler@1.2.3
40
+ - @modern-js/create-request@1.2.4
41
+
42
+ ## 1.4.0
43
+
44
+ ### Minor Changes
45
+
46
+ - d2d1d6b2: feat: support server config
47
+
48
+ ### Patch Changes
49
+
50
+ - d2d1d6b2: feat: add prepare hook
51
+ - Updated dependencies [77ff9754]
52
+ - Updated dependencies [d2d1d6b2]
53
+ - Updated dependencies [07a4887e]
54
+ - Updated dependencies [ea2ae711]
55
+ - Updated dependencies [17d0cc46]
56
+ - Updated dependencies [d2d1d6b2]
57
+ - @modern-js/utils@1.4.0
58
+ - @modern-js/server-utils@1.2.2
59
+
3
60
  ## 1.3.9
4
61
 
5
62
  ### Patch Changes
@@ -1,7 +1,6 @@
1
1
  import path from 'path';
2
- import fs from 'fs-extra';
3
2
  import { compiler } from '@modern-js/babel-compiler';
4
- import { PLUGIN_SCHEMAS, normalizeOutputPath, API_DIR } from '@modern-js/utils';
3
+ import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath } from '@modern-js/utils';
5
4
  import { resolveBabelConfig } from '@modern-js/server-utils';
6
5
  const DEFAULT_API_PREFIX = '/api';
7
6
  const TS_CONFIG_FILENAME = 'tsconfig.json';
@@ -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
- const apiMod = requireExistModule(apiAppPath);
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
- if (apiMod && typeof apiMod === 'function') {
39
- apiMod(transformAPI);
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);
@@ -7,8 +7,6 @@ exports.default = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
10
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
-
12
10
  var _babelCompiler = require("@modern-js/babel-compiler");
13
11
 
14
12
  var _utils = require("@modern-js/utils");
@@ -124,8 +122,8 @@ var _default = () => ({
124
122
  ignore: [`**/__tests__/**`, '**/typings/**', '*.d.ts', '*.test.ts']
125
123
  }, babelConfig);
126
124
 
127
- if (await _fsExtra.default.pathExists(rootDir)) {
128
- await _fsExtra.default.copy(rootDir, distDir, {
125
+ if (await _utils.fs.pathExists(rootDir)) {
126
+ await _utils.fs.copy(rootDir, distDir, {
129
127
  filter: src => !['.ts', '.js'].includes(_path.default.extname(src)) && src !== tsconfigPath
130
128
  });
131
129
  }
@@ -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
- const apiMod = (0, _utils.requireExistModule)(apiAppPath);
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
- if (apiMod && typeof apiMod === 'function') {
54
- apiMod(transformAPI);
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);
@@ -1,4 +1,4 @@
1
- import { LoaderContext } from 'webpack';
1
+ import type { LoaderContext } from 'webpack';
2
2
  export declare type APILoaderOptions = {
3
3
  prefix: string;
4
4
  apiDir: string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.3.9",
14
+ "version": "1.4.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -55,24 +55,22 @@
55
55
  "dependencies": {
56
56
  "@babel/core": "7.16.7",
57
57
  "@babel/runtime": "^7",
58
- "@modern-js/babel-compiler": "^1.2.2",
59
- "@modern-js/bff-utils": "^1.2.2",
60
- "@modern-js/create-request": "^1.2.2",
61
- "@modern-js/server-utils": "^1.2.2",
62
- "@modern-js/utils": "^1.3.7",
63
- "fs-extra": "^10.0.0",
58
+ "@modern-js/babel-compiler": "^1.2.3",
59
+ "@modern-js/bff-utils": "^1.2.4",
60
+ "@modern-js/create-request": "^1.2.5",
61
+ "@modern-js/server-utils": "^1.2.4",
62
+ "@modern-js/utils": "^1.6.0",
64
63
  "loader-utils": "^2.0.0"
65
64
  },
66
65
  "devDependencies": {
67
- "@modern-js/core": "1.6.1",
68
- "@modern-js/plugin-analyze": "^1.3.5",
69
- "@modern-js/runtime": "^1.2.5",
70
- "@modern-js/server-core": "1.2.5",
71
- "@modern-js/types": "^1.3.6",
66
+ "@modern-js/core": "1.9.0",
67
+ "@modern-js/plugin-analyze": "1.4.1",
68
+ "@modern-js/runtime": "1.2.7",
69
+ "@modern-js/server-core": "1.3.2",
70
+ "@modern-js/types": "1.5.1",
72
71
  "@scripts/build": "0.0.0",
73
72
  "@scripts/jest-config": "0.0.0",
74
73
  "@types/babel__core": "^7.1.15",
75
- "@types/fs-extra": "^9.0.13",
76
74
  "@types/jest": "^26",
77
75
  "@types/loader-utils": "^2.0.3",
78
76
  "@types/node": "^14",
package/types.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ declare module '@modern-js/core' {
2
+ interface UserConfig {
3
+ bff?: Partial<{
4
+ prefix: string;
5
+ requestCreator: string;
6
+ fetcher: string;
7
+ }>;
8
+ }
9
+ }
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
@@ -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,52 +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
- const compiler = webpack({
16
- context: __dirname,
17
- entry: fixture,
18
- target: 'node',
19
- output: {
20
- path: path.resolve(__dirname),
21
- filename: 'bundle.js',
22
- },
23
- module: {
24
- rules: [
25
- {
26
- test: /\.ts$/,
27
- use: {
28
- loader: path.resolve(__dirname, '../src/loader.ts'),
29
- options,
30
- },
31
- },
32
- ],
33
- },
34
- resolve: { extensions: ['.ts', '...'] },
35
- });
36
-
37
- compiler.outputFileSystem = createFsFromVolume(new Volume());
38
- compiler.outputFileSystem.join = path.join.bind(path);
39
-
40
- return new Promise<webpack.Stats | undefined>((resolve, reject) => {
41
- compiler.run((err, stats) => {
42
- if (err) {
43
- reject(err);
44
- }
45
- if (stats?.hasErrors()) {
46
- reject(stats.toJson().errors);
47
- }
48
-
49
- resolve(stats);
50
- });
51
- });
52
- };
@@ -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
- );
@@ -1,3 +0,0 @@
1
- export const get = ({ query }: { query: Record<string, unknown> }) => ({
2
- query,
3
- });
@@ -1,3 +0,0 @@
1
- export const get = ({ query }: { query: Record<string, unknown> }) => ({
2
- query,
3
- });
@@ -1,3 +0,0 @@
1
- console.info('');
2
-
3
- export {};
@@ -1,3 +0,0 @@
1
- console.info('');
2
-
3
- export {};
@@ -1,3 +0,0 @@
1
- console.info('');
2
-
3
- export {};
@@ -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
- });
@@ -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
- });
@@ -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
- }