Skip to content

Commit ad28821

Browse files
committed
fix: things
1 parent 2dafb24 commit ad28821

File tree

10 files changed

+326
-206
lines changed

10 files changed

+326
-206
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ jobs:
3232
${{ runner.os }}-pnpm-store-
3333
- name: Install dependencies
3434
run: pnpm install --frozen-lockfile
35+
- name: Run checks
36+
run: |
37+
cd apps/server
38+
pnpm typecheck
39+
pnpm check
3540
- name: Run tests
3641
run: |
3742
cd apps/server

apps/server/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"list:production": "wrangler d1 migrations list DB --env production",
1111
"apply": "wrangler d1 migrations apply DB --local",
1212
"apply:preview": "wrangler d1 migrations apply DB --env preview",
13-
"apply:production": "wrangler d1 migrations apply DB --env production"
13+
"apply:production": "wrangler d1 migrations apply DB --env production",
14+
"check": "biome ci --diagnostic-level=error ./src",
15+
"typecheck": "tsc --noEmit"
1416
},
1517
"dependencies": {
1618
"@hono/zod-openapi": "^0.18.3",
@@ -20,6 +22,7 @@
2022
"compare-versions": "^6.1.1",
2123
"drizzle-kit": "^0.30.2",
2224
"drizzle-orm": "^0.38.4",
25+
"fflate": "^0.8.2",
2326
"hono": "^4.6.16",
2427
"jszip": "^3.10.1",
2528
"qs": "^6.14.0",

apps/server/src/routes/acquisition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
2-
import { compare, compareVersions, satisfies } from "compare-versions";
2+
import { compare, satisfies } from "compare-versions";
33
import qs from "qs";
44
import type { z } from "zod";
55
import { getStorageProvider } from "../storage/factory";

apps/server/src/routes/management.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,12 @@ router.openapi(routes.deployments.release, async (c) => {
11601160
}
11611161

11621162
const packageData = await packageFile.arrayBuffer();
1163-
const differ = await createPackageDiffer(packageData);
1163+
const differ = await createPackageDiffer(
1164+
storage,
1165+
app.id,
1166+
deployment.id,
1167+
packageData,
1168+
);
11641169
const manifestResult = await differ.generateManifest();
11651170
const packageHash = await manifestResult.computeHash();
11661171

@@ -1220,7 +1225,7 @@ router.openapi(routes.deployments.release, async (c) => {
12201225

12211226
// Generate diffs in background
12221227
if (manifestResult) {
1223-
await differ.generateDiffs(history, storage);
1228+
await differ.generateDiffs(history);
12241229
}
12251230

12261231
c.header(

apps/server/src/utils/hash-utils.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const HASH_ALGORITHM = "SHA-256";
2+
const CODEPUSH_METADATA = ".codepushrelease";
3+
4+
/**
5+
* Computes SHA256 hash of the provided data
6+
*/
7+
export async function computeHash(input: string | Uint8Array): Promise<string> {
8+
const data =
9+
typeof input === "string" ? new TextEncoder().encode(input) : input;
10+
11+
const hashBuffer = await crypto.subtle.digest(HASH_ALGORITHM, data);
12+
return Array.from(new Uint8Array(hashBuffer))
13+
.map((b) => b.toString(16).padStart(2, "0"))
14+
.join("");
15+
}
16+
17+
export class PackageManifest {
18+
private readonly _map: Map<string, string>;
19+
20+
constructor(map?: Map<string, string>) {
21+
this._map = new Map(map || new Map());
22+
}
23+
24+
/**
25+
* Returns the internal map of file paths to hashes
26+
*/
27+
public toMap(): Map<string, string> {
28+
return new Map(this._map);
29+
}
30+
31+
/**
32+
* Computes the overall package hash from all file hashes
33+
*/
34+
public async computeHash(): Promise<string> {
35+
const entries = Array.from(this._map.entries())
36+
.filter(
37+
([name]) =>
38+
name !== CODEPUSH_METADATA && !name.endsWith(`/${CODEPUSH_METADATA}`),
39+
)
40+
.map(([name, hash]) => `${name}:${hash}`)
41+
.sort(); // Sort entries for consistent hashing
42+
43+
return computeHash(JSON.stringify(entries));
44+
}
45+
46+
/**
47+
* Serializes the manifest to JSON
48+
*/
49+
public serialize(): string {
50+
return JSON.stringify(Object.fromEntries(this._map));
51+
}
52+
53+
/**
54+
* Deserializes a manifest from JSON
55+
*/
56+
public static deserialize(
57+
serializedContents: string,
58+
): PackageManifest | undefined {
59+
try {
60+
const obj = JSON.parse(serializedContents);
61+
const map = new Map<string, string>();
62+
63+
for (const [key, value] of Object.entries(obj)) {
64+
if (typeof value === "string") {
65+
map.set(key, value);
66+
}
67+
}
68+
69+
return new PackageManifest(map);
70+
} catch {
71+
return undefined;
72+
}
73+
}
74+
75+
/**
76+
* Normalizes a file path to use forward slashes
77+
*/
78+
public static normalizePath(filePath: string): string {
79+
return filePath.replace(/\\/g, "/");
80+
}
81+
82+
/**
83+
* Checks if a file should be ignored in manifest
84+
*/
85+
public static isIgnored(relativeFilePath: string): boolean {
86+
const MACOSX = "__MACOSX/";
87+
const DS_STORE = ".DS_Store";
88+
89+
return (
90+
relativeFilePath.startsWith(MACOSX) ||
91+
relativeFilePath === DS_STORE ||
92+
relativeFilePath.endsWith(`/${DS_STORE}`)
93+
);
94+
}
95+
}

apps/server/src/utils/hash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createHash } from "crypto";
1+
import { createHash } from "node:crypto";
22

33
export function sha256(input: string | Buffer | Uint8Array): string {
44
return createHash("sha256").update(input).digest("hex");

0 commit comments

Comments
 (0)