@legendapp/spark 0.0.3 → 0.0.5

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 (202) hide show
  1. package/init-template.cjs +7 -1
  2. package/package.json +11 -6
  3. package/patches/dependencies.json +4 -4
  4. package/patches/react-native-mmkv@4.3.2.patch +2 -2
  5. package/patches/react-native-nitro-zxing@0.3.1.patch +22 -0
  6. package/patches/registry.json +615 -0
  7. package/patches/workspace/expo-audio@55.0.18.patch +159 -0
  8. package/patches/workspace/op-engineering-op-sqlite@18.2.1.patch +796 -0
  9. package/patches/workspace/react-native-nitro-modules@0.37.0.patch +1348 -0
  10. package/patches/workspace/react-native-runtimes-core@0.1.0-alpha.2.patch +276 -0
  11. package/patches/workspace/react-native-webview@16.0.0.patch +208 -0
  12. package/postinstall.cjs +10 -1
  13. package/skills/spark/SKILL.md +37 -4
  14. package/skills/spark/UPGRADING.md +174 -1
  15. package/skills/spark/ai-customize.md +39 -0
  16. package/skills/spark/app-and-documents.md +56 -0
  17. package/skills/spark/external-libraries.md +87 -0
  18. package/skills/spark/files.md +64 -0
  19. package/skills/spark/integrations.md +69 -0
  20. package/skills/spark/keyboard.md +54 -0
  21. package/skills/spark/library-compat.md +76 -0
  22. package/skills/spark/menus-tray-dock.md +83 -0
  23. package/skills/spark/storage-settings.md +59 -0
  24. package/skills/spark/ui.md +83 -0
  25. package/skills/spark/windows.md +91 -0
  26. package/ui-popover.ts +1 -0
  27. package/ui-progress.ts +1 -0
  28. package/ui-sheet.ts +1 -0
  29. package/ui-split-view.ts +1 -0
  30. package/ui-table.ts +1 -0
  31. package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
  32. package/vendor/node_modules/@legendapp/spark-audio/package.json +3 -13
  33. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -10
  34. package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +5 -0
  35. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +157 -106
  36. package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +4 -1
  37. package/vendor/node_modules/@legendapp/spark-cli/dist/commands.js +16 -7
  38. package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +19 -3
  39. package/vendor/node_modules/@legendapp/spark-cli/dist/dev-command.js +2 -0
  40. package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +3 -0
  41. package/vendor/node_modules/@legendapp/spark-cli/dist/enriched-html-pins.js +2 -0
  42. package/vendor/node_modules/@legendapp/spark-cli/dist/errors.js +1 -1
  43. package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +57 -9
  44. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.cjs +12 -2
  45. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.d.cts +1 -1
  46. package/vendor/node_modules/@legendapp/spark-cli/dist/metro.cjs +1 -0
  47. package/vendor/node_modules/@legendapp/spark-cli/dist/migrate.js +65 -0
  48. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +4 -4
  49. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +2 -2
  50. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +15 -8
  51. package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +35 -7
  52. package/vendor/node_modules/@legendapp/spark-cli/dist/package.js +4 -8
  53. package/vendor/node_modules/@legendapp/spark-cli/dist/patch.js +92 -0
  54. package/vendor/node_modules/@legendapp/spark-cli/dist/project-version.js +12 -4
  55. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +8 -1
  56. package/vendor/node_modules/@legendapp/spark-cli/dist/publish-directory.js +32 -0
  57. package/vendor/node_modules/@legendapp/spark-cli/dist/release-app.js +139 -0
  58. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +17 -17
  59. package/vendor/node_modules/@legendapp/spark-cli/dist/signing.js +61 -41
  60. package/vendor/node_modules/@legendapp/spark-cli/dist/upgrade.js +1 -1
  61. package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +3 -0
  62. package/vendor/node_modules/@legendapp/spark-cli/package.json +5 -4
  63. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
  64. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
  65. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
  66. package/vendor/node_modules/@legendapp/spark-clipboard/macos/RNDesktopClipboard.mm +1 -1
  67. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +3 -10
  68. package/vendor/node_modules/@legendapp/spark-clipboard/src/desktop.ts +1 -0
  69. package/vendor/node_modules/@legendapp/spark-codex/package.json +3 -7
  70. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  71. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +3 -10
  72. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.h +3 -1
  73. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +51 -10
  74. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.h +4 -0
  75. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.mm +82 -0
  76. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.h +2 -0
  77. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +1 -0
  78. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +2 -8
  79. package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +1 -0
  80. package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +6 -8
  81. package/vendor/node_modules/@legendapp/spark-desktop-config/identity.cjs +2 -0
  82. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +300 -71
  83. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +7 -0
  84. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
  85. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.cjs +318 -0
  86. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.d.cts +20 -0
  87. package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.cjs +20 -0
  88. package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.d.cts +1 -0
  89. package/vendor/node_modules/@legendapp/spark-desktop-config/validation.cjs +66 -9
  90. package/vendor/node_modules/@legendapp/spark-desktop-config/windows.plugin.cjs +1 -0
  91. package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +17 -5
  92. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  93. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +3 -10
  94. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +3 -10
  95. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/RNDesktopWindows.mm +7 -2
  96. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +235 -240
  97. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +4 -11
  98. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/api.ts +9 -3
  99. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +7 -0
  100. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/types.ts +32 -3
  101. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/validation.ts +28 -11
  102. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/createWindowsNavigator.tsx +15 -3
  103. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/primaryWindowLifecycle.ts +12 -3
  104. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/usePrimaryWindowLifecycle.ts +2 -1
  105. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/useWindowFocusEffect.ts +4 -1
  106. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  107. package/vendor/node_modules/@legendapp/spark-drag-drop/macos/RNDesktopDragView.mm +77 -17
  108. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +3 -8
  109. package/vendor/node_modules/@legendapp/spark-drag-drop/src/DesktopDragViewNativeComponent.ts +1 -0
  110. package/vendor/node_modules/@legendapp/spark-drag-drop/src/contracts.ts +13 -4
  111. package/vendor/node_modules/@legendapp/spark-drag-drop/src/index.tsx +5 -3
  112. package/vendor/node_modules/@legendapp/spark-drag-drop/windows/SparkDragDrop/SparkDragDrop.h +6 -1
  113. package/vendor/node_modules/@legendapp/spark-expo-compat/metro.cjs +44 -0
  114. package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +20 -0
  115. package/vendor/node_modules/@legendapp/spark-expo-compat/src/clipboard.ts +40 -0
  116. package/vendor/node_modules/@legendapp/spark-expo-compat/src/document-picker.ts +52 -0
  117. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +3 -10
  118. package/vendor/node_modules/@legendapp/spark-file-dialog/src/options.ts +5 -2
  119. package/vendor/node_modules/@legendapp/spark-file-dialog/src/types.ts +3 -3
  120. package/vendor/node_modules/@legendapp/spark-file-system/macos/RNDesktopFileSystem.mm +1 -1
  121. package/vendor/node_modules/@legendapp/spark-file-system/package.json +3 -11
  122. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +3 -10
  123. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  124. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  125. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +3 -10
  126. package/vendor/node_modules/@legendapp/spark-message-dialog/src/index.ts +1 -0
  127. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +3 -9
  128. package/vendor/node_modules/@legendapp/spark-native-menu/src/hooks.ts +4 -0
  129. package/vendor/node_modules/@legendapp/spark-notifications/package.json +3 -10
  130. package/vendor/node_modules/@legendapp/spark-processes/package.json +3 -10
  131. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  132. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +3 -10
  133. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  134. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
  135. package/vendor/node_modules/@legendapp/spark-settings-ui/src/index.tsx +122 -334
  136. package/vendor/node_modules/@legendapp/spark-settings-ui/src/rows.tsx +183 -0
  137. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  138. package/vendor/node_modules/@legendapp/spark-system/package.json +3 -10
  139. package/vendor/node_modules/@legendapp/spark-tray/package.json +3 -10
  140. package/vendor/node_modules/@legendapp/spark-tray/src/index.ts +2 -1
  141. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkButton.mm +82 -14
  142. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.h +1 -1
  143. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.mm +94 -11
  144. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +235 -18
  145. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.h +17 -0
  146. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.mm +216 -0
  147. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.h +4 -0
  148. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.mm +212 -0
  149. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewUpdates.h +6 -0
  150. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +28 -13
  151. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSelect.mm +17 -1
  152. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.h +9 -0
  153. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.mm +126 -0
  154. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.h +9 -0
  155. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.mm +66 -0
  156. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.h +9 -0
  157. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.mm +118 -0
  158. package/vendor/node_modules/@legendapp/spark-ui/macos/sf-symbol/RNSFSymbol.mm +4 -12
  159. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.h +9 -0
  160. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.mm +109 -0
  161. package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +438 -102
  162. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.h +9 -0
  163. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.mm +179 -0
  164. package/vendor/node_modules/@legendapp/spark-ui/package.json +9 -8
  165. package/vendor/node_modules/@legendapp/spark-ui/src/SparkButtonNativeComponent.ts +10 -2
  166. package/vendor/node_modules/@legendapp/spark-ui/src/SparkTextInputNativeComponent.ts +2 -0
  167. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +9 -0
  168. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitView.tsx +99 -0
  169. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitViewNativeComponent.ts +29 -0
  170. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +34 -17
  171. package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +6 -4
  172. package/vendor/node_modules/@legendapp/spark-ui/src/checkbox-unavailable.tsx +20 -0
  173. package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +24 -3
  174. package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +72 -20
  175. package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +18 -12
  176. package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +21 -15
  177. package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +40 -16
  178. package/vendor/node_modules/@legendapp/spark-ui/src/mobile-input.tsx +2 -2
  179. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSegmentedControlNativeComponent.ts +3 -1
  180. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSelectNativeComponent.ts +1 -0
  181. package/vendor/node_modules/@legendapp/spark-ui/src/popover/PopoverNativeComponent.ts +20 -0
  182. package/vendor/node_modules/@legendapp/spark-ui/src/popover/index.tsx +45 -0
  183. package/vendor/node_modules/@legendapp/spark-ui/src/progress/ProgressIndicatorNativeComponent.ts +13 -0
  184. package/vendor/node_modules/@legendapp/spark-ui/src/progress/index.tsx +32 -0
  185. package/vendor/node_modules/@legendapp/spark-ui/src/radio-group/RadioGroupNativeComponent.ts +17 -0
  186. package/vendor/node_modules/@legendapp/spark-ui/src/select.ts +4 -0
  187. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/SheetNativeComponent.ts +15 -0
  188. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/index.tsx +38 -0
  189. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarItemNativeComponent.ts +9 -1
  190. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarNativeComponent.ts +17 -2
  191. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/index.tsx +106 -22
  192. package/vendor/node_modules/@legendapp/spark-ui/src/switch.tsx +13 -0
  193. package/vendor/node_modules/@legendapp/spark-ui/src/table/TableNativeComponent.ts +22 -0
  194. package/vendor/node_modules/@legendapp/spark-ui/src/table/index.tsx +118 -0
  195. package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +52 -7
  196. package/vendor/node_modules/@legendapp/spark-ui/uniwind.ts +3 -1
  197. package/vendor/node_modules/@legendapp/spark-ui/uniwind.web.ts +2 -1
  198. package/vendor/node_modules/@legendapp/spark-ui/windows/SparkUI/SparkUI.h +46 -15
  199. package/vendor/node_modules/@legendapp/spark-updates/package.json +3 -9
  200. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  201. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
  202. /package/{settings-window.ts → ui-settings.ts} +0 -0
