Skip to content
Snippets Groups Projects
Unverified Commit 88e1f181 authored by RahulGautamSingh's avatar RahulGautamSingh Committed by GitHub
Browse files

test(lib/data): `ReplacementsSchema` (#31714)

parent f9ab074b
No related branches found
No related tags found
No related merge requests found
import replacementGroups from '../../../data/replacements.json'; import replacementGroupsJson from '../../../data/replacements.json';
import type { Preset } from '../types'; import type { Preset } from '../types';
import type { PresetTemplate, Replacement } from './auto-generate-replacements'; import type { PresetTemplate, Replacement } from './auto-generate-replacements';
import { addPresets } from './auto-generate-replacements'; import { addPresets } from './auto-generate-replacements';
const { $schema, ...replacementPresets } = replacementGroupsJson;
/* eslint sort-keys: ["error", "asc", {"caseSensitive": false, "natural": true}] */ /* eslint sort-keys: ["error", "asc", {"caseSensitive": false, "natural": true}] */
export const presets: Record<string, Preset> = replacementGroups; export const presets: Record<string, Preset> = replacementPresets;
const muiReplacement: Replacement[] = [ const muiReplacement: Replacement[] = [
[['@material-ui/codemod'], '@mui/codemod'], [['@material-ui/codemod'], '@mui/codemod'],
......
{ {
"$schema": "../../tools/schemas/replacements-schema.json",
"all": { "all": {
"description": "Apply crowd-sourced package replacement rules.", "description": "Apply crowd-sourced package replacement rules.",
"extends": [ "extends": [
......
{ {
"$schema": "http://json-schema.org/draft-04/schema#", "$schema": "https://json-schema.org/draft-04/schema#",
"type": "object", "type": "object",
"properties": { "properties": {
"repoGroups": { "repoGroups": {
......
{
"$schema": "https://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"all": {
"type": "object",
"properties": {
"description": { "type": "string" },
"extends": {
"type": "array",
"items": { "type": "string" }
},
"ignoreDeps": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["description", "extends"]
}
},
"patternProperties": {
"^[a-zA-Z0-9-]+$": {
"type": "object",
"properties": {
"description": { "type": "string" },
"packageRules": {
"type": "array",
"items": {
"type": "object",
"properties": {
"matchCurrentVersion": { "type": "string" },
"matchDatasources": {
"type": "array",
"items": { "type": "string" }
},
"matchPackageNames": {
"type": "array",
"items": { "type": "string" }
},
"replacementName": { "type": "string" },
"replacementVersion": { "type": "string" },
"description": { "type": "string" },
"replacementNameTemplate": { "type": "string" }
},
"required": ["matchDatasources", "matchPackageNames"]
},
"contains": {
"type": "object",
"oneOf": [
{ "required": ["replacementName"] },
{ "required": ["replacementNameTemplate"] }
]
},
"minItems": 1
}
},
"required": ["description", "packageRules"]
}
},
"additionalProperties": false
}
...@@ -5,10 +5,50 @@ const UrlSchema = z.record( ...@@ -5,10 +5,50 @@ const UrlSchema = z.record(
z.union([z.string(), z.array(z.string())]), z.union([z.string(), z.array(z.string())]),
); );
const MonorepoSchema = z.object({ export const MonorepoSchema = z.object({
repoGroups: UrlSchema, repoGroups: UrlSchema,
orgGroups: UrlSchema, orgGroups: UrlSchema,
patternGroups: UrlSchema, patternGroups: UrlSchema,
}); });
export { MonorepoSchema }; const PackageRuleSchema = z.object({
matchCurrentVersion: z.string().optional(),
matchDatasources: z.array(z.string()),
matchPackageNames: z.array(z.string()),
replacementName: z.string().optional(),
replacementVersion: z.string().optional(),
description: z.string().optional(),
replacementNameTemplate: z.string().optional(),
});
const RuleSetSchema = z.object({
description: z.string(),
packageRules: z
.array(PackageRuleSchema)
.min(1)
.refine(
(rules) =>
rules.some(
(rule) =>
rule.replacementName !== undefined ||
rule.replacementNameTemplate !== undefined,
),
{
message:
'At least one package rule must use either the replacementName config option, or the replacementNameTemplate config option',
},
),
});
const AllSchema = z.object({
description: z.string(),
extends: z.array(z.string()),
ignoreDeps: z.array(z.string()).optional(),
});
export const ReplacementsSchema = z
.object({
$schema: z.string(),
all: AllSchema,
})
.catchall(RuleSetSchema);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment