terrastruct / d2

D2 is a modern diagram scripting language that turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
18.05k stars 442 forks source link

[0.6.7] Importing classes that imports icon variables #2191

Closed fguinez closed 1 week ago

fguinez commented 2 weeks ago

The problem

I found an issue when importing classes that in turn import icon variables. This fails in 0.6.7, but works in 0.6.6.

The errors only occur when I use imports from c.d2 as icons. I tried changing icon: to label: in b.d2 and it worked. I tried importing everything from a.d2 and it works too, but this doesn't really fit my use case.

I am not sure but maybe it is something related to #2066, because the error message indicates that a remote image has been detected as a local image. But I don't know why this happens with this specific importing structure.

How to replicate

I have the following files in the same directory:

# a.d2 (the file to compile)
...@b.d2

a1: {
    class: Ecs
}

a2: {
    class: Lambda
}

a1 -> a2
# b.d2 (the file with the classes)
...@c.d2

classes: {
    Ecs: {
        shape: "circle"
        icon: ${icons.ecs}
    }

    Lambda: {
        shape: "hexagon"
        icon: ${icons.lambda}
    }
}
# c.d2 (the file with the icons)
vars: {
    icons: {
        ecs: "https://icons.terrastruct.com/aws%2FCompute%2FAmazon-Elastic-Container-Service.svg"
        lambda: "https://icons.terrastruct.com/aws%2FCompute%2FAWS-Lambda.svg"
    }    
}

Depending on the version of D2 that I'm using, the behavior is different.

image
Errors
err: failed to bundle .: read .: is a directory
err: failed to compile -: failed to bundle local images: [.]

Set up

alixander commented 1 week ago

@fguinez Appreciate the 💯 report