fix(setup): preserve configuration directory requirements

This commit is contained in:
morluto committed 2026-10-27 13:14:50 +08:00
1 parent 235e8bc056
commit 01a725ecfa
4 files changed
+52 -10

No files matched your search

+8 -1
View File
@@ -74,10 +74,17 @@ const canonicalRegularConfigPath = async (
): Promise<string | undefined> => {
if (fileSystem.realpath === undefined) return requestedPath;
let ancestor = absoluteCallerPath(requestedPath);
const directoryRequired =
process.platform !== "win32" && ancestor.endsWith("/");
const missing: string[] = [];
while (true) {
try {
return join(await fileSystem.realpath(ancestor), ...missing);
const canonical = join(await fileSystem.realpath(ancestor), ...missing);
// Reconstructing missing children must retain the caller's directory
// requirement; otherwise a missing `config.json/` becomes a writable file.
return directoryRequired && !canonical.endsWith("/")
? `${canonical}/`
: canonical;
} catch (cause: unknown) {
if (!isAbsentPath(cause) || dirname(ancestor) === ancestor)
return requestedPath;