-
Notifications
You must be signed in to change notification settings - Fork 14
[cli] add pinned deps support to mops update and mops outdated
#316
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ import process from 'node:process'; | |
| import chalk from 'chalk'; | ||
| import {mainActor} from '../api/actors.js'; | ||
| import {Config} from '../types.js'; | ||
| import {getDepName} from '../helpers/get-dep-name.js'; | ||
| import {getDepName, getDepPinnedVersion} from '../helpers/get-dep-name.js'; | ||
| import {SemverPart} from '../declarations/main/main.did.js'; | ||
|
|
||
| // [pkg, oldVersion, newVersion] | ||
| export async function getAvailableUpdates(config : Config, pkg ?: string) : Promise<Array<[string, string, string]>> { | ||
|
|
@@ -11,25 +12,37 @@ export async function getAvailableUpdates(config : Config, pkg ?: string) : Prom | |
| let allDeps = [...deps, ...devDeps].filter((dep) => dep.version); | ||
| let depsToUpdate = pkg ? allDeps.filter((dep) => dep.name === pkg) : allDeps; | ||
|
|
||
| // skip pinned dependencies | ||
| depsToUpdate = depsToUpdate.filter((dep) => getDepName(dep.name) === dep.name); | ||
| // skip hard pinned dependencies (e.g. "base@X.Y.Z") | ||
| depsToUpdate = depsToUpdate.filter((dep) => getDepName(dep.name) === dep.name || getDepPinnedVersion(dep.name).split('.').length !== 3); | ||
|
|
||
| let getCurrentVersion = (pkg : string) => { | ||
| let getCurrentVersion = (pkg : string, updateVersion : string) => { | ||
| for (let dep of allDeps) { | ||
| if (dep.name === pkg && dep.version) { | ||
| if (getDepName(dep.name) === pkg && dep.version) { | ||
| let pinnedVersion = getDepPinnedVersion(dep.name); | ||
| if (pinnedVersion && !updateVersion.startsWith(pinnedVersion)) { | ||
| continue; | ||
| } | ||
| return dep.version; | ||
| } | ||
| } | ||
| return ''; | ||
| }; | ||
|
Comment on lines
+18
to
29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pin check using startsWith() is wrong (e.g., pin "1" matches "10.x"). This can enable invalid updates. Use boundary-aware matching and exclude rows when the pin doesn’t match. Apply: -let getCurrentVersion = (pkg : string, updateVersion : string) => {
+let getCurrentVersion = (pkg : string, updateVersion : string) => {
for (let dep of allDeps) {
- if (getDepName(dep.name) === pkg && dep.version) {
- let pinnedVersion = getDepPinnedVersion(dep.name);
- if (pinnedVersion && !updateVersion.startsWith(pinnedVersion)) {
- continue;
- }
- return dep.version;
- }
+ if (!dep.version) continue;
+ if (getDepName(dep.name) !== pkg) continue;
+ const pin = normalizePin(getDepPinnedVersion(dep.name));
+ if (pin && !matchesPin(pin, updateVersion)) continue;
+ return dep.version;
}
return '';
};Support code to add once (near normalizePin): function matchesPin(pin: string, version: string): boolean {
const v = normalizePin(version);
if (/^\d+$/.test(pin)) return new RegExp(`^${pin}\\.\\d+\\.\\d+(?:[-+].*)?$`).test(v);
if (/^\d+\\.\d+$/.test(pin)) return new RegExp(`^${pin}\\.\\d+(?:[-+].*)?$`).test(v);
if (/^\d+\\.\d+\\.\d+(?:[-+].*)?$/.test(pin)) return new RegExp(`^${pin}(?:$|[-+])`).test(v);
return true;
}🤖 Prompt for AI Agents |
||
|
|
||
| let actor = await mainActor(); | ||
| let res = await actor.getHighestSemverBatch(depsToUpdate.map((dep) => [dep.name, dep.version || '', {major: null}])); | ||
| let res = await actor.getHighestSemverBatch(depsToUpdate.map((dep) => { | ||
| let semverPart : SemverPart = {major: null}; | ||
| let name = getDepName(dep.name); | ||
| let pinnedVersion = getDepPinnedVersion(dep.name); | ||
| if (pinnedVersion) { | ||
| semverPart = pinnedVersion.split('.').length === 1 ? {minor: null} : {patch: null}; | ||
| } | ||
| return [name, dep.version || '', semverPart]; | ||
| })); | ||
|
|
||
| if ('err' in res) { | ||
| console.log(chalk.red('Error:'), res.err); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| return res.ok.filter((dep) => dep[1] !== getCurrentVersion(dep[0])).map((dep) => [dep[0], getCurrentVersion(dep[0]), dep[1]]); | ||
| return res.ok.filter((dep) => dep[1] !== getCurrentVersion(dep[0], dep[1])).map((dep) => [dep[0], getCurrentVersion(dep[0], dep[1]), dep[1]]); | ||
| } | ||
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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| export function getDepName(name : string) : string { | ||
| return name.split('@')[0] || ''; | ||
| } | ||
|
|
||
| export function getDepPinnedVersion(name : string) : string { | ||
| return name.split('@')[1] || ''; | ||
| } |
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.
🛠️ Refactor suggestion
Hard-pin detection is brittle (pre-release/build tags misclassified).
split('.')misses cases like1.2.3-rc.1and may incorrectly update hard-pinned deps. Parse with a regex and normalize the pin.Apply:
Outside selected lines: also make
pkgfiltering pin/alias-aware, otherwisemops update corewon’t selectcore@1:Support code to add near the top of the file: