fix(linter): ensure tslint converter works with pnp (#18323)

This commit is contained in:
Miroslav Jonaš 2023-07-28 11:09:07 +02:00 committed by GitHub
parent eb392109f7
commit f4b7ec2c0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 5 deletions

View File

@ -14,7 +14,17 @@ import { conversionGenerator } from './convert-tslint-to-eslint';
/** /**
* Don't run actual child_process implementation of installPackagesTask() * Don't run actual child_process implementation of installPackagesTask()
*/ */
jest.mock('child_process'); jest.mock('child_process', () => {
return {
...jest.requireActual<any>('child_process'),
execSync: jest.fn((command: string) => {
if (command.includes('pnpm --version')) {
return '8.2.0';
}
return;
}),
};
});
const appProjectName = 'angular-app-1'; const appProjectName = 'angular-app-1';
const appProjectRoot = `apps/${appProjectName}`; const appProjectRoot = `apps/${appProjectName}`;

View File

@ -13,7 +13,17 @@ import { conversionGenerator } from './convert-tslint-to-eslint';
/** /**
* Don't run actual child_process implementation of installPackagesTask() * Don't run actual child_process implementation of installPackagesTask()
*/ */
jest.mock('child_process'); jest.mock('child_process', () => {
return {
...jest.requireActual<any>('child_process'),
execSync: jest.fn((command: string) => {
if (command.includes('pnpm --version')) {
return '8.2.0';
}
return;
}),
};
});
const projectName = 'e2e-app-1'; const projectName = 'e2e-app-1';
const projectRoot = `apps/${projectName}`; const projectRoot = `apps/${projectName}`;

View File

@ -103,8 +103,9 @@ export async function convertToESLintConfig(
*/ */
writeJsonFile(pathToTslintJson, updatedTSLintJson); writeJsonFile(pathToTslintJson, updatedTSLintJson);
} }
const pm = getPackageManagerCommand();
const reportedConfiguration = await findReportedConfiguration( const reportedConfiguration = await findReportedConfiguration(
'npx tslint --print-config', `${pm.exec} tslint --print-config`,
pathToTslintJson 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 * This error could occur if, for example, the user does not have a TSLint plugin installed correctly that they
* reference in their config. * reference in their config.
*/ */
const printConfigFailureMessageStart = const printConfigFailureMessageStart = `Command failed: ${pm.exec} tslint --print-config "tslint.json"`;
'Command failed: npx tslint --print-config "tslint.json"';
if ( if (
reportedConfiguration.message.startsWith(printConfigFailureMessageStart) reportedConfiguration.message.startsWith(printConfigFailureMessageStart)
) { ) {