Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manager/sbt): support more seq constructors #12541

Merged
merged 9 commits into from
Dec 10, 2021
2 changes: 1 addition & 1 deletion lib/manager/sbt/__fixtures__/dependency-file.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ object Dependencies {
"com.abc" % "abc-b" % abcVersion
)

val aloneDepInSeq = Seq("com.abc" % "abc-c" % abcVersion)
val aloneDepInSeq = List("com.abc" % "abc-c" % abcVersion)
}
17 changes: 11 additions & 6 deletions lib/manager/sbt/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ const getScalaVersionVariable = (str: string): string =>

const isResolver = (str: string): boolean =>
regEx(
/^\s*(resolvers\s*\+\+?=\s*(Seq\()?)?"[^"]*"\s*at\s*"[^"]*"[\s,)]*$/
/^\s*(resolvers\s*\+\+?=\s*((Seq|List|Stream)\()?)?"[^"]*"\s*at\s*"[^"]*"[\s,)]*$/
).test(str);
const getResolverUrl = (str: string): string =>
str
.replace(regEx(/^\s*(resolvers\s*\+\+?=\s*(Seq\()?)?"[^"]*"\s*at\s*"/), '')
.replace(
regEx(
/^\s*(resolvers\s*\+\+?=\s*((Seq|List|Stream)\()?)?"[^"]*"\s*at\s*"/
),
''
)
.replace(regEx(/"[\s,)]*$/), '');

const isVarDependency = (str: string): boolean =>
Expand All @@ -94,12 +99,12 @@ const isVarDef = (str: string): boolean =>

const isVarSeqSingleLine = (str: string): boolean =>
regEx(
/^\s*(private\s*)?(lazy\s*)?val\s+[_a-zA-Z][_a-zA-Z0-9]*\s*=\s*Seq\(.*\).*\s*$/
/^\s*(private\s*)?(lazy\s*)?val\s+[_a-zA-Z][_a-zA-Z0-9]*\s*=\s*(Seq|List|Stream)\(.*\).*\s*$/
).test(str);

const isVarSeqMultipleLine = (str: string): boolean =>
regEx(
/^\s*(private\s*)?(lazy\s*)?val\s+[_a-zA-Z][_a-zA-Z0-9]*\s*=\s*Seq\(.*[^)]*.*$/
/^\s*(private\s*)?(lazy\s*)?val\s+[_a-zA-Z][_a-zA-Z0-9]*\s*=\s*(Seq|List|Stream)\(.*[^)]*.*$/
).test(str);

const getVarName = (str: string): string =>
Expand Down Expand Up @@ -250,14 +255,14 @@ function parseSbtLine(
} else if (isVarSeqSingleLine(line)) {
isMultiDeps = false;
const depExpr = line
.replace(regEx(/^.*Seq\(\s*/), '')
.replace(regEx(/^.*(Seq|List|Stream)\(\s*/), '')
.replace(regEx(/\).*$/), '');
dep = parseDepExpr(depExpr, {
...ctx,
});
} else if (isVarSeqMultipleLine(line)) {
isMultiDeps = true;
const depExpr = line.replace(regEx(/^.*Seq\(\s*/), '');
const depExpr = line.replace(regEx(/^.*(Seq|List|Stream)\(\s*/), '');
dep = parseDepExpr(depExpr, {
...ctx,
});
Expand Down