-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathindex.js
638 lines (566 loc) · 27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
const babel = require('@babel/core');
const assert = require("assert").strict;
const traverse = require('@babel/traverse').default;
const generate = require('@babel/generator').default;
const fs = require('fs');
const path = require('path');
const prettier = require("prettier");
const rootPath = path.join(__dirname, "muse/github.copilot-1.57.7193/dist");
const outPath = path.join(__dirname, "codeviz/data");
// const srcFile = path.join(rootPath, 'extension_expanded.js');
const srcFile = path.join(rootPath, 'extension_expanded_v2.js'); // this modifies module 3055 by splitting it into multiple modules (originally 3055 consisted of multiple nested modules which weren't being extracted automatically. So I extracted them manually)
const mainModuleSrcFile = path.join(rootPath, "extension_expanded_main.js");
const code = fs.readFileSync(srcFile, 'utf8');
const mainCode = fs.readFileSync(mainModuleSrcFile, 'utf8');
// navigate the AST of var e = {...}. Every property is a module.
// We want to separate each module into its own file.
const ast = babel.parse(code);
function getModulePath(moduleId) {
return path.join(rootPath, "modules", moduleId + ".js");
}
function normalizeExports(moduleId, moduleCodeRaw) {
/**
Applies two transformations:
First, it converts the modules defined as arrow functions of the form (e, t, n) => {...}
into arrow functions of the form (module, exports, require) => {...}
Second, and more importantly:
Converts code of the form
```
Object.defineProperty(exports, "KeywordCxt", {
enumerable: !0,
get: function () {
return u.KeywordCxt;
}
});
```
into
```
exports.KeywordCxt = u.KeywordCxt;
```
*/
if (moduleCodeRaw.trim().startsWith("function")) {
// change `function(e, t, n) {` to `(e, t, n) => {`
moduleCodeRaw = moduleCodeRaw.replace("function", "");
moduleCodeRaw = moduleCodeRaw.replace(")", ") =>");
}
let transformedArrowFn = false;
const moduleTransformer = {
ArrowFunctionExpression(path) {
if (transformedArrowFn) {
return;
}
const node = path.node; // the module's AST
// at most 3 arguments: module, exports, require
assert(node.params.length <= 3);
// rename the arguments from (e, t, n) to (module, exports, require)
node.params.forEach((param, i) => {
path.scope.rename(param.name, ["module", "exports", "require"][i]);
});
transformedArrowFn = true;
},
CallExpression(path) {
const { node } = path;
if (node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
node.callee.object.name === 'Object' &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name === 'defineProperty' &&
node.arguments.length === 3 &&
node.arguments[0].type === 'Identifier' &&
node.arguments[0].name === 'exports' &&
node.arguments[1].type === 'StringLiteral' &&
node.arguments[2].type === 'ObjectExpression' &&
node.arguments[2].properties.length === 2 &&
node.arguments[2].properties[0].type === 'ObjectProperty' &&
node.arguments[2].properties[0].key.type === 'Identifier' &&
node.arguments[2].properties[0].key.name === 'enumerable' &&
node.arguments[2].properties[1].type === 'ObjectProperty' &&
node.arguments[2].properties[1].key.type === 'Identifier' &&
node.arguments[2].properties[1].key.name === 'get' &&
node.arguments[2].properties[1].value.type === 'FunctionExpression' &&
node.arguments[2].properties[1].value.body.type === 'BlockStatement' &&
node.arguments[2].properties[1].value.body.body.length === 1 &&
node.arguments[2].properties[1].value.body.body[0].type === 'ReturnStatement' &&
node.arguments[2].properties[1].value.body.body[0].argument.type === 'MemberExpression'
) {
const newNode = babel.types.assignmentExpression(
'=',
babel.types.memberExpression(
node.arguments[0],
babel.types.Identifier(node.arguments[1].value),
false
),
node.arguments[2].properties[1].value.body.body[0].argument
);
path.replaceWith(newNode);
foundWeirdExport = true;
}
},
}
moduleAst = babel.parse(moduleCodeRaw);
traverse(moduleAst, moduleTransformer);
return moduleAst;
}
function makeModuleReadable(moduleId, moduleCodeRaw) {
moduleAst = babel.parse(moduleCodeRaw);
const moduleTransformer = {
// e.g., `(0, r.getConfig)(e, r.ConfigKey.DebugOverrideProxyUrl);`
// gets transformed to r.getConfig(e, r.ConfigKey.DebugOverrideProxyUrl);
CallExpression(path) {
if (path.node.callee.type != "SequenceExpression") {
return;
}
if (path.node.callee.expressions.length == 2 && path.node.callee.expressions[0].type == "NumericLiteral") {
path.node.callee = path.node.callee.expressions[1];
}
},
ExpressionStatement(path) {
if (path.node.expression.type == "SequenceExpression") {
const exprs = path.node.expression.expressions;
let exprStmts = exprs.map(e => { return babel.types.expressionStatement(e); });
path.replaceWithMultiple(exprStmts);
return;
}
if (path.node.expression.type == "AssignmentExpression") {
// handle cases like: `a = (expr1, expr2, expr3)`
// convert to: `expr1; expr2; a = expr3;`
if (path.node.expression.right.type == "SequenceExpression") {
const exprs = path.node.expression.right.expressions;
let exprStmts = exprs.map(e => { return babel.types.expressionStatement(e); });
let lastExpr = exprStmts.pop();
path.node.expression.right = lastExpr.expression;
exprStmts.push(path.node);
path.replaceWithMultiple(exprStmts);
return;
}
// handle cases like: `exports.GoodExplainableName = a;` where `a` is a function or a class
// rename `a` to `GoodExplainableName` everywhere in the module
if (path.node.expression.left.type == "MemberExpression" &&
path.node.expression.left.object.type == "Identifier" &&
path.node.expression.left.object.name == "exports" &&
path.node.expression.left.property.type == "Identifier" &&
path.node.expression.left.property.name != "default" &&
path.node.expression.right.type == "Identifier" &&
path.node.expression.right.name.length == 1
) {
path.scope.rename(
path.node.expression.right.name,
path.node.expression.left.property.name
);
return;
}
}
if (path.node.expression.type == "ConditionalExpression") {
// handle cases like: `<test> ? c : d;`
// convert to: `if (<test>) { c; } else { d; }`
const test = path.node.expression.test;
const consequent = path.node.expression.consequent;
const alternate = path.node.expression.alternate;
const ifStmt = babel.types.ifStatement(
test,
babel.types.blockStatement([babel.types.expressionStatement(consequent)]),
babel.types.blockStatement([babel.types.expressionStatement(alternate)])
);
path.replaceWith(ifStmt);
return;
}
if (path.node.expression.type == "LogicalExpression") {
// handle cases like: `a && b;`
// convert to: `if (a) { b; }`
const test = path.node.expression.left;
const consequent = path.node.expression.right;
const ifStmt = babel.types.ifStatement(
test,
babel.types.blockStatement([babel.types.expressionStatement(consequent)]),
null
);
path.replaceWith(ifStmt);
return;
}
},
IfStatement(path) {
if (!path.node.test || path.node.test.type != "SequenceExpression") {
return;
}
const exprs = path.node.test.expressions;
let exprStmts = exprs.map(e => { return babel.types.expressionStatement(e); });
let lastExpr = exprStmts.pop();
path.node.test = lastExpr.expression;
exprStmts.push(path.node);
path.replaceWithMultiple(exprStmts);
},
ReturnStatement(path) {
if (!path.node.argument || path.node.argument.type != "SequenceExpression") {
return;
}
const exprs = path.node.argument.expressions;
let exprStmts = exprs.map(e => { return babel.types.expressionStatement(e); });
let lastExpr = exprStmts.pop();
let returnStmt = babel.types.returnStatement(lastExpr.expression);
exprStmts.push(returnStmt);
path.replaceWithMultiple(exprStmts);
},
UnaryExpression(path) {
// if (path.node.operator == "void" && path.node.argument.type == "NumericLiteral" && path.node.argument.value == 0) {
// path.replaceWithSourceString("undefined");
// return;
// }
if (/Literal$/.test(path.node.argument.type)) {
// evaluate constant expressions
// get the source code of the expression and use `eval` to evaluate it
// replace the expression with the result of the evaluation
let source = path.toString(); //getSource();
let result = eval(source);
path.replaceWithSourceString(result + "");
path.skip();
}
},
VariableDeclaration(path) {
// change `const a = 1, b = 2;` to `const a = 1; const b = 2;`
if (path.node.declarations.length > 1) {
let newDecls = path.node.declarations.map(d => {
return babel.types.variableDeclaration(
path.node.kind,
[d]
);
});
path.replaceWithMultiple(newDecls);
}
},
}
traverse(moduleAst, moduleTransformer);
return moduleAst;
}
function collectModuleDepsAndExports(moduleId, moduleCodeRaw, metadata) {
moduleAst = babel.parse(moduleCodeRaw);
metadata["deps"] = [];
metadata["exports"] = [];
// assert(moduleAst.type == "ArrowFunctionExpression" || moduleAst.type == "FunctionExpression");
// assert.equal(moduleAst.body.type, "BlockStatement");
function collectDeps(moduleArrowFnPath) {
assert.equal(moduleArrowFnPath.node.type, "ArrowFunctionExpression");
// ensure the function takes `require` as an argument
assert.equal(moduleArrowFnPath.node.params.length, 3);
assert.equal(moduleArrowFnPath.node.params[2].name, "require");
// find references to `require`
const requireRefs = moduleArrowFnPath.scope.bindings.require.referencePaths;
for (const requireRef of requireRefs) {
const requireCall = requireRef.parentPath;
if (requireCall.node.type != "CallExpression") {
// e.g., e = n.nmd(e)
continue;
}
assert.equal(requireCall.node.arguments.length, 1);
const depId = requireCall.node.arguments[0].value;
// metadata["deps"].push({depId, path: getModulePath(depId)});
metadata["deps"].push(depId + "");
}
}
function collectExports(moduleArrowFnPath) {
assert.equal(moduleArrowFnPath.node.type, "ArrowFunctionExpression");
// ensure the function takes `exports` as an argument
assert(moduleArrowFnPath.node.params.length >= 2);
assert.equal(moduleArrowFnPath.node.params[1].name, "exports");
// find references to `exports`
const exportsRefPaths = moduleArrowFnPath.scope.bindings.exports.referencePaths;
for (const exportsRefPath of exportsRefPaths) {
const exportsMemberExpr = exportsRefPath.parent;
if (exportsMemberExpr.type != "MemberExpression") {
let code = generate(exportsMemberExpr).code;
if (code.indexOf('Object.defineProperty(exports, "__esModule"') == 0) {
// ignore
} else {
console.log("WTF", moduleId, code);
}
continue;
}
assert.equal(exportsMemberExpr.object.name, "exports");
assert.equal(exportsMemberExpr.property.type, "Identifier");
const exportName = exportsMemberExpr.property.name;
if (metadata["exports"].indexOf(exportName) == -1) {
metadata["exports"].push(exportName);
}
}
// find references to `module.exports`
// two cases:
// 1. module.exports.foo = bar
// 2. module.exports = foo
const moduleRefPaths = moduleArrowFnPath.scope.bindings.module.referencePaths;
for (const moduleRefPath of moduleRefPaths) {
const moduleMemberExpr = moduleRefPath.parent;
if (moduleMemberExpr.type != "MemberExpression") {
console.log("WTF2", moduleId, generate(moduleMemberExpr).code);
continue;
}
assert.equal(moduleMemberExpr.object.name, "module");
assert.equal(moduleMemberExpr.property.type, "Identifier");
assert.equal(moduleMemberExpr.property.name, "exports");
// case 1:
const moduleExportsMemberExpr = moduleRefPath.parentPath.parent;
if (moduleExportsMemberExpr.type == "MemberExpression" &&
moduleExportsMemberExpr.property.type == "Identifier" &&
moduleExportsMemberExpr.object == moduleMemberExpr
) {
const exportName = moduleExportsMemberExpr.property.name;
if (metadata["exports"].indexOf(exportName) == -1) {
metadata["exports"].push(exportName);
}
}
// case 2:
const moduleExportsAssignmentExpr = moduleRefPath.parentPath.parent;
if (moduleExportsAssignmentExpr.type == "AssignmentExpression") {
// case 2.1: module.exports = {foo: bar}
if (moduleExportsAssignmentExpr.right.type == "ObjectExpression") {
for (const prop of moduleExportsAssignmentExpr.right.properties) {
assert.equal(prop.type, "ObjectProperty");
assert.equal(prop.key.type, "Identifier");
const exportName = prop.key.name;
if (metadata["exports"].indexOf(exportName) == -1) {
metadata["exports"].push(exportName);
}
}
}
// case 2.2: module.exports = foo
else if (moduleExportsAssignmentExpr.right.type == "Identifier") {
const exportName = moduleExportsAssignmentExpr.right.name;
if (metadata["exports"].indexOf(exportName) == -1) {
metadata["exports"].push("$maybe-default$ " + exportName + " $maybe-default$");
}
}
// case 2.3: module.exports = function() {}
else if (moduleExportsAssignmentExpr.right.type == "FunctionExpression") {
let exportName = "<anonymouse-function>";
if (moduleExportsAssignmentExpr.right.id) {
exportName = moduleExportsAssignmentExpr.right.id.name;
}
if (metadata["exports"].indexOf(exportName) == -1) {
metadata["exports"].push("$maybe-default$ " + exportName + " $maybe-default$");
}
}
// case 2.4: module.exports = ...anything else...
else {
const exportName = "$complex-export$ "
+ generate(moduleExportsAssignmentExpr.right).code
.replace("<", "<")
.replace(">", ">")
+ " $complex-export$";
if (metadata["exports"].indexOf(exportName) == -1) {
metadata["exports"].push(exportName);
}
}
}
}
}
let transformedArrowFn = false;
const moduleTransformer = {
ArrowFunctionExpression(path) {
if (transformedArrowFn) {
return;
}
const node = path.node; // the module's AST
// at most 3 arguments: module, exports, require
assert(node.params.length <= 3);
// This renaming is already done in `normalizeExports`.
// // rename the arguments from (e, t, n) to (module, exports, require)
// node.params.forEach((param, i) => {
// path.scope.rename(param.name, ["module", "exports", "require"][i]);
// });
if (node.params.length == 3)
collectDeps(path);
if (node.params.length >= 2)
collectExports(path);
transformedArrowFn = true;
},
}
traverse(moduleAst, moduleTransformer);
return moduleAst
}
function handleModule(moduleId, moduleAst, metadata) {
assert(moduleAst.type == "ArrowFunctionExpression" || moduleAst.type == "FunctionExpression");
assert.equal(moduleAst.body.type, "BlockStatement");
let moduleCodeRaw = generate(moduleAst).code;
// Step 1: Convert weird exports into nicer form before we collect exports.
moduleAst = normalizeExports(moduleId, moduleCodeRaw);
// Step 2: Prettify the module code.
moduleCodeRaw = generate(moduleAst).code; // ugly...
moduleAst = makeModuleReadable(moduleId, moduleCodeRaw);
// Step 3: Collect exports and dependencies.
moduleCodeRaw = generate(moduleAst).code; // ugly...
moduleAst = collectModuleDepsAndExports(moduleId, moduleCodeRaw, metadata);
// moduleAst = babel.parse(moduleCodeRaw);
// traverse(moduleAst, moduleTransformer);
assert (moduleAst.type == "File");
assert (moduleAst.program.type == "Program");
assert (moduleAst.program.body.length == 1);
assert (moduleAst.program.body[0].type == "ExpressionStatement");
assert (moduleAst.program.body[0].expression.type == "ArrowFunctionExpression");
assert (moduleAst.program.body[0].expression.body.type == "BlockStatement");
const mainBody = moduleAst.program.body[0].expression.body.body;
const moduleCode = generate(babel.types.Program(mainBody)).code;
const moduleCode2 = prettier.format(moduleCode, {
parser: "babel",
}).trim();
fs.writeFileSync(getModulePath(moduleId), moduleCode2);
}
const moduleDeps = {};
traverse(ast, {
enter(path) {
if (path.node.type == "VariableDeclarator" && path.node.id.name == "e") {
const modules = path.node.init.properties;
for (let module of modules) {
const moduleId = module.key.value;
const moduleAst = module.value;
moduleDeps[moduleId] = {}
try {
handleModule(
moduleId, moduleAst, moduleDeps[moduleId]
);
} catch (e) {
console.log("Error handling module " + moduleId);
throw e;
}
}
path.stop();
}
}
});
// handle the main module - special case because it's not in the `e` object
const mainModuleId = "main";
const mainModuleAst = babel.parse(mainCode).program.body[0].expression;
moduleDeps[mainModuleId] = {}
handleModule(mainModuleId, mainModuleAst, moduleDeps[mainModuleId]);
// add reverse dependencies
for (const moduleId in moduleDeps) {
const metadata = moduleDeps[moduleId];
metadata["importedBy"] = metadata["importedBy"] || [];
for (const depId of metadata["deps"]) {
assert (depId in moduleDeps,
"Module " + moduleId + " depends on " + depId + " but it's not in the list of modules");
moduleDeps[depId]["importedBy"] = moduleDeps[depId]["importedBy"] || [];
moduleDeps[depId]["importedBy"].push(moduleId);
}
}
function removeDups(arr) {
return [...new Set(arr)];
}
function removeModule(moduleId) {
if (!moduleDeps[moduleId]) {
return;
}
const importers = moduleDeps[moduleId]["importedBy"];
for (const importer of importers) {
if (!moduleDeps[importer]) {
console.log("WARNING: " + importer + " imports " + moduleId + " but it's not in the list of modules");
continue;
}
const metadata = moduleDeps[importer];
metadata["deps"] = metadata["deps"].filter(dep => dep != moduleId);
}
delete moduleDeps[moduleId];
}
const moduleCodes = {};
// add line number info
for (const moduleId in moduleDeps) {
const metadata = moduleDeps[moduleId];
const moduleCode = fs.readFileSync(getModulePath(moduleId), "utf8").trim();
const lines = moduleCode.split("\n");
metadata["lines"] = lines.length;
if (lines.length == 1)
{
const isEmptyFunction = moduleCode == "module.exports = function () {};"
const stdLibAliasMatch = moduleCode.match(/^module.exports = require\(("[^"]+")\);?$/);
const internalAliasMatch = moduleCode.match(/^module.exports = require\(([\d_]+)\);?$/);
if (isEmptyFunction)
{
// it's an empty module. Remove it. We don't want noise.
removeModule(moduleId);
console.log("Removing empty module " + moduleId);
continue;
} else if (stdLibAliasMatch || internalAliasMatch) {
// it's an alias to another module. Remove the aliasing and
// make modules that import it import the original module.
// we're not doing this recursively because it's not needed for this project.
const originalModuleId = stdLibAliasMatch ? stdLibAliasMatch[1] : (parseInt(internalAliasMatch[1].replace("_", "")) + "");
const aliasingModule = moduleId;
const importers = removeDups(moduleDeps[aliasingModule]["importedBy"]);
// step 0: update originalModule's importedBy for internal modules
if (internalAliasMatch) {
moduleDeps[originalModuleId]["importedBy"] = removeDups(
moduleDeps[originalModuleId]["importedBy"].concat(
moduleDeps[aliasingModule]["importedBy"]
).filter(x => x != aliasingModule)
);
}
// update the deps and code
for (const importer of importers) {
if (!moduleDeps[importer]) {
console.log("WARNING: " + importer + " imports " + moduleId + " but it's not in the list of modules");
console.log(importers)
}
// step 1: update the importers
const metadata = moduleDeps[importer];
metadata["deps"] = removeDups(
metadata["deps"].map(x => x == aliasingModule ? originalModuleId : x)
);
console.log("Renaming " + aliasingModule + " to " + originalModuleId + " in " + importer);
// step 2: update the code
const moduleCode = moduleCodes[importer] || fs.readFileSync(getModulePath(importer), "utf8").trim();
// replace all occurences of `require(aliasingModule)` with `require(originalModule)`
const pattern = new RegExp(`require\\(${aliasingModule}\\)`, "g");
assert (moduleCode.match(pattern), "Module " + importer + " imports " + aliasingModule + " but it's not in the code");
const newModuleCode = moduleCode.replace(
pattern,
`require(${originalModuleId})`
);
fs.writeFileSync(getModulePath(importer), newModuleCode);
moduleCodes[importer] = newModuleCode;
}
// finally remove the aliasing module
delete moduleDeps[moduleId];
console.log("Removing aliasing module " + moduleId + " (aliasing " + originalModuleId + ")");
continue;
}
}
// if it's not an empty/alias module, add it to the list of modules
moduleCodes[moduleId] = moduleCode;
}
function findDuplicateModules() {
// I noticed some modules have been repeated. I'm not sure why.
// This thing checks if a module's code already exists in another module.
// If it does, we can remove the module.
const duplicates = [];
for (const moduleId in moduleDeps) {
let moduleCode = moduleCodes[moduleId];
// remove indentation
moduleCode = moduleCode.split("\n").map(line => line.trim()).join("\n");
for (const otherModuleId in moduleDeps) {
if (otherModuleId <= moduleId) {
continue;
}
let otherModuleCode = moduleCodes[otherModuleId];
otherModuleCode = otherModuleCode.split("\n").map(line => line.trim()).join("\n");
if (otherModuleCode.includes(moduleCode)) {
console.log("Module " + moduleId + " is already in " + otherModuleId);
duplicates.push(moduleId);
}
}
}
return duplicates;
}
// for now, we're not removing duplicate modules
const duplicates = findDuplicateModules();
// write the module dependency graph
fs.writeFileSync(
path.join(outPath, "module_deps.js"),
"let module_deps_data = " + JSON.stringify(moduleDeps, null, 2),
);
// write the module codes
fs.writeFileSync(
path.join(outPath, "module_codes.js"),
"let module_codes_data = " + JSON.stringify(moduleCodes, null, 2),
);
console.log(
`This is where you'd call predict_module_names_and_categories.py to predict names and categories for the modules. (predicting annotations requires a bit of manual labelling first so that we can call codex in few-shot manner. That was done manually once, and there's no need to do it again.)
After that, you'd run the rename_modules.js to rename the modules as per the mix of gold and predicted annotations.
`
);