Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apps/server/src/cli/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
Effect.result,
);

it.effect("keeps leading spaces only in a relative startup directory", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-cwd-spaces-" });
const resolveCwd = (cwd: string) =>
resolveServerConfig({ ...minimalWebFlags(baseDir), cwd: Option.some(cwd) }, Option.none(), {
prepareDirectories: false,
}).pipe(
Effect.provide(
Layer.merge(
NetService.layer,
ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
),
),
Effect.map((config) => config.cwd),
);
expect(yield* resolveCwd(" project ")).toBe(path.resolve(" project"));
const absolute = path.join(baseDir, "project");
expect(yield* resolveCwd(` ${absolute} `)).toBe(absolute);
}),
);

it.effect("refuses a manual web launch while a lock-aware server owns the T3 home", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
Expand Down
16 changes: 14 additions & 2 deletions apps/server/src/cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ const loadPersistedObservabilitySettings = Effect.fn(function* (settingsPath: st
return parsePersistedServerObservabilitySettings(raw);
});

export const normalizeServerCwdArgument = Effect.fn("config.normalizeServerCwdArgument")(function* (
argument: string,
) {
const cwd = argument.trimEnd();
const trimmed = cwd.trimStart();
if (cwd === trimmed || trimmed === "." || trimmed === "..") return trimmed;
const path = yield* Path.Path;
return path.parse(yield* expandHomePath(trimmed)).root === "" ? cwd : trimmed;
});

export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(function* (
flags: CliServerFlags,
cliLogLevel: Option.Option<LogLevel.LogLevel>,
Expand Down Expand Up @@ -328,8 +338,10 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
resolveOptionPrecedence(explicitBaseDir, Option.fromUndefinedOr(bootstrap?.t3Home)),
),
);
const rawCwd = Option.getOrElse(normalizedFlags.cwd, () => process.cwd());
const cwd = path.resolve(yield* expandHomePath(rawCwd.trim()));
const rawCwd = Option.isSome(normalizedFlags.cwd)
? yield* normalizeServerCwdArgument(normalizedFlags.cwd.value)
: process.cwd().trim();
const cwd = path.resolve(yield* expandHomePath(rawCwd));
const derivedPaths = yield* ServerConfig.deriveServerPaths(baseDir, devUrl, {
baseDirIsExplicit: Option.isSome(explicitBaseDir),
});
Expand Down
9 changes: 7 additions & 2 deletions apps/server/src/cli/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import { stopOnLauncherLoss } from "../launcherWatch.ts";
import * as DatabaseMaintenance from "../persistence/DatabaseMaintenance.ts";
import * as ProcessRunner from "../processRunner.ts";
import * as AutomaticPort from "./automaticPort.ts";
import { type CliServerFlags, resolveServerConfig, sharedServerCommandFlags } from "./config.ts";
import {
type CliServerFlags,
normalizeServerCwdArgument,
resolveServerConfig,
sharedServerCommandFlags,
} from "./config.ts";

const encodeCommand = Schema.encodeEffect(Schema.fromJsonString(Schema.String));

Expand Down Expand Up @@ -47,7 +52,7 @@ const runServerCommand = Effect.fnUntraced(function* (

export const runDefaultServerCommand = Effect.fnUntraced(function* (flags: CliServerFlags) {
if (Option.isSome(flags.cwd)) {
const cwd = flags.cwd.value.trim();
const cwd = yield* normalizeServerCwdArgument(flags.cwd.value);
const fs = yield* FileSystem.FileSystem;
const platform = yield* HostProcess.Platform;
const explicitPath =
Expand Down
Loading