imcp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/JitAccess.yml +28 -0
- package/.github/acl/access.yml +20 -0
- package/.github/compliance/inventory.yml +5 -0
- package/.github/policies/jit.yml +19 -0
- package/README.md +137 -0
- package/dist/cli/commands/install.d.ts +2 -0
- package/dist/cli/commands/install.js +105 -0
- package/dist/cli/commands/list.d.ts +2 -0
- package/dist/cli/commands/list.js +90 -0
- package/dist/cli/commands/pull.d.ts +2 -0
- package/dist/cli/commands/pull.js +17 -0
- package/dist/cli/commands/serve.d.ts +2 -0
- package/dist/cli/commands/serve.js +32 -0
- package/dist/cli/commands/start.d.ts +2 -0
- package/dist/cli/commands/start.js +32 -0
- package/dist/cli/commands/sync.d.ts +2 -0
- package/dist/cli/commands/sync.js +17 -0
- package/dist/cli/commands/uninstall.d.ts +2 -0
- package/dist/cli/commands/uninstall.js +39 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +114 -0
- package/dist/core/ConfigurationProvider.d.ts +31 -0
- package/dist/core/ConfigurationProvider.js +416 -0
- package/dist/core/InstallationService.d.ts +17 -0
- package/dist/core/InstallationService.js +144 -0
- package/dist/core/MCPManager.d.ts +17 -0
- package/dist/core/MCPManager.js +98 -0
- package/dist/core/RequirementService.d.ts +45 -0
- package/dist/core/RequirementService.js +123 -0
- package/dist/core/constants.d.ts +29 -0
- package/dist/core/constants.js +55 -0
- package/dist/core/installers/BaseInstaller.d.ts +73 -0
- package/dist/core/installers/BaseInstaller.js +247 -0
- package/dist/core/installers/ClientInstaller.d.ts +17 -0
- package/dist/core/installers/ClientInstaller.js +307 -0
- package/dist/core/installers/CommandInstaller.d.ts +36 -0
- package/dist/core/installers/CommandInstaller.js +170 -0
- package/dist/core/installers/GeneralInstaller.d.ts +32 -0
- package/dist/core/installers/GeneralInstaller.js +87 -0
- package/dist/core/installers/InstallerFactory.d.ts +52 -0
- package/dist/core/installers/InstallerFactory.js +95 -0
- package/dist/core/installers/NpmInstaller.d.ts +25 -0
- package/dist/core/installers/NpmInstaller.js +123 -0
- package/dist/core/installers/PipInstaller.d.ts +25 -0
- package/dist/core/installers/PipInstaller.js +114 -0
- package/dist/core/installers/RequirementInstaller.d.ts +32 -0
- package/dist/core/installers/RequirementInstaller.js +3 -0
- package/dist/core/installers/index.d.ts +6 -0
- package/dist/core/installers/index.js +7 -0
- package/dist/core/types.d.ts +152 -0
- package/dist/core/types.js +16 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +19 -0
- package/dist/services/InstallRequestValidator.d.ts +21 -0
- package/dist/services/InstallRequestValidator.js +99 -0
- package/dist/services/ServerService.d.ts +47 -0
- package/dist/services/ServerService.js +145 -0
- package/dist/utils/UpdateCheckTracker.d.ts +39 -0
- package/dist/utils/UpdateCheckTracker.js +80 -0
- package/dist/utils/clientUtils.d.ts +29 -0
- package/dist/utils/clientUtils.js +105 -0
- package/dist/utils/feedUtils.d.ts +5 -0
- package/dist/utils/feedUtils.js +29 -0
- package/dist/utils/githubAuth.d.ts +1 -0
- package/dist/utils/githubAuth.js +123 -0
- package/dist/utils/logger.d.ts +14 -0
- package/dist/utils/logger.js +90 -0
- package/dist/utils/osUtils.d.ts +16 -0
- package/dist/utils/osUtils.js +235 -0
- package/dist/web/public/css/modal.css +250 -0
- package/dist/web/public/css/notifications.css +70 -0
- package/dist/web/public/index.html +157 -0
- package/dist/web/public/js/api.js +213 -0
- package/dist/web/public/js/modal.js +572 -0
- package/dist/web/public/js/notifications.js +99 -0
- package/dist/web/public/js/serverCategoryDetails.js +210 -0
- package/dist/web/public/js/serverCategoryList.js +82 -0
- package/dist/web/public/modal.html +61 -0
- package/dist/web/public/styles.css +155 -0
- package/dist/web/server.d.ts +5 -0
- package/dist/web/server.js +150 -0
- package/package.json +53 -0
- package/src/cli/commands/install.ts +140 -0
- package/src/cli/commands/list.ts +112 -0
- package/src/cli/commands/pull.ts +16 -0
- package/src/cli/commands/serve.ts +37 -0
- package/src/cli/commands/uninstall.ts +54 -0
- package/src/cli/index.ts +127 -0
- package/src/core/ConfigurationProvider.ts +489 -0
- package/src/core/InstallationService.ts +173 -0
- package/src/core/MCPManager.ts +134 -0
- package/src/core/RequirementService.ts +147 -0
- package/src/core/constants.ts +61 -0
- package/src/core/installers/BaseInstaller.ts +292 -0
- package/src/core/installers/ClientInstaller.ts +423 -0
- package/src/core/installers/CommandInstaller.ts +185 -0
- package/src/core/installers/GeneralInstaller.ts +89 -0
- package/src/core/installers/InstallerFactory.ts +109 -0
- package/src/core/installers/NpmInstaller.ts +128 -0
- package/src/core/installers/PipInstaller.ts +121 -0
- package/src/core/installers/RequirementInstaller.ts +38 -0
- package/src/core/installers/index.ts +9 -0
- package/src/core/types.ts +163 -0
- package/src/index.ts +44 -0
- package/src/services/InstallRequestValidator.ts +112 -0
- package/src/services/ServerService.ts +181 -0
- package/src/utils/UpdateCheckTracker.ts +86 -0
- package/src/utils/clientUtils.ts +112 -0
- package/src/utils/feedUtils.ts +31 -0
- package/src/utils/githubAuth.ts +142 -0
- package/src/utils/logger.ts +101 -0
- package/src/utils/osUtils.ts +250 -0
- package/src/web/public/css/modal.css +250 -0
- package/src/web/public/css/notifications.css +70 -0
- package/src/web/public/index.html +157 -0
- package/src/web/public/js/api.js +213 -0
- package/src/web/public/js/modal.js +572 -0
- package/src/web/public/js/notifications.js +99 -0
- package/src/web/public/js/serverCategoryDetails.js +210 -0
- package/src/web/public/js/serverCategoryList.js +82 -0
- package/src/web/public/modal.html +61 -0
- package/src/web/public/styles.css +155 -0
- package/src/web/server.ts +195 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { OSType } from '../types.js';
|
|
2
|
+
import { BaseInstaller } from './BaseInstaller.js';
|
|
3
|
+
import { getOSType, refreshPathEnv } from '../../utils/osUtils.js';
|
|
4
|
+
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
/**
|
|
6
|
+
* Installer implementation for command-line tools
|
|
7
|
+
*/
|
|
8
|
+
export class CommandInstaller extends BaseInstaller {
|
|
9
|
+
/**
|
|
10
|
+
* Mapping of command names to their package IDs
|
|
11
|
+
* This handles special cases where the command name differs from the package ID
|
|
12
|
+
*/
|
|
13
|
+
commandMappings = {
|
|
14
|
+
'uv': { windows: 'astral-sh.uv', macos: 'uv' }
|
|
15
|
+
// Add more mappings as needed
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Check if this installer can handle the given requirement type
|
|
19
|
+
* @param requirement The requirement to check
|
|
20
|
+
* @returns True if this installer can handle the requirement
|
|
21
|
+
*/
|
|
22
|
+
canHandle(requirement) {
|
|
23
|
+
return requirement.type === 'command';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the mapped package ID for a command
|
|
27
|
+
* @param commandName The command name to map
|
|
28
|
+
* @returns The mapped package ID
|
|
29
|
+
*/
|
|
30
|
+
getMappedPackageId(commandName) {
|
|
31
|
+
const osType = getOSType();
|
|
32
|
+
const mapping = this.commandMappings[commandName];
|
|
33
|
+
if (mapping) {
|
|
34
|
+
return osType === OSType.Windows ? mapping.windows : mapping.macos;
|
|
35
|
+
}
|
|
36
|
+
// If no mapping exists, use the command name itself
|
|
37
|
+
return commandName;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if the command is already installed
|
|
41
|
+
* @param requirement The requirement to check
|
|
42
|
+
* @returns The status of the requirement
|
|
43
|
+
*/
|
|
44
|
+
async checkInstallation(requirement) {
|
|
45
|
+
try {
|
|
46
|
+
await refreshPathEnv();
|
|
47
|
+
const commandName = requirement.alias || requirement.name;
|
|
48
|
+
const osType = getOSType();
|
|
49
|
+
let commandResult;
|
|
50
|
+
if (osType === OSType.Windows) {
|
|
51
|
+
// Check if command exists on Windows
|
|
52
|
+
try {
|
|
53
|
+
commandResult = await this.execPromise(`where ${commandName} 2>nul`);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
Logger.debug(`Error checking command existence: ${error}`);
|
|
57
|
+
// On Windows, 'where' command returns non-zero exit code if the command is not found
|
|
58
|
+
// We'll handle this as "command not found" rather than an error
|
|
59
|
+
commandResult = { stdout: '', stderr: '' };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Check if command exists on macOS/Linux
|
|
64
|
+
try {
|
|
65
|
+
commandResult = await this.execPromise(`which ${commandName} 2>/dev/null`);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
Logger.debug(`Error checking command existence: ${error}`);
|
|
69
|
+
// Similarly handle command not found on Unix systems
|
|
70
|
+
commandResult = { stdout: '', stderr: '' };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// If the command exists, it will return a path or multiple paths
|
|
74
|
+
const installed = commandResult.stdout.trim().length > 0;
|
|
75
|
+
// Try to get version information if available
|
|
76
|
+
let version;
|
|
77
|
+
if (installed) {
|
|
78
|
+
try {
|
|
79
|
+
const versionResult = await this.execPromise(`${commandName} --version`);
|
|
80
|
+
if (versionResult.stdout) {
|
|
81
|
+
// Extract version information - this is a simple approach that might need refinement
|
|
82
|
+
const versionMatch = versionResult.stdout.match(/\d+\.\d+(\.\d+)?/);
|
|
83
|
+
version = versionMatch ? versionMatch[0] : undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
Logger.debug(`Error checking command version: ${error}`);
|
|
88
|
+
// Ignore errors from version check, consider it installed anyway
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
name: requirement.name,
|
|
93
|
+
type: 'command',
|
|
94
|
+
installed,
|
|
95
|
+
version,
|
|
96
|
+
inProgress: false
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
Logger.error(`Error checking installation: ${error}`);
|
|
101
|
+
return {
|
|
102
|
+
name: requirement.name,
|
|
103
|
+
type: 'command',
|
|
104
|
+
installed: false,
|
|
105
|
+
error: error instanceof Error ? error.message : String(error),
|
|
106
|
+
inProgress: false
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Install the command
|
|
112
|
+
* @param requirement The requirement to install
|
|
113
|
+
* @returns The status of the installation
|
|
114
|
+
*/
|
|
115
|
+
async install(requirement) {
|
|
116
|
+
try {
|
|
117
|
+
const status = await this.checkInstallation(requirement);
|
|
118
|
+
if (status.installed) {
|
|
119
|
+
return status;
|
|
120
|
+
}
|
|
121
|
+
const packageId = this.getMappedPackageId(requirement.name);
|
|
122
|
+
const osType = getOSType();
|
|
123
|
+
let installCommand;
|
|
124
|
+
if (osType === OSType.Windows) {
|
|
125
|
+
// Windows installation using winget
|
|
126
|
+
installCommand = `winget install --id ${packageId}`;
|
|
127
|
+
if (requirement.version && requirement.version !== 'latest') {
|
|
128
|
+
installCommand += ` --version ${requirement.version}`;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (osType === OSType.MacOS) {
|
|
132
|
+
// macOS installation using Homebrew
|
|
133
|
+
installCommand = `brew install ${packageId}`;
|
|
134
|
+
if (requirement.version && requirement.version !== 'latest') {
|
|
135
|
+
installCommand += `@${requirement.version}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw new Error(`Unsupported operating system for installing ${requirement.name}`);
|
|
140
|
+
}
|
|
141
|
+
// Execute the installation command
|
|
142
|
+
const { stderr } = await this.execPromise(installCommand);
|
|
143
|
+
if (stderr && stderr.toLowerCase().includes('error')) {
|
|
144
|
+
throw new Error(stderr);
|
|
145
|
+
}
|
|
146
|
+
// Check if installation was successful
|
|
147
|
+
const updatedStatus = await this.checkInstallation(requirement);
|
|
148
|
+
if (!updatedStatus.installed) {
|
|
149
|
+
throw new Error(`Failed to install ${requirement.name}`);
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
name: requirement.name,
|
|
153
|
+
type: 'command',
|
|
154
|
+
installed: true,
|
|
155
|
+
version: updatedStatus.version || requirement.version,
|
|
156
|
+
inProgress: false
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
return {
|
|
161
|
+
name: requirement.name,
|
|
162
|
+
type: 'command',
|
|
163
|
+
installed: false,
|
|
164
|
+
error: error instanceof Error ? error.message : String(error),
|
|
165
|
+
inProgress: false
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=CommandInstaller.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RequirementConfig, RequirementStatus } from '../types.js';
|
|
2
|
+
import { BaseInstaller } from './BaseInstaller.js';
|
|
3
|
+
/**
|
|
4
|
+
* Installer implementation for general requirements (type 'other')
|
|
5
|
+
* This installer handles requirements that don't fit into specific package manager categories
|
|
6
|
+
*/
|
|
7
|
+
export declare class GeneralInstaller extends BaseInstaller {
|
|
8
|
+
/**
|
|
9
|
+
* Check if this installer can handle the given requirement type
|
|
10
|
+
* @param requirement The requirement to check
|
|
11
|
+
* @returns True if this installer can handle the requirement
|
|
12
|
+
*/
|
|
13
|
+
canHandle(requirement: RequirementConfig): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Check if the requirement is already installed
|
|
16
|
+
* For general installers, we can't easily check if something is installed
|
|
17
|
+
* without specific knowledge of the requirement, so we always return false
|
|
18
|
+
*
|
|
19
|
+
* @param requirement The requirement to check
|
|
20
|
+
* @returns The status of the requirement
|
|
21
|
+
*/
|
|
22
|
+
checkInstallation(requirement: RequirementConfig): Promise<RequirementStatus>;
|
|
23
|
+
/**
|
|
24
|
+
* Install the general requirement
|
|
25
|
+
* For type 'other', this doesn't actually install anything, but downloads
|
|
26
|
+
* or locates the asset and returns the path for the caller to use
|
|
27
|
+
*
|
|
28
|
+
* @param requirement The requirement to install
|
|
29
|
+
* @returns The status of the installation, including the install path in updateInfo
|
|
30
|
+
*/
|
|
31
|
+
install(requirement: RequirementConfig): Promise<RequirementStatus>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { BaseInstaller } from './BaseInstaller.js';
|
|
2
|
+
/**
|
|
3
|
+
* Installer implementation for general requirements (type 'other')
|
|
4
|
+
* This installer handles requirements that don't fit into specific package manager categories
|
|
5
|
+
*/
|
|
6
|
+
export class GeneralInstaller extends BaseInstaller {
|
|
7
|
+
/**
|
|
8
|
+
* Check if this installer can handle the given requirement type
|
|
9
|
+
* @param requirement The requirement to check
|
|
10
|
+
* @returns True if this installer can handle the requirement
|
|
11
|
+
*/
|
|
12
|
+
canHandle(requirement) {
|
|
13
|
+
return requirement.type === 'other';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if the requirement is already installed
|
|
17
|
+
* For general installers, we can't easily check if something is installed
|
|
18
|
+
* without specific knowledge of the requirement, so we always return false
|
|
19
|
+
*
|
|
20
|
+
* @param requirement The requirement to check
|
|
21
|
+
* @returns The status of the requirement
|
|
22
|
+
*/
|
|
23
|
+
async checkInstallation(requirement) {
|
|
24
|
+
// For general installers, we can't easily check if something is installed
|
|
25
|
+
// So we'll always return not installed, and the actual installation will check
|
|
26
|
+
return {
|
|
27
|
+
name: requirement.name,
|
|
28
|
+
type: 'other',
|
|
29
|
+
installed: false,
|
|
30
|
+
inProgress: false
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Install the general requirement
|
|
35
|
+
* For type 'other', this doesn't actually install anything, but downloads
|
|
36
|
+
* or locates the asset and returns the path for the caller to use
|
|
37
|
+
*
|
|
38
|
+
* @param requirement The requirement to install
|
|
39
|
+
* @returns The status of the installation, including the install path in updateInfo
|
|
40
|
+
*/
|
|
41
|
+
async install(requirement) {
|
|
42
|
+
try {
|
|
43
|
+
// For type 'other', a registry must be specified
|
|
44
|
+
if (!requirement.registry) {
|
|
45
|
+
throw new Error('Registry must be specified for requirement type "other"');
|
|
46
|
+
}
|
|
47
|
+
let installPath;
|
|
48
|
+
if (requirement.registry.githubRelease) {
|
|
49
|
+
const result = await this.handleGitHubRelease(requirement, requirement.registry.githubRelease);
|
|
50
|
+
installPath = result.resolvedPath;
|
|
51
|
+
}
|
|
52
|
+
else if (requirement.registry.artifacts) {
|
|
53
|
+
installPath = await this.handleArtifactsRegistry(requirement, requirement.registry.artifacts);
|
|
54
|
+
}
|
|
55
|
+
else if (requirement.registry.local) {
|
|
56
|
+
installPath = await this.handleLocalRegistry(requirement, requirement.registry.local);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error('Invalid registry configuration');
|
|
60
|
+
}
|
|
61
|
+
// For general installer, we just return the path to the downloaded/located file
|
|
62
|
+
// The actual installation mechanism would depend on the specific requirement
|
|
63
|
+
return {
|
|
64
|
+
name: requirement.name,
|
|
65
|
+
type: 'other',
|
|
66
|
+
installed: true,
|
|
67
|
+
version: requirement.version,
|
|
68
|
+
inProgress: false,
|
|
69
|
+
// Store installation path in a way that it can be retrieved later if needed
|
|
70
|
+
updateInfo: {
|
|
71
|
+
available: false,
|
|
72
|
+
installPath
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return {
|
|
78
|
+
name: requirement.name,
|
|
79
|
+
type: 'other',
|
|
80
|
+
installed: false,
|
|
81
|
+
error: error instanceof Error ? error.message : String(error),
|
|
82
|
+
inProgress: false
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=GeneralInstaller.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { RequirementConfig, RequirementStatus } from '../types.js';
|
|
2
|
+
import { RequirementInstaller } from './RequirementInstaller.js';
|
|
3
|
+
import { exec } from 'child_process';
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating the appropriate installer for a requirement
|
|
6
|
+
*/
|
|
7
|
+
export declare class InstallerFactory {
|
|
8
|
+
private installers;
|
|
9
|
+
private readonly execPromise;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new InstallerFactory
|
|
12
|
+
* @param execPromise Function to execute commands
|
|
13
|
+
*/
|
|
14
|
+
constructor(execPromise: (command: string) => Promise<{
|
|
15
|
+
stdout: string;
|
|
16
|
+
stderr: string;
|
|
17
|
+
}>);
|
|
18
|
+
/**
|
|
19
|
+
* Register default installers for npm, pip, and general requirements
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
private registerDefaultInstallers;
|
|
23
|
+
/**
|
|
24
|
+
* Register a custom installer
|
|
25
|
+
* @param installer The installer to register
|
|
26
|
+
*/
|
|
27
|
+
registerInstaller(installer: RequirementInstaller): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get the appropriate installer for a requirement
|
|
30
|
+
* @param requirement The requirement to get an installer for
|
|
31
|
+
* @returns The appropriate installer, or undefined if none found
|
|
32
|
+
*/
|
|
33
|
+
getInstaller(requirement: RequirementConfig): RequirementInstaller | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Install a requirement using the appropriate installer
|
|
36
|
+
* @param requirement The requirement to install
|
|
37
|
+
* @returns The installation status
|
|
38
|
+
*/
|
|
39
|
+
install(requirement: RequirementConfig): Promise<RequirementStatus>;
|
|
40
|
+
/**
|
|
41
|
+
* Check the installation status of a requirement
|
|
42
|
+
* @param requirement The requirement to check
|
|
43
|
+
* @returns The installation status
|
|
44
|
+
*/
|
|
45
|
+
checkInstallation(requirement: RequirementConfig): Promise<RequirementStatus>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a new InstallerFactory with default settings
|
|
49
|
+
* @param execPromise Optional function to execute commands
|
|
50
|
+
* @returns A new InstallerFactory
|
|
51
|
+
*/
|
|
52
|
+
export declare const createInstallerFactory: (execPromise?: typeof exec.__promisify__) => InstallerFactory;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { NpmInstaller } from './NpmInstaller.js';
|
|
2
|
+
import { PipInstaller } from './PipInstaller.js';
|
|
3
|
+
import { CommandInstaller } from './CommandInstaller.js';
|
|
4
|
+
import { GeneralInstaller } from './GeneralInstaller.js';
|
|
5
|
+
import { exec } from 'child_process';
|
|
6
|
+
import util from 'util';
|
|
7
|
+
/**
|
|
8
|
+
* Factory for creating the appropriate installer for a requirement
|
|
9
|
+
*/
|
|
10
|
+
export class InstallerFactory {
|
|
11
|
+
installers = [];
|
|
12
|
+
execPromise;
|
|
13
|
+
/**
|
|
14
|
+
* Create a new InstallerFactory
|
|
15
|
+
* @param execPromise Function to execute commands
|
|
16
|
+
*/
|
|
17
|
+
constructor(execPromise) {
|
|
18
|
+
this.execPromise = execPromise;
|
|
19
|
+
this.registerDefaultInstallers();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Register default installers for npm, pip, and general requirements
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
registerDefaultInstallers() {
|
|
26
|
+
this.registerInstaller(new NpmInstaller(this.execPromise));
|
|
27
|
+
this.registerInstaller(new PipInstaller(this.execPromise));
|
|
28
|
+
this.registerInstaller(new CommandInstaller(this.execPromise));
|
|
29
|
+
this.registerInstaller(new GeneralInstaller(this.execPromise));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Register a custom installer
|
|
33
|
+
* @param installer The installer to register
|
|
34
|
+
*/
|
|
35
|
+
registerInstaller(installer) {
|
|
36
|
+
this.installers.push(installer);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the appropriate installer for a requirement
|
|
40
|
+
* @param requirement The requirement to get an installer for
|
|
41
|
+
* @returns The appropriate installer, or undefined if none found
|
|
42
|
+
*/
|
|
43
|
+
getInstaller(requirement) {
|
|
44
|
+
// Validate that if registry is empty, type must not be 'other'
|
|
45
|
+
if (!requirement.registry && requirement.type === 'other') {
|
|
46
|
+
throw new Error('Registry must be specified for requirement type "other"');
|
|
47
|
+
}
|
|
48
|
+
return this.installers.find(installer => installer.canHandle(requirement));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Install a requirement using the appropriate installer
|
|
52
|
+
* @param requirement The requirement to install
|
|
53
|
+
* @returns The installation status
|
|
54
|
+
*/
|
|
55
|
+
async install(requirement) {
|
|
56
|
+
const installer = this.getInstaller(requirement);
|
|
57
|
+
if (!installer) {
|
|
58
|
+
return {
|
|
59
|
+
name: requirement.name,
|
|
60
|
+
type: requirement.type,
|
|
61
|
+
installed: false,
|
|
62
|
+
error: `No installer found for requirement type '${requirement.type}'`,
|
|
63
|
+
inProgress: false
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return await installer.install(requirement);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check the installation status of a requirement
|
|
70
|
+
* @param requirement The requirement to check
|
|
71
|
+
* @returns The installation status
|
|
72
|
+
*/
|
|
73
|
+
async checkInstallation(requirement) {
|
|
74
|
+
const installer = this.getInstaller(requirement);
|
|
75
|
+
if (!installer) {
|
|
76
|
+
return {
|
|
77
|
+
name: requirement.name,
|
|
78
|
+
type: requirement.type,
|
|
79
|
+
installed: false,
|
|
80
|
+
error: `No installer found for requirement type '${requirement.type}'`,
|
|
81
|
+
inProgress: false
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return await installer.checkInstallation(requirement);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a new InstallerFactory with default settings
|
|
89
|
+
* @param execPromise Optional function to execute commands
|
|
90
|
+
* @returns A new InstallerFactory
|
|
91
|
+
*/
|
|
92
|
+
export const createInstallerFactory = (execPromise = util.promisify(exec)) => {
|
|
93
|
+
return new InstallerFactory(execPromise);
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=InstallerFactory.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RequirementConfig, RequirementStatus } from '../types.js';
|
|
2
|
+
import { BaseInstaller } from './BaseInstaller.js';
|
|
3
|
+
/**
|
|
4
|
+
* Installer implementation for NPM packages
|
|
5
|
+
*/
|
|
6
|
+
export declare class NpmInstaller extends BaseInstaller {
|
|
7
|
+
/**
|
|
8
|
+
* Check if this installer can handle the given requirement type
|
|
9
|
+
* @param requirement The requirement to check
|
|
10
|
+
* @returns True if this installer can handle the requirement
|
|
11
|
+
*/
|
|
12
|
+
canHandle(requirement: RequirementConfig): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Check if the NPM package is already installed
|
|
15
|
+
* @param requirement The requirement to check
|
|
16
|
+
* @returns The status of the requirement
|
|
17
|
+
*/
|
|
18
|
+
checkInstallation(requirement: RequirementConfig): Promise<RequirementStatus>;
|
|
19
|
+
/**
|
|
20
|
+
* Install the NPM package
|
|
21
|
+
* @param requirement The requirement to install
|
|
22
|
+
* @returns The status of the installation
|
|
23
|
+
*/
|
|
24
|
+
install(requirement: RequirementConfig): Promise<RequirementStatus>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { BaseInstaller } from './BaseInstaller.js';
|
|
2
|
+
/**
|
|
3
|
+
* Installer implementation for NPM packages
|
|
4
|
+
*/
|
|
5
|
+
export class NpmInstaller extends BaseInstaller {
|
|
6
|
+
/**
|
|
7
|
+
* Check if this installer can handle the given requirement type
|
|
8
|
+
* @param requirement The requirement to check
|
|
9
|
+
* @returns True if this installer can handle the requirement
|
|
10
|
+
*/
|
|
11
|
+
canHandle(requirement) {
|
|
12
|
+
return requirement.type === 'npm';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check if the NPM package is already installed
|
|
16
|
+
* @param requirement The requirement to check
|
|
17
|
+
* @returns The status of the requirement
|
|
18
|
+
*/
|
|
19
|
+
async checkInstallation(requirement) {
|
|
20
|
+
try {
|
|
21
|
+
const { stdout } = await this.execPromise(`npm list -g ${requirement.name} --json`);
|
|
22
|
+
const pkgInfo = JSON.parse(stdout);
|
|
23
|
+
const installedVersion = pkgInfo?.dependencies?.[requirement.name]?.version;
|
|
24
|
+
return {
|
|
25
|
+
name: requirement.name,
|
|
26
|
+
type: 'npm',
|
|
27
|
+
installed: !!installedVersion,
|
|
28
|
+
version: installedVersion,
|
|
29
|
+
inProgress: false
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
return {
|
|
34
|
+
name: requirement.name,
|
|
35
|
+
type: 'npm',
|
|
36
|
+
installed: false,
|
|
37
|
+
error: error instanceof Error ? error.message : String(error),
|
|
38
|
+
inProgress: false
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Install the NPM package
|
|
44
|
+
* @param requirement The requirement to install
|
|
45
|
+
* @returns The status of the installation
|
|
46
|
+
*/
|
|
47
|
+
async install(requirement) {
|
|
48
|
+
try {
|
|
49
|
+
const status = await this.checkInstallation(requirement);
|
|
50
|
+
if (status.installed) {
|
|
51
|
+
return status;
|
|
52
|
+
}
|
|
53
|
+
let resolvedVersion = requirement.version;
|
|
54
|
+
// If no registry is specified, use standard npm installation
|
|
55
|
+
if (!requirement.registry) {
|
|
56
|
+
const { stderr } = await this.execPromise(`npm install -g ${requirement.name}@${requirement.version}`);
|
|
57
|
+
if (stderr && !stderr.includes('added')) {
|
|
58
|
+
throw new Error(stderr);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Handle different registry types
|
|
63
|
+
let packageSource;
|
|
64
|
+
if (requirement.registry.githubRelease) {
|
|
65
|
+
const result = await this.handleGitHubRelease(requirement, requirement.registry.githubRelease);
|
|
66
|
+
packageSource = result.resolvedPath;
|
|
67
|
+
resolvedVersion = result.resolvedVersion;
|
|
68
|
+
}
|
|
69
|
+
else if (requirement.registry.artifacts) {
|
|
70
|
+
// For npm with artifacts, configure npm to use the specified registry URL
|
|
71
|
+
const registryUrl = requirement.registry.artifacts.registryUrl;
|
|
72
|
+
await this.execPromise(`npm config set registry ${registryUrl}`);
|
|
73
|
+
// Now install the package with the configured registry
|
|
74
|
+
const { stderr } = await this.execPromise(`npm install -g ${requirement.name}@${requirement.version}`);
|
|
75
|
+
if (stderr && !stderr.includes('added')) {
|
|
76
|
+
// Reset the registry to the default npm registry
|
|
77
|
+
await this.execPromise('npm config set registry https://registry.npmjs.org/');
|
|
78
|
+
throw new Error(stderr);
|
|
79
|
+
}
|
|
80
|
+
// Reset the registry to the default npm registry
|
|
81
|
+
await this.execPromise('npm config set registry https://registry.npmjs.org/');
|
|
82
|
+
return {
|
|
83
|
+
name: requirement.name,
|
|
84
|
+
type: 'npm',
|
|
85
|
+
installed: true,
|
|
86
|
+
version: requirement.version,
|
|
87
|
+
inProgress: false
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
else if (requirement.registry.local) {
|
|
91
|
+
packageSource = await this.handleLocalRegistry(requirement, requirement.registry.local);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw new Error('Invalid registry configuration');
|
|
95
|
+
}
|
|
96
|
+
// Install from the package source
|
|
97
|
+
const { stderr } = await this.execPromise(`npm install -g "${packageSource}"`);
|
|
98
|
+
if (stderr && !stderr.includes('added')) {
|
|
99
|
+
const status = await this.checkInstallation(requirement);
|
|
100
|
+
if (!status.installed)
|
|
101
|
+
throw new Error(stderr);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
name: requirement.name,
|
|
106
|
+
type: 'npm',
|
|
107
|
+
installed: true,
|
|
108
|
+
version: resolvedVersion,
|
|
109
|
+
inProgress: false
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return {
|
|
114
|
+
name: requirement.name,
|
|
115
|
+
type: 'npm',
|
|
116
|
+
installed: false,
|
|
117
|
+
error: error instanceof Error ? error.message : String(error),
|
|
118
|
+
inProgress: false
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=NpmInstaller.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RequirementConfig, RequirementStatus } from '../types.js';
|
|
2
|
+
import { BaseInstaller } from './BaseInstaller.js';
|
|
3
|
+
/**
|
|
4
|
+
* Installer implementation for Python packages using pip
|
|
5
|
+
*/
|
|
6
|
+
export declare class PipInstaller extends BaseInstaller {
|
|
7
|
+
/**
|
|
8
|
+
* Check if this installer can handle the given requirement type
|
|
9
|
+
* @param requirement The requirement to check
|
|
10
|
+
* @returns True if this installer can handle the requirement
|
|
11
|
+
*/
|
|
12
|
+
canHandle(requirement: RequirementConfig): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Check if the Python package is already installed
|
|
15
|
+
* @param requirement The requirement to check
|
|
16
|
+
* @returns The status of the requirement
|
|
17
|
+
*/
|
|
18
|
+
checkInstallation(requirement: RequirementConfig): Promise<RequirementStatus>;
|
|
19
|
+
/**
|
|
20
|
+
* Install the Python package
|
|
21
|
+
* @param requirement The requirement to install
|
|
22
|
+
* @returns The status of the installation
|
|
23
|
+
*/
|
|
24
|
+
install(requirement: RequirementConfig): Promise<RequirementStatus>;
|
|
25
|
+
}
|