Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bazel): Support for Maven dependencies (#20351)
- Loading branch information
Showing
6 changed files
with
257 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import is from '@sindresorhus/is'; | ||
import { z } from 'zod'; | ||
import { MavenDatasource } from '../../../datasource/maven'; | ||
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(), | ||
}); | ||
type ArtifactSpec = z.infer<typeof ArtifactSpec>; | ||
|
||
export const MavenTarget = z | ||
.object({ | ||
rule: z.enum(mavenRules), | ||
artifacts: z | ||
.union([z.string(), ArtifactSpec]) | ||
.array() | ||
.transform((xs) => { | ||
const result: ArtifactSpec[] = []; | ||
for (const x of xs) { | ||
if (is.string(x)) { | ||
const [group, artifact, version] = x.split(':'); | ||
if (group && artifact && version) { | ||
result.push({ group, artifact, version }); | ||
} | ||
} else { | ||
result.push(x); | ||
} | ||
} | ||
|
||
return result; | ||
}), | ||
repositories: z.array(z.string()).optional(), | ||
}) | ||
.transform( | ||
({ | ||
rule: depType, | ||
artifacts, | ||
repositories: registryUrls, | ||
}): PackageDependency[] => | ||
artifacts.map(({ group, artifact, version: currentValue }) => ({ | ||
datasource: MavenDatasource.id, | ||
depName: `${group}:${artifact}`, | ||
currentValue, | ||
depType, | ||
registryUrls, | ||
})) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters