-
Notifications
You must be signed in to change notification settings - Fork 101
Removed already-installed packages from install command #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import { createStubLogger, expectEqualWrites } from "../../adapters/logger.stubs"; | ||
import { createEmptyConversionResults } from "../../conversion/conversionResults.stubs"; | ||
import { logMissingPackages } from "./logMissingPackages"; | ||
import { PackageManager } from "./packageManagers"; | ||
|
||
const createStubDependencies = (packageManager = PackageManager.npm) => ({ | ||
choosePackageManager: async () => packageManager, | ||
logger: createStubLogger(), | ||
}); | ||
|
||
describe("logMissingPackages", () => { | ||
it("reports a singular message when one package is missing", async () => { | ||
// Arrange | ||
const { choosePackageManager, logger } = createStubDependencies(PackageManager.npm); | ||
const ruleConversionResults = createEmptyConversionResults(); | ||
|
||
// Act | ||
await logMissingPackages({ choosePackageManager, logger }, ruleConversionResults, { | ||
dependencies: { | ||
"@typescript-eslint/eslint-plugin": "*", | ||
"@typescript-eslint/parser": "*", | ||
}, | ||
devDependencies: {}, | ||
}); | ||
|
||
// Assert | ||
expectEqualWrites( | ||
logger.stdout.write, | ||
`⚡ 1 new package is required for this ESLint configuration. ⚡`, | ||
` npm install eslint --save-dev`, | ||
); | ||
}); | ||
|
||
it("does not include eslint-config-prettier when there are no extensions", async () => { | ||
// Arrange | ||
const { choosePackageManager, logger } = createStubDependencies(); | ||
const ruleConversionResults = createEmptyConversionResults({ | ||
extends: undefined, | ||
}); | ||
|
||
// Act | ||
await logMissingPackages({ choosePackageManager, logger }, ruleConversionResults); | ||
|
||
// Assert | ||
expectEqualWrites( | ||
logger.stdout.write, | ||
`⚡ 3 new packages are required for this ESLint configuration. ⚡`, | ||
` npm install @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint --save-dev`, | ||
); | ||
}); | ||
|
||
it("does not include eslint-config-prettier when extensions don't include eslint-config-prettier", async () => { | ||
// Arrange | ||
const { choosePackageManager, logger } = createStubDependencies(); | ||
const ruleConversionResults = createEmptyConversionResults({ | ||
extends: [], | ||
}); | ||
|
||
// Act | ||
await logMissingPackages({ choosePackageManager, logger }, ruleConversionResults); | ||
|
||
// Assert | ||
expectEqualWrites( | ||
logger.stdout.write, | ||
`⚡ 3 new packages are required for this ESLint configuration. ⚡`, | ||
` npm install @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint --save-dev`, | ||
); | ||
}); | ||
|
||
it("includes eslint-config-prettier when extensions include eslint-config-prettier", async () => { | ||
// Arrange | ||
const { choosePackageManager, logger } = createStubDependencies(); | ||
const ruleConversionResults = createEmptyConversionResults({ | ||
extends: ["plugin:eslint-config-prettier"], | ||
}); | ||
|
||
// Act | ||
await logMissingPackages({ choosePackageManager, logger }, ruleConversionResults); | ||
|
||
// Assert | ||
expectEqualWrites( | ||
logger.stdout.write, | ||
`⚡ 4 new packages are required for this ESLint configuration. ⚡`, | ||
` npm install @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier --save-dev`, | ||
); | ||
}); | ||
|
||
it("includes @typescript-eslint/eslint-plugin-tslint when there are missing conversions", async () => { | ||
// Arrange | ||
const { choosePackageManager, logger } = createStubDependencies(); | ||
const ruleConversionResults = createEmptyConversionResults({ | ||
missing: [ | ||
{ | ||
ruleArguments: [], | ||
ruleName: "missing-rule", | ||
ruleSeverity: "error", | ||
}, | ||
], | ||
}); | ||
|
||
// Act | ||
await logMissingPackages({ choosePackageManager, logger }, ruleConversionResults); | ||
|
||
// Assert | ||
expectEqualWrites( | ||
logger.stdout.write, | ||
`⚡ 4 new packages are required for this ESLint configuration. ⚡`, | ||
` npm install @typescript-eslint/eslint-plugin @typescript-eslint/eslint-plugin-tslint @typescript-eslint/parser eslint --save-dev`, | ||
); | ||
}); | ||
|
||
it("reports an npm command when the package manager is npm", async () => { | ||
// Arrange | ||
const { choosePackageManager, logger } = createStubDependencies(PackageManager.npm); | ||
const ruleConversionResults = createEmptyConversionResults(); | ||
|
||
// Act | ||
await logMissingPackages({ choosePackageManager, logger }, ruleConversionResults); | ||
|
||
// Assert | ||
expectEqualWrites( | ||
logger.stdout.write, | ||
`⚡ 3 new packages are required for this ESLint configuration. ⚡`, | ||
` npm install @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint --save-dev`, | ||
); | ||
}); | ||
|
||
it("reports a pnpm command when the package manager is pnpm", async () => { | ||
// Arrange | ||
const { choosePackageManager, logger } = createStubDependencies(PackageManager.pnpm); | ||
const ruleConversionResults = createEmptyConversionResults(); | ||
|
||
// Act | ||
await logMissingPackages({ choosePackageManager, logger }, ruleConversionResults); | ||
|
||
// Assert | ||
expectEqualWrites( | ||
logger.stdout.write, | ||
`⚡ 3 new packages are required for this ESLint configuration. ⚡`, | ||
` pnpm add @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint --save-dev`, | ||
); | ||
}); | ||
|
||
it("reports a Yarn command when the package manager is Yarn", async () => { | ||
// Arrange | ||
const { choosePackageManager, logger } = createStubDependencies(PackageManager.Yarn); | ||
const ruleConversionResults = createEmptyConversionResults(); | ||
|
||
// Act | ||
await logMissingPackages({ choosePackageManager, logger }, ruleConversionResults); | ||
|
||
// Assert | ||
expectEqualWrites( | ||
logger.stdout.write, | ||
`⚡ 3 new packages are required for this ESLint configuration. ⚡`, | ||
` yarn add @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint --dev`, | ||
); | ||
}); | ||
|
||
it("reports a Yarn command when the package manager is Yarn", async () => { | ||
// Arrange | ||
const { choosePackageManager, logger } = createStubDependencies(PackageManager.Yarn); | ||
const ruleConversionResults = createEmptyConversionResults(); | ||
|
||
// Act | ||
await logMissingPackages({ choosePackageManager, logger }, ruleConversionResults); | ||
|
||
// Assert | ||
expectEqualWrites( | ||
logger.stdout.write, | ||
`⚡ 3 new packages are required for this ESLint configuration. ⚡`, | ||
` yarn add @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint --dev`, | ||
); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import chalk from "chalk"; | ||
import { EOL } from "os"; | ||
|
||
import { Logger } from "../../adapters/logger"; | ||
import { SansDependencies } from "../../binding"; | ||
import { SimplifiedResultsConfiguration } from "../../creation/simplification/simplifyPackageRules"; | ||
import { PackagesConfiguration } from "../../input/findPackagesConfiguration"; | ||
import { isTruthy } from "../../utils"; | ||
import { installationMessages } from "../packages/packageManagers"; | ||
import { choosePackageManager } from "./choosePackageManager"; | ||
|
||
export type LogMissingPackagesDependencies = { | ||
choosePackageManager: SansDependencies<typeof choosePackageManager>; | ||
logger: Logger; | ||
}; | ||
|
||
export const logMissingPackages = async ( | ||
dependencies: LogMissingPackagesDependencies, | ||
ruleConversionResults: Pick<SimplifiedResultsConfiguration, "extends" | "missing" | "plugins">, | ||
packageConfiguration?: PackagesConfiguration, | ||
) => { | ||
const packageManager = await dependencies.choosePackageManager(); | ||
|
||
const existingPackageNames = new Set([ | ||
...Object.keys(packageConfiguration?.dependencies ?? {}), | ||
...Object.keys(packageConfiguration?.devDependencies ?? {}), | ||
]); | ||
|
||
const requiredPackageNames = [ | ||
"@typescript-eslint/eslint-plugin", | ||
"@typescript-eslint/parser", | ||
ruleConversionResults.extends?.join("").includes("eslint-config-prettier") && | ||
"eslint-config-prettier", | ||
ruleConversionResults.missing.length !== 0 && "@typescript-eslint/eslint-plugin-tslint", | ||
"eslint", | ||
...Array.from(ruleConversionResults.plugins), | ||
].filter(isTruthy); | ||
|
||
const missingPackageNames = requiredPackageNames | ||
.filter((packageName) => !existingPackageNames.has(packageName)) | ||
.sort(); | ||
|
||
dependencies.logger.stdout.write(chalk.cyanBright(`${EOL}⚡ ${missingPackageNames.length}`)); | ||
dependencies.logger.stdout.write( | ||
chalk.cyan( | ||
` new package${ | ||
missingPackageNames.length === 1 ? " is" : "s are" | ||
} required for this ESLint configuration.`, | ||
), | ||
); | ||
dependencies.logger.stdout.write(chalk.cyanBright(" ⚡")); | ||
dependencies.logger.stdout.write(`${EOL} `); | ||
dependencies.logger.stdout.write( | ||
chalk.cyan(installationMessages[packageManager](missingPackageNames.join(" "))), | ||
); | ||
dependencies.logger.stdout.write(EOL); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember why this was added before, but it isn't doing anything... 🤷