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
Prev Previous commit
Next Next commit
fix: normalize zip file paths before comparison
  • Loading branch information
shetzel committed Oct 20, 2023
commit c47ad100db24fe9e5aacae18a8e2f89542f4c486
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
### Bug Fixes

## [9.7.27](https://github.com/forcedotcom/source-deploy-retrieve/compare/9.7.26...9.7.27) (2023-10-17)

### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions src/client/metadataApiRetrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ export class MetadataApiRetrieve extends MetadataTransfer<
if (this.options.unzip) {
const zip = await JSZip.loadAsync(zipFileContents, { base64: true, createFolders: true });
const extractPath = path.join(this.options.output, path.parse(name).name);
fs.mkdirSync(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?

const zipObj = zip.file(filePath);
if (!zipObj || zipObj?.dir) {
fs.mkdirSync(path.join(extractPath, filePath));
fs.mkdirSync(path.join(extractPath, filePath), { recursive: true });
} else {
// eslint-disable-next-line no-await-in-loop
const content = await zipObj?.async('nodebuffer');
Expand Down
8 changes: 5 additions & 3 deletions src/resolve/treeContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* eslint-disable class-methods-use-this */
import { join, dirname, basename, sep } from 'path';
import { join, dirname, basename, normalize, sep } from 'path';
import { Readable } from 'stream';
import { statSync, existsSync, readdirSync, createReadStream, readFileSync } from 'graceful-fs';
import * as JSZip from 'jszip';
Expand Down Expand Up @@ -191,12 +191,14 @@ export class ZipTreeContainer extends TreeContainer {
}

// Finds a matching entry in the zip by first comparing basenames, then dirnames.
// Note that zip files always use forward slash separators, so paths within the
// zip files are normalized for the OS file system before comparing.
private match(fsPath: string): string | undefined {
const fsPathBasename = basename(fsPath);
const fsPathDirname = dirname(fsPath);
return Object.keys(this.zip.files).find((f) => {
if (basename(f) === fsPathBasename || fsPath === '.') {
return dirname(f) === fsPathDirname;
if (normalize(basename(f)) === fsPathBasename || fsPath === '.') {
return normalize(dirname(f)) === fsPathDirname;
}
});
}
Expand Down