Skip to content

Commit

Permalink
fix: migrate unpack from shell exec to unzipper library (#1438)
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek authored Jul 24, 2024
1 parent 5fdf8cc commit 7dcd965
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 13 deletions.
72 changes: 71 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/extester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@
"js-yaml": "^4.1.0",
"sanitize-filename": "^1.6.3",
"selenium-webdriver": "^4.23.0",
"targz": "^1.0.1"
"targz": "^1.0.1",
"unzipper": "^0.12.2"
},
"peerDependencies": {
"mocha": ">=5.2.0",
"typescript": ">=4.6.2"
},
"devDependencies": {
"@types/unzipper": "^0.10.9"
}
}
26 changes: 15 additions & 11 deletions packages/extester/src/util/unpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
* limitations under the License.
*/

import * as fs from 'fs-extra';
import { exec } from 'child_process';
import { PathLike } from 'fs-extra';
import unzip from 'unzipper';
import targz from 'targz';
import { exec } from 'child_process';

export class Unpack {
static unpack(input: fs.PathLike, target: fs.PathLike): Promise<void> {
static async unpack(input: PathLike, target: PathLike): Promise<void> {
return new Promise((resolve, reject) => {
if (input.toString().endsWith('.tar.gz')) {
targz.decompress(
Expand All @@ -38,23 +39,26 @@ export class Unpack {
},
);
} else if (input.toString().endsWith('.zip')) {
fs.mkdirpSync(target.toString());
if (process.platform === 'darwin' || process.platform === 'linux') {
exec(`cd ${target} && unzip -qo ${input.toString()}`, (err) => {
exec(`unzip -qo ${input.toString()}`, { cwd: target.toString() }, (err) => {
if (err) {
reject(new Error(err.message));
} else {
resolve();
}
});
} else {
exec(`cd ${target} && tar -xvf ${input.toString()}`, (err) => {
if (err) {
// WINDOWS, ...
unzip.Open.file(`${input.toString()}`)
.then((d: { extract: (arg0: { path: string; concurrency: number }) => any }) =>
d.extract({ path: `${target.toString()}`, concurrency: 5 }),
)
.then((val: void | PromiseLike<void>) => {
resolve(val);
})
.catch((err: { message: string | undefined }) => {
reject(new Error(err.message));
} else {
resolve();
}
});
});
}
} else {
reject(`Unsupported extension for '${input}'`);
Expand Down

0 comments on commit 7dcd965

Please sign in to comment.