fix: duplicate @preact/signals version (#2964)

We initialized new projects with `@preact/signals@2.x` but Fresh itself
was using `1.x`. There shall only ever be one version.

Kinda makes me wish Deno had some sort of `peerDependencies`.

Fixes https://github.com/denoland/fresh/issues/2962
This commit is contained in:
Marvin Hagemeister
2025-05-16 21:23:53 +02:00
committed by GitHub
parent fa5aac5233
commit 6ff0becd0a
4 changed files with 113 additions and 12 deletions
+32
View File
@@ -25,6 +25,7 @@ if (Deno.args.length === 0) {
const ROOT_DIR = path.join(import.meta.dirname!, "..");
const denoJsonPath = path.join(ROOT_DIR, "deno.json");
const wwwDenoJsonPath = path.join(ROOT_DIR, "www", "deno.json");
const denoJson = JSON.parse(await Deno.readTextFile(denoJsonPath)) as DenoJson;
const version = Deno.args[0];
@@ -151,6 +152,37 @@ function updateVersions(content: string): string {
return replaced;
}
function replaceDepVersion(
registry: "jsr" | "npm",
name: string,
version: string,
) {
return (content: string) => {
return content.replace(
new RegExp(`"${name}":\\s"[^"]+"`),
`"${name}": "${registry}:${name}@^${version}"`,
);
};
}
// Update preact + @preact/signals version
await replaceInFile(
denoJsonPath,
replaceDepVersion("npm", "preact", preactVersion),
);
await replaceInFile(
denoJsonPath,
replaceDepVersion("npm", "@preact/signals", preactSignalsVersion),
);
await replaceInFile(
wwwDenoJsonPath,
replaceDepVersion("npm", "preact", preactVersion),
);
await replaceInFile(
wwwDenoJsonPath,
replaceDepVersion("npm", "@preact/signals", preactSignalsVersion),
);
const updateScriptPath = path.join(ROOT_DIR, "update", "src", "update.ts");
await replaceInFile(updateScriptPath, updateVersions);