Skip to content

Commit cee874e

Browse files
authored
Support node v18 and drop node v12 (#97)
* Fix stream error propagation for node v16+ * Support node v18, drop node v12 * Update @hapi/file dependency to v3
1 parent c5d7597 commit cee874e

File tree

5 files changed

+48
-17
lines changed

5 files changed

+48
-17
lines changed

.github/workflows/ci-module.yml

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ on:
1010
jobs:
1111
test:
1212
uses: hapijs/.github/.github/workflows/ci-module.yml@master
13+
with:
14+
min-node-version: 14

LICENSE.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Copyright (c) 2012-2019, Sideway Inc, and project contributors
2-
Copyright (c) 2012-2014, Walmart.
1+
Copyright (c) 2012-2022, Project contributors
2+
Copyright (c) 2012-2019, Sideway Inc
3+
Copyright (c) 2012-2014, Walmart.
34
All rights reserved.
45

56
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

lib/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const Wreck = require('@hapi/wreck');
1616

1717

1818
const internals = {
19+
kSubtext: Symbol('subtext'),
1920
decoders: {
2021
gzip: (options) => Zlib.createGunzip(options),
2122
deflate: (options) => Zlib.createInflate(options)
@@ -114,12 +115,12 @@ internals.parse = async function (req, tap, options, contentType) {
114115
internals.decoder = function (source, options) {
115116

116117
const contentEncoding = source.headers['content-encoding'];
117-
const decoders = options.decoders || internals.decoders;
118+
const decoders = options.decoders ?? internals.decoders;
118119
if (!decoders.hasOwnProperty(contentEncoding)) {
119120
return source;
120121
}
121122

122-
const decoderOptions = options.compression && options.compression[contentEncoding] || null;
123+
const decoderOptions = options.compression?.[contentEncoding] ?? null;
123124
const stream = decoders[contentEncoding](decoderOptions);
124125

125126
const orig = stream.emit;
@@ -208,7 +209,7 @@ internals.object = function (options, payload, mime) {
208209
// Form-encoded
209210

210211
if (mime === 'application/x-www-form-urlencoded') {
211-
const parse = options.querystring || Querystring.parse;
212+
const parse = options.querystring ?? Querystring.parse;
212213
return payload.length ? parse(payload.toString('utf8')) : {};
213214
}
214215

@@ -306,7 +307,7 @@ internals.writeFile = function (req, options, stream) {
306307

307308
const promise = new Promise((resolve, reject) => {
308309

309-
const path = File.uniqueFilename(options.uploads || Os.tmpdir());
310+
const path = File.uniqueFilename(options.uploads ?? Os.tmpdir());
310311
const file = Fs.createWriteStream(path, { flags: 'wx' });
311312
const counter = new internals.Counter(options);
312313

package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
]
2121
},
2222
"dependencies": {
23-
"@hapi/boom": "9.x.x",
24-
"@hapi/bourne": "2.x.x",
25-
"@hapi/content": "^5.0.2",
26-
"@hapi/file": "2.x.x",
27-
"@hapi/hoek": "9.x.x",
28-
"@hapi/pez": "^5.0.1",
29-
"@hapi/wreck": "17.x.x"
23+
"@hapi/boom": "^10.0.0",
24+
"@hapi/bourne": "^3.0.0",
25+
"@hapi/content": "^6.0.0",
26+
"@hapi/file": "^3.0.0",
27+
"@hapi/hoek": "^10.0.0",
28+
"@hapi/pez": "^6.0.0",
29+
"@hapi/wreck": "^18.0.0"
3030
},
3131
"devDependencies": {
32-
"@hapi/code": "8.x.x",
33-
"@hapi/eslint-plugin": "5.x.x",
34-
"@hapi/lab": "24.x.x",
35-
"form-data": "3.x.x"
32+
"@hapi/code": "^9.0.0",
33+
"@hapi/eslint-plugin": "*",
34+
"@hapi/lab": "^25.0.1",
35+
"form-data": "^4.0.0"
3636
},
3737
"scripts": {
3838
"test": "lab -a @hapi/code -t 100 -L",

test/esm.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const Code = require('@hapi/code');
4+
const Lab = require('@hapi/lab');
5+
6+
7+
const { before, describe, it } = exports.lab = Lab.script();
8+
const expect = Code.expect;
9+
10+
11+
describe('import()', () => {
12+
13+
let Subtext;
14+
15+
before(async () => {
16+
17+
Subtext = await import('../lib/index.js');
18+
});
19+
20+
it('exposes all methods and classes as named imports', () => {
21+
22+
expect(Object.keys(Subtext)).to.equal([
23+
'default',
24+
'parse'
25+
]);
26+
});
27+
});

0 commit comments

Comments
 (0)