@gjsify/cli 0.64.45 → 0.64.47

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.
@@ -186,6 +186,7 @@ export const flatpakInitCommand = {
186
186
  command,
187
187
  kind,
188
188
  flatpak,
189
+ desktopExecArgs: configData.ship?.desktopExecArgs,
189
190
  };
190
191
  const missing = validateScaffoldInputs(scaffold);
191
192
  if (missing.length > 0) {
@@ -7,6 +7,8 @@ export interface ScaffoldInputs {
7
7
  command: string;
8
8
  kind: 'app' | 'cli';
9
9
  flatpak: ConfigDataFlatpak;
10
+ /** `gjsify.ship.desktopExecArgs`, when the project declares it. */
11
+ desktopExecArgs?: readonly string[];
10
12
  }
11
13
  /**
12
14
  * Validate that the config has the minimum set of fields required for
@@ -26,6 +26,7 @@ function toMetadataInputs(inputs) {
26
26
  command: inputs.command,
27
27
  kind: inputs.kind,
28
28
  metadata: inputs.flatpak,
29
+ desktopExecArgs: inputs.desktopExecArgs,
29
30
  channel: 'flathub',
30
31
  configKey: 'gjsify.flatpak',
31
32
  };
@@ -396,6 +396,7 @@ async function assemble(args) {
396
396
  command: settings.binaryName,
397
397
  kind: settings.kind,
398
398
  metadata,
399
+ desktopExecArgs: settings.desktopExecArgs,
399
400
  channel,
400
401
  configKey: 'gjsify.ship',
401
402
  copyrightYear: new Date(mtime * 1000).getUTCFullYear(),
@@ -8,7 +8,7 @@ import { dirname, join, resolve, sep } from 'node:path';
8
8
  import { dispatchSite } from '../../utils/site-dispatch.js';
9
9
  import { runSubmit } from '../../utils/webext/submit.js';
10
10
  import { buildWebext } from '../../utils/webext/build.js';
11
- import { resolveWebextConfig, selectTargets } from '../../utils/webext/config.js';
11
+ import { resolveSubmitProject, resolveWebextConfig, selectTargets, } from '../../utils/webext/config.js';
12
12
  import { defaultDevProfile, resolveWebExt, WEB_EXT_MISSING, webExtRunArgs, } from '../../utils/webext/launch.js';
13
13
  function loadConfig(cwd) {
14
14
  const manifest = join(cwd, 'package.json');
@@ -16,6 +16,12 @@ function loadConfig(cwd) {
16
16
  throw new Error(`gjsify webext: no package.json in ${cwd}.`);
17
17
  return resolveWebextConfig(JSON.parse(readFileSync(manifest, 'utf8')), cwd);
18
18
  }
19
+ function loadSubmitProject(cwd) {
20
+ const manifest = join(cwd, 'package.json');
21
+ if (!existsSync(manifest))
22
+ throw new Error(`gjsify webext: no package.json in ${cwd}.`);
23
+ return resolveSubmitProject(JSON.parse(readFileSync(manifest, 'utf8')), cwd);
24
+ }
19
25
  /** `--define K=V` entries on top of the config's map, the way `gjsify build` spells them. */
20
26
  function effectiveDefines(config, flags) {
21
27
  const out = { ...config.define };
@@ -316,7 +322,7 @@ export const webextSubmitCommand = {
316
322
  submit: args.submit,
317
323
  timeoutSeconds: args.timeout,
318
324
  listingDir: args.listingDir,
319
- project: loadConfig(cwd),
325
+ project: loadSubmitProject(cwd),
320
326
  env: process.env,
321
327
  out: (line) => console.log(line),
322
328
  err: (line) => console.error(line),
@@ -741,6 +741,14 @@ export interface ConfigDataShip extends AppMetadata {
741
741
  extraFiles?: Record<string, string>;
742
742
  /** Arguments the launcher appends before the user's own. */
743
743
  execArgs?: string[];
744
+ /**
745
+ * Arguments for the desktop entry's `Exec=` line, after the command and before the `%u`/`%f`
746
+ * field code. Separate from `execArgs` on purpose: `execArgs` is baked into the launcher
747
+ * script, so it applies to every invocation including the CLI; this one only changes what a
748
+ * menu click runs. An app whose binary is both CLI and GUI (`curlew` alone errors, `curlew
749
+ * window` opens the window) needs `["window"]` here and nothing in `execArgs`.
750
+ */
751
+ desktopExecArgs?: string[];
744
752
  /**
745
753
  * Further executables of the SAME package, beside the primary one `gjsify.main` names.
746
754
  *
@@ -10,6 +10,12 @@ export interface AppMetadataInputs {
10
10
  /** `'app'` renders a desktop-application component, `'cli'` a console one. */
11
11
  kind: 'app' | 'cli';
12
12
  metadata: AppMetadata;
13
+ /**
14
+ * Arguments placed in the desktop entry's `Exec=` after {@link command} and
15
+ * before the `%u`/`%f` field code (`gjsify.ship.desktopExecArgs`). Only the
16
+ * launcher entry sees them; the binary itself is unchanged.
17
+ */
18
+ desktopExecArgs?: readonly string[];
13
19
  /** Distribution channel (ADR 0113, 0139). `<url type="donation">` is emitted only where `support` is `external-link`. */
14
20
  channel?: string;
15
21
  /**
@@ -115,13 +115,32 @@ export function renderDesktopEntry(inputs) {
115
115
  return substitute(loadDesktopTemplate(), {
116
116
  NAME: inputs.name,
117
117
  SUMMARY: m.summary ?? inputs.name,
118
- COMMAND: `${inputs.command}${execFieldCode(mimetypes)}`,
118
+ COMMAND: [inputs.command, ...(inputs.desktopExecArgs ?? []).map((arg) => quoteExecArg(arg, inputs.configKey))].join(' ') + execFieldCode(mimetypes),
119
119
  APP_ID: inputs.appId,
120
120
  CATEGORIES_LINE: categoriesLine,
121
121
  KEYWORDS_LINE: keywordsLine,
122
122
  MIMETYPES_LINE: mimetypesLine,
123
123
  });
124
124
  }
125
+ const EXEC_RESERVED = /[\s"'\\><~|&;$*?#()`]/;
126
+ /**
127
+ * One `Exec=` argument per the Desktop Entry spec: `%` doubles (else it is a
128
+ * field code), an argument with a reserved character goes in double quotes with
129
+ * `"`, backtick, `$` and `\` backslash-escaped, and every backslash doubles
130
+ * again for the key-value string layer. A newline cannot be expressed at all.
131
+ */
132
+ function quoteExecArg(arg, configKey) {
133
+ if (/[\r\n]/.test(arg)) {
134
+ throw new Error(`${configKey}.desktopExecArgs contains ${JSON.stringify(arg)}: a newline cannot appear in a desktop entry's Exec= line.`);
135
+ }
136
+ const text = arg.replace(/%/g, '%%');
137
+ if (text === '')
138
+ return '""';
139
+ if (!EXEC_RESERVED.test(text))
140
+ return text;
141
+ const quoted = text.replace(/(["`$\\])/g, '\\$1').replace(/\\/g, '\\\\');
142
+ return `"${quoted}"`;
143
+ }
125
144
  /** The `Exec=` field code implied by the declared MIME types. */
126
145
  function execFieldCode(mimetypes) {
127
146
  if (mimetypes.some((t) => t.startsWith('x-scheme-handler/')))
@@ -44,9 +44,16 @@ export declare function pickFlatpakBuildKeys(preferred: ShipFlatpakOptions | und
44
44
  /** The branch a `ship` Flatpak is exported under when the project names none. */
45
45
  export declare const DEFAULT_SHIP_FLATPAK_BRANCH = "stable";
46
46
  /**
47
- * The scalable icon directory a `kind: 'app'` Flatpak drops before
47
+ * The cleanup entry that drops the app's OWN scalable icon
48
+ * (`scalable/apps/<appId>.svg`) from a `kind: 'app'` Flatpak before
48
49
  * `appstreamcli compose` reads the tree.
49
50
  *
51
+ * ONLY THAT FILE, never the `scalable` directory. The compose failure concerns
52
+ * the app icon alone; removing the whole directory also deleted every extra icon
53
+ * an app ships via `gjsify.ship.extraFiles` (Curlew's
54
+ * `scalable/apps/curlew-protocol-*.svg` badges vanished from the v0.2.0-rc.1
55
+ * Flatpak and the UI showed missing icons).
56
+ *
50
57
  * THE OTHER HALF OF `LAYOUTS.linux.icon`, and the half that cannot live in the
51
58
  * layout: the stage is one payload for four Linux formats (ADR 0024 § 2) and the
52
59
  * `.deb`, the `.rpm` and the AppImage all WANT the SVG — it is the icon GTK
@@ -75,10 +82,12 @@ export declare const DEFAULT_SHIP_FLATPAK_BRANCH = "stable";
75
82
  * icon without gdk-pixbuf at all. Reported as an `Upstream (AppStream, file by
76
83
  * hand)` issue rather than filed there (root AGENTS.md).
77
84
  */
78
- export declare const SCALABLE_ICONS_CLEANUP = "/share/icons/hicolor/scalable";
85
+ export declare function scalableAppIconCleanup(appId: string): string;
79
86
  export interface ShipFlatpakInput {
80
87
  ship: ConfigDataShip;
81
88
  flatpak: ConfigDataFlatpak;
89
+ /** The application id; names the one scalable icon the cleanup removes. */
90
+ appId: string;
82
91
  /** Decides the finish-args default: a GUI app needs a display, a CLI does not. */
83
92
  kind: 'app' | 'cli';
84
93
  }
@@ -89,9 +89,16 @@ export function pickFlatpakBuildKeys(preferred, legacy) {
89
89
  /** The branch a `ship` Flatpak is exported under when the project names none. */
90
90
  export const DEFAULT_SHIP_FLATPAK_BRANCH = 'stable';
91
91
  /**
92
- * The scalable icon directory a `kind: 'app'` Flatpak drops before
92
+ * The cleanup entry that drops the app's OWN scalable icon
93
+ * (`scalable/apps/<appId>.svg`) from a `kind: 'app'` Flatpak before
93
94
  * `appstreamcli compose` reads the tree.
94
95
  *
96
+ * ONLY THAT FILE, never the `scalable` directory. The compose failure concerns
97
+ * the app icon alone; removing the whole directory also deleted every extra icon
98
+ * an app ships via `gjsify.ship.extraFiles` (Curlew's
99
+ * `scalable/apps/curlew-protocol-*.svg` badges vanished from the v0.2.0-rc.1
100
+ * Flatpak and the UI showed missing icons).
101
+ *
95
102
  * THE OTHER HALF OF `LAYOUTS.linux.icon`, and the half that cannot live in the
96
103
  * layout: the stage is one payload for four Linux formats (ADR 0024 § 2) and the
97
104
  * `.deb`, the `.rpm` and the AppImage all WANT the SVG — it is the icon GTK
@@ -120,7 +127,9 @@ export const DEFAULT_SHIP_FLATPAK_BRANCH = 'stable';
120
127
  * icon without gdk-pixbuf at all. Reported as an `Upstream (AppStream, file by
121
128
  * hand)` issue rather than filed there (root AGENTS.md).
122
129
  */
123
- export const SCALABLE_ICONS_CLEANUP = '/share/icons/hicolor/scalable';
130
+ export function scalableAppIconCleanup(appId) {
131
+ return `/share/icons/hicolor/scalable/apps/${appId}.svg`;
132
+ }
124
133
  /**
125
134
  * Resolve the Flatpak half of `gjsify.ship`, reading the legacy block where the
126
135
  * new one is silent, and applying `ship`'s own defaults.
@@ -152,10 +161,12 @@ export function resolveShipFlatpakSettings(input) {
152
161
  // APPENDED to what the project declared, not defaulted to — the one entry
153
162
  // here that is not the author's choice. A project with its own `cleanup`
154
163
  // list would otherwise lose the entry that keeps its own Flatpak buildable
155
- // (see {@link SCALABLE_ICONS_CLEANUP}), and `??` cannot express "ours as
156
- // well as theirs". Deduplicated so a project that already wrote the glob —
157
- // the workaround this replaces — gets one, and in ITS position.
158
- cleanup: [...new Set([...(cleanup ?? []), ...(input.kind === 'app' ? [SCALABLE_ICONS_CLEANUP] : [])])],
164
+ // (see {@link scalableAppIconCleanup}), and `??` cannot express "ours as
165
+ // well as theirs". Deduplicated so a project that already wrote the old
166
+ // glob gets one, and in ITS position.
167
+ cleanup: [
168
+ ...new Set([...(cleanup ?? []), ...(input.kind === 'app' ? [scalableAppIconCleanup(input.appId)] : [])]),
169
+ ],
159
170
  };
160
171
  return { settings, warnings: fromLegacy.length === 0 ? [] : [deprecationWarning(fromLegacy)] };
161
172
  }
@@ -191,7 +191,7 @@ export function resolveShipSettings(input) {
191
191
  // Resolved here rather than in the packer, because the packer may run on a
192
192
  // host with no `package.json` at all (ADR 0024 § A2) — and because the
193
193
  // finish-args default depends on `kind`, which is a project fact.
194
- const flatpakSettings = resolveShipFlatpakSettings({ ship, flatpak, kind });
194
+ const flatpakSettings = resolveShipFlatpakSettings({ ship, flatpak, kind, appId });
195
195
  warnings.push(...flatpakSettings.warnings);
196
196
  // `gjsify.ship.nestedBundles`/`helperExecutables` describe what the DARWIN
197
197
  // `.app` carries — on any other layout they are IGNORED, with one combined
@@ -255,6 +255,7 @@ export function resolveShipSettings(input) {
255
255
  fontFiles: discovered.fontFiles,
256
256
  extraFiles: ship.extraFiles ?? {},
257
257
  execArgs: ship.execArgs ?? [],
258
+ desktopExecArgs: ship.desktopExecArgs ?? [],
258
259
  executables: resolveShipExecutables({
259
260
  declared: ship.executables,
260
261
  binaryName,
@@ -349,7 +349,7 @@ export interface ShipMimeType {
349
349
  * by the payload's own paths. There is no scriptlet to key off it either:
350
350
  * fontconfig scans the directory and caches lazily per user, measured rather
351
351
  * than assumed.
352
- * - `kind`, `execArgs` — read by the planner and the metadata renderers, all of
352
+ * - `kind`, `execArgs`, `desktopExecArgs` — read by the planner and the metadata renderers, all of
353
353
  * which have run by the time a stage exists. `appId` was on this line and
354
354
  * MOVED: the Flatpak packer needs it at pack time twice over — it is the
355
355
  * manifest's `id` and the ref `flatpak build-bundle` exports — and neither is
@@ -631,6 +631,14 @@ export interface ShipSettings extends PackSettings {
631
631
  extraFiles: Record<string, string>;
632
632
  /** Arguments appended to the launcher's `exec` line. */
633
633
  execArgs: string[];
634
+ /**
635
+ * Arguments for the desktop entry's `Exec=` line only (`gjsify.ship.desktopExecArgs`).
636
+ *
637
+ * Not `execArgs`: that one is baked into the launcher script and so reaches the CLI too,
638
+ * which breaks a binary that is both CLI and GUI (`curlew` errors on purpose,
639
+ * `curlew window` opens the window). This one leaves the launcher untouched.
640
+ */
641
+ desktopExecArgs: string[];
634
642
  /** The further executables with their entries; narrows {@link PackSettings.executables}. */
635
643
  executables: ShipExecutable[];
636
644
  /** Output root; `stage/`, `overlay/` and `out/` hang under it. */
@@ -67,6 +67,13 @@ export declare function iconSourceForSize(source: WebextIconSource, size: number
67
67
  * one to disk.
68
68
  */
69
69
  export declare function resolveWebextConfig(pkg: PackageShape, root: string, exists?: (path: string, kind: 'file' | 'dir') => boolean): ResolvedWebext;
70
+ /**
71
+ * What `webext submit` needs: the package name and version, the targets (to find the default zip)
72
+ * and the output folder. It uploads a zip somebody else built, so it neither needs nor checks the
73
+ * manifest, scripts or pages: a project with its own build script (Beifahrer) declares only
74
+ * `gjsify.webext.listing`, and must still be able to submit.
75
+ */
76
+ export declare function resolveSubmitProject(pkg: PackageShape, root: string): Pick<ResolvedWebext, 'root' | 'name' | 'version' | 'targets' | 'outDir'>;
70
77
  /** Narrow the configured targets to the ones a command was asked for. */
71
78
  export declare function selectTargets(config: ResolvedWebext, requested: readonly string[] | undefined): WebextTarget[];
72
79
  export {};
@@ -213,6 +213,46 @@ export function resolveWebextConfig(pkg, root, exists = defaultExists) {
213
213
  minify: block.minify ?? true,
214
214
  };
215
215
  }
216
+ /**
217
+ * What `webext submit` needs: the package name and version, the targets (to find the default zip)
218
+ * and the output folder. It uploads a zip somebody else built, so it neither needs nor checks the
219
+ * manifest, scripts or pages: a project with its own build script (Beifahrer) declares only
220
+ * `gjsify.webext.listing`, and must still be able to submit.
221
+ */
222
+ export function resolveSubmitProject(pkg, root) {
223
+ const raw = pkg.gjsify?.webext;
224
+ if (raw !== undefined && !isRecord(raw))
225
+ throw new Error('gjsify webext: `gjsify.webext` must be an object.');
226
+ const block = (raw ?? {});
227
+ const problems = [];
228
+ const targetIds = block.targets ?? [...DEFAULT_WEBEXT_TARGETS];
229
+ const targets = [];
230
+ if (!Array.isArray(targetIds) || targetIds.length === 0) {
231
+ problems.push('`targets` must be a non-empty array of target names.');
232
+ }
233
+ else {
234
+ for (const id of targetIds) {
235
+ try {
236
+ targets.push(parseWebextTarget(String(id)));
237
+ }
238
+ catch (err) {
239
+ problems.push(err.message.replace(/^gjsify webext: /, ''));
240
+ }
241
+ }
242
+ }
243
+ if (problems.length > 0) {
244
+ throw new Error(`gjsify webext: \`gjsify.webext\` in ${join(root, 'package.json')}:\n - ${problems.join('\n - ')}`);
245
+ }
246
+ return {
247
+ root,
248
+ name: block.name ?? defaultArtifactName(pkg.name),
249
+ version: pkg.version ?? '0.0.0',
250
+ targets,
251
+ outDir: isAbsolute(block.outDir ?? '.output')
252
+ ? block.outDir
253
+ : resolve(root, block.outDir ?? '.output'),
254
+ };
255
+ }
216
256
  function defaultExists(path, kind) {
217
257
  if (!existsSync(path))
218
258
  return false;
@@ -120,8 +120,28 @@ export function createChromeBackend(credentials, options = {}) {
120
120
  return 'unknown';
121
121
  }
122
122
  };
123
+ /** `--dry-run`: the token exchange plus one `fetchStatus` GET. Nothing is uploaded or published. */
124
+ const verifyCredentials = async () => {
125
+ const res = await call(`${API_ROOT}/v2/${name}:fetchStatus`, { method: 'GET' });
126
+ if (res.ok)
127
+ return;
128
+ const detail = await describe(res);
129
+ if (res.status === 401) {
130
+ throw fail(res.status, `fetchStatus refused the access token: ${detail}. ${TOKEN_HINT}`);
131
+ }
132
+ if (res.status === 403) {
133
+ throw fail(res.status, `fetchStatus is forbidden: ${detail}. The Google account behind CHROME_WEB_STORE_REFRESH_TOKEN is not a ` +
134
+ 'publisher of this item, or CHROME_WEB_STORE_PUBLISHER_ID / CHROME_WEB_STORE_ITEM_ID name someone else’s item — ' +
135
+ 'check both ids, or renew the refresh token with the account that owns the item.');
136
+ }
137
+ if (res.status === 404) {
138
+ throw fail(res.status, `fetchStatus found no such item: ${detail}. Check CHROME_WEB_STORE_PUBLISHER_ID and CHROME_WEB_STORE_ITEM_ID.`);
139
+ }
140
+ throw fail(res.status, `fetchStatus failed: ${detail}`);
141
+ };
123
142
  return {
124
143
  store: 'chrome',
144
+ verifyCredentials,
125
145
  async upload(input) {
126
146
  refuseIfBusy(await readStatus(), input.version);
127
147
  const res = await call(`${API_ROOT}/upload/v2/${name}:upload`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/cli",
3
- "version": "0.64.45",
3
+ "version": "0.64.47",
4
4
  "description": "CLI for Gjsify",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -142,22 +142,22 @@
142
142
  "cli"
143
143
  ],
144
144
  "dependencies": {
145
- "@gjsify/blueprint": "0.64.45",
146
- "@gjsify/buffer": "0.64.45",
147
- "@gjsify/create-app": "0.64.45",
148
- "@gjsify/node-globals": "0.64.45",
149
- "@gjsify/node-polyfills": "0.64.45",
150
- "@gjsify/npm-registry": "0.64.45",
151
- "@gjsify/resolve-npm": "0.64.45",
152
- "@gjsify/rolldown-plugin-gjsify": "0.64.45",
153
- "@gjsify/vite-plugin-blueprint": "0.64.45",
154
- "@gjsify/rolldown-plugin-pnp": "0.64.45",
155
- "@gjsify/semver": "0.64.45",
156
- "@gjsify/tar": "0.64.45",
157
- "@gjsify/tsc": "0.64.45",
158
- "@gjsify/utils": "0.64.45",
159
- "@gjsify/web-polyfills": "0.64.45",
160
- "@gjsify/workspace": "0.64.45",
145
+ "@gjsify/blueprint": "0.64.47",
146
+ "@gjsify/buffer": "0.64.47",
147
+ "@gjsify/create-app": "0.64.47",
148
+ "@gjsify/node-globals": "0.64.47",
149
+ "@gjsify/node-polyfills": "0.64.47",
150
+ "@gjsify/npm-registry": "0.64.47",
151
+ "@gjsify/resolve-npm": "0.64.47",
152
+ "@gjsify/rolldown-plugin-gjsify": "0.64.47",
153
+ "@gjsify/vite-plugin-blueprint": "0.64.47",
154
+ "@gjsify/rolldown-plugin-pnp": "0.64.47",
155
+ "@gjsify/semver": "0.64.47",
156
+ "@gjsify/tar": "0.64.47",
157
+ "@gjsify/tsc": "0.64.47",
158
+ "@gjsify/utils": "0.64.47",
159
+ "@gjsify/web-polyfills": "0.64.47",
160
+ "@gjsify/workspace": "0.64.47",
161
161
  "acorn": "^8.17.0",
162
162
  "cosmiconfig": "^9.0.2",
163
163
  "get-tsconfig": "^4.14.0",
@@ -166,13 +166,13 @@
166
166
  "yargs": "^18.0.0"
167
167
  },
168
168
  "devDependencies": {
169
- "@gjsify/unit": "0.64.45",
169
+ "@gjsify/unit": "0.64.47",
170
170
  "@types/yargs": "^17.0.35",
171
171
  "typescript": "^6.0.3"
172
172
  },
173
173
  "peerDependencies": {
174
- "@gjsify/oxfmt-native": "0.64.45",
175
- "@gjsify/rolldown-native": "0.64.45"
174
+ "@gjsify/oxfmt-native": "0.64.47",
175
+ "@gjsify/rolldown-native": "0.64.47"
176
176
  },
177
177
  "peerDependenciesMeta": {
178
178
  "@gjsify/oxfmt-native": {