Skip to content

Commit 575ffe5

Browse files
committed
fix: windows compatibility issues
1 parent 6aa7277 commit 575ffe5

9 files changed

Lines changed: 60 additions & 18 deletions

File tree

lib/code.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
44
import { fileURLToPath } from "node:url";
55

66
// Auto-updated by scripts/pack.ts
7-
const codeArchiveHash = "8e9eb27319d3a38c";
7+
const codeArchiveHash = "6969db4c56cd12e7";
88

99
const archivePath = fileURLToPath(new URL("./code.tar.zst", import.meta.url));
1010

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@vscode/tree-sitter-wasm": "^0.3.0",
3939
"@vscode/vscode-languagedetection": "1.0.23",
4040
"@vscode/windows-process-tree": "workspace:*",
41-
"@vscode/windows-registry": "^1.2.0",
41+
"@vscode/windows-registry": "workspace:*",
4242
"@xterm/addon-clipboard": "^0.3.0-beta.191",
4343
"@xterm/addon-image": "^0.10.0-beta.191",
4444
"@xterm/addon-ligatures": "^0.11.0-beta.191",

lib/src/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { readdirSync, readFileSync, unlinkSync } from "node:fs";
44
import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http";
55
import { join } from "node:path";
66
import type { Duplex } from "node:stream";
7+
import { pathToFileURL } from "node:url";
78
import { createProxyServer } from "httpxy";
89
import { serveStatic } from "./static.ts";
910
import type { VSCodeServerOptions } from "./types.ts";
@@ -129,7 +130,7 @@ export async function createCodeServer(
129130
if (args.length === 2 && typeof args[1] === "string" && !args[1].trim()) return;
130131
_log(...args);
131132
};
132-
const mod = await import(join(vsRootPath, "out/server-main.js"));
133+
const mod = await import(pathToFileURL(join(vsRootPath, "out/server-main.js")).href);
133134
// Override product branding from upstream "code-server" to "coderaft"
134135
const _product = (globalThis as Record<string, unknown>)._VSCODE_PRODUCT_JSON as
135136
| Record<string, unknown>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@vscode/ripgrep": "workspace:*",
4141
"@vscode/spdlog": "workspace:*",
4242
"@vscode/windows-process-tree": "workspace:*",
43+
"@vscode/windows-registry": "workspace:*",
4344
"argon2": "workspace:*",
4445
"fsevents": "workspace:*",
4546
"kerberos": "workspace:*",

pnpm-lock.yaml

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/ssh.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,34 @@ REMOTE_PORT="${REMOTE_PORT:-$(shuf -i 10000-65000 -n 1)}"
2929
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
3030
REMOTE_DIR="coderaft"
3131

