From ecb22c38295ca503577723ed03b4d69e33925646 Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Wed, 26 Apr 2023 22:34:49 +0200 Subject: [PATCH 1/7] fix: restore missing pom.xml in jar archive --- src/bin/keycloakify/keycloakify.ts | 2 +- src/bin/tools/jar.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/bin/keycloakify/keycloakify.ts b/src/bin/keycloakify/keycloakify.ts index 9599ad58..c92ec13f 100644 --- a/src/bin/keycloakify/keycloakify.ts +++ b/src/bin/keycloakify/keycloakify.ts @@ -58,7 +58,7 @@ export async function main() { case "keycloakify": logger.log("🫶 Let keycloakify do its thang"); await jar({ - "rootPath": pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources"), + "rootPath": buildOptions.keycloakifyBuildDirPath, "version": buildOptions.themeVersion, "groupId": buildOptions.groupId, "artifactId": buildOptions.artifactId, diff --git a/src/bin/tools/jar.ts b/src/bin/tools/jar.ts index a87e9048..981a3ef6 100644 --- a/src/bin/tools/jar.ts +++ b/src/bin/tools/jar.ts @@ -1,4 +1,4 @@ -import { dirname, relative, sep } from "path"; +import { dirname, relative, sep, join } from "path"; import { createWriteStream } from "fs"; import walk from "./walk"; @@ -65,15 +65,22 @@ export async function jarStream({ groupId, artifactId, version, asyncPathGenerat * Create a jar archive, using the resources found at `rootPath` (a directory) and write the * archive to `targetPath` (a file). Use `groupId`, `artifactId` and `version` to define * the contents of the pom.properties file which is going to be added to the archive. + * The root directory is expectedto have a conventional maven/gradle folder structure with a + * single `pom.xml` file at the root and a `src/main/resources` directory containing all + * application resources. */ export default async function jar({ groupId, artifactId, version, rootPath, targetPath }: JarArgs) { await mkdir(dirname(targetPath), { recursive: true }); const asyncPathGeneratorFn = async function* (): ZipEntryGenerator { - for await (const fsPath of walk(rootPath)) { + for await (const fsPath of walk(join(rootPath, "src", "main", "resources"))) { const zipPath = relative(rootPath, fsPath).split(sep).join("/"); yield { fsPath, zipPath }; } + yield { + fsPath: join(rootPath, "pom.xml"), + zipPath: `META-INF/maven/${groupId}/${artifactId}/pom.xml` + }; }; const zipFile = await jarStream({ groupId, artifactId, version, asyncPathGeneratorFn }); From c35a1e7c50daf210073e03d84e59f68f3a67035e Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Wed, 26 Apr 2023 22:48:06 +0200 Subject: [PATCH 2/7] fix: fix paths after changing root path param meaning --- src/bin/tools/jar.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bin/tools/jar.ts b/src/bin/tools/jar.ts index 981a3ef6..962f994e 100644 --- a/src/bin/tools/jar.ts +++ b/src/bin/tools/jar.ts @@ -73,8 +73,9 @@ export default async function jar({ groupId, artifactId, version, rootPath, targ await mkdir(dirname(targetPath), { recursive: true }); const asyncPathGeneratorFn = async function* (): ZipEntryGenerator { - for await (const fsPath of walk(join(rootPath, "src", "main", "resources"))) { - const zipPath = relative(rootPath, fsPath).split(sep).join("/"); + const resourcesPath = join(rootPath, "src", "main", "resources"); + for await (const fsPath of walk(resourcesPath)) { + const zipPath = relative(resourcesPath, fsPath).split(sep).join("/"); yield { fsPath, zipPath }; } yield { From 08ae9084532b24689687bbe566f4711f88042950 Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Thu, 27 Apr 2023 14:44:45 +0200 Subject: [PATCH 3/7] fix: adjust test after adjusting jar.ts --- test/bin/jar.spec.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/bin/jar.spec.ts b/test/bin/jar.spec.ts index 4499d664..91d82099 100644 --- a/test/bin/jar.spec.ts +++ b/test/bin/jar.spec.ts @@ -3,7 +3,7 @@ import { fromBuffer, Entry, ZipFile } from "yauzl"; import { it, describe, assert, afterAll } from "vitest"; import { Readable } from "stream"; import { tmpdir } from "os"; -import { mkdtemp, cp, mkdir, rm } from "fs/promises"; +import { mkdtemp, cp, mkdir, rm, writeFile } from "fs/promises"; import path from "path"; import { createReadStream } from "fs"; import walk from "keycloakify/bin/tools/walk"; @@ -98,12 +98,17 @@ describe("jar", () => { it("creates a jar from _real_ files without error", async () => { const tmp = await mkdtemp(path.join(tmpdir(), "kc-jar-test-")); - tmpDirs.push(tmp); - const rootPath = path.join(tmp, "src"); - const targetPath = path.join(tmp, "jar.jar"); - await mkdir(rootPath); - await cp(path.dirname(__dirname), rootPath, { recursive: true }); + tmpDirs.push(tmp); + + const rootPath = path.join(tmp, "root"); + const resourcesPath = path.join(tmp, "root", "src", "main", "resources"); + const targetPath = path.join(tmp, "jar.jar"); + + await mkdir(resourcesPath, { recursive: true }) + await writeFile(path.join(rootPath, "pom.xml"), "foo", "utf-8"); + + await cp(path.dirname(__dirname), resourcesPath, { recursive: true }); await jar({ ...coords, rootPath, targetPath }); @@ -114,11 +119,12 @@ describe("jar", () => { assert.isOk(entries.has("META-INF/MANIFEST.MF")); assert.isOk(entries.has("META-INF/maven/someGroupId/someArtifactId/pom.properties")); + assert.isOk(entries.has("META-INF/maven/someGroupId/someArtifactId/pom.xml")); - for await (const fsPath of walk(rootPath)) { + for await (const fsPath of walk(resourcesPath)) { if (!fsPath.endsWith(path.sep)) { - const rel = path.relative(rootPath, fsPath).replace(path.sep === "/" ? /\//g : /\\/g, "/"); - assert.isOk(zipPaths.includes(rel), `missing ${rel} (${rel}, ${zipPaths.join(", ")})`); + const rel = path.relative(resourcesPath, fsPath).replace(path.sep === "/" ? /\//g : /\\/g, "/"); + assert.isOk(zipPaths.includes(rel), `missing '${rel}' (${rel}, '${zipPaths.join("', '")}')`); } } }); From 465dbb4a8d6d866dad1e2ba442974b56a725387e Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Thu, 27 Apr 2023 14:47:15 +0200 Subject: [PATCH 4/7] fix formatting --- test/bin/jar.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bin/jar.spec.ts b/test/bin/jar.spec.ts index 91d82099..65cf57f3 100644 --- a/test/bin/jar.spec.ts +++ b/test/bin/jar.spec.ts @@ -105,7 +105,7 @@ describe("jar", () => { const resourcesPath = path.join(tmp, "root", "src", "main", "resources"); const targetPath = path.join(tmp, "jar.jar"); - await mkdir(resourcesPath, { recursive: true }) + await mkdir(resourcesPath, { recursive: true }); await writeFile(path.join(rootPath, "pom.xml"), "foo", "utf-8"); await cp(path.dirname(__dirname), resourcesPath, { recursive: true }); From 603e6a99f3cbca0293d3ff8d4eeafa008f09b201 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Thu, 27 Apr 2023 18:00:14 +0200 Subject: [PATCH 5/7] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 67b48105..3923ebf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "7.11.3", + "version": "7.11.4", "description": "Create Keycloak themes using React", "repository": { "type": "git", From 58c10796a1291e8b5be6e55e11c514952990941d Mon Sep 17 00:00:00 2001 From: Waldemar Reusch Date: Fri, 28 Apr 2023 16:59:06 +0200 Subject: [PATCH 6/7] fix: fix broken jar Many tools will handle zipfiles which lack directory entries just fine, others will not. Looks like the JDKs JAR libs are not handling it well. This commit will make sure to create folder entries. --- src/bin/tools/jar.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/tools/jar.ts b/src/bin/tools/jar.ts index 962f994e..33fdf2df 100644 --- a/src/bin/tools/jar.ts +++ b/src/bin/tools/jar.ts @@ -48,8 +48,12 @@ export async function jarStream({ groupId, artifactId, version, asyncPathGenerat for await (const entry of asyncPathGeneratorFn()) { if ("buffer" in entry) { zipFile.addBuffer(entry.buffer, entry.zipPath); - } else if ("fsPath" in entry && !entry.fsPath.endsWith(sep)) { - zipFile.addFile(entry.fsPath, entry.zipPath); + } else if ("fsPath" in entry) { + if (entry.fsPath.endsWith(sep)) { + zipFile.addEmptyDirectory(entry.zipPath); + } else { + zipFile.addFile(entry.fsPath, entry.zipPath); + } } } From 209c2183e1181cef60acf7f2396619f9a21a2f0c Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Fri, 28 Apr 2023 17:58:09 +0200 Subject: [PATCH 7/7] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3923ebf8..33a0d0d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "7.11.4", + "version": "7.11.5", "description": "Create Keycloak themes using React", "repository": { "type": "git",