style: fix formatting

This commit is contained in:
Waldemar Reusch 2023-04-06 22:06:14 +02:00
parent e429127313
commit b325b3537f
2 changed files with 15 additions and 18 deletions

View File

@ -12,7 +12,7 @@ export default async function* walk(root: string): AsyncGenerator<string, void,
for (const entry of await readdir(root, { withFileTypes: true })) {
const absolutePath = resolve(root, entry.name);
if (entry.isDirectory()) {
yield absolutePath.endsWith(sep) ? absolutePath : (absolutePath + sep);
yield absolutePath.endsWith(sep) ? absolutePath : absolutePath + sep;
yield* walk(absolutePath);
} else yield absolutePath.endsWith(sep) ? absolutePath.substring(0, absolutePath.length - 1) : absolutePath;
}

View File

@ -62,10 +62,9 @@ function readAll(zipFile: ZipFile): Promise<Map<string, Buffer>> {
}
describe("jar", () => {
const coords = { artifactId: "someArtifactId", groupId: "someGroupId", version: "1.2.3" };
const coords = { artifactId: "someArtifactId", groupId: "someGroupId", version: "1.2.3" }
const tmpDirs: string[] = []
const tmpDirs: string[] = [];
// afterAll(async () => {
// await Promise.all(tmpDirs.map(dir => rm(dir, { force: true, recursive: true })));
@ -98,31 +97,29 @@ 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);
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 });
await cp(path.dirname(__dirname), rootPath, { recursive: true })
await jar({ ...coords, rootPath, targetPath })
await jar({ ...coords, rootPath, targetPath });
const buffered = await readToBuffer(createReadStream(targetPath));
const unzipped = await unzipBuffer(buffered);
const entries = await readAll(unzipped);
const zipPaths = Array.from(entries.keys())
const zipPaths = Array.from(entries.keys());
assert.isOk(entries.has("META-INF/MANIFEST.MF"));
assert.isOk(entries.has("META-INF/maven/someGroupId/someArtifactId/pom.properties"));
for await (const fsPath of walk(rootPath)) {
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(rootPath, fsPath).replace(path.sep === "/" ? /\//g : /\\/g, "/");
assert.isOk(zipPaths.includes(rel), `missing ${rel} (${rel}, ${zipPaths.join(", ")})`);
}
}
})
});
});