@modern-js/plugin-bff 1.4.0 → 1.4.3

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-bff
2
2
 
3
+ ## 1.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 0ee4bb4e: fix: remove loader-utils from dependencies
8
+ - Updated dependencies [4697d1db]
9
+ - Updated dependencies [0ee4bb4e]
10
+ - Updated dependencies [6fa74d5f]
11
+ - @modern-js/create-request@1.2.6
12
+ - @modern-js/utils@1.7.0
13
+ - @modern-js/server-utils@1.2.4
14
+
15
+ ## 1.4.2
16
+
17
+ ### Patch Changes
18
+
19
+ - 895fa0ff: chore: using "workspace:\*" in devDependencies
20
+ - Updated dependencies [2d155c4c]
21
+ - Updated dependencies [123e432d]
22
+ - Updated dependencies [e5a9b26d]
23
+ - Updated dependencies [0b26b93b]
24
+ - Updated dependencies [123e432d]
25
+ - Updated dependencies [f9f66ef9]
26
+ - Updated dependencies [592edabc]
27
+ - Updated dependencies [895fa0ff]
28
+ - Updated dependencies [3578913e]
29
+ - Updated dependencies [0fccff68]
30
+ - Updated dependencies [1c3beab3]
31
+ - @modern-js/utils@1.6.0
32
+ - @modern-js/bff-utils@1.2.4
33
+ - @modern-js/server-utils@1.2.4
34
+ - @modern-js/create-request@1.2.5
35
+
36
+ ## 1.4.1
37
+
38
+ ### Patch Changes
39
+
40
+ - 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
41
+ - 60f7d8bf: feat: add tests dir to npmignore
42
+ - e4cec1ce: types: fix config hook type
43
+ - Updated dependencies [b8599d09]
44
+ - Updated dependencies [6cffe99d]
45
+ - Updated dependencies [04ae5262]
46
+ - Updated dependencies [60f7d8bf]
47
+ - Updated dependencies [3bf4f8b0]
48
+ - @modern-js/utils@1.5.0
49
+ - @modern-js/bff-utils@1.2.3
50
+ - @modern-js/server-utils@1.2.3
51
+ - @modern-js/babel-compiler@1.2.3
52
+ - @modern-js/create-request@1.2.4
53
+
3
54
  ## 1.4.0
4
55
 
5
56
  ### Minor Changes
@@ -1,4 +1,3 @@
1
- import { getOptions } from 'loader-utils';
2
1
  import { generateClient } from '@modern-js/bff-utils';
3
2
 
4
3
  async function loader(source) {
@@ -7,7 +6,7 @@ async function loader(source) {
7
6
 
8
7
  const callback = this.async(); // eslint-disable-next-line @babel/no-invalid-this
9
8
 
10
- const draftOptions = getOptions(this);
9
+ const draftOptions = this.getOptions();
11
10
  const options = {
12
11
  prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
13
12
  apiDir: draftOptions.apiDir,
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _loaderUtils = require("loader-utils");
9
-
10
8
  var _bffUtils = require("@modern-js/bff-utils");
11
9
 
12
10
  async function loader(source) {
@@ -15,7 +13,7 @@ async function loader(source) {
15
13
 
16
14
  const callback = this.async(); // eslint-disable-next-line @babel/no-invalid-this
17
15
 
18
- const draftOptions = (0, _loaderUtils.getOptions)(this);
16
+ const draftOptions = this.getOptions();
19
17
  const options = {
20
18
  prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
21
19
  apiDir: draftOptions.apiDir,
@@ -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.4.0",
14
+ "version": "1.4.3",
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.4.0",
63
- "loader-utils": "^2.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.6",
61
+ "@modern-js/server-utils": "^1.2.4",
62
+ "@modern-js/utils": "^1.7.0"
64
63
  },
65
64
  "devDependencies": {
66
- "@modern-js/core": "1.7.0",
67
- "@modern-js/plugin-analyze": "^1.3.6",
68
- "@modern-js/runtime": "^1.2.5",
69
- "@modern-js/server-core": "1.3.0",
70
- "@modern-js/types": "^1.4.0",
65
+ "@modern-js/core": "1.10.0",
66
+ "@modern-js/plugin-analyze": "1.4.1",
67
+ "@modern-js/runtime": "1.2.7",
68
+ "@modern-js/server-core": "1.3.3",
69
+ "@modern-js/types": "1.5.2",
71
70
  "@scripts/build": "0.0.0",
72
71
  "@scripts/jest-config": "0.0.0",
73
72
  "@types/babel__core": "^7.1.15",
74
73
  "@types/jest": "^26",
75
- "@types/loader-utils": "^2.0.3",
76
74
  "@types/node": "^14",
77
75
  "jest": "^27",
78
76
  "memfs": "^3.3.0",
@@ -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
- }