From b8a6975f6789e7467006f5a155bb2542fabe93e2 Mon Sep 17 00:00:00 2001 From: Pierre Cavin Date: Fri, 27 Dec 2024 22:26:31 +0100 Subject: [PATCH] feat(mix): implement depType parsing --- lib/modules/manager/mix/__fixtures__/mix.exs | 1 + lib/modules/manager/mix/extract.ts | 39 +++++++++++++------- lib/modules/manager/mix/readme.md | 5 +++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/modules/manager/mix/__fixtures__/mix.exs b/lib/modules/manager/mix/__fixtures__/mix.exs index 8e96800cbf7e796..8cf6fc4503bacbe 100644 --- a/lib/modules/manager/mix/__fixtures__/mix.exs +++ b/lib/modules/manager/mix/__fixtures__/mix.exs @@ -36,6 +36,7 @@ defmodule MyProject.MixProject do {:another_gun, "~> 0.4.0", hex: :raygun}, {:credo, "~> 1.7", only: [:test, + # prod, :dev], runtime: false} ] diff --git a/lib/modules/manager/mix/extract.ts b/lib/modules/manager/mix/extract.ts index 3d9c45e00d74f4f..6957a49bd273010 100644 --- a/lib/modules/manager/mix/extract.ts +++ b/lib/modules/manager/mix/extract.ts @@ -20,6 +20,8 @@ const lockedVersionRegExp = regEx( /^\s+"(?\w+)".*?"(?\d+\.\d+\.\d+)"/, ); const hexRegexp = regEx(/hex:\s*(?:"(?[^"]+)"|:(?\w+))/); +const onlyValueRegexp = /only:\s*(?\[[^\]]*\]|:\w+)/; +const onlyEnvironmentsRegexp = /:(\w+)/gm; export async function extractPackageFile( content: string, @@ -48,22 +50,28 @@ export async function extractPackageFile( const hexGroups = hexRegexp.exec(opts)?.groups; const hex = hexGroups?.strValue ?? hexGroups?.atomValue; - let dep: PackageDependency; + const onlyValue = onlyValueRegexp.exec(opts)?.groups?.only; + const onlyEnvironments = []; + let match; + if (onlyValue) { + while ((match = onlyEnvironmentsRegexp.exec(onlyValue)) !== null) { + onlyEnvironments.push(match[1]); + } + } + + const dep: PackageDependency = { + depName: app, + depType: "dependencies" + }; if (git ?? github) { - dep = { - depName: app, - currentDigest: ref, - currentValue: branchOrTag, - datasource: git ? GitTagsDatasource.id : GithubTagsDatasource.id, - packageName: git ?? github, - }; + dep.currentDigest = ref; + dep.currentValue = branchOrTag; + dep.datasource = git ? GitTagsDatasource.id : GithubTagsDatasource.id; + dep.packageName = git ?? github; } else { - dep = { - depName: app, - currentValue: requirement, - datasource: HexDatasource.id, - }; + dep.currentValue = requirement; + dep.datasource = HexDatasource.id; if (organization) { dep.packageName = `${app}:${organization}`; } else if (hex) { @@ -71,11 +79,16 @@ export async function extractPackageFile( } else { dep.packageName = app; } + if (requirement?.startsWith('==')) { dep.currentVersion = requirement.replace(regEx(/^==\s*/), ''); } } + if (onlyValue !== undefined && !onlyEnvironments.includes("prod")) { + dep.depType = "devDependencies" + } + deps.set(app, dep); logger.trace({ dep }, `setting ${app}`); depMatchGroups = depMatchRegExp.exec(depBuffer)?.groups; diff --git a/lib/modules/manager/mix/readme.md b/lib/modules/manager/mix/readme.md index f63ab44019224e3..803601d38711e0c 100644 --- a/lib/modules/manager/mix/readme.md +++ b/lib/modules/manager/mix/readme.md @@ -1,3 +1,8 @@ The `mix` manager extracts dependencies for the `hex` datasource and uses Renovate's implementation of Hex SemVer to evaluate updates. The `mix` package manager itself is also used to keep the lock file up-to-date. + +The following `depTypes` are currently supported by the npm manager : + +- `dependencies` +- `devDependencies`