Skip to content
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

Add patch support to upgrade-interactive #6492

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
};

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
Loading