Skip to content

Commit

Permalink
Add patch support to upgrade-interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Sep 12, 2024
1 parent 10d16c3 commit ccefe7e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
23 changes: 23 additions & 0 deletions .yarn/versions/4f3c8017.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-interactive-tools": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export default class UpgradeInteractiveCommand extends BaseCommand {
if (from === to)
return to;

const parsedFrom = structUtils.parseRange(from);
const parsedTo = structUtils.parseRange(to);
const parsedFrom = structUtils.parseRange(from.replace(/^patch:/, ''));

Check failure on line 91 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

Strings must use backtick
const parsedTo = structUtils.parseRange(to.replace(/^patch:/, ''));

Check failure on line 92 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

Strings must use backtick

const matchedFrom = parsedFrom.selector.match(SIMPLE_SEMVER);
const matchedTo = parsedTo.selector.match(SIMPLE_SEMVER);
Expand Down Expand Up @@ -133,34 +133,43 @@ export default class UpgradeInteractiveCommand extends BaseCommand {
};

const fetchSuggestions = async (descriptor: Descriptor): Promise<UpgradeSuggestions> => {
const referenceRange = semver.valid(descriptor.range)
? `^${descriptor.range}`
: descriptor.range;
// patch:@amplitude/analytics-browser@npm%3A2.11.0#~/.yarn/patches/@amplitude-analytics-browser-npm-2.11.0-790ed576a5.patch
const {protocol, source, selector, params } = structUtils.parseRange(descriptor.range);

Check failure on line 137 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

There should be no space before '}'
const isPatched = protocol === 'patch:' && source;

Check failure on line 138 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

Strings must use backtick
const [patchPackageName, descriptorRange] = isPatched
? source.split(':')

Check failure on line 140 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

Strings must use backtick
: [undefined, descriptor.range];

const referenceRange = semver.valid(descriptorRange)
? `^${descriptorRange}`
: descriptorRange

Check failure on line 145 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

Missing semicolon

const [resolution, latest] = await Promise.all([
fetchUpdatedDescriptor(descriptor, descriptor.range, referenceRange).catch(() => null),
fetchUpdatedDescriptor(descriptor, descriptor.range, `latest`).catch(() => null),
fetchUpdatedDescriptor(descriptor, descriptorRange, referenceRange).catch(() => null),
fetchUpdatedDescriptor(descriptor, descriptorRange, `latest`).catch(() => null),
]);

const suggestions: Array<{value: string | null, label: string}> = [{
value: null,
label: descriptor.range,
label: isPatched ? `patch:${descriptorRange}` : descriptorRange,
}];

if (resolution && resolution !== descriptor.range) {
suggestions.push({
value: resolution,
label: colorizeVersionDiff(descriptor.range, resolution),
});
if (resolution && resolution !== descriptorRange) {
const value = isPatched
? `patch:${patchPackageName}%3A${resolution}#${selector}${params ? `?${params}` : ``}`
: resolution;
const label = `${isPatched ? 'patch:' : ''}${colorizeVersionDiff(descriptorRange, resolution)}`;

Check failure on line 161 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

Strings must use backtick

Check failure on line 161 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

Strings must use backtick
suggestions.push({ value, label });

Check failure on line 162 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

There should be no space after '{'

Check failure on line 162 in packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

View workflow job for this annotation

GitHub Actions / Testing chores

There should be no space before '}'
} else {
suggestions.push({value: null, label: ``});
}

if (latest && latest !== resolution && latest !== descriptor.range) {
suggestions.push({
value: latest,
label: colorizeVersionDiff(descriptor.range, latest),
});
if (latest && latest !== resolution && latest !== descriptorRange) {
const value = isPatched
? `patch:${patchPackageName}%3A:${latest}#${selector}${params ? `?${params}` : ``}`
: latest;
const label = `${isPatched ? 'patch:' : ''}${colorizeVersionDiff(descriptorRange, latest)}`;
suggestions.push({ value, label });
} else {
suggestions.push({value: null, label: ``});
}
Expand Down

0 comments on commit ccefe7e

Please sign in to comment.