@legendapp/spark 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/init-template.cjs +7 -1
  2. package/package.json +10 -5
  3. package/patches/dependencies.json +252 -0
  4. package/patches/expo-application@55.0.19.patch +54 -0
  5. package/patches/expo-blur@55.0.18.patch +130 -0
  6. package/patches/expo-device@55.0.21.patch +149 -0
  7. package/patches/expo-font@55.0.8.patch +55 -0
  8. package/patches/expo-glass-effect@55.0.11.patch +304 -0
  9. package/patches/expo-haptics@55.0.18.patch +54 -0
  10. package/patches/expo-image-manipulator@55.0.21.patch +312 -0
  11. package/patches/expo-image-picker@55.0.24.patch +327 -0
  12. package/patches/expo-image@55.0.11.patch +158 -0
  13. package/patches/expo-keep-awake@55.0.8.patch +41 -0
  14. package/patches/expo-localization@55.0.19.patch +32 -0
  15. package/patches/expo-location@55.1.15.patch +190 -0
  16. package/patches/expo-symbols@55.0.9.patch +286 -0
  17. package/patches/expo-system-ui@55.0.22.patch +61 -0
  18. package/patches/expo-web-browser@55.0.20.patch +13 -0
  19. package/patches/react-native-app-logs@0.3.1.patch +20 -0
  20. package/patches/react-native-blurhash@2.1.3.patch +318 -0
  21. package/patches/react-native-community-blur@4.4.1.patch +415 -0
  22. package/patches/react-native-community-datetimepicker@9.2.2.patch +320 -0
  23. package/patches/react-native-fast-image@10.9.9.patch +131 -0
  24. package/patches/react-native-graph@1.4.0.patch +157 -0
  25. package/patches/react-native-keyboard-controller@1.22.9.patch +16 -0
  26. package/patches/react-native-masked-view-masked-view@0.3.2.patch +140 -0
  27. package/patches/react-native-mmkv@4.3.2.patch +40 -0
  28. package/patches/react-native-nitro-fetch@1.9.0.patch +130 -0
  29. package/patches/react-native-nitro-zxing@0.3.0.patch +13 -0
  30. package/patches/react-native-nitro-zxing@0.3.1.patch +22 -0
  31. package/patches/react-native-quick-base64@3.0.1.patch +13 -0
  32. package/patches/react-native-quick-crypto@1.1.9.patch +31 -0
  33. package/patches/react-native-release-profiler@0.4.5.patch +37 -0
  34. package/patches/react-native-screen-corner-radius@0.2.3.patch +13 -0
  35. package/patches/react-native-screens@4.23.0.patch +160 -0
  36. package/patches/react-native-svg@15.15.3.patch +31 -0
  37. package/patches/react-native-unistyles@3.6.0.patch +203 -0
  38. package/patches/react-native-worklets-core@1.6.3.patch +13 -0
  39. package/patches/react-navigation-native-stack@7.21.0.patch +16 -0
  40. package/patches/registry.json +615 -0
  41. package/patches/sentry-react-native@8.32.0.patch +76 -0
  42. package/patches/workspace/expo-audio@55.0.18.patch +159 -0
  43. package/patches/workspace/op-engineering-op-sqlite@18.2.1.patch +796 -0
  44. package/patches/workspace/react-native-nitro-modules@0.37.0.patch +1348 -0
  45. package/patches/workspace/react-native-runtimes-core@0.1.0-alpha.2.patch +276 -0
  46. package/patches/workspace/react-native-webview@16.0.0.patch +208 -0
  47. package/postinstall.cjs +10 -1
  48. package/skills/spark/SKILL.md +37 -4
  49. package/skills/spark/UPGRADING.md +150 -1
  50. package/skills/spark/ai-customize.md +39 -0
  51. package/skills/spark/app-and-documents.md +56 -0
  52. package/skills/spark/external-libraries.md +87 -0
  53. package/skills/spark/files.md +64 -0
  54. package/skills/spark/integrations.md +69 -0
  55. package/skills/spark/keyboard.md +54 -0
  56. package/skills/spark/library-compat.md +76 -0
  57. package/skills/spark/menus-tray-dock.md +83 -0
  58. package/skills/spark/storage-settings.md +85 -0
  59. package/skills/spark/ui.md +57 -0
  60. package/skills/spark/windows.md +91 -0
  61. package/ui-popover.ts +1 -0
  62. package/ui-progress.ts +1 -0
  63. package/ui-sheet.ts +1 -0
  64. package/ui-split-view.ts +1 -0
  65. package/ui-table.ts +1 -0
  66. package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
  67. package/vendor/node_modules/@legendapp/spark-audio/package.json +3 -13
  68. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -10
  69. package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +5 -0
  70. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +139 -104
  71. package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +4 -1
  72. package/vendor/node_modules/@legendapp/spark-cli/dist/commands.js +16 -7
  73. package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +19 -3
  74. package/vendor/node_modules/@legendapp/spark-cli/dist/dev-command.js +2 -0
  75. package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +10 -2
  76. package/vendor/node_modules/@legendapp/spark-cli/dist/enriched-html-pins.js +2 -0
  77. package/vendor/node_modules/@legendapp/spark-cli/dist/errors.js +1 -1
  78. package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +57 -9
  79. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.cjs +12 -2
  80. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.d.cts +1 -1
  81. package/vendor/node_modules/@legendapp/spark-cli/dist/metro.cjs +1 -0
  82. package/vendor/node_modules/@legendapp/spark-cli/dist/migrate.js +65 -0
  83. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +4 -4
  84. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +2 -2
  85. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +15 -8
  86. package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +35 -7
  87. package/vendor/node_modules/@legendapp/spark-cli/dist/patch.js +92 -0
  88. package/vendor/node_modules/@legendapp/spark-cli/dist/project-version.js +12 -4
  89. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +20 -1
  90. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +20 -20
  91. package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-input-cache.js +140 -0
  92. package/vendor/node_modules/@legendapp/spark-cli/dist/upgrade.js +1 -1
  93. package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +3 -0
  94. package/vendor/node_modules/@legendapp/spark-cli/package.json +5 -4
  95. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
  96. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
  97. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
  98. package/vendor/node_modules/@legendapp/spark-clipboard/macos/RNDesktopClipboard.mm +1 -1
  99. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +3 -10
  100. package/vendor/node_modules/@legendapp/spark-clipboard/src/desktop.ts +1 -0
  101. package/vendor/node_modules/@legendapp/spark-codex/package.json +3 -7
  102. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  103. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +3 -10
  104. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.h +3 -1
  105. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +51 -10
  106. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.h +4 -0
  107. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.mm +82 -0
  108. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +64 -2
  109. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +2 -8
  110. package/vendor/node_modules/@legendapp/spark-desktop-config/autolinking.cjs +3 -2
  111. package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +6 -8
  112. package/vendor/node_modules/@legendapp/spark-desktop-config/identity.cjs +2 -0
  113. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +315 -68
  114. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +7 -0
  115. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
  116. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.cjs +318 -0
  117. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.d.cts +20 -0
  118. package/vendor/node_modules/@legendapp/spark-desktop-config/validation.cjs +66 -9
  119. package/vendor/node_modules/@legendapp/spark-desktop-config/windows.plugin.cjs +1 -0
  120. package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +1 -0
  121. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  122. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +3 -10
  123. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +3 -10
  124. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/RNDesktopWindows.mm +7 -2
  125. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +235 -240
  126. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +4 -11
  127. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/api.ts +9 -3
  128. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +7 -0
  129. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/types.ts +32 -3
  130. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/validation.ts +28 -11
  131. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/createWindowsNavigator.tsx +15 -3
  132. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/primaryWindowLifecycle.ts +12 -3
  133. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/usePrimaryWindowLifecycle.ts +2 -1
  134. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/useWindowFocusEffect.ts +4 -1
  135. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  136. package/vendor/node_modules/@legendapp/spark-drag-drop/macos/RNDesktopDragView.mm +77 -17
  137. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +3 -8
  138. package/vendor/node_modules/@legendapp/spark-drag-drop/src/DesktopDragViewNativeComponent.ts +1 -0
  139. package/vendor/node_modules/@legendapp/spark-drag-drop/src/contracts.ts +13 -4
  140. package/vendor/node_modules/@legendapp/spark-drag-drop/src/index.tsx +5 -3
  141. package/vendor/node_modules/@legendapp/spark-drag-drop/windows/SparkDragDrop/SparkDragDrop.h +6 -1
  142. package/vendor/node_modules/@legendapp/spark-expo-compat/metro.cjs +44 -0
  143. package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +20 -0
  144. package/vendor/node_modules/@legendapp/spark-expo-compat/src/clipboard.ts +40 -0
  145. package/vendor/node_modules/@legendapp/spark-expo-compat/src/document-picker.ts +52 -0
  146. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +3 -10
  147. package/vendor/node_modules/@legendapp/spark-file-dialog/src/options.ts +5 -2
  148. package/vendor/node_modules/@legendapp/spark-file-dialog/src/types.ts +3 -3
  149. package/vendor/node_modules/@legendapp/spark-file-system/macos/RNDesktopFileSystem.mm +1 -1
  150. package/vendor/node_modules/@legendapp/spark-file-system/package.json +3 -11
  151. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +3 -10
  152. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  153. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  154. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +3 -10
  155. package/vendor/node_modules/@legendapp/spark-message-dialog/src/index.ts +1 -0
  156. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +3 -9
  157. package/vendor/node_modules/@legendapp/spark-native-menu/src/hooks.ts +4 -0
  158. package/vendor/node_modules/@legendapp/spark-notifications/package.json +3 -10
  159. package/vendor/node_modules/@legendapp/spark-processes/package.json +3 -10
  160. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  161. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +3 -10
  162. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  163. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
  164. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  165. package/vendor/node_modules/@legendapp/spark-system/package.json +3 -10
  166. package/vendor/node_modules/@legendapp/spark-tray/package.json +3 -10
  167. package/vendor/node_modules/@legendapp/spark-tray/src/index.ts +2 -1
  168. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkButton.mm +82 -14
  169. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.h +1 -1
  170. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.mm +94 -11
  171. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +235 -18
  172. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.h +17 -0
  173. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.mm +216 -0
  174. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.h +4 -0
  175. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.mm +212 -0
  176. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewUpdates.h +6 -0
  177. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +26 -13
  178. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.h +9 -0
  179. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.mm +126 -0
  180. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.h +9 -0
  181. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.mm +66 -0
  182. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.h +9 -0
  183. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.mm +118 -0
  184. package/vendor/node_modules/@legendapp/spark-ui/macos/sf-symbol/RNSFSymbol.mm +4 -12
  185. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.h +9 -0
  186. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.mm +109 -0
  187. package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +418 -102
  188. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.h +9 -0
  189. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.mm +179 -0
  190. package/vendor/node_modules/@legendapp/spark-ui/package.json +9 -8
  191. package/vendor/node_modules/@legendapp/spark-ui/src/SparkButtonNativeComponent.ts +10 -2
  192. package/vendor/node_modules/@legendapp/spark-ui/src/SparkTextInputNativeComponent.ts +2 -0
  193. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +9 -0
  194. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitView.tsx +99 -0
  195. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitViewNativeComponent.ts +29 -0
  196. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +34 -17
  197. package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +5 -4
  198. package/vendor/node_modules/@legendapp/spark-ui/src/checkbox-unavailable.tsx +20 -0
  199. package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +24 -3
  200. package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +63 -13
  201. package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +12 -7
  202. package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +12 -7
  203. package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +35 -13
  204. package/vendor/node_modules/@legendapp/spark-ui/src/mobile-input.tsx +2 -2
  205. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSegmentedControlNativeComponent.ts +3 -1
  206. package/vendor/node_modules/@legendapp/spark-ui/src/popover/PopoverNativeComponent.ts +20 -0
  207. package/vendor/node_modules/@legendapp/spark-ui/src/popover/index.tsx +45 -0
  208. package/vendor/node_modules/@legendapp/spark-ui/src/progress/ProgressIndicatorNativeComponent.ts +13 -0
  209. package/vendor/node_modules/@legendapp/spark-ui/src/progress/index.tsx +32 -0
  210. package/vendor/node_modules/@legendapp/spark-ui/src/radio-group/RadioGroupNativeComponent.ts +17 -0
  211. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/SheetNativeComponent.ts +15 -0
  212. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/index.tsx +38 -0
  213. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarItemNativeComponent.ts +9 -1
  214. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarNativeComponent.ts +17 -2
  215. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/index.tsx +106 -22
  216. package/vendor/node_modules/@legendapp/spark-ui/src/table/TableNativeComponent.ts +22 -0
  217. package/vendor/node_modules/@legendapp/spark-ui/src/table/index.tsx +118 -0
  218. package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +39 -6
  219. package/vendor/node_modules/@legendapp/spark-ui/uniwind.ts +3 -1
  220. package/vendor/node_modules/@legendapp/spark-ui/uniwind.web.ts +2 -1
  221. package/vendor/node_modules/@legendapp/spark-ui/windows/SparkUI/SparkUI.h +46 -15
  222. package/vendor/node_modules/@legendapp/spark-updates/package.json +3 -9
  223. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  224. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
