Skip to content

Commit 9727635

Browse files
🚴 perf(calendar.now): Only import what is used.
1 parent 09148eb commit 9727635

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

.bin/bun/bun.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.bin/bun/packages/events/lib/events.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import {
55
differenceInDays,
66
formatDistance,
77
} from 'date-fns';
8-
import fs from 'node:fs/promises';
9-
import path from 'node:path';
10-
import crypto from 'node:crypto';
8+
import {readFile} from 'node:fs/promises';
9+
import {join} from 'node:path';
10+
import {createHash} from 'node:crypto';
1111
import { z } from 'zod';
1212

1313
export const log = (...args: any[]) => console.error(...args);
1414

15-
export const CACHE = path.join(homedir(), '.cache/calendar/{}');
16-
export const FRESH = path.join(homedir(), '.cache/calendar/fresh/{}');
17-
export const CONFIG = path.join(homedir(), '.config/calendar/config');
15+
export const CACHE = join(homedir(), '.cache/calendar/{}');
16+
export const FRESH = join(homedir(), '.cache/calendar/fresh/{}');
17+
export const CONFIG = join(homedir(), '.config/calendar/config');
1818

1919
// Zod schema for calendar configuration
2020
const CalendarSchema = z.object({
@@ -63,13 +63,13 @@ export const parseICalendar = (calendarString: string): ParsedEvent[] => {
6363
}
6464
}
6565

66-
export const urlHash = (url: string): string => crypto.createHash('sha1').update(url).digest('hex');
66+
export const urlHash = (url: string): string => createHash('sha1').update(url).digest('hex');
6767

6868
export const cacheRead = async (cache: string, url: string): Promise<string> => {
6969
const h = urlHash(url);
7070
const filename = cache.replace('{}', h);
7171
log(`loading ${url} from ${filename}`);
72-
return fs.readFile(filename, 'utf8');
72+
return readFile(filename, 'utf8');
7373
}
7474

7575
export const cacheLoadUrl = async (cache: string, url: string): Promise<ParsedEvent[]> => {
@@ -84,7 +84,7 @@ export const cacheLoadUrl = async (cache: string, url: string): Promise<ParsedEv
8484
}
8585

8686
export const calendars = async (config: string = CONFIG): Promise<Calendar[]> => {
87-
const rawConfig = await fs.readFile(config, 'utf8');
87+
const rawConfig = await readFile(config, 'utf8');
8888
const parsedConfig = JSON.parse(rawConfig);
8989
const validatedConfig = ConfigSchema.parse(parsedConfig);
9090
return validatedConfig.calendars.filter(c => !c.hide);

.bin/bun/packages/events/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "__events",
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"type": "module",
66
"dependencies": {
77
"chalk": "^5.5.0",

.bin/calendar._all

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bun/dist/packages/events/bin/all.js
1+
bun/dist/events/bin/all.js

.bin/calendar.fetch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bun/dist/packages/events/bin/fetch.js
1+
bun/dist/events/bin/fetch.js

.bin/calendar.filter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bun/dist/packages/events/bin/filter.js
1+
bun/dist/events/bin/filter.js

.bin/calendar.now

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bun/dist/packages/events/bin/now.js
1+
bun/dist/events/bin/now.js

0 commit comments

Comments
 (0)