From c0cd76d40e5ccd5104d30be7f310f0419d9180c1 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Wed, 7 Aug 2024 11:46:05 +0200 Subject: [PATCH 1/6] Debug log for proxy config --- src/bin/shared/buildContext.ts | 4 ++++ src/bin/tools/fetchProxyOptions.ts | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/bin/shared/buildContext.ts b/src/bin/shared/buildContext.ts index d5811e75..88a2760f 100644 --- a/src/bin/shared/buildContext.ts +++ b/src/bin/shared/buildContext.ts @@ -670,6 +670,10 @@ export function getBuildContext(params: { throw error; } + console.log( + `The root of the NPM project should be "${pathRelative(process.cwd(), dirPath) || "."}"` + ); + return dirPath; })(0) }), diff --git a/src/bin/tools/fetchProxyOptions.ts b/src/bin/tools/fetchProxyOptions.ts index c4e0d90c..e9767f5c 100644 --- a/src/bin/tools/fetchProxyOptions.ts +++ b/src/bin/tools/fetchProxyOptions.ts @@ -19,6 +19,9 @@ export function getProxyFetchOptions(params: { }) .toString("utf8"); + console.log("Output of `npm config get`:"); + console.log(output); + return output .split("\n") .filter(line => !line.startsWith(";")) @@ -36,18 +39,35 @@ export function getProxyFetchOptions(params: { ); })(); + console.log("npm config get object"); + console.log(cfg); + const proxy = ensureSingleOrNone(cfg["https-proxy"] ?? cfg["proxy"]); + + console.log("proxy", proxy); + const noProxy = cfg["noproxy"] ?? cfg["no-proxy"]; + console.log("noProxy", noProxy); + function maybeBoolean(arg0: string | undefined) { return typeof arg0 === "undefined" ? undefined : Boolean(arg0); } const strictSSL = maybeBoolean(ensureSingleOrNone(cfg["strict-ssl"])); + + console.log("strictSSL", strictSSL); + const cert = cfg["cert"]; + + console.log("cert", cert); const ca = ensureArray(cfg["ca"] ?? cfg["ca[]"]); + + console.log("ca", ca); const cafile = ensureSingleOrNone(cfg["cafile"]); + console.log("cafile", cafile); + if (typeof cafile !== "undefined" && cafile !== "null") { ca.push( ...(() => { @@ -72,13 +92,17 @@ export function getProxyFetchOptions(params: { ); } - return { + const out = { proxy, noProxy, strictSSL, cert, ca: ca.length === 0 ? undefined : ca }; + + console.log("Final proxy options", out); + + return out; } function ensureArray(arg0: T | T[]) { From 5fa9c3879c8228943b61d3ab1b28b81eba903a23 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Wed, 7 Aug 2024 11:48:02 +0200 Subject: [PATCH 2/6] Release candidate --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8c77984c..d5c9bc20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "10.0.0-rc.128", + "version": "10.0.0-rc.129", "description": "Create Keycloak themes using React", "repository": { "type": "git", From 89320b8d511dee869f9d71fd178c7f1aa5ce1d6c Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Wed, 7 Aug 2024 16:07:07 +0200 Subject: [PATCH 3/6] Fix get proxy option --- src/bin/shared/buildContext.ts | 4 -- src/bin/tools/fetchProxyOptions.ts | 60 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/bin/shared/buildContext.ts b/src/bin/shared/buildContext.ts index 88a2760f..d5811e75 100644 --- a/src/bin/shared/buildContext.ts +++ b/src/bin/shared/buildContext.ts @@ -670,10 +670,6 @@ export function getBuildContext(params: { throw error; } - console.log( - `The root of the NPM project should be "${pathRelative(process.cwd(), dirPath) || "."}"` - ); - return dirPath; })(0) }), diff --git a/src/bin/tools/fetchProxyOptions.ts b/src/bin/tools/fetchProxyOptions.ts index e9767f5c..e0e25de5 100644 --- a/src/bin/tools/fetchProxyOptions.ts +++ b/src/bin/tools/fetchProxyOptions.ts @@ -1,6 +1,7 @@ import { type FetchOptions } from "make-fetch-happen"; import * as child_process from "child_process"; import * as fs from "fs"; +import { exclude } from "tsafe/exclude"; export type ProxyFetchOptions = Pick< FetchOptions, @@ -26,12 +27,32 @@ export function getProxyFetchOptions(params: { .split("\n") .filter(line => !line.startsWith(";")) .map(line => line.trim()) - .map(line => line.split("=", 2) as [string, string]) + .map(line => { + const [key, value] = line.split("="); + if (key === undefined) { + return undefined; + } + if (value === undefined) { + return undefined; + } + return [key.trim(), value.trim()] as const; + }) + .filter(exclude(undefined)) + .filter(([key]) => key !== "") + .map(([key, value]) => { + if (value.startsWith('"') && value.endsWith('"')) { + return [key, value.slice(1, -1)] as const; + } + + if (value === "true" || value === "false") { + return [key, value] as const; + } + + return undefined; + }) + .filter(exclude(undefined)) .reduce( - ( - cfg: Record, - [key, value]: [string, string] - ) => + (cfg: Record, [key, value]) => key in cfg ? { ...cfg, [key]: [...ensureArray(cfg[key]), value] } : { ...cfg, [key]: value }, @@ -39,36 +60,19 @@ export function getProxyFetchOptions(params: { ); })(); - console.log("npm config get object"); - console.log(cfg); - const proxy = ensureSingleOrNone(cfg["https-proxy"] ?? cfg["proxy"]); - console.log("proxy", proxy); - const noProxy = cfg["noproxy"] ?? cfg["no-proxy"]; - console.log("noProxy", noProxy); - - function maybeBoolean(arg0: string | undefined) { - return typeof arg0 === "undefined" ? undefined : Boolean(arg0); - } - - const strictSSL = maybeBoolean(ensureSingleOrNone(cfg["strict-ssl"])); - - console.log("strictSSL", strictSSL); + const strictSSL = ensureSingleOrNone(cfg["strict-ssl"]) === "true"; const cert = cfg["cert"]; - console.log("cert", cert); const ca = ensureArray(cfg["ca"] ?? cfg["ca[]"]); - console.log("ca", ca); const cafile = ensureSingleOrNone(cfg["cafile"]); - console.log("cafile", cafile); - - if (typeof cafile !== "undefined" && cafile !== "null") { + if (cafile !== undefined) { ca.push( ...(() => { const cafileContent = fs.readFileSync(cafile).toString("utf8"); @@ -92,21 +96,17 @@ export function getProxyFetchOptions(params: { ); } - const out = { + return { proxy, noProxy, strictSSL, cert, ca: ca.length === 0 ? undefined : ca }; - - console.log("Final proxy options", out); - - return out; } function ensureArray(arg0: T | T[]) { - return Array.isArray(arg0) ? arg0 : typeof arg0 === "undefined" ? [] : [arg0]; + return Array.isArray(arg0) ? arg0 : arg0 === undefined ? [] : [arg0]; } function ensureSingleOrNone(arg0: T | T[]) { From 83bdbb7a7e08da5ab152af0a89aeadd6ae217cff Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Wed, 7 Aug 2024 16:07:25 +0200 Subject: [PATCH 4/6] Release candidate --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d5c9bc20..2b94207e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "10.0.0-rc.129", + "version": "10.0.0-rc.130", "description": "Create Keycloak themes using React", "repository": { "type": "git", From 13b87de06ce59ed783cb73a513f01030552cdc1a Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Wed, 7 Aug 2024 19:00:57 +0200 Subject: [PATCH 5/6] Remove debug log --- src/bin/tools/fetchProxyOptions.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/bin/tools/fetchProxyOptions.ts b/src/bin/tools/fetchProxyOptions.ts index e0e25de5..e6f8f497 100644 --- a/src/bin/tools/fetchProxyOptions.ts +++ b/src/bin/tools/fetchProxyOptions.ts @@ -20,9 +20,6 @@ export function getProxyFetchOptions(params: { }) .toString("utf8"); - console.log("Output of `npm config get`:"); - console.log(output); - return output .split("\n") .filter(line => !line.startsWith(";")) From d5c7e2547b35ae7fef49454065abfa80867cda09 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Wed, 7 Aug 2024 19:01:15 +0200 Subject: [PATCH 6/6] Release candidate --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b94207e..1102eca0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "10.0.0-rc.130", + "version": "10.0.0-rc.131", "description": "Create Keycloak themes using React", "repository": { "type": "git",