Skip to content

Commit bc09c53

Browse files
authored
Merge pull request #136 from Lightning-Flow-Scanner/treeshake-xmlbuilder2
feat: tree shaking on dependencies that aren't used
2 parents d13abb1 + ba09b00 commit bc09c53

File tree

6 files changed

+47
-89
lines changed

6 files changed

+47
-89
lines changed

package-lock.json

Lines changed: 13 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
"dependencies": {
66
"@oclif/core": "^4.2.4",
77
"@salesforce/core": "^8.8.2",
8-
"@salesforce/sf-plugins-core": "^12.1.2",
8+
"@salesforce/sf-plugins-core": "^12.1.3",
99
"chalk": "^5.4.1",
1010
"cosmiconfig": "^9.0.0",
11-
"fs-extra": "^11.3.0",
1211
"glob": "^11.0.1",
13-
"lightning-flow-scanner-core": "4.11.0",
14-
"tslib": "^2",
15-
"xml2js": "^0.6.2"
12+
"lightning-flow-scanner-core": "^4.13.0"
1613
},
1714
"devDependencies": {
18-
"@oclif/plugin-help": "^6.2.22",
15+
"@oclif/plugin-help": "^6.2.23",
1916
"@oclif/test": "^4.1.8",
2017
"@salesforce/dev-config": "^4.3.1",
2118
"@salesforce/ts-sinon": "^1.4.30",

src/commands/flow/scan.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { SfCommand, Flags } from "@salesforce/sf-plugins-core";
22
import { Messages, SfError } from "@salesforce/core";
3-
import * as core from "lightning-flow-scanner-core";
4-
import * as fse from "fs-extra";
53
import chalk from "chalk";
64
import { exec } from "child_process";
75

86
import { loadScannerOptions } from "../../libs/ScannerConfig.js";
97
import { FindFlows } from "../../libs/FindFlows.js";
108
import { ScanResult } from "../../models/ScanResult.js";
119

10+
import {
11+
parse,
12+
ParsedFlow,
13+
scan,
14+
RuleResult,
15+
ResultDetails,
16+
ScanResult as scanResults,
17+
} from "lightning-flow-scanner-core";
18+
1219
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1320

1421
const messages = Messages.loadMessages("lightning-flow-scanner", "command");
@@ -21,6 +28,7 @@ export default class Scan extends SfCommand<ScanResult> {
2128
"sf flow scan -c path/to/config.json",
2229
"sf flow scan -c path/to/config.json --failon warning",
2330
"sf flow scan -d path/to/flows/directory",
31+
"sf flow scan -p path/to/single/file.flow-meta.xml",
2432
];
2533

2634
protected static requiresUsername = false;
@@ -56,10 +64,13 @@ export default class Scan extends SfCommand<ScanResult> {
5664
description: "Force retrieve Flows from org at the start of the command",
5765
default: false,
5866
}),
59-
sourcepath: Flags.directory({
67+
sourcepath: Flags.file({
6068
char: "p",
6169
description: "Comma-separated list of source flow paths to scan",
6270
required: false,
71+
aliases: ["files"],
72+
multiple: true,
73+
exists: true,
6374
}),
6475
targetusername: Flags.string({
6576
char: "u",
@@ -82,14 +93,15 @@ export default class Scan extends SfCommand<ScanResult> {
8293
this.spinner.start(`Identified ${flowFiles.length} flows to scan`);
8394
// to
8495
// core.Flow
85-
const parsedFlows = await core.parse(flowFiles);
96+
const parsedFlows: ParsedFlow[] = await parse(flowFiles);
97+
this.debug(`parsed flows ${parsedFlows.length}`, ...parsedFlows);
8698

87-
const scanResults: core.ScanResult[] =
99+
const scanResults: scanResults[] =
88100
this.userConfig && Object.keys(this.userConfig).length > 0
89-
? core.scan(parsedFlows, this.userConfig)
90-
: core.scan(parsedFlows);
101+
? scan(parsedFlows, this.userConfig)
102+
: scan(parsedFlows);
91103

92-
this.debug("scan results", ...scanResults);
104+
this.debug(`scan results: ${scanResults.length}`, ...scanResults);
93105
this.spinner.stop(`Scan complete`);
94106
this.log("");
95107

@@ -175,7 +187,7 @@ export default class Scan extends SfCommand<ScanResult> {
175187
return { summary, status: status, results };
176188
}
177189

178-
private findFlows(directory: string, sourcepath: string) {
190+
private findFlows(directory: string, sourcepath: string[]) {
179191
// List flows that will be scanned
180192
let flowFiles;
181193
if (directory && sourcepath) {
@@ -186,7 +198,7 @@ export default class Scan extends SfCommand<ScanResult> {
186198
} else if (directory) {
187199
flowFiles = FindFlows(directory);
188200
} else if (sourcepath) {
189-
flowFiles = sourcepath.split(",").filter((f) => fse.exists(f));
201+
flowFiles = sourcepath;
190202
} else {
191203
flowFiles = FindFlows(".");
192204
}
@@ -222,7 +234,7 @@ export default class Scan extends SfCommand<ScanResult> {
222234
for (const scanResult of scanResults) {
223235
const flowName = scanResult.flow.label;
224236
const flowType = scanResult.flow.type[0];
225-
for (const ruleResult of scanResult.ruleResults as core.RuleResult[]) {
237+
for (const ruleResult of scanResult.ruleResults as RuleResult[]) {
226238
const ruleDescription = ruleResult.ruleDefinition.description;
227239
const rule = ruleResult.ruleDefinition.label;
228240
if (
@@ -231,7 +243,7 @@ export default class Scan extends SfCommand<ScanResult> {
231243
ruleResult.details.length > 0
232244
) {
233245
const severity = ruleResult.severity || "error";
234-
for (const result of ruleResult.details as core.ResultDetails[]) {
246+
for (const result of ruleResult.details as ResultDetails[]) {
235247
const detailObj = Object.assign(result, {
236248
ruleDescription,
237249
rule,

src/libs/CoreFixService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
scan,
55
ScanResult as ScanResults,
66
} from "lightning-flow-scanner-core";
7-
import { IRulesConfig } from "lightning-flow-scanner-core/main/interfaces/IRulesConfig.js";
7+
import IRulesConfig from "lightning-flow-scanner-core/main/interfaces/IRulesConfig.js";
88
import { writeFileSync } from "node:fs";
99

1010
import { FindFlows } from "./FindFlows.js";

src/libs/XMLParser.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/commands/flow/scan.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ describe("flow:scan", () => {
1818
let output: ScanResult;
1919
try {
2020
const output = await new Scan(
21-
["--directory", "test/", "--sourcepath", "test/"],
21+
[
22+
"--directory",
23+
"test/",
24+
"--sourcepath",
25+
"test/commands/flow/scan.test.ts",
26+
],
2227
config,
2328
).run();
2429
console.log(output);

0 commit comments

Comments
 (0)