Skip to content

Commit 2817bf5

Browse files
authored
refactor: upgrade to ohash v2 (#230)
1 parent f5badac commit 2817bf5

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"giget": "^1.2.4",
4444
"jiti": "^2.4.2",
4545
"mlly": "^1.7.4",
46-
"ohash": "^1.1.4",
46+
"ohash": "^2.0.4",
4747
"pathe": "^2.0.3",
4848
"perfect-debounce": "^1.0.0",
4949
"pkg-types": "^1.3.1",

pnpm-lock.yaml

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/loader.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { createJiti } from "jiti";
66
import { fileURLToPath } from "mlly";
77
import * as rc9 from "rc9";
88
import { defu } from "defu";
9-
import { hash } from "ohash";
109
import { findWorkspaceDir, readPackageJSON } from "pkg-types";
1110
import { setupDotenv } from "./dotenv";
1211

@@ -312,11 +311,12 @@ async function resolveConfig<
312311
GIGET_PREFIXES.some((prefix) => source.startsWith(prefix))
313312
) {
314313
const { downloadTemplate } = await import("giget");
314+
const { digest } = await import("ohash");
315315

316316
const cloneName =
317317
source.replace(/\W+/g, "_").split("_").splice(0, 3).join("_") +
318318
"_" +
319-
hash(source);
319+
digest(source).slice(0, 10).replace(/[-_]/g, "");
320320

321321
let cloneDir: string;
322322

src/watch.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ChokidarOptions } from "chokidar";
22
import { debounce } from "perfect-debounce";
33
import { resolve } from "pathe";
4-
import { diff } from "ohash";
4+
import type { diff } from "ohash/utils";
55
import type {
66
UserInputConfig,
77
ConfigLayerMeta,
@@ -10,6 +10,8 @@ import type {
1010
} from "./types";
1111
import { SUPPORTED_EXTENSIONS, loadConfig } from "./loader";
1212

13+
type DiffEntries = ReturnType<typeof diff>;
14+
1315
export type ConfigWatcher<
1416
T extends UserInputConfig = UserInputConfig,
1517
MT extends ConfigLayerMeta = ConfigLayerMeta,
@@ -31,7 +33,7 @@ export interface WatchConfigOptions<
3133
}) => void | Promise<void>;
3234

3335
acceptHMR?: (context: {
34-
getDiff: () => ReturnType<typeof diff>;
36+
getDiff: () => DiffEntries;
3537
newConfig: ResolvedConfig<T, MT>;
3638
oldConfig: ResolvedConfig<T, MT>;
3739
}) => void | boolean | Promise<void | boolean>;
@@ -89,6 +91,7 @@ export async function watchConfig<
8991
] as string[];
9092

9193
const watch = await import("chokidar").then((r) => r.watch || r.default || r);
94+
const { diff } = await import("ohash/utils");
9295
const _fswatcher = watch(watchingFiles, {
9396
ignoreInitial: true,
9497
...options.chokidarOptions,

0 commit comments

Comments
 (0)