Skip to content

Commit d4fa782

Browse files
committed
Add patch support to upgrade-interactive
1 parent 10d16c3 commit d4fa782

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

.yarn/versions/4f3c8017.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-interactive-tools": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-init"
11+
- "@yarnpkg/plugin-nm"
12+
- "@yarnpkg/plugin-npm-cli"
13+
- "@yarnpkg/plugin-pack"
14+
- "@yarnpkg/plugin-patch"
15+
- "@yarnpkg/plugin-pnp"
16+
- "@yarnpkg/plugin-pnpm"
17+
- "@yarnpkg/plugin-stage"
18+
- "@yarnpkg/plugin-typescript"
19+
- "@yarnpkg/plugin-version"
20+
- "@yarnpkg/plugin-workspace-tools"
21+
- "@yarnpkg/builder"
22+
- "@yarnpkg/core"
23+
- "@yarnpkg/doctor"

packages/plugin-interactive-tools/sources/commands/upgrade-interactive.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ export default class UpgradeInteractiveCommand extends BaseCommand {
8888
if (from === to)
8989
return to;
9090

91-
const parsedFrom = structUtils.parseRange(from);
92-
const parsedTo = structUtils.parseRange(to);
91+
const parsedFrom = structUtils.parseRange(from.replace(/^patch:/, ''));
92+
const parsedTo = structUtils.parseRange(to.replace(/^patch:/, ''));
9393

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

135135
const fetchSuggestions = async (descriptor: Descriptor): Promise<UpgradeSuggestions> => {
136-
const referenceRange = semver.valid(descriptor.range)
137-
? `^${descriptor.range}`
138-
: descriptor.range;
136+
// patch:@amplitude/analytics-browser@npm%3A2.11.0#~/.yarn/patches/@amplitude-analytics-browser-npm-2.11.0-790ed576a5.patch
137+
const {protocol, source, selector, params } = structUtils.parseRange(descriptor.range);
138+
const isPatched = protocol === 'patch:' && source;
139+
const [patchPackageName, descriptorRange] = isPatched
140+
? source.split(':')
141+
: [undefined, descriptor.range];
142+
143+
const referenceRange = semver.valid(descriptorRange)
144+
? `^${descriptorRange}`
145+
: descriptorRange
139146

140147
const [resolution, latest] = await Promise.all([
141-
fetchUpdatedDescriptor(descriptor, descriptor.range, referenceRange).catch(() => null),
142-
fetchUpdatedDescriptor(descriptor, descriptor.range, `latest`).catch(() => null),
148+
fetchUpdatedDescriptor(descriptor, descriptorRange, referenceRange).catch(() => null),
149+
fetchUpdatedDescriptor(descriptor, descriptorRange, `latest`).catch(() => null),
143150
]);
144151

145152
const suggestions: Array<{value: string | null, label: string}> = [{
146153
value: null,
147-
label: descriptor.range,
154+
label: isPatched ? `patch:${descriptorRange}` : descriptorRange,
148155
}];
149156

150-
if (resolution && resolution !== descriptor.range) {
151-
suggestions.push({
152-
value: resolution,
153-
label: colorizeVersionDiff(descriptor.range, resolution),
154-
});
157+
if (resolution && resolution !== descriptorRange) {
158+
const value = isPatched
159+
? `patch:${patchPackageName}%3A${resolution}#${selector}${params ? `?${params}` : ``}`
160+
: resolution;
161+
const label = `${isPatched ? 'patch:' : ''}${colorizeVersionDiff(descriptorRange, resolution)}`;
162+
suggestions.push({ value, label });
155163
} else {
156164
suggestions.push({value: null, label: ``});
157165
}
158166

159-
if (latest && latest !== resolution && latest !== descriptor.range) {
160-
suggestions.push({
161-
value: latest,
162-
label: colorizeVersionDiff(descriptor.range, latest),
163-
});
167+
if (latest && latest !== resolution && latest !== descriptorRange) {
168+
const value = isPatched
169+
? `patch:${patchPackageName}%3A:${latest}#${selector}${params ? `?${params}` : ``}`
170+
: latest;
171+
const label = `${isPatched ? 'patch:' : ''}${colorizeVersionDiff(descriptorRange, latest)}`;
172+
suggestions.push({ value, label });
164173
} else {
165174
suggestions.push({value: null, label: ``});
166175
}

0 commit comments

Comments
 (0)