Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package utils for cli independent logic #39

Merged
merged 84 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
d067799
feat(models): setup types and parser with zod
BioPhoton Aug 30, 2023
46d4408
fix(models): add package.lock
BioPhoton Aug 30, 2023
0e5ef27
refactor(models): format
BioPhoton Aug 30, 2023
1369565
refactor(models): align package.json
BioPhoton Aug 30, 2023
63c1bcc
refactor(models): format
BioPhoton Aug 30, 2023
8096b85
refactor(models): package.lock
BioPhoton Aug 31, 2023
70fc405
Update packages/models/project.json
BioPhoton Aug 31, 2023
c885349
Update packages/models/project.json
BioPhoton Aug 31, 2023
a71955e
feat(utils): add collect utils
BioPhoton Aug 31, 2023
337c9c2
refactor(models): remove budgets from initial code base
BioPhoton Aug 31, 2023
aaa17a5
Update packages/models/src/lib/category-config.ts
BioPhoton Aug 31, 2023
0a67872
refactor(models): remove budgets
BioPhoton Aug 31, 2023
2ce3136
Merge branch 'main' into add-package-for-cli-independent-logic
BioPhoton Sep 1, 2023
48dd062
Update packages/models/src/lib/plugins.ts
BioPhoton Sep 1, 2023
3b35871
Update packages/models/src/lib/plugins.ts
BioPhoton Sep 1, 2023
34ceba1
Update packages/models/src/lib/upload.ts
BioPhoton Sep 1, 2023
71c5a4d
Update packages/models/src/lib/upload.ts
BioPhoton Sep 1, 2023
05486fd
refactor(models): add int and non negative validators
BioPhoton Sep 1, 2023
23cf79a
refactor(models): add cross field validators
BioPhoton Sep 4, 2023
d52de86
refactor(models): format files
BioPhoton Sep 4, 2023
b9e1244
refactor(models): implement feedback from PR, format
BioPhoton Sep 5, 2023
8dc0e53
Merge branch 'main' into add-package-for-cli-independent-logic
BioPhoton Sep 5, 2023
9bc21e6
Update packages/models/project.json
BioPhoton Sep 5, 2023
20ccf92
Update packages/models/src/lib/category-config.ts
BioPhoton Sep 5, 2023
401ed9a
Update packages/models/src/lib/implementation/schemas.ts
BioPhoton Sep 5, 2023
cbee718
Update packages/models/src/lib/category-config.ts
BioPhoton Sep 5, 2023
a000ee9
Update packages/models/src/lib/core-config.spec.ts
BioPhoton Sep 5, 2023
651498b
Update packages/models/src/lib/output.ts
BioPhoton Sep 5, 2023
4ec4bc4
Update packages/models/src/lib/output.ts
BioPhoton Sep 5, 2023
c0b4164
Update packages/models/src/lib/plugins.ts
BioPhoton Sep 5, 2023
462c5ed
Update packages/models/src/lib/plugins.ts
BioPhoton Sep 5, 2023
deb7209
Update packages/models/src/lib/core-config.spec.ts
BioPhoton Sep 5, 2023
d3cbc08
Update packages/models/src/lib/output.ts
BioPhoton Sep 5, 2023
82cc90f
Update packages/models/src/lib/output.ts
BioPhoton Sep 5, 2023
7fcdf05
Update packages/models/src/lib/core-config.ts
BioPhoton Sep 5, 2023
b7e985c
Update packages/models/src/lib/core-config.ts
BioPhoton Sep 5, 2023
fca30a4
Update packages/models/src/lib/implementation/utils.spec.ts
BioPhoton Sep 5, 2023
74e6594
Update packages/models/src/lib/implementation/utils.spec.ts
BioPhoton Sep 5, 2023
9a1a2c6
Merge remote-tracking branch 'origin/main' into add-models
BioPhoton Sep 5, 2023
4e0fd2e
refactor(models): add regex and validators and tests
BioPhoton Sep 5, 2023
66a5399
refactor(models): fix tests and lint errors
BioPhoton Sep 5, 2023
ce2362b
refactor(models): fix tests and comments
BioPhoton Sep 5, 2023
1c0e36e
refactor(models): add test case
BioPhoton Sep 5, 2023
9979695
Update schemas.ts
BioPhoton Sep 6, 2023
c000792
Update schemas.ts
BioPhoton Sep 6, 2023
acf20d6
Update schemas.ts
BioPhoton Sep 6, 2023
8b3c562
Update schemas.ts
BioPhoton Sep 6, 2023
ad2f7e9
Update utils.ts
BioPhoton Sep 6, 2023
ea3d7b1
Update utils.ts
BioPhoton Sep 6, 2023
5406c96
Update global-cli-options.ts
BioPhoton Sep 6, 2023
d6a82d6
refactor(models): merge suggestions, fix tests
BioPhoton Sep 6, 2023
7831a5a
Update packages/models/src/lib/category-config.spec.ts
BioPhoton Sep 6, 2023
2f7b498
Update packages/models/src/lib/implementation/schemas.ts
BioPhoton Sep 6, 2023
8f2e201
Update packages/models/src/lib/category-config.spec.ts
BioPhoton Sep 6, 2023
41b4edc
refactor(models): reinstall
BioPhoton Sep 6, 2023
9e97fa4
refactor(models): fix dependencies
BioPhoton Sep 6, 2023
c54d461
refactor(models): fix dependencies 2
BioPhoton Sep 6, 2023
d2ea0f4
refactor(models): fix dependencies 2
BioPhoton Sep 6, 2023
d6fd5e8
refactor(models): fix dependencies 3
BioPhoton Sep 6, 2023
28e6f63
Merge branch 'add-models' into add-package-for-cli-independent-logic
BioPhoton Sep 6, 2023
9719316
Merge branch 'main' into add-package-for-cli-independent-logic
BioPhoton Sep 6, 2023
437334d
refactor(models): adopt refinement logic
BioPhoton Sep 6, 2023
b217954
refactor(models): make buildable
BioPhoton Sep 6, 2023
e7d5c5c
refactor(utils): make buildable, adopt tests
BioPhoton Sep 6, 2023
1d63d45
refactor(utils): add vfs for unit tests
BioPhoton Sep 6, 2023
295cfd3
refactor(utils): remove vfs code
BioPhoton Sep 6, 2023
08609c2
refactor(utils): fix package.lock
BioPhoton Sep 6, 2023
b34defc
refactor(utils): format
BioPhoton Sep 6, 2023
1f7b685
test(utils): fix tests
BioPhoton Sep 6, 2023
0d1f0a0
refactor(utils): cleanup
BioPhoton Sep 6, 2023
c62b0af
Update packages/utils/src/lib/collect/implementation/execute-plugin.s…
BioPhoton Sep 7, 2023
2b87136
Update packages/utils/src/lib/collect/implementation/execute-plugin.ts
BioPhoton Sep 7, 2023
dfbb504
Update packages/utils/src/lib/collect/implementation/execute-plugin.ts
BioPhoton Sep 7, 2023
9acdc40
Update packages/utils/src/lib/collect/implementation/execute-plugin.ts
BioPhoton Sep 7, 2023
b5fb118
Update packages/utils/src/lib/collect/index.ts
BioPhoton Sep 7, 2023
61046d6
Update packages/utils/src/lib/collect/implementation/mock/execute-pro…
BioPhoton Sep 7, 2023
8e02d5a
Update packages/utils/src/lib/collect/implementation/mock/process-hel…
BioPhoton Sep 7, 2023
19a68b0
feat(cli): refactor types, adopt lib setup for build and test
BioPhoton Sep 7, 2023
7a2ca23
feat(utils): format
BioPhoton Sep 7, 2023
22bf8d2
feat(utils): lint fix
BioPhoton Sep 7, 2023
5d9ed9c
feat(utils): fix build
BioPhoton Sep 7, 2023
58a1860
Update packages/utils/src/lib/collect/implementation/execute-process.…
BioPhoton Sep 7, 2023
f6829cf
Apply suggestions from code review
BioPhoton Sep 7, 2023
ddc6dad
feat(utils): adopt test text
BioPhoton Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
424 changes: 314 additions & 110 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cli/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@nx/dependency-checks": [
"error",
{
"ignoredDependencies": ["vite", "@nx/vite"]
"ignoredDependencies": ["vite", "vitest", "@nx/vite"]
}
]
}
Expand Down
7 changes: 6 additions & 1 deletion packages/models/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": ["error"]
"@nx/dependency-checks": [
"error",
{
"ignoredDependencies": ["vite", "vitest", "@nx/vite"]
}
]
}
}
]
Expand Down
7 changes: 7 additions & 0 deletions packages/models/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@quality-metrics/models",
"version": "0.0.1",
"dependencies": {
"zod": "^3.22.1"
}
}
24 changes: 21 additions & 3 deletions packages/models/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,37 @@
"sourceRoot": "packages/models/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/models",
"main": "packages/models/src/index.ts",
"tsConfig": "packages/models/tsconfig.lib.json",
"assets": ["packages/models/*.md"],
"esbuildConfig": "esbuild.config.js"
}
},
"publish": {
"command": "node tools/scripts/publish.mjs models {args.ver} {args.tag}",
"dependsOn": ["build"]
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/models/**/*.ts"]
"lintFilePatterns": [
"packages/models/**/*.ts",
"packages/models/package.json"
]
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["{workspaceRoot}/coverage/packages/cli"],
"outputs": ["{workspaceRoot}/coverage/packages/models"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/packages/cli"
"reportsDirectory": "../../coverage/packages/models"
}
}
},
Expand Down
33 changes: 18 additions & 15 deletions packages/models/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
export { coreConfigSchema, CoreConfigSchema } from './lib/core-config';
export { uploadConfigSchema, UploadConfigSchema } from './lib/upload-config';
export { pluginConfigSchema, PluginConfigSchema } from './lib/plugin-config';
export {
runnerOutputSchema,
RunnerOutputSchema,
runnerOutputAuditRefsPresentInPluginConfigs,
PluginsOutputSchema,
} from './lib/output';
export { persistConfigSchema, PersistConfigSchema } from './lib/persist-config';
unrefinedCoreConfigSchema,
refineCoreConfig,
coreConfigSchema,
CoreConfig,
} from './lib/core-config';
export { uploadConfigSchema, UploadConfig } from './lib/upload-config';
export {
categoryConfigSchema,
CategoryConfigSchema,
} from './lib/category-config';
pluginConfigSchema,
PluginConfig,
RunnerOutput,
runnerOutputSchema,
} from './lib/plugin-config';
export {
globalCliArgsSchema,
GlobalCliArgsSchema,
} from './lib/global-cli-options';
runnerOutputAuditRefsPresentInPluginConfigs,
reportSchema,
Report,
} from './lib/report';
export { persistConfigSchema, PersistConfig } from './lib/persist-config';
export { categoryConfigSchema, CategoryConfig } from './lib/category-config';
export { globalCliArgsSchema, GlobalCliArgs } from './lib/global-cli-options';
2 changes: 1 addition & 1 deletion packages/models/src/lib/category-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const categoryConfigSchema = z.object(
},
);

