@howlil/ez-agents 3.4.2 → 3.5.0
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/README.md +77 -2
- package/agents/ez-observer-agent.md +260 -0
- package/agents/ez-release-agent.md +333 -0
- package/agents/ez-requirements-agent.md +377 -0
- package/agents/ez-scrum-master-agent.md +242 -0
- package/agents/ez-tech-lead-agent.md +267 -0
- package/bin/install.js +3221 -3272
- package/commands/ez/arch-review.md +102 -0
- package/commands/ez/execute-phase.md +11 -0
- package/commands/ez/export-session.md +79 -0
- package/commands/ez/gather-requirements.md +117 -0
- package/commands/ez/git-workflow.md +72 -0
- package/commands/ez/hotfix.md +120 -0
- package/commands/ez/import-session.md +82 -0
- package/commands/ez/list-sessions.md +96 -0
- package/commands/ez/package-manager.md +316 -0
- package/commands/ez/plan-phase.md +9 -1
- package/commands/ez/preflight.md +79 -0
- package/commands/ez/progress.md +13 -1
- package/commands/ez/release.md +153 -0
- package/commands/ez/resume.md +107 -0
- package/commands/ez/standup.md +85 -0
- package/ez-agents/bin/ez-tools.cjs +1095 -716
- package/ez-agents/bin/lib/bdd-validator.cjs +622 -0
- package/ez-agents/bin/lib/content-scanner.cjs +238 -0
- package/ez-agents/bin/lib/context-cache.cjs +154 -0
- package/ez-agents/bin/lib/context-errors.cjs +71 -0
- package/ez-agents/bin/lib/context-manager.cjs +220 -0
- package/ez-agents/bin/lib/discussion-synthesizer.cjs +458 -0
- package/ez-agents/bin/lib/file-access.cjs +207 -0
- package/ez-agents/bin/lib/git-errors.cjs +83 -0
- package/ez-agents/bin/lib/git-utils.cjs +321 -203
- package/ez-agents/bin/lib/git-workflow-engine.cjs +1157 -0
- package/ez-agents/bin/lib/index.cjs +46 -2
- package/ez-agents/bin/lib/lockfile-validator.cjs +227 -0
- package/ez-agents/bin/lib/logger.cjs +124 -154
- package/ez-agents/bin/lib/memory-compression.cjs +256 -0
- package/ez-agents/bin/lib/metrics-tracker.cjs +406 -0
- package/ez-agents/bin/lib/package-manager-detector.cjs +203 -0
- package/ez-agents/bin/lib/package-manager-executor.cjs +385 -0
- package/ez-agents/bin/lib/package-manager-service.cjs +216 -0
- package/ez-agents/bin/lib/release-validator.cjs +614 -0
- package/ez-agents/bin/lib/safe-exec.cjs +128 -214
- package/ez-agents/bin/lib/session-chain.cjs +304 -0
- package/ez-agents/bin/lib/session-errors.cjs +81 -0
- package/ez-agents/bin/lib/session-export.cjs +251 -0
- package/ez-agents/bin/lib/session-import.cjs +262 -0
- package/ez-agents/bin/lib/session-manager.cjs +280 -0
- package/ez-agents/bin/lib/tier-manager.cjs +428 -0
- package/ez-agents/bin/lib/url-fetch.cjs +170 -0
- package/ez-agents/references/metrics-schema.md +118 -0
- package/ez-agents/references/planning-config.md +140 -0
- package/ez-agents/references/tier-strategy.md +103 -0
- package/ez-agents/templates/bdd-feature.md +173 -0
- package/ez-agents/templates/discussion.md +68 -0
- package/ez-agents/templates/incident-runbook.md +205 -0
- package/ez-agents/templates/release-checklist.md +133 -0
- package/ez-agents/templates/rollback-plan.md +201 -0
- package/ez-agents/workflows/arch-review.md +54 -0
- package/ez-agents/workflows/autonomous.md +844 -743
- package/ez-agents/workflows/execute-phase.md +45 -0
- package/ez-agents/workflows/export-session.md +255 -0
- package/ez-agents/workflows/gather-requirements.md +206 -0
- package/ez-agents/workflows/help.md +92 -0
- package/ez-agents/workflows/hotfix.md +291 -0
- package/ez-agents/workflows/import-session.md +303 -0
- package/ez-agents/workflows/new-milestone.md +713 -384
- package/ez-agents/workflows/new-project.md +1107 -1113
- package/ez-agents/workflows/plan-phase.md +22 -0
- package/ez-agents/workflows/progress.md +15 -25
- package/ez-agents/workflows/release.md +253 -0
- package/ez-agents/workflows/resume-session.md +215 -0
- package/ez-agents/workflows/standup.md +64 -0
- package/package.json +9 -2
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Package Manager Detector — Auto-detect available package managers
|
|
5
|
+
*
|
|
6
|
+
* Detects package managers (npm, yarn, pnpm) using a multi-layer strategy:
|
|
7
|
+
* 1. Configuration override (.planning/config.json)
|
|
8
|
+
* 2. Lockfile presence (pnpm-lock.yaml, yarn.lock, package-lock.json)
|
|
9
|
+
* 3. System availability (which pnpm/yarn/npm)
|
|
10
|
+
* 4. Fallback to npm (always available with Node)
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* const PackageManagerDetector = require('./package-manager-detector.cjs');
|
|
14
|
+
* const detector = new PackageManagerDetector(cwd);
|
|
15
|
+
* const result = detector.detect();
|
|
16
|
+
* // Returns: { manager, source, confidence, lockfilePath? }
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const { execFileSync } = require('child_process');
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
const Logger = require('./logger.cjs');
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Package Manager Detector class
|
|
26
|
+
* Detects available package managers with priority-based strategy
|
|
27
|
+
*/
|
|
28
|
+
class PackageManagerDetector {
|
|
29
|
+
/**
|
|
30
|
+
* Create a PackageManagerDetector instance
|
|
31
|
+
* @param {string} cwd - Working directory (default: process.cwd())
|
|
32
|
+
*/
|
|
33
|
+
constructor(cwd = process.cwd()) {
|
|
34
|
+
this.cwd = cwd;
|
|
35
|
+
this.logger = new Logger();
|
|
36
|
+
this.config = this.loadConfig();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Detect package manager with priority-based strategy
|
|
41
|
+
* @returns {Object} Detection result { manager, source, confidence, lockfilePath? }
|
|
42
|
+
*/
|
|
43
|
+
detect() {
|
|
44
|
+
this.logger.info('Starting package manager detection', { cwd: this.cwd });
|
|
45
|
+
|
|
46
|
+
// Layer 1: Configuration override
|
|
47
|
+
const configManager = this._detectFromConfig();
|
|
48
|
+
if (configManager) {
|
|
49
|
+
this.logger.info('Package manager detected from config', { manager: configManager });
|
|
50
|
+
return {
|
|
51
|
+
manager: configManager,
|
|
52
|
+
source: 'config',
|
|
53
|
+
confidence: 'high',
|
|
54
|
+
configPath: '.planning/config.json'
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Layer 2: Lockfile detection
|
|
59
|
+
const lockfileManager = this.detectFromLockfile();
|
|
60
|
+
if (lockfileManager) {
|
|
61
|
+
const lockfilePath = this.getLockfilePath(lockfileManager);
|
|
62
|
+
this.logger.info('Package manager detected from lockfile', {
|
|
63
|
+
manager: lockfileManager,
|
|
64
|
+
lockfilePath
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
manager: lockfileManager,
|
|
68
|
+
source: 'lockfile',
|
|
69
|
+
confidence: 'high',
|
|
70
|
+
lockfilePath
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Layer 3: System availability
|
|
75
|
+
const availableManagers = this.getAvailableManagers();
|
|
76
|
+
if (availableManagers.length > 0) {
|
|
77
|
+
// Prefer pnpm > yarn > npm (performance order)
|
|
78
|
+
const preferred = availableManagers.find(m => m === 'pnpm') ||
|
|
79
|
+
availableManagers.find(m => m === 'yarn') ||
|
|
80
|
+
availableManagers[0];
|
|
81
|
+
this.logger.info('Package manager detected from system', {
|
|
82
|
+
manager: preferred,
|
|
83
|
+
available: availableManagers
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
manager: preferred,
|
|
87
|
+
source: 'system',
|
|
88
|
+
confidence: 'medium',
|
|
89
|
+
available: availableManagers
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Layer 4: Fallback to npm
|
|
94
|
+
this.logger.warn('No package manager detected, falling back to npm');
|
|
95
|
+
return {
|
|
96
|
+
manager: 'npm',
|
|
97
|
+
source: 'fallback',
|
|
98
|
+
confidence: 'low',
|
|
99
|
+
reason: 'No other package manager detected'
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Detect package manager from configuration
|
|
105
|
+
* @private
|
|
106
|
+
* @returns {string|null} Package manager name or null
|
|
107
|
+
*/
|
|
108
|
+
_detectFromConfig() {
|
|
109
|
+
const configManager = this.config?.packageManager?.default;
|
|
110
|
+
if (configManager && this.isPackageManagerInstalled(configManager)) {
|
|
111
|
+
return configManager;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Detect package manager from lockfile presence
|
|
118
|
+
* @returns {string|null} Package manager name or null
|
|
119
|
+
*/
|
|
120
|
+
detectFromLockfile() {
|
|
121
|
+
const lockfiles = {
|
|
122
|
+
'pnpm-lock.yaml': 'pnpm',
|
|
123
|
+
'yarn.lock': 'yarn',
|
|
124
|
+
'package-lock.json': 'npm'
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
for (const [lockfile, manager] of Object.entries(lockfiles)) {
|
|
128
|
+
const lockfilePath = path.join(this.cwd, lockfile);
|
|
129
|
+
if (fs.existsSync(lockfilePath)) {
|
|
130
|
+
return manager;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get all available package managers installed on the system
|
|
138
|
+
* @returns {string[]} Array of available manager names
|
|
139
|
+
*/
|
|
140
|
+
getAvailableManagers() {
|
|
141
|
+
const managers = ['pnpm', 'yarn', 'npm'];
|
|
142
|
+
const available = [];
|
|
143
|
+
|
|
144
|
+
for (const manager of managers) {
|
|
145
|
+
if (this.isPackageManagerInstalled(manager)) {
|
|
146
|
+
available.push(manager);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return available;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Check if a specific package manager is installed
|
|
155
|
+
* @param {string} manager - Package manager name
|
|
156
|
+
* @returns {boolean} True if installed
|
|
157
|
+
*/
|
|
158
|
+
isPackageManagerInstalled(manager) {
|
|
159
|
+
try {
|
|
160
|
+
execFileSync(manager, ['--version'], {
|
|
161
|
+
stdio: 'pipe',
|
|
162
|
+
shell: false
|
|
163
|
+
});
|
|
164
|
+
return true;
|
|
165
|
+
} catch (err) {
|
|
166
|
+
this.logger.debug('Package manager not installed', { manager, error: err.message });
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get the lockfile path for a specific package manager
|
|
173
|
+
* @param {string} manager - Package manager name
|
|
174
|
+
* @returns {string} Full path to lockfile
|
|
175
|
+
*/
|
|
176
|
+
getLockfilePath(manager) {
|
|
177
|
+
const lockfiles = {
|
|
178
|
+
'pnpm': 'pnpm-lock.yaml',
|
|
179
|
+
'yarn': 'yarn.lock',
|
|
180
|
+
'npm': 'package-lock.json'
|
|
181
|
+
};
|
|
182
|
+
return path.join(this.cwd, lockfiles[manager] || 'package-lock.json');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Load configuration from .planning/config.json
|
|
187
|
+
* @returns {Object} Configuration object
|
|
188
|
+
*/
|
|
189
|
+
loadConfig() {
|
|
190
|
+
const configPath = path.join(this.cwd, '.planning', 'config.json');
|
|
191
|
+
try {
|
|
192
|
+
if (fs.existsSync(configPath)) {
|
|
193
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
194
|
+
return JSON.parse(content);
|
|
195
|
+
}
|
|
196
|
+
} catch (err) {
|
|
197
|
+
this.logger.warn('Failed to load config', { path: configPath, error: err.message });
|
|
198
|
+
}
|
|
199
|
+
return {};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
module.exports = PackageManagerDetector;
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Package Manager Executor — Execute package manager commands
|
|
5
|
+
*
|
|
6
|
+
* Provides unified interface for npm, yarn, and pnpm operations:
|
|
7
|
+
* - install: Install dependencies from lockfile
|
|
8
|
+
* - add: Add new package(s) to project
|
|
9
|
+
* - remove: Remove package(s) from project
|
|
10
|
+
*
|
|
11
|
+
* Cross-platform execution using execFile (not exec) for security
|
|
12
|
+
* and consistent behavior across Windows, macOS, and Linux.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* const PackageManagerExecutor = require('./package-manager-executor.cjs');
|
|
16
|
+
* const executor = new PackageManagerExecutor('npm', cwd);
|
|
17
|
+
* await executor.install({ production: false, frozenLockfile: true });
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const { execFile } = require('child_process');
|
|
21
|
+
const { promisify } = require('util');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
const Logger = require('./logger.cjs');
|
|
24
|
+
|
|
25
|
+
const execFileAsync = promisify(execFile);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Custom error class for package manager operations
|
|
29
|
+
*/
|
|
30
|
+
class PackageManagerError extends Error {
|
|
31
|
+
constructor({ manager, cmd, args, error, stderr, stdout }) {
|
|
32
|
+
const message = `[${manager}] ${cmd} ${args.join(' ')} failed: ${error}${stderr ? `\n${stderr}` : ''}`;
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = 'PackageManagerError';
|
|
35
|
+
this.manager = manager;
|
|
36
|
+
this.cmd = cmd;
|
|
37
|
+
this.args = args;
|
|
38
|
+
this.stderr = stderr;
|
|
39
|
+
this.stdout = stdout;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Package Manager Executor class
|
|
45
|
+
* Executes package manager commands with cross-platform compatibility
|
|
46
|
+
*/
|
|
47
|
+
class PackageManagerExecutor {
|
|
48
|
+
/**
|
|
49
|
+
* Create a PackageManagerExecutor instance
|
|
50
|
+
* @param {string} manager - Package manager name ('npm', 'yarn', or 'pnpm')
|
|
51
|
+
* @param {string} cwd - Working directory (default: process.cwd())
|
|
52
|
+
*/
|
|
53
|
+
constructor(manager, cwd = process.cwd()) {
|
|
54
|
+
if (!['npm', 'yarn', 'pnpm'].includes(manager)) {
|
|
55
|
+
throw new Error(`Unknown package manager: ${manager}. Must be 'npm', 'yarn', or 'pnpm'`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.manager = manager;
|
|
59
|
+
this.cwd = cwd;
|
|
60
|
+
this.logger = new Logger();
|
|
61
|
+
this.timeout = 300000; // 5 minutes
|
|
62
|
+
this.maxBuffer = 10 * 1024 * 1024; // 10MB buffer
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Execute install command
|
|
67
|
+
* @param {Object} options - Install options
|
|
68
|
+
* @param {boolean} [options.production] - Production install (exclude devDependencies)
|
|
69
|
+
* @param {boolean} [options.frozenLockfile] - Use frozen lockfile (CI/CD safe)
|
|
70
|
+
* @param {boolean} [options.preferOffline] - Prefer offline cache
|
|
71
|
+
* @returns {Promise<string>} Command output
|
|
72
|
+
*/
|
|
73
|
+
async install(options = {}) {
|
|
74
|
+
const { production, frozenLockfile, preferOffline } = options;
|
|
75
|
+
|
|
76
|
+
const args = this._buildInstallArgs({ production, frozenLockfile, preferOffline });
|
|
77
|
+
|
|
78
|
+
this.logger.info('Package manager install', {
|
|
79
|
+
manager: this.manager,
|
|
80
|
+
args: args.join(' '),
|
|
81
|
+
cwd: this.cwd
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return await this._execute(this.manager, args);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Add package(s) to project
|
|
89
|
+
* @param {string[]} packages - Package names to add
|
|
90
|
+
* @param {Object} options - Add options
|
|
91
|
+
* @param {boolean} [options.dev] - Add as devDependency
|
|
92
|
+
* @param {boolean} [options.peer] - Add as peerDependency
|
|
93
|
+
* @param {boolean} [options.optional] - Add as optionalDependency
|
|
94
|
+
* @param {boolean} [options.global] - Install globally
|
|
95
|
+
* @returns {Promise<string>} Command output
|
|
96
|
+
*/
|
|
97
|
+
async add(packages, options = {}) {
|
|
98
|
+
const { dev, peer, optional, global } = options;
|
|
99
|
+
|
|
100
|
+
const args = this._buildAddArgs(packages, { dev, peer, optional, global });
|
|
101
|
+
|
|
102
|
+
this.logger.info('Package manager add', {
|
|
103
|
+
manager: this.manager,
|
|
104
|
+
packages,
|
|
105
|
+
args: args.join(' '),
|
|
106
|
+
cwd: this.cwd
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return await this._execute(this.manager, args);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Remove package(s) from project
|
|
114
|
+
* @param {string[]} packages - Package names to remove
|
|
115
|
+
* @param {Object} options - Remove options
|
|
116
|
+
* @param {boolean} [options.global] - Remove from global install
|
|
117
|
+
* @returns {Promise<string>} Command output
|
|
118
|
+
*/
|
|
119
|
+
async remove(packages, options = {}) {
|
|
120
|
+
const { global } = options;
|
|
121
|
+
|
|
122
|
+
const args = this._buildRemoveArgs(packages, { global });
|
|
123
|
+
|
|
124
|
+
this.logger.info('Package manager remove', {
|
|
125
|
+
manager: this.manager,
|
|
126
|
+
packages,
|
|
127
|
+
args: args.join(' '),
|
|
128
|
+
cwd: this.cwd
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return await this._execute(this.manager, args);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Build install arguments for specific package manager
|
|
136
|
+
* @private
|
|
137
|
+
* @param {Object} options - Install options
|
|
138
|
+
* @returns {string[]} Command arguments
|
|
139
|
+
*/
|
|
140
|
+
_buildInstallArgs(options = {}) {
|
|
141
|
+
const { production, frozenLockfile, preferOffline } = options;
|
|
142
|
+
|
|
143
|
+
switch (this.manager) {
|
|
144
|
+
case 'npm':
|
|
145
|
+
return this._buildNpmInstallArgs({ production, frozenLockfile, preferOffline });
|
|
146
|
+
case 'yarn':
|
|
147
|
+
return this._buildYarnInstallArgs({ production, frozenLockfile, preferOffline });
|
|
148
|
+
case 'pnpm':
|
|
149
|
+
return this._buildPnpmInstallArgs({ production, frozenLockfile, preferOffline });
|
|
150
|
+
default:
|
|
151
|
+
throw new Error(`Unknown package manager: ${this.manager}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Build npm install arguments
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
_buildNpmInstallArgs(options = {}) {
|
|
160
|
+
const { production, frozenLockfile, preferOffline } = options;
|
|
161
|
+
const args = ['install'];
|
|
162
|
+
|
|
163
|
+
if (production) args.push('--production');
|
|
164
|
+
if (frozenLockfile) args.push('--frozen-lockfile');
|
|
165
|
+
if (preferOffline) args.push('--prefer-offline');
|
|
166
|
+
|
|
167
|
+
return args.filter(Boolean);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Build yarn install arguments
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
_buildYarnInstallArgs(options = {}) {
|
|
175
|
+
const { production, frozenLockfile, preferOffline } = options;
|
|
176
|
+
const args = ['install'];
|
|
177
|
+
|
|
178
|
+
if (production) args.push('--production');
|
|
179
|
+
if (frozenLockfile) args.push('--frozen-lockfile');
|
|
180
|
+
if (preferOffline) args.push('--prefer-offline');
|
|
181
|
+
|
|
182
|
+
return args.filter(Boolean);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Build pnpm install arguments
|
|
187
|
+
* @private
|
|
188
|
+
*/
|
|
189
|
+
_buildPnpmInstallArgs(options = {}) {
|
|
190
|
+
const { production, frozenLockfile, preferOffline } = options;
|
|
191
|
+
const args = ['install'];
|
|
192
|
+
|
|
193
|
+
if (production) args.push('--prod');
|
|
194
|
+
if (frozenLockfile) args.push('--frozen-lockfile');
|
|
195
|
+
if (preferOffline) args.push('--prefer-offline');
|
|
196
|
+
|
|
197
|
+
return args.filter(Boolean);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Build add arguments for specific package manager
|
|
202
|
+
* @private
|
|
203
|
+
* @param {string[]} packages - Package names
|
|
204
|
+
* @param {Object} options - Add options
|
|
205
|
+
* @returns {string[]} Command arguments
|
|
206
|
+
*/
|
|
207
|
+
_buildAddArgs(packages, options = {}) {
|
|
208
|
+
switch (this.manager) {
|
|
209
|
+
case 'npm':
|
|
210
|
+
return this._buildNpmAddArgs(packages, options);
|
|
211
|
+
case 'yarn':
|
|
212
|
+
return this._buildYarnAddArgs(packages, options);
|
|
213
|
+
case 'pnpm':
|
|
214
|
+
return this._buildPnpmAddArgs(packages, options);
|
|
215
|
+
default:
|
|
216
|
+
throw new Error(`Unknown package manager: ${this.manager}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Build npm add arguments
|
|
222
|
+
* @private
|
|
223
|
+
*/
|
|
224
|
+
_buildNpmAddArgs(packages, options = {}) {
|
|
225
|
+
const { dev, peer, optional, global } = options;
|
|
226
|
+
const args = ['install'];
|
|
227
|
+
|
|
228
|
+
if (global) args.push('-g');
|
|
229
|
+
if (dev) args.push('--save-dev');
|
|
230
|
+
if (peer) args.push('--save-peer');
|
|
231
|
+
if (optional) args.push('--save-optional');
|
|
232
|
+
|
|
233
|
+
return [...args, ...packages];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Build yarn add arguments
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
240
|
+
_buildYarnAddArgs(packages, options = {}) {
|
|
241
|
+
const { dev, peer, optional, global } = options;
|
|
242
|
+
const args = ['add'];
|
|
243
|
+
|
|
244
|
+
if (global) args.push('global');
|
|
245
|
+
if (dev) args.push('--dev');
|
|
246
|
+
if (peer) args.push('--peer');
|
|
247
|
+
if (optional) args.push('--optional');
|
|
248
|
+
|
|
249
|
+
return [...args, ...packages];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Build pnpm add arguments
|
|
254
|
+
* @private
|
|
255
|
+
*/
|
|
256
|
+
_buildPnpmAddArgs(packages, options = {}) {
|
|
257
|
+
const { dev, peer, optional, global } = options;
|
|
258
|
+
const args = ['add'];
|
|
259
|
+
|
|
260
|
+
if (global) args.push('-g');
|
|
261
|
+
if (dev) args.push('--save-dev');
|
|
262
|
+
if (peer) args.push('--save-peer');
|
|
263
|
+
if (optional) args.push('--save-optional');
|
|
264
|
+
|
|
265
|
+
return [...args, ...packages];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Build remove arguments for specific package manager
|
|
270
|
+
* @private
|
|
271
|
+
* @param {string[]} packages - Package names
|
|
272
|
+
* @param {Object} options - Remove options
|
|
273
|
+
* @returns {string[]} Command arguments
|
|
274
|
+
*/
|
|
275
|
+
_buildRemoveArgs(packages, options = {}) {
|
|
276
|
+
switch (this.manager) {
|
|
277
|
+
case 'npm':
|
|
278
|
+
return this._buildNpmRemoveArgs(packages, options);
|
|
279
|
+
case 'yarn':
|
|
280
|
+
return this._buildYarnRemoveArgs(packages, options);
|
|
281
|
+
case 'pnpm':
|
|
282
|
+
return this._buildPnpmRemoveArgs(packages, options);
|
|
283
|
+
default:
|
|
284
|
+
throw new Error(`Unknown package manager: ${this.manager}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Build npm remove arguments
|
|
290
|
+
* @private
|
|
291
|
+
*/
|
|
292
|
+
_buildNpmRemoveArgs(packages, options = {}) {
|
|
293
|
+
const { global } = options;
|
|
294
|
+
const args = ['uninstall'];
|
|
295
|
+
|
|
296
|
+
if (global) args.push('-g');
|
|
297
|
+
|
|
298
|
+
return [...args, ...packages];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Build yarn remove arguments
|
|
303
|
+
* @private
|
|
304
|
+
*/
|
|
305
|
+
_buildYarnRemoveArgs(packages, options = {}) {
|
|
306
|
+
const { global } = options;
|
|
307
|
+
const args = ['remove'];
|
|
308
|
+
|
|
309
|
+
if (global) args.push('global');
|
|
310
|
+
|
|
311
|
+
return [...args, ...packages];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Build pnpm remove arguments
|
|
316
|
+
* @private
|
|
317
|
+
*/
|
|
318
|
+
_buildPnpmRemoveArgs(packages, options = {}) {
|
|
319
|
+
const { global } = options;
|
|
320
|
+
const args = ['remove'];
|
|
321
|
+
|
|
322
|
+
if (global) args.push('-g');
|
|
323
|
+
|
|
324
|
+
return [...args, ...packages];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Execute command with cross-platform compatibility
|
|
329
|
+
* @private
|
|
330
|
+
* @param {string} cmd - Command to execute
|
|
331
|
+
* @param {string[]} args - Command arguments
|
|
332
|
+
* @returns {Promise<string>} Command output
|
|
333
|
+
*/
|
|
334
|
+
async _execute(cmd, args) {
|
|
335
|
+
const startTime = Date.now();
|
|
336
|
+
|
|
337
|
+
this.logger.debug('Package manager command start', {
|
|
338
|
+
manager: this.manager,
|
|
339
|
+
cmd,
|
|
340
|
+
args: args.join(' '),
|
|
341
|
+
cwd: this.cwd
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
try {
|
|
345
|
+
const result = await execFileAsync(cmd, args, {
|
|
346
|
+
cwd: this.cwd,
|
|
347
|
+
shell: false, // Use execFile for security (no shell injection)
|
|
348
|
+
maxBuffer: this.maxBuffer,
|
|
349
|
+
timeout: this.timeout
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
const duration = Date.now() - startTime;
|
|
353
|
+
this.logger.debug('Package manager command completed', {
|
|
354
|
+
manager: this.manager,
|
|
355
|
+
duration,
|
|
356
|
+
stdout_length: result.stdout?.length || 0
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
return result.stdout.trim();
|
|
360
|
+
} catch (err) {
|
|
361
|
+
const duration = Date.now() - startTime;
|
|
362
|
+
this.logger.error('Package manager command failed', {
|
|
363
|
+
manager: this.manager,
|
|
364
|
+
cmd,
|
|
365
|
+
args: args.join(' '),
|
|
366
|
+
duration,
|
|
367
|
+
error: err.message,
|
|
368
|
+
stderr: err.stderr?.trim(),
|
|
369
|
+
stdout: err.stdout?.trim()
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
throw new PackageManagerError({
|
|
373
|
+
manager: this.manager,
|
|
374
|
+
cmd,
|
|
375
|
+
args,
|
|
376
|
+
error: err.message,
|
|
377
|
+
stderr: err.stderr?.trim(),
|
|
378
|
+
stdout: err.stdout?.trim()
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
module.exports = PackageManagerExecutor;
|
|
385
|
+
module.exports.PackageManagerError = PackageManagerError;
|