diff --git a/packages/cli/src/utils/privateProjectFile.ts b/packages/cli/src/utils/privateProjectFile.ts
index bd6c1c71fc..d167e62767 100644
--- a/packages/cli/src/utils/privateProjectFile.ts
+++ b/packages/cli/src/utils/privateProjectFile.ts
@@ -29,15 +29,18 @@ function isUnder(path: string, ...dir: string[]): boolean {
return lowerPath === lowerDir || lowerPath.startsWith(`${lowerDir}${sep}`);
}
+const CLOUD_DRIVE_FOLDERS = ["Mobile Documents", "CloudStorage"];
+
function homeAppDataFolder(path: string): string | null {
if (isUnder(path, "AppData")) return "AppData";
- if (isUnder(path, "Library") && !isUnder(path, "Library", "Mobile Documents")) return "Library";
+ const cloudDrive = CLOUD_DRIVE_FOLDERS.some((folder) => isUnder(path, "Library", folder));
+ if (isUnder(path, "Library") && !cloudDrive) return "Library";
return null;
}
function inHomeAppData(projectDir: string, path: string): boolean {
const folder = homeAppDataFolder(path);
- return folder !== null && !isUnder(projectDir, folder);
+ return folder !== null && homeAppDataFolder(projectDir) !== folder;
}
/** An existing file outside the project that publish leaves out: env files, Git data, hidden, system and app-data folders. */
diff --git a/packages/cli/src/utils/publishProject.absolutePath.test.ts b/packages/cli/src/utils/publishProject.absolutePath.test.ts
index a8ac045d6e..0ead0caa5c 100644
--- a/packages/cli/src/utils/publishProject.absolutePath.test.ts
+++ b/packages/cli/src/utils/publishProject.absolutePath.test.ts
@@ -271,6 +271,56 @@ describe("a reference to a file outside the project in a private location", () =
}
});
+ it("leaves out a Library file referenced by a project on iCloud Drive", () => {
+ const home = temp();
+ vi.stubEnv("HOME", home);
+ vi.stubEnv("USERPROFILE", home);
+ try {
+ const drive = join(home, "Library", "Mobile Documents", "com~apple~CloudDocs");
+ const token = join(home, "Library", "Application Support", "app", "token.json");
+ mkdirSync(join(drive, "p"), { recursive: true });
+ mkdirSync(dirname(token), { recursive: true });
+ writeFileSync(token, "KEY");
+ writeFileSync(join(drive, "p", "index.html"), `
`);
+ const warnings: string[] = [];
+ const staged = stagePublishFiles(join(drive, "p"), Infinity, (w) => warnings.push(w));
+ expect([...staged.keys()].some((key) => key.startsWith("_ext/"))).toBe(false);
+ expect(warnings).toHaveLength(1);
+ } finally {
+ vi.unstubAllEnvs();
+ }
+ });
+
+ it("treats Library/CloudStorage like iCloud Drive, in both directions", () => {
+ const home = temp();
+ vi.stubEnv("HOME", home);
+ vi.stubEnv("USERPROFILE", home);
+ try {
+ const dropbox = join(home, "Library", "CloudStorage", "Dropbox");
+ const token = join(home, "Library", "Application Support", "app", "token.json");
+ const logo = join(dropbox, "shared", "logo.png");
+ for (const file of [token, logo]) {
+ mkdirSync(dirname(file), { recursive: true });
+ writeFileSync(file, "x");
+ }
+ mkdirSync(join(dropbox, "p"));
+ writeFileSync(join(dropbox, "p", "index.html"), `
`);
+ const inDrive: string[] = [];
+ const fromDrive = stagePublishFiles(join(dropbox, "p"), Infinity, (w) => inDrive.push(w));
+ expect([...fromDrive.keys()].some((key) => key.startsWith("_ext/"))).toBe(false);
+ expect(inDrive).toHaveLength(1);
+
+ const project = temp();
+ writeFileSync(join(project, "index.html"), `
`);
+ const outside: string[] = [];
+ const toDrive = stagePublishFiles(project, Infinity, (w) => outside.push(w));
+ expect([...toDrive.keys()].filter((key) => key.startsWith("_ext/"))).toHaveLength(1);
+ expect(outside).toEqual([]);
+ } finally {
+ vi.unstubAllEnvs();
+ }
+ });
+
it("still copies a sibling asset folder named library or AppData outside the home folder", () => {
const { ext, warnings } = stageIn("p", {
"library/logo.png": "png",