export type CategoryConfigSchema = z.infer<typeof categoryConfigSchema>;
export type CategoryConfig = z.infer<typeof categoryConfigSchema>;

// helper for validator: categories have unique refs to audits or groups
export function duplicateRefsInCategoryMetricsErrorMsg(metrics) {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/lib/core-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('CoreConfig', () => {
const missingSlug = 'missing-plugin-slug-in-category#groups:auditref';
cfg.categories.push(
mockCategory({
categorySlug: 'test',
categorySlug: 'test-slug',
auditRefOrGroupRef: [`${missingSlug}`],
}),
);
Expand Down
73 changes: 42 additions & 31 deletions packages/models/src/lib/core-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import { Schema, z } from 'zod';
import { pluginConfigSchema } from './plugin-config';
import { categoryConfigSchema } from './category-config';
import { uploadConfigSchema } from './upload-config';
Expand Down Expand Up @@ -28,37 +28,49 @@ import {
* console.error('Invalid plugin config:', validationResult.error);
* }
*/
export const coreConfigSchema = z
.object({
plugins: z.array(pluginConfigSchema, {
description:
'List of plugins to be used (official, community-provided, or custom)',
}),
/** portal configuration for persisting results */
persist: persistConfigSchema,
/** portal configuration for uploading results */
upload: uploadConfigSchema.optional(),
categories: z
.array(categoryConfigSchema, {
description: 'Categorization of individual audits',
})
// categories slugs are unique
export const unrefinedCoreConfigSchema = z.object({
plugins: z.array(pluginConfigSchema, {
description:
'List of plugins to be used (official, community-provided, or custom)',
}),
/** portal configuration for persisting results */
persist: persistConfigSchema,
/** portal configuration for uploading results */
upload: uploadConfigSchema.optional(),
categories: z
.array(categoryConfigSchema, {
description: 'Categorization of individual audits',
})
// categories slugs are unique
.refine(
categoryCfg => !getDuplicateSlugCategories(categoryCfg),
categoryCfg => ({
message: duplicateSlugCategoriesErrorMsg(categoryCfg),
}),
),
});

export const coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);

/**
* Add refinements to coreConfigSchema
* workaround for zod issue: https://github.com/colinhacks/zod/issues/454
*
*/
export function refineCoreConfig(schema: Schema): Schema {
return (
schema
// categories point to existing audit or group refs
.refine(
categoryCfg => !getDuplicateSlugCategories(categoryCfg),
categoryCfg => ({
message: duplicateSlugCategoriesErrorMsg(categoryCfg),
coreCfg => !getMissingRefsForCategories(coreCfg),
coreCfg => ({
message: missingRefsForCategoriesErrorMsg(coreCfg),
}),
),
})
// categories point to existing audit or group refs
.refine(
coreCfg => !getMissingRefsForCategories(coreCfg),
coreCfg => ({
message: missingRefsForCategoriesErrorMsg(coreCfg),
}),
)
);
}

export type CoreConfigSchema = z.infer<typeof coreConfigSchema>;
export type CoreConfig = z.infer<typeof coreConfigSchema>;

// helper for validator: categories point to existing audit or group refs
function missingRefsForCategoriesErrorMsg(coreCfg) {
Expand Down Expand Up @@ -89,9 +101,8 @@ function getMissingRefsForCategories(coreCfg) {
if (Array.isArray(missingAuditRefs) && missingAuditRefs.length > 0) {
missingRefs.push(...missingAuditRefs);
}
const groupRefsFromCategory = coreCfg.categories.flatMap(
({ metrics }) =>
metrics.filter(({ ref }) => isGroupRef(ref)).map(({ ref }) => ref), // plg#group:perf
const groupRefsFromCategory = coreCfg.categories.flatMap(({ metrics }) =>
metrics.filter(({ ref }) => isGroupRef(ref)).map(({ ref }) => ref),
);
const groupRefsFromPlugins = coreCfg.plugins.flatMap(({ groups, meta }) => {
return groups.map(({ slug }) => `${meta.slug}#group:${slug}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/lib/global-cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export const globalCliArgsSchema = z.object({
.default('code-pushup.config.js'),
});

export type GlobalCliArgsSchema = z.infer<typeof globalCliArgsSchema>;
export type GlobalCliArgs = z.infer<typeof globalCliArgsSchema>;
35 changes: 15 additions & 20 deletions packages/models/src/lib/implementation/helpers.mock.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { PluginConfigSchema } from '../plugin-config';
import { RunnerOutputSchema } from '../output';
import { CoreConfigSchema } from '../core-config';
import { CategoryConfigSchema } from '../category-config';
import { UploadConfigSchema } from '../upload-config';
import { PersistConfigSchema } from '../persist-config';
import { PluginConfig, RunnerOutput } from '../plugin-config';
import { CoreConfig } from '../core-config';
import { CategoryConfig } from '../category-config';
import { UploadConfig } from '../upload-config';
import { PersistConfig } from '../persist-config';

export function mockConfig(opt?: {
pluginSlug?: string | string[];
auditSlug?: string | string[];
groupSlug?: string | string[];
}): CoreConfigSchema {
}): CoreConfig {
let { pluginSlug, auditSlug, groupSlug } = opt || {};
pluginSlug = pluginSlug || 'mock-plugin-slug';
auditSlug = auditSlug || 'mock-audit-slug';
Expand All @@ -27,7 +26,7 @@ export function mockPluginConfig(opt?: {
pluginSlug?: string;
auditSlug?: string | string[];
groupSlug?: string | string[];
}): PluginConfigSchema {
}): PluginConfig {
const { groupSlug } = opt || {};
let { pluginSlug, auditSlug } = opt || {};
pluginSlug = pluginSlug || 'mock-plugin-slug';
Expand Down Expand Up @@ -58,7 +57,7 @@ export function mockPluginConfig(opt?: {
slug: `${pluginSlug}#${slug}`,
value: parseFloat('0.' + idx),
})),
} satisfies RunnerOutputSchema)}' > ${outputPath}`,
} satisfies RunnerOutput)}' > ${outputPath}`,
],
outputPath: outputPath,
},
Expand All @@ -71,7 +70,7 @@ export function mockPluginConfig(opt?: {

export function mockAuditConfig(opt?: {
auditSlug?: string;
}): PluginConfigSchema['audits'][0] {
}): PluginConfig['audits'][0] {
let { auditSlug } = opt || {};
auditSlug = auditSlug || 'mock-audit-slug';

Expand All @@ -85,7 +84,7 @@ export function mockAuditConfig(opt?: {
}
export function mockMetric(opt?: {
auditRef?: string;
}): CategoryConfigSchema['metrics'][0] {
}): CategoryConfig['metrics'][0] {
const { auditRef } = opt || {};
const ref = auditRef || 'mock-plugin-slug#mock-audit-slug';

Expand All @@ -98,7 +97,7 @@ export function mockMetric(opt?: {
export function mockGroupConfig(opt?: {
groupSlug?: string;
auditSlug?: string | string[];
}): PluginConfigSchema['groups'][0] {
}): PluginConfig['groups'][0] {
let { groupSlug, auditSlug } = opt || {};
groupSlug = groupSlug || 'mock-group-slug';
auditSlug = auditSlug || 'mock-audit-slug';
Expand All @@ -116,7 +115,7 @@ export function mockGroupConfig(opt?: {
export function mockCategory(opt?: {
categorySlug?: string;
auditRefOrGroupRef?: string | string[];
}): CategoryConfigSchema {
}): CategoryConfig {
let { auditRefOrGroupRef, categorySlug } = opt || {};
categorySlug = categorySlug || 'mock-category-slug';
auditRefOrGroupRef = auditRefOrGroupRef || 'mock-plugin-slug#mock-audit-slug';
Expand All @@ -133,18 +132,14 @@ export function mockCategory(opt?: {
};
}

export function mockUploadConfig(
opt?: Partial<UploadConfigSchema>,
): UploadConfigSchema {
export function mockUploadConfig(opt?: Partial<UploadConfig>): UploadConfig {
return {
apiKey: 'm0ck-API-k3y',
server: 'http://test.server.io',
...opt,
};
}
export function mockPersistConfig(
opt?: Partial<PersistConfigSchema>,
): PersistConfigSchema {
export function mockPersistConfig(opt?: Partial<PersistConfig>): PersistConfig {
return {
outputPath: 'mock-output-path.json',
...opt,
Expand All @@ -153,7 +148,7 @@ export function mockPersistConfig(

export function mockRunnerOutput(opt?: {
auditSlug: string | string[];
}): RunnerOutputSchema {
}): RunnerOutput {
let { auditSlug } = opt || {};
auditSlug = auditSlug || 'mock-audit-output-slug';
const audits = Array.isArray(auditSlug)
Expand Down
53 changes: 0 additions & 53 deletions packages/models/src/lib/output.spec.ts

This file was deleted.

Loading