@legendapp/spark 0.0.3 → 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 (186) hide show
  1. package/init-template.cjs +7 -1
  2. package/package.json +10 -5
  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 +116 -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 +85 -0
  24. package/skills/spark/ui.md +57 -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 +137 -105
  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 +12 -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/patch.js +92 -0
  53. package/vendor/node_modules/@legendapp/spark-cli/dist/project-version.js +12 -4
  54. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +8 -1
  55. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +20 -20
  56. package/vendor/node_modules/@legendapp/spark-cli/dist/upgrade.js +1 -1
  57. package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +3 -0
  58. package/vendor/node_modules/@legendapp/spark-cli/package.json +5 -4
  59. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
  60. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
  61. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
  62. package/vendor/node_modules/@legendapp/spark-clipboard/macos/RNDesktopClipboard.mm +1 -1
  63. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +3 -10
  64. package/vendor/node_modules/@legendapp/spark-clipboard/src/desktop.ts +1 -0
  65. package/vendor/node_modules/@legendapp/spark-codex/package.json +3 -7
  66. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  67. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +3 -10
  68. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.h +3 -1
  69. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +51 -10
  70. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.h +4 -0
  71. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.mm +82 -0
  72. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +2 -8
  73. package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +6 -8
  74. package/vendor/node_modules/@legendapp/spark-desktop-config/identity.cjs +2 -0
  75. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +300 -71
  76. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +7 -0
  77. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
  78. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.cjs +318 -0
  79. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.d.cts +20 -0
  80. package/vendor/node_modules/@legendapp/spark-desktop-config/validation.cjs +66 -9
  81. package/vendor/node_modules/@legendapp/spark-desktop-config/windows.plugin.cjs +1 -0
  82. package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +1 -0
  83. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  84. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +3 -10
  85. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +3 -10
  86. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/RNDesktopWindows.mm +7 -2
  87. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +235 -240
  88. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +4 -11
  89. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/api.ts +9 -3
  90. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +7 -0
  91. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/types.ts +32 -3
  92. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/validation.ts +28 -11
  93. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/createWindowsNavigator.tsx +15 -3
  94. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/primaryWindowLifecycle.ts +12 -3
  95. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/usePrimaryWindowLifecycle.ts +2 -1
  96. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/useWindowFocusEffect.ts +4 -1
  97. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  98. package/vendor/node_modules/@legendapp/spark-drag-drop/macos/RNDesktopDragView.mm +77 -17
  99. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +3 -8
  100. package/vendor/node_modules/@legendapp/spark-drag-drop/src/DesktopDragViewNativeComponent.ts +1 -0
  101. package/vendor/node_modules/@legendapp/spark-drag-drop/src/contracts.ts +13 -4
  102. package/vendor/node_modules/@legendapp/spark-drag-drop/src/index.tsx +5 -3
  103. package/vendor/node_modules/@legendapp/spark-drag-drop/windows/SparkDragDrop/SparkDragDrop.h +6 -1
  104. package/vendor/node_modules/@legendapp/spark-expo-compat/metro.cjs +44 -0
  105. package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +20 -0
  106. package/vendor/node_modules/@legendapp/spark-expo-compat/src/clipboard.ts +40 -0
  107. package/vendor/node_modules/@legendapp/spark-expo-compat/src/document-picker.ts +52 -0
  108. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +3 -10
  109. package/vendor/node_modules/@legendapp/spark-file-dialog/src/options.ts +5 -2
  110. package/vendor/node_modules/@legendapp/spark-file-dialog/src/types.ts +3 -3
  111. package/vendor/node_modules/@legendapp/spark-file-system/macos/RNDesktopFileSystem.mm +1 -1
  112. package/vendor/node_modules/@legendapp/spark-file-system/package.json +3 -11
  113. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +3 -10
  114. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  115. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  116. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +3 -10
  117. package/vendor/node_modules/@legendapp/spark-message-dialog/src/index.ts +1 -0
  118. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +3 -9
  119. package/vendor/node_modules/@legendapp/spark-native-menu/src/hooks.ts +4 -0
  120. package/vendor/node_modules/@legendapp/spark-notifications/package.json +3 -10
  121. package/vendor/node_modules/@legendapp/spark-processes/package.json +3 -10
  122. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  123. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +3 -10
  124. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  125. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
  126. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  127. package/vendor/node_modules/@legendapp/spark-system/package.json +3 -10
  128. package/vendor/node_modules/@legendapp/spark-tray/package.json +3 -10
  129. package/vendor/node_modules/@legendapp/spark-tray/src/index.ts +2 -1
  130. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkButton.mm +82 -14
  131. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.h +1 -1
  132. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.mm +94 -11
  133. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +235 -18
  134. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.h +17 -0
  135. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.mm +216 -0
  136. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.h +4 -0
  137. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.mm +212 -0
  138. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewUpdates.h +6 -0
  139. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +26 -13
  140. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.h +9 -0
  141. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.mm +126 -0
  142. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.h +9 -0
  143. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.mm +66 -0
  144. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.h +9 -0
  145. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.mm +118 -0
  146. package/vendor/node_modules/@legendapp/spark-ui/macos/sf-symbol/RNSFSymbol.mm +4 -12
  147. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.h +9 -0
  148. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.mm +109 -0
  149. package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +418 -102
  150. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.h +9 -0
  151. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.mm +179 -0
  152. package/vendor/node_modules/@legendapp/spark-ui/package.json +9 -8
  153. package/vendor/node_modules/@legendapp/spark-ui/src/SparkButtonNativeComponent.ts +10 -2
  154. package/vendor/node_modules/@legendapp/spark-ui/src/SparkTextInputNativeComponent.ts +2 -0
  155. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +9 -0
  156. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitView.tsx +99 -0
  157. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitViewNativeComponent.ts +29 -0
  158. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +34 -17
  159. package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +5 -4
  160. package/vendor/node_modules/@legendapp/spark-ui/src/checkbox-unavailable.tsx +20 -0
  161. package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +24 -3
  162. package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +63 -13
  163. package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +12 -7
  164. package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +12 -7
  165. package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +35 -13
  166. package/vendor/node_modules/@legendapp/spark-ui/src/mobile-input.tsx +2 -2
  167. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSegmentedControlNativeComponent.ts +3 -1
  168. package/vendor/node_modules/@legendapp/spark-ui/src/popover/PopoverNativeComponent.ts +20 -0
  169. package/vendor/node_modules/@legendapp/spark-ui/src/popover/index.tsx +45 -0
  170. package/vendor/node_modules/@legendapp/spark-ui/src/progress/ProgressIndicatorNativeComponent.ts +13 -0
  171. package/vendor/node_modules/@legendapp/spark-ui/src/progress/index.tsx +32 -0
  172. package/vendor/node_modules/@legendapp/spark-ui/src/radio-group/RadioGroupNativeComponent.ts +17 -0
  173. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/SheetNativeComponent.ts +15 -0
  174. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/index.tsx +38 -0
  175. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarItemNativeComponent.ts +9 -1
  176. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarNativeComponent.ts +17 -2
  177. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/index.tsx +106 -22
  178. package/vendor/node_modules/@legendapp/spark-ui/src/table/TableNativeComponent.ts +22 -0
  179. package/vendor/node_modules/@legendapp/spark-ui/src/table/index.tsx +118 -0
  180. package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +39 -6
  181. package/vendor/node_modules/@legendapp/spark-ui/uniwind.ts +3 -1
  182. package/vendor/node_modules/@legendapp/spark-ui/uniwind.web.ts +2 -1
  183. package/vendor/node_modules/@legendapp/spark-ui/windows/SparkUI/SparkUI.h +46 -15
  184. package/vendor/node_modules/@legendapp/spark-updates/package.json +3 -9
  185. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  186. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
