@modern-js/plugin-testing 2.0.0-beta.2 → 2.0.0-beta.4

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.
Files changed (106) hide show
  1. package/CHANGELOG.md +145 -0
  2. package/dist/js/modern/base/config/index.js +29 -9
  3. package/dist/js/modern/base/config/patches/assetsModule.js +7 -7
  4. package/dist/js/modern/base/config/patches/filemock.js +4 -1
  5. package/dist/js/modern/base/config/patches/index.js +30 -7
  6. package/dist/js/modern/base/config/patches/transformer.js +13 -18
  7. package/dist/js/modern/base/config/resolver.js +11 -6
  8. package/dist/js/modern/base/config/testConfigOperator.js +29 -23
  9. package/dist/js/modern/base/config/transformer/babelTransformer.js +16 -8
  10. package/dist/js/modern/base/hook.js +10 -5
  11. package/dist/js/modern/base/index.js +14 -6
  12. package/dist/js/modern/base/runJest.js +73 -62
  13. package/dist/js/modern/base/utils.js +40 -23
  14. package/dist/js/modern/cli/bff/app.js +37 -12
  15. package/dist/js/modern/cli/bff/constant.js +4 -1
  16. package/dist/js/modern/cli/bff/index.js +95 -52
  17. package/dist/js/modern/cli/bff/mockAPI.js +79 -64
  18. package/dist/js/modern/cli/bff/setup.js +71 -34
  19. package/dist/js/modern/cli/bff/utils/index.js +31 -15
  20. package/dist/js/modern/cli/index.js +64 -30
  21. package/dist/js/modern/cli/test.js +53 -18
  22. package/dist/js/modern/constant.js +4 -1
  23. package/dist/js/modern/index.js +3 -3
  24. package/dist/js/modern/modern-app.env.d.js +0 -0
  25. package/dist/js/modern/runtime-testing/app.js +25 -14
  26. package/dist/js/modern/runtime-testing/base.js +7 -3
  27. package/dist/js/modern/runtime-testing/customRender.js +24 -10
  28. package/dist/js/modern/runtime-testing/index.js +1 -1
  29. package/dist/js/modern/runtime-testing/reduck.js +41 -19
  30. package/dist/js/modern/runtime-testing/request.js +4 -4
  31. package/dist/js/modern/runtime-testing/resolvePlugins.js +24 -8
  32. package/dist/js/node/base/config/index.js +56 -18
  33. package/dist/js/node/base/config/patches/assetsModule.js +30 -12
  34. package/dist/js/node/base/config/patches/filemock.js +22 -7
  35. package/dist/js/node/base/config/patches/index.js +50 -15
  36. package/dist/js/node/base/config/patches/transformer.js +38 -25
  37. package/dist/js/node/base/config/resolver.js +37 -10
  38. package/dist/js/node/base/config/testConfigOperator.js +49 -30
  39. package/dist/js/node/base/config/transformer/babelTransformer.js +40 -15
  40. package/dist/js/node/base/hook.js +28 -13
  41. package/dist/js/node/base/index.js +31 -63
  42. package/dist/js/node/base/runJest.js +99 -71
  43. package/dist/js/node/base/utils.js +66 -34
  44. package/dist/js/node/cli/bff/app.js +57 -22
  45. package/dist/js/node/cli/bff/constant.js +22 -7
  46. package/dist/js/node/cli/bff/index.js +121 -65
  47. package/dist/js/node/cli/bff/mockAPI.js +103 -71
  48. package/dist/js/node/cli/bff/setup.js +100 -38
  49. package/dist/js/node/cli/bff/utils/index.js +55 -22
  50. package/dist/js/node/cli/index.js +87 -46
  51. package/dist/js/node/cli/test.js +79 -27
  52. package/dist/js/node/constant.js +22 -7
  53. package/dist/js/node/index.js +19 -18
  54. package/dist/js/node/modern-app.env.d.js +0 -0
  55. package/dist/js/node/runtime-testing/app.js +53 -25
  56. package/dist/js/node/runtime-testing/base.js +30 -33
  57. package/dist/js/node/runtime-testing/customRender.js +49 -18
  58. package/dist/js/node/runtime-testing/index.js +18 -27
  59. package/dist/js/node/runtime-testing/reduck.js +67 -31
  60. package/dist/js/node/runtime-testing/request.js +32 -13
  61. package/dist/js/node/runtime-testing/resolvePlugins.js +41 -12
  62. package/dist/js/treeshaking/base/config/index.js +150 -31
  63. package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -11
  64. package/dist/js/treeshaking/base/config/patches/filemock.js +2 -1
  65. package/dist/js/treeshaking/base/config/patches/index.js +221 -64
  66. package/dist/js/treeshaking/base/config/patches/transformer.js +34 -37
  67. package/dist/js/treeshaking/base/config/resolver.js +24 -11
  68. package/dist/js/treeshaking/base/config/testConfigOperator.js +120 -69
  69. package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +16 -10
  70. package/dist/js/treeshaking/base/hook.js +8 -7
  71. package/dist/js/treeshaking/base/index.js +7 -6
  72. package/dist/js/treeshaking/base/runJest.js +281 -164
  73. package/dist/js/treeshaking/base/types/index.js +1 -0
  74. package/dist/js/treeshaking/base/utils.js +72 -48
  75. package/dist/js/treeshaking/cli/bff/app.js +192 -68
  76. package/dist/js/treeshaking/cli/bff/constant.js +2 -1
  77. package/dist/js/treeshaking/cli/bff/index.js +291 -130
  78. package/dist/js/treeshaking/cli/bff/mockAPI.js +181 -91
  79. package/dist/js/treeshaking/cli/bff/setup.js +185 -59
  80. package/dist/js/treeshaking/cli/bff/utils/index.js +47 -21
  81. package/dist/js/treeshaking/cli/index.js +248 -108
  82. package/dist/js/treeshaking/cli/test.js +177 -44
  83. package/dist/js/treeshaking/constant.js +2 -1
  84. package/dist/js/treeshaking/index.js +3 -3
  85. package/dist/js/treeshaking/modern-app.env.d.js +1 -0
  86. package/dist/js/treeshaking/runtime-testing/app.js +85 -39
  87. package/dist/js/treeshaking/runtime-testing/base.js +4 -3
  88. package/dist/js/treeshaking/runtime-testing/customRender.js +38 -10
  89. package/dist/js/treeshaking/runtime-testing/index.js +1 -1
  90. package/dist/js/treeshaking/runtime-testing/reduck.js +85 -33
  91. package/dist/js/treeshaking/runtime-testing/request.js +49 -19
  92. package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +45 -14
  93. package/dist/types/base/config/index.d.ts +1 -0
  94. package/dist/types/base/config/patches/assetsModule.d.ts +1 -0
  95. package/dist/types/base/config/patches/filemock.d.ts +1 -0
  96. package/dist/types/base/config/patches/transformer.d.ts +1 -0
  97. package/dist/types/base/config/resolver.d.ts +2 -1
  98. package/dist/types/base/config/testConfigOperator.d.ts +2 -0
  99. package/dist/types/base/runJest.d.ts +2 -0
  100. package/dist/types/base/utils.d.ts +1 -0
  101. package/dist/types/cli/bff/index.d.ts +2 -0
  102. package/dist/types/cli/bff/mockAPI.d.ts +1 -0
  103. package/dist/types/cli/index.d.ts +2 -0
  104. package/dist/types/runtime-testing/app.d.ts +3 -0
  105. package/dist/types/runtime-testing/customRender.d.ts +2 -0
  106. package/package.json +13 -13
