@trebired/code-server-kit 0.3.0 → 1.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/CHANGELOG.md +9 -0
- package/README.md +175 -208
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +150 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/errors.d.ts +5 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/plan.d.ts +3 -2
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +68 -68
- package/dist/plan.js.map +1 -1
- package/dist/preparation.d.ts +5 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +194 -0
- package/dist/preparation.js.map +1 -0
- package/dist/profile.d.ts +5 -2
- package/dist/profile.d.ts.map +1 -1
- package/dist/profile.js +122 -1
- package/dist/profile.js.map +1 -1
- package/dist/proxy.d.ts +4 -2
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +62 -1
- package/dist/proxy.js.map +1 -1
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js +43 -1
- package/dist/resolve.js.map +1 -1
- package/dist/session.d.ts +2 -2
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +416 -534
- package/dist/session.js.map +1 -1
- package/dist/spec.d.ts +3 -3
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js +2 -33
- package/dist/spec.js.map +1 -1
- package/dist/systemd.d.ts +5 -2
- package/dist/systemd.d.ts.map +1 -1
- package/dist/systemd.js +57 -6
- package/dist/systemd.js.map +1 -1
- package/dist/types.d.ts +215 -67
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { CodeServerPreparationError } from "./errors.js";
|
|
6
|
+
import { resolveLogger } from "./logging.js";
|
|
7
|
+
const preparationCache = new Map();
|
|
8
|
+
function getCodeServerPreparationStatus(options = {}) {
|
|
9
|
+
const packageJsonPath = resolveCodeServerPackageJsonPath(options.resolveFrom);
|
|
10
|
+
const packageRoot = path.dirname(packageJsonPath);
|
|
11
|
+
const cached = preparationCache.get(packageRoot);
|
|
12
|
+
if (cached) {
|
|
13
|
+
return cached;
|
|
14
|
+
}
|
|
15
|
+
const status = buildPreparationStatus(packageRoot, options.strictWatchdog ?? false);
|
|
16
|
+
preparationCache.set(packageRoot, status);
|
|
17
|
+
return status;
|
|
18
|
+
}
|
|
19
|
+
async function ensureCodeServerPrepared(options = {}) {
|
|
20
|
+
const log = resolveLogger(options.logger, options.loggerAdapter);
|
|
21
|
+
const packageJsonPath = resolveCodeServerPackageJsonPath(options.resolveFrom);
|
|
22
|
+
const packageRoot = path.dirname(packageJsonPath);
|
|
23
|
+
let status = buildPreparationStatus(packageRoot, options.strictWatchdog ?? false);
|
|
24
|
+
preparationCache.set(packageRoot, status);
|
|
25
|
+
if (status.state === "prepared") {
|
|
26
|
+
return {
|
|
27
|
+
changed: false,
|
|
28
|
+
command: null,
|
|
29
|
+
output: null,
|
|
30
|
+
status,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const scriptPath = status.postinstallScriptPath;
|
|
34
|
+
if (!scriptPath) {
|
|
35
|
+
throw new CodeServerPreparationError("Could not prepare code-server because no package bootstrap script was found.", {
|
|
36
|
+
issues: status.issues,
|
|
37
|
+
packageRoot,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
log.info("preparation", "ensuring code-server package is prepared", {
|
|
41
|
+
packageRoot,
|
|
42
|
+
scriptPath,
|
|
43
|
+
});
|
|
44
|
+
const output = await runBootstrapScript(packageRoot, scriptPath);
|
|
45
|
+
status = buildPreparationStatus(packageRoot, options.strictWatchdog ?? false);
|
|
46
|
+
preparationCache.set(packageRoot, status);
|
|
47
|
+
if (status.state !== "prepared") {
|
|
48
|
+
throw new CodeServerPreparationError("The code-server package bootstrap step completed but the package still looks incomplete.", {
|
|
49
|
+
issues: status.issues,
|
|
50
|
+
output,
|
|
51
|
+
packageRoot,
|
|
52
|
+
scriptPath,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
changed: true,
|
|
57
|
+
command: `sh ${scriptPath}`,
|
|
58
|
+
output,
|
|
59
|
+
status,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function buildPreparationStatus(packageRoot, strictWatchdog) {
|
|
63
|
+
const supportRoot = path.join(packageRoot, "lib", "vscode");
|
|
64
|
+
const postinstallScriptPath = isFile(path.join(packageRoot, "postinstall.sh"))
|
|
65
|
+
? path.join(packageRoot, "postinstall.sh")
|
|
66
|
+
: null;
|
|
67
|
+
const issues = [];
|
|
68
|
+
if (!isDirectory(supportRoot)) {
|
|
69
|
+
issues.push(issue("missing_support_root", "The embedded VS Code support root is missing.", {
|
|
70
|
+
supportRoot,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
const requiredPaths = [
|
|
74
|
+
path.join(packageRoot, "package.json"),
|
|
75
|
+
path.join(packageRoot, "out", "node", "entry.js"),
|
|
76
|
+
path.join(supportRoot, "package.json"),
|
|
77
|
+
path.join(supportRoot, "extensions", "package.json"),
|
|
78
|
+
path.join(supportRoot, "out", "server-main.js"),
|
|
79
|
+
];
|
|
80
|
+
for (const requiredPath of requiredPaths) {
|
|
81
|
+
if (!isFile(requiredPath)) {
|
|
82
|
+
issues.push(issue("missing_runtime_artifact", "A required code-server runtime artifact is missing.", {
|
|
83
|
+
path: requiredPath,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const watchdogIssue = resolveWatchdogIssue(supportRoot, strictWatchdog);
|
|
88
|
+
if (watchdogIssue) {
|
|
89
|
+
issues.push(watchdogIssue);
|
|
90
|
+
}
|
|
91
|
+
const state = issues.some((value) => value.code !== "missing_native_watchdog")
|
|
92
|
+
? postinstallScriptPath
|
|
93
|
+
? "repairable"
|
|
94
|
+
: "missing"
|
|
95
|
+
: "prepared";
|
|
96
|
+
const status = {
|
|
97
|
+
checkedAt: new Date().toISOString(),
|
|
98
|
+
issues,
|
|
99
|
+
packageRoot,
|
|
100
|
+
postinstallScriptPath,
|
|
101
|
+
state,
|
|
102
|
+
supportRoot: isDirectory(supportRoot) ? supportRoot : null,
|
|
103
|
+
watchdogIssue,
|
|
104
|
+
watchdogMode: watchdogIssue ? "disabled_fallback" : "native",
|
|
105
|
+
};
|
|
106
|
+
return status;
|
|
107
|
+
}
|
|
108
|
+
function resolveWatchdogIssue(supportRoot, strictWatchdog) {
|
|
109
|
+
const watchdogRoot = path.join(supportRoot, "node_modules", "@vscode", "native-watchdog");
|
|
110
|
+
if (isDirectory(watchdogRoot) || isFile(path.join(watchdogRoot, "package.json"))) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
code: "missing_native_watchdog",
|
|
115
|
+
dependency: "@vscode/native-watchdog",
|
|
116
|
+
details: {
|
|
117
|
+
path: watchdogRoot,
|
|
118
|
+
strictWatchdog,
|
|
119
|
+
},
|
|
120
|
+
fatal: strictWatchdog,
|
|
121
|
+
message: strictWatchdog
|
|
122
|
+
? "The optional native watchdog dependency is missing and strict watchdog mode is enabled."
|
|
123
|
+
: "The optional native watchdog dependency is missing. The package will use a disabled watchdog fallback.",
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function issue(code, message, details) {
|
|
127
|
+
return {
|
|
128
|
+
code,
|
|
129
|
+
details,
|
|
130
|
+
message,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function resolveCodeServerPackageJsonPath(resolveFrom) {
|
|
134
|
+
const anchorPath = createResolutionAnchor(resolveFrom);
|
|
135
|
+
const requireFrom = createRequire(anchorPath);
|
|
136
|
+
return requireFrom.resolve("code-server/package.json");
|
|
137
|
+
}
|
|
138
|
+
function createResolutionAnchor(resolveFrom) {
|
|
139
|
+
const resolved = path.resolve(resolveFrom ?? process.cwd());
|
|
140
|
+
try {
|
|
141
|
+
const stats = fs.statSync(resolved);
|
|
142
|
+
return stats.isDirectory()
|
|
143
|
+
? path.join(resolved, "__code_server_kit__.js")
|
|
144
|
+
: resolved;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return path.extname(resolved)
|
|
148
|
+
? resolved
|
|
149
|
+
: path.join(resolved, "__code_server_kit__.js");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function runBootstrapScript(packageRoot, scriptPath) {
|
|
153
|
+
return await new Promise((resolve, reject) => {
|
|
154
|
+
execFile("sh", [scriptPath], {
|
|
155
|
+
cwd: packageRoot,
|
|
156
|
+
encoding: "utf8",
|
|
157
|
+
env: {
|
|
158
|
+
...process.env,
|
|
159
|
+
npm_config_user_agent: process.env.npm_config_user_agent ?? "npm/10 node/v22 linux x64",
|
|
160
|
+
npm_config_unsafe_perm: process.env.npm_config_unsafe_perm ?? "true",
|
|
161
|
+
},
|
|
162
|
+
}, (error, stdout, stderr) => {
|
|
163
|
+
const output = [stdout, stderr].filter(Boolean).join("\n").trim();
|
|
164
|
+
if (error) {
|
|
165
|
+
reject(new CodeServerPreparationError("Could not run the code-server package bootstrap script.", {
|
|
166
|
+
cause: error.message,
|
|
167
|
+
output,
|
|
168
|
+
packageRoot,
|
|
169
|
+
scriptPath,
|
|
170
|
+
}));
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
resolve(output);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function isDirectory(value) {
|
|
178
|
+
try {
|
|
179
|
+
return fs.statSync(value).isDirectory();
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function isFile(value) {
|
|
186
|
+
try {
|
|
187
|
+
return fs.statSync(value).isFile();
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
export { ensureCodeServerPrepared, getCodeServerPreparationStatus, };
|
|
194
|
+
//# sourceMappingURL=preparation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preparation.js","sourceRoot":"","sources":["../src/preparation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAU7C,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAuC,CAAC;AAExE,SAAS,8BAA8B,CAAC,UAAwC,EAAE;IAChF,MAAM,eAAe,GAAG,gCAAgC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9E,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACjD,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAG,sBAAsB,CAAC,WAAW,EAAE,OAAO,CAAC,cAAc,IAAI,KAAK,CAAC,CAAC;IACpF,gBAAgB,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,KAAK,UAAU,wBAAw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
|
-
import type { CodeServerProfileItem, CodeServerProfilePathMap, CodeServerProfileSyncPlan, CodeServerProfileSyncResult, CreateCodeServerProfileSyncPlanOptions, SyncCodeServerProfileOptions } from "./types.js";
|
|
1
|
+
import type { CodeServerProfileItem, CodeServerProfilePathMap, CodeServerProfileSnapshot, CodeServerProfileSyncPlan, CodeServerProfileSyncResult, CreateCodeServerProfileSyncPlanOptions, PersistCodeServerProfileIfChangedOptions, PersistCodeServerProfileIfChangedResult, ReadCodeServerProfileSignatureOptions, ReadCodeServerProfileSnapshotOptions, SyncCodeServerProfileOptions } from "./types.js";
|
|
2
2
|
declare const DEFAULT_CODE_SERVER_PROFILE_PATHS: CodeServerProfilePathMap;
|
|
3
3
|
declare const DEFAULT_CODE_SERVER_PROFILE_ITEMS: CodeServerProfileItem[];
|
|
4
4
|
declare function createCodeServerProfileSyncPlan(options: CreateCodeServerProfileSyncPlanOptions): CodeServerProfileSyncPlan;
|
|
5
5
|
declare function syncCodeServerProfile(options: SyncCodeServerProfileOptions): Promise<CodeServerProfileSyncResult>;
|
|
6
|
+
declare function readCodeServerProfileSnapshot(options: ReadCodeServerProfileSnapshotOptions): Promise<CodeServerProfileSnapshot>;
|
|
7
|
+
declare function readCodeServerProfileSignature(options: ReadCodeServerProfileSignatureOptions): Promise<string>;
|
|
8
|
+
declare function persistCodeServerProfileIfChanged(options: PersistCodeServerProfileIfChangedOptions): Promise<PersistCodeServerProfileIfChangedResult>;
|
|
6
9
|
declare function resolveCodeServerProfilePathMap(overrides?: Partial<CodeServerProfilePathMap>): CodeServerProfilePathMap;
|
|
7
|
-
export { DEFAULT_CODE_SERVER_PROFILE_ITEMS, DEFAULT_CODE_SERVER_PROFILE_PATHS, createCodeServerProfileSyncPlan, resolveCodeServerProfilePathMap, syncCodeServerProfile, };
|
|
10
|
+
export { DEFAULT_CODE_SERVER_PROFILE_ITEMS, DEFAULT_CODE_SERVER_PROFILE_PATHS, createCodeServerProfileSyncPlan, persistCodeServerProfileIfChanged, readCodeServerProfileSignature, readCodeServerProfileSnapshot, resolveCodeServerProfilePathMap, syncCodeServerProfile, };
|
|
8
11
|
//# sourceMappingURL=profile.d.ts.map
|
package/dist/profile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EAGzB,yBAAyB,EACzB,2BAA2B,EAC3B,sCAAsC,EACtC,wCAAwC,EACxC,uCAAuC,EACvC,qCAAqC,EACrC,oCAAoC,EACpC,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAEpB,QAAA,MAAM,iCAAiC,EAAE,wBAMxC,CAAC;AAEF,QAAA,MAAM,iCAAiC,EAAE,qBAAqB,EAM7D,CAAC;AAEF,iBAAS,+BAA+B,CAAC,OAAO,EAAE,sCAAsC,GAAG,yBAAyB,CAYnH;AAED,iBAAe,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CA2ChH;AAED,iBAAe,6BAA6B,CAAC,OAAO,EAAE,oCAAoC,GAAG,OAAO,CAAC,yBAAyB,CAAC,CA6B9H;AAED,iBAAe,8BAA8B,CAAC,OAAO,EAAE,qCAAqC,GAAG,OAAO,CAAC,MAAM,CAAC,CAG7G;AAED,iBAAe,iCAAiC,CAC9C,OAAO,EAAE,wCAAwC,GAChD,OAAO,CAAC,uCAAuC,CAAC,CA8BlD;AAED,iBAAS,+BAA+B,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,wBAAwB,CAEhH;AAoHD,OAAO,EACL,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,iCAAiC,EACjC,8BAA8B,EAC9B,6BAA6B,EAC7B,+BAA+B,EAC/B,qBAAqB,GACtB,CAAC"}
|
package/dist/profile.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
3
4
|
const DEFAULT_CODE_SERVER_PROFILE_PATHS = {
|
|
4
5
|
"extensions": "extensions",
|
|
5
6
|
"extensions.json": "User/extensions.json",
|
|
@@ -32,6 +33,7 @@ async function syncCodeServerProfile(options) {
|
|
|
32
33
|
const skipped = [];
|
|
33
34
|
const skipMissing = options.skipMissing ?? true;
|
|
34
35
|
const skipUnreadable = options.skipUnreadable ?? true;
|
|
36
|
+
let changed = false;
|
|
35
37
|
for (const entry of plan.entries) {
|
|
36
38
|
try {
|
|
37
39
|
await fs.promises.mkdir(path.dirname(entry.targetPath), { recursive: true });
|
|
@@ -40,6 +42,7 @@ async function syncCodeServerProfile(options) {
|
|
|
40
42
|
recursive: entry.kind === "directory",
|
|
41
43
|
});
|
|
42
44
|
copied.push(entry);
|
|
45
|
+
changed = true;
|
|
43
46
|
}
|
|
44
47
|
catch (error) {
|
|
45
48
|
if (isMissingError(error) && skipMissing) {
|
|
@@ -60,10 +63,71 @@ async function syncCodeServerProfile(options) {
|
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
return {
|
|
66
|
+
changed,
|
|
63
67
|
copied,
|
|
64
68
|
skipped,
|
|
65
69
|
};
|
|
66
70
|
}
|
|
71
|
+
async function readCodeServerProfileSnapshot(options) {
|
|
72
|
+
const rootDir = path.resolve(options.rootDir);
|
|
73
|
+
const items = normalizeProfileItems(options.items);
|
|
74
|
+
const pathMap = resolveProfilePathMap(options.pathMap);
|
|
75
|
+
const entries = [];
|
|
76
|
+
for (const item of items) {
|
|
77
|
+
const targetPath = path.join(rootDir, pathMap[item]);
|
|
78
|
+
entries.push({
|
|
79
|
+
item,
|
|
80
|
+
present: exists(targetPath),
|
|
81
|
+
signature: await readEntrySignature(targetPath),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (options.snapshotExtensions && !entries.some((value) => value.item === "extensions")) {
|
|
85
|
+
const targetPath = path.join(rootDir, pathMap.extensions);
|
|
86
|
+
entries.push({
|
|
87
|
+
item: "extensions",
|
|
88
|
+
present: exists(targetPath),
|
|
89
|
+
signature: await readEntrySignature(targetPath),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
entries,
|
|
94
|
+
rootDir,
|
|
95
|
+
signature: hashJson(entries),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async function readCodeServerProfileSignature(options) {
|
|
99
|
+
const snapshot = await readCodeServerProfileSnapshot(options);
|
|
100
|
+
return snapshot.signature;
|
|
101
|
+
}
|
|
102
|
+
async function persistCodeServerProfileIfChanged(options) {
|
|
103
|
+
const previousSignature = await safeReadSignature({
|
|
104
|
+
items: options.items,
|
|
105
|
+
pathMap: options.pathMap,
|
|
106
|
+
rootDir: options.targetDir,
|
|
107
|
+
snapshotExtensions: options.snapshotExtensions,
|
|
108
|
+
});
|
|
109
|
+
const nextSignature = await readCodeServerProfileSignature({
|
|
110
|
+
items: options.items,
|
|
111
|
+
pathMap: options.pathMap,
|
|
112
|
+
rootDir: options.sourceDir,
|
|
113
|
+
snapshotExtensions: options.snapshotExtensions,
|
|
114
|
+
});
|
|
115
|
+
if (previousSignature && previousSignature === nextSignature) {
|
|
116
|
+
return {
|
|
117
|
+
changed: false,
|
|
118
|
+
copied: [],
|
|
119
|
+
nextSignature,
|
|
120
|
+
previousSignature,
|
|
121
|
+
skipped: [],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const result = await syncCodeServerProfile(options);
|
|
125
|
+
return {
|
|
126
|
+
...result,
|
|
127
|
+
nextSignature,
|
|
128
|
+
previousSignature,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
67
131
|
function resolveCodeServerProfilePathMap(overrides) {
|
|
68
132
|
return resolveProfilePathMap(overrides);
|
|
69
133
|
}
|
|
@@ -94,6 +158,63 @@ function createProfileSyncEntry(item, sourceDir, targetDir, relativePath) {
|
|
|
94
158
|
targetPath: path.join(targetDir, relativePath),
|
|
95
159
|
};
|
|
96
160
|
}
|
|
161
|
+
async function readEntrySignature(targetPath) {
|
|
162
|
+
if (!exists(targetPath))
|
|
163
|
+
return null;
|
|
164
|
+
const stats = await fs.promises.stat(targetPath);
|
|
165
|
+
if (stats.isFile()) {
|
|
166
|
+
return createHash("sha256")
|
|
167
|
+
.update(await fs.promises.readFile(targetPath))
|
|
168
|
+
.digest("hex");
|
|
169
|
+
}
|
|
170
|
+
if (!stats.isDirectory()) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const files = await listFiles(targetPath);
|
|
174
|
+
const hash = createHash("sha256");
|
|
175
|
+
for (const filePath of files) {
|
|
176
|
+
hash.update(path.relative(targetPath, filePath));
|
|
177
|
+
hash.update(await fs.promises.readFile(filePath));
|
|
178
|
+
}
|
|
179
|
+
return hash.digest("hex");
|
|
180
|
+
}
|
|
181
|
+
async function listFiles(rootDir) {
|
|
182
|
+
const values = [];
|
|
183
|
+
const entries = await fs.promises.readdir(rootDir, { withFileTypes: true });
|
|
184
|
+
for (const entry of entries) {
|
|
185
|
+
const filePath = path.join(rootDir, entry.name);
|
|
186
|
+
if (entry.isDirectory()) {
|
|
187
|
+
values.push(...await listFiles(filePath));
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (entry.isFile()) {
|
|
191
|
+
values.push(filePath);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return values.sort();
|
|
195
|
+
}
|
|
196
|
+
async function safeReadSignature(options) {
|
|
197
|
+
try {
|
|
198
|
+
return await readCodeServerProfileSignature(options);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function hashJson(value) {
|
|
205
|
+
return createHash("sha256")
|
|
206
|
+
.update(JSON.stringify(value))
|
|
207
|
+
.digest("hex");
|
|
208
|
+
}
|
|
209
|
+
function exists(value) {
|
|
210
|
+
try {
|
|
211
|
+
fs.accessSync(value);
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
97
218
|
function isMissingError(error) {
|
|
98
219
|
return typeof error === "object" && error != null && "code" in error && String(error.code) === "ENOENT";
|
|
99
220
|
}
|
|
@@ -103,5 +224,5 @@ function isUnreadableError(error) {
|
|
|
103
224
|
const code = String(error.code);
|
|
104
225
|
return code === "EACCES" || code === "EPERM";
|
|
105
226
|
}
|
|
106
|
-
export { DEFAULT_CODE_SERVER_PROFILE_ITEMS, DEFAULT_CODE_SERVER_PROFILE_PATHS, createCodeServerProfileSyncPlan, resolveCodeServerProfilePathMap, syncCodeServerProfile, };
|
|
227
|
+
export { DEFAULT_CODE_SERVER_PROFILE_ITEMS, DEFAULT_CODE_SERVER_PROFILE_PATHS, createCodeServerProfileSyncPlan, persistCodeServerProfileIfChanged, readCodeServerProfileSignature, readCodeServerProfileSnapshot, resolveCodeServerProfilePathMap, syncCodeServerProfile, };
|
|
107
228
|
//# sourceMappingURL=profile.js.map
|
package/dist/profile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAkBzC,MAAM,iCAAiC,GAA6B;IAClE,YAAY,EAAE,YAAY;IAC1B,iBAAiB,EAAE,sBAAsB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,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACnF,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,OAAO,CAAC;AAC/C,CAAC;AAED,OAAO,EACL,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,iCAAiC,EACjC,8BAA8B,EAC9B,6BAA6B,EAC7B,+BAA+B,EAC/B,qBAAqB,GACtB,CAAC"}
|
package/dist/proxy.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { BuildForwardedHeadersOptions, CodeServerHtmlResponseOptions } from "./types.js";
|
|
1
|
+
import type { BuildCodeServerWebSocketHeadersOptions, BuildForwardedHeadersOptions, ClassifyCodeServerProxyFailureOptions, CodeServerHtmlResponseOptions, CodeServerProxyFailure } from "./types.js";
|
|
2
2
|
declare function buildForwardedHeaders(options: BuildForwardedHeadersOptions): Record<string, string>;
|
|
3
3
|
declare function isCodeServerHtmlResponse(options: CodeServerHtmlResponseOptions): boolean;
|
|
4
|
+
declare function buildCodeServerWebSocketHeaders(options: BuildCodeServerWebSocketHeadersOptions): Record<string, string>;
|
|
5
|
+
declare function classifyCodeServerProxyFailure(options: ClassifyCodeServerProxyFailureOptions): CodeServerProxyFailure;
|
|
4
6
|
declare function normalizeTrustedOrigin(value: string): string;
|
|
5
|
-
export { buildForwardedHeaders, isCodeServerHtmlResponse, normalizeTrustedOrigin, };
|
|
7
|
+
export { buildCodeServerWebSocketHeaders, buildForwardedHeaders, classifyCodeServerProxyFailure, isCodeServerHtmlResponse, normalizeTrustedOrigin, };
|
|
6
8
|
//# sourceMappingURL=proxy.d.ts.map
|
package/dist/proxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sCAAsC,EACtC,4BAA4B,EAC5B,qCAAqC,EACrC,6BAA6B,EAC7B,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAEpB,iBAAS,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoB5F;AAED,iBAAS,wBAAwB,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CASjF;AAED,iBAAS,+BAA+B,CAAC,OAAO,EAAE,sCAAsC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMhH;AAED,iBAAS,8BAA8B,CAAC,OAAO,EAAE,qCAAqC,GAAG,sBAAsB,CA0D9G;AAED,iBAAS,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYrD;AAmDD,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,EACrB,8BAA8B,EAC9B,wBAAwB,EACxB,sBAAsB,GACvB,CAAC"}
|
package/dist/proxy.js
CHANGED
|
@@ -31,6 +31,67 @@ function isCodeServerHtmlResponse(options) {
|
|
|
31
31
|
const contentType = normalizeContentType(options);
|
|
32
32
|
return contentType.startsWith("text/html") || contentType.startsWith("application/xhtml+xml");
|
|
33
33
|
}
|
|
34
|
+
function buildCodeServerWebSocketHeaders(options) {
|
|
35
|
+
return {
|
|
36
|
+
...buildForwardedHeaders(options),
|
|
37
|
+
"connection": normalizeOptionalString(options.connection) ?? "Upgrade",
|
|
38
|
+
"upgrade": normalizeOptionalString(options.upgrade) ?? "websocket",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function classifyCodeServerProxyFailure(options) {
|
|
42
|
+
const errorCode = typeof options.error === "object" && options.error && "code" in options.error
|
|
43
|
+
? String(options.error.code)
|
|
44
|
+
: null;
|
|
45
|
+
const statusCode = options.statusCode ?? null;
|
|
46
|
+
if (errorCode === "ECONNREFUSED" || statusCode === 502) {
|
|
47
|
+
return {
|
|
48
|
+
category: "refused",
|
|
49
|
+
details: {
|
|
50
|
+
code: errorCode,
|
|
51
|
+
statusCode,
|
|
52
|
+
},
|
|
53
|
+
message: "The code-server upstream refused the connection.",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (errorCode === "ECONNRESET") {
|
|
57
|
+
return {
|
|
58
|
+
category: "reset",
|
|
59
|
+
details: {
|
|
60
|
+
code: errorCode,
|
|
61
|
+
statusCode,
|
|
62
|
+
},
|
|
63
|
+
message: "The code-server upstream reset the connection.",
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (errorCode === "ETIMEDOUT" || statusCode === 504) {
|
|
67
|
+
return {
|
|
68
|
+
category: "timeout",
|
|
69
|
+
details: {
|
|
70
|
+
code: errorCode,
|
|
71
|
+
statusCode,
|
|
72
|
+
},
|
|
73
|
+
message: "The code-server upstream timed out.",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (statusCode && statusCode >= 500) {
|
|
77
|
+
return {
|
|
78
|
+
category: "upstream_failure",
|
|
79
|
+
details: {
|
|
80
|
+
code: errorCode,
|
|
81
|
+
statusCode,
|
|
82
|
+
},
|
|
83
|
+
message: "The code-server upstream returned an error.",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
category: "unknown",
|
|
88
|
+
details: {
|
|
89
|
+
code: errorCode,
|
|
90
|
+
statusCode,
|
|
91
|
+
},
|
|
92
|
+
message: "The code-server upstream request failed.",
|
|
93
|
+
};
|
|
94
|
+
}
|
|
34
95
|
function normalizeTrustedOrigin(value) {
|
|
35
96
|
try {
|
|
36
97
|
const origin = new URL(value).origin;
|
|
@@ -88,5 +149,5 @@ function normalizeOptionalString(value) {
|
|
|
88
149
|
const normalized = value.trim();
|
|
89
150
|
return normalized ? normalized : null;
|
|
90
151
|
}
|
|
91
|
-
export { buildForwardedHeaders, isCodeServerHtmlResponse, normalizeTrustedOrigin, };
|
|
152
|
+
export { buildCodeServerWebSocketHeaders, buildForwardedHeaders, classifyCodeServerProxyFailure, isCodeServerHtmlResponse, normalizeTrustedOrigin, };
|
|
92
153
|
//# sourceMappingURL=proxy.js.map
|
package/dist/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;AASlE,SAAS,qBAAqB,CAAC,OAAqC;IAClE,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,MAAM,IAAI,GAAG,uBAAuB,CAAC,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,MAAM,KAAK,GAAG,uBAAuB,CAAC,OAAO,CAAC,cAAc,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/E,MAAM,IAAI,GAAG,uBAAuB,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9F,MAAM,YAAY,GAAG,qBAAqB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEjE,IAAI,IAAI;QAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC;IAC7C,IAAI,KAAK;QAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,KAAK,CAAC;IAChD,IAAI,IAAI;QAAE,OAAO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O,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAChC,OAAO,UAAU,IAAI,IAAI,CAAC;IAC5B,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEvC,MAAM,MAAM,GAAG,KAAK;SACjB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAClC,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACpC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAChC,OAAO,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;AACxC,CAAC;AAED,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,EACrB,8BAA8B,EAC9B,wBAAwB,EACxB,sBAAsB,GACvB,CAAC"}
|
package/dist/resolve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAuB,sBAAsB,EAAE,oCAAoC,EAAE,MAAM,YAAY,CAAC;AAQpH,iBAAS,6BAA6B,CACpC,OAAO,GAAE,oCAAyC,GACjD,sBAAsB,CAuDxB;AAoHD,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
|
package/dist/resolve.js
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { CodeServerBinaryNotFoundError, CodeServerPackageResolutionError } from "./errors.js";
|
|
5
|
+
import { getCodeServerPreparationStatus } from "./preparation.js";
|
|
5
6
|
function resolveCodeServerInstallation(options = {}) {
|
|
6
7
|
const packageJsonPath = resolveCodeServerPackageJsonPath(options.resolveFrom);
|
|
7
8
|
const packageRoot = path.dirname(packageJsonPath);
|
|
@@ -16,13 +17,42 @@ function resolveCodeServerInstallation(options = {}) {
|
|
|
16
17
|
packageRoot,
|
|
17
18
|
});
|
|
18
19
|
}
|
|
20
|
+
const supportRoot = resolveSupportRoot(packageRoot);
|
|
21
|
+
const preparationStatus = getCodeServerPreparationStatus({
|
|
22
|
+
resolveFrom: options.resolveFrom,
|
|
23
|
+
strictWatchdog: options.strictWatchdog,
|
|
24
|
+
});
|
|
19
25
|
return {
|
|
26
|
+
defaultCwd: packageRoot,
|
|
27
|
+
defaultEnv: {},
|
|
28
|
+
entryArgs: [],
|
|
29
|
+
entryCommand: detectEntryKind(entryPoint) === "node_script"
|
|
30
|
+
? process.execPath
|
|
31
|
+
: entryPoint,
|
|
20
32
|
entryKind: detectEntryKind(entryPoint),
|
|
21
33
|
entryPoint,
|
|
22
34
|
entryRelativePath,
|
|
23
35
|
packageJsonPath,
|
|
36
|
+
packageManagerHints: {
|
|
37
|
+
installCommand: "npm install",
|
|
38
|
+
packageManager: "npm",
|
|
39
|
+
},
|
|
24
40
|
packageRoot,
|
|
25
|
-
|
|
41
|
+
preparationStatus,
|
|
42
|
+
recommendedReadablePaths: uniquePaths([
|
|
43
|
+
packageRoot,
|
|
44
|
+
entryPoint,
|
|
45
|
+
supportRoot,
|
|
46
|
+
]),
|
|
47
|
+
supportBindings: supportRoot
|
|
48
|
+
? [{
|
|
49
|
+
access: "read",
|
|
50
|
+
hostPath: supportRoot,
|
|
51
|
+
mountPath: supportRoot,
|
|
52
|
+
reason: "code-server support root",
|
|
53
|
+
}]
|
|
54
|
+
: [],
|
|
55
|
+
supportRoot,
|
|
26
56
|
version: typeof packageJson.version === "string" ? packageJson.version : undefined,
|
|
27
57
|
};
|
|
28
58
|
}
|
|
@@ -102,6 +132,18 @@ function resolveSupportRoot(packageRoot) {
|
|
|
102
132
|
const supportRoot = path.join(packageRoot, "lib", "vscode");
|
|
103
133
|
return isDirectory(supportRoot) ? supportRoot : null;
|
|
104
134
|
}
|
|
135
|
+
function uniquePaths(values) {
|
|
136
|
+
const normalized = [];
|
|
137
|
+
for (const value of values) {
|
|
138
|
+
if (typeof value !== "string")
|
|
139
|
+
continue;
|
|
140
|
+
const nextValue = path.resolve(value);
|
|
141
|
+
if (!normalized.includes(nextValue)) {
|
|
142
|
+
normalized.push(nextValue);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return normalized;
|
|
146
|
+
}
|
|
105
147
|
function isDirectory(value) {
|
|
106
148
|
try {
|
|
107
149
|
return fs.statSync(value).isDirectory();
|
package/dist/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,6BAA6B,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve.js","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C;AAED,SAAS,kBAAkB,CAAC,WAAmB;IAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5D,OAAO,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;AACvD,CAAC;AAED,SAAS,WAAW,CAAC,MAAwC;IAC3D,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,SAAS;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACpC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,KAAa;IAC3B,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
|
package/dist/session.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { CodeServerSessionDiagnostics, CodeServerSessionManager, CodeServerSessionManagerOptions, CodeServerSessionRequest, CodeServerSessionRestartResult, CodeServerSessionStartResult, CodeServerSessionStatus, CodeServerSessionStopResult } from "./types.js";
|
|
2
2
|
declare function createCodeServerSessionManager(options?: CodeServerSessionManagerOptions): CodeServerSessionManager;
|
|
3
3
|
declare function startCodeServerSession(options: CodeServerSessionRequest): Promise<CodeServerSessionStartResult>;
|
|
4
|
-
declare function stopCodeServerSession(options: Pick<CodeServerSessionRequest, "logger" | "loggerAdapter" | "profile" | "sessionKey" | "stateRoot"> & {
|
|
4
|
+
declare function stopCodeServerSession(options: Pick<CodeServerSessionRequest, "logger" | "loggerAdapter" | "profile" | "sanitizer" | "sessionKey" | "stateRoot"> & {
|
|
5
5
|
signal?: NodeJS.Signals | number;
|
|
6
6
|
}): Promise<CodeServerSessionStopResult | null>;
|
|
7
7
|
declare function restartCodeServerSession(options: CodeServerSessionRequest): Promise<CodeServerSessionRestartResult>;
|
|
8
|
-
declare function getCodeServerSessionStatus(options: Pick<CodeServerSessionRequest, "logger" | "loggerAdapter" | "sessionKey" | "stateRoot">): Promise<CodeServerSessionStatus | null>;
|
|
8
|
+
declare function getCodeServerSessionStatus(options: Pick<CodeServerSessionRequest, "logger" | "loggerAdapter" | "sanitizer" | "sessionKey" | "stateRoot">): Promise<CodeServerSessionStatus | null>;
|
|
9
9
|
declare function readCodeServerSessionDiagnostics(options: Pick<CodeServerSessionRequest, "sessionKey" | "stateRoot">): Promise<CodeServerSessionDiagnostics | null>;
|
|
10
10
|
export { createCodeServerSessionManager, getCodeServerSessionStatus, readCodeServerSessionDiagnostics, restartCodeServerSession, startCodeServerSession, stopCodeServerSession, };
|
|
11
11
|
//# sourceMappingURL=session.d.ts.map
|