From 68fa008a3ff709862b83cbbd824af75352e7d868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Tue, 24 Sep 2024 10:33:09 +0200 Subject: [PATCH] fix(js): do not ensure prettier package presence when skipPackageJson is true --- packages/js/src/generators/init/init.ts | 8 ++++++-- packages/js/src/generators/setup-prettier/generator.ts | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/js/src/generators/init/init.ts b/packages/js/src/generators/init/init.ts index 672fc8964e4a4..17a89b7f60723 100644 --- a/packages/js/src/generators/init/init.ts +++ b/packages/js/src/generators/init/init.ts @@ -121,8 +121,12 @@ export async function initGeneratorInternal( : () => {}; tasks.push(installTask); - if (!schema.skipFormat && schema.setUpPrettier) { - ensurePackage('prettier', prettierVersion); + if (!schema.skipFormat) { + if (!schema.skipPackageJson) { + ensurePackage('prettier', prettierVersion); + } + // even if skipPackageJson === true, we can safely run formatFiles, prettier might + // have been installed earlier and if not, the formatFiles function still handles it await formatFiles(tree); } diff --git a/packages/js/src/generators/setup-prettier/generator.ts b/packages/js/src/generators/setup-prettier/generator.ts index 85dd349fe9dc5..f73b3faa96c8e 100644 --- a/packages/js/src/generators/setup-prettier/generator.ts +++ b/packages/js/src/generators/setup-prettier/generator.ts @@ -17,7 +17,11 @@ export async function setupPrettierGenerator( }); if (!options.skipFormat) { - ensurePackage('prettier', prettierVersion); + if (!options.skipPackageJson) { + ensurePackage('prettier', prettierVersion); + } + // even if skipPackageJson === true, we can safely run formatFiles, prettier might + // have been installed earlier and if not, the formatFiles function still handles it await formatFiles(tree); }