@bigcommerce/stencil-cli 8.10.2 → 8.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @module Contains helpers functions for working with async stuff and streams
2
+ * @module Contains helpers functions for working with streams
3
3
  */
4
+
5
+ import { PassThrough } from 'stream';
6
+
4
7
  /**
5
8
  * WARNING! Can be used with text content only. Binary data (e.g. images) will get broken!
6
9
  *
@@ -14,7 +17,38 @@ async function readFromStream(stream) {
14
17
  }
15
18
  return result;
16
19
  }
17
- export { readFromStream };
20
+
21
+ function readStream(stream) {
22
+ return new Promise((resolve, reject) => {
23
+ let data = '';
24
+ stream.on('data', (chunk) => {
25
+ data += chunk;
26
+ });
27
+ stream.on('end', () => {
28
+ resolve(data);
29
+ });
30
+ stream.on('error', reject);
31
+ });
32
+ }
33
+
34
+ function tapStream(originalStream, onData) {
35
+ const tee = new PassThrough();
36
+ originalStream.pipe(tee);
37
+
38
+ let data = '';
39
+ tee.on('data', (chunk) => {
40
+ data += chunk;
41
+ });
42
+ tee.on('end', () => {
43
+ onData(data);
44
+ });
45
+
46
+ return tee; // Use this stream for downstream consumers
47
+ }
48
+
49
+ export { readFromStream, tapStream, readStream };
18
50
  export default {
19
51
  readFromStream,
52
+ tapStream,
53
+ readStream,
20
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigcommerce/stencil-cli",
3
- "version": "8.10.2",
3
+ "version": "8.10.3",
4
4
  "type": "module",
5
5
  "description": "CLI tool to run BigCommerce Stores locally for theme development.",
6
6
  "main": "index.js",
@@ -9,7 +9,7 @@ import langAssembler from '../../../lib/lang-assembler.js';
9
9
  import { RawResponse, RedirectResponse, PencilResponse } from './responses/index.js';
10
10
  import templateAssembler from '../../../lib/template-assembler.js';
11
11
  import { int2uuid, stripDomainFromCookies, normalizeRedirectUrl } from '../../lib/utils.js';
12
- import { readFromStream } from '../../../lib/utils/asyncUtils.js';
12
+ import { readFromStream, readStream, tapStream } from '../../../lib/utils/asyncUtils.js';
13
13
  import NetworkUtils from '../../../lib/utils/NetworkUtils.js';
14
14
  import contentApiClient from '../../../lib/content-api-client.js';
15
15
  import { getPageType } from '../../lib/page-type-util.js';
@@ -114,9 +114,17 @@ internals.getResponse = async (request) => {
114
114
  // (5xx will be just thrown by axios)
115
115
  const contentType = response.headers['content-type'] || '';
116
116
  const isResponseJson = contentType.toLowerCase().includes('application/json');
117
- const bcAppData = isResponseJson
118
- ? JSON.parse(await readFromStream(response.data))
119
- : response.data;
117
+ const isWebDavRequest = request.path.startsWith('/content');
118
+ let bcAppData = response.data;
119
+
120
+ if (isResponseJson) {
121
+ bcAppData = JSON.parse(await readFromStream(response.data));
122
+ } else if (isWebDavRequest) {
123
+ const tappedStream = tapStream(response.data, (body) => {
124
+ return body;
125
+ });
126
+ bcAppData = await readStream(tappedStream);
127
+ }
120
128
  // cache response
121
129
  cache.put(
122
130
  requestSignature,