@modern-js/plugin-testing 2.48.6 → 2.49.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.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var app_exports = {};
20
30
  __export(app_exports, {
@@ -25,36 +35,39 @@ __export(app_exports, {
25
35
  });
26
36
  module.exports = __toCommonJS(app_exports);
27
37
  var import_async_hooks = require("async_hooks");
38
+ var import_node_path = __toESM(require("node:path"));
28
39
  var import_prod_server = require("@modern-js/prod-server");
29
40
  const store = new import_async_hooks.AsyncLocalStorage();
30
41
  const isInHandler = () => Boolean(store.getStore());
31
- let server = null;
42
+ let server;
32
43
  const createApp = async (pwd, config, plugins, routes) => {
33
44
  if (!server) {
34
45
  config.output.path = "./";
35
- server = new import_prod_server.Server({
36
- apiOnly: true,
46
+ server = await (0, import_prod_server.createProdServer)({
37
47
  pwd,
38
48
  config,
39
49
  internalPlugins: plugins,
40
- routes
50
+ routes,
51
+ appContext: {
52
+ apiDirectory: import_node_path.default.join(pwd, "api"),
53
+ lambdaDirectory: import_node_path.default.join(pwd, "api", "lambda")
54
+ }
41
55
  });
42
- await server.init();
43
56
  }
44
- const app = server.getRequestHandler();
57
+ const app = server.getRequestListener();
45
58
  return app;
46
59
  };
47
60
  const getApp = () => {
48
61
  if (!server) {
49
62
  throw new Error("please createApp first");
50
63
  }
51
- return server.getRequestHandler();
64
+ return server.getRequestListener();
52
65
  };
53
66
  const closeServer = async () => {
54
67
  if (!server) {
55
68
  throw new Error("please createApp first");
56
69
  }
57
- await server.close();
70
+ server.close();
58
71
  };
59
72
  // Annotate the CommonJS export names for ESM import in node:
60
73
  0 && (module.exports = {
@@ -32,15 +32,14 @@ __export(bff_exports, {
32
32
  testingBffPlugin: () => testingBffPlugin
33
33
  });
34
34
  module.exports = __toCommonJS(bff_exports);
35
- var import_path = __toESM(require("path"));
36
35
  var import_utils = require("@modern-js/utils");
37
36
  var import_base = require("../../base");
38
37
  var import_constant = require("./constant");
39
38
  var import_utils2 = require("./utils");
40
- const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils }) => {
39
+ const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils, appContext }) => {
41
40
  var _userConfig_source;
42
41
  const bffConfig = {
43
- rootDir: import_path.default.join(pwd, "./api"),
42
+ rootDir: appContext.apiDirectory,
44
43
  setupFilesAfterEnv: [
45
44
  require.resolve("./setup")
46
45
  ],
@@ -56,7 +55,8 @@ const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils })
56
55
  appDir: pwd,
57
56
  modernUserConfig: userConfig,
58
57
  plugins,
59
- routes
58
+ routes,
59
+ appContext
60
60
  }
61
61
  }
62
62
  };
@@ -140,7 +140,8 @@ const testingBffPlugin = () => ({
140
140
  routes: appContext.serverRoutes,
141
141
  // Todo need use collect server internalPlugins
142
142
  plugins: appContext.serverInternalPlugins,
143
- utils
143
+ utils,
144
+ appContext
144
145
  });
145
146
  return next(utils);
146
147
  }
@@ -1,12 +1,13 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { AsyncLocalStorage } from "async_hooks";
4
- import { Server } from "@modern-js/prod-server";
4
+ import path from "node:path";
5
+ import { createProdServer } from "@modern-js/prod-server";
5
6
  var store = new AsyncLocalStorage();
6
7
  var isInHandler = function() {
7
8
  return Boolean(store.getStore());
8
9
  };
