fix(cli): publish leaves out private files outside the project and says so (#7577)

* fix(cli): publish leaves out private files outside the project and says so

A project you open may come from someone else, and its markup can point at
files outside the project folder. Publish and cloud render now leave out an
outside file that sits in a hidden folder (any path segment starting with a
dot past the folders the project itself sits in) or under /etc, /proc, /sys
or /dev, checked both as written and after resolving links.

Whenever an outside reference is left out, for this reason or because it is
an env file or Git data, the CLI now prints which project file holds the
reference and the reference as written. Other outside references are copied
into _ext/ as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): feedback's repro publish also names files it leaves out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): publish also leaves out project links to private outside files, and AppData/Library

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): only the home folder's AppData and Library count as private

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): a referenced project link to a private outside file stays out too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): resolve both paths the same way and skip AppData/Library when the project sits there

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
James Russo
2026-11-12 01:57:56 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent ab66e5bd72
commit b4bd8b0739
6 changed files with 320 additions and 20 deletions
+51 -1
View File
@@ -1,4 +1,5 @@
import { relative } from "node:path";
import { homedir } from "node:os";
import { isAbsolute, join, relative, sep } from "node:path";
import { isPrivateProjectFile, realFilePath } from "@hyperframes/studio-server/safe-path";
const ENV_FILE = /^\.env([._-].*|rc)?$/;
@@ -8,6 +9,55 @@ export function isEnvOrGitPath(path: string): boolean {
return segments.includes(".git") || ENV_FILE.test(segments.at(-1) ?? "");
}
const SYSTEM_DIRS = ["/etc", "/proc", "/sys", "/dev", "/private/etc"];
function inPrivateLocation(projectDir: string, path: string): boolean {
const posixPath = path.replaceAll("\\", "/");
if (SYSTEM_DIRS.some((dir) => posixPath === dir || posixPath.startsWith(`${dir}/`))) return true;
const segmentsPastProjectFolders = relative(projectDir, path)
.split(/[\\/]/)
.filter((segment) => segment !== "..");
return (
segmentsPastProjectFolders.some((segment) => segment.startsWith(".")) ||
inHomeAppData(projectDir, path)
);
}
function isUnder(path: string, ...dir: string[]): boolean {
const lowerPath = path.toLowerCase();
const lowerDir = join(homedir(), ...dir).toLowerCase();
return lowerPath === lowerDir || lowerPath.startsWith(`${lowerDir}${sep}`);
}
function homeAppDataFolder(path: string): string | null {
if (isUnder(path, "AppData")) return "AppData";
if (isUnder(path, "Library") && !isUnder(path, "Library", "Mobile Documents")) return "Library";
return null;
}
function inHomeAppData(projectDir: string, path: string): boolean {
const folder = homeAppDataFolder(path);
return folder !== null && !isUnder(projectDir, folder);
}
/** An existing file outside the project that publish leaves out: env files, Git data, hidden, system and app-data folders. */
export function isPrivateOutsideFile(projectDir: string, absPath: string): boolean {
const realPath = realFilePath(absPath);
return (
isEnvOrGitPath(absPath) ||
isEnvOrGitPath(realPath) ||
inPrivateLocation(projectDir, absPath) ||
inPrivateLocation(realFilePath(projectDir), realPath)
);
}
export function linksToPrivateOutsideFile(projectDir: string, filePath: string): boolean {
const fromProject = relative(realFilePath(projectDir), realFilePath(filePath));
const outside =
fromProject === ".." || fromProject.startsWith(`..${sep}`) || isAbsolute(fromProject);
return outside && isPrivateOutsideFile(projectDir, filePath);
}
/** Project files no composition loads, so none is served or uploaded for one: env files, Git data, tool records. */
export function isPrivateCompositionFile(projectDir: string, filePath: string): boolean {
return (