Skip to content

Commit 5705ef6

Browse files
authored
Merge pull request #59 from FacturAPI/fix/fix-conditional-stream
Fix conditional stream
2 parents 9251fcc + c309ea5 commit 5705ef6

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [4.4.4] 2024-12-18
9+
10+
### Fixed
11+
12+
- Added try/catch to conditional import and define "stream" as external.
13+
814
## [4.4.3] 2024-12-13
915

1016
### Fixed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "facturapi",
3-
"version": "4.4.3",
3+
"version": "4.4.4",
44
"description": "Librería oficial de Facturapi. Crea CFDIs timbrados y enviados al SAT, XML y PDF",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.es.js",

src/wrapper.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,24 @@ const responseInterceptor = async (response: Response) => {
4242
if (!reader) {
4343
return response.body;
4444
}
45-
const { Readable } = await import('stream');
46-
return new Readable({
47-
read() {
48-
reader.read().then(({ done, value }) => {
49-
if (done) {
50-
this.push(null); // end stream
51-
} else {
52-
this.push(Buffer.from(value)); // push data to stream
53-
}
54-
});
55-
},
56-
});
45+
try {
46+
const { Readable } = await import('stream');
47+
return new Readable({
48+
read() {
49+
reader.read().then(({ done, value }) => {
50+
if (done) {
51+
this.push(null); // end stream
52+
} else {
53+
this.push(Buffer.from(value)); // push data to stream
54+
}
55+
});
56+
},
57+
});
58+
} catch (e) {
59+
throw new Error(
60+
'Node.js streams are not available in this environment. Please install the "stream" package.',
61+
);
62+
}
5763
} else {
5864
return response.blob();
5965
}

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig({
88
fileName: (format) => `index.${format}.js`,
99
},
1010
rollupOptions: {
11-
external: ['form-data'],
11+
external: ['form-data', 'stream'],
1212
output: {
1313
exports: 'named', // Use named exports to avoid the warning
1414
},

0 commit comments

Comments
 (0)