vite-plugin-automock 1.1.1 → 1.1.3
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.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -405,6 +405,9 @@ async function writeMockFile(filePath, mockInfo) {
|
|
|
405
405
|
// src/inspector.ts
|
|
406
406
|
var import_path3 = __toESM(require("path"));
|
|
407
407
|
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
408
|
+
var import_url = require("url");
|
|
409
|
+
var import_meta = {};
|
|
410
|
+
var _dirName = typeof __dirname !== "undefined" ? __dirname : import_path3.default.dirname((0, import_url.fileURLToPath)(import_meta.url));
|
|
408
411
|
function buildMockItem(key, filePath, mockDir, info) {
|
|
409
412
|
return {
|
|
410
413
|
key,
|
|
@@ -487,7 +490,7 @@ async function serveInspectorHtml({
|
|
|
487
490
|
const routeJson = JSON.stringify(ensureTrailingSlash(inspectorRoute));
|
|
488
491
|
const allowToggleJson = JSON.stringify(inspectorConfig.enableToggle);
|
|
489
492
|
const apiPrefixEscaped = escapeHtml(apiPrefix);
|
|
490
|
-
const templatePath = import_path3.default.join(
|
|
493
|
+
const templatePath = import_path3.default.join(_dirName, "inspector-template.html");
|
|
491
494
|
const template = import_fs_extra2.default.readFileSync(templatePath, "utf-8");
|
|
492
495
|
const html = template.replace("__API_PREFIX__", apiPrefixEscaped).replace("__ROUTE_JSON__", routeJson).replace("__ALLOW_TOGGLE_JSON__", allowToggleJson);
|
|
493
496
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
@@ -830,10 +833,8 @@ function proxyAndCapture(req, res, options) {
|
|
|
830
833
|
let bodyStr = "";
|
|
831
834
|
req.on("data", (chunk) => bodyStr += chunk.toString());
|
|
832
835
|
req.on("end", () => sendProxyRequest(bodyStr));
|
|
833
|
-
} else if (req.readableEnded) {
|
|
834
|
-
sendProxyRequest();
|
|
835
836
|
} else {
|
|
836
|
-
|
|
837
|
+
sendProxyRequest();
|
|
837
838
|
}
|
|
838
839
|
}
|
|
839
840
|
function printServerUrls(server, urls) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/middleware.ts","../src/mockFileUtils.ts","../src/utils.ts","../src/inspector.ts","../src/mockBundler.ts","../src/client/interceptor.ts"],"sourcesContent":["import path from 'path'\nimport fs from 'fs-extra'\n\nimport { automock as createAutomockPlugin } from './middleware'\nimport { bundleMockFiles, writeMockBundle } from './mockBundler'\nimport { buildMockIndex } from './mockFileUtils'\nimport type { Plugin } from 'vite'\nimport type { AutomockPluginOptions } from './types'\nimport type { MockBundle } from './mockBundler'\n\nexport type { AutomockPluginOptions, InspectorOptions } from './types'\nexport { saveMockData, buildMockIndex, parseMockModule, writeMockFile } from './mockFileUtils'\nexport type { MockBundle, MockBundleData } from './mockBundler'\nexport { bundleMockFiles, writeMockBundle } from './mockBundler'\n\n// Client interceptor exports\nexport {\n createMockInterceptor,\n initMockInterceptor,\n initMockInterceptorForPureHttp,\n setMockEnabled,\n isMockEnabled,\n loadMockData,\n registerHttpInstance\n} from './client'\nexport type { MockInterceptorOptions, MockBundleData as ClientMockBundleData } from './client/interceptor'\n\nexport interface AutomockWithBundleOptions extends AutomockPluginOptions {\n bundleMockData?: boolean\n bundleOutputPath?: string\n}\n\nexport function automock(options: AutomockWithBundleOptions = {}): Plugin {\n const {\n bundleMockData = true,\n bundleOutputPath = 'public/mock-data.json',\n ...pluginOptions\n } = options\n\n const basePlugin = createAutomockPlugin(pluginOptions)\n\n let cachedBundle: MockBundle | null = null\n\n const ensureBundleExists = () => {\n const outputPath = path.join(process.cwd(), bundleOutputPath)\n if (!fs.existsSync(outputPath) && cachedBundle) {\n console.log('[automock] Re-writing mock bundle...')\n writeMockBundle(cachedBundle, outputPath)\n }\n }\n\n return {\n ...basePlugin,\n name: 'vite-plugin-automock-with-bundle',\n config() {\n // Inject compile-time constant for client interceptor\n const enabled = pluginOptions.productionMock !== false\n return {\n define: {\n __AUTOMOCK_ENABLED__: JSON.stringify(enabled),\n },\n }\n },\n buildEnd: async () => {\n if (bundleMockData && pluginOptions.productionMock !== false) {\n try {\n const mockDir = pluginOptions.mockDir || path.join(process.cwd(), 'mock')\n\n if (!fs.existsSync(mockDir)) {\n console.log('[automock] Mock directory not found, skipping bundle generation')\n console.log('[automock] Using existing mock-data.json if present')\n return\n }\n\n const mockFileMap = await buildMockIndex(mockDir)\n if (mockFileMap.size === 0) {\n console.log('[automock] No mock files found, skipping bundle generation')\n return\n }\n\n cachedBundle = await bundleMockFiles({ mockDir })\n\n const outputPath = path.join(process.cwd(), bundleOutputPath)\n writeMockBundle(cachedBundle, outputPath)\n console.log(`[automock] Mock bundle written to: ${outputPath}`)\n } catch (error) {\n console.error('[automock] Failed to bundle mock data:', error)\n }\n }\n },\n writeBundle: ensureBundleExists,\n closeBundle: ensureBundleExists,\n }\n}\n\n","import chokidar from \"chokidar\";\nimport debounce from \"lodash.debounce\";\nimport path from \"path\";\nimport fs from \"fs-extra\";\nimport http from \"http\";\nimport https from \"https\";\nimport type { AddressInfo } from \"net\";\n\nimport { buildMockIndex, saveMockData } from \"./mockFileUtils\";\nimport { createInspectorHandler, normalizeInspectorConfig } from \"./inspector\";\nimport {\n resolveAbsolutePath,\n getServerAddress,\n sendError,\n} from \"./utils\";\n\nimport type { Plugin } from \"vite\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { FSWatcher } from \"chokidar\";\nimport type { AutomockPluginOptions } from \"./types\";\n\nfunction serveMockResponse(\n res: ServerResponse,\n mockFilePath: string,\n mockResult: { data?: unknown; delay?: number; status?: number },\n): void {\n const { data, delay = 0, status = 200 } = mockResult;\n\n setTimeout(() => {\n const isBinaryMock = data && typeof data === \"object\" && (data as Record<string, unknown>).__binaryFile;\n\n if (isBinaryMock) {\n const binaryData = data as Record<string, unknown>;\n const binaryFilePath = mockFilePath.replace(\n /\\.js$/,\n \".\" + binaryData.__binaryFile,\n );\n\n if (!fs.existsSync(binaryFilePath)) {\n console.error(\n `[automock] Binary mock file not found: ${binaryFilePath}`,\n );\n sendError(res, \"Binary mock file not found\", 404);\n return;\n }\n\n try {\n const fileData = fs.readFileSync(binaryFilePath);\n const contentType =\n (binaryData.__contentType as string) || \"application/octet-stream\";\n res.setHeader(\"Content-Type\", contentType);\n res.setHeader(\"Content-Length\", fileData.length);\n res.setHeader(\"X-Mock-Response\", \"true\");\n res.setHeader(\"X-Mock-Source\", \"vite-plugin-automock\");\n res.setHeader(\"X-Mock-Binary-File\", \"true\");\n res.statusCode = status;\n res.end(fileData);\n } catch (error) {\n console.error(\"[automock] Failed to read binary mock file:\", error);\n sendError(res, \"Failed to read binary mock file\");\n }\n } else {\n res.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n res.setHeader(\"X-Mock-Response\", \"true\");\n res.setHeader(\"X-Mock-Source\", \"vite-plugin-automock\");\n res.statusCode = status;\n res.end(typeof data === \"string\" ? data : JSON.stringify(data));\n }\n }, delay);\n}\n\nfunction proxyAndCapture(\n req: IncomingMessage,\n res: ServerResponse,\n options: {\n proxyBaseUrl: string;\n pathRewrite: (p: string) => string;\n shouldSave: boolean;\n method: string;\n pathname: string;\n mockDir: string;\n onMockSaved: () => void;\n },\n): void {\n const { proxyBaseUrl, pathRewrite, shouldSave, method, pathname, mockDir, onMockSaved } = options;\n const targetUrl = proxyBaseUrl + pathRewrite(req.url || \"\");\n const client = targetUrl.startsWith(\"https\") ? https : http;\n\n function sendProxyRequest(body?: string) {\n const targetUrlObj = new URL(proxyBaseUrl);\n const proxyOptions = {\n method: req.method,\n headers: {\n ...req.headers,\n host: targetUrlObj.host,\n },\n rejectUnauthorized: false,\n };\n\n const proxyReq = client.request(targetUrl, proxyOptions, (proxyRes) => {\n const contentType = proxyRes.headers[\"content-type\"] || \"\";\n const isJson = contentType.includes(\"application/json\");\n\n // Non-JSON response (file download, stream, etc.) → pipe directly\n if (!isJson) {\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n proxyRes.pipe(res);\n return;\n }\n\n // JSON response → buffer, save mock, then respond\n const chunks: Buffer[] = [];\n\n proxyRes.on(\"data\", (chunk) => chunks.push(chunk));\n proxyRes.on(\"end\", async () => {\n try {\n const responseData = Buffer.concat(chunks);\n\n if (shouldSave) {\n try {\n console.log(\n `[automock] Capturing mock: ${req.url!} -> ${pathname}`,\n );\n const savedFilePath = await saveMockData(\n req.url!,\n method,\n responseData,\n mockDir,\n proxyRes.statusCode,\n contentType,\n );\n if (savedFilePath) {\n console.log(`[automock] Mock saved: ${pathname}`);\n onMockSaved();\n } else {\n console.log(\n `[automock] Mock file already exists, skipped: ${pathname}`,\n );\n }\n } catch (saveError) {\n console.error(\"[automock] Failed to save mock:\", saveError);\n }\n }\n\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n res.end(responseData);\n } catch (error) {\n console.error(\"[automock] Failed to process response:\", error);\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n res.end(Buffer.concat(chunks));\n }\n });\n });\n\n proxyReq.on(\"error\", (err) => {\n console.error(\"[automock] Proxy request failed:\", err);\n sendError(res, err.message);\n });\n\n if (\n body &&\n (req.method === \"POST\" || req.method === \"PUT\" || req.method === \"PATCH\")\n ) {\n proxyReq.write(body);\n }\n\n proxyReq.end();\n }\n\n if (\n req.method === \"POST\" ||\n req.method === \"PUT\" ||\n req.method === \"PATCH\"\n ) {\n let bodyStr = \"\";\n req.on(\"data\", (chunk) => (bodyStr += chunk.toString()));\n req.on(\"end\", () => sendProxyRequest(bodyStr));\n } else if (req.readableEnded) {\n sendProxyRequest();\n } else {\n req.on(\"end\", () => sendProxyRequest());\n }\n}\n\nfunction printServerUrls(\n server: { httpServer?: { address(): AddressInfo | string | null; once(event: string, cb: () => void): void } | null; config: { server: { https?: unknown } } },\n urls: Array<{ path: string; label: string; color: string; delay: number }>,\n): void {\n server.httpServer?.once(\"listening\", () => {\n const address = server.httpServer?.address();\n if (!address || typeof address !== \"object\") return;\n\n const { protocol, host, port } = getServerAddress(\n address,\n !!server.config.server.https,\n );\n\n for (const { path: urlPath, label, color, delay } of urls) {\n setTimeout(() => {\n const fullUrl = `${protocol}://${host}:${port}${urlPath}`;\n console.log(` ➜ ${color}${label}\\x1b[0m: \\x1b[1m${fullUrl}\\x1b[0m`);\n }, delay);\n }\n });\n}\n\nexport function automock(options: AutomockPluginOptions): Plugin {\n const {\n mockDir: configMockDir = path.join(process.cwd(), \"mock\"),\n apiPrefix = \"/api\",\n pathRewrite = (p) => p,\n proxyBaseUrl,\n inspector = false,\n } = options;\n\n const mockDir = resolveAbsolutePath(configMockDir);\n\n if (!fs.existsSync(mockDir)) {\n try {\n fs.ensureDirSync(mockDir);\n console.log(`[automock] Mock directory created: ${mockDir}`);\n } catch (error) {\n console.error(`[automock] Failed to create mock directory: ${mockDir}`, error);\n }\n }\n\n let watcher: FSWatcher | undefined;\n\n return {\n name: \"vite-plugin-automock\",\n config(userConfig) {\n if (proxyBaseUrl && userConfig.server?.proxy) {\n const proxyConfig = userConfig.server.proxy;\n const hasConflictingPrefix =\n typeof proxyConfig === \"object\" && apiPrefix in proxyConfig;\n\n if (hasConflictingPrefix) {\n console.warn(\n `\\n⚠️ [automock] WARNING: You have both Vite's server.proxy[\"${apiPrefix}\"] and automock's proxyBaseUrl configured.`,\n );\n console.warn(\n ` This may cause request conflicts. Remove the \"${apiPrefix}\" entry from vite.config.ts server.proxy to avoid issues.`,\n );\n console.warn(\n ` Automock will handle all ${apiPrefix} requests when proxyBaseUrl is set.\\n`,\n );\n }\n }\n },\n async configureServer(server) {\n let mockFileMap = await buildMockIndex(mockDir);\n console.log(`[automock] Loaded ${mockFileMap.size} mock files`);\n\n const rebuildMockFileMap = debounce(async () => {\n mockFileMap = await buildMockIndex(mockDir);\n }, 200);\n\n watcher = chokidar.watch(mockDir, {\n ignoreInitial: true,\n persistent: true,\n depth: 30,\n });\n watcher.on(\"add\", () => rebuildMockFileMap());\n watcher.on(\"unlink\", () => rebuildMockFileMap());\n\n server.httpServer?.on(\"close\", () => watcher?.close());\n\n const inspectorHandler = createInspectorHandler({\n inspector,\n apiPrefix,\n mockDir,\n getMockFileMap: () => mockFileMap,\n });\n\n const urlsToPrint: Array<{ path: string; label: string; color: string; delay: number }> = [\n { path: apiPrefix, label: \"Mock API\", color: \"\\x1b[32m\", delay: 100 },\n ];\n\n if (inspector) {\n const inspectorConfig = normalizeInspectorConfig(inspector);\n urlsToPrint.push({\n path: inspectorConfig.route,\n label: \"Mock Inspector\",\n color: \"\\x1b[95m\",\n delay: 150,\n });\n }\n\n printServerUrls(server, urlsToPrint);\n\n async function tryLoadMock(key: string): Promise<{ absolutePath: string; mockResult: Record<string, unknown> } | null> {\n const mockFilePath = mockFileMap.get(key);\n if (!mockFilePath) return null;\n\n const absolutePath = resolveAbsolutePath(mockFilePath);\n if (!fs.existsSync(absolutePath)) return null;\n\n const { default: mockModule } = await import(\n `${absolutePath}?t=${Date.now()}`\n );\n const mockResult =\n typeof mockModule.data === \"function\"\n ? mockModule.data()\n : mockModule;\n\n const { enable = true } = mockResult || {};\n return enable ? { absolutePath, mockResult } : null;\n }\n\n server.middlewares.use(\n async (\n req: IncomingMessage,\n res: ServerResponse,\n next: (err?: Error | unknown) => void,\n ): Promise<void> => {\n if (inspectorHandler && req.url) {\n const handled = await inspectorHandler(req, res);\n if (handled) return;\n }\n\n if (!req.url?.startsWith(apiPrefix)) {\n return next();\n }\n\n // Skip non-standard requests (SSE, WebSocket, file streams)\n const accept = req.headers.accept || \"\";\n const upgrade = req.headers.upgrade || \"\";\n if (accept.includes(\"text/event-stream\") || upgrade.toLowerCase() === \"websocket\") {\n return next();\n }\n\n const method = (req.method || \"GET\").toLowerCase();\n const pathname = new URL(req.url, \"http://localhost\").pathname;\n const key = `${pathname}/${method}.js`.toLowerCase();\n\n // 1. Try mock\n try {\n const mock = await tryLoadMock(key);\n if (mock) {\n serveMockResponse(res, mock.absolutePath, mock.mockResult);\n return;\n }\n } catch (error) {\n console.error(\"[automock] Failed to load mock file:\", error);\n }\n\n // 2. Try proxy\n if (!proxyBaseUrl) return next();\n\n try {\n proxyAndCapture(req, res, {\n proxyBaseUrl,\n pathRewrite,\n shouldSave: !mockFileMap.has(key),\n method,\n pathname,\n mockDir,\n onMockSaved: async () => {\n mockFileMap = await buildMockIndex(mockDir);\n },\n });\n } catch (error) {\n console.error(\"[automock] Proxy request error:\", error);\n sendError(res, \"Internal server error\");\n }\n },\n );\n },\n closeBundle() {\n watcher?.close();\n },\n transform() {\n return null;\n },\n };\n}\n","import path from \"path\";\nimport fs from \"fs-extra\";\nimport prettier from \"prettier\";\n\nimport { resolveAbsolutePath, toPosixPath } from \"./utils\";\n\nexport interface MockFileConfig {\n enable: boolean;\n data: unknown;\n delay: number;\n status: number;\n [key: string]: unknown;\n}\n\nexport interface MockFileInfo {\n config: MockFileConfig;\n serializable: boolean;\n hasDynamicData: boolean;\n headerComment?: string;\n description?: string;\n dataText: string;\n isBinary?: boolean;\n}\n\nexport const DEFAULT_CONFIG: MockFileConfig = {\n enable: true,\n data: null,\n delay: 0,\n status: 200,\n};\n\nconst isBufferTextLike = (buffer: Buffer): boolean => {\n try {\n const sample = buffer.slice(0, 100);\n const nullBytes = [...sample].filter((b) => b === 0).length;\n const controlChars = [...sample].filter(\n (b) => b < 32 && b !== 9 && b !== 10 && b !== 13,\n ).length;\n return nullBytes === 0 && controlChars < 5;\n } catch {\n return false;\n }\n};\n\nconst isBinaryResponse = (\n contentType: string | undefined,\n data: Buffer,\n): boolean => {\n if (!contentType) return false;\n\n const binaryTypes = [\n \"application/octet-stream\",\n \"application/pdf\",\n \"application/zip\",\n \"application/x-zip-compressed\",\n \"application/vnd.ms-excel\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.ms-powerpoint\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \"image/\",\n \"video/\",\n \"audio/\",\n ];\n\n return (\n binaryTypes.some((type) => contentType.toLowerCase().includes(type)) ||\n !isBufferTextLike(data)\n );\n};\n\nconst getFileExtension = (\n contentType: string | undefined,\n url: string,\n): string => {\n const mimeMap: Record<string, string> = {\n \"application/json\": \"json\",\n \"application/pdf\": \"pdf\",\n \"application/zip\": \"zip\",\n \"application/vnd.ms-excel\": \"xls\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\": \"xlsx\",\n \"application/msword\": \"doc\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\":\n \"docx\",\n \"application/vnd.ms-powerpoint\": \"ppt\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\":\n \"pptx\",\n \"image/jpeg\": \"jpg\",\n \"image/png\": \"png\",\n \"image/gif\": \"gif\",\n \"text/plain\": \"txt\",\n \"text/html\": \"html\",\n \"text/css\": \"css\",\n \"application/javascript\": \"js\",\n \"text/xml\": \"xml\",\n };\n\n if (contentType && mimeMap[contentType.toLowerCase()]) {\n return mimeMap[contentType.toLowerCase()];\n }\n\n try {\n const urlObj = new URL(url, \"http://localhost\");\n const fileName = urlObj.searchParams.get(\"file_name\");\n if (fileName) {\n const extensionMatch = fileName.match(/\\.([a-zA-Z0-9]+)$/);\n if (extensionMatch) {\n return extensionMatch[1];\n }\n }\n } catch {\n // Ignore URL parse errors\n }\n\n return \"bin\";\n};\n\nasync function formatWithPrettier(content: string): Promise<string> {\n try {\n return await prettier.format(content, { parser: \"babel\" });\n } catch {\n return content;\n }\n}\n\nfunction buildMockFileHeader(\n pathname: string,\n method: string,\n search: string,\n extra?: string,\n): string {\n return `/**\n * Mock data for ${pathname} (${method.toUpperCase()})${search || \"\"}\n * @description ${pathname}${search || \"\"}${extra ? ` - ${extra}` : \"\"}\n * Generated at ${new Date().toISOString()}\n */`;\n}\n\nasync function saveBinaryMock(\n filePath: string,\n binaryData: Buffer,\n pathname: string,\n method: string,\n search: string,\n contentType: string | undefined,\n url: string,\n statusCode: number | undefined,\n): Promise<string | null> {\n const extension = getFileExtension(contentType, url);\n const binaryFilePath = filePath.replace(/\\.js$/, \".\" + extension);\n\n if (fs.existsSync(binaryFilePath)) return null;\n\n fs.writeFileSync(binaryFilePath, binaryData);\n\n const header = buildMockFileHeader(pathname, method, search, `Binary file (${extension})`);\n const configContent = `${header}\nexport default {\n enable: false,\n data: {\n __binaryFile: '${extension}',\n __originalPath: '${pathname}',\n __originalQuery: '${search}',\n __originalUrl: '${pathname}${search || \"\"}',\n __contentType: '${contentType}',\n __fileSize: ${binaryData.length}\n },\n delay: 0,\n status: ${statusCode || 200}\n}`;\n\n const formatted = await formatWithPrettier(configContent);\n fs.writeFileSync(filePath, formatted, \"utf-8\");\n return filePath;\n}\n\nasync function saveJsonMock(\n filePath: string,\n dataStr: string,\n pathname: string,\n method: string,\n search: string,\n statusCode: number | undefined,\n): Promise<string | null> {\n if (fs.existsSync(filePath)) return null;\n\n let jsonData;\n if (!dataStr || dataStr.trim() === \"\") {\n jsonData = {\n error: true,\n message: `Empty response (${statusCode || \"unknown status\"})`,\n status: statusCode || 404,\n data: null,\n };\n } else {\n try {\n jsonData = JSON.parse(dataStr);\n if (statusCode && statusCode >= 400) {\n const errorMeta = { __mockStatusCode: statusCode, __isErrorResponse: true };\n jsonData =\n typeof jsonData === \"object\" && jsonData !== null\n ? { ...jsonData, ...errorMeta }\n : { originalData: jsonData, ...errorMeta };\n }\n } catch {\n jsonData = {\n error: true,\n message: `Non-JSON response (${statusCode || \"unknown status\"})`,\n status: statusCode || 404,\n data: dataStr,\n __mockStatusCode: statusCode,\n __isErrorResponse: true,\n };\n }\n }\n\n const header = buildMockFileHeader(pathname, method, search);\n const content = `${header}\nexport default {\n enable: false,\n data: ${JSON.stringify(jsonData)},\n delay: 0,\n status: ${statusCode || 200}\n}`;\n\n const formatted = await formatWithPrettier(content);\n fs.writeFileSync(filePath, formatted, \"utf-8\");\n return filePath;\n}\n\nexport async function saveMockData(\n url: string,\n method: string,\n data: Buffer | string,\n rootDir: string,\n statusCode?: number,\n contentType?: string,\n): Promise<string | null> {\n try {\n const absoluteRootDir = resolveAbsolutePath(rootDir);\n const urlObj = new URL(url, \"http://localhost\");\n const pathname = urlObj.pathname;\n const search = urlObj.search;\n\n const filePath = path.join(\n absoluteRootDir,\n pathname.replace(/^\\//, \"\"),\n method.toLowerCase() + \".js\",\n );\n\n await fs.ensureDir(path.dirname(filePath));\n\n const isBuffer = Buffer.isBuffer(data);\n const binaryData = isBuffer ? data : Buffer.from(data || \"\");\n const isBinary = isBinaryResponse(contentType, binaryData);\n\n if (isBinary) {\n return saveBinaryMock(\n filePath, binaryData, pathname, method, search,\n contentType, url, statusCode,\n );\n }\n\n const dataStr = isBuffer ? data.toString(\"utf8\") : data || \"\";\n return saveJsonMock(filePath, dataStr, pathname, method, search, statusCode);\n } catch (error) {\n console.error(`Failed to save mock data for ${url}:`, error);\n console.error(\n `URL details: url=${url}, method=${method}, statusCode=${statusCode}, contentType=${contentType}`,\n );\n throw error;\n }\n}\n\nconst recursiveReadAllFiles = async (dir: string): Promise<string[]> => {\n if (!(await fs.pathExists(dir))) return [];\n\n const files: string[] = [];\n try {\n const list = await fs.readdir(dir);\n for (const file of list) {\n const filePath = path.join(dir, file);\n const stat = await fs.stat(filePath);\n if (stat.isDirectory()) {\n files.push(...(await recursiveReadAllFiles(filePath)));\n } else {\n files.push(filePath);\n }\n }\n } catch (error) {\n console.error(`Error reading directory ${dir}:`, error);\n }\n return files;\n};\n\nexport async function buildMockIndex(mockDir: string): Promise<Map<string, string>> {\n const mockFileMap = new Map<string, string>();\n\n if (!(await fs.pathExists(mockDir))) {\n await fs.ensureDir(mockDir);\n return mockFileMap;\n }\n\n const files = await recursiveReadAllFiles(mockDir);\n\n files.forEach((filePath) => {\n if (!filePath.endsWith(\".js\")) return;\n\n try {\n const relativePath = path.relative(mockDir, filePath);\n const method = path.basename(filePath, \".js\");\n const dirPath = path.dirname(relativePath);\n const urlPath = \"/\" + toPosixPath(dirPath);\n const absolutePath = resolveAbsolutePath(filePath);\n const key = `${urlPath}/${method}.js`.toLowerCase();\n\n mockFileMap.set(key, absolutePath);\n } catch (error) {\n console.error(`[automock] Failed to process file ${filePath}:`, error);\n }\n });\n\n return mockFileMap;\n}\n\nexport async function parseMockModule(filePath: string): Promise<MockFileInfo> {\n const absolutePath = resolveAbsolutePath(filePath);\n\n if (!fs.existsSync(absolutePath)) {\n throw new Error(`Mock file does not exist: ${absolutePath}`);\n }\n\n const content = fs.readFileSync(absolutePath, \"utf-8\");\n const headerCommentMatch = content.match(/^(\\/\\*\\*[\\s\\S]*?\\*\\/)/);\n const headerComment = headerCommentMatch ? headerCommentMatch[1] : undefined;\n\n let description: string | undefined;\n if (headerComment) {\n const descMatch = headerComment.match(/@description\\s+(.+?)(?:\\n|\\*\\/)/s);\n if (descMatch) {\n description = descMatch[1].trim();\n }\n }\n\n const { default: mockModule } = await import(\n `${absolutePath}?t=${Date.now()}`\n );\n\n const exportedConfig =\n typeof mockModule === \"function\" ? mockModule() : mockModule;\n const hasDynamicData = typeof exportedConfig?.data === \"function\";\n const config: MockFileConfig = {\n ...DEFAULT_CONFIG,\n ...(exportedConfig ?? {}),\n };\n\n const serializable = !hasDynamicData;\n const dataObj =\n typeof config.data === \"object\" && config.data !== null\n ? (config.data as Record<string, unknown>)\n : null;\n const isBinary = dataObj !== null && \"__binaryFile\" in dataObj;\n\n return {\n config,\n serializable,\n hasDynamicData,\n headerComment,\n description,\n dataText: isBinary\n ? `/* Binary file: ${dataObj?.__binaryFile} */`\n : serializable\n ? JSON.stringify(config.data ?? null, null, 2)\n : \"/* data is generated dynamically and cannot be edited here */\",\n isBinary,\n };\n}\n\nexport async function writeMockFile(\n filePath: string,\n mockInfo: Pick<MockFileInfo, \"config\" | \"headerComment\" | \"description\">,\n): Promise<void> {\n const absolutePath = resolveAbsolutePath(filePath);\n\n let header = mockInfo.headerComment || \"\";\n\n if (mockInfo.description !== undefined) {\n if (header) {\n if (/@description/.test(header)) {\n header = header.replace(\n /@description\\s+.+?(?=\\n|\\*\\/)/s,\n `@description ${mockInfo.description}`,\n );\n } else {\n header = header.replace(\n /\\*\\//,\n ` * @description ${mockInfo.description}\\n */`,\n );\n }\n }\n }\n\n const content = header ? `${header}\\n` : \"\";\n const finalContent = `${content}export default ${JSON.stringify(mockInfo.config, null, 2)}\\n`;\n\n try {\n const formatted = await formatWithPrettier(finalContent);\n fs.writeFileSync(absolutePath, formatted, \"utf-8\");\n } catch {\n console.error(\"Error formatting code with prettier, writing raw content\");\n fs.writeFileSync(absolutePath, finalContent, \"utf-8\");\n }\n}\n","import path from \"path\";\n\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { AddressInfo } from \"net\";\n\nexport function resolveAbsolutePath(p: string): string {\n return path.isAbsolute(p) ? p : path.resolve(process.cwd(), p);\n}\n\nexport function toPosixPath(p: string): string {\n return p.replace(/\\\\/g, \"/\");\n}\n\nexport interface ServerAddress {\n protocol: string;\n host: string;\n port: number;\n}\n\nexport function getServerAddress(\n address: AddressInfo,\n isHttps: boolean,\n): ServerAddress {\n return {\n protocol: isHttps ? \"https\" : \"http\",\n host:\n address.address === \"::\" || address.address === \"0.0.0.0\"\n ? \"localhost\"\n : address.address,\n port: address.port,\n };\n}\n\nexport function sendJson(\n res: ServerResponse,\n data: unknown,\n status = 200,\n): void {\n res.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n res.statusCode = status;\n res.end(typeof data === \"string\" ? data : JSON.stringify(data));\n}\n\nexport function sendError(\n res: ServerResponse,\n message: string,\n status = 500,\n): void {\n sendJson(res, { error: message }, status);\n}\n\nconst MAX_BODY_SIZE = 10 * 1024 * 1024; // 10MB\n\nexport function readBody(req: IncomingMessage): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n let totalSize = 0;\n req.on(\"data\", (chunk: Buffer) => {\n totalSize += chunk.length;\n if (totalSize > MAX_BODY_SIZE) {\n reject(new Error(\"Request body too large\"));\n req.destroy();\n return;\n }\n chunks.push(chunk);\n });\n req.on(\"end\", () => resolve(Buffer.concat(chunks).toString(\"utf-8\")));\n req.on(\"error\", reject);\n });\n}\n","import path from \"path\";\nimport fs from \"fs-extra\";\nimport { parseMockModule, writeMockFile, saveMockData, buildMockIndex, type MockFileConfig } from \"./mockFileUtils\";\nimport { toPosixPath, sendJson, readBody } from \"./utils\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { AutomockPluginOptions, InspectorOptions } from \"./types\";\n\ninterface InspectorContext {\n req: IncomingMessage;\n res: ServerResponse;\n mockDir: string;\n inspectorRoute: string;\n apiPrefix: string;\n inspectorConfig: Required<InspectorOptions>;\n getMockFileMap: () => Map<string, string>;\n}\n\ninterface InspectorHandlerOptions {\n inspector: AutomockPluginOptions[\"inspector\"];\n apiPrefix: string;\n mockDir: string;\n getMockFileMap: () => Map<string, string>;\n}\n\ninterface InspectorApiContext extends InspectorContext {\n pathname: string;\n}\n\ninterface InspectorPayload {\n key: string;\n config?: Partial<MockFileConfig>;\n description?: string;\n}\n\ninterface MockItem {\n key: string;\n file: string;\n method: string;\n path: string;\n config: MockFileConfig;\n editable: boolean;\n description?: string;\n dataText: string;\n}\n\nfunction buildMockItem(\n key: string,\n filePath: string,\n mockDir: string,\n info: Awaited<ReturnType<typeof parseMockModule>>,\n): MockItem {\n return {\n key,\n file: path.relative(mockDir, filePath),\n method: key.split(\"/\").pop()?.replace(/\\.js$/, \"\") ?? \"get\",\n path: key.replace(/\\/[^/]+\\.js$/, \"\"),\n config: info.config,\n editable: info.serializable,\n description: info.description,\n dataText: info.dataText,\n };\n}\n\nexport const DEFAULT_ROUTE = \"/__mock/\";\n\nfunction ensureTrailingSlash(route: string): string {\n return route.endsWith(\"/\") ? route : `${route}/`;\n}\n\nfunction escapeHtml(value: string): string {\n return value\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nexport function normalizeInspectorConfig(\n input: AutomockPluginOptions[\"inspector\"],\n): Required<InspectorOptions> {\n if (input === false || input === undefined) {\n return { route: DEFAULT_ROUTE, enableToggle: true };\n }\n if (input === true) {\n return { route: DEFAULT_ROUTE, enableToggle: true };\n }\n return {\n route: ensureTrailingSlash(input.route ?? DEFAULT_ROUTE),\n enableToggle: input.enableToggle ?? true,\n };\n}\n\nexport type InspectorRequestHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<boolean>;\n\nexport function createInspectorHandler(\n options: InspectorHandlerOptions,\n): InspectorRequestHandler | null {\n if (!options.inspector) {\n return null;\n }\n\n const inspectorConfig = normalizeInspectorConfig(options.inspector);\n const inspectorRoute = ensureTrailingSlash(inspectorConfig.route);\n\n return async (req, res) => {\n if (!req.url) {\n return false;\n }\n const url = new URL(req.url, \"http://localhost\");\n if (!url.pathname.startsWith(inspectorRoute)) {\n return false;\n }\n\n await handleInspectorRequest({\n req,\n res,\n mockDir: options.mockDir,\n inspectorRoute,\n apiPrefix: options.apiPrefix,\n inspectorConfig,\n getMockFileMap: options.getMockFileMap,\n });\n\n return true;\n };\n}\n\nasync function handleInspectorRequest(\n context: InspectorContext,\n): Promise<void> {\n const { req, res, inspectorRoute } = context;\n const url = new URL(req.url || inspectorRoute, \"http://localhost\");\n const normalizedRoute = ensureTrailingSlash(inspectorRoute);\n\n if (\n url.pathname === normalizedRoute.slice(0, -1) ||\n url.pathname === normalizedRoute\n ) {\n await serveInspectorHtml(context);\n return;\n }\n\n const relativePath = url.pathname.startsWith(normalizedRoute)\n ? url.pathname.slice(normalizedRoute.length)\n : null;\n\n if (relativePath && relativePath.startsWith(\"api/\")) {\n await handleInspectorApi({ ...context, pathname: relativePath.slice(4) });\n return;\n }\n\n res.statusCode = 404;\n res.end(\"Not Found\");\n}\n\nasync function serveInspectorHtml({\n res,\n inspectorRoute,\n apiPrefix,\n inspectorConfig,\n}: InspectorContext): Promise<void> {\n const routeJson = JSON.stringify(ensureTrailingSlash(inspectorRoute));\n const allowToggleJson = JSON.stringify(inspectorConfig.enableToggle);\n const apiPrefixEscaped = escapeHtml(apiPrefix);\n\n const templatePath = path.join(__dirname, \"inspector-template.html\");\n const template = fs.readFileSync(templatePath, \"utf-8\");\n const html = template\n .replace(\"__API_PREFIX__\", apiPrefixEscaped)\n .replace(\"__ROUTE_JSON__\", routeJson)\n .replace(\"__ALLOW_TOGGLE_JSON__\", allowToggleJson);\n\n res.setHeader(\"Content-Type\", \"text/html; charset=utf-8\");\n res.end(html);\n}\n\nasync function handleList(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { res, mockDir } = ctx;\n const list = await Promise.all(\n Array.from(mockFileMap.entries()).map(async ([key, filePath]) => {\n const info = await parseMockModule(filePath);\n return buildMockItem(key, filePath, mockDir, info);\n }),\n );\n sendJson(res, { mocks: list });\n return true;\n}\n\nasync function handleDetail(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir } = ctx;\n const url = new URL(req.url || \"\", \"http://localhost\");\n const key = url.searchParams.get(\"key\");\n if (!key) {\n sendJson(res, { error: \"Missing key\" }, 400);\n return true;\n }\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n const info = await parseMockModule(filePath);\n sendJson(res, { mock: buildMockItem(key, filePath, mockDir, info) });\n return true;\n}\n\nasync function handleUpdate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir, inspectorConfig } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: InspectorPayload;\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const { key, config, description } = payload || {};\n if (!key) {\n sendJson(res, { error: \"Invalid payload: missing key\" }, 400);\n return true;\n }\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n\n const info = await parseMockModule(filePath);\n\n let nextConfig = info.config;\n if (config && typeof config === \"object\") {\n if (!inspectorConfig.enableToggle && config.enable !== undefined) {\n delete config.enable;\n }\n nextConfig = { ...info.config, ...config };\n }\n\n const nextDescription =\n description !== undefined ? description : info.description;\n\n await writeMockFile(filePath, {\n headerComment: info.headerComment,\n config: nextConfig,\n description: nextDescription,\n });\n\n const updatedInfo = await parseMockModule(filePath);\n sendJson(res, { mock: buildMockItem(key, filePath, mockDir, updatedInfo) });\n return true;\n}\n\nasync function handleCreate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir, apiPrefix } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: { method: string; path: string; description?: string; data?: unknown };\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const { method, path: apiPath, data } = payload || {};\n if (!method || !apiPath) {\n sendJson(res, { error: \"Invalid payload: missing method or path\" }, 400);\n return true;\n }\n\n const fullUrl = apiPrefix + apiPath;\n\n try {\n let dataToSave: Buffer | string;\n if (typeof data === \"object\" && data !== null) {\n dataToSave = JSON.stringify(data, null, 2);\n } else {\n dataToSave = typeof data === \"string\" ? data : \"\";\n }\n\n await saveMockData(fullUrl, method.toLowerCase(), dataToSave, mockDir, 200);\n\n const newMockFileMap = await buildMockIndex(mockDir);\n for (const [key, value] of newMockFileMap.entries()) {\n mockFileMap.set(key, value);\n }\n\n const normalizedPath = toPosixPath(apiPath);\n const key = (normalizedPath.startsWith(\"/\") ? \"\" : \"/\") +\n normalizedPath.toLowerCase() + \"/\" + method.toLowerCase() + \".js\";\n const filePath = mockFileMap.get(key);\n\n if (!filePath) {\n sendJson(res, { error: \"Mock file created but not found in map\" }, 500);\n return true;\n }\n\n const info = await parseMockModule(filePath);\n sendJson(res, {\n success: true,\n mock: buildMockItem(key, filePath, mockDir, info),\n });\n return true;\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n sendJson(res, { error: \"Failed to create mock: \" + errorMessage }, 500);\n return true;\n }\n}\n\nasync function handleDelete(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res } = ctx;\n const url = new URL(req.url || \"\", \"http://localhost\");\n const key = url.searchParams.get(\"key\");\n if (!key) {\n sendJson(res, { error: \"Missing key\" }, 400);\n return true;\n }\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n\n try {\n const stats = await fs.stat(filePath);\n if (stats.isDirectory()) {\n await fs.remove(filePath);\n for (const [mapKey, mapPath] of mockFileMap.entries()) {\n if (mapPath.startsWith(filePath + path.sep) || mapPath === filePath) {\n mockFileMap.delete(mapKey);\n }\n }\n } else {\n await fs.unlink(filePath);\n mockFileMap.delete(key);\n }\n sendJson(res, { success: true });\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n sendJson(res, { error: \"Failed to delete: \" + errorMessage }, 500);\n }\n return true;\n}\n\ntype ApiHandler = (ctx: InspectorApiContext, mockFileMap: Map<string, string>) => Promise<boolean>;\n\nasync function handleBatchUpdate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: { updates?: Array<{ key: string; config?: Record<string, unknown> }> };\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const updates = payload?.updates;\n if (!Array.isArray(updates) || updates.length === 0) {\n sendJson(res, { error: \"Invalid payload: updates must be a non-empty array\" }, 400);\n return true;\n }\n\n let updated = 0;\n const errors: string[] = [];\n\n for (const item of updates) {\n const { key, config } = item;\n if (!key) continue;\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n errors.push(`Mock not found: ${key}`);\n continue;\n }\n\n try {\n const info = await parseMockModule(filePath);\n const nextConfig = config ? { ...info.config, ...config } : info.config;\n\n await writeMockFile(filePath, {\n headerComment: info.headerComment,\n config: nextConfig,\n description: info.description,\n });\n updated++;\n } catch (err) {\n errors.push(`Failed to update ${key}: ${err instanceof Error ? err.message : String(err)}`);\n }\n }\n\n sendJson(res, { success: true, updated, errors: errors.length > 0 ? errors : undefined });\n return true;\n}\n\nconst API_ROUTES: Record<string, ApiHandler> = {\n list: handleList,\n detail: handleDetail,\n update: handleUpdate,\n \"batch-update\": handleBatchUpdate,\n create: handleCreate,\n delete: handleDelete,\n};\n\nasync function handleInspectorApi(ctx: InspectorApiContext): Promise<void> {\n try {\n const mockFileMap = ctx.getMockFileMap();\n const handler = API_ROUTES[ctx.pathname];\n if (handler) {\n await handler(ctx, mockFileMap);\n return;\n }\n sendJson(ctx.res, { error: \"Unknown inspector endpoint\" }, 404);\n } catch (error) {\n console.error(\"[automock] Inspector request failed:\", error);\n sendJson(ctx.res, { error: \"Inspector failed\" }, 500);\n }\n}\n","import path from 'path'\nimport fs from 'fs-extra'\n\nimport { buildMockIndex, parseMockModule } from './mockFileUtils'\n\nexport interface MockBundleData {\n enable: boolean\n data: unknown\n delay: number\n status: number\n isBinary?: boolean\n}\n\nexport interface MockBundle {\n [key: string]: MockBundleData\n}\n\nexport interface BundleOptions {\n mockDir: string\n includeDisabled?: boolean\n log?: boolean\n}\n\nconst DEFAULT_BUNDLE_OPTIONS: Partial<BundleOptions> = {\n includeDisabled: true,\n log: true\n}\n\nasync function bundleMockFiles(options: BundleOptions): Promise<MockBundle> {\n const opts = { ...DEFAULT_BUNDLE_OPTIONS, ...options }\n const { mockDir, log } = opts\n\n if (!fs.existsSync(mockDir)) {\n if (log) {\n console.log(`[mock-bundler] Mock directory does not exist: ${mockDir}`)\n }\n return {}\n }\n\n const mockFileMap = await buildMockIndex(mockDir)\n const bundle: MockBundle = {}\n let bundledCount = 0\n let skippedCount = 0\n\n for (const [key, filePath] of mockFileMap) {\n try {\n const mockInfo = await parseMockModule(filePath)\n\n if (!mockInfo.serializable) {\n skippedCount++\n if (log) {\n console.log(`[mock-bundler] Skipping non-serializable mock: ${key}`)\n }\n continue\n }\n\n bundle[key] = {\n enable: mockInfo.config.enable,\n data: mockInfo.config.data,\n delay: mockInfo.config.delay,\n status: mockInfo.config.status,\n isBinary: mockInfo.isBinary\n }\n\n bundledCount++\n } catch (error) {\n if (log) {\n console.error(`[mock-bundler] Failed to bundle mock ${key}:`, error)\n }\n }\n }\n\n if (log) {\n console.log(`[mock-bundler] Bundled ${bundledCount} mocks, skipped ${skippedCount} non-serializable mocks`)\n }\n\n return bundle\n}\n\nfunction writeMockBundle(bundle: MockBundle, outputPath: string): void {\n const outputDir = path.dirname(outputPath)\n\n if (!fs.existsSync(outputDir)) {\n fs.ensureDirSync(outputDir)\n }\n\n fs.writeFileSync(\n outputPath,\n JSON.stringify(bundle, null, 2),\n 'utf-8'\n )\n}\n\nexport { bundleMockFiles, writeMockBundle }\n","import type {\n AxiosInstance,\n AxiosResponse,\n InternalAxiosRequestConfig,\n} from \"axios\";\n\ndeclare const __AUTOMOCK_ENABLED__: boolean;\n\nexport type MockBundleData = {\n enable: boolean;\n data: unknown;\n delay?: number;\n status?: number;\n isBinary?: boolean;\n};\n\nexport type MockInterceptorOptions = {\n mockData: Record<string, MockBundleData>;\n enabled?: boolean | (() => boolean);\n onMockHit?: (url: string, method: string, mock: MockBundleData) => void;\n onBypass?: (url: string, method: string, reason: string) => void;\n};\n\ntype MockEnabledState = boolean | undefined;\n\ndeclare global {\n interface Window {\n __MOCK_ENABLED__?: MockEnabledState;\n }\n}\n\nclass MockInterceptor {\n private options: MockInterceptorOptions;\n\n constructor(options: MockInterceptorOptions) {\n this.options = options;\n }\n\n /**\n * Check if mock is enabled\n */\n isEnabled(): boolean {\n // Check runtime flag first\n if (window.__MOCK_ENABLED__ !== undefined) {\n return window.__MOCK_ENABLED__;\n }\n // Check environment variable\n if (typeof this.options.enabled === \"function\") {\n return this.options.enabled();\n }\n return this.options.enabled ?? false;\n }\n\n /**\n * Find matching mock data for the request\n * Supports both formats:\n * - \"GET /api/v1/asset/xxx\" (HTTP method + URL)\n * - \"/api/v1/asset/xxx/get.js\" (File path format from automock plugin)\n */\n private findMock(url: string, method: string): MockBundleData | null {\n const methodUpper = method.toUpperCase();\n const methodLower = method.toLowerCase();\n\n // Try HTTP method + URL format first (for compatibility)\n const httpMethodKey = `${methodUpper} ${url}`;\n if (this.options.mockData[httpMethodKey]) {\n return this.options.mockData[httpMethodKey];\n }\n\n // Try file path format from automock plugin: /api/v1/asset/xxx/get.js\n const filePathKey = `${url}/${methodLower}.js`;\n if (this.options.mockData[filePathKey]) {\n return this.options.mockData[filePathKey];\n }\n\n return null;\n }\n\n /**\n * Determine if request should be mocked\n */\n shouldMock(url: string, method: string): boolean {\n if (!this.isEnabled()) {\n return false;\n }\n\n const mock = this.findMock(url, method);\n return mock !== null && mock.enable;\n }\n\n /**\n * Get mock data for request\n */\n getMock(url: string, method: string): MockBundleData | null {\n if (!this.shouldMock(url, method)) {\n return null;\n }\n return this.findMock(url, method);\n }\n\n /**\n * Setup axios interceptor\n */\n setupAxios(axiosInstance: AxiosInstance): void {\n axiosInstance.interceptors.request.use(\n async (config: InternalAxiosRequestConfig) => {\n const url = config.url || \"\";\n const method = config.method?.toUpperCase() || \"GET\";\n\n const mock = this.getMock(url, method);\n\n if (mock) {\n // Trigger mock hit callback\n this.options.onMockHit?.(url, method, mock);\n\n // Set adapter to return mock data\n (config as InternalAxiosRequestConfig & { adapter: () => Promise<AxiosResponse> }).adapter = async () => {\n const { data, delay = 0, status = 200 } = mock;\n\n // Simulate delay\n if (delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n\n return {\n data,\n status,\n statusText: \"OK\",\n headers: {},\n config,\n };\n };\n } else {\n // Trigger bypass callback\n const reason = !this.isEnabled()\n ? \"Mock disabled globally\"\n : \"No matching mock found or mock disabled\";\n this.options.onBypass?.(url, method, reason);\n }\n\n return config;\n },\n (error: unknown) => Promise.reject(error),\n );\n }\n}\n\n/**\n * Create mock interceptor instance\n */\nexport function createMockInterceptor(\n options: MockInterceptorOptions,\n): MockInterceptor {\n return new MockInterceptor(options);\n}\n\n/**\n * Load mock data from bundled JSON file\n */\nexport async function loadMockData(): Promise<Record<string, MockBundleData>> {\n try {\n // In production, mock-data.json is generated by automock plugin\n // Use absolute path to load it from dist directory\n const response = await fetch(\"/mock-data.json\");\n if (!response.ok) {\n console.warn(\n \"[MockInterceptor] Failed to load mock-data.json:\",\n response.statusText,\n );\n return {};\n }\n const data = (await response.json()) as Record<string, MockBundleData>;\n return data;\n } catch (error) {\n console.warn(\"[MockInterceptor] Failed to load mock-data.json:\", error);\n return {};\n }\n}\n\nasync function createInterceptorFromBundle(): Promise<MockInterceptor> {\n const mockData = await loadMockData();\n const isEnabled = typeof __AUTOMOCK_ENABLED__ !== \"undefined\" && __AUTOMOCK_ENABLED__;\n\n return new MockInterceptor({\n mockData,\n enabled: isEnabled,\n onMockHit: (url: string, method: string) => {\n console.log(`[MOCK HIT] ${method} ${url}`);\n },\n onBypass: (url: string, method: string, reason: string) => {\n console.log(`[MOCK BYPASS] ${method} ${url} - ${reason}`);\n },\n });\n}\n\nexport async function initMockInterceptor(\n axiosInstance?: AxiosInstance,\n): Promise<void> {\n if (!axiosInstance) {\n throw new Error(\n \"[MockInterceptor] axiosInstance is required. Please provide an axios instance.\",\n );\n }\n\n const interceptor = await createInterceptorFromBundle();\n interceptor.setupAxios(axiosInstance);\n}\n\nexport function setMockEnabled(enabled: boolean): void {\n window.__MOCK_ENABLED__ = enabled;\n}\n\nexport function isMockEnabled(): boolean {\n return !!window.__MOCK_ENABLED__;\n}\n\ntype HttpInstance = {\n constructor: { axiosInstance: AxiosInstance };\n};\n\nlet httpInstanceRef: HttpInstance | undefined;\n\nexport function registerHttpInstance(http: HttpInstance): void {\n httpInstanceRef = http;\n}\n\nexport async function initMockInterceptorForPureHttp(): Promise<void> {\n if (!httpInstanceRef) {\n throw new Error(\n \"[MockInterceptor] http instance not registered. Call registerHttpInstance(http) first.\",\n );\n }\n\n const interceptor = await createInterceptorFromBundle();\n interceptor.setupAxios(httpInstanceRef.constructor.axiosInstance);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAC,eAAiB;AACjB,IAAAC,mBAAe;;;ACDf,sBAAqB;AACrB,oBAAqB;AACrB,IAAAC,eAAiB;AACjB,IAAAC,mBAAe;AACf,kBAAiB;AACjB,mBAAkB;;;ACLlB,IAAAC,eAAiB;AACjB,sBAAe;AACf,sBAAqB;;;ACFrB,kBAAiB;AAKV,SAAS,oBAAoB,GAAmB;AACrD,SAAO,YAAAC,QAAK,WAAW,CAAC,IAAI,IAAI,YAAAA,QAAK,QAAQ,QAAQ,IAAI,GAAG,CAAC;AAC/D;AAEO,SAAS,YAAY,GAAmB;AAC7C,SAAO,EAAE,QAAQ,OAAO,GAAG;AAC7B;AAQO,SAAS,iBACd,SACA,SACe;AACf,SAAO;AAAA,IACL,UAAU,UAAU,UAAU;AAAA,IAC9B,MACE,QAAQ,YAAY,QAAQ,QAAQ,YAAY,YAC5C,cACA,QAAQ;AAAA,IACd,MAAM,QAAQ;AAAA,EAChB;AACF;AAEO,SAAS,SACd,KACA,MACA,SAAS,KACH;AACN,MAAI,UAAU,gBAAgB,iCAAiC;AAC/D,MAAI,aAAa;AACjB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ACpB,UAAI,kBAAkB,cAAc,mBAAmB,OAAO;AAC5D,YAAI;AACF,gBAAM,UAAU,cAAc,WAAW,aAAAD,QAAK,KAAK,QAAQ,IAAI,GAAG,MAAM;AAExE,cAAI,CAAC,iBAAAC,QAAG,WAAW,OAAO,GAAG;AAC3B,oBAAQ,IAAI,iEAAiE;AAC7E,oBAAQ,IAAI,qDAAqD;AACjE;AAAA,UACF;AAEA,gBAAM,cAAc,MAAM,eAAe,OAAO;AAChD,cAAI,YAAY,SAAS,GAAG;AAC1B,oBAAQ,IAAI,4DAA4D;AACxE;AAAA,UACF;AAEA,yBAAe,MAAM,gBAAgB,EAAE,QAAQ,CAAC;AAEhD,gBAAM,aAAa,aAAAD,QAAK,KAAK,QAAQ,IAAI,GAAG,gBAAgB;AAC5D,0BAAgB,cAAc,UAAU;AACxC,kBAAQ,IAAI,sCAAsC,UAAU,EAAE;AAAA,QAChE,SAAS,OAAO;AACd,kBAAQ,MAAM,0CAA0C,KAAK;AAAA,QAC/D;AAAA,MACF;AAAA,IACF;AAAA,IACA,aAAa;AAAA,IACb,aAAa;AAAA,EACf;AACF;","names":["automock","import_path","import_fs_extra","import_path","import_fs_extra","import_path","path","prettier","fs","path","import_path","import_fs_extra","path","fs","key","fs","https","http","path","debounce","chokidar","import_path","import_fs_extra","fs","path","http","automock","path","fs"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/middleware.ts","../src/mockFileUtils.ts","../src/utils.ts","../src/inspector.ts","../src/mockBundler.ts","../src/client/interceptor.ts"],"sourcesContent":["import path from 'path'\nimport fs from 'fs-extra'\n\nimport { automock as createAutomockPlugin } from './middleware'\nimport { bundleMockFiles, writeMockBundle } from './mockBundler'\nimport { buildMockIndex } from './mockFileUtils'\nimport type { Plugin } from 'vite'\nimport type { AutomockPluginOptions } from './types'\nimport type { MockBundle } from './mockBundler'\n\nexport type { AutomockPluginOptions, InspectorOptions } from './types'\nexport { saveMockData, buildMockIndex, parseMockModule, writeMockFile } from './mockFileUtils'\nexport type { MockBundle, MockBundleData } from './mockBundler'\nexport { bundleMockFiles, writeMockBundle } from './mockBundler'\n\n// Client interceptor exports\nexport {\n createMockInterceptor,\n initMockInterceptor,\n initMockInterceptorForPureHttp,\n setMockEnabled,\n isMockEnabled,\n loadMockData,\n registerHttpInstance\n} from './client'\nexport type { MockInterceptorOptions, MockBundleData as ClientMockBundleData } from './client/interceptor'\n\nexport interface AutomockWithBundleOptions extends AutomockPluginOptions {\n bundleMockData?: boolean\n bundleOutputPath?: string\n}\n\nexport function automock(options: AutomockWithBundleOptions = {}): Plugin {\n const {\n bundleMockData = true,\n bundleOutputPath = 'public/mock-data.json',\n ...pluginOptions\n } = options\n\n const basePlugin = createAutomockPlugin(pluginOptions)\n\n let cachedBundle: MockBundle | null = null\n\n const ensureBundleExists = () => {\n const outputPath = path.join(process.cwd(), bundleOutputPath)\n if (!fs.existsSync(outputPath) && cachedBundle) {\n console.log('[automock] Re-writing mock bundle...')\n writeMockBundle(cachedBundle, outputPath)\n }\n }\n\n return {\n ...basePlugin,\n name: 'vite-plugin-automock-with-bundle',\n config() {\n // Inject compile-time constant for client interceptor\n const enabled = pluginOptions.productionMock !== false\n return {\n define: {\n __AUTOMOCK_ENABLED__: JSON.stringify(enabled),\n },\n }\n },\n buildEnd: async () => {\n if (bundleMockData && pluginOptions.productionMock !== false) {\n try {\n const mockDir = pluginOptions.mockDir || path.join(process.cwd(), 'mock')\n\n if (!fs.existsSync(mockDir)) {\n console.log('[automock] Mock directory not found, skipping bundle generation')\n console.log('[automock] Using existing mock-data.json if present')\n return\n }\n\n const mockFileMap = await buildMockIndex(mockDir)\n if (mockFileMap.size === 0) {\n console.log('[automock] No mock files found, skipping bundle generation')\n return\n }\n\n cachedBundle = await bundleMockFiles({ mockDir })\n\n const outputPath = path.join(process.cwd(), bundleOutputPath)\n writeMockBundle(cachedBundle, outputPath)\n console.log(`[automock] Mock bundle written to: ${outputPath}`)\n } catch (error) {\n console.error('[automock] Failed to bundle mock data:', error)\n }\n }\n },\n writeBundle: ensureBundleExists,\n closeBundle: ensureBundleExists,\n }\n}\n\n","import chokidar from \"chokidar\";\nimport debounce from \"lodash.debounce\";\nimport path from \"path\";\nimport fs from \"fs-extra\";\nimport http from \"http\";\nimport https from \"https\";\nimport type { AddressInfo } from \"net\";\n\nimport { buildMockIndex, saveMockData } from \"./mockFileUtils\";\nimport { createInspectorHandler, normalizeInspectorConfig } from \"./inspector\";\nimport {\n resolveAbsolutePath,\n getServerAddress,\n sendError,\n} from \"./utils\";\n\nimport type { Plugin } from \"vite\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { FSWatcher } from \"chokidar\";\nimport type { AutomockPluginOptions } from \"./types\";\n\nfunction serveMockResponse(\n res: ServerResponse,\n mockFilePath: string,\n mockResult: { data?: unknown; delay?: number; status?: number },\n): void {\n const { data, delay = 0, status = 200 } = mockResult;\n\n setTimeout(() => {\n const isBinaryMock = data && typeof data === \"object\" && (data as Record<string, unknown>).__binaryFile;\n\n if (isBinaryMock) {\n const binaryData = data as Record<string, unknown>;\n const binaryFilePath = mockFilePath.replace(\n /\\.js$/,\n \".\" + binaryData.__binaryFile,\n );\n\n if (!fs.existsSync(binaryFilePath)) {\n console.error(\n `[automock] Binary mock file not found: ${binaryFilePath}`,\n );\n sendError(res, \"Binary mock file not found\", 404);\n return;\n }\n\n try {\n const fileData = fs.readFileSync(binaryFilePath);\n const contentType =\n (binaryData.__contentType as string) || \"application/octet-stream\";\n res.setHeader(\"Content-Type\", contentType);\n res.setHeader(\"Content-Length\", fileData.length);\n res.setHeader(\"X-Mock-Response\", \"true\");\n res.setHeader(\"X-Mock-Source\", \"vite-plugin-automock\");\n res.setHeader(\"X-Mock-Binary-File\", \"true\");\n res.statusCode = status;\n res.end(fileData);\n } catch (error) {\n console.error(\"[automock] Failed to read binary mock file:\", error);\n sendError(res, \"Failed to read binary mock file\");\n }\n } else {\n res.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n res.setHeader(\"X-Mock-Response\", \"true\");\n res.setHeader(\"X-Mock-Source\", \"vite-plugin-automock\");\n res.statusCode = status;\n res.end(typeof data === \"string\" ? data : JSON.stringify(data));\n }\n }, delay);\n}\n\nfunction proxyAndCapture(\n req: IncomingMessage,\n res: ServerResponse,\n options: {\n proxyBaseUrl: string;\n pathRewrite: (p: string) => string;\n shouldSave: boolean;\n method: string;\n pathname: string;\n mockDir: string;\n onMockSaved: () => void;\n },\n): void {\n const { proxyBaseUrl, pathRewrite, shouldSave, method, pathname, mockDir, onMockSaved } = options;\n const targetUrl = proxyBaseUrl + pathRewrite(req.url || \"\");\n const client = targetUrl.startsWith(\"https\") ? https : http;\n\n function sendProxyRequest(body?: string) {\n const targetUrlObj = new URL(proxyBaseUrl);\n const proxyOptions = {\n method: req.method,\n headers: {\n ...req.headers,\n host: targetUrlObj.host,\n },\n rejectUnauthorized: false,\n };\n\n const proxyReq = client.request(targetUrl, proxyOptions, (proxyRes) => {\n const contentType = proxyRes.headers[\"content-type\"] || \"\";\n const isJson = contentType.includes(\"application/json\");\n\n // Non-JSON response (file download, stream, etc.) → pipe directly\n if (!isJson) {\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n proxyRes.pipe(res);\n return;\n }\n\n // JSON response → buffer, save mock, then respond\n const chunks: Buffer[] = [];\n\n proxyRes.on(\"data\", (chunk) => chunks.push(chunk));\n proxyRes.on(\"end\", async () => {\n try {\n const responseData = Buffer.concat(chunks);\n\n if (shouldSave) {\n try {\n console.log(\n `[automock] Capturing mock: ${req.url!} -> ${pathname}`,\n );\n const savedFilePath = await saveMockData(\n req.url!,\n method,\n responseData,\n mockDir,\n proxyRes.statusCode,\n contentType,\n );\n if (savedFilePath) {\n console.log(`[automock] Mock saved: ${pathname}`);\n onMockSaved();\n } else {\n console.log(\n `[automock] Mock file already exists, skipped: ${pathname}`,\n );\n }\n } catch (saveError) {\n console.error(\"[automock] Failed to save mock:\", saveError);\n }\n }\n\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n res.end(responseData);\n } catch (error) {\n console.error(\"[automock] Failed to process response:\", error);\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n res.end(Buffer.concat(chunks));\n }\n });\n });\n\n proxyReq.on(\"error\", (err) => {\n console.error(\"[automock] Proxy request failed:\", err);\n sendError(res, err.message);\n });\n\n if (\n body &&\n (req.method === \"POST\" || req.method === \"PUT\" || req.method === \"PATCH\")\n ) {\n proxyReq.write(body);\n }\n\n proxyReq.end();\n }\n\n if (\n req.method === \"POST\" ||\n req.method === \"PUT\" ||\n req.method === \"PATCH\"\n ) {\n let bodyStr = \"\";\n req.on(\"data\", (chunk) => (bodyStr += chunk.toString()));\n req.on(\"end\", () => sendProxyRequest(bodyStr));\n } else {\n sendProxyRequest();\n }\n}\n\nfunction printServerUrls(\n server: { httpServer?: { address(): AddressInfo | string | null; once(event: string, cb: () => void): void } | null; config: { server: { https?: unknown } } },\n urls: Array<{ path: string; label: string; color: string; delay: number }>,\n): void {\n server.httpServer?.once(\"listening\", () => {\n const address = server.httpServer?.address();\n if (!address || typeof address !== \"object\") return;\n\n const { protocol, host, port } = getServerAddress(\n address,\n !!server.config.server.https,\n );\n\n for (const { path: urlPath, label, color, delay } of urls) {\n setTimeout(() => {\n const fullUrl = `${protocol}://${host}:${port}${urlPath}`;\n console.log(` ➜ ${color}${label}\\x1b[0m: \\x1b[1m${fullUrl}\\x1b[0m`);\n }, delay);\n }\n });\n}\n\nexport function automock(options: AutomockPluginOptions): Plugin {\n const {\n mockDir: configMockDir = path.join(process.cwd(), \"mock\"),\n apiPrefix = \"/api\",\n pathRewrite = (p) => p,\n proxyBaseUrl,\n inspector = false,\n } = options;\n\n const mockDir = resolveAbsolutePath(configMockDir);\n\n if (!fs.existsSync(mockDir)) {\n try {\n fs.ensureDirSync(mockDir);\n console.log(`[automock] Mock directory created: ${mockDir}`);\n } catch (error) {\n console.error(`[automock] Failed to create mock directory: ${mockDir}`, error);\n }\n }\n\n let watcher: FSWatcher | undefined;\n\n return {\n name: \"vite-plugin-automock\",\n config(userConfig) {\n if (proxyBaseUrl && userConfig.server?.proxy) {\n const proxyConfig = userConfig.server.proxy;\n const hasConflictingPrefix =\n typeof proxyConfig === \"object\" && apiPrefix in proxyConfig;\n\n if (hasConflictingPrefix) {\n console.warn(\n `\\n⚠️ [automock] WARNING: You have both Vite's server.proxy[\"${apiPrefix}\"] and automock's proxyBaseUrl configured.`,\n );\n console.warn(\n ` This may cause request conflicts. Remove the \"${apiPrefix}\" entry from vite.config.ts server.proxy to avoid issues.`,\n );\n console.warn(\n ` Automock will handle all ${apiPrefix} requests when proxyBaseUrl is set.\\n`,\n );\n }\n }\n },\n async configureServer(server) {\n let mockFileMap = await buildMockIndex(mockDir);\n console.log(`[automock] Loaded ${mockFileMap.size} mock files`);\n\n const rebuildMockFileMap = debounce(async () => {\n mockFileMap = await buildMockIndex(mockDir);\n }, 200);\n\n watcher = chokidar.watch(mockDir, {\n ignoreInitial: true,\n persistent: true,\n depth: 30,\n });\n watcher.on(\"add\", () => rebuildMockFileMap());\n watcher.on(\"unlink\", () => rebuildMockFileMap());\n\n server.httpServer?.on(\"close\", () => watcher?.close());\n\n const inspectorHandler = createInspectorHandler({\n inspector,\n apiPrefix,\n mockDir,\n getMockFileMap: () => mockFileMap,\n });\n\n const urlsToPrint: Array<{ path: string; label: string; color: string; delay: number }> = [\n { path: apiPrefix, label: \"Mock API\", color: \"\\x1b[32m\", delay: 100 },\n ];\n\n if (inspector) {\n const inspectorConfig = normalizeInspectorConfig(inspector);\n urlsToPrint.push({\n path: inspectorConfig.route,\n label: \"Mock Inspector\",\n color: \"\\x1b[95m\",\n delay: 150,\n });\n }\n\n printServerUrls(server, urlsToPrint);\n\n async function tryLoadMock(key: string): Promise<{ absolutePath: string; mockResult: Record<string, unknown> } | null> {\n const mockFilePath = mockFileMap.get(key);\n if (!mockFilePath) return null;\n\n const absolutePath = resolveAbsolutePath(mockFilePath);\n if (!fs.existsSync(absolutePath)) return null;\n\n const { default: mockModule } = await import(\n `${absolutePath}?t=${Date.now()}`\n );\n const mockResult =\n typeof mockModule.data === \"function\"\n ? mockModule.data()\n : mockModule;\n\n const { enable = true } = mockResult || {};\n return enable ? { absolutePath, mockResult } : null;\n }\n\n server.middlewares.use(\n async (\n req: IncomingMessage,\n res: ServerResponse,\n next: (err?: Error | unknown) => void,\n ): Promise<void> => {\n if (inspectorHandler && req.url) {\n const handled = await inspectorHandler(req, res);\n if (handled) return;\n }\n\n if (!req.url?.startsWith(apiPrefix)) {\n return next();\n }\n\n // Skip non-standard requests (SSE, WebSocket, file streams)\n const accept = req.headers.accept || \"\";\n const upgrade = req.headers.upgrade || \"\";\n if (accept.includes(\"text/event-stream\") || upgrade.toLowerCase() === \"websocket\") {\n return next();\n }\n\n const method = (req.method || \"GET\").toLowerCase();\n const pathname = new URL(req.url, \"http://localhost\").pathname;\n const key = `${pathname}/${method}.js`.toLowerCase();\n\n // 1. Try mock\n try {\n const mock = await tryLoadMock(key);\n if (mock) {\n serveMockResponse(res, mock.absolutePath, mock.mockResult);\n return;\n }\n } catch (error) {\n console.error(\"[automock] Failed to load mock file:\", error);\n }\n\n // 2. Try proxy\n if (!proxyBaseUrl) return next();\n\n try {\n proxyAndCapture(req, res, {\n proxyBaseUrl,\n pathRewrite,\n shouldSave: !mockFileMap.has(key),\n method,\n pathname,\n mockDir,\n onMockSaved: async () => {\n mockFileMap = await buildMockIndex(mockDir);\n },\n });\n } catch (error) {\n console.error(\"[automock] Proxy request error:\", error);\n sendError(res, \"Internal server error\");\n }\n },\n );\n },\n closeBundle() {\n watcher?.close();\n },\n transform() {\n return null;\n },\n };\n}\n","import path from \"path\";\nimport fs from \"fs-extra\";\nimport prettier from \"prettier\";\n\nimport { resolveAbsolutePath, toPosixPath } from \"./utils\";\n\nexport interface MockFileConfig {\n enable: boolean;\n data: unknown;\n delay: number;\n status: number;\n [key: string]: unknown;\n}\n\nexport interface MockFileInfo {\n config: MockFileConfig;\n serializable: boolean;\n hasDynamicData: boolean;\n headerComment?: string;\n description?: string;\n dataText: string;\n isBinary?: boolean;\n}\n\nexport const DEFAULT_CONFIG: MockFileConfig = {\n enable: true,\n data: null,\n delay: 0,\n status: 200,\n};\n\nconst isBufferTextLike = (buffer: Buffer): boolean => {\n try {\n const sample = buffer.slice(0, 100);\n const nullBytes = [...sample].filter((b) => b === 0).length;\n const controlChars = [...sample].filter(\n (b) => b < 32 && b !== 9 && b !== 10 && b !== 13,\n ).length;\n return nullBytes === 0 && controlChars < 5;\n } catch {\n return false;\n }\n};\n\nconst isBinaryResponse = (\n contentType: string | undefined,\n data: Buffer,\n): boolean => {\n if (!contentType) return false;\n\n const binaryTypes = [\n \"application/octet-stream\",\n \"application/pdf\",\n \"application/zip\",\n \"application/x-zip-compressed\",\n \"application/vnd.ms-excel\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.ms-powerpoint\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \"image/\",\n \"video/\",\n \"audio/\",\n ];\n\n return (\n binaryTypes.some((type) => contentType.toLowerCase().includes(type)) ||\n !isBufferTextLike(data)\n );\n};\n\nconst getFileExtension = (\n contentType: string | undefined,\n url: string,\n): string => {\n const mimeMap: Record<string, string> = {\n \"application/json\": \"json\",\n \"application/pdf\": \"pdf\",\n \"application/zip\": \"zip\",\n \"application/vnd.ms-excel\": \"xls\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\": \"xlsx\",\n \"application/msword\": \"doc\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\":\n \"docx\",\n \"application/vnd.ms-powerpoint\": \"ppt\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\":\n \"pptx\",\n \"image/jpeg\": \"jpg\",\n \"image/png\": \"png\",\n \"image/gif\": \"gif\",\n \"text/plain\": \"txt\",\n \"text/html\": \"html\",\n \"text/css\": \"css\",\n \"application/javascript\": \"js\",\n \"text/xml\": \"xml\",\n };\n\n if (contentType && mimeMap[contentType.toLowerCase()]) {\n return mimeMap[contentType.toLowerCase()];\n }\n\n try {\n const urlObj = new URL(url, \"http://localhost\");\n const fileName = urlObj.searchParams.get(\"file_name\");\n if (fileName) {\n const extensionMatch = fileName.match(/\\.([a-zA-Z0-9]+)$/);\n if (extensionMatch) {\n return extensionMatch[1];\n }\n }\n } catch {\n // Ignore URL parse errors\n }\n\n return \"bin\";\n};\n\nasync function formatWithPrettier(content: string): Promise<string> {\n try {\n return await prettier.format(content, { parser: \"babel\" });\n } catch {\n return content;\n }\n}\n\nfunction buildMockFileHeader(\n pathname: string,\n method: string,\n search: string,\n extra?: string,\n): string {\n return `/**\n * Mock data for ${pathname} (${method.toUpperCase()})${search || \"\"}\n * @description ${pathname}${search || \"\"}${extra ? ` - ${extra}` : \"\"}\n * Generated at ${new Date().toISOString()}\n */`;\n}\n\nasync function saveBinaryMock(\n filePath: string,\n binaryData: Buffer,\n pathname: string,\n method: string,\n search: string,\n contentType: string | undefined,\n url: string,\n statusCode: number | undefined,\n): Promise<string | null> {\n const extension = getFileExtension(contentType, url);\n const binaryFilePath = filePath.replace(/\\.js$/, \".\" + extension);\n\n if (fs.existsSync(binaryFilePath)) return null;\n\n fs.writeFileSync(binaryFilePath, binaryData);\n\n const header = buildMockFileHeader(pathname, method, search, `Binary file (${extension})`);\n const configContent = `${header}\nexport default {\n enable: false,\n data: {\n __binaryFile: '${extension}',\n __originalPath: '${pathname}',\n __originalQuery: '${search}',\n __originalUrl: '${pathname}${search || \"\"}',\n __contentType: '${contentType}',\n __fileSize: ${binaryData.length}\n },\n delay: 0,\n status: ${statusCode || 200}\n}`;\n\n const formatted = await formatWithPrettier(configContent);\n fs.writeFileSync(filePath, formatted, \"utf-8\");\n return filePath;\n}\n\nasync function saveJsonMock(\n filePath: string,\n dataStr: string,\n pathname: string,\n method: string,\n search: string,\n statusCode: number | undefined,\n): Promise<string | null> {\n if (fs.existsSync(filePath)) return null;\n\n let jsonData;\n if (!dataStr || dataStr.trim() === \"\") {\n jsonData = {\n error: true,\n message: `Empty response (${statusCode || \"unknown status\"})`,\n status: statusCode || 404,\n data: null,\n };\n } else {\n try {\n jsonData = JSON.parse(dataStr);\n if (statusCode && statusCode >= 400) {\n const errorMeta = { __mockStatusCode: statusCode, __isErrorResponse: true };\n jsonData =\n typeof jsonData === \"object\" && jsonData !== null\n ? { ...jsonData, ...errorMeta }\n : { originalData: jsonData, ...errorMeta };\n }\n } catch {\n jsonData = {\n error: true,\n message: `Non-JSON response (${statusCode || \"unknown status\"})`,\n status: statusCode || 404,\n data: dataStr,\n __mockStatusCode: statusCode,\n __isErrorResponse: true,\n };\n }\n }\n\n const header = buildMockFileHeader(pathname, method, search);\n const content = `${header}\nexport default {\n enable: false,\n data: ${JSON.stringify(jsonData)},\n delay: 0,\n status: ${statusCode || 200}\n}`;\n\n const formatted = await formatWithPrettier(content);\n fs.writeFileSync(filePath, formatted, \"utf-8\");\n return filePath;\n}\n\nexport async function saveMockData(\n url: string,\n method: string,\n data: Buffer | string,\n rootDir: string,\n statusCode?: number,\n contentType?: string,\n): Promise<string | null> {\n try {\n const absoluteRootDir = resolveAbsolutePath(rootDir);\n const urlObj = new URL(url, \"http://localhost\");\n const pathname = urlObj.pathname;\n const search = urlObj.search;\n\n const filePath = path.join(\n absoluteRootDir,\n pathname.replace(/^\\//, \"\"),\n method.toLowerCase() + \".js\",\n );\n\n await fs.ensureDir(path.dirname(filePath));\n\n const isBuffer = Buffer.isBuffer(data);\n const binaryData = isBuffer ? data : Buffer.from(data || \"\");\n const isBinary = isBinaryResponse(contentType, binaryData);\n\n if (isBinary) {\n return saveBinaryMock(\n filePath, binaryData, pathname, method, search,\n contentType, url, statusCode,\n );\n }\n\n const dataStr = isBuffer ? data.toString(\"utf8\") : data || \"\";\n return saveJsonMock(filePath, dataStr, pathname, method, search, statusCode);\n } catch (error) {\n console.error(`Failed to save mock data for ${url}:`, error);\n console.error(\n `URL details: url=${url}, method=${method}, statusCode=${statusCode}, contentType=${contentType}`,\n );\n throw error;\n }\n}\n\nconst recursiveReadAllFiles = async (dir: string): Promise<string[]> => {\n if (!(await fs.pathExists(dir))) return [];\n\n const files: string[] = [];\n try {\n const list = await fs.readdir(dir);\n for (const file of list) {\n const filePath = path.join(dir, file);\n const stat = await fs.stat(filePath);\n if (stat.isDirectory()) {\n files.push(...(await recursiveReadAllFiles(filePath)));\n } else {\n files.push(filePath);\n }\n }\n } catch (error) {\n console.error(`Error reading directory ${dir}:`, error);\n }\n return files;\n};\n\nexport async function buildMockIndex(mockDir: string): Promise<Map<string, string>> {\n const mockFileMap = new Map<string, string>();\n\n if (!(await fs.pathExists(mockDir))) {\n await fs.ensureDir(mockDir);\n return mockFileMap;\n }\n\n const files = await recursiveReadAllFiles(mockDir);\n\n files.forEach((filePath) => {\n if (!filePath.endsWith(\".js\")) return;\n\n try {\n const relativePath = path.relative(mockDir, filePath);\n const method = path.basename(filePath, \".js\");\n const dirPath = path.dirname(relativePath);\n const urlPath = \"/\" + toPosixPath(dirPath);\n const absolutePath = resolveAbsolutePath(filePath);\n const key = `${urlPath}/${method}.js`.toLowerCase();\n\n mockFileMap.set(key, absolutePath);\n } catch (error) {\n console.error(`[automock] Failed to process file ${filePath}:`, error);\n }\n });\n\n return mockFileMap;\n}\n\nexport async function parseMockModule(filePath: string): Promise<MockFileInfo> {\n const absolutePath = resolveAbsolutePath(filePath);\n\n if (!fs.existsSync(absolutePath)) {\n throw new Error(`Mock file does not exist: ${absolutePath}`);\n }\n\n const content = fs.readFileSync(absolutePath, \"utf-8\");\n const headerCommentMatch = content.match(/^(\\/\\*\\*[\\s\\S]*?\\*\\/)/);\n const headerComment = headerCommentMatch ? headerCommentMatch[1] : undefined;\n\n let description: string | undefined;\n if (headerComment) {\n const descMatch = headerComment.match(/@description\\s+(.+?)(?:\\n|\\*\\/)/s);\n if (descMatch) {\n description = descMatch[1].trim();\n }\n }\n\n const { default: mockModule } = await import(\n `${absolutePath}?t=${Date.now()}`\n );\n\n const exportedConfig =\n typeof mockModule === \"function\" ? mockModule() : mockModule;\n const hasDynamicData = typeof exportedConfig?.data === \"function\";\n const config: MockFileConfig = {\n ...DEFAULT_CONFIG,\n ...(exportedConfig ?? {}),\n };\n\n const serializable = !hasDynamicData;\n const dataObj =\n typeof config.data === \"object\" && config.data !== null\n ? (config.data as Record<string, unknown>)\n : null;\n const isBinary = dataObj !== null && \"__binaryFile\" in dataObj;\n\n return {\n config,\n serializable,\n hasDynamicData,\n headerComment,\n description,\n dataText: isBinary\n ? `/* Binary file: ${dataObj?.__binaryFile} */`\n : serializable\n ? JSON.stringify(config.data ?? null, null, 2)\n : \"/* data is generated dynamically and cannot be edited here */\",\n isBinary,\n };\n}\n\nexport async function writeMockFile(\n filePath: string,\n mockInfo: Pick<MockFileInfo, \"config\" | \"headerComment\" | \"description\">,\n): Promise<void> {\n const absolutePath = resolveAbsolutePath(filePath);\n\n let header = mockInfo.headerComment || \"\";\n\n if (mockInfo.description !== undefined) {\n if (header) {\n if (/@description/.test(header)) {\n header = header.replace(\n /@description\\s+.+?(?=\\n|\\*\\/)/s,\n `@description ${mockInfo.description}`,\n );\n } else {\n header = header.replace(\n /\\*\\//,\n ` * @description ${mockInfo.description}\\n */`,\n );\n }\n }\n }\n\n const content = header ? `${header}\\n` : \"\";\n const finalContent = `${content}export default ${JSON.stringify(mockInfo.config, null, 2)}\\n`;\n\n try {\n const formatted = await formatWithPrettier(finalContent);\n fs.writeFileSync(absolutePath, formatted, \"utf-8\");\n } catch {\n console.error(\"Error formatting code with prettier, writing raw content\");\n fs.writeFileSync(absolutePath, finalContent, \"utf-8\");\n }\n}\n","import path from \"path\";\n\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { AddressInfo } from \"net\";\n\nexport function resolveAbsolutePath(p: string): string {\n return path.isAbsolute(p) ? p : path.resolve(process.cwd(), p);\n}\n\nexport function toPosixPath(p: string): string {\n return p.replace(/\\\\/g, \"/\");\n}\n\nexport interface ServerAddress {\n protocol: string;\n host: string;\n port: number;\n}\n\nexport function getServerAddress(\n address: AddressInfo,\n isHttps: boolean,\n): ServerAddress {\n return {\n protocol: isHttps ? \"https\" : \"http\",\n host:\n address.address === \"::\" || address.address === \"0.0.0.0\"\n ? \"localhost\"\n : address.address,\n port: address.port,\n };\n}\n\nexport function sendJson(\n res: ServerResponse,\n data: unknown,\n status = 200,\n): void {\n res.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n res.statusCode = status;\n res.end(typeof data === \"string\" ? data : JSON.stringify(data));\n}\n\nexport function sendError(\n res: ServerResponse,\n message: string,\n status = 500,\n): void {\n sendJson(res, { error: message }, status);\n}\n\nconst MAX_BODY_SIZE = 10 * 1024 * 1024; // 10MB\n\nexport function readBody(req: IncomingMessage): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n let totalSize = 0;\n req.on(\"data\", (chunk: Buffer) => {\n totalSize += chunk.length;\n if (totalSize > MAX_BODY_SIZE) {\n reject(new Error(\"Request body too large\"));\n req.destroy();\n return;\n }\n chunks.push(chunk);\n });\n req.on(\"end\", () => resolve(Buffer.concat(chunks).toString(\"utf-8\")));\n req.on(\"error\", reject);\n });\n}\n","import path from \"path\";\nimport fs from \"fs-extra\";\nimport { fileURLToPath } from \"url\";\n\n// ESM/CJS compatible __dirname\nconst _dirName = typeof __dirname !== \"undefined\"\n ? __dirname\n : path.dirname(fileURLToPath(import.meta.url));\nimport { parseMockModule, writeMockFile, saveMockData, buildMockIndex, type MockFileConfig } from \"./mockFileUtils\";\nimport { toPosixPath, sendJson, readBody } from \"./utils\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { AutomockPluginOptions, InspectorOptions } from \"./types\";\n\ninterface InspectorContext {\n req: IncomingMessage;\n res: ServerResponse;\n mockDir: string;\n inspectorRoute: string;\n apiPrefix: string;\n inspectorConfig: Required<InspectorOptions>;\n getMockFileMap: () => Map<string, string>;\n}\n\ninterface InspectorHandlerOptions {\n inspector: AutomockPluginOptions[\"inspector\"];\n apiPrefix: string;\n mockDir: string;\n getMockFileMap: () => Map<string, string>;\n}\n\ninterface InspectorApiContext extends InspectorContext {\n pathname: string;\n}\n\ninterface InspectorPayload {\n key: string;\n config?: Partial<MockFileConfig>;\n description?: string;\n}\n\ninterface MockItem {\n key: string;\n file: string;\n method: string;\n path: string;\n config: MockFileConfig;\n editable: boolean;\n description?: string;\n dataText: string;\n}\n\nfunction buildMockItem(\n key: string,\n filePath: string,\n mockDir: string,\n info: Awaited<ReturnType<typeof parseMockModule>>,\n): MockItem {\n return {\n key,\n file: path.relative(mockDir, filePath),\n method: key.split(\"/\").pop()?.replace(/\\.js$/, \"\") ?? \"get\",\n path: key.replace(/\\/[^/]+\\.js$/, \"\"),\n config: info.config,\n editable: info.serializable,\n description: info.description,\n dataText: info.dataText,\n };\n}\n\nexport const DEFAULT_ROUTE = \"/__mock/\";\n\nfunction ensureTrailingSlash(route: string): string {\n return route.endsWith(\"/\") ? route : `${route}/`;\n}\n\nfunction escapeHtml(value: string): string {\n return value\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nexport function normalizeInspectorConfig(\n input: AutomockPluginOptions[\"inspector\"],\n): Required<InspectorOptions> {\n if (input === false || input === undefined) {\n return { route: DEFAULT_ROUTE, enableToggle: true };\n }\n if (input === true) {\n return { route: DEFAULT_ROUTE, enableToggle: true };\n }\n return {\n route: ensureTrailingSlash(input.route ?? DEFAULT_ROUTE),\n enableToggle: input.enableToggle ?? true,\n };\n}\n\nexport type InspectorRequestHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<boolean>;\n\nexport function createInspectorHandler(\n options: InspectorHandlerOptions,\n): InspectorRequestHandler | null {\n if (!options.inspector) {\n return null;\n }\n\n const inspectorConfig = normalizeInspectorConfig(options.inspector);\n const inspectorRoute = ensureTrailingSlash(inspectorConfig.route);\n\n return async (req, res) => {\n if (!req.url) {\n return false;\n }\n const url = new URL(req.url, \"http://localhost\");\n if (!url.pathname.startsWith(inspectorRoute)) {\n return false;\n }\n\n await handleInspectorRequest({\n req,\n res,\n mockDir: options.mockDir,\n inspectorRoute,\n apiPrefix: options.apiPrefix,\n inspectorConfig,\n getMockFileMap: options.getMockFileMap,\n });\n\n return true;\n };\n}\n\nasync function handleInspectorRequest(\n context: InspectorContext,\n): Promise<void> {\n const { req, res, inspectorRoute } = context;\n const url = new URL(req.url || inspectorRoute, \"http://localhost\");\n const normalizedRoute = ensureTrailingSlash(inspectorRoute);\n\n if (\n url.pathname === normalizedRoute.slice(0, -1) ||\n url.pathname === normalizedRoute\n ) {\n await serveInspectorHtml(context);\n return;\n }\n\n const relativePath = url.pathname.startsWith(normalizedRoute)\n ? url.pathname.slice(normalizedRoute.length)\n : null;\n\n if (relativePath && relativePath.startsWith(\"api/\")) {\n await handleInspectorApi({ ...context, pathname: relativePath.slice(4) });\n return;\n }\n\n res.statusCode = 404;\n res.end(\"Not Found\");\n}\n\nasync function serveInspectorHtml({\n res,\n inspectorRoute,\n apiPrefix,\n inspectorConfig,\n}: InspectorContext): Promise<void> {\n const routeJson = JSON.stringify(ensureTrailingSlash(inspectorRoute));\n const allowToggleJson = JSON.stringify(inspectorConfig.enableToggle);\n const apiPrefixEscaped = escapeHtml(apiPrefix);\n\n const templatePath = path.join(_dirName, \"inspector-template.html\");\n const template = fs.readFileSync(templatePath, \"utf-8\");\n const html = template\n .replace(\"__API_PREFIX__\", apiPrefixEscaped)\n .replace(\"__ROUTE_JSON__\", routeJson)\n .replace(\"__ALLOW_TOGGLE_JSON__\", allowToggleJson);\n\n res.setHeader(\"Content-Type\", \"text/html; charset=utf-8\");\n res.end(html);\n}\n\nasync function handleList(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { res, mockDir } = ctx;\n const list = await Promise.all(\n Array.from(mockFileMap.entries()).map(async ([key, filePath]) => {\n const info = await parseMockModule(filePath);\n return buildMockItem(key, filePath, mockDir, info);\n }),\n );\n sendJson(res, { mocks: list });\n return true;\n}\n\nasync function handleDetail(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir } = ctx;\n const url = new URL(req.url || \"\", \"http://localhost\");\n const key = url.searchParams.get(\"key\");\n if (!key) {\n sendJson(res, { error: \"Missing key\" }, 400);\n return true;\n }\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n const info = await parseMockModule(filePath);\n sendJson(res, { mock: buildMockItem(key, filePath, mockDir, info) });\n return true;\n}\n\nasync function handleUpdate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir, inspectorConfig } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: InspectorPayload;\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const { key, config, description } = payload || {};\n if (!key) {\n sendJson(res, { error: \"Invalid payload: missing key\" }, 400);\n return true;\n }\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n\n const info = await parseMockModule(filePath);\n\n let nextConfig = info.config;\n if (config && typeof config === \"object\") {\n if (!inspectorConfig.enableToggle && config.enable !== undefined) {\n delete config.enable;\n }\n nextConfig = { ...info.config, ...config };\n }\n\n const nextDescription =\n description !== undefined ? description : info.description;\n\n await writeMockFile(filePath, {\n headerComment: info.headerComment,\n config: nextConfig,\n description: nextDescription,\n });\n\n const updatedInfo = await parseMockModule(filePath);\n sendJson(res, { mock: buildMockItem(key, filePath, mockDir, updatedInfo) });\n return true;\n}\n\nasync function handleCreate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir, apiPrefix } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: { method: string; path: string; description?: string; data?: unknown };\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const { method, path: apiPath, data } = payload || {};\n if (!method || !apiPath) {\n sendJson(res, { error: \"Invalid payload: missing method or path\" }, 400);\n return true;\n }\n\n const fullUrl = apiPrefix + apiPath;\n\n try {\n let dataToSave: Buffer | string;\n if (typeof data === \"object\" && data !== null) {\n dataToSave = JSON.stringify(data, null, 2);\n } else {\n dataToSave = typeof data === \"string\" ? data : \"\";\n }\n\n await saveMockData(fullUrl, method.toLowerCase(), dataToSave, mockDir, 200);\n\n const newMockFileMap = await buildMockIndex(mockDir);\n for (const [key, value] of newMockFileMap.entries()) {\n mockFileMap.set(key, value);\n }\n\n const normalizedPath = toPosixPath(apiPath);\n const key = (normalizedPath.startsWith(\"/\") ? \"\" : \"/\") +\n normalizedPath.toLowerCase() + \"/\" + method.toLowerCase() + \".js\";\n const filePath = mockFileMap.get(key);\n\n if (!filePath) {\n sendJson(res, { error: \"Mock file created but not found in map\" }, 500);\n return true;\n }\n\n const info = await parseMockModule(filePath);\n sendJson(res, {\n success: true,\n mock: buildMockItem(key, filePath, mockDir, info),\n });\n return true;\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n sendJson(res, { error: \"Failed to create mock: \" + errorMessage }, 500);\n return true;\n }\n}\n\nasync function handleDelete(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res } = ctx;\n const url = new URL(req.url || \"\", \"http://localhost\");\n const key = url.searchParams.get(\"key\");\n if (!key) {\n sendJson(res, { error: \"Missing key\" }, 400);\n return true;\n }\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n\n try {\n const stats = await fs.stat(filePath);\n if (stats.isDirectory()) {\n await fs.remove(filePath);\n for (const [mapKey, mapPath] of mockFileMap.entries()) {\n if (mapPath.startsWith(filePath + path.sep) || mapPath === filePath) {\n mockFileMap.delete(mapKey);\n }\n }\n } else {\n await fs.unlink(filePath);\n mockFileMap.delete(key);\n }\n sendJson(res, { success: true });\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n sendJson(res, { error: \"Failed to delete: \" + errorMessage }, 500);\n }\n return true;\n}\n\ntype ApiHandler = (ctx: InspectorApiContext, mockFileMap: Map<string, string>) => Promise<boolean>;\n\nasync function handleBatchUpdate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: { updates?: Array<{ key: string; config?: Record<string, unknown> }> };\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const updates = payload?.updates;\n if (!Array.isArray(updates) || updates.length === 0) {\n sendJson(res, { error: \"Invalid payload: updates must be a non-empty array\" }, 400);\n return true;\n }\n\n let updated = 0;\n const errors: string[] = [];\n\n for (const item of updates) {\n const { key, config } = item;\n if (!key) continue;\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n errors.push(`Mock not found: ${key}`);\n continue;\n }\n\n try {\n const info = await parseMockModule(filePath);\n const nextConfig = config ? { ...info.config, ...config } : info.config;\n\n await writeMockFile(filePath, {\n headerComment: info.headerComment,\n config: nextConfig,\n description: info.description,\n });\n updated++;\n } catch (err) {\n errors.push(`Failed to update ${key}: ${err instanceof Error ? err.message : String(err)}`);\n }\n }\n\n sendJson(res, { success: true, updated, errors: errors.length > 0 ? errors : undefined });\n return true;\n}\n\nconst API_ROUTES: Record<string, ApiHandler> = {\n list: handleList,\n detail: handleDetail,\n update: handleUpdate,\n \"batch-update\": handleBatchUpdate,\n create: handleCreate,\n delete: handleDelete,\n};\n\nasync function handleInspectorApi(ctx: InspectorApiContext): Promise<void> {\n try {\n const mockFileMap = ctx.getMockFileMap();\n const handler = API_ROUTES[ctx.pathname];\n if (handler) {\n await handler(ctx, mockFileMap);\n return;\n }\n sendJson(ctx.res, { error: \"Unknown inspector endpoint\" }, 404);\n } catch (error) {\n console.error(\"[automock] Inspector request failed:\", error);\n sendJson(ctx.res, { error: \"Inspector failed\" }, 500);\n }\n}\n","import path from 'path'\nimport fs from 'fs-extra'\n\nimport { buildMockIndex, parseMockModule } from './mockFileUtils'\n\nexport interface MockBundleData {\n enable: boolean\n data: unknown\n delay: number\n status: number\n isBinary?: boolean\n}\n\nexport interface MockBundle {\n [key: string]: MockBundleData\n}\n\nexport interface BundleOptions {\n mockDir: string\n includeDisabled?: boolean\n log?: boolean\n}\n\nconst DEFAULT_BUNDLE_OPTIONS: Partial<BundleOptions> = {\n includeDisabled: true,\n log: true\n}\n\nasync function bundleMockFiles(options: BundleOptions): Promise<MockBundle> {\n const opts = { ...DEFAULT_BUNDLE_OPTIONS, ...options }\n const { mockDir, log } = opts\n\n if (!fs.existsSync(mockDir)) {\n if (log) {\n console.log(`[mock-bundler] Mock directory does not exist: ${mockDir}`)\n }\n return {}\n }\n\n const mockFileMap = await buildMockIndex(mockDir)\n const bundle: MockBundle = {}\n let bundledCount = 0\n let skippedCount = 0\n\n for (const [key, filePath] of mockFileMap) {\n try {\n const mockInfo = await parseMockModule(filePath)\n\n if (!mockInfo.serializable) {\n skippedCount++\n if (log) {\n console.log(`[mock-bundler] Skipping non-serializable mock: ${key}`)\n }\n continue\n }\n\n bundle[key] = {\n enable: mockInfo.config.enable,\n data: mockInfo.config.data,\n delay: mockInfo.config.delay,\n status: mockInfo.config.status,\n isBinary: mockInfo.isBinary\n }\n\n bundledCount++\n } catch (error) {\n if (log) {\n console.error(`[mock-bundler] Failed to bundle mock ${key}:`, error)\n }\n }\n }\n\n if (log) {\n console.log(`[mock-bundler] Bundled ${bundledCount} mocks, skipped ${skippedCount} non-serializable mocks`)\n }\n\n return bundle\n}\n\nfunction writeMockBundle(bundle: MockBundle, outputPath: string): void {\n const outputDir = path.dirname(outputPath)\n\n if (!fs.existsSync(outputDir)) {\n fs.ensureDirSync(outputDir)\n }\n\n fs.writeFileSync(\n outputPath,\n JSON.stringify(bundle, null, 2),\n 'utf-8'\n )\n}\n\nexport { bundleMockFiles, writeMockBundle }\n","import type {\n AxiosInstance,\n AxiosResponse,\n InternalAxiosRequestConfig,\n} from \"axios\";\n\ndeclare const __AUTOMOCK_ENABLED__: boolean;\n\nexport type MockBundleData = {\n enable: boolean;\n data: unknown;\n delay?: number;\n status?: number;\n isBinary?: boolean;\n};\n\nexport type MockInterceptorOptions = {\n mockData: Record<string, MockBundleData>;\n enabled?: boolean | (() => boolean);\n onMockHit?: (url: string, method: string, mock: MockBundleData) => void;\n onBypass?: (url: string, method: string, reason: string) => void;\n};\n\ntype MockEnabledState = boolean | undefined;\n\ndeclare global {\n interface Window {\n __MOCK_ENABLED__?: MockEnabledState;\n }\n}\n\nclass MockInterceptor {\n private options: MockInterceptorOptions;\n\n constructor(options: MockInterceptorOptions) {\n this.options = options;\n }\n\n /**\n * Check if mock is enabled\n */\n isEnabled(): boolean {\n // Check runtime flag first\n if (window.__MOCK_ENABLED__ !== undefined) {\n return window.__MOCK_ENABLED__;\n }\n // Check environment variable\n if (typeof this.options.enabled === \"function\") {\n return this.options.enabled();\n }\n return this.options.enabled ?? false;\n }\n\n /**\n * Find matching mock data for the request\n * Supports both formats:\n * - \"GET /api/v1/asset/xxx\" (HTTP method + URL)\n * - \"/api/v1/asset/xxx/get.js\" (File path format from automock plugin)\n */\n private findMock(url: string, method: string): MockBundleData | null {\n const methodUpper = method.toUpperCase();\n const methodLower = method.toLowerCase();\n\n // Try HTTP method + URL format first (for compatibility)\n const httpMethodKey = `${methodUpper} ${url}`;\n if (this.options.mockData[httpMethodKey]) {\n return this.options.mockData[httpMethodKey];\n }\n\n // Try file path format from automock plugin: /api/v1/asset/xxx/get.js\n const filePathKey = `${url}/${methodLower}.js`;\n if (this.options.mockData[filePathKey]) {\n return this.options.mockData[filePathKey];\n }\n\n return null;\n }\n\n /**\n * Determine if request should be mocked\n */\n shouldMock(url: string, method: string): boolean {\n if (!this.isEnabled()) {\n return false;\n }\n\n const mock = this.findMock(url, method);\n return mock !== null && mock.enable;\n }\n\n /**\n * Get mock data for request\n */\n getMock(url: string, method: string): MockBundleData | null {\n if (!this.shouldMock(url, method)) {\n return null;\n }\n return this.findMock(url, method);\n }\n\n /**\n * Setup axios interceptor\n */\n setupAxios(axiosInstance: AxiosInstance): void {\n axiosInstance.interceptors.request.use(\n async (config: InternalAxiosRequestConfig) => {\n const url = config.url || \"\";\n const method = config.method?.toUpperCase() || \"GET\";\n\n const mock = this.getMock(url, method);\n\n if (mock) {\n // Trigger mock hit callback\n this.options.onMockHit?.(url, method, mock);\n\n // Set adapter to return mock data\n (config as InternalAxiosRequestConfig & { adapter: () => Promise<AxiosResponse> }).adapter = async () => {\n const { data, delay = 0, status = 200 } = mock;\n\n // Simulate delay\n if (delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n\n return {\n data,\n status,\n statusText: \"OK\",\n headers: {},\n config,\n };\n };\n } else {\n // Trigger bypass callback\n const reason = !this.isEnabled()\n ? \"Mock disabled globally\"\n : \"No matching mock found or mock disabled\";\n this.options.onBypass?.(url, method, reason);\n }\n\n return config;\n },\n (error: unknown) => Promise.reject(error),\n );\n }\n}\n\n/**\n * Create mock interceptor instance\n */\nexport function createMockInterceptor(\n options: MockInterceptorOptions,\n): MockInterceptor {\n return new MockInterceptor(options);\n}\n\n/**\n * Load mock data from bundled JSON file\n */\nexport async function loadMockData(): Promise<Record<string, MockBundleData>> {\n try {\n // In production, mock-data.json is generated by automock plugin\n // Use absolute path to load it from dist directory\n const response = await fetch(\"/mock-data.json\");\n if (!response.ok) {\n console.warn(\n \"[MockInterceptor] Failed to load mock-data.json:\",\n response.statusText,\n );\n return {};\n }\n const data = (await response.json()) as Record<string, MockBundleData>;\n return data;\n } catch (error) {\n console.warn(\"[MockInterceptor] Failed to load mock-data.json:\", error);\n return {};\n }\n}\n\nasync function createInterceptorFromBundle(): Promise<MockInterceptor> {\n const mockData = await loadMockData();\n const isEnabled = typeof __AUTOMOCK_ENABLED__ !== \"undefined\" && __AUTOMOCK_ENABLED__;\n\n return new MockInterceptor({\n mockData,\n enabled: isEnabled,\n onMockHit: (url: string, method: string) => {\n console.log(`[MOCK HIT] ${method} ${url}`);\n },\n onBypass: (url: string, method: string, reason: string) => {\n console.log(`[MOCK BYPASS] ${method} ${url} - ${reason}`);\n },\n });\n}\n\nexport async function initMockInterceptor(\n axiosInstance?: AxiosInstance,\n): Promise<void> {\n if (!axiosInstance) {\n throw new Error(\n \"[MockInterceptor] axiosInstance is required. Please provide an axios instance.\",\n );\n }\n\n const interceptor = await createInterceptorFromBundle();\n interceptor.setupAxios(axiosInstance);\n}\n\nexport function setMockEnabled(enabled: boolean): void {\n window.__MOCK_ENABLED__ = enabled;\n}\n\nexport function isMockEnabled(): boolean {\n return !!window.__MOCK_ENABLED__;\n}\n\ntype HttpInstance = {\n constructor: { axiosInstance: AxiosInstance };\n};\n\nlet httpInstanceRef: HttpInstance | undefined;\n\nexport function registerHttpInstance(http: HttpInstance): void {\n httpInstanceRef = http;\n}\n\nexport async function initMockInterceptorForPureHttp(): Promise<void> {\n if (!httpInstanceRef) {\n throw new Error(\n \"[MockInterceptor] http instance not registered. Call registerHttpInstance(http) first.\",\n );\n }\n\n const interceptor = await createInterceptorFromBundle();\n interceptor.setupAxios(httpInstanceRef.constructor.axiosInstance);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AC5D,0BAAgB,cAAc,UAAU;AACxC,kBAAQ,IAAI,sCAAsC,UAAU,EAAE;AAAA,QAChE,SAAS,OAAO;AACd,kBAAQ,MAAM,0CAA0C,KAAK;AAAA,QAC/D;AAAA,MACF;AAAA,IACF;AAAA,IACA,aAAa;AAAA,IACb,aAAa;AAAA,EACf;AACF;","names":["automock","import_path","import_fs_extra","import_path","import_fs_extra","import_path","path","prettier","fs","path","import_path","import_fs_extra","path","fs","key","fs","https","http","path","debounce","chokidar","import_path","import_fs_extra","fs","path","http","automock","path","fs"]}
|
package/dist/index.mjs
CHANGED
|
@@ -368,6 +368,8 @@ async function writeMockFile(filePath, mockInfo) {
|
|
|
368
368
|
// src/inspector.ts
|
|
369
369
|
import path3 from "path";
|
|
370
370
|
import fs2 from "fs-extra";
|
|
371
|
+
import { fileURLToPath } from "url";
|
|
372
|
+
var _dirName = typeof __dirname !== "undefined" ? __dirname : path3.dirname(fileURLToPath(import.meta.url));
|
|
371
373
|
function buildMockItem(key, filePath, mockDir, info) {
|
|
372
374
|
return {
|
|
373
375
|
key,
|
|
@@ -450,7 +452,7 @@ async function serveInspectorHtml({
|
|
|
450
452
|
const routeJson = JSON.stringify(ensureTrailingSlash(inspectorRoute));
|
|
451
453
|
const allowToggleJson = JSON.stringify(inspectorConfig.enableToggle);
|
|
452
454
|
const apiPrefixEscaped = escapeHtml(apiPrefix);
|
|
453
|
-
const templatePath = path3.join(
|
|
455
|
+
const templatePath = path3.join(_dirName, "inspector-template.html");
|
|
454
456
|
const template = fs2.readFileSync(templatePath, "utf-8");
|
|
455
457
|
const html = template.replace("__API_PREFIX__", apiPrefixEscaped).replace("__ROUTE_JSON__", routeJson).replace("__ALLOW_TOGGLE_JSON__", allowToggleJson);
|
|
456
458
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
@@ -793,10 +795,8 @@ function proxyAndCapture(req, res, options) {
|
|
|
793
795
|
let bodyStr = "";
|
|
794
796
|
req.on("data", (chunk) => bodyStr += chunk.toString());
|
|
795
797
|
req.on("end", () => sendProxyRequest(bodyStr));
|
|
796
|
-
} else if (req.readableEnded) {
|
|
797
|
-
sendProxyRequest();
|
|
798
798
|
} else {
|
|
799
|
-
|
|
799
|
+
sendProxyRequest();
|
|
800
800
|
}
|
|
801
801
|
}
|
|
802
802
|
function printServerUrls(server, urls) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/middleware.ts","../src/mockFileUtils.ts","../src/utils.ts","../src/inspector.ts","../src/mockBundler.ts"],"sourcesContent":["import path from 'path'\nimport fs from 'fs-extra'\n\nimport { automock as createAutomockPlugin } from './middleware'\nimport { bundleMockFiles, writeMockBundle } from './mockBundler'\nimport { buildMockIndex } from './mockFileUtils'\nimport type { Plugin } from 'vite'\nimport type { AutomockPluginOptions } from './types'\nimport type { MockBundle } from './mockBundler'\n\nexport type { AutomockPluginOptions, InspectorOptions } from './types'\nexport { saveMockData, buildMockIndex, parseMockModule, writeMockFile } from './mockFileUtils'\nexport type { MockBundle, MockBundleData } from './mockBundler'\nexport { bundleMockFiles, writeMockBundle } from './mockBundler'\n\n// Client interceptor exports\nexport {\n createMockInterceptor,\n initMockInterceptor,\n initMockInterceptorForPureHttp,\n setMockEnabled,\n isMockEnabled,\n loadMockData,\n registerHttpInstance\n} from './client'\nexport type { MockInterceptorOptions, MockBundleData as ClientMockBundleData } from './client/interceptor'\n\nexport interface AutomockWithBundleOptions extends AutomockPluginOptions {\n bundleMockData?: boolean\n bundleOutputPath?: string\n}\n\nexport function automock(options: AutomockWithBundleOptions = {}): Plugin {\n const {\n bundleMockData = true,\n bundleOutputPath = 'public/mock-data.json',\n ...pluginOptions\n } = options\n\n const basePlugin = createAutomockPlugin(pluginOptions)\n\n let cachedBundle: MockBundle | null = null\n\n const ensureBundleExists = () => {\n const outputPath = path.join(process.cwd(), bundleOutputPath)\n if (!fs.existsSync(outputPath) && cachedBundle) {\n console.log('[automock] Re-writing mock bundle...')\n writeMockBundle(cachedBundle, outputPath)\n }\n }\n\n return {\n ...basePlugin,\n name: 'vite-plugin-automock-with-bundle',\n config() {\n // Inject compile-time constant for client interceptor\n const enabled = pluginOptions.productionMock !== false\n return {\n define: {\n __AUTOMOCK_ENABLED__: JSON.stringify(enabled),\n },\n }\n },\n buildEnd: async () => {\n if (bundleMockData && pluginOptions.productionMock !== false) {\n try {\n const mockDir = pluginOptions.mockDir || path.join(process.cwd(), 'mock')\n\n if (!fs.existsSync(mockDir)) {\n console.log('[automock] Mock directory not found, skipping bundle generation')\n console.log('[automock] Using existing mock-data.json if present')\n return\n }\n\n const mockFileMap = await buildMockIndex(mockDir)\n if (mockFileMap.size === 0) {\n console.log('[automock] No mock files found, skipping bundle generation')\n return\n }\n\n cachedBundle = await bundleMockFiles({ mockDir })\n\n const outputPath = path.join(process.cwd(), bundleOutputPath)\n writeMockBundle(cachedBundle, outputPath)\n console.log(`[automock] Mock bundle written to: ${outputPath}`)\n } catch (error) {\n console.error('[automock] Failed to bundle mock data:', error)\n }\n }\n },\n writeBundle: ensureBundleExists,\n closeBundle: ensureBundleExists,\n }\n}\n\n","import chokidar from \"chokidar\";\nimport debounce from \"lodash.debounce\";\nimport path from \"path\";\nimport fs from \"fs-extra\";\nimport http from \"http\";\nimport https from \"https\";\nimport type { AddressInfo } from \"net\";\n\nimport { buildMockIndex, saveMockData } from \"./mockFileUtils\";\nimport { createInspectorHandler, normalizeInspectorConfig } from \"./inspector\";\nimport {\n resolveAbsolutePath,\n getServerAddress,\n sendError,\n} from \"./utils\";\n\nimport type { Plugin } from \"vite\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { FSWatcher } from \"chokidar\";\nimport type { AutomockPluginOptions } from \"./types\";\n\nfunction serveMockResponse(\n res: ServerResponse,\n mockFilePath: string,\n mockResult: { data?: unknown; delay?: number; status?: number },\n): void {\n const { data, delay = 0, status = 200 } = mockResult;\n\n setTimeout(() => {\n const isBinaryMock = data && typeof data === \"object\" && (data as Record<string, unknown>).__binaryFile;\n\n if (isBinaryMock) {\n const binaryData = data as Record<string, unknown>;\n const binaryFilePath = mockFilePath.replace(\n /\\.js$/,\n \".\" + binaryData.__binaryFile,\n );\n\n if (!fs.existsSync(binaryFilePath)) {\n console.error(\n `[automock] Binary mock file not found: ${binaryFilePath}`,\n );\n sendError(res, \"Binary mock file not found\", 404);\n return;\n }\n\n try {\n const fileData = fs.readFileSync(binaryFilePath);\n const contentType =\n (binaryData.__contentType as string) || \"application/octet-stream\";\n res.setHeader(\"Content-Type\", contentType);\n res.setHeader(\"Content-Length\", fileData.length);\n res.setHeader(\"X-Mock-Response\", \"true\");\n res.setHeader(\"X-Mock-Source\", \"vite-plugin-automock\");\n res.setHeader(\"X-Mock-Binary-File\", \"true\");\n res.statusCode = status;\n res.end(fileData);\n } catch (error) {\n console.error(\"[automock] Failed to read binary mock file:\", error);\n sendError(res, \"Failed to read binary mock file\");\n }\n } else {\n res.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n res.setHeader(\"X-Mock-Response\", \"true\");\n res.setHeader(\"X-Mock-Source\", \"vite-plugin-automock\");\n res.statusCode = status;\n res.end(typeof data === \"string\" ? data : JSON.stringify(data));\n }\n }, delay);\n}\n\nfunction proxyAndCapture(\n req: IncomingMessage,\n res: ServerResponse,\n options: {\n proxyBaseUrl: string;\n pathRewrite: (p: string) => string;\n shouldSave: boolean;\n method: string;\n pathname: string;\n mockDir: string;\n onMockSaved: () => void;\n },\n): void {\n const { proxyBaseUrl, pathRewrite, shouldSave, method, pathname, mockDir, onMockSaved } = options;\n const targetUrl = proxyBaseUrl + pathRewrite(req.url || \"\");\n const client = targetUrl.startsWith(\"https\") ? https : http;\n\n function sendProxyRequest(body?: string) {\n const targetUrlObj = new URL(proxyBaseUrl);\n const proxyOptions = {\n method: req.method,\n headers: {\n ...req.headers,\n host: targetUrlObj.host,\n },\n rejectUnauthorized: false,\n };\n\n const proxyReq = client.request(targetUrl, proxyOptions, (proxyRes) => {\n const contentType = proxyRes.headers[\"content-type\"] || \"\";\n const isJson = contentType.includes(\"application/json\");\n\n // Non-JSON response (file download, stream, etc.) → pipe directly\n if (!isJson) {\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n proxyRes.pipe(res);\n return;\n }\n\n // JSON response → buffer, save mock, then respond\n const chunks: Buffer[] = [];\n\n proxyRes.on(\"data\", (chunk) => chunks.push(chunk));\n proxyRes.on(\"end\", async () => {\n try {\n const responseData = Buffer.concat(chunks);\n\n if (shouldSave) {\n try {\n console.log(\n `[automock] Capturing mock: ${req.url!} -> ${pathname}`,\n );\n const savedFilePath = await saveMockData(\n req.url!,\n method,\n responseData,\n mockDir,\n proxyRes.statusCode,\n contentType,\n );\n if (savedFilePath) {\n console.log(`[automock] Mock saved: ${pathname}`);\n onMockSaved();\n } else {\n console.log(\n `[automock] Mock file already exists, skipped: ${pathname}`,\n );\n }\n } catch (saveError) {\n console.error(\"[automock] Failed to save mock:\", saveError);\n }\n }\n\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n res.end(responseData);\n } catch (error) {\n console.error(\"[automock] Failed to process response:\", error);\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n res.end(Buffer.concat(chunks));\n }\n });\n });\n\n proxyReq.on(\"error\", (err) => {\n console.error(\"[automock] Proxy request failed:\", err);\n sendError(res, err.message);\n });\n\n if (\n body &&\n (req.method === \"POST\" || req.method === \"PUT\" || req.method === \"PATCH\")\n ) {\n proxyReq.write(body);\n }\n\n proxyReq.end();\n }\n\n if (\n req.method === \"POST\" ||\n req.method === \"PUT\" ||\n req.method === \"PATCH\"\n ) {\n let bodyStr = \"\";\n req.on(\"data\", (chunk) => (bodyStr += chunk.toString()));\n req.on(\"end\", () => sendProxyRequest(bodyStr));\n } else if (req.readableEnded) {\n sendProxyRequest();\n } else {\n req.on(\"end\", () => sendProxyRequest());\n }\n}\n\nfunction printServerUrls(\n server: { httpServer?: { address(): AddressInfo | string | null; once(event: string, cb: () => void): void } | null; config: { server: { https?: unknown } } },\n urls: Array<{ path: string; label: string; color: string; delay: number }>,\n): void {\n server.httpServer?.once(\"listening\", () => {\n const address = server.httpServer?.address();\n if (!address || typeof address !== \"object\") return;\n\n const { protocol, host, port } = getServerAddress(\n address,\n !!server.config.server.https,\n );\n\n for (const { path: urlPath, label, color, delay } of urls) {\n setTimeout(() => {\n const fullUrl = `${protocol}://${host}:${port}${urlPath}`;\n console.log(` ➜ ${color}${label}\\x1b[0m: \\x1b[1m${fullUrl}\\x1b[0m`);\n }, delay);\n }\n });\n}\n\nexport function automock(options: AutomockPluginOptions): Plugin {\n const {\n mockDir: configMockDir = path.join(process.cwd(), \"mock\"),\n apiPrefix = \"/api\",\n pathRewrite = (p) => p,\n proxyBaseUrl,\n inspector = false,\n } = options;\n\n const mockDir = resolveAbsolutePath(configMockDir);\n\n if (!fs.existsSync(mockDir)) {\n try {\n fs.ensureDirSync(mockDir);\n console.log(`[automock] Mock directory created: ${mockDir}`);\n } catch (error) {\n console.error(`[automock] Failed to create mock directory: ${mockDir}`, error);\n }\n }\n\n let watcher: FSWatcher | undefined;\n\n return {\n name: \"vite-plugin-automock\",\n config(userConfig) {\n if (proxyBaseUrl && userConfig.server?.proxy) {\n const proxyConfig = userConfig.server.proxy;\n const hasConflictingPrefix =\n typeof proxyConfig === \"object\" && apiPrefix in proxyConfig;\n\n if (hasConflictingPrefix) {\n console.warn(\n `\\n⚠️ [automock] WARNING: You have both Vite's server.proxy[\"${apiPrefix}\"] and automock's proxyBaseUrl configured.`,\n );\n console.warn(\n ` This may cause request conflicts. Remove the \"${apiPrefix}\" entry from vite.config.ts server.proxy to avoid issues.`,\n );\n console.warn(\n ` Automock will handle all ${apiPrefix} requests when proxyBaseUrl is set.\\n`,\n );\n }\n }\n },\n async configureServer(server) {\n let mockFileMap = await buildMockIndex(mockDir);\n console.log(`[automock] Loaded ${mockFileMap.size} mock files`);\n\n const rebuildMockFileMap = debounce(async () => {\n mockFileMap = await buildMockIndex(mockDir);\n }, 200);\n\n watcher = chokidar.watch(mockDir, {\n ignoreInitial: true,\n persistent: true,\n depth: 30,\n });\n watcher.on(\"add\", () => rebuildMockFileMap());\n watcher.on(\"unlink\", () => rebuildMockFileMap());\n\n server.httpServer?.on(\"close\", () => watcher?.close());\n\n const inspectorHandler = createInspectorHandler({\n inspector,\n apiPrefix,\n mockDir,\n getMockFileMap: () => mockFileMap,\n });\n\n const urlsToPrint: Array<{ path: string; label: string; color: string; delay: number }> = [\n { path: apiPrefix, label: \"Mock API\", color: \"\\x1b[32m\", delay: 100 },\n ];\n\n if (inspector) {\n const inspectorConfig = normalizeInspectorConfig(inspector);\n urlsToPrint.push({\n path: inspectorConfig.route,\n label: \"Mock Inspector\",\n color: \"\\x1b[95m\",\n delay: 150,\n });\n }\n\n printServerUrls(server, urlsToPrint);\n\n async function tryLoadMock(key: string): Promise<{ absolutePath: string; mockResult: Record<string, unknown> } | null> {\n const mockFilePath = mockFileMap.get(key);\n if (!mockFilePath) return null;\n\n const absolutePath = resolveAbsolutePath(mockFilePath);\n if (!fs.existsSync(absolutePath)) return null;\n\n const { default: mockModule } = await import(\n `${absolutePath}?t=${Date.now()}`\n );\n const mockResult =\n typeof mockModule.data === \"function\"\n ? mockModule.data()\n : mockModule;\n\n const { enable = true } = mockResult || {};\n return enable ? { absolutePath, mockResult } : null;\n }\n\n server.middlewares.use(\n async (\n req: IncomingMessage,\n res: ServerResponse,\n next: (err?: Error | unknown) => void,\n ): Promise<void> => {\n if (inspectorHandler && req.url) {\n const handled = await inspectorHandler(req, res);\n if (handled) return;\n }\n\n if (!req.url?.startsWith(apiPrefix)) {\n return next();\n }\n\n // Skip non-standard requests (SSE, WebSocket, file streams)\n const accept = req.headers.accept || \"\";\n const upgrade = req.headers.upgrade || \"\";\n if (accept.includes(\"text/event-stream\") || upgrade.toLowerCase() === \"websocket\") {\n return next();\n }\n\n const method = (req.method || \"GET\").toLowerCase();\n const pathname = new URL(req.url, \"http://localhost\").pathname;\n const key = `${pathname}/${method}.js`.toLowerCase();\n\n // 1. Try mock\n try {\n const mock = await tryLoadMock(key);\n if (mock) {\n serveMockResponse(res, mock.absolutePath, mock.mockResult);\n return;\n }\n } catch (error) {\n console.error(\"[automock] Failed to load mock file:\", error);\n }\n\n // 2. Try proxy\n if (!proxyBaseUrl) return next();\n\n try {\n proxyAndCapture(req, res, {\n proxyBaseUrl,\n pathRewrite,\n shouldSave: !mockFileMap.has(key),\n method,\n pathname,\n mockDir,\n onMockSaved: async () => {\n mockFileMap = await buildMockIndex(mockDir);\n },\n });\n } catch (error) {\n console.error(\"[automock] Proxy request error:\", error);\n sendError(res, \"Internal server error\");\n }\n },\n );\n },\n closeBundle() {\n watcher?.close();\n },\n transform() {\n return null;\n },\n };\n}\n","import path from \"path\";\nimport fs from \"fs-extra\";\nimport prettier from \"prettier\";\n\nimport { resolveAbsolutePath, toPosixPath } from \"./utils\";\n\nexport interface MockFileConfig {\n enable: boolean;\n data: unknown;\n delay: number;\n status: number;\n [key: string]: unknown;\n}\n\nexport interface MockFileInfo {\n config: MockFileConfig;\n serializable: boolean;\n hasDynamicData: boolean;\n headerComment?: string;\n description?: string;\n dataText: string;\n isBinary?: boolean;\n}\n\nexport const DEFAULT_CONFIG: MockFileConfig = {\n enable: true,\n data: null,\n delay: 0,\n status: 200,\n};\n\nconst isBufferTextLike = (buffer: Buffer): boolean => {\n try {\n const sample = buffer.slice(0, 100);\n const nullBytes = [...sample].filter((b) => b === 0).length;\n const controlChars = [...sample].filter(\n (b) => b < 32 && b !== 9 && b !== 10 && b !== 13,\n ).length;\n return nullBytes === 0 && controlChars < 5;\n } catch {\n return false;\n }\n};\n\nconst isBinaryResponse = (\n contentType: string | undefined,\n data: Buffer,\n): boolean => {\n if (!contentType) return false;\n\n const binaryTypes = [\n \"application/octet-stream\",\n \"application/pdf\",\n \"application/zip\",\n \"application/x-zip-compressed\",\n \"application/vnd.ms-excel\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.ms-powerpoint\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \"image/\",\n \"video/\",\n \"audio/\",\n ];\n\n return (\n binaryTypes.some((type) => contentType.toLowerCase().includes(type)) ||\n !isBufferTextLike(data)\n );\n};\n\nconst getFileExtension = (\n contentType: string | undefined,\n url: string,\n): string => {\n const mimeMap: Record<string, string> = {\n \"application/json\": \"json\",\n \"application/pdf\": \"pdf\",\n \"application/zip\": \"zip\",\n \"application/vnd.ms-excel\": \"xls\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\": \"xlsx\",\n \"application/msword\": \"doc\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\":\n \"docx\",\n \"application/vnd.ms-powerpoint\": \"ppt\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\":\n \"pptx\",\n \"image/jpeg\": \"jpg\",\n \"image/png\": \"png\",\n \"image/gif\": \"gif\",\n \"text/plain\": \"txt\",\n \"text/html\": \"html\",\n \"text/css\": \"css\",\n \"application/javascript\": \"js\",\n \"text/xml\": \"xml\",\n };\n\n if (contentType && mimeMap[contentType.toLowerCase()]) {\n return mimeMap[contentType.toLowerCase()];\n }\n\n try {\n const urlObj = new URL(url, \"http://localhost\");\n const fileName = urlObj.searchParams.get(\"file_name\");\n if (fileName) {\n const extensionMatch = fileName.match(/\\.([a-zA-Z0-9]+)$/);\n if (extensionMatch) {\n return extensionMatch[1];\n }\n }\n } catch {\n // Ignore URL parse errors\n }\n\n return \"bin\";\n};\n\nasync function formatWithPrettier(content: string): Promise<string> {\n try {\n return await prettier.format(content, { parser: \"babel\" });\n } catch {\n return content;\n }\n}\n\nfunction buildMockFileHeader(\n pathname: string,\n method: string,\n search: string,\n extra?: string,\n): string {\n return `/**\n * Mock data for ${pathname} (${method.toUpperCase()})${search || \"\"}\n * @description ${pathname}${search || \"\"}${extra ? ` - ${extra}` : \"\"}\n * Generated at ${new Date().toISOString()}\n */`;\n}\n\nasync function saveBinaryMock(\n filePath: string,\n binaryData: Buffer,\n pathname: string,\n method: string,\n search: string,\n contentType: string | undefined,\n url: string,\n statusCode: number | undefined,\n): Promise<string | null> {\n const extension = getFileExtension(contentType, url);\n const binaryFilePath = filePath.replace(/\\.js$/, \".\" + extension);\n\n if (fs.existsSync(binaryFilePath)) return null;\n\n fs.writeFileSync(binaryFilePath, binaryData);\n\n const header = buildMockFileHeader(pathname, method, search, `Binary file (${extension})`);\n const configContent = `${header}\nexport default {\n enable: false,\n data: {\n __binaryFile: '${extension}',\n __originalPath: '${pathname}',\n __originalQuery: '${search}',\n __originalUrl: '${pathname}${search || \"\"}',\n __contentType: '${contentType}',\n __fileSize: ${binaryData.length}\n },\n delay: 0,\n status: ${statusCode || 200}\n}`;\n\n const formatted = await formatWithPrettier(configContent);\n fs.writeFileSync(filePath, formatted, \"utf-8\");\n return filePath;\n}\n\nasync function saveJsonMock(\n filePath: string,\n dataStr: string,\n pathname: string,\n method: string,\n search: string,\n statusCode: number | undefined,\n): Promise<string | null> {\n if (fs.existsSync(filePath)) return null;\n\n let jsonData;\n if (!dataStr || dataStr.trim() === \"\") {\n jsonData = {\n error: true,\n message: `Empty response (${statusCode || \"unknown status\"})`,\n status: statusCode || 404,\n data: null,\n };\n } else {\n try {\n jsonData = JSON.parse(dataStr);\n if (statusCode && statusCode >= 400) {\n const errorMeta = { __mockStatusCode: statusCode, __isErrorResponse: true };\n jsonData =\n typeof jsonData === \"object\" && jsonData !== null\n ? { ...jsonData, ...errorMeta }\n : { originalData: jsonData, ...errorMeta };\n }\n } catch {\n jsonData = {\n error: true,\n message: `Non-JSON response (${statusCode || \"unknown status\"})`,\n status: statusCode || 404,\n data: dataStr,\n __mockStatusCode: statusCode,\n __isErrorResponse: true,\n };\n }\n }\n\n const header = buildMockFileHeader(pathname, method, search);\n const content = `${header}\nexport default {\n enable: false,\n data: ${JSON.stringify(jsonData)},\n delay: 0,\n status: ${statusCode || 200}\n}`;\n\n const formatted = await formatWithPrettier(content);\n fs.writeFileSync(filePath, formatted, \"utf-8\");\n return filePath;\n}\n\nexport async function saveMockData(\n url: string,\n method: string,\n data: Buffer | string,\n rootDir: string,\n statusCode?: number,\n contentType?: string,\n): Promise<string | null> {\n try {\n const absoluteRootDir = resolveAbsolutePath(rootDir);\n const urlObj = new URL(url, \"http://localhost\");\n const pathname = urlObj.pathname;\n const search = urlObj.search;\n\n const filePath = path.join(\n absoluteRootDir,\n pathname.replace(/^\\//, \"\"),\n method.toLowerCase() + \".js\",\n );\n\n await fs.ensureDir(path.dirname(filePath));\n\n const isBuffer = Buffer.isBuffer(data);\n const binaryData = isBuffer ? data : Buffer.from(data || \"\");\n const isBinary = isBinaryResponse(contentType, binaryData);\n\n if (isBinary) {\n return saveBinaryMock(\n filePath, binaryData, pathname, method, search,\n contentType, url, statusCode,\n );\n }\n\n const dataStr = isBuffer ? data.toString(\"utf8\") : data || \"\";\n return saveJsonMock(filePath, dataStr, pathname, method, search, statusCode);\n } catch (error) {\n console.error(`Failed to save mock data for ${url}:`, error);\n console.error(\n `URL details: url=${url}, method=${method}, statusCode=${statusCode}, contentType=${contentType}`,\n );\n throw error;\n }\n}\n\nconst recursiveReadAllFiles = async (dir: string): Promise<string[]> => {\n if (!(await fs.pathExists(dir))) return [];\n\n const files: string[] = [];\n try {\n const list = await fs.readdir(dir);\n for (const file of list) {\n const filePath = path.join(dir, file);\n const stat = await fs.stat(filePath);\n if (stat.isDirectory()) {\n files.push(...(await recursiveReadAllFiles(filePath)));\n } else {\n files.push(filePath);\n }\n }\n } catch (error) {\n console.error(`Error reading directory ${dir}:`, error);\n }\n return files;\n};\n\nexport async function buildMockIndex(mockDir: string): Promise<Map<string, string>> {\n const mockFileMap = new Map<string, string>();\n\n if (!(await fs.pathExists(mockDir))) {\n await fs.ensureDir(mockDir);\n return mockFileMap;\n }\n\n const files = await recursiveReadAllFiles(mockDir);\n\n files.forEach((filePath) => {\n if (!filePath.endsWith(\".js\")) return;\n\n try {\n const relativePath = path.relative(mockDir, filePath);\n const method = path.basename(filePath, \".js\");\n const dirPath = path.dirname(relativePath);\n const urlPath = \"/\" + toPosixPath(dirPath);\n const absolutePath = resolveAbsolutePath(filePath);\n const key = `${urlPath}/${method}.js`.toLowerCase();\n\n mockFileMap.set(key, absolutePath);\n } catch (error) {\n console.error(`[automock] Failed to process file ${filePath}:`, error);\n }\n });\n\n return mockFileMap;\n}\n\nexport async function parseMockModule(filePath: string): Promise<MockFileInfo> {\n const absolutePath = resolveAbsolutePath(filePath);\n\n if (!fs.existsSync(absolutePath)) {\n throw new Error(`Mock file does not exist: ${absolutePath}`);\n }\n\n const content = fs.readFileSync(absolutePath, \"utf-8\");\n const headerCommentMatch = content.match(/^(\\/\\*\\*[\\s\\S]*?\\*\\/)/);\n const headerComment = headerCommentMatch ? headerCommentMatch[1] : undefined;\n\n let description: string | undefined;\n if (headerComment) {\n const descMatch = headerComment.match(/@description\\s+(.+?)(?:\\n|\\*\\/)/s);\n if (descMatch) {\n description = descMatch[1].trim();\n }\n }\n\n const { default: mockModule } = await import(\n `${absolutePath}?t=${Date.now()}`\n );\n\n const exportedConfig =\n typeof mockModule === \"function\" ? mockModule() : mockModule;\n const hasDynamicData = typeof exportedConfig?.data === \"function\";\n const config: MockFileConfig = {\n ...DEFAULT_CONFIG,\n ...(exportedConfig ?? {}),\n };\n\n const serializable = !hasDynamicData;\n const dataObj =\n typeof config.data === \"object\" && config.data !== null\n ? (config.data as Record<string, unknown>)\n : null;\n const isBinary = dataObj !== null && \"__binaryFile\" in dataObj;\n\n return {\n config,\n serializable,\n hasDynamicData,\n headerComment,\n description,\n dataText: isBinary\n ? `/* Binary file: ${dataObj?.__binaryFile} */`\n : serializable\n ? JSON.stringify(config.data ?? null, null, 2)\n : \"/* data is generated dynamically and cannot be edited here */\",\n isBinary,\n };\n}\n\nexport async function writeMockFile(\n filePath: string,\n mockInfo: Pick<MockFileInfo, \"config\" | \"headerComment\" | \"description\">,\n): Promise<void> {\n const absolutePath = resolveAbsolutePath(filePath);\n\n let header = mockInfo.headerComment || \"\";\n\n if (mockInfo.description !== undefined) {\n if (header) {\n if (/@description/.test(header)) {\n header = header.replace(\n /@description\\s+.+?(?=\\n|\\*\\/)/s,\n `@description ${mockInfo.description}`,\n );\n } else {\n header = header.replace(\n /\\*\\//,\n ` * @description ${mockInfo.description}\\n */`,\n );\n }\n }\n }\n\n const content = header ? `${header}\\n` : \"\";\n const finalContent = `${content}export default ${JSON.stringify(mockInfo.config, null, 2)}\\n`;\n\n try {\n const formatted = await formatWithPrettier(finalContent);\n fs.writeFileSync(absolutePath, formatted, \"utf-8\");\n } catch {\n console.error(\"Error formatting code with prettier, writing raw content\");\n fs.writeFileSync(absolutePath, finalContent, \"utf-8\");\n }\n}\n","import path from \"path\";\n\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { AddressInfo } from \"net\";\n\nexport function resolveAbsolutePath(p: string): string {\n return path.isAbsolute(p) ? p : path.resolve(process.cwd(), p);\n}\n\nexport function toPosixPath(p: string): string {\n return p.replace(/\\\\/g, \"/\");\n}\n\nexport interface ServerAddress {\n protocol: string;\n host: string;\n port: number;\n}\n\nexport function getServerAddress(\n address: AddressInfo,\n isHttps: boolean,\n): ServerAddress {\n return {\n protocol: isHttps ? \"https\" : \"http\",\n host:\n address.address === \"::\" || address.address === \"0.0.0.0\"\n ? \"localhost\"\n : address.address,\n port: address.port,\n };\n}\n\nexport function sendJson(\n res: ServerResponse,\n data: unknown,\n status = 200,\n): void {\n res.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n res.statusCode = status;\n res.end(typeof data === \"string\" ? data : JSON.stringify(data));\n}\n\nexport function sendError(\n res: ServerResponse,\n message: string,\n status = 500,\n): void {\n sendJson(res, { error: message }, status);\n}\n\nconst MAX_BODY_SIZE = 10 * 1024 * 1024; // 10MB\n\nexport function readBody(req: IncomingMessage): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n let totalSize = 0;\n req.on(\"data\", (chunk: Buffer) => {\n totalSize += chunk.length;\n if (totalSize > MAX_BODY_SIZE) {\n reject(new Error(\"Request body too large\"));\n req.destroy();\n return;\n }\n chunks.push(chunk);\n });\n req.on(\"end\", () => resolve(Buffer.concat(chunks).toString(\"utf-8\")));\n req.on(\"error\", reject);\n });\n}\n","import path from \"path\";\nimport fs from \"fs-extra\";\nimport { parseMockModule, writeMockFile, saveMockData, buildMockIndex, type MockFileConfig } from \"./mockFileUtils\";\nimport { toPosixPath, sendJson, readBody } from \"./utils\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { AutomockPluginOptions, InspectorOptions } from \"./types\";\n\ninterface InspectorContext {\n req: IncomingMessage;\n res: ServerResponse;\n mockDir: string;\n inspectorRoute: string;\n apiPrefix: string;\n inspectorConfig: Required<InspectorOptions>;\n getMockFileMap: () => Map<string, string>;\n}\n\ninterface InspectorHandlerOptions {\n inspector: AutomockPluginOptions[\"inspector\"];\n apiPrefix: string;\n mockDir: string;\n getMockFileMap: () => Map<string, string>;\n}\n\ninterface InspectorApiContext extends InspectorContext {\n pathname: string;\n}\n\ninterface InspectorPayload {\n key: string;\n config?: Partial<MockFileConfig>;\n description?: string;\n}\n\ninterface MockItem {\n key: string;\n file: string;\n method: string;\n path: string;\n config: MockFileConfig;\n editable: boolean;\n description?: string;\n dataText: string;\n}\n\nfunction buildMockItem(\n key: string,\n filePath: string,\n mockDir: string,\n info: Awaited<ReturnType<typeof parseMockModule>>,\n): MockItem {\n return {\n key,\n file: path.relative(mockDir, filePath),\n method: key.split(\"/\").pop()?.replace(/\\.js$/, \"\") ?? \"get\",\n path: key.replace(/\\/[^/]+\\.js$/, \"\"),\n config: info.config,\n editable: info.serializable,\n description: info.description,\n dataText: info.dataText,\n };\n}\n\nexport const DEFAULT_ROUTE = \"/__mock/\";\n\nfunction ensureTrailingSlash(route: string): string {\n return route.endsWith(\"/\") ? route : `${route}/`;\n}\n\nfunction escapeHtml(value: string): string {\n return value\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nexport function normalizeInspectorConfig(\n input: AutomockPluginOptions[\"inspector\"],\n): Required<InspectorOptions> {\n if (input === false || input === undefined) {\n return { route: DEFAULT_ROUTE, enableToggle: true };\n }\n if (input === true) {\n return { route: DEFAULT_ROUTE, enableToggle: true };\n }\n return {\n route: ensureTrailingSlash(input.route ?? DEFAULT_ROUTE),\n enableToggle: input.enableToggle ?? true,\n };\n}\n\nexport type InspectorRequestHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<boolean>;\n\nexport function createInspectorHandler(\n options: InspectorHandlerOptions,\n): InspectorRequestHandler | null {\n if (!options.inspector) {\n return null;\n }\n\n const inspectorConfig = normalizeInspectorConfig(options.inspector);\n const inspectorRoute = ensureTrailingSlash(inspectorConfig.route);\n\n return async (req, res) => {\n if (!req.url) {\n return false;\n }\n const url = new URL(req.url, \"http://localhost\");\n if (!url.pathname.startsWith(inspectorRoute)) {\n return false;\n }\n\n await handleInspectorRequest({\n req,\n res,\n mockDir: options.mockDir,\n inspectorRoute,\n apiPrefix: options.apiPrefix,\n inspectorConfig,\n getMockFileMap: options.getMockFileMap,\n });\n\n return true;\n };\n}\n\nasync function handleInspectorRequest(\n context: InspectorContext,\n): Promise<void> {\n const { req, res, inspectorRoute } = context;\n const url = new URL(req.url || inspectorRoute, \"http://localhost\");\n const normalizedRoute = ensureTrailingSlash(inspectorRoute);\n\n if (\n url.pathname === normalizedRoute.slice(0, -1) ||\n url.pathname === normalizedRoute\n ) {\n await serveInspectorHtml(context);\n return;\n }\n\n const relativePath = url.pathname.startsWith(normalizedRoute)\n ? url.pathname.slice(normalizedRoute.length)\n : null;\n\n if (relativePath && relativePath.startsWith(\"api/\")) {\n await handleInspectorApi({ ...context, pathname: relativePath.slice(4) });\n return;\n }\n\n res.statusCode = 404;\n res.end(\"Not Found\");\n}\n\nasync function serveInspectorHtml({\n res,\n inspectorRoute,\n apiPrefix,\n inspectorConfig,\n}: InspectorContext): Promise<void> {\n const routeJson = JSON.stringify(ensureTrailingSlash(inspectorRoute));\n const allowToggleJson = JSON.stringify(inspectorConfig.enableToggle);\n const apiPrefixEscaped = escapeHtml(apiPrefix);\n\n const templatePath = path.join(__dirname, \"inspector-template.html\");\n const template = fs.readFileSync(templatePath, \"utf-8\");\n const html = template\n .replace(\"__API_PREFIX__\", apiPrefixEscaped)\n .replace(\"__ROUTE_JSON__\", routeJson)\n .replace(\"__ALLOW_TOGGLE_JSON__\", allowToggleJson);\n\n res.setHeader(\"Content-Type\", \"text/html; charset=utf-8\");\n res.end(html);\n}\n\nasync function handleList(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { res, mockDir } = ctx;\n const list = await Promise.all(\n Array.from(mockFileMap.entries()).map(async ([key, filePath]) => {\n const info = await parseMockModule(filePath);\n return buildMockItem(key, filePath, mockDir, info);\n }),\n );\n sendJson(res, { mocks: list });\n return true;\n}\n\nasync function handleDetail(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir } = ctx;\n const url = new URL(req.url || \"\", \"http://localhost\");\n const key = url.searchParams.get(\"key\");\n if (!key) {\n sendJson(res, { error: \"Missing key\" }, 400);\n return true;\n }\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n const info = await parseMockModule(filePath);\n sendJson(res, { mock: buildMockItem(key, filePath, mockDir, info) });\n return true;\n}\n\nasync function handleUpdate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir, inspectorConfig } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: InspectorPayload;\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const { key, config, description } = payload || {};\n if (!key) {\n sendJson(res, { error: \"Invalid payload: missing key\" }, 400);\n return true;\n }\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n\n const info = await parseMockModule(filePath);\n\n let nextConfig = info.config;\n if (config && typeof config === \"object\") {\n if (!inspectorConfig.enableToggle && config.enable !== undefined) {\n delete config.enable;\n }\n nextConfig = { ...info.config, ...config };\n }\n\n const nextDescription =\n description !== undefined ? description : info.description;\n\n await writeMockFile(filePath, {\n headerComment: info.headerComment,\n config: nextConfig,\n description: nextDescription,\n });\n\n const updatedInfo = await parseMockModule(filePath);\n sendJson(res, { mock: buildMockItem(key, filePath, mockDir, updatedInfo) });\n return true;\n}\n\nasync function handleCreate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir, apiPrefix } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: { method: string; path: string; description?: string; data?: unknown };\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const { method, path: apiPath, data } = payload || {};\n if (!method || !apiPath) {\n sendJson(res, { error: \"Invalid payload: missing method or path\" }, 400);\n return true;\n }\n\n const fullUrl = apiPrefix + apiPath;\n\n try {\n let dataToSave: Buffer | string;\n if (typeof data === \"object\" && data !== null) {\n dataToSave = JSON.stringify(data, null, 2);\n } else {\n dataToSave = typeof data === \"string\" ? data : \"\";\n }\n\n await saveMockData(fullUrl, method.toLowerCase(), dataToSave, mockDir, 200);\n\n const newMockFileMap = await buildMockIndex(mockDir);\n for (const [key, value] of newMockFileMap.entries()) {\n mockFileMap.set(key, value);\n }\n\n const normalizedPath = toPosixPath(apiPath);\n const key = (normalizedPath.startsWith(\"/\") ? \"\" : \"/\") +\n normalizedPath.toLowerCase() + \"/\" + method.toLowerCase() + \".js\";\n const filePath = mockFileMap.get(key);\n\n if (!filePath) {\n sendJson(res, { error: \"Mock file created but not found in map\" }, 500);\n return true;\n }\n\n const info = await parseMockModule(filePath);\n sendJson(res, {\n success: true,\n mock: buildMockItem(key, filePath, mockDir, info),\n });\n return true;\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n sendJson(res, { error: \"Failed to create mock: \" + errorMessage }, 500);\n return true;\n }\n}\n\nasync function handleDelete(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res } = ctx;\n const url = new URL(req.url || \"\", \"http://localhost\");\n const key = url.searchParams.get(\"key\");\n if (!key) {\n sendJson(res, { error: \"Missing key\" }, 400);\n return true;\n }\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n\n try {\n const stats = await fs.stat(filePath);\n if (stats.isDirectory()) {\n await fs.remove(filePath);\n for (const [mapKey, mapPath] of mockFileMap.entries()) {\n if (mapPath.startsWith(filePath + path.sep) || mapPath === filePath) {\n mockFileMap.delete(mapKey);\n }\n }\n } else {\n await fs.unlink(filePath);\n mockFileMap.delete(key);\n }\n sendJson(res, { success: true });\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n sendJson(res, { error: \"Failed to delete: \" + errorMessage }, 500);\n }\n return true;\n}\n\ntype ApiHandler = (ctx: InspectorApiContext, mockFileMap: Map<string, string>) => Promise<boolean>;\n\nasync function handleBatchUpdate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: { updates?: Array<{ key: string; config?: Record<string, unknown> }> };\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const updates = payload?.updates;\n if (!Array.isArray(updates) || updates.length === 0) {\n sendJson(res, { error: \"Invalid payload: updates must be a non-empty array\" }, 400);\n return true;\n }\n\n let updated = 0;\n const errors: string[] = [];\n\n for (const item of updates) {\n const { key, config } = item;\n if (!key) continue;\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n errors.push(`Mock not found: ${key}`);\n continue;\n }\n\n try {\n const info = await parseMockModule(filePath);\n const nextConfig = config ? { ...info.config, ...config } : info.config;\n\n await writeMockFile(filePath, {\n headerComment: info.headerComment,\n config: nextConfig,\n description: info.description,\n });\n updated++;\n } catch (err) {\n errors.push(`Failed to update ${key}: ${err instanceof Error ? err.message : String(err)}`);\n }\n }\n\n sendJson(res, { success: true, updated, errors: errors.length > 0 ? errors : undefined });\n return true;\n}\n\nconst API_ROUTES: Record<string, ApiHandler> = {\n list: handleList,\n detail: handleDetail,\n update: handleUpdate,\n \"batch-update\": handleBatchUpdate,\n create: handleCreate,\n delete: handleDelete,\n};\n\nasync function handleInspectorApi(ctx: InspectorApiContext): Promise<void> {\n try {\n const mockFileMap = ctx.getMockFileMap();\n const handler = API_ROUTES[ctx.pathname];\n if (handler) {\n await handler(ctx, mockFileMap);\n return;\n }\n sendJson(ctx.res, { error: \"Unknown inspector endpoint\" }, 404);\n } catch (error) {\n console.error(\"[automock] Inspector request failed:\", error);\n sendJson(ctx.res, { error: \"Inspector failed\" }, 500);\n }\n}\n","import path from 'path'\nimport fs from 'fs-extra'\n\nimport { buildMockIndex, parseMockModule } from './mockFileUtils'\n\nexport interface MockBundleData {\n enable: boolean\n data: unknown\n delay: number\n status: number\n isBinary?: boolean\n}\n\nexport interface MockBundle {\n [key: string]: MockBundleData\n}\n\nexport interface BundleOptions {\n mockDir: string\n includeDisabled?: boolean\n log?: boolean\n}\n\nconst DEFAULT_BUNDLE_OPTIONS: Partial<BundleOptions> = {\n includeDisabled: true,\n log: true\n}\n\nasync function bundleMockFiles(options: BundleOptions): Promise<MockBundle> {\n const opts = { ...DEFAULT_BUNDLE_OPTIONS, ...options }\n const { mockDir, log } = opts\n\n if (!fs.existsSync(mockDir)) {\n if (log) {\n console.log(`[mock-bundler] Mock directory does not exist: ${mockDir}`)\n }\n return {}\n }\n\n const mockFileMap = await buildMockIndex(mockDir)\n const bundle: MockBundle = {}\n let bundledCount = 0\n let skippedCount = 0\n\n for (const [key, filePath] of mockFileMap) {\n try {\n const mockInfo = await parseMockModule(filePath)\n\n if (!mockInfo.serializable) {\n skippedCount++\n if (log) {\n console.log(`[mock-bundler] Skipping non-serializable mock: ${key}`)\n }\n continue\n }\n\n bundle[key] = {\n enable: mockInfo.config.enable,\n data: mockInfo.config.data,\n delay: mockInfo.config.delay,\n status: mockInfo.config.status,\n isBinary: mockInfo.isBinary\n }\n\n bundledCount++\n } catch (error) {\n if (log) {\n console.error(`[mock-bundler] Failed to bundle mock ${key}:`, error)\n }\n }\n }\n\n if (log) {\n console.log(`[mock-bundler] Bundled ${bundledCount} mocks, skipped ${skippedCount} non-serializable mocks`)\n }\n\n return bundle\n}\n\nfunction writeMockBundle(bundle: MockBundle, outputPath: string): void {\n const outputDir = path.dirname(outputPath)\n\n if (!fs.existsSync(outputDir)) {\n fs.ensureDirSync(outputDir)\n }\n\n fs.writeFileSync(\n outputPath,\n JSON.stringify(bundle, null, 2),\n 'utf-8'\n )\n}\n\nexport { bundleMockFiles, writeMockBundle }\n"],"mappings":";;;;;;;;;;;AAAA,OAAOA,WAAU;AACjB,OAAOC,SAAQ;;;ACDf,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,OAAOC,WAAU;AACjB,OAAOC,SAAQ;AACf,OAAO,UAAU;AACjB,OAAO,WAAW;;;ACLlB,OAAOC,WAAU;AACjB,OAAO,QAAQ;AACf,OAAO,cAAc;;;ACFrB,OAAO,UAAU;AAKV,SAAS,oBAAoB,GAAmB;AACrD,SAAO,KAAK,WAAW,CAAC,IAAI,IAAI,KAAK,Q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","fs","path","path","path","fs","path","fs","key","fs","path","path","fs","fs","path","automock","path","fs"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/middleware.ts","../src/mockFileUtils.ts","../src/utils.ts","../src/inspector.ts","../src/mockBundler.ts"],"sourcesContent":["import path from 'path'\nimport fs from 'fs-extra'\n\nimport { automock as createAutomockPlugin } from './middleware'\nimport { bundleMockFiles, writeMockBundle } from './mockBundler'\nimport { buildMockIndex } from './mockFileUtils'\nimport type { Plugin } from 'vite'\nimport type { AutomockPluginOptions } from './types'\nimport type { MockBundle } from './mockBundler'\n\nexport type { AutomockPluginOptions, InspectorOptions } from './types'\nexport { saveMockData, buildMockIndex, parseMockModule, writeMockFile } from './mockFileUtils'\nexport type { MockBundle, MockBundleData } from './mockBundler'\nexport { bundleMockFiles, writeMockBundle } from './mockBundler'\n\n// Client interceptor exports\nexport {\n createMockInterceptor,\n initMockInterceptor,\n initMockInterceptorForPureHttp,\n setMockEnabled,\n isMockEnabled,\n loadMockData,\n registerHttpInstance\n} from './client'\nexport type { MockInterceptorOptions, MockBundleData as ClientMockBundleData } from './client/interceptor'\n\nexport interface AutomockWithBundleOptions extends AutomockPluginOptions {\n bundleMockData?: boolean\n bundleOutputPath?: string\n}\n\nexport function automock(options: AutomockWithBundleOptions = {}): Plugin {\n const {\n bundleMockData = true,\n bundleOutputPath = 'public/mock-data.json',\n ...pluginOptions\n } = options\n\n const basePlugin = createAutomockPlugin(pluginOptions)\n\n let cachedBundle: MockBundle | null = null\n\n const ensureBundleExists = () => {\n const outputPath = path.join(process.cwd(), bundleOutputPath)\n if (!fs.existsSync(outputPath) && cachedBundle) {\n console.log('[automock] Re-writing mock bundle...')\n writeMockBundle(cachedBundle, outputPath)\n }\n }\n\n return {\n ...basePlugin,\n name: 'vite-plugin-automock-with-bundle',\n config() {\n // Inject compile-time constant for client interceptor\n const enabled = pluginOptions.productionMock !== false\n return {\n define: {\n __AUTOMOCK_ENABLED__: JSON.stringify(enabled),\n },\n }\n },\n buildEnd: async () => {\n if (bundleMockData && pluginOptions.productionMock !== false) {\n try {\n const mockDir = pluginOptions.mockDir || path.join(process.cwd(), 'mock')\n\n if (!fs.existsSync(mockDir)) {\n console.log('[automock] Mock directory not found, skipping bundle generation')\n console.log('[automock] Using existing mock-data.json if present')\n return\n }\n\n const mockFileMap = await buildMockIndex(mockDir)\n if (mockFileMap.size === 0) {\n console.log('[automock] No mock files found, skipping bundle generation')\n return\n }\n\n cachedBundle = await bundleMockFiles({ mockDir })\n\n const outputPath = path.join(process.cwd(), bundleOutputPath)\n writeMockBundle(cachedBundle, outputPath)\n console.log(`[automock] Mock bundle written to: ${outputPath}`)\n } catch (error) {\n console.error('[automock] Failed to bundle mock data:', error)\n }\n }\n },\n writeBundle: ensureBundleExists,\n closeBundle: ensureBundleExists,\n }\n}\n\n","import chokidar from \"chokidar\";\nimport debounce from \"lodash.debounce\";\nimport path from \"path\";\nimport fs from \"fs-extra\";\nimport http from \"http\";\nimport https from \"https\";\nimport type { AddressInfo } from \"net\";\n\nimport { buildMockIndex, saveMockData } from \"./mockFileUtils\";\nimport { createInspectorHandler, normalizeInspectorConfig } from \"./inspector\";\nimport {\n resolveAbsolutePath,\n getServerAddress,\n sendError,\n} from \"./utils\";\n\nimport type { Plugin } from \"vite\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { FSWatcher } from \"chokidar\";\nimport type { AutomockPluginOptions } from \"./types\";\n\nfunction serveMockResponse(\n res: ServerResponse,\n mockFilePath: string,\n mockResult: { data?: unknown; delay?: number; status?: number },\n): void {\n const { data, delay = 0, status = 200 } = mockResult;\n\n setTimeout(() => {\n const isBinaryMock = data && typeof data === \"object\" && (data as Record<string, unknown>).__binaryFile;\n\n if (isBinaryMock) {\n const binaryData = data as Record<string, unknown>;\n const binaryFilePath = mockFilePath.replace(\n /\\.js$/,\n \".\" + binaryData.__binaryFile,\n );\n\n if (!fs.existsSync(binaryFilePath)) {\n console.error(\n `[automock] Binary mock file not found: ${binaryFilePath}`,\n );\n sendError(res, \"Binary mock file not found\", 404);\n return;\n }\n\n try {\n const fileData = fs.readFileSync(binaryFilePath);\n const contentType =\n (binaryData.__contentType as string) || \"application/octet-stream\";\n res.setHeader(\"Content-Type\", contentType);\n res.setHeader(\"Content-Length\", fileData.length);\n res.setHeader(\"X-Mock-Response\", \"true\");\n res.setHeader(\"X-Mock-Source\", \"vite-plugin-automock\");\n res.setHeader(\"X-Mock-Binary-File\", \"true\");\n res.statusCode = status;\n res.end(fileData);\n } catch (error) {\n console.error(\"[automock] Failed to read binary mock file:\", error);\n sendError(res, \"Failed to read binary mock file\");\n }\n } else {\n res.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n res.setHeader(\"X-Mock-Response\", \"true\");\n res.setHeader(\"X-Mock-Source\", \"vite-plugin-automock\");\n res.statusCode = status;\n res.end(typeof data === \"string\" ? data : JSON.stringify(data));\n }\n }, delay);\n}\n\nfunction proxyAndCapture(\n req: IncomingMessage,\n res: ServerResponse,\n options: {\n proxyBaseUrl: string;\n pathRewrite: (p: string) => string;\n shouldSave: boolean;\n method: string;\n pathname: string;\n mockDir: string;\n onMockSaved: () => void;\n },\n): void {\n const { proxyBaseUrl, pathRewrite, shouldSave, method, pathname, mockDir, onMockSaved } = options;\n const targetUrl = proxyBaseUrl + pathRewrite(req.url || \"\");\n const client = targetUrl.startsWith(\"https\") ? https : http;\n\n function sendProxyRequest(body?: string) {\n const targetUrlObj = new URL(proxyBaseUrl);\n const proxyOptions = {\n method: req.method,\n headers: {\n ...req.headers,\n host: targetUrlObj.host,\n },\n rejectUnauthorized: false,\n };\n\n const proxyReq = client.request(targetUrl, proxyOptions, (proxyRes) => {\n const contentType = proxyRes.headers[\"content-type\"] || \"\";\n const isJson = contentType.includes(\"application/json\");\n\n // Non-JSON response (file download, stream, etc.) → pipe directly\n if (!isJson) {\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n proxyRes.pipe(res);\n return;\n }\n\n // JSON response → buffer, save mock, then respond\n const chunks: Buffer[] = [];\n\n proxyRes.on(\"data\", (chunk) => chunks.push(chunk));\n proxyRes.on(\"end\", async () => {\n try {\n const responseData = Buffer.concat(chunks);\n\n if (shouldSave) {\n try {\n console.log(\n `[automock] Capturing mock: ${req.url!} -> ${pathname}`,\n );\n const savedFilePath = await saveMockData(\n req.url!,\n method,\n responseData,\n mockDir,\n proxyRes.statusCode,\n contentType,\n );\n if (savedFilePath) {\n console.log(`[automock] Mock saved: ${pathname}`);\n onMockSaved();\n } else {\n console.log(\n `[automock] Mock file already exists, skipped: ${pathname}`,\n );\n }\n } catch (saveError) {\n console.error(\"[automock] Failed to save mock:\", saveError);\n }\n }\n\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n res.end(responseData);\n } catch (error) {\n console.error(\"[automock] Failed to process response:\", error);\n res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);\n res.end(Buffer.concat(chunks));\n }\n });\n });\n\n proxyReq.on(\"error\", (err) => {\n console.error(\"[automock] Proxy request failed:\", err);\n sendError(res, err.message);\n });\n\n if (\n body &&\n (req.method === \"POST\" || req.method === \"PUT\" || req.method === \"PATCH\")\n ) {\n proxyReq.write(body);\n }\n\n proxyReq.end();\n }\n\n if (\n req.method === \"POST\" ||\n req.method === \"PUT\" ||\n req.method === \"PATCH\"\n ) {\n let bodyStr = \"\";\n req.on(\"data\", (chunk) => (bodyStr += chunk.toString()));\n req.on(\"end\", () => sendProxyRequest(bodyStr));\n } else {\n sendProxyRequest();\n }\n}\n\nfunction printServerUrls(\n server: { httpServer?: { address(): AddressInfo | string | null; once(event: string, cb: () => void): void } | null; config: { server: { https?: unknown } } },\n urls: Array<{ path: string; label: string; color: string; delay: number }>,\n): void {\n server.httpServer?.once(\"listening\", () => {\n const address = server.httpServer?.address();\n if (!address || typeof address !== \"object\") return;\n\n const { protocol, host, port } = getServerAddress(\n address,\n !!server.config.server.https,\n );\n\n for (const { path: urlPath, label, color, delay } of urls) {\n setTimeout(() => {\n const fullUrl = `${protocol}://${host}:${port}${urlPath}`;\n console.log(` ➜ ${color}${label}\\x1b[0m: \\x1b[1m${fullUrl}\\x1b[0m`);\n }, delay);\n }\n });\n}\n\nexport function automock(options: AutomockPluginOptions): Plugin {\n const {\n mockDir: configMockDir = path.join(process.cwd(), \"mock\"),\n apiPrefix = \"/api\",\n pathRewrite = (p) => p,\n proxyBaseUrl,\n inspector = false,\n } = options;\n\n const mockDir = resolveAbsolutePath(configMockDir);\n\n if (!fs.existsSync(mockDir)) {\n try {\n fs.ensureDirSync(mockDir);\n console.log(`[automock] Mock directory created: ${mockDir}`);\n } catch (error) {\n console.error(`[automock] Failed to create mock directory: ${mockDir}`, error);\n }\n }\n\n let watcher: FSWatcher | undefined;\n\n return {\n name: \"vite-plugin-automock\",\n config(userConfig) {\n if (proxyBaseUrl && userConfig.server?.proxy) {\n const proxyConfig = userConfig.server.proxy;\n const hasConflictingPrefix =\n typeof proxyConfig === \"object\" && apiPrefix in proxyConfig;\n\n if (hasConflictingPrefix) {\n console.warn(\n `\\n⚠️ [automock] WARNING: You have both Vite's server.proxy[\"${apiPrefix}\"] and automock's proxyBaseUrl configured.`,\n );\n console.warn(\n ` This may cause request conflicts. Remove the \"${apiPrefix}\" entry from vite.config.ts server.proxy to avoid issues.`,\n );\n console.warn(\n ` Automock will handle all ${apiPrefix} requests when proxyBaseUrl is set.\\n`,\n );\n }\n }\n },\n async configureServer(server) {\n let mockFileMap = await buildMockIndex(mockDir);\n console.log(`[automock] Loaded ${mockFileMap.size} mock files`);\n\n const rebuildMockFileMap = debounce(async () => {\n mockFileMap = await buildMockIndex(mockDir);\n }, 200);\n\n watcher = chokidar.watch(mockDir, {\n ignoreInitial: true,\n persistent: true,\n depth: 30,\n });\n watcher.on(\"add\", () => rebuildMockFileMap());\n watcher.on(\"unlink\", () => rebuildMockFileMap());\n\n server.httpServer?.on(\"close\", () => watcher?.close());\n\n const inspectorHandler = createInspectorHandler({\n inspector,\n apiPrefix,\n mockDir,\n getMockFileMap: () => mockFileMap,\n });\n\n const urlsToPrint: Array<{ path: string; label: string; color: string; delay: number }> = [\n { path: apiPrefix, label: \"Mock API\", color: \"\\x1b[32m\", delay: 100 },\n ];\n\n if (inspector) {\n const inspectorConfig = normalizeInspectorConfig(inspector);\n urlsToPrint.push({\n path: inspectorConfig.route,\n label: \"Mock Inspector\",\n color: \"\\x1b[95m\",\n delay: 150,\n });\n }\n\n printServerUrls(server, urlsToPrint);\n\n async function tryLoadMock(key: string): Promise<{ absolutePath: string; mockResult: Record<string, unknown> } | null> {\n const mockFilePath = mockFileMap.get(key);\n if (!mockFilePath) return null;\n\n const absolutePath = resolveAbsolutePath(mockFilePath);\n if (!fs.existsSync(absolutePath)) return null;\n\n const { default: mockModule } = await import(\n `${absolutePath}?t=${Date.now()}`\n );\n const mockResult =\n typeof mockModule.data === \"function\"\n ? mockModule.data()\n : mockModule;\n\n const { enable = true } = mockResult || {};\n return enable ? { absolutePath, mockResult } : null;\n }\n\n server.middlewares.use(\n async (\n req: IncomingMessage,\n res: ServerResponse,\n next: (err?: Error | unknown) => void,\n ): Promise<void> => {\n if (inspectorHandler && req.url) {\n const handled = await inspectorHandler(req, res);\n if (handled) return;\n }\n\n if (!req.url?.startsWith(apiPrefix)) {\n return next();\n }\n\n // Skip non-standard requests (SSE, WebSocket, file streams)\n const accept = req.headers.accept || \"\";\n const upgrade = req.headers.upgrade || \"\";\n if (accept.includes(\"text/event-stream\") || upgrade.toLowerCase() === \"websocket\") {\n return next();\n }\n\n const method = (req.method || \"GET\").toLowerCase();\n const pathname = new URL(req.url, \"http://localhost\").pathname;\n const key = `${pathname}/${method}.js`.toLowerCase();\n\n // 1. Try mock\n try {\n const mock = await tryLoadMock(key);\n if (mock) {\n serveMockResponse(res, mock.absolutePath, mock.mockResult);\n return;\n }\n } catch (error) {\n console.error(\"[automock] Failed to load mock file:\", error);\n }\n\n // 2. Try proxy\n if (!proxyBaseUrl) return next();\n\n try {\n proxyAndCapture(req, res, {\n proxyBaseUrl,\n pathRewrite,\n shouldSave: !mockFileMap.has(key),\n method,\n pathname,\n mockDir,\n onMockSaved: async () => {\n mockFileMap = await buildMockIndex(mockDir);\n },\n });\n } catch (error) {\n console.error(\"[automock] Proxy request error:\", error);\n sendError(res, \"Internal server error\");\n }\n },\n );\n },\n closeBundle() {\n watcher?.close();\n },\n transform() {\n return null;\n },\n };\n}\n","import path from \"path\";\nimport fs from \"fs-extra\";\nimport prettier from \"prettier\";\n\nimport { resolveAbsolutePath, toPosixPath } from \"./utils\";\n\nexport interface MockFileConfig {\n enable: boolean;\n data: unknown;\n delay: number;\n status: number;\n [key: string]: unknown;\n}\n\nexport interface MockFileInfo {\n config: MockFileConfig;\n serializable: boolean;\n hasDynamicData: boolean;\n headerComment?: string;\n description?: string;\n dataText: string;\n isBinary?: boolean;\n}\n\nexport const DEFAULT_CONFIG: MockFileConfig = {\n enable: true,\n data: null,\n delay: 0,\n status: 200,\n};\n\nconst isBufferTextLike = (buffer: Buffer): boolean => {\n try {\n const sample = buffer.slice(0, 100);\n const nullBytes = [...sample].filter((b) => b === 0).length;\n const controlChars = [...sample].filter(\n (b) => b < 32 && b !== 9 && b !== 10 && b !== 13,\n ).length;\n return nullBytes === 0 && controlChars < 5;\n } catch {\n return false;\n }\n};\n\nconst isBinaryResponse = (\n contentType: string | undefined,\n data: Buffer,\n): boolean => {\n if (!contentType) return false;\n\n const binaryTypes = [\n \"application/octet-stream\",\n \"application/pdf\",\n \"application/zip\",\n \"application/x-zip-compressed\",\n \"application/vnd.ms-excel\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.ms-powerpoint\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \"image/\",\n \"video/\",\n \"audio/\",\n ];\n\n return (\n binaryTypes.some((type) => contentType.toLowerCase().includes(type)) ||\n !isBufferTextLike(data)\n );\n};\n\nconst getFileExtension = (\n contentType: string | undefined,\n url: string,\n): string => {\n const mimeMap: Record<string, string> = {\n \"application/json\": \"json\",\n \"application/pdf\": \"pdf\",\n \"application/zip\": \"zip\",\n \"application/vnd.ms-excel\": \"xls\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\": \"xlsx\",\n \"application/msword\": \"doc\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\":\n \"docx\",\n \"application/vnd.ms-powerpoint\": \"ppt\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\":\n \"pptx\",\n \"image/jpeg\": \"jpg\",\n \"image/png\": \"png\",\n \"image/gif\": \"gif\",\n \"text/plain\": \"txt\",\n \"text/html\": \"html\",\n \"text/css\": \"css\",\n \"application/javascript\": \"js\",\n \"text/xml\": \"xml\",\n };\n\n if (contentType && mimeMap[contentType.toLowerCase()]) {\n return mimeMap[contentType.toLowerCase()];\n }\n\n try {\n const urlObj = new URL(url, \"http://localhost\");\n const fileName = urlObj.searchParams.get(\"file_name\");\n if (fileName) {\n const extensionMatch = fileName.match(/\\.([a-zA-Z0-9]+)$/);\n if (extensionMatch) {\n return extensionMatch[1];\n }\n }\n } catch {\n // Ignore URL parse errors\n }\n\n return \"bin\";\n};\n\nasync function formatWithPrettier(content: string): Promise<string> {\n try {\n return await prettier.format(content, { parser: \"babel\" });\n } catch {\n return content;\n }\n}\n\nfunction buildMockFileHeader(\n pathname: string,\n method: string,\n search: string,\n extra?: string,\n): string {\n return `/**\n * Mock data for ${pathname} (${method.toUpperCase()})${search || \"\"}\n * @description ${pathname}${search || \"\"}${extra ? ` - ${extra}` : \"\"}\n * Generated at ${new Date().toISOString()}\n */`;\n}\n\nasync function saveBinaryMock(\n filePath: string,\n binaryData: Buffer,\n pathname: string,\n method: string,\n search: string,\n contentType: string | undefined,\n url: string,\n statusCode: number | undefined,\n): Promise<string | null> {\n const extension = getFileExtension(contentType, url);\n const binaryFilePath = filePath.replace(/\\.js$/, \".\" + extension);\n\n if (fs.existsSync(binaryFilePath)) return null;\n\n fs.writeFileSync(binaryFilePath, binaryData);\n\n const header = buildMockFileHeader(pathname, method, search, `Binary file (${extension})`);\n const configContent = `${header}\nexport default {\n enable: false,\n data: {\n __binaryFile: '${extension}',\n __originalPath: '${pathname}',\n __originalQuery: '${search}',\n __originalUrl: '${pathname}${search || \"\"}',\n __contentType: '${contentType}',\n __fileSize: ${binaryData.length}\n },\n delay: 0,\n status: ${statusCode || 200}\n}`;\n\n const formatted = await formatWithPrettier(configContent);\n fs.writeFileSync(filePath, formatted, \"utf-8\");\n return filePath;\n}\n\nasync function saveJsonMock(\n filePath: string,\n dataStr: string,\n pathname: string,\n method: string,\n search: string,\n statusCode: number | undefined,\n): Promise<string | null> {\n if (fs.existsSync(filePath)) return null;\n\n let jsonData;\n if (!dataStr || dataStr.trim() === \"\") {\n jsonData = {\n error: true,\n message: `Empty response (${statusCode || \"unknown status\"})`,\n status: statusCode || 404,\n data: null,\n };\n } else {\n try {\n jsonData = JSON.parse(dataStr);\n if (statusCode && statusCode >= 400) {\n const errorMeta = { __mockStatusCode: statusCode, __isErrorResponse: true };\n jsonData =\n typeof jsonData === \"object\" && jsonData !== null\n ? { ...jsonData, ...errorMeta }\n : { originalData: jsonData, ...errorMeta };\n }\n } catch {\n jsonData = {\n error: true,\n message: `Non-JSON response (${statusCode || \"unknown status\"})`,\n status: statusCode || 404,\n data: dataStr,\n __mockStatusCode: statusCode,\n __isErrorResponse: true,\n };\n }\n }\n\n const header = buildMockFileHeader(pathname, method, search);\n const content = `${header}\nexport default {\n enable: false,\n data: ${JSON.stringify(jsonData)},\n delay: 0,\n status: ${statusCode || 200}\n}`;\n\n const formatted = await formatWithPrettier(content);\n fs.writeFileSync(filePath, formatted, \"utf-8\");\n return filePath;\n}\n\nexport async function saveMockData(\n url: string,\n method: string,\n data: Buffer | string,\n rootDir: string,\n statusCode?: number,\n contentType?: string,\n): Promise<string | null> {\n try {\n const absoluteRootDir = resolveAbsolutePath(rootDir);\n const urlObj = new URL(url, \"http://localhost\");\n const pathname = urlObj.pathname;\n const search = urlObj.search;\n\n const filePath = path.join(\n absoluteRootDir,\n pathname.replace(/^\\//, \"\"),\n method.toLowerCase() + \".js\",\n );\n\n await fs.ensureDir(path.dirname(filePath));\n\n const isBuffer = Buffer.isBuffer(data);\n const binaryData = isBuffer ? data : Buffer.from(data || \"\");\n const isBinary = isBinaryResponse(contentType, binaryData);\n\n if (isBinary) {\n return saveBinaryMock(\n filePath, binaryData, pathname, method, search,\n contentType, url, statusCode,\n );\n }\n\n const dataStr = isBuffer ? data.toString(\"utf8\") : data || \"\";\n return saveJsonMock(filePath, dataStr, pathname, method, search, statusCode);\n } catch (error) {\n console.error(`Failed to save mock data for ${url}:`, error);\n console.error(\n `URL details: url=${url}, method=${method}, statusCode=${statusCode}, contentType=${contentType}`,\n );\n throw error;\n }\n}\n\nconst recursiveReadAllFiles = async (dir: string): Promise<string[]> => {\n if (!(await fs.pathExists(dir))) return [];\n\n const files: string[] = [];\n try {\n const list = await fs.readdir(dir);\n for (const file of list) {\n const filePath = path.join(dir, file);\n const stat = await fs.stat(filePath);\n if (stat.isDirectory()) {\n files.push(...(await recursiveReadAllFiles(filePath)));\n } else {\n files.push(filePath);\n }\n }\n } catch (error) {\n console.error(`Error reading directory ${dir}:`, error);\n }\n return files;\n};\n\nexport async function buildMockIndex(mockDir: string): Promise<Map<string, string>> {\n const mockFileMap = new Map<string, string>();\n\n if (!(await fs.pathExists(mockDir))) {\n await fs.ensureDir(mockDir);\n return mockFileMap;\n }\n\n const files = await recursiveReadAllFiles(mockDir);\n\n files.forEach((filePath) => {\n if (!filePath.endsWith(\".js\")) return;\n\n try {\n const relativePath = path.relative(mockDir, filePath);\n const method = path.basename(filePath, \".js\");\n const dirPath = path.dirname(relativePath);\n const urlPath = \"/\" + toPosixPath(dirPath);\n const absolutePath = resolveAbsolutePath(filePath);\n const key = `${urlPath}/${method}.js`.toLowerCase();\n\n mockFileMap.set(key, absolutePath);\n } catch (error) {\n console.error(`[automock] Failed to process file ${filePath}:`, error);\n }\n });\n\n return mockFileMap;\n}\n\nexport async function parseMockModule(filePath: string): Promise<MockFileInfo> {\n const absolutePath = resolveAbsolutePath(filePath);\n\n if (!fs.existsSync(absolutePath)) {\n throw new Error(`Mock file does not exist: ${absolutePath}`);\n }\n\n const content = fs.readFileSync(absolutePath, \"utf-8\");\n const headerCommentMatch = content.match(/^(\\/\\*\\*[\\s\\S]*?\\*\\/)/);\n const headerComment = headerCommentMatch ? headerCommentMatch[1] : undefined;\n\n let description: string | undefined;\n if (headerComment) {\n const descMatch = headerComment.match(/@description\\s+(.+?)(?:\\n|\\*\\/)/s);\n if (descMatch) {\n description = descMatch[1].trim();\n }\n }\n\n const { default: mockModule } = await import(\n `${absolutePath}?t=${Date.now()}`\n );\n\n const exportedConfig =\n typeof mockModule === \"function\" ? mockModule() : mockModule;\n const hasDynamicData = typeof exportedConfig?.data === \"function\";\n const config: MockFileConfig = {\n ...DEFAULT_CONFIG,\n ...(exportedConfig ?? {}),\n };\n\n const serializable = !hasDynamicData;\n const dataObj =\n typeof config.data === \"object\" && config.data !== null\n ? (config.data as Record<string, unknown>)\n : null;\n const isBinary = dataObj !== null && \"__binaryFile\" in dataObj;\n\n return {\n config,\n serializable,\n hasDynamicData,\n headerComment,\n description,\n dataText: isBinary\n ? `/* Binary file: ${dataObj?.__binaryFile} */`\n : serializable\n ? JSON.stringify(config.data ?? null, null, 2)\n : \"/* data is generated dynamically and cannot be edited here */\",\n isBinary,\n };\n}\n\nexport async function writeMockFile(\n filePath: string,\n mockInfo: Pick<MockFileInfo, \"config\" | \"headerComment\" | \"description\">,\n): Promise<void> {\n const absolutePath = resolveAbsolutePath(filePath);\n\n let header = mockInfo.headerComment || \"\";\n\n if (mockInfo.description !== undefined) {\n if (header) {\n if (/@description/.test(header)) {\n header = header.replace(\n /@description\\s+.+?(?=\\n|\\*\\/)/s,\n `@description ${mockInfo.description}`,\n );\n } else {\n header = header.replace(\n /\\*\\//,\n ` * @description ${mockInfo.description}\\n */`,\n );\n }\n }\n }\n\n const content = header ? `${header}\\n` : \"\";\n const finalContent = `${content}export default ${JSON.stringify(mockInfo.config, null, 2)}\\n`;\n\n try {\n const formatted = await formatWithPrettier(finalContent);\n fs.writeFileSync(absolutePath, formatted, \"utf-8\");\n } catch {\n console.error(\"Error formatting code with prettier, writing raw content\");\n fs.writeFileSync(absolutePath, finalContent, \"utf-8\");\n }\n}\n","import path from \"path\";\n\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { AddressInfo } from \"net\";\n\nexport function resolveAbsolutePath(p: string): string {\n return path.isAbsolute(p) ? p : path.resolve(process.cwd(), p);\n}\n\nexport function toPosixPath(p: string): string {\n return p.replace(/\\\\/g, \"/\");\n}\n\nexport interface ServerAddress {\n protocol: string;\n host: string;\n port: number;\n}\n\nexport function getServerAddress(\n address: AddressInfo,\n isHttps: boolean,\n): ServerAddress {\n return {\n protocol: isHttps ? \"https\" : \"http\",\n host:\n address.address === \"::\" || address.address === \"0.0.0.0\"\n ? \"localhost\"\n : address.address,\n port: address.port,\n };\n}\n\nexport function sendJson(\n res: ServerResponse,\n data: unknown,\n status = 200,\n): void {\n res.setHeader(\"Content-Type\", \"application/json; charset=utf-8\");\n res.statusCode = status;\n res.end(typeof data === \"string\" ? data : JSON.stringify(data));\n}\n\nexport function sendError(\n res: ServerResponse,\n message: string,\n status = 500,\n): void {\n sendJson(res, { error: message }, status);\n}\n\nconst MAX_BODY_SIZE = 10 * 1024 * 1024; // 10MB\n\nexport function readBody(req: IncomingMessage): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n let totalSize = 0;\n req.on(\"data\", (chunk: Buffer) => {\n totalSize += chunk.length;\n if (totalSize > MAX_BODY_SIZE) {\n reject(new Error(\"Request body too large\"));\n req.destroy();\n return;\n }\n chunks.push(chunk);\n });\n req.on(\"end\", () => resolve(Buffer.concat(chunks).toString(\"utf-8\")));\n req.on(\"error\", reject);\n });\n}\n","import path from \"path\";\nimport fs from \"fs-extra\";\nimport { fileURLToPath } from \"url\";\n\n// ESM/CJS compatible __dirname\nconst _dirName = typeof __dirname !== \"undefined\"\n ? __dirname\n : path.dirname(fileURLToPath(import.meta.url));\nimport { parseMockModule, writeMockFile, saveMockData, buildMockIndex, type MockFileConfig } from \"./mockFileUtils\";\nimport { toPosixPath, sendJson, readBody } from \"./utils\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport type { AutomockPluginOptions, InspectorOptions } from \"./types\";\n\ninterface InspectorContext {\n req: IncomingMessage;\n res: ServerResponse;\n mockDir: string;\n inspectorRoute: string;\n apiPrefix: string;\n inspectorConfig: Required<InspectorOptions>;\n getMockFileMap: () => Map<string, string>;\n}\n\ninterface InspectorHandlerOptions {\n inspector: AutomockPluginOptions[\"inspector\"];\n apiPrefix: string;\n mockDir: string;\n getMockFileMap: () => Map<string, string>;\n}\n\ninterface InspectorApiContext extends InspectorContext {\n pathname: string;\n}\n\ninterface InspectorPayload {\n key: string;\n config?: Partial<MockFileConfig>;\n description?: string;\n}\n\ninterface MockItem {\n key: string;\n file: string;\n method: string;\n path: string;\n config: MockFileConfig;\n editable: boolean;\n description?: string;\n dataText: string;\n}\n\nfunction buildMockItem(\n key: string,\n filePath: string,\n mockDir: string,\n info: Awaited<ReturnType<typeof parseMockModule>>,\n): MockItem {\n return {\n key,\n file: path.relative(mockDir, filePath),\n method: key.split(\"/\").pop()?.replace(/\\.js$/, \"\") ?? \"get\",\n path: key.replace(/\\/[^/]+\\.js$/, \"\"),\n config: info.config,\n editable: info.serializable,\n description: info.description,\n dataText: info.dataText,\n };\n}\n\nexport const DEFAULT_ROUTE = \"/__mock/\";\n\nfunction ensureTrailingSlash(route: string): string {\n return route.endsWith(\"/\") ? route : `${route}/`;\n}\n\nfunction escapeHtml(value: string): string {\n return value\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nexport function normalizeInspectorConfig(\n input: AutomockPluginOptions[\"inspector\"],\n): Required<InspectorOptions> {\n if (input === false || input === undefined) {\n return { route: DEFAULT_ROUTE, enableToggle: true };\n }\n if (input === true) {\n return { route: DEFAULT_ROUTE, enableToggle: true };\n }\n return {\n route: ensureTrailingSlash(input.route ?? DEFAULT_ROUTE),\n enableToggle: input.enableToggle ?? true,\n };\n}\n\nexport type InspectorRequestHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<boolean>;\n\nexport function createInspectorHandler(\n options: InspectorHandlerOptions,\n): InspectorRequestHandler | null {\n if (!options.inspector) {\n return null;\n }\n\n const inspectorConfig = normalizeInspectorConfig(options.inspector);\n const inspectorRoute = ensureTrailingSlash(inspectorConfig.route);\n\n return async (req, res) => {\n if (!req.url) {\n return false;\n }\n const url = new URL(req.url, \"http://localhost\");\n if (!url.pathname.startsWith(inspectorRoute)) {\n return false;\n }\n\n await handleInspectorRequest({\n req,\n res,\n mockDir: options.mockDir,\n inspectorRoute,\n apiPrefix: options.apiPrefix,\n inspectorConfig,\n getMockFileMap: options.getMockFileMap,\n });\n\n return true;\n };\n}\n\nasync function handleInspectorRequest(\n context: InspectorContext,\n): Promise<void> {\n const { req, res, inspectorRoute } = context;\n const url = new URL(req.url || inspectorRoute, \"http://localhost\");\n const normalizedRoute = ensureTrailingSlash(inspectorRoute);\n\n if (\n url.pathname === normalizedRoute.slice(0, -1) ||\n url.pathname === normalizedRoute\n ) {\n await serveInspectorHtml(context);\n return;\n }\n\n const relativePath = url.pathname.startsWith(normalizedRoute)\n ? url.pathname.slice(normalizedRoute.length)\n : null;\n\n if (relativePath && relativePath.startsWith(\"api/\")) {\n await handleInspectorApi({ ...context, pathname: relativePath.slice(4) });\n return;\n }\n\n res.statusCode = 404;\n res.end(\"Not Found\");\n}\n\nasync function serveInspectorHtml({\n res,\n inspectorRoute,\n apiPrefix,\n inspectorConfig,\n}: InspectorContext): Promise<void> {\n const routeJson = JSON.stringify(ensureTrailingSlash(inspectorRoute));\n const allowToggleJson = JSON.stringify(inspectorConfig.enableToggle);\n const apiPrefixEscaped = escapeHtml(apiPrefix);\n\n const templatePath = path.join(_dirName, \"inspector-template.html\");\n const template = fs.readFileSync(templatePath, \"utf-8\");\n const html = template\n .replace(\"__API_PREFIX__\", apiPrefixEscaped)\n .replace(\"__ROUTE_JSON__\", routeJson)\n .replace(\"__ALLOW_TOGGLE_JSON__\", allowToggleJson);\n\n res.setHeader(\"Content-Type\", \"text/html; charset=utf-8\");\n res.end(html);\n}\n\nasync function handleList(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { res, mockDir } = ctx;\n const list = await Promise.all(\n Array.from(mockFileMap.entries()).map(async ([key, filePath]) => {\n const info = await parseMockModule(filePath);\n return buildMockItem(key, filePath, mockDir, info);\n }),\n );\n sendJson(res, { mocks: list });\n return true;\n}\n\nasync function handleDetail(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir } = ctx;\n const url = new URL(req.url || \"\", \"http://localhost\");\n const key = url.searchParams.get(\"key\");\n if (!key) {\n sendJson(res, { error: \"Missing key\" }, 400);\n return true;\n }\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n const info = await parseMockModule(filePath);\n sendJson(res, { mock: buildMockItem(key, filePath, mockDir, info) });\n return true;\n}\n\nasync function handleUpdate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir, inspectorConfig } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: InspectorPayload;\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const { key, config, description } = payload || {};\n if (!key) {\n sendJson(res, { error: \"Invalid payload: missing key\" }, 400);\n return true;\n }\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n\n const info = await parseMockModule(filePath);\n\n let nextConfig = info.config;\n if (config && typeof config === \"object\") {\n if (!inspectorConfig.enableToggle && config.enable !== undefined) {\n delete config.enable;\n }\n nextConfig = { ...info.config, ...config };\n }\n\n const nextDescription =\n description !== undefined ? description : info.description;\n\n await writeMockFile(filePath, {\n headerComment: info.headerComment,\n config: nextConfig,\n description: nextDescription,\n });\n\n const updatedInfo = await parseMockModule(filePath);\n sendJson(res, { mock: buildMockItem(key, filePath, mockDir, updatedInfo) });\n return true;\n}\n\nasync function handleCreate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res, mockDir, apiPrefix } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: { method: string; path: string; description?: string; data?: unknown };\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const { method, path: apiPath, data } = payload || {};\n if (!method || !apiPath) {\n sendJson(res, { error: \"Invalid payload: missing method or path\" }, 400);\n return true;\n }\n\n const fullUrl = apiPrefix + apiPath;\n\n try {\n let dataToSave: Buffer | string;\n if (typeof data === \"object\" && data !== null) {\n dataToSave = JSON.stringify(data, null, 2);\n } else {\n dataToSave = typeof data === \"string\" ? data : \"\";\n }\n\n await saveMockData(fullUrl, method.toLowerCase(), dataToSave, mockDir, 200);\n\n const newMockFileMap = await buildMockIndex(mockDir);\n for (const [key, value] of newMockFileMap.entries()) {\n mockFileMap.set(key, value);\n }\n\n const normalizedPath = toPosixPath(apiPath);\n const key = (normalizedPath.startsWith(\"/\") ? \"\" : \"/\") +\n normalizedPath.toLowerCase() + \"/\" + method.toLowerCase() + \".js\";\n const filePath = mockFileMap.get(key);\n\n if (!filePath) {\n sendJson(res, { error: \"Mock file created but not found in map\" }, 500);\n return true;\n }\n\n const info = await parseMockModule(filePath);\n sendJson(res, {\n success: true,\n mock: buildMockItem(key, filePath, mockDir, info),\n });\n return true;\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n sendJson(res, { error: \"Failed to create mock: \" + errorMessage }, 500);\n return true;\n }\n}\n\nasync function handleDelete(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res } = ctx;\n const url = new URL(req.url || \"\", \"http://localhost\");\n const key = url.searchParams.get(\"key\");\n if (!key) {\n sendJson(res, { error: \"Missing key\" }, 400);\n return true;\n }\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n sendJson(res, { error: \"Mock not found\" }, 404);\n return true;\n }\n\n try {\n const stats = await fs.stat(filePath);\n if (stats.isDirectory()) {\n await fs.remove(filePath);\n for (const [mapKey, mapPath] of mockFileMap.entries()) {\n if (mapPath.startsWith(filePath + path.sep) || mapPath === filePath) {\n mockFileMap.delete(mapKey);\n }\n }\n } else {\n await fs.unlink(filePath);\n mockFileMap.delete(key);\n }\n sendJson(res, { success: true });\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n sendJson(res, { error: \"Failed to delete: \" + errorMessage }, 500);\n }\n return true;\n}\n\ntype ApiHandler = (ctx: InspectorApiContext, mockFileMap: Map<string, string>) => Promise<boolean>;\n\nasync function handleBatchUpdate(\n ctx: InspectorApiContext,\n mockFileMap: Map<string, string>,\n): Promise<boolean> {\n const { req, res } = ctx;\n if (req.method !== \"POST\") {\n sendJson(res, { error: \"Method not allowed\" }, 405);\n return true;\n }\n const body = await readBody(req);\n let payload: { updates?: Array<{ key: string; config?: Record<string, unknown> }> };\n try {\n payload = JSON.parse(body);\n } catch {\n sendJson(res, { error: \"Invalid JSON body\" }, 400);\n return true;\n }\n\n const updates = payload?.updates;\n if (!Array.isArray(updates) || updates.length === 0) {\n sendJson(res, { error: \"Invalid payload: updates must be a non-empty array\" }, 400);\n return true;\n }\n\n let updated = 0;\n const errors: string[] = [];\n\n for (const item of updates) {\n const { key, config } = item;\n if (!key) continue;\n\n const filePath = mockFileMap.get(key);\n if (!filePath) {\n errors.push(`Mock not found: ${key}`);\n continue;\n }\n\n try {\n const info = await parseMockModule(filePath);\n const nextConfig = config ? { ...info.config, ...config } : info.config;\n\n await writeMockFile(filePath, {\n headerComment: info.headerComment,\n config: nextConfig,\n description: info.description,\n });\n updated++;\n } catch (err) {\n errors.push(`Failed to update ${key}: ${err instanceof Error ? err.message : String(err)}`);\n }\n }\n\n sendJson(res, { success: true, updated, errors: errors.length > 0 ? errors : undefined });\n return true;\n}\n\nconst API_ROUTES: Record<string, ApiHandler> = {\n list: handleList,\n detail: handleDetail,\n update: handleUpdate,\n \"batch-update\": handleBatchUpdate,\n create: handleCreate,\n delete: handleDelete,\n};\n\nasync function handleInspectorApi(ctx: InspectorApiContext): Promise<void> {\n try {\n const mockFileMap = ctx.getMockFileMap();\n const handler = API_ROUTES[ctx.pathname];\n if (handler) {\n await handler(ctx, mockFileMap);\n return;\n }\n sendJson(ctx.res, { error: \"Unknown inspector endpoint\" }, 404);\n } catch (error) {\n console.error(\"[automock] Inspector request failed:\", error);\n sendJson(ctx.res, { error: \"Inspector failed\" }, 500);\n }\n}\n","import path from 'path'\nimport fs from 'fs-extra'\n\nimport { buildMockIndex, parseMockModule } from './mockFileUtils'\n\nexport interface MockBundleData {\n enable: boolean\n data: unknown\n delay: number\n status: number\n isBinary?: boolean\n}\n\nexport interface MockBundle {\n [key: string]: MockBundleData\n}\n\nexport interface BundleOptions {\n mockDir: string\n includeDisabled?: boolean\n log?: boolean\n}\n\nconst DEFAULT_BUNDLE_OPTIONS: Partial<BundleOptions> = {\n includeDisabled: true,\n log: true\n}\n\nasync function bundleMockFiles(options: BundleOptions): Promise<MockBundle> {\n const opts = { ...DEFAULT_BUNDLE_OPTIONS, ...options }\n const { mockDir, log } = opts\n\n if (!fs.existsSync(mockDir)) {\n if (log) {\n console.log(`[mock-bundler] Mock directory does not exist: ${mockDir}`)\n }\n return {}\n }\n\n const mockFileMap = await buildMockIndex(mockDir)\n const bundle: MockBundle = {}\n let bundledCount = 0\n let skippedCount = 0\n\n for (const [key, filePath] of mockFileMap) {\n try {\n const mockInfo = await parseMockModule(filePath)\n\n if (!mockInfo.serializable) {\n skippedCount++\n if (log) {\n console.log(`[mock-bundler] Skipping non-serializable mock: ${key}`)\n }\n continue\n }\n\n bundle[key] = {\n enable: mockInfo.config.enable,\n data: mockInfo.config.data,\n delay: mockInfo.config.delay,\n status: mockInfo.config.status,\n isBinary: mockInfo.isBinary\n }\n\n bundledCount++\n } catch (error) {\n if (log) {\n console.error(`[mock-bundler] Failed to bundle mock ${key}:`, error)\n }\n }\n }\n\n if (log) {\n console.log(`[mock-bundler] Bundled ${bundledCount} mocks, skipped ${skippedCount} non-serializable mocks`)\n }\n\n return bundle\n}\n\nfunction writeMockBundle(bundle: MockBundle, outputPath: string): void {\n const outputDir = path.dirname(outputPath)\n\n if (!fs.existsSync(outputDir)) {\n fs.ensureDirSync(outputDir)\n }\n\n fs.writeFileSync(\n outputPath,\n JSON.stringify(bundle, null, 2),\n 'utf-8'\n )\n}\n\nexport { bundleMockFiles, writeMockBundle }\n"],"mappings":";;;;;;;;;;;AAAA,OAAOA,WAAU;AACjB,OAAOC,SAAQ;;;ACDf,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,OAAOC,WAAU;AACjB,OAAOC,SAAQ;AACf,OAAO,UAAU;AACjB,OAAO,WAAW;;;ACLlB,OAAOC,WAAU;AACjB,OAAO,QAAQ;AACf,OAAO,cAAc;;;ACFrB,OAAO,UAAU;AAKV,SAAS,oBAAoB,GAAmB;AACrD,SAAO,KAAK,WAAW,CAAC,IAAI,IAAI,KAAK,QAAQ,QAAQ,IAAI,GAAG,CAAC;AAC/D;AAEO,SAAS,YAAY,GAAmB;AAC7C,SAAO,EAAE,QAAQ,OAAO,GAAG;AAC7B;AAQO,SAAS,iBACd,SAC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C;AAEtC,QAAM,qBAAqB,MAAM;AAC/B,UAAM,aAAaC,MAAK,KAAK,QAAQ,IAAI,GAAG,gBAAgB;AAC5D,QAAI,CAACC,IAAG,WAAW,UAAU,KAAK,cAAc;AAC9C,cAAQ,IAAI,sCAAsC;AAClD,sBAAgB,cAAc,UAAU;AAAA,IAC1C;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AAAA,IACN,SAAS;AAEP,YAAM,UAAU,cAAc,mBAAmB;AACjD,aAAO;AAAA,QACL,QAAQ;AAAA,UACN,sBAAsB,KAAK,UAAU,OAAO;AAAA,QAC9C;AAAA,MACF;AAAA,IACF;AAAA,IACA,UAAU,YAAY;AACpB,UAAI,kBAAkB,cAAc,mBAAmB,OAAO;AAC5D,YAAI;AACF,gBAAM,UAAU,cAAc,WAAWD,MAAK,KAAK,QAAQ,IAAI,GAAG,MAAM;AAExE,cAAI,CAACC,IAAG,WAAW,OAAO,GAAG;AAC3B,oBAAQ,IAAI,iEAAiE;AAC7E,oBAAQ,IAAI,qDAAqD;AACjE;AAAA,UACF;AAEA,gBAAM,cAAc,MAAM,eAAe,OAAO;AAChD,cAAI,YAAY,SAAS,GAAG;AAC1B,oBAAQ,IAAI,4DAA4D;AACxE;AAAA,UACF;AAEA,yBAAe,MAAM,gBAAgB,EAAE,QAAQ,CAAC;AAEhD,gBAAM,aAAaD,MAAK,KAAK,QAAQ,IAAI,GAAG,gBAAgB;AAC5D,0BAAgB,cAAc,UAAU;AACxC,kBAAQ,IAAI,sCAAsC,UAAU,EAAE;AAAA,QAChE,SAAS,OAAO;AACd,kBAAQ,MAAM,0CAA0C,KAAK;AAAA,QAC/D;AAAA,MACF;AAAA,IACF;AAAA,IACA,aAAa;AAAA,IACb,aAAa;AAAA,EACf;AACF;","names":["path","fs","path","fs","path","path","path","fs","path","fs","key","fs","path","path","fs","fs","path","automock","path","fs"]}
|