opaque uris and resources interaction
with 0.29, opaque uris are invalid: https://pkl-lang.org/main/current/release-notes/0.29.html#opaque-file-uris-are-invalid
the error message says:
–– Pkl Error ––
Resource URI `file:../path/.manifest.yml` has invalid syntax.
30 | const manifest = yamlParser.parse(read("file:../\(manifestPath)"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at Common#manifest (file:///pkl/Common.pkl, line 30)
File URIs must have a path that starts with `/` (e.g. file:/path/to/my_module.pkl).
To resolve relative paths, remove the scheme prefix (remove "file:").
However, read requires a Resource which mandates the file: prefix.
It is a bit awkward to do
const workingDirectory = read("env:PWD")
const manifest = yamlParser.parse(read("file:\(workingDirectory)/../\(manifestPath)"))
Are there any alternatives?
Is that resource at a relative path to your Pkl file? If so, you'd just pass in the relative path:
const manifest = yamlParser.parse(read("../\(manifestPath)"))
If you do truly want to read relative to the working directory, here's how to do it in a robust, cross-platform way:
https://github.com/apple/pkl-pantry/blob/7a8db5d291bd91b0a1cd0fcc3e6284a167968abf/packages/k8s.contrib.crd/generate.pkl#L98-L107
Is that resource at a relative path to your Pkl file? If so, you'd just pass in the relative path:
const manifest = yamlParser.parse(read("../(manifestPath)"))
this doesn't work, it fails with:
–– Pkl Error ––
Cannot find resource `../path/manifest.yml`.
The prefix in Resource might me mandatory?
The prefix in Resource might me mandatory?
It is not. Reading with relative path reads relative to the module the read is in. If you are intending to read relative to the working directory, you need to use the more verbose invocation I linked above.