@salesforce/core 4.1.3 → 4.2.0
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.
- package/lib/util/zipWriter.d.ts +2 -3
- package/lib/util/zipWriter.js +23 -40
- package/package.json +6 -7
package/lib/util/zipWriter.d.ts
CHANGED
|
@@ -5,12 +5,11 @@ import { StructuredWriter } from './structuredWriter';
|
|
|
5
5
|
export declare class ZipWriter extends Writable implements StructuredWriter {
|
|
6
6
|
private readonly rootDestination?;
|
|
7
7
|
private zip;
|
|
8
|
-
private
|
|
8
|
+
private zipBuffer?;
|
|
9
|
+
private logger;
|
|
9
10
|
constructor(rootDestination?: string | undefined);
|
|
10
11
|
get buffer(): Buffer;
|
|
11
12
|
addToStore(contents: string | Readable | Buffer, path: string): Promise<void>;
|
|
12
13
|
finalize(): Promise<void>;
|
|
13
14
|
getDestinationPath(): string | undefined;
|
|
14
|
-
private getOutputStream;
|
|
15
|
-
private getInputBuffer;
|
|
16
15
|
}
|
package/lib/util/zipWriter.js
CHANGED
|
@@ -7,62 +7,45 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ZipWriter = void 0;
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
10
|
const stream_1 = require("stream");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
11
|
+
const JSZip = require("jszip");
|
|
12
|
+
const logger_1 = require("../logger");
|
|
13
|
+
const sfError_1 = require("../sfError");
|
|
15
14
|
class ZipWriter extends stream_1.Writable {
|
|
16
15
|
constructor(rootDestination) {
|
|
17
16
|
super({ objectMode: true });
|
|
18
17
|
this.rootDestination = rootDestination;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
this.buffers = [];
|
|
24
|
-
void pipeline(this.zip, this.getOutputStream());
|
|
18
|
+
this.zip = JSZip();
|
|
19
|
+
const destination = rootDestination ? `for: ${rootDestination}` : 'in memory';
|
|
20
|
+
this.logger = logger_1.Logger.childFromRoot(this.constructor.name);
|
|
21
|
+
this.logger.debug(`generating zip ${destination}`);
|
|
25
22
|
}
|
|
26
23
|
get buffer() {
|
|
27
|
-
|
|
24
|
+
if (!this.zipBuffer) {
|
|
25
|
+
throw new sfError_1.SfError('Must finalize the ZipWriter before getting a buffer');
|
|
26
|
+
}
|
|
27
|
+
return this.zipBuffer;
|
|
28
28
|
}
|
|
29
29
|
async addToStore(contents, path) {
|
|
30
|
-
|
|
30
|
+
// Ensure only posix paths are added to zip files
|
|
31
|
+
const posixPath = path.replace(/\\/g, '/');
|
|
32
|
+
this.zip.file(posixPath, contents);
|
|
31
33
|
return Promise.resolve();
|
|
32
34
|
}
|
|
33
35
|
async finalize() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
// compression-/speed+ (0)<---(3)---------->(9) compression+/speed-
|
|
37
|
+
// 3 appears to be a decent balance of compression and speed. It felt like
|
|
38
|
+
// higher values = diminishing returns on compression and made conversion slower
|
|
39
|
+
this.zipBuffer = await this.zip.generateAsync({
|
|
40
|
+
type: 'nodebuffer',
|
|
41
|
+
compression: 'DEFLATE',
|
|
42
|
+
compressionOptions: { level: 3 },
|
|
43
|
+
});
|
|
44
|
+
this.logger.debug('Generated zip complete');
|
|
36
45
|
}
|
|
37
46
|
getDestinationPath() {
|
|
38
47
|
return this.rootDestination;
|
|
39
48
|
}
|
|
40
|
-
getOutputStream() {
|
|
41
|
-
if (this.rootDestination) {
|
|
42
|
-
return (0, fs_1.createWriteStream)(this.rootDestination);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const bufferWritable = new stream_1.Writable();
|
|
46
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
47
|
-
bufferWritable._write = (chunk, encoding, cb) => {
|
|
48
|
-
this.buffers.push(chunk);
|
|
49
|
-
cb();
|
|
50
|
-
};
|
|
51
|
-
return bufferWritable;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async getInputBuffer() {
|
|
55
|
-
if (this.rootDestination) {
|
|
56
|
-
const inputStream = (0, fs_1.createReadStream)(this.rootDestination);
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
inputStream.on('data', (chunk) => {
|
|
59
|
-
this.buffers.push(chunk);
|
|
60
|
-
});
|
|
61
|
-
inputStream.once('end', () => resolve());
|
|
62
|
-
inputStream.once('error', (error) => reject(error));
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
49
|
}
|
|
67
50
|
exports.ZipWriter = ZipWriter;
|
|
68
51
|
//# sourceMappingURL=zipWriter.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"types": "lib/exported.d.ts",
|
|
@@ -41,26 +41,25 @@
|
|
|
41
41
|
"@salesforce/bunyan": "^2.0.0",
|
|
42
42
|
"@salesforce/kit": "^3.0.2",
|
|
43
43
|
"@salesforce/schemas": "^1.5.1",
|
|
44
|
-
"@salesforce/ts-types": "^2.0.
|
|
44
|
+
"@salesforce/ts-types": "^2.0.2",
|
|
45
45
|
"@types/semver": "^7.5.0",
|
|
46
46
|
"ajv": "^8.12.0",
|
|
47
|
-
"archiver": "^5.3.0",
|
|
48
47
|
"change-case": "^4.1.2",
|
|
49
48
|
"debug": "^3.2.7",
|
|
50
49
|
"faye": "^1.4.0",
|
|
51
50
|
"form-data": "^4.0.0",
|
|
52
51
|
"js2xmlparser": "^4.0.1",
|
|
53
|
-
"jsforce": "^2.0.0-beta.
|
|
52
|
+
"jsforce": "^2.0.0-beta.24",
|
|
54
53
|
"jsonwebtoken": "9.0.0",
|
|
54
|
+
"jszip": "3.10.1",
|
|
55
55
|
"proper-lockfile": "^4.1.2",
|
|
56
56
|
"ts-retry-promise": "^0.7.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@salesforce/dev-config": "^4.0.1",
|
|
60
|
-
"@salesforce/dev-scripts": "^5.
|
|
61
|
-
"@salesforce/prettier-config": "^0.0.
|
|
60
|
+
"@salesforce/dev-scripts": "^5.4.2",
|
|
61
|
+
"@salesforce/prettier-config": "^0.0.3",
|
|
62
62
|
"@salesforce/ts-sinon": "^1.4.6",
|
|
63
|
-
"@types/archiver": "^5.3.2",
|
|
64
63
|
"@types/chai-string": "^1.4.2",
|
|
65
64
|
"@types/debug": "0.0.31",
|
|
66
65
|
"@types/jsonwebtoken": "9.0.2",
|