Format authored monorepo code with pinned language formatters
This commit is contained in:
@@ -19,7 +19,11 @@ export const planAtomScaffold = (workspace: string, name: string, id: string) =>
|
||||
|
||||
/** Validate an in-memory proposal before creating files. Never replace a fragment. */
|
||||
export const scaffoldAtom = async (options: {
|
||||
root: string; name: string; id: string; write: boolean; resolveResource: CapabilityRepositoryResolver;
|
||||
root: string;
|
||||
name: string;
|
||||
id: string;
|
||||
write: boolean;
|
||||
resolveResource: CapabilityRepositoryResolver;
|
||||
}) => {
|
||||
const before = await readQxSource(options.root, "workspace.qx");
|
||||
const plan = planAtomScaffold(before, options.name, options.id);
|
||||
@@ -31,14 +35,17 @@ export const scaffoldAtom = async (options: {
|
||||
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
||||
}
|
||||
const observed = new Map<string, string>();
|
||||
await compileWorkspaceRepository({ rootDirectory: options.root, resolveResource: options.resolveResource,
|
||||
await compileWorkspaceRepository({
|
||||
rootDirectory: options.root,
|
||||
resolveResource: options.resolveResource,
|
||||
readSource: async (name) => {
|
||||
if (name === "workspace.qx") return plan.workspace;
|
||||
if (name === plan.fileName) return plan.fragment;
|
||||
const text = await readQxSource(options.root, name);
|
||||
observed.set(name, text);
|
||||
return text;
|
||||
} });
|
||||
},
|
||||
});
|
||||
if (!options.write) return plan;
|
||||
const workspacePath = path.join(options.root, "workspace.qx");
|
||||
const temporary = path.join(options.root, `.qx-scaffold-${randomUUID()}.tmp`);
|
||||
@@ -47,13 +54,22 @@ export const scaffoldAtom = async (options: {
|
||||
try {
|
||||
const fragment = await open(fragmentPath, "wx");
|
||||
createdFragment = true;
|
||||
try { await fragment.writeFile(plan.fragment); } finally { await fragment.close(); }
|
||||
try {
|
||||
await fragment.writeFile(plan.fragment);
|
||||
} finally {
|
||||
await fragment.close();
|
||||
}
|
||||
const file = await open(temporary, "wx", (await lstat(workspacePath)).mode);
|
||||
createdTemporary = true;
|
||||
try { await file.writeFile(plan.workspace); } finally { await file.close(); }
|
||||
try {
|
||||
await file.writeFile(plan.workspace);
|
||||
} finally {
|
||||
await file.close();
|
||||
}
|
||||
observed.set("workspace.qx", before);
|
||||
for (const [name, text] of observed) {
|
||||
if (await readQxSource(options.root, name) !== text) throw new Error(`QX source changed during scaffolding: ${name}`);
|
||||
if ((await readQxSource(options.root, name)) !== text)
|
||||
throw new Error(`QX source changed during scaffolding: ${name}`);
|
||||
}
|
||||
await rename(temporary, workspacePath);
|
||||
createdTemporary = false;
|
||||
|
||||
Reference in New Issue
Block a user