MCPcopy Create free account
hub / github.com/donghaxkim/react-rewrite / processQueue

Function processQueue

packages/cli/src/server.ts:77–382  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75 }
76
77 async function processQueue() {
78 if (processing || queue.length === 0) return;
79 processing = true;
80
81 const { msg, ws } = queue.shift()!;
82
83 try {
84 switch (msg.type) {
85 case "reorder": {
86 if (!isProjectFilePathSafe(msg.filePath, projectRoot)) {
87 const error = msg.filePath.trim()
88 ? "File path is outside the project root"
89 : "File path could not be resolved for this element";
90 logger.warn(`[ReactRewrite] Rejected reorder path: ${msg.filePath}`);
91 send(ws, { type: "reorderComplete", success: false, error });
92 break;
93 }
94 const resolvedPath = resolveProjectFilePath(msg.filePath, projectRoot)!;
95 const prevContent = fs.readFileSync(resolvedPath, "utf-8");
96 const undoId = randomUUID();
97
98 try {
99 const newSource = reorderComponent(
100 resolvedPath,
101 msg.fromLine,
102 msg.toLine
103 );
104 fs.writeFileSync(resolvedPath, newSource, "utf-8");
105 undoStack.push({
106 id: undoId,
107 filePath: resolvedPath,
108 content: prevContent,
109 afterContent: newSource,
110 timestamp: Date.now(),
111 });
112 send(ws, { type: "reorderComplete", success: true });
113 } catch (err) {
114 send(ws, {
115 type: "reorderComplete",
116 success: false,
117 error: err instanceof Error ? err.message : String(err),
118 });
119 }
120 break;
121 }
122
123 case "undo": {
124 const entry = undoStack.pop();
125 if (!entry) {
126 send(ws, {
127 type: "undoComplete",
128 success: false,
129 error: "Nothing to undo",
130 });
131 } else {
132 fs.writeFileSync(entry.filePath, entry.content, "utf-8");
133 send(ws, { type: "undoComplete", success: true });
134 }

Callers 1

createSketchServerFunction · 0.85

Calls 7

isProjectFilePathSafeFunction · 0.85
resolveProjectFilePathFunction · 0.85
reorderComponentFunction · 0.85
executeBatchFunction · 0.85
extractErrorCodeFunction · 0.85
sendFunction · 0.70

Tested by

no test coverage detected