diff --git a/package-lock.json b/package-lock.json index d85de6718..a09e4a0df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2373,51 +2373,6 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, - "node_modules/@esbuild/android-arm": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.19.tgz", - "integrity": "sha512-rIKddzqhmav7MSmoFCmDIb6e2W57geRsM94gV2l38fzhXMwq7hZoClug9USI2pFRGL06f4IOPHHpFNOkWieR8A==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-arm64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.19.tgz", - "integrity": "sha512-KBMWvEZooR7+kzY0BtbTQn0OAYY7CsiydT63pVEaPtVYF0hXbUaOyZog37DKxK7NF3XacBJOpYT4adIJh+avxA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.19.tgz", - "integrity": "sha512-uUTTc4xGNDT7YSArp/zbtmbhO0uEEK9/ETW29Wk1thYUJBz3IVnvgEiEwEa9IeLyvnpKrWK64Utw2bgUmDveww==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/@esbuild/darwin-arm64": { "version": "0.19.4", "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.4.tgz", @@ -2433,276 +2388,6 @@ "node": ">=12" } }, - "node_modules/@esbuild/darwin-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.19.tgz", - "integrity": "sha512-IJM4JJsLhRYr9xdtLytPLSH9k/oxR3boaUIYiHkAawtwNOXKE8KoU8tMvryogdcT8AU+Bflmh81Xn6Q0vTZbQw==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-arm64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.19.tgz", - "integrity": "sha512-pBwbc7DufluUeGdjSU5Si+P3SoMF5DQ/F/UmTSb8HXO80ZEAJmrykPyzo1IfNbAoaqw48YRpv8shwd1NoI0jcQ==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.19.tgz", - "integrity": "sha512-4lu+n8Wk0XlajEhbEffdy2xy53dpR06SlzvhGByyg36qJw6Kpfk7cp45DR/62aPH9mtJRmIyrXAS5UWBrJT6TQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.19.tgz", - "integrity": "sha512-cdmT3KxjlOQ/gZ2cjfrQOtmhG4HJs6hhvm3mWSRDPtZ/lP5oe8FWceS10JaSJC13GBd4eH/haHnqf7hhGNLerA==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.19.tgz", - "integrity": "sha512-ct1Tg3WGwd3P+oZYqic+YZF4snNl2bsnMKRkb3ozHmnM0dGWuxcPTTntAF6bOP0Sp4x0PjSF+4uHQ1xvxfRKqg==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ia32": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.19.tgz", - "integrity": "sha512-w4IRhSy1VbsNxHRQpeGCHEmibqdTUx61Vc38APcsRbuVgK0OPEnQ0YD39Brymn96mOx48Y2laBQGqgZ0j9w6SQ==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-loong64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.19.tgz", - "integrity": "sha512-2iAngUbBPMq439a+z//gE+9WBldoMp1s5GWsUSgqHLzLJ9WoZLZhpwWuym0u0u/4XmZ3gpHmzV84PonE+9IIdQ==", - "cpu": [ - "loong64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-mips64el": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.19.tgz", - "integrity": "sha512-LKJltc4LVdMKHsrFe4MGNPp0hqDFA1Wpt3jE1gEyM3nKUvOiO//9PheZZHfYRfYl6AwdTH4aTcXSqBerX0ml4A==", - "cpu": [ - "mips64el" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ppc64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.19.tgz", - "integrity": "sha512-/c/DGybs95WXNS8y3Ti/ytqETiW7EU44MEKuCAcpPto3YjQbyK3IQVKfF6nbghD7EcLUGl0NbiL5Rt5DMhn5tg==", - "cpu": [ - "ppc64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-riscv64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.19.tgz", - "integrity": "sha512-FC3nUAWhvFoutlhAkgHf8f5HwFWUL6bYdvLc/TTuxKlvLi3+pPzdZiFKSWz/PF30TB1K19SuCxDTI5KcqASJqA==", - "cpu": [ - "riscv64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-s390x": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.19.tgz", - "integrity": "sha512-IbFsFbxMWLuKEbH+7sTkKzL6NJmG2vRyy6K7JJo55w+8xDk7RElYn6xvXtDW8HCfoKBFK69f3pgBJSUSQPr+4Q==", - "cpu": [ - "s390x" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.19.tgz", - "integrity": "sha512-68ngA9lg2H6zkZcyp22tsVt38mlhWde8l3eJLWkyLrp4HwMUr3c1s/M2t7+kHIhvMjglIBrFpncX1SzMckomGw==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/netbsd-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.19.tgz", - "integrity": "sha512-CwFq42rXCR8TYIjIfpXCbRX0rp1jo6cPIUPSaWwzbVI4aOfX96OXY8M6KNmtPcg7QjYeDmN+DD0Wp3LaBOLf4Q==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/openbsd-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.19.tgz", - "integrity": "sha512-cnq5brJYrSZ2CF6c35eCmviIN3k3RczmHz8eYaVlNasVqsNY+JKohZU5MKmaOI+KkllCdzOKKdPs762VCPC20g==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/sunos-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.19.tgz", - "integrity": "sha512-vCRT7yP3zX+bKWFeP/zdS6SqdWB8OIpaRq/mbXQxTGHnIxspRtigpkUcDMlSCOejlHowLqII7K2JKevwyRP2rg==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-arm64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.19.tgz", - "integrity": "sha512-yYx+8jwowUstVdorcMdNlzklLYhPxjniHWFKgRqH7IFlUEa0Umu3KuYplf1HUZZ422e3NU9F4LGb+4O0Kdcaag==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-ia32": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.19.tgz", - "integrity": "sha512-eggDKanJszUtCdlVs0RB+h35wNlb5v4TWEkq4vZcmVt5u/HiDZrTXe2bWFQUez3RgNHwx/x4sk5++4NSSicKkw==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-x64": { - "version": "0.17.19", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.19.tgz", - "integrity": "sha512-lAhycmKnVOuRYNtRtatQR1LPQf2oYCkRGkSFnseDAKPl8lu5SOsK/e1sXe5a0Pc5kHIHe6P2I/ilntNv2xf3cA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "dev": true, diff --git a/packages/cli/package.json b/packages/cli/package.json index 794adb842..0730e2728 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -8,8 +8,8 @@ "bundle-require": "^4.0.1", "chalk": "^5.3.0", "yargs": "^17.7.2", - "@quality-metrics/models": "^0.0.1", - "@quality-metrics/utils": "^0.0.1", - "zod": "^3.22.1" + "@quality-metrics/models": "*", + "zod": "^3.22.1", + "@quality-metrics-cli/core": "*" } } diff --git a/packages/cli/src/lib/cli.spec.ts b/packages/cli/src/lib/cli.spec.ts index 5de704138..242363c85 100644 --- a/packages/cli/src/lib/cli.spec.ts +++ b/packages/cli/src/lib/cli.spec.ts @@ -3,9 +3,9 @@ import { describe, expect, it } from 'vitest'; import { yargsCli } from './cli'; import { middlewares } from './middlewares'; import { options as defaultOptions } from './options'; -import { CollectOptions } from '@quality-metrics/utils'; -import { GlobalOptions } from './model'; +import { CollectOptions } from '@quality-metrics/core'; import { getDirname } from './implementation/helper.mock'; +import { GlobalOptions } from './model'; const __dirname = getDirname(import.meta.url); const withDirName = (path: string) => join(__dirname, path); diff --git a/packages/cli/src/lib/collect/command-object.spec.ts b/packages/cli/src/lib/collect/command-object.spec.ts index 8fd3be134..5e714c29d 100644 --- a/packages/cli/src/lib/collect/command-object.spec.ts +++ b/packages/cli/src/lib/collect/command-object.spec.ts @@ -1,6 +1,6 @@ import { Report } from '@quality-metrics/models'; import { dummyConfig } from '@quality-metrics/models/testing'; -import { CollectOptions } from '@quality-metrics/utils'; +import { CollectOptions } from '@quality-metrics/core'; import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import { yargsCli } from '../cli'; diff --git a/packages/cli/src/lib/implementation/collect-and-persist.ts b/packages/cli/src/lib/implementation/collect-and-persist.ts index 4b987a2be..186df9139 100644 --- a/packages/cli/src/lib/implementation/collect-and-persist.ts +++ b/packages/cli/src/lib/implementation/collect-and-persist.ts @@ -1,10 +1,9 @@ import { collect, CollectOptions, - CollectOutputError, logPersistedResults, persistReport, -} from '@quality-metrics/utils'; +} from '@quality-metrics/core'; import { pluginOutputSchema, Report } from '@quality-metrics/models'; import * as packageJson from '../../../package.json'; @@ -29,7 +28,7 @@ export async function collectAndPersistReports( // Running checks after persisting helps while debugging as you can check the invalid output after the error pluginOutputSchema.parse(plugin); } catch (e) { - throw new CollectOutputError(plugin.slug, e as Error); + throw new Error(`${plugin.slug} - ${(e as Error).message}`); } }); } diff --git a/packages/cli/src/lib/implementation/config-middleware.ts b/packages/cli/src/lib/implementation/config-middleware.ts index 53c83b3fb..103fda1d8 100644 --- a/packages/cli/src/lib/implementation/config-middleware.ts +++ b/packages/cli/src/lib/implementation/config-middleware.ts @@ -1,4 +1,4 @@ -import { GlobalOptions, globalOptionsSchema } from '../model'; +import { GlobalOptions, globalOptionsSchema } from '@quality-metrics/models'; import { readCodePushupConfig } from './read-code-pushup-config'; export class ConfigParseError extends Error { diff --git a/packages/core/package.json b/packages/core/package.json index 2e9075dbb..60f0d023a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,7 +1,11 @@ { "name": "@quality-metrics-cli/core", "version": "0.0.1", - "dependencies": {}, + "dependencies": { + "@quality-metrics/models": "*", + "@quality-metrics/utils": "*", + "chalk": "^5.3.0" + }, "type": "commonjs", "main": "./index.cjs" } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index e87855f47..813f9f6cd 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1 +1,3 @@ -export * from './lib/core'; +export { logPersistedResults, persistReport } from './lib/persist'; +export { executePlugins } from './lib/execute-plugin'; +export { collect, CollectOptions } from './lib/collect'; diff --git a/packages/utils/src/lib/collect/index.ts b/packages/core/src/lib/collect.ts similarity index 89% rename from packages/utils/src/lib/collect/index.ts rename to packages/core/src/lib/collect.ts index 4675b1773..c2f7e885f 100644 --- a/packages/utils/src/lib/collect/index.ts +++ b/packages/core/src/lib/collect.ts @@ -1,6 +1,6 @@ import { CoreConfig, GlobalOptions, Report } from '@quality-metrics/models'; -import { executePlugins } from './implementation/execute-plugin'; -import { calcDuration } from './implementation/utils'; +import { executePlugins } from './execute-plugin'; +import { calcDuration } from '@quality-metrics/utils'; /** * Error thrown when collect output is invalid. diff --git a/packages/core/src/lib/core.spec.ts b/packages/core/src/lib/core.spec.ts deleted file mode 100644 index 290f5f766..000000000 --- a/packages/core/src/lib/core.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { core } from './core'; - -describe('core', () => { - it('should work', () => { - expect(core()).toEqual('core'); - }); -}); diff --git a/packages/core/src/lib/core.ts b/packages/core/src/lib/core.ts deleted file mode 100644 index 54913edb0..000000000 --- a/packages/core/src/lib/core.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function core(): string { - return 'core'; -} diff --git a/packages/utils/src/lib/collect/implementation/execute-plugin.spec.ts b/packages/core/src/lib/execute-plugin.spec.ts similarity index 100% rename from packages/utils/src/lib/collect/implementation/execute-plugin.spec.ts rename to packages/core/src/lib/execute-plugin.spec.ts diff --git a/packages/utils/src/lib/collect/implementation/execute-plugin.ts b/packages/core/src/lib/execute-plugin.ts similarity index 97% rename from packages/utils/src/lib/collect/implementation/execute-plugin.ts rename to packages/core/src/lib/execute-plugin.ts index cbea4daef..0067da88c 100644 --- a/packages/utils/src/lib/collect/implementation/execute-plugin.ts +++ b/packages/core/src/lib/execute-plugin.ts @@ -5,7 +5,7 @@ import { } from '@quality-metrics/models'; import { readFile } from 'fs/promises'; import { join } from 'path'; -import { executeProcess, ProcessObserver } from './execute-process'; +import { executeProcess, ProcessObserver } from '@quality-metrics/utils'; /** * Error thrown when plugin output is invalid. diff --git a/packages/utils/src/lib/collect/index.spec.ts b/packages/core/src/lib/index.spec.ts similarity index 90% rename from packages/utils/src/lib/collect/index.spec.ts rename to packages/core/src/lib/index.spec.ts index 82174f260..c1f886b64 100644 --- a/packages/utils/src/lib/collect/index.spec.ts +++ b/packages/core/src/lib/index.spec.ts @@ -1,7 +1,7 @@ import { reportSchema } from '@quality-metrics/models'; import { mockCoreConfig } from '@quality-metrics/models/testing'; import { describe, expect, it } from 'vitest'; -import { CollectOptions, collect } from '../collect/'; +import { CollectOptions, collect } from './collect'; const baseOptions: CollectOptions = { ...mockCoreConfig(), diff --git a/packages/utils/src/lib/collect/implementation/persist.spec.ts b/packages/core/src/lib/persist.spec.ts similarity index 98% rename from packages/utils/src/lib/collect/implementation/persist.spec.ts rename to packages/core/src/lib/persist.spec.ts index 9b521cd1c..f636a5a27 100644 --- a/packages/utils/src/lib/collect/implementation/persist.spec.ts +++ b/packages/core/src/lib/persist.spec.ts @@ -10,7 +10,7 @@ import { } from '@quality-metrics/models/testing'; import { vol } from 'memfs'; import { join } from 'path'; -import { mockConsole, unmockConsole } from './mock/helper.mock'; +import { mockConsole, unmockConsole } from '../../test/console.mock'; vi.mock('fs', async () => { const memfs: typeof import('memfs') = await vi.importActual('memfs'); diff --git a/packages/utils/src/lib/collect/implementation/persist.ts b/packages/core/src/lib/persist.ts similarity index 95% rename from packages/utils/src/lib/collect/implementation/persist.ts rename to packages/core/src/lib/persist.ts index 3cc7a5d94..9855bd422 100644 --- a/packages/utils/src/lib/collect/implementation/persist.ts +++ b/packages/core/src/lib/persist.ts @@ -3,9 +3,11 @@ import { writeFile, stat } from 'fs/promises'; import { join } from 'path'; import chalk from 'chalk'; import { CoreConfig, Report } from '@quality-metrics/models'; -import { formatBytes } from './utils'; -import { reportToStdout } from './report-to-stdout'; -import { reportToMd } from './report-to-md'; +import { + formatBytes, + reportToStdout, + reportToMd, +} from '@quality-metrics/utils'; export class PersistDirError extends Error { constructor(outputPath: string) { diff --git a/packages/core/test/console.mock.ts b/packages/core/test/console.mock.ts new file mode 100644 index 000000000..5ba95a061 --- /dev/null +++ b/packages/core/test/console.mock.ts @@ -0,0 +1,17 @@ +import { vi } from 'vitest'; + +const _log = console.log; +let mocked = false; +export function mockConsole( + log: (...args: string[]) => void = (..._: string[]) => { + void 0; + }, +) { + console.log = vi.fn(log); + mocked = true; +} + +export function unmockConsole() { + console.log = _log; + mocked = false; +} diff --git a/packages/nx-plugin/package.json b/packages/nx-plugin/package.json index 8d7793fba..a6b215409 100644 --- a/packages/nx-plugin/package.json +++ b/packages/nx-plugin/package.json @@ -2,8 +2,8 @@ "name": "@quality-metrics/nx-plugin", "version": "0.0.1", "dependencies": { - "@nx/devkit": "16.8.1", - "tslib": "^2.3.0" + "@nx/devkit": "^16.8.1", + "tslib": "2.6.2" }, "type": "commonjs", "main": "./src/index.js", diff --git a/packages/plugin-eslint/package.json b/packages/plugin-eslint/package.json index 0bff42787..894086121 100644 --- a/packages/plugin-eslint/package.json +++ b/packages/plugin-eslint/package.json @@ -2,7 +2,8 @@ "name": "@quality-metrics/eslint-plugin", "version": "0.0.1", "dependencies": { - "eslint": "~8.46.0", - "@quality-metrics/models": ">=0.0.1" + "@quality-metrics/models": "*", + "@quality-metrics/utils": "*", + "eslint": "~8.46.0" } } diff --git a/packages/plugin-eslint/src/lib/eslint-plugin.ts b/packages/plugin-eslint/src/lib/eslint-plugin.ts index 8d4807578..be5c772d9 100644 --- a/packages/plugin-eslint/src/lib/eslint-plugin.ts +++ b/packages/plugin-eslint/src/lib/eslint-plugin.ts @@ -1,4 +1,5 @@ import { AuditOutputs, PluginConfig } from '@quality-metrics/models'; +import { objectToCliArgs } from '@quality-metrics/utils'; import * as eslint from 'eslint'; type ESLintPluginConfig = { @@ -18,9 +19,8 @@ export function eslintPlugin(_: ESLintPluginConfig): PluginConfig { ], runner: { command: 'node', - args: [ - '-e', - `require('fs').writeFileSync('tmp/out.json', '${JSON.stringify([ + args: objectToCliArgs({ + e: `require('fs').writeFileSync('tmp/out.json', '${JSON.stringify([ { slug: 'no-any', title: 'No any type', @@ -28,7 +28,7 @@ export function eslintPlugin(_: ESLintPluginConfig): PluginConfig { score: 0, }, ] satisfies AuditOutputs)}')`, - ], + }), outputPath: 'tmp/out.json', }, slug: 'eslint', diff --git a/packages/plugin-lighthouse/package.json b/packages/plugin-lighthouse/package.json index 046933818..e50c72ba5 100644 --- a/packages/plugin-lighthouse/package.json +++ b/packages/plugin-lighthouse/package.json @@ -2,7 +2,8 @@ "name": "@quality-metrics/lighthouse-plugin", "version": "0.0.1", "dependencies": { - "lighthouse": "^11.0.0", - "@quality-metrics/models": ">=0.0.1" + "@quality-metrics/models": "*", + "@quality-metrics/utils": "*", + "lighthouse": "^11.0.0" } } diff --git a/packages/plugin-lighthouse/src/lib/lighthouse-plugin.ts b/packages/plugin-lighthouse/src/lib/lighthouse-plugin.ts index 1abce767e..62d5888c7 100644 --- a/packages/plugin-lighthouse/src/lib/lighthouse-plugin.ts +++ b/packages/plugin-lighthouse/src/lib/lighthouse-plugin.ts @@ -1,4 +1,5 @@ import { AuditOutputs, PluginConfig } from '@quality-metrics/models'; +import { objectToCliArgs } from '@quality-metrics/utils'; import { defaultConfig } from 'lighthouse'; type LighthousePluginConfig = { @@ -18,9 +19,8 @@ export function lighthousePlugin(_: LighthousePluginConfig): PluginConfig { ], runner: { command: 'node', - args: [ - '-e', - `require('fs').writeFileSync('tmp/out.json', '${JSON.stringify([ + args: objectToCliArgs({ + e: `require('fs').writeFileSync('tmp/out.json', '${JSON.stringify([ { slug: 'largest-contentful-paint', title: 'Largest Contentful Paint', @@ -28,7 +28,7 @@ export function lighthousePlugin(_: LighthousePluginConfig): PluginConfig { score: 0, }, ] satisfies AuditOutputs)}')`, - ], + }), outputPath: 'tmp/out.json', }, slug: 'lighthouse', diff --git a/packages/utils/package.json b/packages/utils/package.json index 95c6bbbcf..8561ac5cf 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -2,7 +2,7 @@ "name": "@quality-metrics/utils", "version": "0.0.1", "dependencies": { - "@quality-metrics/models": "^0.0.1", + "@quality-metrics/models": "*", "chalk": "^5.3.0", "cliui": "^8.0.1" } diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index b092f46ac..b0abacf0f 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -6,14 +6,6 @@ export { ProcessError, objectToCliArgs, } from './lib/collect/implementation/execute-process'; -export { - collect, - CollectOptions, - CollectOutputError, -} from './lib/collect/index'; -export { - persistReport, - PersistDirError, - PersistError, - logPersistedResults, -} from './lib/collect/implementation/persist'; +export { calcDuration, formatBytes } from './lib/collect/implementation/utils'; +export { reportToStdout } from './lib/collect/implementation/report-to-stdout'; +export { reportToMd } from './lib/collect/implementation/report-to-md'; diff --git a/packages/utils/src/lib/collect/implementation/execute-process.spec.ts b/packages/utils/src/lib/collect/implementation/execute-process.spec.ts index 7fa54ad5e..c0056c753 100644 --- a/packages/utils/src/lib/collect/implementation/execute-process.spec.ts +++ b/packages/utils/src/lib/collect/implementation/execute-process.spec.ts @@ -62,6 +62,21 @@ describe('objectToCliArgs', () => { expect(result).toEqual(['bin.js']); }); + it('should handle shorthands arguments', () => { + const params = { + e: `require('fs').writeFileSync('tmp/out.json', '${JSON.stringify([ + { + slug: 'largest-contentful-paint', + title: 'Largest Contentful Paint', + value: 0, + score: 0, + }, + ] satisfies AuditOutputs)}')`, + }; + const result = objectToCliArgs(params); + expect(result).toEqual([`-e="${params.e}"`]); + }); + it('should handle string arguments', () => { const params = { name: 'Juanita' }; const result = objectToCliArgs(params); diff --git a/packages/utils/src/lib/collect/implementation/execute-process.ts b/packages/utils/src/lib/collect/implementation/execute-process.ts index ae1c38cf6..21e017ea4 100644 --- a/packages/utils/src/lib/collect/implementation/execute-process.ts +++ b/packages/utils/src/lib/collect/implementation/execute-process.ts @@ -183,24 +183,31 @@ export function objectToCliArgs( params: Record | { _: string }, ): string[] { return Object.entries(params).flatMap(([key, value]) => { + // process/file/script if (key === '_') { return [value.toString()]; } + const prefix = key.length === 1 ? '-' : '--'; + // "-*" arguments (shorthands) + if (Array.isArray(value)) { + return value.map(v => `${prefix}${key}="${v}"`); + } + // --* arguments ========== if (Array.isArray(value)) { - return value.map(v => `--${key}="${v}"`); + return value.map(v => `${prefix}${key}="${v}"`); } if (typeof value === 'string') { - return [`--${key}="${value}"`]; + return [`${prefix}${key}="${value}"`]; } if (typeof value === 'number') { - return [`--${key}=${value}`]; + return [`${prefix}${key}=${value}`]; } if (typeof value === 'boolean') { - return [`--${value ? '' : 'no-'}${key}`]; + return [`${prefix}${value ? '' : 'no-'}${key}`]; } throw new Error(`Unsupported type ${typeof value} for key ${key}`); diff --git a/tsconfig.base.json b/tsconfig.base.json index 15f82021c..81645bb41 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -18,15 +18,15 @@ "baseUrl": ".", "resolveJsonModule": true, "paths": { - "@quality-metrics-cli/core": ["packages/core/src/index.ts"], - "@quality-metrics-cli/nx-plugin": ["packages/nx-plugin/src/index.ts"], "@quality-metrics/cli": ["packages/cli/src/index.ts"], + "@quality-metrics/core": ["packages/core/src/index.ts"], "@quality-metrics/eslint-plugin": ["packages/plugin-eslint/src/index.ts"], "@quality-metrics/lighthouse-plugin": [ "packages/plugin-lighthouse/src/index.ts" ], "@quality-metrics/models": ["packages/models/src/index.ts"], "@quality-metrics/models/testing": ["packages/models/test/index.ts"], + "@quality-metrics/nx-plugin": ["packages/nx-plugin/src/index.ts"], "@quality-metrics/utils": ["packages/utils/src/index.ts"] } },