@modern-js/plugin-bff 0.0.0-canary-202111382413 → 0.0.0-runtime-2021112193858

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.
File without changes
@@ -1 +1 @@
1
- export * from '/github/workspace/packages/cli/plugin-runtime'
1
+ export * from '/Users/admin/github/modern.js/packages/cli/plugin-runtime'
package/CHANGELOG.md CHANGED
@@ -1,15 +1,46 @@
1
1
  # @modern-js/plugin-bff
2
2
 
3
- ## 0.0.0-canary-202111382413
3
+ ## 0.0.0-runtime-2021112193858
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - fda2d7f0: support server runtime
8
- - Updated dependencies [fda2d7f0]
9
- - @modern-js/core@0.0.0-canary-202111382413
10
- - @modern-js/server-plugin@0.0.0-canary-202111382413
11
- - @modern-js/server-utils@0.0.0-canary-202111382413
12
- - @modern-js/utils@0.0.0-canary-202111382413
7
+ - 8698465e: fix: dependence version
8
+ - Updated dependencies [8698465e]
9
+ - Updated dependencies [e04914ce]
10
+ - Updated dependencies [e04914ce]
11
+ - @modern-js/babel-preset-lib@0.0.0-runtime-2021112193858
12
+ - @modern-js/core@0.0.0-runtime-2021112193858
13
+ - @modern-js/bff-utils@0.0.0-runtime-2021112193858
14
+ - @modern-js/create-request@0.0.0-runtime-2021112193858
15
+ - @modern-js/server-plugin@0.0.0-runtime-2021112193858
16
+ - @modern-js/server-utils@0.0.0-runtime-2021112193858
17
+ - @modern-js/babel-chain@0.0.0-runtime-2021112193858
18
+ - @modern-js/babel-compiler@0.0.0-runtime-2021112193858
19
+ - @modern-js/utils@0.0.0-runtime-2021112193858
20
+
21
+ ## 1.1.2
22
+
23
+ ### Patch Changes
24
+
25
+ - 085a6a58: refactor server plugin
26
+ - 39e8137d: fix: support prefix array & webpack loader should read requestCreator & adjust runtime path to relative
27
+ - 085a6a58: refactor server plugin
28
+ - 085a6a58: refactor server conifg
29
+ - 085a6a58: support server runtime
30
+ - 085a6a58: feat: refactor server plugin
31
+ - Updated dependencies [085a6a58]
32
+ - Updated dependencies [085a6a58]
33
+ - Updated dependencies [085a6a58]
34
+ - Updated dependencies [d280ea33]
35
+ - Updated dependencies [d4fcc73a]
36
+ - Updated dependencies [085a6a58]
37
+ - Updated dependencies [ed1f6b12]
38
+ - Updated dependencies [a5ebbb00]
39
+ - Updated dependencies [085a6a58]
40
+ - @modern-js/core@1.1.3
41
+ - @modern-js/server-plugin@1.1.2
42
+ - @modern-js/server-utils@1.1.2
43
+ - @modern-js/utils@1.1.3
13
44
 
14
45
  ## 1.1.1
15
46
 
@@ -2,9 +2,8 @@ import path from 'path';
2
2
  import fs from 'fs-extra';
3
3
  import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
4
4
  import { compiler } from '@modern-js/babel-compiler';
5
- import { PLUGIN_SCHEMAS, normalizeOutputPath } from '@modern-js/utils';
5
+ import { PLUGIN_SCHEMAS, normalizeOutputPath, API_DIR } from '@modern-js/utils';
6
6
  import { resolveBabelConfig } from '@modern-js/server-utils';
7
- import { API_DIR } from "./constants";
8
7
  const DEFAULT_API_PREFIX = '/api';
9
8
  const TS_CONFIG_FILENAME = 'tsconfig.json';
10
9
  const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
@@ -41,7 +40,8 @@ export default createPlugin(() => ({
41
40
  apiDir: rootDir,
42
41
  port,
43
42
  fetcher,
44
- target: _config.name
43
+ target: _config.name,
44
+ requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator
45
45
  });
46
46
  }
47
47
  },
@@ -1,3 +1,2 @@
1
- export const API_DIR = 'api';
2
1
  export const API_APP_NAME = '_app';
3
2
  export const BUILD_FILES = ['**/*.[tj]sx?', '!**/*.test.jsx?', '!**/*.test.tsx?', '!**/*.spec.jsx?', '!**/*.spec.tsx?', '!__tests__/*.tsx?', '!__tests__/*.jsx?'];
