Skip to content

Commit c4882c7

Browse files
authored
Merge pull request #1609 from appwrite/fix/cli-open-browser-windows-url
Fix CLI Windows browser launch and bump console SDK
2 parents eb46dc4 + 5614c8b commit c4882c7

6 files changed

Lines changed: 40 additions & 15 deletions

File tree

templates/cli/bun.lock.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"": {
66
"name": "{{ language.params.npmPackage|caseDash }}",
77
"dependencies": {
8-
"@appwrite.io/console": "^15.1.0",
8+
"@appwrite.io/console": "^15.1.1",
99
"@napi-rs/keyring": "^1.3.0",
1010
"chalk": "4.1.2",
1111
"chokidar": "^3.6.0",
@@ -52,7 +52,7 @@
5252
"tmp": "^0.2.6",
5353
},
5454
"packages": {
55-
"@appwrite.io/console": ["@appwrite.io/console@15.1.0", "", { "dependencies": { "json-bigint": "1.0.0" } }, "sha512-uQ8can9vDKoP6zxqhp8JzOYma/w40eKuYzZzsI9ATCRHSzRig0WQ6fue8rZEgOuD3eF3S2GbtHZK4drotAT8Ug=="],
55+
"@appwrite.io/console": ["@appwrite.io/console@15.1.1", "", { "dependencies": { "json-bigint": "1.0.0" } }, "sha512-W4t9xNuHoNUYGypcZtgPaHvuS/AFjSdDDleeNQl3cWMiOrS9wasVyIwygAHeQjis9evwPC4WUbfpx8WWYXijDg=="],
5656

5757
"@babel/runtime": ["@babel/runtime@7.29.7", "", {}, "sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw=="],
5858

templates/cli/lib/utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,8 @@ export function openBrowser(url: string): void {
830830

831831
switch (process.platform) {
832832
case "win32":
833-
command = "cmd";
834-
// "" is start's window-title arg; quoting the URL stops cmd from
835-
// splitting it on `&` (and running the remainder as a command).
836-
args = ["/c", "start", "", `"${url}"`];
833+
command = "rundll32";
834+
args = ["url.dll,FileProtocolHandler", url];
837835
break;
838836
case "darwin":
839837
command = "open";

templates/cli/package-lock.json.twig

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

templates/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"windows-arm64": "esbuild cli.ts --bundle --loader:.hbs=text --platform=node --target=node18 --format=esm --external:fsevents --external:terminal-image --outfile=dist/bundle-win-arm64.mjs && pkg dist/bundle-win-arm64.mjs --fallback-to-source -t node18-win-arm64 -o build/appwrite-cli-win-arm64.exe"
4949
},
5050
"dependencies": {
51-
"@appwrite.io/console": "^15.1.0",
51+
"@appwrite.io/console": "^15.1.1",
5252
"@napi-rs/keyring": "^1.3.0",
5353
"chalk": "4.1.2",
5454
"chokidar": "^3.6.0",

templates/cli/package.json.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"windows-arm64": "bun build cli.ts --compile --minify --target=bun-windows-arm64 --outfile build/appwrite-cli-win-arm64.exe"
5252
},
5353
"dependencies": {
54-
"@appwrite.io/console": "^15.1.0",
54+
"@appwrite.io/console": "^15.1.1",
5555
"@napi-rs/keyring": "^1.3.0",
5656
"chalk": "4.1.2",
5757
"chokidar": "^3.6.0",

tests/e2e/languages/cli/test.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,14 +1146,13 @@ async function runAuthChecks() {
11461146
assert.ok(captured, "expected openBrowser to spawn an open command");
11471147
const expectedCommand =
11481148
process.platform === "win32"
1149-
? "cmd"
1149+
? "rundll32"
11501150
: process.platform === "darwin"
11511151
? "open"
11521152
: "xdg-open";
11531153
assert.equal(captured.command, expectedCommand);
1154-
// win32 quotes the URL arg, so match by substring rather than equality.
11551154
assert.ok(
1156-
captured.args.some((arg) => arg.includes(url)),
1155+
captured.args.includes(url),
11571156
"expected the verification URL to be passed to the open command",
11581157
);
11591158

@@ -1168,6 +1167,34 @@ async function runAuthChecks() {
11681167
};
11691168
assert.doesNotThrow(() => openBrowser(url));
11701169

1170+
const originalPlatform = process.platform;
1171+
try {
1172+
Object.defineProperty(process, "platform", {
1173+
value: "win32",
1174+
});
1175+
1176+
const windowsUrl =
1177+
"https://cloud.appwrite.io/device?user=a b&next=one|two<three>four^five";
1178+
captured = null;
1179+
childProcess.spawn = (command, args) => {
1180+
captured = { command, args };
1181+
return {
1182+
on() {},
1183+
unref() {},
1184+
};
1185+
};
1186+
1187+
openBrowser(windowsUrl);
1188+
assert.deepEqual(captured, {
1189+
command: "rundll32",
1190+
args: ["url.dll,FileProtocolHandler", windowsUrl],
1191+
});
1192+
} finally {
1193+
Object.defineProperty(process, "platform", {
1194+
value: originalPlatform,
1195+
});
1196+
}
1197+
11711198
const listeners = new Map();
11721199
const stdin = process.stdin;
11731200
const originalIsTTY = stdin.isTTY;

0 commit comments

Comments
 (0)