@@ -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";
@@ -15,6 +16,7 @@ import { registerRuntime } from "./local.js";
15
16
  import { binary, doctor, run } from "./commands.js";
16
17
  import { prepareConfig, entryFile, digest, hashFiles, nativePreparationInputs, nativeProjectFingerprint, localSigningIdentity, nativePackages, readJson, runtimeFor, selection, stateFile, writeJson, validateBuildModules, goConfigurationIssues, } from "./project.js";
17
18
  export async function analyze(root) {
19
+ await ensurePatchRegistry(root);
18
20
  assertNativePatchPreflight(root);
19
21
  if (projectPlatform(root) === "windows")
20
22
  throw new Error("Windows production analysis is not implemented; use spark build --dev.");
@@ -140,6 +142,29 @@ export function warnExampleBundleId(config) {
140
142
  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
143
  }
142
144
  export async function build(root, mode, force = false) {
145
+ return withBuildLock(root, async () => {
146
+ const result = await buildUnlocked(root, mode, force);
147
+ if (mode === "go") {
148
+ registerRuntime(result.app);
149
+ console.log("Spark Runner registered. Apps will discover it automatically.");
150
+ }
151
+ return result;
152
+ });
153
+ }
154
+ export async function prebuild(root) {
155
+ if (projectPlatform(root) !== "macos")
156
+ throw new Error("macOS preparation requires --platform macos.");
157
+ await withBuildLock(root, async () => {
158
+ prepareConfig(root);
159
+ await doctor(root, { nativeBuild: false });
160
+ const chosen = { included: nativePackages(root), excluded: [] };
161
+ validateBuildModules("dev", chosen.included);
162
+ await prepareMacOS(root, chosen, false);
163
+ console.log("macOS native project and CocoaPods dependencies are ready.");
164
+ });
165
+ }
166
+ async function withBuildLock(root, action) {
167
+ await ensurePatchRegistry(root);
143
168
  assertNativePatchPreflight(root);
144
169
  const lock = stateFile(root, "build.lock");
145
170
  mkdirSync(path.dirname(lock), { recursive: true });
@@ -153,25 +178,20 @@ export async function build(root, mode, force = false) {
153
178
  throw error;
154
179
  const pid = Number(readFileSync(lock, "utf8"));
155
180
  if (!Number.isInteger(pid) || pid <= 0)
156
- throw new Error(`Invalid build lock: ${lock}. Check for an active build before removing it.`);
181
+ throw new Error(`Invalid build lock: ${lock}. Check for an active build or prebuild before removing it.`);
157
182
  try {
158
183
  process.kill(pid, 0);
159
184
  }
160
185
  catch (signalError) {
161
186
  if (signalError.code === "ESRCH") {
162
187
  rmSync(lock);
163
- return build(root, mode, force);
188
+ return withBuildLock(root, action);
164
189
  }
165
190
  }
166
- throw new Error(`Another build owns this project (PID ${pid}). Wait for it to finish.`);
191
+ throw new Error(`Another build or prebuild owns this project (PID ${pid}). Wait for it to finish.`);
167
192
  }
168
193
  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;
194
+ return await action();
175
195
  }
176
196
  finally {
177
197
  rmSync(lock, { force: true });
@@ -201,6 +221,99 @@ async function buildUnlocked(root, mode, force) {
201
221
  if (productionHash)
202
222
  runtime.fingerprint = digest(runtime.fingerprint + productionHash);
203
223
  const resultFile = stateFile(root, `${mode}-build.json`);
224
+ const { preparation, nativeConfig, nativeRoot, workspace } = await prepareMacOS(root, chosen, force);
225
+ const existing = existsSync(resultFile) ? readJson(resultFile) : undefined;
226
+ if (!force && existing) {
227
+ if (existing.runtime.fingerprint === runtime.fingerprint &&
228
+ existing.preparation?.fingerprint === preparation.fingerprint &&
229
+ existing.product === path.basename(existing.app) &&
230
+ existsSync(existing.app)) {
231
+ console.log(`Reusing ${existing.app}`);
232
+ return existing;
233
+ }
234
+ }
235
+ const reasons = force ? ["forced build"] : !existing ? ["no cached app"] : [
236
+ ...preparationChanges(existing.preparation, preparation),
237
+ ...(existing.runtime.fingerprint !== runtime.fingerprint ? ["runtime inputs changed"] : []),
238
+ ...(!existsSync(existing.app) ? ["cached app missing"] : []),
239
+ ...(existing.product !== path.basename(existing.app) ? ["cached app product is unverified"] : []),
240
+ ];
241
+ console.log(`Building ${mode} runtime: ${reasons.join("; ")}.`);
242
+ const name = workspace.slice(0, -".xcworkspace".length);
243
+ const configuration = mode === "release" ? "Release" : "Debug";
244
+ const xcodeArch = macOSXcodeArchitecture(runtime.arch);
245
+ const derived = stateFile(root, `DerivedData/macos-${runtime.arch}`);
246
+ await run(root, [
247
+ "xcodebuild",
248
+ "-workspace",
249
+ path.join(nativeRoot, workspace),
250
+ "-scheme",
251
+ `${name}-macOS`,
252
+ "-configuration",
253
+ configuration,
254
+ "-destination",
255
+ `platform=macOS,arch=${xcodeArch}`,
256
+ "-derivedDataPath",
257
+ derived,
258
+ `ARCHS=${xcodeArch}`,
259
+ "ONLY_ACTIVE_ARCH=YES",
260
+ "CODE_SIGNING_ALLOWED=NO",
261
+ ...(mode === "release" ? macOSReleaseSettings : []),
262
+ "-jobs",
263
+ /^\d+$/.test(process.env.SPARK_XCODEBUILD_JOBS ?? "") ? process.env.SPARK_XCODEBUILD_JOBS : "8",
264
+ "build",
265
+ ], {
266
+ // Absolute, like analysis: Metro resolves a relative entry from its server root.
267
+ env: { RCT_NEW_ARCH_ENABLED: "1", ENTRY_FILE: path.resolve(root, entryFile(root)), ...(productionGraph ? { SPARK_RUNTIME_SOURCES: stateFile(root, "analysis/runtime-sources.json") } : {}) },
268
+ label: `Building ${mode === "go" ? "Spark Runner" : mode} runtime (${configuration}, ${runtime.arch})`,
269
+ });
270
+ const products = path.join(derived, "Build", "Products", configuration);
271
+ // The scheme's product, not the first .app: a renamed app leaves its old bundle in DerivedData.
272
+ const product = `${name}.app`;
273
+ if (!existsSync(path.join(products, product)))
274
+ throw new Error(`Build completed without ${product}.`);
275
+ const destination = stateFile(root, `products/macos-${runtime.arch}/${mode}/${product}`);
276
+ rmSync(path.dirname(destination), { recursive: true, force: true });
277
+ mkdirSync(path.dirname(destination), { recursive: true });
278
+ cpSync(path.join(products, product), destination, { recursive: true, verbatimSymlinks: true });
279
+ if (mode === "release" &&
280
+ !existsSync(path.join(destination, "Contents/Resources/main.jsbundle")))
281
+ throw new Error("Standalone build is missing its JavaScript bundle.");
282
+ if (mode === "release")
283
+ checkReleaseTestDriver(destination, nativeConfig.macos?.testDriverInRelease === true);
284
+ const result = {
285
+ app: destination,
286
+ // Older receipts may record a stale bundle selected from DerivedData.
287
+ product,
288
+ runtime: runtimeFor(root, chosen.included, mode),
289
+ preparation,
290
+ };
291
+ if (mode === "go" && process.env.SPARK_RELEASE_REVISION) {
292
+ if (!/^[a-f0-9]{40}$/.test(process.env.SPARK_RELEASE_REVISION))
293
+ throw new Error("Invalid release source revision");
294
+ result.runtime.sourceRevision = process.env.SPARK_RELEASE_REVISION;
295
+ }
296
+ if (productionHash)
297
+ result.runtime.fingerprint = digest(result.runtime.fingerprint + productionHash);
298
+ // prebuild can update package/config fields; cache the actual post-generation inputs.
299
+ writeJson(path.join(destination, "Contents/Resources/spark-runtime.json"), result.runtime);
300
+ if (mode === "release")
301
+ await prepareCustomizeArtifacts(root, result.runtime, destination);
302
+ copyHelpers(root, destination, readAppConfig(root).expo?.extra?.spark?.helpers);
303
+ if (mode === "release") {
304
+ // Hermes is prebuilt, so Xcode's app/Pod compiler settings cannot strip it.
305
+ const hermes = path.join(destination, "Contents/Frameworks/hermes.framework/Versions/Current/hermes");
306
+ if (existsSync(hermes))
307
+ await run(root, ["strip", "-S", "-x", hermes], { capture: true });
308
+ }
309
+ // Development apps can opt into a local identity for same-team native plugins.
310
+ // Standalone outputs remain ad-hoc until `spark package` signs its staging copy.
311
+ await run(root, ["codesign", "--force", "--deep", "--sign", localSigningIdentity(root, mode), destination], { capture: true });
312
+ writeJson(resultFile, result);
313
+ console.log(`Built ${destination}`);
314
+ return result;
315
+ }
316
+ async function prepareMacOS(root, chosen, force) {
204
317
  // RNW's CLI config probes for PowerShell when Expo autolinking loads it on macOS.
205
318
  const excludedNames = [...new Set([
206
319
  "react-native-windows",
@@ -229,8 +342,11 @@ async function buildUnlocked(root, mode, force) {
229
342
  pkg.expo.autolinking.exclude = excludedNames;
230
343
  writeJson(path.join(root, "package.json"), pkg);
231
344
  }
232
- const inputs = nativePreparationInputs(root, chosen.included);
233
- const preparation = { fingerprint: digest(JSON.stringify(inputs)), inputs, projectFingerprint: nativeProjectFingerprint(inputs, chosen.included) };
345
+ const currentPreparation = () => {
346
+ const inputs = nativePreparationInputs(root, chosen.included);
347
+ return { fingerprint: digest(JSON.stringify(inputs)), inputs, projectFingerprint: nativeProjectFingerprint(inputs, chosen.included) };
348
+ };
349
+ let preparation = currentPreparation();
234
350
  const preparedFile = stateFile(root, "native-preparation.json");
235
351
  const prepared = existsSync(preparedFile) ? readJson(preparedFile) : undefined;
236
352
  const nativeRoot = path.join(root, "macos");
@@ -238,26 +354,12 @@ async function buildUnlocked(root, mode, force) {
238
354
  const needsProject = force || !hasNativeProject || prepared?.projectFingerprint !== preparation.projectFingerprint;
239
355
  const needsPreparation = needsProject ||
240
356
  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("; ")}.`);
357
+ !existsSync(path.join(nativeRoot, "Podfile.lock")) ||
358
+ !existsSync(path.join(nativeRoot, "Pods/Manifest.lock")) ||
359
+ readFileSync(path.join(nativeRoot, "Podfile.lock"), "utf8") !== readFileSync(path.join(nativeRoot, "Pods/Manifest.lock"), "utf8");
259
360
  const nativeConfig = readAppConfig(root).expo;
260
- if (needsPreparation)
361
+ const missing = needsProject ? [] : missingNativeFrameworks(root);
362
+ if (needsPreparation || missing.length)
261
363
  rmSync(preparedFile, { force: true });
262
364
  if (needsProject) {
263
365
  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 +397,9 @@ async function buildUnlocked(root, mode, force) {
295
397
  force: true,
296
398
  });
297
399
  }
298
- const missing = missingNativeFrameworks(root);
299
400
  if (needsPreparation || missing.length) {
300
401
  if (needsPreparation && !needsProject)
301
- console.log(`Updating CocoaPods dependencies: ${prepared?.fingerprint !== preparation.fingerprint ? preparationChanges(prepared, preparation).join("; ") : "CocoaPods state missing"}.`);
402
+ console.log(`Updating CocoaPods dependencies: ${prepared?.fingerprint !== preparation.fingerprint ? preparationChanges(prepared, preparation).join("; ") : "CocoaPods state missing or stale"}.`);
302
403
  if (missing.length && !needsPreparation)
303
404
  console.log(`Restoring missing native frameworks:\n${missing.join("\n")}`);
304
405
  await run(root, ["pod", "install"], {
@@ -309,83 +410,14 @@ async function buildUnlocked(root, mode, force) {
309
410
  const remaining = missingNativeFrameworks(root);
310
411
  if (remaining.length)
311
412
  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
413
  }
314
414
  await restoreNativeMetadata(root, nativeConfig);
315
415
  const workspace = readdirSync(nativeRoot).find((name) => name.endsWith(".xcworkspace"));
316
416
  if (!workspace)
317
417
  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 });
418
+ if (needsPreparation || missing.length) {
419
+ preparation = currentPreparation();
420
+ writeJson(preparedFile, preparation);
384
421
  }
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;
422
+ return { preparation, nativeConfig, nativeRoot, workspace };
391
423
  }
@@ -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
  }