@@ -0,0 +1,140 @@
1
+ import { realpathSync, statSync, watch } from "node:fs";
2
+ import path from "node:path";
3
+ import { createRequire } from "node:module";
4
+ import { installedPackages, nativePackages } from "./project.js";
5
+ import { isExpoProject } from "@legendapp/spark-desktop-config/config.cjs";
6
+ /** Native compatibility inputs stay stable until a source or resolution path changes. */
7
+ export function createRuntimeInputCache(root) {
8
+ let value;
9
+ let dirty = true;
10
+ let disabled = false;
11
+ let watchers = [];
12
+ let resolutionPaths = new Map();
13
+ let observedRoots = "";
14
+ let readiness;
15
+ function identity(location) {
16
+ try {
17
+ const stat = statSync(location, { throwIfNoEntry: false });
18
+ return stat ? `${stat.dev}:${stat.ino}` : null;
19
+ }
20
+ catch (error) {
21
+ if (error.code === "ENOTDIR")
22
+ return null;
23
+ throw error;
24
+ }
25
+ }
26
+ function stop() {
27
+ clearImmediate(readiness);
28
+ readiness = undefined;
29
+ for (const watcher of watchers)
30
+ watcher.close();
31
+ watchers = [];
32
+ }
33
+ const invalidate = () => { dirty = true; };
34
+ function fail() {
35
+ disabled = true;
36
+ dirty = true;
37
+ stop();
38
+ }
39
+ const calculate = () => ({ native: nativePackages(root) });
40
+ function observe(installed) {
41
+ const realRoot = realpathSync(root);
42
+ const requested = new Map();
43
+ const add = (location, recursive) => {
44
+ const directory = realpathSync(location);
45
+ requested.set(directory, recursive || requested.get(directory) || false);
46
+ };
47
+ const paths = new Map();
48
+ for (const pkg of [{ root, json: {} }, ...installed]) {
49
+ add(pkg.root, true);
50
+ add(path.dirname(pkg.root), false);
51
+ const context = path.join(pkg.root, pkg.json.spark?.bundledModuleRoot ?? ".", "package.json");
52
+ for (const search of createRequire(context).resolve.paths("__spark_runtime_inputs__") ?? []) {
53
+ if (!paths.has(search)) {
54
+ const current = identity(search);
55
+ paths.set(search, current);
56
+ if (current !== null)
57
+ add(search, true);
58
+ }
59
+ }
60
+ }
61
+ const recursiveRoots = [...requested].filter(([, recursive]) => recursive).map(([directory]) => directory);
62
+ const roots = [...requested].filter(([directory]) => !recursiveRoots.some(parent => parent !== directory && directory.startsWith(parent + path.sep)));
63
+ const key = JSON.stringify(roots.map(([directory, recursive]) => [directory, recursive, identity(directory)]));
64
+ if (key === observedRoots) {
65
+ resolutionPaths = paths;
66
+ return;
67
+ }
68
+ const next = [];
69
+ try {
70
+ for (const [directory, recursive] of roots) {
71
+ const watcher = watch(directory, { recursive }, (_event, filename) => {
72
+ const relative = filename === null ? null : path.relative(realRoot, path.join(directory, String(filename))).split(path.sep).join("/");
73
+ // Session status is output of the check, never an input to it.
74
+ if (relative && /^\.spark\/(?:platforms\/[^/]+\/)?session\.json(?:\.\d+\.tmp)?$/.test(relative))
75
+ return;
76
+ invalidate();
77
+ });
78
+ watcher.on("error", fail);
79
+ next.push(watcher);
80
+ }
81
+ }
82
+ catch {
83
+ for (const watcher of next)
84
+ watcher.close();
85
+ fail();
86
+ return;
87
+ }
88
+ stop();
89
+ watchers = next;
90
+ resolutionPaths = paths;
91
+ observedRoots = key;
92
+ // A watch may start asynchronously. Recheck after its first event-loop turn.
93
+ readiness = setImmediate(() => { readiness = undefined; invalidate(); });
94
+ }
95
+ return {
96
+ invalidate,
97
+ read() {
98
+ // Expo configuration can depend on arbitrary external modules or environment.
99
+ if (disabled || isExpoProject(root))
100
+ return calculate();
101
+ if (!dirty) {
102
+ try {
103
+ // Installs can replace a watched directory before its event is delivered.
104
+ for (const [location, previous] of resolutionPaths) {
105
+ if (identity(location) !== previous) {
106
+ dirty = true;
107
+ break;
108
+ }
109
+ }
110
+ }
111
+ catch {
112
+ fail();
113
+ return calculate();
114
+ }
115
+ if (!dirty)
116
+ return value;
117
+ }
118
+ dirty = false;
119
+ try {
120
+ const installed = installedPackages(root);
121
+ try {
122
+ observe(installed);
123
+ }
124
+ catch {
125
+ fail();
126
+ }
127
+ value = calculate();
128
+ // A concurrent graph change needs a fresh set of source watches next poll.
129
+ if (JSON.stringify(installed) !== JSON.stringify(installedPackages(root)))
130
+ dirty = true;
131
+ return value;
132
+ }
133
+ catch (error) {
134
+ dirty = true;
135
+ throw error;
136
+ }
137
+ },
138
+ close() { disabled = true; stop(); },
139
+ };
140
+ }
@@ -91,7 +91,7 @@ export async function upgrade(root, dryRun = false) {
91
91
  const updatedCLI = cliRoot(installed);
92
92
  const { initializeTemplate } = createRequire(path.join(updatedCLI, "package.json"))("./dist/init-template.cjs");
93
93
  const { recordProjectVersion, refreshPointers } = createRequire(path.join(updatedCLI, "package.json"))("./dist/migrations.cjs");
94
- initializeTemplate(root);
94
+ initializeTemplate(root, false);
95
95
  refreshPointers(root);
96
96
  recordProjectVersion(root, version);
97
97
  console.log(`Updated Spark to ${version}.`);
@@ -1,3 +1,4 @@
1
+ import { ensurePatchRegistry } from "@legendapp/spark-desktop-config/patch-registry.cjs";
1
2
  import { which, nodeCommand } from "./process.js";
2
3
  import { prepareWindowsGeometry } from "./windows-geometry.js";
3
4
  import { copyHelpers } from "./helpers.js";
@@ -48,6 +49,7 @@ export async function preserveWindowsBuildOutputs(root, prepare) {
48
49
  }
49
50
  }