@@ -9,7 +9,7 @@ async function loader(source) {
9
9
 
10
10
  const draftOptions = getOptions(this);
11
11
  const options = {
12
- prefix: draftOptions.prefix,
12
+ prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
13
13
  apiDir: draftOptions.apiDir,
14
14
  target: draftOptions.target,
15
15
  port: Number(draftOptions.port),
@@ -2,8 +2,8 @@ import path from 'path';
2
2
  import { createPlugin } from '@modern-js/server-plugin';
3
3
  import { injectAPIHandlerInfos } from '@modern-js/bff-utils';
4
4
  import { useAppContext } from '@modern-js/core';
5
- import { API_DIR, API_APP_NAME } from "./constants";
6
- import { requireModule } from "./requireModule";
5
+ import { API_DIR, isProd, requireExistModule } from '@modern-js/utils';
6
+ import { API_APP_NAME } from "./constants";
7
7
 
8
8
  class Storage {
9
9
  constructor() {
@@ -25,13 +25,15 @@ const createTransformAPI = storage => ({
25
25
 
26
26
  export default createPlugin(() => {
27
27
  const {
28
- appDirectory
28
+ appDirectory,
29
+ distDirectory
29
30
  } = useAppContext();
30
- const apiPath = path.resolve(appDirectory, API_DIR);
31
+ const root = isProd() ? distDirectory : appDirectory;
32
+ const apiPath = path.resolve(root || process.cwd(), API_DIR);
31
33
  const apiAppPath = path.resolve(apiPath, API_APP_NAME);
32
34
  const storage = new Storage();
33
35
  const transformAPI = createTransformAPI(storage);
34
- const apiMod = requireModule(apiAppPath);
36
+ const apiMod = requireExistModule(apiAppPath);
35
37
 
36
38
  if (apiMod) {
37
39
  apiMod(transformAPI);
@@ -40,7 +42,7 @@ export default createPlugin(() => {
40
42
  return {
41
43
  reset() {
42
44
  storage.reset();
43
- const newApiModule = requireModule(apiAppPath);
45
+ const newApiModule = requireExistModule(apiAppPath);
44
46
 
45
47
  if (newApiModule) {
46
48
  newApiModule(transformAPI);
@@ -17,8 +17,6 @@ var _utils = require("@modern-js/utils");
17
17
 
18
18
  var _serverUtils = require("@modern-js/server-utils");
19
19
 
20
- var _constants = require("./constants");
21
-
22
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
21
 
24
22
  const DEFAULT_API_PREFIX = '/api';
@@ -51,7 +49,7 @@ var _default = (0, _core.createPlugin)(() => ({
51
49
  } = bff || {};
52
50
  const prefix = (bff === null || bff === void 0 ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
53
51
 
54
- const rootDir = _path.default.resolve(appDirectory, _constants.API_DIR);
52
+ const rootDir = _path.default.resolve(appDirectory, _utils.API_DIR);
55
53
 
56
54
  chain.resolve.alias.set('@api', rootDir);
57
55
  const apiRegexp = new RegExp((0, _utils.normalizeOutputPath)(`${appDirectory}${_path.default.sep}api${_path.default.sep}.*(.[tj]s)$`));
@@ -60,12 +58,13 @@ var _default = (0, _core.createPlugin)(() => ({
60
58
  apiDir: rootDir,
61
59
  port,
62
60
  fetcher,
63
- target: _config.name
61
+ target: _config.name,
62
+ requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator
64
63
  });
65
64
  }
66
65
  },
67
66
  source: {
68
- moduleScopes: [`./${_constants.API_DIR}`]
67
+ moduleScopes: [`./${_utils.API_DIR}`]
69
68
  }
70
69
  };
71
70
  },
@@ -109,11 +108,11 @@ var _default = (0, _core.createPlugin)(() => ({
109
108
 
110
109
  const modernConfig = (0, _core.useResolvedConfigContext)();
111
110
 
112
- const rootDir = _path.default.resolve(appDirectory, _constants.API_DIR);
111
+ const rootDir = _path.default.resolve(appDirectory, _utils.API_DIR);
113
112
 
114
- const distDir = _path.default.resolve(distDirectory, _constants.API_DIR);
113
+ const distDir = _path.default.resolve(distDirectory, _utils.API_DIR);
115
114
 
116
- const sourceAbsDir = _path.default.resolve(appDirectory, _constants.API_DIR);
115
+ const sourceAbsDir = _path.default.resolve(appDirectory, _utils.API_DIR);
117
116
 
118
117
  const tsconfigPath = _path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
119
118
 
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.BUILD_FILES = exports.API_DIR = exports.API_APP_NAME = void 0;
7
- const API_DIR = 'api';
8
- exports.API_DIR = API_DIR;
6
+ exports.BUILD_FILES = exports.API_APP_NAME = void 0;
9
7
  const API_APP_NAME = '_app';
10
8
  exports.API_APP_NAME = API_APP_NAME;
11
9
  const BUILD_FILES = ['**/*.[tj]sx?', '!**/*.test.jsx?', '!**/*.test.tsx?', '!**/*.spec.jsx?', '!**/*.spec.tsx?', '!__tests__/*.tsx?', '!__tests__/*.jsx?'];
@@ -17,7 +17,7 @@ async function loader(source) {
17
17
 
18
18
  const draftOptions = (0, _loaderUtils.getOptions)(this);
19
19
  const options = {
20
- prefix: draftOptions.prefix,
20
+ prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
21
21
  apiDir: draftOptions.apiDir,
22
22
  target: draftOptions.target,
23
23
  port: Number(draftOptions.port),
@@ -13,9 +13,9 @@ var _bffUtils = require("@modern-js/bff-utils");
13
13
 
14
14
  var _core = require("@modern-js/core");
15
15
 
16
- var _constants = require("./constants");
16
+ var _utils = require("@modern-js/utils");
17
17
 
18
- var _requireModule = require("./requireModule");
18
+ var _constants = require("./constants");
19
19
 
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
 
@@ -39,16 +39,18 @@ const createTransformAPI = storage => ({
39
39
 
40
40
  var _default = (0, _serverPlugin.createPlugin)(() => {
41
41
  const {
42
- appDirectory
42
+ appDirectory,
43
+ distDirectory
43
44
  } = (0, _core.useAppContext)();
45
+ const root = (0, _utils.isProd)() ? distDirectory : appDirectory;
44
46
 
45
- const apiPath = _path.default.resolve(appDirectory, _constants.API_DIR);
47
+ const apiPath = _path.default.resolve(root || process.cwd(), _utils.API_DIR);
46
48
 
47
49
  const apiAppPath = _path.default.resolve(apiPath, _constants.API_APP_NAME);
48
50
 
49
51
  const storage = new Storage();
50
52
  const transformAPI = createTransformAPI(storage);
51
- const apiMod = (0, _requireModule.requireModule)(apiAppPath);
53
+ const apiMod = (0, _utils.requireExistModule)(apiAppPath);
52
54
 
53
55
  if (apiMod) {
54
56
  apiMod(transformAPI);
@@ -57,7 +59,7 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
57
59
  return {
58
60
  reset() {
59
61
  storage.reset();
60
- const newApiModule = (0, _requireModule.requireModule)(apiAppPath);
62
+ const newApiModule = (0, _utils.requireExistModule)(apiAppPath);
61
63
 
62
64
  if (newApiModule) {
63
65
  newApiModule(transformAPI);
@@ -78,7 +80,7 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
78
80
  prefix
79
81
  } = props;
80
82
 
81
- const apiDir = _path.default.resolve(pwd, _constants.API_DIR);
83
+ const apiDir = _path.default.resolve(pwd, _utils.API_DIR);
82
84
 
83
85
  (0, _bffUtils.injectAPIHandlerInfos)(apiDir, prefix);
84
86
  return next(props);
@@ -2,7 +2,7 @@ declare module '@modern-js/core' {
2
2
  interface UserConfig {
3
3
  bff: {
4
4
  prefix?: string;
5
- requestCreater?: string;
5
+ requestCreator?: string;
6
6
  fetcher?: string;
7
7
  proxy: Record<string, any>;
8
8
  };
@@ -1,3 +1,2 @@
1
- export declare const API_DIR = "api";
2
1
  export declare const API_APP_NAME = "_app";
3
2
  export declare const BUILD_FILES: string[];
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "0.0.0-canary-202111382413",
14
+ "version": "0.0.0-runtime-2021112193858",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -44,24 +44,24 @@
44
44
  "dependencies": {
45
45
  "@babel/core": "^7.15.5",
46
46
  "@babel/runtime": "^7",
47
- "@modern-js/babel-chain": "^1.1.1",
48
- "@modern-js/babel-compiler": "^1.1.2",
49
- "@modern-js/babel-preset-lib": "^1.1.1",
50
- "@modern-js/create-request": "^1.1.1",
51
- "@modern-js/server-utils": "^0.0.0-canary-202111382413",
52
- "@modern-js/utils": "^0.0.0-canary-202111382413",
47
+ "@modern-js/babel-chain": "^0.0.0-runtime-2021112193858",
48
+ "@modern-js/babel-compiler": "^0.0.0-runtime-2021112193858",
49
+ "@modern-js/babel-preset-lib": "^0.0.0-runtime-2021112193858",
50
+ "@modern-js/create-request": "^0.0.0-runtime-2021112193858",
51
+ "@modern-js/server-utils": "^0.0.0-runtime-2021112193858",
52
+ "@modern-js/utils": "^0.0.0-runtime-2021112193858",
53
53
  "fs-extra": "^10.0.0",
54
54
  "loader-utils": "^2.0.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@modern-js/bff-utils": "^1.1.1",
58
- "@modern-js/core": "^0.0.0-canary-202111382413",
59
- "@modern-js/module-tools": "^1.1.1",
60
- "@modern-js/plugin-analyze": "^1.1.1",
61
- "@modern-js/plugin-testing": "^1.1.1",
62
- "@modern-js/runtime": "^1.1.1",
63
- "@modern-js/server-plugin": "^0.0.0-canary-202111382413",
64
- "@modern-js/types": "^1.1.2",
57
+ "@modern-js/bff-utils": "^0.0.0-runtime-2021112193858",
58
+ "@modern-js/core": "^0.0.0-runtime-2021112193858",
59
+ "@modern-js/module-tools": "^0.0.0-runtime-2021112193858",
60
+ "@modern-js/plugin-analyze": "^0.0.0-runtime-2021112193858",
61
+ "@modern-js/plugin-testing": "^0.0.0-runtime-2021112193858",
62
+ "@modern-js/runtime": "^0.0.0-runtime-2021112193858",
63
+ "@modern-js/server-plugin": "^0.0.0-runtime-2021112193858",
64
+ "@modern-js/types": "^0.0.0-runtime-2021112193858",
65
65
  "@types/babel__core": "^7.1.15",
66
66
  "@types/fs-extra": "^9.0.13",
67
67
  "@types/jest": "^26",
@@ -69,14 +69,14 @@
69
69
  "@types/node": "^14",
70
70
  "memfs": "^3.3.0",
71
71
  "ts-jest": "^27.0.5",
72
- "typescript": "^4",
72
+ "typescript": "^4.4.4",
73
73
  "webpack": "^5.54.0",
74
74
  "webpack-chain": "^6.5.1"
75
75
  },
76
76
  "peerDependencies": {
77
- "@modern-js/bff-utils": "^1.1.1",
78
- "@modern-js/core": "^0.0.0-canary-202111382413",
79
- "@modern-js/server-plugin": "^0.0.0-canary-202111382413"
77
+ "@modern-js/bff-utils": "^0.0.0-runtime-2021112193858",
78
+ "@modern-js/core": "^0.0.0-runtime-2021112193858",
79
+ "@modern-js/server-plugin": "^0.0.0-runtime-2021112193858"
80
80
  },
81
81
  "modernConfig": {
82
82
  "output": {
package/src/cli.ts CHANGED
@@ -6,19 +6,18 @@ import {
6
6
  useResolvedConfigContext,
7
7
  } from '@modern-js/core';
8
8
  import { compiler } from '@modern-js/babel-compiler';
9
- import { PLUGIN_SCHEMAS, normalizeOutputPath } from '@modern-js/utils';
9
+ import { PLUGIN_SCHEMAS, normalizeOutputPath, API_DIR } from '@modern-js/utils';
10
10
  import { resolveBabelConfig } from '@modern-js/server-utils';
11
11
 
12
12
  import type { Configuration } from 'webpack';
13
13
  import type Chain from 'webpack-chain';
14
14
  import type { ServerRoute } from '@modern-js/types';
15
- import { API_DIR } from './constants';
16
15
 
17
16
  declare module '@modern-js/core' {
18
17
  interface UserConfig {
19
18
  bff: {
20
19
  prefix?: string;
21
- requestCreater?: string;
20
+ requestCreator?: string;
22
21
  fetcher?: string;
23
22
  proxy: Record<string, any>;
24
23
  };
@@ -69,6 +68,7 @@ export default createPlugin(
69
68
  port,
70
69
  fetcher,
71
70
  target: _config.name,
71
+ requestCreator: bff?.requestCreator,
72
72
  });
73
73
  },
74
74
  },
package/src/constants.ts CHANGED
@@ -1,5 +1,3 @@
1
- export const API_DIR = 'api';
2
-
3
1
  export const API_APP_NAME = '_app';
4
2
 
5
3
  export const BUILD_FILES = [
package/src/loader.ts CHANGED
@@ -20,7 +20,9 @@ async function loader(this: LoaderContext<APILoaderOptions>, source: string) {
20
20
  const draftOptions = getOptions(this as any);
21
21
 
22
22
  const options: GenClientOptions = {
23
- prefix: draftOptions.prefix as string,
23
+ prefix: (Array.isArray(draftOptions.prefix)
24
+ ? draftOptions.prefix[0]
25
+ : draftOptions.prefix) as string,
24
26
  apiDir: draftOptions.apiDir as string,
25
27
  target: draftOptions.target as string,
26
28
  port: Number(draftOptions.port),
package/src/server.ts CHANGED
@@ -2,8 +2,8 @@ import path from 'path';
2
2
  import { createPlugin } from '@modern-js/server-plugin';
3
3
  import { injectAPIHandlerInfos } from '@modern-js/bff-utils';
4
4
  import { useAppContext } from '@modern-js/core';
5
- import { API_DIR, API_APP_NAME } from './constants';
6
- import { requireModule } from './requireModule';
5
+ import { API_DIR, isProd, requireExistModule } from '@modern-js/utils';
6
+ import { API_APP_NAME } from './constants';
7
7
 
8
8
  type SF = (args: any) => void;
9
9
  class Storage {
@@ -22,15 +22,17 @@ const createTransformAPI = (storage: Storage) => ({
22
22
 
23
23
  export default createPlugin(
24
24
  () => {
25
- const { appDirectory } = useAppContext();
25
+ const { appDirectory, distDirectory } = useAppContext();
26
26
 
27
- const apiPath = path.resolve(appDirectory, API_DIR);
27
+ const root = isProd() ? distDirectory : appDirectory;
28
+
29
+ const apiPath = path.resolve(root || process.cwd(), API_DIR);
28
30
  const apiAppPath = path.resolve(apiPath, API_APP_NAME);
29
31
 
30
32
  const storage = new Storage();
31
33
  const transformAPI = createTransformAPI(storage);
32
34
 
33
- const apiMod = requireModule(apiAppPath);
35
+ const apiMod = requireExistModule(apiAppPath);
34
36
  if (apiMod) {
35
37
  apiMod(transformAPI);
36
38
  }
@@ -38,7 +40,7 @@ export default createPlugin(
38
40
  return {
39
41
  reset() {
40
42
  storage.reset();
41
- const newApiModule = requireModule(apiAppPath);
43
+ const newApiModule = requireExistModule(apiAppPath);
42
44
  if (newApiModule) {
43
45
  newApiModule(transformAPI);
44
46
  }
@@ -25,12 +25,18 @@ Array [
25
25
  "type": "string",
26
26
  },
27
27
  "prefix": Object {
28
- "type": "string",
28
+ "items": Object {
29
+ "type": "string",
30
+ },
31
+ "type": Array [
32
+ "string",
33
+ "array",
34
+ ],
29
35
  },
30
36
  "proxy": Object {
31
37
  "type": "object",
32
38
  },
33
- "requestCreater": Object {
39
+ "requestCreator": Object {
34
40
  "type": "string",
35
41
  },
36
42
  },
@@ -1,14 +0,0 @@
1
- import { findExists, compatRequire } from '@modern-js/utils';
2
- const FILE_EXTENSIONS = ['.ts', '.js'];
3
- export const requireModule = filename => {
4
- const exist = findExists(FILE_EXTENSIONS.map(ext => `${filename}${ext}`));
5
-
6
- if (!exist) {
7
- return null;
8
- } // throw errors directly if require fail
9
-
10
-
11
- const mod = require(exist);
12
-
13
- return compatRequire(mod);
14
- };
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.requireModule = void 0;
7
-
8
- var _utils = require("@modern-js/utils");
9
-
10
- const FILE_EXTENSIONS = ['.ts', '.js'];
11
-
12
- const requireModule = filename => {
13
- const exist = (0, _utils.findExists)(FILE_EXTENSIONS.map(ext => `${filename}${ext}`));
14
-
15
- if (!exist) {
16
- return null;
17
- } // throw errors directly if require fail
18
-
19
-
20
- const mod = require(exist);
21
-
22
- return (0, _utils.compatRequire)(mod);
23
- };
24
-
25
- exports.requireModule = requireModule;
@@ -1 +0,0 @@
1
- export declare const requireModule: (filename: string) => any;
@@ -1,15 +0,0 @@
1
- import { findExists, compatRequire } from '@modern-js/utils';
2
-
3
- const FILE_EXTENSIONS = ['.ts', '.js'];
4
-
5
- export const requireModule = (filename: string) => {
6
- const exist = findExists(FILE_EXTENSIONS.map(ext => `${filename}${ext}`));
7
-
8
- if (!exist) {
9
- return null;
10
- }
11
-
12
- // throw errors directly if require fail
13
- const mod = require(exist);
14
- return compatRequire(mod);
15
- };