Skip to content

Commit beb93b3

Browse files
authored
Add catalogs configuration schema.json (#35)
1 parent 1fba14c commit beb93b3

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,21 @@ list:
5252
react: npm:19.0.0
5353
```
5454
55-
### 2. Apply catalogs to `.yarnrc.yml`
55+
### 2. (Optional) Configure schema validation in VSCode
56+
57+
For better editing experience with `catalogs.yml`, you can enable schema validation in VSCode by adding the following to `.vscode/settings.json`:
58+
59+
```json
60+
{
61+
"yaml.schemas": {
62+
"https://raw.githubusercontent.com/toss/yarn-plugin-catalogs/refs/heads/main/sources/configuration/schema.json": "catalogs.yml"
63+
}
64+
}
65+
```
66+
67+
This will provide autocomplete and validation for your `catalogs.yml` file.
68+
69+
### 3. Apply catalogs to `.yarnrc.yml`
5670

5771
```bash
5872
$ yarn catalogs apply
@@ -101,7 +115,7 @@ catalogs:
101115
react: npm:19.0.0
102116
```
103117

104-
### 3. Use catalog protocol in package.json
118+
### 4. Use catalog protocol in package.json
105119

106120
```json
107121
{

sources/configuration/schema.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema#",
3+
"title": "Yarn Catalogs Configuration",
4+
"description": "The schema for the Yarn catalogs configuration file (catalogs.yml). Strictly validates options and catalog mappings.",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"properties": {
8+
"options": {
9+
"type": "object",
10+
"description": "Optional options that control the catalog behavior",
11+
"additionalProperties": false,
12+
"properties": {
13+
"default": {
14+
"description": "Default enabled catalog groups for 'yarn add'. Can be the reserved token 'max' for max mode, a single group name, or an array of group names.",
15+
"oneOf": [
16+
{ "type": "string", "enum": ["max"] },
17+
{ "$ref": "#/$defs/catalogGroupName" },
18+
{
19+
"type": "array",
20+
"items": { "$ref": "#/$defs/catalogGroupName" }
21+
}
22+
]
23+
},
24+
"validation": {
25+
"type": "string",
26+
"description": "The level of dependency source validation",
27+
"enum": ["warn", "strict", "off"]
28+
},
29+
"includedWorkspaces": {
30+
"type": "array",
31+
"description": "The list of workspace names/paths to include in catalog application",
32+
"items": { "$ref": "#/$defs/workspaceName" }
33+
},
34+
"ignoredWorkspaces": {
35+
"type": "array",
36+
"description": "The list of workspace names/paths to exclude from catalog application",
37+
"items": { "$ref": "#/$defs/workspaceName" }
38+
}
39+
}
40+
},
41+
"list": {
42+
"type": "object",
43+
"description": "The mapping of package sources by catalog group",
44+
"propertyNames": { "$ref": "#/$defs/catalogGroupName" },
45+
"additionalProperties": { "$ref": "#/$defs/catalogGroup" },
46+
"minProperties": 1
47+
}
48+
},
49+
"required": ["list"],
50+
"$defs": {
51+
"workspaceName": {
52+
"type": "string",
53+
"minLength": 1
54+
},
55+
"catalogGroupName": {
56+
"type": "string",
57+
"description": "Catalog group name; may include '/' to indicate inheritance (e.g., stable, stable/canary). Excludes the reserved token 'max'.",
58+
"pattern": "^(?!max$)[A-Za-z0-9._-]+(?:\\/[A-Za-z0-9._-]+)*$"
59+
},
60+
"packageName": {
61+
"type": "string",
62+
"description": "The package name",
63+
"pattern": "^(?:@[a-z0-9][a-z0-9-_]*\\/)?[a-z0-9][a-z0-9-._]*$"
64+
},
65+
"sourceString": {
66+
"type": "string",
67+
"description": "Free-form version/source string (e.g. \"18.2.0\", \"log-v3:45.0.1::__version=7.0.16\", \"1.0.14-nightly.20251119194855\")."
68+
},
69+
"catalogGroup": {
70+
"type": "object",
71+
"description": "Mapping of package name → source specification",
72+
"additionalProperties": { "$ref": "#/$defs/sourceString" },
73+
"propertyNames": { "$ref": "#/$defs/packageName" },
74+
"minProperties": 0
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)