From 1be135cd4f9de1e08d55df766102c2417daa4c8a Mon Sep 17 00:00:00 2001 From: junners Date: Sun, 26 Jan 2025 23:38:06 -0800 Subject: [PATCH] feat: use swc compiled core package --- .gitignore | 1 + package-lock.json | 8 ++++---- package.json | 2 +- src/commands/flow/fix.ts | 12 ++++++------ src/commands/flow/scan.ts | 18 ++++++++---------- src/libs/CoreFixService.ts | 17 ++++++++--------- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index ce1c93b..af0df8a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ coverage/** .yarn/install-state.gz oclif.manifest.json *.log +*.tgz \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bf50f66..3e42f31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "chalk": "^5.4.1", "cosmiconfig": "^9.0.0", "glob": "^11.0.1", - "lightning-flow-scanner-core": "4.14.0" + "lightning-flow-scanner-core": "4.15.0" }, "devDependencies": { "@oclif/plugin-help": "^6.2.23", @@ -8575,9 +8575,9 @@ } }, "node_modules/lightning-flow-scanner-core": { - "version": "4.14.0", - "resolved": "https://registry.npmjs.org/lightning-flow-scanner-core/-/lightning-flow-scanner-core-4.14.0.tgz", - "integrity": "sha512-U81L1NN2QQB8LA1cKvKIoxopFQNj9sKHdJXM6QCB43sxHYLiyC6J7J95z6A7cd+ebE3MUil6E04Qy6Pqx2o0tw==", + "version": "4.15.0", + "resolved": "https://registry.npmjs.org/lightning-flow-scanner-core/-/lightning-flow-scanner-core-4.15.0.tgz", + "integrity": "sha512-hQX/Cgy4LUfuqfww37wz3rKTxJrESe9pjrjx/K4rpin0GkrMNNiiq3r50BBGG8gIwP1ZvrOvgJC5Gu3r5+y4Ww==", "license": "MIT", "dependencies": { "path-browserify": "^1.0.1", diff --git a/package.json b/package.json index a20dd66..7621833 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "chalk": "^5.4.1", "cosmiconfig": "^9.0.0", "glob": "^11.0.1", - "lightning-flow-scanner-core": "4.14.0" + "lightning-flow-scanner-core": "4.15.0" }, "devDependencies": { "@oclif/plugin-help": "^6.2.23", diff --git a/src/commands/flow/fix.ts b/src/commands/flow/fix.ts index 93d5ebd..c81adca 100644 --- a/src/commands/flow/fix.ts +++ b/src/commands/flow/fix.ts @@ -28,9 +28,9 @@ export default class FlowFix extends SfCommand { char: "d", multiple: true, description: commandMessages.getMessage("flagsDirsDescription"), - exclusive: ["file"], + exclusive: ["files"], }), - file: Flags.file({ + files: Flags.file({ exists: true, multiple: true, description: commandMessages.getMessage("flagsFilesDescription"), @@ -41,8 +41,8 @@ export default class FlowFix extends SfCommand { public async run(): Promise { const { flags } = await this.parse(FlowFix); - const { dir, file, rules } = flags; - if (!dir && !file) { + const { dir, files, rules } = flags; + if (!dir && !files) { throw new SfError( commandMessages.getMessage("errorMutuallyExclusiveRequired"), ); @@ -52,11 +52,11 @@ export default class FlowFix extends SfCommand { stdout: true, }); - const fixService = new CoreFixService(dir, file, rules); + const fixService = new CoreFixService(dir, files, rules); const outMessage = (await fixService.fix()).join(", "); - console.log(`test`, outMessage); + this.debug(`test`, outMessage); this.spinner.stop(`Fix Complete.. Fixed ${outMessage}`); diff --git a/src/commands/flow/scan.ts b/src/commands/flow/scan.ts index a7fb970..15493a9 100644 --- a/src/commands/flow/scan.ts +++ b/src/commands/flow/scan.ts @@ -7,15 +7,13 @@ import { loadScannerOptions } from "../../libs/ScannerConfig.js"; import { FindFlows } from "../../libs/FindFlows.js"; import { ScanResult } from "../../models/ScanResult.js"; -import { - parse, - scan, +import pkg, { + ScanResult as ScanResults, RuleResult, ResultDetails, - ScanResult as scanResults, } from "lightning-flow-scanner-core"; - -import { ParsedFlow } from "lightning-flow-scanner-core/main/models/ParsedFlow.js"; +const { parse: parseFlows, scan: scanFlows } = pkg; +import type { ParsedFlow } from "lightning-flow-scanner-core/main/models/ParsedFlow.js"; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); @@ -94,13 +92,13 @@ export default class Scan extends SfCommand { this.spinner.start(`Identified ${flowFiles.length} flows to scan`); // to // core.Flow - const parsedFlows: ParsedFlow[] = await parse(flowFiles); + const parsedFlows: ParsedFlow[] = await parseFlows(flowFiles); this.debug(`parsed flows ${parsedFlows.length}`, ...parsedFlows); - const scanResults: scanResults[] = + const scanResults: ScanResults[] = this.userConfig && Object.keys(this.userConfig).length > 0 - ? scan(parsedFlows, this.userConfig) - : scan(parsedFlows); + ? scanFlows(parsedFlows, this.userConfig) + : scanFlows(parsedFlows); this.debug(`scan results: ${scanResults.length}`, ...scanResults); this.spinner.stop(`Scan complete`); diff --git a/src/libs/CoreFixService.ts b/src/libs/CoreFixService.ts index 664c510..b47cc08 100644 --- a/src/libs/CoreFixService.ts +++ b/src/libs/CoreFixService.ts @@ -1,14 +1,13 @@ -import { - fix, - parse, - scan, - ScanResult as ScanResults, -} from "lightning-flow-scanner-core"; import { IRulesConfig } from "lightning-flow-scanner-core/main/internals/internals.js"; import { writeFileSync } from "node:fs"; import { FindFlows } from "./FindFlows.js"; +import pkg from "lightning-flow-scanner-core"; +const { fix: fixFlows, parse: parseFlows, scan: scanFlows } = pkg; + +import type { ScanResult as FlowScanResults } from "lightning-flow-scanner-core"; + export default class CoreFixService { public constructor( private readonly dir, @@ -24,7 +23,7 @@ export default class CoreFixService { } else { flowFiles = this.findFlowsByPath(this.file); } - const parsedFlows = await parse(flowFiles); + const parsedFlows = await parseFlows(flowFiles); // make on the fly rule const flatRules = this.rules @@ -40,10 +39,10 @@ export default class CoreFixService { ) as IRulesConfig; // scan - const scanResults: ScanResults[] = scan(parsedFlows, flatRules); + const scanResults: FlowScanResults[] = scanFlows(parsedFlows, flatRules); // fix - const fixFlow: ScanResults[] = fix(scanResults); + const fixFlow: FlowScanResults[] = fixFlows(scanResults); fixFlow.forEach((fixedObject) => { writeFileSync(fixedObject.flow.fsPath, fixedObject.flow.toXMLString()); });