From c00f931500c0fe3b532da9b9d25c3bf9f6b6b6c9 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 3 Jun 2020 18:23:42 -0400 Subject: [PATCH] Remove zip library dependency --- ci/build/build-packages.sh | 2 +- ci/build/code-server.sh | 2 +- ci/dev/fmt.sh | 2 +- package.json | 2 -- src/node/app/update.ts | 43 ++------------------------------------ test/update.test.ts | 34 ++++++++++-------------------- yarn.lock | 12 ----------- 7 files changed, 16 insertions(+), 81 deletions(-) diff --git a/ci/build/build-packages.sh b/ci/build/build-packages.sh index 5c770a4a8..058a54781 100755 --- a/ci/build/build-packages.sh +++ b/ci/build/build-packages.sh @@ -30,7 +30,7 @@ release_archive() { local release_name="code-server-$VERSION-$OS-$ARCH" if [[ $OS == "linux" ]]; then tar -czf "release-packages/$release_name.tar.gz" --transform "s/^\.\/release-standalone/$release_name/" ./release-standalone - elif [[ "$OS" == "darwin" && "$ARCH" == "x86_64" ]]; then + elif [[ $OS == "darwin" && $ARCH == "x86_64" ]]; then # Just exists to make autoupdating from 3.2.0 work again. mv ./release-standalone "./$release_name" zip -r "release-packages/$release_name.zip" "./$release_name" diff --git a/ci/build/code-server.sh b/ci/build/code-server.sh index 831bcefc4..deb36ac31 100755 --- a/ci/build/code-server.sh +++ b/ci/build/code-server.sh @@ -29,7 +29,7 @@ _realpath() { root() { script="$(_realpath "$0")" bin_dir="$(dirname "$script")" - echo "$(dirname "$bin_dir")" + dirname "$bin_dir" } ROOT="$(root)" diff --git a/ci/dev/fmt.sh b/ci/dev/fmt.sh index b619a7e48..d3bd41915 100755 --- a/ci/dev/fmt.sh +++ b/ci/dev/fmt.sh @@ -4,7 +4,7 @@ set -euo pipefail main() { cd "$(dirname "$0")/../.." - shfmt -i 2 -w -s -sr $(git ls-files "*.sh") + shfmt -i 2 -w -sr $(git ls-files "*.sh") local prettierExts prettierExts=( diff --git a/package.json b/package.json index cd7c45ffc..aa6d1fe63 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ }, "main": "out/node/entry.js", "devDependencies": { - "@types/adm-zip": "^0.4.32", "@types/fs-extra": "^8.0.1", "@types/http-proxy": "^1.17.4", "@types/js-yaml": "^3.12.3", @@ -66,7 +65,6 @@ }, "dependencies": { "@coder/logger": "1.1.11", - "adm-zip": "^0.4.14", "env-paths": "^2.2.0", "fs-extra": "^8.1.0", "http-proxy": "^1.18.0", diff --git a/src/node/app/update.ts b/src/node/app/update.ts index 588e5201c..23cfd88b7 100644 --- a/src/node/app/update.ts +++ b/src/node/app/update.ts @@ -1,5 +1,4 @@ import { field, logger } from "@coder/logger" -import zip from "adm-zip" import * as cp from "child_process" import * as fs from "fs-extra" import * as http from "http" @@ -213,11 +212,7 @@ export class UpdateHttpProvider extends HttpProvider { const response = await this.requestResponse(url) try { - if (downloadPath.endsWith(".tar.gz")) { - downloadPath = await this.extractTar(response, downloadPath) - } else { - downloadPath = await this.extractZip(response, downloadPath) - } + downloadPath = await this.extractTar(response, downloadPath) logger.debug("Downloaded update", field("path", downloadPath)) // The archive should have a directory inside at the top level with the @@ -275,40 +270,6 @@ export class UpdateHttpProvider extends HttpProvider { return downloadPath } - private async extractZip(response: Readable, downloadPath: string): Promise { - logger.debug("Downloading zip", field("path", downloadPath)) - - response.pause() - await fs.remove(downloadPath) - - const write = fs.createWriteStream(downloadPath) - response.pipe(write) - response.on("error", (error) => write.destroy(error)) - response.on("close", () => write.end()) - - await new Promise((resolve, reject) => { - write.on("error", reject) - write.on("close", resolve) - response.resume - }) - - const zipPath = downloadPath - downloadPath = downloadPath.replace(/\.zip$/, "") - await fs.remove(downloadPath) - - logger.debug("Extracting zip", field("path", zipPath)) - - await new Promise((resolve, reject) => { - new zip(zipPath).extractAllToAsync(downloadPath, true, (error) => { - return error ? reject(error) : resolve() - }) - }) - - await fs.remove(zipPath) - - return downloadPath - } - /** * Given an update return the name for the packaged archived. */ @@ -329,7 +290,7 @@ export class UpdateHttpProvider extends HttpProvider { if (arch === "x64") { arch = "x86_64" } - return `code-server-${update.version}-${target}-${arch}.${target === "darwin" ? "zip" : "tar.gz"}` + return `code-server-${update.version}-${target}-${arch}.tar.gz` } private async request(uri: string): Promise { diff --git a/test/update.test.ts b/test/update.test.ts index 18f0d9a6e..8725eb5fb 100644 --- a/test/update.test.ts +++ b/test/update.test.ts @@ -1,8 +1,6 @@ -import zip from "adm-zip" import * as assert from "assert" import * as fs from "fs-extra" import * as http from "http" -import * as os from "os" import * as path from "path" import * as tar from "tar-fs" import * as zlib from "zlib" @@ -88,28 +86,18 @@ describe("update", () => { fs.writeFile(path.join(archivePath, archiveName, "node"), `NODE BINARY`), ]) - if (os.platform() === "darwin") { - await new Promise((resolve, reject) => { - const zipFile = new zip() - zipFile.addLocalFolder(archivePath) - zipFile.writeZip(archivePath + ".zip", (error) => { - return error ? reject(error) : resolve(error) - }) + await new Promise((resolve, reject) => { + const write = fs.createWriteStream(archivePath + ".tar.gz") + const compress = zlib.createGzip() + compress.pipe(write) + compress.on("error", (error) => compress.destroy(error)) + compress.on("close", () => write.end()) + tar.pack(archivePath).pipe(compress) + write.on("close", reject) + write.on("finish", () => { + resolve() }) - } else { - await new Promise((resolve, reject) => { - const write = fs.createWriteStream(archivePath + ".tar.gz") - const compress = zlib.createGzip() - compress.pipe(write) - compress.on("error", (error) => compress.destroy(error)) - compress.on("close", () => write.end()) - tar.pack(archivePath).pipe(compress) - write.on("close", reject) - write.on("finish", () => { - resolve() - }) - }) - } + }) }) after(() => { diff --git a/yarn.lock b/yarn.lock index f8b76db07..2ba7cba62 100644 --- a/yarn.lock +++ b/yarn.lock @@ -910,13 +910,6 @@ traverse "^0.6.6" unified "^6.1.6" -"@types/adm-zip@^0.4.32": - version "0.4.33" - resolved "https://registry.yarnpkg.com/@types/adm-zip/-/adm-zip-0.4.33.tgz#ea5b94f771443f655613b64f920c0555867200dd" - integrity sha512-WM0DCWFLjXtddl0fu0+iN2ZF+qz8RF9RddG5OSy/S90AQz01Fu8lHn/3oTIZDxvG8gVcnBLAHMHOdBLbV6m6Mw== - dependencies: - "@types/node" "*" - "@types/color-name@^1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" @@ -1130,11 +1123,6 @@ acorn@^7.1.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.1.tgz#e35668de0b402f359de515c5482a1ab9f89a69bf" integrity sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg== -adm-zip@^0.4.14: - version "0.4.14" - resolved "https://registry.yarnpkg.com/adm-zip/-/adm-zip-0.4.14.tgz#2cf312bcc9f8875df835b0f6040bd89be0a727a9" - integrity sha512-/9aQCnQHF+0IiCl0qhXoK7qs//SwYE7zX8lsr/DNk1BRAHYxeLZPL4pguwK29gUEqasYQjqPtEpDRSWEkdHn9g== - ajv@^6.10.0, ajv@^6.10.2, ajv@^6.5.5: version "6.12.2" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd"