@gjsify/cli 0.64.51-next.351 → 0.64.52

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/lib/cli-app.js CHANGED
@@ -18,7 +18,7 @@
18
18
  import yargs from 'yargs';
19
19
  import { classifyCliFailure } from './cli-fail.js';
20
20
  import { cliVersion } from './utils/publish-headers.js';
21
- import { buildCommand as build, clearCommand as clear, copyCommand as copy, envCommand as env, execCommand as exec, testCommand as test, runCommand as run, infoCommand as info, systemCheckCommand as systemCheck, checkCommand as check, showcaseCommand as showcase, createCommand as create, gresourceCommand as gresource, gettextCommand as gettext, gsettingsCommand as gsettings, flatpakCommand as flatpak, shipCommand as ship, flatparkCommand as flatpark, dlxCommand as dlx, installCommand as install, linkCommand as link, unlinkCommand as unlink, foreachCommand as foreach, workspaceCommand as workspace, packCommand as pack, publishCommand as publish, whoamiCommand as whoami, releaseNotesCommand as releaseNotes, androidIconsCommand as androidIcons, creditsCommand as credits, loginCommand as login, logoutCommand as logout, trustCommand as trust, onboardCommand as onboard, selfUpdateCommand as selfUpdate, generateInstallerCommand as generateInstaller, pruneCommand as prune, uninstallCommand as uninstall, formatCommand as format, lintCommand as lint, fixCommand as fix, upgradeCommand as upgrade, barrelsCommand as barrels, tscCommand as tsc, affectedCommand as affected, storybookCommand as storybook, siteCommand as site, devCommand as dev, debugCommand as debug, devtoolsCommand as devtools, browseCommand as browse, webextCommand as webext, blueprintCommand as blueprint, } from './commands/index.js';
21
+ import { buildCommand as build, clearCommand as clear, copyCommand as copy, envCommand as env, execCommand as exec, testCommand as test, runCommand as run, infoCommand as info, systemCheckCommand as systemCheck, checkCommand as check, showcaseCommand as showcase, createCommand as create, gresourceCommand as gresource, gettextCommand as gettext, gsettingsCommand as gsettings, flatpakCommand as flatpak, shipCommand as ship, flatparkCommand as flatpark, dlxCommand as dlx, installCommand as install, linkCommand as link, unlinkCommand as unlink, foreachCommand as foreach, workspaceCommand as workspace, packCommand as pack, publishCommand as publish, whoamiCommand as whoami, releaseNotesCommand as releaseNotes, androidIconsCommand as androidIcons, creditsCommand as credits, loginCommand as login, logoutCommand as logout, trustCommand as trust, onboardCommand as onboard, selfUpdateCommand as selfUpdate, generateInstallerCommand as generateInstaller, pruneCommand as prune, uninstallCommand as uninstall, formatCommand as format, lintCommand as lint, fixCommand as fix, upgradeCommand as upgrade, barrelsCommand as barrels, tscCommand as tsc, affectedCommand as affected, storybookCommand as storybook, siteCommand as site, devCommand as dev, debugCommand as debug, devtoolsCommand as devtools, browseCommand as browse, webextCommand as webext, snapCommand as snap, blueprintCommand as blueprint, } from './commands/index.js';
22
22
  import { APP_NAME } from './constants.js';
23
23
  import { isBun, isDeno, isNode, gjsSystemVersion } from '@gjsify/rolldown-plugin-gjsify/runtime';
24
24
  import { ensureGjsifyShimOnPath } from './utils/gjsify-shim.js';
@@ -143,6 +143,7 @@ export async function runCli(argv) {
143
143
  .command(devtools.command, devtools.description, devtools.builder, devtools.handler)
144
144
  .command(browse.command, browse.description, browse.builder, browse.handler)
145
145
  .command(webext.command, webext.description, webext.builder, webext.handler)
146
+ .command(snap.command, snap.description, snap.builder, snap.handler)
146
147
  .command(blueprint.command, blueprint.description, blueprint.builder, blueprint.handler)
147
148
  .demandCommand(1)
148
149
  .epilogue(`Running on ${runtimeLabel()}`)
@@ -49,4 +49,5 @@ export * from './debug.js';
49
49
  export * from './devtools.js';
50
50
  export * from './browse.js';
51
51
  export { webextCommand } from './webext/index.js';
52
+ export { snapCommand } from './snap/index.js';
52
53
  export { blueprintCommand, blueprintTypesCommand } from './blueprint/index.js';
@@ -49,4 +49,5 @@ export * from './debug.js';
49
49
  export * from './devtools.js';
50
50
  export * from './browse.js';
51
51
  export { webextCommand } from './webext/index.js';
52
+ export { snapCommand } from './snap/index.js';
52
53
  export { blueprintCommand, blueprintTypesCommand } from './blueprint/index.js';
@@ -52,6 +52,7 @@ import { isNodeRuntimeTarget, resolveNodeRuntime } from '../utils/ship/node-runt
52
52
  import { isUnder, SHARE } from '../utils/ship/share-dirs.js';
53
53
  import { compileSchemasForPayload, compileSchemasForStage } from '../utils/ship/schemas.js';
54
54
  import { buildMsi, MSI_PAYLOAD_DIR } from '../utils/ship/msi.js';
55
+ import { buildSnap } from '../utils/ship/snap.js';
55
56
  import { buildLinuxTarball } from '../utils/ship/tarball.js';
56
57
  import { buildZip, zipEntriesFromPayload } from '../utils/ship/zip.js';
57
58
  import { assertEntryRunsUnder } from '../utils/ship/entry-interpreter.js';
@@ -1257,6 +1258,21 @@ async function packOne(input) {
1257
1258
  });
