diff --git a/lib/modules/manager/bazel/parser.spec.ts b/lib/modules/manager/bazel/parser.spec.ts index 3f7075bda638e02081255dc3e61cedd7ecc7c1b8..7bdccab9167eb3dcedcf9956925b4150d39ef738 100644 --- a/lib/modules/manager/bazel/parser.spec.ts +++ b/lib/modules/manager/bazel/parser.spec.ts @@ -228,6 +228,12 @@ describe('modules/manager/bazel/parser', () => { group = "com.example2", artifact = "bar", version = "2.2.2", + ), + maven.artifact( + "com.example3", + "baz", + "3.3.3", + neverlink = True ) ], repositories = [ @@ -246,10 +252,16 @@ describe('modules/manager/bazel/parser', () => { 'com.example1:foo:1.1.1', { _function: 'maven.artifact', - artifact: 'bar', group: 'com.example2', + artifact: 'bar', version: '2.2.2', }, + { + _function: 'maven.artifact', + '0': 'com.example3', + '1': 'baz', + '2': '3.3.3', + }, ], repositories: [ 'https://example1.com/maven2', diff --git a/lib/modules/manager/bazel/parser.ts b/lib/modules/manager/bazel/parser.ts index c6a8f77828cb7f827214ae7f946de94c9ed8c75a..36e5f457143ef434bdae5c8df668e70fcb49974f 100644 --- a/lib/modules/manager/bazel/parser.ts +++ b/lib/modules/manager/bazel/parser.ts @@ -11,6 +11,7 @@ interface Ctx { stack: NestedFragment[]; recordKey?: string; subRecordKey?: string; + argIndex?: number; } function emptyCtx(source: string): Ctx { @@ -140,13 +141,18 @@ const kwParams = q startsWith: '(', endsWith: ')', search: q - .sym<Ctx>((ctx, { value: subRecordKey }) => ({ - ...ctx, - subRecordKey, - })) - .op('=') + .opt( + q + .sym<Ctx>((ctx, { value: subRecordKey }) => ({ + ...ctx, + subRecordKey, + })) + .op('=') + ) .str((ctx, { value: subRecordValue, offset }) => { - const subRecordKey = ctx.subRecordKey!; + const argIndex = ctx.argIndex ?? 0; + + const subRecordKey = ctx.subRecordKey! ?? argIndex.toString(); const ruleFragment = currentFragment(ctx); if (ruleFragment.type === 'record') { ruleFragment.children[subRecordKey] = { @@ -156,9 +162,12 @@ const kwParams = q }; } delete ctx.subRecordKey; + ctx.argIndex = argIndex + 1; return ctx; }), postHandler: (ctx, tree) => { + delete ctx.argIndex; + const callFrag = currentFragment(ctx); ctx.stack.pop(); if (callFrag.type === 'record' && tree.type === 'wrapped-tree') { diff --git a/lib/modules/manager/bazel/rules/index.spec.ts b/lib/modules/manager/bazel/rules/index.spec.ts index 83963981517e1e7aba0c871f815d26fe06449b06..a1b9a9553614691988f827c7116cac351913471a 100644 --- a/lib/modules/manager/bazel/rules/index.spec.ts +++ b/lib/modules/manager/bazel/rules/index.spec.ts @@ -357,11 +357,17 @@ describe('modules/manager/bazel/rules/index', () => { artifacts: [ 'com.example1:foo:1.1.1', { - artifact: 'bar', - function: 'maven.artifact', + _function: 'maven.artifact', group: 'com.example2', + artifact: 'bar', version: '2.2.2', }, + { + _function: 'maven.artifact', + '0': 'com.example3', + '1': 'baz', + '2': '3.3.3', + }, ], repositories: [ 'https://example1.com/maven2', @@ -389,6 +395,16 @@ describe('modules/manager/bazel/rules/index', () => { 'https://example2.com/maven2', ], }, + { + currentValue: '3.3.3', + datasource: 'maven', + depType: 'maven_install', + depName: 'com.example3:baz', + registryUrls: [ + 'https://example1.com/maven2', + 'https://example2.com/maven2', + ], + }, ]); }); }); diff --git a/lib/modules/manager/bazel/rules/maven.ts b/lib/modules/manager/bazel/rules/maven.ts index 82fcdd3934fa01e103d0413590ae5359f9ccb33e..448185e371a0fcb069d7cc74681ed6bf10ecee3d 100644 --- a/lib/modules/manager/bazel/rules/maven.ts +++ b/lib/modules/manager/bazel/rules/maven.ts @@ -5,11 +5,20 @@ import type { PackageDependency } from '../../types'; export const mavenRules = ['maven_install'] as const; -const ArtifactSpec = z.object({ - group: z.string(), - artifact: z.string(), - version: z.string(), -}); +const ArtifactSpec = z.union([ + z.object({ + group: z.string(), + artifact: z.string(), + version: z.string(), + }), + z + .object({ + '0': z.string(), + '1': z.string(), + '2': z.string(), + }) + .transform((x) => ({ group: x[0], artifact: x[1], version: x[2] })), +]); type ArtifactSpec = z.infer<typeof ArtifactSpec>; export const MavenTarget = z