@@ -1,32 +1,65 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var stdin_exports = {};
25
+ __export(stdin_exports, {
26
+ runJest: () => runJest,
27
+ runTest: () => runTest
5
28
  });
6
- exports.runJest = runJest;
7
- exports.runTest = runTest;
8
- var _yargs = _interopRequireDefault(require("yargs/yargs"));
9
- var _jest = require("jest");
10
- var _utils = require("@modern-js/utils");
11
- var _config = require("./config");
12
- var _utils2 = require("./utils");
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- /**
15
- * @file run jest by nodejs API
16
- * @description
17
- * Jest does not provide node API to run jest.
18
- * The followed code is inspired by
19
- * https://github.com/facebook/jest/blob/fdc74af37235354e077edeeee8aa2d1a4a863032/packages/jest-cli/src/cli/index.ts#L21
20
- */
21
-
22
- const buildArgv = async (rawArgv, config) => {
23
- const argv = await (0, _yargs.default)(rawArgv).argv;
29
+ module.exports = __toCommonJS(stdin_exports);
30
+ var import_yargs = __toESM(require("yargs/yargs"));
31
+ var import_jest = require("jest");
32
+ var import_utils = require("@modern-js/utils");
33
+ var import_config = require("./config");
34
+ var import_utils2 = require("./utils");
35
+ var __async = (__this, __arguments, generator) => {
36
+ return new Promise((resolve, reject) => {
37
+ var fulfilled = (value) => {
38
+ try {
39
+ step(generator.next(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var rejected = (value) => {
45
+ try {
46
+ step(generator.throw(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
52
+ step((generator = generator.apply(__this, __arguments)).next());
53
+ });
54
+ };
55
+ const buildArgv = (rawArgv, config) => __async(void 0, null, function* () {
56
+ const argv = yield (0, import_yargs.default)(rawArgv).argv;
24
57
  const result = {
25
58
  $0: argv.$0,
26
59
  _: argv._.slice(1)
27
60
  };
28
- Object.keys(argv).forEach(key => {
29
- if (key.includes('-') || key === '_') {
61
+ Object.keys(argv).forEach((key) => {
62
+ if (key.includes("-") || key === "_") {
30
63
  return;
31
64
  }
32
65
  result[key] = argv[key];
@@ -35,65 +68,60 @@ const buildArgv = async (rawArgv, config) => {
35
68
  result.config = JSON.stringify(config);
36
69
  }
37
70
  return result;
38
- };
71
+ });
39
72
  const readResultsAndExit = (result, globalConfig) => {
40
73
  const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
41
-
42
- // Only exit if needed
43
- process.on('exit', () => {
44
- if (typeof code === 'number' && code !== 0) {
74
+ process.on("exit", () => {
75
+ if (typeof code === "number" && code !== 0) {
45
76
  process.exitCode = code;
46
77
  }
47
78
  });
48
79
  if (globalConfig.forceExit) {
49
80
  if (!globalConfig.detectOpenHandles) {
50
- console.warn(`${_utils.chalk.bold('Force exiting Jest: ')}Have you considered using \`--detectOpenHandles\` to detect ` + `async operations that kept running after all tests finished?`);
81
+ console.warn(
82
+ `${import_utils.chalk.bold(
83
+ "Force exiting Jest: "
84
+ )}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`
85
+ );
51
86
  }
52
-
53
- // eslint-disable-next-line no-process-exit
54
87
  process.exit(code);
55
88
  } else if (!globalConfig.detectOpenHandles) {
56
89
  setTimeout(() => {
57
- console.warn(_utils.chalk.yellow.bold('Jest did not exit one second after the test run has completed.\n\n') + _utils.chalk.yellow('This usually means that there are asynchronous operations that ' + "weren't stopped in your tests. Consider running Jest with " + '`--detectOpenHandles` to troubleshoot this issue.'));
58
- }, 1000).unref();
90
+ console.warn(
91
+ import_utils.chalk.yellow.bold(
92
+ "Jest did not exit one second after the test run has completed.\n\n"
93
+ ) + import_utils.chalk.yellow(
94
+ "This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."
95
+ )
96
+ );
97
+ }, 1e3).unref();
59
98
  }
60
99
  };
61
-
62
- /**
63
- * Node API: execute jest
64
- */
65
- async function runJest(config, pwd = process.cwd()) {
66
- try {
67
- const argvConfig = await buildArgv(process.argv.slice(2), config);
68
- const {
69
- results,
70
- globalConfig
71
- } = await (0, _jest.runCLI)(argvConfig, [pwd]);
72
- readResultsAndExit(results, globalConfig);
73
- } catch (e) {
74
- console.error(_utils.chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
75
-
76
- // eslint-disable-next-line no-process-exit
77
- process.exit(1);
78
- }
100
+ function runJest(_0) {
101
+ return __async(this, arguments, function* (config, pwd = process.cwd()) {
102
+ try {
103
+ const argvConfig = yield buildArgv(process.argv.slice(2), config);
104
+ const { results, globalConfig } = yield (0, import_jest.runCLI)(argvConfig, [pwd]);
105
+ readResultsAndExit(results, globalConfig);
106
+ } catch (e) {
107
+ console.error(import_utils.chalk.red((e == null ? void 0 : e.stack) || e));
108
+ process.exit(1);
109
+ }
110
+ });
79
111
  }
80
-
81
- /**
82
- * Node API: run test
83
- */
84
- async function runTest(api, config, pwd = process.cwd()) {
85
- process.env.NODE_ENV = 'test';
86
- const jestUtils = (0, _config.getJestUtils)(config);
87
- await (0, _config.patchConfig)(jestUtils);
88
-
89
- // 确保用户设置的配置可以被插件处理,比如设置在 projects 中
90
- jestUtils.setJestUserConfig();
91
- const hookRunners = api.useHookRunners();
92
- const testConfigOperator = await hookRunners.jestConfig(jestUtils, {
93
- onLast: input => input
112
+ function runTest(_0, _1) {
113
+ return __async(this, arguments, function* (api, config, pwd = process.cwd()) {
114
+ process.env.NODE_ENV = "test";
115
+ const jestUtils = (0, import_config.getJestUtils)(config);
116
+ yield (0, import_config.patchConfig)(jestUtils);
117
+ jestUtils.setJestUserConfig();
118
+ const hookRunners = api.useHookRunners();
119
+ const testConfigOperator = yield hookRunners.jestConfig(jestUtils, {
120
+ onLast: (input) => input
121
+ });
122
+ const finalConfig = testConfigOperator.getFinalConfig();
123
+ (0, import_utils2.debug)("Jest config:", finalConfig);
124
+ yield runJest(finalConfig, pwd);
125
+ yield hookRunners.afterTest();
94
126
  });
95
- const finalConfig = testConfigOperator.getFinalConfig();
96
- (0, _utils2.debug)('Jest config:', finalConfig);
97
- await runJest(finalConfig, pwd);
98
- await hookRunners.afterTest();
99
- }
127
+ }
@@ -1,50 +1,83 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var stdin_exports = {};
25
+ __export(stdin_exports, {
26
+ debug: () => debug,
27
+ getModuleNameMapper: () => getModuleNameMapper,
28
+ readCompilerOptions: () => readCompilerOptions
5
29
  });
6
- exports.readCompilerOptions = exports.getModuleNameMapper = exports.debug = void 0;
7
- var _fs = _interopRequireDefault(require("fs"));
8
- var _path = _interopRequireDefault(require("path"));
9
- var _utils = require("@modern-js/utils");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
- const debug = (0, _utils.createDebugger)('test');
15
- exports.debug = debug;
16
- /**
17
- * Read `compilerOptions` in the current pwd's tsconfig.json file
18
- */
19
- const readCompilerOptions = (pwd = process.cwd(), filename = 'tsconfig.json') => {
30
+ module.exports = __toCommonJS(stdin_exports);
31
+ var import_fs = __toESM(require("fs"));
32
+ var import_path = __toESM(require("path"));
33
+ var import_utils = require("@modern-js/utils");
34
+ var __defProp2 = Object.defineProperty;
35
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
36
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
37
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
38
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
39
+ var __spreadValues = (a, b) => {
40
+ for (var prop in b || (b = {}))
41
+ if (__hasOwnProp2.call(b, prop))
42
+ __defNormalProp(a, prop, b[prop]);
43
+ if (__getOwnPropSymbols)
44
+ for (var prop of __getOwnPropSymbols(b)) {
45
+ if (__propIsEnum.call(b, prop))
46
+ __defNormalProp(a, prop, b[prop]);
47
+ }
48
+ return a;
49
+ };
50
+ const debug = (0, import_utils.createDebugger)("test");
51
+ const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
20
52
  let tsConfig = {};
21
53
  let extendedCompilerOptions = {};
22
- let tsconfigFile = '';
54
+ let tsconfigFile = "";
23
55
  try {
24
- const maybeTsconfigFile = _path.default.join(pwd, filename);
25
- if (_fs.default.existsSync(maybeTsconfigFile)) {
56
+ const maybeTsconfigFile = import_path.default.join(pwd, filename);
57
+ if (import_fs.default.existsSync(maybeTsconfigFile)) {
26
58
  tsconfigFile = maybeTsconfigFile;
27
59
  } else {
28
60
  tsconfigFile = require.resolve(filename);
29
61
  }
30
- ({
31
- config: tsConfig
32
- } = require('typescript').parseConfigFileTextToJson(tsconfigFile, _fs.default.readFileSync(tsconfigFile, 'utf8')));
62
+ ({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(
63
+ tsconfigFile,
64
+ import_fs.default.readFileSync(tsconfigFile, "utf8")
65
+ ));
33
66
  } catch (e) {
34
67
  return {};
35
68
  }
36
69
  if (tsConfig.extends) {
37
- extendedCompilerOptions = readCompilerOptions(_path.default.dirname(tsconfigFile), tsConfig.extends);
70
+ extendedCompilerOptions = readCompilerOptions(
71
+ import_path.default.dirname(tsconfigFile),
72
+ tsConfig.extends
73
+ );
38
74
  }
39
- return _objectSpread(_objectSpread({}, extendedCompilerOptions), tsConfig.compilerOptions);
75
+ return __spreadValues(__spreadValues({}, extendedCompilerOptions), tsConfig.compilerOptions);
40
76
  };
41
- exports.readCompilerOptions = readCompilerOptions;
42
- const getModuleNameMapper = alias => Object.keys(alias).reduce((memo, cur) => {
77
+ const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
43
78
  const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
44
- const isFile = aliasValue.some(s => s.endsWith('.js'));
45
-
46
- // It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
47
- if (cur === '@modern-js/runtime$') {
79
+ const isFile = aliasValue.some((s) => s.endsWith(".js"));
80
+ if (cur === "@modern-js/runtime$") {
48
81
  memo[`.+${cur}`] = aliasValue[0];
49
82
  return memo;
50
83
  }
@@ -52,8 +85,7 @@ const getModuleNameMapper = alias => Object.keys(alias).reduce((memo, cur) => {
52
85
  memo[cur] = aliasValue[0];
53
86
  }
54
87
  const key = `^${cur}/(.*)$`;
55
- const value = _path.default.normalize(`${aliasValue}/$1`);
88
+ const value = import_path.default.normalize(`${aliasValue}/$1`);
56
89
  memo[key] = value;
57
90
  return memo;
58
91
  }, {});
59
- exports.getModuleNameMapper = getModuleNameMapper;
@@ -1,42 +1,77 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var stdin_exports = {};
19
+ __export(stdin_exports, {
20
+ closeServer: () => closeServer,
21
+ createApp: () => createApp,
22
+ getApp: () => getApp,
23
+ isInHandler: () => isInHandler
5
24
  });
6
- exports.isInHandler = exports.getApp = exports.createApp = exports.closeServer = void 0;
7
- var _async_hooks = require("async_hooks");
8
- var _prodServer = require("@modern-js/prod-server");
9
- const store = new _async_hooks.AsyncLocalStorage();
25
+ module.exports = __toCommonJS(stdin_exports);
26
+ var import_async_hooks = require("async_hooks");
27
+ var import_prod_server = require("@modern-js/prod-server");
28
+ var __async = (__this, __arguments, generator) => {
29
+ return new Promise((resolve, reject) => {
30
+ var fulfilled = (value) => {
31
+ try {
32
+ step(generator.next(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var rejected = (value) => {
38
+ try {
39
+ step(generator.throw(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
45
+ step((generator = generator.apply(__this, __arguments)).next());
46
+ });
47
+ };
48
+ const store = new import_async_hooks.AsyncLocalStorage();
10
49
  const isInHandler = () => Boolean(store.getStore());
11
- exports.isInHandler = isInHandler;
12
50
  let server = null;
13
- const createApp = async (pwd, config, plugins, routes) => {
51
+ const createApp = (pwd, config, plugins, routes) => __async(void 0, null, function* () {
14
52
  if (!server) {
15
- config.output.path = './';
16
- server = new _prodServer.Server({
53
+ config.output.path = "./";
54
+ server = new import_prod_server.Server({
17
55
  apiOnly: true,
18
56
  pwd,
19
57
  config,
20
58
  internalPlugins: plugins,
21
59
  routes
22
60
  });
23
- await server.init();
61
+ yield server.init();
24
62
  }
25
63
  const app = server.getRequestHandler();
26
64
  return app;
27
- };
28
- exports.createApp = createApp;
65
+ });
29
66
  const getApp = () => {
30
67
  if (!server) {
31
- throw new Error('please createApp first');
68
+ throw new Error("please createApp first");
32
69
  }
33
70
  return server.getRequestHandler();
34
71
  };
35
- exports.getApp = getApp;
36
- const closeServer = async () => {
72
+ const closeServer = () => __async(void 0, null, function* () {
37
73
  if (!server) {
38
- throw new Error('please createApp first');
74
+ throw new Error("please createApp first");
39
75
  }
40
- await server.close();
41
- };
42
- exports.closeServer = closeServer;
76
+ yield server.close();
77
+ });
@@ -1,8 +1,23 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var stdin_exports = {};
19
+ __export(stdin_exports, {
20
+ bff_info_key: () => bff_info_key
5
21
  });
6
- exports.bff_info_key = void 0;
7
- const bff_info_key = 'modern_bff_info';
8
- exports.bff_info_key = bff_info_key;
22
+ module.exports = __toCommonJS(stdin_exports);
23
+ const bff_info_key = "modern_bff_info";