pandite 0.0.0-stage → 1.0.0

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.
@@ -0,0 +1,125 @@
1
+ // The release file of each system, the systems without one, and the
2
+ // per-user folder of the installer.
3
+
4
+ import path from 'node:path';
5
+ import process from 'node:process';
6
+ import { InstallerError } from './errors.js';
7
+
8
+ export const REPO = 'xls/pandite';
9
+ export const REPO_URL = `https://github.com/${REPO}`;
10
+ export const RELEASES_URL = `${REPO_URL}/releases`;
11
+ export const SUMS_FILE = 'SHA256SUMS.txt';
12
+ export const MIN_GLIBC = '2.35';
13
+ /** The AppId of the Windows setup program (packaging/windows/pandite.iss). */
14
+ export const WINDOWS_APP_ID = '{E5E712AA-D4BF-4DC9-BB19-9841DC38CD1E}';
15
+ export const WINDOWS_TARGETS = { x64: 'x86_64-pc-windows-msvc', arm64: 'aarch64-pc-windows-msvc' };
16
+ export const MAC_TARGET = 'universal-apple-darwin';
17
+ /** The app bundle at the top of the macOS zip and disk image. */
18
+ export const MAC_APP = 'pandite.app';
19
+ export const LINUX_TARGET = 'x86_64-unknown-linux-gnu';
20
+ export const SUPPORTED =
21
+ 'Windows x64 and ARM64, macOS 11 or later (Apple Silicon and Intel), and Linux x64 with glibc 2.35 or later';
22
+
23
+ /** Every system with a Pandite release file, as Node.js names it. */
24
+ export const PLATFORMS = [
25
+ { platform: 'win32', arch: 'x64' },
26
+ { platform: 'win32', arch: 'arm64' },
27
+ { platform: 'darwin', arch: 'x64' },
28
+ { platform: 'darwin', arch: 'arm64' },
29
+ { platform: 'linux', arch: 'x64' },
30
+ ];
31
+
32
+ const OS_NAMES = { win32: 'Windows', darwin: 'macOS', linux: 'Linux' };
33
+
34
+ export function systemName(platform, arch) {
35
+ return `${OS_NAMES[platform] ?? platform} ${arch}`;
36
+ }
37
+
38
+ function glibcBelow(have, want) {
39
+ const a = String(have).split('.').map((n) => Number.parseInt(n, 10) || 0);
40
+ const b = want.split('.').map(Number);
41
+ for (let i = 0; i < b.length; i += 1) {
42
+ const x = a[i] ?? 0;
43
+ if (x !== b[i]) return x < b[i];
44
+ }
45
+ return false;
46
+ }
47
+
48
+ function unsupported(what) {
49
+ return new InstallerError(
50
+ `${what} is not supported. Pandite releases exist for ${SUPPORTED}. ` +
51
+ `To build Pandite yourself, see ${REPO_URL}/blob/main/docs/building.md`,
52
+ );
53
+ }
54
+
55
+ /** The folder at the top of the Linux tarball. */
56
+ export function tarballTop(version) {
57
+ return `pandite-${version}-${LINUX_TARGET}`;
58
+ }
59
+
60
+ /**
61
+ * The release files for a system, best first: [{ name, kind }]. Kinds:
62
+ * "setup" (Windows setup program), "app-zip" and "dmg" (macOS app),
63
+ * "tarball" (Linux). Throws an InstallerError for an unsupported system.
64
+ */
65
+ export function candidateAssets({ platform, arch, glibc, version }) {
66
+ const system = systemName(platform, arch);
67
+ if (platform === 'win32') {
68
+ const target = WINDOWS_TARGETS[arch];
69
+ if (!target) throw unsupported(system);
70
+ return [{ name: `pandite-${version}-${target}-setup.exe`, kind: 'setup' }];
71
+ }
72
+ if (platform === 'darwin') {
73
+ if (arch !== 'x64' && arch !== 'arm64') throw unsupported(system);
74
+ const base = `pandite-${version}-${MAC_TARGET}`;
75
+ return [
76
+ { name: `${base}.zip`, kind: 'app-zip' },
77
+ { name: `${base}.dmg`, kind: 'dmg' },
78
+ ];
79
+ }
80
+ if (platform === 'linux' && arch === 'x64') {
81
+ if (!glibc) throw unsupported('Linux without glibc (for example with musl)');
82
+ if (glibcBelow(glibc, MIN_GLIBC)) throw unsupported(`Linux with glibc ${glibc}`);
83
+ return [{ name: `${tarballTop(version)}.tar.gz`, kind: 'tarball' }];
84
+ }
85
+ throw unsupported(system);
86
+ }
87
+
88
+ /** Throws an InstallerError when no release file exists for this system. */
89
+ export function checkSupported(system) {
90
+ candidateAssets({ ...system, version: '0.0.0' });
91
+ }
92
+
93
+ /**
94
+ * The release file to download: the first candidate that `available` (the
95
+ * file names of the release) holds.
96
+ */
97
+ export function chooseAsset({ platform, arch, glibc, version, available }) {
98
+ const candidates = candidateAssets({ platform, arch, glibc, version });
99
+ const found = candidates.find((c) => available.includes(c.name));
100
+ if (!found) {
101
+ const names = candidates.map((c) => c.name).join(' or ');
102
+ throw new InstallerError(`release v${version} has no ${names} for ${systemName(platform, arch)}`);
103
+ }
104
+ return found;
105
+ }
106
+
107
+ /** The glibc version of this Linux system, or null (musl, or not Linux). */
108
+ export function detectGlibc() {
109
+ try {
110
+ if (process.report && 'excludeNetwork' in process.report) process.report.excludeNetwork = true;
111
+ return process.report?.getReport?.()?.header?.glibcVersionRuntime ?? null;
112
+ } catch {
113
+ return null;
114
+ }
115
+ }
116
+
117
+ /** The per-user folder of the installer: the version marker and kept files. */
118
+ export function dataDir({ platform, env, home }) {
119
+ if (platform === 'win32') {
120
+ return path.join(env.LOCALAPPDATA || path.join(home, 'AppData', 'Local'), 'pandite-installer');
121
+ }
122
+ if (platform === 'darwin') return path.join(home, 'Library', 'Application Support', 'pandite-installer');
123
+ const xdg = env.XDG_DATA_HOME && path.isAbsolute(env.XDG_DATA_HOME) ? env.XDG_DATA_HOME : path.join(home, '.local', 'share');
124
+ return path.join(xdg, 'pandite-installer');
125
+ }
package/lib/version.js ADDED
@@ -0,0 +1,67 @@
1
+ // Semantic versions (https://semver.org): parse, normalize and compare.
2
+
3
+ import { usageError } from './errors.js';
4
+
5
+ const SEMVER =
6
+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
7
+
8
+ /** { major, minor, patch, pre: [identifiers] } of a version, or null. */
9
+ export function parseVersion(text) {
10
+ const m = SEMVER.exec(String(text));
11
+ if (!m) return null;
12
+ return { major: m[1], minor: m[2], patch: m[3], pre: m[4] ? m[4].split('.') : [] };
13
+ }
14
+
15
+ /**
16
+ * The version that the user typed after -v, without a leading "v".
17
+ * "0.1.0" and "v0.1.0" give "0.1.0"; "1.0" gives "1.0.0" and "1" gives
18
+ * "1.0.0". Throws a usage error for anything else.
19
+ */
20
+ export function normalizeVersion(input) {
21
+ let text = String(input ?? '').trim();
22
+ if (/^[vV]/.test(text)) text = text.slice(1);
23
+ const short = /^(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?$/.exec(text);
24
+ if (short) text = `${short[1]}.${short[2] ?? '0'}.0`;
25
+ if (!parseVersion(text)) throw usageError(`"${input}" is not a version such as 0.1.0 or v0.1.0`);
26
+ return text;
27
+ }
28
+
29
+ /** Compare two digit strings of any length as numbers. */
30
+ function compareDigits(a, b) {
31
+ if (a.length !== b.length) return a.length < b.length ? -1 : 1;
32
+ if (a === b) return 0;
33
+ return a < b ? -1 : 1;
34
+ }
35
+
36
+ function compareIdentifiers(a, b) {
37
+ const an = /^\d+$/.test(a);
38
+ const bn = /^\d+$/.test(b);
39
+ if (an && bn) return compareDigits(a, b);
40
+ // Numeric identifiers have lower precedence than alphanumeric ones.
41
+ if (an) return -1;
42
+ if (bn) return 1;
43
+ if (a === b) return 0;
44
+ return a < b ? -1 : 1;
45
+ }
46
+
47
+ /**
48
+ * -1 when a is older than b, 0 when they are equal, 1 when a is newer.
49
+ * 0.10.0 is newer than 0.9.0, and 1.0.0-rc.1 is older than 1.0.0. Build
50
+ * metadata (+...) does not count. Throws for an invalid version.
51
+ */
52
+ export function compareVersions(a, b) {
53
+ const x = parseVersion(a);
54
+ const y = parseVersion(b);
55
+ if (!x || !y) throw new Error(`cannot compare "${a}" with "${b}": not semantic versions`);
56
+ for (const key of ['major', 'minor', 'patch']) {
57
+ const order = compareDigits(x[key], y[key]);
58
+ if (order) return order;
59
+ }
60
+ if (!x.pre.length || !y.pre.length) return x.pre.length === y.pre.length ? 0 : x.pre.length ? -1 : 1;
61
+ for (let i = 0; i < Math.min(x.pre.length, y.pre.length); i += 1) {
62
+ const order = compareIdentifiers(x.pre[i], y.pre[i]);
63
+ if (order) return order;
64
+ }
65
+ if (x.pre.length === y.pre.length) return 0;
66
+ return x.pre.length < y.pre.length ? -1 : 1;
67
+ }
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "pandite",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Installer for Pandite, the fast offline image viewer: npx pandite installs or updates the latest GitHub release for your system",
5
+ "keywords": [
6
+ "pandite",
7
+ "image",
8
+ "viewer",
9
+ "installer",
10
+ "photo",
11
+ "raw"
12
+ ],
13
+ "homepage": "https://github.com/xls/pandite",
14
+ "bugs": "https://github.com/xls/pandite/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/xls/pandite.git",
18
+ "directory": "packaging/npm"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Thomas Rizos",
22
+ "type": "module",
23
+ "bin": {
24
+ "pandite": "bin/pandite.js",
25
+ "pandite-installer": "bin/pandite.js"
26
+ },
27
+ "files": [
28
+ "bin/",
29
+ "lib/"
30
+ ],
31
+ "engines": {
32
+ "node": ">=18"
33
+ }
34
+ }