@preventive/upstream 1.10.0 → 1.11.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.
package/electron.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ // The version is asserted to be an Electron one (`45.5.0`,
2
+ // `45.0.0-alpha.16`, `36.0.0-nightly.20250101`), the platform and arch
3
+ // ones Electron builds for, and the checksum 64 lowercase hex digits,
4
+ // before any request or cache path. The cache is setCacheDir's (npm.js).
5
+
6
+ import type { CacheOptions } from './npm.js'
7
+
8
+ export { HttpError } from './npm.js'
9
+
10
+ export type ElectronPlatform = 'darwin' | 'linux' | 'mas' | 'win32'
11
+ export type ElectronArch = 'arm64' | 'armv7l' | 'ia32' | 'x64'
12
+
13
+ // `electron-v<version>-<platform>-<arch>.zip`, whole, in memory, from the
14
+ // GitHub release `v<version>` of electron/electron (electron/nightlies
15
+ // for a version naming a nightly), through GitHub's redirect to its asset
16
+ // host. The release says nothing a lockfile holds of what the zip hashes
17
+ // to, so `checksum` is required: its sha256, as the `electron` package's
18
+ // checksums.json gives it. The bytes are checked against it, whether
19
+ // downloaded (before they are kept) or read from upstream's or stasis's
20
+ // default cache, setCacheDir's, or a `cache` store in its place, where one
21
+ // that does not match throws. A kept zip that matches is answered with no
22
+ // request at all.
23
+ //
24
+ // @electron/get's cache is read first, and never written: the zip under
25
+ // $electron_config_cache where install.js is told to keep it there, else
26
+ // under the platform's cache directory for electron (~/.cache/electron on
27
+ // Linux), in the directory named for the sha256 of the release's URL. A
28
+ // file there that does not match is passed over.
29
+ export function getElectronZip(version: string, platform: ElectronPlatform, arch: ElectronArch, checksum: string, options?: CacheOptions): Promise<Uint8Array>
package/electron.js ADDED
@@ -0,0 +1,2 @@
1
+ export { HttpError } from './src/http.js'
2
+ export { getElectronZip } from './src/electron.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@preventive/upstream",
3
- "version": "1.10.0",
4
- "description": "Minimal npm, crates.io, RubyGems, Soldeer, CocoaPods trunk, GitHub and git checkout clients",
3
+ "version": "1.11.0",
4
+ "description": "Minimal npm, crates.io, RubyGems, Soldeer, CocoaPods trunk, GitHub, Electron release and git checkout clients",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./advisories.js": {
@@ -16,6 +16,10 @@
16
16
  "types": "./cocoapods.d.ts",
17
17
  "default": "./cocoapods.js"
18
18
  },
