a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
101
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(time-ms): fallback on system time mocking

Mary 4669d5eb 0cfed5ad

+42 -19
+5
.changeset/modern-pumas-wait.md
··· 1 + --- 2 + '@atcute/time-ms': patch 3 + --- 4 + 5 + fallback on system time mocking
+3
packages/misc/time-ms/lib/env.d.ts
··· 1 + interface DateConstructor { 2 + isFake?: boolean; 3 + }
+8
packages/misc/time-ms/lib/index.bun.ts
··· 29 29 const bufPtr = ptr(buf); 30 30 31 31 now = (): number => { 32 + if (Date.isFake) { 33 + return Date.now() * 1_000; 34 + } 35 + 32 36 lib.symbols.GetSystemTimePreciseAsFileTime(bufPtr); 33 37 const low = BigInt(buf[0]); 34 38 const high = BigInt(buf[1]); ··· 50 54 const bufPtr = ptr(buf); 51 55 52 56 now = (): number => { 57 + if (Date.isFake) { 58 + return Date.now() * 1_000; 59 + } 60 + 53 61 lib.symbols.clock_gettime(CLOCK_REALTIME, bufPtr); 54 62 const sec = buf[0]; 55 63 const nsec = buf[1];
+8
packages/misc/time-ms/lib/index.deno.ts
··· 27 27 const ptr = Deno.UnsafePointer.of(buf); 28 28 29 29 now = (): number => { 30 + if (Date.isFake) { 31 + return Date.now() * 1_000; 32 + } 33 + 30 34 lib.symbols.GetSystemTimePreciseAsFileTime(ptr); 31 35 const low = BigInt(buf[0]); 32 36 const high = BigInt(buf[1]); ··· 48 52 const ptr = Deno.UnsafePointer.of(buf); 49 53 50 54 now = (): number => { 55 + if (Date.isFake) { 56 + return Date.now() * 1_000; 57 + } 58 + 51 59 lib.symbols.clock_gettime(CLOCK_REALTIME, ptr); 52 60 const sec = buf[0]; 53 61 const nsec = buf[1];
+17 -16
packages/misc/time-ms/lib/index.node.ts
··· 4 4 now: () => number; 5 5 }; 6 6 7 - let binding: TimeBinding | null = null; 8 - 9 - try { 10 - // node-gyp-build handles platform/arch detection, libc variants, etc. 11 - binding = require('node-gyp-build')(join(import.meta.dirname, '..')) as TimeBinding; 12 - } catch { 13 - binding = null; 14 - } 15 - 16 7 /** 17 8 * whether the native module is available for the current runtime. 18 9 */ 19 - export const hasNative = binding !== null; 10 + export let hasNative = false; 20 11 21 12 /** 22 13 * returns the current time in microseconds since unix epoch. 23 14 * @returns timestamp in microseconds 24 15 */ 25 - export const now = (): number => { 26 - if (binding === null) { 27 - return Date.now() * 1_000; 28 - } 16 + export let now = (): number => { 17 + return Date.now() * 1_000; 18 + }; 19 + 20 + try { 21 + const binding: TimeBinding = require('node-gyp-build')(join(import.meta.dirname, '..')); 29 22 30 - return binding.now(); 31 - }; 23 + now = (): number => { 24 + if (Date.isFake) { 25 + return Date.now() * 1_000; 26 + } 27 + 28 + return binding.now(); 29 + }; 30 + 31 + hasNative = true; 32 + } catch {}
+1 -3
packages/misc/time-ms/package.json
··· 33 33 "install": "node-gyp-build", 34 34 "build:native": "prebuildify --napi --strip", 35 35 "build": "tsgo --project tsconfig.build.json", 36 - "test": "vitest", 37 36 "prepublish": "rm -rf dist; pnpm run build:native; pnpm run build" 38 37 }, 39 38 "dependencies": { ··· 41 40 "node-gyp-build": "^4.8.4" 42 41 }, 43 42 "devDependencies": { 44 - "prebuildify": "^6.0.1", 45 - "vitest": "^4.0.18" 43 + "prebuildify": "^6.0.1" 46 44 } 47 45 }