@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.
- package/init-template.cjs +7 -1
- package/package.json +10 -5
- package/patches/dependencies.json +4 -4
- package/patches/react-native-mmkv@4.3.2.patch +2 -2
- package/patches/react-native-nitro-zxing@0.3.1.patch +22 -0
- package/patches/registry.json +615 -0
- package/patches/workspace/expo-audio@55.0.18.patch +159 -0
- package/patches/workspace/op-engineering-op-sqlite@18.2.1.patch +796 -0
- package/patches/workspace/react-native-nitro-modules@0.37.0.patch +1348 -0
- package/patches/workspace/react-native-runtimes-core@0.1.0-alpha.2.patch +276 -0
- package/patches/workspace/react-native-webview@16.0.0.patch +208 -0
- package/postinstall.cjs +10 -1
- package/skills/spark/SKILL.md +37 -4
- package/skills/spark/UPGRADING.md +116 -1
- package/skills/spark/ai-customize.md +39 -0
- package/skills/spark/app-and-documents.md +56 -0
- package/skills/spark/external-libraries.md +87 -0
- package/skills/spark/files.md +64 -0
- package/skills/spark/integrations.md +69 -0
- package/skills/spark/keyboard.md +54 -0
- package/skills/spark/library-compat.md +76 -0
- package/skills/spark/menus-tray-dock.md +83 -0
- package/skills/spark/storage-settings.md +85 -0
- package/skills/spark/ui.md +57 -0
- package/skills/spark/windows.md +91 -0
- package/ui-popover.ts +1 -0
- package/ui-progress.ts +1 -0
- package/ui-sheet.ts +1 -0
- package/ui-split-view.ts +1 -0
- package/ui-table.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-audio/package.json +3 -13
- package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +5 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +137 -105
- package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +4 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/commands.js +16 -7
- package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +19 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/dev-command.js +2 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +3 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/enriched-html-pins.js +2 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/errors.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +57 -9
- package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.cjs +12 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.d.cts +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/metro.cjs +1 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migrate.js +65 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +4 -4
- package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +2 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +12 -8
- package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +35 -7
- package/vendor/node_modules/@legendapp/spark-cli/dist/patch.js +92 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/project-version.js +12 -4
- package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +8 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +20 -20
- package/vendor/node_modules/@legendapp/spark-cli/dist/upgrade.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +3 -0
- package/vendor/node_modules/@legendapp/spark-cli/package.json +5 -4
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-clipboard/macos/RNDesktopClipboard.mm +1 -1
- package/vendor/node_modules/@legendapp/spark-clipboard/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-clipboard/src/desktop.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-codex/package.json +3 -7
- package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-context-menu/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.h +3 -1
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +51 -10
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.h +4 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.mm +82 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +2 -8
- package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +6 -8
- package/vendor/node_modules/@legendapp/spark-desktop-config/identity.cjs +2 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +300 -71
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +7 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.cjs +318 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.d.cts +20 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/validation.cjs +66 -9
- package/vendor/node_modules/@legendapp/spark-desktop-config/windows.plugin.cjs +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/RNDesktopWindows.mm +7 -2
- package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +235 -240
- package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +4 -11
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/api.ts +9 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +7 -0
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/types.ts +32 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/validation.ts +28 -11
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/createWindowsNavigator.tsx +15 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/primaryWindowLifecycle.ts +12 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/usePrimaryWindowLifecycle.ts +2 -1
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/useWindowFocusEffect.ts +4 -1
- package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
- package/vendor/node_modules/@legendapp/spark-drag-drop/macos/RNDesktopDragView.mm +77 -17
- package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +3 -8
- package/vendor/node_modules/@legendapp/spark-drag-drop/src/DesktopDragViewNativeComponent.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-drag-drop/src/contracts.ts +13 -4
- package/vendor/node_modules/@legendapp/spark-drag-drop/src/index.tsx +5 -3
- package/vendor/node_modules/@legendapp/spark-drag-drop/windows/SparkDragDrop/SparkDragDrop.h +6 -1
- package/vendor/node_modules/@legendapp/spark-expo-compat/metro.cjs +44 -0
- package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +20 -0
- package/vendor/node_modules/@legendapp/spark-expo-compat/src/clipboard.ts +40 -0
- package/vendor/node_modules/@legendapp/spark-expo-compat/src/document-picker.ts +52 -0
- package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-file-dialog/src/options.ts +5 -2
- package/vendor/node_modules/@legendapp/spark-file-dialog/src/types.ts +3 -3
- package/vendor/node_modules/@legendapp/spark-file-system/macos/RNDesktopFileSystem.mm +1 -1
- package/vendor/node_modules/@legendapp/spark-file-system/package.json +3 -11
- package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-message-dialog/src/index.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-native-menu/package.json +3 -9
- package/vendor/node_modules/@legendapp/spark-native-menu/src/hooks.ts +4 -0
- package/vendor/node_modules/@legendapp/spark-notifications/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-processes/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-system/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-tray/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-tray/src/index.ts +2 -1
- package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkButton.mm +82 -14
- package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.h +1 -1
- package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.mm +94 -11
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +235 -18
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.h +17 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.mm +216 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.h +4 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.mm +212 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewUpdates.h +6 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +26 -13
- package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.mm +126 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.mm +66 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.mm +118 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/sf-symbol/RNSFSymbol.mm +4 -12
- package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.mm +109 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +418 -102
- package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.mm +179 -0
- package/vendor/node_modules/@legendapp/spark-ui/package.json +9 -8
- package/vendor/node_modules/@legendapp/spark-ui/src/SparkButtonNativeComponent.ts +10 -2
- package/vendor/node_modules/@legendapp/spark-ui/src/SparkTextInputNativeComponent.ts +2 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitView.tsx +99 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitViewNativeComponent.ts +29 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +34 -17
- package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +5 -4
- package/vendor/node_modules/@legendapp/spark-ui/src/checkbox-unavailable.tsx +20 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +24 -3
- package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +63 -13
- package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +12 -7
- package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +12 -7
- package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +35 -13
- package/vendor/node_modules/@legendapp/spark-ui/src/mobile-input.tsx +2 -2
- package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSegmentedControlNativeComponent.ts +3 -1
- package/vendor/node_modules/@legendapp/spark-ui/src/popover/PopoverNativeComponent.ts +20 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/popover/index.tsx +45 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/progress/ProgressIndicatorNativeComponent.ts +13 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/progress/index.tsx +32 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/radio-group/RadioGroupNativeComponent.ts +17 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/sheet/SheetNativeComponent.ts +15 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/sheet/index.tsx +38 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarItemNativeComponent.ts +9 -1
- package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarNativeComponent.ts +17 -2
- package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/index.tsx +106 -22
- package/vendor/node_modules/@legendapp/spark-ui/src/table/TableNativeComponent.ts +22 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/table/index.tsx +118 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +39 -6
- package/vendor/node_modules/@legendapp/spark-ui/uniwind.ts +3 -1
- package/vendor/node_modules/@legendapp/spark-ui/uniwind.web.ts +2 -1
- package/vendor/node_modules/@legendapp/spark-ui/windows/SparkUI/SparkUI.h +46 -15
- package/vendor/node_modules/@legendapp/spark-updates/package.json +3 -9
- package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const os = require("node:os");
|
|
4
|
+
const { createHash } = require("node:crypto");
|
|
5
|
+
const { createRequire } = require("node:module");
|
|
6
|
+
const { spawnSync } = require("node:child_process");
|
|
7
|
+
const { validatePackageSettings } = require("./validation.cjs");
|
|
8
|
+
|
|
9
|
+
const sources = new Map();
|
|
10
|
+
const offeredUpgrades = new Set();
|
|
11
|
+
const hash = bytes => createHash("sha256").update(bytes).digest("hex");
|
|
12
|
+
const read = file => JSON.parse(fs.readFileSync(file, "utf8"));
|
|
13
|
+
const exact = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?$/;
|
|
14
|
+
function compareVersions(a, b) {
|
|
15
|
+
if (!exact.test(a) || !exact.test(b)) throw new Error(`Expected exact version: ${a}, ${b}`);
|
|
16
|
+
const [av, ap] = a.split("-", 2), [bv, bp] = b.split("-", 2);
|
|
17
|
+
const an = av.split(".").map(Number), bn = bv.split(".").map(Number);
|
|
18
|
+
for (let i = 0; i < 3; i++) if (an[i] !== bn[i]) return an[i] > bn[i] ? 1 : -1;
|
|
19
|
+
if (ap === undefined || bp === undefined) return ap === bp ? 0 : ap === undefined ? 1 : -1;
|
|
20
|
+
const aa = a.slice(av.length + 1).split("."), bb = b.slice(bv.length + 1).split(".");
|
|
21
|
+
for (let i = 0; i < Math.max(aa.length, bb.length); i++) {
|
|
22
|
+
if (aa[i] === bb[i]) continue;
|
|
23
|
+
if (aa[i] === undefined || bb[i] === undefined) return aa[i] === undefined ? -1 : 1;
|
|
24
|
+
const na = /^\d+$/.test(aa[i]), nb = /^\d+$/.test(bb[i]);
|
|
25
|
+
if (na !== nb) return na ? -1 : 1;
|
|
26
|
+
return na ? (BigInt(aa[i]) > BigInt(bb[i]) ? 1 : -1) : aa[i] > bb[i] ? 1 : -1;
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
function object(value, fields, label) {
|
|
31
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`Malformed patch registry: ${label} must be an object`);
|
|
32
|
+
for (const key of Object.keys(value)) if (fields && !fields.includes(key)) throw new Error(`Malformed patch registry: unknown ${label}.${key}`);
|
|
33
|
+
}
|
|
34
|
+
function validateRegistry(value) {
|
|
35
|
+
object(value, ["schema", "libraries"], "registry");
|
|
36
|
+
if (value.schema !== 1) throw new Error("Unsupported patch registry schema");
|
|
37
|
+
object(value.libraries, undefined, "libraries");
|
|
38
|
+
for (const [name, library] of Object.entries(value.libraries)) {
|
|
39
|
+
if (!/^(?:@[a-z0-9_.-]+\/)?[a-z0-9_.-]+$/.test(name) || ["__proto__", "constructor", "prototype"].includes(name)) throw new Error(`Invalid registry library: ${name}`);
|
|
40
|
+
object(library, ["kind", "versions"], name);
|
|
41
|
+
if (!["patch", "sdk", "redirect"].includes(library.kind) || !Array.isArray(library.versions) || !library.versions.length) throw new Error(`Malformed patch registry library: ${name}`);
|
|
42
|
+
const seen = new Set();
|
|
43
|
+
for (const entry of library.versions) {
|
|
44
|
+
object(entry, ["version", "minSpark", "patch", "sha256", "integrity", "requires", "optional", "sdkPatch", "sdkSha256"], name);
|
|
45
|
+
if (typeof entry.version !== "string" || typeof entry.minSpark !== "string" || !exact.test(entry.version) || !exact.test(entry.minSpark)) throw new Error(`Registry versions must be exact: ${name}`);
|
|
46
|
+
const key = `${entry.version}@${entry.minSpark}`;
|
|
47
|
+
if (seen.has(key)) throw new Error(`Duplicate registry patch: ${name}@${key}`);
|
|
48
|
+
seen.add(key);
|
|
49
|
+
if (library.kind === "redirect") {
|
|
50
|
+
if (entry.patch !== undefined || entry.sha256 !== undefined) throw new Error(`Redirect ${name} cannot declare a patch`);
|
|
51
|
+
} else if (typeof entry.patch !== "string" || !/^[A-Za-z0-9@+_.-]+(?:\/[A-Za-z0-9@+_.-]+)*\.patch$/.test(entry.patch) || entry.patch.split("/").some(part => part === "..") || typeof entry.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(entry.sha256)) throw new Error(`Invalid registry patch path/hash: ${name}`);
|
|
52
|
+
if (entry.sdkPatch !== undefined || entry.sdkSha256 !== undefined) {
|
|
53
|
+
if (typeof entry.sdkPatch !== "string" || !/^workspace\/[A-Za-z0-9@+_.-]+\.patch$/.test(entry.sdkPatch) || typeof entry.sdkSha256 !== "string" || !/^[a-f0-9]{64}$/.test(entry.sdkSha256)) throw new Error(`Invalid SDK patch metadata: ${name}`);
|
|
54
|
+
}
|
|
55
|
+
if (entry.optional !== undefined && typeof entry.optional !== "boolean") throw new Error(`Invalid optional metadata: ${name}`);
|
|
56
|
+
if (entry.integrity !== undefined && (typeof entry.integrity !== "string" || !entry.integrity.startsWith("sha512-"))) throw new Error(`Invalid integrity metadata: ${name}`);
|
|
57
|
+
if (entry.requires !== undefined && (!Array.isArray(entry.requires) || entry.requires.some(dep => typeof dep !== "string" || !dep.length) || new Set(entry.requires).size !== entry.requires.length)) throw new Error(`Invalid requires metadata: ${name}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function selectPatch(library, version, sparkVersion) {
|
|
63
|
+
return library.versions.filter(entry => entry.version === version && compareVersions(entry.minSpark, sparkVersion) <= 0)
|
|
64
|
+
.sort((a, b) => compareVersions(b.minSpark, a.minSpark))[0];
|
|
65
|
+
}
|
|
66
|
+
function resolveManifest(req, name) {
|
|
67
|
+
try { return req.resolve(`${name}/package.json`); }
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (!["ERR_PACKAGE_PATH_NOT_EXPORTED", "MODULE_NOT_FOUND"].includes(error.code)) throw error;
|
|
70
|
+
return (req.resolve.paths(name) ?? []).map(base => path.join(base, name, "package.json")).find(fs.existsSync);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function bundledSource(root) {
|
|
74
|
+
const req = createRequire(path.join(root, "package.json"));
|
|
75
|
+
const self = read(path.join(root, "package.json"));
|
|
76
|
+
const sparkFile = self.name === "@legendapp/spark" ? path.join(root, "package.json") : resolveManifest(req, "@legendapp/spark");
|
|
77
|
+
if (!sparkFile) return undefined;
|
|
78
|
+
const spark = read(sparkFile);
|
|
79
|
+
if (!spark.spark?.bundledModuleRoot && fs.realpathSync(sparkFile) !== fs.realpathSync(path.resolve(__dirname, "../desktop/package.json"))) return undefined;
|
|
80
|
+
const directory = spark.spark?.bundledModuleRoot ? path.join(path.dirname(sparkFile), "patches") : path.resolve(__dirname, "../../patches");
|
|
81
|
+
const file = path.join(directory, "registry.json");
|
|
82
|
+
if (!fs.existsSync(file)) return undefined;
|
|
83
|
+
return { registry: validateRegistry(read(file)), directory, sha: "bundled", sparkVersion: spark.version, sparkFile: fs.realpathSync(sparkFile) };
|
|
84
|
+
}
|
|
85
|
+
function sourceFor(root) {
|
|
86
|
+
const bundled = bundledSource(root);
|
|
87
|
+
if (!bundled) return undefined;
|
|
88
|
+
if (sources.has(bundled.sparkFile)) return sources.get(bundled.sparkFile);
|
|
89
|
+
if (process.env.SPARK_PATCH_REGISTRY_SOURCE) {
|
|
90
|
+
const selected = JSON.parse(process.env.SPARK_PATCH_REGISTRY_SOURCE);
|
|
91
|
+
object(selected, ["sparkFile", "sha", "directory"], "source");
|
|
92
|
+
if (!/^[a-f0-9]{40}$/.test(selected.sha) || typeof selected.directory !== "string" || !path.isAbsolute(selected.directory) || path.basename(selected.directory) !== selected.sha) throw new Error("Invalid inherited patch registry source");
|
|
93
|
+
if (selected.sparkFile === bundled.sparkFile) {
|
|
94
|
+
const source = verifyFiles({ ...bundled, registry: validateRegistry(read(path.join(selected.directory, "registry.json"))), directory: selected.directory, sha: selected.sha });
|
|
95
|
+
sources.set(bundled.sparkFile, source);
|
|
96
|
+
return source;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return bundled;
|
|
100
|
+
}
|
|
101
|
+
function readPatch(source, entry) {
|
|
102
|
+
const bytes = source.bytes?.get(entry.patch) ?? fs.readFileSync(path.join(source.directory, entry.patch));
|
|
103
|
+
if (hash(bytes) !== entry.sha256) throw new Error(`Patch registry hash mismatch: ${entry.patch}`);
|
|
104
|
+
return Buffer.from(bytes);
|
|
105
|
+
}
|
|
106
|
+
function verifyFiles(source) {
|
|
107
|
+
for (const library of Object.values(source.registry.libraries)) for (const entry of library.versions) {
|
|
108
|
+
for (const [file, expected] of [[entry.patch, entry.sha256], [entry.sdkPatch, entry.sdkSha256]]) {
|
|
109
|
+
if (file && hash(fs.readFileSync(path.join(source.directory, file))) !== expected) throw new Error(`Patch registry hash mismatch: ${file}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return source;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function fetchRegistry(root, { fetcher = globalThis.fetch, cache = path.join(process.env.SPARK_HOME || path.join(os.homedir(), ".spark"), "patch-registry"), notice = console.warn, writeCache = true } = {}) {
|
|
116
|
+
const bundled = bundledSource(root);
|
|
117
|
+
if (!bundled) return undefined;
|
|
118
|
+
if (process.env.SPARK_PATCH_REGISTRY_SOURCE) {
|
|
119
|
+
const inherited = sourceFor(root);
|
|
120
|
+
if (inherited.sha !== "bundled") return inherited;
|
|
121
|
+
}
|
|
122
|
+
// A command uses one immutable snapshot, including nested native discovery calls.
|
|
123
|
+
if (sources.has(bundled.sparkFile)) return sources.get(bundled.sparkFile);
|
|
124
|
+
async function get(url) {
|
|
125
|
+
const response = await fetcher(url, { redirect: "error", signal: AbortSignal.timeout(10000), headers: { Accept: "application/vnd.github+json" } });
|
|
126
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
127
|
+
return response.text();
|
|
128
|
+
}
|
|
129
|
+
let sha, registryText, files;
|
|
130
|
+
try {
|
|
131
|
+
const head = JSON.parse(await get("https://api.github.com/repos/LegendApp/legend-spark/commits/main"));
|
|
132
|
+
sha = head.sha;
|
|
133
|
+
if (!/^[a-f0-9]{40}$/.test(sha)) throw Object.assign(new Error("Invalid GitHub commit SHA"), { registryMetadata: true });
|
|
134
|
+
const directory = path.join(cache, sha);
|
|
135
|
+
if (fs.existsSync(path.join(directory, "registry.json"))) {
|
|
136
|
+
let source;
|
|
137
|
+
try { source = verifyFiles({ ...bundled, registry: validateRegistry(read(path.join(directory, "registry.json"))), directory, sha }); }
|
|
138
|
+
catch (error) { error.registryMetadata = true; throw error; }
|
|
139
|
+
sources.set(bundled.sparkFile, source);
|
|
140
|
+
return source;
|
|
141
|
+
}
|
|
142
|
+
registryText = await get(`https://raw.githubusercontent.com/LegendApp/legend-spark/${sha}/patches/registry.json`);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (error.registryMetadata) throw error;
|
|
145
|
+
notice(`Spark patch registry unavailable (${error.message}); using bundled patches.`);
|
|
146
|
+
const source = verifyFiles(bundled);
|
|
147
|
+
sources.set(bundled.sparkFile, source);
|
|
148
|
+
return source;
|
|
149
|
+
}
|
|
150
|
+
// A reachable but malformed registry is a publisher error, never an offline fallback.
|
|
151
|
+
let registry;
|
|
152
|
+
try { registry = validateRegistry(JSON.parse(registryText)); }
|
|
153
|
+
catch (error) { throw new Error(`Malformed GitHub patch registry: ${error.message}`); }
|
|
154
|
+
files = [...new Set(Object.values(registry.libraries).flatMap(lib => lib.versions.flatMap(entry => [entry.patch, entry.sdkPatch]).filter(Boolean)))];
|
|
155
|
+
const bytes = new Map();
|
|
156
|
+
try {
|
|
157
|
+
await Promise.all(files.map(async file => bytes.set(file, await get(`https://raw.githubusercontent.com/LegendApp/legend-spark/${sha}/patches/${file}`))));
|
|
158
|
+
} catch (error) {
|
|
159
|
+
notice(`Spark patch download failed (${error.message}); using bundled patches.`);
|
|
160
|
+
const source = verifyFiles(bundled);
|
|
161
|
+
sources.set(bundled.sparkFile, source);
|
|
162
|
+
return source;
|
|
163
|
+
}
|
|
164
|
+
for (const library of Object.values(registry.libraries)) for (const entry of library.versions) {
|
|
165
|
+
for (const [file, expected] of [[entry.patch, entry.sha256], [entry.sdkPatch, entry.sdkSha256]]) {
|
|
166
|
+
if (file && hash(bytes.get(file)) !== expected) throw new Error(`GitHub patch hash mismatch: ${file}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (!writeCache) {
|
|
170
|
+
const source = { ...bundled, registry, sha, bytes };
|
|
171
|
+
sources.set(bundled.sparkFile, source);
|
|
172
|
+
return source;
|
|
173
|
+
}
|
|
174
|
+
fs.mkdirSync(cache, { recursive: true });
|
|
175
|
+
const temporary = fs.mkdtempSync(path.join(cache, `${sha}-`));
|
|
176
|
+
try {
|
|
177
|
+
for (const [file, text] of bytes) { fs.mkdirSync(path.dirname(path.join(temporary, file)), { recursive: true }); fs.writeFileSync(path.join(temporary, file), text); }
|
|
178
|
+
fs.writeFileSync(path.join(temporary, "registry.json"), registryText);
|
|
179
|
+
try { fs.renameSync(temporary, path.join(cache, sha)); }
|
|
180
|
+
catch (error) { if (!fs.existsSync(path.join(cache, sha, "registry.json"))) throw error; }
|
|
181
|
+
} finally { fs.rmSync(temporary, { recursive: true, force: true }); }
|
|
182
|
+
const source = verifyFiles({ ...bundled, registry, sha, directory: path.join(cache, sha) });
|
|
183
|
+
sources.set(bundled.sparkFile, source);
|
|
184
|
+
return source;
|
|
185
|
+
}
|
|
186
|
+
function installedRegistryPackages(root, source) {
|
|
187
|
+
const found = [], visited = new Set(), queue = [{ file: path.join(root, "package.json"), app: true }];
|
|
188
|
+
while (queue.length) {
|
|
189
|
+
const { file, app } = queue.shift();
|
|
190
|
+
const real = fs.realpathSync(file);
|
|
191
|
+
if (visited.has(real)) continue;
|
|
192
|
+
visited.add(real);
|
|
193
|
+
const pkg = read(real), directory = path.dirname(real);
|
|
194
|
+
const req = createRequire(path.join(directory, pkg.spark?.bundledModuleRoot ?? ".", "package.json"));
|
|
195
|
+
const dependencies = { ...pkg.dependencies, ...pkg.optionalDependencies, ...(app ? pkg.devDependencies : {}), ...Object.fromEntries(Object.keys(pkg.peerDependencies ?? {}).filter(name => !pkg.peerDependenciesMeta?.[name]?.optional).map(name => [name, true])) };
|
|
196
|
+
if (!app && source.registry.libraries[pkg.name]) found.push({ name: pkg.name, version: pkg.version, file: real, root: directory });
|
|
197
|
+
for (const name of Object.keys(dependencies)) {
|
|
198
|
+
const dependency = resolveManifest(req, name);
|
|
199
|
+
if (dependency) queue.push({ file: dependency, app: false });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return found;
|
|
203
|
+
}
|
|
204
|
+
function sharedRoot(root, file) {
|
|
205
|
+
const normalized = fs.realpathSync(file).split(path.sep), index = normalized.lastIndexOf("node_modules");
|
|
206
|
+
// pnpm's virtual store is beneath the actual shared installation root.
|
|
207
|
+
const first = normalized.indexOf("node_modules");
|
|
208
|
+
const owner = index >= 0 ? normalized.slice(0, first).join(path.sep) || path.parse(file).root : root;
|
|
209
|
+
const realRoot = fs.realpathSync(root);
|
|
210
|
+
return fs.existsSync(path.join(owner, "package.json")) && (realRoot === owner || realRoot.startsWith(owner + path.sep))
|
|
211
|
+
? path.resolve(root, path.relative(realRoot, owner)) : root;
|
|
212
|
+
}
|
|
213
|
+
function installCommand(root, name, version) {
|
|
214
|
+
const pkg = read(path.join(root, "package.json"));
|
|
215
|
+
const manager = pkg.packageManager?.split("@")[0] ?? (["pnpm-lock.yaml", "yarn.lock", "bun.lock", "bun.lockb"].find(file => fs.existsSync(path.join(root, file)))?.split(/[.-]/)[0] || "npm");
|
|
216
|
+
if (!["npm", "pnpm", "yarn", "bun"].includes(manager)) throw new Error(`Unsupported package manager: ${manager}`);
|
|
217
|
+
return { manager, command: `${manager} ${manager === "npm" ? "install" : "add"}${manager === "npm" || manager === "yarn" ? " --exact" : " --save-exact"} ${name}@${version}` };
|
|
218
|
+
}
|
|
219
|
+
function patchDisabled(root, name, file) {
|
|
220
|
+
const app = read(path.join(root, "package.json"));
|
|
221
|
+
const owner = file ? sharedRoot(root, file) : root;
|
|
222
|
+
const settings = read(path.join(owner, "package.json")).spark;
|
|
223
|
+
validatePackageSettings(app.spark, root);
|
|
224
|
+
validatePackageSettings(settings, owner);
|
|
225
|
+
return app.spark?.patches?.[name] === false || settings?.patches?.[name] === false;
|
|
226
|
+
}
|
|
227
|
+
function registryFindings(root, source = sourceFor(root)) {
|
|
228
|
+
if (!source) return [];
|
|
229
|
+
const app = read(path.join(root, "package.json"));
|
|
230
|
+
validatePackageSettings(app.spark, root);
|
|
231
|
+
for (const name of Object.keys(app.spark?.patches ?? {})) if (!Object.hasOwn(source.registry.libraries, name)) throw new Error(`Unknown package.json spark.patches package: ${name}`);
|
|
232
|
+
const findings = [];
|
|
233
|
+
for (const pkg of installedRegistryPackages(root, source)) {
|
|
234
|
+
const owner = sharedRoot(root, pkg.file), settings = read(path.join(owner, "package.json")).spark;
|
|
235
|
+
validatePackageSettings(settings, owner);
|
|
236
|
+
for (const name of Object.keys(settings?.patches ?? {})) if (!Object.hasOwn(source.registry.libraries, name)) throw new Error(`Unknown package.json spark.patches package: ${name}`);
|
|
237
|
+
if (patchDisabled(root, pkg.name, pkg.file)) continue;
|
|
238
|
+
const library = source.registry.libraries[pkg.name];
|
|
239
|
+
const selected = selectPatch(library, pkg.version, source.sparkVersion);
|
|
240
|
+
const latest = library.versions.filter(entry => entry.version === pkg.version).sort((a, b) => compareVersions(b.minSpark, a.minSpark))[0];
|
|
241
|
+
const versions = [...new Set(library.versions.filter(entry => compareVersions(entry.minSpark, source.sparkVersion) <= 0).map(entry => entry.version))].sort((a, b) => compareVersions(b, a));
|
|
242
|
+
if (!selected || latest && compareVersions(latest.minSpark, source.sparkVersion) > 0) {
|
|
243
|
+
const target = versions[0];
|
|
244
|
+
const fix = !selected && target ? installCommand(owner, pkg.name, target).command : "spark upgrade";
|
|
245
|
+
findings.push({ ...pkg, owner, selected, latest, versions, fix, message: selected
|
|
246
|
+
? `${pkg.name}@${pkg.version} has a newer patch requiring Spark ${latest.minSpark} (installed ${source.sparkVersion}).`
|
|
247
|
+
: `${pkg.name}@${pkg.version} has no patch compatible with Spark ${source.sparkVersion}.` });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return findings;
|
|
251
|
+
}
|
|
252
|
+
function assertRegistryVersions(root) {
|
|
253
|
+
const issues = registryFindings(root).filter(issue => !issue.selected);
|
|
254
|
+
if (issues.length) throw new Error(issues.map(issue => `${issue.message}\nFix: cd ${JSON.stringify(issue.owner)} && ${issue.fix}`).join("\n"));
|
|
255
|
+
}
|
|
256
|
+
async function question(message) {
|
|
257
|
+
const input = require("node:readline/promises").createInterface({ input: process.stdin, output: process.stdout });
|
|
258
|
+
try { return await input.question(message); } finally { input.close(); }
|
|
259
|
+
}
|
|
260
|
+
async function ensurePatchRegistry(root, options = {}) {
|
|
261
|
+
object(options, ["fetcher", "cache", "notice", "writeCache", "tty", "ask", "install"], "options");
|
|
262
|
+
const source = await fetchRegistry(root, options);
|
|
263
|
+
if (!source) return;
|
|
264
|
+
if (source.sha !== "bundled") process.env.SPARK_PATCH_REGISTRY_SOURCE = JSON.stringify({ sparkFile: source.sparkFile, sha: source.sha, directory: source.directory });
|
|
265
|
+
else delete process.env.SPARK_PATCH_REGISTRY_SOURCE;
|
|
266
|
+
const tty = !process.env.SPARK_PATCH_REINSTALL && (options.tty ?? (!!process.stdin.isTTY && !process.env.CI));
|
|
267
|
+
const ask = options.ask ?? question;
|
|
268
|
+
const install = options.install ?? ((owner, manager) => {
|
|
269
|
+
const result = spawnSync(manager, ["install"], { cwd: owner, stdio: "inherit", shell: process.platform === "win32", env: { ...process.env, SPARK_PATCH_REINSTALL: "1" } });
|
|
270
|
+
if (result.error || result.status !== 0) throw new Error(`Patch version reinstall failed: ${result.error?.message ?? result.status}`);
|
|
271
|
+
});
|
|
272
|
+
const grouped = new Set(), reinstalls = new Map();
|
|
273
|
+
for (const issue of registryFindings(root, source)) {
|
|
274
|
+
const key = `${issue.owner}:${issue.name}`;
|
|
275
|
+
if (grouped.has(key)) continue;
|
|
276
|
+
grouped.add(key);
|
|
277
|
+
const upgradeKey = `${key}:${source.sha}:${issue.latest?.minSpark}`;
|
|
278
|
+
if (issue.latest && compareVersions(issue.latest.minSpark, source.sparkVersion) > 0 && !offeredUpgrades.has(upgradeKey)) {
|
|
279
|
+
offeredUpgrades.add(upgradeKey);
|
|
280
|
+
console.warn(`${issue.message}\nFix: spark upgrade`);
|
|
281
|
+
if (tty && /^y(?:es)?$/i.test((await ask("Run spark upgrade? [y/N] ")).trim())) {
|
|
282
|
+
const cli = createRequire(path.join(path.dirname(source.sparkFile), read(source.sparkFile).spark?.bundledModuleRoot ?? ".", "package.json")).resolve("@legendapp/spark-cli/dist/index.js");
|
|
283
|
+
const result = spawnSync(process.execPath, [cli, "upgrade", "--project", root], { stdio: "inherit" });
|
|
284
|
+
if (result.error || result.status !== 0) throw new Error("spark upgrade failed");
|
|
285
|
+
throw new Error("Spark upgraded. Retry the command with the updated CLI.");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (issue.selected) continue;
|
|
289
|
+
const fail = () => new Error(`${issue.message}\nFix: cd ${JSON.stringify(issue.owner)} && ${issue.fix}`);
|
|
290
|
+
if (!tty || process.env.SPARK_PATCH_REINSTALL || !issue.versions.length) throw fail();
|
|
291
|
+
console.log(`${issue.message}\nPatched versions: ${issue.versions.join(", ")}`);
|
|
292
|
+
const answer = (await ask(`Install patched ${issue.name} [${issue.versions[0]}] (version or n to decline)? `)).trim();
|
|
293
|
+
if (/^(n|no)$/i.test(answer)) throw fail();
|
|
294
|
+
const version = answer || issue.versions[0];
|
|
295
|
+
if (!issue.versions.includes(version)) throw new Error(`Choose a listed patched version for ${issue.name}: ${issue.versions.join(", ")}`);
|
|
296
|
+
const ownerFile = path.join(issue.owner, "package.json"), pkg = read(ownerFile);
|
|
297
|
+
let direct = false;
|
|
298
|
+
for (const field of ["dependencies", "devDependencies", "optionalDependencies"]) if (Object.hasOwn(pkg[field] ?? {}, issue.name)) { pkg[field][issue.name] = version; direct = true; }
|
|
299
|
+
if (!direct) (pkg.dependencies ??= {})[issue.name] = version;
|
|
300
|
+
const { manager } = installCommand(issue.owner, issue.name, version);
|
|
301
|
+
const overrides = manager === "yarn" ? (pkg.resolutions ??= {}) : manager === "pnpm" ? ((pkg.pnpm ??= {}).overrides ??= {}) : (pkg.overrides ??= {});
|
|
302
|
+
if (overrides[issue.name] && typeof overrides[issue.name] === "object") overrides[issue.name]["."] = version;
|
|
303
|
+
else overrides[issue.name] = version;
|
|
304
|
+
if (manager === "pnpm") {
|
|
305
|
+
const sdk = read(source.sparkFile);
|
|
306
|
+
const req = createRequire(path.join(path.dirname(source.sparkFile), sdk.spark?.bundledModuleRoot ?? ".", "package.json"));
|
|
307
|
+
const cli = path.dirname(req.resolve("@legendapp/spark-cli/package.json"));
|
|
308
|
+
const { pathToFileURL } = require("node:url");
|
|
309
|
+
const { writePackageConfig } = await import(pathToFileURL(path.join(cli, "dist/package-manager-config.js")).href);
|
|
310
|
+
writePackageConfig(issue.owner, pkg, manager);
|
|
311
|
+
} else fs.writeFileSync(ownerFile, JSON.stringify(pkg, null, 2) + "\n");
|
|
312
|
+
reinstalls.set(issue.owner, manager);
|
|
313
|
+
}
|
|
314
|
+
for (const [owner, manager] of reinstalls) await install(owner, manager);
|
|
315
|
+
assertRegistryVersions(root);
|
|
316
|
+
}
|
|
317
|
+
function patchSourceSHA(root) { return sourceFor(root)?.sha ?? "bundled"; }
|
|
318
|
+
module.exports = { validateRegistry, compareVersions, selectPatch, bundledSource, sourceFor, fetchRegistry, installedRegistryPackages, registryFindings, assertRegistryVersions, ensurePatchRegistry, patchSourceSHA, patchDisabled, readPatch, hash };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type RegistryVersion = { version: string; minSpark: string; patch?: string; sdkPatch?: string; sdkSha256?: string; sha256?: string; integrity?: string; requires?: string[]; optional?: boolean };
|
|
2
|
+
export type RegistryLibrary = { kind: "patch" | "sdk" | "redirect"; versions: RegistryVersion[] };
|
|
3
|
+
export type PatchRegistry = { schema: 1; libraries: Record<string, RegistryLibrary> };
|
|
4
|
+
export type RegistrySource = { registry: PatchRegistry; directory: string; sha: string; sparkVersion: string; sparkFile: string; bytes?: Map<string, string> };
|
|
5
|
+
export type RegistryFinding = { name: string; version: string; file: string; root: string; owner: string; selected?: RegistryVersion; latest?: RegistryVersion; versions: string[]; fix: string; message: string };
|
|
6
|
+
export type FetchOptions = { fetcher?: typeof fetch; cache?: string; notice?: (message: string) => void; writeCache?: boolean };
|
|
7
|
+
export function validateRegistry(value: unknown): PatchRegistry;
|
|
8
|
+
export function compareVersions(a: string, b: string): number;
|
|
9
|
+
export function selectPatch(library: RegistryLibrary, version: string, sparkVersion: string): RegistryVersion | undefined;
|
|
10
|
+
export function bundledSource(root: string): RegistrySource | undefined;
|
|
11
|
+
export function sourceFor(root: string): RegistrySource | undefined;
|
|
12
|
+
export function fetchRegistry(root: string, options?: FetchOptions): Promise<RegistrySource | undefined>;
|
|
13
|
+
export function installedRegistryPackages(root: string, source: RegistrySource): { name: string; version: string; file: string; root: string }[];
|
|
14
|
+
export function registryFindings(root: string, source?: RegistrySource): RegistryFinding[];
|
|
15
|
+
export function assertRegistryVersions(root: string): void;
|
|
16
|
+
export function ensurePatchRegistry(root: string, options?: FetchOptions & { tty?: boolean; ask?: (message: string) => Promise<string>; install?: (root: string, manager: string) => void | Promise<void> }): Promise<void>;
|
|
17
|
+
export function patchSourceSHA(root: string): string;
|
|
18
|
+
export function hash(bytes: string | Uint8Array): string;
|
|
19
|
+
export function patchDisabled(root: string, name: string, file?: string): boolean;
|
|
20
|
+
export function readPatch(source: RegistrySource, entry: RegistryVersion): Buffer;
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
+
class SparkError extends Error {
|
|
2
|
+
constructor(message, code = "E_INVALID_ARGUMENT") {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = "SparkError";
|
|
5
|
+
this.code = code;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
1
8
|
const platforms = ["macos", "windows", "ios", "android", "web"];
|
|
2
9
|
function object(value, name, keys) {
|
|
3
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw new
|
|
4
|
-
if (keys) for (const key of Object.keys(value)) if (!keys.includes(key)) throw new
|
|
10
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new SparkError(`${name} must be an object`);
|
|
11
|
+
if (keys) for (const key of Object.keys(value)) if (!keys.includes(key)) throw new SparkError(`Unknown ${name} field: ${key}`, "E_UNSUPPORTED_OPTION");
|
|
5
12
|
}
|
|
6
13
|
function validatePlatforms(value) {
|
|
7
|
-
if (!Array.isArray(value) || !value.length || new Set(value).size !== value.length || value.some(p => !platforms.includes(p))) throw new
|
|
14
|
+
if (!Array.isArray(value) || !value.length || new Set(value).size !== value.length || value.some(p => !platforms.includes(p))) throw new SparkError("platforms must list unique supported targets: macos, windows, ios, android, web");
|
|
8
15
|
return value;
|
|
9
16
|
}
|
|
10
17
|
function validateOwned(value) {
|
|
11
18
|
if (value.macos !== undefined) {
|
|
12
19
|
object(value.macos, "macos", ["bundleIdentifier", "buildNumber", "entitlements", "infoPlist", "testDriverInRelease", "lifecycle"]);
|
|
13
|
-
if (typeof value.macos.bundleIdentifier !== "string" || !/^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/.test(value.macos.bundleIdentifier)) throw new
|
|
14
|
-
if (value.macos.buildNumber !== undefined && typeof value.macos.buildNumber !== "string") throw new
|
|
15
|
-
if (value.macos.testDriverInRelease !== undefined && typeof value.macos.testDriverInRelease !== "boolean") throw new
|
|
20
|
+
if (typeof value.macos.bundleIdentifier !== "string" || !/^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/.test(value.macos.bundleIdentifier)) throw new SparkError("macos.bundleIdentifier must be a reverse-DNS identifier");
|
|
21
|
+
if (value.macos.buildNumber !== undefined && typeof value.macos.buildNumber !== "string") throw new SparkError("macos.buildNumber must be a string");
|
|
22
|
+
if (value.macos.testDriverInRelease !== undefined && typeof value.macos.testDriverInRelease !== "boolean") throw new SparkError("macos.testDriverInRelease must be a boolean");
|
|
16
23
|
for (const key of ["entitlements", "infoPlist"]) if (value.macos[key] !== undefined) object(value.macos[key], `macos.${key}`);
|
|
17
24
|
require("./lifecycle.cjs").validateLifecycle(value.macos.lifecycle);
|
|
18
25
|
}
|
|
19
26
|
if (value.documentTypes !== undefined) {
|
|
20
|
-
if (!Array.isArray(value.documentTypes)) throw new
|
|
27
|
+
if (!Array.isArray(value.documentTypes)) throw new SparkError("documentTypes must be an array");
|
|
21
28
|
for (const document of value.documentTypes) object(document, "documentType", ["name", "contentTypes", "role"]);
|
|
22
29
|
}
|
|
23
30
|
if (value.signing !== undefined) {
|
|
@@ -25,7 +32,7 @@ function validateOwned(value) {
|
|
|
25
32
|
const macos = value.signing.macos;
|
|
26
33
|
if (macos !== undefined) {
|
|
27
34
|
object(macos, "signing.macos", ["identity", "teamId", "entitlementsByPath"]);
|
|
28
|
-
for (const key of ["identity", "teamId"]) if (macos[key] !== undefined && (typeof macos[key] !== "string" || !macos[key].trim())) throw new
|
|
35
|
+
for (const key of ["identity", "teamId"]) if (macos[key] !== undefined && (typeof macos[key] !== "string" || !macos[key].trim())) throw new SparkError(`signing.macos.${key} must be a nonempty string`);
|
|
29
36
|
if (macos.entitlementsByPath !== undefined) {
|
|
30
37
|
object(macos.entitlementsByPath, "entitlementsByPath");
|
|
31
38
|
for (const [path, entitlements] of Object.entries(macos.entitlementsByPath)) object(entitlements, `entitlementsByPath.${path}`);
|
|
@@ -33,4 +40,54 @@ function validateOwned(value) {
|
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
|
-
|
|
43
|
+
function validateSettings(value, platform) {
|
|
44
|
+
if (value === undefined) return;
|
|
45
|
+
object(value, "extra.spark", ["projectId", "window", "documentTypes", "menuBarOnly", "updates", "include", "signing", "helpers", "customize", "supportedPlatforms"]);
|
|
46
|
+
validateOwned(value);
|
|
47
|
+
require("@legendapp/spark-window-options").validateWindow(value.window ?? {});
|
|
48
|
+
if (platform === "windows" && value.window?.titleBarStyle === "overlay") throw new SparkError("Windows does not support overlay title bars");
|
|
49
|
+
if (value.include !== undefined && (!Array.isArray(value.include) || value.include.some(name => typeof name !== "string"))) throw new SparkError("include must be a list of package names");
|
|
50
|
+
if (value.supportedPlatforms !== undefined) validatePlatforms(value.supportedPlatforms);
|
|
51
|
+
require("./helpers.cjs").validateHelpers(value.helpers);
|
|
52
|
+
require("./customize.cjs").validateCustomize(value.customize);
|
|
53
|
+
require("./updates.cjs").updateConfiguration({ extra: { spark: value } });
|
|
54
|
+
}
|
|
55
|
+
function validatePackageSettings(value, root) {
|
|
56
|
+
if (value === undefined) return;
|
|
57
|
+
object(value, "package.json spark", ["sdk", "nativeModules", "requires", "testOnly", "entitlements", "patches", "bundledModules", "bundledModuleRoot", "patchHash", "upstreamIntegrity", "upstreamRevision", "workspacePatch", "dependencyPatch", "nativePatchRequirements"]);
|
|
58
|
+
for (const key of ["sdk", "testOnly"]) if (value[key] !== undefined && typeof value[key] !== "boolean") throw new SparkError(`package.json spark.${key} must be boolean`);
|
|
59
|
+
for (const key of ["requires", "bundledModules"]) if (value[key] !== undefined && (!Array.isArray(value[key]) || new Set(value[key]).size !== value[key].length || value[key].some(name => typeof name !== "string" || !name.trim()))) throw new SparkError(`package.json spark.${key} must list nonempty strings`);
|
|
60
|
+
if (value.nativeModules !== undefined && value.nativeModules !== true) throw new SparkError("package.json spark.nativeModules must be true; native binding names come from codegen");
|
|
61
|
+
for (const key of ["bundledModuleRoot", "patchHash", "upstreamIntegrity", "upstreamRevision"]) if (value[key] !== undefined && (typeof value[key] !== "string" || !value[key].length)) throw new SparkError(`package.json spark.${key} must be a nonempty string`);
|
|
62
|
+
if (value.bundledModuleRoot !== undefined) {
|
|
63
|
+
const path = require("node:path"), fs = require("node:fs");
|
|
64
|
+
const directory = path.resolve(root, value.bundledModuleRoot);
|
|
65
|
+
if (path.isAbsolute(value.bundledModuleRoot) || value.bundledModuleRoot.includes("\\") || path.relative(root, directory).split(path.sep).includes("..") || !fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) throw new SparkError("package.json spark.bundledModuleRoot must name a directory inside its package");
|
|
66
|
+
}
|
|
67
|
+
for (const key of ["workspacePatch", "dependencyPatch"]) if (value[key] !== undefined) {
|
|
68
|
+
const receipt = value[key];
|
|
69
|
+
object(receipt, `package.json spark.${key}`, ["schema", "version", "patchHash", "appPatchHash", "appRoot", "upstreamIntegrity", "upstreamRevision"]);
|
|
70
|
+
if (receipt.schema !== undefined && receipt.schema !== 1) throw new SparkError(`package.json spark.${key}.schema must be 1`);
|
|
71
|
+
for (const field of ["version", "patchHash", "appPatchHash", "appRoot", "upstreamIntegrity", "upstreamRevision"]) if (receipt[field] !== undefined && (typeof receipt[field] !== "string" || !receipt[field].length)) throw new SparkError(`package.json spark.${key}.${field} must be a nonempty string`);
|
|
72
|
+
}
|
|
73
|
+
if (value.nativePatchRequirements !== undefined) {
|
|
74
|
+
const requirements = value.nativePatchRequirements;
|
|
75
|
+
object(requirements, "package.json spark.nativePatchRequirements", ["schema", "frameworkVersion", "packages"]);
|
|
76
|
+
if (requirements.schema !== 1 || typeof requirements.frameworkVersion !== "string" || !requirements.frameworkVersion.length) throw new SparkError("package.json spark.nativePatchRequirements needs schema 1 and frameworkVersion");
|
|
77
|
+
object(requirements.packages, "package.json spark.nativePatchRequirements.packages");
|
|
78
|
+
for (const [name, record] of Object.entries(requirements.packages)) {
|
|
79
|
+
object(record, `package.json spark.nativePatchRequirements.packages.${name}`, ["version", "patchHash", "upstreamIntegrity", "upstreamRevision"]);
|
|
80
|
+
for (const field of ["version", "patchHash"]) if (typeof record[field] !== "string" || !record[field].length) throw new SparkError(`package.json spark.nativePatchRequirements.packages.${name}.${field} must be a nonempty string`);
|
|
81
|
+
for (const field of ["upstreamIntegrity", "upstreamRevision"]) if (record[field] !== undefined && (typeof record[field] !== "string" || !record[field].length)) throw new SparkError(`package.json spark.nativePatchRequirements.packages.${name}.${field} must be a nonempty string`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (value.entitlements !== undefined) {
|
|
85
|
+
object(value.entitlements, "package.json spark.entitlements", ["macos"]);
|
|
86
|
+
if (value.entitlements.macos !== undefined) object(value.entitlements.macos, "package.json spark.entitlements.macos");
|
|
87
|
+
}
|
|
88
|
+
if (value.patches !== undefined) {
|
|
89
|
+
object(value.patches, "package.json spark.patches");
|
|
90
|
+
for (const [name, enabled] of Object.entries(value.patches)) if (typeof enabled !== "boolean") throw new SparkError(`package.json spark.patches.${name} must be boolean`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
module.exports = { SparkError, validateOwned, validatePlatforms, validateSettings, validatePackageSettings };
|
|
@@ -28,6 +28,7 @@ function patchHost(source, core, metadata, defaults = {}) {
|
|
|
28
28
|
return source.replace(include, `${include}\n// BEGIN SPARK CORE\n${core.replace('__SPARK_METADATA__', JSON.stringify(metadata)).replace('__SPARK_PROJECT_CONFIG__', JSON.stringify({ ...defaults, SPARK_RUNTIME_MODE: metadata.mode }).replaceAll(')', '\\u0029').replace(/[^\x00-\x7F]/g, char => '\\u' + char.charCodeAt(0).toString(16).padStart(4, '0')))}\n// END SPARK CORE\n`);
|
|
29
29
|
}
|
|
30
30
|
module.exports = config => {
|
|
31
|
+
require("./validation.cjs").validateSettings(config.extra?.spark, "windows");
|
|
31
32
|
const { withAppCpp } = require('expo-desktop-config-plugins');
|
|
32
33
|
config = withAppCpp(config, mod => {
|
|
33
34
|
const root = mod.modRequest.projectRoot;
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
self.sparkPrimaryInstance = SparkTestDriverStart() || SparkAcquireInstance();
|
|
28
28
|
// A second process forwards its launch to the owner and exits (SparkAcquireInstance).
|
|
29
29
|
if (!self.sparkPrimaryInstance) return;
|
|
30
|
+
SparkPrepareStorage();
|
|
30
31
|
facebook::react::ReactMarker::logMarkerDone(facebook::react::ReactMarker::APP_STARTUP_START, CACurrentMediaTime() * 1000);
|
|
31
32
|
[self sparkPrepareMainMenu];
|
|
32
33
|
SparkPrepareApplication();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/spark-desktop-host",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"AppDelegate.mm",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"SparkCustomize.mm"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@legendapp/spark-desktop-app": "0.0.
|
|
12
|
+
"@legendapp/spark-desktop-app": "0.0.4"
|
|
13
13
|
},
|
|
14
14
|
"private": true
|
|
15
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/spark-desktop-links",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"react-native": "src/index",
|
|
@@ -29,20 +29,13 @@
|
|
|
29
29
|
},
|
|
30
30
|
"spark": {
|
|
31
31
|
"sdk": true,
|
|
32
|
-
"nativeModules":
|
|
33
|
-
"NativeDesktopLinks"
|
|
34
|
-
],
|
|
35
|
-
"pod": "RNDesktopLinks",
|
|
36
|
-
"platforms": [
|
|
37
|
-
"macos",
|
|
38
|
-
"windows"
|
|
39
|
-
],
|
|
32
|
+
"nativeModules": true,
|
|
40
33
|
"requires": [
|
|
41
34
|
"@legendapp/spark-desktop-app"
|
|
42
35
|
]
|
|
43
36
|
},
|
|
44
37
|
"dependencies": {
|
|
45
|
-
"@legendapp/spark-desktop-app": "0.0.
|
|
38
|
+
"@legendapp/spark-desktop-app": "0.0.4"
|
|
46
39
|
},
|
|
47
40
|
"peerDependenciesMeta": {
|
|
48
41
|
"expo-linking": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/spark-desktop-shortcuts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"react-native": "src/index",
|
|
@@ -27,20 +27,13 @@
|
|
|
27
27
|
},
|
|
28
28
|
"spark": {
|
|
29
29
|
"sdk": true,
|
|
30
|
-
"nativeModules":
|
|
31
|
-
"NativeDesktopShortcuts",
|
|
32
|
-
"NativeKeyboardManager"
|
|
33
|
-
],
|
|
34
|
-
"pod": "RNDesktopShortcuts",
|
|
35
|
-
"platforms": [
|
|
36
|
-
"macos"
|
|
37
|
-
],
|
|
30
|
+
"nativeModules": true,
|
|
38
31
|
"requires": [
|
|
39
32
|
"@legendapp/spark-desktop-app"
|
|
40
33
|
]
|
|
41
34
|
},
|
|
42
35
|
"dependencies": {
|
|
43
|
-
"@legendapp/spark-desktop-app": "0.0.
|
|
36
|
+
"@legendapp/spark-desktop-app": "0.0.4"
|
|
44
37
|
},
|
|
45
38
|
"private": true
|
|
46
39
|
}
|
|
@@ -191,11 +191,15 @@ static BOOL ApplyCommon(NSWindow *window, NSDictionary *options, RCTPromiseRejec
|
|
|
191
191
|
window.backgroundColor = [NSColor colorWithSRGBRed:((rgba >> 24) & 255) / 255.0 green:((rgba >> 16) & 255) / 255.0 blue:((rgba >> 8) & 255) / 255.0 alpha:(rgba & 255) / 255.0];
|
|
192
192
|
window.opaque = (rgba & 255) == 255;
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
// Size limits are set only when given: reading minSize back from a window with a toolbar returns a larger value
|
|
195
|
+
// than was set, so writing it back on every update grew the window each time.
|
|
196
|
+
if (!options[@"minSize"] && !options[@"maxSize"]) return YES;
|
|
197
|
+
if (options[@"minSize"]) window.minSize = minimum;
|
|
198
|
+
if (options[@"maxSize"]) window.maxSize = maximum;
|
|
195
199
|
NSRect frame = window.frame;
|
|
196
200
|
frame.size.width = MIN(MAX(frame.size.width, minimum.width), maximum.width);
|
|
197
201
|
frame.size.height = MIN(MAX(frame.size.height, minimum.height), maximum.height);
|
|
198
|
-
[window setFrame:frame display:YES];
|
|
202
|
+
if (!NSEqualRects(frame, window.frame)) [window setFrame:frame display:YES];
|
|
199
203
|
return YES;
|
|
200
204
|
}
|
|
201
205
|
static BOOL SetBounds(NSWindow *window, NSDictionary *bounds, double durationMs, RCTPromiseResolveBlock resolve, RCTPromiseRejectBlock reject) {
|
|
@@ -292,6 +296,7 @@ RCT_EXPORT_MODULE(NativeDesktopWindowManager)
|
|
|
292
296
|
else [delegate finishClose:NO];
|
|
293
297
|
}
|
|
294
298
|
} else if ([method isEqual:@"show"]) {
|
|
299
|
+
if ([args[@"activate"] boolValue]) [NSApp activateIgnoringOtherApps:YES];
|
|
295
300
|
[window deminiaturize:nil]; NSDictionary *opening = objc_getAssociatedObject(window, @selector(call:args:resolve:reject:));
|
|
296
301
|
if ([opening[@"modal"] boolValue] && !window.sheetParent) {
|
|
297
302
|
NSWindow *parent = Window(opening[@"parentId"]);
|