50
51
  export async function prepareWindows(root, mode) {
52
+ await ensurePatchRegistry(root);
51
53
  assertNativePatchPreflight(root);
52
54
  await checkExpoDesktopNode(root);
53
55
  prepareConfig(root);
@@ -77,6 +79,7 @@ export async function prepareWindows(root, mode) {
77
79
  export async function buildWindows(root, mode, force) {
78
80
  if (mode !== "go" && mode !== "dev")
79
81
  throw new Error("Windows currently supports Spark Runner runtimes and development builds. Use spark build --dev; production builds and packaging are not implemented.");
82
+ await ensurePatchRegistry(root);
80
83
  assertNativePatchPreflight(root);
81
84
  if (process.platform !== "win32")
82
85
  throw new Error("Windows native builds require Windows x64 or ARM64. Project generation and Metro bundle checks can run on macOS.");
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [
@@ -11,15 +11,16 @@
11
11
  "node": ">=24.19.0"
12
12
  },
13
13
  "dependencies": {
14
- "@legendapp/spark-desktop-config": "0.0.2",
14
+ "@legendapp/spark-desktop-config": "0.0.4",
15
15
  "ws": "8.21.0",
16
16
  "expo-desktop": "1.0.6",
17
17
  "npm": "11.21.1",
18
18
  "typescript": "5.9.3",
19
19
  "cross-spawn": "7.0.6",
20
- "@legendapp/spark-window-options": "0.0.2",
20
+ "@legendapp/spark-window-options": "0.0.4",
21
21
  "diff": "8.0.4",
22
- "yaml": "2.9.1"
22
+ "yaml": "2.9.1",
23
+ "@legendapp/spark-expo-compat": "0.0.4"
23
24
  },
24
25
  "private": true
25
26
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spark-template-blank-typescript",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": true,
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "postinstall": "node node_modules/@legendapp/spark/init-template.cjs"
14
14
  },
15
15
  "dependencies": {
16
- "@legendapp/spark": "0.0.2",
16
+ "@legendapp/spark": "0.0.4",
17
17
  "expo": "55.0.32",
18
18
  "expo-desktop": "1.0.6",
19
19
  "expo-desktop-prebuild-config": "1.1.3",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spark-template-universal",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": true,
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -41,7 +41,7 @@
41
41
  "react-native-web": "0.21.0",
42
42
  "uniwind": "1.6.3",
43
43
  "tailwindcss": "4.2.4",
44
- "@legendapp/spark": "0.0.2"
44
+ "@legendapp/spark": "0.0.4"
45
45
  },
46
46
  "overrides": {
47
47
  "expo": "55.0.32",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spark-template-windows",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": true,
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -28,7 +28,7 @@
28
28
  "react-native-windows": "0.83.2",
29
29
  "expo-desktop-modules-core": "55.0.2",
30
30
  "expo-desktop-stubs": "55.0.2",
31
- "@legendapp/spark": "0.0.2"
31
+ "@legendapp/spark": "0.0.4"
32
32
  },
33
33
  "overrides": {
34
34
  "expo": "55.0.32",
@@ -70,7 +70,7 @@ RCT_EXPORT_MODULE(NativeDesktopClipboard)
70
70
  if (item.types.count) [objects addObject:item];
71
71
  }
72
72
  [board clearContents]; if (objects.count && ![board writeObjects:objects]) { reject(@"E_CLIPBOARD", @"Could not write clipboard", nil); return; }
73
- resolve(@"null"); return;
73
+ resolve(binary ? NSNull.null : @"null"); return;
74
74
  }
75
75
  SparkInvalid(reject, @"Unknown clipboard operation");
76
76
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-clipboard",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "main": "src/index",
6
6
  "react-native": "src/index",
@@ -28,20 +28,13 @@
28
28
  },
