Skip to content

Commit a69b270

Browse files
committed
fix(cli): limit drive prefixes to windows hosts
1 parent fb9c334 commit a69b270

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎apps/server/src/cli/app.test.ts‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,18 @@ describe("t3 server command safety", () => {
139139
withTempDirectory("t3-cli-unknown-", (root) =>
140140
Effect.gen(function* () {
141141
const baseDir = NodePath.join(root, "home");
142-
for (const word of ["account", "login", "clients", "conenct", "package.json"]) {
143-
const error = yield* runCli([word, "--base-dir", baseDir]).pipe(Effect.flip);
142+
for (const word of [
143+
"account",
144+
"login",
145+
"clients",
146+
"conenct",
147+
"package.json",
148+
"C:new-project",
149+
]) {
150+
const error = yield* runCli([word, "--base-dir", baseDir]).pipe(
151+
Effect.provideService(HostProcessPlatform, "linux"),
152+
Effect.flip,
153+
);
144154
expect(String(error)).toContain(`Unknown command "${word}"`);
145155
expect(yield* pathExists(word)).toBe(word === "package.json");
146156
expect(yield* pathExists(baseDir)).toBe(false);
@@ -177,6 +187,7 @@ describe("t3 server command safety", () => {
177187
yield* Effect.promise(() => NodeFSP.mkdir(stateDir, { recursive: true }));
178188
yield* Effect.promise(() => NodeFSP.writeFile(statePath, record));
179189
const newDirectory = NodePath.join(root, "new-project");
190+
const platform = yield* HostProcessPlatform;
180191
for (const args of [
181192
[],
182193
["start"],
@@ -186,7 +197,13 @@ describe("t3 server command safety", () => {
186197
[newDirectory],
187198
["start", newDirectory],
188199
]) {
189-
const error = yield* runCli(args, { T3CODE_HOME: baseDir }).pipe(Effect.flip);
200+
const error = yield* runCli(args, { T3CODE_HOME: baseDir }).pipe(
201+
Effect.provideService(
202+
HostProcessPlatform,
203+
args[0] === "C:new-project" ? "win32" : platform,
204+
),
205+
Effect.flip,
206+
);
190207
expect(String(error)).toContain("A T3 Code server is already running");
191208
expect(yield* Effect.promise(() => NodeFSP.readFile(statePath, "utf8"))).toBe(record);
192209
expect(yield* pathExists(newDirectory)).toBe(false);

‎apps/server/src/cli/server.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
12
import * as Effect from "effect/Effect";
23
import * as FileSystem from "effect/FileSystem";
34
import * as Option from "effect/Option";
@@ -34,7 +35,13 @@ export const runDefaultServerCommand = (flags: CliServerFlags) =>
3435
if (Option.isSome(flags.cwd)) {
3536
const cwd = flags.cwd.value.trim();
3637
const fs = yield* FileSystem.FileSystem;
37-
const explicitPath = cwd === "." || cwd === ".." || cwd === "~" || /[/\\]|^[a-z]:/i.test(cwd);
38+
const platform = yield* HostProcessPlatform;
39+
const explicitPath =
40+
cwd === "." ||
41+
cwd === ".." ||
42+
cwd === "~" ||
43+
/[/\\]/.test(cwd) ||
44+
(platform === "win32" && /^[a-z]:/i.test(cwd));
3845
if (
3946
!explicitPath &&
4047
(!(yield* fs.exists(cwd)) || (yield* fs.stat(cwd)).type !== "Directory")

0 commit comments

Comments
 (0)