grafana / cuetsy

Experimental CUE->TypeScript exporter
Apache License 2.0
106 stars 8 forks source link

Import Mapping Fails for CUE standard library imports #103

Open IfSentient opened 1 year ago

IfSentient commented 1 year ago

When creating a lineage which imports a piece of the CUE standard library, such as time, cuetsy errors on codegen with:

generating TS for child elements of schema failed: a corresponding typescript import is not available for "time" for input "customkind"

Example CUE lineage file:

package foo

import (
    "time"
    "github.com/grafana/thema"
)

customKind: thema.#Lineage & {
    name: "customkind"
    schemas: [{
        version: [0,0]
        schema: {
            spec: {
                timestamp: string & time.Time @cuetsy(kind="string")
            }
        }
    }]
}

Currently, this can be remedied with a custom import mapper in the cuetsy.Config, or using cuetsy.IgnoreImportMapper, so it doesn't block codegen.

sdboyer commented 1 year ago

Thanks for the issue!

IMO the simplest fix here is probably just not calling the provided ImportMapper func for all cue stdlib package imports. If needed, we could allow also providing mappings for stdlib packages in a later change.