mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 20:20:49 +00:00
Fix some border cases
This commit is contained in:
parent
1b82aeb6b0
commit
1fdb15a392
9 changed files with 685 additions and 46 deletions
|
|
@ -1,52 +0,0 @@
|
|||
import { commandArgumentScanner } from "./dependencyScanner/commandArgumentScanner.js";
|
||||
import { nullScanner } from "./dependencyScanner/nullScanner.js";
|
||||
import { runPip } from "./runPipCommand.js";
|
||||
import {
|
||||
getPipCommandForArgs,
|
||||
pipInstallCommand,
|
||||
pipUninstallCommand,
|
||||
} from "./utils/pipCommands.js";
|
||||
|
||||
/**
|
||||
* Creates a package manager interface for Python's pip package installer
|
||||
*
|
||||
* @param {string} [command="pip"] - The pip command to use (e.g., "pip", "pip3") defaults to "pip"
|
||||
*/
|
||||
export function createPipPackageManager(command = "pip") {
|
||||
function isSupportedCommand(args) {
|
||||
const scanner = findDependencyScannerForCommand(
|
||||
commandScannerMapping,
|
||||
args
|
||||
);
|
||||
return scanner.shouldScan(args);
|
||||
}
|
||||
|
||||
function getDependencyUpdatesForCommand(args) {
|
||||
const scanner = findDependencyScannerForCommand(
|
||||
commandScannerMapping,
|
||||
args
|
||||
);
|
||||
return scanner.scan(args);
|
||||
}
|
||||
|
||||
return {
|
||||
runCommand: (args) => runPip(command, args),
|
||||
isSupportedCommand,
|
||||
getDependencyUpdatesForCommand,
|
||||
};
|
||||
}
|
||||
|
||||
const commandScannerMapping = {
|
||||
[pipInstallCommand]: commandArgumentScanner(),
|
||||
[pipUninstallCommand]: nullScanner(), // Uninstall doesn't need scanning
|
||||
};
|
||||
|
||||
function findDependencyScannerForCommand(scanners, args) {
|
||||
const command = getPipCommandForArgs(args);
|
||||
if (!command) {
|
||||
return nullScanner();
|
||||
}
|
||||
|
||||
const scanner = scanners[command];
|
||||
return scanner ? scanner : nullScanner();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue