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

node: Prepare for a larger Npm refactoring #9385

Merged
merged 6 commits into from
Nov 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
package org.ossreviewtoolkit.plugins.packagemanagers.node.utils

import java.io.File
import java.lang.invoke.MethodHandles

import org.apache.logging.log4j.kotlin.logger
import org.apache.logging.log4j.kotlin.loggerOf

import org.ossreviewtoolkit.analyzer.PackageManager.Companion.getFallbackProjectName
import org.ossreviewtoolkit.analyzer.PackageManager.Companion.processPackageVcs
Expand All @@ -37,7 +38,6 @@
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.npm.Npm
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJson
import org.ossreviewtoolkit.utils.common.realFile
import org.ossreviewtoolkit.utils.common.toUri
Expand Down Expand Up @@ -218,7 +218,7 @@

val vcsFromDownloadUrl = VcsHost.parseUrl(downloadUrl)
if (vcsFromDownloadUrl.url != downloadUrl) {
vcsFromPackage = vcsFromPackage.merge(vcsFromDownloadUrl)

Check warning on line 221 in plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt

View check run for this annotation

Codecov / codecov/patch

plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt#L221

Added line #L221 was not covered by tests
}

val module = Package(
Expand All @@ -237,18 +237,20 @@
)

require(module.id.name.isNotEmpty()) {
"Generated package info for '${id.toCoordinates()}' has no name."

Check warning on line 240 in plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt

View check run for this annotation

Codecov / codecov/patch

plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt#L240

Added line #L240 was not covered by tests
}

require(module.id.version.isNotEmpty()) {
"Generated package info for '${id.toCoordinates()}' has no version."

Check warning on line 244 in plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt

View check run for this annotation

Codecov / codecov/patch

plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt#L244

Added line #L244 was not covered by tests
}

return module
}

private val logger = loggerOf(MethodHandles.lookup().lookupClass())
Copy link
Member

@sschuberth sschuberth Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this to the top to make more clear that all functions could make use of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.


internal fun parseProject(packageJsonFile: File, analysisRoot: File, managerName: String): Project {
Npm.logger.debug { "Parsing project info from '$packageJsonFile'." }
logger.debug { "Parsing project info from '$packageJsonFile'." }

val packageJson = parsePackageJson(packageJsonFile)

Expand All @@ -256,14 +258,14 @@
val (namespace, name) = splitNpmNamespaceAndName(rawName)

val projectName = name.ifBlank {
getFallbackProjectName(analysisRoot, packageJsonFile).also {
Npm.logger.warn { "'$packageJsonFile' does not define a name, falling back to '$it'." }
logger.warn { "'$packageJsonFile' does not define a name, falling back to '$it'." }
}

Check warning on line 263 in plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt

View check run for this annotation

Codecov / codecov/patch

plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt#L261-L263

Added lines #L261 - L263 were not covered by tests
}

val version = packageJson.version.orEmpty()
if (version.isBlank()) {
Npm.logger.warn { "'$packageJsonFile' does not define a version." }
logger.warn { "'$packageJsonFile' does not define a version." }

Check warning on line 268 in plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt

View check run for this annotation

Codecov / codecov/patch

plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt#L268

Added line #L268 was not covered by tests
}

val declaredLicenses = packageJson.licenses.mapNpmLicenses()
Expand Down
Loading