Skip to content

Commit 54c4954

Browse files
committed
Avoid depending on Node's 'util' module for promisify()
Historically this wasn't a problem as bundlers would automatically include polyfills for Node modules, but that's no longer true (in Webpack 5 it's mildly awkward, and with ESBuild even more so) so it's useful to avoid these where possible.
1 parent 65c703a commit 54c4954

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@
4646
"homepage": "https://github.com/httptoolkit/http-encoding#readme",
4747
"dependencies": {
4848
"brotli-wasm": "^1.1.0",
49+
"pify": "^5.0.0",
4950
"zstd-codec": "^0.1.4"
5051
},
5152
"devDependencies": {
5253
"@types/chai": "^4.2.18",
5354
"@types/chai-as-promised": "^7.1.4",
5455
"@types/mocha": "^8.2.2",
5556
"@types/node": "^15.3.0",
57+
"@types/pify": "^5.0.1",
5658
"assert": "^2.0.0",
5759
"browserify-zlib": "^0.2.0",
5860
"buffer": "^6.0.3",

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import * as zlib from 'zlib';
2-
import { promisify } from 'util';
32
import type { ZstdStreaming } from 'zstd-codec';
43

4+
// We want promisify, but for easy browser usage downstream we want to avoid using Node's util
5+
// version. We replace it with pify, but we import util here purely to get the more accurate types.
6+
import { promisify as utilPromisify } from 'util';
7+
const promisify: typeof utilPromisify = require('pify');
8+
59
export type SUPPORTED_ENCODING =
610
| 'identity'
711
| 'gzip'

0 commit comments

Comments
 (0)