@gjsify/cli 0.64.53 → 0.64.54
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/dist/cli.gjs.mjs +70 -68
- package/lib/commands/ship.js +30 -3
- package/lib/commands/webext/subcommands.d.ts +2 -0
- package/lib/commands/webext/subcommands.js +11 -0
- package/lib/types/config-data.d.ts +14 -1
- package/lib/utils/ship/hand-metainfo.d.ts +41 -0
- package/lib/utils/ship/hand-metainfo.js +106 -0
- package/lib/utils/ship/snap.js +14 -3
- package/lib/utils/webext/listing-upload.d.ts +12 -0
- package/lib/utils/webext/listing-upload.js +51 -0
- package/lib/utils/webext/stores/amo-listing.d.ts +21 -0
- package/lib/utils/webext/stores/amo-listing.js +131 -0
- package/lib/utils/webext/stores/amo.d.ts +1 -0
- package/lib/utils/webext/stores/amo.js +98 -1
- package/lib/utils/webext/stores/index.d.ts +23 -0
- package/lib/utils/webext/submit.d.ts +13 -0
- package/lib/utils/webext/submit.js +61 -2
- package/package.json +20 -20
package/lib/commands/ship.js
CHANGED
|
@@ -45,6 +45,8 @@ import { addApplicationsLink, buildDmgImage, dmgVolumeDir, dmgVolumeName, signDm
|
|
|
45
45
|
import { assertNoDroppedFlatpakModules } from '../utils/ship/flatpak-config.js';
|
|
46
46
|
import { buildFlatpakBundle } from '../utils/ship/flatpak.js';
|
|
47
47
|
import { iconSizes, resolveAppIcon } from '../utils/ship/icons.js';
|
|
48
|
+
import { formatFinding, lintMetainfo } from '../utils/metainfo-quality.js';
|
|
49
|
+
import { checkHandMetainfo, resolveHandMetainfo } from '../utils/ship/hand-metainfo.js';
|
|
48
50
|
import { localizeMetadata } from '../utils/ship/localize-metadata.js';
|
|
49
51
|
import { assertHostCanFinish, assertKindCanPack, assertToolsInstalled, canCarryTicket, configuredFormats, defaultFormatIds, formatIdsFor, resolveFormats, windowsProgramDirName, FORMAT_IDS, FORMATS, } from '../utils/ship/formats.js';
|
|
50
52
|
import { assertLayoutSupportsArch, hostLayout, layoutForOs, place, placeStage, resolveLayout, payloadArchExemptions, LAYOUT_NAMES, } from '../utils/ship/layout.js';
|
|
@@ -402,11 +404,32 @@ async function assemble(args) {
|
|
|
402
404
|
configKey: 'gjsify.ship',
|
|
403
405
|
copyrightYear: new Date(mtime * 1000).getUTCFullYear(),
|
|
404
406
|
};
|
|
407
|
+
// BEFORE staging: a hand file whose `<id>` is not this package's is refused, not shipped.
|
|
408
|
+
const hand = resolveHandMetainfo({
|
|
409
|
+
shipMetainfo: ship.metainfo,
|
|
410
|
+
siteMetainfo: configData.site?.metainfo,
|
|
411
|
+
configReleases: ship.releases,
|
|
412
|
+
projectDir,
|
|
413
|
+
});
|
|
414
|
+
if (hand !== undefined) {
|
|
415
|
+
for (const warning of checkHandMetainfo(hand, {
|
|
416
|
+
appId: settings.appId,
|
|
417
|
+
kind: settings.kind,
|
|
418
|
+
version: settings.version,
|
|
419
|
+
})) {
|
|
420
|
+
console.warn(`${LOG} ${warning}`);
|
|
421
|
+
}
|
|
422
|
+
console.log(`${LOG} AppStream metainfo from ${hand.path} (\`${hand.key}\`), staged as written`);
|
|
423
|
+
for (const finding of await lintMetainfo(hand.xml))
|
|
424
|
+
console.warn(`${LOG} ${formatFinding(finding, false)}`);
|
|
425
|
+
}
|
|
405
426
|
// Warn rather than fail: an incomplete AppStream component still
|
|
406
427
|
// installs and still runs. It is app STORES that will reject it, and
|
|
407
428
|
// that is a different day's problem than getting the package built.
|
|
408
|
-
|
|
409
|
-
|
|
429
|
+
if (hand === undefined) {
|
|
430
|
+
for (const missing of validateAppMetadata(metadataInputs)) {
|
|
431
|
+
console.warn(`${LOG} ${missing.field} is not set — ${missing.hint}`);
|
|
432
|
+
}
|
|
410
433
|
}
|
|
411
434
|
// Printed, not assumed. The text may come from an ancestor — one `LICENSE`
|
|
412
435
|
// at a monorepo root covers every package under it (see `discoverLicense`)
|
|
@@ -421,6 +444,10 @@ async function assemble(args) {
|
|
|
421
444
|
// shipped every `.mo` while `Name=` and `<name>` stayed English, so a fully
|
|
422
445
|
// translated app showed an English entry in the app menu and in Software.
|
|
423
446
|
// Both files stay valid either way, which is why nobody reported it.
|
|
447
|
+
// A hand file carries its own `xml:lang` elements and is staged untouched: the
|
|
448
|
+
// rendered metainfo below is discarded in its favour, and only the desktop
|
|
449
|
+
// entry's translation is used.
|
|
450
|
+
const handMetainfo = hand?.xml;
|
|
424
451
|
const translated = localizeMetadata({
|
|
425
452
|
metainfo: settings.kind === 'app' ? renderMetainfoApp(metadataInputs) : renderMetainfoCli(metadataInputs),
|
|
426
453
|
desktopEntry: settings.kind === 'app' ? renderDesktopEntry(metadataInputs) : undefined,
|
|
@@ -454,7 +481,7 @@ async function assemble(args) {
|
|
|
454
481
|
executable.name,
|
|
455
482
|
renderLauncher(settings, executable.entry, layout, runtime.launcher),
|
|
456
483
|
])),
|
|
457
|
-
metainfo: translated.metainfo,
|
|
484
|
+
metainfo: handMetainfo ?? translated.metainfo,
|
|
458
485
|
desktopEntry: translated.desktopEntry,
|
|
459
486
|
licenseText: settings.licenseFile === undefined ? undefined : readFileSync(settings.licenseFile, 'utf-8'),
|
|
460
487
|
changelogText: settings.changelogFile === undefined ? undefined : readFileSync(settings.changelogFile, 'utf-8'),
|
|
@@ -309,6 +309,15 @@ export const webextSubmitCommand = {
|
|
|
309
309
|
.option('source', {
|
|
310
310
|
description: 'AMO only: source archive for reviewers (needed when the zip is bundled or minified); attached with --submit.',
|
|
311
311
|
type: 'string',
|
|
312
|
+
})
|
|
313
|
+
.option('listing-only', {
|
|
314
|
+
description: 'AMO only: send description and privacy policy from --listing-dir (not the zip), then read each back. With --dry-run: lengths only, no network.',
|
|
315
|
+
type: 'boolean',
|
|
316
|
+
default: false,
|
|
317
|
+
})
|
|
318
|
+
.option('notes-version', {
|
|
319
|
+
description: 'With --listing-only: also send the reviewer notes (approval_notes) to this version id or number.',
|
|
320
|
+
type: 'string',
|
|
312
321
|
})
|
|
313
322
|
.option('listing-dir', {
|
|
314
323
|
description: 'Where `webext listing` wrote store.json (default: dist/listing).',
|
|
@@ -328,6 +337,8 @@ export const webextSubmitCommand = {
|
|
|
328
337
|
timeoutSeconds: args.timeout,
|
|
329
338
|
listingDir: args.listingDir,
|
|
330
339
|
sourceZip: args.source ? resolve(cwd, args.source) : undefined,
|
|
340
|
+
listingOnly: args.listingOnly,
|
|
341
|
+
notesVersion: args.notesVersion,
|
|
331
342
|
project: loadSubmitProject(cwd),
|
|
332
343
|
env: process.env,
|
|
333
344
|
out: (line) => console.log(line),
|
|
@@ -413,7 +413,7 @@ export interface AppMetadata {
|
|
|
413
413
|
localizedUrls?: Record<string, string>;
|
|
414
414
|
caption?: string;
|
|
415
415
|
captionTranslatorHint?: string;
|
|
416
|
-
environment?:
|
|
416
|
+
environment?: ScreenshotEnvironment;
|
|
417
417
|
type?: 'default' | 'source';
|
|
418
418
|
}>;
|
|
419
419
|
/** Light/dark accent colours (hex `#rrggbb`) — emit `<branding>` block. */
|
|
@@ -514,7 +514,20 @@ export interface AppMetadata {
|
|
|
514
514
|
* Everything here has a derived default; a project that already has a
|
|
515
515
|
* `gjsify.flatpak` block usually needs no `gjsify.ship` block at all.
|
|
516
516
|
*/
|
|
517
|
+
/**
|
|
518
|
+
* AppStream's `<screenshot environment>`: a desktop, optionally with the colour scheme the shot
|
|
519
|
+
* was taken in (`gnome:dark`, `plasma:light`), or `cli`.
|
|
520
|
+
*/
|
|
521
|
+
export type ScreenshotEnvironment = 'cli' | `${'gnome' | 'plasma'}${'' | ':dark' | ':light'}`;
|
|
517
522
|
export interface ConfigDataShip extends AppMetadata {
|
|
523
|
+
/**
|
|
524
|
+
* Path (relative to the project) to a hand-written AppStream metainfo that `ship` stages
|
|
525
|
+
* verbatim instead of rendering one from this block (ADR 0151). Its `<id>` and
|
|
526
|
+
* `<launchable>` must match `appId`; it is not re-translated and must hold its own
|
|
527
|
+
* `<releases>` (a `releases` here is refused). Default: `gjsify.site.metainfo` when set and
|
|
528
|
+
* this block has no `releases`, else the rendered component.
|
|
529
|
+
*/
|
|
530
|
+
metainfo?: string;
|
|
518
531
|
/**
|
|
519
532
|
* Distribution channel (ADR 0113): `flathub | web | microsoft-store | apple-app-store`.
|
|
520
533
|
* Becomes the `__GJSIFY_CHANNEL__` define that `@gjsify/distribution` reads, and gates the
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface HandMetainfo {
|
|
2
|
+
/** The path as the project wrote it, for messages. */
|
|
3
|
+
path: string;
|
|
4
|
+
/** The file's bytes as UTF-8 — staged unchanged. */
|
|
5
|
+
xml: string;
|
|
6
|
+
/** `ship.metainfo` or the `site.metainfo` fallback — for messages. */
|
|
7
|
+
key: 'gjsify.ship.metainfo' | 'gjsify.site.metainfo';
|
|
8
|
+
}
|
|
9
|
+
export interface HandMetainfoInputs {
|
|
10
|
+
shipMetainfo?: string;
|
|
11
|
+
siteMetainfo?: string;
|
|
12
|
+
/** `gjsify.ship.releases` — a second source of the same `<releases>` block. */
|
|
13
|
+
configReleases?: readonly unknown[];
|
|
14
|
+
projectDir: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Which hand file, if any, replaces the rendered metainfo.
|
|
18
|
+
*
|
|
19
|
+
* `ship.metainfo` is an explicit request, so a missing file or a conflicting `releases` in the
|
|
20
|
+
* config REFUSES — merging would silently pick one. `site.metainfo` is only a fallback: a project
|
|
21
|
+
* that already declares `ship.releases` keeps today's rendering rather than changing behaviour
|
|
22
|
+
* under it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveHandMetainfo(input: HandMetainfoInputs): HandMetainfo | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Refuse a hand file that would ship as a different component than the package is.
|
|
27
|
+
*
|
|
28
|
+
* - `<id>` ≠ `appId`: the stage names the file `<appId>.metainfo.xml`, and every store resolves
|
|
29
|
+
* the component by the `<id>` INSIDE it — a mismatch installs and is invisible.
|
|
30
|
+
* - `<launchable type="desktop-id">` ≠ `<appId>.desktop`: the desktop entry is still rendered
|
|
31
|
+
* from config under that name; a launchable pointing elsewhere gives Software a Launch button
|
|
32
|
+
* that finds nothing. An absent launchable is left to `lintMetainfo`, which warns.
|
|
33
|
+
*
|
|
34
|
+
* Returns warnings (the file lacks the package version) rather than throwing on them: the
|
|
35
|
+
* release entry is usually added by the release step, which may run after `ship`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function checkHandMetainfo(hand: HandMetainfo, expect: {
|
|
38
|
+
appId: string;
|
|
39
|
+
kind: 'app' | 'cli';
|
|
40
|
+
version: string;
|
|
41
|
+
}): string[];
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// A hand-written AppStream metainfo that `gjsify ship` stages verbatim (ADR 0151).
|
|
2
|
+
//
|
|
3
|
+
// Apps that keep the file by hand — already translated, with screenshots and releases —
|
|
4
|
+
// name it in `gjsify.ship.metainfo` (or, as a fallback, `gjsify.site.metainfo`, which
|
|
5
|
+
// `gjsify site` and `gjsify release-notes` already read). `ship` then stages THAT file
|
|
6
|
+
// instead of rendering one from config, so the shipped component and the website cannot drift.
|
|
7
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { resolve } from 'node:path';
|
|
9
|
+
import { scanXml } from '@gjsify/utils/core';
|
|
10
|
+
/**
|
|
11
|
+
* Which hand file, if any, replaces the rendered metainfo.
|
|
12
|
+
*
|
|
13
|
+
* `ship.metainfo` is an explicit request, so a missing file or a conflicting `releases` in the
|
|
14
|
+
* config REFUSES — merging would silently pick one. `site.metainfo` is only a fallback: a project
|
|
15
|
+
* that already declares `ship.releases` keeps today's rendering rather than changing behaviour
|
|
16
|
+
* under it.
|
|
17
|
+
*/
|
|
18
|
+
export function resolveHandMetainfo(input) {
|
|
19
|
+
const hasReleases = (input.configReleases?.length ?? 0) > 0;
|
|
20
|
+
let key;
|
|
21
|
+
let path;
|
|
22
|
+
if (input.shipMetainfo !== undefined) {
|
|
23
|
+
key = 'gjsify.ship.metainfo';
|
|
24
|
+
path = input.shipMetainfo;
|
|
25
|
+
if (hasReleases) {
|
|
26
|
+
throw new Error(`gjsify ship: \`gjsify.ship.metainfo\` and \`gjsify.ship.releases\` both describe the releases. ` +
|
|
27
|
+
`The file is staged verbatim, so the config entries would be dropped without a word — ` +
|
|
28
|
+
`keep the \`<releases>\` in ${path} and remove \`releases\` from the config.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (input.siteMetainfo !== undefined && !hasReleases) {
|
|
32
|
+
key = 'gjsify.site.metainfo';
|
|
33
|
+
path = input.siteMetainfo;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const abs = resolve(input.projectDir, path);
|
|
39
|
+
if (!existsSync(abs)) {
|
|
40
|
+
throw new Error(`gjsify ship: \`${key}\` points at ${path}, which does not exist (${abs}).`);
|
|
41
|
+
}
|
|
42
|
+
return { path, xml: readFileSync(abs, 'utf-8'), key };
|
|
43
|
+
}
|
|
44
|
+
function readFacts(xml) {
|
|
45
|
+
const facts = { releaseVersions: [] };
|
|
46
|
+
const stack = [];
|
|
47
|
+
let text = '';
|
|
48
|
+
for (const token of scanXml(xml)) {
|
|
49
|
+
if (token.kind === 'open') {
|
|
50
|
+
const name = token.name;
|
|
51
|
+
if (name === 'release' && token.attributes.version !== undefined) {
|
|
52
|
+
facts.releaseVersions.push(token.attributes.version);
|
|
53
|
+
}
|
|
54
|
+
if (name === 'launchable' && token.attributes.type === 'desktop-id' && !token.selfClosing) {
|
|
55
|
+
stack.push('launchable');
|
|
56
|
+
text = '';
|
|
57
|
+
}
|
|
58
|
+
else if (name === 'id' && stack.length === 0 && facts.id === undefined && !token.selfClosing) {
|
|
59
|
+
stack.push('id');
|
|
60
|
+
text = '';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (token.kind === 'text') {
|
|
64
|
+
if (stack.length > 0)
|
|
65
|
+
text += token.text;
|
|
66
|
+
}
|
|
67
|
+
else if (stack.length > 0) {
|
|
68
|
+
const open = stack.pop();
|
|
69
|
+
if (open === 'id')
|
|
70
|
+
facts.id = text.trim();
|
|
71
|
+
else if (open === 'launchable')
|
|
72
|
+
facts.launchable = text.trim();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return facts;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Refuse a hand file that would ship as a different component than the package is.
|
|
79
|
+
*
|
|
80
|
+
* - `<id>` ≠ `appId`: the stage names the file `<appId>.metainfo.xml`, and every store resolves
|
|
81
|
+
* the component by the `<id>` INSIDE it — a mismatch installs and is invisible.
|
|
82
|
+
* - `<launchable type="desktop-id">` ≠ `<appId>.desktop`: the desktop entry is still rendered
|
|
83
|
+
* from config under that name; a launchable pointing elsewhere gives Software a Launch button
|
|
84
|
+
* that finds nothing. An absent launchable is left to `lintMetainfo`, which warns.
|
|
85
|
+
*
|
|
86
|
+
* Returns warnings (the file lacks the package version) rather than throwing on them: the
|
|
87
|
+
* release entry is usually added by the release step, which may run after `ship`.
|
|
88
|
+
*/
|
|
89
|
+
export function checkHandMetainfo(hand, expect) {
|
|
90
|
+
const facts = readFacts(hand.xml);
|
|
91
|
+
if (facts.id !== expect.appId) {
|
|
92
|
+
throw new Error(`gjsify ship: ${hand.path} (\`${hand.key}\`) has <id>${facts.id ?? ''}</id>, but the package's ` +
|
|
93
|
+
`application id is "${expect.appId}" (\`gjsify.ship.appId\`). Stores resolve the component by the ` +
|
|
94
|
+
`<id> inside the file, so one of the two is wrong.`);
|
|
95
|
+
}
|
|
96
|
+
if (expect.kind === 'app' && facts.launchable !== undefined && facts.launchable !== `${expect.appId}.desktop`) {
|
|
97
|
+
throw new Error(`gjsify ship: ${hand.path} (\`${hand.key}\`) has <launchable type="desktop-id">${facts.launchable}` +
|
|
98
|
+
`</launchable>, but \`ship\` stages the desktop entry as ${expect.appId}.desktop.`);
|
|
99
|
+
}
|
|
100
|
+
const warnings = [];
|
|
101
|
+
if (!facts.releaseVersions.includes(expect.version)) {
|
|
102
|
+
warnings.push(`${hand.path} has no <release version="${expect.version}"> — the shipped component will not list ` +
|
|
103
|
+
`the version it is packaged as.`);
|
|
104
|
+
}
|
|
105
|
+
return warnings;
|
|
106
|
+
}
|
package/lib/utils/ship/snap.js
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
// (`desktop-launch`, the GPU wrapper) is GPL-3 code that changes per base, so porting it
|
|
8
8
|
// would turn gjsify into a downstream of snapcraft's tree. The cost is the one every
|
|
9
9
|
// tool-backed row pays: `snapcraft` must be on PATH, and it is not on the machine this was
|
|
10
|
-
// written on
|
|
11
|
-
//
|
|
12
|
-
//
|
|
10
|
+
// written on. What only the tool can answer is measured by `ship-pack-snap` in CI and
|
|
11
|
+
// recorded in ADR 0149: the launcher reaches the platform's `gjs` (with
|
|
12
|
+
// `GJS_PRIVATE_TYPELIB_DIR` below), every extension plug auto-connects, and a window opens
|
|
13
|
+
// under Xvfb. arm64 and a real desktop session are not measured.
|
|
13
14
|
//
|
|
14
15
|
// WHAT IS MEASURED, from the published `gnome-core26` revision (2026-11-20): it carries
|
|
15
16
|
// `gjs` 1.88, GTK 4, libadwaita, libsoup 3 and the GObject typelibs a GJS app imports, so
|
|
@@ -31,6 +32,15 @@ export const SNAP_TOOL = 'snapcraft';
|
|
|
31
32
|
export const SNAP_BASE = 'core26';
|
|
32
33
|
/** Set to `1` to build on the host instead of in LXD (`snapcraft pack --destructive-mode`). */
|
|
33
34
|
export const SNAP_DESTRUCTIVE_ENV = 'GJSIFY_SNAP_DESTRUCTIVE';
|
|
35
|
+
/**
|
|
36
|
+
* Where `gnome-core26` keeps `GjsPrivate-1.0.typelib`, which every GJS override of Gio and Gtk
|
|
37
|
+
* requires. The extension's `desktop-launch` prepends `usr/lib/gjs/girepository-1.0` but not
|
|
38
|
+
* this Debian multiarch spelling, and the platform's `gjs` has the path compiled in relative to
|
|
39
|
+
* `/`, so without it the first `gi://Gtk` throws "Typelib file for namespace 'GjsPrivate' (any
|
|
40
|
+
* version) not found" — measured in run 44885398599. `desktop-launch` prepends to an existing
|
|
41
|
+
* value, so setting it on the app survives the command chain. snapcraft expands the triplet.
|
|
42
|
+
*/
|
|
43
|
+
const GJS_PRIVATE_TYPELIB_DIR = '$SNAP/gnome-platform/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/gjs/girepository-1.0';
|
|
34
44
|
/** Directory inside the work dir that holds the payload `dump` copies. */
|
|
35
45
|
const PAYLOAD_DIR = 'payload';
|
|
36
46
|
/** The prefix the payload sits under inside the snap — the AppImage layout, for its reason. */
|
|
@@ -92,6 +102,7 @@ export function renderSnapcraftManifest(input) {
|
|
|
92
102
|
extensions: ['gnome'],
|
|
93
103
|
desktop: `${PREFIX_DIR}/${snapDesktopPath(settings)}`,
|
|
94
104
|
'common-id': settings.appId,
|
|
105
|
+
environment: { GI_TYPELIB_PATH: GJS_PRIVATE_TYPELIB_DIR },
|
|
95
106
|
};
|
|
96
107
|
const manifest = {
|
|
97
108
|
name: settings.binaryName,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StoreBackend } from './stores/index.js';
|
|
2
|
+
export interface ListingUploadInput {
|
|
3
|
+
readonly listingRoot: string;
|
|
4
|
+
readonly dryRun: boolean;
|
|
5
|
+
/** Send the reviewer notes to this version (id or number); without it they are not sent. */
|
|
6
|
+
readonly notesVersion?: string;
|
|
7
|
+
/** Called only for a real send, so a dry run never builds a backend or reads credentials. */
|
|
8
|
+
readonly backend: () => StoreBackend;
|
|
9
|
+
readonly out: (line: string) => void;
|
|
10
|
+
}
|
|
11
|
+
/** Returns the exit code: 0 only when every field was read back and matches. */
|
|
12
|
+
export declare function runListingUpload(input: ListingUploadInput): Promise<number>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// `gjsify webext submit --store amo --listing-only`: send the texts `webext listing` wrote to AMO's
|
|
2
|
+
// listing endpoints, then report per field what a READ-BACK found (the publish-readback.ts rule:
|
|
3
|
+
// never claim what was not read). `--dry-run` prints lengths per field and locale and touches
|
|
4
|
+
// neither credentials nor network.
|
|
5
|
+
import { resolve } from 'node:path';
|
|
6
|
+
import { readAmoListing } from './stores/amo-listing.js';
|
|
7
|
+
/** Returns the exit code: 0 only when every field was read back and matches. */
|
|
8
|
+
export async function runListingUpload(input) {
|
|
9
|
+
const files = readAmoListing(resolve(input.listingRoot));
|
|
10
|
+
const { approvalNotesText, ...texts } = files.input;
|
|
11
|
+
if (input.notesVersion !== undefined && approvalNotesText === undefined) {
|
|
12
|
+
throw new Error('--notes-version is set but no amo/<lang>/reviewer-notes.txt exists.');
|
|
13
|
+
}
|
|
14
|
+
const listing = {
|
|
15
|
+
...texts,
|
|
16
|
+
...(input.notesVersion !== undefined && approvalNotesText !== undefined
|
|
17
|
+
? { approvalNotes: { version: input.notesVersion, text: approvalNotesText } }
|
|
18
|
+
: {}),
|
|
19
|
+
};
|
|
20
|
+
if (input.dryRun) {
|
|
21
|
+
input.out('addons.mozilla.org listing: dry run — nothing is sent, no request is made.');
|
|
22
|
+
const lines = (field, values) => {
|
|
23
|
+
for (const [locale, text] of Object.entries(values)) {
|
|
24
|
+
input.out(` would send ${field} [${locale}]: ${text.length} chars`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
lines('description', listing.description);
|
|
28
|
+
if (listing.privacyPolicy !== undefined)
|
|
29
|
+
lines('privacy_policy (eula_policy)', listing.privacyPolicy);
|
|
30
|
+
if (listing.approvalNotes !== undefined) {
|
|
31
|
+
input.out(` would send approval_notes (version ${listing.approvalNotes.version}): ${listing.approvalNotes.text.length} chars`);
|
|
32
|
+
}
|
|
33
|
+
input.out(' name and summary are never sent: AMO takes the name from the manifest, and the store summary is the manifest description.');
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
const backend = input.backend();
|
|
37
|
+
if (backend.updateListing === undefined) {
|
|
38
|
+
throw new Error('this store has no listing API; only AMO takes listing texts.');
|
|
39
|
+
}
|
|
40
|
+
const result = await backend.updateListing(listing);
|
|
41
|
+
let failed = 0;
|
|
42
|
+
for (const f of result.fields) {
|
|
43
|
+
if (f.verdict !== 'match')
|
|
44
|
+
failed += 1;
|
|
45
|
+
input.out(` ${f.field}${f.locale === undefined ? '' : ` [${f.locale}]`}: ${f.verdict} — ${f.detail}`);
|
|
46
|
+
}
|
|
47
|
+
input.out(failed === 0
|
|
48
|
+
? `addons.mozilla.org listing: ${result.fields.length} field(s) written and read back, all match.`
|
|
49
|
+
: `addons.mozilla.org listing: ${failed} of ${result.fields.length} field(s) NOT confirmed by the read-back.`);
|
|
50
|
+
return failed === 0 ? 0 : 1;
|
|
51
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { StoreListingInput } from './index.js';
|
|
2
|
+
/** The locales addons-server accepts for translated fields (its `LANGUAGES` setting). */
|
|
3
|
+
export declare const AMO_LOCALES: readonly string[];
|
|
4
|
+
/**
|
|
5
|
+
* The AMO locale for a generator language (`en`, `de`, `pt_BR`, `de-DE`), or null when AMO has none
|
|
6
|
+
* that is unambiguous. `en` is AMO's `en-US`, the default locale of every listing.
|
|
7
|
+
*/
|
|
8
|
+
export declare function amoLocale(language: string): string | null;
|
|
9
|
+
export interface AmoListingFiles {
|
|
10
|
+
readonly input: Omit<StoreListingInput, 'approvalNotes'> & {
|
|
11
|
+
readonly approvalNotesText?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Generator language → AMO locale, for the report. */
|
|
14
|
+
readonly locales: Readonly<Record<string, string>>;
|
|
15
|
+
}
|
|
16
|
+
export declare const readText: (dir: string, name: string) => string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Reads `<listingRoot>/amo/<lang>/{description,privacy,reviewer-notes}.txt`. Throws one
|
|
19
|
+
* error naming every problem, so a run needs one fix, not one per language. `name.txt` is never read.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readAmoListing(listingRoot: string): AmoListingFiles;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Reads what `gjsify webext listing` wrote for AMO (`<dir>/amo/<lang>/*.txt`) and maps it onto
|
|
2
|
+
// the fields AMO's API takes. Pure but for the file reads: the network half is `updateListing`
|
|
3
|
+
// in amo.ts.
|
|
4
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
/** The locales addons-server accepts for translated fields (its `LANGUAGES` setting). */
|
|
7
|
+
export const AMO_LOCALES = [
|
|
8
|
+
'ar',
|
|
9
|
+
'bg',
|
|
10
|
+
'ca',
|
|
11
|
+
'cak',
|
|
12
|
+
'cs',
|
|
13
|
+
'da',
|
|
14
|
+
'de',
|
|
15
|
+
'dsb',
|
|
16
|
+
'el',
|
|
17
|
+
'en-CA',
|
|
18
|
+
'en-GB',
|
|
19
|
+
'en-US',
|
|
20
|
+
'es',
|
|
21
|
+
'eu',
|
|
22
|
+
'fa',
|
|
23
|
+
'fi',
|
|
24
|
+
'fr',
|
|
25
|
+
'fy-NL',
|
|
26
|
+
'ga-IE',
|
|
27
|
+
'he',
|
|
28
|
+
'hsb',
|
|
29
|
+
'hu',
|
|
30
|
+
'id',
|
|
31
|
+
'it',
|
|
32
|
+
'ja',
|
|
33
|
+
'ka',
|
|
34
|
+
'kab',
|
|
35
|
+
'ko',
|
|
36
|
+
'mk',
|
|
37
|
+
'mn',
|
|
38
|
+
'nl',
|
|
39
|
+
'pl',
|
|
40
|
+
'pt-BR',
|
|
41
|
+
'pt-PT',
|
|
42
|
+
'ro',
|
|
43
|
+
'ru',
|
|
44
|
+
'sk',
|
|
45
|
+
'sl',
|
|
46
|
+
'sq',
|
|
47
|
+
'sv-SE',
|
|
48
|
+
'tr',
|
|
49
|
+
'uk',
|
|
50
|
+
'vi',
|
|
51
|
+
'zh-CN',
|
|
52
|
+
'zh-TW',
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* The AMO locale for a generator language (`en`, `de`, `pt_BR`, `de-DE`), or null when AMO has none
|
|
56
|
+
* that is unambiguous. `en` is AMO's `en-US`, the default locale of every listing.
|
|
57
|
+
*/
|
|
58
|
+
export function amoLocale(language) {
|
|
59
|
+
const [primary = '', region] = language.replace(/_/g, '-').split('-');
|
|
60
|
+
const lower = primary.toLowerCase();
|
|
61
|
+
const exact = AMO_LOCALES.find((l) => l.toLowerCase() === (region === undefined ? lower : `${lower}-${region.toLowerCase()}`));
|
|
62
|
+
if (exact !== undefined)
|
|
63
|
+
return exact;
|
|
64
|
+
if (lower === 'en')
|
|
65
|
+
return 'en-US';
|
|
66
|
+
if (AMO_LOCALES.includes(lower))
|
|
67
|
+
return lower;
|
|
68
|
+
const regional = AMO_LOCALES.filter((l) => l.startsWith(`${lower}-`));
|
|
69
|
+
return regional.length === 1 ? regional[0] : null;
|
|
70
|
+
}
|
|
71
|
+
export const readText = (dir, name) => {
|
|
72
|
+
const path = join(dir, name);
|
|
73
|
+
return existsSync(path) ? readFileSync(path, 'utf8').trim() : undefined;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Reads `<listingRoot>/amo/<lang>/{description,privacy,reviewer-notes}.txt`. Throws one
|
|
77
|
+
* error naming every problem, so a run needs one fix, not one per language. `name.txt` is never read.
|
|
78
|
+
*/
|
|
79
|
+
export function readAmoListing(listingRoot) {
|
|
80
|
+
const amoDir = join(listingRoot, 'amo');
|
|
81
|
+
if (!existsSync(amoDir)) {
|
|
82
|
+
throw new Error(`${amoDir} does not exist. Run \`gjsify webext listing --store amo\` first.`);
|
|
83
|
+
}
|
|
84
|
+
const problems = [];
|
|
85
|
+
const description = {};
|
|
86
|
+
const privacyPolicy = {};
|
|
87
|
+
const locales = {};
|
|
88
|
+
const reviewerNotes = {};
|
|
89
|
+
const languages = readdirSync(amoDir)
|
|
90
|
+
.filter((entry) => statSync(join(amoDir, entry)).isDirectory() && existsSync(join(amoDir, entry, 'description.txt')))
|
|
91
|
+
.sort();
|
|
92
|
+
for (const language of languages) {
|
|
93
|
+
const dir = join(amoDir, language);
|
|
94
|
+
const locale = amoLocale(language);
|
|
95
|
+
if (locale === null) {
|
|
96
|
+
problems.push(`language "${language}" has no AMO locale (known: ${AMO_LOCALES.join(', ')}).`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const taken = Object.entries(locales).find(([, l]) => l === locale);
|
|
100
|
+
if (taken !== undefined) {
|
|
101
|
+
problems.push(`languages "${taken[0]}" and "${language}" both map to AMO locale ${locale}.`);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
locales[language] = locale;
|
|
105
|
+
const d = readText(dir, 'description.txt');
|
|
106
|
+
if (d === undefined || d === '')
|
|
107
|
+
problems.push(`${language}/description.txt is missing or empty.`);
|
|
108
|
+
else
|
|
109
|
+
description[locale] = d;
|
|
110
|
+
const p = readText(dir, 'privacy.txt');
|
|
111
|
+
if (p !== undefined && p !== '')
|
|
112
|
+
privacyPolicy[locale] = p;
|
|
113
|
+
const r = readText(dir, 'reviewer-notes.txt');
|
|
114
|
+
if (r !== undefined && r !== '')
|
|
115
|
+
reviewerNotes[language] = r;
|
|
116
|
+
}
|
|
117
|
+
if (languages.length === 0)
|
|
118
|
+
problems.push(`${amoDir} holds no language directory with a description.txt.`);
|
|
119
|
+
if (problems.length > 0)
|
|
120
|
+
throw new Error(`the AMO listing in ${amoDir} cannot be sent:\n ${problems.join('\n ')}`);
|
|
121
|
+
// Reviewer notes are one plain string per version: the default language's, i.e. `en`, else the first.
|
|
122
|
+
const notesLanguage = 'en' in reviewerNotes ? 'en' : Object.keys(reviewerNotes)[0];
|
|
123
|
+
return {
|
|
124
|
+
input: {
|
|
125
|
+
description,
|
|
126
|
+
...(Object.keys(privacyPolicy).length > 0 ? { privacyPolicy } : {}),
|
|
127
|
+
...(notesLanguage === undefined ? {} : { approvalNotesText: reviewerNotes[notesLanguage] }),
|
|
128
|
+
},
|
|
129
|
+
locales,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -4,6 +4,7 @@ import { type StoreBackendFactory } from './index.js';
|
|
|
4
4
|
* seconds), `exp` ≤ iat + 5 min. Exported for the spec, which verifies the signature itself.
|
|
5
5
|
*/
|
|
6
6
|
export declare function signJwt(key: string, secret: string, nowMs: number): string;
|
|
7
|
+
export declare const normalizeText: (text: string) => string;
|
|
7
8
|
/** The error lines of a `validation` blob, whatever its exact shape. */
|
|
8
9
|
export declare function validationLines(validation: unknown): string[];
|
|
9
10
|
export declare const createAmoBackend: StoreBackendFactory;
|
|
@@ -49,6 +49,22 @@ export function signJwt(key, secret, nowMs) {
|
|
|
49
49
|
const signature = createHmac('sha256', secret).update(`${header}.${payload}`).digest();
|
|
50
50
|
return `${header}.${payload}.${b64url(signature)}`;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* AMO normalises line endings and outer whitespace, and LINKIFIES bare URLs on read (`<a href="…">url</a>`,
|
|
54
|
+
* entities escaped). Compare after undoing that; what is sent is never altered.
|
|
55
|
+
*/
|
|
56
|
+
const sameText = (a, b) => normalizeText(a) === normalizeText(b);
|
|
57
|
+
const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
|
|
58
|
+
export const normalizeText = (text) => text
|
|
59
|
+
.replace(/<\/?a\b[^>]*>/gi, '')
|
|
60
|
+
.replace(/&(?:#(\d+)|#x([0-9a-f]+)|(amp|lt|gt|quot|apos));/gi, (m, dec, hex, name) => {
|
|
61
|
+
if (name !== undefined)
|
|
62
|
+
return ENTITIES[name.toLowerCase()];
|
|
63
|
+
const code = dec !== undefined ? Number(dec) : parseInt(hex, 16);
|
|
64
|
+
return code <= 0x10ffff ? String.fromCodePoint(code) : m;
|
|
65
|
+
})
|
|
66
|
+
.replace(/\r\n/g, '\n')
|
|
67
|
+
.trim();
|
|
52
68
|
/** The error lines of a `validation` blob, whatever its exact shape. */
|
|
53
69
|
export function validationLines(validation) {
|
|
54
70
|
if (typeof validation !== 'object' || validation === null)
|
|
@@ -229,5 +245,86 @@ export const createAmoBackend = (credentials, options = {}) => {
|
|
|
229
245
|
async function verifyCredentials() {
|
|
230
246
|
await send('GET', `${addon}/`);
|
|
231
247
|
}
|
|
232
|
-
|
|
248
|
+
/** A version id is digits; anything else is a version number, which AMO wants as `v<number>`. */
|
|
249
|
+
const versionRef = (version) => /^\d+$/.test(version) ? version : `v${encodeURIComponent(version)}`;
|
|
250
|
+
/** A GET whose failure means "not established", never a failure of the write that preceded it. */
|
|
251
|
+
async function readBack(url, what) {
|
|
252
|
+
try {
|
|
253
|
+
return { body: await json(await send('GET', url), what) };
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
// The write already succeeded; a failed read must be reported as unread, not thrown.
|
|
257
|
+
if (error instanceof StoreApiError)
|
|
258
|
+
return { unread: error.message };
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function compareLocales(field, sent, stored, read) {
|
|
263
|
+
return Object.entries(sent).map(([locale, text]) => {
|
|
264
|
+
const base = { field, locale, sent: text.length };
|
|
265
|
+
if (read !== null)
|
|
266
|
+
return { ...base, verdict: 'unread', detail: read.unread };
|
|
267
|
+
if (typeof stored !== 'object' || stored === null) {
|
|
268
|
+
return { ...base, verdict: 'unread', detail: `AMO returned no per-locale ${field}.` };
|
|
269
|
+
}
|
|
270
|
+
const value = stored[locale];
|
|
271
|
+
if (typeof value !== 'string') {
|
|
272
|
+
return { ...base, verdict: 'mismatch', detail: `AMO holds no ${field} for ${locale}.` };
|
|
273
|
+
}
|
|
274
|
+
return sameText(value, text)
|
|
275
|
+
? { ...base, verdict: 'match', detail: `read back ${value.length} chars.` }
|
|
276
|
+
: {
|
|
277
|
+
...base,
|
|
278
|
+
verdict: 'mismatch',
|
|
279
|
+
detail: `AMO holds ${value.length} chars, sent ${text.length}.`,
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
async function updateListing(input) {
|
|
284
|
+
// Never `name` (AMO takes it from the manifest) and never `summary`: the store summary is the manifest's
|
|
285
|
+
// description, while summary.txt is the shorter metainfo text and would overwrite it. `privacy_policy` is
|
|
286
|
+
// ignored on this PATCH — it has its own endpoint.
|
|
287
|
+
await send('PATCH', `${addon}/`, { json: { description: input.description } });
|
|
288
|
+
if (input.privacyPolicy !== undefined) {
|
|
289
|
+
await send('PATCH', `${addon}/eula_policy/`, { json: { privacy_policy: input.privacyPolicy } });
|
|
290
|
+
}
|
|
291
|
+
const notes = input.approvalNotes;
|
|
292
|
+
const versionUrl = notes === undefined ? '' : `${addon}/versions/${versionRef(notes.version)}/`;
|
|
293
|
+
if (notes !== undefined)
|
|
294
|
+
await send('PATCH', versionUrl, { json: { approval_notes: notes.text } });
|
|
295
|
+
const fields = [];
|
|
296
|
+
const detail = await readBack(`${addon}/`, 'the add-on detail');
|
|
297
|
+
const unread = 'unread' in detail ? detail : null;
|
|
298
|
+
const stored = 'body' in detail ? detail.body : {};
|
|
299
|
+
fields.push(...compareLocales('description', input.description, stored.description, unread));
|
|
300
|
+
if (input.privacyPolicy !== undefined) {
|
|
301
|
+
const policy = await readBack(`${addon}/eula_policy/`, 'the eula_policy');
|
|
302
|
+
fields.push(...compareLocales('privacy_policy', input.privacyPolicy, 'body' in policy ? policy.body.privacy_policy : undefined, 'unread' in policy ? policy : null));
|
|
303
|
+
}
|
|
304
|
+
if (notes !== undefined) {
|
|
305
|
+
const version = await readBack(versionUrl, 'the version detail');
|
|
306
|
+
const base = { field: 'approval_notes', sent: notes.text.length };
|
|
307
|
+
if ('unread' in version)
|
|
308
|
+
fields.push({ ...base, verdict: 'unread', detail: version.unread });
|
|
309
|
+
else if (typeof version.body.approval_notes !== 'string') {
|
|
310
|
+
fields.push({ ...base, verdict: 'unread', detail: 'AMO returned no approval_notes.' });
|
|
311
|
+
}
|
|
312
|
+
else if (sameText(version.body.approval_notes, notes.text)) {
|
|
313
|
+
fields.push({
|
|
314
|
+
...base,
|
|
315
|
+
verdict: 'match',
|
|
316
|
+
detail: `read back ${version.body.approval_notes.length} chars.`,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
fields.push({
|
|
321
|
+
...base,
|
|
322
|
+
verdict: 'mismatch',
|
|
323
|
+
detail: `AMO holds ${version.body.approval_notes.length} chars.`,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return { fields };
|
|
328
|
+
}
|
|
329
|
+
return { store: STORE, upload, publish, status, operation, verifyCredentials, updateListing };
|
|
233
330
|
};
|