1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-27 04:35:25 +00:00

Remove zip library dependency

This commit is contained in:
Anmol Sethi 2020-06-03 18:23:42 -04:00
parent fd5c5960c2
commit c00f931500
No known key found for this signature in database
GPG Key ID: 8CEF1878FF10ADEB
7 changed files with 16 additions and 81 deletions

View File

@ -30,7 +30,7 @@ release_archive() {
local release_name="code-server-$VERSION-$OS-$ARCH" local release_name="code-server-$VERSION-$OS-$ARCH"
if [[ $OS == "linux" ]]; then if [[ $OS == "linux" ]]; then
tar -czf "release-packages/$release_name.tar.gz" --transform "s/^\.\/release-standalone/$release_name/" ./release-standalone 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. # Just exists to make autoupdating from 3.2.0 work again.
mv ./release-standalone "./$release_name" mv ./release-standalone "./$release_name"
zip -r "release-packages/$release_name.zip" "./$release_name" zip -r "release-packages/$release_name.zip" "./$release_name"

View File

@ -29,7 +29,7 @@ _realpath() {
root() { root() {
script="$(_realpath "$0")" script="$(_realpath "$0")"
bin_dir="$(dirname "$script")" bin_dir="$(dirname "$script")"
echo "$(dirname "$bin_dir")" dirname "$bin_dir"
} }
ROOT="$(root)" ROOT="$(root)"

View File

@ -4,7 +4,7 @@ set -euo pipefail
main() { main() {
cd "$(dirname "$0")/../.." cd "$(dirname "$0")/../.."
shfmt -i 2 -w -s -sr $(git ls-files "*.sh") shfmt -i 2 -w -sr $(git ls-files "*.sh")
local prettierExts local prettierExts
prettierExts=( prettierExts=(

View File

@ -30,7 +30,6 @@
}, },
"main": "out/node/entry.js", "main": "out/node/entry.js",
"devDependencies": { "devDependencies": {
"@types/adm-zip": "^0.4.32",
"@types/fs-extra": "^8.0.1", "@types/fs-extra": "^8.0.1",
"@types/http-proxy": "^1.17.4", "@types/http-proxy": "^1.17.4",
"@types/js-yaml": "^3.12.3", "@types/js-yaml": "^3.12.3",
@ -66,7 +65,6 @@
}, },
"dependencies": { "dependencies": {
"@coder/logger": "1.1.11", "@coder/logger": "1.1.11",
"adm-zip": "^0.4.14",
"env-paths": "^2.2.0", "env-paths": "^2.2.0",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"http-proxy": "^1.18.0", "http-proxy": "^1.18.0",

View File

@ -1,5 +1,4 @@
import { field, logger } from "@coder/logger" import { field, logger } from "@coder/logger"
import zip from "adm-zip"
import * as cp from "child_process" import * as cp from "child_process"
import * as fs from "fs-extra" import * as fs from "fs-extra"
import * as http from "http" import * as http from "http"
@ -213,11 +212,7 @@ export class UpdateHttpProvider extends HttpProvider {
const response = await this.requestResponse(url) const response = await this.requestResponse(url)
try { try {
if (downloadPath.endsWith(".tar.gz")) { downloadPath = await this.extractTar(response, downloadPath)
downloadPath = await this.extractTar(response, downloadPath)
} else {
downloadPath = await this.extractZip(response, downloadPath)
}
logger.debug("Downloaded update", field("path", downloadPath)) logger.debug("Downloaded update", field("path", downloadPath))
// The archive should have a directory inside at the top level with the // The archive should have a directory inside at the top level with the
@ -275,40 +270,6 @@ export class UpdateHttpProvider extends HttpProvider {
return downloadPath return downloadPath
} }
private async extractZip(response: Readable, downloadPath: string): Promise<string> {
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. * Given an update return the name for the packaged archived.
*/ */
@ -329,7 +290,7 @@ export class UpdateHttpProvider extends HttpProvider {
if (arch === "x64") { if (arch === "x64") {
arch = "x86_64" 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<Buffer> { private async request(uri: string): Promise<Buffer> {

View File

@ -1,8 +1,6 @@
import zip from "adm-zip"
import * as assert from "assert" import * as assert from "assert"
import * as fs from "fs-extra" import * as fs from "fs-extra"
import * as http from "http" import * as http from "http"
import * as os from "os"
import * as path from "path" import * as path from "path"
import * as tar from "tar-fs" import * as tar from "tar-fs"
import * as zlib from "zlib" import * as zlib from "zlib"
@ -88,28 +86,18 @@ describe("update", () => {
fs.writeFile(path.join(archivePath, archiveName, "node"), `NODE BINARY`), fs.writeFile(path.join(archivePath, archiveName, "node"), `NODE BINARY`),
]) ])
if (os.platform() === "darwin") { await new Promise((resolve, reject) => {
await new Promise((resolve, reject) => { const write = fs.createWriteStream(archivePath + ".tar.gz")
const zipFile = new zip() const compress = zlib.createGzip()
zipFile.addLocalFolder(archivePath) compress.pipe(write)
zipFile.writeZip(archivePath + ".zip", (error) => { compress.on("error", (error) => compress.destroy(error))
return error ? reject(error) : resolve(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(() => { after(() => {

View File

@ -910,13 +910,6 @@
traverse "^0.6.6" traverse "^0.6.6"
unified "^6.1.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": "@types/color-name@^1.1.1":
version "1.1.1" version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" 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" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.1.tgz#e35668de0b402f359de515c5482a1ab9f89a69bf"
integrity sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg== 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: ajv@^6.10.0, ajv@^6.10.2, ajv@^6.5.5:
version "6.12.2" version "6.12.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd"