vite-plugin-mock-dev-server 1.6.0 → 1.6.1
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/index.cjs +15 -13
- package/dist/index.js +15 -13
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -49,14 +49,14 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${_
|
|
|
49
49
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
50
50
|
|
|
51
51
|
// src/plugin.ts
|
|
52
|
-
var
|
|
52
|
+
var import_node_process5 = __toESM(require("process"), 1);
|
|
53
53
|
var import_utils16 = require("@pengzhanbo/utils");
|
|
54
54
|
|
|
55
55
|
// src/build.ts
|
|
56
56
|
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
57
57
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
58
58
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
59
|
-
var
|
|
59
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
60
60
|
var import_utils2 = require("@pengzhanbo/utils");
|
|
61
61
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
62
62
|
var import_is_core_module = __toESM(require("is-core-module"), 1);
|
|
@@ -68,6 +68,7 @@ var import_node_fs2 = __toESM(require("fs"), 1);
|
|
|
68
68
|
var import_node_module = require("module");
|
|
69
69
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
70
70
|
var import_node_url2 = require("url");
|
|
71
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
71
72
|
var import_esbuild = require("esbuild");
|
|
72
73
|
var import_json5 = __toESM(require("json5"), 1);
|
|
73
74
|
|
|
@@ -208,7 +209,7 @@ function aliasMatches(pattern, importee) {
|
|
|
208
209
|
}
|
|
209
210
|
async function transformWithEsbuild(entryPoint, options) {
|
|
210
211
|
var _a;
|
|
211
|
-
const { isESM = true, define, alias } = options;
|
|
212
|
+
const { isESM = true, define, alias, cwd = import_node_process.default.cwd() } = options;
|
|
212
213
|
try {
|
|
213
214
|
const result = await (0, import_esbuild.build)({
|
|
214
215
|
entryPoints: [entryPoint],
|
|
@@ -220,7 +221,8 @@ async function transformWithEsbuild(entryPoint, options) {
|
|
|
220
221
|
metafile: true,
|
|
221
222
|
format: isESM ? "esm" : "cjs",
|
|
222
223
|
define,
|
|
223
|
-
plugins: [aliasPlugin(alias), externalizeDeps, jsonLoader, json5Loader]
|
|
224
|
+
plugins: [aliasPlugin(alias), externalizeDeps, jsonLoader, json5Loader],
|
|
225
|
+
absWorkingDir: cwd
|
|
224
226
|
});
|
|
225
227
|
return {
|
|
226
228
|
code: result.outputFiles[0].text,
|
|
@@ -239,6 +241,7 @@ async function loadFromCode({
|
|
|
239
241
|
isESM,
|
|
240
242
|
cwd
|
|
241
243
|
}) {
|
|
244
|
+
filepath = import_node_path2.default.resolve(cwd, filepath);
|
|
242
245
|
if (isESM) {
|
|
243
246
|
const fileBase = `${filepath}.timestamp-${Date.now()}`;
|
|
244
247
|
const fileNameTmp = `${fileBase}.mjs`;
|
|
@@ -253,7 +256,6 @@ async function loadFromCode({
|
|
|
253
256
|
}
|
|
254
257
|
}
|
|
255
258
|
} else {
|
|
256
|
-
filepath = import_node_path2.default.resolve(cwd, filepath);
|
|
257
259
|
const extension = import_node_path2.default.extname(filepath);
|
|
258
260
|
const realFileName = import_node_fs2.default.realpathSync(filepath);
|
|
259
261
|
const loaderExt = extension in _require.extensions ? extension : ".js";
|
|
@@ -274,10 +276,10 @@ async function loadFromCode({
|
|
|
274
276
|
}
|
|
275
277
|
|
|
276
278
|
// src/define.ts
|
|
277
|
-
var
|
|
279
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
278
280
|
function viteDefine(config) {
|
|
279
281
|
const processNodeEnv = {};
|
|
280
|
-
const nodeEnv =
|
|
282
|
+
const nodeEnv = import_node_process2.default.env.NODE_ENV || config.mode;
|
|
281
283
|
Object.assign(processNodeEnv, {
|
|
282
284
|
"process.env.NODE_ENV": JSON.stringify(nodeEnv),
|
|
283
285
|
"global.process.env.NODE_ENV": JSON.stringify(nodeEnv),
|
|
@@ -354,12 +356,12 @@ function canJsonParse(value) {
|
|
|
354
356
|
|
|
355
357
|
// src/build.ts
|
|
356
358
|
var packageName = true ? "vite-plugin-mock-dev-server" : "vite-plugin-mock-dev-server";
|
|
357
|
-
var packageVersion = true ? "1.6.
|
|
359
|
+
var packageVersion = true ? "1.6.1" : "latest";
|
|
358
360
|
async function generateMockServer(ctx, config, options) {
|
|
359
361
|
const include = (0, import_utils2.toArray)(options.include);
|
|
360
362
|
const exclude = (0, import_utils2.toArray)(options.exclude);
|
|
361
363
|
const define = viteDefine(config);
|
|
362
|
-
const cwd = options.cwd ||
|
|
364
|
+
const cwd = options.cwd || import_node_process3.default.cwd();
|
|
363
365
|
const { httpProxies } = ensureProxies(config.server.proxy || {});
|
|
364
366
|
httpProxies.push(...(0, import_utils2.toArray)(options.prefix));
|
|
365
367
|
const wsProxies = (0, import_utils2.toArray)(options.wsPrefix);
|
|
@@ -1122,7 +1124,7 @@ function createLogger(prefix, defaultLevel = "info") {
|
|
|
1122
1124
|
|
|
1123
1125
|
// src/MockLoader.ts
|
|
1124
1126
|
var import_node_events = __toESM(require("events"), 1);
|
|
1125
|
-
var
|
|
1127
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
1126
1128
|
var import_utils11 = require("@pengzhanbo/utils");
|
|
1127
1129
|
var import_chokidar = __toESM(require("chokidar"), 1);
|
|
1128
1130
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
@@ -1190,7 +1192,7 @@ var MockLoader = class extends import_node_events.default {
|
|
|
1190
1192
|
constructor(options) {
|
|
1191
1193
|
super();
|
|
1192
1194
|
this.options = options;
|
|
1193
|
-
this.cwd = options.cwd ||
|
|
1195
|
+
this.cwd = options.cwd || import_node_process4.default.cwd();
|
|
1194
1196
|
try {
|
|
1195
1197
|
const pkg = lookupFile(this.cwd, ["package.json"]);
|
|
1196
1198
|
this.moduleType = !!pkg && JSON.parse(pkg).type === "module" ? "esm" : "cjs";
|
|
@@ -1326,7 +1328,7 @@ var MockLoader = class extends import_node_events.default {
|
|
|
1326
1328
|
const { define, alias } = this.options;
|
|
1327
1329
|
const { code, deps } = await transformWithEsbuild(
|
|
1328
1330
|
filepath,
|
|
1329
|
-
{ isESM, define, alias }
|
|
1331
|
+
{ isESM, define, alias, cwd: this.cwd }
|
|
1330
1332
|
);
|
|
1331
1333
|
try {
|
|
1332
1334
|
const raw = await loadFromCode({
|
|
@@ -1611,7 +1613,7 @@ function corsMiddleware(mockLoader, proxies, config, options) {
|
|
|
1611
1613
|
function mockDevServerPlugin({
|
|
1612
1614
|
prefix = [],
|
|
1613
1615
|
wsPrefix = [],
|
|
1614
|
-
cwd =
|
|
1616
|
+
cwd = import_node_process5.default.cwd(),
|
|
1615
1617
|
include = ["mock/**/*.mock.{js,ts,cjs,mjs,json,json5}"],
|
|
1616
1618
|
exclude = ["**/node_modules/**", "**/.vscode/**", "**/.git/**"],
|
|
1617
1619
|
reload = false,
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/plugin.ts
|
|
2
|
-
import
|
|
2
|
+
import process5 from "node:process";
|
|
3
3
|
import { toArray as toArray5 } from "@pengzhanbo/utils";
|
|
4
4
|
|
|
5
5
|
// src/build.ts
|
|
6
6
|
import fs3 from "node:fs";
|
|
7
7
|
import fsp2 from "node:fs/promises";
|
|
8
8
|
import path3 from "node:path";
|
|
9
|
-
import
|
|
9
|
+
import process3 from "node:process";
|
|
10
10
|
import { toArray } from "@pengzhanbo/utils";
|
|
11
11
|
import fg from "fast-glob";
|
|
12
12
|
import isCore from "is-core-module";
|
|
@@ -18,6 +18,7 @@ import fs2, { promises as fsp } from "node:fs";
|
|
|
18
18
|
import { createRequire } from "node:module";
|
|
19
19
|
import path2 from "node:path";
|
|
20
20
|
import { pathToFileURL } from "node:url";
|
|
21
|
+
import process from "node:process";
|
|
21
22
|
import { build } from "esbuild";
|
|
22
23
|
import JSON5 from "json5";
|
|
23
24
|
|
|
@@ -158,7 +159,7 @@ function aliasMatches(pattern, importee) {
|
|
|
158
159
|
}
|
|
159
160
|
async function transformWithEsbuild(entryPoint, options) {
|
|
160
161
|
var _a;
|
|
161
|
-
const { isESM = true, define, alias } = options;
|
|
162
|
+
const { isESM = true, define, alias, cwd = process.cwd() } = options;
|
|
162
163
|
try {
|
|
163
164
|
const result = await build({
|
|
164
165
|
entryPoints: [entryPoint],
|
|
@@ -170,7 +171,8 @@ async function transformWithEsbuild(entryPoint, options) {
|
|
|
170
171
|
metafile: true,
|
|
171
172
|
format: isESM ? "esm" : "cjs",
|
|
172
173
|
define,
|
|
173
|
-
plugins: [aliasPlugin(alias), externalizeDeps, jsonLoader, json5Loader]
|
|
174
|
+
plugins: [aliasPlugin(alias), externalizeDeps, jsonLoader, json5Loader],
|
|
175
|
+
absWorkingDir: cwd
|
|
174
176
|
});
|
|
175
177
|
return {
|
|
176
178
|
code: result.outputFiles[0].text,
|
|
@@ -189,6 +191,7 @@ async function loadFromCode({
|
|
|
189
191
|
isESM,
|
|
190
192
|
cwd
|
|
191
193
|
}) {
|
|
194
|
+
filepath = path2.resolve(cwd, filepath);
|
|
192
195
|
if (isESM) {
|
|
193
196
|
const fileBase = `${filepath}.timestamp-${Date.now()}`;
|
|
194
197
|
const fileNameTmp = `${fileBase}.mjs`;
|
|
@@ -203,7 +206,6 @@ async function loadFromCode({
|
|
|
203
206
|
}
|
|
204
207
|
}
|
|
205
208
|
} else {
|
|
206
|
-
filepath = path2.resolve(cwd, filepath);
|
|
207
209
|
const extension = path2.extname(filepath);
|
|
208
210
|
const realFileName = fs2.realpathSync(filepath);
|
|
209
211
|
const loaderExt = extension in _require.extensions ? extension : ".js";
|
|
@@ -224,10 +226,10 @@ async function loadFromCode({
|
|
|
224
226
|
}
|
|
225
227
|
|
|
226
228
|
// src/define.ts
|
|
227
|
-
import
|
|
229
|
+
import process2 from "node:process";
|
|
228
230
|
function viteDefine(config) {
|
|
229
231
|
const processNodeEnv = {};
|
|
230
|
-
const nodeEnv =
|
|
232
|
+
const nodeEnv = process2.env.NODE_ENV || config.mode;
|
|
231
233
|
Object.assign(processNodeEnv, {
|
|
232
234
|
"process.env.NODE_ENV": JSON.stringify(nodeEnv),
|
|
233
235
|
"global.process.env.NODE_ENV": JSON.stringify(nodeEnv),
|
|
@@ -304,12 +306,12 @@ function canJsonParse(value) {
|
|
|
304
306
|
|
|
305
307
|
// src/build.ts
|
|
306
308
|
var packageName = true ? "vite-plugin-mock-dev-server" : "vite-plugin-mock-dev-server";
|
|
307
|
-
var packageVersion = true ? "1.6.
|
|
309
|
+
var packageVersion = true ? "1.6.1" : "latest";
|
|
308
310
|
async function generateMockServer(ctx, config, options) {
|
|
309
311
|
const include = toArray(options.include);
|
|
310
312
|
const exclude = toArray(options.exclude);
|
|
311
313
|
const define = viteDefine(config);
|
|
312
|
-
const cwd = options.cwd ||
|
|
314
|
+
const cwd = options.cwd || process3.cwd();
|
|
313
315
|
const { httpProxies } = ensureProxies(config.server.proxy || {});
|
|
314
316
|
httpProxies.push(...toArray(options.prefix));
|
|
315
317
|
const wsProxies = toArray(options.wsPrefix);
|
|
@@ -1085,7 +1087,7 @@ function createLogger(prefix, defaultLevel = "info") {
|
|
|
1085
1087
|
|
|
1086
1088
|
// src/MockLoader.ts
|
|
1087
1089
|
import EventEmitter from "node:events";
|
|
1088
|
-
import
|
|
1090
|
+
import process4 from "node:process";
|
|
1089
1091
|
import { hasOwn, isArray as isArray4, promiseParallel, toArray as toArray3 } from "@pengzhanbo/utils";
|
|
1090
1092
|
import chokidar from "chokidar";
|
|
1091
1093
|
import fastGlob from "fast-glob";
|
|
@@ -1159,7 +1161,7 @@ var MockLoader = class extends EventEmitter {
|
|
|
1159
1161
|
constructor(options) {
|
|
1160
1162
|
super();
|
|
1161
1163
|
this.options = options;
|
|
1162
|
-
this.cwd = options.cwd ||
|
|
1164
|
+
this.cwd = options.cwd || process4.cwd();
|
|
1163
1165
|
try {
|
|
1164
1166
|
const pkg = lookupFile(this.cwd, ["package.json"]);
|
|
1165
1167
|
this.moduleType = !!pkg && JSON.parse(pkg).type === "module" ? "esm" : "cjs";
|
|
@@ -1295,7 +1297,7 @@ var MockLoader = class extends EventEmitter {
|
|
|
1295
1297
|
const { define, alias } = this.options;
|
|
1296
1298
|
const { code, deps } = await transformWithEsbuild(
|
|
1297
1299
|
filepath,
|
|
1298
|
-
{ isESM, define, alias }
|
|
1300
|
+
{ isESM, define, alias, cwd: this.cwd }
|
|
1299
1301
|
);
|
|
1300
1302
|
try {
|
|
1301
1303
|
const raw = await loadFromCode({
|
|
@@ -1580,7 +1582,7 @@ function corsMiddleware(mockLoader, proxies, config, options) {
|
|
|
1580
1582
|
function mockDevServerPlugin({
|
|
1581
1583
|
prefix = [],
|
|
1582
1584
|
wsPrefix = [],
|
|
1583
|
-
cwd =
|
|
1585
|
+
cwd = process5.cwd(),
|
|
1584
1586
|
include = ["mock/**/*.mock.{js,ts,cjs,mjs,json,json5}"],
|
|
1585
1587
|
exclude = ["**/node_modules/**", "**/.vscode/**", "**/.git/**"],
|
|
1586
1588
|
reload = false,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-mock-dev-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.1",
|
|
5
5
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://vite-plugin-mock-dev-server.netlify.app",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"co-body": "^6.2.0",
|
|
49
49
|
"cookies": "^0.9.1",
|
|
50
50
|
"cors": "^2.8.5",
|
|
51
|
-
"debug": "^4.3.
|
|
51
|
+
"debug": "^4.3.6",
|
|
52
52
|
"esbuild": "^0.23.0",
|
|
53
53
|
"fast-glob": "^3.3.2",
|
|
54
54
|
"formidable": "2.1.2",
|
|
@@ -69,15 +69,15 @@
|
|
|
69
69
|
"@types/formidable": "2.0.6",
|
|
70
70
|
"@types/is-core-module": "^2.2.2",
|
|
71
71
|
"@types/mime-types": "^2.1.4",
|
|
72
|
-
"@types/node": "^20.14.
|
|
72
|
+
"@types/node": "^20.14.13",
|
|
73
73
|
"@types/ws": "^8.5.11",
|
|
74
74
|
"bumpp": "^9.4.1",
|
|
75
75
|
"conventional-changelog-cli": "^5.0.0",
|
|
76
|
-
"eslint": "^9.
|
|
76
|
+
"eslint": "^9.8.0",
|
|
77
77
|
"mockjs": "^1.1.0",
|
|
78
78
|
"tsup": "^8.2.3",
|
|
79
79
|
"typescript": "^5.5.4",
|
|
80
|
-
"vite": "^5.3.
|
|
80
|
+
"vite": "^5.3.5",
|
|
81
81
|
"vitepress": "^1.3.1",
|
|
82
82
|
"vitest": "^2.0.4"
|
|
83
83
|
},
|