mirror of
https://github.com/apple/pkl.git
synced 2026-05-28 17:49:15 +02:00
Improve handling of evaling dependency notation URIs (#1595)
This commit is contained in:
@@ -190,7 +190,7 @@ data class CliBaseOptions(
|
||||
sourceModules
|
||||
.map { uri ->
|
||||
if (uri.isAbsolute) uri
|
||||
else if (uri.path.startsWith("@") && !noProject && normalizedProjectFile != null) uri
|
||||
else if (uri.path.startsWith("@")) uri
|
||||
else IoUtils.resolve(normalizedWorkingDir.toUri(), uri)
|
||||
}
|
||||
// sort modules to make cli output independent of source module order
|
||||
|
||||
@@ -86,36 +86,6 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun resolveModuleUri(uri: URI): URI =
|
||||
if (uri.isAbsolute) uri
|
||||
else { // must be @dep/mod.pkl notation!!
|
||||
if (!uri.path.startsWith('@'))
|
||||
throw CliBugException(
|
||||
RuntimeException("tried to resolve project URI `$uri` with no @ prefix")
|
||||
)
|
||||
if (project == null)
|
||||
throw CliBugException(
|
||||
RuntimeException("tried to resolve project URI `$uri` with no project present")
|
||||
)
|
||||
val dep = uri.path.substringBefore('/').drop(1)
|
||||
val path = uri.path.dropWhile { it != '/' }
|
||||
if (path.isEmpty()) throw CliException("Invalid project dependency URI `$uri`.")
|
||||
|
||||
val remoteDep =
|
||||
project!!.dependencies.remoteDependencies()[dep]
|
||||
?: if (project!!.dependencies.localDependencies().containsKey(dep))
|
||||
throw CliException(
|
||||
"Only remote project dependencies may be referenced using @-notation. Dependency `@$dep` is a local dependency."
|
||||
)
|
||||
else throw CliException("Project does not contain dependency `@$dep`.")
|
||||
remoteDep.packageUri.toPackageAssetUri(path).uri
|
||||
}
|
||||
|
||||
protected val resolvedSourceModules: List<URI> by lazy {
|
||||
if (project == null) cliOptions.normalizedSourceModules
|
||||
else cliOptions.normalizedSourceModules.map(::resolveModuleUri)
|
||||
}
|
||||
|
||||
protected fun loadProject(projectFile: Path): Project {
|
||||
val securityManager =
|
||||
SecurityManagers.standard(
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
amends "pkl:Project"
|
||||
|
||||
dependencies {
|
||||
["fruit"] { uri = "package://localhost:0/fruit@1.1.0" }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"resolvedDependencies": {
|
||||
"package://localhost:0/fruit@1": {
|
||||
"type": "remote",
|
||||
"uri": "projectpackage://localhost:0/fruit@1.1.0",
|
||||
"checksums": {
|
||||
"sha256": "$skipChecksumVerification"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user