@trebired/code-server-kit 0.1.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 ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Trebired
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # @trebired/code-server-kit
2
+
3
+ Framework-agnostic `code-server` launch planning for Node.js applications.
4
+
5
+ `@trebired/code-server-kit` gives your app a small, typed layer for finding an installed `code-server`, building a stable launch command, waiting for readiness, and optionally spawning the process without leaking `code-server` package layout details into product code.
6
+
7
+ The package stays in one lane:
8
+
9
+ - resolve the installed `code-server` package root and launch entrypoint
10
+ - build standard `code-server` CLI args for host-managed sessions
11
+ - expose the launch command and args for your own sandbox or supervisor
12
+ - optionally spawn the process and capture stdout and stderr
13
+ - wait for the TCP port to become ready with timeout and early-exit handling
14
+
15
+ It does not try to be a `code-server` fork, a sandbox manager, a container runtime, or a product layer with app-specific routes and filesystem rules.
16
+
17
+ ## Install
18
+
19
+ Runtime target: Node.js 22+ on Linux first.
20
+
21
+ ```sh
22
+ npm install @trebired/code-server-kit code-server
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```ts
28
+ import {
29
+ createCodeServerLaunch,
30
+ launchCodeServerProcess,
31
+ resolveCodeServerInstallation,
32
+ waitForCodeServerReady,
33
+ } from "@trebired/code-server-kit";
34
+
35
+ const installation = resolveCodeServerInstallation({
36
+ resolveFrom: process.cwd(),
37
+ });
38
+
39
+ const launch = await createCodeServerLaunch({
40
+ installation,
41
+ dataRoot: "/srv/code-server/session-42",
42
+ host: "127.0.0.1",
43
+ port: 8080,
44
+ trustedOrigins: [
45
+ "https://app.example.com",
46
+ ],
47
+ workspacePath: "/srv/workspaces/demo",
48
+ });
49
+
50
+ const processHandle = await launchCodeServerProcess({
51
+ plan: launch,
52
+ stdout(text) {
53
+ process.stdout.write(text);
54
+ },
55
+ stderr(text) {
56
+ process.stderr.write(text);
57
+ },
58
+ });
59
+
60
+ await waitForCodeServerReady({
61
+ host: launch.host,
62
+ port: launch.port,
63
+ process: processHandle,
64
+ timeoutMs: 30_000,
65
+ });
66
+ ```
67
+
68
+ ## Public API
69
+
70
+ ### `resolveCodeServerInstallation(options?)`
71
+
72
+ Resolves the installed `code-server` package from a caller-controlled starting path and returns:
73
+
74
+ - `packageRoot`
75
+ - `packageJsonPath`
76
+ - `entryPoint`
77
+ - `entryKind`
78
+ - `supportRoot`
79
+ - `version`
80
+
81
+ ### `createCodeServerLaunch(options)`
82
+
83
+ Builds a stable launch plan and returns:
84
+
85
+ - `command`
86
+ - `args`
87
+ - `codeServerPackageRoot`
88
+ - `supportRoot`
89
+ - `userDataDir`
90
+ - `extensionsDir`
91
+ - `bindAddr`
92
+ - `host`
93
+ - `port`
94
+ - `workspacePath`
95
+
96
+ If you pass `dataRoot`, the package derives:
97
+
98
+ - `${dataRoot}/user-data`
99
+ - `${dataRoot}/extensions`
100
+
101
+ If you omit `port` or pass `0`, the package allocates a free TCP port first.
102
+
103
+ ### `waitForCodeServerReady(options)`
104
+
105
+ Polls the target TCP port until it accepts connections or fails with:
106
+
107
+ - `CodeServerProcessExitedBeforeReadyError`
108
+ - `CodeServerStartupTimeoutError`
109
+
110
+ ### `launchCodeServerProcess(options)`
111
+
112
+ Starts the resolved command directly with `stdout` and `stderr` hooks and returns a typed handle with:
113
+
114
+ - `child`
115
+ - `pid`
116
+ - `exit`
117
+ - `kill()`
118
+ - `getStdout()`
119
+ - `getStderr()`
120
+
121
+ ## Launch Modes
122
+
123
+ `createCodeServerLaunch()` supports two concrete launch modes:
124
+
125
+ - `node`, which runs `node <entrypoint> ...`
126
+ - `direct`, which runs the resolved entrypoint directly when it is executable
127
+
128
+ `auto` is the default. It prefers `node` for JS entry files and `direct` for non-JS executables.
129
+
130
+ ## Standard CLI Args
131
+
132
+ The launch plan always includes:
133
+
134
+ - `--auth none`
135
+ - `--bind-addr`
136
+ - `--disable-telemetry`
137
+ - `--disable-update-check`
138
+ - `--disable-workspace-trust`
139
+ - `--disable-getting-started-override`
140
+ - `--user-data-dir`
141
+ - `--extensions-dir`
142
+
143
+ Trusted origins are appended with repeated `--trusted-origins` flags, and `workspacePath` is appended as the positional workspace/folder target when provided.
144
+
145
+ ## Dependency vs Peer Dependency for `code-server`
146
+
147
+ For an application, prefer a regular `dependency` on `code-server` when you want one installed runtime and want `@trebired/code-server-kit` to resolve the same package reliably every time.
148
+
149
+ For a wrapper library on top of this package, prefer a `peerDependency` on `code-server` when the host application must choose the exact `code-server` version and install location itself. In that setup, document that `code-server` must still be resolvable from the host application's dependency tree, and pass `resolveFrom` when you need to anchor resolution to the host side explicitly.
150
+
151
+ ## Error Types
152
+
153
+ The package exposes structured errors for the failure modes that usually matter in integration code:
154
+
155
+ - `CodeServerBinaryNotFoundError`
156
+ - `CodeServerPackageResolutionError`
157
+ - `CodeServerPortAllocationError`
158
+ - `CodeServerProcessExitedBeforeReadyError`
159
+ - `CodeServerStartupTimeoutError`
@@ -0,0 +1,25 @@
1
+ type CodeServerKitErrorCode = "binary_not_found" | "package_resolution_failed" | "port_allocation_failed" | "process_exited_before_ready" | "startup_timeout";
2
+ declare class CodeServerKitError extends Error {
3
+ code: CodeServerKitErrorCode | string;
4
+ details: Record<string, unknown>;
5
+ constructor(code: CodeServerKitErrorCode | string, message: string, details?: Record<string, unknown>);
6
+ }
7
+ declare class CodeServerBinaryNotFoundError extends CodeServerKitError {
8
+ constructor(message: string, details?: Record<string, unknown>);
9
+ }
10
+ declare class CodeServerPackageResolutionError extends CodeServerKitError {
11
+ constructor(message: string, details?: Record<string, unknown>);
12
+ }
13
+ declare class CodeServerPortAllocationError extends CodeServerKitError {
14
+ constructor(message: string, details?: Record<string, unknown>);
15
+ }
16
+ declare class CodeServerProcessExitedBeforeReadyError extends CodeServerKitError {
17
+ constructor(message: string, details?: Record<string, unknown>);
18
+ }
19
+ declare class CodeServerStartupTimeoutError extends CodeServerKitError {
20
+ constructor(message: string, details?: Record<string, unknown>);
21
+ }
22
+ declare function isCodeServerKitError(value: unknown): value is CodeServerKitError;
23
+ export { CodeServerBinaryNotFoundError, CodeServerKitError, CodeServerPackageResolutionError, CodeServerPortAllocationError, CodeServerProcessExitedBeforeReadyError, CodeServerStartupTimeoutError, isCodeServerKitError, };
24
+ export type { CodeServerKitErrorCode };
25
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,KAAK,sBAAsB,GACvB,kBAAkB,GAClB,2BAA2B,GAC3B,wBAAwB,GACxB,6BAA6B,GAC7B,iBAAiB,CAAC;AAEtB,cAAM,kBAAmB,SAAQ,KAAK;IACpC,IAAI,EAAE,sBAAsB,GAAG,MAAM,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAErB,IAAI,EAAE,sBAAsB,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAM1G;AAED,cAAM,6BAA8B,SAAQ,kBAAkB;gBAChD,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAInE;AAED,cAAM,gCAAiC,SAAQ,kBAAkB;gBACnD,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAInE;AAED,cAAM,6BAA8B,SAAQ,kBAAkB;gBAChD,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAInE;AAED,cAAM,uCAAwC,SAAQ,kBAAkB;gBAC1D,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAInE;AAED,cAAM,6BAA8B,SAAQ,kBAAkB;gBAChD,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAInE;AAED,iBAAS,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAEzE;AAED,OAAO,EACL,6BAA6B,EAC7B,kBAAkB,EAClB,gCAAgC,EAChC,6BAA6B,EAC7B,uCAAuC,EACvC,6BAA6B,EAC7B,oBAAoB,GACrB,CAAC;AACF,YAAY,EAAE,sBAAsB,EAAE,CAAC"}
package/dist/errors.js ADDED
@@ -0,0 +1,43 @@
1
+ class CodeServerKitError extends Error {
2
+ constructor(code, message, details = {}) {
3
+ super(message);
4
+ this.name = "CodeServerKitError";
5
+ this.code = code;
6
+ this.details = details;
7
+ }
8
+ }
9
+ class CodeServerBinaryNotFoundError extends CodeServerKitError {
10
+ constructor(message, details = {}) {
11
+ super("binary_not_found", message, details);
12
+ this.name = "CodeServerBinaryNotFoundError";
13
+ }
14
+ }
15
+ class CodeServerPackageResolutionError extends CodeServerKitError {
16
+ constructor(message, details = {}) {
17
+ super("package_resolution_failed", message, details);
18
+ this.name = "CodeServerPackageResolutionError";
19
+ }
20
+ }
21
+ class CodeServerPortAllocationError extends CodeServerKitError {
22
+ constructor(message, details = {}) {
23
+ super("port_allocation_failed", message, details);
24
+ this.name = "CodeServerPortAllocationError";
25
+ }
26
+ }
27
+ class CodeServerProcessExitedBeforeReadyError extends CodeServerKitError {
28
+ constructor(message, details = {}) {
29
+ super("process_exited_before_ready", message, details);
30
+ this.name = "CodeServerProcessExitedBeforeReadyError";
31
+ }
32
+ }
33
+ class CodeServerStartupTimeoutError extends CodeServerKitError {
34
+ constructor(message, details = {}) {
35
+ super("startup_timeout", message, details);
36
+ this.name = "CodeServerStartupTimeoutError";
37
+ }
38
+ }
39
+ function isCodeServerKitError(value) {
40
+ return value instanceof CodeServerKitError;
41
+ }
42
+ export { CodeServerBinaryNotFoundError, CodeServerKitError, CodeServerPackageResolutionError, CodeServerPortAllocationError, CodeServerProcessExitedBeforeReadyError, CodeServerStartupTimeoutError, isCodeServerKitError, };
43
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA,MAAM,kBAAmB,SAAQ,KAAK;IAIpC,YAAY,IAAqC,EAAE,OAAe,EAAE,UAAmC,EAAE;QACvG,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED,MAAM,6BAA8B,SAAQ,kBAAkB;IAC5D,YAAY,OA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erPortAllocationError, CodeServerProcessExitedBeforeReadyError, CodeServerStartupTimeoutError, isCodeServerKitError, } from "./errors.js";
2
+ export { createCodeServerLaunch, launchCodeServerProcess } from "./launch.js";
3
+ export { waitForCodeServerReady } from "./readiness.js";
4
+ export { resolveCodeServerInstallation } from "./resolve.js";
5
+ export type { CodeServerEntryKind, CodeServerInstallation, CodeServerLaunchMode, CodeServerLaunchOptions, CodeServerLaunchPlan, CodeServerProcessExit, CodeServerProcessHandle, CodeServerReadyOptions, CodeServerReadyResult, LaunchCodeServerProcessOptions, ResolveCodeServerInstallationOptions, } from "./types.js";
6
+ export type { CodeServerKitErrorCode } from "./errors.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,kBAAkB,EAClB,gCAAgC,EAChC,6BAA6B,EAC7B,uCAAuC,EACvC,6BAA6B,EAC7B,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAE7D,YAAY,EACV,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,8BAA8B,EAC9B,oCAAoC,GACrC,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { CodeServerBinaryNotFoundError, CodeServerKitError, CodeServerPackageResolutionError, CodeServerPortAllocationError, CodeServerProcessExitedBeforeReadyError, CodeServerStartupTimeoutError, isCodeServerKitError, } from "./errors.js";
2
+ export { createCodeServerLaunch, launchCodeServerProcess } from "./launch.js";
3
+ export { waitForCodeServerReady } from "./readiness.js";
4
+ export { resolveCodeServerInstallation } from "./resolve.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,kBAAkB,EAClB,gCAAgC,EAChC,6BAA6B,EAC7B,uCAAuC,EACvC,6BAA6B,EAC7B,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { CodeServerLaunchOptions, CodeServerLaunchPlan, CodeServerProcessHandle, LaunchCodeServerProcessOptions } from "./types.js";
2
+ declare function createCodeServerLaunch(options: CodeServerLaunchOptions): Promise<CodeServerLaunchPlan>;
3
+ declare function launchCodeServerProcess(options: LaunchCodeServerProcessOptions): Promise<CodeServerProcessHandle>;
4
+ export { createCodeServerLaunch, launchCodeServerProcess };
5
+ //# sourceMappingURL=launch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launch.d.ts","sourceRoot":"","sources":["../src/launch.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAEV,uBAAuB,EACvB,oBAAoB,EAEpB,uBAAuB,EACvB,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAKpB,iBAAe,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAkDrG;AAED,iBAAe,uBAAuB,CAAC,OAAO,EAAE,8BAA8B,GAAG,OAAO,CAAC,uBAAuB,CAAC,CA6DhH;AAsOD,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,CAAC"}
package/dist/launch.js ADDED
@@ -0,0 +1,292 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import net from "node:net";
4
+ import path from "node:path";
5
+ import { CodeServerBinaryNotFoundError, CodeServerPortAllocationError, } from "./errors.js";
6
+ import { resolveCodeServerInstallation } from "./resolve.js";
7
+ const DEFAULT_BIND_HOST = "127.0.0.1";
8
+ const DIRECT_LAUNCH_ACCESS = fs.constants.X_OK;
9
+ async function createCodeServerLaunch(options) {
10
+ const installation = options.installation ?? resolveCodeServerInstallation({
11
+ resolveFrom: options.resolveFrom,
12
+ });
13
+ const launchMode = normalizeLaunchMode(options.launchMode, installation);
14
+ const { extensionsDir, userDataDir } = resolveLaunchDirectories(options);
15
+ const binding = await resolveLaunchBinding(options);
16
+ const workspacePath = options.workspacePath ? path.resolve(options.workspacePath) : null;
17
+ const trustedOrigins = normalizeTrustedOrigins(options.trustedOrigins);
18
+ const cliArgs = buildCodeServerArgs({
19
+ bindAddr: binding.bindAddr,
20
+ extensionsDir,
21
+ trustedOrigins,
22
+ userDataDir,
23
+ workspacePath,
24
+ });
25
+ if (launchMode === "direct") {
26
+ assertDirectLaunchAvailable(installation.entryPoint);
27
+ }
28
+ return launchMode === "node"
29
+ ? {
30
+ args: [installation.entryPoint, ...cliArgs],
31
+ bindAddr: binding.bindAddr,
32
+ codeServerPackageRoot: installation.packageRoot,
33
+ command: normalizeNodeCommand(options.nodeCommand),
34
+ entryPoint: installation.entryPoint,
35
+ extensionsDir,
36
+ host: binding.host,
37
+ launchMode,
38
+ port: binding.port,
39
+ supportRoot: installation.supportRoot,
40
+ userDataDir,
41
+ workspacePath,
42
+ }
43
+ : {
44
+ args: cliArgs,
45
+ bindAddr: binding.bindAddr,
46
+ codeServerPackageRoot: installation.packageRoot,
47
+ command: installation.entryPoint,
48
+ entryPoint: installation.entryPoint,
49
+ extensionsDir,
50
+ host: binding.host,
51
+ launchMode,
52
+ port: binding.port,
53
+ supportRoot: installation.supportRoot,
54
+ userDataDir,
55
+ workspacePath,
56
+ };
57
+ }
58
+ async function launchCodeServerProcess(options) {
59
+ const plan = options.plan;
60
+ const stdoutChunks = [];
61
+ const stderrChunks = [];
62
+ const child = spawn(plan.command, plan.args, {
63
+ cwd: options.cwd,
64
+ env: options.env ? { ...process.env, ...options.env } : process.env,
65
+ stdio: ["ignore", "pipe", "pipe"],
66
+ });
67
+ child.stdout?.on("data", (chunk) => {
68
+ const text = String(chunk);
69
+ stdoutChunks.push(text);
70
+ options.stdout?.(text);
71
+ });
72
+ child.stderr?.on("data", (chunk) => {
73
+ const text = String(chunk);
74
+ stderrChunks.push(text);
75
+ options.stderr?.(text);
76
+ });
77
+ const exit = new Promise((resolve) => {
78
+ child.once("close", (code, signal) => {
79
+ resolve({
80
+ code,
81
+ signal: typeof signal === "string" ? signal : null,
82
+ });
83
+ });
84
+ });
85
+ await new Promise((resolve, reject) => {
86
+ child.once("spawn", () => resolve());
87
+ child.once("error", (error) => reject(wrapSpawnError(error, plan)));
88
+ });
89
+ return {
90
+ args: [...plan.args],
91
+ bindAddr: plan.bindAddr,
92
+ child,
93
+ codeServerPackageRoot: plan.codeServerPackageRoot,
94
+ command: plan.command,
95
+ exit,
96
+ extensionsDir: plan.extensionsDir,
97
+ getStderr() {
98
+ return stderrChunks.join("");
99
+ },
100
+ getStdout() {
101
+ return stdoutChunks.join("");
102
+ },
103
+ host: plan.host,
104
+ kill(signal) {
105
+ return child.kill(signal);
106
+ },
107
+ launchMode: plan.launchMode,
108
+ pid: child.pid,
109
+ port: plan.port,
110
+ supportRoot: plan.supportRoot,
111
+ userDataDir: plan.userDataDir,
112
+ workspacePath: plan.workspacePath,
113
+ };
114
+ }
115
+ function buildCodeServerArgs(options) {
116
+ const args = [
117
+ "--auth",
118
+ "none",
119
+ "--bind-addr",
120
+ options.bindAddr,
121
+ "--disable-telemetry",
122
+ "--disable-update-check",
123
+ "--disable-workspace-trust",
124
+ "--disable-getting-started-override",
125
+ "--user-data-dir",
126
+ options.userDataDir,
127
+ "--extensions-dir",
128
+ options.extensionsDir,
129
+ ];
130
+ for (const origin of options.trustedOrigins) {
131
+ args.push("--trusted-origins", origin);
132
+ }
133
+ if (options.workspacePath) {
134
+ args.push(options.workspacePath);
135
+ }
136
+ return args;
137
+ }
138
+ function resolveLaunchDirectories(options) {
139
+ const dataRoot = options.dataRoot ? path.resolve(options.dataRoot) : null;
140
+ const userDataDir = options.userDataDir
141
+ ? path.resolve(options.userDataDir)
142
+ : dataRoot
143
+ ? path.join(dataRoot, "user-data")
144
+ : null;
145
+ const extensionsDir = options.extensionsDir
146
+ ? path.resolve(options.extensionsDir)
147
+ : dataRoot
148
+ ? path.join(dataRoot, "extensions")
149
+ : null;
150
+ if (!userDataDir || !extensionsDir) {
151
+ throw new TypeError("createCodeServerLaunch requires userDataDir and extensionsDir, or a shared dataRoot.");
152
+ }
153
+ return {
154
+ extensionsDir,
155
+ userDataDir,
156
+ };
157
+ }
158
+ async function resolveLaunchBinding(options) {
159
+ if (options.bindAddr && (options.host || options.port !== undefined)) {
160
+ throw new TypeError("Pass either bindAddr or host/port to createCodeServerLaunch, not both.");
161
+ }
162
+ if (options.bindAddr) {
163
+ const parsed = parseBindAddr(options.bindAddr);
164
+ const port = parsed.port === 0 ? await allocatePort(parsed.host) : parsed.port;
165
+ return {
166
+ bindAddr: formatBindAddr(parsed.host, port),
167
+ host: parsed.host,
168
+ port,
169
+ };
170
+ }
171
+ const host = normalizeHost(options.host);
172
+ const port = options.port == null || options.port === 0
173
+ ? await allocatePort(host)
174
+ : normalizePort(options.port);
175
+ return {
176
+ bindAddr: formatBindAddr(host, port),
177
+ host,
178
+ port,
179
+ };
180
+ }
181
+ function normalizeLaunchMode(requested, installation) {
182
+ if (requested === "direct" || requested === "node") {
183
+ return requested;
184
+ }
185
+ return installation.entryKind === "executable" ? "direct" : "node";
186
+ }
187
+ function normalizeTrustedOrigins(value) {
188
+ const normalized = [];
189
+ for (const origin of value ?? []) {
190
+ if (typeof origin !== "string")
191
+ continue;
192
+ const trimmed = origin.trim();
193
+ if (!trimmed || normalized.includes(trimmed))
194
+ continue;
195
+ normalized.push(trimmed);
196
+ }
197
+ return normalized;
198
+ }
199
+ function normalizeNodeCommand(value) {
200
+ const normalized = typeof value === "string" ? value.trim() : "";
201
+ return normalized || process.execPath;
202
+ }
203
+ function normalizeHost(value) {
204
+ const normalized = typeof value === "string" ? value.trim() : "";
205
+ return normalized || DEFAULT_BIND_HOST;
206
+ }
207
+ function normalizePort(value) {
208
+ if (!Number.isInteger(value) || value < 0 || value > 65535) {
209
+ throw new TypeError("Port must be an integer between 0 and 65535.");
210
+ }
211
+ return value;
212
+ }
213
+ function parseBindAddr(bindAddr) {
214
+ const normalized = bindAddr.trim();
215
+ const ipv6Match = /^\[(.+)\]:(\d+)$/.exec(normalized);
216
+ if (ipv6Match) {
217
+ return {
218
+ host: ipv6Match[1],
219
+ port: normalizePort(Number(ipv6Match[2])),
220
+ };
221
+ }
222
+ const lastColonIndex = normalized.lastIndexOf(":");
223
+ if (lastColonIndex <= 0) {
224
+ throw new TypeError("bindAddr must use host:port or [host]:port format.");
225
+ }
226
+ return {
227
+ host: normalized.slice(0, lastColonIndex),
228
+ port: normalizePort(Number(normalized.slice(lastColonIndex + 1))),
229
+ };
230
+ }
231
+ function formatBindAddr(host, port) {
232
+ return host.includes(":")
233
+ ? `[${host}]:${port}`
234
+ : `${host}:${port}`;
235
+ }
236
+ async function allocatePort(host) {
237
+ return await new Promise((resolve, reject) => {
238
+ const server = net.createServer();
239
+ server.once("error", (error) => {
240
+ reject(new CodeServerPortAllocationError("Could not allocate a code-server TCP port.", {
241
+ cause: error instanceof Error ? error.message : String(error),
242
+ host,
243
+ }));
244
+ });
245
+ server.listen(0, host, () => {
246
+ const address = server.address();
247
+ if (!address || typeof address === "string") {
248
+ server.close();
249
+ reject(new CodeServerPortAllocationError("Could not determine the allocated code-server TCP port.", {
250
+ host,
251
+ }));
252
+ return;
253
+ }
254
+ server.close((error) => {
255
+ if (error) {
256
+ reject(new CodeServerPortAllocationError("Could not release the allocated code-server TCP port.", {
257
+ cause: error.message,
258
+ host,
259
+ port: address.port,
260
+ }));
261
+ return;
262
+ }
263
+ resolve(address.port);
264
+ });
265
+ });
266
+ });
267
+ }
268
+ function assertDirectLaunchAvailable(entryPoint) {
269
+ try {
270
+ fs.accessSync(entryPoint, DIRECT_LAUNCH_ACCESS);
271
+ }
272
+ catch (error) {
273
+ throw new CodeServerBinaryNotFoundError("Resolved code-server entrypoint is not directly executable.", {
274
+ cause: error instanceof Error ? error.message : String(error),
275
+ entryPoint,
276
+ });
277
+ }
278
+ }
279
+ function wrapSpawnError(error, plan) {
280
+ const errorCode = typeof error === "object" && error && "code" in error
281
+ ? String(error.code)
282
+ : null;
283
+ if (errorCode === "ENOENT") {
284
+ return new CodeServerBinaryNotFoundError("Could not launch the resolved code-server command.", {
285
+ args: plan.args,
286
+ command: plan.command,
287
+ });
288
+ }
289
+ return error instanceof Error ? error : new Error(String(error));
290
+ }
291
+ export { createCodeServerLaunch, launchCodeServerProcess };
292
+ //# sourceMappingURL=launch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launch.js","sourceRoot":"","sources":["../src/launch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAU7D,MAAM,iBAAiB,GAAG,WAAW,CAAC;AACtC,MAAM,oBAAoB,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC;AAE/C,KAAK,UAAU,sBAAsB,CAAC,OAAgC;IACpE,MAAM,YAAY,GAAG,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2BAA2B,CAAC,UAAkB;IACrD,IAAI,CAAC;QACH,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,6BAA6B,CAAC,6DAA6D,EAAE;YACrG,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7D,UAAU;SACX,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,IAA0B;IAChE,MAAM,SAAS,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK;QACrE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;QACpB,CAAC,CAAC,IAAI,CAAC;IAET,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;QAC3B,OAAO,IAAI,6BAA6B,CAAC,oDAAoD,EAAE;YAC7F,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { CodeServerReadyOptions, CodeServerReadyResult } from "./types.js";
2
+ declare function waitForCodeServerReady(options: CodeServerReadyOptions): Promise<CodeServerReadyResult>;
3
+ export { waitForCodeServerReady };
4
+ //# sourceMappingURL=readiness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readiness.d.ts","sourceRoot":"","sources":["../src/readiness.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAyB,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAOvG,iBAAe,sBAAsB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA8CrG;AAiED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,97 @@
1
+ import net from "node:net";
2
+ import { CodeServerProcessExitedBeforeReadyError, CodeServerStartupTimeoutError, } from "./errors.js";
3
+ const DEFAULT_READY_HOST = "127.0.0.1";
4
+ const DEFAULT_READY_RETRY_INTERVAL_MS = 100;
5
+ const DEFAULT_READY_TIMEOUT_MS = 30000;
6
+ const CONNECT_ATTEMPT_TIMEOUT_MS = 400;
7
+ async function waitForCodeServerReady(options) {
8
+ const host = normalizeReadyHost(options.host);
9
+ const port = normalizeReadyPort(options.port);
10
+ const retryIntervalMs = normalizePositiveDuration(options.retryIntervalMs, DEFAULT_READY_RETRY_INTERVAL_MS);
11
+ const timeoutMs = normalizePositiveDuration(options.timeoutMs, DEFAULT_READY_TIMEOUT_MS);
12
+ const startedAt = Date.now();
13
+ let exitResult = null;
14
+ if (options.process) {
15
+ void options.process.exit.then((result) => {
16
+ exitResult = result;
17
+ });
18
+ }
19
+ while (Date.now() - startedAt < timeoutMs) {
20
+ if (exitResult) {
21
+ throw createExitedBeforeReadyError(host, port, exitResult, options.process);
22
+ }
23
+ const remainingMs = timeoutMs - (Date.now() - startedAt);
24
+ const connected = await canConnect(host, port, Math.min(CONNECT_ATTEMPT_TIMEOUT_MS, remainingMs));
25
+ if (connected) {
26
+ return {
27
+ elapsedMs: Date.now() - startedAt,
28
+ host,
29
+ port,
30
+ };
31
+ }
32
+ if (exitResult) {
33
+ throw createExitedBeforeReadyError(host, port, exitResult, options.process);
34
+ }
35
+ await sleep(Math.min(retryIntervalMs, Math.max(remainingMs, 0)));
36
+ }
37
+ throw new CodeServerStartupTimeoutError("Timed out waiting for code-server to accept TCP connections.", {
38
+ host,
39
+ port,
40
+ stderr: options.process?.getStderr(),
41
+ stdout: options.process?.getStdout(),
42
+ timeoutMs,
43
+ });
44
+ }
45
+ async function canConnect(host, port, timeoutMs) {
46
+ return await new Promise((resolve) => {
47
+ const socket = net.connect({
48
+ host,
49
+ port,
50
+ });
51
+ let settled = false;
52
+ const finish = (value) => {
53
+ if (settled)
54
+ return;
55
+ settled = true;
56
+ socket.destroy();
57
+ resolve(value);
58
+ };
59
+ socket.setTimeout(Math.max(timeoutMs, 1));
60
+ socket.once("connect", () => finish(true));
61
+ socket.once("error", () => finish(false));
62
+ socket.once("timeout", () => finish(false));
63
+ });
64
+ }
65
+ function createExitedBeforeReadyError(host, port, exitResult, process) {
66
+ return new CodeServerProcessExitedBeforeReadyError("code-server exited before the TCP port became ready.", {
67
+ code: exitResult.code,
68
+ host,
69
+ port,
70
+ signal: exitResult.signal,
71
+ stderr: process?.getStderr(),
72
+ stdout: process?.getStdout(),
73
+ });
74
+ }
75
+ function normalizeReadyHost(value) {
76
+ const normalized = typeof value === "string" ? value.trim() : "";
77
+ return normalized || DEFAULT_READY_HOST;
78
+ }
79
+ function normalizeReadyPort(value) {
80
+ if (!Number.isInteger(value) || value < 1 || value > 65535) {
81
+ throw new TypeError("waitForCodeServerReady requires a TCP port between 1 and 65535.");
82
+ }
83
+ return value;
84
+ }
85
+ function normalizePositiveDuration(value, fallback) {
86
+ if (value == null)
87
+ return fallback;
88
+ if (!Number.isFinite(value) || value <= 0) {
89
+ throw new TypeError("Readiness durations must be greater than zero.");
90
+ }
91
+ return Math.floor(value);
92
+ }
93
+ function sleep(durationMs) {
94
+ return new Promise((resolve) => setTimeout(resolve, durationMs));
95
+ }
96
+ export { waitForCodeServerReady };
97
+ //# sourceMappingURL=readiness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readiness.js","sourceRoot":"","sources":["../src/readiness.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,OAAO,EACL,uCAAuC,EACvC,6BAA6B,GAC9B,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;QAC1C,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAS,KAAK,CAAC,UAAkB;IAC/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { CodeServerInstallation, ResolveCodeServerInstallationOptions } from "./types.js";
2
+ declare function resolveCodeServerInstallation(options?: ResolveCodeServerInstallationOptions): CodeServerInstallation;
3
+ export { resolveCodeServerInstallation };
4
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAuB,sBAAsB,EAAE,oCAAoC,EAAE,MAAM,YAAY,CAAC;AAQpH,iBAAS,6BAA6B,CAAC,OAAO,GAAE,oCAAyC,GAAG,sBAAsB,CAuBjH;AAsGD,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
@@ -0,0 +1,120 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { createRequire } from "node:module";
4
+ import { CodeServerBinaryNotFoundError, CodeServerPackageResolutionError } from "./errors.js";
5
+ function resolveCodeServerInstallation(options = {}) {
6
+ const packageJsonPath = resolveCodeServerPackageJsonPath(options.resolveFrom);
7
+ const packageRoot = path.dirname(packageJsonPath);
8
+ const packageJson = readCodeServerPackageJson(packageJsonPath);
9
+ const entryRelativePath = resolveEntryRelativePath(packageJson);
10
+ const entryPoint = path.resolve(packageRoot, entryRelativePath);
11
+ if (!isFile(entryPoint)) {
12
+ throw new CodeServerBinaryNotFoundError("Resolved code-server entrypoint was not found.", {
13
+ entryPoint,
14
+ packageJsonPath,
15
+ packageRoot,
16
+ });
17
+ }
18
+ return {
19
+ entryKind: detectEntryKind(entryPoint),
20
+ entryPoint,
21
+ packageJsonPath,
22
+ packageRoot,
23
+ supportRoot: resolveSupportRoot(packageRoot),
24
+ version: typeof packageJson.version === "string" ? packageJson.version : undefined,
25
+ };
26
+ }
27
+ function resolveCodeServerPackageJsonPath(resolveFrom) {
28
+ const anchorPath = createResolutionAnchor(resolveFrom);
29
+ const requireFrom = createRequire(anchorPath);
30
+ try {
31
+ return requireFrom.resolve("code-server/package.json");
32
+ }
33
+ catch (error) {
34
+ throw new CodeServerPackageResolutionError("Could not resolve the installed code-server package.", {
35
+ cause: error instanceof Error ? error.message : String(error),
36
+ resolveFrom: resolveFrom ? path.resolve(resolveFrom) : process.cwd(),
37
+ });
38
+ }
39
+ }
40
+ function createResolutionAnchor(resolveFrom) {
41
+ const resolved = path.resolve(resolveFrom ?? process.cwd());
42
+ try {
43
+ const stats = fs.statSync(resolved);
44
+ return stats.isDirectory()
45
+ ? path.join(resolved, "__code_server_kit__.js")
46
+ : resolved;
47
+ }
48
+ catch {
49
+ return path.extname(resolved)
50
+ ? resolved
51
+ : path.join(resolved, "__code_server_kit__.js");
52
+ }
53
+ }
54
+ function readCodeServerPackageJson(packageJsonPath) {
55
+ try {
56
+ return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
57
+ }
58
+ catch (error) {
59
+ throw new CodeServerPackageResolutionError("Could not read the resolved code-server package metadata.", {
60
+ cause: error instanceof Error ? error.message : String(error),
61
+ packageJsonPath,
62
+ });
63
+ }
64
+ }
65
+ function resolveEntryRelativePath(packageJson) {
66
+ if (typeof packageJson.bin === "string" && packageJson.bin.trim()) {
67
+ return packageJson.bin;
68
+ }
69
+ if (packageJson.bin && typeof packageJson.bin === "object") {
70
+ const binPath = packageJson.bin["code-server"];
71
+ if (typeof binPath === "string" && binPath.trim()) {
72
+ return binPath;
73
+ }
74
+ }
75
+ if (typeof packageJson.main === "string" && packageJson.main.trim()) {
76
+ return packageJson.main;
77
+ }
78
+ throw new CodeServerPackageResolutionError("The installed code-server package does not expose a launch entrypoint.", {});
79
+ }
80
+ function detectEntryKind(entryPoint) {
81
+ const extension = path.extname(entryPoint).toLowerCase();
82
+ if (extension === ".cjs" || extension === ".js" || extension === ".mjs") {
83
+ return "node_script";
84
+ }
85
+ try {
86
+ const handle = fs.openSync(entryPoint, "r");
87
+ const buffer = Buffer.alloc(128);
88
+ const length = fs.readSync(handle, buffer, 0, buffer.length, 0);
89
+ fs.closeSync(handle);
90
+ const header = buffer.toString("utf8", 0, length);
91
+ return header.startsWith("#!") && header.includes("node")
92
+ ? "node_script"
93
+ : "executable";
94
+ }
95
+ catch {
96
+ return "executable";
97
+ }
98
+ }
99
+ function resolveSupportRoot(packageRoot) {
100
+ const supportRoot = path.join(packageRoot, "lib", "vscode");
101
+ return isDirectory(supportRoot) ? supportRoot : null;
102
+ }
103
+ function isDirectory(value) {
104
+ try {
105
+ return fs.statSync(value).isDirectory();
106
+ }
107
+ catch {
108
+ return false;
109
+ }
110
+ }
111
+ function isFile(value) {
112
+ try {
113
+ return fs.statSync(value).isFile();
114
+ }
115
+ catch {
116
+ return false;
117
+ }
118
+ }
119
+ export { resolveCodeServerInstallation };
120
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +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;AAS9F,SAAS,6BAA6B,CAAC,UAAgD,EAAE;IACvF,MAAM,eAAe,GAAG,gCAAgC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9E,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,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CAAC;IAAC,MAAM,CAAC;QACP,OAAO,YAAY,CAAC;IACtB,CAAC;AACH,CAAC;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,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"}
@@ -0,0 +1,86 @@
1
+ import type { ChildProcess } from "node:child_process";
2
+ type CodeServerEntryKind = "node_script" | "executable";
3
+ type CodeServerLaunchMode = "auto" | "direct" | "node";
4
+ type CodeServerInstallation = {
5
+ entryKind: CodeServerEntryKind;
6
+ entryPoint: string;
7
+ packageJsonPath: string;
8
+ packageRoot: string;
9
+ supportRoot: string | null;
10
+ version?: string;
11
+ };
12
+ type ResolveCodeServerInstallationOptions = {
13
+ resolveFrom?: string;
14
+ };
15
+ type CodeServerLaunchOptions = {
16
+ bindAddr?: string;
17
+ dataRoot?: string;
18
+ extensionsDir?: string;
19
+ host?: string;
20
+ installation?: CodeServerInstallation;
21
+ launchMode?: CodeServerLaunchMode;
22
+ nodeCommand?: string;
23
+ port?: number;
24
+ resolveFrom?: string;
25
+ trustedOrigins?: string[];
26
+ userDataDir?: string;
27
+ workspacePath?: string;
28
+ };
29
+ type CodeServerLaunchPlan = {
30
+ args: string[];
31
+ bindAddr: string;
32
+ codeServerPackageRoot: string;
33
+ command: string;
34
+ entryPoint: string;
35
+ extensionsDir: string;
36
+ host: string;
37
+ launchMode: Exclude<CodeServerLaunchMode, "auto">;
38
+ port: number;
39
+ supportRoot: string | null;
40
+ userDataDir: string;
41
+ workspacePath: string | null;
42
+ };
43
+ type CodeServerProcessExit = {
44
+ code: number | null;
45
+ signal: NodeJS.Signals | null;
46
+ };
47
+ type CodeServerProcessHandle = {
48
+ args: string[];
49
+ bindAddr: string;
50
+ child: ChildProcess;
51
+ codeServerPackageRoot: string;
52
+ command: string;
53
+ exit: Promise<CodeServerProcessExit>;
54
+ extensionsDir: string;
55
+ getStderr(): string;
56
+ getStdout(): string;
57
+ host: string;
58
+ kill(signal?: NodeJS.Signals | number): boolean;
59
+ launchMode: Exclude<CodeServerLaunchMode, "auto">;
60
+ pid: number | undefined;
61
+ port: number;
62
+ supportRoot: string | null;
63
+ userDataDir: string;
64
+ workspacePath: string | null;
65
+ };
66
+ type CodeServerReadyOptions = {
67
+ host?: string;
68
+ port: number;
69
+ process?: CodeServerProcessHandle;
70
+ retryIntervalMs?: number;
71
+ timeoutMs?: number;
72
+ };
73
+ type CodeServerReadyResult = {
74
+ elapsedMs: number;
75
+ host: string;
76
+ port: number;
77
+ };
78
+ type LaunchCodeServerProcessOptions = {
79
+ cwd?: string;
80
+ env?: NodeJS.ProcessEnv;
81
+ plan: CodeServerLaunchPlan;
82
+ stderr?(text: string): void;
83
+ stdout?(text: string): void;
84
+ };
85
+ export type { CodeServerEntryKind, CodeServerInstallation, CodeServerLaunchMode, CodeServerLaunchOptions, CodeServerLaunchPlan, CodeServerProcessExit, CodeServerProcessHandle, CodeServerReadyOptions, CodeServerReadyResult, LaunchCodeServerProcessOptions, ResolveCodeServerInstallationOptions, };
86
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0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AC,EAAE,uBAAuB,CAAC;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,YAAY,EACV,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,8BAA8B,EAC9B,oCAAoC,GACrC,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@trebired/code-server-kit",
3
+ "version": "0.1.0",
4
+ "description": "Framework-agnostic code-server launch kit for Node.js apps with installation resolution, launch planning, readiness checks, and process helpers.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "code-server",
8
+ "node",
9
+ "launcher",
10
+ "backend",
11
+ "integration"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/Trebired/code-server-kit"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/Trebired/code-server-kit/issues"
19
+ },
20
+ "homepage": "https://github.com/Trebired/code-server-kit#readme",
21
+ "type": "module",
22
+ "engines": {
23
+ "node": ">=22"
24
+ },
25
+ "private": false,
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "packageManager": "bun@1.3.12",
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "CHANGELOG.md",
41
+ "LICENSE",
42
+ "README.md"
43
+ ],
44
+ "scripts": {
45
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
46
+ "prepublishOnly": "bun run typecheck && bun test && bun run build",
47
+ "test": "bun test",
48
+ "typecheck": "tsc --noEmit"
49
+ },
50
+ "dependencies": {
51
+ "code-server": "^4.117.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/bun": "^1.3.4",
55
+ "@types/node": "^24.10.1",
56
+ "typescript": "^6.0.2"
57
+ }
58
+ }