Format authored monorepo code with pinned language formatters
This commit is contained in:
@@ -35,9 +35,9 @@ const parseArgs = (args: string[]) => {
|
||||
else positional.push(argument);
|
||||
}
|
||||
if (
|
||||
positional.length !== 1
|
||||
|| Boolean(workspaceId) !== Boolean(workspaceRevisionId)
|
||||
|| (resource && Boolean(workspaceId || workspaceRevisionId || sourceRootCommit))
|
||||
positional.length !== 1 ||
|
||||
Boolean(workspaceId) !== Boolean(workspaceRevisionId) ||
|
||||
(resource && Boolean(workspaceId || workspaceRevisionId || sourceRootCommit))
|
||||
) {
|
||||
throw new Error(usage);
|
||||
}
|
||||
@@ -50,14 +50,7 @@ const main = async () => {
|
||||
process.stdout.write(`${usage}\n`);
|
||||
return;
|
||||
}
|
||||
const {
|
||||
checkOnly,
|
||||
resource,
|
||||
workspaceId,
|
||||
workspaceRevisionId,
|
||||
sourceRootCommit,
|
||||
fileName,
|
||||
} = parseArgs(args);
|
||||
const { checkOnly, resource, workspaceId, workspaceRevisionId, sourceRootCommit, fileName } = parseArgs(args);
|
||||
const source =
|
||||
fileName === "-"
|
||||
? await new Promise<string>((resolve, reject) => {
|
||||
@@ -67,33 +60,33 @@ const main = async () => {
|
||||
process.stdin.on("error", reject);
|
||||
})
|
||||
: await readFile(fileName, "utf8");
|
||||
const reportDiagnostics = (diagnostics: readonly {
|
||||
fileName: string;
|
||||
line: number;
|
||||
column: number;
|
||||
phase: string;
|
||||
code: string;
|
||||
message: string;
|
||||
path?: string;
|
||||
}[]) => {
|
||||
const reportDiagnostics = (
|
||||
diagnostics: readonly {
|
||||
fileName: string;
|
||||
line: number;
|
||||
column: number;
|
||||
phase: string;
|
||||
code: string;
|
||||
message: string;
|
||||
path?: string;
|
||||
}[],
|
||||
) => {
|
||||
for (const diagnostic of diagnostics) {
|
||||
const location = diagnostic.line
|
||||
? `${diagnostic.fileName}:${diagnostic.line}:${diagnostic.column + 1}`
|
||||
: `${diagnostic.fileName}${diagnostic.path ? `:${diagnostic.path}` : ""}`;
|
||||
process.stderr.write(
|
||||
`${location}: ${diagnostic.phase} ${diagnostic.code}: ${diagnostic.message}\n`,
|
||||
);
|
||||
process.stderr.write(`${location}: ${diagnostic.phase} ${diagnostic.code}: ${diagnostic.message}\n`);
|
||||
}
|
||||
process.exitCode = 1;
|
||||
};
|
||||
if (resource) {
|
||||
const result = compileCapabilityResourceSource(source, {
|
||||
source: {
|
||||
repository: "https://compiler.invalid/resource.git",
|
||||
commit: "0000000000000000000000000000000000000000",
|
||||
},
|
||||
fileName,
|
||||
});
|
||||
source: {
|
||||
repository: "https://compiler.invalid/resource.git",
|
||||
commit: "0000000000000000000000000000000000000000",
|
||||
},
|
||||
fileName,
|
||||
});
|
||||
if (!result.ok) {
|
||||
reportDiagnostics(result.diagnostics);
|
||||
return;
|
||||
@@ -106,14 +99,15 @@ const main = async () => {
|
||||
reportDiagnostics(result.diagnostics);
|
||||
return;
|
||||
}
|
||||
const workspace = workspaceId && workspaceRevisionId
|
||||
? {
|
||||
...result.workspace,
|
||||
workspaceId: capabilityId.workspace(workspaceId),
|
||||
id: capabilityId.workspaceRevision(workspaceRevisionId),
|
||||
...(sourceRootCommit ? { sourceRootCommit } : {}),
|
||||
}
|
||||
: { ...result.workspace, ...(sourceRootCommit ? { sourceRootCommit } : {}) };
|
||||
const workspace =
|
||||
workspaceId && workspaceRevisionId
|
||||
? {
|
||||
...result.workspace,
|
||||
workspaceId: capabilityId.workspace(workspaceId),
|
||||
id: capabilityId.workspaceRevision(workspaceRevisionId),
|
||||
...(sourceRootCommit ? { sourceRootCommit } : {}),
|
||||
}
|
||||
: { ...result.workspace, ...(sourceRootCommit ? { sourceRootCommit } : {}) };
|
||||
const instantiated = compileWorkspaceRevision(workspace);
|
||||
if (!instantiated.ok) {
|
||||
throw new Error(instantiated.issues.map((issue) => `${issue.path}: ${issue.message}`).join("\n"));
|
||||
|
||||
Reference in New Issue
Block a user