I wanted to use sharp-cli to scale images at <folder>/original/<picture>.png to folder/scaled/<picture>.png. When I used sharp resize 2000 --input "*/original/*.png" --output "{dir}/../scaled/{base}", I got the error ENOENT: no such file or directory, open 'scaled/<picture>.png' because the folder scaled doesn't exist on the project level but only in the subfolders (i.e. <folder>/scaled). (Please take all values in this example figuratively. The error message used an absolute path but I cut the prefix as it's not relevant here, etc.)
After debugging sharp-cli locally, I realized that the problem is not where the output template is processed but rather where the arguments are parsed. So apparently yargs is to blame for this. When looking at
Is there any reason to ask yarg for this normalization (rather than just resolving the path after processing the template)? If not, can you remove this line upstream so that I don't have to run a custom version of sharp-cli on my computer? (If you want, I can make a PR for this.) It cannot be there for security reasons as it's still possible to leave the current working directory with --output "{dir}/../../scaled/{base}" respectively just --output "../generated/{base}".
I wanted to use
sharp-cli
to scale images at<folder>/original/<picture>.png
tofolder/scaled/<picture>.png
. When I usedsharp resize 2000 --input "*/original/*.png" --output "{dir}/../scaled/{base}"
, I got the errorENOENT: no such file or directory, open 'scaled/<picture>.png'
because the folderscaled
doesn't exist on the project level but only in the subfolders (i.e.<folder>/scaled
). (Please take all values in this example figuratively. The error message used an absolute path but I cut the prefix as it's not relevant here, etc.)After debugging
sharp-cli
locally, I realized that the problem is not where the output template is processed but rather where the arguments are parsed. So apparentlyyargs
is to blame for this. When looking athttps://github.com/vseventer/sharp-cli/blob/cf12e80be7d56e229b344643b4213f1bfc154e3f/lib/cli.js#L87-L97
and
yarg
's options documentation, it became clear thatsharp-cli
asksyarg
to normalize the template. After removingnormalize: true,
, I had the behavior I wanted.Is there any reason to ask
yarg
for this normalization (rather than just resolving the path after processing the template)? If not, can you remove this line upstream so that I don't have to run a custom version ofsharp-cli
on my computer? (If you want, I can make a PR for this.) It cannot be there for security reasons as it's still possible to leave the current working directory with--output "{dir}/../../scaled/{base}"
respectively just--output "../generated/{base}"
.