-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Yarn): Add basic support for Corepack [1].
According to the Yarn 2+ documentation, Corepack is the preferred way to install this package manager. If this method is used, the name of the executable has to be determined differently. [1]: https://yarnpkg.com/corepack Signed-off-by: Oliver Heger <oliver.heger@bosch.io>
- Loading branch information
1 parent
1765a15
commit 2119800
Showing
2 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2024 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
package org.ossreviewtoolkit.analyzer | ||
|
||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.engine.spec.tempdir | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.string.shouldContain | ||
|
||
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration | ||
import org.ossreviewtoolkit.model.config.PackageManagerConfiguration | ||
import org.ossreviewtoolkit.model.config.RepositoryConfiguration | ||
import org.ossreviewtoolkit.plugins.packagemanagers.node.Yarn2 | ||
|
||
class Yarn2Test : WordSpec({ | ||
"command" should { | ||
"return the executable defined in yarnrc.yml" { | ||
val workingDir = tempdir() | ||
val executable = "yarn-wrapper.js" | ||
workingDir.resolve(".yarnrc.yml").writeText("yarnPath: $executable") | ||
val executableFile = workingDir.resolve(executable).also { | ||
it.writeText("#!/usr/bin/env node\nconsole.log('yarn')") | ||
} | ||
|
||
val yarn = Yarn2("yarn", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) | ||
val command = yarn.command(workingDir) | ||
|
||
command shouldBe executableFile.absolutePath | ||
} | ||
|
||
"throw if no executable is defined in yarnrc.yml" { | ||
val workingDir = tempdir() | ||
workingDir.resolve(".yarnrc.yml").writeText("someProperty: some-value") | ||
|
||
val yarn = Yarn2("yarn", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) | ||
|
||
val exception = shouldThrow<IllegalArgumentException> { | ||
yarn.command(workingDir) | ||
} | ||
|
||
exception.localizedMessage shouldContain "No Yarn 2+ executable" | ||
} | ||
|
||
"throw if the executable defined in yarnrc.yml does not exist" { | ||
val workingDir = tempdir() | ||
val executable = "non-existing-yarn-wrapper.js" | ||
workingDir.resolve(".yarnrc.yml").writeText("yarnPath: $executable") | ||
|
||
val yarn = Yarn2("yarn", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) | ||
|
||
val exception = shouldThrow<IllegalArgumentException> { | ||
yarn.command(workingDir) | ||
} | ||
|
||
exception.localizedMessage shouldContain executable | ||
} | ||
|
||
"return the default executable name if corepack is enabled" { | ||
val workingDir = tempdir() | ||
val yarn2Options = mapOf("corepackEnabled" to "true") | ||
val analyzerConfiguration = AnalyzerConfiguration( | ||
packageManagers = mapOf("Yarn2" to PackageManagerConfiguration(options = yarn2Options)) | ||
) | ||
|
||
val yarn = Yarn2("Yarn2", workingDir, analyzerConfiguration, RepositoryConfiguration()) | ||
val command = yarn.command(workingDir) | ||
|
||
command shouldBe "yarn" | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters