Skip to content

Commit

Permalink
feat(mix): implement depType parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Dec 27, 2024
1 parent 384da77 commit b8a6975
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions lib/modules/manager/mix/__fixtures__/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defmodule MyProject.MixProject do
{:another_gun, "~> 0.4.0", hex: :raygun},
{:credo, "~> 1.7", only:
[:test,
# prod,
:dev],
runtime: false}
]
Expand Down
39 changes: 26 additions & 13 deletions lib/modules/manager/mix/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const lockedVersionRegExp = regEx(
/^\s+"(?<app>\w+)".*?"(?<lockedVersion>\d+\.\d+\.\d+)"/,
);
const hexRegexp = regEx(/hex:\s*(?:"(?<strValue>[^"]+)"|:(?<atomValue>\w+))/);
const onlyValueRegexp = /only:\s*(?<only>\[[^\]]*\]|:\w+)/;
const onlyEnvironmentsRegexp = /:(\w+)/gm;

export async function extractPackageFile(
content: string,
Expand Down Expand Up @@ -48,34 +50,45 @@ 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) {
dep.packageName = hex;
} 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;
Expand Down
5 changes: 5 additions & 0 deletions lib/modules/manager/mix/readme.md
Original file line number Diff line number Diff line change
@@ -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`

0 comments on commit b8a6975

Please sign in to comment.