balena-request
Advanced tools
Comparing version 14.0.0 to 14.0.1-build-conditional-imports-739b173c101e5a73c1423dd79e213d4da86117a4-1
@@ -122,22 +122,6 @@ "use strict"; | ||
if (!isBrowser && utils.isResponseCompressed(response)) { | ||
const { createGunzip } = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const zlib = require('zlib'); | ||
// Be more lenient with decoding compressed responses, since (very rarely) | ||
// servers send slightly invalid gzip responses that are still accepted | ||
// by common browsers. | ||
// Always using Z_SYNC_FLUSH is what cURL does. | ||
let zlibOptions = { | ||
flush: zlib.constants.Z_SYNC_FLUSH, | ||
finishFlush: zlib.constants.Z_SYNC_FLUSH, | ||
}; | ||
// Allow overriding this behaviour by setting the ZLIB_FLUSH env var | ||
// to one of the allowed zlib flush values (process.env.ZLIB_FLUSH="Z_NO_FLUSH"). | ||
// https://github.com/nodejs/node/blob/master/doc/api/zlib.md#zlib-constants | ||
if (process.env.ZLIB_FLUSH && process.env.ZLIB_FLUSH in zlib.constants) { | ||
zlibOptions = { | ||
flush: zlib.constants[process.env.ZLIB_FLUSH], | ||
finishFlush: zlib.constants[process.env.ZLIB_FLUSH], | ||
}; | ||
} | ||
const gunzip = zlib.createGunzip(zlibOptions); | ||
require('./conditional-imports'); | ||
const gunzip = createGunzip(); | ||
gunzip.on('error', (e) => output.emit('error', e)); | ||
@@ -144,0 +128,0 @@ // Uncompress after or before piping through progress |
@@ -331,11 +331,2 @@ "use strict"; | ||
}; | ||
const getForm = () => { | ||
if (!IS_BROWSER) { | ||
const { FormData: NodeFormData } = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('formdata-node'); | ||
return new NodeFormData(); | ||
} | ||
return new FormData(); | ||
}; | ||
// This is the actual implementation that hides the internal `retriesRemaining` parameter | ||
@@ -366,3 +357,6 @@ async function requestAsync(fetch, options, retriesRemaining) { | ||
if (fileKeys.size > 0) { | ||
const form = getForm(); | ||
const { getFormDataConstructor, getFormDataEncoder } = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('./conditional-imports'); | ||
const form = getFormDataConstructor(); | ||
for (const [k, v] of bodyEntries) { | ||
@@ -384,5 +378,3 @@ if (fileKeys.has(k)) { | ||
else { | ||
const { FormDataEncoder } = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('form-data-encoder'); | ||
const FormDataEncoder = getFormDataEncoder(); | ||
const encoder = new FormDataEncoder(form); | ||
@@ -389,0 +381,0 @@ opts.headers.set('Content-Type', encoder.headers['Content-Type']); |
@@ -7,2 +7,6 @@ # Change Log | ||
## 14.0.1 - 2024-12-05 | ||
* Avoid requiring some node dependencies using the package.json browser field [Thodoris Greasidis] | ||
## 14.0.0 - 2024-12-04 | ||
@@ -9,0 +13,0 @@ |
@@ -19,3 +19,4 @@ const getKarmaConfig = require('balena-config-karma'); | ||
util: false, | ||
zlib: require.resolve('browserify-zlib'), | ||
// required by mockttp -> http-encoding | ||
zlib: false, | ||
}; | ||
@@ -22,0 +23,0 @@ karmaConfig.webpack.module.rules.push({ |
@@ -159,31 +159,7 @@ /* | ||
if (!isBrowser && utils.isResponseCompressed(response)) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const zlib = require('zlib') as typeof import('zlib'); | ||
const { createGunzip } = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('./conditional-imports') as typeof import('./conditional-imports'); | ||
// Be more lenient with decoding compressed responses, since (very rarely) | ||
// servers send slightly invalid gzip responses that are still accepted | ||
// by common browsers. | ||
// Always using Z_SYNC_FLUSH is what cURL does. | ||
let zlibOptions = { | ||
flush: zlib.constants.Z_SYNC_FLUSH, | ||
finishFlush: zlib.constants.Z_SYNC_FLUSH, | ||
}; | ||
// Allow overriding this behaviour by setting the ZLIB_FLUSH env var | ||
// to one of the allowed zlib flush values (process.env.ZLIB_FLUSH="Z_NO_FLUSH"). | ||
// https://github.com/nodejs/node/blob/master/doc/api/zlib.md#zlib-constants | ||
if (process.env.ZLIB_FLUSH && process.env.ZLIB_FLUSH in zlib.constants) { | ||
zlibOptions = { | ||
flush: | ||
zlib.constants[ | ||
process.env.ZLIB_FLUSH as keyof typeof zlib.constants | ||
], | ||
finishFlush: | ||
zlib.constants[ | ||
process.env.ZLIB_FLUSH as keyof typeof zlib.constants | ||
], | ||
}; | ||
} | ||
const gunzip = zlib.createGunzip(zlibOptions); | ||
const gunzip = createGunzip(); | ||
gunzip.on('error', (e) => output.emit('error', e)); | ||
@@ -190,0 +166,0 @@ |
@@ -389,13 +389,2 @@ /* | ||
const getForm = (): FormDataNodeType | FormData => { | ||
if (!IS_BROWSER) { | ||
const { FormData: NodeFormData } = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('formdata-node') as typeof import('formdata-node'); | ||
return new NodeFormData(); | ||
} | ||
return new FormData(); | ||
}; | ||
// This is the actual implementation that hides the internal `retriesRemaining` parameter | ||
@@ -433,3 +422,6 @@ async function requestAsync( | ||
if (fileKeys.size > 0) { | ||
const form = getForm(); | ||
const { getFormDataConstructor, getFormDataEncoder } = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('./conditional-imports') as typeof import('./conditional-imports'); | ||
const form = getFormDataConstructor(); | ||
for (const [k, v] of bodyEntries) { | ||
@@ -450,6 +442,3 @@ if (fileKeys.has(k)) { | ||
} else { | ||
const { FormDataEncoder } = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require('form-data-encoder') as typeof import('form-data-encoder'); | ||
const FormDataEncoder = getFormDataEncoder(); | ||
const encoder = new FormDataEncoder(form as FormDataNodeType); | ||
@@ -456,0 +445,0 @@ opts.headers.set('Content-Type', encoder.headers['Content-Type']); |
{ | ||
"name": "balena-request", | ||
"version": "14.0.0", | ||
"version": "14.0.1-build-conditional-imports-739b173c101e5a73c1423dd79e213d4da86117a4-1", | ||
"description": "Balena HTTP client", | ||
@@ -8,2 +8,6 @@ "type": "commonjs", | ||
"types": "build/request.d.ts", | ||
"browser": { | ||
"./build/request.js": "./build/request.js", | ||
"./build/conditional-imports.js": "./build/conditional-imports.browser.js" | ||
}, | ||
"homepage": "https://github.com/balena-io-modules/balena-request", | ||
@@ -87,4 +91,4 @@ "repository": { | ||
"versionist": { | ||
"publishedAt": "2024-12-04T16:35:59.225Z" | ||
"publishedAt": "2024-12-05T18:23:26.082Z" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
236400
39
4568
1