@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.
- package/CHANGELOG.md +145 -0
- package/dist/js/modern/base/config/index.js +29 -9
- package/dist/js/modern/base/config/patches/assetsModule.js +7 -7
- package/dist/js/modern/base/config/patches/filemock.js +4 -1
- package/dist/js/modern/base/config/patches/index.js +30 -7
- package/dist/js/modern/base/config/patches/transformer.js +13 -18
- package/dist/js/modern/base/config/resolver.js +11 -6
- package/dist/js/modern/base/config/testConfigOperator.js +29 -23
- package/dist/js/modern/base/config/transformer/babelTransformer.js +16 -8
- package/dist/js/modern/base/hook.js +10 -5
- package/dist/js/modern/base/index.js +14 -6
- package/dist/js/modern/base/runJest.js +73 -62
- package/dist/js/modern/base/utils.js +40 -23
- package/dist/js/modern/cli/bff/app.js +37 -12
- package/dist/js/modern/cli/bff/constant.js +4 -1
- package/dist/js/modern/cli/bff/index.js +95 -52
- package/dist/js/modern/cli/bff/mockAPI.js +79 -64
- package/dist/js/modern/cli/bff/setup.js +71 -34
- package/dist/js/modern/cli/bff/utils/index.js +31 -15
- package/dist/js/modern/cli/index.js +64 -30
- package/dist/js/modern/cli/test.js +53 -18
- package/dist/js/modern/constant.js +4 -1
- package/dist/js/modern/index.js +3 -3
- package/dist/js/modern/modern-app.env.d.js +0 -0
- package/dist/js/modern/runtime-testing/app.js +25 -14
- package/dist/js/modern/runtime-testing/base.js +7 -3
- package/dist/js/modern/runtime-testing/customRender.js +24 -10
- package/dist/js/modern/runtime-testing/index.js +1 -1
- package/dist/js/modern/runtime-testing/reduck.js +41 -19
- package/dist/js/modern/runtime-testing/request.js +4 -4
- package/dist/js/modern/runtime-testing/resolvePlugins.js +24 -8
- package/dist/js/node/base/config/index.js +56 -18
- package/dist/js/node/base/config/patches/assetsModule.js +30 -12
- package/dist/js/node/base/config/patches/filemock.js +22 -7
- package/dist/js/node/base/config/patches/index.js +50 -15
- package/dist/js/node/base/config/patches/transformer.js +38 -25
- package/dist/js/node/base/config/resolver.js +37 -10
- package/dist/js/node/base/config/testConfigOperator.js +49 -30
- package/dist/js/node/base/config/transformer/babelTransformer.js +40 -15
- package/dist/js/node/base/hook.js +28 -13
- package/dist/js/node/base/index.js +31 -63
- package/dist/js/node/base/runJest.js +99 -71
- package/dist/js/node/base/utils.js +66 -34
- package/dist/js/node/cli/bff/app.js +57 -22
- package/dist/js/node/cli/bff/constant.js +22 -7
- package/dist/js/node/cli/bff/index.js +121 -65
- package/dist/js/node/cli/bff/mockAPI.js +103 -71
- package/dist/js/node/cli/bff/setup.js +100 -38
- package/dist/js/node/cli/bff/utils/index.js +55 -22
- package/dist/js/node/cli/index.js +87 -46
- package/dist/js/node/cli/test.js +79 -27
- package/dist/js/node/constant.js +22 -7
- package/dist/js/node/index.js +19 -18
- package/dist/js/node/modern-app.env.d.js +0 -0
- package/dist/js/node/runtime-testing/app.js +53 -25
- package/dist/js/node/runtime-testing/base.js +30 -33
- package/dist/js/node/runtime-testing/customRender.js +49 -18
- package/dist/js/node/runtime-testing/index.js +18 -27
- package/dist/js/node/runtime-testing/reduck.js +67 -31
- package/dist/js/node/runtime-testing/request.js +32 -13
- package/dist/js/node/runtime-testing/resolvePlugins.js +41 -12
- package/dist/js/treeshaking/base/config/index.js +150 -31
- package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -11
- package/dist/js/treeshaking/base/config/patches/filemock.js +2 -1
- package/dist/js/treeshaking/base/config/patches/index.js +221 -64
- package/dist/js/treeshaking/base/config/patches/transformer.js +34 -37
- package/dist/js/treeshaking/base/config/resolver.js +24 -11
- package/dist/js/treeshaking/base/config/testConfigOperator.js +120 -69
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +16 -10
- package/dist/js/treeshaking/base/hook.js +8 -7
- package/dist/js/treeshaking/base/index.js +7 -6
- package/dist/js/treeshaking/base/runJest.js +281 -164
- package/dist/js/treeshaking/base/types/index.js +1 -0
- package/dist/js/treeshaking/base/utils.js +72 -48
- package/dist/js/treeshaking/cli/bff/app.js +192 -68
- package/dist/js/treeshaking/cli/bff/constant.js +2 -1
- package/dist/js/treeshaking/cli/bff/index.js +291 -130
- package/dist/js/treeshaking/cli/bff/mockAPI.js +181 -91
- package/dist/js/treeshaking/cli/bff/setup.js +185 -59
- package/dist/js/treeshaking/cli/bff/utils/index.js +47 -21
- package/dist/js/treeshaking/cli/index.js +248 -108
- package/dist/js/treeshaking/cli/test.js +177 -44
- package/dist/js/treeshaking/constant.js +2 -1
- package/dist/js/treeshaking/index.js +3 -3
- package/dist/js/treeshaking/modern-app.env.d.js +1 -0
- package/dist/js/treeshaking/runtime-testing/app.js +85 -39
- package/dist/js/treeshaking/runtime-testing/base.js +4 -3
- package/dist/js/treeshaking/runtime-testing/customRender.js +38 -10
- package/dist/js/treeshaking/runtime-testing/index.js +1 -1
- package/dist/js/treeshaking/runtime-testing/reduck.js +85 -33
- package/dist/js/treeshaking/runtime-testing/request.js +49 -19
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +45 -14
- package/dist/types/base/config/index.d.ts +1 -0
- package/dist/types/base/config/patches/assetsModule.d.ts +1 -0
- package/dist/types/base/config/patches/filemock.d.ts +1 -0
- package/dist/types/base/config/patches/transformer.d.ts +1 -0
- package/dist/types/base/config/resolver.d.ts +2 -1
- package/dist/types/base/config/testConfigOperator.d.ts +2 -0
- package/dist/types/base/runJest.d.ts +2 -0
- package/dist/types/base/utils.d.ts +1 -0
- package/dist/types/cli/bff/index.d.ts +2 -0
- package/dist/types/cli/bff/mockAPI.d.ts +1 -0
- package/dist/types/cli/index.d.ts +2 -0
- package/dist/types/runtime-testing/app.d.ts +3 -0
- package/dist/types/runtime-testing/customRender.d.ts +2 -0
- package/package.json +13 -13
|
@@ -1,32 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
58
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
96
|
-
(0, _utils2.debug)('Jest config:', finalConfig);
|
|
97
|
-
await runJest(finalConfig, pwd);
|
|
98
|
-
await hookRunners.afterTest();
|
|
99
|
-
}
|
|
127
|
+
}
|
|
@@ -1,50 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 =
|
|
25
|
-
if (
|
|
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
|
-
|
|
32
|
-
|
|
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(
|
|
70
|
+
extendedCompilerOptions = readCompilerOptions(
|
|
71
|
+
import_path.default.dirname(tsconfigFile),
|
|
72
|
+
tsConfig.extends
|
|
73
|
+
);
|
|
38
74
|
}
|
|
39
|
-
return
|
|
75
|
+
return __spreadValues(__spreadValues({}, extendedCompilerOptions), tsConfig.compilerOptions);
|
|
40
76
|
};
|
|
41
|
-
|
|
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(
|
|
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 =
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
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 =
|
|
51
|
+
const createApp = (pwd, config, plugins, routes) => __async(void 0, null, function* () {
|
|
14
52
|
if (!server) {
|
|
15
|
-
config.output.path =
|
|
16
|
-
server = new
|
|
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
|
-
|
|
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(
|
|
68
|
+
throw new Error("please createApp first");
|
|
32
69
|
}
|
|
33
70
|
return server.getRequestHandler();
|
|
34
71
|
};
|
|
35
|
-
|
|
36
|
-
const closeServer = async () => {
|
|
72
|
+
const closeServer = () => __async(void 0, null, function* () {
|
|
37
73
|
if (!server) {
|
|
38
|
-
throw new Error(
|
|
74
|
+
throw new Error("please createApp first");
|
|
39
75
|
}
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
exports.closeServer = closeServer;
|
|
76
|
+
yield server.close();
|
|
77
|
+
});
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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
|
|
7
|
-
const bff_info_key =
|
|
8
|
-
exports.bff_info_key = bff_info_key;
|
|
22
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
23
|
+
const bff_info_key = "modern_bff_info";
|