@preventive/upstream 1.7.0 → 1.8.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/cocoapods.d.ts +24 -13
- package/cocoapods.js +1 -1
- package/package.json +1 -1
- package/src/cocoapods.js +21 -11
- package/src/http.js +2 -1
package/cocoapods.d.ts
CHANGED
|
@@ -33,18 +33,29 @@ export { HttpError } from './npm.js'
|
|
|
33
33
|
// getPodArchive's.
|
|
34
34
|
export function getPodspec(name: string, version: string, checksum: string): Promise<Uint8Array>
|
|
35
35
|
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
36
|
+
// Whether `url` is an archive getPodArchive fetches, as a podspec's
|
|
37
|
+
// `source` names one by :http, from GitHub or Meta's namespace on Maven
|
|
38
|
+
// Central alone: https://github.com/<owner>/<repo>/ and a path under it,
|
|
39
|
+
// such as GitHub's archive of a tag, `archive/refs/tags/<tag>.tar.gz`, or a
|
|
40
|
+
// release's asset, `releases/download/<tag>/<file>`; or
|
|
41
|
+
// https://repo1.maven.org/maven2/com/facebook/ and a path under it ending
|
|
42
|
+
// in `.tar.gz` or `.zip`, such as React Native's
|
|
43
|
+
// `react/react-native-artifacts/<version>/<file>.tar.gz`. Either exactly as
|
|
44
|
+
// the URL parser writes it back out, `new URL(url).toString() === url`, so
|
|
45
|
+
// that no `..`, `%2e%2e` or case takes it out from under the prefix it is
|
|
46
|
+
// written with; with no query, fragment (an empty `?` or `#` among them),
|
|
47
|
+
// credentials or port; and each segment of the path letters, digits, `_`,
|
|
48
|
+
// `.`, `~`, `@`, `-` or a %-escape in capitals.
|
|
49
|
+
export function isPodArchiveUrl(url: unknown): boolean
|
|
50
|
+
|
|
51
|
+
// An archive a podspec's `source` names by :http, whole, in memory: `url`
|
|
52
|
+
// is one isPodArchiveUrl takes. The hash is the podspec's :sha256, in
|
|
53
|
+
// lowercase hex, as cocoapods-downloader checks it; a sha1, which two
|
|
54
|
+
// archives made to collide share, is not taken. GitHub answers with a
|
|
45
55
|
// redirect, to codeload.github.com or to where it keeps a release's files,
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
56
|
+
// and Maven Central with one to repo.reactnative.dev for React Native's
|
|
57
|
+
// archives, which is followed, as the bytes are held to the hash whoever
|
|
58
|
+
// answers, downloaded (before they are cached) or read from setCacheDir's
|
|
59
|
+
// cache. They are cached by the hash alone; one in the cache that does not
|
|
60
|
+
// match throws. Each argument is asserted before any request.
|
|
50
61
|
export function getPodArchive(url: string, sha256: string): Promise<Uint8Array>
|
package/cocoapods.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getPodArchive, getPodspec } from './src/cocoapods.js'
|
|
1
|
+
export { getPodArchive, getPodspec, isPodArchiveUrl } from './src/cocoapods.js'
|
|
2
2
|
export { HttpError } from './src/http.js'
|
package/package.json
CHANGED
package/src/cocoapods.js
CHANGED
|
@@ -5,7 +5,7 @@ import { join, resolve } from 'node:path'
|
|
|
5
5
|
|
|
6
6
|
import { assertPod, assertSha1, assertSha256, assertion, isRepo } from './args.js'
|
|
7
7
|
import { verifiedDownload } from './download.js'
|
|
8
|
-
import { COCOAPODS_CDN, GITHUB_WEB, buildUrl, encodeSegment } from './http.js'
|
|
8
|
+
import { COCOAPODS_CDN, GITHUB_WEB, MAVEN_CENTRAL, buildUrl, encodeSegment } from './http.js'
|
|
9
9
|
|
|
10
10
|
// No expiry, but kept by checksum as well: trunk refuses a version it
|
|
11
11
|
// already has, yet rewrites a podspec it has, as `pod trunk deprecate`
|
|
@@ -39,29 +39,39 @@ async function localPaths(name, version) {
|
|
|
39
39
|
// Where pod archives are kept: by their hash alone, which names them.
|
|
40
40
|
const ARCHIVES = 'cocoapods/archives'
|
|
41
41
|
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
// Meta's namespace on Maven Central, which React Native's archives are
|
|
43
|
+
// published under, and the two kinds of archive taken from it.
|
|
44
|
+
const MAVEN_FACEBOOK = `${MAVEN_CENTRAL}/maven2/com/facebook/`
|
|
45
|
+
const MAVEN_ARCHIVE = /\.(?:tar\.gz|zip)$/u
|
|
46
|
+
|
|
47
|
+
// As the URL parser writes it back out, so that what its text is checked
|
|
48
|
+
// for, a prefix above all, holds of what is fetched; and as buildUrl writes
|
|
49
|
+
// it, with no query, fragment, credentials or port, and nothing in a
|
|
50
|
+
// segment but what it lets through.
|
|
51
|
+
export function isPodArchiveUrl(value) {
|
|
46
52
|
const parsed = typeof value === 'string' ? URL.parse(value) : null
|
|
47
|
-
if (parsed
|
|
53
|
+
if (parsed === null || parsed.toString() !== value) return false
|
|
48
54
|
const segments = parsed.pathname.slice(1).split('/')
|
|
49
|
-
|
|
55
|
+
const github = parsed.origin === GITHUB_WEB && segments.length >= 3 && isRepo(`${segments[0]}/${segments[1]}`)
|
|
56
|
+
const maven = value.startsWith(MAVEN_FACEBOOK) && MAVEN_ARCHIVE.test(value)
|
|
57
|
+
if (!github && !maven) return false
|
|
50
58
|
try {
|
|
51
|
-
return buildUrl(
|
|
59
|
+
return buildUrl(parsed.origin, segments) === value
|
|
52
60
|
} catch {
|
|
53
61
|
return false
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
|
-
const
|
|
64
|
+
const assertPodArchiveUrl = assertion('an https URL of a GitHub repository\'s, with a path under it, or of a .tar.gz or a .zip under Maven Central\'s com/facebook/', isPodArchiveUrl)
|
|
57
65
|
|
|
58
66
|
// An archive a podspec's source names by :http, held to the sha256 the
|
|
59
67
|
// podspec gives of it: a sha1 alone, which two archives made to collide
|
|
60
68
|
// share, is not taken. GitHub's answer for a tag's archive or a release's
|
|
61
69
|
// asset is a redirect, to codeload.github.com or to where it keeps the
|
|
62
|
-
// files,
|
|
70
|
+
// files, and Maven Central's for React Native's is one to
|
|
71
|
+
// repo.reactnative.dev, which is followed: the bytes are held to the hash
|
|
72
|
+
// whoever answers.
|
|
63
73
|
export async function getPodArchive(url, sha256) {
|
|
64
|
-
|
|
74
|
+
assertPodArchiveUrl('getPodArchive', 'url', url)
|
|
65
75
|
assertSha256('getPodArchive', 'sha256', sha256)
|
|
66
76
|
return await verifiedDownload({
|
|
67
77
|
method: 'getPodArchive', dir: ARCHIVES, what: url, entry: `sha256-${sha256}`, ext: 'archive', algorithm: 'sha256', expected: sha256,
|
package/src/http.js
CHANGED
|
@@ -22,9 +22,10 @@ export const RUBYGEMS = 'https://rubygems.org'
|
|
|
22
22
|
export const RUBYGEMS_INDEX = 'https://index.rubygems.org'
|
|
23
23
|
export const PYPI = 'https://pypi.org'
|
|
24
24
|
export const GITHUB_WEB = 'https://github.com'
|
|
25
|
+
export const MAVEN_CENTRAL = 'https://repo1.maven.org'
|
|
25
26
|
export const MAX_BYTES = 512 * 1024 * 1024
|
|
26
27
|
|
|
27
|
-
const ORIGINS = new Set([NPM_REGISTRY, GITHUB_API, OSV_API, OSV_EXPORTS, CRATES_API, PACKAGIST_REPO, PACKAGIST, CRATES_INDEX, CRATES_STATIC, SOLDEER_API, SOLDEER_REVISIONS, COCOAPODS_CDN, RUBYGEMS, RUBYGEMS_INDEX, PYPI, GITHUB_WEB])
|
|
28
|
+
const ORIGINS = new Set([NPM_REGISTRY, GITHUB_API, OSV_API, OSV_EXPORTS, CRATES_API, PACKAGIST_REPO, PACKAGIST, CRATES_INDEX, CRATES_STATIC, SOLDEER_API, SOLDEER_REVISIONS, COCOAPODS_CDN, RUBYGEMS, RUBYGEMS_INDEX, PYPI, GITHUB_WEB, MAVEN_CENTRAL])
|
|
28
29
|
const isSegment = matches(/^(?!\.\.?$)(?:[\w.~@-]|%[\dA-F]{2})+$/u)
|
|
29
30
|
const isQueryKey = matches(/^[a-z_]+(?:\[\])?$/u)
|
|
30
31
|
const isQueryValue = (value) => (typeof value === 'string' && value !== '') || (Number.isSafeInteger(value) && value >= 0)
|