poe-code 3.0.398 → 3.0.399
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/cli/commands/update.d.ts +11 -0
- package/dist/cli/commands/update.js +58 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/program.js +3 -0
- package/dist/cli/program.js.map +1 -1
- package/dist/index.js +250 -48
- package/dist/index.js.map +4 -4
- package/dist/metafile.json +1 -1
- package/dist/services/update.d.ts +30 -0
- package/dist/services/update.js +113 -0
- package/dist/services/update.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HttpClient } from "../cli/http.js";
|
|
2
|
+
import type { CommandRunner } from "../utils/command-checks.js";
|
|
3
|
+
import { type VersionCheckResult } from "./version.js";
|
|
4
|
+
export type PoeCodePackageManager = "npm" | "bun" | "pnpm" | "yarn";
|
|
5
|
+
export interface PoeCodeUpdatePlan {
|
|
6
|
+
packageManager: PoeCodePackageManager;
|
|
7
|
+
command: string;
|
|
8
|
+
args: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface UpdatePoeCodeOptions {
|
|
11
|
+
currentVersion: string;
|
|
12
|
+
httpClient: HttpClient;
|
|
13
|
+
runCommand: CommandRunner;
|
|
14
|
+
env: Record<string, string | undefined>;
|
|
15
|
+
packageManager?: PoeCodePackageManager;
|
|
16
|
+
force?: boolean;
|
|
17
|
+
checkVersion?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface PoeCodeUpdateResult {
|
|
20
|
+
status: "current" | "updated";
|
|
21
|
+
plan: PoeCodeUpdatePlan;
|
|
22
|
+
version: VersionCheckResult | null;
|
|
23
|
+
}
|
|
24
|
+
export declare function detectPoeCodePackageManager(env: Record<string, string | undefined>): PoeCodePackageManager;
|
|
25
|
+
export declare function createPoeCodeUpdatePlan(options: {
|
|
26
|
+
packageManager?: PoeCodePackageManager;
|
|
27
|
+
env?: Record<string, string | undefined>;
|
|
28
|
+
}): PoeCodeUpdatePlan;
|
|
29
|
+
export declare function updatePoeCode(options: UpdatePoeCodeOptions): Promise<PoeCodeUpdateResult>;
|
|
30
|
+
export declare function formatPoeCodeUpdateCommand(plan: PoeCodeUpdatePlan): string;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { formatCommandRunnerResult } from "../utils/command-checks.js";
|
|
2
|
+
import { checkForUpdate } from "./version.js";
|
|
3
|
+
const POE_CODE_PACKAGE = "poe-code@latest";
|
|
4
|
+
export function detectPoeCodePackageManager(env) {
|
|
5
|
+
const userAgent = env.npm_config_user_agent ?? "";
|
|
6
|
+
const userAgentManager = userAgent.split(" ")[0]?.split("/")[0];
|
|
7
|
+
const normalizedUserAgentManager = normalizePackageManager(userAgentManager);
|
|
8
|
+
if (normalizedUserAgentManager) {
|
|
9
|
+
return normalizedUserAgentManager;
|
|
10
|
+
}
|
|
11
|
+
const execPath = env.npm_execpath ?? "";
|
|
12
|
+
const execPathManager = detectPackageManagerFromPath(execPath);
|
|
13
|
+
return execPathManager ?? "npm";
|
|
14
|
+
}
|
|
15
|
+
export function createPoeCodeUpdatePlan(options) {
|
|
16
|
+
const packageManager = options.packageManager ?? detectPoeCodePackageManager(options.env ?? {});
|
|
17
|
+
if (packageManager === "bun") {
|
|
18
|
+
return {
|
|
19
|
+
packageManager,
|
|
20
|
+
command: "bun",
|
|
21
|
+
args: ["install", "-g", POE_CODE_PACKAGE]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (packageManager === "pnpm") {
|
|
25
|
+
return {
|
|
26
|
+
packageManager,
|
|
27
|
+
command: "pnpm",
|
|
28
|
+
args: ["add", "-g", POE_CODE_PACKAGE]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (packageManager === "yarn") {
|
|
32
|
+
return {
|
|
33
|
+
packageManager,
|
|
34
|
+
command: "yarn",
|
|
35
|
+
args: ["global", "add", POE_CODE_PACKAGE]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
packageManager,
|
|
40
|
+
command: "npm",
|
|
41
|
+
args: ["install", "-g", POE_CODE_PACKAGE]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export async function updatePoeCode(options) {
|
|
45
|
+
const plan = createPoeCodeUpdatePlan({
|
|
46
|
+
packageManager: options.packageManager,
|
|
47
|
+
env: options.env
|
|
48
|
+
});
|
|
49
|
+
const shouldCheckVersion = options.checkVersion !== false;
|
|
50
|
+
const version = shouldCheckVersion
|
|
51
|
+
? await checkForUpdate({
|
|
52
|
+
currentVersion: options.currentVersion,
|
|
53
|
+
httpClient: options.httpClient
|
|
54
|
+
})
|
|
55
|
+
: null;
|
|
56
|
+
if (version && !version.updateAvailable && options.force !== true) {
|
|
57
|
+
return {
|
|
58
|
+
status: "current",
|
|
59
|
+
plan,
|
|
60
|
+
version
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const result = await options.runCommand(plan.command, plan.args);
|
|
64
|
+
if (result.exitCode !== 0) {
|
|
65
|
+
throw new Error([
|
|
66
|
+
`poe-code update failed with exit code ${result.exitCode}: ${formatPoeCodeUpdateCommand(plan)}`,
|
|
67
|
+
formatCommandRunnerResult(result)
|
|
68
|
+
].join("\n"));
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
status: "updated",
|
|
72
|
+
plan,
|
|
73
|
+
version
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export function formatPoeCodeUpdateCommand(plan) {
|
|
77
|
+
return [plan.command, ...plan.args].map(quoteCommandPart).join(" ");
|
|
78
|
+
}
|
|
79
|
+
function normalizePackageManager(value) {
|
|
80
|
+
if (value === "npm" || value === "bun" || value === "pnpm" || value === "yarn") {
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
function detectPackageManagerFromPath(value) {
|
|
86
|
+
const lower = value.toLowerCase();
|
|
87
|
+
if (lower.includes("bun")) {
|
|
88
|
+
return "bun";
|
|
89
|
+
}
|
|
90
|
+
if (lower.includes("pnpm")) {
|
|
91
|
+
return "pnpm";
|
|
92
|
+
}
|
|
93
|
+
if (lower.includes("yarn")) {
|
|
94
|
+
return "yarn";
|
|
95
|
+
}
|
|
96
|
+
if (lower.includes("npm")) {
|
|
97
|
+
return "npm";
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
function quoteCommandPart(value) {
|
|
102
|
+
if (value.length === 0) {
|
|
103
|
+
return '""';
|
|
104
|
+
}
|
|
105
|
+
if (!needsQuoting(value)) {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
return `"${value.replaceAll('"', '\\"')}"`;
|
|
109
|
+
}
|
|
110
|
+
function needsQuoting(value) {
|
|
111
|
+
return value.includes(" ") || value.includes("\t") || value.includes("\n");
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/services/update.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,cAAc,EAA2B,MAAM,cAAc,CAAC;AA0BvE,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,UAAU,2BAA2B,CACzC,GAAuC;IAEvC,MAAM,SAAS,GAAG,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC;IAClD,MAAM,gBAAgB,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,MAAM,0BAA0B,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;IAC7E,IAAI,0BAA0B,EAAE,CAAC;QAC/B,OAAO,0BAA0B,CAAC;IACpC,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAA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