1258
1259
  break;
1259
1260
  }
1261
+ case 'snap': {
1262
+ // FROM THE PAYLOAD, like every container here. The compile is on the pack path for
1263
+ // the AppImage's reason: the shared Linux stage carries the schema XML and no
1264
+ // `gschemas.compiled`, and GSettings aborts without the cache.
1265
+ const schemaCache = await compileSchemasForPayload({ payload, workDir: join(outRoot, 'snap-schemas') });
1266
+ await buildSnap({
1267
+ settings,
1268
+ payload: schemaCache === undefined ? payload : [...payload, schemaCache],
1269
+ workDir: join(outRoot, 'snap'),
1270
+ target,
1271
+ archLabel,
1272
+ verbose: input.verbose,
1273
+ });
1274
+ break;
1275
+ }
1260
1276
  case 'linux-tar':
1261
1277
  case 'linux-tar-flatpak': {
1262
1278
  // FROM THE PAYLOAD, like every container here. The Flatpak variant adds
@@ -0,0 +1,2 @@
1
+ import type { Command } from '../../types/index.js';
2
+ export declare const snapCommand: Command;
@@ -0,0 +1,13 @@
1
+ // `gjsify snap` — Snap Store helpers (ADR 0149), the `gjsify webext` shape (ADR 0148):
2
+ // a yargs subcommand group over `snapcraft`.
3
+ import { snapRegisterCommand, snapStatusCommand, snapUploadCommand } from './subcommands.js';
4
+ export const snapCommand = {
5
+ command: 'snap <subcommand>',
6
+ description: 'Snap Store helpers: register a name, upload a .snap, show channel status.',
7
+ builder: (yargs) => yargs
8
+ .command(snapRegisterCommand.command, snapRegisterCommand.description, snapRegisterCommand.builder, snapRegisterCommand.handler)
9
+ .command(snapUploadCommand.command, snapUploadCommand.description, snapUploadCommand.builder, snapUploadCommand.handler)
10
+ .command(snapStatusCommand.command, snapStatusCommand.description, snapStatusCommand.builder, snapStatusCommand.handler)
11
+ .demandCommand(1)
12
+ .strict(),
13
+ };
@@ -0,0 +1,12 @@
1
+ import type { Command } from '../../types/index.js';
2
+ interface NameArgs {
3
+ name?: string;
4
+ }
5
+ interface UploadArgs {
6
+ file?: string;
7
+ release: string[];
8
+ }
9
+ export declare const snapRegisterCommand: Command<unknown, NameArgs>;
10
+ export declare const snapUploadCommand: Command<unknown, UploadArgs>;
11
+ export declare const snapStatusCommand: Command<unknown, NameArgs>;
12
+ export {};
@@ -0,0 +1,37 @@
1
+ // `gjsify snap register|upload|status` — one self-contained Command each, composed in index.ts
2
+ // (the webext/subcommands.ts split). Building the .snap is `gjsify ship --target snap`.
3
+ import { resolve } from 'node:path';
4
+ import { assertSnapCredentials, assertSnapFile, assertSnapNameForStore, parseChannels, runSnapcraft, snapRegisterArgs, snapStatusArgs, snapUploadArgs, } from '../../utils/snap/store.js';
5
+ export const snapRegisterCommand = {
6
+ command: 'register <name>',
7
+ description: 'Claim a snap name in the Snap Store (snapcraft register). Needs an interactive `snapcraft login`.',
8
+ builder: (yargs) => yargs.positional('name', { description: 'The store name.', type: 'string' }),
9
+ handler: (args) => runSnapcraft('register', snapRegisterArgs(assertSnapNameForStore('register', args.name))),
10
+ };
11
+ export const snapUploadCommand = {
12
+ command: 'upload <file>',
13
+ description: 'Upload a .snap to the Snap Store, optionally releasing it to channels (snapcraft upload).',
14
+ builder: (yargs) => yargs
15
+ .positional('file', { description: 'The .snap that `gjsify ship --format snap` wrote.', type: 'string' })
16
+ .option('release', {
17
+ description: 'Release to these channels after the upload, e.g. edge or stable,candidate (repeatable).',
18
+ type: 'string',
19
+ array: true,
20
+ default: [],
21
+ })
22
+ .epilog('Credentials come from $SNAPCRAFT_STORE_CREDENTIALS only (create one with `snapcraft export-login`); ' +
23
+ 'this command never reads or prints them.'),
24
+ handler: async (args) => {
25
+ // Every refusal comes before snapcraft starts, so a typo costs no upload.
26
+ const channels = parseChannels(args.release);
27
+ const file = assertSnapFile(args.file === undefined ? undefined : resolve(process.cwd(), args.file));
28
+ assertSnapCredentials(process.env);
29
+ await runSnapcraft('upload', snapUploadArgs(file, channels));
30
+ },
31
+ };
32
+ export const snapStatusCommand = {
33
+ command: 'status <name>',
34
+ description: 'Show the revisions and channels of a snap in the Snap Store (snapcraft status).',
35
+ builder: (yargs) => yargs.positional('name', { description: 'The store name.', type: 'string' }),
36
+ handler: (args) => runSnapcraft('status', snapStatusArgs(assertSnapNameForStore('status', args.name))),
37
+ };
@@ -9,6 +9,7 @@
9
9
  // a format can be host-bound (§ A3), so `host` is a descriptor field now.
10
10
  import { isOnPath } from '../check-system-deps.js';
11
11
  import { APPIMAGE_TOOL } from './appimage.js';
12
+ import { SNAP_BASE, SNAP_TOOL } from './snap.js';
12
13
  import { DMG_TOOL } from './dmg.js';
13
14
  import { LAYOUTS, LAYOUT_NAMES } from './layout.js';
14
15
  import { SCHEMA_COMPILER, SCHEMA_COMPILER_HINT } from './schemas.js';
@@ -100,6 +101,15 @@ const APPIMAGE_ARCH = {
100
101
  function appImageArch(arch, _archIndependent) {
101
102
  return lookupArch(APPIMAGE_ARCH, arch, 'AppImage');
102
103
  }
104
+ /**
105
+ * `process.arch` → the name snapd and the store use. Its own table for the AppImage's reason:
106
+ * `amd64` is Debian's spelling and happens to match, but this one is the store's vocabulary
107
+ * and gains rows (`armhf`, `s390x`) on the store's schedule, not apt's.
108
+ */
109
+ const SNAP_ARCH = { x64: 'amd64', arm64: 'arm64' };
110
+ function snapArch(arch, _archIndependent) {
111
+ return lookupArch(SNAP_ARCH, arch, 'Snap');
112
+ }
103
113
  /**
104
114
  * `process.arch` → the `uname -m` spelling a tarball name carries (and the
105
115
  * Flatpak arch the `-flatpak` variant is consumed under). `archIndependent` is
@@ -514,6 +524,38 @@ export const FORMATS = {
514
524
  // build beside the tool gate rather than after it inside the packer.
515
525
  requiresDesktopEntry: true,
516
526
  },
527
+ // THE SIXTH CONTAINER OVER THE LINUX TREE (ADR 0149). Unlike the AppImage it
528
+ // bundles no runtime: `gnome-core26` is the closure, as `org.gnome.Platform` is
529
+ // for the Flatpak. Unlike `deb`/`rpm` it is written by a host tool, so the oracle
530
+ // reads it with `unsquashfs` — a program this tree did not write and snapcraft
531
+ // does not run. The file-level comparison script is not written yet (ADR 0149).
532
+ snap: {
533
+ id: 'snap',
534
+ layoutOs: 'linux',
535
+ // `/usr` inside the snap, the AppImage's layout and for its reason: the staged
536
+ // launcher computes its own prefix from `readlink -f "$0"`.
537
+ prefix: '/usr',
538
+ host: {
539
+ finishOn: ['linux'],
540
+ // The compiler is on the pack path for the AppImage's reason: no Linux stage
541
+ // carries `gschemas.compiled`, and GSettings aborts without it.
542
+ requiredTools: [SNAP_TOOL, SCHEMA_COMPILER],
543
+ installHint: `\`sudo snap install ${SNAP_TOOL} --classic\` (snapcraft is a snap; ${SNAP_BASE} builds need ` +
544
+ 'Ubuntu 26.04 with `GJSIFY_SNAP_DESTRUCTIVE=1`, or LXD without it); or assemble here with ' +
545
+ `\`gjsify ship linux --stage\` and pack where snapcraft is. The schema compiler is packaged: ${SCHEMA_COMPILER_HINT}`,
546
+ oracle: { readWith: ['unsquashfs'], readOn: ['linux'], selfReading: false },
547
+ },
548
+ depends: null,
549
+ // GJS ONLY: `gnome-core26` ships `gjs` and no `node`.
550
+ interpreters: ['gjs'],
551
+ interpreterGap: 'a snap runs against the `gnome-core26` platform snap, which ships `gjs` and no `node`, and the ' +
552
+ 'payload bundles no interpreter',
553
+ licenseDest: SHARE_LICENSE_DEST,
554
+ licenseKind: 'plain',
555
+ archName: snapArch,
556
+ fileName: (s, archLabel) => `${s.binaryName}_${s.version}_${archLabel}.snap`,
557
+ artifactKind: 'file',
558
+ },
517
559
  // THE FIFTH CONTAINER OVER THE LINUX TREE, and the first with no install
518
560
  // step and no prefix at all: a gzip'd tar whose single top directory is
519
561
  // `<binaryName>-<version>-linux-<arch>/`. It is a download to unpack anywhere,
@@ -1267,6 +1309,7 @@ export function canCarryTicket(id) {
1267
1309
  case 'rpm':
1268
1310
  case 'flatpak':
1269
1311
  case 'appimage':
1312
+ case 'snap':
1270
1313
  case 'linux-tar':
1271
1314
  case 'linux-tar-flatpak':
1272
1315
  case 'windows-dir':
@@ -0,0 +1,57 @@
1
+ import type { PayloadEntry } from './payload.js';
2
+ import type { PackSettings } from './types.js';
3
+ /** The tool this packer execs. One spelling, read by this module AND by the format row. */
4
+ export declare const SNAP_TOOL = "snapcraft";
5
+ /** The base the generated snap declares, and the platform snap that goes with it. */
6
+ export declare const SNAP_BASE = "core26";
7
+ /** Set to `1` to build on the host instead of in LXD (`snapcraft pack --destructive-mode`). */
8
+ export declare const SNAP_DESTRUCTIVE_ENV = "GJSIFY_SNAP_DESTRUCTIVE";
9
+ /** Shared with the store helpers (`gjsify snap register`), so both refuse the same names. */
10
+ export declare function isSnapName(name: string): boolean;
11
+ export interface SnapManifestInput {
12
+ settings: PackSettings;
13
+ }
14
+ /**
15
+ * Everything the store or snapcraft would refuse, refused here with the field named.
16
+ *
17
+ * Pure. The desktop entry is checked against the payload because `desktop:` pointing at a
18
+ * file that is not there is a snapcraft error that names neither the file nor the cause.
19
+ */
20
+ export declare function assertSnapIsPackable(payload: readonly {
21
+ path: string;
22
+ }[], settings: PackSettings): void;
23
+ /**
24
+ * The generated `snap/snapcraft.yaml`, as a plain object.
25
+ *
26
+ * Pure, so every key is unit-testable without snapcraft. `extensions` sits on the APP, which
27
+ * is where snapcraft reads it; the part is a `dump` of the staged payload, so nothing is
28
+ * compiled or fetched in the build.
29
+ */
30
+ export declare function renderSnapcraftManifest(input: SnapManifestInput): Record<string, unknown>;
31
+ /**
32
+ * The file's text. JSON IS YAML, and snapcraft reads it as YAML — a generated build input
33
+ * needs no emitter whose quoting rules this tree would then own.
34
+ */
35
+ export declare function renderSnapcraftYaml(input: SnapManifestInput): string;
36
+ /** The argument vector, as data, for the same reason the AppImage's is. */
37
+ export declare function snapcraftArgs(input: {
38
+ target: string;
39
+ archLabel: string;
40
+ destructive: boolean;
41
+ }): string[];
42
+ export interface SnapPackInput {
43
+ settings: PackSettings;
44
+ /** Prefix-relative payload, with `gschemas.compiled` already appended when there are schemas. */
45
+ payload: readonly PayloadEntry[];
46
+ /** Working root: holds `snap/snapcraft.yaml` and `payload/`, and is wiped first. */
47
+ workDir: string;
48
+ /** Absolute path the finished `.snap` is written to. */
49
+ target: string;
50
+ /** snapd's spelling of the architecture, e.g. `amd64`. */
51
+ archLabel: string;
52
+ verbose: boolean;
53
+ }
54
+ /** Write the project directory snapcraft builds from. Wipes `workDir`. */
55
+ export declare function writeSnapProject(input: SnapPackInput): void;
56
+ /** Build the snap and leave it at `input.target`. */
57
+ export declare function buildSnap(input: SnapPackInput): Promise<void>;
@@ -0,0 +1,161 @@
1
+ // The Snap packer — ADR 0149.
2
+ //
3
+ // The Flatpak shape, not the `.deb` shape: this tree writes the INPUT of a build tool
4
+ // (`snap/snapcraft.yaml` plus the payload it points at) and the host's `snapcraft` writes
5
+ // the container. A `.snap` is a squashfs plus `meta/snap.yaml`, and writing a squashfs is
6
+ // what ADR 0024 § A6 rejects by name; the `gnome` extension's launcher glue
7
+ // (`desktop-launch`, the GPU wrapper) is GPL-3 code that changes per base, so porting it
8
+ // would turn gjsify into a downstream of snapcraft's tree. The cost is the one every
9
+ // tool-backed row pays: `snapcraft` must be on PATH, and it is not on the machine this was
10
+ // written on, so what only the tool can answer (does the launcher find `gjs` through
11
+ // `$SNAP/gnome-platform`, which plugs a typical app needs, arm64) is recorded in ADR 0149
12
+ // as NOT yet measured.
13
+ //
14
+ // WHAT IS MEASURED, from the published `gnome-core26` revision (2026-11-20): it carries
15
+ // `gjs` 1.88, GTK 4, libadwaita, libsoup 3 and the GObject typelibs a GJS app imports, so
16
+ // the payload bundles nothing and the interpreter half of the artifact is the platform
17
+ // snap, exactly as `org.gnome.Platform` is for a Flatpak.
18
+ //
19
+ // THE PAYLOAD LIVES INSIDE THE PROJECT DIRECTORY and `source` is relative. snapcraft builds
20
+ // in an LXD container that mounts the project directory and nothing else, so an absolute
21
+ // path into `out/` would resolve on the host and not in the build.
22
+ import { existsSync, mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
23
+ import { join } from 'node:path';
24
+ import { describeExit, spawnToCompletion } from '../spawn.js';
25
+ import { encodeUtf8 } from './bytes.js';
26
+ import { SHARE } from './share-dirs.js';
27
+ import { writePayload } from './stage-writer.js';
28
+ /** The tool this packer execs. One spelling, read by this module AND by the format row. */
29
+ export const SNAP_TOOL = 'snapcraft';
30
+ /** The base the generated snap declares, and the platform snap that goes with it. */
31
+ export const SNAP_BASE = 'core26';
32
+ /** Set to `1` to build on the host instead of in LXD (`snapcraft pack --destructive-mode`). */
33
+ export const SNAP_DESTRUCTIVE_ENV = 'GJSIFY_SNAP_DESTRUCTIVE';
34
+ /** Directory inside the work dir that holds the payload `dump` copies. */
35
+ const PAYLOAD_DIR = 'payload';
36
+ /** The prefix the payload sits under inside the snap — the AppImage layout, for its reason. */
37
+ const PREFIX_DIR = 'usr';
38
+ /**
39
+ * Snap names: lowercase letters, digits and hyphens, no leading, trailing or doubled hyphen,
40
+ * at least one letter, at most 40 characters. The store enforces it at registration; failing
41
+ * here is minutes earlier than failing inside an LXD container.
42
+ */
43
+ const SNAP_NAME = /^(?=.*[a-z])[a-z0-9]+(-[a-z0-9]+)*$/;
44
+ const SNAP_NAME_MAX = 40;
45
+ const SNAP_VERSION_MAX = 32;
46
+ /** Shared with the store helpers (`gjsify snap register`), so both refuse the same names. */
47
+ export function isSnapName(name) {
48
+ return name.length <= SNAP_NAME_MAX && SNAP_NAME.test(name);
49
+ }
50
+ const SNAP_SUMMARY_MAX = 78;
51
+ /**
52
+ * Everything the store or snapcraft would refuse, refused here with the field named.
53
+ *
54
+ * Pure. The desktop entry is checked against the payload because `desktop:` pointing at a
55
+ * file that is not there is a snapcraft error that names neither the file nor the cause.
56
+ */
57
+ export function assertSnapIsPackable(payload, settings) {
58
+ const problems = [];
59
+ if (!isSnapName(settings.binaryName)) {
60
+ problems.push(`the binary name "${settings.binaryName}" is not a snap name (lowercase letters, digits and single ` +
61
+ `hyphens, at most ${SNAP_NAME_MAX} characters, at least one letter)`);
62
+ }
63
+ if (settings.version.length > SNAP_VERSION_MAX) {
64
+ problems.push(`the version "${settings.version}" is longer than ${SNAP_VERSION_MAX} characters`);
65
+ }
66
+ if (settings.summary.length > SNAP_SUMMARY_MAX) {
67
+ problems.push(`the summary is ${settings.summary.length} characters, the store takes ${SNAP_SUMMARY_MAX}`);
68
+ }
69
+ const desktop = snapDesktopPath(settings);
70
+ if (!payload.some((entry) => entry.path === desktop)) {
71
+ problems.push(`the payload has no ${desktop}, which the snap's \`desktop:\` key must point at`);
72
+ }
73
+ if (problems.length > 0) {
74
+ throw new Error(`gjsify ship: cannot pack a snap: ${problems.join('; ')}.`);
75
+ }
76
+ }
77
+ /** Prefix-relative path of the staged desktop entry. */
78
+ function snapDesktopPath(settings) {
79
+ return `${SHARE.applications}/${settings.appId}.desktop`;
80
+ }
81
+ /**
82
+ * The generated `snap/snapcraft.yaml`, as a plain object.
83
+ *
84
+ * Pure, so every key is unit-testable without snapcraft. `extensions` sits on the APP, which
85
+ * is where snapcraft reads it; the part is a `dump` of the staged payload, so nothing is
86
+ * compiled or fetched in the build.
87
+ */
88
+ export function renderSnapcraftManifest(input) {
89
+ const { settings } = input;
90
+ const app = {
91
+ command: `${PREFIX_DIR}/bin/${settings.binaryName}`,
92
+ extensions: ['gnome'],
93
+ desktop: `${PREFIX_DIR}/${snapDesktopPath(settings)}`,
94
+ 'common-id': settings.appId,
95
+ };
96
+ const manifest = {
97
+ name: settings.binaryName,
98
+ title: settings.name,
99
+ base: SNAP_BASE,
100
+ version: settings.version,
101
+ summary: settings.summary,
102
+ description: settings.description.join('\n\n'),
103
+ license: settings.license,
104
+ grade: 'stable',
105
+ confinement: 'strict',
106
+ apps: { [settings.binaryName]: app },
107
+ parts: {
108
+ [settings.binaryName]: { plugin: 'dump', source: PAYLOAD_DIR },
109
+ },
110
+ };
111
+ if (settings.homepage !== undefined)
112
+ manifest.website = settings.homepage;
113
+ return manifest;
114
+ }
115
+ /**
116
+ * The file's text. JSON IS YAML, and snapcraft reads it as YAML — a generated build input
117
+ * needs no emitter whose quoting rules this tree would then own.
118
+ */
119
+ export function renderSnapcraftYaml(input) {
120
+ return `${JSON.stringify(renderSnapcraftManifest(input), null, 2)}\n`;
121
+ }
122
+ /** The argument vector, as data, for the same reason the AppImage's is. */
123
+ export function snapcraftArgs(input) {
124
+ const args = ['pack', `--build-for=${input.archLabel}`, '--output', input.target];
125
+ if (input.destructive)
126
+ args.push('--destructive-mode');
127
+ return args;
128
+ }
129
+ /** Write the project directory snapcraft builds from. Wipes `workDir`. */
130
+ export function writeSnapProject(input) {
131
+ assertSnapIsPackable(input.payload, input.settings);
132
+ rmSync(input.workDir, { recursive: true, force: true, maxRetries: 5 });
133
+ mkdirSync(join(input.workDir, 'snap'), { recursive: true });
134
+ writePayload(join(input.workDir, PAYLOAD_DIR), input.payload.map((entry) => ({ ...entry, path: `${PREFIX_DIR}/${entry.path}` })), '');
135
+ writeFileSync(join(input.workDir, 'snap', 'snapcraft.yaml'), encodeUtf8(renderSnapcraftYaml(input)));
136
+ }
137
+ /** Build the snap and leave it at `input.target`. */
138
+ export async function buildSnap(input) {
139
+ writeSnapProject(input);
140
+ const destructive = process.env[SNAP_DESTRUCTIVE_ENV] === '1';
141
+ const stagedTarget = join(input.workDir, 'out.snap');
142
+ const args = snapcraftArgs({ target: stagedTarget, archLabel: input.archLabel, destructive });
143
+ if (input.verbose)
144
+ console.log(`[gjsify ship] ${SNAP_TOOL} ${args.join(' ')}`);
145
+ const result = await spawnToCompletion(SNAP_TOOL, args, {
146
+ completion: 'return',
147
+ cwd: input.workDir,
148
+ stdio: 'inherit',
149
+ notFound: () => new Error(`gjsify ship: ${SNAP_TOOL} not found. Install it with \`sudo snap install snapcraft --classic\`.`),
150
+ });
151
+ if (result.code !== 0) {
152
+ throw new Error(`gjsify ship: ${SNAP_TOOL} failed with ${describeExit(result)}.`);
153
+ }
154
+ // Built to a fixed name inside the work dir and moved, so a snapcraft that exits 0 without
155
+ // writing the file fails HERE, and a stale `.snap` from a previous run cannot be mistaken
156
+ // for this one (the work dir is wiped above).
157
+ if (!existsSync(stagedTarget)) {
158
+ throw new Error(`gjsify ship: ${SNAP_TOOL} exited 0 but wrote no snap at ${stagedTarget}.`);
159
+ }
160
+ renameSync(stagedTarget, input.target);
161
+ }
@@ -61,7 +61,7 @@ export interface ShipArtifact {
61
61
  * TEXTUALLY and fails if a comment gives it a second match, which is why this one
62
62
  * describes the union without quoting its head.
63
63
  */
64
- export type FormatId = 'deb' | 'rpm' | 'flatpak' | 'appimage' | 'linux-tar' | 'linux-tar-flatpak' | 'macos-app' | 'macos-app-zip' | 'macos-app-dmg' | 'windows-dir' | 'windows-dir-zip' | 'msi';
64
+ export type FormatId = 'deb' | 'rpm' | 'flatpak' | 'appimage' | 'snap' | 'linux-tar' | 'linux-tar-flatpak' | 'macos-app' | 'macos-app-zip' | 'macos-app-dmg' | 'windows-dir' | 'windows-dir-zip' | 'msi';
65
65
  /**
66
66
  * The formats whose ARTIFACT carries a distro dependency list.
67
67
  *
@@ -0,0 +1,13 @@
1
+ /** The one way in. A file in the tree would be one `git add` from a leaked store login. */
2
+ export declare const SNAP_CREDENTIALS_ENV = "SNAPCRAFT_STORE_CREDENTIALS";
3
+ export declare function snapRegisterArgs(name: string): string[];
4
+ export declare function snapStatusArgs(name: string): string[];
5
+ /** `--release` takes the channels comma-separated, as one value. */
6
+ export declare function snapUploadArgs(file: string, releases: readonly string[]): string[];
7
+ /** Split `--release a,b` (repeatable) into channels; refuses what the store would. */
8
+ export declare function parseChannels(values: readonly string[]): string[];
9
+ export declare function assertSnapNameForStore(command: string, name: string | undefined): string;
10
+ export declare function assertSnapCredentials(env: NodeJS.ProcessEnv): void;
11
+ export declare function assertSnapFile(file: string | undefined): string;
12
+ /** Run snapcraft with the terminal attached; a non-zero exit becomes the error. */
13
+ export declare function runSnapcraft(command: string, args: readonly string[]): Promise<void>;
@@ -0,0 +1,76 @@
1
+ // `gjsify snap register|upload|status` — thin wrappers over `snapcraft` (ADR 0149).
2
+ //
3
+ // Not a second Snap Store client: the argument vectors are pure functions, the refusals come
4
+ // before the process starts, and the credential never passes through this code. snapcraft reads
5
+ // `SNAPCRAFT_STORE_CREDENTIALS` from the inherited environment itself; we only check that it is
6
+ // set, and no message below ever contains its value.
7
+ import { existsSync, statSync } from 'node:fs';
8
+ import { SNAP_TOOL, isSnapName } from '../ship/snap.js';
9
+ import { describeExit, spawnToCompletion } from '../spawn.js';
10
+ /** The one way in. A file in the tree would be one `git add` from a leaked store login. */
11
+ export const SNAP_CREDENTIALS_ENV = 'SNAPCRAFT_STORE_CREDENTIALS';
12
+ /** `stable`, `latest/edge`, `stable/hotfix`: track/risk/branch, each part lowercase. */
13
+ const CHANNEL = /^[a-z0-9][a-z0-9._-]*(\/[a-z0-9][a-z0-9._-]*){0,2}$/;
14
+ export function snapRegisterArgs(name) {
15
+ return ['register', name];
16
+ }
17
+ export function snapStatusArgs(name) {
18
+ return ['status', name];
19
+ }
20
+ /** `--release` takes the channels comma-separated, as one value. */
21
+ export function snapUploadArgs(file, releases) {
22
+ const args = ['upload'];
23
+ if (releases.length > 0)
24
+ args.push(`--release=${releases.join(',')}`);
25
+ args.push(file);
26
+ return args;
27
+ }
28
+ /** Split `--release a,b` (repeatable) into channels; refuses what the store would. */
29
+ export function parseChannels(values) {
30
+ const channels = values
31
+ .flatMap((value) => value.split(','))
32
+ .map((c) => c.trim())
33
+ .filter((c) => c !== '');
34
+ for (const channel of channels) {
35
+ if (!CHANNEL.test(channel)) {
36
+ throw new Error(`gjsify snap upload: "${channel}" is not a channel (e.g. stable, latest/edge).`);
37
+ }
38
+ }
39
+ return channels;
40
+ }
41
+ export function assertSnapNameForStore(command, name) {
42
+ if (name === undefined || name === '') {
43
+ throw new Error(`gjsify snap ${command}: pass the snap name (the store name, e.g. hello-app).`);
44
+ }
45
+ if (!isSnapName(name)) {
46
+ throw new Error(`gjsify snap ${command}: "${name}" is not a snap name (lowercase letters, digits, single hyphens).`);
47
+ }
48
+ return name;
49
+ }
50
+ export function assertSnapCredentials(env) {
51
+ if (env[SNAP_CREDENTIALS_ENV] === undefined || env[SNAP_CREDENTIALS_ENV] === '') {
52
+ throw new Error(`gjsify snap upload: ${SNAP_CREDENTIALS_ENV} is not set. Create one with ` +
53
+ `\`${SNAP_TOOL} export-login --snaps=<name> --acls=package_access,package_push,package_release -\` ` +
54
+ 'and pass it through the environment (a CI secret); it is never read from a file.');
55
+ }
56
+ }
57
+ export function assertSnapFile(file) {
58
+ if (file === undefined || file === '')
59
+ throw new Error('gjsify snap upload: pass the .snap file.');
60
+ if (!file.endsWith('.snap'))
61
+ throw new Error(`gjsify snap upload: "${file}" is not a .snap file.`);
62
+ if (!existsSync(file) || !statSync(file).isFile())
63
+ throw new Error(`gjsify snap upload: no such file: ${file}.`);
64
+ return file;
65
+ }
66
+ /** Run snapcraft with the terminal attached; a non-zero exit becomes the error. */
67
+ export async function runSnapcraft(command, args) {
68
+ const result = await spawnToCompletion(SNAP_TOOL, args, {
69
+ completion: 'return',
70
+ stdio: 'inherit',
71
+ notFound: () => new Error(`gjsify snap ${command}: ${SNAP_TOOL} not found. Install it with \`sudo snap install snapcraft --classic\`.`),
72
+ });
73
+ if (result.code !== 0) {
74
+ throw new Error(`gjsify snap ${command}: ${SNAP_TOOL} failed with ${describeExit(result)}.`);
75
+ }
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/cli",
3
- "version": "0.64.51-next.351",
3
+ "version": "0.64.52",
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.51-next.351",
146
- "@gjsify/buffer": "0.64.51-next.351",
147
- "@gjsify/create-app": "0.64.51-next.351",
148
- "@gjsify/node-globals": "0.64.51-next.351",
149
- "@gjsify/node-polyfills": "0.64.51-next.351",
150
- "@gjsify/npm-registry": "0.64.51-next.351",
151
- "@gjsify/resolve-npm": "0.64.51-next.351",
152
- "@gjsify/rolldown-plugin-gjsify": "0.64.51-next.351",
153
- "@gjsify/vite-plugin-blueprint": "0.64.51-next.351",
154
- "@gjsify/rolldown-plugin-pnp": "0.64.51-next.351",
155
- "@gjsify/semver": "0.64.51-next.351",
156
- "@gjsify/tar": "0.64.51-next.351",
157
- "@gjsify/tsc": "0.64.51-next.351",
158
- "@gjsify/utils": "0.64.51-next.351",
159
- "@gjsify/web-polyfills": "0.64.51-next.351",
160
- "@gjsify/workspace": "0.64.51-next.351",
145
+ "@gjsify/blueprint": "0.64.52",
146
+ "@gjsify/buffer": "0.64.52",
147
+ "@gjsify/create-app": "0.64.52",
148
+ "@gjsify/node-globals": "0.64.52",
149
+ "@gjsify/node-polyfills": "0.64.52",
150
+ "@gjsify/npm-registry": "0.64.52",
151
+ "@gjsify/resolve-npm": "0.64.52",
152
+ "@gjsify/rolldown-plugin-gjsify": "0.64.52",
153
+ "@gjsify/vite-plugin-blueprint": "0.64.52",
154
+ "@gjsify/rolldown-plugin-pnp": "0.64.52",
155
+ "@gjsify/semver": "0.64.52",
156
+ "@gjsify/tar": "0.64.52",
157
+ "@gjsify/tsc": "0.64.52",
158
+ "@gjsify/utils": "0.64.52",
159
+ "@gjsify/web-polyfills": "0.64.52",
160
+ "@gjsify/workspace": "0.64.52",
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.51-next.351",
169
+ "@gjsify/unit": "0.64.52",
170
170
  "@types/yargs": "^17.0.35",
171
171
  "typescript": "^6.0.3"
172
172
  },
173
173
  "peerDependencies": {
174
- "@gjsify/oxfmt-native": "0.64.51-next.351",
175
- "@gjsify/rolldown-native": "0.64.51-next.351"
174
+ "@gjsify/oxfmt-native": "0.64.52",
175
+ "@gjsify/rolldown-native": "0.64.52"
176
176
  },
177
177
  "peerDependenciesMeta": {
178
178
  "@gjsify/oxfmt-native": {
@@ -191,6 +191,5 @@
191
191
  "bugs": {
192
192
  "url": "https://github.com/gjsify/gjsify/issues"
193
193
  },
194
- "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/cli#readme",
195
- "gitHead": "0dd479207aa90c2ce0e5b530bd1b7c38fab8706e"
194
+ "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/cli#readme"
196
195
  }