@modern-js/plugin-bff 1.3.9 → 1.4.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,23 @@
1
1
  # @modern-js/plugin-bff
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d2d1d6b2: feat: support server config
8
+
9
+ ### Patch Changes
10
+
11
+ - d2d1d6b2: feat: add prepare hook
12
+ - Updated dependencies [77ff9754]
13
+ - Updated dependencies [d2d1d6b2]
14
+ - Updated dependencies [07a4887e]
15
+ - Updated dependencies [ea2ae711]
16
+ - Updated dependencies [17d0cc46]
17
+ - Updated dependencies [d2d1d6b2]
18
+ - @modern-js/utils@1.4.0
19
+ - @modern-js/server-utils@1.2.2
20
+
3
21
  ## 1.3.9
4
22
 
5
23
  ### 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);
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.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -59,20 +59,18 @@
59
59
  "@modern-js/bff-utils": "^1.2.2",
60
60
  "@modern-js/create-request": "^1.2.2",
61
61
  "@modern-js/server-utils": "^1.2.2",
62
- "@modern-js/utils": "^1.3.7",
63
- "fs-extra": "^10.0.0",
62
+ "@modern-js/utils": "^1.4.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",
66
+ "@modern-js/core": "1.7.0",
67
+ "@modern-js/plugin-analyze": "^1.3.6",
69
68
  "@modern-js/runtime": "^1.2.5",
70
- "@modern-js/server-core": "1.2.5",
71
- "@modern-js/types": "^1.3.6",
69
+ "@modern-js/server-core": "1.3.0",
70
+ "@modern-js/types": "^1.4.0",
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
+ }