19
+ "./electron.js": {
20
+ "types": "./electron.d.ts",
21
+ "default": "./electron.js"
22
+ },
19
23
  "./github.js": {
20
24
  "types": "./github.d.ts",
21
25
  "default": "./github.js"
@@ -62,6 +66,8 @@
62
66
  "cargo.js",
63
67
  "cocoapods.d.ts",
64
68
  "cocoapods.js",
69
+ "electron.d.ts",
70
+ "electron.js",
65
71
  "github.d.ts",
66
72
  "github.js",
67
73
  "git.d.ts",
@@ -97,6 +103,7 @@
97
103
  "src/cargo/repos.js",
98
104
  "src/cocoapods.js",
99
105
  "src/download.js",
106
+ "src/electron.js",
100
107
  "src/git.js",
101
108
  "src/github/client.js",
102
109
  "src/github/commit.js",
package/src/cache.js CHANGED
@@ -10,7 +10,7 @@ import { assertCacheName, assertDirectoryPath, assertion, isRepo } from './args.
10
10
  import { MAX_BYTES, decode } from './http.js'
11
11
  import { pool } from './pool.js'
12
12
 
13
- const DIRS = new Set(['npm/repos', 'npm/public', 'npm/tarballs', 'npm/versions', 'cargo/repos', 'cargo/crates', 'cargo/index', 'composer/repos', 'soldeer/repos', 'soldeer/zips', 'rubygems/repos', 'rubygems/gems', 'pypi/repos', 'cocoapods/podspecs', 'cocoapods/archives', 'cocoapods/repos', 'github/trees', 'github/advisories', 'github/public', 'osv/names', 'osv/github-aliases', 'rubysec/index', 'rubysec/advisories'])
13
+ const DIRS = new Set(['npm/repos', 'npm/public', 'npm/tarballs', 'npm/versions', 'cargo/repos', 'cargo/crates', 'cargo/index', 'composer/repos', 'soldeer/repos', 'soldeer/zips', 'electron/zips', 'rubygems/repos', 'rubygems/gems', 'pypi/repos', 'cocoapods/podspecs', 'cocoapods/archives', 'cocoapods/repos', 'github/trees', 'github/advisories', 'github/public', 'osv/names', 'osv/github-aliases', 'rubysec/index', 'rubysec/advisories'])
14
14
  const RECORD_TTL_MS = 30 * 24 * 60 * 60 * 1000 // A link only moves on a transfer or rename, and GitHub redirects those.
15
15
  const RECORDS_AT_ONCE = 8
16
16
  // JSON filed gzipped, as `<name>.json.gz`: a listing carries each
@@ -0,0 +1,42 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { join, posix } from 'node:path'
3
+
4
+ import { assertArgs, assertSha256, assertion, matches, optional } from './args.js'
5
+ import { absolute, assertCache, cacheDirFor } from './cache.js'
6
+ import { verifiedDownload } from './download.js'
7
+ import { GITHUB_WEB, buildUrl } from './http.js'
8
+
9
+ const DIR = 'electron/zips' // No expiry: a zip is held to its checksum.
10
+
11
+ // As @electron/get names the builds Electron publishes.
12
+ const PLATFORMS = new Set(['darwin', 'linux', 'mas', 'win32'])
13
+ const ARCHES = new Set(['arm64', 'armv7l', 'ia32', 'x64'])
14
+ // No build metadata: the version is a URL segment and a file name.
15
+ const assertElectronVersion = assertion('an Electron version', matches(/^(?=.{1,128}$)\d+\.\d+\.\d+(?:-[\dA-Za-z][\dA-Za-z.-]*)?$/u))
16
+ const assertOneOf = (set, must) => assertion(must, (value) => set.has(value))
17
+ const assertPlatform = assertOneOf(PLATFORMS, `one of ${[...PLATFORMS].join(', ')}`)
18
+ const assertArch = assertOneOf(ARCHES, `one of ${[...ARCHES].join(', ')}`)
19
+
20
+ // Where @electron/get keeps `url`: <root>/<sha256 of its directory's URL>/<file>,
21
+ // the root install.js's electron_config_cache, else the platform's cache for electron.
22
+ function electronGetPaths(url) {
23
+ const parsed = new URL(url)
24
+ parsed.pathname = posix.dirname(parsed.pathname)
25
+ const dir = createHash('sha256').update(parsed.toString()).digest('hex')
26
+ return [absolute(process.env.electron_config_cache), cacheDirFor('electron')].filter(Boolean).map((root) => join(root, dir, posix.basename(url)))
27
+ }
28
+
29
+ // As @electron/get downloads it for install.js. The redirect to GitHub's asset
30
+ // host is followed: the bytes are held to `checksum` wherever they come from.
31
+ export async function getElectronZip(version, platform, arch, checksum, options = {}) {
32
+ const method = 'getElectronZip'
33
+ assertElectronVersion(method, 'version', version)
34
+ assertPlatform(method, 'platform', platform)
35
+ assertArch(method, 'arch', arch)
36
+ assertSha256(method, 'checksum', checksum)
37
+ assertArgs(method, options, { cache: optional(assertCache) })
38
+ const name = `electron-v${version}-${platform}-${arch}`
39
+ const repo = version.includes('nightly') ? 'nightlies' : 'electron'
40
+ const url = buildUrl(GITHUB_WEB, ['electron', repo, 'releases', 'download', `v${version}`, `${name}.zip`])
41
+ return await verifiedDownload({ method, dir: DIR, what: `${name}.zip`, entry: name, ext: 'zip', algorithm: 'sha256', expected: checksum, local: electronGetPaths(url), ours: true, cache: options.cache, locate: () => url, options: { redirect: 'follow' } })
42
+ }