@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,10 +1,11 @@
1
1
  const fs = require('node:fs');
2
2
  const path = require('node:path');
3
+ const { installedSparkVersion, planMigrations, applyMigrationPlan } = require('./migrations.cjs');
3
4
  const { prepareConfig, toExpo } = require('@legendapp/spark-desktop-config/config.cjs');
4
5
 
5
6
  // Expo Desktop assigns the application names and native IDs. Initialize only
6
7
  // spark-owned configuration, once, after its template dependencies are installed.
7
- function initializeTemplate(root) {
8
+ function initializeTemplate(root, recordVersion = true) {
8
9
  const file = path.join(root, 'desktop.config.json');
9
10
  if (!fs.existsSync(file)) return;
10
11
  const config = JSON.parse(fs.readFileSync(file, 'utf8'));
@@ -13,6 +14,8 @@ function initializeTemplate(root) {
13
14
  if (!expo?.windows?.projectGuid || !expo.name || !expo.macos?.bundleIdentifier) {
14
15
  throw new Error('Create this template with expo-desktop create-app so its application identity is initialized.');
15
16
  }
17
+ const installed = recordVersion ? installedSparkVersion(root) : undefined;
18
+ const plan = installed ? planMigrations(root, installed, { automatic: true, fromVersion: installed }) : undefined;
16
19
  config.name = expo.name;
17
20
  config.projectId = expo.windows.projectGuid;
18
21
  config.expo = { ...expo, ...config.expo };
@@ -21,6 +24,13 @@ function initializeTemplate(root) {
21
24
  toExpo(config);
22
25
  fs.writeFileSync(file, JSON.stringify(config, null, 2) + '\n');
23
26
  prepareConfig(root);
27
+ if (plan) applyMigrationPlan(root, plan);
24
28
  }
25
29
  module.exports = { initializeTemplate };
26
- if (require.main === module) initializeTemplate(process.cwd());
30
+ if (require.main === module) {
31
+ const root = process.cwd();
32
+ require('@legendapp/spark-desktop-config/patch-registry.cjs').ensurePatchRegistry(root).then(() => {
33
+ initializeTemplate(root);
34
+ require('@legendapp/spark-desktop-config/native-patches.cjs').prepareNativePatches(root);
35
+ }).catch(error => { console.error(error.message); process.exitCode = 1; });
36
+ }
@@ -1 +1 @@
1
- export function initializeTemplate(root: string): void;
1
+ export function initializeTemplate(root: string, recordVersion?: boolean): void;
@@ -31,6 +31,7 @@ function withDesktop(config, options = {}) {
31
31
  // spark dev found Watchman unresponsive; crawl and watch with Node instead.
32
32
  ...(process.env.SPARK_METRO_NO_WATCHMAN === "1" ? { useWatchman: false } : {}) } };
33
33
  const root = path.resolve(config.projectRoot || process.cwd());
34
+ config = require("@legendapp/spark-expo-compat/metro.cjs").withExpoCompat(config);
34
35
  // Keep the configured workspace root so lazy imports outside the app have
35
36
  // valid URLs. Only the prebuilt host's fixed entry URLs are app-relative.
36
37
  const serverRoot = path.resolve(config.server?.unstable_serverRoot || root);
@@ -0,0 +1,65 @@
1
+ import { createRequire } from "node:module";
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { supportedPlatforms } from "@legendapp/spark-desktop-config/config.cjs";
5
+ import { dependencyPinIssues, expectedDependencyPins, optionalBackendIssues, projectDependencies } from "./dependency-pins.js";
6
+ import { applyMigrationPlan, planMigrations, printMigrationPlan } from "./migrations.cjs";
7
+ import { projectSparkVersion } from "./project-version.js";
8
+ import { readJson } from "./json.js";
9
+ export function migrate(root, { dryRun = false, init = false } = {}) {
10
+ readJson(path.join(root, "package.json"));
11
+ const version = projectSparkVersion(root);
12
+ const plan = planMigrations(root, version, { fromVersion: init ? version : undefined });
13
+ if (init && plan.previous !== version)
14
+ throw new Error("spark migrate --init is only for newly generated projects without a receipt, or projects already at the installed version. Run spark migrate --dry-run to review the existing receipt's migrations.");
15
+ console.log(`Spark ${plan.previous ?? "(unrecorded)"} → ${version}${init ? " — initialize generated project" : ""}${dryRun ? " — dry run" : ""}`);
16
+ printMigrationPlan(plan);
17
+ const blocked = plan.manualSteps.filter(step => step.requires).map(step => `${step.requires}: ${step.message}`);
18
+ for (const change of plan.changes) {
19
+ if (/(^|\/)(package\.json|(?:bun|package|npm-shrinkwrap|pnpm|yarn).*lock.*|pnpm-workspace\.yaml|\.npmrc|\.yarnrc\.yml|(?:desktop\.config|app|app\.config|metro\.config|react-native\.config)\.(?:json|[cm]?[jt]s))$/.test(change.file)) {
20
+ blocked.push(`Install inputs or configuration would change: ${change.file}.`);
21
+ }
22
+ }
23
+ const configFile = path.join(root, "desktop.config.json");
24
+ if (existsSync(configFile) && !readJson(configFile).projectId)
25
+ blocked.push("Template configuration is uninitialized. Create the project with expo-desktop create-app, then run node node_modules/@legendapp/spark/init-template.cjs.");
26
+ if (plan.versions.includes("0.0.2")) {
27
+ const req = createRequire(path.join(root, "package.json"));
28
+ const platforms = supportedPlatforms(root);
29
+ const pins = { ...expectedDependencyPins };
30
+ if (platforms.includes("windows"))
31
+ pins["react-native-windows"] = readJson(path.resolve(import.meta.dirname, "../templates/windows/package.json")).dependencies["react-native-windows"];
32
+ for (const issue of dependencyPinIssues({ dependencies: projectDependencies(root, true) }, platforms, pins))
33
+ blocked.push(`Install inputs: pin ${issue.package} to ${issue.expected} in its owning manifest (found ${issue.found}).`);
34
+ for (const [name, expected] of Object.entries(pins)) {
35
+ if (name === "react-native-macos" && !platforms.includes("macos"))
36
+ continue;
37
+ let installed;
38
+ try {
39
+ installed = readJson(req.resolve(`${name}/package.json`)).version;
40
+ }
41
+ catch (error) {
42
+ if (error.code !== "MODULE_NOT_FOUND")
43
+ throw error;
44
+ }
45
+ if (installed !== expected)
46
+ blocked.push(`Install ${name}@${expected}; resolved ${installed ?? "(missing)"}.`);
47
+ }
48
+ for (const issue of optionalBackendIssues(root, true))
49
+ blocked.push(`Install ${issue.package}@${issue.expected}: ${issue.where.join(" → ")}.`);
50
+ }
51
+ for (const reason of blocked)
52
+ console.log(`Blocked: ${reason}`);
53
+ if (blocked.length) {
54
+ const guidance = "Migrations require an install or configuration changes. Resolve the listed requirements in the owning project, or run spark upgrade to update release inputs and install, then retry spark migrate.";
55
+ if (!dryRun)
56
+ throw new Error(`${guidance} No app files changed.`);
57
+ console.log(guidance);
58
+ }
59
+ else if (!dryRun) {
60
+ applyMigrationPlan(root, plan);
61
+ console.log(`Migrated to installed Spark ${version}. Review .spark/upgrade-notes.md if present.`);
62
+ return;
63
+ }
64
+ console.log("No app files changed.");
65
+ }
@@ -50,7 +50,7 @@ function createMigrationContext(root, version, changes, manualSteps) {
50
50
  try {
51
51
  const value = JSON.parse(before);
52
52
  if (!value || typeof value !== 'object' || Array.isArray(value)) {
53
- context.manualStep(`Edit ${file} manually; expected a JSON object.`);
53
+ context.manualStep(`Edit ${file} manually; expected a JSON object.`, 'configuration');
54
54
  return;
55
55
  }
56
56
  const original = JSON.stringify(value);
@@ -62,7 +62,7 @@ function createMigrationContext(root, version, changes, manualSteps) {
62
62
  }
63
63
  } catch (error) {
64
64
  if (!(error instanceof SyntaxError)) throw error;
65
- context.manualStep(`Edit ${file} manually; it is not valid JSON: ${error.message}`);
65
+ context.manualStep(`Edit ${file} manually; it is not valid JSON: ${error.message}`, 'configuration');
66
66
  }
67
67
  },
68
68
  renameFile(from, to) {
@@ -83,9 +83,9 @@ function createMigrationContext(root, version, changes, manualSteps) {
83
83
  if (content === null || content === previous) context.writeFile(file, next);
84
84
  else if (content !== next) context.manualStep(`Merge the new template for ${file}; the app has customized it.`);
85
85
  },
86
- manualStep(message) {
86
+ manualStep(message, requires) {
87
87
  const notes = `${upgradeNotesPath}#${version.replaceAll('.', '')}`;
88
- if (!manualSteps.some(step => step.version === version && step.message === message)) manualSteps.push({ version, message, notes });
88
+ if (!manualSteps.some(step => step.version === version && step.message === message)) manualSteps.push({ version, message, notes, ...(requires ? { requires } : {}) });
89
89
  },
90
90
  replaceImport(from, to, names = {}) {
91
91
  /** @type {typeof import('typescript')} */
@@ -1,7 +1,7 @@
1
1
  export type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };
2
2
  export type JsonObject = { [key: string]: JsonValue };
3
3
  export interface FileChange { file: string; before: string | null; after: string | null }
4
- export interface ManualStep { version: string; message: string; notes: string }
4
+ export interface ManualStep { version: string; message: string; notes: string; requires?: "configuration" | "install" }
5
5
  export interface MigrationContext {
6
6
  readFile(file: string): string | null;
7
7
  writeFile(file: string, content: string): void;
@@ -9,7 +9,7 @@ export interface MigrationContext {
9
9
  renameFile(from: string, to: string): void;
10
10
  updateTemplate(file: string, previous: string, next: string): void;
11
11
  replaceImport(from: string, to: string, names?: Readonly<Record<string, string>>): void;
12
- manualStep(message: string): void;
12
+ manualStep(message: string, requires?: ManualStep["requires"]): void;
13
13
  }
14
14
  export const upgradeNotesPath: string;
15
15
  export function createMigrationContext(root: string, version: string, changes: Map<string, FileChange>, manualSteps: ManualStep[]): MigrationContext;
@@ -51,24 +51,24 @@ function upgradeWindowConfig(context) {
51
51
  context.editJson(file, /** @param {{ window?: import('./migration-helpers.cjs').JsonObject; expo?: { extra?: { spark?: { window?: import('./migration-helpers.cjs').JsonObject } } } }} config */ config => {
52
52
  const options = file === 'desktop.config.json' ? config.window : config.expo?.extra?.spark?.window;
53
53
  if (!options) return;
54
- if (typeof options !== 'object' || Array.isArray(options)) { context.manualStep(`Repair window configuration in ${file}; expected an object.`); return; }
54
+ if (typeof options !== 'object' || Array.isArray(options)) { context.manualStep(`Repair window configuration in ${file}; expected an object.`, 'configuration'); return; }
55
55
  for (const [nested, width, height] of [['size', 'width', 'height'], ['minSize', 'minWidth', 'minHeight'], ['maxSize', 'maxWidth', 'maxHeight']]) {
56
56
  if (!(width in options) && !(height in options)) continue;
57
57
  if (typeof options[width] !== 'number' || typeof options[height] !== 'number' || options[nested] !== undefined) {
58
- context.manualStep(`Merge legacy ${width}/${height} into window.${nested} in ${file}; incomplete or conflicting dimensions need review.`);
58
+ context.manualStep(`Merge legacy ${width}/${height} into window.${nested} in ${file}; incomplete or conflicting dimensions need review.`, 'configuration');
59
59
  } else {
60
60
  options[nested] = { width: options[width], height: options[height] };
61
61
  delete options[width]; delete options[height];
62
62
  }
63
63
  }
64
64
  if ('restoreFrame' in options) {
65
- if ('restoreBounds' in options && options.restoreBounds !== options.restoreFrame) context.manualStep(`Resolve window.restoreFrame/restoreBounds in ${file}.`);
65
+ if ('restoreBounds' in options && options.restoreBounds !== options.restoreFrame) context.manualStep(`Resolve window.restoreFrame/restoreBounds in ${file}.`, 'configuration');
66
66
  else { options.restoreBounds = options.restoreFrame; delete options.restoreFrame; }
67
67
  }
68
68
  for (const [legacy, nested] of [['material', 'backgroundMaterial'], ['trafficLights', 'titleBar']]) {
69
69
  if (!(legacy in options)) continue;
70
70
  const macos = /** @type {import('./migration-helpers.cjs').JsonObject} */ (options.macos ?? {});
71
- if (typeof macos !== 'object' || Array.isArray(macos) || macos[nested] !== undefined) context.manualStep(`Merge window.${legacy} into window.macos.${nested} in ${file}.`);
71
+ if (typeof macos !== 'object' || Array.isArray(macos) || macos[nested] !== undefined) context.manualStep(`Merge window.${legacy} into window.macos.${nested} in ${file}.`, 'configuration');
72
72
  else {
73
73
  macos[nested] = legacy === 'trafficLights' ? { trafficLights: options[legacy] } : options[legacy];
74
74
  options.macos = macos; delete options[legacy];
@@ -103,6 +103,12 @@ const migrations = [
103
103
  { version: '0.0.3', automatic: false, breaking: true, apply(context) {
104
104
  context.manualStep('Apps using the default macOS react-native-mmkv@4.3.2 store must plan data migration from ~/Documents/mmkv to ~/Library/Application Support/<Spark namespace>/mmkv before deployment. Existing files are not moved automatically and the old folder can contain other apps\' data. Back up the store, preserve IDs and encryption keys, and validate values and relaunch persistence; see the linked upgrade notes.');
105
105
  } },
106
+ { version: '0.0.4', automatic: false, breaking: true, apply(context) {
107
+ context.manualStep('Quit older builds, back up macOS file/MMKV data, keep bundle identifiers stable, and rebuild custom hosts. First launch automatically migrates owned legacy data to ~/Library/Application Support/<bundle id>/Spark; ambiguous sources and IO errors stop startup. Review any reported conflict without overwriting data, then verify file/MMKV values and relaunch persistence; see the linked upgrade notes.');
108
+ } },
109
+ { version: '0.0.5', automatic: false, breaking: true, apply(context) {
110
+ context.manualStep('For macOS settings windows, replace @legendapp/spark/settings/window with @legendapp/spark/ui/settings, install @legendapp/list if missing, and migrate the pages and rows to the new JSX API. See the linked upgrade notes and verify the settings window after rebuilding custom macOS hosts.');
111
+ } },
106
112
  ];
107
113
 
108
114
  /** @param {string} root */
@@ -114,13 +120,13 @@ function installedSparkVersion(root) {
114
120
  /** @type {typeof import('./migrations.cjs').planMigrations} */
115
121
  function planMigrations(root, version, { automatic = false, fromVersion } = {}) {
116
122
  const { compare, valid } = createRequire(resolveDependency(root, 'npm/package.json'))('semver');
117
- const file = path.join(root, '.spark/version');
118
- const previous = fs.existsSync(file) ? fs.readFileSync(file, 'utf8').trim() : fromVersion;
123
+ const receipt = createMigrationContext(root, version, new Map(), []).readFile('.spark/version');
124
+ const previous = receipt === null ? fromVersion : receipt.trim();
119
125
  if (!valid(version) || (previous !== undefined && (!valid(previous) || compare(previous, version) > 0))) {
120
126
  throw new Error(`Spark project version ${previous ?? '(unrecorded)'} cannot migrate to ${version}. Run spark upgrade.`);
121
127
  }
122
128
  const pending = migrations.filter(step => (!previous || compare(step.version, previous) > 0) && compare(step.version, version) <= 0).sort((a, b) => compare(a.version, b.version));
123
- if (automatic && pending.some(step => !step.automatic)) throw new Error('Spark has pending migrations that require an install or configuration changes. Run spark upgrade.');
129
+ if (automatic && pending.some(step => !step.automatic)) throw new Error('Spark has pending migrations. Run spark migrate --dry-run, then spark migrate to apply at the installed version. Run spark upgrade if an install or configuration changes are required.');
124
130
  const changes = new Map();
125
131
  /** @type {import('./migration-helpers.cjs').ManualStep[]} */
126
132
  const manualSteps = [];
@@ -165,8 +171,9 @@ function applyMigrationPlan(root, plan, recordVersion = true) {
165
171
 
166
172
  /** @type {typeof import('./migrations.cjs').recordProjectVersion} */
167
173
  function recordProjectVersion(root, version) {
174
+ const context = createMigrationContext(root, version, new Map(), []);
168
175
  const file = path.join(root, '.spark/version');
169
- if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === version + '\n') return;
176
+ if (context.readFile('.spark/version') === version + '\n') return;
170
177
  // Record only successful migrations. A failed/partial attempt is safe to retry.
171
178
  fs.mkdirSync(path.dirname(file), { recursive: true });
172
179
  const temporary = `${file}.${process.pid}.tmp`;
@@ -1,21 +1,24 @@
1
+ import { patchDisabled } from "@legendapp/spark-desktop-config/patch-registry.cjs";
1
2
  import { assertEnrichedHtmlPins } from "./enriched-html-pins.js";
2
3
  import { createHash } from "node:crypto";
3
4
  import { existsSync, readFileSync } from "node:fs";
4
5
  import path from "node:path";
5
- import { prepareNativePatches } from "@legendapp/spark-desktop-config/native-patches.cjs";
6
+ import { appPatches, prepareNativePatches } from "@legendapp/spark-desktop-config/native-patches.cjs";
6
7
  import { findFramework } from "./local.js";
7
8
  import { installedPackages, readJson, VERSION } from "./project.js";
8
9
  const required = ["@react-native-runtimes/core", "react-native-nitro-modules"];
9
10
  const optional = ["@op-engineering/op-sqlite", "react-native-webview", "expo-audio"];
10
- export function validatePackedNativePatches(packages, requirements, frameworkVersion = VERSION) {
11
+ export function validatePackedNativePatches(packages, requirements, frameworkVersion = VERSION, disabled = []) {
11
12
  if (!requirements || requirements.schema !== 1 || requirements.frameworkVersion !== frameworkVersion || !requirements.packages || typeof requirements.packages !== "object")
12
13
  return [`The installed @legendapp/spark SDK does not include native patch provenance for ${frameworkVersion}. Run spark add desktop to install the matching SDK packages, then retry.`];
13
14
  const installed = new Map(packages.map(pkg => [pkg.name, pkg.json]));
14
15
  const errors = [];
15
16
  for (const name of required)
16
- if (!installed.has(name))
17
+ if (!disabled.includes(name) && !installed.has(name))
17
18
  errors.push(`${name} is missing; reinstall the dependencies from this Spark SDK.`);
18
19
  for (const name of [...required, ...optional]) {
20
+ if (disabled.includes(name))
21
+ continue;
19
22
  const actual = installed.get(name);
20
23
  if (!actual)
21
24
  continue;
@@ -29,7 +32,7 @@ export function validatePackedNativePatches(packages, requirements, frameworkVer
29
32
  }
30
33
  return errors;
31
34
  }
32
- export function validateWorkspaceNativePatches(root, packages) {
35
+ export function validateWorkspaceNativePatches(root, packages, disabled = []) {
33
36
  const framework = findFramework(root);
34
37
  if (!framework)
35
38
  return ["The Spark SDK is missing native patch provenance. Run spark add desktop to install matching SDK packages, then retry."];
@@ -41,6 +44,8 @@ export function validateWorkspaceNativePatches(root, packages) {
41
44
  const installed = new Map(packages.map(pkg => [pkg.name, pkg]));
42
45
  const errors = [];
43
46
  for (const name of [...required, ...optional]) {
47
+ if (disabled.includes(name))
48
+ continue;
44
49
  const pkg = installed.get(name);
45
50
  if (!pkg) {
46
51
  if (required.includes(name))
@@ -68,6 +73,24 @@ export function validateWorkspaceNativePatches(root, packages) {
68
73
  }
69
74
  return errors;
70
75
  }
76
+ /** Each patched package's receipt must name the Spark and app patch layers the app currently declares. */
77
+ export function validateAppPatches(root, packages) {
78
+ const app = readJson(path.join(root, "package.json"));
79
+ const patches = app.name === "@legendapp/spark" ? {} : appPatches(root, app);
80
+ const errors = [];
81
+ for (const pkg of packages) {
82
+ const receipt = pkg.json.spark?.dependencyPatch;
83
+ if (!receipt)
84
+ continue;
85
+ const own = patches[pkg.name];
86
+ const appPatchHash = own && createHash("sha256").update(own.bytes).digest("hex");
87
+ if (receipt.appPatchHash !== appPatchHash)
88
+ errors.push(`${pkg.name}@${pkg.json.version} does not carry ${own?.file ?? "the app's current patches"}. Reinstall ${pkg.name}, then retry.`);
89
+ if (app.spark?.patches?.[pkg.name] === false && receipt.patchHash)
90
+ errors.push(`${pkg.name}@${pkg.json.version} still has Spark's patch, which spark.patches disables. Reinstall ${pkg.name}, then retry.`);
91
+ }
92
+ return errors;
93
+ }
71
94
  export function assertNativePatchPreflight(root) {
72
95
  assertEnrichedHtmlPins(root);
73
96
  const packages = installedPackages(root);
@@ -76,13 +99,18 @@ export function assertNativePatchPreflight(root) {
76
99
  let errors;
77
100
  const spark = packages.find(pkg => pkg.name === "@legendapp/spark");
78
101
  const requirements = spark?.json.spark?.nativePatchRequirements;
102
+ const disabled = [...required, ...optional].filter(name => {
103
+ const pkg = packages.find(pkg => pkg.name === name);
104
+ return patchDisabled(root, name, pkg && path.join(pkg.root, "package.json"));
105
+ });
79
106
  if (requirements)
80
- errors = validatePackedNativePatches(packages, requirements);
107
+ errors = validatePackedNativePatches(packages, requirements, VERSION, disabled);
81
108
  else if (framework)
82
- errors = validateWorkspaceNativePatches(root, packages);
109
+ errors = validateWorkspaceNativePatches(root, packages, disabled);
83
110
  else {
84
- errors = validatePackedNativePatches(packages, requirements);
111
+ errors = validatePackedNativePatches(packages, requirements, VERSION, disabled);
85
112
  }
113
+ errors.push(...validateAppPatches(root, packages));
86
114
  if (errors.length)
87
115
  throw new Error(`Native patch preparation stopped before changing project files:\n${errors.map(error => `- ${error}`).join("\n")}`);
88
116
  }
@@ -7,7 +7,7 @@ import path from "node:path";
7
7
  import { build } from "./build.js";
8
8
  import { credentials, notaryAuth } from "./credentials.js";
9
9
  import { run } from "./commands.js";
10
- import { appEntitlements, distributionEntitlements, signApp, validateApp } from "./signing.js";
10
+ import { releaseAppExpectation, signApp, validateApp } from "./signing.js";
11
11
  import { digest, readJson, stateFile, writeJson } from "./project.js";
12
12
  export function artifactHash(file) {
13
13
  const hash = createHash("sha256");
@@ -68,14 +68,9 @@ async function packageUnlocked(root, options, deps) {
68
68
  const config = readAppConfig(root).expo;
69
69
  if (config.extra?.spark?.updates && !result.runtime.modules["@legendapp/spark-updates"])
70
70
  throw new Error("Updates are configured but the module was pruned. Import @legendapp/spark/updates from the app entry.");
71
- const entitlements = distributionEntitlements(appEntitlements(root, result.runtime.modules));
72
- if (!config.macos?.bundleIdentifier || !config.version)
73
- throw new Error("Packaging requires macos.bundleIdentifier and version");
74
- const byPath = config.extra?.spark?.signing?.macos?.entitlementsByPath ?? {};
75
71
  const info = JSON.parse(await execute(root, ["plutil", "-convert", "json", "-o", "-", path.join(result.app, "Contents/Info.plist")], { capture: true }));
76
- const expected = { arch: result.runtime.arch, runner: options.runner, bundleId: config.macos.bundleIdentifier, version: config.version, buildVersion: info.CFBundleVersion, entitlements, byPath };
77
- if (!expected.bundleId || !expected.version || !expected.buildVersion)
78
- throw new Error("Bundle identifier and release version metadata must be configured before packaging.");
72
+ const expected = releaseAppExpectation(root, result.runtime, config, info.CFBundleVersion);
73
+ const { entitlements, byPath } = expected;
79
74
  const inputHash = artifactHash(result.app);
80
75
  const key = digest(JSON.stringify({ recipe: 1, inputHash, identity: identity.hash, entitlements, byPath }));
81
76
  const folder = stateFile(root, `packaging/${key}`);
@@ -90,6 +85,7 @@ async function packageUnlocked(root, options, deps) {
90
85
  if (!existsSync(app) || artifactHash(app) !== state.stagedHash || !existsSync(upload) || createHash("sha256").update(readFileSync(upload)).digest("hex") !== state.archiveHash) {
91
86
  throw new Error(`The staged notarization artifacts changed. Preserve ${statePath} for submission recovery; rebuild from clean inputs before retrying.`);
92
87
  }
88
+ await validateApp(root, app, identity, expected, false, execute);
93
89
  }
94
90
  else {
95
91
  rmSync(app, { recursive: true, force: true });
@@ -0,0 +1,92 @@
1
+ import { createHash } from "node:crypto";
2
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { createTwoFilesPatch } from "diff";
7
+ import { appPatches, layerPatches, prepareNativePatches, resolveManifest, withoutReceipt } from "@legendapp/spark-desktop-config/native-patches.cjs";
8
+ import { readJson } from "./project.js";
9
+ function files(directory, relative = "") {
10
+ if (!existsSync(path.join(directory, relative)))
11
+ return [];
12
+ return readdirSync(path.join(directory, relative), { withFileTypes: true }).flatMap(entry => {
13
+ const child = relative ? `${relative}/${entry.name}` : entry.name;
14
+ if (entry.name === "node_modules" || entry.name === ".git")
15
+ return [];
16
+ return entry.isDirectory() ? files(directory, child) : [child];
17
+ });
18
+ }
19
+ const read = (file) => existsSync(file) ? readFileSync(file, "utf8") : undefined;
20
+ /** The nearest folder from start that owns app patches: a Spark app, a patches/ folder or a package.json with a spark field. */
21
+ export function patchRoot(start) {
22
+ for (let dir = path.resolve(start);; dir = path.dirname(dir)) {
23
+ const manifest = path.join(dir, "package.json");
24
+ if (existsSync(path.join(dir, "patches")) || (existsSync(manifest) &&
25
+ (existsSync(path.join(dir, "app.json")) || existsSync(path.join(dir, "desktop.config.json")) || readJson(manifest).spark)))
26
+ return dir;
27
+ if (path.dirname(dir) === dir)
28
+ throw new Error("No patches/ folder or Spark app found. Run spark patch inside your app or pass --root.");
29
+ }
30
+ }
31
+ /**
32
+ * Two steps, like patch-package: the first copies the library installed for root with Spark's patch (and
33
+ * without the app's) to a temporary folder for editing; `done` saves the edits as <out>/patches/<name>@<version>.patch.
34
+ * The installed copy follows only patches saved in root's own patches/.
35
+ */
36
+ export function patchLibrary(root, name, { done = false, force = false, out = root } = {}) {
37
+ prepareNativePatches(root);
38
+ let manifest;
39
+ try {
40
+ manifest = resolveManifest(createRequire(path.join(root, "package.json")), name);
41
+ }
42
+ catch {
43
+ throw new Error(`${name} is not installed in ${root}.`);
44
+ }
45
+ const installed = realpathSync(path.dirname(manifest));
46
+ const { version } = readJson(manifest);
47
+ const manifestOut = path.join(out, "package.json");
48
+ const own = appPatches(out, existsSync(manifestOut) ? readJson(manifestOut) : {})[name];
49
+ if (own?.thirdParty)
50
+ throw new Error(`${own.file} already patches ${name} through your package manager. Remove it and reinstall ${name} before using spark patch.`);
51
+ const file = path.join("patches", `${name.replace("/", "+")}@${version}.patch`);
52
+ const work = path.join(os.tmpdir(), "spark-patch", createHash("sha256").update(root).digest("hex").slice(0, 12), `${name.replace("/", "+")}@${version}`);
53
+ const base = path.join(work, "base"), edit = path.join(work, "edit");
54
+ if (!done) {
55
+ if (existsSync(edit) && !force) {
56
+ console.log(`${name} is already prepared for editing in ${edit}\nRun spark patch ${name} --done to save it, or --force to start over.`);
57
+ return edit;
58
+ }
59
+ rmSync(work, { recursive: true, force: true });
60
+ cpSync(installed, base, { recursive: true, filter: source => !["node_modules", ".git", ".spark-app.patch"].includes(path.relative(installed, source).split(path.sep)[0]) });
61
+ writeFileSync(path.join(base, "package.json"), withoutReceipt(readFileSync(path.join(base, "package.json"), "utf8")));
62
+ if (own)
63
+ layerPatches(base, name, [undefined, { text: own.bytes.toString("utf8"), apply: false, error: () => "" }]);
64
+ cpSync(base, edit, { recursive: true });
65
+ console.log(`Edit ${name}@${version} in ${edit}\nThen run spark patch ${name} --done to save ${file}.`);
66
+ return edit;
67
+ }
68
+ if (!existsSync(edit))
69
+ throw new Error(`Run spark patch ${name} first, edit the copy it prints, then rerun with --done.`);
70
+ let diff = "";
71
+ for (const relative of [...new Set([...files(base), ...files(edit)])].sort()) {
72
+ const before = read(path.join(base, relative)), after = read(path.join(edit, relative));
73
+ if (before === after)
74
+ continue;
75
+ if (after === undefined)
76
+ throw new Error(`App patches can't delete ${relative}; empty it instead.`);
77
+ if (after.includes("\0"))
78
+ throw new Error(`App patches can't change binary file ${relative}.`);
79
+ diff += `diff --git a/${relative} b/${relative}\n` + createTwoFilesPatch(before === undefined ? "/dev/null" : `a/${relative}`, `b/${relative}`, before ?? "", after).replace(/^=+\n/, "");
80
+ }
81
+ if (diff) {
82
+ mkdirSync(path.join(out, "patches"), { recursive: true });
83
+ writeFileSync(path.join(out, file), diff);
84
+ }
85
+ else
86
+ rmSync(path.join(out, file), { force: true });
87
+ if (out === root)
88
+ prepareNativePatches(root);
89
+ rmSync(work, { recursive: true, force: true });
90
+ console.log(diff ? `Saved ${file}.` : `No changes to ${name}; ${file} is absent.`);
91
+ return path.join(out, file);
92
+ }
@@ -1,12 +1,20 @@
1
1
  import { initializeTemplate } from "./init-template.cjs";
2
- import { installedSparkVersion, migrateProject } from "./migrations.cjs";
2
+ import { installedSparkVersion, migrateProject, planMigrations } from "./migrations.cjs";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { readJson } from "./json.js";
5
5
  const version = readJson(fileURLToPath(new URL("../package.json", import.meta.url))).version;
6
- export function ensureProjectVersion(root) {
6
+ export function projectSparkVersion(root) {
7
7
  const installed = installedSparkVersion(root);
8
8
  if (installed !== version)
9
9
  throw new Error(`This CLI is Spark ${version}, but the app has ${installed}. Run spark upgrade using the app's installed CLI.`);
10
- migrateProject(root, installed);
11
- initializeTemplate(root);
10
+ return installed;
11
+ }
12
+ export function ensureProjectVersion(root, { readOnly = false } = {}) {
13
+ const version = projectSparkVersion(root);
14
+ if (readOnly)
15
+ planMigrations(root, version);
16
+ else {
17
+ migrateProject(root, version);
18
+ initializeTemplate(root, false);
19
+ }
12
20
  }
@@ -1,3 +1,5 @@
1
+ import { patchSourceSHA } from "@legendapp/spark-desktop-config/patch-registry.cjs";
2
+ import { SparkError, validatePackageSettings } from "@legendapp/spark-desktop-config/validation.cjs";
1
3
  import { assertEnrichedHtmlPins } from "./enriched-html-pins.js";
2
4
  import { nativeWindowOptions } from "@legendapp/spark-window-options";
3
5
  import { prepareNativePatches, removeExpoApplicationAlias } from "@legendapp/spark-desktop-config/native-patches.cjs";
@@ -12,7 +14,7 @@ import { existsSync, readFileSync, readdirSync, realpathSync, } from "node:fs";
12
14
  import path from "node:path";
13
15
  import { readJson, writeJson } from "./json.js";
14
16
  export { readJson, writeJson };
15
- export const VERSION = "0.0.3";
17
+ export const VERSION = "0.0.5";
16
18
  export function digest(value) {
17
19
  return createHash("sha256").update(value).digest("hex");
18
20
  }
@@ -35,6 +37,7 @@ export function installedPackages(root) {
35
37
  const visited = new Set();
36
38
  while (queue.length) {
37
39
  const current = queue.shift();
40
+ validatePackageSettings(current.json.spark, current.root);
38
41
  const contextualRequire = createRequire(path.join(current.root, current.json.spark?.bundledModuleRoot ?? ".", "package.json"));
39
42
  const bundled = current.json.spark?.bundledModules ?? current.json.bundledDependencies ?? current.json.bundleDependencies;
40
43
  const names = Object.keys({
@@ -77,6 +80,8 @@ export function installedPackages(root) {
77
80
  catch { }
78
81
  }
79
82
  if (!file || !existsSync(file)) {
83
+ if (current.json.spark?.bundledModules?.includes(name))
84
+ throw new SparkError(`package.json spark.bundledModules includes missing package ${name}`);
80
85
  if (current.app &&
81
86
  (current.json.dependencies?.[name] || current.json.devDependencies?.[name]))
82
87
  throw new Error(`Dependency ${name} is not installed yet. Finish the package installation, then retry.`);
@@ -337,6 +342,7 @@ export function runtimeFor(root, packages, mode) {
337
342
  return {
338
343
  schema: 1,
339
344
  framework: VERSION,
345
+ patchSourceSHA: patchSourceSHA(root),
340
346
  platform,
341
347
  arch: architecture(platform),
342
348
  mode,
@@ -412,6 +418,7 @@ export function projectEnvironment(root) {
412
418
  return {
413
419
  SPARK_WINDOW_CONFIG: JSON.stringify(nativeWindowOptions(config.extra?.spark?.window ?? {})),
414
420
  SPARK_PROJECT_ID: projectId,
421
+ ...(typeof config.macos?.bundleIdentifier === "string" ? { SPARK_PROJECT_BUNDLE_IDENTIFIER: config.macos.bundleIdentifier } : {}),
415
422
  SPARK_PROJECT_NAME: typeof config.name === "string" ? config.name : path.basename(root),
416
423
  SPARK_PROJECT_VERSION: typeof config.version === "string" ? config.version : "0.0.0",
417
424
  };
@@ -0,0 +1,32 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import { existsSync, mkdirSync, renameSync, rmSync } from "node:fs";
4
+ import path from "node:path";
5
+ // Node's rename cannot replace a nonempty directory. macOS can exchange their names.
6
+ const source = `#include <stdio.h>
7
+ int main(int argc, char **argv) {
8
+ if (argc != 3) return 2;
9
+ if (renamex_np(argv[1], argv[2], RENAME_SWAP) == 0) return 0;
10
+ perror("Cannot swap Spark build directories");
11
+ return 1;
12
+ }
13
+ `;
14
+ export function publishDirectory(staged, target, tools) {
15
+ if (!existsSync(target)) {
16
+ renameSync(staged, target);
17
+ return;
18
+ }
19
+ const tool = path.join(tools, `swap-${createHash("sha256").update(source).digest("hex").slice(0, 16)}`);
20
+ if (!existsSync(tool)) {
21
+ mkdirSync(tools, { recursive: true });
22
+ const pending = `${tool}.${process.pid}.tmp`;
23
+ try {
24
+ execFileSync("xcrun", ["clang", "-x", "c", "-o", pending, "-"], { input: source });
25
+ renameSync(pending, tool);
26
+ }
27
+ finally {
28
+ rmSync(pending, { force: true });
29
+ }
30
+ }
31
+ execFileSync(tool, [staged, target]);
32
+ }