32+
# Detect remote OS (Windows vs POSIX) — on Windows, default SSH shell is cmd.exe
33+
# which doesn't understand `~`, `mkdir -p`, or `VAR=value cmd` syntax.
34+
REMOTE_OS="$(ssh -p "$SSH_PORT" "$SSH_HOST" "uname -s 2>/dev/null || ver" 2>/dev/null)"
35+
case "$REMOTE_OS" in
36+
*Windows*|*Microsoft*) IS_WINDOWS=1 ;;
37+
*) IS_WINDOWS=0 ;;
38+
esac
39+
3240
echo "=> Syncing lib/ and shims/ to $SSH_HOST:~/$REMOTE_DIR/..."
33-
tar -C "$ROOT_DIR" --no-xattrs -h -cf - lib/ shims/ | ssh -p "$SSH_PORT" "$SSH_HOST" "mkdir -p ~/$REMOTE_DIR && tar -C ~/$REMOTE_DIR -xf -"
41+
if [ "$IS_WINDOWS" = "1" ]; then
42+
# Prepare remote dir & wipe stale sources in a separate ssh call so stdin
43+
# of the second call is cleanly consumed only by `tar -xf -`.
44+
ssh -p "$SSH_PORT" "$SSH_HOST" "if not exist \"%USERPROFILE%\\$REMOTE_DIR\" mkdir \"%USERPROFILE%\\$REMOTE_DIR\"" || exit 1
45+
ssh -p "$SSH_PORT" "$SSH_HOST" "if exist \"%USERPROFILE%\\$REMOTE_DIR\\lib\\src\" rmdir /S /Q \"%USERPROFILE%\\$REMOTE_DIR\\lib\\src\"" || true
46+
ssh -p "$SSH_PORT" "$SSH_HOST" "if exist \"%USERPROFILE%\\$REMOTE_DIR\\shims\" rmdir /S /Q \"%USERPROFILE%\\$REMOTE_DIR\\shims\"" || true
47+
# tar.exe ships with Windows 10+ and understands `-xf -` from stdin.
48+
tar -C "$ROOT_DIR" --no-xattrs -h -cf - lib/ shims/ | ssh -p "$SSH_PORT" "$SSH_HOST" "tar -C \"%USERPROFILE%\\$REMOTE_DIR\" -xf -" || exit 1
49+
# Verify a known file reached the remote with the expected content.
50+
ssh -p "$SSH_PORT" "$SSH_HOST" "findstr /C:\"pathToFileURL\" \"%USERPROFILE%\\$REMOTE_DIR\\lib\\src\\server.ts\" >nul && echo sync-verified || echo sync-WARN-old-server-ts"
51+
else
52+
tar -C "$ROOT_DIR" --no-xattrs -h -cf - lib/ shims/ | ssh -p "$SSH_PORT" "$SSH_HOST" "mkdir -p ~/$REMOTE_DIR && tar -C ~/$REMOTE_DIR -xf -"
53+
fi
3454

3555
echo "=> Starting server on remote port $REMOTE_PORT (forwarding to localhost:$PORT and localhost:$REMOTE_PORT)..."
36-
ssh -t -p "$SSH_PORT" -L "$PORT:localhost:$REMOTE_PORT" -L "$REMOTE_PORT:localhost:$REMOTE_PORT" "$SSH_HOST" \
37-
"DEBUG=* node ~/$REMOTE_DIR/lib/src/cli.ts ~/$REMOTE_DIR --port $REMOTE_PORT $*"
56+
if [ "$IS_WINDOWS" = "1" ]; then
57+
ssh -t -p "$SSH_PORT" -L "$PORT:localhost:$REMOTE_PORT" -L "$REMOTE_PORT:localhost:$REMOTE_PORT" "$SSH_HOST" \
58+
"set DEBUG=* && node \"%USERPROFILE%\\$REMOTE_DIR\\lib\\src\\cli.ts\" \"%USERPROFILE%\\$REMOTE_DIR\" --port $REMOTE_PORT $*"
59+
else
60+
ssh -t -p "$SSH_PORT" -L "$PORT:localhost:$REMOTE_PORT" -L "$REMOTE_PORT:localhost:$REMOTE_PORT" "$SSH_HOST" \
61+
"DEBUG=* node ~/$REMOTE_DIR/lib/src/cli.ts ~/$REMOTE_DIR --port $REMOTE_PORT $*"
62+
fi

