From cfbd1e5e4b5fdf3782a678c471d63651b27f6145 Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Sun, 5 Feb 2023 12:34:48 +0100 Subject: [PATCH 1/6] fix(bundler): fix type mismatch introduced in last-minute 'fixes' --- src/bin/tools/jar.ts | 6 +++--- src/bin/tools/zip.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bin/tools/jar.ts b/src/bin/tools/jar.ts index 76fbba57..1ee53da9 100644 --- a/src/bin/tools/jar.ts +++ b/src/bin/tools/jar.ts @@ -57,9 +57,9 @@ export default async function jar({ groupId, artifactId, version, rootPath, targ const pathToRecord = () => new Transform({ objectMode: true, - transform: function (path, _, cb) { - const filename = relative(rootPath, path).split(sep).join("/"); - this.push({ filename, path }); + transform: function (fsPath, _, cb) { + const path = relative(rootPath, fsPath).split(sep).join("/"); + this.push({ path, fsPath }); cb(); }, final: function () { diff --git a/src/bin/tools/zip.ts b/src/bin/tools/zip.ts index 737ba4c2..5a2ad9be 100644 --- a/src/bin/tools/zip.ts +++ b/src/bin/tools/zip.ts @@ -216,7 +216,7 @@ export default function zip() { const writeRecord = async (source: ZipSource) => { if ("fsPath" in source) await writeFromPath(source.path, source.fsPath); else if ("data" in source) await writeFromBuffer(source.path, source.data); - else throw new Error("Illegal argument " + typeof source + " " + source); + else throw new Error("Illegal argument " + typeof source + " " + JSON.stringify(source)); }; /** From 557de34eea0efd4b2002f75a555bc0c2090316ab Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Sun, 5 Feb 2023 12:56:01 +0100 Subject: [PATCH 2/6] fix: bundler fix missing change --- src/bin/keycloakify/keycloakify.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/keycloakify/keycloakify.ts b/src/bin/keycloakify/keycloakify.ts index 2f3f1d77..fd3d35d3 100644 --- a/src/bin/keycloakify/keycloakify.ts +++ b/src/bin/keycloakify/keycloakify.ts @@ -56,7 +56,7 @@ export async function main() { } else if (buildOptions.bundler === "keycloakify") { logger.log("🫶 Let keycloakify do its thang"); await jar({ - "rootPath": keycloakThemeBuildingDirPath, + "rootPath": pathJoin(keycloakThemeBuildingDirPath, "src"), "version": buildOptions.version, "groupId": buildOptions.groupId, "artifactId": buildOptions.artifactId || `${buildOptions.themeName}-keycloak-theme`, From d4ff6b1f401a856be28a95bd0f1f1d29e9717ea7 Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Sun, 5 Feb 2023 12:59:05 +0100 Subject: [PATCH 3/6] fix: bundler fix missing directory --- src/bin/tools/jar.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin/tools/jar.ts b/src/bin/tools/jar.ts index 1ee53da9..62c99288 100644 --- a/src/bin/tools/jar.ts +++ b/src/bin/tools/jar.ts @@ -1,11 +1,12 @@ import { Readable, Transform } from "stream"; import { pipeline } from "stream/promises"; -import { relative, sep } from "path"; +import { dirname, relative, sep } from "path"; import { createWriteStream } from "fs"; import walk from "./walk"; import type { ZipSource } from "./zip"; import zip from "./zip"; +import { mkdir } from "fs/promises"; /** Trim leading whitespace from every line */ const trimIndent = (s: string) => s.replace(/(\n)\s+/g, "$1"); @@ -69,6 +70,7 @@ export default async function jar({ groupId, artifactId, version, rootPath, targ } }); + await mkdir(dirname(targetPath), { recursive: true }); /** * Create an async pipeline, wait until everything is fully processed */ From fcc26c3e7a96e19ed813d88b86fc9ab25046fd9e Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Sun, 5 Feb 2023 13:31:03 +0100 Subject: [PATCH 4/6] now that main is a promise, we shuold catch errors --- src/bin/keycloakify/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/keycloakify/index.ts b/src/bin/keycloakify/index.ts index 258b6e23..13d73c75 100644 --- a/src/bin/keycloakify/index.ts +++ b/src/bin/keycloakify/index.ts @@ -4,5 +4,5 @@ export * from "./keycloakify"; import { main } from "./keycloakify"; if (require.main === module) { - main(); + main().catch(e => console.error(e)); } From 45ed359bef471d5dbe003ea056ff733af446efb3 Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Sun, 5 Feb 2023 13:31:34 +0100 Subject: [PATCH 5/6] fix keycloak theme source path for internal bundler --- src/bin/keycloakify/keycloakify.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/keycloakify/keycloakify.ts b/src/bin/keycloakify/keycloakify.ts index fd3d35d3..2aa36d7d 100644 --- a/src/bin/keycloakify/keycloakify.ts +++ b/src/bin/keycloakify/keycloakify.ts @@ -56,7 +56,7 @@ export async function main() { } else if (buildOptions.bundler === "keycloakify") { logger.log("🫶 Let keycloakify do its thang"); await jar({ - "rootPath": pathJoin(keycloakThemeBuildingDirPath, "src"), + "rootPath": pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources"), "version": buildOptions.version, "groupId": buildOptions.groupId, "artifactId": buildOptions.artifactId || `${buildOptions.themeName}-keycloak-theme`, From 38ad47ea75b61cb6d5842f562a0924e4254c8212 Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Sun, 5 Feb 2023 13:32:24 +0100 Subject: [PATCH 6/6] use hand-crafted promise, pipeline does not resolve properly --- src/bin/tools/jar.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/bin/tools/jar.ts b/src/bin/tools/jar.ts index 62c99288..2dc60f0e 100644 --- a/src/bin/tools/jar.ts +++ b/src/bin/tools/jar.ts @@ -1,5 +1,4 @@ import { Readable, Transform } from "stream"; -import { pipeline } from "stream/promises"; import { dirname, relative, sep } from "path"; import { createWriteStream } from "fs"; @@ -71,19 +70,20 @@ export default async function jar({ groupId, artifactId, version, rootPath, targ }); await mkdir(dirname(targetPath), { recursive: true }); - /** - * Create an async pipeline, wait until everything is fully processed - */ - await pipeline( + + // Create an async pipeline, wait until everything is fully processed + await new Promise((resolve, reject) => { // walk all files in `rootPath` recursively - Readable.from(walk(rootPath)), - // transform every path into a ZipSource object - pathToRecord(), - // let the zip lib convert all ZipSource objects into a byte stream - zip(), - // write that byte stream to targetPath - createWriteStream(targetPath, { encoding: "binary" }) - ); + Readable.from(walk(rootPath)) + // transform every path into a ZipSource object + .pipe(pathToRecord()) + // let the zip lib convert all ZipSource objects into a byte stream + .pipe(zip()) + // write that byte stream to targetPath + .pipe(createWriteStream(targetPath, { encoding: "binary" })) + .on("finish", () => resolve()) + .on("error", e => reject(e)); + }); } /**