pistazie / cdk-dia

Automated diagrams of CDK provisioned infrastructure
MIT License
863 stars 37 forks source link

Run with yarn dlx or as yarn run show no images #13

Open SvenMarquardt5772 opened 3 years ago

SvenMarquardt5772 commented 3 years ago

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?

pistazie commented 3 years ago

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 dlxand get the diagram with missing icons you can see, that additionally to your diagram.png there is a diagram.png.dotfile 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:

  1. You run CDK-Dia using yarn exec cdk-dia.
  2. You run CDK-Dia using ./node_modules/cdk-dia/bin/cli.js
  3. CDK-Dia uses a different way to resolve the npm package location. one which works for both npx and yarn dlx. currently, the resolution happens here using require.resolve('cdk-dia/package.json').
SvenMarquardt5772 commented 3 years ago

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.