Skip to content

Commit

Permalink
fix(misc): do not print formatting errors while setting up nx cloud i…
Browse files Browse the repository at this point in the history
…n nx init (nrwl#21302)
  • Loading branch information
leosvelperez authored Jan 24, 2024
1 parent d9c53e1 commit 70fd808
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"type": "string",
"description": "Name of Nx Cloud installation invoker (ex. user, add-nx-to-monorepo, create-nx-workspace, nx-upgrade",
"default": "user"
},
"hideFormatLogs": {
"type": "boolean",
"description": "Hide formatting logs",
"x-priority": "internal"
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/command-line/init/init-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export async function initHandler(options: InitArgs): Promise<void> {
if (useNxCloud) {
output.log({ title: '🛠️ Setting up Nx Cloud' });
execSync(
`${pmc.exec} nx g nx:connect-to-nx-cloud --installationSource=nx-init-pcv3 --quiet --no-interactive`,
`${pmc.exec} nx g nx:connect-to-nx-cloud --installationSource=nx-init-pcv3 --quiet --hideFormatLogs --no-interactive`,
{
stdio: [0, 1, 2],
cwd: repoRoot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import type * as Prettier from 'prettier';
* @param tree - the file system tree
*/
export async function formatChangedFilesWithPrettierIfAvailable(
tree: Tree
tree: Tree,
options?: {
silent?: boolean;
}
): Promise<void> {
let prettier: typeof Prettier;
try {
Expand Down Expand Up @@ -51,7 +54,9 @@ export async function formatChangedFilesWithPrettierIfAvailable(
| string)
);
} catch (e) {
console.warn(`Could not format ${file.path}. Error: "${e.message}"`);
if (!options?.silent) {
console.warn(`Could not format ${file.path}. Error: "${e.message}"`);
}
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function printSuccessMessage(url: string) {
interface ConnectToNxCloudOptions {
analytics: boolean;
installationSource: string;
hideFormatLogs?: boolean;
}

function addNxCloudOptionsToNxJson(
Expand Down Expand Up @@ -135,7 +136,9 @@ export async function connectToNxCloud(

addNxCloudOptionsToNxJson(tree, nxJson, r.token);

await formatChangedFilesWithPrettierIfAvailable(tree);
await formatChangedFilesWithPrettierIfAvailable(tree, {
silent: schema.hideFormatLogs,
});

return () => printSuccessMessage(r.url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"type": "string",
"description": "Name of Nx Cloud installation invoker (ex. user, add-nx-to-monorepo, create-nx-workspace, nx-upgrade",
"default": "user"
},
"hideFormatLogs": {
"type": "boolean",
"description": "Hide formatting logs",
"x-priority": "internal"
}
},
"additionalProperties": false,
Expand Down

0 comments on commit 70fd808

Please sign in to comment.