Skip to content

Commit

Permalink
Remove the esm wrapper, rely on commonjs autodetection (#599)
Browse files Browse the repository at this point in the history
* Remove the esm wrapper, rely on commonjs autodetection

Fixes #598
  • Loading branch information
mcollina authored Mar 17, 2021
1 parent 60c1ea0 commit 2366fa3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ function undici (url, opts) {
return new Pool(url, opts)
}

undici.Pool = Pool
undici.Client = Client
undici.errors = errors
module.exports = undici

undici.Agent = Agent
undici.request = request
undici.stream = stream
undici.pipeline = pipeline
undici.setGlobalAgent = setGlobalAgent
module.exports.Pool = Pool
module.exports.Client = Client
module.exports.errors = errors

module.exports = undici
module.exports.Agent = Agent
module.exports.request = request
module.exports.stream = stream
module.exports.pipeline = pipeline
module.exports.setGlobalAgent = setGlobalAgent
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "An HTTP/1.1 client, written from scratch for Node.js",
"main": "index.js",
"types": "index.d.ts",
"module": "wrapper.mjs",
"scripts": {
"lint": "standard | snazzy",
"test": "tap test/*.js --no-coverage && jest test/jest/test",
Expand Down Expand Up @@ -44,6 +43,7 @@
"proxy": "^1.0.2",
"proxyquire": "^2.0.1",
"sinon": "^9.2.4",
"semver": "^5.7.1",
"snazzy": "^8.0.0",
"standard": "^14.3.4",
"tap": "^14.10.8",
Expand Down
27 changes: 16 additions & 11 deletions test/esm-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
'use strict'
const semver = require('semver')

;(async () => {
try {
await import('./esm-wrapper.mjs')
} catch (e) {
if (e.message === 'Not supported') {
require('tap') // shows skipped
return
if (!semver.satisfies(process.version, '>= v14.13.0 || ^12.20.0')) {
require('tap') // shows skipped
} else {
;(async () => {
try {
await import('./esm-wrapper.mjs')
} catch (e) {
if (e.message === 'Not supported') {
require('tap') // shows skipped
return
}
console.error(e.stack)
process.exitCode = 1
}
console.error(e.stack)
process.exitCode = 1
}
})()
})()
}
13 changes: 12 additions & 1 deletion test/esm-wrapper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import tap from 'tap'

import { createServer } from 'http'

import { Client, errors } from '../wrapper.mjs'
import { Client, errors, Pool, Agent, request, stream, pipeline, setGlobalAgent } from '../index.js'

const { test } = tap

Expand Down Expand Up @@ -76,3 +76,14 @@ test('imported errors work with request args validation promise', (t) => {
t.ok(err instanceof errors.InvalidArgumentError)
})
})

test('name dexports', (t) => {
t.is(typeof Client, 'function')
t.is(typeof Pool, 'function')
t.is(typeof Agent, 'function')
t.is(typeof request, 'function')
t.is(typeof stream, 'function')
t.is(typeof pipeline, 'function')
t.is(typeof setGlobalAgent, 'function')
t.end()
})
7 changes: 0 additions & 7 deletions wrapper.mjs

This file was deleted.

0 comments on commit 2366fa3

Please sign in to comment.