Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replaces unzipper library with jszip #1086

Merged
merged 9 commits into from
Oct 30, 2023
Merged

Conversation

shetzel
Copy link
Contributor

@shetzel shetzel commented Aug 23, 2023

What does this PR do?

replaces unzipper library with jszip. This will reduce dependencies since we are already using JSZip in this library for zipping metadata for a deploy. This affects StaticResouces unzipping in certain scenarios, unzipping retrieved metadata in mdapi format, and the ZipTreeContainer internal implementation.

What issues does this PR fix or reference?

@W-13520613@

Testing:
It's probably easiest to link this branch of the library to a CLI plugin, either plugin-source or plugin-deploy-retrieve

  1. retrieve metadata in mdapi format and use the --unzip flag
  2. retrieve a static resource that is zipped and needs unzipping to merge with files in a project. An example of this scenario is retrieving the bike_assets static resource from the ebikes-lwc repo.

@shetzel shetzel requested a review from a team as a code owner August 23, 2023 17:59
const extractPath = path.join(this.options.output, path.parse(name).name);
await dir.extract({ path: extractPath });
fs.mkdirSync(extractPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

checking my understanding: we need these mkdir/writeFile to be done sequentially to make sure the mkdir happens before any files that would go inside it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and I have no reason to believe that doing them async provides any perf boost.

for (const filePath of Object.keys(zip.files)) {
const zipObj = zip.file(filePath);
if (!zipObj || zipObj?.dir) {
fs.mkdirSync(path.join(extractPath, filePath));
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason we need the sync versions since the method is async?

Copy link
Contributor

Choose a reason for hiding this comment

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

meta: I'm imagining something that iterates zip.files and does all the mkdir in one Promise.all and then all the writeFile in another Promise.all would be be faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it would be faster, and I think it would make the code harder to read/debug. We can test it out though if you want.

src/resolve/treeContainers.ts Show resolved Hide resolved
src/resolve/treeContainers.ts Show resolved Hide resolved
const extractPath = path.join(this.options.output, path.parse(name).name);
await dir.extract({ path: extractPath });
fs.mkdirSync(extractPath, { recursive: true });
for (const filePath of Object.keys(zip.files)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

was it faster serially?


private constructor(directory: unzipper.CentralDirectory) {
private constructor(zip: JSZip) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this avoids the declaration on 127 and the assignment on 131.

Suggested change
private constructor(zip: JSZip) {
private constructor(private zip: JSZip) {

@WillieRuemmele
Copy link
Member

QA Notes


built and linked into plugin-source

✅ : force mdapi retrieve --retrievetargetdir force-app --unpackaged package.xml --unzip --wait 4 of static resources
✅ : right up to the limit of SR

 ➜  du -sh force-app/main/default/staticresources/sample_data_brokers.json
3.6M	force-app/main/default/staticresources/sample_data_brokers.json

 ➜  sf project deploy start                                                                        
Deploying v58.0 metadata to test-wobioos3usus@example.com using the v59.0 SOAP API.
Deploy ID: 0Af8D00000pTsQZSA0
Status: Failed | ████████████████████████████████████████ | 1/1 Components (Errors:1) | 0/0 Tests (Errors:0)

Component Failures [1]
=========================================================================
| Type  Name                Problem                           Line:Column 
| ───── ─────────────────── ───────────────────────────────── ─────────── 
| Error sample_data_brokers static resource cannot exceed 5MB  

✅ : upload .zip SR to the org, retrieve it, unzip it, delete it, zip it, flip it, copy, (Daft Punk)🕺


🪟

✅ : performed all of the same tests on a windows machine to verify

@WillieRuemmele WillieRuemmele merged commit 6bc0c12 into main Oct 30, 2023
66 checks passed
@WillieRuemmele WillieRuemmele deleted the sh/remove-unzipper branch October 30, 2023 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants