@pyreon/mcp 0.5.0 → 0.5.2

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/lib/index.js CHANGED
@@ -3,9 +3,7 @@ import Ajv from "ajv";
3
3
  import _addFormats from "ajv-formats";
4
4
  import { ZodOptional, z } from "zod";
5
5
  import process$1 from "node:process";
6
- import { detectReactPatterns, diagnoseError, migrateReactCode } from "@pyreon/compiler";
7
- import * as fs from "node:fs";
8
- import * as path from "node:path";
6
+ import { detectReactPatterns, diagnoseError, generateContext, migrateReactCode } from "@pyreon/compiler";
9
7
 
10
8
  //#region ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v3/helpers/util.js
11
9
  var util;
@@ -3679,10 +3677,7 @@ function assignProp(target, prop, value) {
3679
3677
  }
3680
3678
  function mergeDefs(...defs) {
3681
3679
  const mergedDescriptors = {};
3682
- for (const def of defs) {
3683
- const descriptors = Object.getOwnPropertyDescriptors(def);
3684
- Object.assign(mergedDescriptors, descriptors);
3685
- }
3680
+ for (const def of defs) Object.assign(mergedDescriptors, Object.getOwnPropertyDescriptors(def));
3686
3681
  return Object.defineProperties({}, mergedDescriptors);
3687
3682
  }
