@shriyanss/js-recon 1.4.1-alpha.2 → 1.4.1-alpha.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/CHANGELOG.md +41 -0
- package/CLAUDE.md +39 -2
- package/README.md +2 -0
- package/build/analyze/engine/index.js.map +1 -1
- package/build/analyze/helpers/schemas.js +1 -1
- package/build/analyze/helpers/schemas.js.map +1 -1
- package/build/analyze/index.js +1 -0
- package/build/analyze/index.js.map +1 -1
- package/build/globalConfig.js +2 -2
- package/build/globalConfig.js.map +1 -1
- package/build/index.js +73 -3
- package/build/index.js.map +1 -1
- package/build/lazyLoad/downloadQueue.js +1 -1
- package/build/lazyLoad/downloadQueue.js.map +1 -1
- package/build/lazyLoad/index.js +25 -0
- package/build/lazyLoad/index.js.map +1 -1
- package/build/lazyLoad/methodFilter.js +1 -0
- package/build/lazyLoad/methodFilter.js.map +1 -1
- package/build/lazyLoad/nuxt_js/nuxt_getBuildsManifest.js +64 -0
- package/build/lazyLoad/nuxt_js/nuxt_getBuildsManifest.js.map +1 -0
- package/build/lazyLoad/react/react_followImports.js +8 -2
- package/build/lazyLoad/react/react_followImports.js.map +1 -1
- package/build/lazyLoad/svelte/svelte_getFromPageSource.js +16 -0
- package/build/lazyLoad/svelte/svelte_getFromPageSource.js.map +1 -1
- package/build/lazyLoad/svelte/svelte_getVersionJson.js +40 -0
- package/build/lazyLoad/svelte/svelte_getVersionJson.js.map +1 -0
- package/build/map/angular_js/getAngularConnections.js +88 -0
- package/build/map/angular_js/getAngularConnections.js.map +1 -0
- package/build/map/angular_js/interactive.js +4 -0
- package/build/map/angular_js/interactive.js.map +1 -0
- package/build/map/index.js +38 -0
- package/build/map/index.js.map +1 -1
- package/build/refactor/index.js +478 -12
- package/build/refactor/index.js.map +1 -1
- package/build/refactor/react/helpers.js +13 -0
- package/build/refactor/react/helpers.js.map +1 -1
- package/build/refactor/react/index.js +149 -41
- package/build/refactor/react/index.js.map +1 -1
- package/build/refactor/react/library-classify.js +232 -1
- package/build/refactor/react/library-classify.js.map +1 -1
- package/build/refactor/react/transform.js +1046 -34
- package/build/refactor/react/transform.js.map +1 -1
- package/build/refactor/react-vite/index.js +618 -0
- package/build/refactor/react-vite/index.js.map +1 -0
- package/build/refactor/react-vite/vendor-analyze.js +336 -0
- package/build/refactor/react-vite/vendor-analyze.js.map +1 -0
- package/build/refactor/remote/cache.js +211 -0
- package/build/refactor/remote/cache.js.map +1 -0
- package/build/refactor/remote/config.js +47 -0
- package/build/refactor/remote/config.js.map +1 -0
- package/build/refactor/remote/hf-client.js +137 -0
- package/build/refactor/remote/hf-client.js.map +1 -0
- package/build/run/index.js +116 -11
- package/build/run/index.js.map +1 -1
- package/build/utility/banner.js +68 -0
- package/build/utility/banner.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// Analyzes a Vite vendor chunk to build a map of exported names → canonical library API names.
|
|
2
|
+
// Used to rewrite minified direct vendor imports (like r = Link from react-router-dom).
|
|
3
|
+
var _a;
|
|
4
|
+
import { parse } from "@babel/parser";
|
|
5
|
+
import _traverse from "@babel/traverse";
|
|
6
|
+
import * as t from "@babel/types";
|
|
7
|
+
import _generator from "@babel/generator";
|
|
8
|
+
const traverse = _traverse.default;
|
|
9
|
+
import { REACT_CANONICAL, JSX_RUNTIME_CANONICAL, REACT_DOM_CLIENT_CANONICAL, REACT_ROUTER_DOM_CANONICAL, } from "../react/library-classify.js";
|
|
10
|
+
const generate = (_a = _generator.default) !== null && _a !== void 0 ? _a : _generator;
|
|
11
|
+
/**
|
|
12
|
+
* Determines which library a CJS module corresponds to by inspecting its factory function.
|
|
13
|
+
* Returns the library identifier or null if unknown.
|
|
14
|
+
*
|
|
15
|
+
* The factory is the first argument to __commonJS(factory).
|
|
16
|
+
* Its first parameter is the exports object (e.g. `e` in `(e) => { e.jsx = ... }`).
|
|
17
|
+
*/
|
|
18
|
+
function classifyFactory(factory) {
|
|
19
|
+
// Derive the exports parameter name (first param, e.g. "e")
|
|
20
|
+
const exportsParam = factory.params[0];
|
|
21
|
+
const exportsParamName = exportsParam && t.isIdentifier(exportsParam) ? exportsParam.name : "exports";
|
|
22
|
+
let bodyCode;
|
|
23
|
+
try {
|
|
24
|
+
bodyCode = generate(factory.body).code;
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
// react-dom/client: exports createRoot
|
|
30
|
+
if (bodyCode.includes("createRoot")) {
|
|
31
|
+
return "react-dom/client";
|
|
32
|
+
}
|
|
33
|
+
// react/jsx-runtime: exports both jsx and jsxs via the exports parameter
|
|
34
|
+
// Pattern: exportsParam.jsx = ..., exportsParam.jsxs = ...
|
|
35
|
+
if (bodyCode.includes(`${exportsParamName}.jsx =`) && bodyCode.includes(`${exportsParamName}.jsxs =`)) {
|
|
36
|
+
return "react/jsx-runtime";
|
|
37
|
+
}
|
|
38
|
+
// React: uses Symbol.for react.element / react.transitional.element sentinel
|
|
39
|
+
if (bodyCode.includes("react.element") ||
|
|
40
|
+
bodyCode.includes("react.transitional.element") ||
|
|
41
|
+
bodyCode.includes("ReactCurrentOwner") ||
|
|
42
|
+
bodyCode.includes("__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED")) {
|
|
43
|
+
return "react";
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Analyzes a Vite vendor chunk to build a map of exported names → VendorExportInfo.
|
|
49
|
+
*
|
|
50
|
+
* The vendor chunk (vendor-react-*.js) typically:
|
|
51
|
+
* 1. Imports rolldown interop helpers (__commonJS, __toESM) from the runtime chunk
|
|
52
|
+
* 2. Wraps CJS modules (React, jsx-runtime, react-dom) in __commonJS calls
|
|
53
|
+
* 3. Directly exports react-router-dom APIs with .displayName assignments
|
|
54
|
+
* 4. Has a single export statement: export { localVar as exportedName, ... }
|
|
55
|
+
*
|
|
56
|
+
* Returns a Map from exported name (e.g. "r", "n", "t") to VendorExportInfo.
|
|
57
|
+
*/
|
|
58
|
+
export function analyzeVendorChunk(code) {
|
|
59
|
+
const result = new Map();
|
|
60
|
+
let ast;
|
|
61
|
+
try {
|
|
62
|
+
ast = parse(code, {
|
|
63
|
+
sourceType: "module",
|
|
64
|
+
plugins: ["jsx"],
|
|
65
|
+
errorRecovery: true,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (_a) {
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
// Step 1: Find the __commonJS import from rolldown-runtime.
|
|
72
|
+
// Pattern: import { t as commonJSLocalName } from "./rolldown-runtime-*.js"
|
|
73
|
+
// or: import { n as toESMLocalName, t as commonJSLocalName } from "./rolldown-runtime-*.js"
|
|
74
|
+
let commonJSLocalName = null;
|
|
75
|
+
for (const node of ast.program.body) {
|
|
76
|
+
if (!t.isImportDeclaration(node))
|
|
77
|
+
continue;
|
|
78
|
+
if (!node.source.value.includes("rolldown-runtime"))
|
|
79
|
+
continue;
|
|
80
|
+
for (const spec of node.specifiers) {
|
|
81
|
+
if (!t.isImportSpecifier(spec))
|
|
82
|
+
continue;
|
|
83
|
+
const imported = t.isIdentifier(spec.imported)
|
|
84
|
+
? spec.imported.name
|
|
85
|
+
: spec.imported.value;
|
|
86
|
+
// rolldown exports __commonJS as 't'
|
|
87
|
+
if (imported === "t") {
|
|
88
|
+
commonJSLocalName = spec.local.name;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Step 2: Find all `var X = commonJSLocalName(fn)` patterns — CJS module getters.
|
|
93
|
+
// Track local var name → library type
|
|
94
|
+
const cjsVarToLibrary = new Map();
|
|
95
|
+
// wrappedBy: varName → name of the CJS var it re-exports (for chain resolution)
|
|
96
|
+
const wrappedBy = new Map();
|
|
97
|
+
if (commonJSLocalName) {
|
|
98
|
+
for (const node of ast.program.body) {
|
|
99
|
+
if (!t.isVariableDeclaration(node))
|
|
100
|
+
continue;
|
|
101
|
+
for (const decl of node.declarations) {
|
|
102
|
+
if (!t.isIdentifier(decl.id) || !decl.init)
|
|
103
|
+
continue;
|
|
104
|
+
if (!t.isCallExpression(decl.init))
|
|
105
|
+
continue;
|
|
106
|
+
const callee = decl.init.callee;
|
|
107
|
+
if (!t.isIdentifier(callee, { name: commonJSLocalName }))
|
|
108
|
+
continue;
|
|
109
|
+
const localVarName = decl.id.name;
|
|
110
|
+
const args = decl.init.arguments;
|
|
111
|
+
if (args.length !== 1)
|
|
112
|
+
continue;
|
|
113
|
+
const factory = args[0];
|
|
114
|
+
if (!t.isArrowFunctionExpression(factory) && !t.isFunctionExpression(factory))
|
|
115
|
+
continue;
|
|
116
|
+
if (!t.isBlockStatement(factory.body))
|
|
117
|
+
continue;
|
|
118
|
+
const body = factory.body.body;
|
|
119
|
+
// Detect wrapper pattern: factory body contains `t.exports = Y()` somewhere.
|
|
120
|
+
// Handles:
|
|
121
|
+
// - Simple: `(e, t) => { t.exports = Y() }`
|
|
122
|
+
// - With preamble: `(e, t) => { n(); t.exports = Y() }`
|
|
123
|
+
// - Sequence form: `(e, t) => { ...; n(), t.exports = Y() }`
|
|
124
|
+
let wrappedVarName = null;
|
|
125
|
+
const extractWrappedVar = (expr) => {
|
|
126
|
+
if (t.isAssignmentExpression(expr) &&
|
|
127
|
+
t.isMemberExpression(expr.left) &&
|
|
128
|
+
t.isIdentifier(expr.left.property, { name: "exports" }) &&
|
|
129
|
+
t.isCallExpression(expr.right) &&
|
|
130
|
+
t.isIdentifier(expr.right.callee)) {
|
|
131
|
+
return expr.right.callee.name;
|
|
132
|
+
}
|
|
133
|
+
// Sequence expression: (n(), t.exports = Y())
|
|
134
|
+
if (t.isSequenceExpression(expr)) {
|
|
135
|
+
for (const subExpr of expr.expressions) {
|
|
136
|
+
const v = extractWrappedVar(subExpr);
|
|
137
|
+
if (v)
|
|
138
|
+
return v;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
};
|
|
143
|
+
for (const stmt of body) {
|
|
144
|
+
if (!t.isExpressionStatement(stmt))
|
|
145
|
+
continue;
|
|
146
|
+
const found = extractWrappedVar(stmt.expression);
|
|
147
|
+
if (found) {
|
|
148
|
+
wrappedVarName = found;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (wrappedVarName) {
|
|
153
|
+
wrappedBy.set(localVarName, wrappedVarName);
|
|
154
|
+
continue; // chain resolution happens in the second pass below
|
|
155
|
+
}
|
|
156
|
+
// Classify this factory directly
|
|
157
|
+
const libType = classifyFactory(factory);
|
|
158
|
+
if (libType) {
|
|
159
|
+
cjsVarToLibrary.set(localVarName, libType);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Resolve wrapper chains: wrapper → direct factory → libType
|
|
164
|
+
for (const [wrapperVar, targetVar] of wrappedBy) {
|
|
165
|
+
const libType = cjsVarToLibrary.get(targetVar);
|
|
166
|
+
if (libType) {
|
|
167
|
+
cjsVarToLibrary.set(wrapperVar, libType);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Step 3: Scan for .displayName = "CanonicalName" assignments for react-router-dom components.
|
|
172
|
+
// localVarName → canonicalName
|
|
173
|
+
const displayNameMap = new Map();
|
|
174
|
+
traverse(ast, {
|
|
175
|
+
AssignmentExpression(path) {
|
|
176
|
+
var _a;
|
|
177
|
+
const node = path.node;
|
|
178
|
+
if (node.operator !== "=")
|
|
179
|
+
return;
|
|
180
|
+
const lhs = node.left;
|
|
181
|
+
if (!t.isMemberExpression(lhs) || lhs.computed)
|
|
182
|
+
return;
|
|
183
|
+
if (!t.isIdentifier(lhs.property, { name: "displayName" }))
|
|
184
|
+
return;
|
|
185
|
+
if (!t.isIdentifier(lhs.object))
|
|
186
|
+
return;
|
|
187
|
+
const rhs = node.right;
|
|
188
|
+
let canonicalName = null;
|
|
189
|
+
if (t.isStringLiteral(rhs)) {
|
|
190
|
+
canonicalName = rhs.value;
|
|
191
|
+
}
|
|
192
|
+
else if (t.isTemplateLiteral(rhs) && rhs.expressions.length === 0 && rhs.quasis.length === 1) {
|
|
193
|
+
// Template literal with no expressions: `Link` etc.
|
|
194
|
+
canonicalName = (_a = rhs.quasis[0].value.cooked) !== null && _a !== void 0 ? _a : rhs.quasis[0].value.raw;
|
|
195
|
+
}
|
|
196
|
+
if (canonicalName && REACT_ROUTER_DOM_CANONICAL.has(canonicalName)) {
|
|
197
|
+
displayNameMap.set(lhs.object.name, canonicalName);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
// Step 4: Also detect react-router-dom exports by scanning function bodies for canonical hints.
|
|
202
|
+
// For each variable declaration that is not a CJS getter, check if its body references
|
|
203
|
+
// react-router-dom canonical names in backtick strings, call patterns, or JSX element names.
|
|
204
|
+
const routerDomVars = new Map(); // localVar → canonicalName
|
|
205
|
+
for (const [varName, canonicalName] of displayNameMap) {
|
|
206
|
+
routerDomVars.set(varName, canonicalName);
|
|
207
|
+
}
|
|
208
|
+
// Also scan function declarations for canonical hints
|
|
209
|
+
for (const node of ast.program.body) {
|
|
210
|
+
if (!t.isFunctionDeclaration(node) || !node.id)
|
|
211
|
+
continue;
|
|
212
|
+
const fnName = node.id.name;
|
|
213
|
+
if (displayNameMap.has(fnName))
|
|
214
|
+
continue; // already found via displayName
|
|
215
|
+
try {
|
|
216
|
+
const bodyCode = generate(node).code;
|
|
217
|
+
const canonicalName = extractRouterDomCanonical(bodyCode);
|
|
218
|
+
if (canonicalName) {
|
|
219
|
+
routerDomVars.set(fnName, canonicalName);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch (_b) {
|
|
223
|
+
// skip
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Step 5: Parse the export statement to build a map of exported name → local var
|
|
227
|
+
// Pattern: export { localA as exportedA, localB as exportedB, ... }
|
|
228
|
+
const localToExported = new Map(); // localVarName → exportedName
|
|
229
|
+
for (const node of ast.program.body) {
|
|
230
|
+
if (!t.isExportNamedDeclaration(node))
|
|
231
|
+
continue;
|
|
232
|
+
if (node.declaration)
|
|
233
|
+
continue; // skip `export const ...`
|
|
234
|
+
for (const spec of node.specifiers) {
|
|
235
|
+
if (!t.isExportSpecifier(spec))
|
|
236
|
+
continue;
|
|
237
|
+
const localName = t.isIdentifier(spec.local) ? spec.local.name : spec.local.value;
|
|
238
|
+
const exportedName = t.isIdentifier(spec.exported)
|
|
239
|
+
? spec.exported.name
|
|
240
|
+
: spec.exported.value;
|
|
241
|
+
localToExported.set(localName, exportedName);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// Step 6: Build the result map.
|
|
245
|
+
// For each local var, find its exported name and classify.
|
|
246
|
+
// CJS getters
|
|
247
|
+
for (const [localVar, libType] of cjsVarToLibrary) {
|
|
248
|
+
const exportedName = localToExported.get(localVar);
|
|
249
|
+
if (!exportedName)
|
|
250
|
+
continue;
|
|
251
|
+
result.set(exportedName, {
|
|
252
|
+
canonicalName: libType, // for CJS getters, canonicalName is the library path
|
|
253
|
+
library: libType,
|
|
254
|
+
isCjsGetter: true,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
// react-router-dom direct exports
|
|
258
|
+
for (const [localVar, canonicalName] of routerDomVars) {
|
|
259
|
+
const exportedName = localToExported.get(localVar);
|
|
260
|
+
if (!exportedName)
|
|
261
|
+
continue;
|
|
262
|
+
result.set(exportedName, {
|
|
263
|
+
canonicalName,
|
|
264
|
+
library: "react-router-dom",
|
|
265
|
+
isCjsGetter: false,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
// Also check for react/react-dom direct function exports (non-CJS)
|
|
269
|
+
// by scanning exported vars whose body contains canonical hints
|
|
270
|
+
for (const [localVar, exportedName] of localToExported) {
|
|
271
|
+
if (result.has(exportedName))
|
|
272
|
+
continue; // already classified
|
|
273
|
+
// Check if local var is a function with react-related canonical name hints
|
|
274
|
+
// We do a targeted scan here for completeness
|
|
275
|
+
for (const node of ast.program.body) {
|
|
276
|
+
if (!t.isVariableDeclaration(node))
|
|
277
|
+
continue;
|
|
278
|
+
for (const decl of node.declarations) {
|
|
279
|
+
if (!t.isIdentifier(decl.id, { name: localVar }) || !decl.init)
|
|
280
|
+
continue;
|
|
281
|
+
try {
|
|
282
|
+
const bodyCode = generate(decl.init).code;
|
|
283
|
+
const canonicalName = extractRouterDomCanonical(bodyCode);
|
|
284
|
+
if (canonicalName) {
|
|
285
|
+
result.set(exportedName, {
|
|
286
|
+
canonicalName,
|
|
287
|
+
library: "react-router-dom",
|
|
288
|
+
isCjsGetter: false,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
catch (_c) {
|
|
293
|
+
// skip
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Extracts a react-router-dom canonical name from a code string using priority heuristics.
|
|
302
|
+
* Returns the canonical name if found, null otherwise.
|
|
303
|
+
*/
|
|
304
|
+
function extractRouterDomCanonical(bodyCode) {
|
|
305
|
+
// Priority 1: backtick-quoted form inside error strings
|
|
306
|
+
for (const canonical of REACT_ROUTER_DOM_CANONICAL) {
|
|
307
|
+
if (bodyCode.includes("`" + canonical + "`"))
|
|
308
|
+
return canonical;
|
|
309
|
+
}
|
|
310
|
+
// Priority 2: call-site mention
|
|
311
|
+
for (const canonical of REACT_ROUTER_DOM_CANONICAL) {
|
|
312
|
+
if (bodyCode.includes(canonical + "("))
|
|
313
|
+
return canonical;
|
|
314
|
+
}
|
|
315
|
+
// Priority 3: JSX element mention
|
|
316
|
+
for (const canonical of REACT_ROUTER_DOM_CANONICAL) {
|
|
317
|
+
if (bodyCode.includes("<" + canonical + ">"))
|
|
318
|
+
return canonical;
|
|
319
|
+
}
|
|
320
|
+
// Priority 4: Outlet-specific
|
|
321
|
+
if (bodyCode.includes(".outlet"))
|
|
322
|
+
return "Outlet";
|
|
323
|
+
// Priority 5: useParams-specific
|
|
324
|
+
if (bodyCode.includes("?.params"))
|
|
325
|
+
return "useParams";
|
|
326
|
+
// Priority 6: BrowserRouter-specific
|
|
327
|
+
if (bodyCode.includes("basename:"))
|
|
328
|
+
return "BrowserRouter";
|
|
329
|
+
// Priority 7: Routes-specific
|
|
330
|
+
if (bodyCode.includes("children:") && bodyCode.includes("location:"))
|
|
331
|
+
return "Routes";
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
// Re-export canonical sets for use in the main index
|
|
335
|
+
export { REACT_CANONICAL, JSX_RUNTIME_CANONICAL, REACT_DOM_CLIENT_CANONICAL, REACT_ROUTER_DOM_CANONICAL };
|
|
336
|
+
//# sourceMappingURL=vendor-analyze.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vendor-analyze.js","sourceRoot":"","sources":["../../../src/refactor/react-vite/vendor-analyze.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,wFAAwF;;AAExF,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAE1C,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC;AACnC,OAAO,EACH,eAAe,EACf,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,GAC7B,MAAM,8BAA8B,CAAC;AAEtC,MAAM,QAAQ,GAAG,MAAC,UAAwD,CAAC,OAAO,mCAAI,UAAU,CAAC;AASjG;;;;;;GAMG;AACH,SAAS,eAAe,CACpB,OAAyD;IAEzD,4DAA4D;IAC5D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvC,MAAM,gBAAgB,GAClB,YAAY,IAAI,CAAC,CA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import { getRefactorConfigDir } from "./config.js";
|
|
4
|
+
const ONE_WEEK_MS = 7 * 24 * 60 * 60 * 1000;
|
|
5
|
+
const getListCachePath = () => path.join(getRefactorConfigDir(), "cs-mast-s-list-cache.json");
|
|
6
|
+
export const loadListCache = () => {
|
|
7
|
+
const p = getListCachePath();
|
|
8
|
+
if (!fs.existsSync(p))
|
|
9
|
+
return null;
|
|
10
|
+
try {
|
|
11
|
+
const raw = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
12
|
+
if (typeof raw !== "object" || raw === null)
|
|
13
|
+
return null;
|
|
14
|
+
const c = raw;
|
|
15
|
+
if (typeof c.generatedAt !== "number")
|
|
16
|
+
return null;
|
|
17
|
+
if (typeof c.branches !== "object" || c.branches === null)
|
|
18
|
+
return null;
|
|
19
|
+
return raw;
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const saveListCache = (data) => {
|
|
26
|
+
const dir = getRefactorConfigDir();
|
|
27
|
+
if (!fs.existsSync(dir))
|
|
28
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
29
|
+
fs.writeFileSync(getListCachePath(), JSON.stringify(data, null, 2));
|
|
30
|
+
};
|
|
31
|
+
export const isListCacheStale = (cache) => Date.now() - cache.generatedAt > ONE_WEEK_MS;
|
|
32
|
+
export const shouldRefreshListCache = (cache, opts) => {
|
|
33
|
+
if (opts.refreshCache)
|
|
34
|
+
return true;
|
|
35
|
+
if (cache === null)
|
|
36
|
+
return true;
|
|
37
|
+
if (!opts.skipCacheChecks && isListCacheStale(cache))
|
|
38
|
+
return true;
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
// --- Signature file cache ---
|
|
42
|
+
const getSignatureCacheRoot = () => path.join(getRefactorConfigDir(), "signature_cache");
|
|
43
|
+
// subpath is the relative file path from the HF branch root,
|
|
44
|
+
// e.g. "01-usestate-hook-webpack/lit-decl-loop-cond/collisions.json"
|
|
45
|
+
const getSignatureCacheDir = (branch, subpath) => {
|
|
46
|
+
// Strip the trailing "/collisions.json" to get the directory path.
|
|
47
|
+
const dir = subpath.endsWith("/collisions.json") ? subpath.slice(0, -"/collisions.json".length) : subpath;
|
|
48
|
+
return path.join(getSignatureCacheRoot(), branch, dir);
|
|
49
|
+
};
|
|
50
|
+
export const getSignatureCacheFilePath = (branch, subpath) => path.join(getSignatureCacheDir(branch, subpath), "collisions.json");
|
|
51
|
+
const getCachedAtPath = (branch, subpath) => path.join(getSignatureCacheDir(branch, subpath), "cached_at.txt");
|
|
52
|
+
export const isSignatureCacheFresh = (branch, subpath, skipCacheChecks) => {
|
|
53
|
+
const atPath = getCachedAtPath(branch, subpath);
|
|
54
|
+
const filePath = getSignatureCacheFilePath(branch, subpath);
|
|
55
|
+
if (!fs.existsSync(atPath) || !fs.existsSync(filePath))
|
|
56
|
+
return false;
|
|
57
|
+
if (skipCacheChecks)
|
|
58
|
+
return true;
|
|
59
|
+
try {
|
|
60
|
+
const ts = parseInt(fs.readFileSync(atPath, "utf8").trim(), 10);
|
|
61
|
+
if (isNaN(ts))
|
|
62
|
+
return false;
|
|
63
|
+
return Date.now() - ts <= ONE_WEEK_MS;
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export const loadCachedSignature = (branch, subpath) => {
|
|
70
|
+
const filePath = getSignatureCacheFilePath(branch, subpath);
|
|
71
|
+
if (!fs.existsSync(filePath))
|
|
72
|
+
return null;
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
75
|
+
}
|
|
76
|
+
catch (_a) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
export const saveSignatureToCache = (branch, subpath, records, maxCacheSizeMb) => {
|
|
81
|
+
const dir = getSignatureCacheDir(branch, subpath);
|
|
82
|
+
if (!fs.existsSync(dir))
|
|
83
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
84
|
+
fs.writeFileSync(path.join(dir, "collisions.json"), JSON.stringify(records));
|
|
85
|
+
fs.writeFileSync(path.join(dir, "cached_at.txt"), String(Date.now()));
|
|
86
|
+
runEvictionIfNeeded(maxCacheSizeMb);
|
|
87
|
+
};
|
|
88
|
+
// --- Cache size & eviction ---
|
|
89
|
+
// Recursively sums sizes of all files under dir. Returns bytes.
|
|
90
|
+
const getDirSizeBytes = (dir) => {
|
|
91
|
+
if (!fs.existsSync(dir))
|
|
92
|
+
return 0;
|
|
93
|
+
let total = 0;
|
|
94
|
+
const walk = (d) => {
|
|
95
|
+
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
|
|
96
|
+
const full = path.join(d, entry.name);
|
|
97
|
+
if (entry.isDirectory()) {
|
|
98
|
+
walk(full);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
try {
|
|
102
|
+
total += fs.statSync(full).size;
|
|
103
|
+
}
|
|
104
|
+
catch (_a) {
|
|
105
|
+
// ignore
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
walk(dir);
|
|
111
|
+
return total;
|
|
112
|
+
};
|
|
113
|
+
export const getCacheDirSizeMb = () => getDirSizeBytes(getSignatureCacheRoot()) / (1024 * 1024);
|
|
114
|
+
// Deletes oldest cached entries until the cache dir is below 50% of maxSizeMb.
|
|
115
|
+
export const runEvictionIfNeeded = (maxSizeMb) => {
|
|
116
|
+
const root = getSignatureCacheRoot();
|
|
117
|
+
if (!fs.existsSync(root))
|
|
118
|
+
return;
|
|
119
|
+
const currentMb = getCacheDirSizeMb();
|
|
120
|
+
if (currentMb <= maxSizeMb)
|
|
121
|
+
return;
|
|
122
|
+
const entries = [];
|
|
123
|
+
const walkForCachedAt = (d) => {
|
|
124
|
+
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
|
|
125
|
+
const full = path.join(d, entry.name);
|
|
126
|
+
if (entry.isDirectory()) {
|
|
127
|
+
walkForCachedAt(full);
|
|
128
|
+
}
|
|
129
|
+
else if (entry.name === "cached_at.txt") {
|
|
130
|
+
try {
|
|
131
|
+
const ts = parseInt(fs.readFileSync(full, "utf8").trim(), 10);
|
|
132
|
+
if (!isNaN(ts))
|
|
133
|
+
entries.push({ cachedAt: ts, dir: path.dirname(full) });
|
|
134
|
+
}
|
|
135
|
+
catch (_a) {
|
|
136
|
+
// ignore
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
walkForCachedAt(root);
|
|
142
|
+
// Sort oldest first.
|
|
143
|
+
entries.sort((a, b) => a.cachedAt - b.cachedAt);
|
|
144
|
+
const targetMb = maxSizeMb * 0.5;
|
|
145
|
+
for (const { dir } of entries) {
|
|
146
|
+
if (getCacheDirSizeMb() <= targetMb)
|
|
147
|
+
break;
|
|
148
|
+
try {
|
|
149
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
150
|
+
}
|
|
151
|
+
catch (_a) {
|
|
152
|
+
// ignore
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
// --- Cache validation ---
|
|
157
|
+
// Returns an array of warning strings describing structural issues.
|
|
158
|
+
// Empty array = all clear.
|
|
159
|
+
export const validateCaches = () => {
|
|
160
|
+
const warnings = [];
|
|
161
|
+
// Validate list cache structure if it exists.
|
|
162
|
+
const listCachePath = getListCachePath();
|
|
163
|
+
if (fs.existsSync(listCachePath)) {
|
|
164
|
+
try {
|
|
165
|
+
const raw = JSON.parse(fs.readFileSync(listCachePath, "utf8"));
|
|
166
|
+
if (typeof raw !== "object" || raw === null) {
|
|
167
|
+
warnings.push("cs-mast-s-list-cache.json: invalid JSON structure");
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const c = raw;
|
|
171
|
+
if (typeof c.generatedAt !== "number")
|
|
172
|
+
warnings.push("cs-mast-s-list-cache.json: missing or invalid generatedAt");
|
|
173
|
+
if (typeof c.branches !== "object" || c.branches === null)
|
|
174
|
+
warnings.push("cs-mast-s-list-cache.json: missing or invalid branches");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (_a) {
|
|
178
|
+
warnings.push("cs-mast-s-list-cache.json: could not parse JSON");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Spot-check a sample of cached collisions.json files.
|
|
182
|
+
const root = getSignatureCacheRoot();
|
|
183
|
+
if (fs.existsSync(root)) {
|
|
184
|
+
const walkForCollisions = (d, depth, found) => {
|
|
185
|
+
if (depth > 5 || found.length >= 5)
|
|
186
|
+
return;
|
|
187
|
+
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
|
|
188
|
+
const full = path.join(d, entry.name);
|
|
189
|
+
if (entry.isDirectory())
|
|
190
|
+
walkForCollisions(full, depth + 1, found);
|
|
191
|
+
else if (entry.name === "collisions.json")
|
|
192
|
+
found.push(full);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const samples = [];
|
|
196
|
+
walkForCollisions(root, 0, samples);
|
|
197
|
+
for (const p of samples) {
|
|
198
|
+
try {
|
|
199
|
+
const arr = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
200
|
+
if (!Array.isArray(arr)) {
|
|
201
|
+
warnings.push(`${p}: cached collisions.json is not an array`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch (_b) {
|
|
205
|
+
warnings.push(`${p}: could not parse cached collisions.json`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return warnings;
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/refactor/remote/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,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,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB;oBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChE,CAAC;QACL,CAAC,CAAC;QACF,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,iBAAiB,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;QACpC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACtB,IAAI,CAAC;gBACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,CAAY,CAAC;gBAC9D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;oBACtB,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;gBAClE,CAAC;YACL,CAAC;YAAC,WAAM,CAAC;gBACL,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;YAClE,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
const DEFAULT_CONFIG = {
|
|
5
|
+
maxCacheSizeMb: 512,
|
|
6
|
+
};
|
|
7
|
+
export const getRefactorConfigDir = () => path.join(os.homedir(), ".js-recon", "refactor");
|
|
8
|
+
const getConfigFilePath = () => path.join(getRefactorConfigDir(), "config.json");
|
|
9
|
+
export const loadRefactorConfig = () => {
|
|
10
|
+
const dir = getRefactorConfigDir();
|
|
11
|
+
if (!fs.existsSync(dir))
|
|
12
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
13
|
+
const configPath = getConfigFilePath();
|
|
14
|
+
if (!fs.existsSync(configPath)) {
|
|
15
|
+
fs.writeFileSync(configPath, JSON.stringify(DEFAULT_CONFIG, null, 2));
|
|
16
|
+
return Object.assign({}, DEFAULT_CONFIG);
|
|
17
|
+
}
|
|
18
|
+
let raw;
|
|
19
|
+
try {
|
|
20
|
+
raw = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
21
|
+
}
|
|
22
|
+
catch (_a) {
|
|
23
|
+
return Object.assign({}, DEFAULT_CONFIG);
|
|
24
|
+
}
|
|
25
|
+
if (typeof raw !== "object" || raw === null)
|
|
26
|
+
return Object.assign({}, DEFAULT_CONFIG);
|
|
27
|
+
const cfg = raw;
|
|
28
|
+
const maxCacheSizeMb = typeof cfg.maxCacheSizeMb === "number" && cfg.maxCacheSizeMb > 0
|
|
29
|
+
? cfg.maxCacheSizeMb
|
|
30
|
+
: DEFAULT_CONFIG.maxCacheSizeMb;
|
|
31
|
+
return { maxCacheSizeMb };
|
|
32
|
+
};
|
|
33
|
+
export const saveRefactorConfig = (config) => {
|
|
34
|
+
const dir = getRefactorConfigDir();
|
|
35
|
+
if (!fs.existsSync(dir))
|
|
36
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
37
|
+
fs.writeFileSync(getConfigFilePath(), JSON.stringify(config, null, 2));
|
|
38
|
+
};
|
|
39
|
+
// Validates config and returns a list of warning strings (empty = valid).
|
|
40
|
+
export const validateRefactorConfig = (config) => {
|
|
41
|
+
const warnings = [];
|
|
42
|
+
if (typeof config.maxCacheSizeMb !== "number" || config.maxCacheSizeMb <= 0) {
|
|
43
|
+
warnings.push(`config.maxCacheSizeMb must be a positive number (got ${config.maxCacheSizeMb})`);
|
|
44
|
+
}
|
|
45
|
+
return warnings;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/refactor/remote/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,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