Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESM wrapper for named imports #369

Merged
merged 5 commits into from
Aug 29, 2020
Merged

Add ESM wrapper for named imports #369

merged 5 commits into from
Aug 29, 2020

Conversation

talentlessguy
Copy link
Contributor

Hello, I'd like to add ESM wrapper to be able to use named imports in Node ESM, like this:

import { Client } from 'undici'

const client = new Client(`http://example.com`)

client.request({
  path: '/',
  method: 'GET'
}, function (err, data) {
  if (err) {
    // handle this in some way!
    return
  }

  const {
    statusCode,
    headers,
    body
  } = data

  console.log('response received', statusCode)
  console.log('headers', headers)

  body.setEncoding('utf8')
  body.on('data', console.log)

  client.close()
})

I simply wrapped the index.js file and put a "module" field to package.json

Do I need to do any other work, or it is ok as it is now?

thanks in advance for PR feedback

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Can you please add a unit test for this? Thanks.

@talentlessguy
Copy link
Contributor Author

Can you please add a unit test for this? Thanks.

pardon for forgetting to do it, going to add it soon and write back here

@talentlessguy
Copy link
Contributor Author

talentlessguy commented Aug 29, 2020

@mcollina I added the tests, they passed on all environments, except macOS Node 14.X

And the error seems to drop in another place that I haven't even touched: https://github.com/nodejs/undici/pull/369/checks?check_run_id=1044833326#step:5:6274

 not ok 8 - should be equal
          ---
          found: true
          wanted: false
          compare: ===
          at:
            line: 92
            column: 7
            file: test/tls.js
          stack: |
            test/tls.js:92:7
            lib/client-request.js:90:14
          source: |2
                t.strictEqual(didDisconnect, true)
                t.strictEqual(client[kSocket].authorized, false)
            ------^
                t.ok(err)
              })
          ...
        
        ok 9 - expect truthy value
        # failed 1 of 9 tests

not sure what is causing it, but is not my ESM wrapper because it is not used in that test suite that fails

What should I do in this case? 🤔

@ronag
Copy link
Member

ronag commented Aug 29, 2020

not sure what is causing it, but is not my ESM wrapper because it is not used in that test suite that fails

It's a flaky test not related. I'm investigating it.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit e7f8a37 into nodejs:master Aug 29, 2020
@talentlessguy
Copy link
Contributor Author

yaaay it got merged :DD

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.

3 participants