mustard-claude 2.0.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 +198 -0
- package/bin/mustard.js +5 -0
- package/dist/analyzers/llm.d.ts +13 -0
- package/dist/analyzers/llm.js +339 -0
- package/dist/analyzers/llm.js.map +1 -0
- package/dist/analyzers/semantic.d.ts +13 -0
- package/dist/analyzers/semantic.js +215 -0
- package/dist/analyzers/semantic.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +42 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.js +377 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/sync.d.ts +5 -0
- package/dist/commands/sync.js +235 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/commands/update.d.ts +8 -0
- package/dist/commands/update.js +237 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/generators/claude-md-llm.d.ts +5 -0
- package/dist/generators/claude-md-llm.js +101 -0
- package/dist/generators/claude-md-llm.js.map +1 -0
- package/dist/generators/claude-md-template.d.ts +5 -0
- package/dist/generators/claude-md-template.js +273 -0
- package/dist/generators/claude-md-template.js.map +1 -0
- package/dist/generators/commands.d.ts +17 -0
- package/dist/generators/commands.js +845 -0
- package/dist/generators/commands.js.map +1 -0
- package/dist/generators/context.d.ts +11 -0
- package/dist/generators/context.js +621 -0
- package/dist/generators/context.js.map +1 -0
- package/dist/generators/hooks.d.ts +5 -0
- package/dist/generators/hooks.js +128 -0
- package/dist/generators/hooks.js.map +1 -0
- package/dist/generators/index.d.ts +11 -0
- package/dist/generators/index.js +541 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/prompts.d.ts +13 -0
- package/dist/generators/prompts.js +579 -0
- package/dist/generators/prompts.js.map +1 -0
- package/dist/generators/registry.d.ts +5 -0
- package/dist/generators/registry.js +93 -0
- package/dist/generators/registry.js.map +1 -0
- package/dist/scanners/dependencies.d.ts +7 -0
- package/dist/scanners/dependencies.js +195 -0
- package/dist/scanners/dependencies.js.map +1 -0
- package/dist/scanners/index.d.ts +6 -0
- package/dist/scanners/index.js +37 -0
- package/dist/scanners/index.js.map +1 -0
- package/dist/scanners/samples.d.ts +8 -0
- package/dist/scanners/samples.js +193 -0
- package/dist/scanners/samples.js.map +1 -0
- package/dist/scanners/stack.d.ts +5 -0
- package/dist/scanners/stack.js +294 -0
- package/dist/scanners/stack.js.map +1 -0
- package/dist/scanners/structure.d.ts +5 -0
- package/dist/scanners/structure.js +274 -0
- package/dist/scanners/structure.js.map +1 -0
- package/dist/services/grepai.d.ts +25 -0
- package/dist/services/grepai.js +89 -0
- package/dist/services/grepai.js.map +1 -0
- package/dist/services/ollama.d.ts +22 -0
- package/dist/services/ollama.js +86 -0
- package/dist/services/ollama.js.map +1 -0
- package/dist/services/package-manager.d.ts +95 -0
- package/dist/services/package-manager.js +164 -0
- package/dist/services/package-manager.js.map +1 -0
- package/dist/types.d.ts +233 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
/**
|
|
3
|
+
* Check if grepai CLI is available
|
|
4
|
+
*/
|
|
5
|
+
export async function checkGrepaiAvailable() {
|
|
6
|
+
try {
|
|
7
|
+
execSync('grepai --version', { stdio: 'pipe' });
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get grepai index status
|
|
16
|
+
*/
|
|
17
|
+
export async function indexStatus() {
|
|
18
|
+
try {
|
|
19
|
+
const result = execSync('grepai index-status --format json', {
|
|
20
|
+
encoding: 'utf-8',
|
|
21
|
+
maxBuffer: 10 * 1024 * 1024
|
|
22
|
+
});
|
|
23
|
+
return JSON.parse(result);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Search using grepai semantic search
|
|
31
|
+
*/
|
|
32
|
+
export async function search(query, options = {}) {
|
|
33
|
+
const { limit = 10, format = 'json', compact = false } = options;
|
|
34
|
+
try {
|
|
35
|
+
const compactFlag = compact ? '--compact' : '';
|
|
36
|
+
const result = execSync(`grepai search "${query}" --limit ${limit} --format ${format} ${compactFlag}`, {
|
|
37
|
+
encoding: 'utf-8',
|
|
38
|
+
maxBuffer: 10 * 1024 * 1024
|
|
39
|
+
});
|
|
40
|
+
return JSON.parse(result);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
44
|
+
console.error('grepai search failed:', message);
|
|
45
|
+
return { results: [] };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Find all functions that call the specified symbol
|
|
50
|
+
*/
|
|
51
|
+
export async function traceCallers(symbol, options = {}) {
|
|
52
|
+
const { format = 'json', compact = false } = options;
|
|
53
|
+
try {
|
|
54
|
+
const compactFlag = compact ? '--compact' : '';
|
|
55
|
+
const result = execSync(`grepai trace-callers "${symbol}" --format ${format} ${compactFlag}`, { encoding: 'utf-8' });
|
|
56
|
+
return JSON.parse(result);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return { callers: [] };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Find all functions called by the specified symbol
|
|
64
|
+
*/
|
|
65
|
+
export async function traceCallees(symbol, options = {}) {
|
|
66
|
+
const { format = 'json', compact = false } = options;
|
|
67
|
+
try {
|
|
68
|
+
const compactFlag = compact ? '--compact' : '';
|
|
69
|
+
const result = execSync(`grepai trace-callees "${symbol}" --format ${format} ${compactFlag}`, { encoding: 'utf-8' });
|
|
70
|
+
return JSON.parse(result);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return { callees: [] };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build a complete call graph around a symbol
|
|
78
|
+
*/
|
|
79
|
+
export async function traceGraph(symbol, options = {}) {
|
|
80
|
+
const { format = 'json', depth = 2 } = options;
|
|
81
|
+
try {
|
|
82
|
+
const result = execSync(`grepai trace-graph "${symbol}" --depth ${depth} --format ${format}`, { encoding: 'utf-8' });
|
|
83
|
+
return JSON.parse(result);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return { graph: {} };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=grepai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grepai.js","sourceRoot":"","sources":["../../src/services/grepai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,CAAC;QACH,QAAQ,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,CAAC,mCAAmC,EAAE;YAC3D,QAAQ,EAAE,OAAO;YACjB,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;SAC5B,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAA4B,CAAC;IACvD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAa,EAAE,UAAyB,EAAE;IACrE,MA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,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc,EAAE,UAAwB,EAAE;IAC3E,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAErD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,MAAM,MAAM,GAAG,QAAQ,CACrB,yBAAyB,MAAM,cAAc,MAAM,IAAI,WAAW,EAAE,EACpE,EAAE,QAAQ,EAAE,OAAO,EAAE,CACtB,CAAC;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAgB,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAc,EAAE,UAAwB,EAAE;IACzE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAE/C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,CACrB,uBAAuB,MAAM,aAAa,KAAK,aAAa,MAAM,EAAE,EACpE,EAAE,QAAQ,EAAE,OAAO,EAAE,CACtB,CAAC;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAgB,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OllamaOptions } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if Ollama is available and running
|
|
4
|
+
*/
|
|
5
|
+
export declare function checkOllamaAvailable(): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* Get list of available models
|
|
8
|
+
*/
|
|
9
|
+
export declare function getAvailableModels(): Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Select the best available model
|
|
12
|
+
* Preference: llama3.2 > codellama > mistral > qwen > any
|
|
13
|
+
*/
|
|
14
|
+
export declare function selectBestModel(models: string[]): Promise<string | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Generate text using Ollama
|
|
17
|
+
*/
|
|
18
|
+
export declare function generate(prompt: string, options?: OllamaOptions): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Generate JSON using Ollama
|
|
21
|
+
*/
|
|
22
|
+
export declare function generateJSON<T = unknown>(prompt: string, options?: OllamaOptions): Promise<T>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Ollama } from 'ollama';
|
|
2
|
+
let ollamaClient = null;
|
|
3
|
+
/**
|
|
4
|
+
* Get or create Ollama client
|
|
5
|
+
*/
|
|
6
|
+
function getClient() {
|
|
7
|
+
if (!ollamaClient) {
|
|
8
|
+
ollamaClient = new Ollama({ host: 'http://localhost:11434' });
|
|
9
|
+
}
|
|
10
|
+
return ollamaClient;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Check if Ollama is available and running
|
|
14
|
+
*/
|
|
15
|
+
export async function checkOllamaAvailable() {
|
|
16
|
+
try {
|
|
17
|
+
const client = getClient();
|
|
18
|
+
await client.list();
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get list of available models
|
|
27
|
+
*/
|
|
28
|
+
export async function getAvailableModels() {
|
|
29
|
+
try {
|
|
30
|
+
const client = getClient();
|
|
31
|
+
const { models } = await client.list();
|
|
32
|
+
return models.map(m => m.name);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Select the best available model
|
|
40
|
+
* Preference: llama3.2 > codellama > mistral > qwen > any
|
|
41
|
+
*/
|
|
42
|
+
export async function selectBestModel(models) {
|
|
43
|
+
const preferred = ['llama3.2', 'llama3.1', 'codellama', 'mistral', 'qwen', 'deepseek'];
|
|
44
|
+
for (const name of preferred) {
|
|
45
|
+
const found = models.find(m => m.toLowerCase().includes(name));
|
|
46
|
+
if (found)
|
|
47
|
+
return found;
|
|
48
|
+
}
|
|
49
|
+
return models[0] ?? null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Wrap a promise with a timeout
|
|
53
|
+
*/
|
|
54
|
+
function withTimeout(promise, ms, label) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
const timer = setTimeout(() => reject(new Error(`Ollama timeout after ${ms / 1000}s: ${label}`)), ms);
|
|
57
|
+
promise.then((val) => { clearTimeout(timer); resolve(val); }, (err) => { clearTimeout(timer); reject(err); });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generate text using Ollama
|
|
62
|
+
*/
|
|
63
|
+
export async function generate(prompt, options = {}) {
|
|
64
|
+
const client = getClient();
|
|
65
|
+
const { model = 'llama3.2', format, timeout = 60000 } = options;
|
|
66
|
+
const response = await withTimeout(client.generate({ model, prompt, format, stream: false }), timeout, `generate(${model})`);
|
|
67
|
+
return response.response;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Generate JSON using Ollama
|
|
71
|
+
*/
|
|
72
|
+
export async function generateJSON(prompt, options = {}) {
|
|
73
|
+
const response = await generate(prompt, { ...options, format: 'json' });
|
|
74
|
+
try {
|
|
75
|
+
return JSON.parse(response);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Try to extract JSON from response
|
|
79
|
+
const match = response.match(/\{[\s\S]*\}/);
|
|
80
|
+
if (match) {
|
|
81
|
+
return JSON.parse(match[0]);
|
|
82
|
+
}
|
|
83
|
+
throw new Error('Failed to parse JSON from Ollama response');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=ollama.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.js","sourceRoot":"","sources":["../../src/services/ollama.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,IAAI,YAAY,GAAkB,IAAI,CAAC;AAEvC;;GAEG;AACH,SAAS,SAAS;IAChB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAgB;IACpD,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EA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,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EACzD,OAAO,EACP,YAAY,KAAK,GAAG,CACrB,CAAC;IAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAc,MAAc,EAAE,UAAyB,EAAE;IACzF,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAExE,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAM,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,oCAAoC;QACpC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC5C,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAM,CAAC;QACnC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package Manager Service
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for working with different JavaScript package managers.
|
|
5
|
+
* Supports npm, yarn, pnpm, and bun with their respective command differences.
|
|
6
|
+
*/
|
|
7
|
+
export type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';
|
|
8
|
+
export interface PackageManagerConfig {
|
|
9
|
+
run: (script: string) => string;
|
|
10
|
+
install: string;
|
|
11
|
+
installDev: string;
|
|
12
|
+
exec: string;
|
|
13
|
+
add: (pkg: string) => string;
|
|
14
|
+
addDev: (pkg: string) => string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the full configuration for a package manager
|
|
18
|
+
*/
|
|
19
|
+
export declare function getConfig(pm: string): PackageManagerConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Get the command to run a script
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* getRunCommand('npm', 'build') // 'npm run build'
|
|
25
|
+
* getRunCommand('yarn', 'build') // 'yarn build'
|
|
26
|
+
* getRunCommand('pnpm', 'build') // 'pnpm build'
|
|
27
|
+
* getRunCommand('bun', 'build') // 'bun run build'
|
|
28
|
+
*/
|
|
29
|
+
export declare function getRunCommand(pm: string, script: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get the command to install all dependencies
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* getInstallCommand('npm') // 'npm install'
|
|
35
|
+
* getInstallCommand('yarn') // 'yarn'
|
|
36
|
+
* getInstallCommand('pnpm') // 'pnpm install'
|
|
37
|
+
* getInstallCommand('bun') // 'bun install'
|
|
38
|
+
*/
|
|
39
|
+
export declare function getInstallCommand(pm: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get the command to execute a binary (like npx)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* getExecCommand('npm') // 'npx'
|
|
45
|
+
* getExecCommand('yarn') // 'yarn exec'
|
|
46
|
+
* getExecCommand('pnpm') // 'pnpm exec'
|
|
47
|
+
* getExecCommand('bun') // 'bunx'
|
|
48
|
+
*/
|
|
49
|
+
export declare function getExecCommand(pm: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Get the command to add a package
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* getAddCommand('npm', 'lodash') // 'npm install lodash'
|
|
55
|
+
* getAddCommand('npm', 'typescript', true) // 'npm install --save-dev typescript'
|
|
56
|
+
* getAddCommand('yarn', 'lodash') // 'yarn add lodash'
|
|
57
|
+
* getAddCommand('yarn', 'typescript', true) // 'yarn add --dev typescript'
|
|
58
|
+
*/
|
|
59
|
+
export declare function getAddCommand(pm: string, pkg: string, dev?: boolean): string;
|
|
60
|
+
/**
|
|
61
|
+
* Check if the package manager can omit "run" for scripts
|
|
62
|
+
*
|
|
63
|
+
* yarn and pnpm allow running scripts without "run":
|
|
64
|
+
* yarn build (instead of yarn run build)
|
|
65
|
+
* pnpm build (instead of pnpm run build)
|
|
66
|
+
*
|
|
67
|
+
* npm and bun require "run":
|
|
68
|
+
* npm run build
|
|
69
|
+
* bun run build
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* canOmitRun('yarn') // true
|
|
73
|
+
* canOmitRun('pnpm') // true
|
|
74
|
+
* canOmitRun('npm') // false
|
|
75
|
+
* canOmitRun('bun') // false
|
|
76
|
+
*/
|
|
77
|
+
export declare function canOmitRun(pm: string): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Get the display name for a package manager
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* getDisplayName('npm') // 'npm'
|
|
83
|
+
* getDisplayName('yarn') // 'Yarn'
|
|
84
|
+
* getDisplayName('pnpm') // 'pnpm'
|
|
85
|
+
* getDisplayName('bun') // 'Bun'
|
|
86
|
+
*/
|
|
87
|
+
export declare function getDisplayName(pm: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Check if a string is a valid package manager
|
|
90
|
+
*/
|
|
91
|
+
export declare function isValidPackageManager(pm: string): pm is PackageManager;
|
|
92
|
+
/**
|
|
93
|
+
* Get all supported package managers
|
|
94
|
+
*/
|
|
95
|
+
export declare function getSupportedPackageManagers(): PackageManager[];
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package Manager Service
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for working with different JavaScript package managers.
|
|
5
|
+
* Supports npm, yarn, pnpm, and bun with their respective command differences.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for each package manager
|
|
9
|
+
*/
|
|
10
|
+
const configs = {
|
|
11
|
+
npm: {
|
|
12
|
+
run: (script) => `npm run ${script}`,
|
|
13
|
+
install: 'npm install',
|
|
14
|
+
installDev: 'npm install --save-dev',
|
|
15
|
+
exec: 'npx',
|
|
16
|
+
add: (pkg) => `npm install ${pkg}`,
|
|
17
|
+
addDev: (pkg) => `npm install --save-dev ${pkg}`,
|
|
18
|
+
},
|
|
19
|
+
yarn: {
|
|
20
|
+
run: (script) => `yarn ${script}`,
|
|
21
|
+
install: 'yarn',
|
|
22
|
+
installDev: 'yarn add --dev',
|
|
23
|
+
exec: 'yarn exec',
|
|
24
|
+
add: (pkg) => `yarn add ${pkg}`,
|
|
25
|
+
addDev: (pkg) => `yarn add --dev ${pkg}`,
|
|
26
|
+
},
|
|
27
|
+
pnpm: {
|
|
28
|
+
run: (script) => `pnpm ${script}`,
|
|
29
|
+
install: 'pnpm install',
|
|
30
|
+
installDev: 'pnpm add --save-dev',
|
|
31
|
+
exec: 'pnpm exec',
|
|
32
|
+
add: (pkg) => `pnpm add ${pkg}`,
|
|
33
|
+
addDev: (pkg) => `pnpm add --save-dev ${pkg}`,
|
|
34
|
+
},
|
|
35
|
+
bun: {
|
|
36
|
+
run: (script) => `bun run ${script}`,
|
|
37
|
+
install: 'bun install',
|
|
38
|
+
installDev: 'bun add --dev',
|
|
39
|
+
exec: 'bunx',
|
|
40
|
+
add: (pkg) => `bun add ${pkg}`,
|
|
41
|
+
addDev: (pkg) => `bun add --dev ${pkg}`,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Display names for each package manager
|
|
46
|
+
*/
|
|
47
|
+
const displayNames = {
|
|
48
|
+
npm: 'npm',
|
|
49
|
+
yarn: 'Yarn',
|
|
50
|
+
pnpm: 'pnpm',
|
|
51
|
+
bun: 'Bun',
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Validate and normalize package manager string
|
|
55
|
+
*/
|
|
56
|
+
function normalizePackageManager(pm) {
|
|
57
|
+
const normalized = pm.toLowerCase();
|
|
58
|
+
if (normalized in configs) {
|
|
59
|
+
return normalized;
|
|
60
|
+
}
|
|
61
|
+
// Default to npm for unknown package managers
|
|
62
|
+
return 'npm';
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the full configuration for a package manager
|
|
66
|
+
*/
|
|
67
|
+
export function getConfig(pm) {
|
|
68
|
+
return configs[normalizePackageManager(pm)];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the command to run a script
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* getRunCommand('npm', 'build') // 'npm run build'
|
|
75
|
+
* getRunCommand('yarn', 'build') // 'yarn build'
|
|
76
|
+
* getRunCommand('pnpm', 'build') // 'pnpm build'
|
|
77
|
+
* getRunCommand('bun', 'build') // 'bun run build'
|
|
78
|
+
*/
|
|
79
|
+
export function getRunCommand(pm, script) {
|
|
80
|
+
return configs[normalizePackageManager(pm)].run(script);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the command to install all dependencies
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* getInstallCommand('npm') // 'npm install'
|
|
87
|
+
* getInstallCommand('yarn') // 'yarn'
|
|
88
|
+
* getInstallCommand('pnpm') // 'pnpm install'
|
|
89
|
+
* getInstallCommand('bun') // 'bun install'
|
|
90
|
+
*/
|
|
91
|
+
export function getInstallCommand(pm) {
|
|
92
|
+
return configs[normalizePackageManager(pm)].install;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the command to execute a binary (like npx)
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* getExecCommand('npm') // 'npx'
|
|
99
|
+
* getExecCommand('yarn') // 'yarn exec'
|
|
100
|
+
* getExecCommand('pnpm') // 'pnpm exec'
|
|
101
|
+
* getExecCommand('bun') // 'bunx'
|
|
102
|
+
*/
|
|
103
|
+
export function getExecCommand(pm) {
|
|
104
|
+
return configs[normalizePackageManager(pm)].exec;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the command to add a package
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* getAddCommand('npm', 'lodash') // 'npm install lodash'
|
|
111
|
+
* getAddCommand('npm', 'typescript', true) // 'npm install --save-dev typescript'
|
|
112
|
+
* getAddCommand('yarn', 'lodash') // 'yarn add lodash'
|
|
113
|
+
* getAddCommand('yarn', 'typescript', true) // 'yarn add --dev typescript'
|
|
114
|
+
*/
|
|
115
|
+
export function getAddCommand(pm, pkg, dev = false) {
|
|
116
|
+
const config = configs[normalizePackageManager(pm)];
|
|
117
|
+
return dev ? config.addDev(pkg) : config.add(pkg);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if the package manager can omit "run" for scripts
|
|
121
|
+
*
|
|
122
|
+
* yarn and pnpm allow running scripts without "run":
|
|
123
|
+
* yarn build (instead of yarn run build)
|
|
124
|
+
* pnpm build (instead of pnpm run build)
|
|
125
|
+
*
|
|
126
|
+
* npm and bun require "run":
|
|
127
|
+
* npm run build
|
|
128
|
+
* bun run build
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* canOmitRun('yarn') // true
|
|
132
|
+
* canOmitRun('pnpm') // true
|
|
133
|
+
* canOmitRun('npm') // false
|
|
134
|
+
* canOmitRun('bun') // false
|
|
135
|
+
*/
|
|
136
|
+
export function canOmitRun(pm) {
|
|
137
|
+
const normalized = normalizePackageManager(pm);
|
|
138
|
+
return normalized === 'yarn' || normalized === 'pnpm';
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get the display name for a package manager
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* getDisplayName('npm') // 'npm'
|
|
145
|
+
* getDisplayName('yarn') // 'Yarn'
|
|
146
|
+
* getDisplayName('pnpm') // 'pnpm'
|
|
147
|
+
* getDisplayName('bun') // 'Bun'
|
|
148
|
+
*/
|
|
149
|
+
export function getDisplayName(pm) {
|
|
150
|
+
return displayNames[normalizePackageManager(pm)];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Check if a string is a valid package manager
|
|
154
|
+
*/
|
|
155
|
+
export function isValidPackageManager(pm) {
|
|
156
|
+
return pm.toLowerCase() in configs;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get all supported package managers
|
|
160
|
+
*/
|
|
161
|
+
export function getSupportedPackageManagers() {
|
|
162
|
+
return Object.keys(configs);
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=package-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../../src/services/package-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH;;GAEG;AACH,MAAM,OAAO,GAAiD;IAC5D,GAAG,EAAE;QACH,GAAG,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,WAAW,MAAM,EAAE;QAC5C,OAAO,EAAE,aAAa;QACtB,UAAU,EAAE,wBAAwB;QACpC,IAAI,EAAE,KAAK;QACX,GAAG,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,eAAe,GAAG,EAAE;QAC1C,MAAM,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,0BAA0B,GAAG,EAAE;KACzD;IACD,IAAI,EAAE;QACJ,GAAG,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,QAAQ,MAAM,EAAE;QACzC,OAAO,EAAE,MAAM;QACf,UAAU,EAAE,gBAAgB;QAC5B,IAAI,EAAE,WAAW;QACjB,GAAG,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,YAAY,GAAG,EAAE;QACvC,MAAM,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,kBAAkB,GAAG,EAAE;KACjD;IACD,IAAI,EAAE;QACJ,GAAG,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,QAAQ,MAAM,EAAE;QACzC,OAAO,EAAE,cAAc;QACvB,UAAU,EAAE,qBAAqB;QACjC,IAAI,EAAE,WAAW;QACjB,GAAG,EAAE,CAAC,GAAW,EAAE,E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