diff --git a/package.json b/package.json index 55e9b85..374cb8a 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "clean:test": "premove coverage", "build:js": "npm run clean:build && tsc", "build": "npm run lint && npm run build:js", - "lint": "eslint src", + "lint": "prettier --check src && eslint src", "format": "prettier --write src", "test": "npm run build:js && npm run clean:test && c8 node --test", "prepublishOnly": "npm run test" diff --git a/src/main.ts b/src/main.ts index 61318d9..056def5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -32,9 +32,7 @@ export async function run(): Promise { const tasks = await cl.multiselect({ message: 'What would you like to do?', - initialValues: [ - 'module-replacements' - ], + initialValues: ['module-replacements'], options: [ { label: 'Scan for module replacements', diff --git a/src/stages/scan-files.ts b/src/stages/scan-files.ts index 8ba9a66..bd619b8 100644 --- a/src/stages/scan-files.ts +++ b/src/stages/scan-files.ts @@ -12,14 +12,10 @@ async function scanFile( contents: string, lines: string[], replacements: modReplacements.ModuleReplacement[] -): Promise { +): Promise { const ast = sg.parse(contents); const root = ast.root(); - const result: FileReplacement = { - path: filePath, - contents, - replacements: [] - }; + const matches: modReplacements.ModuleReplacement[] = []; for (const replacement of replacements) { const imports = root.findAll({ @@ -42,7 +38,7 @@ async function scanFile( }); if (imports.length > 0) { - result.replacements.push(replacement); + matches.push(replacement); } for (const node of imports) { @@ -73,7 +69,15 @@ async function scanFile( } } - return result; + if (matches.length === 0) { + return null; + } + + return { + path: filePath, + contents, + replacements: matches + }; } export async function scanFiles( @@ -90,7 +94,11 @@ export async function scanFiles( spinner.message(`Scanning ${file}`); - results.push(await scanFile(file, contents, lines, replacements)); + const scanResult = await scanFile(file, contents, lines, replacements); + + if (scanResult) { + results.push(scanResult); + } } catch (err) { cl.log.error(dedent` Could not read file ${file}: