-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add prompt to fix unsupported mismatches
- Loading branch information
1 parent
96d6c6d
commit 296fad5
Showing
37 changed files
with
631 additions
and
259 deletions.
There are no files selected for viewing
This file contains 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 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,34 @@ | ||
--- | ||
id: prompt | ||
title: prompt | ||
--- | ||
|
||
Displays a series of prompts to fix mismatches which syncpack cannot fix | ||
automatically. | ||
|
||
## CLI Options | ||
|
||
``` | ||
-s, --source [pattern] glob pattern for package.json files to read from | ||
-f, --filter [pattern] only include dependencies whose name matches this regex | ||
-c, --config <path> path to a syncpack config file | ||
-t, --types <names> only include dependencies matching these types (eg. types=dev,prod,myCustomType) | ||
-h, --help display help for command | ||
``` | ||
|
||
## Examples | ||
|
||
```bash | ||
# uses defaults for resolving packages | ||
syncpack prompt | ||
# uses packages defined by --source when provided | ||
syncpack prompt --source "apps/*/package.json" | ||
# multiple globs can be provided like this | ||
syncpack prompt --source "apps/*/package.json" --source "core/*/package.json" | ||
# uses dependencies regular expression defined by --filter when provided | ||
syncpack prompt --filter "typescript|tslint" | ||
# only inspect "devDependencies" | ||
syncpack prompt --types dev | ||
# only inspect "devDependencies" and "peerDependencies" | ||
syncpack prompt --types dev,peer | ||
``` |
This file contains 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 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 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,62 @@ | ||
#!/usr/bin/env node | ||
|
||
import chalk from 'chalk'; | ||
import { program } from 'commander'; | ||
import { disk } from '../lib/disk'; | ||
import { showHelpOnError } from '../lib/show-help-on-error'; | ||
import { option } from '../option'; | ||
import { promptCli } from './prompt-cli'; | ||
|
||
program.description( | ||
' displays a series of prompts to fix mismatches which syncpack cannot fix automatically', | ||
); | ||
|
||
program.on('--help', () => { | ||
console.log(chalk` | ||
Examples: | ||
{dim # uses defaults for resolving packages} | ||
syncpack prompt | ||
{dim # uses packages defined by --source when provided} | ||
syncpack prompt --source {yellow "apps/*/package.json"} | ||
{dim # multiple globs can be provided like this} | ||
syncpack prompt --source {yellow "apps/*/package.json"} --source {yellow "core/*/package.json"} | ||
{dim # uses dependencies regular expression defined by --filter when provided} | ||
syncpack prompt --filter {yellow "typescript|tslint"} | ||
{dim # only inspect "devDependencies"} | ||
syncpack prompt --types dev | ||
{dim # only inspect "devDependencies" and "peerDependencies"} | ||
syncpack prompt --types dev,peer | ||
Resolving Packages: | ||
1. If {yellow --source} globs are provided, use those. | ||
2. If using Pnpm Workspaces, read {yellow packages} from {yellow pnpm-workspace.yaml} in the root of the project. | ||
3. If using Yarn Workspaces, read {yellow workspaces} from {yellow package.json}. | ||
4. If using Lerna, read {yellow packages} from {yellow lerna.json}. | ||
5. Default to {yellow "package.json"} and {yellow "packages/*/package.json"}. | ||
Reference: | ||
globs {blue.underline https://github.com/isaacs/node-glob#glob-primer} | ||
lerna.json {blue.underline https://github.com/lerna/lerna#lernajson} | ||
Yarn Workspaces {blue.underline https://yarnpkg.com/lang/en/docs/workspaces} | ||
Pnpm Workspaces {blue.underline https://pnpm.js.org/en/workspaces} | ||
`); | ||
}); | ||
|
||
showHelpOnError(program); | ||
|
||
program | ||
.option(...option.source) | ||
.option(...option.filter) | ||
.option(...option.config) | ||
.option(...option.types) | ||
.parse(process.argv); | ||
|
||
promptCli( | ||
{ | ||
configPath: program.opts().config, | ||
filter: program.opts().filter, | ||
source: program.opts().source, | ||
types: program.opts().types, | ||
}, | ||
disk, | ||
); |
This file contains 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,51 @@ | ||
import chalk from 'chalk'; | ||
|
||
import type { CliConfig } from '../config/types'; | ||
import { getContext } from '../get-context'; | ||
import { getVersionGroups } from '../get-version-groups'; | ||
import { getUniqueVersions } from '../get-version-groups/lib/get-unique-versions'; | ||
import type { Disk } from '../lib/disk'; | ||
import { sortByName } from '../lib/sort-by-name'; | ||
import { writeIfChanged } from '../lib/write-if-changed'; | ||
|
||
export async function promptCli( | ||
input: Partial<CliConfig>, | ||
disk: Disk, | ||
): Promise<void> { | ||
const ctx = getContext(input, disk); | ||
const versionGroups = getVersionGroups(ctx); | ||
|
||
for (const versionGroup of versionGroups) { | ||
const reports = versionGroup.inspect().sort(sortByName); | ||
for (const report of reports) { | ||
switch (report.status) { | ||
case 'SAME_RANGE_MISMATCH': | ||
case 'UNSUPPORTED_MISMATCH': { | ||
const OTHER = chalk.dim('Other'); | ||
const SKIP = chalk.dim('Skip this dependency'); | ||
const chosenVersion = await disk.askForChoice({ | ||
message: chalk`${report.name} {dim Choose a version to replace the others}`, | ||
choices: [...getUniqueVersions(report.instances), OTHER, SKIP], | ||
}); | ||
|
||
if (chosenVersion === SKIP) { | ||
continue; | ||
} else if (chosenVersion === OTHER) { | ||
const newVersion = await disk.askForInput({ | ||
message: chalk`${report.name} {dim Enter a new version to replace the others}`, | ||
}); | ||
report.instances.forEach((instance) => { | ||
instance.setVersion(newVersion); | ||
}); | ||
} else { | ||
report.instances.forEach((instance) => { | ||
instance.setVersion(chosenVersion); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
writeIfChanged(ctx); | ||
} |
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.