Skip to content

Commit

Permalink
fix(manager/sbt): support more seq constructors (#12541)
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnhoekstra committed Dec 10, 2021
1 parent a9d3348 commit bdbcd61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/manager/sbt/__fixtures__/dependency-file.scala
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
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

0 comments on commit bdbcd61

Please sign in to comment.