@metamask-previews/messenger-cli 0.0.0-preview-23f4dfd
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 +16 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/check.cjs +105 -0
- package/dist/check.cjs.map +1 -0
- package/dist/check.d.cts +11 -0
- package/dist/check.d.cts.map +1 -0
- package/dist/check.d.mts +11 -0
- package/dist/check.d.mts.map +1 -0
- package/dist/check.mjs +78 -0
- package/dist/check.mjs.map +1 -0
- package/dist/cli.cjs +107 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +3 -0
- package/dist/cli.d.cts.map +1 -0
- package/dist/cli.d.mts +3 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +102 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/fix.cjs +63 -0
- package/dist/fix.cjs.map +1 -0
- package/dist/fix.d.cts +11 -0
- package/dist/fix.d.cts.map +1 -0
- package/dist/fix.d.mts +11 -0
- package/dist/fix.d.mts.map +1 -0
- package/dist/fix.mjs +36 -0
- package/dist/fix.mjs.map +1 -0
- package/dist/generate-content.cjs +69 -0
- package/dist/generate-content.cjs.map +1 -0
- package/dist/generate-content.d.cts +9 -0
- package/dist/generate-content.d.cts.map +1 -0
- package/dist/generate-content.d.mts +9 -0
- package/dist/generate-content.d.mts.map +1 -0
- package/dist/generate-content.mjs +42 -0
- package/dist/generate-content.mjs.map +1 -0
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -0
- package/dist/parse-source.cjs +324 -0
- package/dist/parse-source.cjs.map +1 -0
- package/dist/parse-source.d.cts +25 -0
- package/dist/parse-source.d.cts.map +1 -0
- package/dist/parse-source.d.mts +25 -0
- package/dist/parse-source.d.mts.map +1 -0
- package/dist/parse-source.mjs +297 -0
- package/dist/parse-source.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +6 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +6 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type MethodInfo = {
|
|
2
|
+
name: string;
|
|
3
|
+
jsDoc: string;
|
|
4
|
+
};
|
|
5
|
+
export type SourceInfo = {
|
|
6
|
+
name: string;
|
|
7
|
+
filePath: string;
|
|
8
|
+
methods: MethodInfo[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Parses a source file to extract exposed methods and their metadata.
|
|
12
|
+
*
|
|
13
|
+
* @param filePath - Path to the controller/service file to parse.
|
|
14
|
+
* @returns Source information or null if parsing fails.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseSourceFile(filePath: string): Promise<SourceInfo | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Finds all source files that have MESSENGER_EXPOSED_METHODS constants.
|
|
19
|
+
* Searches recursively through subdirectories.
|
|
20
|
+
*
|
|
21
|
+
* @param sourcePath - Path to the folder where controllers/services are located.
|
|
22
|
+
* @returns A list of source information objects.
|
|
23
|
+
*/
|
|
24
|
+
export declare function findSourcesWithExposedMethods(sourcePath: string): Promise<SourceInfo[]>;
|
|
25
|
+
//# sourceMappingURL=parse-source.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-source.d.cts","sourceRoot":"","sources":["../src/parse-source.ts"],"names":[],"mappings":"AAgCA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC;AAsPF;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA4E5B;AAgCD;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,EAAE,CAAC,CA0BvB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type MethodInfo = {
|
|
2
|
+
name: string;
|
|
3
|
+
jsDoc: string;
|
|
4
|
+
};
|
|
5
|
+
export type SourceInfo = {
|
|
6
|
+
name: string;
|
|
7
|
+
filePath: string;
|
|
8
|
+
methods: MethodInfo[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Parses a source file to extract exposed methods and their metadata.
|
|
12
|
+
*
|
|
13
|
+
* @param filePath - Path to the controller/service file to parse.
|
|
14
|
+
* @returns Source information or null if parsing fails.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseSourceFile(filePath: string): Promise<SourceInfo | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Finds all source files that have MESSENGER_EXPOSED_METHODS constants.
|
|
19
|
+
* Searches recursively through subdirectories.
|
|
20
|
+
*
|
|
21
|
+
* @param sourcePath - Path to the folder where controllers/services are located.
|
|
22
|
+
* @returns A list of source information objects.
|
|
23
|
+
*/
|
|
24
|
+
export declare function findSourcesWithExposedMethods(sourcePath: string): Promise<SourceInfo[]>;
|
|
25
|
+
//# sourceMappingURL=parse-source.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-source.d.mts","sourceRoot":"","sources":["../src/parse-source.ts"],"names":[],"mappings":"AAgCA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC;AAsPF;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA4E5B;AAgCD;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,EAAE,CAAC,CA0BvB"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { assert, hasProperty, isObject } from "@metamask/utils";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import $typescript from "typescript";
|
|
5
|
+
const { ScriptTarget, createProgram, createSourceFile, findConfigFile, forEachChild, getJSDocCommentsAndTags, isArrayLiteralExpression, isAsExpression, isClassDeclaration, isIdentifier, isJSDoc, isMethodDeclaration, isStringLiteral, isVariableStatement, parseJsonConfigFileContent, readConfigFile, sys } = $typescript;
|
|
6
|
+
/**
|
|
7
|
+
* Extracts JSDoc comment from a method declaration.
|
|
8
|
+
*
|
|
9
|
+
* @param node - The method declaration node.
|
|
10
|
+
* @param source - The source file.
|
|
11
|
+
* @returns The JSDoc comment.
|
|
12
|
+
*/
|
|
13
|
+
function extractJSDoc(node, source) {
|
|
14
|
+
const jsDocTags = getJSDocCommentsAndTags(node);
|
|
15
|
+
if (jsDocTags.length === 0) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
const jsDoc = jsDocTags[0];
|
|
19
|
+
if (isJSDoc(jsDoc)) {
|
|
20
|
+
const fullText = source.getFullText();
|
|
21
|
+
const start = jsDoc.getFullStart();
|
|
22
|
+
const end = jsDoc.getEnd();
|
|
23
|
+
const rawJsDoc = fullText.substring(start, end).trim();
|
|
24
|
+
return formatJSDoc(rawJsDoc);
|
|
25
|
+
}
|
|
26
|
+
// istanbul ignore next: defensive check — getJSDocCommentsAndTags always returns JSDoc nodes
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Formats JSDoc comments to have consistent indentation for the generated file.
|
|
31
|
+
*
|
|
32
|
+
* @param rawJsDoc - The raw JSDoc comment from the source.
|
|
33
|
+
* @returns The formatted JSDoc comment.
|
|
34
|
+
*/
|
|
35
|
+
function formatJSDoc(rawJsDoc) {
|
|
36
|
+
const lines = rawJsDoc.split('\n');
|
|
37
|
+
const formattedLines = [];
|
|
38
|
+
for (let i = 0; i < lines.length; i++) {
|
|
39
|
+
const line = lines[i];
|
|
40
|
+
if (i === 0) {
|
|
41
|
+
formattedLines.push('/**');
|
|
42
|
+
}
|
|
43
|
+
else if (i === lines.length - 1) {
|
|
44
|
+
formattedLines.push(' */');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const trimmed = line.trim();
|
|
48
|
+
if (trimmed.startsWith('*')) {
|
|
49
|
+
const content = trimmed.substring(1).trim();
|
|
50
|
+
formattedLines.push(content ? ` * ${content}` : ' *');
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
formattedLines.push(trimmed ? ` * ${trimmed}` : ' *');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return formattedLines.join('\n');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Visits AST nodes to find exposed methods and controller/service class.
|
|
61
|
+
*
|
|
62
|
+
* @param context - The visitor context.
|
|
63
|
+
* @returns A function to visit nodes.
|
|
64
|
+
*/
|
|
65
|
+
function createASTVisitor(context) {
|
|
66
|
+
function visitNode(node) {
|
|
67
|
+
if (isVariableStatement(node)) {
|
|
68
|
+
const declaration = node.declarationList.declarations[0];
|
|
69
|
+
if (isIdentifier(declaration.name) &&
|
|
70
|
+
declaration.name.text === 'MESSENGER_EXPOSED_METHODS') {
|
|
71
|
+
if (declaration.initializer) {
|
|
72
|
+
let arrayExpression;
|
|
73
|
+
if (isArrayLiteralExpression(declaration.initializer)) {
|
|
74
|
+
arrayExpression = declaration.initializer;
|
|
75
|
+
}
|
|
76
|
+
else if (isAsExpression(declaration.initializer) &&
|
|
77
|
+
isArrayLiteralExpression(declaration.initializer.expression)) {
|
|
78
|
+
arrayExpression = declaration.initializer.expression;
|
|
79
|
+
}
|
|
80
|
+
if (arrayExpression) {
|
|
81
|
+
context.exposedMethods = arrayExpression.elements
|
|
82
|
+
.filter(isStringLiteral)
|
|
83
|
+
.map((element) => element.text);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (isClassDeclaration(node) && node.name) {
|
|
89
|
+
const classText = node.name.text;
|
|
90
|
+
if (classText.includes('Controller') || classText.includes('Service')) {
|
|
91
|
+
context.className = classText;
|
|
92
|
+
const seenMethods = new Set();
|
|
93
|
+
for (const member of node.members) {
|
|
94
|
+
if (isMethodDeclaration(member) &&
|
|
95
|
+
member.name &&
|
|
96
|
+
isIdentifier(member.name)) {
|
|
97
|
+
const methodName = member.name.text;
|
|
98
|
+
if (context.exposedMethods.includes(methodName) &&
|
|
99
|
+
!seenMethods.has(methodName)) {
|
|
100
|
+
seenMethods.add(methodName);
|
|
101
|
+
const jsDoc = extractJSDoc(member, context.sourceFile);
|
|
102
|
+
context.methods.push({
|
|
103
|
+
name: methodName,
|
|
104
|
+
jsDoc,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
forEachChild(node, visitNode);
|
|
112
|
+
}
|
|
113
|
+
return visitNode;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Create a TypeScript program for the given file by locating the nearest
|
|
117
|
+
* tsconfig.json.
|
|
118
|
+
*
|
|
119
|
+
* @param filePath - Absolute path to the source file.
|
|
120
|
+
* @returns A TypeScript program, or null if no tsconfig was found.
|
|
121
|
+
*/
|
|
122
|
+
function createProgramForFile(filePath) {
|
|
123
|
+
const configPath = findConfigFile(path.dirname(filePath), sys.fileExists.bind(sys), 'tsconfig.json');
|
|
124
|
+
if (!configPath) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const { config, error } = readConfigFile(configPath, sys.readFile.bind(sys));
|
|
128
|
+
if (error) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const parsedConfig = parseJsonConfigFileContent(config, sys, path.dirname(configPath));
|
|
132
|
+
return createProgram({
|
|
133
|
+
rootNames: parsedConfig.fileNames,
|
|
134
|
+
options: parsedConfig.options,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Find a class declaration with the given name in a source file.
|
|
139
|
+
*
|
|
140
|
+
* @param source - The source file to search.
|
|
141
|
+
* @param className - The class name to look for.
|
|
142
|
+
* @returns The class declaration node, or null if not found.
|
|
143
|
+
*/
|
|
144
|
+
function findClassInSourceFile(source, className) {
|
|
145
|
+
return (source.statements.find((node) => isClassDeclaration(node) && node.name?.text === className) ?? // istanbul ignore next: class is always found when called from parseSourceFile
|
|
146
|
+
null);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Search through the class hierarchy of a TypeScript type to find the
|
|
150
|
+
* declaration of a method with the given name.
|
|
151
|
+
*
|
|
152
|
+
* @param classType - The class type to search.
|
|
153
|
+
* @param methodName - The method name to look for.
|
|
154
|
+
* @returns The method declaration node, or null if not found.
|
|
155
|
+
*/
|
|
156
|
+
function findMethodInHierarchy(classType, methodName) {
|
|
157
|
+
const symbol = classType.getProperty(methodName);
|
|
158
|
+
if (!symbol) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const declarations = symbol.getDeclarations();
|
|
162
|
+
// istanbul ignore next: defensive check — symbols from getProperty always have declarations
|
|
163
|
+
if (!declarations) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
for (const declaration of declarations) {
|
|
167
|
+
if (isMethodDeclaration(declaration)) {
|
|
168
|
+
return declaration;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// istanbul ignore next: defensive fallback — property found but not a method declaration
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Check if a path is a directory.
|
|
176
|
+
*
|
|
177
|
+
* @param pathValue - The path to check.
|
|
178
|
+
* @returns True if the path is a directory, false otherwise.
|
|
179
|
+
*/
|
|
180
|
+
async function isDirectory(pathValue) {
|
|
181
|
+
try {
|
|
182
|
+
const stats = await fs.promises.stat(pathValue);
|
|
183
|
+
return stats.isDirectory();
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
if (isObject(error) &&
|
|
187
|
+
hasProperty(error, 'code') &&
|
|
188
|
+
error.code === 'ENOENT') {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Parses a source file to extract exposed methods and their metadata.
|
|
196
|
+
*
|
|
197
|
+
* @param filePath - Path to the controller/service file to parse.
|
|
198
|
+
* @returns Source information or null if parsing fails.
|
|
199
|
+
*/
|
|
200
|
+
export async function parseSourceFile(filePath) {
|
|
201
|
+
try {
|
|
202
|
+
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
203
|
+
const source = createSourceFile(filePath, content, ScriptTarget.Latest, true);
|
|
204
|
+
const context = {
|
|
205
|
+
exposedMethods: [],
|
|
206
|
+
className: '',
|
|
207
|
+
methods: [],
|
|
208
|
+
sourceFile: source,
|
|
209
|
+
};
|
|
210
|
+
createASTVisitor(context)(source);
|
|
211
|
+
if (context.exposedMethods.length === 0 || !context.className) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
const foundMethodNames = new Set(context.methods.map((method) => method.name));
|
|
215
|
+
const inheritedMethodNames = context.exposedMethods.filter((name) => !foundMethodNames.has(name));
|
|
216
|
+
if (inheritedMethodNames.length > 0) {
|
|
217
|
+
const program = createProgramForFile(filePath);
|
|
218
|
+
const checker = program?.getTypeChecker();
|
|
219
|
+
const programSourceFile = program?.getSourceFile(filePath);
|
|
220
|
+
assert(checker, `Type checker could not be created for "${filePath}". Ensure a valid tsconfig.json is present.`);
|
|
221
|
+
assert(programSourceFile, `Source file "${filePath}" not found in program.`);
|
|
222
|
+
const classNode = findClassInSourceFile(programSourceFile, context.className);
|
|
223
|
+
assert(classNode, `Class "${context.className}" not found in "${filePath}".`);
|
|
224
|
+
const classType = checker.getTypeAtLocation(classNode);
|
|
225
|
+
for (const methodName of inheritedMethodNames) {
|
|
226
|
+
const methodDeclaration = findMethodInHierarchy(classType, methodName);
|
|
227
|
+
const jsDoc = methodDeclaration
|
|
228
|
+
? extractJSDoc(methodDeclaration, methodDeclaration.getSourceFile())
|
|
229
|
+
: '';
|
|
230
|
+
context.methods.push({ name: methodName, jsDoc });
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
name: context.className,
|
|
235
|
+
filePath,
|
|
236
|
+
methods: context.methods,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.error(`Error parsing ${filePath}:`, error);
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Recursively get all files in a directory and its subdirectories.
|
|
246
|
+
*
|
|
247
|
+
* @param directory - The directory to search.
|
|
248
|
+
* @returns An array of file paths.
|
|
249
|
+
*/
|
|
250
|
+
const EXCLUDED_DIRECTORIES = new Set([
|
|
251
|
+
'node_modules',
|
|
252
|
+
'dist',
|
|
253
|
+
'.git',
|
|
254
|
+
'coverage',
|
|
255
|
+
]);
|
|
256
|
+
async function getFiles(directory) {
|
|
257
|
+
const entries = await fs.promises.readdir(directory, { withFileTypes: true });
|
|
258
|
+
const files = await Promise.all(entries.map(async (entry) => {
|
|
259
|
+
const fullPath = path.join(directory, entry.name);
|
|
260
|
+
if (entry.isDirectory()) {
|
|
261
|
+
return EXCLUDED_DIRECTORIES.has(entry.name)
|
|
262
|
+
? []
|
|
263
|
+
: await getFiles(fullPath);
|
|
264
|
+
}
|
|
265
|
+
return fullPath;
|
|
266
|
+
}));
|
|
267
|
+
return files.flat();
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Finds all source files that have MESSENGER_EXPOSED_METHODS constants.
|
|
271
|
+
* Searches recursively through subdirectories.
|
|
272
|
+
*
|
|
273
|
+
* @param sourcePath - Path to the folder where controllers/services are located.
|
|
274
|
+
* @returns A list of source information objects.
|
|
275
|
+
*/
|
|
276
|
+
export async function findSourcesWithExposedMethods(sourcePath) {
|
|
277
|
+
const srcPath = path.resolve(globalThis.process.cwd(), sourcePath);
|
|
278
|
+
const sources = [];
|
|
279
|
+
if (!(await isDirectory(srcPath))) {
|
|
280
|
+
throw new Error(`The specified path is not a directory: ${srcPath}`);
|
|
281
|
+
}
|
|
282
|
+
const srcFiles = await getFiles(srcPath);
|
|
283
|
+
for (const file of srcFiles) {
|
|
284
|
+
if (!file.endsWith('.ts') || file.endsWith('.test.ts')) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const content = await fs.promises.readFile(file, 'utf8');
|
|
288
|
+
if (content.includes('MESSENGER_EXPOSED_METHODS')) {
|
|
289
|
+
const sourceInfo = await parseSourceFile(file);
|
|
290
|
+
if (sourceInfo) {
|
|
291
|
+
sources.push(sourceInfo);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return sources;
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=parse-source.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-source.mjs","sourceRoot":"","sources":["../src/parse-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAChE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nimport type {\n ArrayLiteralExpression,\n ClassDeclaration,\n MethodDeclaration,\n Node as TSNode,\n Program,\n SourceFile,\n Type,\n} from 'typescript';\nimport {\n ScriptTarget,\n createProgram,\n createSourceFile,\n findConfigFile,\n forEachChild,\n getJSDocCommentsAndTags,\n isArrayLiteralExpression,\n isAsExpression,\n isClassDeclaration,\n isIdentifier,\n isJSDoc,\n isMethodDeclaration,\n isStringLiteral,\n isVariableStatement,\n parseJsonConfigFileContent,\n readConfigFile,\n sys,\n} from 'typescript';\n\nexport type MethodInfo = {\n name: string;\n jsDoc: string;\n};\n\nexport type SourceInfo = {\n name: string;\n filePath: string;\n methods: MethodInfo[];\n};\n\ntype VisitorContext = {\n exposedMethods: string[];\n className: string;\n methods: MethodInfo[];\n sourceFile: SourceFile;\n};\n\n/**\n * Extracts JSDoc comment from a method declaration.\n *\n * @param node - The method declaration node.\n * @param source - The source file.\n * @returns The JSDoc comment.\n */\nfunction extractJSDoc(node: MethodDeclaration, source: SourceFile): string {\n const jsDocTags = getJSDocCommentsAndTags(node);\n if (jsDocTags.length === 0) {\n return '';\n }\n\n const jsDoc = jsDocTags[0];\n if (isJSDoc(jsDoc)) {\n const fullText = source.getFullText();\n const start = jsDoc.getFullStart();\n const end = jsDoc.getEnd();\n const rawJsDoc = fullText.substring(start, end).trim();\n return formatJSDoc(rawJsDoc);\n }\n\n // istanbul ignore next: defensive check — getJSDocCommentsAndTags always returns JSDoc nodes\n return '';\n}\n\n/**\n * Formats JSDoc comments to have consistent indentation for the generated file.\n *\n * @param rawJsDoc - The raw JSDoc comment from the source.\n * @returns The formatted JSDoc comment.\n */\nfunction formatJSDoc(rawJsDoc: string): string {\n const lines = rawJsDoc.split('\\n');\n const formattedLines: string[] = [];\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (i === 0) {\n formattedLines.push('/**');\n } else if (i === lines.length - 1) {\n formattedLines.push(' */');\n } else {\n const trimmed = line.trim();\n if (trimmed.startsWith('*')) {\n const content = trimmed.substring(1).trim();\n formattedLines.push(content ? ` * ${content}` : ' *');\n } else {\n formattedLines.push(trimmed ? ` * ${trimmed}` : ' *');\n }\n }\n }\n\n return formattedLines.join('\\n');\n}\n\n/**\n * Visits AST nodes to find exposed methods and controller/service class.\n *\n * @param context - The visitor context.\n * @returns A function to visit nodes.\n */\nfunction createASTVisitor(context: VisitorContext): (node: TSNode) => void {\n function visitNode(node: TSNode): void {\n if (isVariableStatement(node)) {\n const declaration = node.declarationList.declarations[0];\n if (\n isIdentifier(declaration.name) &&\n declaration.name.text === 'MESSENGER_EXPOSED_METHODS'\n ) {\n if (declaration.initializer) {\n let arrayExpression: ArrayLiteralExpression | undefined;\n\n if (isArrayLiteralExpression(declaration.initializer)) {\n arrayExpression = declaration.initializer;\n } else if (\n isAsExpression(declaration.initializer) &&\n isArrayLiteralExpression(declaration.initializer.expression)\n ) {\n arrayExpression = declaration.initializer.expression;\n }\n\n if (arrayExpression) {\n context.exposedMethods = arrayExpression.elements\n .filter(isStringLiteral)\n .map((element) => element.text);\n }\n }\n }\n }\n\n if (isClassDeclaration(node) && node.name) {\n const classText = node.name.text;\n if (classText.includes('Controller') || classText.includes('Service')) {\n context.className = classText;\n\n const seenMethods = new Set<string>();\n for (const member of node.members) {\n if (\n isMethodDeclaration(member) &&\n member.name &&\n isIdentifier(member.name)\n ) {\n const methodName = member.name.text;\n if (\n context.exposedMethods.includes(methodName) &&\n !seenMethods.has(methodName)\n ) {\n seenMethods.add(methodName);\n const jsDoc = extractJSDoc(member, context.sourceFile);\n context.methods.push({\n name: methodName,\n jsDoc,\n });\n }\n }\n }\n }\n }\n\n forEachChild(node, visitNode);\n }\n\n return visitNode;\n}\n\n/**\n * Create a TypeScript program for the given file by locating the nearest\n * tsconfig.json.\n *\n * @param filePath - Absolute path to the source file.\n * @returns A TypeScript program, or null if no tsconfig was found.\n */\nfunction createProgramForFile(filePath: string): Program | null {\n const configPath = findConfigFile(\n path.dirname(filePath),\n sys.fileExists.bind(sys),\n 'tsconfig.json',\n );\n if (!configPath) {\n return null;\n }\n\n const { config, error } = readConfigFile(configPath, sys.readFile.bind(sys));\n\n if (error) {\n return null;\n }\n\n const parsedConfig = parseJsonConfigFileContent(\n config,\n sys,\n path.dirname(configPath),\n );\n\n return createProgram({\n rootNames: parsedConfig.fileNames,\n options: parsedConfig.options,\n });\n}\n\n/**\n * Find a class declaration with the given name in a source file.\n *\n * @param source - The source file to search.\n * @param className - The class name to look for.\n * @returns The class declaration node, or null if not found.\n */\nfunction findClassInSourceFile(\n source: SourceFile,\n className: string,\n): ClassDeclaration | null {\n return (\n source.statements.find(\n (node): node is ClassDeclaration =>\n isClassDeclaration(node) && node.name?.text === className,\n ) ?? // istanbul ignore next: class is always found when called from parseSourceFile\n null\n );\n}\n\n/**\n * Search through the class hierarchy of a TypeScript type to find the\n * declaration of a method with the given name.\n *\n * @param classType - The class type to search.\n * @param methodName - The method name to look for.\n * @returns The method declaration node, or null if not found.\n */\nfunction findMethodInHierarchy(\n classType: Type,\n methodName: string,\n): MethodDeclaration | null {\n const symbol = classType.getProperty(methodName);\n if (!symbol) {\n return null;\n }\n\n const declarations = symbol.getDeclarations();\n // istanbul ignore next: defensive check — symbols from getProperty always have declarations\n if (!declarations) {\n return null;\n }\n\n for (const declaration of declarations) {\n if (isMethodDeclaration(declaration)) {\n return declaration;\n }\n }\n\n // istanbul ignore next: defensive fallback — property found but not a method declaration\n return null;\n}\n\n/**\n * Check if a path is a directory.\n *\n * @param pathValue - The path to check.\n * @returns True if the path is a directory, false otherwise.\n */\nasync function isDirectory(pathValue: string): Promise<boolean> {\n try {\n const stats = await fs.promises.stat(pathValue);\n return stats.isDirectory();\n } catch (error) {\n if (\n isObject(error) &&\n hasProperty(error, 'code') &&\n error.code === 'ENOENT'\n ) {\n return false;\n }\n\n throw error;\n }\n}\n\n/**\n * Parses a source file to extract exposed methods and their metadata.\n *\n * @param filePath - Path to the controller/service file to parse.\n * @returns Source information or null if parsing fails.\n */\nexport async function parseSourceFile(\n filePath: string,\n): Promise<SourceInfo | null> {\n try {\n const content = await fs.promises.readFile(filePath, 'utf8');\n const source = createSourceFile(\n filePath,\n content,\n ScriptTarget.Latest,\n true,\n );\n\n const context: VisitorContext = {\n exposedMethods: [],\n className: '',\n methods: [],\n sourceFile: source,\n };\n\n createASTVisitor(context)(source);\n\n if (context.exposedMethods.length === 0 || !context.className) {\n return null;\n }\n\n const foundMethodNames = new Set(\n context.methods.map((method) => method.name),\n );\n\n const inheritedMethodNames = context.exposedMethods.filter(\n (name) => !foundMethodNames.has(name),\n );\n\n if (inheritedMethodNames.length > 0) {\n const program = createProgramForFile(filePath);\n const checker = program?.getTypeChecker();\n const programSourceFile = program?.getSourceFile(filePath);\n\n assert(\n checker,\n `Type checker could not be created for \"${filePath}\". Ensure a valid tsconfig.json is present.`,\n );\n\n assert(\n programSourceFile,\n `Source file \"${filePath}\" not found in program.`,\n );\n\n const classNode = findClassInSourceFile(\n programSourceFile,\n context.className,\n );\n\n assert(\n classNode,\n `Class \"${context.className}\" not found in \"${filePath}\".`,\n );\n\n const classType = checker.getTypeAtLocation(classNode);\n for (const methodName of inheritedMethodNames) {\n const methodDeclaration = findMethodInHierarchy(classType, methodName);\n\n const jsDoc = methodDeclaration\n ? extractJSDoc(methodDeclaration, methodDeclaration.getSourceFile())\n : '';\n context.methods.push({ name: methodName, jsDoc });\n }\n }\n\n return {\n name: context.className,\n filePath,\n methods: context.methods,\n };\n } catch (error) {\n console.error(`Error parsing ${filePath}:`, error);\n return null;\n }\n}\n\n/**\n * Recursively get all files in a directory and its subdirectories.\n *\n * @param directory - The directory to search.\n * @returns An array of file paths.\n */\nconst EXCLUDED_DIRECTORIES = new Set([\n 'node_modules',\n 'dist',\n '.git',\n 'coverage',\n]);\n\nasync function getFiles(directory: string): Promise<string[]> {\n const entries = await fs.promises.readdir(directory, { withFileTypes: true });\n const files = await Promise.all(\n entries.map(async (entry) => {\n const fullPath = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n return EXCLUDED_DIRECTORIES.has(entry.name)\n ? []\n : await getFiles(fullPath);\n }\n return fullPath;\n }),\n );\n\n return files.flat();\n}\n\n/**\n * Finds all source files that have MESSENGER_EXPOSED_METHODS constants.\n * Searches recursively through subdirectories.\n *\n * @param sourcePath - Path to the folder where controllers/services are located.\n * @returns A list of source information objects.\n */\nexport async function findSourcesWithExposedMethods(\n sourcePath: string,\n): Promise<SourceInfo[]> {\n const srcPath = path.resolve(globalThis.process.cwd(), sourcePath);\n const sources: SourceInfo[] = [];\n\n if (!(await isDirectory(srcPath))) {\n throw new Error(`The specified path is not a directory: ${srcPath}`);\n }\n\n const srcFiles = await getFiles(srcPath);\n\n for (const file of srcFiles) {\n if (!file.endsWith('.ts') || file.endsWith('.test.ts')) {\n continue;\n }\n\n const content = await fs.promises.readFile(file, 'utf8');\n\n if (content.includes('MESSENGER_EXPOSED_METHODS')) {\n const sourceInfo = await parseSourceFile(file);\n if (sourceInfo) {\n sources.push(sourceInfo);\n }\n }\n }\n\n return sources;\n}\n"]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ESLint as eslintClass } from 'eslint';\n\nexport type ESLint = {\n instance: eslintClass;\n eslintClass: typeof eslintClass;\n};\n"]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAE,eAAe;AAEpD,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,WAAW,CAAC;IACtB,WAAW,EAAE,OAAO,WAAW,CAAC;CACjC,CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAE,eAAe;AAEpD,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,WAAW,CAAC;IACtB,WAAW,EAAE,OAAO,WAAW,CAAC;CACjC,CAAC"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ESLint as eslintClass } from 'eslint';\n\nexport type ESLint = {\n instance: eslintClass;\n eslintClass: typeof eslintClass;\n};\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask-previews/messenger-cli",
|
|
3
|
+
"version": "0.0.0-preview-23f4dfd",
|
|
4
|
+
"description": "CLI tools for the MetaMask messenger system",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"MetaMask",
|
|
7
|
+
"Ethereum"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/messenger-cli#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/MetaMask/core/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/MetaMask/core.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/index.d.cts",
|
|
27
|
+
"default": "./dist/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
34
|
+
"bin": {
|
|
35
|
+
"messenger-generate-action-types": "./dist/cli.mjs"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist/"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
42
|
+
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
43
|
+
"build:docs": "typedoc",
|
|
44
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/messenger-cli",
|
|
45
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/messenger-cli",
|
|
46
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
47
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
48
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
49
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
50
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@metamask/utils": "^11.9.0",
|
|
54
|
+
"eslint": "^9.39.1",
|
|
55
|
+
"typescript": "~5.3.3",
|
|
56
|
+
"yargs": "^17.7.2"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
60
|
+
"@ts-bridge/cli": "^0.6.4",
|
|
61
|
+
"@types/jest": "^29.5.14",
|
|
62
|
+
"@types/yargs": "^17.0.32",
|
|
63
|
+
"deepmerge": "^4.2.2",
|
|
64
|
+
"execa": "^5.0.0",
|
|
65
|
+
"jest": "^29.7.0",
|
|
66
|
+
"ts-jest": "^29.2.5",
|
|
67
|
+
"typedoc": "^0.25.13",
|
|
68
|
+
"typedoc-plugin-missing-exports": "^2.0.0"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": "^18.18 || >=20"
|
|
72
|
+
},
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public",
|
|
75
|
+
"registry": "https://registry.npmjs.org/"
|
|
76
|
+
}
|
|
77
|
+
}
|