@@ -1,3 +1,4 @@
1
+ import { ensurePatchRegistry } from "@legendapp/spark-desktop-config/patch-registry.cjs";
1
2
  import { restoreNativeMetadata } from "./native-metadata.js";
2
3
  import { assertNativePatchPreflight } from "./native-patch-preflight.js";
3
4
  import { missingNativeFrameworks, preparationChanges, preserveMacOSPods } from "./native-preparation.js";
@@ -11,10 +12,12 @@ import { copyHelpers } from "./helpers.js";
11
12
  import { lacksMacOSPod, readAppConfig } from "./project.js";
12
13
  import { cpSync, existsSync, mkdirSync, readFileSync, realpathSync, readdirSync, rmSync, writeFileSync, openSync, closeSync, } from "node:fs";
13
14
  import path from "node:path";
14
- import { registerRuntime } from "./local.js";
15
+ import { readRuntime, registerRuntime } from "./local.js";
16
+ import { publishDirectory } from "./publish-directory.js";
15
17
  import { binary, doctor, run } from "./commands.js";
16
18
  import { prepareConfig, entryFile, digest, hashFiles, nativePreparationInputs, nativeProjectFingerprint, localSigningIdentity, nativePackages, readJson, runtimeFor, selection, stateFile, writeJson, validateBuildModules, goConfigurationIssues, } from "./project.js";
