Skip to content

Commit

Permalink
refactor: ignoreUnstable settings change to unstableFilter (#139)
Browse files Browse the repository at this point in the history
* refactor: ignoreUnstable settings change to unstableFilter

* refactor: Update unstableFilter type in dependi indexes and fetchers

* refactor: Migrate unstableFilter settings in config.ts
  • Loading branch information
kadirkaang authored Sep 12, 2024
1 parent 8b59104 commit c2e6202
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 92 deletions.
10 changes: 5 additions & 5 deletions vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ While Dependi works out-of-the-box without any configuration, we also offer a fe
- `dependi.rust.enabled`: Enable Rust package management.
- `dependi.rust.lockFileEnabled` : Enable checking for Rust dependencies in lockfiles.
- `dependi.rust.indexServerURL`: The URL for the Rust package index server.
- `dependi.rust.excludeUnstableVersions`: Exclude unstable versions from Rust package lists.
- `dependi.rust.unstableFilter`: Filter unstable versions: Exclude, Include Always, or Include If Unstable.
- `dependi.rust.ignoreLinePattern`: Matches lines based on `*` position: `text*`, `*text`, `*text*`. Multiple patterns can be used, separated by commas.
- `dependi.npm.enabled`: Enable NPM package management.
- `dependi.npm.lockFileEnabled`: Enable checking for Npm dependencies in lockfiles.
- `dependi.npm.indexServerURL`: The URL for the NPM package index server.
- `dependi.npm.excludeUnstableVersions`: Exclude unstable versions from NPM package lists.
- `dependi.npm.unstableFilter`: Filter unstable versions: Exclude, Include Always, or Include If Unstable.
- `dependi.npm.ignoreLinePattern`: Matches lines based on `*` position: `text*`, `*text`, `*text*`. Multiple patterns can be used, separated by commas.
- `dependi.go.enabled`: Enable Go package management.
- `dependi.go.indexServerURL`: The URL for the Go package index server.
- `dependi.go.excludeUnstableVersions`: Exclude unstable versions from Go package lists.
- `dependi.go.unstableFilter`: Filter unstable versions: Exclude, Include Always, or Include If Unstable.
- `dependi.go.ignoreLinePattern`: Matches lines based on `*` position: `text*`, `*text`, `*text*`. Multiple patterns can be used, separated by commas.
- `dependi.python.enabled`: Enable Python package management.
- `dependi.python.lockFileEnabled`: Enable checking for Python dependencies in lockfiles.
- `dependi.python.indexServerURL`: The URL for the Python package index server.
- `dependi.python.excludeUnstableVersions`: Exclude unstable versions from Python package lists.
- `dependi.python.unstableFilter`: Filter unstable versions: Exclude, Include Always, or Include If Unstable.
- `dependi.python.ignoreLinePattern`: Matches lines based on `*` position: `text*`, `*text`, `*text*`. Multiple patterns can be used, separated by commas.
- `dependi.php.enabled`: Enable PHP package management.
- `dependi.php.lockFileEnabled`: Enable checking for PHP dependencies in lockfiles.
- `dependi.php.indexServerURL`: The URL for the PHP package index server.
- `dependi.php.excludeUnstableVersions`: Exclude unstable versions from PHP package lists.
- `dependi.php.unstableFilter`: Filter unstable versions: Exclude, Include Always, or Include If Unstable.
- `dependi.php.ignoreLinePattern`: Matches lines based on `*` position: `text*`, `*text`, `*text*`. Multiple patterns can be used, separated by commas.
- `dependi.vulnerability.enabled`: Enable checking for vulnerabilities in dependencies.
- `dependi.vulnerability.ghsa.enabled`: Include GitHub Security Advisory vulnerabilities in checks.
Expand Down
92 changes: 71 additions & 21 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,21 @@
"default": "https://index.crates.io",
"order": 5
},
"dependi.rust.excludeUnstableVersions": {
"type": "boolean",
"dependi.rust.unstableFilter": {
"type": "string",
"enum": [
"Exclude",
"IncludeAlways",
"IncludeIfUnstable"
],
"default": "Exclude",
"scope": "resource",
"default": true,
"description": "Exclude unstable versions from Rust package lists.",
"enumDescriptions": [
"Exclude them (default)",
"Include them and always consider as latest",
"Include if the current version is already unstable"
],
"description": "Filter unstable versions: Exclude, Include Always, or Include If Unstable.",
"order": 6
},
"dependi.rust.ignoreLinePatterns": {
Expand Down Expand Up @@ -265,11 +275,21 @@
"pattern": "^https?://(?!.*//)([^/]+/)*[^/]+$",
"order": 11
},
"dependi.npm.excludeUnstableVersions": {
"type": "boolean",
"dependi.npm.unstableFilter": {
"type": "string",
"enum": [
"Exclude",
"IncludeAlways",
"IncludeIfUnstable"
],
"default": "Exclude",
"scope": "resource",
"default": true,
"description": "Exclude unstable versions from NPM package lists.",
"enumDescriptions": [
"Exclude them (default)",
"Include them and always consider as latest",
"Include if the current version is already unstable"
],
"description": "Filter unstable versions: Exclude, Include Always, or Include If Unstable.",
"order": 12
},
"dependi.npm.ignoreLinePatterns": {
Expand Down Expand Up @@ -314,11 +334,21 @@
"default": "https://proxy.golang.org",
"order": 17
},
"dependi.go.excludeUnstableVersions": {
"type": "boolean",
"dependi.go.unstableFilter": {
"type": "string",
"enum": [
"Exclude",
"IncludeAlways",
"IncludeIfUnstable"
],
"default": "Exclude",
"scope": "resource",
"default": true,
"description": "Exclude unstable versions from Go package lists.",
"enumDescriptions": [
"Exclude them (default)",
"Include them and always consider as latest",
"Include if the current version is already unstable"
],
"description": "Filter unstable versions: Exclude, Include Always, or Include If Unstable.",
"order": 18
},
"dependi.go.ignoreLinePatterns": {
Expand Down Expand Up @@ -356,11 +386,21 @@
"default": "https://pypi.org/pypi",
"order": 22
},
"dependi.python.excludeUnstableVersions": {
"type": "boolean",
"dependi.python.unstableFilter": {
"type": "string",
"enum": [
"Exclude",
"IncludeAlways",
"IncludeIfUnstable"
],
"default": "Exclude",
"scope": "resource",
"default": true,
"description": "Exclude unstable versions from Python package lists.",
"enumDescriptions": [
"Exclude them (default)",
"Include them and always consider as latest",
"Include if the current version is already unstable"
],
"description": "Filter unstable versions: Exclude, Include Always, or Include If Unstable.",
"order": 23
},
"dependi.python.ignoreLinePatterns": {
Expand Down Expand Up @@ -405,11 +445,21 @@
"default": "https://repo.packagist.org",
"order": 28
},
"dependi.php.excludeUnstableVersions": {
"type": "boolean",
"dependi.php.unstableFilter": {
"type": "string",
"enum": [
"Exclude",
"IncludeAlways",
"IncludeIfUnstable"
],
"default": "Exclude",
"scope": "resource",
"default": true,
"description": "Exclude unstable versions from PHP package lists.",
"enumDescriptions": [
"Exclude them (default)",
"Include them and always consider as latest",
"Include if the current version is already unstable"
],
"description": "Filter unstable versions: Exclude, Include Always, or Include If Unstable.",
"order": 29
},
"dependi.php.ignoreLinePatterns": {
Expand Down Expand Up @@ -818,4 +868,4 @@
"extensionDependencies": [
"vscode.git"
]
}
}
7 changes: 4 additions & 3 deletions vscode/src/api/indexes/dependi/indexes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { window } from "vscode";
import { request } from ".";

import { Configs } from "../../../config";
import { Configs, UnstableFilter } from "../../../config";
import Dependency from "../../../core/Dependency";
import { Logger } from "../../../extension";
import { openDeviceLimitDialog, openPaymentRequiredDialog, openSettingsDialog } from "../../../ui/dialogs";
import { Errors, getError } from "./errors";
import { Language } from "./reports";
import Item from "../../../core/Item";

export interface VersionsResp {
Name: string;
Expand All @@ -18,8 +19,8 @@ export interface VersionsResp {

export interface VersionsReq {
Language: Language;
Packages: string[];
IgnoreUnstables: boolean;
Packages: Item[];
IgnoreUnstables: UnstableFilter;
Dependencies?: Dependency[] | VersionsResp[];
VulnerabilityCheck: boolean;
GhsaCheck?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/api/indexes/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const setVersions = (response: any, versions: string[]) => {
versionData.forEach(([key, value]: [string, any]) => {
if (
!value.deprecated &&
(!Settings.npm.ignoreUnstable || !key.includes("-"))
(Settings.npm.unstableFilter !== "exclude" || !key.includes("-"))
) {
versions.push(key);
}
Expand Down
61 changes: 44 additions & 17 deletions vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,43 @@ import { DecorationPosition } from "./ui/pref";
export const DEPENDI = "dependi.";
const WORKBENCH_ACTIONS = "workbench.action.";

export enum UnstableFilter {
Exclude,
IncludeAlways,
IncludeIfUnstable
}

export enum Configs {
RUST_ENABLED = `rust.enabled`,
RUST_INDEX_SERVER_URL = `rust.indexServerURL`,
RUST_IGNORE_UNSTABLES = `rust.excludeUnstableVersions`,
RUST_UNSTABLE_FILTER = `rust.unstableFilter`,
RUST_IGNORE_LINE_PATTERN = `rust.ignoreLinePattern`,
RUST_INFORM_PATCH_UPDATES = `rust.informPatchUpdates`,
RUST_ENABLED_LOCK_FILE = `rust.lockFileEnabled`,

NPM_ENABLED = `npm.enabled`,
NPM_INDEX_SERVER_URL = `npm.indexServerURL`,
NPM_IGNORE_UNSTABLES = `npm.excludeUnstableVersions`,
NPM_UNSTABLE_FILTER = `npm.unstableFilter`,
NPM_IGNORE_LINE_PATTERN = `npm.ignoreLinePattern`,
NPM_INFORM_PATCH_UPDATES = `npm.informPatchUpdates`,
NPM_ENABLED_LOCK_FILE = `npm.lockFileEnabled`,

PHP_ENABLED = `php.enabled`,
PHP_INDEX_SERVER_URL = `php.indexServerURL`,
PHP_IGNORE_UNSTABLES = `php.excludeUnstableVersions`,
PHP_UNSTABLE_FILTER = `php.unstableFilter`,
PHP_IGNORE_LINE_PATTERN = `php.ignoreLinePattern`,
PHP_INFORM_PATCH_UPDATES = `php.informPatchUpdates`,
PHP_ENABLED_LOCK_FILE = `php.lockFileEnabled`,

GO_ENABLED = `go.enabled`,
GO_INDEX_SERVER_URL = `go.indexServerURL`,
GO_IGNORE_UNSTABLES = `go.excludeUnstableVersions`,
GO_UNSTABLE_FILTER = `go.unstableFilter`,
GO_IGNORE_LINE_PATTERN = `go.ignoreLinePattern`,
GO_INFORM_PATCH_UPDATES = `go.informPatchUpdates`,

PYTHON_ENABLED = `python.enabled`,
PYTHON_INDEX_SERVER_URL = `python.indexServerURL`,
PYTHON_IGNORE_UNSTABLES = `python.excludeUnstableVersions`,
PYTHON_UNSTABLE_FILTER = `python.unstableFilter`,
PYTHON_IGNORE_LINE_PATTERN = `python.ignoreLinePattern`,
PYTHON_INFORM_PATCH_UPDATES = `python.informPatchUpdates`,
PYTHON_ENABLED_LOCK_FILE = `python.lockFileEnabled`,
Expand Down Expand Up @@ -75,14 +81,21 @@ export enum Configs {
//Storage
DEVICE_ID = `${DEPENDI}deviceID`,
SHOWN_VERSION = `${DEPENDI}shownVersion`,

// Old Settings
RUST_UNSTABLE_OLD = `rust.excludeUnstableVersions`,
NPM_UNSTABLE_OLD = `npm.excludeUnstableVersions`,
PHP_UNSTABLE_OLD = `php.excludeUnstableVersions`,
GO_UNSTABLE_OLD = `go.excludeUnstableVersions`,
PYTHON_UNSTABLE_OLD = `python.excludeUnstableVersions`
}

export const Settings = {
version: "0.0.1",
rust: {
enabled: true,
index: "",
ignoreUnstable: false,
unstableFilter: UnstableFilter.Exclude,
ignoreLinePattern: "",
informPatchUpdates: false,
lockFileEnabled: true
Expand All @@ -91,30 +104,30 @@ export const Settings = {
npm: {
enabled: true,
index: "",
ignoreUnstable: false,
unstableFilter: UnstableFilter.Exclude,
ignoreLinePattern: "",
informPatchUpdates: false,
lockFileEnabled: true
},
php: {
enabled: true,
index: "",
ignoreUnstable: false,
unstableFilter: UnstableFilter.Exclude,
ignoreLinePattern: "",
informPatchUpdates: false,
lockFileEnabled: true
},
go: {
enabled: true,
index: "",
ignoreUnstable: false,
unstableFilter: UnstableFilter.Exclude,
ignoreLinePattern: "",
informPatchUpdates: true
},
python: {
enabled: true,
index: "",
ignoreUnstable: false,
unstableFilter: UnstableFilter.Exclude,
ignoreLinePattern: "",
informPatchUpdates: false,
lockFileEnabled: true
Expand Down Expand Up @@ -157,38 +170,38 @@ export const Settings = {

load: function () {
const config = workspace.getConfiguration("dependi");

console.log(this.version);
// fill in the settings
this.rust.enabled = config.get<boolean>(Configs.RUST_ENABLED) ?? true;
this.rust.index = config.get<string>(Configs.RUST_INDEX_SERVER_URL) || "https://index.crates.io";
this.rust.ignoreUnstable = config.get<boolean>(Configs.RUST_IGNORE_UNSTABLES) ?? true;
this.rust.unstableFilter = migrateUnstableSettings(Configs.RUST_UNSTABLE_FILTER, Configs.RUST_UNSTABLE_OLD);
this.rust.ignoreLinePattern = config.get<string>(Configs.RUST_IGNORE_LINE_PATTERN) || "";
this.rust.informPatchUpdates = config.get<boolean>(Configs.RUST_INFORM_PATCH_UPDATES) ?? false;
this.rust.lockFileEnabled = config.get<boolean>(Configs.RUST_ENABLED_LOCK_FILE) ?? true;

this.npm.enabled = config.get<boolean>(Configs.NPM_ENABLED) ?? true;
this.npm.index = config.get<string>(Configs.NPM_INDEX_SERVER_URL) || "https://registry.npmjs.org";
this.npm.ignoreUnstable = config.get<boolean>(Configs.NPM_IGNORE_UNSTABLES) ?? true;
this.npm.unstableFilter = migrateUnstableSettings(Configs.NPM_UNSTABLE_FILTER, Configs.NPM_UNSTABLE_OLD);
this.npm.ignoreLinePattern = config.get<string>(Configs.NPM_IGNORE_LINE_PATTERN) || "";
this.npm.informPatchUpdates = config.get<boolean>(Configs.NPM_INFORM_PATCH_UPDATES) ?? false;
this.npm.lockFileEnabled = config.get<boolean>(Configs.NPM_ENABLED_LOCK_FILE) ?? true;

this.php.enabled = config.get<boolean>(Configs.PHP_ENABLED) ?? true;
this.php.index = config.get<string>(Configs.PHP_INDEX_SERVER_URL) || "https://repo.packagist.org";
this.php.ignoreUnstable = config.get<boolean>(Configs.PHP_IGNORE_UNSTABLES) ?? true;
this.php.unstableFilter = migrateUnstableSettings(Configs.PHP_UNSTABLE_FILTER, Configs.PHP_UNSTABLE_OLD);
this.php.ignoreLinePattern = config.get<string>(Configs.PHP_IGNORE_LINE_PATTERN) || "";
this.php.informPatchUpdates = config.get<boolean>(Configs.PHP_INFORM_PATCH_UPDATES) ?? false;
this.php.lockFileEnabled = config.get<boolean>(Configs.PHP_ENABLED_LOCK_FILE) ?? true;

this.go.enabled = config.get<boolean>(Configs.GO_ENABLED) ?? true;
this.go.index = config.get<string>(Configs.GO_INDEX_SERVER_URL) || "https://proxy.golang.org";
this.go.ignoreUnstable = config.get<boolean>(Configs.GO_IGNORE_UNSTABLES) ?? true;
this.go.unstableFilter = migrateUnstableSettings(Configs.GO_UNSTABLE_FILTER, Configs.GO_UNSTABLE_OLD);
this.go.ignoreLinePattern = config.get<string>(Configs.GO_IGNORE_LINE_PATTERN) || "";
this.go.informPatchUpdates = config.get<boolean>(Configs.GO_INFORM_PATCH_UPDATES) ?? false;

this.python.enabled = config.get<boolean>(Configs.PYTHON_ENABLED) ?? true;
this.python.index = config.get<string>(Configs.PYTHON_INDEX_SERVER_URL) || "https://pypi.org/pypi";
this.python.ignoreUnstable = config.get<boolean>(Configs.PYTHON_IGNORE_UNSTABLES) ?? true;
this.python.unstableFilter = migrateUnstableSettings(Configs.PYTHON_UNSTABLE_FILTER, Configs.PYTHON_UNSTABLE_OLD);
this.python.ignoreLinePattern = config.get<string>(Configs.PYTHON_IGNORE_LINE_PATTERN) || "";
this.python.informPatchUpdates = config.get<boolean>(Configs.PYTHON_INFORM_PATCH_UPDATES) ?? false;
this.python.lockFileEnabled = config.get<boolean>(Configs.PYTHON_ENABLED_LOCK_FILE) ?? true;
Expand Down Expand Up @@ -224,3 +237,17 @@ export const Settings = {
}
}
};

function migrateUnstableSettings(newSettingKey: string , oldSettingKey: string): UnstableFilter {
const config = workspace.getConfiguration("dependi");
const filter = config.get<string>(newSettingKey);
if (Settings.version > "0.7.9") {
const oldSetting = config.get<boolean>(oldSettingKey);
if (oldSetting !== undefined) {
config.update(oldSettingKey, undefined, true);
config.update(newSettingKey, oldSetting ? "Exclude" : "IncludeAlways", true);
return oldSetting ? UnstableFilter.Exclude : UnstableFilter.IncludeAlways;
}
}
return UnstableFilter[filter as keyof typeof UnstableFilter] || UnstableFilter.Exclude;
}
2 changes: 1 addition & 1 deletion vscode/src/core/fetchers/CratesFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CratesFetcher extends Fetcher {
return versions(dep.item.key)
.then((crate) => {
const versions = crate.versions
.filter((i: string) => i !== "" && i !== undefined && !base.checkPreRelease(Settings.rust.ignoreUnstable, i))
.filter((i: string) => i !== "" && i !== undefined && !base.checkUnstables(Settings.rust.unstableFilter, i, dep.item.value!))
.sort(compareVersions)
.reverse();

Expand Down
Loading

0 comments on commit c2e6202

Please sign in to comment.