@remixhq/core 0.1.10 → 0.1.12
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.
- package/dist/api.d.ts +29 -0
- package/dist/api.js +1 -1
- package/dist/binding.d.ts +9 -4
- package/dist/binding.js +3 -1
- package/dist/chunk-4L3ZBZUQ.js +281 -0
- package/dist/chunk-BNKPTE2U.js +401 -0
- package/dist/chunk-C5NBNU32.js +240 -0
- package/dist/chunk-DXCL6I4Q.js +399 -0
- package/dist/chunk-HZNEDSRS.js +0 -0
- package/dist/chunk-IXWQWFYT.js +342 -0
- package/dist/chunk-K54U353Z.js +691 -0
- package/dist/chunk-RM2BGDBB.js +400 -0
- package/dist/chunk-ZXP6ENQY.js +244 -0
- package/dist/collab.d.ts +49 -7
- package/dist/collab.js +1071 -139
- package/dist/index.js +1 -1
- package/dist/repo.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCurrentBranch
|
|
3
|
+
} from "./chunk-RREREIGW.js";
|
|
4
|
+
import {
|
|
5
|
+
RemixError
|
|
6
|
+
} from "./chunk-YZ34ICNN.js";
|
|
7
|
+
|
|
8
|
+
// src/infrastructure/binding/collabBindingStore.ts
|
|
9
|
+
import fs2 from "fs/promises";
|
|
10
|
+
import path2 from "path";
|
|
11
|
+
|
|
12
|
+
// src/shared/fs.ts
|
|
13
|
+
import fs from "fs/promises";
|
|
14
|
+
import path from "path";
|
|
15
|
+
async function reserveDirectory(targetDir) {
|
|
16
|
+
try {
|
|
17
|
+
await fs.mkdir(targetDir);
|
|
18
|
+
return targetDir;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (error?.code === "EEXIST") {
|
|
21
|
+
throw new RemixError("Output directory already exists.", {
|
|
22
|
+
exitCode: 2,
|
|
23
|
+
hint: `Choose an empty destination path: ${targetDir}`
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function reserveAvailableDirPath(preferredDir) {
|
|
30
|
+
const parent = path.dirname(preferredDir);
|
|
31
|
+
const base = path.basename(preferredDir);
|
|
32
|
+
for (let i = 1; i <= 1e3; i += 1) {
|
|
33
|
+
const candidate = i === 1 ? preferredDir : path.join(parent, `${base}-${i}`);
|
|
34
|
+
try {
|
|
35
|
+
await fs.mkdir(candidate);
|
|
36
|
+
return candidate;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error?.code === "EEXIST") continue;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
throw new RemixError("No available output directory name.", {
|
|
43
|
+
exitCode: 2,
|
|
44
|
+
hint: `Tried ${base} through ${base}-1000 under ${parent}.`
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async function writeJsonAtomic(filePath, value) {
|
|
48
|
+
const dir = path.dirname(filePath);
|
|
49
|
+
await fs.mkdir(dir, { recursive: true });
|
|
50
|
+
const tmp = `${filePath}.tmp-${Date.now()}`;
|
|
51
|
+
await fs.writeFile(tmp, `${JSON.stringify(value, null, 2)}
|
|
52
|
+
`, "utf8");
|
|
53
|
+
await fs.rename(tmp, filePath);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/infrastructure/binding/collabBindingStore.ts
|
|
57
|
+
function getCollabBindingPath(repoRoot) {
|
|
58
|
+
return path2.join(repoRoot, ".remix", "config.json");
|
|
59
|
+
}
|
|
60
|
+
function buildBindingFileV3(params) {
|
|
61
|
+
return {
|
|
62
|
+
schemaVersion: 3,
|
|
63
|
+
repoFingerprint: params.repoFingerprint,
|
|
64
|
+
remoteUrl: params.remoteUrl,
|
|
65
|
+
defaultBranch: params.defaultBranch,
|
|
66
|
+
branchBindings: params.branchBindings,
|
|
67
|
+
...params.explicitRootBinding ? { explicitRootBinding: params.explicitRootBinding } : {}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function normalizeBranchName(value) {
|
|
71
|
+
const normalized = String(value ?? "").trim();
|
|
72
|
+
return normalized || null;
|
|
73
|
+
}
|
|
74
|
+
function normalizeProjectId(value) {
|
|
75
|
+
const normalized = String(value ?? "").trim();
|
|
76
|
+
return normalized || null;
|
|
77
|
+
}
|
|
78
|
+
function normalizeBranchBinding(value) {
|
|
79
|
+
if (!value?.currentAppId || !value?.upstreamAppId) return null;
|
|
80
|
+
return {
|
|
81
|
+
projectId: normalizeProjectId(value.projectId),
|
|
82
|
+
currentAppId: value.currentAppId,
|
|
83
|
+
upstreamAppId: value.upstreamAppId,
|
|
84
|
+
threadId: value.threadId ?? null,
|
|
85
|
+
laneId: value.laneId ?? null,
|
|
86
|
+
bindingMode: value.bindingMode === "legacy" ? "legacy" : value.bindingMode === "explicit_root" ? "explicit_root" : "lane"
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function buildResolvedBinding(params) {
|
|
90
|
+
if (!params.binding) return null;
|
|
91
|
+
return {
|
|
92
|
+
schemaVersion: 3,
|
|
93
|
+
projectId: params.binding.projectId ?? params.fallbackProjectId,
|
|
94
|
+
currentAppId: params.binding.currentAppId,
|
|
95
|
+
upstreamAppId: params.binding.upstreamAppId,
|
|
96
|
+
threadId: params.binding.threadId,
|
|
97
|
+
repoFingerprint: params.repoFingerprint,
|
|
98
|
+
remoteUrl: params.remoteUrl,
|
|
99
|
+
defaultBranch: params.defaultBranch,
|
|
100
|
+
laneId: params.binding.laneId,
|
|
101
|
+
branchName: params.branchName,
|
|
102
|
+
bindingMode: params.binding.bindingMode
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function deriveFallbackProjectId(params) {
|
|
106
|
+
const candidates = [
|
|
107
|
+
params.currentBranch ? params.branchBindings[params.currentBranch]?.projectId ?? null : null,
|
|
108
|
+
params.defaultBranch ? params.branchBindings[params.defaultBranch]?.projectId ?? null : null,
|
|
109
|
+
...Object.values(params.branchBindings).map((binding) => binding.projectId),
|
|
110
|
+
params.legacyProjectId
|
|
111
|
+
];
|
|
112
|
+
for (const candidate of candidates) {
|
|
113
|
+
if (candidate) return candidate;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
async function readCollabBindingState(repoRoot, options) {
|
|
118
|
+
try {
|
|
119
|
+
const persist = options?.persist === true;
|
|
120
|
+
const filePath = getCollabBindingPath(repoRoot);
|
|
121
|
+
const raw = await fs2.readFile(filePath, "utf8");
|
|
122
|
+
const parsed = JSON.parse(raw);
|
|
123
|
+
if (!parsed || typeof parsed !== "object") return null;
|
|
124
|
+
const currentBranch = normalizeBranchName(await getCurrentBranch(repoRoot).catch(() => null));
|
|
125
|
+
if (parsed.schemaVersion === 1) {
|
|
126
|
+
if (!parsed.currentAppId || !parsed.upstreamAppId) return null;
|
|
127
|
+
const projectId = normalizeProjectId(parsed.projectId);
|
|
128
|
+
const preferredBranch = normalizeBranchName(parsed.preferredBranch ?? parsed.defaultBranch ?? null);
|
|
129
|
+
const branchKey = preferredBranch ?? currentBranch ?? null;
|
|
130
|
+
const branchBindings2 = branchKey ? {
|
|
131
|
+
[branchKey]: {
|
|
132
|
+
projectId,
|
|
133
|
+
currentAppId: parsed.currentAppId,
|
|
134
|
+
upstreamAppId: parsed.upstreamAppId,
|
|
135
|
+
threadId: parsed.threadId ?? null,
|
|
136
|
+
laneId: null,
|
|
137
|
+
bindingMode: "legacy"
|
|
138
|
+
}
|
|
139
|
+
} : {};
|
|
140
|
+
const migratedFile = buildBindingFileV3({
|
|
141
|
+
repoFingerprint: parsed.repoFingerprint ?? null,
|
|
142
|
+
remoteUrl: parsed.remoteUrl ?? null,
|
|
143
|
+
defaultBranch: parsed.defaultBranch ?? null,
|
|
144
|
+
branchBindings: branchBindings2
|
|
145
|
+
});
|
|
146
|
+
if (persist) {
|
|
147
|
+
try {
|
|
148
|
+
await writeJsonAtomic(filePath, migratedFile);
|
|
149
|
+
} catch {
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
schemaVersion: 3,
|
|
154
|
+
projectId,
|
|
155
|
+
repoFingerprint: migratedFile.repoFingerprint,
|
|
156
|
+
remoteUrl: migratedFile.remoteUrl,
|
|
157
|
+
defaultBranch: migratedFile.defaultBranch,
|
|
158
|
+
currentBranch,
|
|
159
|
+
branchBindings: migratedFile.branchBindings,
|
|
160
|
+
explicitRootBinding: null,
|
|
161
|
+
binding: buildResolvedBinding({
|
|
162
|
+
fallbackProjectId: projectId,
|
|
163
|
+
repoFingerprint: migratedFile.repoFingerprint,
|
|
164
|
+
remoteUrl: migratedFile.remoteUrl,
|
|
165
|
+
defaultBranch: migratedFile.defaultBranch,
|
|
166
|
+
branchName: branchKey,
|
|
167
|
+
binding: branchKey ? migratedFile.branchBindings[branchKey] : null
|
|
168
|
+
})
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (parsed.schemaVersion !== 2 && parsed.schemaVersion !== 3) return null;
|
|
172
|
+
const file = parsed;
|
|
173
|
+
let shouldPersistNormalizedBranchBindings = false;
|
|
174
|
+
const legacyProjectId = normalizeProjectId(file.projectId);
|
|
175
|
+
const branchBindings = Object.fromEntries(
|
|
176
|
+
Object.entries(file.branchBindings ?? {}).map(([branchName, branchBinding]) => {
|
|
177
|
+
const normalized = normalizeBranchBinding(branchBinding);
|
|
178
|
+
const rawProjectId = branchBinding && typeof branchBinding === "object" && "projectId" in branchBinding ? normalizeProjectId(branchBinding.projectId) : null;
|
|
179
|
+
const rawBindingMode = branchBinding && typeof branchBinding === "object" && "bindingMode" in branchBinding ? branchBinding.bindingMode : null;
|
|
180
|
+
const hasLegacyPreferredBranch = Boolean(branchBinding) && typeof branchBinding === "object" && "preferredBranch" in branchBinding;
|
|
181
|
+
let normalizedWithProject = normalized;
|
|
182
|
+
if (normalizedWithProject && !normalizedWithProject.projectId && legacyProjectId) {
|
|
183
|
+
normalizedWithProject = {
|
|
184
|
+
...normalizedWithProject,
|
|
185
|
+
projectId: legacyProjectId
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (normalizedWithProject && (rawBindingMode !== normalizedWithProject.bindingMode || hasLegacyPreferredBranch || rawProjectId !== normalizedWithProject.projectId)) {
|
|
189
|
+
shouldPersistNormalizedBranchBindings = true;
|
|
190
|
+
}
|
|
191
|
+
return [branchName, normalizedWithProject];
|
|
192
|
+
}).filter((entry) => Boolean(entry[1]))
|
|
193
|
+
);
|
|
194
|
+
const legacyExplicitBinding = normalizeBranchBinding(file.explicitBinding ?? null);
|
|
195
|
+
const legacyExplicitBranch = currentBranch ?? normalizeBranchName(file.defaultBranch);
|
|
196
|
+
if (legacyExplicitBinding && legacyExplicitBranch) {
|
|
197
|
+
branchBindings[legacyExplicitBranch] = {
|
|
198
|
+
...legacyExplicitBinding,
|
|
199
|
+
projectId: legacyExplicitBinding.projectId ?? branchBindings[legacyExplicitBranch]?.projectId ?? legacyProjectId,
|
|
200
|
+
bindingMode: "lane"
|
|
201
|
+
};
|
|
202
|
+
shouldPersistNormalizedBranchBindings = true;
|
|
203
|
+
}
|
|
204
|
+
let explicitRootBinding = normalizeBranchBinding(file.explicitRootBinding ?? null);
|
|
205
|
+
if (explicitRootBinding && !explicitRootBinding.projectId && legacyProjectId) {
|
|
206
|
+
explicitRootBinding = {
|
|
207
|
+
...explicitRootBinding,
|
|
208
|
+
projectId: legacyProjectId
|
|
209
|
+
};
|
|
210
|
+
shouldPersistNormalizedBranchBindings = true;
|
|
211
|
+
}
|
|
212
|
+
if (explicitRootBinding && explicitRootBinding.bindingMode !== "explicit_root") {
|
|
213
|
+
explicitRootBinding = {
|
|
214
|
+
...explicitRootBinding,
|
|
215
|
+
bindingMode: "explicit_root"
|
|
216
|
+
};
|
|
217
|
+
shouldPersistNormalizedBranchBindings = true;
|
|
218
|
+
}
|
|
219
|
+
if (persist && ("explicitBinding" in file || "explicitRootBinding" in file || shouldPersistNormalizedBranchBindings || parsed.schemaVersion === 2)) {
|
|
220
|
+
try {
|
|
221
|
+
await writeJsonAtomic(
|
|
222
|
+
filePath,
|
|
223
|
+
buildBindingFileV3({
|
|
224
|
+
repoFingerprint: file.repoFingerprint ?? null,
|
|
225
|
+
remoteUrl: file.remoteUrl ?? null,
|
|
226
|
+
defaultBranch: file.defaultBranch ?? null,
|
|
227
|
+
branchBindings,
|
|
228
|
+
explicitRootBinding
|
|
229
|
+
})
|
|
230
|
+
);
|
|
231
|
+
} catch {
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const resolvedBranch = currentBranch ?? normalizeBranchName(file.defaultBranch);
|
|
235
|
+
const fallbackProjectId = deriveFallbackProjectId({
|
|
236
|
+
branchBindings,
|
|
237
|
+
currentBranch: resolvedBranch,
|
|
238
|
+
defaultBranch: normalizeBranchName(file.defaultBranch),
|
|
239
|
+
legacyProjectId: explicitRootBinding?.projectId ?? legacyProjectId
|
|
240
|
+
});
|
|
241
|
+
const resolvedBinding = buildResolvedBinding({
|
|
242
|
+
fallbackProjectId,
|
|
243
|
+
repoFingerprint: file.repoFingerprint ?? null,
|
|
244
|
+
remoteUrl: file.remoteUrl ?? null,
|
|
245
|
+
defaultBranch: file.defaultBranch ?? null,
|
|
246
|
+
branchName: resolvedBranch,
|
|
247
|
+
binding: resolvedBranch ? branchBindings[resolvedBranch] ?? null : null
|
|
248
|
+
}) ?? (resolvedBranch && resolvedBranch === normalizeBranchName(file.defaultBranch) && explicitRootBinding ? buildResolvedBinding({
|
|
249
|
+
fallbackProjectId,
|
|
250
|
+
repoFingerprint: file.repoFingerprint ?? null,
|
|
251
|
+
remoteUrl: file.remoteUrl ?? null,
|
|
252
|
+
defaultBranch: file.defaultBranch ?? null,
|
|
253
|
+
branchName: normalizeBranchName(file.defaultBranch),
|
|
254
|
+
binding: explicitRootBinding
|
|
255
|
+
}) : null);
|
|
256
|
+
return {
|
|
257
|
+
schemaVersion: parsed.schemaVersion,
|
|
258
|
+
projectId: fallbackProjectId,
|
|
259
|
+
repoFingerprint: file.repoFingerprint ?? null,
|
|
260
|
+
remoteUrl: file.remoteUrl ?? null,
|
|
261
|
+
defaultBranch: file.defaultBranch ?? null,
|
|
262
|
+
currentBranch,
|
|
263
|
+
branchBindings,
|
|
264
|
+
explicitRootBinding: buildResolvedBinding({
|
|
265
|
+
fallbackProjectId,
|
|
266
|
+
repoFingerprint: file.repoFingerprint ?? null,
|
|
267
|
+
remoteUrl: file.remoteUrl ?? null,
|
|
268
|
+
defaultBranch: file.defaultBranch ?? null,
|
|
269
|
+
branchName: normalizeBranchName(file.defaultBranch),
|
|
270
|
+
binding: explicitRootBinding
|
|
271
|
+
}),
|
|
272
|
+
binding: resolvedBinding
|
|
273
|
+
};
|
|
274
|
+
} catch {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async function readCollabBinding(repoRoot) {
|
|
279
|
+
const state = await readCollabBindingState(repoRoot);
|
|
280
|
+
return state?.binding ?? null;
|
|
281
|
+
}
|
|
282
|
+
async function writeCollabBinding(repoRoot, binding) {
|
|
283
|
+
const filePath = getCollabBindingPath(repoRoot);
|
|
284
|
+
const currentBranch = normalizeBranchName(await getCurrentBranch(repoRoot).catch(() => null));
|
|
285
|
+
const branchName = normalizeBranchName(binding.branchName) ?? currentBranch ?? binding.defaultBranch ?? "main";
|
|
286
|
+
const existing = await readCollabBindingState(repoRoot, { persist: true });
|
|
287
|
+
const branchBindings = { ...existing?.branchBindings ?? {} };
|
|
288
|
+
branchBindings[branchName] = {
|
|
289
|
+
projectId: normalizeProjectId(binding.projectId) ?? branchBindings[branchName]?.projectId ?? existing?.projectId ?? null,
|
|
290
|
+
currentAppId: binding.currentAppId,
|
|
291
|
+
upstreamAppId: binding.upstreamAppId,
|
|
292
|
+
threadId: binding.threadId ?? null,
|
|
293
|
+
laneId: binding.laneId ?? null,
|
|
294
|
+
bindingMode: binding.bindingMode ?? "lane"
|
|
295
|
+
};
|
|
296
|
+
const explicitRootBinding = binding.bindingMode === "explicit_root" ? {
|
|
297
|
+
...branchBindings[branchName],
|
|
298
|
+
bindingMode: "explicit_root"
|
|
299
|
+
} : existing?.explicitRootBinding ? {
|
|
300
|
+
projectId: existing.explicitRootBinding.projectId,
|
|
301
|
+
currentAppId: existing.explicitRootBinding.currentAppId,
|
|
302
|
+
upstreamAppId: existing.explicitRootBinding.upstreamAppId,
|
|
303
|
+
threadId: existing.explicitRootBinding.threadId,
|
|
304
|
+
laneId: existing.explicitRootBinding.laneId,
|
|
305
|
+
bindingMode: "explicit_root"
|
|
306
|
+
} : null;
|
|
307
|
+
await writeJsonAtomic(
|
|
308
|
+
filePath,
|
|
309
|
+
buildBindingFileV3({
|
|
310
|
+
repoFingerprint: binding.repoFingerprint ?? null,
|
|
311
|
+
remoteUrl: binding.remoteUrl ?? null,
|
|
312
|
+
defaultBranch: binding.defaultBranch ?? null,
|
|
313
|
+
branchBindings,
|
|
314
|
+
explicitRootBinding
|
|
315
|
+
})
|
|
316
|
+
);
|
|
317
|
+
return filePath;
|
|
318
|
+
}
|
|
319
|
+
async function writeCollabBindingSnapshot(params) {
|
|
320
|
+
const filePath = getCollabBindingPath(params.repoRoot);
|
|
321
|
+
await writeJsonAtomic(
|
|
322
|
+
filePath,
|
|
323
|
+
buildBindingFileV3({
|
|
324
|
+
repoFingerprint: params.repoFingerprint,
|
|
325
|
+
remoteUrl: params.remoteUrl,
|
|
326
|
+
defaultBranch: params.defaultBranch,
|
|
327
|
+
branchBindings: params.branchBindings,
|
|
328
|
+
explicitRootBinding: params.explicitRootBinding ?? null
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
return filePath;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export {
|
|
335
|
+
reserveDirectory,
|
|
336
|
+
reserveAvailableDirPath,
|
|
337
|
+
getCollabBindingPath,
|
|
338
|
+
readCollabBindingState,
|
|
339
|
+
readCollabBinding,
|
|
340
|
+
writeCollabBinding,
|
|
341
|
+
writeCollabBindingSnapshot
|
|
342
|
+
};
|