17
19
  export async function analyze(root) {
20
+ await ensurePatchRegistry(root);
18
21
  assertNativePatchPreflight(root);
19
22
  if (projectPlatform(root) === "windows")
20
23
  throw new Error("Windows production analysis is not implemented; use spark build --dev.");
@@ -140,6 +143,29 @@ export function warnExampleBundleId(config) {
140
143
  console.warn(`Warning: the bundle ID is still the placeholder ${id}. Change bundleIdentifier in desktop.config.json to an ID you own before you distribute this app.`);
141
144
  }
142
145
  export async function build(root, mode, force = false) {
146
+ return withBuildLock(root, async () => {
147
+ const result = await buildUnlocked(root, mode, force);
148
+ if (mode === "go") {
149
+ registerRuntime(result.app);
150
+ console.log("Spark Runner registered. Apps will discover it automatically.");
151
+ }
152
+ return result;
153
+ });
154
+ }
155
+ export async function prebuild(root) {
156
+ if (projectPlatform(root) !== "macos")
157
+ throw new Error("macOS preparation requires --platform macos.");
158
+ await withBuildLock(root, async () => {
159
+ prepareConfig(root);
160
+ await doctor(root, { nativeBuild: false });
161
+ const chosen = { included: nativePackages(root), excluded: [] };
162
+ validateBuildModules("dev", chosen.included);
163
+ await prepareMacOS(root, chosen, false);
164
+ console.log("macOS native project and CocoaPods dependencies are ready.");
165
+ });
166
+ }
167
+ async function withBuildLock(root, action) {
168
+ await ensurePatchRegistry(root);
143
169
  assertNativePatchPreflight(root);
144
170
  const lock = stateFile(root, "build.lock");
145
171
  mkdirSync(path.dirname(lock), { recursive: true });
@@ -153,25 +179,20 @@ export async function build(root, mode, force = false) {
153
179
  throw error;
154
180
  const pid = Number(readFileSync(lock, "utf8"));
155
181
  if (!Number.isInteger(pid) || pid <= 0)
156
- throw new Error(`Invalid build lock: ${lock}. Check for an active build before removing it.`);
182
+ throw new Error(`Invalid build lock: ${lock}. Check for an active build or prebuild before removing it.`);
157
183
  try {
158
184
  process.kill(pid, 0);
159
185
  }
160
186
  catch (signalError) {
161
187
  if (signalError.code === "ESRCH") {
162
188
  rmSync(lock);
163
- return build(root, mode, force);
189
+ return withBuildLock(root, action);
164
190
  }
165
191
  }
166
- throw new Error(`Another build owns this project (PID ${pid}). Wait for it to finish.`);
192
+ throw new Error(`Another build or prebuild owns this project (PID ${pid}). Wait for it to finish.`);
167
193
  }
168
194
  try {
169
- const result = await buildUnlocked(root, mode, force);
170
- if (mode === "go") {
171
- registerRuntime(result.app);
172
- console.log("Spark Runner registered. Apps will discover it automatically.");
173
- }
174
- return result;
195
+ return await action();
175
196
  }
176
197
  finally {
177
198
  rmSync(lock, { force: true });
@@ -201,6 +222,117 @@ async function buildUnlocked(root, mode, force) {
201
222
  if (productionHash)
202
223
  runtime.fingerprint = digest(runtime.fingerprint + productionHash);
203
224
  const resultFile = stateFile(root, `${mode}-build.json`);
225
+ const { preparation, nativeConfig, nativeRoot, workspace } = await prepareMacOS(root, chosen, force);
226
+ const existing = existsSync(resultFile) ? readJson(resultFile) : undefined;
227
+ const publishedRuntime = existing && readRuntime(existing.app);
228
+ if (!force && existing) {
229
+ if (existing.runtime.fingerprint === runtime.fingerprint &&
230
+ existing.preparation?.fingerprint === preparation.fingerprint &&
231
+ existing.product === path.basename(existing.app) &&
232
+ publishedRuntime?.fingerprint === runtime.fingerprint) {
233
+ console.log(`Reusing ${existing.app}`);
234
+ return existing;
235
+ }
236
+ }
237
+ const reasons = force ? ["forced build"] : !existing ? ["no cached app"] : [
238
+ ...preparationChanges(existing.preparation, preparation),
239
+ ...(existing.runtime.fingerprint !== runtime.fingerprint ? ["runtime inputs changed"] : []),
240
+ ...(publishedRuntime?.fingerprint !== existing.runtime.fingerprint ? ["published app does not match its receipt"] : []),
241
+ ...(existing.product !== path.basename(existing.app) ? ["cached app product is unverified"] : []),
242
+ ];
243
+ console.log(`Building ${mode} runtime: ${reasons.join("; ")}.`);
244
+ const name = workspace.slice(0, -".xcworkspace".length);
245
+ const configuration = mode === "release" ? "Release" : "Debug";
246
+ const xcodeArch = macOSXcodeArchitecture(runtime.arch);
247
+ const derived = stateFile(root, `DerivedData/macos-${runtime.arch}`);
248
+ await run(root, [
249
+ "xcodebuild",
250
+ "-workspace",
251
+ path.join(nativeRoot, workspace),
252
+ "-scheme",
253
+ `${name}-macOS`,
254
+ "-configuration",
255
+ configuration,
256
+ "-destination",
257
+ `platform=macOS,arch=${xcodeArch}`,
258
+ "-derivedDataPath",
259
+ derived,
260
+ `ARCHS=${xcodeArch}`,
261
+ "ONLY_ACTIVE_ARCH=YES",
262
+ "CODE_SIGNING_ALLOWED=NO",
263
+ ...(mode === "release" ? macOSReleaseSettings : []),
264
+ "-jobs",
265
+ /^\d+$/.test(process.env.SPARK_XCODEBUILD_JOBS ?? "") ? process.env.SPARK_XCODEBUILD_JOBS : "8",
266
+ "build",
267
+ ], {
268
+ // Absolute, like analysis: Metro resolves a relative entry from its server root.
269
+ env: { RCT_NEW_ARCH_ENABLED: "1", ENTRY_FILE: path.resolve(root, entryFile(root)), ...(productionGraph ? { SPARK_RUNTIME_SOURCES: stateFile(root, "analysis/runtime-sources.json") } : {}) },
270
+ label: `Building ${mode === "go" ? "Spark Runner" : mode} runtime (${configuration}, ${runtime.arch})`,
271
+ });
272
+ const products = path.join(derived, "Build", "Products", configuration);
273
+ // The scheme's product, not the first .app: a renamed app leaves its old bundle in DerivedData.
274
+ const product = `${name}.app`;
275
+ if (!existsSync(path.join(products, product)))
276
+ throw new Error(`Build completed without ${product}.`);
277
+ const destination = stateFile(root, `products/macos-${runtime.arch}/${mode}/${product}`);
278
+ const result = {
279
+ app: destination,
280
+ // Older receipts may record a stale bundle selected from DerivedData.
281
+ product,
282
+ runtime: runtimeFor(root, chosen.included, mode),
283
+ preparation,
284
+ };
285
+ if (mode === "go" && process.env.SPARK_RELEASE_REVISION) {
286
+ if (!/^[a-f0-9]{40}$/.test(process.env.SPARK_RELEASE_REVISION))
287
+ throw new Error("Invalid release source revision");
288
+ result.runtime.sourceRevision = process.env.SPARK_RELEASE_REVISION;
289
+ }
290
+ if (productionHash)
291
+ result.runtime.fingerprint = digest(result.runtime.fingerprint + productionHash);
292
+ const target = path.dirname(destination);
293
+ const staging = `${target}.staging`;
294
+ const stagedApp = path.join(staging, product);
295
+ rmSync(staging, { recursive: true, force: true });
296
+ mkdirSync(staging, { recursive: true });
297
+ try {
298
+ cpSync(path.join(products, product), stagedApp, { recursive: true, verbatimSymlinks: true });
299
+ if (mode === "release") {
300
+ if (!existsSync(path.join(stagedApp, "Contents/Resources/main.jsbundle")))
301
+ throw new Error("Standalone build is missing its JavaScript bundle.");
302
+ checkReleaseTestDriver(stagedApp, nativeConfig.macos?.testDriverInRelease === true);
303
+ const plist = path.join(stagedApp, "Contents/Info.plist");
304
+ const info = JSON.parse(await run(root, ["plutil", "-convert", "json", "-o", "-", plist], { capture: true }));
305
+ const ats = info.NSAppTransportSecurity;
306
+ if (ats && "NSAllowsLocalNetworking" in ats) {
307
+ const key = Object.keys(ats).length === 1
308
+ ? "NSAppTransportSecurity" : "NSAppTransportSecurity.NSAllowsLocalNetworking";
309
+ await run(root, ["plutil", "-remove", key, plist], { capture: true });
310
+ }
311
+ }
312
+ // prebuild can update package/config fields; cache the actual post-generation inputs.
313
+ writeJson(path.join(stagedApp, "Contents/Resources/spark-runtime.json"), result.runtime);
314
+ if (mode === "release")
315
+ await prepareCustomizeArtifacts(root, result.runtime, stagedApp);
316
+ copyHelpers(root, stagedApp, readAppConfig(root).expo?.extra?.spark?.helpers);
317
+ if (mode === "release") {
318
+ // Hermes is prebuilt, so Xcode's app/Pod compiler settings cannot strip it.
319
+ const hermes = path.join(stagedApp, "Contents/Frameworks/hermes.framework/Versions/Current/hermes");
320
+ if (existsSync(hermes))
321
+ await run(root, ["strip", "-S", "-x", hermes], { capture: true });
322
+ }
323
+ // Development apps can opt into a local identity for same-team native plugins.
324
+ // Standalone outputs remain ad-hoc until `spark package` signs its staging copy.
325
+ await run(root, ["codesign", "--force", "--deep", "--sign", localSigningIdentity(root, mode), stagedApp], { capture: true });
326
+ publishDirectory(staging, target, stateFile(root, "tools"));
327
+ }
328
+ finally {
329
+ rmSync(staging, { recursive: true, force: true });
330
+ }
331
+ writeJson(resultFile, result);
332
+ console.log(`Built ${destination}`);
333
+ return result;
334
+ }
335
+ async function prepareMacOS(root, chosen, force) {
204
336
  // RNW's CLI config probes for PowerShell when Expo autolinking loads it on macOS.
205
337
  const excludedNames = [...new Set([
206
338
  "react-native-windows",
@@ -229,8 +361,11 @@ async function buildUnlocked(root, mode, force) {
229
361
  pkg.expo.autolinking.exclude = excludedNames;
230
362
  writeJson(path.join(root, "package.json"), pkg);
231
363
  }
232
- const inputs = nativePreparationInputs(root, chosen.included);
233
- const preparation = { fingerprint: digest(JSON.stringify(inputs)), inputs, projectFingerprint: nativeProjectFingerprint(inputs, chosen.included) };
364
+ const currentPreparation = () => {
365
+ const inputs = nativePreparationInputs(root, chosen.included);
366
+ return { fingerprint: digest(JSON.stringify(inputs)), inputs, projectFingerprint: nativeProjectFingerprint(inputs, chosen.included) };
367
+ };
368
+ let preparation = currentPreparation();
234
369
  const preparedFile = stateFile(root, "native-preparation.json");
235
370
  const prepared = existsSync(preparedFile) ? readJson(preparedFile) : undefined;
236
371
  const nativeRoot = path.join(root, "macos");
@@ -238,26 +373,12 @@ async function buildUnlocked(root, mode, force) {
238
373
  const needsProject = force || !hasNativeProject || prepared?.projectFingerprint !== preparation.projectFingerprint;
239
374
  const needsPreparation = needsProject ||
240
375
  prepared?.fingerprint !== preparation.fingerprint ||
241
- !existsSync(path.join(root, "macos/Pods/Manifest.lock"));
242
- const existing = existsSync(resultFile) ? readJson(resultFile) : undefined;
243
- if (!force && existing) {
244
- if (existing.runtime.fingerprint === runtime.fingerprint &&
245
- existing.preparation?.fingerprint === preparation.fingerprint &&
246
- existing.product === path.basename(existing.app) &&
247
- existsSync(existing.app)) {
248
- console.log(`Reusing ${existing.app}`);
249
- return existing;
250
- }
251
- }
252
- const reasons = force ? ["forced build"] : !existing ? ["no cached app"] : [
253
- ...preparationChanges(existing.preparation, preparation),
254
- ...(existing.runtime.fingerprint !== runtime.fingerprint ? ["runtime inputs changed"] : []),
255
- ...(!existsSync(existing.app) ? ["cached app missing"] : []),
256
- ...(existing.product !== path.basename(existing.app) ? ["cached app product is unverified"] : []),
257
- ];
258
- console.log(`Building ${mode} runtime: ${reasons.join("; ")}.`);
376
+ !existsSync(path.join(nativeRoot, "Podfile.lock")) ||
377
+ !existsSync(path.join(nativeRoot, "Pods/Manifest.lock")) ||
378
+ readFileSync(path.join(nativeRoot, "Podfile.lock"), "utf8") !== readFileSync(path.join(nativeRoot, "Pods/Manifest.lock"), "utf8");
259
379
  const nativeConfig = readAppConfig(root).expo;
260
- if (needsPreparation)
380
+ const missing = needsProject ? [] : missingNativeFrameworks(root);
381
+ if (needsPreparation || missing.length)
261
382
  rmSync(preparedFile, { force: true });
262
383
  if (needsProject) {
263
384
  console.log(`Preparing native project (preserving CocoaPods cache): ${force ? "forced build" : !hasNativeProject ? "native project missing" : preparationChanges(prepared, preparation).join("; ") || "native project provenance missing"}.`);
@@ -295,10 +416,9 @@ async function buildUnlocked(root, mode, force) {
295
416
  force: true,
296
417
  });
297
418
  }
298
- const missing = missingNativeFrameworks(root);
299
419
  if (needsPreparation || missing.length) {
300
420
  if (needsPreparation && !needsProject)
301
- console.log(`Updating CocoaPods dependencies: ${prepared?.fingerprint !== preparation.fingerprint ? preparationChanges(prepared, preparation).join("; ") : "CocoaPods state missing"}.`);
421
+ console.log(`Updating CocoaPods dependencies: ${prepared?.fingerprint !== preparation.fingerprint ? preparationChanges(prepared, preparation).join("; ") : "CocoaPods state missing or stale"}.`);
302
422
  if (missing.length && !needsPreparation)
303
423
  console.log(`Restoring missing native frameworks:\n${missing.join("\n")}`);
304
424
  await run(root, ["pod", "install"], {
@@ -309,83 +429,14 @@ async function buildUnlocked(root, mode, force) {
309
429
  const remaining = missingNativeFrameworks(root);
310
430
  if (remaining.length)
311
431
  throw new Error(`Native frameworks are missing after pod install. Restore the package's native artifacts and retry:\n${remaining.join("\n")}`);
312
- writeJson(preparedFile, preparation);
313
432
  }
314
433
  await restoreNativeMetadata(root, nativeConfig);
315
434
  const workspace = readdirSync(nativeRoot).find((name) => name.endsWith(".xcworkspace"));
316
435
  if (!workspace)
317
436
  throw new Error("Prebuild did not produce a macOS workspace.");
318
- const name = workspace.slice(0, -".xcworkspace".length);
319
- const configuration = mode === "release" ? "Release" : "Debug";
320
- const xcodeArch = macOSXcodeArchitecture(runtime.arch);
321
- const derived = stateFile(root, `DerivedData/macos-${runtime.arch}`);
322
- await run(root, [
323
- "xcodebuild",
324
- "-workspace",
325
- path.join(nativeRoot, workspace),
326
- "-scheme",
327
- `${name}-macOS`,
328
- "-configuration",
329
- configuration,
330
- "-destination",
331
- `platform=macOS,arch=${xcodeArch}`,
332
- "-derivedDataPath",
333
- derived,
334
- `ARCHS=${xcodeArch}`,
335
- "ONLY_ACTIVE_ARCH=YES",
336
- "CODE_SIGNING_ALLOWED=NO",
337
- ...(mode === "release" ? macOSReleaseSettings : []),
338
- "-jobs",
339
- /^\d+$/.test(process.env.SPARK_XCODEBUILD_JOBS ?? "") ? process.env.SPARK_XCODEBUILD_JOBS : "8",
340
- "build",
341
- ], {
342
- // Absolute, like analysis: Metro resolves a relative entry from its server root.
343
- env: { RCT_NEW_ARCH_ENABLED: "1", ENTRY_FILE: path.resolve(root, entryFile(root)), ...(productionGraph ? { SPARK_RUNTIME_SOURCES: stateFile(root, "analysis/runtime-sources.json") } : {}) },
344
- label: `Building ${mode === "go" ? "Spark Runner" : mode} runtime (${configuration}, ${runtime.arch})`,
345
- });
346
- const products = path.join(derived, "Build", "Products", configuration);
347
- // The scheme's product, not the first .app: a renamed app leaves its old bundle in DerivedData.
348
- const product = `${name}.app`;
349
- if (!existsSync(path.join(products, product)))
350
- throw new Error(`Build completed without ${product}.`);
351
- const destination = stateFile(root, `products/macos-${runtime.arch}/${mode}/${product}`);
352
- rmSync(path.dirname(destination), { recursive: true, force: true });
353
- mkdirSync(path.dirname(destination), { recursive: true });
354
- cpSync(path.join(products, product), destination, { recursive: true, verbatimSymlinks: true });
355
- if (mode === "release" &&
356
- !existsSync(path.join(destination, "Contents/Resources/main.jsbundle")))
357
- throw new Error("Standalone build is missing its JavaScript bundle.");
358
- if (mode === "release")
359
- checkReleaseTestDriver(destination, nativeConfig.macos?.testDriverInRelease === true);
360
- const result = {
361
- app: destination,
362
- // Older receipts may record a stale bundle selected from DerivedData.
363
- product,
364
- runtime: runtimeFor(root, chosen.included, mode),
365
- preparation,
366
- };
367
- if (mode === "go" && process.env.SPARK_RELEASE_REVISION) {
368
- if (!/^[a-f0-9]{40}$/.test(process.env.SPARK_RELEASE_REVISION))
369
- throw new Error("Invalid release source revision");
370
- result.runtime.sourceRevision = process.env.SPARK_RELEASE_REVISION;
371
- }
372
- if (productionHash)
373
- result.runtime.fingerprint = digest(result.runtime.fingerprint + productionHash);
374
- // prebuild can update package/config fields; cache the actual post-generation inputs.
375
- writeJson(path.join(destination, "Contents/Resources/spark-runtime.json"), result.runtime);
376
- if (mode === "release")
377
- await prepareCustomizeArtifacts(root, result.runtime, destination);
378
- copyHelpers(root, destination, readAppConfig(root).expo?.extra?.spark?.helpers);
379
- if (mode === "release") {
380
- // Hermes is prebuilt, so Xcode's app/Pod compiler settings cannot strip it.
381
- const hermes = path.join(destination, "Contents/Frameworks/hermes.framework/Versions/Current/hermes");
382
- if (existsSync(hermes))
383
- await run(root, ["strip", "-S", "-x", hermes], { capture: true });
437
+ if (needsPreparation || missing.length) {
438
+ preparation = currentPreparation();
439
+ writeJson(preparedFile, preparation);
384
440
  }
385
- // Development apps can opt into a local identity for same-team native plugins.
386
- // Standalone outputs remain ad-hoc until `spark package` signs its staging copy.
387
- await run(root, ["codesign", "--force", "--deep", "--sign", localSigningIdentity(root, mode), destination], { capture: true });
388
- writeJson(resultFile, result);
389
- console.log(`Built ${destination}`);
390
- return result;
441
+ return { preparation, nativeConfig, nativeRoot, workspace };
391
442
  }
@@ -6,7 +6,8 @@ const options = {
6
6
  device: { type: "string" }, project: { type: "string" }, platform: { type: "string" },
7
7
  packages: { type: "string" }, port: { type: "string" }, runner: { type: "boolean" },
8
8
  dev: { type: "boolean" }, release: { type: "boolean" }, preview: { type: "boolean" },
9
- force: { type: "boolean" }, "dry-run": { type: "boolean" }, "submission-id": { type: "string" }, help: { type: "boolean", short: "h" },
9
+ root: { type: "string" }, out: { type: "string" },
10
+ init: { type: "boolean" }, force: { type: "boolean" }, done: { type: "boolean" }, "dry-run": { type: "boolean" }, "submission-id": { type: "string" }, help: { type: "boolean", short: "h" },
10
11
  };
11
12
  const commands = {
12
13
  create: { flags: ["example", "package-manager", "bundle-id", "universal", "platform", "packages"], arguments: [1, 1] },
@@ -20,7 +21,9 @@ const commands = {
20
21
  build: { flags: ["project", "platform", "device", "port", "runner", "dev", "release", "preview", "force"], arguments: [0, 0] },
21
22
  prebuild: { flags: ["project", "platform"], arguments: [0, 0] },
22
23
  doctor: { flags: ["project"], arguments: [0, 0] },
24
+ migrate: { flags: ["project", "dry-run", "init"], arguments: [0, 0] },
23
25
  upgrade: { flags: ["project", "dry-run"], arguments: [0, 0] },
26
+ patch: { flags: ["project", "root", "out", "done", "force"], arguments: [1, 1] },
24
27
  "updates init": { flags: ["project", "platform"], arguments: [1, 1] },
25
28
  credentials: { flags: ["project", "platform"], arguments: [0, 0] },
26
29
  package: { flags: ["project", "platform", "force", "submission-id"], arguments: [0, 0] },
@@ -89,7 +89,16 @@ export function binary(root, name) {
89
89
  throw new Error(`${name} does not expose its CLI entry point`);
90
90
  return path.resolve(path.dirname(manifest), entry);
91
91
  }
92
- export async function doctor(root) {
92
+ export async function doctor(root, { nativeBuild = true, readOnly = false } = {}) {
93
+ const probe = async (argv) => {
94
+ if (!readOnly)
95
+ return run(root, argv, { capture: true });
96
+ const child = spawnProcess(argv, { cwd: root, stdout: "pipe", stderr: "pipe" });
97
+ const [out, err, code] = await Promise.all([new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited]);
98
+ if (code)
99
+ throw new Error(`${argv[0]} failed: ${err || out}`);
100
+ return out;
101
+ };
93
102
  if (process.platform === "win32") {
94
103
  for (const tool of ["node", "pwsh.exe", "dotnet.exe"])
95
104
  if (!which(tool))
@@ -97,17 +106,17 @@ export async function doctor(root) {
97
106
  await checkExpoDesktopNode(root);
98
107
  const require = createRequire(path.join(root, "package.json"));
99
108
  const windows = path.dirname(require.resolve("react-native-windows/package.json"));
100
- await run(root, ["pwsh.exe", "-File", path.join(windows, "Scripts/rnw-dependencies.ps1")]);
109
+ if (!readOnly)
110
+ await run(root, ["pwsh.exe", "-File", path.join(windows, "Scripts/rnw-dependencies.ps1")]);
101
111
  return;
102
112
  }
103
113
  if (process.platform !== "darwin")
104
114
  throw new Error("Native macOS builds require macOS.");
105
- for (const tool of ["node", "pod", "xcodebuild"])
115
+ for (const tool of ["node", "pod", ...(nativeBuild ? ["xcodebuild"] : [])])
106
116
  if (!which(tool))
107
117
  throw new Error(`Missing ${tool}. Install the macOS native prerequisites described in docs/development.md, then retry the build.`);
108
118
  await checkExpoDesktopNode(root);
109
- await run(root, ["xcodebuild", "-version"], { capture: true });
110
- await run(root, ["xcrun", "--sdk", "macosx", "--show-sdk-path"], {
111
- capture: true,
112
- });
119
+ if (nativeBuild)
120
+ await probe(["xcodebuild", "-version"]);
121
+ await probe(["xcrun", "--sdk", "macosx", "--show-sdk-path"]);
113
122
  }
@@ -8,16 +8,32 @@ const packages = ["react", "react-native", "react-native-macos", "expo"];
8
8
  // create/refreshLocalPackages use this starter's tested compatibility matrix too.
9
9
  const defaults = JSON.parse(readFileSync(new URL("../templates/blank-typescript/package.json", import.meta.url), "utf8"));
10
10
  export const expectedDependencyPins = Object.fromEntries(packages.map(name => [name, defaults.dependencies[name]]));
11
+ export function projectDependencies(root, inherited = false) {
12
+ const pkg = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
13
+ const dependencies = { ...pkg.dependencies, ...pkg.devDependencies, ...pkg.optionalDependencies };
14
+ if (inherited) {
15
+ for (let directory = path.dirname(root);; directory = path.dirname(directory)) {
16
+ const file = path.join(directory, "package.json");
17
+ if (existsSync(file)) {
18
+ const owner = JSON.parse(readFileSync(file, "utf8"));
19
+ for (const [name, spec] of Object.entries({ ...owner.dependencies, ...owner.devDependencies, ...owner.optionalDependencies }))
20
+ dependencies[name] ??= spec;
21
+ }
22
+ if (path.dirname(directory) === directory)
23
+ break;
24
+ }
25
+ }
26
+ return dependencies;
27
+ }
11
28
  /** Optional feature backends belong to the app, even when Spark supplies the API. */
12
- export function optionalBackendIssues(root) {
29
+ export function optionalBackendIssues(root, inherited = false) {
13
30
  const backends = {
14
31
  "@legendapp/spark/markdown": "react-native-enriched-markdown",
15
32
  "@legendapp/spark/html": "react-native-enriched-html",
16
33
  "@legendapp/spark/webview": "react-native-webview",
17
34
  "@legendapp/spark/sqlite": "@op-engineering/op-sqlite",
18
35
  };
19
- const pkg = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
20
- const dependencies = { ...pkg.dependencies, ...pkg.devDependencies, ...pkg.optionalDependencies };
36
+ const dependencies = projectDependencies(root, inherited);
21
37
  const platforms = supportedPlatforms(root);
22
38
  const req = createRequire(path.join(root, "package.json"));
23
39
  const issues = new Map();
@@ -1,3 +1,4 @@
1
+ import { ensurePatchRegistry } from "@legendapp/spark-desktop-config/patch-registry.cjs";
1
2
  import { spawnProcess } from "./process.js";
2
3
  import path from "node:path";
3
4
  import { prepareConfig, selectTarget, supportedPlatforms } from "@legendapp/spark-desktop-config/config.cjs";
@@ -61,6 +62,7 @@ export async function devCommand(args) {
61
62
  }
62
63
  const root = findProject(start);
63
64
  ensureProjectVersion(root);
65
+ await ensurePatchRegistry(root);
64
66
  const { desktop, initial } = devTargets(supportedPlatforms(root), options.platform ?? process.env.SPARK_PLATFORM);
65
67
  // This selects only desktop build/signature state in the supervisor. Expo's
66
68
  // child uses shared development config and chooses each JS graph per request.
@@ -1,3 +1,4 @@
1
+ import { ensurePatchRegistry } from "@legendapp/spark-desktop-config/patch-registry.cjs";
1
2
  import { installedRelease } from "./release.js";
2
3
  import { createRuntimeInputCache } from "./runtime-input-cache.js";
3
4
  import { acquireRunner } from "./runner-install.js";
@@ -18,6 +19,7 @@ import { watchmanStalls } from "./watchman.js";
18
19
  import { assertNativePatchPreflight } from "./native-patch-preflight.js";
19
20
  import { prepareConfig, dependencyStamp, goConfigurationIssues, incompatible, nativePackages, readJson, projectEnvironment, runtimeFor, stateFile, writeJson, } from "./project.js";
20
21
  export async function launch(root, app, port, options = {}) {
22
+ await ensurePatchRegistry(root);
21
23
  assertNativePatchPreflight(root);
22
24
  if (readRuntime(app)?.platform === "windows") {
23
25
  if (process.platform !== "win32")
@@ -54,6 +56,7 @@ export async function launch(root, app, port, options = {}) {
54
56
  });
55
57
  }
56
58
  export async function dev(root, goApp, expoArgs = [], noOpen = false, appArgs = []) {
59
+ await ensurePatchRegistry(root);
57
60
  assertNativePatchPreflight(root);
58
61
  const platform = projectPlatform(root);
59
62
  preparePatch(root);
@@ -1,3 +1,4 @@
1
+ import { ensurePatchRegistry } from "@legendapp/spark-desktop-config/patch-registry.cjs";
1
2
  import { existsSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
2
3
  import { createRequire } from "node:module";
3
4
  import path from "node:path";
@@ -125,4 +126,5 @@ export async function installWithEnrichedHtmlPins(root, manager, policy = enrich
125
126
  if (repairEnrichedHtmlPins(root, manager, false, policy).length)
126
127
  await run(root, managerCommand(manager, ["install"]));
127
128
  assertEnrichedHtmlPins(root, policy);
129
+ await ensurePatchRegistry(root);
128
130
  }
@@ -23,7 +23,7 @@ export function errorPresentation(error) {
23
23
  const message = error instanceof Error ? error.message : String(error);
24
24
  const command = error instanceof CommandError ? error.argv.join(" ") : "";
25
25
  const details = error instanceof CommandError ? error.output : message;
26
- let summary = message.split("\n")[0] || "An unexpected error occurred.";
26
+ let summary = (message.includes("\nFix:") ? message : message.split("\n")[0]) || "An unexpected error occurred.";
27
27
  let next;
28
28
  if (isNetworkError(error)) {
29
29
  summary = command.includes("notarytool") ? "Could not reach Apple’s notarization service." : "Could not reach the remote service.";
@@ -1,3 +1,4 @@
1
+ import { ensurePatchRegistry, fetchRegistry, registryFindings } from "@legendapp/spark-desktop-config/patch-registry.cjs";
1
2
  import { enrichedHtmlPinIssues } from "./enriched-html-pins.js";
2
3
  import { publishCustomize } from "./customize-artifacts.js";
3
4
  import { nodeCommand, spawnProcess } from "./process.js";
@@ -17,14 +18,17 @@ import { buildMode } from "./build-mode.js";
17
18
  import { initializeUpdates } from "./updates.js";
18
19
  import { packageApp } from "./package.js";
19
20
  import { credentials } from "./credentials.js";
20
- import { build, analyze } from "./build.js";
21
+ import { build, analyze, prebuild } from "./build.js";
21
22
  import { launch } from "./dev.js";
23
+ import { appPatchIssues } from "@legendapp/spark-desktop-config/native-patches.cjs";
22
24
  import { doctor, run } from "./commands.js";
23
25
  import { findFramework, findProject, sparkHome, creationManifest, packageManifest, registerRuntime } from "./local.js";
24
26
  import { readJson, stateFile, VERSION, writeJson } from "./project.js";
25
27
  import { devCommand } from "./dev-command.js";
26
28
  import { optionalBackendIssues, printDependencyPins, upgradeDependencyPins } from "./dependency-pins.js";
29
+ import { migrate } from "./migrate.js";
27
30
  import { upgrade } from "./upgrade.js";
31
+ import { patchLibrary, patchRoot } from "./patch.js";
28
32
  import { ensureProjectVersion } from "./project-version.js";
29
33
  import { reportError } from "./errors.js";
30
34
  async function main() {
@@ -48,6 +52,7 @@ async function main() {
48
52
  if (!values.help && ["build", "prebuild"].includes(command ?? "")) {
49
53
  const root = project();
50
54
  ensureProjectVersion(root);
55
+ await ensurePatchRegistry(root);
51
56
  const selected = readConfig(root).expo.platforms[0];
52
57
  if (!["ios", "android", "web"].includes(selected) && (values.device || values.port))
53
58
  throw new Error("--device and --port are mobile build options; use spark dev for desktop launch options.");
@@ -84,10 +89,13 @@ async function main() {
84
89
  spark add desktop Add desktop to an existing Expo app without replacing its entry point
85
90
  spark dev Develop with Fast Refresh
86
91
  spark build Build a standalone desktop app
87
- spark prebuild Generate a Windows/mobile native project
92
+ spark prebuild Generate a native project (macOS also installs Pods; no app build)
88
93
  spark package Sign and notarize a distribution archive
89
- spark doctor Check app dependency pins and native tooling (exits 1 on issues)
94
+ spark doctor Check dependency pins, app patches, and native tooling (exits 1 on issues)
95
+ spark migrate Apply installed-version migrations (--project <dir>, --dry-run; --init stamps a newly generated project)
90
96
  spark upgrade Update Spark on its current release channel (--dry-run previews changes)
97
+ spark patch <lib> Copy a library with Spark's patch for editing; --done saves patches/<lib>@<version>.patch
98
+ in the nearest app or patches/ owner (--root: where it's installed, --out: where patches/ goes)
91
99
  spark customize publish Upload prepared customization artifacts to existing GitHub releases
92
100
 
93
101
  Inside an app: npm run dev, npm run build, npm run package (or pnpm, yarn, bun)
@@ -107,6 +115,10 @@ Overrides: --project <directory>, --port <number>, dev --runner-binary <runtime
107
115
  await addDesktop(start, creationManifest(values.packages));
108
116
  break;
109
117
  }
118
+ case "migrate": {
119
+ migrate(projectOption ? start : project(), { dryRun: !!values["dry-run"], init: !!values.init });
120
+ break;
121
+ }
110
122
  case "create": {
111
123
  if (!positionals[1])
112
124
  throw new Error("Usage: spark create MyApp");
@@ -196,9 +208,10 @@ Overrides: --project <directory>, --port <number>, dev --runner-binary <runtime
196
208
  break;
197
209
  }
198
210
  case "prebuild":
199
- if (readConfig(project()).expo.platforms[0] !== "windows")
200
- throw new Error("For macOS, spark build --dev generates and builds the native project.");
201
- await prepareWindows(project(), "dev");
211
+ if (readConfig(project()).expo.platforms[0] === "windows")
212
+ await prepareWindows(project(), "dev");
213
+ else
214
+ await prebuild(project());
202
215
  break;
203
216
  case "doctor": {
204
217
  let root;
@@ -210,7 +223,22 @@ Overrides: --project <directory>, --port <number>, dev --runner-binary <runtime
210
223
  console.log("No Spark app found; skipping dependency pin check.");
211
224
  }
212
225
  if (root) {
213
- ensureProjectVersion(root);
226
+ ensureProjectVersion(root, { readOnly: true });
227
+ try {
228
+ const source = await fetchRegistry(root, { writeCache: false });
229
+ const findings = registryFindings(root, source);
230
+ for (const issue of findings)
231
+ console.error(`${issue.message}\nFix: cd ${JSON.stringify(issue.owner)} && ${issue.fix}`);
232
+ if (findings.length) {
233
+ process.exitCode = 1;
234
+ pinIssues = true;
235
+ }
236
+ }
237
+ catch (error) {
238
+ console.error(`Patch registry check failed: ${error instanceof Error ? error.message : String(error)}\nFix: repair the registry metadata or reinstall Spark.`);
239
+ process.exitCode = 1;
240
+ pinIssues = true;
241
+ }
214
242
  try {
215
243
  const issues = [...upgradeDependencyPins(root, true), ...enrichedHtmlPinIssues(root), ...optionalBackendIssues(root)];
216
244
  printDependencyPins(issues);
@@ -225,7 +253,19 @@ Overrides: --project <directory>, --port <number>, dev --runner-binary <runtime
225
253
  pinIssues = true;
226
254
  }
227
255
  }
228
- await doctor(root ?? start);
256
+ try {
257
+ const patchIssues = appPatchIssues(root ?? start);
258
+ if (patchIssues.length) {
259
+ console.error(`App patch issues:\n${patchIssues.map(issue => `- ${issue}`).join("\n")}`);
260
+ process.exitCode = 1;
261
+ break;
262
+ }
263
+ }
264
+ catch (error) {
265
+ console.error(`App patch check failed: ${error instanceof Error ? error.message : String(error)}`);
266
+ process.exitCode = 1;
267
+ }
268
+ await doctor(root ?? start, { readOnly: true });
229
269
  console.log("Native toolchain available.");
230
270
  if (pinIssues)
231
271
  console.log("Dependency pin issues found; run spark upgrade.");
@@ -235,6 +275,11 @@ Overrides: --project <directory>, --port <number>, dev --runner-binary <runtime
235
275
  await upgrade(project(), !!values["dry-run"]);
236
276
  break;
237
277
  }
278
+ case "patch": {
279
+ const root = values.root ? path.resolve(values.root) : patchRoot(start);
280
+ patchLibrary(root, positionals[1], { done: !!values.done, force: !!values.force, out: values.out ? path.resolve(values.out) : root });
281
+ break;
282
+ }
238
283
  case "customize": {
239
284
  if (positionals[1] !== "publish")
240
285
  throw new Error("Usage: spark customize publish (after a customize release build)");
@@ -294,6 +339,9 @@ try {
294
339
  await main();
295
340
  }
296
341
  catch (error) {
297
- reportError(process.cwd(), error, "Spark");
342
+ if (process.argv[2] === "doctor")
343
+ console.error(error instanceof Error ? error.message : String(error));
344
+ else
345
+ reportError(process.cwd(), error, "Spark");
298
346
  process.exitCode = 1;
299
347
  }