@modern-js/plugin-bff 1.2.2-beta.1 → 1.3.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,82 @@
1
1
  # @modern-js/plugin-bff
2
2
 
3
+ ## 1.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 272cab15: refactor server plugin manager
8
+ - Updated dependencies [d9cc5ea9]
9
+ - Updated dependencies [bd819a8d]
10
+ - Updated dependencies [ec4dbffb]
11
+ - Updated dependencies [d099e5c5]
12
+ - Updated dependencies [bada2879]
13
+ - Updated dependencies [24f616ca]
14
+ - Updated dependencies [bd819a8d]
15
+ - Updated dependencies [272cab15]
16
+ - @modern-js/core@1.4.0
17
+ - @modern-js/utils@1.3.0
18
+ - @modern-js/server-core@1.2.2
19
+
20
+ ## 1.3.2
21
+
22
+ ### Patch Changes
23
+
24
+ - 83166714: change .npmignore
25
+ - Updated dependencies [83166714]
26
+ - Updated dependencies [c3de9882]
27
+ - Updated dependencies [33ff48af]
28
+ - @modern-js/babel-preset-lib@1.2.1
29
+ - @modern-js/core@1.3.2
30
+ - @modern-js/bff-utils@1.2.2
31
+ - @modern-js/create-request@1.2.1
32
+ - @modern-js/server-plugin@1.2.1
33
+ - @modern-js/server-utils@1.2.1
34
+ - @modern-js/babel-chain@1.2.1
35
+ - @modern-js/babel-compiler@1.2.1
36
+ - @modern-js/utils@1.2.2
37
+
38
+ ## 1.3.1
39
+
40
+ ### Patch Changes
41
+
42
+ - e2d3a575: fix extending core config interface
43
+ - Updated dependencies [823809c6]
44
+ - Updated dependencies [4584cc04]
45
+ - Updated dependencies [7c19fd94]
46
+ - @modern-js/bff-utils@1.2.1
47
+ - @modern-js/utils@1.2.1
48
+ - @modern-js/core@1.3.1
49
+
50
+ ## 1.3.0
51
+
52
+ ### Minor Changes
53
+
54
+ - cfe11628: Make Modern.js self bootstraping
55
+
56
+ ### Patch Changes
57
+
58
+ - 8e7603ee: fix custom requestCreator path
59
+ - 1ebc7ee2: fix: @babel/core version
60
+ - Updated dependencies [2da09c69]
61
+ - Updated dependencies [5597289b]
62
+ - Updated dependencies [fc71e36f]
63
+ - Updated dependencies [146dcd85]
64
+ - Updated dependencies [c3d46ee4]
65
+ - Updated dependencies [cfe11628]
66
+ - Updated dependencies [146dcd85]
67
+ - Updated dependencies [8e7603ee]
68
+ - Updated dependencies [146dcd85]
69
+ - Updated dependencies [1ebc7ee2]
70
+ - @modern-js/utils@1.2.0
71
+ - @modern-js/create-request@1.2.0
72
+ - @modern-js/core@1.3.0
73
+ - @modern-js/server-utils@1.2.0
74
+ - @modern-js/babel-preset-lib@1.2.0
75
+ - @modern-js/bff-utils@1.2.0
76
+ - @modern-js/server-plugin@1.2.0
77
+ - @modern-js/babel-chain@1.2.0
78
+ - @modern-js/babel-compiler@1.2.0
79
+
3
80
  ## 1.2.1
4
81
 
5
82
  ### Patch Changes
@@ -1,7 +1,6 @@
1
1
  import path from 'path';
2
- import { createPlugin } from '@modern-js/server-plugin';
2
+ import { createPlugin, useAppContext } from '@modern-js/server-core';
3
3
  import { injectAPIHandlerInfos } from '@modern-js/bff-utils';
4
- import { useAppContext } from '@modern-js/core';
5
4
  import { API_DIR, isProd, requireExistModule } from '@modern-js/utils';
6
5
  import { API_APP_NAME } from "./constants";
7
6
 
@@ -7,12 +7,10 @@ exports.default = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
10
- var _serverPlugin = require("@modern-js/server-plugin");
10
+ var _serverCore = require("@modern-js/server-core");
11
11
 
12
12
  var _bffUtils = require("@modern-js/bff-utils");
13
13
 
14
- var _core = require("@modern-js/core");
15
-
16
14
  var _utils = require("@modern-js/utils");
17
15
 
18
16
  var _constants = require("./constants");
@@ -37,11 +35,11 @@ const createTransformAPI = storage => ({
37
35
 
38
36
  });
