create-pracht 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+
4
+ /** Written next to `package.json` by `scripts/sync-versions.js` at build time. */
5
+ export const FALLBACK_VERSIONS_FILE = "fallback-versions.json";
6
+
7
+ /**
8
+ * `^<version>` for every published `@pracht/*` package in a packages
9
+ * directory, keyed by package name.
10
+ */
11
+ export function collectWorkspaceVersionRanges(packagesDir) {
12
+ const ranges = {};
13
+ for (const entry of readdirSync(packagesDir, { withFileTypes: true })) {
14
+ if (!entry.isDirectory()) continue;
15
+ const manifestPath = resolve(packagesDir, entry.name, "package.json");
16
+ if (!existsSync(manifestPath)) continue;
17
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
18
+ if (manifest.private || !manifest.name?.startsWith("@pracht/") || !manifest.version) continue;
19
+ ranges[manifest.name] = `^${manifest.version}`;
20
+ }
21
+ return Object.fromEntries(Object.entries(ranges).sort(([a], [b]) => a.localeCompare(b)));
22
+ }
23
+
24
+ /**
25
+ * The `@pracht/*` ranges a scaffold falls back to when the registry lookup
26
+ * fails. Inside the monorepo they come straight from the sibling packages, so
27
+ * a checkout never goes stale; a published copy reads the file its build
28
+ * wrote from those same siblings.
29
+ */
30
+ export function loadFallbackVersionRanges(packageRoot) {
31
+ const packagesDir = resolve(packageRoot, "..");
32
+ try {
33
+ const core = JSON.parse(readFileSync(resolve(packagesDir, "framework/package.json"), "utf-8"));
34
+ if (core.name === "@pracht/core") return collectWorkspaceVersionRanges(packagesDir);
35
+ } catch {
36
+ // Not a checkout of the monorepo.
37
+ }
38
+ try {
39
+ return JSON.parse(readFileSync(resolve(packageRoot, FALLBACK_VERSIONS_FILE), "utf-8"));
40
+ } catch {
41
+ return {};
42
+ }
43
+ }