feat: support shared project registration
This commit is contained in:
54
dist/index.cjs
vendored
54
dist/index.cjs
vendored
@@ -15124,7 +15124,7 @@ async function writeSingleFileAtomically(target, content) {
|
||||
fail(`Failed to update ${target}: ${detail}`);
|
||||
}
|
||||
}
|
||||
async function registerProject(harnessRoot, projectId, projectPathInput) {
|
||||
async function registerProject(harnessRoot, projectId, projectPathInput, scope = "local") {
|
||||
if (!SLUG_PATTERN.test(projectId)) {
|
||||
fail(`Invalid project id: ${projectId}`);
|
||||
}
|
||||
@@ -15141,7 +15141,12 @@ async function registerProject(harnessRoot, projectId, projectPathInput) {
|
||||
if (existing) {
|
||||
const existingPath = import_node_path.default.resolve(context.workspaceRoot, existing.path);
|
||||
if (comparablePath(existingPath) === comparablePath(candidate)) {
|
||||
return { changed: false, path: projectPath };
|
||||
if (scope === "shared" && existing.source === "local") {
|
||||
fail(
|
||||
`Project ${projectId} is already registered locally. Remove it from workspace.local.yml before shared registration.`
|
||||
);
|
||||
}
|
||||
return { changed: false, path: projectPath, source: existing.source };
|
||||
}
|
||||
fail(`Project id is already registered with another path: ${projectId}`);
|
||||
}
|
||||
@@ -15152,25 +15157,40 @@ async function registerProject(harnessRoot, projectId, projectPathInput) {
|
||||
if (profile.project.id !== projectId) {
|
||||
fail(`Profile project id does not match registration: ${profile.project.id} != ${projectId}`);
|
||||
}
|
||||
const localPath = import_node_path.default.join(context.harnessRoot, "workspace.local.yml");
|
||||
let local = { schema_version: 1, projects: {} };
|
||||
if (await pathExists(localPath)) {
|
||||
local = await loadWorkspaceDocument(localPath, context.validators);
|
||||
if (local.workspace_root !== void 0) {
|
||||
fail(`${localPath} must not override workspace_root.`);
|
||||
const registryPath = import_node_path.default.join(
|
||||
context.harnessRoot,
|
||||
scope === "shared" ? "workspace.yml" : "workspace.local.yml"
|
||||
);
|
||||
let registry = { schema_version: 1, projects: {} };
|
||||
if (await pathExists(registryPath)) {
|
||||
registry = await loadWorkspaceDocument(registryPath, context.validators);
|
||||
if (scope === "local" && registry.workspace_root !== void 0) {
|
||||
fail(`${registryPath} must not override workspace_root.`);
|
||||
}
|
||||
}
|
||||
if (local.projects[projectId]) {
|
||||
fail(`Project id already exists in ${localPath}: ${projectId}`);
|
||||
if (scope === "shared" && !registry.workspace_root) {
|
||||
fail(`${registryPath} must declare workspace_root.`);
|
||||
}
|
||||
local.projects[projectId] = { path: projectPath };
|
||||
const sortedProjects = Object.fromEntries(
|
||||
Object.entries(local.projects).sort(([left], [right]) => left.localeCompare(right))
|
||||
if (registry.projects[projectId]) {
|
||||
fail(`Project id already exists in ${registryPath}: ${projectId}`);
|
||||
}
|
||||
registry.projects[projectId] = { path: projectPath };
|
||||
const projects = scope === "local" ? Object.fromEntries(
|
||||
Object.entries(registry.projects).sort(([left], [right]) => left.localeCompare(right))
|
||||
) : registry.projects;
|
||||
const document = scope === "shared" ? {
|
||||
schema_version: 1,
|
||||
workspace_root: registry.workspace_root,
|
||||
projects
|
||||
} : { schema_version: 1, projects };
|
||||
const normalized = normalizeNewlines((0, import_yaml.stringify)(document));
|
||||
const serialized = scope === "shared" ? normalized.replace("\nprojects:\n", "\n\nprojects:\n") : normalized;
|
||||
await writeSingleFileAtomically(
|
||||
registryPath,
|
||||
serialized.endsWith("\n") ? serialized : `${serialized}
|
||||
`
|
||||
);
|
||||
const serialized = normalizeNewlines((0, import_yaml.stringify)({ schema_version: 1, projects: sortedProjects }));
|
||||
await writeSingleFileAtomically(localPath, serialized.endsWith("\n") ? serialized : `${serialized}
|
||||
`);
|
||||
return { changed: true, path: projectPath };
|
||||
return { changed: true, path: projectPath, source: scope };
|
||||
}
|
||||
async function listProjects(harnessRoot) {
|
||||
const context = await loadHarnessContext(harnessRoot);
|
||||
|
||||
Reference in New Issue
Block a user