Skip to content

NodeJS SDK - Export Container type - #5141

Merged
grouville merged 4 commits into
mainfrom
sdk-nodejs-export-type
May 17, 2023
Merged

grouville merged 4 commits into
mainfrom
sdk-nodejs-export-type

Conversation

@slumbering

Copy link
Copy Markdown
Contributor

To properly use typescript with the Node.js SDK, it should export more types.

In order to fix the cookbook PR #5139, this PR will only cover Container type.

Additional PRs will be developed subsequently to accommodate other types.

@crjm crjm left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to avoid VSCode from complaining when importing the Container type in the pipeline.

This is the pipeline:

import Client, { connect, Container } from "@dagger.io/dagger"
// create Dagger client
connect(async (client: Client) => {
    // setup container and
    // define environment variables
    const ctr = client
        .container()
        .from("alpine")
        .with(envVariables({
            ENV_VAR_1: "VALUE 1",
            ENV_VAR_2: "VALUE 2",
            ENV_VAR_3: "VALUE 3",
        }))
        .withExec(["env"])

    // print environment variables
    console.log(await ctr.stdout())
}, { LogOutput: process.stderr })


function envVariables(envs: Record<string, string>) {
    return (c: Container): Container => {
        Object.entries(envs).forEach(([key, value]) => {
            c = c.withEnvVariable(key, value)
        })
        return c
    }
}

This is my dagger/sdk/nodejs/dist/index.ts

import Client, { Container } from "./api/client.gen.js"

export { gql } from "graphql-tag"
export { GraphQLClient } from "graphql-request"

export { connect, ConnectOpts, CallbackFct } from "./connect.js"

export default Client
export { Container }

I get Module '"@dagger.io/dagger"' has no exported member 'Container'. Did you mean to use 'import Container from "@dagger.io/dagger"' instead?

Things I tried:

  • Unlinked the @dagger.io/dagger repo, and relinked it.
  • Removed the node_modules folder, linked the @dagger.io/dagger package again.
  • Reloaded the TS server.
  • Reloaded the window.

The pipeline runs ok, but I don't know why TS static checking is not happy.

Comment thread sdk/nodejs/index.ts Resolved
@slumbering
slumbering force-pushed the sdk-nodejs-export-type branch 2 times, most recently from bc21886 to aa414a7 Compare May 17, 2023 09:23
@slumbering

Copy link
Copy Markdown
Contributor Author

Pushing a fix for tests now

@crjm

crjm commented May 17, 2023

Copy link
Copy Markdown
Contributor

I just pushed a fix that updates the imports in /dagger/sdk/nodejs/index.ts and sdk/nodejs/api/test/api.spec.ts.

  • All tests are 🟢
  • I can import any Type from my pipelines.

image

As discussed with @grouville, I pushed the commit so we can unblock PR #5139

@grouville
grouville force-pushed the sdk-nodejs-export-type branch from 7b281db to 01fee00 Compare May 17, 2023 18:28

@grouville grouville left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works perfectly, thanks for this add-on 🙏 ✅

@grouville
grouville merged commit 0c1d7fc into main May 17, 2023
@grouville
grouville deleted the sdk-nodejs-export-type branch May 17, 2023 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants