Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@salesforce/kit": "^1.5.32",
"@salesforce/ts-types": "^1.4.2",
"archiver": "^5.3.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the third party dependency that got the deal done. https://www.npmjs.com/package/deasync. MIT licensed and around 1M downloads a week so seemed a safe choice. I'm following up on what I need to do for 3PP land.

"deasync": "^0.1.24",
"fast-xml-parser": "^3.17.4",
"graceful-fs": "^4.2.8",
"ignore": "^5.1.8",
Expand All @@ -41,6 +42,7 @@
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "^1.1.2",
"@types/archiver": "^5.1.1",
"@types/deasync": "^0.1.2",
"@types/deep-equal-in-any-order": "^1.0.1",
"@types/jsforce": "^1.9.38",
"@types/mime": "2.0.3",
Expand Down
19 changes: 17 additions & 2 deletions src/resolve/treeContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { join, dirname, basename, normalize, sep } from 'path';
import { Readable } from 'stream';
import { statSync, existsSync, readdirSync, createReadStream, readFileSync } from 'graceful-fs';
import * as unzipper from 'unzipper';
import deasync = require('deasync');
import { baseName, parseMetadataXml } from '../utils';
import { LibraryError } from '../errors';
import { SourcePath } from '../common';
Expand Down Expand Up @@ -166,9 +167,23 @@ export class ZipTreeContainer extends TreeContainer {
throw new LibraryError('error_expected_file_path', fsPath);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public readFileSync(fsPath: string): Buffer {
throw new Error('Method not implemented');
let done = false;
let dataBuffer: Buffer;
this.readFile(fsPath)
.then((buffer) => {
dataBuffer = buffer;
done = true;
})
.catch((error) => {
done = true;
throw error;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module covers doing exactly the ask here. Do something async but treat the current flow and synchronous.

deasync.loopWhile(() => {
return !done;
});
return dataBuffer;
}

public stream(fsPath: string): Readable {
Expand Down
15 changes: 13 additions & 2 deletions test/resolve/treeContainers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,19 @@ describe('Tree Containers', () => {
});

describe('readFileSync', () => {
it('should throw an error because it is not implemented yet', () => {
assert.throws(() => tree.readFileSync(join(filesRoot, 'test.txt')), Error, 'Method not implemented');
it('should syncrounsly read contents of zip entry into buffer.', () => {
const path = join(filesRoot, 'test.txt');
const contents = tree.readFileSync(path).toString();
expect(contents).to.equal('test text');
});

it('should throw a library error if readFile throws', () => {
assert.throws(
// eslint-disable-next-line @typescript-eslint/no-misused-promises
() => tree.readFileSync(filesRoot),
LibraryError,
nls.localize('error_expected_file_path', filesRoot)
);
});
});

Expand Down
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==

"@types/deasync@^0.1.2":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@types/deasync/-/deasync-0.1.2.tgz#a64b68d6ebc145d0a5fe004a53e8e0f4e6d2ec7e"
integrity sha512-sCBFlGCEmZMPS06wdnQELcYzyUYio2K1Hp6g0fjJSKP1jkGKQpIdjRNUQAvdSCCJCWxIMCkX2CL7pi4BCm8Ydg==

"@types/deep-equal-in-any-order@^1.0.1":
version "1.0.1"
resolved "https://registry.npmjs.org/@types/deep-equal-in-any-order/-/deep-equal-in-any-order-1.0.1.tgz#0559d855797a5034e187f248b23a4490e5444f2e"
Expand Down Expand Up @@ -1367,6 +1372,13 @@ binary@~0.3.0:
buffers "~0.1.1"
chainsaw "~0.1.0"

bindings@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
dependencies:
file-uri-to-path "1.0.0"

bl@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/bl/-/bl-4.0.3.tgz#12d6287adc29080e22a705e5764b2a9522cdc489"
Expand Down Expand Up @@ -2048,6 +2060,14 @@ dayjs@^1.8.16:
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.36.tgz#be36e248467afabf8f5a86bae0de0cdceecced50"
integrity sha512-3VmRXEtw7RZKAf+4Tv1Ym9AGeo8r8+CjDi26x+7SYQil1UqtqdaokhzoEJohqlzt0m5kacJSDhJQkG/LWhpRBw==

deasync@^0.1.24:
version "0.1.24"
resolved "https://registry.yarnpkg.com/deasync/-/deasync-0.1.24.tgz#6ecc9c6ff9eba64a4f4572ae3c4db77fed09268a"
integrity sha512-i98vg42xNfRZCymummMAN0rIcQ1gZFinSe3btvPIvy6JFTaeHcumeKybRo2HTv86nasfmT0nEgAn2ggLZhOCVA==
dependencies:
bindings "^1.5.0"
node-addon-api "^1.7.1"

debug@4.3.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
Expand Down Expand Up @@ -2780,6 +2800,11 @@ file-entry-cache@^6.0.1:
dependencies:
flat-cache "^3.0.4"

file-uri-to-path@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==

fill-range@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7"
Expand Down Expand Up @@ -4752,6 +4777,11 @@ nise@^4.1.0:
just-extend "^4.0.2"
path-to-regexp "^1.7.0"

node-addon-api@^1.7.1:
version "1.7.2"
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-1.7.2.tgz#3df30b95720b53c24e59948b49532b662444f54d"
integrity sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==

node-preload@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/node-preload/-/node-preload-0.2.1.tgz#c03043bb327f417a18fee7ab7ee57b408a144301"
Expand Down