Skip to content

Commit

Permalink
refactor(package-managers): Align on lowercase lockfile in var names
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Mar 15, 2024
1 parent 16ee7fd commit fde139f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions plugins/package-managers/bundler/src/main/kotlin/Bundler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ class Bundler(
// [2]: https://github.com/jruby/jruby/discussions/7403

val lockfiles = definitionFiles.map { it.resolveSibling(BUNDLER_LOCKFILE_NAME) }.filter { it.isFile }
val lockFilesBundlerVersion = lockfiles.mapNotNull {
val lockfilesBundlerVersion = lockfiles.mapNotNull {
parseBundlerVersionFromLockfile(it)
}.sortedWith(AlphaNumericComparator).lastOrNull()

val bundlerVersion = options[OPTION_BUNDLER_VERSION] ?: lockFilesBundlerVersion
val bundlerVersion = options[OPTION_BUNDLER_VERSION] ?: lockfilesBundlerVersion

if (bundlerVersion != null) {
val duration = measureTime {
Expand Down
32 changes: 16 additions & 16 deletions plugins/package-managers/composer/src/main/kotlin/Composer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ class Composer(
return listOf(result)
}

val lockFile = ensureLockFile(workingDir)
val lockfile = ensureLockFile(workingDir)

logger.info { "Parsing lock file at '$lockFile'..." }
logger.info { "Parsing lock file at '$lockfile'..." }

val json = jsonMapper.readTree(lockFile)
val json = jsonMapper.readTree(lockfile)
val packages = parseInstalledPackages(json)

// Let's also determine the "virtual" (replaced and provided) packages. These can be declared as
Expand All @@ -157,18 +157,18 @@ class Composer(
private fun parseScope(
scopeName: String,
manifest: JsonNode,
lockFile: JsonNode,
lockile: JsonNode,
packages: Map<String, Package>,
virtualPackages: Set<String>
): Scope {
val requiredPackages = manifest[scopeName].fieldNamesOrEmpty().asSequence()
val dependencies = buildDependencyTree(requiredPackages, lockFile, packages, virtualPackages)
val dependencies = buildDependencyTree(requiredPackages, lockile, packages, virtualPackages)
return Scope(scopeName, dependencies)
}

private fun buildDependencyTree(
dependencies: Sequence<String>,
lockFile: JsonNode,
lockfile: JsonNode,
packages: Map<String, Package>,
virtualPackages: Set<String>,
dependencyBranch: List<String> = emptyList()
Expand All @@ -191,9 +191,9 @@ class Composer(
}

try {
val runtimeDependencies = getRuntimeDependencies(packageName, lockFile)
val runtimeDependencies = getRuntimeDependencies(packageName, lockfile)
val transitiveDependencies = buildDependencyTree(
runtimeDependencies, lockFile, packages, virtualPackages, dependencyBranch + packageName
runtimeDependencies, lockfile, packages, virtualPackages, dependencyBranch + packageName
)
packageReferences += packageInfo.toReference(dependencies = transitiveDependencies)
} catch (e: IOException) {
Expand Down Expand Up @@ -278,11 +278,11 @@ class Composer(
}

private fun ensureLockFile(workingDir: File): File {
val lockFile = workingDir.resolve(COMPOSER_LOCK_FILE)
val lockfile = workingDir.resolve(COMPOSER_LOCK_FILE)

val hasLockFile = lockFile.isFile
val hasLockFile = lockfile.isFile
requireLockfile(workingDir) { hasLockFile }
if (hasLockFile) return lockFile
if (hasLockFile) return lockfile

val composerVersion = Semver(getVersion(workingDir))
val args = listOfNotNull(
Expand All @@ -293,7 +293,7 @@ class Composer(

run(workingDir, *args.toTypedArray())

return lockFile
return lockfile
}
}

Expand All @@ -307,9 +307,9 @@ private fun String.isPlatformDependency(): Boolean =
private val COMPOSER_PLATFORM_TYPES = setOf("composer", "composer-plugin-api", "composer-runtime-api")
private val PHP_PLATFORM_TYPES = setOf("php", "php-64bit", "php-ipv6", "php-zts", "php-debug")

private fun getRuntimeDependencies(packageName: String, lockFile: JsonNode): Sequence<String> {
private fun getRuntimeDependencies(packageName: String, lockfile: JsonNode): Sequence<String> {
listOf("packages", "packages-dev").forEach {
lockFile[it]?.forEach { packageInfo ->
lockfile[it]?.forEach { packageInfo ->
if (packageInfo["name"].textValueOrEmpty() == packageName) {
val requiredPackages = packageInfo["require"]
if (requiredPackages != null && requiredPackages.isObject) {
Expand Down Expand Up @@ -355,7 +355,7 @@ private fun parseVcsInfo(packageInfo: JsonNode): VcsInfo =
private fun parseVirtualPackageNames(
packages: Map<String, Package>,
manifest: JsonNode,
lockFile: JsonNode
lockfile: JsonNode
): Set<String> {
val replacedNames = mutableSetOf<String>()

Expand All @@ -364,7 +364,7 @@ private fun parseVirtualPackageNames(
replacedNames += parseVirtualNames(manifest)

listOf("packages", "packages-dev").forEach { type ->
lockFile[type]?.flatMap { pkgInfo ->
lockfile[type]?.flatMap { pkgInfo ->
parseVirtualNames(pkgInfo)
}?.let {
replacedNames += it
Expand Down
24 changes: 12 additions & 12 deletions plugins/package-managers/node/src/main/kotlin/utils/NpmDetection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class NpmDetection(private val definitionFiles: Collection<File>) {
* An enum of all supported Node package managers.
*/
enum class NodePackageManager(
val lockFileName: String,
val lockfileName: String,
val markerFileName: String? = null,
val workspaceFileName: String = NodePackageManager.DEFINITION_FILE
) {
Expand All @@ -135,27 +135,27 @@ enum class NodePackageManager(
},

YARN("yarn.lock") {
private val lockFileMarker = "# yarn lockfile v1"
private val lockfileMarker = "# yarn lockfile v1"

override fun hasLockFile(projectDir: File): Boolean {
val lockFile = projectDir.resolve(lockFileName)
if (!lockFile.isFile) return false
val lockfile = projectDir.resolve(lockfileName)
if (!lockfile.isFile) return false

return lockFile.useLines { lines ->
lines.take(2).lastOrNull() == lockFileMarker
return lockfile.useLines { lines ->
lines.take(2).lastOrNull() == lockfileMarker
}
}
},

YARN2("yarn.lock", markerFileName = ".yarnrc.yml") {
private val lockFileMarker = "__metadata:"
private val lockfileMarker = "__metadata:"

override fun hasLockFile(projectDir: File): Boolean {
val lockFile = projectDir.resolve(lockFileName)
if (!lockFile.isFile) return false
val lockfile = projectDir.resolve(lockfileName)
if (!lockfile.isFile) return false

return lockFile.useLines { lines ->
lines.take(4).lastOrNull() == lockFileMarker
return lockfile.useLines { lines ->
lines.take(4).lastOrNull() == lockfileMarker
}
}
};
Expand Down Expand Up @@ -190,7 +190,7 @@ enum class NodePackageManager(
/**
* Return true if the [projectDir] contains a lock file for this package manager, or return false otherwise.
*/
open fun hasLockFile(projectDir: File): Boolean = hasNonEmptyFile(projectDir, lockFileName)
open fun hasLockFile(projectDir: File): Boolean = hasNonEmptyFile(projectDir, lockfileName)

/**
* If the [projectDir] contains a workspace file for this package manager, return the list of package patterns, or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class NpmDetectionTest : WordSpec({
"All Node package manager detections" should {
"ignore empty lock files" {
NodePackageManager.entries.forAll {
val lockFile = tempdir().resolve(it.lockFileName).apply {
val lockfile = tempdir().resolve(it.lockfileName).apply {
writeText("")
}

it.hasLockFile(lockFile.parentFile) shouldBe false
it.hasLockFile(lockfile.parentFile) shouldBe false
}
}

Expand All @@ -72,8 +72,8 @@ class NpmDetectionTest : WordSpec({
"return only those managers whose lock files are present" {
val projectDir = tempdir().apply {
resolve("package.json").writeText("{}")
resolve(NPM.lockFileName).writeText("{}")
resolve(PNPM.lockFileName).writeText("#")
resolve(NPM.lockfileName).writeText("{}")
resolve(PNPM.lockfileName).writeText("#")
}

NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(NPM, PNPM)
Expand All @@ -82,7 +82,7 @@ class NpmDetectionTest : WordSpec({
"return only NPM if distinguished by lock file" {
val projectDir = tempdir().apply {
resolve("package.json").writeText("{}")
resolve(NPM.lockFileName).writeText("{}")
resolve(NPM.lockfileName).writeText("{}")
}

NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(NPM)
Expand All @@ -100,7 +100,7 @@ class NpmDetectionTest : WordSpec({
"return only PNPM if distinguished by lock file" {
val projectDir = tempdir().apply {
resolve("package.json").writeText("{}")
resolve(PNPM.lockFileName).writeText("#")
resolve(PNPM.lockfileName).writeText("#")
}

NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(PNPM)
Expand All @@ -118,7 +118,7 @@ class NpmDetectionTest : WordSpec({
"return only YARN if distinguished by lock file" {
val projectDir = tempdir().apply {
resolve("package.json").writeText("{}")
resolve(YARN.lockFileName).writeText(YARN_LOCK_FILE_HEADER)
resolve(YARN.lockfileName).writeText(YARN_LOCK_FILE_HEADER)
}

NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(YARN)
Expand All @@ -127,7 +127,7 @@ class NpmDetectionTest : WordSpec({
"return only YARN2 if distinguished by lock file" {
val projectDir = tempdir().apply {
resolve("package.json").writeText("{}")
resolve(YARN2.lockFileName).writeText(YARN2_LOCK_FILE_HEADER)
resolve(YARN2.lockfileName).writeText(YARN2_LOCK_FILE_HEADER)
}

NodePackageManager.forDirectory(projectDir).shouldContainExactlyInAnyOrder(YARN2)
Expand All @@ -136,11 +136,11 @@ class NpmDetectionTest : WordSpec({

"NPM detection" should {
"recognize lock files" {
val lockFile = tempdir().resolve(NPM.lockFileName).apply {
val lockfile = tempdir().resolve(NPM.lockfileName).apply {
writeText("{}")
}

NPM.hasLockFile(lockFile.parentFile) shouldBe true
NPM.hasLockFile(lockfile.parentFile) shouldBe true
}

"parse workspace files" {
Expand Down Expand Up @@ -171,11 +171,11 @@ class NpmDetectionTest : WordSpec({

"PNPM detection" should {
"recognize lock files" {
val lockFile = tempdir().resolve(PNPM.lockFileName).apply {
val lockfile = tempdir().resolve(PNPM.lockfileName).apply {
writeText("lockfileVersion: '6.0'")
}

PNPM.hasLockFile(lockFile.parentFile) shouldBe true
PNPM.hasLockFile(lockfile.parentFile) shouldBe true
}

"parse workspace files" {
Expand Down Expand Up @@ -204,11 +204,11 @@ class NpmDetectionTest : WordSpec({

"Yarn detection" should {
"recognize lock files" {
val lockFile = tempdir().resolve(YARN.lockFileName).apply {
val lockfile = tempdir().resolve(YARN.lockfileName).apply {
writeText(YARN_LOCK_FILE_HEADER)
}

YARN.hasLockFile(lockFile.parentFile) shouldBe true
YARN.hasLockFile(lockfile.parentFile) shouldBe true
}

"parse workspace files" {
Expand All @@ -234,11 +234,11 @@ class NpmDetectionTest : WordSpec({

"Yarn2 detection" should {
"recognize lock files" {
val lockFile = tempdir().resolve(YARN2.lockFileName).apply {
val lockfile = tempdir().resolve(YARN2.lockfileName).apply {
writeText(YARN2_LOCK_FILE_HEADER)
}

YARN2.hasLockFile(lockFile.parentFile) shouldBe true
YARN2.hasLockFile(lockfile.parentFile) shouldBe true
}

"parse workspace files" {
Expand Down
4 changes: 2 additions & 2 deletions plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class PubFunTest : WordSpec({
"resolve dart http dependencies correctly".config(enabled = false) {
val definitionFile = getAssetFile("projects/external/dart-http/pubspec.yaml")
val expectedResultFile = getAssetFile("projects/external/dart-http-expected-output.yml")
val lockFile = definitionFile.resolveSibling("pubspec.lock").also {
val lockfile = definitionFile.resolveSibling("pubspec.lock").also {
getAssetFile("projects/external/dart-http-pubspec.lock").copyTo(it, overwrite = true)
}

val result = try {
create("Pub", allowDynamicVersions = true).resolveSingleProject(definitionFile)
} finally {
lockFile.delete()
lockfile.delete()
}

result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
Expand Down
Loading

0 comments on commit fde139f

Please sign in to comment.