9
- var server = null;
10
+ var server;
10
11
  var createApp = function() {
11
12
  var _ref = _async_to_generator(function(pwd, config, plugins, routes) {
12
13
  var app;
@@ -19,22 +20,24 @@ var createApp = function() {
19
20
  2
20
21
  ];
21
22
  config.output.path = "./";
22
- server = new Server({
23
- apiOnly: true,
24
- pwd,
25
- config,
26
- internalPlugins: plugins,
27
- routes
28
- });
29
23
  return [
30
24
  4,
31
- server.init()
25
+ createProdServer({
26
+ pwd,
27
+ config,
28
+ internalPlugins: plugins,
29
+ routes,
30
+ appContext: {
31
+ apiDirectory: path.join(pwd, "api"),
32
+ lambdaDirectory: path.join(pwd, "api", "lambda")
33
+ }
34
+ })
32
35
  ];
33
36
  case 1:
34
- _state.sent();
37
+ server = _state.sent();
35
38
  _state.label = 2;
36
39
  case 2:
37
- app = server.getRequestHandler();
40
+ app = server.getRequestListener();
38
41
  return [
39
42
  2,
40
43
  app
@@ -50,26 +53,18 @@ var getApp = function() {
50
53
  if (!server) {
51
54
  throw new Error("please createApp first");
52
55
  }
53
- return server.getRequestHandler();
56
+ return server.getRequestListener();
54
57
  };
55
58
  var closeServer = function() {
56
59
  var _ref = _async_to_generator(function() {
57
60
  return _ts_generator(this, function(_state) {
58
- switch (_state.label) {
59
- case 0:
60
- if (!server) {
61
- throw new Error("please createApp first");
62
- }
63
- return [
64
- 4,
65
- server.close()
66
- ];
67
- case 1:
68
- _state.sent();
69
- return [
70
- 2
71
- ];
61
+ if (!server) {
62
+ throw new Error("please createApp first");
72
63
  }
64
+ server.close();
65
+ return [
66
+ 2
67
+ ];
73
68
  });
74
69
  });
75
70
  return function closeServer2() {
@@ -2,20 +2,19 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
3
3
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
- import path from "path";
6
5
  import { isApiOnly } from "@modern-js/utils";
7
6
  import { getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../../base";
8
7
  import { bff_info_key } from "./constant";
9
8
  import { isBFFProject } from "./utils";
10
9
  var setJestConfigForBFF = function() {
11
10
  var _ref = _async_to_generator(function(param) {
12
- var pwd, userConfig, plugins, routes, utils, _userConfig_source, bffConfig, jestConfig, alias, aliasMapper, moduleNameMapper, transform, apiOnly, mergedModuleNameMapper, resolver, configFields, commonConfig;
11
+ var pwd, userConfig, plugins, routes, utils, appContext, _userConfig_source, bffConfig, jestConfig, alias, aliasMapper, moduleNameMapper, transform, apiOnly, mergedModuleNameMapper, resolver, configFields, commonConfig;
13
12
  return _ts_generator(this, function(_state) {
14
13
  switch (_state.label) {
15
14
  case 0:
16
- pwd = param.pwd, userConfig = param.userConfig, plugins = param.plugins, routes = param.routes, utils = param.utils;
15
+ pwd = param.pwd, userConfig = param.userConfig, plugins = param.plugins, routes = param.routes, utils = param.utils, appContext = param.appContext;
17
16
  bffConfig = {
18
- rootDir: path.join(pwd, "./api"),
17
+ rootDir: appContext.apiDirectory,
19
18
  setupFilesAfterEnv: [
20
19
  require.resolve("./setup")
21
20
  ],
@@ -30,7 +29,8 @@ var setJestConfigForBFF = function() {
30
29
  appDir: pwd,
31
30
  modernUserConfig: userConfig,
32
31
  plugins,
33
- routes
32
+ routes,
33
+ appContext
34
34
  })
35
35
  };
36
36
  jestConfig = utils.jestConfig;
@@ -131,7 +131,8 @@ var testingBffPlugin = function() {
131
131
  routes: appContext.serverRoutes,
132
132
  // Todo need use collect server internalPlugins
133
133
  plugins: appContext.serverInternalPlugins,
134
- utils
134
+ utils,
135
+ appContext
135
136
  })
136
137
  ];
137
138
  case 1:
@@ -1,34 +1,37 @@
1
1
  import { AsyncLocalStorage } from "async_hooks";
2
- import { Server } from "@modern-js/prod-server";
2
+ import path from "node:path";
3
+ import { createProdServer } from "@modern-js/prod-server";
3
4
  const store = new AsyncLocalStorage();
4
5
  const isInHandler = () => Boolean(store.getStore());
5
- let server = null;
6
+ let server;
6
7
  const createApp = async (pwd, config, plugins, routes) => {
7
8
  if (!server) {
8
9
  config.output.path = "./";
9
- server = new Server({
10
- apiOnly: true,
10
+ server = await createProdServer({
11
11
  pwd,
12
12
  config,
13
13
  internalPlugins: plugins,
14
- routes
14
+ routes,
15
+ appContext: {
16
+ apiDirectory: path.join(pwd, "api"),
17
+ lambdaDirectory: path.join(pwd, "api", "lambda")
18
+ }
15
19
  });
16
- await server.init();
17
20
  }
18
- const app = server.getRequestHandler();
21
+ const app = server.getRequestListener();
19
22
  return app;
20
23
  };
21
24
  const getApp = () => {
22
25
  if (!server) {
23
26
  throw new Error("please createApp first");
24
27
  }
25
- return server.getRequestHandler();
28
+ return server.getRequestListener();
26
29
  };
27
30
  const closeServer = async () => {
28
31
  if (!server) {
29
32
  throw new Error("please createApp first");
30
33
  }
31
- await server.close();
34
+ server.close();
32
35
  };
33
36
  export {
34
37
  closeServer,
@@ -1,12 +1,11 @@
1
- import path from "path";
2
1
  import { isApiOnly } from "@modern-js/utils";
3
2
  import { getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../../base";
4
3
  import { bff_info_key } from "./constant";
5
4
  import { isBFFProject } from "./utils";
6
- const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils }) => {
5
+ const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils, appContext }) => {
7
6
  var _userConfig_source;
8
7
  const bffConfig = {
9
- rootDir: path.join(pwd, "./api"),
8
+ rootDir: appContext.apiDirectory,
10
9
  setupFilesAfterEnv: [
11
10
  require.resolve("./setup")
12
11
  ],
@@ -22,7 +21,8 @@ const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils })
22
21
  appDir: pwd,
23
22
  modernUserConfig: userConfig,
24
23
  plugins,
25
- routes
24
+ routes,
25
+ appContext
26
26
  }
27
27
  }
28
28
  };
@@ -106,7 +106,8 @@ const testingBffPlugin = () => ({
106
106
  routes: appContext.serverRoutes,
107
107
  // Todo need use collect server internalPlugins
108
108
  plugins: appContext.serverInternalPlugins,
109
- utils
109
+ utils,
110
+ appContext
110
111
  });
111
112
  return next(utils);
112
113
  }
@@ -1,9 +1,7 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node/http" />
3
- /// <reference types="@modern-js/prod-server/src/type" />
4
2
  import { InternalPlugins } from '@modern-js/types';
5
3
  export declare const isInHandler: () => boolean;
6
- declare const createApp: (pwd: string, config: any, plugins: InternalPlugins, routes: any[]) => Promise<(req: import("http").IncomingMessage, res: import("http").ServerResponse, next?: (() => void) | undefined) => void>;
7
- declare const getApp: () => (req: import("http").IncomingMessage, res: import("http").ServerResponse, next?: (() => void) | undefined) => void;
4
+ declare const createApp: (pwd: string, config: any, plugins: InternalPlugins, routes: any[]) => Promise<(req: import("http").IncomingMessage, res: import("http").ServerResponse) => Promise<void>>;
5
+ declare const getApp: () => (req: import("http").IncomingMessage, res: import("http").ServerResponse) => Promise<void>;
8
6
  declare const closeServer: () => Promise<void>;
9
7
  export { createApp, getApp, closeServer };
@@ -1,14 +1,15 @@
1
- import type { CliPlugin } from '@modern-js/core';
1
+ import type { CliPlugin, IAppContext } from '@modern-js/core';
2
2
  import { InternalPlugins } from '@modern-js/types';
3
3
  import { UserConfig } from '../../base/config';
4
4
  import { TestConfigOperator } from '../../base';
5
5
  import type { Hooks } from '../../base/hook';
6
- export declare const setJestConfigForBFF: ({ pwd, userConfig, plugins, routes, utils, }: {
6
+ export declare const setJestConfigForBFF: ({ pwd, userConfig, plugins, routes, utils, appContext, }: {
7
7
  pwd: string;
8
8
  userConfig: any;
9
9
  plugins: InternalPlugins;
10
10
  routes: any[];
11
11
  utils: TestConfigOperator;
12
+ appContext: IAppContext;
12
13
  }) => Promise<void>;
13
14
  export declare const testingBffPlugin: () => CliPlugin<{
14
15
  hooks: Hooks;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.48.6",
18
+ "version": "2.49.0",
19
19
  "jsnext:source": "./src/cli/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "main": "./dist/cjs/cli/index.js",
@@ -116,7 +116,7 @@
116
116
  "@modern-js-reduck/plugin-effects": "^1.1.10",
117
117
  "@modern-js-reduck/plugin-immutable": "^1.1.10",
118
118
  "@modern-js-reduck/store": "^1.1.10",
119
- "@rsbuild/babel-preset": "0.6.1",
119
+ "@rsbuild/babel-preset": "0.6.3",
120
120
  "@testing-library/jest-dom": "^5.16.1",
121
121
  "@testing-library/react": "^13.4.0",
122
122
  "@types/testing-library__jest-dom": "^5.14.3",
@@ -131,17 +131,17 @@
131
131
  "ts-jest": "^29.1.0",
132
132
  "yargs": "^17.0.1",
133
133
  "@swc/helpers": "0.5.3",
134
- "@modern-js/babel-compiler": "2.48.6",
135
- "@modern-js/utils": "2.48.6",
136
- "@modern-js/plugin": "2.48.6",
137
- "@modern-js/types": "2.48.6",
138
- "@modern-js/bff-core": "2.48.6",
139
- "@modern-js/prod-server": "2.48.6"
134
+ "@modern-js/babel-compiler": "2.49.0",
135
+ "@modern-js/plugin": "2.49.0",
136
+ "@modern-js/types": "2.49.0",
137
+ "@modern-js/utils": "2.49.0",
138
+ "@modern-js/prod-server": "2.49.0",
139
+ "@modern-js/bff-core": "2.49.0"
140
140
  },
141
141
  "peerDependencies": {
142
142
  "react": ">=17",
143
143
  "react-dom": ">=17",
144
- "@modern-js/runtime": "^2.48.6"
144
+ "@modern-js/runtime": "^2.49.0"
145
145
  },
146
146
  "peerDependenciesMeta": {
147
147
  "@modern-js/runtime": {
@@ -156,10 +156,10 @@
156
156
  "@types/node": "^14",
157
157
  "@types/yargs": "^17.0.2",
158
158
  "typescript": "^5",
159
- "@modern-js/core": "2.48.6",
160
- "@modern-js/runtime": "2.48.6",
161
- "@scripts/build": "2.48.6",
162
- "@scripts/jest-config": "2.48.6"
159
+ "@modern-js/core": "2.49.0",
160
+ "@modern-js/runtime": "2.49.0",
161
+ "@scripts/build": "2.49.0",
162
+ "@scripts/jest-config": "2.49.0"
163
163
  },
164
164
  "sideEffects": false,
165
165
  "publishConfig": {