fix(manager/sbt): handle new line after equalities in the file (#15613)

This commit is contained in:
Hasan Awad 2022-05-20 10:50:46 +03:00 committed by GitHub
parent 5afed40ba3
commit e183d4c064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 2 deletions

View file

@ -217,5 +217,46 @@ describe('modules/manager/sbt/extract', () => {
packageFileVersion: undefined,
});
});
it('extract deps when they are defined in a new line', () => {
const content = `
name := "service"
scalaVersion := "2.13.8"
lazy val compileDependencies =
Seq(
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",
"ch.qos.logback" % "logback-classic" % "1.2.10"
)
libraryDependencies ++= compileDependencies`;
expect(extractPackageFile(content)).toMatchObject({
deps: [
{
registryUrls: ['https://repo.maven.apache.org/maven2'],
datasource: 'maven',
depName: 'scala',
packageName: 'org.scala-lang:scala-library',
currentValue: '2.13.8',
separateMinorPatch: true,
},
{
registryUrls: ['https://repo.maven.apache.org/maven2'],
depName: 'com.typesafe.scala-logging:scala-logging',
packageName: 'com.typesafe.scala-logging:scala-logging_2.13',
currentValue: '3.9.4',
datasource: 'sbt-package',
},
{
registryUrls: ['https://repo.maven.apache.org/maven2'],
depName: 'ch.qos.logback:logback-classic',
packageName: 'ch.qos.logback:logback-classic',
currentValue: '1.2.10',
datasource: 'sbt-package',
},
],
packageFileVersion: undefined,
});
});
});
});

View file

@ -1,4 +1,4 @@
import { regEx } from '../../../util/regex';
import { newlineRegex, regEx } from '../../../util/regex';
import { MavenDatasource } from '../../datasource/maven';
import { MAVEN_REPO } from '../../datasource/maven/common';
import { SbtPackageDatasource } from '../../datasource/sbt-package';
@ -347,7 +347,9 @@ export function extractPackageFile(content: string): PackageFile | null {
if (!content) {
return null;
}
const lines = content.split(regEx(/\n/)).map(stripComment);
const equalsToNewLineRe = regEx(/=\s*\n/, 'gm');
const goodContentForParsing = content.replace(equalsToNewLineRe, '=');
const lines = goodContentForParsing.split(newlineRegex).map(stripComment);
const acc: PackageFile & ParseOptions = {
registryUrls: [MAVEN_REPO],