@mearl/setup 2.2.2 → 2.3.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/dist/aliSkills.js +6 -22
- package/dist/process.d.ts +7 -0
- package/dist/process.js +31 -0
- package/package.json +1 -1
package/dist/aliSkills.js
CHANGED
|
@@ -2,33 +2,13 @@ import fs from 'node:fs';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { spawn } from 'node:child_process';
|
|
5
|
-
import { executableNames, findExecutable, isExecutable, prependCommandPath, prependNodePath, resolveSpawnCommand, runCommand, } from './process.js';
|
|
5
|
+
import { executableNames, findExecutable, isExecutable, prependCommandPath, prependNodePath, resolveSpawnCommand, runCommand, versionManagerExecutableCandidates, } from './process.js';
|
|
6
6
|
const COMMAND_TIMEOUT_MS = 120_000;
|
|
7
7
|
const MAX_OUTPUT_LENGTH = 1_000_000;
|
|
8
8
|
const ANSI_ESCAPE_PATTERN = new RegExp(String.raw `\u001B\[[0-?]*[ -/]*[@-~]`, 'g');
|
|
9
9
|
function existingExecutable(candidates, existsSync) {
|
|
10
10
|
return candidates.find(candidate => candidate && existsSync(candidate)) ?? null;
|
|
11
11
|
}
|
|
12
|
-
function versionManagerCandidates(home, executableNames, readdirSync) {
|
|
13
|
-
const roots = [
|
|
14
|
-
path.join(home, '.nvm', 'versions', 'node'),
|
|
15
|
-
path.join(home, '.fnm', 'node-versions'),
|
|
16
|
-
];
|
|
17
|
-
return roots.flatMap(root => {
|
|
18
|
-
try {
|
|
19
|
-
return readdirSync(root, { withFileTypes: true })
|
|
20
|
-
.filter(entry => entry.isDirectory())
|
|
21
|
-
.sort((left, right) => right.name.localeCompare(left.name, undefined, { numeric: true }))
|
|
22
|
-
.flatMap(entry => executableNames.flatMap(name => [
|
|
23
|
-
path.join(root, entry.name, 'bin', name),
|
|
24
|
-
path.join(root, entry.name, 'installation', 'bin', name),
|
|
25
|
-
]));
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
12
|
export function stripAnsi(value) {
|
|
33
13
|
return value.replace(ANSI_ESCAPE_PATTERN, '');
|
|
34
14
|
}
|
|
@@ -53,7 +33,11 @@ export function resolveAliSkillsExecutable(options = {}) {
|
|
|
53
33
|
...names.map(name => path.join(home, '.volta', 'bin', name)),
|
|
54
34
|
...names.map(name => path.join(home, '.local', 'share', 'pnpm', name)),
|
|
55
35
|
...names.map(name => path.join(home, 'Library', 'pnpm', name)),
|
|
56
|
-
...
|
|
36
|
+
...versionManagerExecutableCandidates(home, names, {
|
|
37
|
+
env,
|
|
38
|
+
platform,
|
|
39
|
+
readdirSync,
|
|
40
|
+
}),
|
|
57
41
|
...(platform === 'win32'
|
|
58
42
|
? []
|
|
59
43
|
: ['/opt/homebrew/bin/ali-skills', '/usr/local/bin/ali-skills', '/usr/bin/ali-skills']),
|
package/dist/process.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
export interface SpawnCommand {
|
|
2
3
|
command: string;
|
|
3
4
|
args: string[];
|
|
@@ -16,6 +17,12 @@ export interface RunCommandOptions {
|
|
|
16
17
|
export type CommandRunner = (command: string, args: string[], options?: RunCommandOptions) => Promise<CommandResult>;
|
|
17
18
|
export declare function isExecutable(filePath: string, platform?: NodeJS.Platform): boolean;
|
|
18
19
|
export declare function executableNames(name: string, platform?: NodeJS.Platform): string[];
|
|
20
|
+
export interface VersionManagerExecutableCandidateOptions {
|
|
21
|
+
env?: NodeJS.ProcessEnv;
|
|
22
|
+
platform?: NodeJS.Platform;
|
|
23
|
+
readdirSync?: typeof fs.readdirSync;
|
|
24
|
+
}
|
|
25
|
+
export declare function versionManagerExecutableCandidates(home: string, names: string[], options?: VersionManagerExecutableCandidateOptions): string[];
|
|
19
26
|
export declare function resolveSpawnCommand(executable: string, args: string[], platform?: NodeJS.Platform, commandInterpreter?: string | undefined): SpawnCommand;
|
|
20
27
|
export declare function prependCommandPath(command: string, env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
21
28
|
export declare function prependNodePath(env?: NodeJS.ProcessEnv, nodeExecutable?: string): NodeJS.ProcessEnv;
|
package/dist/process.js
CHANGED
|
@@ -14,6 +14,37 @@ export function isExecutable(filePath, platform = process.platform) {
|
|
|
14
14
|
export function executableNames(name, platform = process.platform) {
|
|
15
15
|
return platform === 'win32' ? [`${name}.cmd`, `${name}.exe`, name] : [name];
|
|
16
16
|
}
|
|
17
|
+
export function versionManagerExecutableCandidates(home, names, options = {}) {
|
|
18
|
+
const env = options.env ?? process.env;
|
|
19
|
+
const platform = options.platform ?? process.platform;
|
|
20
|
+
const readdirSync = options.readdirSync ?? fs.readdirSync;
|
|
21
|
+
const fnmDefaultRoot = env.XDG_DATA_HOME
|
|
22
|
+
? path.join(env.XDG_DATA_HOME, 'fnm')
|
|
23
|
+
: platform === 'darwin'
|
|
24
|
+
? path.join(home, 'Library', 'Application Support', 'fnm')
|
|
25
|
+
: platform === 'win32' && env.APPDATA
|
|
26
|
+
? path.join(env.APPDATA, 'fnm')
|
|
27
|
+
: path.join(home, '.local', 'share', 'fnm');
|
|
28
|
+
const roots = [
|
|
29
|
+
path.join(env.NVM_DIR || path.join(home, '.nvm'), 'versions', 'node'),
|
|
30
|
+
path.join(env.FNM_DIR || fnmDefaultRoot, 'node-versions'),
|
|
31
|
+
path.join(home, '.fnm', 'node-versions'),
|
|
32
|
+
].filter((root, index, all) => all.indexOf(root) === index);
|
|
33
|
+
return roots.flatMap(root => {
|
|
34
|
+
try {
|
|
35
|
+
return readdirSync(root, { withFileTypes: true })
|
|
36
|
+
.filter(entry => entry.isDirectory())
|
|
37
|
+
.sort((left, right) => right.name.localeCompare(left.name, undefined, { numeric: true }))
|
|
38
|
+
.flatMap(entry => names.flatMap(name => [
|
|
39
|
+
path.join(root, entry.name, 'bin', name),
|
|
40
|
+
path.join(root, entry.name, 'installation', 'bin', name),
|
|
41
|
+
]));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
17
48
|
export function resolveSpawnCommand(executable, args, platform = process.platform, commandInterpreter = process.env.ComSpec) {
|
|
18
49
|
if (platform === 'win32' && /\.(?:cmd|bat)$/i.test(executable)) {
|
|
19
50
|
return {
|