mock-config-server 5.0.0-beta.3 → 5.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/dist/bin/build.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { resolveConfigFile } from "./helpers/resolveConfigFile.mjs";
|
|
|
2
2
|
import { resolveConfigFilePath } from "./helpers/resolveConfigFilePath.mjs";
|
|
3
3
|
import "./helpers/index.mjs";
|
|
4
4
|
import { run } from "./run.mjs";
|
|
5
|
+
import path from "node:path";
|
|
5
6
|
import { build, context } from "esbuild";
|
|
6
7
|
//#region bin/build.ts
|
|
7
8
|
const build$1 = async (argv) => {
|
|
@@ -18,6 +19,7 @@ const build$1 = async (argv) => {
|
|
|
18
19
|
metafile: false,
|
|
19
20
|
logLevel: "info",
|
|
20
21
|
format: "esm",
|
|
22
|
+
banner: { js: "import { createRequire as __mcsCreateRequire } from \"node:module\"; const require = __mcsCreateRequire(import.meta.url);" },
|
|
21
23
|
plugins: []
|
|
22
24
|
};
|
|
23
25
|
if (argv.watch) {
|
|
@@ -28,8 +30,8 @@ const build$1 = async (argv) => {
|
|
|
28
30
|
build.onStart(() => {
|
|
29
31
|
instance?.destroy();
|
|
30
32
|
});
|
|
31
|
-
build.onEnd((result) => {
|
|
32
|
-
if (!result.errors.length) instance = run(resolveConfigFile(result.outputFiles[0].text), argv);
|
|
33
|
+
build.onEnd(async (result) => {
|
|
34
|
+
if (!result.errors.length) instance = run(await resolveConfigFile(result.outputFiles[0].text, path.dirname(configFilePath)), argv);
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
});
|
|
@@ -37,7 +39,7 @@ const build$1 = async (argv) => {
|
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
39
41
|
const { outputFiles } = await build(buildOptions);
|
|
40
|
-
return run(resolveConfigFile(outputFiles[0].text), argv);
|
|
42
|
+
return run(await resolveConfigFile(outputFiles[0].text, path.dirname(configFilePath)), argv);
|
|
41
43
|
};
|
|
42
44
|
//#endregion
|
|
43
45
|
export { build$1 as build };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { APP_PATH } from "../../src/utils/constants/appPath.mjs";
|
|
2
|
-
import "../../src/utils/constants/index.mjs";
|
|
3
1
|
import { resolveExportsFromSourceCode } from "./resolveExportsFromSourceCode.mjs";
|
|
4
2
|
//#region bin/helpers/resolveConfigFile.ts
|
|
5
|
-
const resolveConfigFile = (configSourceCode) => {
|
|
3
|
+
const resolveConfigFile = async (configSourceCode, configDir) => {
|
|
6
4
|
if (!configSourceCode) throw new Error("Cannot handle source code of mock-server.config.(ts|js)");
|
|
7
|
-
const mockServerConfig = resolveExportsFromSourceCode(configSourceCode,
|
|
5
|
+
const mockServerConfig = (await resolveExportsFromSourceCode(configSourceCode, configDir)).default;
|
|
8
6
|
if (!mockServerConfig) throw new Error("Cannot handle exports of mock-server.config.(ts|js)");
|
|
9
7
|
if (!Array.isArray(mockServerConfig)) throw new TypeError("configuration should be array config; see our doc (https://www.npmjs.com/package/mock-config-server) for more information");
|
|
10
8
|
return mockServerConfig;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { Module, createRequire } from "node:module";
|
|
2
1
|
import path from "node:path";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { unlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
3
5
|
//#region bin/helpers/resolveExportsFromSourceCode.ts
|
|
4
|
-
const resolveExportsFromSourceCode = (sourceCode, configDirname) => {
|
|
5
|
-
const filename = path.join(configDirname,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const resolveExportsFromSourceCode = async (sourceCode, configDirname) => {
|
|
7
|
+
const filename = path.join(configDirname, `mock-server.config.${randomBytes(8).toString("hex")}.mjs`);
|
|
8
|
+
await writeFile(filename, sourceCode);
|
|
9
|
+
try {
|
|
10
|
+
return await import(pathToFileURL(filename).href);
|
|
11
|
+
} finally {
|
|
12
|
+
await unlink(filename);
|
|
13
|
+
}
|
|
12
14
|
};
|
|
13
15
|
//#endregion
|
|
14
16
|
export { resolveExportsFromSourceCode };
|
package/dist/package.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { __commonJSMin } from "./_virtual/_rolldown/runtime.mjs";
|
|
|
3
3
|
var require_package = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4
4
|
module.exports = {
|
|
5
5
|
"name": "mock-config-server",
|
|
6
|
-
"version": "5.0.0-beta.
|
|
6
|
+
"version": "5.0.0-beta.4",
|
|
7
7
|
"description": "Tool that easily and quickly imitates server operation, create full fake api in few steps",
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "SIBERIA CAN CODE 🧊",
|
package/package.json
CHANGED