@nissyai/desktop 0.2.7 → 0.2.10

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/bin/nissy.mjs CHANGED
@@ -30,11 +30,12 @@ import {
30
30
  resolvePayloadSpec,
31
31
  UnsupportedPlatformError,
32
32
  } from "../src/resolve.mjs";
33
+ import { DISTRIBUTION } from "../src/distribution.mjs";
33
34
 
34
35
  const require = createRequire(import.meta.url);
35
36
 
36
37
  function fail(message) {
37
- console.error(`[nissy] ${message}`);
38
+ console.error(`[${DISTRIBUTION.npmCommand}] ${message}`);
38
39
  process.exit(1);
39
40
  }
40
41
 
@@ -136,7 +137,7 @@ if (existsSync(join(payloadRoot, "app"))) {
136
137
  // launcher versions used (~140 MB each). Never block launch.
137
138
  try {
138
139
  for (const entry of readdirSync(cacheRoot)) {
139
- if (entry.startsWith("nissy-app-darwin-")) {
140
+ if (entry.startsWith(`${DISTRIBUTION.cacheName}-app-darwin-`)) {
140
141
  rmSync(join(cacheRoot, entry), { recursive: true, force: true });
141
142
  }
142
143
  }
@@ -180,7 +181,7 @@ const { command, args, viaLaunchServices } = resolveLaunchCommand({
180
181
  // anyway), so the stamp is a harmless no-op there.
181
182
  const childEnv = {
182
183
  ...process.env,
183
- ...npxChannelEnv(process.execPath, fileURLToPath(import.meta.url)),
184
+ ...npxChannelEnv(process.execPath, fileURLToPath(import.meta.url), DISTRIBUTION),
184
185
  };
185
186
 
186
187
  // Record the toolchain to a FILE as well as the env, because macOS `open`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nissyai/desktop",
3
- "version": "0.2.7",
3
+ "version": "0.2.10",
4
4
  "type": "module",
5
5
  "description": "Launcher for the Nissy desktop app. Resolves the host's app payload and spawns it. Run via `npx @nissyai/desktop`; a global install (`npm i -g @nissyai/desktop`) exposes the `nissy` command.",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -20,8 +20,8 @@
20
20
  "src/"
21
21
  ],
22
22
  "optionalDependencies": {
23
- "@nissyai/app-win32-x64": "0.2.7",
24
- "@nissyai/app-darwin-arm64": "0.2.7",
25
- "@nissyai/app-darwin-x64": "0.2.7"
23
+ "@nissyai/app-win32-x64": "0.2.10",
24
+ "@nissyai/app-darwin-arm64": "0.2.10",
25
+ "@nissyai/app-darwin-x64": "0.2.10"
26
26
  }
27
27
  }
@@ -0,0 +1,17 @@
1
+ export const DISTRIBUTION = Object.freeze({
2
+ "flavor": "production",
3
+ "appName": "Nissy",
4
+ "executableName": "nissy",
5
+ "bundleId": "software.cleverbit.nissy",
6
+ "appUserModelId": "Nissy",
7
+ "protocol": "nissy",
8
+ "loginItemName": "Nissy",
9
+ "userDataName": "Nissy",
10
+ "cacheName": "nissy",
11
+ "npmScope": "@nissyai",
12
+ "npmLauncherPackage": "@nissyai/desktop",
13
+ "npmCommand": "nissy",
14
+ "npmRegistry": null,
15
+ "environment": "production",
16
+ "ownsGlobalHooks": true
17
+ });
package/src/resolve.mjs CHANGED
@@ -7,6 +7,8 @@
7
7
  // Electron), so each payload exposes a single executable we spawn
8
8
  // directly — there is no dependency on the `electron` npm package.
9
9
 
10
+ import { DISTRIBUTION } from "./distribution.mjs";
11
+
10
12
  /** Error thrown when the host platform/arch has no payload mapping. */
11
13
  export class UnsupportedPlatformError extends Error {
12
14
  /** @param {string} key host key, e.g. "linux-x64" */
@@ -24,20 +26,27 @@ export class UnsupportedPlatformError extends Error {
24
26
  *
25
27
  * @type {Record<string, { pkg: string, exe: readonly string[] }>}
26
28
  */
27
- export const PAYLOADS = {
28
- "win32-x64": {
29
- pkg: "@nissyai/app-win32-x64",
30
- exe: ["app", "nissy.exe"],
31
- },
32
- "darwin-arm64": {
33
- pkg: "@nissyai/app-darwin-arm64",
34
- exe: ["app", "Nissy.app", "Contents", "MacOS", "nissy"],
35
- },
36
- "darwin-x64": {
37
- pkg: "@nissyai/app-darwin-x64",
38
- exe: ["app", "Nissy.app", "Contents", "MacOS", "nissy"],
39
- },
40
- };
29
+ export function payloadsForDistribution(distribution = DISTRIBUTION) {
30
+ const scope = distribution.npmScope;
31
+ const appName = distribution.appName;
32
+ const executableName = distribution.executableName;
33
+ return {
34
+ "win32-x64": {
35
+ pkg: `${scope}/app-win32-x64`,
36
+ exe: ["app", `${executableName}.exe`],
37
+ },
38
+ "darwin-arm64": {
39
+ pkg: `${scope}/app-darwin-arm64`,
40
+ exe: ["app", `${appName}.app`, "Contents", "MacOS", executableName],
41
+ },
42
+ "darwin-x64": {
43
+ pkg: `${scope}/app-darwin-x64`,
44
+ exe: ["app", `${appName}.app`, "Contents", "MacOS", executableName],
45
+ },
46
+ };
47
+ }
48
+
49
+ export const PAYLOADS = payloadsForDistribution();
41
50
 
42
51
  /**
43
52
  * Resolve the payload spec for a host platform/arch.
@@ -46,9 +55,9 @@ export const PAYLOADS = {
46
55
  * @returns {{ key: string, pkg: string, exe: readonly string[] }}
47
56
  * @throws {UnsupportedPlatformError} when no mapping exists
48
57
  */
49
- export function resolvePayloadSpec(platform, arch) {
58
+ export function resolvePayloadSpec(platform, arch, payloads = PAYLOADS) {
50
59
  const key = `${platform}-${arch}`;
51
- const spec = PAYLOADS[key];
60
+ const spec = payloads[key];
52
61
  if (spec === undefined) {
53
62
  throw new UnsupportedPlatformError(key);
54
63
  }
@@ -64,12 +73,19 @@ export function resolvePayloadSpec(platform, arch) {
64
73
  * @param {{ platform: NodeJS.Platform | string, home: string, env: Record<string, string | undefined> }} host
65
74
  * @returns {string[]} path segments of the cache root
66
75
  */
67
- export function cacheRootSegments({ platform, home, env }) {
68
- if (platform === "darwin") return [home, "Library", "Caches", "nissy"];
76
+ export function cacheRootSegments({
77
+ platform,
78
+ home,
79
+ env,
80
+ cacheName = DISTRIBUTION.cacheName,
81
+ }) {
82
+ if (platform === "darwin") return [home, "Library", "Caches", cacheName];
69
83
  if (platform === "win32") {
70
- return [env.LOCALAPPDATA || env.TEMP || home, "nissy", "Cache"];
84
+ return [env.LOCALAPPDATA || env.TEMP || home, cacheName, "Cache"];
71
85
  }
72
- return env.XDG_CACHE_HOME ? [env.XDG_CACHE_HOME, "nissy"] : [home, ".cache", "nissy"];
86
+ return env.XDG_CACHE_HOME
87
+ ? [env.XDG_CACHE_HOME, cacheName]
88
+ : [home, ".cache", cacheName];
73
89
  }
74
90
 
75
91
  /**
@@ -130,9 +146,15 @@ export function stalePayloadCaches(entries, currentKey) {
130
146
  * @param {string} launcherScript absolute path to this launcher script
131
147
  * @returns {{ NISSY_CHANNEL: string, NISSY_LAUNCHER_NODE: string, NISSY_LAUNCHER_SCRIPT: string }}
132
148
  */
133
- export function npxChannelEnv(nodePath, launcherScript) {
149
+ export function npxChannelEnv(
150
+ nodePath,
151
+ launcherScript,
152
+ distribution = DISTRIBUTION,
153
+ ) {
134
154
  return {
135
155
  NISSY_CHANNEL: "npx",
156
+ NISSY_DISTRIBUTION_FLAVOR: distribution.flavor,
157
+ NISSY_ENVIRONMENT: distribution.environment,
136
158
  NISSY_LAUNCHER_NODE: nodePath,
137
159
  NISSY_LAUNCHER_SCRIPT: launcherScript,
138
160
  };
@@ -167,14 +189,24 @@ export function npxChannelEnv(nodePath, launcherScript) {
167
189
  * }} input bundlePath is the installed `.app` (macOS only; null elsewhere).
168
190
  * @returns {{ command: string, args: string[], viaLaunchServices: boolean }}
169
191
  */
170
- export function resolveLaunchCommand({ platform, bundlePath, exePath, foreground, forwardedArgs }) {
192
+ export function resolveLaunchCommand({
193
+ platform,
194
+ bundlePath,
195
+ exePath,
196
+ foreground,
197
+ forwardedArgs,
198
+ }) {
171
199
  if (platform === "darwin" && !foreground && bundlePath !== null) {
172
200
  const args = [bundlePath];
173
201
  // `open` forwards extra argv to the app only after a `--args` separator.
174
202
  if (forwardedArgs.length > 0) args.push("--args", ...forwardedArgs);
175
203
  return { command: "/usr/bin/open", args, viaLaunchServices: true };
176
204
  }
177
- return { command: exePath, args: [...forwardedArgs], viaLaunchServices: false };
205
+ return {
206
+ command: exePath,
207
+ args: [...forwardedArgs],
208
+ viaLaunchServices: false,
209
+ };
178
210
  }
179
211
 
180
212
  /**
@@ -186,6 +218,10 @@ export function resolveLaunchCommand({ platform, bundlePath, exePath, foreground
186
218
  * @param {{ markerVersion: string | null, payloadVersion: string, exeExists: boolean }} input
187
219
  * @returns {boolean}
188
220
  */
189
- export function needsMacReinstall({ markerVersion, payloadVersion, exeExists }) {
221
+ export function needsMacReinstall({
222
+ markerVersion,
223
+ payloadVersion,
224
+ exeExists,
225
+ }) {
190
226
  return !exeExists || markerVersion !== payloadVersion;
191
227
  }