cdk-dia
cdk-dia copied to clipboard
Run with yarn dlx or as yarn run show no images
If I run cdk-dia with yarn dlx or after added to the project as yarn run, all images are missing. Installing it globally fixes this. Is there any way to get debug output from cdk-dia so see what is missing here?
Hi Sven,
What is happening here?
For this purpose we'll say that CDK-Dia works in two stages:
A. Create a Dot language graph representation of the infrastructure (99% of CDK-Dia's code)
B. Exucute the Graphviz dot
binary on A. (that's why you need to install Graphviz)
In Step A CDK-Dia creates an absolute path for each icon. the icons are part of the npm package.
When you execute yarn dlx
and get the diagram with missing icons you can see, that additionally to your diagram.png
there is a diagram.png.dot
file created
Inspecting this file shows the absolute icon paths look like:
/Users/*******/.yarn/berry/cache/cdk-dia-npm-0.3.0-b3abf495df-7.zip/node_modules/cdk-dia/icons/aws
- which is not available when the dot
binary (stage B) runs - this is why the icons are missing.
When CDK-Dia
is ran using npx cdk-dia
the paths are like:
/Users/*******/yourProjectPath/node_modules/cdk-dia/icons/aws
- which is available when the dot
binary runs.
Apparently yarn dlx
"Runs a package in a temporary environment." and that is the issue.
Possible fixes / workarounds:
- You run CDK-Dia using
yarn exec cdk-dia
. - You run CDK-Dia using
./node_modules/cdk-dia/bin/cli.js
- CDK-Dia uses a different way to resolve the npm package location. one which works for both
npx
andyarn dlx
. currently, the resolution happens here usingrequire.resolve('cdk-dia/package.json')
.
So, currently there is no way to use this with yarn 2. I have to first install it with yarn 1 globally and then execute cdk-dia in the project. yarn exec cdk-dia only works if cdk-dia is in my path. There is no node_modules path anymore.