From f4b7ec2c0decda0fc87c2d536a340e3b43c6452a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Fri, 28 Jul 2023 11:09:07 +0200 Subject: [PATCH] fix(linter): ensure tslint converter works with pnp (#18323) --- .../convert-tslint-to-eslint.spec.ts | 12 +++++++++++- .../convert-tslint-to-eslint.spec.ts | 12 +++++++++++- .../convert-to-eslint-config.ts | 6 +++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/angular/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.spec.ts b/packages/angular/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.spec.ts index cbcf10b79c527..cf2c2412c76ef 100644 --- a/packages/angular/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.spec.ts +++ b/packages/angular/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.spec.ts @@ -14,7 +14,17 @@ import { conversionGenerator } from './convert-tslint-to-eslint'; /** * Don't run actual child_process implementation of installPackagesTask() */ -jest.mock('child_process'); +jest.mock('child_process', () => { + return { + ...jest.requireActual('child_process'), + execSync: jest.fn((command: string) => { + if (command.includes('pnpm --version')) { + return '8.2.0'; + } + return; + }), + }; +}); const appProjectName = 'angular-app-1'; const appProjectRoot = `apps/${appProjectName}`; diff --git a/packages/cypress/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.spec.ts b/packages/cypress/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.spec.ts index 0e981c95d1dd0..4cbcbc7b57a81 100644 --- a/packages/cypress/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.spec.ts +++ b/packages/cypress/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.spec.ts @@ -13,7 +13,17 @@ import { conversionGenerator } from './convert-tslint-to-eslint'; /** * Don't run actual child_process implementation of installPackagesTask() */ -jest.mock('child_process'); +jest.mock('child_process', () => { + return { + ...jest.requireActual('child_process'), + execSync: jest.fn((command: string) => { + if (command.includes('pnpm --version')) { + return '8.2.0'; + } + return; + }), + }; +}); const projectName = 'e2e-app-1'; const projectRoot = `apps/${projectName}`; diff --git a/packages/linter/src/utils/convert-tslint-to-eslint/convert-to-eslint-config.ts b/packages/linter/src/utils/convert-tslint-to-eslint/convert-to-eslint-config.ts index ffa41f252c5c8..a29113863f82e 100644 --- a/packages/linter/src/utils/convert-tslint-to-eslint/convert-to-eslint-config.ts +++ b/packages/linter/src/utils/convert-tslint-to-eslint/convert-to-eslint-config.ts @@ -103,8 +103,9 @@ export async function convertToESLintConfig( */ writeJsonFile(pathToTslintJson, updatedTSLintJson); } + const pm = getPackageManagerCommand(); const reportedConfiguration = await findReportedConfiguration( - 'npx tslint --print-config', + `${pm.exec} tslint --print-config`, pathToTslintJson ); @@ -121,8 +122,7 @@ export async function convertToESLintConfig( * This error could occur if, for example, the user does not have a TSLint plugin installed correctly that they * reference in their config. */ - const printConfigFailureMessageStart = - 'Command failed: npx tslint --print-config "tslint.json"'; + const printConfigFailureMessageStart = `Command failed: ${pm.exec} tslint --print-config "tslint.json"`; if ( reportedConfiguration.message.startsWith(printConfigFailureMessageStart) ) {