@preventive/upstream 1.0.0-alpha.6 → 1.0.0-alpha.7
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/npm.d.ts +2 -1
- package/package.d.ts +1 -1
- package/package.json +1 -1
- package/src/npm/repos.js +8 -4
- package/src/package.js +3 -1
package/npm.d.ts
CHANGED
|
@@ -50,7 +50,8 @@ export interface PackageRepo {
|
|
|
50
50
|
export function resolvePackageRepos(packageNames: Iterable<string>, options?: { cachedOnly?: boolean }): Promise<Map<string, PackageRepo>>
|
|
51
51
|
|
|
52
52
|
// The disk cache resolvePackageRepos reads and writes, a month per entry.
|
|
53
|
-
// A read answers null for anything but a usable entry
|
|
53
|
+
// A read answers null for anything but a usable entry, one written by a
|
|
54
|
+
// release that resolved repos by other rules included; a write answers
|
|
54
55
|
// false where it could not write, and never throws.
|
|
55
56
|
export function readPackageRepoCache(name: string): Promise<PackageRepo | null>
|
|
56
57
|
export function writePackageRepoCache(name: string, github: string, directory?: string): Promise<boolean>
|
package/package.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface PackageRepoLink {
|
|
|
11
11
|
url?: string
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// Read off `
|
|
14
|
+
// Read off `repository`, `bugs` and `homepage`, in that order, from a
|
|
15
15
|
// package.json or the registry's document for a version of one. Both
|
|
16
16
|
// fields absent where nothing in it names a GitHub repo; a throw only
|
|
17
17
|
// for something that is not an object at all.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/upstream",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.7",
|
|
4
4
|
"description": "Minimal npm, crates.io and Soldeer registry clients, a GitHub client, and a git checkout reader: the calls we use, nothing more",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
package/src/npm/repos.js
CHANGED
|
@@ -9,6 +9,9 @@ import { getDocument } from './registry.js'
|
|
|
9
9
|
|
|
10
10
|
const DIR = 'npm/repos'
|
|
11
11
|
const CONCURRENCY = 8
|
|
12
|
+
// Stamped on each entry, and raised when getRepo would answer differently:
|
|
13
|
+
// 2 is `repository` taking precedence over `bugs`.
|
|
14
|
+
const VERSION = 2
|
|
12
15
|
|
|
13
16
|
// `latest`, not the full packument, which is megabytes of version history.
|
|
14
17
|
const fetchRepo = async (method, name) => getRepo(await getDocument(method, name, 'latest'))
|
|
@@ -20,12 +23,13 @@ export async function getGitHub(name) {
|
|
|
20
23
|
return link
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
// An entry
|
|
24
|
-
//
|
|
26
|
+
// An entry under another VERSION was resolved by other rules, and may
|
|
27
|
+
// name the repo a stale tracker does: a miss, as is one without
|
|
28
|
+
// `directory`, which would read as a package at the repo root.
|
|
25
29
|
export async function readPackageRepoCache(name) {
|
|
26
30
|
assertPackageName('readPackageRepoCache', 'name', name)
|
|
27
31
|
const entry = await readRecord(DIR, name)
|
|
28
|
-
if (!isRepo(entry
|
|
32
|
+
if (entry?.v !== VERSION || !isRepo(entry.github) || !isRepoDirectory(entry.directory)) return null
|
|
29
33
|
return { github: entry.github, ...(entry.directory && { directory: entry.directory }) }
|
|
30
34
|
}
|
|
31
35
|
|
|
@@ -35,7 +39,7 @@ export async function writePackageRepoCache(name, github, directory = '') {
|
|
|
35
39
|
assertPackageName('writePackageRepoCache', 'name', name)
|
|
36
40
|
assertRepo('writePackageRepoCache', 'github', github)
|
|
37
41
|
assertRepoDirectory('writePackageRepoCache', 'directory', directory)
|
|
38
|
-
return await writeRecord(DIR, name, { github, directory })
|
|
42
|
+
return await writeRecord(DIR, name, { v: VERSION, github, directory })
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
export async function resolvePackageRepos(packageNames, options = {}) {
|
package/src/package.js
CHANGED
|
@@ -41,7 +41,9 @@ export function getRepo(pkg) {
|
|
|
41
41
|
const { bugs, repository } = pkg
|
|
42
42
|
const declared = repositoryRepo(urlOf(repository))
|
|
43
43
|
const homepage = homepageRegex.exec(homepageUrl(pkg.homepage))?.groups
|
|
44
|
-
|
|
44
|
+
// `repository` first: it is the field a publisher maintains, where a
|
|
45
|
+
// `bugs` tracker can be left pointing at a former owner or misspelt.
|
|
46
|
+
const github = [declared, repoIn(bugsRegex, urlOf(bugs)), homepage?.repo].find(isRepo)
|
|
45
47
|
if (github === undefined) return {}
|
|
46
48
|
const directory = (sameName(declared, github) && repoSubdirectory(repository?.directory))
|
|
47
49
|
|| (sameName(homepage?.repo, github) && repoSubdirectory(decodePath(homepage.directory)))
|