shims/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This directory contains workspace packages that replace native/heavy dependencie
1616
- [`parcel-watcher/`](./parcel-watcher/) — Replaces [`@parcel/watcher`](https://github.com/parcel-bundler/watcher) (native C++ file watcher with node-gyp) with Node.js built-in `fs.watch` (recursive mode). Trades snapshot/history features for zero native binaries.
1717
- [`fsevents/`](./fsevents/) — No-op shim for [`fsevents`](https://github.com/fsevents/fsevents) (macOS-only native FSEvents binding). Consumers already fall back to `fs.watch`/polling when unavailable.
1818
- [`windows-process-tree/`](./windows-process-tree/) — Replaces [`@vscode/windows-process-tree`](https://github.com/nicedoc/windows-process-tree) (Windows-only native addon) with cross-platform process inspection using `ps` (Unix) / `wmic` (Windows).
19+
- [`vscode-windows-registry/`](./vscode-windows-registry/) — Stub for [`@vscode/windows-registry`](https://www.npmjs.com/package/@vscode/windows-registry) (native C++ registry addon with unbuilt `binding.gyp`). Only used by VS Code's telemetry/machine-id code (`GetStringRegKey("HKEY_LOCAL_MACHINE", …, "MachineId")`); callers already handle errors and fall back to defaults.
1920
- [`argon2/`](./argon2/) — Replaces [`argon2`](https://github.com/ranisalt/node-argon2) (native C binding) with Node.js `crypto.scrypt`. Encodes/decodes PHC-format hashes for compatibility with existing stored passwords.
2021
- [`vscode-proxy-agent/`](./vscode-proxy-agent/) — No-op shim for [`@vscode/proxy-agent`](https://github.com/microsoft/vscode-proxy-agent) (proxy resolver with heavy deps: `undici`, `socks-proxy-agent`, `http-proxy-agent`, etc.). Passes through Node.js native `http`/`https`/`net`/`tls` unmodified. Users behind a proxy can rely on `HTTP_PROXY`/`HTTPS_PROXY` env vars.
2122
- [`1ds-core-js/`](./1ds-core-js/) — No-op shim for [`@microsoft/1ds-core-js`](https://www.npmjs.com/package/@microsoft/1ds-core-js) (Microsoft 1DS telemetry core). Silently drops all telemetry events. Also eliminates transitive deps: `@microsoft/applicationinsights-core-js`, `@microsoft/dynamicproto-js`, `@microsoft/applicationinsights-shims`.
@@ -42,6 +43,7 @@ The mappings configured in root [`package.json`](../package.json):
4243
| `@parcel/watcher` | `shims/parcel-watcher/` |
4344
| `fsevents` | `shims/fsevents/` |
4445
| `@vscode/windows-process-tree` | `shims/windows-process-tree/` |
46+
| `@vscode/windows-registry` | `shims/vscode-windows-registry/`|
4547
| `argon2` | `shims/argon2/` |
4648
| `@vscode/proxy-agent` | `shims/vscode-proxy-agent/` |
4749
| `@microsoft/1ds-core-js` | `shims/1ds-core-js/` |
@@ -60,11 +62,7 @@ Remaining `.node` binaries in `lib/node_modules` (after shimming):
6062
| `ms-vscode.js-debug` (ext) | ~460K | win32-x64 + win32-arm64 | bundled |
6163
| `microsoft-authentication` (ext) | ~400K | linux-x64 only | bundled |
6264

63-
All other native packages (`@github/copilot`, `@vscode/spdlog`, `@vscode/native-watchdog`, `@vscode/windows-process-tree`, `@vscode/deviceid`, `@parcel/watcher`, `fsevents`, `argon2`, `kerberos`) are fully shimmed with zero native binaries.
64-
65-
### Packages with `binding.gyp` but no compiled binaries
66-
67-
- `@vscode/windows-registry` — not built
65+
All other native packages (`@github/copilot`, `@vscode/spdlog`, `@vscode/native-watchdog`, `@vscode/windows-process-tree`, `@vscode/windows-registry`, `@vscode/deviceid`, `@parcel/watcher`, `fsevents`, `argon2`, `kerberos`) are fully shimmed with zero native binaries.
6866

6967
### Notes
7068

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// JS shim for `@vscode/windows-registry` (native C++ addon with unbuilt node-gyp sources).
2+
// Used only by VS Code's telemetry/machine-id code on Windows, e.g.
3+
// `GetStringRegKey("HKEY_LOCAL_MACHINE", ..., "MachineId")`.
4+
// The real addon has no prebuilt binary, so calls would crash with
5+
// "Cannot find module '../build/Release/winregistry.node'". Every call site
6+
// in VS Code already handles errors / empty returns, so we throw from each
7+
// entry point — callers fall back to their own defaults.
8+
9+
function unavailable() {
10+
throw new Error("@vscode/windows-registry native addon is not available in coderaft");
11+
}
12+
13+
exports.GetStringRegKey = unavailable;
14+
exports.GetDWORDRegKey = unavailable;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@vscode/windows-registry",
3+
"version": "1.2.0",
4+
"private": true,
5+
"main": "./index.js"
6+
}

0 commit comments

Comments
 (0)