Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit 9e83613

Browse files
committed
feat: enhance lockfile management with latest version tracking and validation improvements
1 parent 40f5008 commit 9e83613

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

src/cli.ts

+10
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,19 @@ cli.command(
228228
consola.log(versions.map((v) => `${yellow(v.emoji_version)}${v.draft ? ` ${red("(draft)")}` : ""}`).join(", "));
229229

230230
if (args.writeLockfile) {
231+
const sortedVersions = versions.filter((v) => !v.draft).sort((a, b) => semver.rcompare(a.unicode_version, b.unicode_version));
232+
233+
if (sortedVersions.length === 0 || sortedVersions[0] == null) {
234+
consola.warn("no stable versions found, skipping lockfile update");
235+
return;
236+
}
237+
238+
const latestVersion = sortedVersions[0].emoji_version;
239+
231240
const lockfile = await readLockfile();
232241

233242
lockfile.versions = Array.from(versions);
243+
lockfile.latest_version = latestVersion;
234244

235245
await writeLockfile(lockfile);
236246
consola.log(`updated ${yellow("emojis.lock")}`);

src/lockfile.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,37 @@ import process from "node:process";
33
import fs from "fs-extra";
44
import * as v from "valibot";
55

6+
const EMOJI_VERSION_METADATA_SCHEMA = v.object({
7+
emojis: v.nullable(v.string()),
8+
sequences: v.nullable(v.string()),
9+
variations: v.nullable(v.string()),
10+
metadata: v.nullable(v.string()),
11+
shortcodes: v.nullable(v.string()),
12+
zwj: v.nullable(v.string()),
13+
});
14+
615
const EMOJI_VERSION_SCHEMA = v.object({
7-
emoji_version: v.nullable(v.string()),
8-
unicode_version: v.nullable(v.string()),
16+
emoji_version: v.string(),
17+
unicode_version: v.string(),
918
draft: v.boolean(),
19+
generated: v.boolean(),
20+
metadata: v.nullable(EMOJI_VERSION_METADATA_SCHEMA),
1021
});
1122

1223
export type EmojiVersion = v.InferInput<typeof EMOJI_VERSION_SCHEMA>;
1324

1425
const LOCKFILE_SCHEMA = v.object({
26+
updated_at: v.optional(v.number(), new Date().getTime()),
27+
latest_version: v.optional(v.nullable(v.string())),
1528
versions: v.array(EMOJI_VERSION_SCHEMA),
1629
});
1730

1831
export type EmojiLockfile = v.InferInput<typeof LOCKFILE_SCHEMA>;
1932

2033
const DEFAULT_LOCKFILE = {
34+
updated_at: new Date().getTime(),
2135
versions: [],
36+
latest_version: null,
2237
} satisfies EmojiLockfile;
2338

2439
/**
@@ -49,7 +64,9 @@ export async function writeLockfile(lockfile: EmojiLockfile, cwd: string = proce
4964
const result = await v.safeParseAsync(LOCKFILE_SCHEMA, lockfile);
5065

5166
if (result.success === false) {
52-
throw new Error(`invalid lockfile: ${result.issues.join(", ")}`);
67+
// if lockfile is invalid, throw an error with the pretty-printed validation errors
68+
console.error(result.issues);
69+
throw new Error("invalid lockfile");
5370
}
5471

5572
await fs.writeJSON(path.join(cwd, "emojis.lock"), result.output, { spaces: 2 });

src/versions.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,11 @@ export async function getAllEmojiVersions(): Promise<EmojiVersion[]> {
239239
}
240240

241241
versions.push({
242-
emoji_version: null,
242+
emoji_version: version,
243243
unicode_version: version,
244244
draft: version === draft.unicode_version || version === draft.emoji_version,
245+
metadata: null,
246+
generated: false,
245247
});
246248
}
247249

@@ -293,8 +295,10 @@ export async function getAllEmojiVersions(): Promise<EmojiVersion[]> {
293295

294296
versions.push({
295297
emoji_version: match[1],
296-
unicode_version,
298+
unicode_version: unicode_version || match[1],
297299
draft: version === draft.unicode_version || version === draft.emoji_version,
300+
metadata: null,
301+
generated: false,
298302
});
299303
}
300304

test/lockfile.test.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ describe("writeLockfile", () => {
2929
emoji_version: "15.0",
3030
unicode_version: "15.0",
3131
draft: false,
32+
generated: false,
33+
metadata: null,
3234
}],
33-
latestVersion: "15.0",
34-
};
35+
latest_version: "15.0",
36+
} satisfies EmojiLockfile;
3537

3638
await writeLockfile(lockfile, path);
3739
expect(await fs.exists(`${path}/emojis.lock`)).toBe(true);
@@ -43,7 +45,7 @@ describe("writeLockfile", () => {
4345
versions: [{
4446
// @ts-expect-error invalid type for emoji_version
4547
emoji_version: 123,
46-
unicode_version: null,
48+
unicode_version: "15.0.0",
4749
draft: false,
4850
}],
4951
} satisfies EmojiLockfile;
@@ -60,9 +62,11 @@ describe("readLockfile", () => {
6062
emoji_version: "15.0",
6163
unicode_version: "15.0",
6264
draft: false,
65+
generated: false,
66+
metadata: null,
6367
}],
64-
latestVersion: "15.0",
65-
}),
68+
latest_version: "15.0",
69+
} satisfies EmojiLockfile),
6670
});
6771

6872
const result = await readLockfile(path);
@@ -71,9 +75,12 @@ describe("readLockfile", () => {
7175
emoji_version: "15.0",
7276
unicode_version: "15.0",
7377
draft: false,
78+
generated: false,
79+
metadata: null,
7480
}],
75-
latestVersion: "15.0",
76-
});
81+
latest_version: "15.0",
82+
updated_at: expect.any(Number),
83+
} satisfies EmojiLockfile);
7784
});
7885

7986
it("should return default lockfile when file does not exist", async () => {
@@ -82,8 +89,9 @@ describe("readLockfile", () => {
8289
const result = await readLockfile(path);
8390
expect(result).toEqual({
8491
versions: [],
85-
latestVersion: null,
86-
});
92+
latest_version: null,
93+
updated_at: expect.any(Number),
94+
} satisfies EmojiLockfile);
8795
});
8896

8997
it("should throw error for invalid lockfile content", async () => {
@@ -92,7 +100,7 @@ describe("readLockfile", () => {
92100
versions: [{
93101
// @ts-expect-error invalid type for emoji_version
94102
emoji_version: 123,
95-
unicode_version: null,
103+
unicode_version: "15.0.0",
96104
draft: false,
97105
}],
98106
} satisfies EmojiLockfile),

0 commit comments

Comments
 (0)