vite-plugin-webmcp-nexus 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -62,10 +62,10 @@ function vitePluginWebMcp(options = {}) {
|
|
|
62
62
|
transform(code, id) {
|
|
63
63
|
const cleanId = id.split("?")[0];
|
|
64
64
|
if (!/\.[jt]sx?$/.test(cleanId)) return null;
|
|
65
|
-
const relativePath = import_node_path.default.relative(projectRoot, cleanId);
|
|
65
|
+
const relativePath = import_node_path.default.relative(projectRoot, cleanId).replace(/\\/g, "/");
|
|
66
66
|
const isIncluded = include.some((pattern) => {
|
|
67
67
|
const regex = new RegExp(
|
|
68
|
-
"^" + pattern.replace(/\./g, "\\.").replace(/\*\*\//g, "
|
|
68
|
+
"^" + pattern.replace(/\./g, "\\.").replace(/\*\*\//g, "").replace(/\*/g, "[^/]*").replace(/\x01/g, "(?:.*\\/)?") + "$"
|
|
69
69
|
);
|
|
70
70
|
return regex.test(relativePath);
|
|
71
71
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * vite-plugin-webmcp-nexus\n *\n * Vite 插件胶水层,在构建时通过 transform hook 委托 webmcp-nexus-core\n * 自动提取 TypeScript 类型并注入 __webmcpSchema 属性。\n */\n\nimport nodePath from 'node:path';\nimport type { Plugin, ResolvedConfig } from 'vite';\nimport { transformCode, type AliasMap } from 'webmcp-nexus-core';\n\nconst isDebug = () => (process.env.DEBUG ?? '').toLowerCase().includes('webmcp');\n\nexport interface WebMcpPluginOptions {\n /** 扫描范围(glob patterns),默认 ['src/\\*\\*\\/*.ts', 'src/\\*\\*\\/*.tsx'] */\n include?: string[];\n /**\n * 额外的模块路径 alias(合并到 vite 的 resolve.alias 之上)。\n * 用于解析 `import * as api from '@alias/xxx'` 类型的模块说明符。\n */\n alias?: Record<string, string>;\n}\n\n/**\n * 将 Vite 解析后的 resolve.alias(Alias[] 形式)归一化为 Record<string, string>。\n * 仅取 find 为 string 的项;RegExp find 无法直接形成前缀匹配表,忽略。\n */\nfunction normalizeViteAlias(raw: ResolvedConfig['resolve']['alias']): Record<string, string> {\n const out: Record<string, string> = {};\n if (!raw) return out;\n const list = Array.isArray(raw) ? raw : [];\n for (const item of list) {\n if (!item || typeof item.find !== 'string' || typeof item.replacement !== 'string') continue;\n out[item.find] = item.replacement;\n }\n return out;\n}\n\nexport function vitePluginWebMcp(options: WebMcpPluginOptions = {}): Plugin {\n const { include = ['src/**/*.ts', 'src/**/*.tsx'], alias: userAlias = {} } = options;\n let projectRoot = '';\n let mergedAlias: AliasMap = {};\n\n return {\n name: 'vite-plugin-webmcp',\n enforce: 'pre',\n\n configResolved(config) {\n projectRoot = config.root;\n const viteAlias = normalizeViteAlias(config.resolve?.alias);\n // 用户显式配置优先覆盖 vite 默认 alias\n mergedAlias = { ...viteAlias, ...userAlias };\n },\n\n transform(code: string, id: string) {\n const cleanId = id.split('?')[0];\n if (!/\\.[jt]sx?$/.test(cleanId)) return null;\n\n // include
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * vite-plugin-webmcp-nexus\n *\n * Vite 插件胶水层,在构建时通过 transform hook 委托 webmcp-nexus-core\n * 自动提取 TypeScript 类型并注入 __webmcpSchema 属性。\n */\n\nimport nodePath from 'node:path';\nimport type { Plugin, ResolvedConfig } from 'vite';\nimport { transformCode, type AliasMap } from 'webmcp-nexus-core';\n\nconst isDebug = () => (process.env.DEBUG ?? '').toLowerCase().includes('webmcp');\n\nexport interface WebMcpPluginOptions {\n /** 扫描范围(glob patterns),默认 ['src/\\*\\*\\/*.ts', 'src/\\*\\*\\/*.tsx'] */\n include?: string[];\n /**\n * 额外的模块路径 alias(合并到 vite 的 resolve.alias 之上)。\n * 用于解析 `import * as api from '@alias/xxx'` 类型的模块说明符。\n */\n alias?: Record<string, string>;\n}\n\n/**\n * 将 Vite 解析后的 resolve.alias(Alias[] 形式)归一化为 Record<string, string>。\n * 仅取 find 为 string 的项;RegExp find 无法直接形成前缀匹配表,忽略。\n */\nfunction normalizeViteAlias(raw: ResolvedConfig['resolve']['alias']): Record<string, string> {\n const out: Record<string, string> = {};\n if (!raw) return out;\n const list = Array.isArray(raw) ? raw : [];\n for (const item of list) {\n if (!item || typeof item.find !== 'string' || typeof item.replacement !== 'string') continue;\n out[item.find] = item.replacement;\n }\n return out;\n}\n\nexport function vitePluginWebMcp(options: WebMcpPluginOptions = {}): Plugin {\n const { include = ['src/**/*.ts', 'src/**/*.tsx'], alias: userAlias = {} } = options;\n let projectRoot = '';\n let mergedAlias: AliasMap = {};\n\n return {\n name: 'vite-plugin-webmcp',\n enforce: 'pre',\n\n configResolved(config) {\n projectRoot = config.root;\n const viteAlias = normalizeViteAlias(config.resolve?.alias);\n // 用户显式配置优先覆盖 vite 默认 alias\n mergedAlias = { ...viteAlias, ...userAlias };\n },\n\n transform(code: string, id: string) {\n const cleanId = id.split('?')[0];\n if (!/\\.[jt]sx?$/.test(cleanId)) return null;\n\n // include 匹配检查(node:path.relative 在 Windows 上返回反斜杠,而 include 正则仅识别正斜杠)\n const relativePath = nodePath.relative(projectRoot, cleanId).replace(/\\\\/g, '/');\n const isIncluded = include.some(pattern => {\n const regex = new RegExp(\n '^' +\n pattern\n .replace(/\\./g, '\\\\.')\n // 先用占位符暂存 **/,避免后续 * 替换破坏 .* 中的 *\n .replace(/\\*\\*\\//g, '\\x01')\n .replace(/\\*/g, '[^/]*')\n .replace(/\\x01/g, '(?:.*\\\\/)?') +\n '$',\n );\n return regex.test(relativePath);\n });\n if (!isIncluded) return null;\n\n if (isDebug()) {\n console.log(`[webmcp] vite transform processing: ${cleanId}`);\n }\n\n // 委托给 webmcp-nexus-core\n try {\n const result = transformCode(code, cleanId, { projectRoot, alias: mergedAlias });\n\n if (result.transformed) {\n if (isDebug()) {\n console.log(`[webmcp] vite transformed: ${cleanId}`);\n }\n return { code: result.code, map: null };\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n this.warn(`[webmcp] transform failed for ${cleanId}: ${message}`);\n if (isDebug()) {\n console.warn(`[webmcp] transform error:`, err);\n }\n }\n\n return null;\n },\n };\n}\n\nexport default vitePluginWebMcp;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,uBAAqB;AAErB,+BAA6C;AAE7C,IAAM,UAAU,OAAO,QAAQ,IAAI,SAAS,IAAI,YAAY,EAAE,SAAS,QAAQ;AAgB/E,SAAS,mBAAmB,KAAiE;AAC3F,QAAM,MAA8B,CAAC;AACrC,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,OAAO,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC;AACzC,aAAW,QAAQ,MAAM;AACvB,QAAI,CAAC,QAAQ,OAAO,KAAK,SAAS,YAAY,OAAO,KAAK,gBAAgB,SAAU;AACpF,QAAI,KAAK,IAAI,IAAI,KAAK;AAAA,EACxB;AACA,SAAO;AACT;AAEO,SAAS,iBAAiB,UAA+B,CAAC,GAAW;AAC1E,QAAM,EAAE,UAAU,CAAC,eAAe,cAAc,GAAG,OAAO,YAAY,CAAC,EAAE,IAAI;AAC7E,MAAI,cAAc;AAClB,MAAI,cAAwB,CAAC;AAE7B,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,eAAe,QAAQ;AACrB,oBAAc,OAAO;AACrB,YAAM,YAAY,mBAAmB,OAAO,SAAS,KAAK;AAE1D,oBAAc,EAAE,GAAG,WAAW,GAAG,UAAU;AAAA,IAC7C;AAAA,IAEA,UAAU,MAAc,IAAY;AAClC,YAAM,UAAU,GAAG,MAAM,GAAG,EAAE,CAAC;AAC/B,UAAI,CAAC,aAAa,KAAK,OAAO,EAAG,QAAO;AAGxC,YAAM,eAAe,iBAAAA,QAAS,SAAS,aAAa,OAAO,EAAE,QAAQ,OAAO,GAAG;AAC/E,YAAM,aAAa,QAAQ,KAAK,aAAW;AACzC,cAAM,QAAQ,IAAI;AAAA,UAChB,MACE,QACG,QAAQ,OAAO,KAAK,EAEpB,QAAQ,WAAW,GAAM,EACzB,QAAQ,OAAO,OAAO,EACtB,QAAQ,SAAS,YAAY,IAChC;AAAA,QACJ;AACA,eAAO,MAAM,KAAK,YAAY;AAAA,MAChC,CAAC;AACD,UAAI,CAAC,WAAY,QAAO;AAExB,UAAI,QAAQ,GAAG;AACb,gBAAQ,IAAI,uCAAuC,OAAO,EAAE;AAAA,MAC9D;AAGA,UAAI;AACF,cAAM,aAAS,wCAAc,MAAM,SAAS,EAAE,aAAa,OAAO,YAAY,CAAC;AAE/E,YAAI,OAAO,aAAa;AACtB,cAAI,QAAQ,GAAG;AACb,oBAAQ,IAAI,8BAA8B,OAAO,EAAE;AAAA,UACrD;AACA,iBAAO,EAAE,MAAM,OAAO,MAAM,KAAK,KAAK;AAAA,QACxC;AAAA,MACF,SAAS,KAAc;AACrB,cAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC/D,aAAK,KAAK,iCAAiC,OAAO,KAAK,OAAO,EAAE;AAChE,YAAI,QAAQ,GAAG;AACb,kBAAQ,KAAK,6BAA6B,GAAG;AAAA,QAC/C;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["nodePath"]}
|
package/dist/index.js
CHANGED
|
@@ -27,10 +27,10 @@ function vitePluginWebMcp(options = {}) {
|
|
|
27
27
|
transform(code, id) {
|
|
28
28
|
const cleanId = id.split("?")[0];
|
|
29
29
|
if (!/\.[jt]sx?$/.test(cleanId)) return null;
|
|
30
|
-
const relativePath = nodePath.relative(projectRoot, cleanId);
|
|
30
|
+
const relativePath = nodePath.relative(projectRoot, cleanId).replace(/\\/g, "/");
|
|
31
31
|
const isIncluded = include.some((pattern) => {
|
|
32
32
|
const regex = new RegExp(
|
|
33
|
-
"^" + pattern.replace(/\./g, "\\.").replace(/\*\*\//g, "
|
|
33
|
+
"^" + pattern.replace(/\./g, "\\.").replace(/\*\*\//g, "").replace(/\*/g, "[^/]*").replace(/\x01/g, "(?:.*\\/)?") + "$"
|
|
34
34
|
);
|
|
35
35
|
return regex.test(relativePath);
|
|
36
36
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * vite-plugin-webmcp-nexus\n *\n * Vite 插件胶水层,在构建时通过 transform hook 委托 webmcp-nexus-core\n * 自动提取 TypeScript 类型并注入 __webmcpSchema 属性。\n */\n\nimport nodePath from 'node:path';\nimport type { Plugin, ResolvedConfig } from 'vite';\nimport { transformCode, type AliasMap } from 'webmcp-nexus-core';\n\nconst isDebug = () => (process.env.DEBUG ?? '').toLowerCase().includes('webmcp');\n\nexport interface WebMcpPluginOptions {\n /** 扫描范围(glob patterns),默认 ['src/\\*\\*\\/*.ts', 'src/\\*\\*\\/*.tsx'] */\n include?: string[];\n /**\n * 额外的模块路径 alias(合并到 vite 的 resolve.alias 之上)。\n * 用于解析 `import * as api from '@alias/xxx'` 类型的模块说明符。\n */\n alias?: Record<string, string>;\n}\n\n/**\n * 将 Vite 解析后的 resolve.alias(Alias[] 形式)归一化为 Record<string, string>。\n * 仅取 find 为 string 的项;RegExp find 无法直接形成前缀匹配表,忽略。\n */\nfunction normalizeViteAlias(raw: ResolvedConfig['resolve']['alias']): Record<string, string> {\n const out: Record<string, string> = {};\n if (!raw) return out;\n const list = Array.isArray(raw) ? raw : [];\n for (const item of list) {\n if (!item || typeof item.find !== 'string' || typeof item.replacement !== 'string') continue;\n out[item.find] = item.replacement;\n }\n return out;\n}\n\nexport function vitePluginWebMcp(options: WebMcpPluginOptions = {}): Plugin {\n const { include = ['src/**/*.ts', 'src/**/*.tsx'], alias: userAlias = {} } = options;\n let projectRoot = '';\n let mergedAlias: AliasMap = {};\n\n return {\n name: 'vite-plugin-webmcp',\n enforce: 'pre',\n\n configResolved(config) {\n projectRoot = config.root;\n const viteAlias = normalizeViteAlias(config.resolve?.alias);\n // 用户显式配置优先覆盖 vite 默认 alias\n mergedAlias = { ...viteAlias, ...userAlias };\n },\n\n transform(code: string, id: string) {\n const cleanId = id.split('?')[0];\n if (!/\\.[jt]sx?$/.test(cleanId)) return null;\n\n // include
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * vite-plugin-webmcp-nexus\n *\n * Vite 插件胶水层,在构建时通过 transform hook 委托 webmcp-nexus-core\n * 自动提取 TypeScript 类型并注入 __webmcpSchema 属性。\n */\n\nimport nodePath from 'node:path';\nimport type { Plugin, ResolvedConfig } from 'vite';\nimport { transformCode, type AliasMap } from 'webmcp-nexus-core';\n\nconst isDebug = () => (process.env.DEBUG ?? '').toLowerCase().includes('webmcp');\n\nexport interface WebMcpPluginOptions {\n /** 扫描范围(glob patterns),默认 ['src/\\*\\*\\/*.ts', 'src/\\*\\*\\/*.tsx'] */\n include?: string[];\n /**\n * 额外的模块路径 alias(合并到 vite 的 resolve.alias 之上)。\n * 用于解析 `import * as api from '@alias/xxx'` 类型的模块说明符。\n */\n alias?: Record<string, string>;\n}\n\n/**\n * 将 Vite 解析后的 resolve.alias(Alias[] 形式)归一化为 Record<string, string>。\n * 仅取 find 为 string 的项;RegExp find 无法直接形成前缀匹配表,忽略。\n */\nfunction normalizeViteAlias(raw: ResolvedConfig['resolve']['alias']): Record<string, string> {\n const out: Record<string, string> = {};\n if (!raw) return out;\n const list = Array.isArray(raw) ? raw : [];\n for (const item of list) {\n if (!item || typeof item.find !== 'string' || typeof item.replacement !== 'string') continue;\n out[item.find] = item.replacement;\n }\n return out;\n}\n\nexport function vitePluginWebMcp(options: WebMcpPluginOptions = {}): Plugin {\n const { include = ['src/**/*.ts', 'src/**/*.tsx'], alias: userAlias = {} } = options;\n let projectRoot = '';\n let mergedAlias: AliasMap = {};\n\n return {\n name: 'vite-plugin-webmcp',\n enforce: 'pre',\n\n configResolved(config) {\n projectRoot = config.root;\n const viteAlias = normalizeViteAlias(config.resolve?.alias);\n // 用户显式配置优先覆盖 vite 默认 alias\n mergedAlias = { ...viteAlias, ...userAlias };\n },\n\n transform(code: string, id: string) {\n const cleanId = id.split('?')[0];\n if (!/\\.[jt]sx?$/.test(cleanId)) return null;\n\n // include 匹配检查(node:path.relative 在 Windows 上返回反斜杠,而 include 正则仅识别正斜杠)\n const relativePath = nodePath.relative(projectRoot, cleanId).replace(/\\\\/g, '/');\n const isIncluded = include.some(pattern => {\n const regex = new RegExp(\n '^' +\n pattern\n .replace(/\\./g, '\\\\.')\n // 先用占位符暂存 **/,避免后续 * 替换破坏 .* 中的 *\n .replace(/\\*\\*\\//g, '\\x01')\n .replace(/\\*/g, '[^/]*')\n .replace(/\\x01/g, '(?:.*\\\\/)?') +\n '$',\n );\n return regex.test(relativePath);\n });\n if (!isIncluded) return null;\n\n if (isDebug()) {\n console.log(`[webmcp] vite transform processing: ${cleanId}`);\n }\n\n // 委托给 webmcp-nexus-core\n try {\n const result = transformCode(code, cleanId, { projectRoot, alias: mergedAlias });\n\n if (result.transformed) {\n if (isDebug()) {\n console.log(`[webmcp] vite transformed: ${cleanId}`);\n }\n return { code: result.code, map: null };\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n this.warn(`[webmcp] transform failed for ${cleanId}: ${message}`);\n if (isDebug()) {\n console.warn(`[webmcp] transform error:`, err);\n }\n }\n\n return null;\n },\n };\n}\n\nexport default vitePluginWebMcp;\n"],"mappings":";AAOA,OAAO,cAAc;AAErB,SAAS,qBAAoC;AAE7C,IAAM,UAAU,OAAO,QAAQ,IAAI,SAAS,IAAI,YAAY,EAAE,SAAS,QAAQ;AAgB/E,SAAS,mBAAmB,KAAiE;AAC3F,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a,OAAO,YAAY,CAAC;AAE/E,YAAI,OAAO,aAAa;AACtB,cAAI,QAAQ,GAAG;AACb,oBAAQ,IAAI,8BAA8B,OAAO,EAAE;AAAA,UACrD;AACA,iBAAO,EAAE,MAAM,OAAO,MAAM,KAAK,KAAK;AAAA,QACxC;AAAA,MACF,SAAS,KAAc;AACrB,cAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC/D,aAAK,KAAK,iCAAiC,OAAO,KAAK,OAAO,EAAE;AAChE,YAAI,QAAQ,GAAG;AACb,kBAAQ,KAAK,6BAA6B,GAAG;AAAA,QAC/C;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-webmcp-nexus",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Vite plugin for WebMCP Nexus - auto-generates JSON Schema from TypeScript tool definitions at build time",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"dist"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"webmcp-nexus-core": "0.1.
|
|
42
|
-
"webmcp-nexus-sdk": "0.1.
|
|
41
|
+
"webmcp-nexus-core": "0.1.14",
|
|
42
|
+
"webmcp-nexus-sdk": "0.1.14"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"vite": "^7.0.0 || ^8.0.0"
|