3688
3683
  function esc(str) {
@@ -13111,159 +13106,6 @@ hydrateRoot(<App />, document.getElementById("app")!)`
13111
13106
  }
13112
13107
  };
13113
13108
 
13114
- //#endregion
13115
- //#region src/project-scanner.ts
13116
- /**
13117
- * Project scanner — extracts route, component, and island information from source files.
13118
- */
13119
- function generateContext(cwd) {
13120
- const files = collectSourceFiles(cwd);
13121
- return {
13122
- framework: "pyreon",
13123
- version: readVersion(cwd),
13124
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
13125
- routes: extractRoutes(files, cwd),
13126
- components: extractComponents(files, cwd),
13127
- islands: extractIslands(files, cwd)
13128
- };
13129
- }
13130
- function collectSourceFiles(cwd) {
13131
- const results = [];
13132
- const extensions = new Set([
13133
- ".tsx",
13134
- ".jsx",
13135
- ".ts",
13136
- ".js"
13137
- ]);
13138
- const ignoreDirs = new Set([
13139
- "node_modules",
13140
- "dist",
13141
- "lib",
13142
- ".pyreon",
13143
- ".git",
13144
- "build"
13145
- ]);
13146
- function walk(dir) {
13147
- let entries;
13148
- try {
13149
- entries = fs.readdirSync(dir, { withFileTypes: true });
13150
- } catch {
13151
- return;
13152
- }
13153
- for (const entry of entries) {
13154
- if (entry.name.startsWith(".") && entry.isDirectory()) continue;
13155
- if (ignoreDirs.has(entry.name) && entry.isDirectory()) continue;
13156
- const fullPath = path.join(dir, entry.name);
13157
- if (entry.isDirectory()) walk(fullPath);
13158
- else if (entry.isFile() && extensions.has(path.extname(entry.name))) results.push(fullPath);
13159
- }
13160
- }
13161
- walk(cwd);
13162
- return results;
13163
- }
13164
- function extractRoutes(files, _cwd) {
13165
- const routes = [];
13166
- for (const file of files) {
13167
- let code;
13168
- try {
13169
- code = fs.readFileSync(file, "utf-8");
13170
- } catch {
13171
- continue;
13172
- }
13173
- const routeArrayRe = /(?:createRouter\s*\(\s*\[|(?:const|let)\s+routes\s*(?::\s*RouteRecord\[\])?\s*=\s*\[)([\s\S]*?)\]/g;
13174
- let match;
13175
- for (match = routeArrayRe.exec(code); match; match = routeArrayRe.exec(code)) {
13176
- const block = match[1] ?? "";
13177
- const routeObjRe = /path\s*:\s*["']([^"']+)["']/g;
13178
- let routeMatch;
13179
- for (routeMatch = routeObjRe.exec(block); routeMatch; routeMatch = routeObjRe.exec(block)) {
13180
- const routePath = routeMatch[1] ?? "";
13181
- const surroundingStart = Math.max(0, routeMatch.index - 50);
13182
- const surroundingEnd = Math.min(block.length, routeMatch.index + 200);
13183
- const surrounding = block.slice(surroundingStart, surroundingEnd);
13184
- routes.push({
13185
- path: routePath,
13186
- name: surrounding.match(/name\s*:\s*["']([^"']+)["']/)?.[1],
13187
- hasLoader: /loader\s*:/.test(surrounding),
13188
- hasGuard: /beforeEnter\s*:|beforeLeave\s*:/.test(surrounding),
13189
- params: extractParams(routePath)
13190
- });
13191
- }
13192
- }
13193
- }
13194
- return routes;
13195
- }
13196
- function extractComponents(files, cwd) {
13197
- const components = [];
13198
- for (const file of files) {
13199
- let code;
13200
- try {
13201
- code = fs.readFileSync(file, "utf-8");
13202
- } catch {
13203
- continue;
13204
- }
13205
- const componentRe = /(?:export\s+)?(?:const|function)\s+([A-Z]\w*)\s*(?::\s*ComponentFn<[^>]+>\s*)?=?\s*\(?(?:\s*\{?\s*([^)]*?)\s*\}?\s*)?\)?\s*(?:=>|{)/g;
13206
- let match;
13207
- for (match = componentRe.exec(code); match; match = componentRe.exec(code)) {
13208
- const name = match[1] ?? "Unknown";
13209
- const props = (match[2] ?? "").split(/[,;]/).map((p) => p.trim().replace(/[{}]/g, "").trim().split(":")[0]?.split("=")[0]?.trim() ?? "").filter((p) => p && p !== "props");
13210
- const bodyStart = match.index + match[0].length;
13211
- const body = code.slice(bodyStart, Math.min(code.length, bodyStart + 2e3));
13212
- const signalNames = [];
13213
- const signalRe = /(?:const|let)\s+(\w+)\s*=\s*signal\s*[<(]/g;
13214
- let sigMatch;
13215
- for (sigMatch = signalRe.exec(body); sigMatch; sigMatch = signalRe.exec(body)) if (sigMatch[1]) signalNames.push(sigMatch[1]);
13216
- components.push({
13217
- name,
13218
- file: path.relative(cwd, file),
13219
- hasSignals: signalNames.length > 0,
13220
- signalNames,
13221
- props
13222
- });
13223
- }
13224
- }
13225
- return components;
13226
- }
13227
- function extractIslands(files, cwd) {
13228
- const islands = [];
13229
- for (const file of files) {
13230
- let code;
13231
- try {
13232
- code = fs.readFileSync(file, "utf-8");
13233
- } catch {
13234
- continue;
13235
- }
13236
- const islandRe = /island\s*\(\s*\(\)\s*=>\s*import\(.+?\)\s*,\s*\{[^}]*name\s*:\s*["']([^"']+)["'][^}]*?(?:hydrate\s*:\s*["']([^"']+)["'])?[^}]*\}/g;
13237
- let match;
13238
- for (match = islandRe.exec(code); match; match = islandRe.exec(code)) if (match[1]) islands.push({
13239
- name: match[1],
13240
- file: path.relative(cwd, file),
13241
- hydrate: match[2] ?? "load"
13242
- });
13243
- }
13244
- return islands;
13245
- }
13246
- function extractParams(routePath) {
13247
- const params = [];
13248
- const paramRe = /:(\w+)\??/g;
13249
- let match;
13250
- for (match = paramRe.exec(routePath); match; match = paramRe.exec(routePath)) if (match[1]) params.push(match[1]);
13251
- return params;
13252
- }
13253
- function readVersion(cwd) {
13254
- try {
13255
- const pkg = JSON.parse(fs.readFileSync(path.join(cwd, "package.json"), "utf-8"));
13256
- const deps = {
13257
- ...pkg.dependencies,
13258
- ...pkg.devDependencies
13259
- };
13260
- for (const [name, ver] of Object.entries(deps)) if (name.startsWith("@pyreon/") && typeof ver === "string") return ver.replace(/^[\^~]/, "");
13261
- return pkg.version || "unknown";
13262
- } catch {
13263
- return "unknown";
13264
- }
13265
- }
13266
-
13267
13109
  //#endregion
13268
13110
  //#region src/index.ts
13269
13111
  /**