@remixhq/core 0.1.8 → 0.1.10

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,93 @@
1
+ import {
2
+ RemixError
3
+ } from "./chunk-YZ34ICNN.js";
4
+
5
+ // src/infrastructure/binding/collabBindingStore.ts
6
+ import fs2 from "fs/promises";
7
+ import path2 from "path";
8
+
9
+ // src/shared/fs.ts
10
+ import fs from "fs/promises";
11
+ import path from "path";
12
+ async function reserveDirectory(targetDir) {
13
+ try {
14
+ await fs.mkdir(targetDir);
15
+ return targetDir;
16
+ } catch (error) {
17
+ if (error?.code === "EEXIST") {
18
+ throw new RemixError("Output directory already exists.", {
19
+ exitCode: 2,
20
+ hint: `Choose an empty destination path: ${targetDir}`
21
+ });
22
+ }
23
+ throw error;
24
+ }
25
+ }
26
+ async function reserveAvailableDirPath(preferredDir) {
27
+ const parent = path.dirname(preferredDir);
28
+ const base = path.basename(preferredDir);
29
+ for (let i = 1; i <= 1e3; i += 1) {
30
+ const candidate = i === 1 ? preferredDir : path.join(parent, `${base}-${i}`);
31
+ try {
32
+ await fs.mkdir(candidate);
33
+ return candidate;
34
+ } catch (error) {
35
+ if (error?.code === "EEXIST") continue;
36
+ throw error;
37
+ }
38
+ }
39
+ throw new RemixError("No available output directory name.", {
40
+ exitCode: 2,
41
+ hint: `Tried ${base} through ${base}-1000 under ${parent}.`
42
+ });
43
+ }
44
+ async function writeJsonAtomic(filePath, value) {
45
+ const dir = path.dirname(filePath);
46
+ await fs.mkdir(dir, { recursive: true });
47
+ const tmp = `${filePath}.tmp-${Date.now()}`;
48
+ await fs.writeFile(tmp, `${JSON.stringify(value, null, 2)}
49
+ `, "utf8");
50
+ await fs.rename(tmp, filePath);
51
+ }
52
+
53
+ // src/infrastructure/binding/collabBindingStore.ts
54
+ function getCollabBindingPath(repoRoot) {
55
+ return path2.join(repoRoot, ".remix", "config.json");
56
+ }
57
+ async function readCollabBinding(repoRoot) {
58
+ try {
59
+ const raw = await fs2.readFile(getCollabBindingPath(repoRoot), "utf8");
60
+ const parsed = JSON.parse(raw);
61
+ if (parsed?.schemaVersion !== 1) return null;
62
+ if (!parsed.projectId || !parsed.currentAppId || !parsed.upstreamAppId) return null;
63
+ return {
64
+ schemaVersion: 1,
65
+ projectId: parsed.projectId,
66
+ currentAppId: parsed.currentAppId,
67
+ upstreamAppId: parsed.upstreamAppId,
68
+ threadId: parsed.threadId ?? null,
69
+ repoFingerprint: parsed.repoFingerprint ?? null,
70
+ remoteUrl: parsed.remoteUrl ?? null,
71
+ defaultBranch: parsed.defaultBranch ?? null,
72
+ preferredBranch: parsed.preferredBranch ?? parsed.defaultBranch ?? null
73
+ };
74
+ } catch {
75
+ return null;
76
+ }
77
+ }
78
+ async function writeCollabBinding(repoRoot, binding) {
79
+ const filePath = getCollabBindingPath(repoRoot);
80
+ await writeJsonAtomic(filePath, {
81
+ schemaVersion: 1,
82
+ ...binding
83
+ });
84
+ return filePath;
85
+ }
86
+
87
+ export {
88
+ reserveDirectory,
89
+ reserveAvailableDirPath,
90
+ getCollabBindingPath,
91
+ readCollabBinding,
92
+ writeCollabBinding
93
+ };