39
37
 
40
- var _default = (0, _serverPlugin.createPlugin)(() => {
38
+ var _default = (0, _serverCore.createPlugin)(() => {
41
39
  const {
42
40
  appDirectory,
43
41
  distDirectory
44
- } = (0, _core.useAppContext)();
42
+ } = (0, _serverCore.useAppContext)();
45
43
  const root = (0, _utils.isProd)() ? distDirectory : appDirectory;
46
44
 
47
45
  const apiPath = _path.default.resolve(root || process.cwd(), _utils.API_DIR);
@@ -1,6 +1,6 @@
1
1
  declare module '@modern-js/core' {
2
2
  interface UserConfig {
3
- bff: {
3
+ bff?: {
4
4
  prefix?: string;
5
5
  requestCreator?: string;
6
6
  fetcher?: string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.2-beta.1",
14
+ "version": "1.3.3",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -49,25 +49,25 @@
49
49
  }
50
50
  },
51
51
  "dependencies": {
52
- "@babel/core": "^7.15.5",
52
+ "@babel/core": "7.16.7",
53
53
  "@babel/runtime": "^7",
54
- "@modern-js/babel-chain": "^1.1.2",
55
- "@modern-js/babel-compiler": "^1.1.4",
56
- "@modern-js/babel-preset-lib": "^1.1.6",
57
- "@modern-js/create-request": "^1.1.2",
58
- "@modern-js/server-utils": "^1.1.2",
59
- "@modern-js/utils": "^1.1.6",
54
+ "@modern-js/babel-chain": "^1.2.1",
55
+ "@modern-js/babel-compiler": "^1.2.1",
56
+ "@modern-js/babel-preset-lib": "^1.2.1",
57
+ "@modern-js/create-request": "^1.2.1",
58
+ "@modern-js/server-utils": "^1.2.1",
59
+ "@modern-js/utils": "^1.3.0",
60
60
  "fs-extra": "^10.0.0",
61
61
  "loader-utils": "^2.0.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@modern-js/bff-utils": "^1.1.1",
65
- "@modern-js/core": "^1.2.0",
64
+ "@modern-js/bff-utils": "^1.2.2",
65
+ "@modern-js/core": "^1.4.0",
66
66
  "@scripts/build": "0.0.0",
67
- "@modern-js/plugin-analyze": "^1.1.3",
68
- "@modern-js/runtime": "^1.1.3",
69
- "@modern-js/server-plugin": "^1.1.4",
70
- "@modern-js/types": "^1.1.5",
67
+ "@modern-js/plugin-analyze": "^1.3.0",
68
+ "@modern-js/runtime": "^1.2.2",
69
+ "@modern-js/server-core": "^1.2.2",
70
+ "@modern-js/types": "^1.3.0",
71
71
  "@types/babel__core": "^7.1.15",
72
72
  "@types/fs-extra": "^9.0.13",
73
73
  "@types/jest": "^26",
@@ -82,9 +82,9 @@
82
82
  "@scripts/jest-config": "0.0.0"
83
83
  },
84
84
  "peerDependencies": {
85
- "@modern-js/bff-utils": "^1.1.1",
86
- "@modern-js/core": "^1.2.0",
87
- "@modern-js/server-plugin": "^1.1.4"
85
+ "@modern-js/bff-utils": "^1.2.2",
86
+ "@modern-js/core": "^1.4.0",
87
+ "@modern-js/server-core": "^1.2.2"
88
88
  },
89
89
  "modernConfig": {
90
90
  "output": {
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { serverManager } from '@modern-js/server-plugin';
2
+ import { serverManager } from '@modern-js/server-core';
3
3
  import { useAPIHandlerInfos } from '@modern-js/bff-utils';
4
4
  import plugin from '../src/server';
5
5
 
package/src/cli.ts DELETED
@@ -1,146 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs-extra';
3
- import {
4
- createPlugin,
5
- useAppContext,
6
- useResolvedConfigContext,
7
- } from '@modern-js/core';
8
- import { compiler } from '@modern-js/babel-compiler';
9
- import { PLUGIN_SCHEMAS, normalizeOutputPath, API_DIR } from '@modern-js/utils';
10
- import { resolveBabelConfig } from '@modern-js/server-utils';
11
-
12
- import type { Configuration } from 'webpack';
13
- import type Chain from 'webpack-chain';
14
- import type { ServerRoute } from '@modern-js/types';
15
-
16
- declare module '@modern-js/core' {
17
- interface UserConfig {
18
- bff: {
19
- prefix?: string;
20
- requestCreator?: string;
21
- fetcher?: string;
22
- proxy: Record<string, any>;
23
- };
24
- }
25
- }
26
-
27
- const DEFAULT_API_PREFIX = '/api';
28
- const TS_CONFIG_FILENAME = 'tsconfig.json';
29
- const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
30
-
31
- export default createPlugin(
32
- () => ({
33
- validateSchema() {
34
- return PLUGIN_SCHEMAS['@modern-js/plugin-bff'];
35
- },
36
- config() {
37
- return {
38
- tools: {
39
- webpack: (_config: Configuration, { chain }: { chain: Chain }) => {
40
- // eslint-disable-next-line react-hooks/rules-of-hooks
41
- const { appDirectory, port } = useAppContext();
42
- // eslint-disable-next-line react-hooks/rules-of-hooks
43
- const modernConfig = useResolvedConfigContext();
44
-
45
- const { bff } = modernConfig || {};
46
- const { fetcher } = bff || {};
47
- const prefix = bff?.prefix || DEFAULT_API_PREFIX;
48
-
49
- const rootDir = path.resolve(appDirectory, API_DIR);
50
-
51
- chain.resolve.alias.set('@api', rootDir);
52
-
53
- const apiRegexp = new RegExp(
54
- normalizeOutputPath(
55
- `${appDirectory}${path.sep}api${path.sep}.*(.[tj]s)$`,
56
- ),
57
- );
58
- chain.module
59
- .rule('loaders')
60
- .oneOf('bff-client')
61
- .before('fallback')
62
- .test(apiRegexp)
63
- .use('custom-loader')
64
- .loader(require.resolve('./loader').replace(/\\/g, '/'))
65
- .options({
66
- prefix,
67
- apiDir: rootDir,
68
- port,
69
- fetcher,
70
- target: _config.name,
71
- requestCreator: bff?.requestCreator,
72
- });
73
- },
74
- },
75
- source: {
76
- moduleScopes: [`./${API_DIR}`, /create-request/],
77
- },
78
- };
79
- },
80
- modifyServerRoutes({ routes }: any) {
81
- // eslint-disable-next-line react-hooks/rules-of-hooks
82
- const modernConfig = useResolvedConfigContext();
83
-
84
- const { bff } = modernConfig || {};
85
- const prefix = bff?.prefix || '/api';
86
-
87
- const prefixList: string[] = [];
88
-
89
- if (Array.isArray(prefix)) {
90
- prefixList.push(...prefix);
91
- } else {
92
- prefixList.push(prefix);
93
- }
94
- const apiServerRoutes = prefixList.map(pre => ({
95
- urlPath: pre,
96
- isApi: true,
97
- entryPath: '',
98
- isSPA: false,
99
- isSSR: false,
100
- // FIXME: })) as IAppContext[`serverRoutes`];
101
- })) as ServerRoute[];
102
-
103
- return { routes: routes.concat(apiServerRoutes) };
104
- },
105
- async afterBuild() {
106
- // eslint-disable-next-line react-hooks/rules-of-hooks
107
- const { appDirectory, distDirectory } = useAppContext();
108
- // eslint-disable-next-line react-hooks/rules-of-hooks
109
- const modernConfig = useResolvedConfigContext();
110
-
111
- const rootDir = path.resolve(appDirectory, API_DIR);
112
- const distDir = path.resolve(distDirectory, API_DIR);
113
-
114
- const sourceAbsDir = path.resolve(appDirectory, API_DIR);
115
- const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
116
- const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
117
- tsconfigPath,
118
- syntax: 'es6+',
119
- type: 'commonjs',
120
- });
121
-
122
- const result = await compiler(
123
- {
124
- rootDir,
125
- distDir,
126
- sourceDir: sourceAbsDir,
127
- extensions: FILE_EXTENSIONS,
128
- ignore: [`**/__tests__/**`, '**/typings/**', '*.d.ts'],
129
- },
130
- babelConfig,
131
- );
132
-
133
- if (await fs.pathExists(rootDir)) {
134
- await fs.copy(rootDir, distDir, {
135
- filter: src =>
136
- !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath,
137
- });
138
- }
139
-
140
- if (result.code === 1) {
141
- throw new Error(result.message);
142
- }
143
- },
144
- }),
145
- { name: '@modern-js/plugin-bff' },
146
- ) as any;
package/src/constants.ts DELETED
@@ -1,11 +0,0 @@
1
- export const API_APP_NAME = '_app';
2
-
3
- export const BUILD_FILES = [
4
- '**/*.[tj]sx?',
5
- '!**/*.test.jsx?',
6
- '!**/*.test.tsx?',
7
- '!**/*.spec.jsx?',
8
- '!**/*.spec.tsx?',
9
- '!__tests__/*.tsx?',
10
- '!__tests__/*.jsx?',
11
- ];
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './constants';
package/src/loader.ts DELETED
@@ -1,53 +0,0 @@
1
- import { getOptions } from 'loader-utils';
2
- import { generateClient, GenClientOptions } from '@modern-js/bff-utils';
3
- import { LoaderContext } from 'webpack';
4
-
5
- export type APILoaderOptions = {
6
- prefix: string;
7
- apiDir: string;
8
- port: number;
9
- fetcher?: string;
10
- requestCreator?: string;
11
- target: string;
12
- };
13
-
14
- async function loader(this: LoaderContext<APILoaderOptions>, source: string) {
15
- // eslint-disable-next-line @babel/no-invalid-this
16
- this.cacheable();
17
- // eslint-disable-next-line @babel/no-invalid-this
18
- const callback = this.async();
19
- // eslint-disable-next-line @babel/no-invalid-this
20
- const draftOptions = getOptions(this as any);
21
-
22
- const options: GenClientOptions = {
23
- prefix: (Array.isArray(draftOptions.prefix)
24
- ? draftOptions.prefix[0]
25
- : draftOptions.prefix) as string,
26
- apiDir: draftOptions.apiDir as string,
27
- target: draftOptions.target as string,
28
- port: Number(draftOptions.port),
29
- source,
30
- // eslint-disable-next-line @babel/no-invalid-this
31
- resourcePath: this.resourcePath,
32
- };
33
-
34
- if (draftOptions.fetcher) {
35
- options.fetcher = draftOptions.fetcher as string;
36
- }
37
-
38
- if (draftOptions.requestCreator) {
39
- options.requestCreator = draftOptions.requestCreator as string;
40
- }
41
-
42
- options.requireResolve = require.resolve;
43
-
44
- const result = await generateClient(options);
45
-
46
- if (result.isOk) {
47
- callback(undefined, result.value);
48
- } else {
49
- callback(undefined, `throw new Error('${result.value}')`);
50
- }
51
- }
52
-
53
- export default loader;
package/src/server.ts DELETED
@@ -1,64 +0,0 @@
1
- import path from 'path';
2
- import { createPlugin } from '@modern-js/server-plugin';
3
- import { injectAPIHandlerInfos } from '@modern-js/bff-utils';
4
- import { useAppContext } from '@modern-js/core';
5
- import { API_DIR, isProd, requireExistModule } from '@modern-js/utils';
6
- import { API_APP_NAME } from './constants';
7
-
8
- type SF = (args: any) => void;
9
- class Storage {
10
- public middlewares: SF[] = [];
11
-
12
- reset() {
13
- this.middlewares = [];
14
- }
15
- }
16
-
17
- const createTransformAPI = (storage: Storage) => ({
18
- addMiddleware(fn: SF) {
19
- storage.middlewares.push(fn);
20
- },
21
- });
22
-
23
- export default createPlugin(
24
- () => {
25
- const { appDirectory, distDirectory } = useAppContext();
26
-
27
- const root = isProd() ? distDirectory : appDirectory;
28
-
29
- const apiPath = path.resolve(root || process.cwd(), API_DIR);
30
- const apiAppPath = path.resolve(apiPath, API_APP_NAME);
31
-
32
- const storage = new Storage();
33
- const transformAPI = createTransformAPI(storage);
34
-
35
- const apiMod = requireExistModule(apiAppPath);
36
- if (apiMod && typeof apiMod === 'function') {
37
- apiMod(transformAPI);
38
- }
39
-
40
- return {
41
- reset() {
42
- storage.reset();
43
- const newApiModule = requireExistModule(apiAppPath);
44
- if (newApiModule && typeof newApiModule === 'function') {
45
- newApiModule(transformAPI);
46
- }
47
- },
48
- gather({ addAPIMiddleware }) {
49
- storage.middlewares.forEach(mid => {
50
- addAPIMiddleware(mid);
51
- });
52
- },
53
- prepareApiServer(props, next) {
54
- const { pwd, prefix } = props;
55
- const apiDir = path.resolve(pwd, API_DIR);
56
-
57
- injectAPIHandlerInfos(apiDir, prefix);
58
-
59
- return next(props);
60
- },
61
- };
62
- },
63
- { name: '@modern-js/plugin-bff' },
64
- ) as any;