From 7dcd96546180b8db96a6d17f6dba79df4c03ffd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Jel=C3=ADnek?= Date: Wed, 24 Jul 2024 16:23:32 +0200 Subject: [PATCH] fix: migrate unpack from shell exec to unzipper library (#1438) Signed-off-by: Dominik Jelinek --- package-lock.json | 72 +++++++++++++++++++++++++++- packages/extester/package.json | 6 ++- packages/extester/src/util/unpack.ts | 26 +++++----- 3 files changed, 91 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index ed5fefcca..6c2414214 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2145,6 +2145,15 @@ "@types/tar-fs": "*" } }, + "node_modules/@types/unzipper": { + "version": "0.10.9", + "resolved": "https://registry.npmjs.org/@types/unzipper/-/unzipper-0.10.9.tgz", + "integrity": "sha512-vHbmFZAw8emNAOVkHVbS3qBnbr0x/qHQZ+ei1HE7Oy6Tyrptl+jpqnOX+BF5owcu/HZLOV0nJK+K9sjs1Ox2JA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/vscode": { "version": "1.88.0", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.88.0.tgz", @@ -2985,6 +2994,11 @@ "readable-stream": "^3.4.0" } }, + "node_modules/bluebird": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" + }, "node_modules/boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", @@ -4400,6 +4414,41 @@ "integrity": "sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==", "dev": true }, + "node_modules/duplexer2": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", + "integrity": "sha512-asLFVfWWtJ90ZyOUHMqk7/S2w2guQKxUI2itj3d92ADHhxUSbCMGi1f1cBcJ7xM1To+pE/Khbwo1yuNbMEPKeA==", + "dependencies": { + "readable-stream": "^2.0.2" + } + }, + "node_modules/duplexer2/node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/duplexer2/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "node_modules/duplexer2/node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -7994,6 +8043,11 @@ "node": "^16.13.0 || >=18.0.0" } }, + "node_modules/node-int64": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", + "integrity": "sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==" + }, "node_modules/node-machine-id": { "version": "1.1.12", "resolved": "https://registry.npmjs.org/node-machine-id/-/node-machine-id-1.1.12.tgz", @@ -10669,6 +10723,18 @@ "node": ">= 10.0.0" } }, + "node_modules/unzipper": { + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/unzipper/-/unzipper-0.12.2.tgz", + "integrity": "sha512-ecRhBc+ZfQkYnRr8L7OkxvAAWDkqP3Dun9CHUmYYZx/mErGdy7N7ju6ODJ7uKmm9PD99aAG8grxzl5y9lmEK2A==", + "dependencies": { + "bluebird": "~3.7.2", + "duplexer2": "~0.1.4", + "fs-extra": "^11.2.0", + "graceful-fs": "^4.2.2", + "node-int64": "^0.4.0" + } + }, "node_modules/upath": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/upath/-/upath-2.0.1.tgz", @@ -11138,11 +11204,15 @@ "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" }, "bin": { "extest": "out/cli.js" }, + "devDependencies": { + "@types/unzipper": "^0.10.9" + }, "peerDependencies": { "mocha": ">=5.2.0", "typescript": ">=4.6.2" diff --git a/packages/extester/package.json b/packages/extester/package.json index 5ea940526..94a5ec019 100644 --- a/packages/extester/package.json +++ b/packages/extester/package.json @@ -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" } } diff --git a/packages/extester/src/util/unpack.ts b/packages/extester/src/util/unpack.ts index 2bff0ebd9..cbc98516f 100644 --- a/packages/extester/src/util/unpack.ts +++ b/packages/extester/src/util/unpack.ts @@ -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 { + static async unpack(input: PathLike, target: PathLike): Promise { return new Promise((resolve, reject) => { if (input.toString().endsWith('.tar.gz')) { targz.decompress( @@ -38,9 +39,8 @@ 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 { @@ -48,13 +48,17 @@ export class Unpack { } }); } 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) => { + resolve(val); + }) + .catch((err: { message: string | undefined }) => { reject(new Error(err.message)); - } else { - resolve(); - } - }); + }); } } else { reject(`Unsupported extension for '${input}'`);