From f00e36b18540a1930c9b92c7f195242c27efb892 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 8 Mar 2022 14:40:18 -0500 Subject: [PATCH] Don't download binaries for unsupported windows Signed-off-by: Sebastian Malton --- build/download_binaries.ts | 29 ++++++----------------------- src/common/utils/once-cell.ts | 7 ++++--- src/common/vars.ts | 12 ++++++------ 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/build/download_binaries.ts b/build/download_binaries.ts index c59ef2d08b..f66a473345 100644 --- a/build/download_binaries.ts +++ b/build/download_binaries.ts @@ -18,7 +18,7 @@ import { getBinaryName, normalizedPlatform } from "../src/common/vars"; const pipeline = promisify(_pipeline); -interface DownloadK8sProxyArgs { +interface BinaryDownloaderArgs { readonly version: string; readonly platform: SupportedPlatform; readonly downloadArch: string; @@ -36,7 +36,7 @@ abstract class BinaryDownloader { return [file]; } - constructor(public readonly args: DownloadK8sProxyArgs, multiBar: MultiBar) { + constructor(public readonly args: BinaryDownloaderArgs, multiBar: MultiBar) { this.bar = multiBar.create(1, 0, args); this.target = path.join(args.baseDir, args.platform, args.fileArch, args.binaryName); } @@ -102,7 +102,7 @@ abstract class BinaryDownloader { class LensK8sProxyDownloader extends BinaryDownloader { protected readonly url: string; - constructor(args: Omit, bar: MultiBar) { + constructor(args: Omit, bar: MultiBar) { const binaryName = getBinaryName("lens-k8s-proxy", { forPlatform: args.platform }); super({ ...args, binaryName }, bar); @@ -113,7 +113,7 @@ class LensK8sProxyDownloader extends BinaryDownloader { class KubectlDownloader extends BinaryDownloader { protected readonly url: string; - constructor(args: Omit, bar: MultiBar) { + constructor(args: Omit, bar: MultiBar) { const binaryName = getBinaryName("kubectl", { forPlatform: args.platform }); super({ ...args, binaryName }, bar); @@ -124,7 +124,7 @@ class KubectlDownloader extends BinaryDownloader { class HelmDownloader extends BinaryDownloader { protected readonly url: string; - constructor(args: Omit, bar: MultiBar) { + constructor(args: Omit, bar: MultiBar) { const binaryName = getBinaryName("helm", { forPlatform: args.platform }); super({ ...args, binaryName }, bar); @@ -188,24 +188,7 @@ async function main() { }, multiBar), ]; - if (normalizedPlatform === "windows") { - downloaders.push( - new LensK8sProxyDownloader({ - version: packageInfo.config.k8sProxyVersion, - platform: normalizedPlatform, - downloadArch: "386", - fileArch: "ia32", - baseDir, - }, multiBar), - new KubectlDownloader({ - version: packageInfo.config.bundledKubectlVersion, - platform: normalizedPlatform, - downloadArch: "386", - fileArch: "ia32", - baseDir, - }, multiBar), - ); - } else { + if (normalizedPlatform !== "windows") { downloaders.push( new LensK8sProxyDownloader({ version: packageInfo.config.k8sProxyVersion, diff --git a/src/common/utils/once-cell.ts b/src/common/utils/once-cell.ts index a080aa61e0..866999e208 100644 --- a/src/common/utils/once-cell.ts +++ b/src/common/utils/once-cell.ts @@ -9,14 +9,14 @@ * It then only calls the function on the first call to `get()` and returns the * same instance/value on every subsequent call. */ -export interface OnceCell { +export interface LazyInitialized { get(): T; } /** * A function to make a `OnceCell` */ -export function onceCell(builder: () => T): OnceCell { +export function lazyInitialized(builder: () => T): LazyInitialized { let value: T | undefined; let called = false; @@ -26,9 +26,10 @@ export function onceCell(builder: () => T): OnceCell { return value; } + value = builder(); called = true; - return value = builder(); + return value; }, }; } diff --git a/src/common/vars.ts b/src/common/vars.ts index df55e6d69d..a899d8129d 100644 --- a/src/common/vars.ts +++ b/src/common/vars.ts @@ -8,7 +8,7 @@ import path from "path"; import { SemVer } from "semver"; import packageInfo from "../../package.json"; import { defineGlobal } from "./utils/defineGlobal"; -import { onceCell } from "./utils/once-cell"; +import { lazyInitialized } from "./utils/once-cell"; export const isMac = process.platform === "darwin"; export const isWindows = process.platform === "win32"; @@ -66,18 +66,18 @@ export function getBinaryName(name: string, { forPlatform = normalizedPlatform } return name; } -export const resourcesDir = onceCell(() => ( +const resourcesDir = lazyInitialized(() => ( isProduction ? process.resourcesPath : path.join(process.cwd(), "binaries", "client", normalizedPlatform) )); -export const baseBinariesDir = onceCell(() => path.join(resourcesDir.get(), normalizedArch)); - +export const baseBinariesDir = lazyInitialized(() => path.join(resourcesDir.get(), normalizedArch)); +export const kubeAuthProxyBinaryName = getBinaryName("lens-k8s-proxy"); export const helmBinaryName = getBinaryName("helm"); -export const helmBinaryPath = onceCell(() => path.join(resourcesDir.get(), helmBinaryName)); +export const helmBinaryPath = lazyInitialized(() => path.join(baseBinariesDir.get(), helmBinaryName)); export const kubectlBinaryName = getBinaryName("kubectl"); -export const kubectlBinaryPath = onceCell(() => path.join(baseBinariesDir.get(), kubectlBinaryName)); +export const kubectlBinaryPath = lazyInitialized(() => path.join(baseBinariesDir.get(), kubectlBinaryName)); // Webpack build paths export const contextDir = process.cwd();