Skip to content

Commit 2366fa3

Browse files
authored
Remove the esm wrapper, rely on commonjs autodetection (#599)
* Remove the esm wrapper, rely on commonjs autodetection Fixes #598
1 parent 60c1ea0 commit 2366fa3

5 files changed

Lines changed: 38 additions & 29 deletions

File tree

index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ function undici (url, opts) {
1515
return new Pool(url, opts)
1616
}
1717

18-
undici.Pool = Pool
19-
undici.Client = Client
20-
undici.errors = errors
18+
module.exports = undici
2119

22-
undici.Agent = Agent
23-
undici.request = request
24-
undici.stream = stream
25-
undici.pipeline = pipeline
26-
undici.setGlobalAgent = setGlobalAgent
20+
module.exports.Pool = Pool
21+
module.exports.Client = Client
22+
module.exports.errors = errors
2723

28-
module.exports = undici
24+
module.exports.Agent = Agent
25+
module.exports.request = request
26+
module.exports.stream = stream
27+
module.exports.pipeline = pipeline
28+
module.exports.setGlobalAgent = setGlobalAgent

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "An HTTP/1.1 client, written from scratch for Node.js",
55
"main": "index.js",
66
"types": "index.d.ts",
7-
"module": "wrapper.mjs",
87
"scripts": {
98
"lint": "standard | snazzy",
109
"test": "tap test/*.js --no-coverage && jest test/jest/test",
@@ -44,6 +43,7 @@
4443
"proxy": "^1.0.2",
4544
"proxyquire": "^2.0.1",
4645
"sinon": "^9.2.4",
46+
"semver": "^5.7.1",
4747
"snazzy": "^8.0.0",
4848
"standard": "^14.3.4",
4949
"tap": "^14.10.8",

test/esm-wrapper.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
'use strict'
2+
const semver = require('semver')
23

3-
;(async () => {
4-
try {
5-
await import('./esm-wrapper.mjs')
6-
} catch (e) {
7-
if (e.message === 'Not supported') {
8-
require('tap') // shows skipped
9-
return
4+
if (!semver.satisfies(process.version, '>= v14.13.0 || ^12.20.0')) {
5+
require('tap') // shows skipped
6+
} else {
7+
;(async () => {
8+
try {
9+
await import('./esm-wrapper.mjs')
10+
} catch (e) {
11+
if (e.message === 'Not supported') {
12+
require('tap') // shows skipped
13+
return
14+
}
15+
console.error(e.stack)
16+
process.exitCode = 1
1017
}
11-
console.error(e.stack)
12-
process.exitCode = 1
13-
}
14-
})()
18+
})()
19+
}

test/esm-wrapper.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import tap from 'tap'
22

33
import { createServer } from 'http'
44

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

77
const { test } = tap
88

@@ -76,3 +76,14 @@ test('imported errors work with request args validation promise', (t) => {
7676
t.ok(err instanceof errors.InvalidArgumentError)
7777
})
7878
})
79+
80+
test('name dexports', (t) => {
81+
t.is(typeof Client, 'function')
82+
t.is(typeof Pool, 'function')
83+
t.is(typeof Agent, 'function')
84+
t.is(typeof request, 'function')
85+
t.is(typeof stream, 'function')
86+
t.is(typeof pipeline, 'function')
87+
t.is(typeof setGlobalAgent, 'function')
88+
t.end()
89+
})

wrapper.mjs

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)