Skip to content

Commit 1cb61dc

Browse files
RahulGautamSinghrarkinsviceice
authoredFeb 24, 2025
feat(manager/jsonata): add toml support (renovatebot#34380)
Co-authored-by: Rhys Arkins <[email protected]> Co-authored-by: Michael Kriese <[email protected]>
1 parent 1e1f0d6 commit 1cb61dc

File tree

5 files changed

+92
-6
lines changed

5 files changed

+92
-6
lines changed
 

‎docs/usage/configuration-options.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ It will be compiled using Handlebars and the regex `groups` result.
845845
It specifies the syntax of the package file that's managed by the custom `jsonata` manager.
846846
This setting helps the system correctly parse and interpret the configuration file's contents.
847847

848-
Only the `json` and `yaml` formats are supported.
848+
Only the `json`, `toml` and `yaml` formats are supported.
849849
`yaml` files are parsed as multi document YAML files.
850850

851851
```json title="Parsing a JSON file with a custom manager"
@@ -856,7 +856,7 @@ Only the `json` and `yaml` formats are supported.
856856
"fileFormat": "json",
857857
"fileMatch": [".renovaterc"],
858858
"matchStrings": [
859-
"packages.{ \"depName\": package, \"currentValue\": version }"
859+
"packages.{ 'depName': package, 'currentValue': version }"
860860
]
861861
}
862862
]
@@ -871,7 +871,22 @@ Only the `json` and `yaml` formats are supported.
871871
"fileFormat": "yaml",
872872
"fileMatch": ["file.yml"],
873873
"matchStrings": [
874-
"packages.{ \"depName\": package, \"currentValue\": version }"
874+
"packages.{ 'depName': package, 'currentValue': version }"
875+
]
876+
}
877+
]
878+
}
879+
```
880+
881+
```json title="Parsing a TOML file with a custom manager"
882+
{
883+
"customManagers": [
884+
{
885+
"customType": "jsonata",
886+
"fileFormat": "toml",
887+
"fileMatch": ["file.toml"],
888+
"matchStrings": [
889+
"packages.{ 'depName': package, 'currentValue': version }"
875890
]
876891
}
877892
]

‎lib/config/options/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2766,7 +2766,7 @@ const options: RenovateOptions[] = [
27662766
description:
27672767
'It specifies the syntax of the package file being managed by the custom JSONata manager.',
27682768
type: 'string',
2769-
allowedValues: ['json', 'yaml'],
2769+
allowedValues: ['json', 'toml', 'yaml'],
27702770
parents: ['customManagers'],
27712771
cli: false,
27722772
env: false,

‎lib/modules/manager/custom/jsonata/index.spec.ts

+51
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,55 @@ describe('modules/manager/custom/jsonata/index', () => {
362362
datasourceTemplate: 'npm',
363363
});
364364
});
365+
366+
it('extracts toml', async () => {
367+
const json = codeBlock`
368+
[[packages]]
369+
dep_name = "foo"
370+
package_name = "fii"
371+
current_value = "1.2.3"
372+
current_digest = "1234"
373+
data_source = "nuget"
374+
versioning = "maven"
375+
extract_version = "custom-extract-version"
376+
registry_url = "https://registry.npmjs.org"
377+
dep_type = "dev"
378+
379+
some = true
380+
`;
381+
const config = {
382+
fileFormat: 'toml',
383+
matchStrings: [
384+
`packages.{
385+
"depName": dep_name,
386+
"packageName": package_name,
387+
"currentValue": current_value,
388+
"currentDigest": current_digest,
389+
"datasource": data_source,
390+
"versioning": versioning,
391+
"extractVersion": extract_version,
392+
"registryUrl": registry_url,
393+
"depType": dep_type
394+
}`,
395+
],
396+
};
397+
const res = await extractPackageFile(json, 'unused', config);
398+
399+
expect(res).toMatchObject({
400+
...config,
401+
deps: [
402+
{
403+
depName: 'foo',
404+
packageName: 'fii',
405+
currentValue: '1.2.3',
406+
currentDigest: '1234',
407+
datasource: 'nuget',
408+
versioning: 'maven',
409+
extractVersion: 'custom-extract-version',
410+
registryUrls: ['https://registry.npmjs.org/'],
411+
depType: 'dev',
412+
},
413+
],
414+
});
415+
});
365416
});

‎lib/modules/manager/custom/jsonata/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import is from '@sindresorhus/is';
22
import type { Category } from '../../../../constants';
33
import { logger } from '../../../../logger';
44
import { parseJson } from '../../../../util/common';
5+
import { parse as parseToml } from '../../../../util/toml';
56
import { parseYaml } from '../../../../util/yaml';
67
import type { PackageFileContent } from '../../types';
78
import { validMatchFields } from '../utils';
@@ -30,6 +31,9 @@ export async function extractPackageFile(
3031
case 'yaml':
3132
json = parseYaml(content);
3233
break;
34+
case 'toml':
35+
json = parseToml(content);
36+
break;
3337
}
3438
} catch (err) {
3539
logger.debug(

‎lib/modules/manager/custom/jsonata/readme.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
With `customManagers` using `JSONata` queries you can configure Renovate so it finds dependencies in JSON or YAML files, that are not detected by its other built-in package managers.
1+
With `customManagers` using `JSONata` queries you can configure Renovate so it finds dependencies in JSON, TOML and YAML files, that are not detected by its other built-in package managers.
22

3-
Renovate uses the `jsonata` package to process the `json` or `yaml` file content using the queries.
3+
Renovate uses the `jsonata` package to process the file content using the queries, after the content has been parsed into `json` format.
44

55
For more on the jsonata query language, read the [jsonata query language site](https://docs.jsonata.org/overview.html).
66

@@ -231,3 +231,19 @@ Query:
231231
```
232232
packages.{ "depName": package, "currentValue": version }
233233
```
234+
235+
```toml title="JSONata manager config to extract deps from a toml file"
236+
[[packages]]
237+
version = "1.2.3"
238+
package = "foo"
239+
240+
[[packages]]
241+
version = "1.2.2"
242+
package = "bar"
243+
```
244+
245+
Query:
246+
247+
```
248+
packages.{ "depName": package, "currentValue": version }
249+
```

0 commit comments

Comments
 (0)
Please sign in to comment.