Skip to content

Commit

Permalink
fix(js): ensure prettier is available for generators if it is meant t…
Browse files Browse the repository at this point in the history
…o be installed (#28082)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
leosvelperez authored Sep 25, 2024
1 parent 6182d20 commit 4fa50ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/js/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ export async function initGeneratorInternal(
: () => {};
tasks.push(installTask);

if (!schema.skipPackageJson && 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);
Expand Down
7 changes: 4 additions & 3 deletions packages/js/src/generators/setup-prettier/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export async function setupPrettierGenerator(
skipPackageJson: options.skipPackageJson,
});

if (!options.skipPackageJson) {
ensurePackage('prettier', prettierVersion);
}

if (!options.skipFormat) {
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);
Expand Down

0 comments on commit 4fa50ad

Please sign in to comment.