Skip to content

Commit d14b51a

Browse files
committed
refactor: only the jszip matters
1 parent af53556 commit d14b51a

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/convert/streams.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { createWriteStream, existsSync, promises as fsPromises } from 'graceful-
2121
import { JsonMap } from '@salesforce/ts-types';
2222
import { XMLBuilder } from 'fast-xml-parser';
2323
import { Logger } from '@salesforce/core/logger';
24-
import { Global } from '@salesforce/core';
2524
import { SourceComponent } from '../resolve/sourceComponent';
2625
import { SourcePath } from '../common/types';
2726
import { XML_COMMENT_PROP_NAME, XML_DECL } from '../common/constants';
@@ -41,11 +40,6 @@ export type PromisifiedPipeline = <T extends NodeJS.ReadableStream>(
4140

4241
let promisifiedPipeline: PromisifiedPipeline | undefined; // store it so we don't have to promisify every time
4342

44-
// jszip does not behave well in web environments when retrieving multiple files.
45-
// it has a minified `browser` target which has a v3 ReadableStream, but the extensions are using polyfilles of v4.
46-
// Setting the highWaterMark to 1 seems to fix the issue.
47-
export const getStreamOptions = (): { highWaterMark?: number } => (Global.isWeb ? { highWaterMark: 1 } : {});
48-
4943
export const getPipeline = (): PromisifiedPipeline => {
5044
promisifiedPipeline ??= promisify(cbPipeline);
5145
return promisifiedPipeline;

src/resolve/treeContainers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import JSZip from 'jszip';
2121
import { Messages } from '@salesforce/core/messages';
2222
import { SfError } from '@salesforce/core/sfError';
2323
import { isString } from '@salesforce/ts-types';
24+
import { Global } from '@salesforce/core/global';
2425
import { baseName, parseMetadataXml } from '../utils/path';
2526
import type { SourcePath } from '../common/types';
26-
import { getStreamOptions } from '../convert/streams';
2727
import type { VirtualDirectory } from './types';
2828

2929
Messages.importMessagesDirectory(__dirname);
@@ -203,7 +203,10 @@ export class ZipTreeContainer extends TreeContainer {
203203
if (resolvedPath) {
204204
const jsZipObj = this.zip.file(resolvedPath);
205205
if (jsZipObj && !jsZipObj.dir) {
206-
return new Readable(getStreamOptions()).wrap(jsZipObj.nodeStream());
206+
// jszip does not behave well in web environments when retrieving multiple files.
207+
// it has a minified `browser` target which has a v3 ReadableStream, but the extensions are using polyfilles of v4.
208+
// Setting the highWaterMark to 1 seems to fix the issue.
209+
return new Readable(Global.isWeb ? { highWaterMark: 1 } : {}).wrap(jsZipObj.nodeStream());
207210
}
208211
throw new SfError(messages.getMessage('error_no_directory_stream', [this.constructor.name]), 'LibraryError');
209212
}

0 commit comments

Comments
 (0)