29
29
  "spark": {
30
30
  "sdk": true,
31
- "nativeModules": [
32
- "NativeDesktopClipboard"
33
- ],
34
- "pod": "RNDesktopClipboard",
35
- "platforms": [
36
- "macos",
37
- "windows"
38
- ],
31
+ "nativeModules": true,
39
32
  "requires": [
40
33
  "@legendapp/spark-desktop-app"
41
34
  ]
42
35
  },
43
36
  "dependencies": {
44
- "@legendapp/spark-desktop-app": "0.0.2"
37
+ "@legendapp/spark-desktop-app": "0.0.4"
45
38
  },
46
39
  "peerDependenciesMeta": {
47
40
  "expo-clipboard": {
@@ -58,6 +58,7 @@ export async function writeClipboard(content: ClipboardWriteContent): Promise<vo
58
58
  const files = content.files?.map(path => nativePath(path, Platform.OS));
59
59
  const { image, ...rest } = content;
60
60
  if (image !== undefined && (!image || image.format !== "png" || !(image.bytes instanceof Uint8Array))) throw new SparkError("E_INVALID_ARGUMENT", "Expected PNG image bytes");
61
+ if (image !== undefined) for (const key of Object.keys(image)) if (key !== "format" && key !== "bytes") throw new SparkError("E_UNSUPPORTED_OPTION", `Unsupported clipboard image option: ${key}`);
61
62
  const response = await invokeNative(() => callBinary(native(), "__sparkClipboardBinary", "write", { ...rest, files }, image?.bytes));
62
63
  if (response !== null) throw new SparkError("E_INVALID_DATA", "Invalid native clipboard response");
63
64
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-codex",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": true,
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "license": "MIT",
12
12
  "dependencies": {
13
- "@legendapp/spark-desktop-app": "0.0.2",
13
+ "@legendapp/spark-desktop-app": "0.0.4",
14
14
  "react-native-nitro-modules": "0.37.0"
15
15
  },
16
16
  "files": [
@@ -23,11 +23,7 @@
23
23
  ],
24
24
  "spark": {
25
25
  "sdk": true,
26
- "nativeModules": [],
27
- "pod": "RNCodex",
28
- "platforms": [
29
- "macos"
30
- ],
26
+ "nativeModules": true,
31
27
  "requires": [
32
28
  "react-native-nitro-modules"
33
29
  ]
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-commands",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "main": "src/index.tsx",
@@ -8,11 +8,11 @@
8
8
  "src"
9
9
  ],
10
10
  "dependencies": {
11
- "@legendapp/spark-ui": "0.0.2",
12
- "@legendapp/spark-desktop-shortcuts": "0.0.2",
13
- "@legendapp/spark-settings": "0.0.2",
11
+ "@legendapp/spark-ui": "0.0.4",
12
+ "@legendapp/spark-desktop-shortcuts": "0.0.4",
13
+ "@legendapp/spark-settings": "0.0.4",
14
14
  "@legendapp/state": "^3.0.0-beta.42",
15
- "@legendapp/spark-desktop-app": "0.0.2"
15
+ "@legendapp/spark-desktop-app": "0.0.4"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "react": "^19.2.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-context-menu",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -28,20 +28,13 @@
28
28
  },
29
29
  "spark": {
30
30
  "sdk": true,
31
- "nativeModules": [
32
- "NativeContextMenu"
33
- ],
34
- "pod": "RNContextMenu",
35
- "platforms": [
36
- "macos",
37
- "windows"
38
- ],
31
+ "nativeModules": true,
39
32
  "requires": [
40
33
  "@legendapp/spark-desktop-app"
41
34
  ]
42
35
  },
43
36
  "dependencies": {
44
- "@legendapp/spark-desktop-app": "0.0.2"
37
+ "@legendapp/spark-desktop-app": "0.0.4"
45
38
  },
46
39
  "private": true
47
40
  }
@@ -3,7 +3,7 @@
3
3
  #import <React/RCTBridgeModule.h>
4
4
 
5
5
  FOUNDATION_EXPORT NSString * const SparkDesktopEvent;
6
- // Call in applicationWillFinishLaunching:. YES: this process owns the project's
6
+ // Call in applicationWillFinishLaunching:. YES: this process owns the app's
7
7
  // instance. NO: another process does; this one forwards its launch and exits.
8
8
  FOUNDATION_EXPORT BOOL SparkAcquireInstance(void);
9
9
  // Latched on first call during launch: --spark-safe-mode, or Shift held at launch.
@@ -15,6 +15,8 @@ FOUNDATION_EXPORT void SparkRelaunch(NSArray<NSString *> *arguments, void (^comp
15
15
  FOUNDATION_EXPORT NSDictionary *SparkContext(void);
16
16
  FOUNDATION_EXPORT NSDictionary *SparkInitialProps(NSString *windowID, NSDictionary *props);
17
17
  FOUNDATION_EXPORT NSString *SparkNamespace(void);
18
+ FOUNDATION_EXPORT NSString *SparkStorageNamespace(void);
19
+ FOUNDATION_EXPORT void SparkPrepareStorage(void);
18
20
  FOUNDATION_EXPORT void SparkEmit(NSDictionary *event);
19
21
  FOUNDATION_EXPORT void SparkOpenURLs(NSArray<NSURL *> *urls);
20
22
  FOUNDATION_EXPORT NSArray *SparkPendingURLs(void);
@@ -2,6 +2,7 @@
2
2
  #import "SparkDesktopError.h"
3
3
  #import "SparkQuitCoordinator.h"
4
4
  #import "SparkInstance.h"
5
+ #import "SparkStorage.h"
5
6
  #import "SparkTestDriver.h"
6
7
  #import <sys/wait.h>
7
8
  #import <CommonCrypto/CommonDigest.h>
@@ -26,6 +27,14 @@ void SparkInvalid(RCTPromiseRejectBlock reject, NSString *message) { reject(@"E_
26
27
  void SparkReject(RCTPromiseRejectBlock reject, NSError *error) {
27
28
  reject(SparkDesktopErrorCode(error), error.localizedDescription ?: @"Native operation failed", error);
28
29
  }
30
+ static NSString *SparkHashedNamespace(NSString *identifier) {
31
+ NSData *data = [identifier dataUsingEncoding:NSUTF8StringEncoding];
32
+ unsigned char hash[CC_SHA256_DIGEST_LENGTH];
33
+ CC_SHA256(data.bytes, (CC_LONG)data.length, hash);
34
+ NSMutableString *result = [NSMutableString stringWithString:@"spark.desktop."];
35
+ for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) [result appendFormat:@"%02x", hash[i]];
36
+ return result;
37
+ }
29
38
  NSDictionary *SparkContext(void) {
30
39
  static NSDictionary *context;
31
40
  static dispatch_once_t once;
@@ -57,14 +66,29 @@ NSDictionary *SparkContext(void) {
57
66
  });
58
67
  return context;
59
68
  }
60
- NSString *SparkNamespace(void) {
61
- NSString *project = SparkContext()[@"projectId"];
62
- NSData *data = [project dataUsingEncoding:NSUTF8StringEncoding];
63
- unsigned char hash[CC_SHA256_DIGEST_LENGTH];
64
- CC_SHA256(data.bytes, (CC_LONG)data.length, hash);
65
- NSMutableString *result = [NSMutableString stringWithString:@"spark.desktop."];
66
- for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) [result appendFormat:@"%02x", hash[i]];
67
- return result;
69
+ NSString *SparkNamespace(void) { return SparkHashedNamespace(SparkContext()[@"projectId"]); }
70
+ static NSString *SparkBundleIdentifier(void) {
71
+ NSString *identifier = NSBundle.mainBundle.bundleIdentifier;
72
+ if (!identifier.length || [identifier containsString:@"/"] || [identifier isEqual:@"."] || [identifier isEqual:@".."]) {
73
+ [NSException raise:NSInvalidArgumentException format:@"Spark requires a valid CFBundleIdentifier"];
74
+ }
75
+ return identifier;
76
+ }
77
+ static NSString *SparkConfiguredBundleIdentifier(void) {
78
+ #if DEBUG
79
+ if ([SparkContext()[@"runtime"][@"mode"] isEqual:@"go"]) return NSProcessInfo.processInfo.environment[@"SPARK_PROJECT_BUNDLE_IDENTIFIER"];
80
+ #endif
81
+ return [NSBundle.mainBundle objectForInfoDictionaryKey:@"SparkDefaultBundleIdentifier"];
82
+ }
83
+ NSString *SparkStorageNamespace(void) {
84
+ NSString *value = [SparkBundleIdentifier() stringByAppendingPathComponent:@"Spark"];
85
+ if ([SparkContext()[@"runtime"][@"mode"] isEqual:@"go"]) value = [value stringByAppendingPathComponent:SparkNamespace()];
86
+ return value;
87
+ }
88
+ static NSString *SparkInstanceNamespace(void) {
89
+ NSString *identifier = SparkBundleIdentifier();
90
+ if ([SparkContext()[@"runtime"][@"mode"] isEqual:@"go"]) identifier = [identifier stringByAppendingFormat:@":%@", SparkContext()[@"projectId"]];
91
+ return SparkHashedNamespace(identifier);
68
92
  }
69
93
  NSDictionary *SparkInitialProps(NSString *windowID, NSDictionary *props) {
70
94
  NSMutableDictionary *result = [SparkContext() mutableCopy];
@@ -153,7 +177,7 @@ static void SparkForwardLaunch(void) {
153
177
  for (NSURL *url in forwardedURLs) { if (url.isFileURL) [files addObject:url.path]; else [urls addObject:url.absoluteString]; }
154
178
  NSDictionary *launch = @{ @"arguments": NSProcessInfo.processInfo.arguments, @"workingDirectory": NSFileManager.defaultManager.currentDirectoryPath ?: @"/", @"files": files, @"urls": urls };
155
179
  NSError *error;
156
- if (!SparkInstanceForward(NSTemporaryDirectory(), SparkNamespace(), launch, 10, &error)) SparkLaunchFailed(@"The running app did not accept this launch", error);
180
+ if (!SparkInstanceForward(NSTemporaryDirectory(), SparkInstanceNamespace(), launch, 10, &error)) SparkLaunchFailed(@"The running app did not accept this launch", error);
157
181
  exit(0);
158
182
  }];
159
183
  }
@@ -172,6 +196,23 @@ NSDictionary *SparkLaunchState(void) {
172
196
  return @{ @"safeMode": SparkSafeMode() ? safeModeTrigger : NSNull.null, @"relaunched": @(relaunched),
173
197
  @"instance": instanceOwner ? @"primary" : @"test-driver" };
174
198
  }
199
+ void SparkPrepareStorage(void) {
200
+ NSError *error = nil;
201
+ NSFileManager *fm = NSFileManager.defaultManager;
202
+ NSURL *base = [fm URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error];
203
+ if (!base) SparkLaunchFailed(@"Unable to locate the app storage directory", error);
204
+ NSMutableOrderedSet<NSURL *> *legacy = [NSMutableOrderedSet orderedSetWithObject:[base URLByAppendingPathComponent:SparkNamespace() isDirectory:YES]];
205
+ if (![SparkContext()[@"runtime"][@"mode"] isEqual:@"go"]) {
206
+ NSString *name = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"] ?: [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleName"];
207
+ if ([name containsString:@"/"] || [name isEqual:@"."] || [name isEqual:@".."]) {
208
+ SparkLaunchFailed(@"Unable to migrate legacy app storage", [NSError errorWithDomain:@"SparkStorage" code:1 userInfo:@{ NSLocalizedDescriptionKey: @"The legacy display name must be a single directory name. Migrate its data explicitly." }]);
209
+ }
210
+ if (name.length) [legacy addObject:[base URLByAppendingPathComponent:name isDirectory:YES]];
211
+ }
212
+ SparkMigrateStorage([base URLByAppendingPathComponent:SparkStorageNamespace() isDirectory:YES], legacy.array,
213
+ SparkBundleIdentifier(), SparkConfiguredBundleIdentifier(), &error);
214
+ if (error) SparkLaunchFailed(@"Unable to prepare the app's storage", error);
215
+ }
175
216
  BOOL SparkAcquireInstance(void) {
176
217
  SparkSafeMode();
177
218
  NSString *parent = NSProcessInfo.processInfo.environment[@"SPARK_RELAUNCH_PARENT"];
@@ -182,7 +223,7 @@ BOOL SparkAcquireInstance(void) {
182
223
  // The previous instance holds the lock until it exits; it kills this process if its quit is vetoed.
183
224
  if (!SparkInstanceWaitForExit(parent.intValue, &error)) SparkLaunchFailed(@"Unable to relaunch", error);
184
225
  }
185
- instanceOwner = SparkInstanceAcquire(NSTemporaryDirectory(), SparkNamespace(), ^(NSDictionary *launch) { SparkReceiveLaunch(launch); }, &error);
226
+ instanceOwner = SparkInstanceAcquire(NSTemporaryDirectory(), SparkInstanceNamespace(), ^(NSDictionary *launch) { SparkReceiveLaunch(launch); }, &error);
186
227
  if (error) SparkLaunchFailed(@"Unable to establish the app instance lock", error);
187
228
  if (!instanceOwner) SparkForwardLaunch();
188
229
  return instanceOwner;
@@ -0,0 +1,4 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ BOOL SparkMigrateStorage(NSURL *destination, NSArray<NSURL *> *legacyDirectories,
4
+ NSString *bundleIdentifier, NSString *configuredIdentifier, NSError **error);
@@ -0,0 +1,82 @@
1
+ #import "SparkStorage.h"
2
+ #import <sys/stdio.h>
3
+ #import <errno.h>
4
+
5
+ static NSString * const SparkStorageOwnerFile = @".spark-bundle-identifier";
6
+ static BOOL SparkStorageFail(NSError **error, NSString *message) {
7
+ if (error) *error = [NSError errorWithDomain:@"SparkStorage" code:1 userInfo:@{ NSLocalizedDescriptionKey: message }];
8
+ return NO;
9
+ }
10
+ static BOOL SparkStorageDirectory(NSURL *url, BOOL *exists, NSError **error) {
11
+ NSDictionary *attributes = [NSFileManager.defaultManager attributesOfItemAtPath:url.path error:error];
12
+ if (!attributes) {
13
+ if ([(*error).domain isEqual:NSCocoaErrorDomain] && ((*error).code == NSFileNoSuchFileError || (*error).code == NSFileReadNoSuchFileError)) { *error = nil; *exists = NO; return YES; }
14
+ return NO;
15
+ }
16
+ *exists = YES;
17
+ return [attributes[NSFileType] isEqual:NSFileTypeDirectory] || SparkStorageFail(error, [@"Expected a storage directory, not a file or symlink: " stringByAppendingString:url.path]);
18
+ }
19
+ static NSString *SparkStorageOwner(NSURL *directory, NSError **error) {
20
+ NSURL *marker = [directory URLByAppendingPathComponent:SparkStorageOwnerFile];
21
+ NSString *owner = [NSString stringWithContentsOfURL:marker encoding:NSUTF8StringEncoding error:error];
22
+ if (!owner && [(*error).domain isEqual:NSCocoaErrorDomain] && (*error).code == NSFileReadNoSuchFileError) *error = nil;
23
+ if (owner && !owner.length) SparkStorageFail(error, [@"Invalid storage owner marker: " stringByAppendingString:marker.path]);
24
+ return owner;
25
+ }
26
+ static BOOL SparkStorageClaim(NSURL *directory, NSString *bundleIdentifier, NSError **error) {
27
+ NSString *owner = SparkStorageOwner(directory, error);
28
+ if (*error) return NO;
29
+ if (!owner) {
30
+ NSFileManager *fm = NSFileManager.defaultManager;
31
+ NSURL *marker = [directory URLByAppendingPathComponent:SparkStorageOwnerFile];
32
+ NSURL *temporary = [directory URLByAppendingPathComponent:[@".spark-owner-" stringByAppendingString:NSUUID.UUID.UUIDString]];
33
+ NSData *data = [bundleIdentifier dataUsingEncoding:NSUTF8StringEncoding];
34
+ if (![data writeToURL:temporary options:NSDataWritingAtomic error:error]) return NO;
35
+ // Link a complete marker without replacing a concurrent owner's claim.
36
+ BOOL claimed = [fm linkItemAtURL:temporary toURL:marker error:error];
37
+ NSError *cleanup;
38
+ if (![fm removeItemAtURL:temporary error:&cleanup]) NSLog(@"Unable to remove storage owner staging file %@: %@", temporary.path, cleanup);
39
+ if (claimed) owner = bundleIdentifier;
40
+ else {
41
+ if (![(*error).domain isEqual:NSCocoaErrorDomain] || (*error).code != NSFileWriteFileExistsError) return NO;
42
+ *error = nil;
43
+ owner = SparkStorageOwner(directory, error);
44
+ if (*error) return NO;
45
+ }
46
+ }
47
+ return [owner isEqual:bundleIdentifier] || SparkStorageFail(error, [@"Storage belongs to another bundle: " stringByAppendingString:directory.path]);
48
+ }
49
+ BOOL SparkMigrateStorage(NSURL *destination, NSArray<NSURL *> *legacyDirectories,
50
+ NSString *bundleIdentifier, NSString *configuredIdentifier, NSError **error) {
51
+ NSError *__autoreleasing failure = nil;
52
+ if (!error) error = &failure;
53
+ *error = nil;
54
+ NSFileManager *fm = NSFileManager.defaultManager;
55
+ BOOL exists;
56
+ if (!SparkStorageDirectory(destination, &exists, error)) return NO;
57
+ if (exists) return SparkStorageClaim(destination, bundleIdentifier, error);
58
+ NSURL *source = nil;
59
+ for (NSURL *legacy in legacyDirectories) {
60
+ if ([legacy isEqual:destination]) continue;
61
+ if (!SparkStorageDirectory(legacy, &exists, error)) return NO;
62
+ if (!exists) continue;
63
+ NSString *owner = SparkStorageOwner(legacy, error);
64
+ if (*error) return NO;
65
+ if (!owner && !configuredIdentifier.length)
66
+ return SparkStorageFail(error, @"Unmarked storage needs SparkDefaultBundleIdentifier from a rebuilt custom host, or macos.bundleIdentifier supplied by the current Go CLI. Configure/rebuild the app or migrate explicitly.");
67
+ if (owner ? ![owner isEqual:bundleIdentifier] : ![configuredIdentifier isEqual:bundleIdentifier]) continue;
68
+ if (source) return SparkStorageFail(error, @"Multiple legacy storage directories need migration. Resolve them explicitly before launching the app.");
69
+ source = legacy;
70
+ }
71
+ if (![fm createDirectoryAtURL:destination.URLByDeletingLastPathComponent withIntermediateDirectories:YES attributes:nil error:error]) return NO;
72
+ if (!source) return [fm createDirectoryAtURL:destination withIntermediateDirectories:NO attributes:nil error:error] && SparkStorageClaim(destination, bundleIdentifier, error);
73
+ if ([destination.path hasPrefix:[source.path stringByAppendingString:@"/"]])
74
+ return SparkStorageFail(error, @"Legacy storage contains the destination. Resolve its data layout explicitly before launching the app.");
75
+ if (!SparkStorageClaim(source, bundleIdentifier, error)) return NO;
76
+ // Both paths are in Application Support. Rename the owned folder atomically so
77
+ // clearing the new store cannot resurrect an old snapshot on the next launch.
78
+ if (renamex_np(source.fileSystemRepresentation, destination.fileSystemRepresentation, RENAME_EXCL) == 0) return YES;
79
+ int code = errno;
80
+ *error = [NSError errorWithDomain:NSPOSIXErrorDomain code:code userInfo:@{ NSFilePathErrorKey: source.path }];
81
+ return NO;
82
+ }