From 08e11e74765666bf0691f7fb4765ee278e36663e Mon Sep 17 00:00:00 2001 From: Edward Ezekiel Date: Fri, 25 Apr 2025 13:48:13 -0500 Subject: [PATCH 1/3] feat: run `scan eol -t` by default When the user provides no arguments to the cli, by default it should run `scan eol-t`. --- bin/dev.js | 8 ++++++++ bin/run.js | 8 ++++++++ e2e/scan/eol.test.ts | 35 +++++++++++++++++++++++++++++++---- package.json | 2 +- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/bin/dev.js b/bin/dev.js index c2674f17..1c76f5aa 100755 --- a/bin/dev.js +++ b/bin/dev.js @@ -11,4 +11,12 @@ process.env.GRAPHQL_HOST = 'https://api.dev.nes.herodevs.com'; // Prod // process.env.GRAPHQL_HOST = 'https://api.nes.herodevs.com'; +// If no command is provided, default to scan:eol -t +// See https://github.com/oclif/oclif/issues/277#issuecomment-657352674 for more info +// There is no canonical way to do this, so we're using a hacky solution +if (process.argv.length === 2) { + process.argv[2] = 'scan:eol'; + process.argv[3] = '-t'; +} + await execute({ development: true, dir: import.meta.url }); diff --git a/bin/run.js b/bin/run.js index 176d2af5..a5c2cab1 100755 --- a/bin/run.js +++ b/bin/run.js @@ -2,4 +2,12 @@ import { execute } from '@oclif/core'; +// If no command is provided, default to scan:eol -t +// See https://github.com/oclif/oclif/issues/277#issuecomment-657352674 for more info +// There is no canonical way to do this, so we're using a hacky solution +if (process.argv.length === 2) { + process.argv[2] = 'scan:eol'; + process.argv[3] = '-t'; +} + await execute({ dir: import.meta.url }); diff --git a/e2e/scan/eol.test.ts b/e2e/scan/eol.test.ts index 4526d0a9..e526afc6 100644 --- a/e2e/scan/eol.test.ts +++ b/e2e/scan/eol.test.ts @@ -1,11 +1,17 @@ +import { runCommand } from '@oclif/test'; import { doesNotThrow } from 'node:assert'; import { doesNotMatch, match, strictEqual } from 'node:assert/strict'; +import { exec } from 'node:child_process'; import { existsSync, readFileSync, unlinkSync } from 'node:fs'; import { mkdir } from 'node:fs/promises'; import path from 'node:path'; import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; -import { runCommand } from '@oclif/test'; +import { promisify } from 'node:util'; + +const execAsync = promisify(exec); + +const GRAPHQL_HOST = 'https://api.dev.nes.herodevs.com'; describe('scan:eol e2e', () => { const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -20,8 +26,7 @@ describe('scan:eol e2e', () => { async function run(cmd: string) { // Set up environment - process.env.GRAPHQL_HOST = 'https://api.dev.nes.herodevs.com'; - // process.env.GRAPHQL_HOST = 'http://localhost:3000'; + process.env.GRAPHQL_HOST = GRAPHQL_HOST; // Ensure fixtures directory exists and is clean await mkdir(fixturesDir, { recursive: true }); @@ -40,6 +45,28 @@ describe('scan:eol e2e', () => { return output; } + it('defaults to scan:eol -t when no arguments are provided', async () => { + // Run the CLI directly with no arguments + const { stdout } = await execAsync('node bin/run.js', { + env: { ...process.env, GRAPHQL_HOST }, + }); + + // Match table header + match(stdout, /┌.*┬.*┬.*┬.*┬.*┐/, 'Should show table top border'); + match(stdout, /│ NAME\s*│ VERSION\s*│ EOL\s*│ DAYS EOL\s*│ TYPE\s*│ # OF VULNS*|/, 'Should show table headers'); + match(stdout, /├.*┼.*┼.*┼.*┼.*┤/, 'Should show table header separator'); + + // Match table content + match( + stdout, + /│ bootstrap\s*│ 3\.1\.1\s*│ 2019-07-24\s*│ \d+\s*│ npm\s*│/, + 'Should show bootstrap package in table', + ); + + // Match table footer + match(stdout, /└.*┴.*┴.*┴.*┴.*┘/, 'Should show table bottom border'); + }); + it('scans existing SBOM for EOL components', async () => { const cmd = `scan:eol --file ${simpleSbom}`; const { stdout } = await run(cmd); @@ -193,7 +220,7 @@ describe('scan:eol e2e directory', () => { async function run(cmd: string) { // Set up environment - process.env.GRAPHQL_HOST = 'https://api.dev.nes.herodevs.com'; + process.env.GRAPHQL_HOST = GRAPHQL_HOST; // process.env.GRAPHQL_HOST = 'http://localhost:3000'; // Ensure test directory exists and is clean diff --git a/package.json b/package.json index 7821ff6e..8ceab031 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "@oclif/plugin-update" ], "hooks": { - "init": "./dist/hooks/npm-update-notifier", + "init": "./dist/hooks/npm-update-notifier.js", "prerun": "./dist/hooks/prerun.js" }, "topicSeparator": " ", From 5e636793cf95853a7f1f800ed446d069f4a62db0 Mon Sep 17 00:00:00 2001 From: Edward Ezekiel Date: Fri, 25 Apr 2025 14:07:09 -0500 Subject: [PATCH 2/3] chore: update based on pr feedback --- bin/dev.js | 1 - bin/run.js | 1 - 2 files changed, 2 deletions(-) diff --git a/bin/dev.js b/bin/dev.js index 1c76f5aa..80b056e2 100755 --- a/bin/dev.js +++ b/bin/dev.js @@ -13,7 +13,6 @@ process.env.GRAPHQL_HOST = 'https://api.dev.nes.herodevs.com'; // If no command is provided, default to scan:eol -t // See https://github.com/oclif/oclif/issues/277#issuecomment-657352674 for more info -// There is no canonical way to do this, so we're using a hacky solution if (process.argv.length === 2) { process.argv[2] = 'scan:eol'; process.argv[3] = '-t'; diff --git a/bin/run.js b/bin/run.js index a5c2cab1..9d90bd7c 100755 --- a/bin/run.js +++ b/bin/run.js @@ -4,7 +4,6 @@ import { execute } from '@oclif/core'; // If no command is provided, default to scan:eol -t // See https://github.com/oclif/oclif/issues/277#issuecomment-657352674 for more info -// There is no canonical way to do this, so we're using a hacky solution if (process.argv.length === 2) { process.argv[2] = 'scan:eol'; process.argv[3] = '-t'; From 7d2507c9d7880c6fe04daa234d3d1927854ad06e Mon Sep 17 00:00:00 2001 From: Edward Ezekiel Date: Fri, 25 Apr 2025 14:08:17 -0500 Subject: [PATCH 3/3] chore: run linting --- e2e/scan/eol.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/scan/eol.test.ts b/e2e/scan/eol.test.ts index e526afc6..dd13e4f7 100644 --- a/e2e/scan/eol.test.ts +++ b/e2e/scan/eol.test.ts @@ -1,4 +1,3 @@ -import { runCommand } from '@oclif/test'; import { doesNotThrow } from 'node:assert'; import { doesNotMatch, match, strictEqual } from 'node:assert/strict'; import { exec } from 'node:child_process'; @@ -8,6 +7,7 @@ import path from 'node:path'; import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; import { promisify } from 'node:util'; +import { runCommand } from '@oclif/test'; const execAsync = promisify(exec);