#Fix typescript blueprints

1 messages Β· Page 1 of 1 (latest)

runic horizon
#

I have this PR with a fix in the typescript SDK introspection https://github.com/dagger/dagger/pull/11018
a bit about blueprints here https://deploy-preview-11013--devel-docs-dagger-io.netlify.app/getting-started/quickstarts/blueprint

Basically in typescript, and only typescript, introspection fails because its looking for the "main" module name and not the blueprint module's name (error snippet in PR)

Chatting with @desert sun , i'm confused how this works fine in go and python without sdk modification. If I create a go module that doesn't have an object matching the module's name, it fails, but no issues with blueprints

#

and I think with this fix, that expected error case of missing an object that matches the module name would no longer be an error in typescript, which is not intended. I will add a test for this

desert sun
#

I have an idea

#

But on Typescript I already do the check

#

What we could do in typescript is:

  • Check for the main object (easier to then introspect)
  • If no main object: loop through all classes and consider each class as main to make sure we explore everything

In case of regular module, the CLI side error will create a failure but in case of blueprint, the objects will be there

runic horizon
desert sun
#

Yeah exactly

So like instead of

    const mainDaggerObject = new DaggerObject(mainObjectNode.node, this.ast)

    this.objects[this.name] = mainDaggerObject
    this.references[this.name] = {
      kind: TypeDefKind.ObjectKind,
      name: this.name,
    }

    this.resolveReferences(mainDaggerObject.getReferences())
    this.propagateReferences()

You would loop through all class, and call the exact same logic

#

I would suggest to add the loop no matter the case, but just create a 1 item array if the mainObject is found

#

So you can simply create a new private method that either look for the main object or return all classes instead

#

As ResolvedNodeWithSymbol<T>[]

#

Them boom loop over it and here we go it's fixed

#

Make sure to update typescripts tests since we verify that it errors out if the main object isn't found

#

I let you do it so you can gain knowledge on the TS sdk but feel free to ping if you have any issue πŸ˜„

runic horizon
#

Awesome thank you, i will work on those changes!

worldly heron
#

Thanks for doing this @runic horizon and sorry for not catching this pretty major gap in the feature πŸ˜…

runic horizon
runic horizon
desert sun
#

Hmm

#

Yeah no description I think, because it's only for cloud

runic horizon
#

got it that makes sense. it should only apply to blueprints

desert sun
#

Yeah exactly

runic horizon
#

so it wouldn't apply here

runic horizon
#

all green @desert sun https://github.com/dagger/dagger/pull/11018
the findAllDeclarations function kind of bothers me because its 99% the same as findResolvedNodeByName but even moving the main logic out to a new function will result in more code than it is now πŸ€·β€β™‚οΈ

GitHub

Blueprint modules in typescript were failing to load during introspection because it was looking for the wrong main object name between the main module and blueprint module.
I added tests to confir...

desert sun
worldly heron
#

Fix typescript blueprints