rflib-plugin 0.15.0 → 0.16.1
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/commands/rflib/logging/apex/instrument.d.ts +1 -0
- package/lib/commands/rflib/logging/apex/instrument.js +44 -98
- package/lib/commands/rflib/logging/apex/instrument.js.map +1 -1
- package/lib/commands/rflib/logging/aura/instrument.d.ts +1 -0
- package/lib/commands/rflib/logging/aura/instrument.js +18 -49
- package/lib/commands/rflib/logging/aura/instrument.js.map +1 -1
- package/lib/commands/rflib/logging/flow/instrument.d.ts +1 -0
- package/lib/commands/rflib/logging/flow/instrument.js +9 -2
- package/lib/commands/rflib/logging/flow/instrument.js.map +1 -1
- package/lib/commands/rflib/logging/lwc/instrument.d.ts +1 -0
- package/lib/commands/rflib/logging/lwc/instrument.js +18 -49
- package/lib/commands/rflib/logging/lwc/instrument.js.map +1 -1
- package/lib/shared/concurrency.d.ts +1 -0
- package/lib/shared/concurrency.js +16 -0
- package/lib/shared/concurrency.js.map +1 -0
- package/lib/shared/formatting.d.ts +9 -0
- package/lib/shared/formatting.js +45 -0
- package/lib/shared/formatting.js.map +1 -0
- package/lib/shared/types.d.ts +15 -0
- package/lib/shared/types.js +2 -0
- package/lib/shared/types.js.map +1 -0
- package/messages/rflib.logging.apex.instrument.md +8 -0
- package/messages/rflib.logging.aura.instrument.md +8 -0
- package/messages/rflib.logging.flow.instrument.md +8 -0
- package/messages/rflib.logging.lwc.instrument.md +8 -0
- package/oclif.manifest.json +41 -1
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ export default class RflibLoggingApexInstrument extends SfCommand<RflibLoggingAp
|
|
|
17
17
|
'skip-instrumented': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
18
|
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
19
|
exclude: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
concurrency: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
21
|
};
|
|
21
22
|
private logger;
|
|
22
23
|
private readonly stats;
|
|
@@ -2,12 +2,22 @@ import * as fs from 'node:fs';
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
4
4
|
import { Messages, Logger } from '@salesforce/core';
|
|
5
|
-
import * as prettier from 'prettier';
|
|
6
5
|
import { minimatch } from 'minimatch';
|
|
6
|
+
import { processWithConcurrency } from '../../../../shared/concurrency.js';
|
|
7
|
+
import { writeInstrumentedFile } from '../../../../shared/formatting.js';
|
|
7
8
|
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
8
9
|
const messages = Messages.loadMessages('rflib-plugin', 'rflib.logging.apex.instrument');
|
|
9
10
|
class ApexInstrumentationService {
|
|
10
11
|
static TEST_SETUP_REGEX = /@TestSetup\s+((public|private|protected|global)s+)?(?:static\s+)?void\s+(\w+)\s*\([^)]*\)\s*{/g;
|
|
12
|
+
static IS_TEST_REGEX = /@isTest\b/i;
|
|
13
|
+
static PRETTIER_CONFIG = {
|
|
14
|
+
parser: 'apex',
|
|
15
|
+
plugins: ['prettier-plugin-apex'],
|
|
16
|
+
printWidth: 120,
|
|
17
|
+
tabWidth: 4,
|
|
18
|
+
useTabs: false,
|
|
19
|
+
singleQuote: true,
|
|
20
|
+
};
|
|
11
21
|
static METHOD_REGEX = /(@AuraEnabled\s*[\s\S]*?)?\b(public|private|protected|global)\s+(static\s+)?(?:(\w+(?:\s*<(?:[^<>]|<[^<>]*>)*>)?)|void)\s+(\w+)\s*\(([\s\S]*?)\)\s*{/g;
|
|
12
22
|
static CLASS_REGEX = /\bclass\s+\w+\s*{/;
|
|
13
23
|
static CLASS_LOGGER_REGEX = /\bprivate\s+(?:static\s+)?(?:final\s+)?rflib_Logger\s+(\w+)\b/;
|
|
@@ -30,24 +40,8 @@ class ApexInstrumentationService {
|
|
|
30
40
|
'TIME',
|
|
31
41
|
'ID',
|
|
32
42
|
]);
|
|
33
|
-
static
|
|
34
|
-
|
|
35
|
-
plugins: ['prettier-plugin-apex'],
|
|
36
|
-
printWidth: 120,
|
|
37
|
-
tabWidth: 4,
|
|
38
|
-
useTabs: false,
|
|
39
|
-
singleQuote: true,
|
|
40
|
-
};
|
|
41
|
-
static async formatContent(content) {
|
|
42
|
-
try {
|
|
43
|
-
return await prettier.format(content, this.PRETTIER_CONFIG);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
if (error instanceof Error) {
|
|
47
|
-
throw new Error(`Formatting failed: ${error.message}`);
|
|
48
|
-
}
|
|
49
|
-
throw new Error('Formatting failed with unknown error');
|
|
50
|
-
}
|
|
43
|
+
static isTestClass(content) {
|
|
44
|
+
return this.IS_TEST_REGEX.test(content);
|
|
51
45
|
}
|
|
52
46
|
static isInstrumented(content) {
|
|
53
47
|
return this.IS_INSTRUMENTED_REGEX.test(content);
|
|
@@ -278,6 +272,12 @@ export default class RflibLoggingApexInstrument extends SfCommand {
|
|
|
278
272
|
description: messages.getMessage('flags.exclude.description'),
|
|
279
273
|
char: 'e',
|
|
280
274
|
}),
|
|
275
|
+
concurrency: Flags.integer({
|
|
276
|
+
summary: messages.getMessage('flags.concurrency.summary'),
|
|
277
|
+
description: messages.getMessage('flags.concurrency.description'),
|
|
278
|
+
char: 'c',
|
|
279
|
+
default: 10,
|
|
280
|
+
}),
|
|
281
281
|
};
|
|
282
282
|
logger;
|
|
283
283
|
stats = {
|
|
@@ -303,15 +303,15 @@ export default class RflibLoggingApexInstrument extends SfCommand {
|
|
|
303
303
|
this.logger.debug(`Dry run mode: ${isDryRun}`);
|
|
304
304
|
this.spinner.start('Running...');
|
|
305
305
|
const files = await this.findAllApexFiles(sourcePath, instrumentationOpts.exclude);
|
|
306
|
-
await
|
|
307
|
-
const
|
|
308
|
-
if (
|
|
309
|
-
await this.processTestFile(filePath, isDryRun, instrumentationOpts);
|
|
306
|
+
await processWithConcurrency(files, flags.concurrency, async (filePath) => {
|
|
307
|
+
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
308
|
+
if (ApexInstrumentationService.isTestClass(content)) {
|
|
309
|
+
await this.processTestFile(filePath, content, isDryRun, instrumentationOpts);
|
|
310
310
|
}
|
|
311
311
|
else {
|
|
312
|
-
await this.instrumentApexClass(filePath, isDryRun, instrumentationOpts);
|
|
312
|
+
await this.instrumentApexClass(filePath, content, isDryRun, instrumentationOpts);
|
|
313
313
|
}
|
|
314
|
-
})
|
|
314
|
+
});
|
|
315
315
|
this.spinner.stop();
|
|
316
316
|
const duration = Date.now() - startTime;
|
|
317
317
|
this.logger.debug(`Completed instrumentation in ${duration}ms`);
|
|
@@ -340,94 +340,40 @@ export default class RflibLoggingApexInstrument extends SfCommand {
|
|
|
340
340
|
}));
|
|
341
341
|
return results.flat();
|
|
342
342
|
}
|
|
343
|
-
async processTestFile(filePath, isDryRun, instrumentationOpts) {
|
|
343
|
+
async processTestFile(filePath, content, isDryRun, instrumentationOpts) {
|
|
344
344
|
this.logger.debug(`Processing test file: ${filePath}`);
|
|
345
|
-
let
|
|
346
|
-
const originalContent =
|
|
347
|
-
if (instrumentationOpts.skipInstrumented && ApexInstrumentationService.isInstrumented(
|
|
345
|
+
let fileContent = content;
|
|
346
|
+
const originalContent = fileContent;
|
|
347
|
+
if (instrumentationOpts.skipInstrumented && ApexInstrumentationService.isInstrumented(fileContent)) {
|
|
348
348
|
this.logger.info(`Skipping instrumented test class: ${filePath}`);
|
|
349
349
|
return;
|
|
350
350
|
}
|
|
351
|
-
|
|
352
|
-
if (
|
|
353
|
-
this.stats.
|
|
354
|
-
this.stats.modifiedFilePaths?.push(filePath);
|
|
355
|
-
if (!isDryRun) {
|
|
356
|
-
try {
|
|
357
|
-
const finalContent = instrumentationOpts.prettier
|
|
358
|
-
? await ApexInstrumentationService.formatContent(content)
|
|
359
|
-
: content;
|
|
360
|
-
await fs.promises.writeFile(filePath, finalContent);
|
|
361
|
-
if (instrumentationOpts.prettier) {
|
|
362
|
-
this.stats.formattedFiles++;
|
|
363
|
-
this.logger.info(`Modified and formatted test file: ${filePath}`);
|
|
364
|
-
}
|
|
365
|
-
else {
|
|
366
|
-
this.logger.info(`Modified test file: ${filePath}`);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
catch (error) {
|
|
370
|
-
this.logger.warn(`Failed to format ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
371
|
-
await fs.promises.writeFile(filePath, content);
|
|
372
|
-
this.logger.info(`Modified test file without formatting: ${filePath}`);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
this.logger.info(`Would modify test file: ${filePath}`);
|
|
377
|
-
if (instrumentationOpts.verbose) {
|
|
378
|
-
this.log(`Would modify test file: ${filePath}`);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
351
|
+
fileContent = fileContent.replace(ApexInstrumentationService.TEST_SETUP_REGEX, (match) => `${match}\n rflib_TestUtil.prepareLoggerForUnitTests();`);
|
|
352
|
+
if (fileContent !== originalContent) {
|
|
353
|
+
await writeInstrumentedFile(filePath, fileContent, originalContent, instrumentationOpts, isDryRun, this.stats, this.logger, (msg) => this.log(msg), ApexInstrumentationService.PRETTIER_CONFIG);
|
|
381
354
|
}
|
|
382
355
|
}
|
|
383
|
-
async instrumentApexClass(filePath, isDryRun, instrumentationOpts) {
|
|
356
|
+
async instrumentApexClass(filePath, content, isDryRun, instrumentationOpts) {
|
|
384
357
|
const className = path.basename(filePath, '.cls');
|
|
385
358
|
this.logger.debug(`Processing class: ${className}`);
|
|
386
359
|
try {
|
|
387
360
|
this.stats.processedFiles++;
|
|
388
|
-
let
|
|
389
|
-
const originalContent =
|
|
390
|
-
if (instrumentationOpts.skipInstrumented && ApexInstrumentationService.isInstrumented(
|
|
361
|
+
let fileContent = content;
|
|
362
|
+
const originalContent = fileContent;
|
|
363
|
+
if (instrumentationOpts.skipInstrumented && ApexInstrumentationService.isInstrumented(fileContent)) {
|
|
391
364
|
this.logger.info(`Skipping instrumented class: ${className}`);
|
|
392
365
|
return;
|
|
393
366
|
}
|
|
394
|
-
const { variableName } = ApexInstrumentationService.detectLogger(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
367
|
+
const { variableName } = ApexInstrumentationService.detectLogger(fileContent);
|
|
368
|
+
fileContent = ApexInstrumentationService.addLoggerDeclaration(fileContent, className);
|
|
369
|
+
fileContent = ApexInstrumentationService.processMethodDeclarations(fileContent, variableName);
|
|
370
|
+
fileContent = ApexInstrumentationService.processSystemDebugStatements(fileContent, variableName);
|
|
371
|
+
fileContent = ApexInstrumentationService.processCatchBlocks(fileContent, variableName);
|
|
399
372
|
if (!instrumentationOpts.noIf) {
|
|
400
|
-
|
|
373
|
+
fileContent = ApexInstrumentationService.processIfStatements(fileContent, variableName);
|
|
401
374
|
}
|
|
402
|
-
if (
|
|
403
|
-
this.stats.
|
|
404
|
-
this.stats.modifiedFilePaths?.push(filePath);
|
|
405
|
-
if (!isDryRun) {
|
|
406
|
-
try {
|
|
407
|
-
const finalContent = instrumentationOpts.prettier
|
|
408
|
-
? await ApexInstrumentationService.formatContent(content)
|
|
409
|
-
: content;
|
|
410
|
-
await fs.promises.writeFile(filePath, finalContent);
|
|
411
|
-
if (instrumentationOpts.prettier) {
|
|
412
|
-
this.stats.formattedFiles++;
|
|
413
|
-
this.logger.info(`Modified and formatted: ${filePath}`);
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
this.logger.info(`Modified: ${filePath}`);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
catch (error) {
|
|
420
|
-
this.logger.warn(`Failed to format ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
421
|
-
await fs.promises.writeFile(filePath, content);
|
|
422
|
-
this.logger.info(`Modified without formatting: ${filePath}`);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
else {
|
|
426
|
-
this.logger.info(`Would modify: ${filePath}`);
|
|
427
|
-
if (instrumentationOpts.verbose) {
|
|
428
|
-
this.log(`Would modify: ${filePath}`);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
375
|
+
if (fileContent !== originalContent) {
|
|
376
|
+
await writeInstrumentedFile(filePath, fileContent, originalContent, instrumentationOpts, isDryRun, this.stats, this.logger, (msg) => this.log(msg), ApexInstrumentationService.PRETTIER_CONFIG);
|
|
431
377
|
}
|
|
432
378
|
}
|
|
433
379
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrument.js","sourceRoot":"","sources":["../../../../../src/commands/rflib/logging/apex/instrument.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAyCtC,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,EAAE,+BAA+B,CAAC,CAAC;AAExF,MAAM,0BAA0B;IACvB,MAAM,CAAU,gBAAgB,GACrC,gGAAgG,CAAC;IAE3F,MAAM,CAAU,YAAY,GAClC,uJAAuJ,CAAC;IAClJ,MAAM,CAAU,WAAW,GAAG,mBAAmB,CAAC;IAClD,MAAM,CAAU,kBAAkB,GAAG,+DAA+D,CAAC;IACrG,MAAM,CAAU,kBAAkB,GAAG,UAAU,CAAC;IAChD,MAAM,CAAU,WAAW,GAAG,oCAAoC,CAAC;IACnE,MAAM,CAAU,kBAAkB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M,CAAC;4BACN,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,QAAQ,EAAE,CAAC,CAAC;wBAC5C,CAAC;oBACH,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,QAAQ,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;wBAC5G,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;wBAC/C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAgC,QAAQ,EAAE,CAAC,CAAC;oBAC/D,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,QAAQ,EAAE,CAAC,CAAC;oBAC9C,IAAI,mBAAmB,CAAC,OAAO,EAAE,CAAC;wBAChC,IAAI,CAAC,GAAG,CAAC,iBAAiB,QAAQ,EAAE,CAAC,CAAC;oBACxC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,SAAS,EAAE,EAAE,KAAK,CAAC,CAAC;YAChE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { SfCommand, Flags } from '@salesforce/sf-plugins-core';\nimport { Messages, Logger } from '@salesforce/core';\nimport * as prettier from 'prettier';\nimport { minimatch } from 'minimatch';\n\ntype ApexMethodMatch = {\n auraEnabled?: string;\n access: string;\n isStatic?: string;\n returnType: string;\n methodName: string;\n args: string;\n}\n\ntype IfCondition = {\n condition: string;\n position: number;\n}\n\ntype InstrumentationOptions = {\n readonly prettier: boolean;\n readonly noIf: boolean;\n readonly skipInstrumented: boolean;\n readonly verbose: boolean;\n readonly exclude?: string;\n}\n\ntype LoggerInfo = {\n readonly exists: boolean;\n readonly variableName: string;\n}\n\ntype ProcessedParameters = {\n readonly paramList: readonly string[];\n readonly logArgs: string;\n}\n\nexport type RflibLoggingApexInstrumentResult = {\n processedFiles: number;\n modifiedFiles: number;\n formattedFiles: number;\n modifiedFilePaths?: string[];\n}\n\nMessages.importMessagesDirectoryFromMetaUrl(import.meta.url);\nconst messages = Messages.loadMessages('rflib-plugin', 'rflib.logging.apex.instrument');\n\nclass ApexInstrumentationService {\n public static readonly TEST_SETUP_REGEX =\n /@TestSetup\\s+((public|private|protected|global)s+)?(?:static\\s+)?void\\s+(\\w+)\\s*\\([^)]*\\)\\s*{/g;\n\n private static readonly METHOD_REGEX =\n /(@AuraEnabled\\s*[\\s\\S]*?)?\\b(public|private|protected|global)\\s+(static\\s+)?(?:(\\w+(?:\\s*<(?:[^<>]|<[^<>]*>)*>)?)|void)\\s+(\\w+)\\s*\\(([\\s\\S]*?)\\)\\s*{/g;\n private static readonly CLASS_REGEX = /\\bclass\\s+\\w+\\s*{/;\n private static readonly CLASS_LOGGER_REGEX = /\\bprivate\\s+(?:static\\s+)?(?:final\\s+)?rflib_Logger\\s+(\\w+)\\b/;\n private static readonly GENERIC_ARGS_REGEX = /<[^>]+>/g;\n private static readonly CATCH_REGEX = /catch\\s*\\(\\s*\\w+\\s+(\\w+)\\s*\\)\\s*{/g;\n private static readonly IF_STATEMENT_REGEX =\n /if\\s*\\((.*?)\\)\\s*(?:{([^]*?(?:(?<!{){(?:[^]*?)}(?!})[^]*?)*)}|([^{].*?)(?=\\s*(?:;|$));)/g;\n private static readonly ELSE_REGEX = /\\s*else(?!\\s*if\\b)\\s*(?:{((?:[^{}]|{(?:[^{}]|{[^{}]*})*})*)}|([^{;]*(?:;|$)))/g;\n private static readonly IS_INSTRUMENTED_REGEX = /(\\brflib_Logger\\b|\\brflib_TestUtil\\b)/;\n private static readonly SYSTEM_DEBUG_START_REGEX = /System\\.debug\\s*\\(/g;\n private static readonly LOGGING_LEVEL_REGEX = /^LoggingLevel\\.(\\w+)\\s*,\\s*([\\s\\S]*)$/;\n\n private static readonly PRIMITIVE_TYPES = new Set([\n 'STRING',\n 'INTEGER',\n 'LONG',\n 'DECIMAL',\n 'DOUBLE',\n 'BOOLEAN',\n 'DATE',\n 'DATETIME',\n 'TIME',\n 'ID',\n ]);\n\n private static readonly PRETTIER_CONFIG: prettier.Options = {\n parser: 'apex',\n plugins: ['prettier-plugin-apex'],\n printWidth: 120,\n tabWidth: 4,\n useTabs: false,\n singleQuote: true,\n };\n\n public static async formatContent(content: string): Promise<string> {\n try {\n return await prettier.format(content, this.PRETTIER_CONFIG);\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Formatting failed: ${error.message}`);\n }\n throw new Error('Formatting failed with unknown error');\n }\n }\n\n public static isInstrumented(content: string): boolean {\n return this.IS_INSTRUMENTED_REGEX.test(content);\n }\n\n public static detectLogger(content: string): LoggerInfo {\n const match = content.match(this.CLASS_LOGGER_REGEX);\n return {\n exists: this.CLASS_LOGGER_REGEX.test(content),\n variableName: match ? match[1] : 'LOGGER',\n };\n }\n\n public static addLoggerDeclaration(content: string, className: string): string {\n const { exists, variableName } = this.detectLogger(content);\n if (!exists) {\n const loggerDecl = `private static final rflib_Logger ${variableName} = rflib_LoggerUtil.getFactory().createLogger('${className}');`;\n return content.replace(this.CLASS_REGEX, `$&\\n ${loggerDecl}`);\n }\n return content;\n }\n\n public static processMethodDeclarations(content: string, loggerName: string): string {\n return content.replace(this.METHOD_REGEX, (match: string, ...args: unknown[]) => {\n const methodInfo: ApexMethodMatch = {\n auraEnabled: args[0] as string,\n access: args[1] as string,\n isStatic: args[2] as string,\n returnType: args[3] as string,\n methodName: args[4] as string,\n args: args[5] as string,\n };\n\n const { paramList, logArgs } = this.processParameters(methodInfo.args);\n\n return `${match}\\n ${loggerName}.info('${methodInfo.methodName}(${paramList\n .map((_, i) => `{${i}}`)\n .join(', ')})'${logArgs});\\n`;\n });\n }\n\n public static processCatchBlocks(content: string, loggerName: string): string {\n return content.replace(this.CATCH_REGEX, (match: string, exceptionVar: string, offset: number) => {\n const contentBeforeCatch = content.substring(0, offset);\n const methodMatches = [...contentBeforeCatch.matchAll(this.METHOD_REGEX)];\n const lastMethodMatch = methodMatches[methodMatches.length - 1];\n const methodName = lastMethodMatch ? lastMethodMatch[5] : 'unknown';\n\n return `${match}\\n ${loggerName}.error('An error occurred in ${methodName}()', ${exceptionVar.trim()});`;\n });\n }\n\n public static processIfStatements(content: string, loggerName: string): string {\n const conditions: IfCondition[] = [];\n\n let modified = content.replace(\n this.IF_STATEMENT_REGEX,\n (match: string, condition: string, blockBody: string, singleLineBody: string, offset: number) => {\n const cleanedUpCondition = condition.trim().replaceAll(\"'\", \"\\\\'\");\n conditions.push({\n condition: cleanedUpCondition,\n position: offset,\n });\n\n const logStatement = `${loggerName}.debug('if (${cleanedUpCondition})');\\n `;\n\n if (blockBody) {\n return `if (${condition}) {\\n ${logStatement}${blockBody}}\\n`;\n } else if (singleLineBody) {\n const cleanBody = singleLineBody.replace(/;$/, '').trim();\n return `if (${condition}) {\\n ${logStatement}${cleanBody};\\n }\\n`;\n }\n return match;\n },\n );\n\n modified = modified.replace(\n this.ELSE_REGEX,\n (match: string, blockBody?: string, singleLineBody?: string, offset?: number) => {\n const nearestIf = conditions\n .filter((c) => c.position < (offset ?? 0))\n .reduce((prev, curr) => (!prev || curr.position > prev.position ? curr : prev));\n\n const logStatement = nearestIf\n ? `${loggerName}.debug('else for if (${nearestIf.condition})');\\n `\n : `${loggerName}.debug('else statement');\\n `;\n\n if (blockBody) {\n return ` else {\\n ${logStatement}${blockBody}}`;\n } else if (singleLineBody) {\n return ` else {\\n ${logStatement}${singleLineBody}\\n }`;\n }\n return match;\n },\n );\n\n return modified;\n }\n\n public static processSystemDebugStatements(content: string, loggerName: string): string {\n const debugStartRegex = new RegExp(this.SYSTEM_DEBUG_START_REGEX);\n let match;\n let lastIndex = 0;\n let output = '';\n\n while ((match = debugStartRegex.exec(content)) !== null) {\n output += content.substring(lastIndex, match.index);\n\n const openParenIndex = match.index + match[0].length - 1;\n let depth = 1;\n let i = openParenIndex + 1;\n let inString = false;\n let isEscaped = false;\n\n for (; i < content.length && depth > 0; i++) {\n const char = content[i];\n\n if (inString) {\n if (isEscaped) {\n isEscaped = false;\n } else if (char === '\\\\') {\n isEscaped = true;\n } else if (char === \"'\") {\n inString = false;\n }\n } else if (char === \"'\") {\n inString = true;\n } else if (char === '(') {\n depth++;\n } else if (char === ')') {\n depth--;\n }\n }\n\n if (depth === 0) {\n const closeParenIndex = i - 1;\n const remaining = content.substring(closeParenIndex + 1);\n const semiColonMatch = remaining.match(/^\\s*;/);\n\n if (semiColonMatch) {\n const endOfStatement = closeParenIndex + 1 + semiColonMatch[0].length;\n const args = content.substring(openParenIndex + 1, closeParenIndex);\n const processed = this.transformSystemDebug(args, loggerName);\n output += processed;\n lastIndex = endOfStatement;\n debugStartRegex.lastIndex = endOfStatement;\n } else {\n output += match[0];\n lastIndex = match.index + match[0].length;\n }\n } else {\n output += match[0];\n lastIndex = match.index + match[0].length;\n }\n }\n\n output += content.substring(lastIndex);\n return output;\n }\n\n private static transformSystemDebug(args: string, loggerName: string): string {\n const trimmedArgs = args.trim();\n const levelMatch = trimmedArgs.match(this.LOGGING_LEVEL_REGEX);\n\n if (levelMatch) {\n const level = levelMatch[1].toUpperCase();\n const message = levelMatch[2].trim();\n let method = 'debug';\n\n if (level === 'ERROR') {\n method = 'error';\n } else if (level === 'WARN') {\n method = 'warn';\n } else if (level === 'INFO') {\n method = 'info';\n }\n\n const formattedMessage = message.startsWith(\"'\") ? message : `JSON.serialize(${message})`;\n return `${loggerName}.${method}(${formattedMessage});`;\n }\n\n const formattedArgs = trimmedArgs.startsWith(\"'\") ? trimmedArgs : `JSON.serialize(${trimmedArgs})`;\n return `${loggerName}.debug(${formattedArgs});`;\n }\n\n private static isComplexType(paramType: string): boolean {\n return (\n paramType.includes('<') ||\n paramType.includes('[') ||\n paramType === 'Object' ||\n !this.PRIMITIVE_TYPES.has(paramType.toUpperCase())\n );\n }\n\n private static processParameters(args: string): ProcessedParameters {\n const parameters = args\n ? args\n .replaceAll(this.GENERIC_ARGS_REGEX, '')\n .split(',')\n .map((param) => param.trim())\n : [];\n\n const logArgs =\n parameters.length > 0 && parameters[0] !== ''\n ? `, new Object[] { ${parameters\n .map((p) => {\n const [paramType, ...rest] = p.split(' ');\n const paramName = rest.length > 0 ? rest.join(' ') : paramType;\n return this.isComplexType(paramType) ? `JSON.serialize(${paramName})` : paramName;\n })\n .join(', ')} }`\n : '';\n\n return { paramList: parameters, logArgs };\n }\n}\n\nexport default class RflibLoggingApexInstrument extends SfCommand<RflibLoggingApexInstrumentResult> {\n public static readonly summary = messages.getMessage('summary');\n public static readonly description = messages.getMessage('description');\n public static readonly examples = messages.getMessages('examples');\n\n public static readonly flags = {\n sourcepath: Flags.string({\n summary: messages.getMessage('flags.sourcepath.summary'),\n description: messages.getMessage('flags.sourcepath.description'),\n char: 's',\n required: true,\n }),\n dryrun: Flags.boolean({\n summary: messages.getMessage('flags.dryrun.summary'),\n description: messages.getMessage('flags.dryrun.description'),\n char: 'd',\n default: false,\n }),\n prettier: Flags.boolean({\n summary: messages.getMessage('flags.prettier.summary'),\n description: messages.getMessage('flags.prettier.description'),\n char: 'p',\n default: false,\n }),\n 'no-if': Flags.boolean({\n summary: messages.getMessage('flags.no-if.summary'),\n description: messages.getMessage('flags.no-if.description'),\n default: false,\n }),\n 'skip-instrumented': Flags.boolean({\n summary: messages.getMessage('flags.skip-instrumented.summary'),\n description: messages.getMessage('flags.skip-instrumented.description'),\n default: false,\n }),\n verbose: Flags.boolean({\n summary: messages.getMessage('flags.verbose.summary'),\n description: messages.getMessage('flags.verbose.description'),\n char: 'v',\n default: false,\n }),\n exclude: Flags.string({\n summary: messages.getMessage('flags.exclude.summary'),\n description: messages.getMessage('flags.exclude.description'),\n char: 'e',\n }),\n };\n\n private logger!: Logger;\n private readonly stats: RflibLoggingApexInstrumentResult = {\n processedFiles: 0,\n modifiedFiles: 0,\n formattedFiles: 0,\n modifiedFilePaths: [],\n };\n\n public async run(): Promise<RflibLoggingApexInstrumentResult> {\n this.logger = await Logger.child(this.ctor.name);\n const startTime = Date.now();\n\n const { flags } = await this.parse(RflibLoggingApexInstrument);\n const sourcePath = flags.sourcepath;\n const isDryRun = flags.dryrun;\n\n const instrumentationOpts: InstrumentationOptions = {\n prettier: flags.prettier,\n noIf: flags['no-if'],\n skipInstrumented: flags['skip-instrumented'],\n verbose: flags.verbose,\n exclude: flags.exclude,\n };\n\n this.log(`Scanning Apex classes in ${sourcePath} and sub directories`);\n this.logger.debug(`Dry run mode: ${isDryRun}`);\n\n this.spinner.start('Running...');\n\n const files = await this.findAllApexFiles(sourcePath, instrumentationOpts.exclude);\n await Promise.all(\n files.map(async (filePath) => {\n const fileName = path.basename(filePath);\n if (fileName.includes('Test')) {\n await this.processTestFile(filePath, isDryRun, instrumentationOpts);\n } else {\n await this.instrumentApexClass(filePath, isDryRun, instrumentationOpts);\n }\n })\n );\n\n this.spinner.stop();\n\n const duration = Date.now() - startTime;\n this.logger.debug(`Completed instrumentation in ${duration}ms`);\n\n this.log('\\nInstrumentation complete.');\n this.log(`Processed files: ${this.stats.processedFiles}`);\n this.log(`Modified files: ${this.stats.modifiedFiles}`);\n this.log(`Formatted files: ${this.stats.formattedFiles}`);\n\n return { ...this.stats };\n }\n\n private async findAllApexFiles(dirPath: string, excludePattern?: string): Promise<string[]> {\n this.logger.debug(`Scanning directory: ${dirPath}`);\n const entries = await fs.promises.readdir(dirPath, { withFileTypes: true });\n\n const results = await Promise.all(\n entries.map(async (entry) => {\n const filePath = path.join(dirPath, entry.name);\n\n if (excludePattern && minimatch(filePath, excludePattern, { matchBase: true })) {\n this.logger.debug(`Skipping excluded path: ${filePath}`);\n return [];\n }\n\n if (entry.isDirectory()) {\n return this.findAllApexFiles(filePath, excludePattern);\n }\n\n if (entry.name.endsWith('.cls')) {\n return [filePath];\n }\n\n return [];\n })\n );\n\n return results.flat();\n }\n\n private async processTestFile(\n filePath: string,\n isDryRun: boolean,\n instrumentationOpts: InstrumentationOptions,\n ): Promise<void> {\n this.logger.debug(`Processing test file: ${filePath}`);\n let content = await fs.promises.readFile(filePath, 'utf8');\n const originalContent = content;\n\n if (instrumentationOpts.skipInstrumented && ApexInstrumentationService.isInstrumented(content)) {\n this.logger.info(`Skipping instrumented test class: ${filePath}`);\n return;\n }\n\n content = content.replace(\n ApexInstrumentationService.TEST_SETUP_REGEX,\n (match) => `${match}\\n rflib_TestUtil.prepareLoggerForUnitTests();`,\n );\n\n if (content !== originalContent) {\n this.stats.modifiedFiles++;\n this.stats.modifiedFilePaths?.push(filePath);\n if (!isDryRun) {\n try {\n const finalContent = instrumentationOpts.prettier\n ? await ApexInstrumentationService.formatContent(content)\n : content;\n\n await fs.promises.writeFile(filePath, finalContent);\n\n if (instrumentationOpts.prettier) {\n this.stats.formattedFiles++;\n this.logger.info(`Modified and formatted test file: ${filePath}`);\n } else {\n this.logger.info(`Modified test file: ${filePath}`);\n }\n } catch (error) {\n this.logger.warn(`Failed to format ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n await fs.promises.writeFile(filePath, content);\n this.logger.info(`Modified test file without formatting: ${filePath}`);\n }\n } else {\n this.logger.info(`Would modify test file: ${filePath}`);\n if (instrumentationOpts.verbose) {\n this.log(`Would modify test file: ${filePath}`);\n }\n }\n }\n }\n\n private async instrumentApexClass(\n filePath: string,\n isDryRun: boolean,\n instrumentationOpts: InstrumentationOptions,\n ): Promise<void> {\n const className = path.basename(filePath, '.cls');\n this.logger.debug(`Processing class: ${className}`);\n\n try {\n this.stats.processedFiles++;\n let content = await fs.promises.readFile(filePath, 'utf8');\n const originalContent = content;\n\n if (instrumentationOpts.skipInstrumented && ApexInstrumentationService.isInstrumented(content)) {\n this.logger.info(`Skipping instrumented class: ${className}`);\n return;\n }\n\n const { variableName } = ApexInstrumentationService.detectLogger(content);\n content = ApexInstrumentationService.addLoggerDeclaration(content, className);\n content = ApexInstrumentationService.processMethodDeclarations(content, variableName);\n content = ApexInstrumentationService.processSystemDebugStatements(content, variableName);\n content = ApexInstrumentationService.processCatchBlocks(content, variableName);\n\n if (!instrumentationOpts.noIf) {\n content = ApexInstrumentationService.processIfStatements(content, variableName);\n }\n\n if (content !== originalContent) {\n this.stats.modifiedFiles++;\n this.stats.modifiedFilePaths?.push(filePath);\n if (!isDryRun) {\n try {\n const finalContent = instrumentationOpts.prettier\n ? await ApexInstrumentationService.formatContent(content)\n : content;\n\n await fs.promises.writeFile(filePath, finalContent);\n\n if (instrumentationOpts.prettier) {\n this.stats.formattedFiles++;\n this.logger.info(`Modified and formatted: ${filePath}`);\n } else {\n this.logger.info(`Modified: ${filePath}`);\n }\n } catch (error) {\n this.logger.warn(`Failed to format ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n await fs.promises.writeFile(filePath, content);\n this.logger.info(`Modified without formatting: ${filePath}`);\n }\n } else {\n this.logger.info(`Would modify: ${filePath}`);\n if (instrumentationOpts.verbose) {\n this.log(`Would modify: ${filePath}`);\n }\n }\n }\n } catch (error) {\n this.logger.error(`Error processing class ${className}`, error);\n throw error;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"instrument.js","sourceRoot":"","sources":["../../../../../src/commands/rflib/logging/apex/instrument.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO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AqB,CACzB,QAAQ,EACR,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,QAAQ,EACR,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,MAAM,EACX,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EACtB,0BAA0B,CAAC,eAAe,CAC3C,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,SAAS,EAAE,EAAE,KAAK,CAAC,CAAC;YAChE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { SfCommand, Flags } from '@salesforce/sf-plugins-core';\nimport { Messages, Logger } from '@salesforce/core';\nimport * as prettier from 'prettier';\nimport { minimatch } from 'minimatch';\nimport { processWithConcurrency } from '../../../../shared/concurrency.js';\nimport { IfCondition, InstrumentationOptions, LoggerInfo } from '../../../../shared/types.js';\nimport { writeInstrumentedFile } from '../../../../shared/formatting.js';\n\ntype ApexMethodMatch = {\n auraEnabled?: string;\n access: string;\n isStatic?: string;\n returnType: string;\n methodName: string;\n args: string;\n}\n\ntype ProcessedParameters = {\n readonly paramList: readonly string[];\n readonly logArgs: string;\n}\n\nexport type RflibLoggingApexInstrumentResult = {\n processedFiles: number;\n modifiedFiles: number;\n formattedFiles: number;\n modifiedFilePaths?: string[];\n}\n\nMessages.importMessagesDirectoryFromMetaUrl(import.meta.url);\nconst messages = Messages.loadMessages('rflib-plugin', 'rflib.logging.apex.instrument');\n\nclass ApexInstrumentationService {\n public static readonly TEST_SETUP_REGEX =\n /@TestSetup\\s+((public|private|protected|global)s+)?(?:static\\s+)?void\\s+(\\w+)\\s*\\([^)]*\\)\\s*{/g;\n\n public static readonly IS_TEST_REGEX = /@isTest\\b/i;\n\n public static readonly PRETTIER_CONFIG: prettier.Options = {\n parser: 'apex',\n plugins: ['prettier-plugin-apex'],\n printWidth: 120,\n tabWidth: 4,\n useTabs: false,\n singleQuote: true,\n };\n\n private static readonly METHOD_REGEX =\n /(@AuraEnabled\\s*[\\s\\S]*?)?\\b(public|private|protected|global)\\s+(static\\s+)?(?:(\\w+(?:\\s*<(?:[^<>]|<[^<>]*>)*>)?)|void)\\s+(\\w+)\\s*\\(([\\s\\S]*?)\\)\\s*{/g;\n private static readonly CLASS_REGEX = /\\bclass\\s+\\w+\\s*{/;\n private static readonly CLASS_LOGGER_REGEX = /\\bprivate\\s+(?:static\\s+)?(?:final\\s+)?rflib_Logger\\s+(\\w+)\\b/;\n private static readonly GENERIC_ARGS_REGEX = /<[^>]+>/g;\n private static readonly CATCH_REGEX = /catch\\s*\\(\\s*\\w+\\s+(\\w+)\\s*\\)\\s*{/g;\n private static readonly IF_STATEMENT_REGEX =\n /if\\s*\\((.*?)\\)\\s*(?:{([^]*?(?:(?<!{){(?:[^]*?)}(?!})[^]*?)*)}|([^{].*?)(?=\\s*(?:;|$));)/g;\n private static readonly ELSE_REGEX = /\\s*else(?!\\s*if\\b)\\s*(?:{((?:[^{}]|{(?:[^{}]|{[^{}]*})*})*)}|([^{;]*(?:;|$)))/g;\n private static readonly IS_INSTRUMENTED_REGEX = /(\\brflib_Logger\\b|\\brflib_TestUtil\\b)/;\n private static readonly SYSTEM_DEBUG_START_REGEX = /System\\.debug\\s*\\(/g;\n private static readonly LOGGING_LEVEL_REGEX = /^LoggingLevel\\.(\\w+)\\s*,\\s*([\\s\\S]*)$/;\n\n private static readonly PRIMITIVE_TYPES = new Set([\n 'STRING',\n 'INTEGER',\n 'LONG',\n 'DECIMAL',\n 'DOUBLE',\n 'BOOLEAN',\n 'DATE',\n 'DATETIME',\n 'TIME',\n 'ID',\n ]);\n\n\n\n\n\n public static isTestClass(content: string): boolean {\n return this.IS_TEST_REGEX.test(content);\n }\n\n public static isInstrumented(content: string): boolean {\n return this.IS_INSTRUMENTED_REGEX.test(content);\n }\n\n public static detectLogger(content: string): LoggerInfo {\n const match = content.match(this.CLASS_LOGGER_REGEX);\n return {\n exists: this.CLASS_LOGGER_REGEX.test(content),\n variableName: match ? match[1] : 'LOGGER',\n };\n }\n\n public static addLoggerDeclaration(content: string, className: string): string {\n const { exists, variableName } = this.detectLogger(content);\n if (!exists) {\n const loggerDecl = `private static final rflib_Logger ${variableName} = rflib_LoggerUtil.getFactory().createLogger('${className}');`;\n return content.replace(this.CLASS_REGEX, `$&\\n ${loggerDecl}`);\n }\n return content;\n }\n\n public static processMethodDeclarations(content: string, loggerName: string): string {\n return content.replace(this.METHOD_REGEX, (match: string, ...args: unknown[]) => {\n const methodInfo: ApexMethodMatch = {\n auraEnabled: args[0] as string,\n access: args[1] as string,\n isStatic: args[2] as string,\n returnType: args[3] as string,\n methodName: args[4] as string,\n args: args[5] as string,\n };\n\n const { paramList, logArgs } = this.processParameters(methodInfo.args);\n\n return `${match}\\n ${loggerName}.info('${methodInfo.methodName}(${paramList\n .map((_, i) => `{${i}}`)\n .join(', ')})'${logArgs});\\n`;\n });\n }\n\n public static processCatchBlocks(content: string, loggerName: string): string {\n return content.replace(this.CATCH_REGEX, (match: string, exceptionVar: string, offset: number) => {\n const contentBeforeCatch = content.substring(0, offset);\n const methodMatches = [...contentBeforeCatch.matchAll(this.METHOD_REGEX)];\n const lastMethodMatch = methodMatches[methodMatches.length - 1];\n const methodName = lastMethodMatch ? lastMethodMatch[5] : 'unknown';\n\n return `${match}\\n ${loggerName}.error('An error occurred in ${methodName}()', ${exceptionVar.trim()});`;\n });\n }\n\n public static processIfStatements(content: string, loggerName: string): string {\n const conditions: IfCondition[] = [];\n\n let modified = content.replace(\n this.IF_STATEMENT_REGEX,\n (match: string, condition: string, blockBody: string, singleLineBody: string, offset: number) => {\n const cleanedUpCondition = condition.trim().replaceAll(\"'\", \"\\\\'\");\n conditions.push({\n condition: cleanedUpCondition,\n position: offset,\n });\n\n const logStatement = `${loggerName}.debug('if (${cleanedUpCondition})');\\n `;\n\n if (blockBody) {\n return `if (${condition}) {\\n ${logStatement}${blockBody}}\\n`;\n } else if (singleLineBody) {\n const cleanBody = singleLineBody.replace(/;$/, '').trim();\n return `if (${condition}) {\\n ${logStatement}${cleanBody};\\n }\\n`;\n }\n return match;\n },\n );\n\n modified = modified.replace(\n this.ELSE_REGEX,\n (match: string, blockBody?: string, singleLineBody?: string, offset?: number) => {\n const nearestIf = conditions\n .filter((c) => c.position < (offset ?? 0))\n .reduce((prev, curr) => (!prev || curr.position > prev.position ? curr : prev));\n\n const logStatement = nearestIf\n ? `${loggerName}.debug('else for if (${nearestIf.condition})');\\n `\n : `${loggerName}.debug('else statement');\\n `;\n\n if (blockBody) {\n return ` else {\\n ${logStatement}${blockBody}}`;\n } else if (singleLineBody) {\n return ` else {\\n ${logStatement}${singleLineBody}\\n }`;\n }\n return match;\n },\n );\n\n return modified;\n }\n\n public static processSystemDebugStatements(content: string, loggerName: string): string {\n const debugStartRegex = new RegExp(this.SYSTEM_DEBUG_START_REGEX);\n let match;\n let lastIndex = 0;\n let output = '';\n\n while ((match = debugStartRegex.exec(content)) !== null) {\n output += content.substring(lastIndex, match.index);\n\n const openParenIndex = match.index + match[0].length - 1;\n let depth = 1;\n let i = openParenIndex + 1;\n let inString = false;\n let isEscaped = false;\n\n for (; i < content.length && depth > 0; i++) {\n const char = content[i];\n\n if (inString) {\n if (isEscaped) {\n isEscaped = false;\n } else if (char === '\\\\') {\n isEscaped = true;\n } else if (char === \"'\") {\n inString = false;\n }\n } else if (char === \"'\") {\n inString = true;\n } else if (char === '(') {\n depth++;\n } else if (char === ')') {\n depth--;\n }\n }\n\n if (depth === 0) {\n const closeParenIndex = i - 1;\n const remaining = content.substring(closeParenIndex + 1);\n const semiColonMatch = remaining.match(/^\\s*;/);\n\n if (semiColonMatch) {\n const endOfStatement = closeParenIndex + 1 + semiColonMatch[0].length;\n const args = content.substring(openParenIndex + 1, closeParenIndex);\n const processed = this.transformSystemDebug(args, loggerName);\n output += processed;\n lastIndex = endOfStatement;\n debugStartRegex.lastIndex = endOfStatement;\n } else {\n output += match[0];\n lastIndex = match.index + match[0].length;\n }\n } else {\n output += match[0];\n lastIndex = match.index + match[0].length;\n }\n }\n\n output += content.substring(lastIndex);\n return output;\n }\n\n private static transformSystemDebug(args: string, loggerName: string): string {\n const trimmedArgs = args.trim();\n const levelMatch = trimmedArgs.match(this.LOGGING_LEVEL_REGEX);\n\n if (levelMatch) {\n const level = levelMatch[1].toUpperCase();\n const message = levelMatch[2].trim();\n let method = 'debug';\n\n if (level === 'ERROR') {\n method = 'error';\n } else if (level === 'WARN') {\n method = 'warn';\n } else if (level === 'INFO') {\n method = 'info';\n }\n\n const formattedMessage = message.startsWith(\"'\") ? message : `JSON.serialize(${message})`;\n return `${loggerName}.${method}(${formattedMessage});`;\n }\n\n const formattedArgs = trimmedArgs.startsWith(\"'\") ? trimmedArgs : `JSON.serialize(${trimmedArgs})`;\n return `${loggerName}.debug(${formattedArgs});`;\n }\n\n private static isComplexType(paramType: string): boolean {\n return (\n paramType.includes('<') ||\n paramType.includes('[') ||\n paramType === 'Object' ||\n !this.PRIMITIVE_TYPES.has(paramType.toUpperCase())\n );\n }\n\n private static processParameters(args: string): ProcessedParameters {\n const parameters = args\n ? args\n .replaceAll(this.GENERIC_ARGS_REGEX, '')\n .split(',')\n .map((param) => param.trim())\n : [];\n\n const logArgs =\n parameters.length > 0 && parameters[0] !== ''\n ? `, new Object[] { ${parameters\n .map((p) => {\n const [paramType, ...rest] = p.split(' ');\n const paramName = rest.length > 0 ? rest.join(' ') : paramType;\n return this.isComplexType(paramType) ? `JSON.serialize(${paramName})` : paramName;\n })\n .join(', ')} }`\n : '';\n\n return { paramList: parameters, logArgs };\n }\n}\n\nexport default class RflibLoggingApexInstrument extends SfCommand<RflibLoggingApexInstrumentResult> {\n public static readonly summary = messages.getMessage('summary');\n public static readonly description = messages.getMessage('description');\n public static readonly examples = messages.getMessages('examples');\n\n public static readonly flags = {\n sourcepath: Flags.string({\n summary: messages.getMessage('flags.sourcepath.summary'),\n description: messages.getMessage('flags.sourcepath.description'),\n char: 's',\n required: true,\n }),\n dryrun: Flags.boolean({\n summary: messages.getMessage('flags.dryrun.summary'),\n description: messages.getMessage('flags.dryrun.description'),\n char: 'd',\n default: false,\n }),\n prettier: Flags.boolean({\n summary: messages.getMessage('flags.prettier.summary'),\n description: messages.getMessage('flags.prettier.description'),\n char: 'p',\n default: false,\n }),\n 'no-if': Flags.boolean({\n summary: messages.getMessage('flags.no-if.summary'),\n description: messages.getMessage('flags.no-if.description'),\n default: false,\n }),\n 'skip-instrumented': Flags.boolean({\n summary: messages.getMessage('flags.skip-instrumented.summary'),\n description: messages.getMessage('flags.skip-instrumented.description'),\n default: false,\n }),\n verbose: Flags.boolean({\n summary: messages.getMessage('flags.verbose.summary'),\n description: messages.getMessage('flags.verbose.description'),\n char: 'v',\n default: false,\n }),\n exclude: Flags.string({\n summary: messages.getMessage('flags.exclude.summary'),\n description: messages.getMessage('flags.exclude.description'),\n char: 'e',\n }),\n concurrency: Flags.integer({\n summary: messages.getMessage('flags.concurrency.summary'),\n description: messages.getMessage('flags.concurrency.description'),\n char: 'c',\n default: 10,\n }),\n };\n\n private logger!: Logger;\n private readonly stats: RflibLoggingApexInstrumentResult = {\n processedFiles: 0,\n modifiedFiles: 0,\n formattedFiles: 0,\n modifiedFilePaths: [],\n };\n\n public async run(): Promise<RflibLoggingApexInstrumentResult> {\n this.logger = await Logger.child(this.ctor.name);\n const startTime = Date.now();\n\n const { flags } = await this.parse(RflibLoggingApexInstrument);\n const sourcePath = flags.sourcepath;\n const isDryRun = flags.dryrun;\n\n const instrumentationOpts: InstrumentationOptions = {\n prettier: flags.prettier,\n noIf: flags['no-if'],\n skipInstrumented: flags['skip-instrumented'],\n verbose: flags.verbose,\n exclude: flags.exclude,\n };\n\n this.log(`Scanning Apex classes in ${sourcePath} and sub directories`);\n this.logger.debug(`Dry run mode: ${isDryRun}`);\n\n this.spinner.start('Running...');\n\n const files = await this.findAllApexFiles(sourcePath, instrumentationOpts.exclude);\n await processWithConcurrency(\n files,\n flags.concurrency,\n async (filePath) => {\n const content = await fs.promises.readFile(filePath, 'utf8');\n if (ApexInstrumentationService.isTestClass(content)) {\n await this.processTestFile(filePath, content, isDryRun, instrumentationOpts);\n } else {\n await this.instrumentApexClass(filePath, content, isDryRun, instrumentationOpts);\n }\n }\n );\n\n this.spinner.stop();\n\n const duration = Date.now() - startTime;\n this.logger.debug(`Completed instrumentation in ${duration}ms`);\n\n this.log('\\nInstrumentation complete.');\n this.log(`Processed files: ${this.stats.processedFiles}`);\n this.log(`Modified files: ${this.stats.modifiedFiles}`);\n this.log(`Formatted files: ${this.stats.formattedFiles}`);\n\n return { ...this.stats };\n }\n\n private async findAllApexFiles(dirPath: string, excludePattern?: string): Promise<string[]> {\n this.logger.debug(`Scanning directory: ${dirPath}`);\n const entries = await fs.promises.readdir(dirPath, { withFileTypes: true });\n\n const results = await Promise.all(\n entries.map(async (entry) => {\n const filePath = path.join(dirPath, entry.name);\n\n if (excludePattern && minimatch(filePath, excludePattern, { matchBase: true })) {\n this.logger.debug(`Skipping excluded path: ${filePath}`);\n return [];\n }\n\n if (entry.isDirectory()) {\n return this.findAllApexFiles(filePath, excludePattern);\n }\n\n if (entry.name.endsWith('.cls')) {\n return [filePath];\n }\n\n return [];\n })\n );\n\n return results.flat();\n }\n\n private async processTestFile(\n filePath: string,\n content: string,\n isDryRun: boolean,\n instrumentationOpts: InstrumentationOptions,\n ): Promise<void> {\n this.logger.debug(`Processing test file: ${filePath}`);\n let fileContent = content;\n const originalContent = fileContent;\n\n if (instrumentationOpts.skipInstrumented && ApexInstrumentationService.isInstrumented(fileContent)) {\n this.logger.info(`Skipping instrumented test class: ${filePath}`);\n return;\n }\n\n fileContent = fileContent.replace(\n ApexInstrumentationService.TEST_SETUP_REGEX,\n (match) => `${match}\\n rflib_TestUtil.prepareLoggerForUnitTests();`,\n );\n\n if (fileContent !== originalContent) {\n await writeInstrumentedFile(\n filePath,\n fileContent,\n originalContent,\n instrumentationOpts,\n isDryRun,\n this.stats,\n this.logger,\n (msg) => this.log(msg),\n ApexInstrumentationService.PRETTIER_CONFIG,\n );\n }\n }\n\n private async instrumentApexClass(\n filePath: string,\n content: string,\n isDryRun: boolean,\n instrumentationOpts: InstrumentationOptions,\n ): Promise<void> {\n const className = path.basename(filePath, '.cls');\n this.logger.debug(`Processing class: ${className}`);\n\n try {\n this.stats.processedFiles++;\n let fileContent = content;\n const originalContent = fileContent;\n\n if (instrumentationOpts.skipInstrumented && ApexInstrumentationService.isInstrumented(fileContent)) {\n this.logger.info(`Skipping instrumented class: ${className}`);\n return;\n }\n\n const { variableName } = ApexInstrumentationService.detectLogger(fileContent);\n fileContent = ApexInstrumentationService.addLoggerDeclaration(fileContent, className);\n fileContent = ApexInstrumentationService.processMethodDeclarations(fileContent, variableName);\n fileContent = ApexInstrumentationService.processSystemDebugStatements(fileContent, variableName);\n fileContent = ApexInstrumentationService.processCatchBlocks(fileContent, variableName);\n\n if (!instrumentationOpts.noIf) {\n fileContent = ApexInstrumentationService.processIfStatements(fileContent, variableName);\n }\n\n if (fileContent !== originalContent) {\n await writeInstrumentedFile(\n filePath,\n fileContent,\n originalContent,\n instrumentationOpts,\n isDryRun,\n this.stats,\n this.logger,\n (msg) => this.log(msg),\n ApexInstrumentationService.PRETTIER_CONFIG,\n );\n }\n } catch (error) {\n this.logger.error(`Error processing class ${className}`, error);\n throw error;\n }\n }\n}\n"]}
|
|
@@ -17,6 +17,7 @@ export default class RflibLoggingAuraInstrument extends SfCommand<RflibLoggingAu
|
|
|
17
17
|
'skip-instrumented': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
18
|
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
19
|
exclude: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
concurrency: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
21
|
};
|
|
21
22
|
private logger;
|
|
22
23
|
private readonly stats;
|
|
@@ -2,20 +2,14 @@ import * as fs from 'node:fs';
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
4
4
|
import { Messages, Logger } from '@salesforce/core';
|
|
5
|
-
import * as prettier from 'prettier';
|
|
6
5
|
import { minimatch } from 'minimatch';
|
|
6
|
+
import { processWithConcurrency } from '../../../../shared/concurrency.js';
|
|
7
|
+
import { writeInstrumentedFile } from '../../../../shared/formatting.js';
|
|
7
8
|
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
8
9
|
const messages = Messages.loadMessages('rflib-plugin', 'rflib.logging.aura.instrument');
|
|
9
10
|
class AuraInstrumentationService {
|
|
10
11
|
static ATTRIBUTE_REGEX = /<aura:attribute[^>]*>/g;
|
|
11
12
|
static LOGGER_COMPONENT_REGEX = /<c:rflibLoggerCmp\s+aura:id="([^"]+)"\s+name="([^"]+)"\s+appendComponentId="([^"]+)"\s*\/>/;
|
|
12
|
-
static LOGGER_VAR_REGEX = /var\s+(\w+)\s*=\s*\w+\.find\(['"](\w+)['"]\);/;
|
|
13
|
-
static METHOD_REGEX = /(\b\w+)\s*:\s*function\s*\((.*?)\)\s*{((?:[^{}]|{(?:[^{}]|{(?:[^{}]|{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})*})*})*})*?)}/g;
|
|
14
|
-
static PROMISE_CHAIN_REGEX = /\.(then|catch|finally)\s*\(\s*function\s*\(([^)]*)\)\s*{([\s\S]*?)}/g;
|
|
15
|
-
static TRY_CATCH_BLOCK_REGEX = /try\s*{[\s\S]*?}\s*catch\s*\(([^)]*)\)\s*{/g;
|
|
16
|
-
static IF_STATEMENT_REGEX = /if\s*\((.*?)\)\s*(?:{([^]*?(?:(?<!{){(?:[^]*?)}(?!})[^]*?)*)}|([^{].*?)(?=\s*(?:;|$));)/g;
|
|
17
|
-
static ELSE_REGEX = /}\s*else(?!\s+if\b)\s*(?:{((?:[^{}]|{(?:[^{}]|{[^{}]*})*})*)}|([^{].*?)(?=\n|;|$))/g;
|
|
18
|
-
static CONSOLE_LOG_REGEX = /console\.(log|debug|info|warn|error)\s*\(\s*([^)]+)\s*\)\s*;?/g;
|
|
19
13
|
static PRETTIER_CONFIG = {
|
|
20
14
|
parser: 'babel',
|
|
21
15
|
printWidth: 120,
|
|
@@ -24,20 +18,16 @@ class AuraInstrumentationService {
|
|
|
24
18
|
singleQuote: true,
|
|
25
19
|
trailingComma: 'none',
|
|
26
20
|
};
|
|
21
|
+
static LOGGER_VAR_REGEX = /var\s+(\w+)\s*=\s*\w+\.find\(['"](\w+)['"]\);/;
|
|
22
|
+
static METHOD_REGEX = /(\b\w+)\s*:\s*function\s*\((.*?)\)\s*{((?:[^{}]|{(?:[^{}]|{(?:[^{}]|{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})*})*})*})*?)}/g;
|
|
23
|
+
static PROMISE_CHAIN_REGEX = /\.(then|catch|finally)\s*\(\s*function\s*\(([^)]*)\)\s*{([\s\S]*?)}/g;
|
|
24
|
+
static TRY_CATCH_BLOCK_REGEX = /try\s*{[\s\S]*?}\s*catch\s*\(([^)]*)\)\s*{/g;
|
|
25
|
+
static IF_STATEMENT_REGEX = /if\s*\((.*?)\)\s*(?:{([^]*?(?:(?<!{){(?:[^]*?)}(?!})[^]*?)*)}|([^{].*?)(?=\s*(?:;|$));)/g;
|
|
26
|
+
static ELSE_REGEX = /}\s*else(?!\s+if\b)\s*(?:{((?:[^{}]|{(?:[^{}]|{[^{}]*})*})*)}|([^{].*?)(?=\n|;|$))/g;
|
|
27
|
+
static CONSOLE_LOG_REGEX = /console\.(log|debug|info|warn|error)\s*\(\s*([^)]+)\s*\)\s*;?/g;
|
|
27
28
|
static isInstrumented(content, loggerId) {
|
|
28
29
|
return new RegExp(`\\.find\\(['"]${loggerId}['"]\\)`, 'g').test(content);
|
|
29
30
|
}
|
|
30
|
-
static async formatContent(content) {
|
|
31
|
-
try {
|
|
32
|
-
return await prettier.format(content, this.PRETTIER_CONFIG);
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
if (error instanceof Error) {
|
|
36
|
-
throw new Error(`Formatting failed: ${error.message}`);
|
|
37
|
-
}
|
|
38
|
-
throw new Error('Formatting failed with unknown error');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
31
|
static processMethodLogging(content, loggerId, isHelper, noIf) {
|
|
42
32
|
return content.replace(this.METHOD_REGEX, (match, methodName, params, body) => {
|
|
43
33
|
const paramList = params
|
|
@@ -175,6 +165,12 @@ export default class RflibLoggingAuraInstrument extends SfCommand {
|
|
|
175
165
|
description: messages.getMessage('flags.exclude.description'),
|
|
176
166
|
char: 'e',
|
|
177
167
|
}),
|
|
168
|
+
concurrency: Flags.integer({
|
|
169
|
+
summary: messages.getMessage('flags.concurrency.summary'),
|
|
170
|
+
description: messages.getMessage('flags.concurrency.description'),
|
|
171
|
+
char: 'c',
|
|
172
|
+
default: 10,
|
|
173
|
+
}),
|
|
178
174
|
};
|
|
179
175
|
logger;
|
|
180
176
|
stats = {
|
|
@@ -197,9 +193,9 @@ export default class RflibLoggingAuraInstrument extends SfCommand {
|
|
|
197
193
|
this.logger.debug(`Dry run mode: ${flags.dryrun}`);
|
|
198
194
|
this.spinner.start('Running...');
|
|
199
195
|
const components = await this.findAllAuraComponents(flags.sourcepath, instrumentationOpts.exclude);
|
|
200
|
-
await
|
|
196
|
+
await processWithConcurrency(components, flags.concurrency, async (component) => {
|
|
201
197
|
await this.processAuraComponent(component.path, component.name, flags.dryrun, instrumentationOpts);
|
|
202
|
-
})
|
|
198
|
+
});
|
|
203
199
|
this.spinner.stop();
|
|
204
200
|
this.log('\nInstrumentation complete.');
|
|
205
201
|
this.log(`Processed files: ${this.stats.processedFiles}`);
|
|
@@ -323,34 +319,7 @@ export default class RflibLoggingAuraInstrument extends SfCommand {
|
|
|
323
319
|
content = AuraInstrumentationService.processMethodLogging(content, loggerId, isHelper, instrumentationOpts.noIf);
|
|
324
320
|
content = AuraInstrumentationService.processTryCatchBlocks(content);
|
|
325
321
|
if (content !== originalContent) {
|
|
326
|
-
this.stats.
|
|
327
|
-
this.stats.modifiedFilePaths?.push(filePath);
|
|
328
|
-
if (!isDryRun) {
|
|
329
|
-
try {
|
|
330
|
-
const finalContent = instrumentationOpts.prettier
|
|
331
|
-
? await AuraInstrumentationService.formatContent(content)
|
|
332
|
-
: content;
|
|
333
|
-
await fs.promises.writeFile(filePath, finalContent);
|
|
334
|
-
if (instrumentationOpts.prettier) {
|
|
335
|
-
this.stats.formattedFiles++;
|
|
336
|
-
this.logger.info(`Modified and formatted: ${filePath}`);
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
this.logger.info(`Modified: ${filePath}`);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
catch (error) {
|
|
343
|
-
this.logger.warn(`Failed to format ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
344
|
-
await fs.promises.writeFile(filePath, content);
|
|
345
|
-
this.logger.info(`Modified without formatting: ${filePath}`);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
this.logger.info(`Would modify: ${filePath}`);
|
|
350
|
-
if (instrumentationOpts.verbose) {
|
|
351
|
-
this.log(`Would modify: ${filePath}`);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
322
|
+
await writeInstrumentedFile(filePath, content, originalContent, instrumentationOpts, isDryRun, this.stats, this.logger, (msg) => this.log(msg), AuraInstrumentationService.PRETTIER_CONFIG);
|
|
354
323
|
}
|
|
355
324
|
}
|
|
356
325
|
}
|