@preventive/triage 1.0.0-alpha.66 → 1.0.0-alpha.68
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/common/bundle-imports.js +20 -0
- package/common/bundle-metadata.js +1 -1
- package/common/bundle-reasons.d.ts +4 -0
- package/common/bundle-reasons.js +38 -1
- package/common/bundle-sources.d.ts +1 -0
- package/common/bundle-sources.js +22 -0
- package/common/managed/npm-packages.js +3 -3
- package/common/managed/routes.js +37 -18
- package/common/managed/stasis-config.ts +7 -0
- package/out/activity.js +4 -4
- package/out/{chunk-J2FWBXFV.js → chunk-2F3CYNPZ.js} +1 -1
- package/out/chunk-2HGKTQ5Q.js +52 -0
- package/out/chunk-4RS3NDOG.js +1 -0
- package/out/chunk-CGRIZ5M5.js +1 -0
- package/out/{chunk-Z6VEV2QL.js → chunk-D37M7J4B.js} +1 -1
- package/out/chunk-GZ46SSTF.js +1 -0
- package/out/{chunk-IZ6MYRYB.js → chunk-HETCVNO4.js} +1 -1
- package/out/chunk-MPXVKVPF.js +3 -0
- package/out/{chunk-24AKGEH3.js → chunk-NB4JBTKK.js} +1 -1
- package/out/{chunk-OVGR4D3M.js → chunk-OAWY4T6R.js} +1 -1
- package/out/chunk-QPGM3DTI.js +42 -0
- package/out/chunk-SCN2TBP2.js +247 -0
- package/out/chunk-VG5RH6KN.js +2 -0
- package/out/chunk-WFDXHPT2.js +12 -0
- package/out/client-managed-import.js +2 -2
- package/out/client-managed.js +19 -19
- package/out/compare.js +12 -12
- package/out/dialogs.js +38 -38
- package/out/graph.js +8 -8
- package/out/index.html +9 -9
- package/out/scan.js +2 -2
- package/out/view.css +1 -1
- package/out/view.js +15 -15
- package/package.json +11 -8
- package/server-managed/activity.ts +21 -12
- package/server-managed/bundle-build-diagnostics.d.ts +1 -1
- package/server-managed/bundle-build-worker.js +140 -19
- package/server-managed/bundle-build.ts +102 -21
- package/server-managed/bundle-cache.ts +28 -6
- package/server-managed/bundle-dependency-reviews.ts +38 -22
- package/server-managed/commit-lockfiles.ts +2 -1
- package/server-managed/db-neon.ts +5 -2
- package/server-managed/dependency-review-comments.ts +38 -16
- package/server-managed/dependency-reviews.ts +17 -14
- package/server-managed/http.ts +178 -70
- package/server-managed/locked-packages.ts +34 -14
- package/server-managed/lockfile-scope.ts +10 -1
- package/server-managed/npm-kept.ts +10 -0
- package/server-managed/npm-patch.ts +188 -53
- package/server-managed/public-workspace.ts +3 -2
- package/server-managed/pull-dependencies.ts +58 -37
- package/server-managed/pull-dependency-reviews.ts +35 -22
- package/server-managed/report-sources.ts +6 -3
- package/server-managed/repository-dependency-reviews.ts +4 -2
- package/server-managed/repository-issues.ts +14 -11
- package/server-managed/stasis-dependencies.ts +170 -0
- package/out/chunk-65PLAG3I.js +0 -12
- package/out/chunk-DCBXCBLL.js +0 -52
- package/out/chunk-F3UI65ZI.js +0 -42
- package/out/chunk-FAG6E5RC.js +0 -3
- package/out/chunk-OBZWBTZL.js +0 -247
- package/out/chunk-PTFQKLKO.js +0 -1
- package/out/chunk-QVKFY4FA.js +0 -1
- package/out/chunk-SYXT3SFP.js +0 -2
- package/out/chunk-WL3SPQB4.js +0 -1
- /package/out/{chunk-WCPJDAYA.js → chunk-D6NVKGGG.js} +0 -0
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
// tarball (locked-packages.ts), with an integrity. One from git, another
|
|
17
17
|
// tarball (a mirror's too), or with no integrity can't be; a file of the
|
|
18
18
|
// project's isn't. Its reviews are those of it, of an integrity it is locked
|
|
19
|
-
// with, either whole,
|
|
20
|
-
//
|
|
19
|
+
// with, either whole, compared with any version of another package, or
|
|
20
|
+
// compared with a version of its own: for a version the pull request adds,
|
|
21
|
+
// one it was; for another, any. A patched
|
|
21
22
|
// one's (`patch`) are of it as patched, by its patch's hash, its patch read
|
|
22
|
-
// of the repository
|
|
23
|
-
//
|
|
24
|
-
// the
|
|
23
|
+
// of the repository at its file, which its lockfile names, or which is found
|
|
24
|
+
// where it names it by its hash alone (npm-patch.ts withPatchFiles):
|
|
25
|
+
// compared with the version it patches, where that is one it was, they
|
|
26
|
+
// review the patch alone. Locked so at that commit, its patch too, it needs
|
|
27
|
+
// none.
|
|
25
28
|
// Which versions the repository's lockfiles locked at that commit never
|
|
26
29
|
// changes: it is read once, every lockfile there of those read here
|
|
27
30
|
// (pull-dependencies.ts), and kept by the commit (`baselines` in this
|
|
@@ -49,18 +52,20 @@ export interface ReviewBaselineStore {
|
|
|
49
52
|
const baselines: Lru<Baseline> = lru(500_000, baseline => baseline.versions.size + baseline.unread.length + 1)
|
|
50
53
|
|
|
51
54
|
// Why a version can't be reviewed: from git, of a tarball not npm's
|
|
52
|
-
// registry's of its version,
|
|
53
|
-
|
|
55
|
+
// registry's of its version, locked with no integrity, or, a Stasis build's
|
|
56
|
+
// (stasis-dependencies.ts), locked by no lockfile read (`unlocked`).
|
|
57
|
+
export type Unsupported = 'git' | 'tarball' | 'integrity' | 'unlocked'
|
|
54
58
|
// How a version is reviewed: by its name, version and integrity
|
|
55
59
|
// (`version`), not at all (`skip`), or why it can't be.
|
|
56
60
|
function reviewedAs(pkg: LockedPackage): 'version' | 'skip' | Unsupported {
|
|
61
|
+
if (pkg.unlocked) return 'unlocked'
|
|
57
62
|
if (pkg.source === 'file') return 'skip'
|
|
58
63
|
if (pkg.source === 'git') return 'git'
|
|
59
64
|
if (pkg.source !== 'registry' || pkg.version === null) return 'tarball'
|
|
60
65
|
return pkg.integrity ? 'version' : 'integrity'
|
|
61
66
|
}
|
|
62
67
|
// The hashes an integrity names, each of which is npm's of it.
|
|
63
|
-
const hashesOf = (pkg: LockedPackage) => (pkg.integrity ?? '').split(/\s+/u).filter(Boolean)
|
|
68
|
+
export const hashesOf = (pkg: LockedPackage) => (pkg.integrity ?? '').split(/\s+/u).filter(Boolean)
|
|
64
69
|
// A version as a baseline holds it: its name and version with each hash,
|
|
65
70
|
// and its patch.
|
|
66
71
|
const baselineKeys = (pkg: LockedPackage) => hashesOf(pkg).map(hash => `${pkg.name}@${pkg.version ?? ''}\0${hash}\0${pkg.patchHash ?? ''}`)
|
|
@@ -95,18 +100,19 @@ export function reviewsOf(pkg: LockedPackage, reviews: ReviewsOf): PublishedRevi
|
|
|
95
100
|
const hashes = hashesOf(pkg)
|
|
96
101
|
return (reviews.get(`${pkg.name}@${pkg.version}`) ?? []).filter(review => hashes.includes(review.integrity) && (review.patchHash ?? '') === (pkg.patchHash ?? ''))
|
|
97
102
|
}
|
|
98
|
-
// Whether `review` is of `pkg` whole,
|
|
99
|
-
// package (any,
|
|
103
|
+
// Whether `review` is of `pkg` whole, compared with a version of another
|
|
104
|
+
// package (any), or compared with one of `bases` of its own package (any,
|
|
105
|
+
// for `any`).
|
|
100
106
|
export const comparedWith = (review: PublishedReview, pkg: LockedPackage, bases: string[] | 'any') => review.basePackage === null
|
|
101
|
-
||
|
|
107
|
+
|| review.basePackage !== pkg.name || bases === 'any' || bases.includes(review.baseVersion ?? '')
|
|
102
108
|
|
|
103
109
|
const ACCEPTING = new Set(['accept', 'accept-with-nits'])
|
|
104
110
|
// Where `pkg`'s reviewers stand on it among `reviews`, those of its version,
|
|
105
111
|
// of an integrity it is locked with, and of its patch: each one's latest
|
|
106
112
|
// telling it, any rejecting it holding it unreviewed (`rejected`); those
|
|
107
113
|
// accepting it passing it (`passing`), each once, by a full, accepting
|
|
108
|
-
// review of theirs, whole
|
|
109
|
-
// (any, for `any`); and how many review it in its pull request's comments
|
|
114
|
+
// review of theirs, whole, compared with another package's version, or
|
|
115
|
+
// compared with one of `bases` of its own (any, for `any`); and how many review it in its pull request's comments
|
|
110
116
|
// alone (`commented`), which count for it alone: whose reviews passing it,
|
|
111
117
|
// else whose latest, are its comments'. Each reviewer too (`reviewers`), by
|
|
112
118
|
// their login, their latest verdict, whether they pass it, and whether that
|
|
@@ -133,18 +139,18 @@ type Reviewer = { login: string; status: PublishedReview['status']; passes?: tru
|
|
|
133
139
|
|
|
134
140
|
// A version as the client is told it: what its reviews are held to left
|
|
135
141
|
// out, but its patch, where it is patched (`patch`): its hash, which its
|
|
136
|
-
// reviews are held to, and its file, where its lockfile names one
|
|
137
|
-
// repository's root, whence its reviews read it.
|
|
142
|
+
// reviews are held to, and its file, where its lockfile names one or it
|
|
143
|
+
// was found, from the repository's root, whence its reviews read it.
|
|
138
144
|
type Patch = { hash: string; path?: string }
|
|
139
|
-
function shown<T extends LockedPackage>(pkg: T): Omit<T, 'integrity' | 'shasum' | 'patchHash' | 'patchPath' | 'lockfile'> & { patch?: Patch } {
|
|
145
|
+
function shown<T extends LockedPackage>(pkg: T): Omit<T, 'integrity' | 'shasum' | 'patchHash' | 'patchPath' | 'patchDir' | 'lockfile' | 'unlocked'> & { patch?: Patch } {
|
|
140
146
|
const copy = { ...pkg }
|
|
141
|
-
for (const field of ['integrity', 'shasum', 'patchHash', 'patchPath', 'lockfile'] as const) delete copy[field]
|
|
147
|
+
for (const field of ['integrity', 'shasum', 'patchHash', 'patchPath', 'patchDir', 'lockfile', 'unlocked'] as const) delete copy[field]
|
|
142
148
|
return { ...copy, ...pkg.patchHash ? { patch: { hash: pkg.patchHash, ...pkg.patchPath ? { path: pkg.patchPath } : {} } } : {} }
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
// A version as the registered reviewed dependencies are asked of it, by
|
|
146
152
|
// what it is asked.
|
|
147
|
-
function askedOf(pkg: LockedPackage): [string, ReviewedDependency] {
|
|
153
|
+
export function askedOf(pkg: LockedPackage): [string, ReviewedDependency] {
|
|
148
154
|
const dependency: ReviewedDependency = { ecosystem: 'npm', lockfile: pkg.lockfile ?? 'npm', name: pkg.name, version: pkg.version ?? '', integrity: pkg.integrity ?? '',
|
|
149
155
|
...pkg.shasum ? { shasum: pkg.shasum } : {}, ...pkg.patchHash ? { patchHash: pkg.patchHash } : {} }
|
|
150
156
|
return [JSON.stringify(dependency), dependency]
|
|
@@ -230,7 +236,8 @@ export function heldDependencies<T extends PullDependencies>(told: T, scope: Loc
|
|
|
230
236
|
// wanting one of the reviews its comments make (`commentReviews`, where the
|
|
231
237
|
// host reads them), and the review's terms (`review`), with how many
|
|
232
238
|
// reviewers' its comments count (`commentReviews`), or that they couldn't be
|
|
233
|
-
// read (`commentsFailed`), and
|
|
239
|
+
// read (`commentsFailed`), and that reviews count by comments alone, those
|
|
240
|
+
// published here not (`byComments`, where the host reads them), and how many versions across its directories want
|
|
234
241
|
// reviews, of those it adds (`toReview`) and the rest (`unreviewed`), and
|
|
235
242
|
// can't be reviewed (`unsupported`), each once; how many the reviewed dependencies failed to
|
|
236
243
|
// answer (`unasked`), and whether they are registered (`reviewedDependencies`,
|
|
@@ -249,7 +256,13 @@ export async function reviewedDependencies(told: PullDependencies, state: RepoRe
|
|
|
249
256
|
const answered = heldDependencies(told, scope)
|
|
250
257
|
if (!state) return { ...answered, lockfiles: answered.lockfiles.map(dir => reviewedDirectory(dir, null)) }
|
|
251
258
|
const { cut, lockfiles: held } = answered
|
|
252
|
-
|
|
259
|
+
// Reviews published here count but where the host reads those pull
|
|
260
|
+
// requests' comments make (`parseComments`): what is reviewed is then the
|
|
261
|
+
// host's to tell, by those and its `lookup`, and one published here counts
|
|
262
|
+
// for nothing, whatever it was compared with: of a pull request's versions,
|
|
263
|
+
// a default branch's or a bundle's. Its author still copies it as a comment.
|
|
264
|
+
const published = reviewed?.parseComments ? [] : state.reviews
|
|
265
|
+
let context = { state, reviews: reviewsByVersion(published), baseline: reviewed ? null : baseline }
|
|
253
266
|
// What wants a review, as `lookup` is asked of, each once.
|
|
254
267
|
const wanting = () => {
|
|
255
268
|
const asked = new Map<string, ReviewedDependency>()
|
|
@@ -288,7 +301,7 @@ export async function reviewedDependencies(told: PullDependencies, state: RepoRe
|
|
|
288
301
|
}
|
|
289
302
|
const comments = parsing.size > 0 && commentReviews ? await commentReviews([...parsing.values()]) : { reviews: [], failed: false }
|
|
290
303
|
if (comments.reviews.length > 0) {
|
|
291
|
-
context = { ...context, reviews: reviewsByVersion([...
|
|
304
|
+
context = { ...context, reviews: reviewsByVersion([...published, ...comments.reviews.map(review => ({ ...review, comment: true as const }))]) }
|
|
292
305
|
await ask(new Map([...wanting()].filter(([key]) => !asked.has(key))))
|
|
293
306
|
}
|
|
294
307
|
const dirs = held.map(dir => reviewedDirectory(dir, (pkg, bases) => {
|
|
@@ -298,7 +311,7 @@ export async function reviewedDependencies(told: PullDependencies, state: RepoRe
|
|
|
298
311
|
const unread = baselineUnread.filter(path => heldTo(scope, path))
|
|
299
312
|
const listed = dirs.filter(dir => 'unreviewed' in dir)
|
|
300
313
|
return { ...answered, cut, lockfiles: dirs.map(dir => 'unreviewed' in dir ? capped(dir) : dir), review: { required: state.required,
|
|
301
|
-
since: reviewed ? null : state.since, canReview: state.canReview, ...reviewed ? { reviewedDependencies: true } : {},
|
|
314
|
+
since: reviewed ? null : state.since, canReview: state.canReview, ...reviewed ? { reviewedDependencies: true } : {}, ...reviewed?.parseComments ? { byComments: true } : {},
|
|
302
315
|
toReview: distinct(listed.map(dir => dir.toReview), versionKey), unreviewed: distinct(listed.map(dir => dir.unreviewed), versionKey),
|
|
303
316
|
unsupported: distinct(listed.map(dir => dir.unsupported), sourceKey),
|
|
304
317
|
...unasked > 0 ? { unasked } : {}, ...baselineError && !reviewed ? { baselineError } : {},
|
|
@@ -3,7 +3,7 @@ import { createHash } from 'node:crypto'
|
|
|
3
3
|
import { extname } from 'node:path'
|
|
4
4
|
import { promisify } from 'node:util'
|
|
5
5
|
import { gzip } from 'node:zlib'
|
|
6
|
-
import { bundlePackageDirs, bundleSourcesAsMap } from '../common/bundle-sources.js'
|
|
6
|
+
import { bundlePackageDirs, bundlePackageRepos, bundleSourcesAsMap } from '../common/bundle-sources.js'
|
|
7
7
|
import { bundleSourceLinkImports } from '../common/bundle-source-links.js'
|
|
8
8
|
import type { BundleDetails } from '../common/bundle-metadata.js'
|
|
9
9
|
import { loadManagedFindings, managedFindingSourcePaths } from '../common/managed/report-content.ts'
|
|
@@ -31,7 +31,7 @@ function formatDirectory(bundleId: string, sha256: string, name: string) {
|
|
|
31
31
|
}
|
|
32
32
|
function sourceCacheFilename(report: ReportRecord, bundle: ManagedBundle, permissions: ViewerPermissions, repo: { github: string | null }, sourcePaths?: Set<string>) {
|
|
33
33
|
const key = createHash('sha256').update(JSON.stringify([
|
|
34
|
-
'finding-access-
|
|
34
|
+
'finding-access-v11', sourcePaths ? [...sourcePaths].toSorted() : null, bundle.integrity, bundle.kind, permissions.dependencies, permissions.security, repo,
|
|
35
35
|
])).digest('hex')
|
|
36
36
|
return `${formatDirectory(bundle.id, report.sha256, report.filename)}/${key}.json.gz`
|
|
37
37
|
}
|
|
@@ -69,7 +69,10 @@ function encodeSources(integrity: string, details: BundleDetails, selection: Ret
|
|
|
69
69
|
const bundle = details.kind === 'stasis' ? details.bundle as { formats: Map<string, string> } : null
|
|
70
70
|
const formats = [...(bundle?.formats ?? [])].filter(([file]) => sources.has(file))
|
|
71
71
|
const packageDirs = [...(bundlePackageDirs(details) ?? [])].filter(([file]) => sources.has(file))
|
|
72
|
-
|
|
72
|
+
// The repository and commit each of those files' packages records, which
|
|
73
|
+
// the finding's dependency evidence links to (focus-code.js).
|
|
74
|
+
const packageRepos = [...bundlePackageRepos(details, new Set(packageDirs.map(([, dir]) => dir)))]
|
|
75
|
+
return compress(Buffer.from(JSON.stringify({ integrity, ...selection, imports, formats, packageDirs, packageRepos })), { level: 6 })
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
type SourcemapEdges = (bundle: ManagedBundle) => Promise<BundleDetails['edges']>
|
|
@@ -26,7 +26,9 @@ export interface RepoDependencyReview { enabled: boolean; required: number; sinc
|
|
|
26
26
|
// lockfile names it), the version it was compared with (none for a whole package's),
|
|
27
27
|
// who wrote it (`reviewer`, their id, else their login then), their login
|
|
28
28
|
// as it was then (`login`), its verdict, whether it checked every file
|
|
29
|
-
// (`full`), and when it was published.
|
|
29
|
+
// (`full`), and when it was published. One compared with a version as a patch
|
|
30
|
+
// changes it counts for none: what a pull request replaced isn't told by its
|
|
31
|
+
// patch.
|
|
30
32
|
// One made in a pull request's comments (`comment`) counts for it alone;
|
|
31
33
|
// one published here has its `id`.
|
|
32
34
|
export interface PublishedReview {
|
|
@@ -83,7 +85,7 @@ async function publishedReviews(db: ManagedSql, repoId: number, versions: Review
|
|
|
83
85
|
const rows = (await db.prepare(`SELECT r.id, r.user_id AS userId, r.user_login AS userLogin, r.package, r.version, r.integrity, r.patch_hash AS patchHash,
|
|
84
86
|
NULLIF(r.base_package, '') AS basePackage, NULLIF(r.base_version, '') AS baseVersion, r.files, r.status, r.published_at AS publishedAt
|
|
85
87
|
FROM managed_dependency_review r
|
|
86
|
-
WHERE r.ecosystem = 'npm' AND r.published_at IS NOT NULL AND r.revoked_at IS NULL AND r.status IS NOT NULL
|
|
88
|
+
WHERE r.ecosystem = 'npm' AND r.published_at IS NOT NULL AND r.revoked_at IS NULL AND r.status IS NOT NULL AND r.base_patch_hash = ''
|
|
87
89
|
AND r.package IN (${names.map(() => '?').join(',')}) AND r.version IN (${numbers.map(() => '?').join(',')})
|
|
88
90
|
AND EXISTS (SELECT 1 FROM managed_dependency_review_team rt JOIN managed_team t ON t.id = rt.team_id
|
|
89
91
|
WHERE rt.review_id = r.id AND ${COUNTING_TEAM})`).all(...names, ...numbers, repoId) as
|
|
@@ -17,7 +17,7 @@ import { ACTOR, type GraphAccount, actorOf } from './github-accounts.ts'
|
|
|
17
17
|
import { GithubApiError } from './github-errors.ts'
|
|
18
18
|
import { type GraphqlError, githubGraphql } from './github-graphql.ts'
|
|
19
19
|
import { SHA, count, nameOf, timeOf } from './github-values.ts'
|
|
20
|
-
import { touchesLockfile } from './pull-dependencies.ts'
|
|
20
|
+
import { pullRefs, touchesLockfile } from './pull-dependencies.ts'
|
|
21
21
|
import { ITEM_THREADS, type ReviewNode, TILE_THREADS, pullReviews, reviewFields, reviewsRefused } from './pull-reviews.ts'
|
|
22
22
|
import type { Connection } from './repository-history.ts'
|
|
23
23
|
|
|
@@ -57,14 +57,14 @@ const pageQuery = (kind: IssuesKind, state: IssuesState) => `query($owner: Strin
|
|
|
57
57
|
closed: ${connection[kind]}(states: ${states[kind].closed}) { totalCount }
|
|
58
58
|
page: ${connection[kind]}(states: ${states[kind][state]}, first: ${ISSUES_PAGE}, after: $after, orderBy: { field: UPDATED_AT, direction: DESC }) {
|
|
59
59
|
pageInfo { hasNextPage endCursor }
|
|
60
|
-
nodes { ${fields[kind]}${kind === 'pulls' && state === 'open' ? ` baseRefOid headRefOid ${files} ${reviewFields(TILE_THREADS, false)}` : ''} }
|
|
60
|
+
nodes { ${fields[kind]}${kind === 'pulls' && state === 'open' ? ` baseRefOid headRefOid isCrossRepository ${files} ${reviewFields(TILE_THREADS, false)}` : ''} }
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}`
|
|
64
64
|
|
|
65
65
|
type Node = ReviewNode & { number?: unknown; title?: unknown; createdAt?: unknown; updatedAt?: unknown; closedAt?: unknown; mergedAt?: unknown; author?: GraphAccount
|
|
66
66
|
comments?: { totalCount?: unknown }; labels?: { totalCount?: unknown; nodes?: { name?: unknown; color?: unknown }[] }; state?: unknown; stateReason?: unknown
|
|
67
|
-
isDraft?: unknown; reviewDecision?: unknown; additions?: unknown; deletions?: unknown; headRefName?: unknown; baseRefName?: unknown; baseRefOid?: unknown
|
|
67
|
+
isDraft?: unknown; reviewDecision?: unknown; additions?: unknown; deletions?: unknown; headRefName?: unknown; baseRefName?: unknown; baseRefOid?: unknown; isCrossRepository?: unknown
|
|
68
68
|
commits?: { nodes?: { commit?: { statusCheckRollup?: { state?: unknown } | null } | null }[] }
|
|
69
69
|
files?: { totalCount?: unknown; nodes?: ({ path?: unknown } | null)[] } | null }
|
|
70
70
|
type Page = { repository?: { open?: { totalCount?: unknown }; closed?: { totalCount?: unknown }; page?: Connection<Node> } | null }
|
|
@@ -178,9 +178,12 @@ export async function repositoryItem(fullName: string, token: string, number: nu
|
|
|
178
178
|
|
|
179
179
|
// An open pull request's base's and head's commits, by its number, as GitHub
|
|
180
180
|
// has them now: those its REST API names `base.sha` and `head.sha`
|
|
181
|
-
// (pull-dependencies.ts pullCommits)
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
// (pull-dependencies.ts pullCommits), with the branches they are of
|
|
182
|
+
// (pullRefs), its head's where it is no fork's, and that it is one's where
|
|
183
|
+
// it is. None where either isn't a commit's id.
|
|
184
|
+
const commitsOf = (number: number, { baseRefOid: base, headRefOid: head, baseRefName, headRefName, isCrossRepository }: Node) =>
|
|
185
|
+
typeof base === 'string' && SHA.test(base) && typeof head === 'string' && SHA.test(head)
|
|
186
|
+
? [{ number, base, head, ...pullRefs(baseRefName, isCrossRepository === false ? headRefName : undefined, isCrossRepository) }] : []
|
|
184
187
|
|
|
185
188
|
// The label the pull requests changing a repository's dependencies carry,
|
|
186
189
|
// as Dependabot's do: where it has one, a team's Dependencies reads its open
|
|
@@ -229,15 +232,15 @@ export async function repositoryIssues(fullName: string, token: string, kind: Is
|
|
|
229
232
|
// what its card there and its popup's heading tell (its number, title and
|
|
230
233
|
// author, when it was opened and last updated, whether it is a draft), the
|
|
231
234
|
// files by which whether it changes a lockfile is told, and its base's and
|
|
232
|
-
// head's commits, by which what its lockfiles add is read
|
|
233
|
-
// tile shows (its labels, comments,
|
|
234
|
-
// and comments), which GitHub is slow enough
|
|
235
|
-
// repository's to fail the page.
|
|
235
|
+
// head's commits, by which what its lockfiles add is read, with the branches
|
|
236
|
+
// they are of (commitsOf). Nothing else a tile shows (its labels, comments,
|
|
237
|
+
// size, checks, reviews, threads and comments), which GitHub is slow enough
|
|
238
|
+
// to gather for fifty of a large repository's to fail the page.
|
|
236
239
|
const openPullsQuery = (labelled: boolean) => `query($owner: String!, $name: String!, $first: Int!, $after: String${labelled ? ', $labels: [String!]' : ''}) {
|
|
237
240
|
repository(owner: $owner, name: $name) {
|
|
238
241
|
page: pullRequests(states: [OPEN], first: $first, after: $after, ${labelled ? 'labels: $labels, ' : ''}orderBy: { field: UPDATED_AT, direction: DESC }) {
|
|
239
242
|
pageInfo { hasNextPage endCursor }
|
|
240
|
-
nodes { number title createdAt updatedAt author { ${ACTOR} } state isDraft baseRefOid headRefOid ${files} }
|
|
243
|
+
nodes { number title createdAt updatedAt author { ${ACTOR} } state isDraft baseRefOid headRefOid baseRefName headRefName isCrossRepository ${files} }
|
|
241
244
|
}
|
|
242
245
|
}
|
|
243
246
|
}`
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// The npm versions a repository's stasis.config.json files have Stasis reach,
|
|
2
|
+
// as its dependency review holds to those it names (lockfile-scope.ts
|
|
3
|
+
// stasisConfigs): what the build worker tells of the lockfile it builds
|
|
4
|
+
// (bundle-build-worker.js buildStasisLockfile), kept by the repository, the
|
|
5
|
+
// commit and the file's path, which never change, in this instance and in
|
|
6
|
+
// the database, the versions alone. A build takes minutes, so none is waited
|
|
7
|
+
// for: one not kept is told as pending and built behind the answer, one at a
|
|
8
|
+
// time, the one asked for last meanwhile following a quick one at once; any
|
|
9
|
+
// other is built when asked for again, as its page asks. A failed one is
|
|
10
|
+
// held in this instance, then built again as asked.
|
|
11
|
+
import { BundleBuildError, type LockfileInput, type StasisDependency } from './bundle-build.ts'
|
|
12
|
+
import { directoryOf, installsBundle, lockedVersions } from './bundle-dependency-reviews.ts'
|
|
13
|
+
import type { CommitLockfiles } from './commit-lockfiles.ts'
|
|
14
|
+
import type { LockedPackage } from './locked-packages.ts'
|
|
15
|
+
import { isStasisConfig } from './lockfile-scope.ts'
|
|
16
|
+
import { type Lru, lru } from './lru.ts'
|
|
17
|
+
import type { KeptStore } from './npm-kept.ts'
|
|
18
|
+
import { plainObject } from './npm-manifest.ts'
|
|
19
|
+
import { type DirectoryDependencies, type PullDependencies, addedBetween, lockedAs } from './pull-dependencies.ts'
|
|
20
|
+
|
|
21
|
+
// The rules they are told by, kept with them: one told by others is built again.
|
|
22
|
+
export const STASIS_DEPENDENCIES_READ = 1
|
|
23
|
+
// How long a failed build is held: GitHub's failure of it, or an unexpected
|
|
24
|
+
// one (`transient`), and any other, the commit's or the build's own.
|
|
25
|
+
const TRANSIENT_HELD_MS = 60_000
|
|
26
|
+
const FAILED_HELD_MS = 60 * 60_000
|
|
27
|
+
const TRANSIENT = new Set(['github-rate-limited', 'github-build-failed'])
|
|
28
|
+
// How long no build is tried again once one found its slot busy.
|
|
29
|
+
const BUSY_MS = 10_000
|
|
30
|
+
// How long after the first of them began builds follow one another at once:
|
|
31
|
+
// later, the next is built when asked for again, lest they outlast the
|
|
32
|
+
// invocation they run behind (serverless).
|
|
33
|
+
const FOLLOWED_WITHIN_MS = 60_000
|
|
34
|
+
// How often a build under way looks whether the server is stopping.
|
|
35
|
+
const STOPPING_EVERY_MS = 1000
|
|
36
|
+
|
|
37
|
+
export type StasisRead = { status: 'ready'; dependencies: StasisDependency[] } | { status: 'pending' } | { status: 'failed'; error: string; transient: boolean }
|
|
38
|
+
|
|
39
|
+
export interface StasisDependencyReader {
|
|
40
|
+
// What the stasis.config.json at `config` of `repo` reaches at `commit`, as
|
|
41
|
+
// known now; where nothing is, a build of it started behind the answer
|
|
42
|
+
// with `token`, told the `branch` the commit is of, where its asker knows.
|
|
43
|
+
read(repo: { repoId: number; fullName: string }, token: string, commit: string, config: string, branch?: string): Promise<StasisRead>
|
|
44
|
+
}
|
|
45
|
+
interface ReaderOptions {
|
|
46
|
+
store: KeptStore<unknown>
|
|
47
|
+
// Builds one, as the deployment's builds are admitted (http.ts stasisReader).
|
|
48
|
+
build(input: LockfileInput, github: string, token: string, signal: AbortSignal): Promise<StasisDependency[]>
|
|
49
|
+
// Work going on behind an answer, handed to its owner (http.ts trackBehind).
|
|
50
|
+
behind(work: Promise<unknown>): void
|
|
51
|
+
stopping(): boolean
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type Job = { key: string; input: LockfileInput; github: string; token: string }
|
|
55
|
+
const optional = (value: unknown) => value === undefined || typeof value === 'string'
|
|
56
|
+
const dependenciesOf = (value: unknown) => Array.isArray(value) && value.every(one => plainObject(one) && typeof one['name'] === 'string'
|
|
57
|
+
&& typeof one['version'] === 'string' && optional(one['integrity']) && optional(one['patch'])) ? value as StasisDependency[] : null
|
|
58
|
+
|
|
59
|
+
export function stasisDependencyReader({ store, build, behind, stopping }: ReaderOptions): StasisDependencyReader {
|
|
60
|
+
const known: Lru<{ read: StasisRead; until: number }> = lru(500_000, ({ read }) => read.status === 'ready' ? read.dependencies.length + 1 : 1)
|
|
61
|
+
const hold = (key: string, read: StasisRead, until = Infinity) => { known.set(key, { read, until }); return read }
|
|
62
|
+
// The one being built here, till when none is tried after one found its slot busy, and the one asked for last meanwhile.
|
|
63
|
+
let building: string | null = null, busyTill = 0, next: Job | null = null
|
|
64
|
+
|
|
65
|
+
async function built({ key, input, github, token }: Job) {
|
|
66
|
+
const stop = new AbortController()
|
|
67
|
+
const watching = setInterval(() => { if (stopping()) stop.abort() }, STOPPING_EVERY_MS)
|
|
68
|
+
watching.unref()
|
|
69
|
+
try {
|
|
70
|
+
const dependencies = await build(input, github, token, stop.signal)
|
|
71
|
+
await store.write(key, dependencies, Date.now())
|
|
72
|
+
hold(key, { status: 'ready', dependencies })
|
|
73
|
+
} catch (err) {
|
|
74
|
+
if (stop.signal.aborted) return
|
|
75
|
+
const refused = err instanceof BundleBuildError
|
|
76
|
+
const code = refused ? err.code : 'build-failed'
|
|
77
|
+
// Its slot another's, or given up to a build asked for: built when asked for again.
|
|
78
|
+
if (code === 'build-busy' || code === 'build-yielded') { busyTill = Date.now() + BUSY_MS; return }
|
|
79
|
+
if (!refused) console.warn('managed: stasis dependencies build failed:', err)
|
|
80
|
+
const transient = !refused || TRANSIENT.has(code)
|
|
81
|
+
hold(key, { status: 'failed', error: code, transient }, Date.now() + (transient ? TRANSIENT_HELD_MS : FAILED_HELD_MS))
|
|
82
|
+
} finally { clearInterval(watching) }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// `first` built, then the one asked for last meanwhile, and so on while the first began FOLLOWED_WITHIN_MS ago or less.
|
|
86
|
+
async function run(first: Job) {
|
|
87
|
+
const began = Date.now()
|
|
88
|
+
try {
|
|
89
|
+
for (let job: Job | null = first; job; job = Date.now() - began < FOLLOWED_WITHIN_MS && Date.now() >= busyTill && !stopping() ? next : null) {
|
|
90
|
+
building = job.key
|
|
91
|
+
next = null
|
|
92
|
+
await built(job)
|
|
93
|
+
}
|
|
94
|
+
} finally { building = next = null }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
async read({ repoId, fullName }, token, commit, config, branch) {
|
|
99
|
+
const key = `${repoId}\0${STASIS_DEPENDENCIES_READ}\0${commit}\0${config}`
|
|
100
|
+
const held = known.get(key)
|
|
101
|
+
if (held && Date.now() < held.until) return held.read
|
|
102
|
+
const kept = dependenciesOf((await store.read(key))?.value)
|
|
103
|
+
if (kept) return hold(key, { status: 'ready', dependencies: kept })
|
|
104
|
+
const job = { key, input: { repoId, commit, config, ...branch !== undefined && { branch } }, github: fullName, token }
|
|
105
|
+
if (building !== null) next = building === key ? next : job
|
|
106
|
+
else if (Date.now() >= busyTill && !stopping()) {
|
|
107
|
+
building = key
|
|
108
|
+
behind(run(job))
|
|
109
|
+
}
|
|
110
|
+
return { status: 'pending' }
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// The stasis.config.json at `config` as a directory of a review's
|
|
116
|
+
// dependencies (pull-dependencies.ts DirectoryDependencies), by its own
|
|
117
|
+
// path: the versions its entries reach at `head` that they didn't at `base`,
|
|
118
|
+
// a pull request's merge base, and all they reach at `head`; for a default
|
|
119
|
+
// branch, of no base, those alone. Each is told as the lockfiles in its
|
|
120
|
+
// directory or above lock it there (`locked`; lockedVersions), a patched one
|
|
121
|
+
// as the build installed it; one none of them locks told so (`unlocked`),
|
|
122
|
+
// which can't be reviewed. Where a build is still to be made, that it is
|
|
123
|
+
// (`stasis-pending`); where the head's failed, or GitHub failed the base's,
|
|
124
|
+
// why (`stasis-failed`). A base that couldn't be built of its own, as one of
|
|
125
|
+
// no such file, reaches nothing, so every version at the head is new.
|
|
126
|
+
export async function stasisDirectory(config: string, base: string | null, head: string, read: (commit: string) => Promise<StasisRead>,
|
|
127
|
+
locked: (commit: string, held: (path: string) => boolean) => Promise<CommitLockfiles>): Promise<DirectoryDependencies> {
|
|
128
|
+
const paths = [config]
|
|
129
|
+
const [after, before] = await Promise.all([read(head), base === null || base === head ? null : read(base)])
|
|
130
|
+
if (after.status === 'failed') return { paths, error: 'stasis-failed', detail: after.error }
|
|
131
|
+
if (before?.status === 'failed' && before.transient) return { paths, error: 'stasis-failed', detail: before.error }
|
|
132
|
+
if (after.status === 'pending' || before?.status === 'pending') return { paths, error: 'stasis-pending' }
|
|
133
|
+
const lockedAt = async (commit: string, dependencies: StasisDependency[]): Promise<LockedPackage[]> => {
|
|
134
|
+
const found = lockedVersions(dependencies, await locked(commit, path => installsBundle(path, directoryOf(config))))
|
|
135
|
+
return [...found.locked, ...found.unlocked.map(({ name, version }): LockedPackage => ({ name, version, source: 'registry', unlocked: true }))]
|
|
136
|
+
}
|
|
137
|
+
const [now, was] = await Promise.all([lockedAt(head, after.dependencies), before?.status === 'ready' ? lockedAt(base!, before.dependencies) : []])
|
|
138
|
+
return addedBetween(paths, before === null ? now : was, now)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// `answer`, a review's dependencies, each version its package manager alone
|
|
142
|
+
// asks a review of marked so (`unreached`): one a lockfile locks that the
|
|
143
|
+
// stasis.config.json in its directory, held to with it, reaches not, nor
|
|
144
|
+
// does any other told; but one another lockfile, with none beside it, locks
|
|
145
|
+
// too. Nothing is marked by a file whose reach isn't told (still built,
|
|
146
|
+
// failed, or more than are told). `lockfiles`: each lockfile and what it
|
|
147
|
+
// locks, where `answer`'s directories don't tell them apart (a default
|
|
148
|
+
// branch's).
|
|
149
|
+
const isStasis = (dir: DirectoryDependencies) => dir.paths.length > 0 && isStasisConfig(dir.paths[0]!)
|
|
150
|
+
export function withReach<T extends PullDependencies>(answer: T, lockfiles?: { path: string; packages: LockedPackage[] }[]): T {
|
|
151
|
+
const beside = new Set<string>(), reached = new Set<string>()
|
|
152
|
+
for (const dir of answer.lockfiles) {
|
|
153
|
+
if (!isStasis(dir) || 'error' in dir || dir.moreLocked > 0) continue
|
|
154
|
+
beside.add(directoryOf(dir.paths[0]!))
|
|
155
|
+
for (const pkg of dir.locked) reached.add(lockedAs(pkg))
|
|
156
|
+
}
|
|
157
|
+
if (beside.size === 0) return answer
|
|
158
|
+
const locking = lockfiles ?? answer.lockfiles.flatMap(dir => isStasis(dir) || 'error' in dir || dir.paths.length === 0 ? [] : [{ path: dir.paths[0]!, packages: dir.locked }])
|
|
159
|
+
// Those a lockfile beside such a file locks, and those any other does.
|
|
160
|
+
const alone = new Set<string>(), asked = new Set<string>()
|
|
161
|
+
for (const { path, packages } of locking) {
|
|
162
|
+
const keys = beside.has(directoryOf(path)) ? alone : asked
|
|
163
|
+
for (const pkg of packages) keys.add(lockedAs(pkg))
|
|
164
|
+
}
|
|
165
|
+
const marked = <P extends LockedPackage>(pkg: P): P => {
|
|
166
|
+
const key = lockedAs(pkg)
|
|
167
|
+
return alone.has(key) && !asked.has(key) && !reached.has(key) ? { ...pkg, unreached: true } : pkg
|
|
168
|
+
}
|
|
169
|
+
return { ...answer, lockfiles: answer.lockfiles.map(dir => isStasis(dir) || 'error' in dir ? dir : { ...dir, added: dir.added.map(marked), locked: dir.locked.map(marked) }) }
|
|
170
|
+
}
|
package/out/chunk-65PLAG3I.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{a as e}from"./chunk-QRKFPLA4.js";import{b as t}from"./chunk-TUII34K2.js";var n=new Set([`module`,`commonjs`,`json`,`module-typescript`,`commonjs-typescript`]),r=new Set([`solidity`,`php`,`shell`,`rust`,`teal`]),i=new Set([`java`,`kotlin`,`gradle`,`objc`,`objcpp`,`swift`,`c`,`cpp`,`c-header`,`cpp-header`,`ruby`,`python`,`cmake`,`podspec`,`podfile`,`podfile-lock`,`gemfile`,`gemfile-lock`,`template`,`xml`,`env`,`fastlane`,`pbxproj`]),a=new Set([`generic-javascript`,`generic-typescript`]),o=new Set([`resource`,`resource:base64`]),s=new Set([`stat:file`,`stat:directory`]),c=new Set([...n,...r,...i,...a,...o,`patch`,`directory`,...s]),l=e=>s.has(e),u=e=>e===`directory`||e===`stat:directory`?`directory`:`file`,d=new Set([`module`,`commonjs`,`module-typescript`,`commonjs-typescript`]),f=(e,t)=>a.has(e)&&d.has(t);function p(e,t,n){if(e===t)return e;if(f(e,t))return t;if(f(t,e))return e;let r=l(e);if(r!==l(t)&&u(e)===u(t))return r?t:e;throw Error(`format conflict for '${n}' ('${t}' vs '${e}')`)}var m=(e,t)=>t===``?e:e===`.`?t:`${e}/${t}`,h=/^(?=[A-Za-z0-9-]{1,39}\/)[A-Za-z0-9](?:-?[A-Za-z0-9])*\/(?!\.\.?$)[\w.-]{1,100}$/u,ee=/^(?!\.\.?(?:\/|$))[\w.~@+-]+(?:\/(?!\.\.?(?:\/|$))[\w.~@+-]+)*$/u,te=/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u,g={github:e=>typeof e==`string`&&h.test(e),directory:e=>typeof e==`string`&&e.length<=1024&&(e===``||ee.test(e)),commit:e=>typeof e==`string`&&te.test(e)},ne=(e,t)=>e?.toLowerCase()===t?.toLowerCase(),_=(e,t,n)=>{if(e===void 0)return;E(e)||C(!1,`${n} must be an object`);for(let r of Object.keys(e))Object.hasOwn(t,r)||C(!1,`unknown ${n} key '${r}'`);let r=Object.entries(t).map(([t,r])=>typeof r==`object`?[t,_(e[t],r,`${n}.${t}`)]:(e[t]!==void 0&&!r(e[t])&&C(!1,`invalid ${n}.${t}: ${JSON.stringify(e[t])}`),[t,e[t]])).filter(([,e])=>e!==void 0);return r.length===0?void 0:Object.freeze(D(r))},re=(e,t=`bundle repo`)=>_(e,g,t),v=(e,t)=>t??(M(e)?`npm`:void 0),ie=(e,t,n,r,i)=>(a,{ecosystem:o,[e]:s},c)=>{if(s===void 0)return;r(a,o)||C(!1,`${c}: '${a}' is no ${i} bucket, and carries no ${e}`);let l=_(s,t,`${c} module '${a}' ${e}`);return l?.[n]===void 0&&C(!1,`${c} module '${a}' ${e} has no ${n}`),l},ae=ie(`repo`,g,`github`,(e,t)=>v(e,t)!==void 0,`dependency's`),oe={sha1:/^sha1-[A-Za-z\d+/]{27}=$/u,sha256:/^sha256-[A-Za-z\d+/]{43}=$/u,sha512:/^sha512-[A-Za-z\d+/]{86}==$/u},se=/^(?:\.\.\/)*(?!\.\.?(?:\/|$))[^/\\\p{Cc}]+(?:\/(?!\.\.?(?:\/|$))[^/\\\p{Cc}]+)*$/u,ce={integrity:e=>typeof e==`string`&&oe.sha256.test(e),file:e=>typeof e==`string`&&e.length<=4096&&se.test(e)},le=(e,t)=>M(e)&&v(e,t)===`npm`,ue={npm:`sha512`,cargo:`sha256`,composer:`sha1`,soldeer:`sha256`},de=(e,{ecosystem:t,integrity:n},r)=>{if(n===void 0)return;let i=v(e,t);return(!Object.hasOwn(ue,i)||i===`npm`&&!M(e))&&C(!1,`${r}: '${e}' is no npm, cargo, composer or soldeer dependency's bucket, and carries no integrity`),typeof n==`string`&&oe[ue[i]].test(n)||C(!1,`invalid ${r} module '${e}' integrity: ${JSON.stringify(n)}`),n},fe=ie(`patch`,ce,`integrity`,le,`npm dependency's`),pe=e=>typeof e==`string`&&/^[\w.+@/~'!()*-]+$/u.test(e),y={name:pe,version:pe},me=e=>typeof e==`string`&&e!==``&&!e.includes(`\\`)&&e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`&&e!==`node_modules`),he=(e,t,n)=>typeof e==`string`&&me(n)&&e===`${t}/${n}`,ge={vendored:()=>!0,subpackages:(e,t,n)=>he(e.name,t,n)},_e=(e,t)=>{for(let n=t.lastIndexOf(`/`);n>0;n=t.lastIndexOf(`/`,n-1))if(Object.hasOwn(e,t.slice(0,n)))return t.slice(0,n)};function ve(e,t){if(e===void 0)return;let n=new Set(Object.keys(t).map(t=>_e(e,t)).filter(e=>e!==void 0));return n.size===0?void 0:Object.freeze(D(w(n).map(t=>[t,e[t]])))}var ye=(e,t,{name:n,ecosystem:r,files:i,[e]:a},o)=>{if(a===void 0)return;v(t,r)===void 0&&C(!1,`${o}: '${t}' is no dependency's bucket, and carries no ${e}`),E(a)||C(!1,`${o} module '${t}' ${e} must be an object`);let s=D(Object.entries(a).map(([r,i])=>{me(r)||C(!1,`${o} module '${t}' ${e}: invalid directory ${JSON.stringify(r)}`);let a=_(i,y,`${o} module '${t}' ${e} '${r}'`);return a?.name===void 0&&C(!1,`${o} module '${t}' ${e} '${r}' has no name`),ge[e](a,n,r)||C(!1,`${o} module '${t}' ${e} '${r}' is named '${a.name}', not '${n}/${r}'`),[r,a]})),c=ve(s,i),l=Object.keys(s).find(e=>!Object.hasOwn(c??{},e));return l!==void 0&&C(!1,`${o} module '${t}' ${e} '${l}' holds none of its files`),c},be={integrity:de,patch:fe,repo:ae},b=Object.keys(ge),x=[...Object.keys(be),...b],xe=[`ecosystem`,...x],S=e=>{let t={name:e.name,version:e.version};for(let n of xe)e[n]!==void 0&&(t[n]=e[n]);return t.files=e.files,t},Se={integrity:(e,t)=>e===t,patch:(e,t)=>e?.integrity===t?.integrity&&(e?.file===void 0||t?.file===void 0||e.file===t.file)},Ce=Object.keys(Se),we=(e,t,n)=>Se[e](t,n),Te=(e,t)=>e[t]??(t===`patch`&&e.integrity!==void 0?null:void 0),Ee=(e,t,n,r)=>{if(we(e,t[e],n[e]))return;let[i,a]=[t[e],n[e]].map(e=>JSON.stringify(e)??`none`);C(!1,`${r} ${e} mismatch (${i} vs ${a})`)},De=(e,t,n)=>{let[r,i]=[t[e],n[e]];if([r,i].every(e=>typeof e==`object`&&!!e))return Object.keys(i).some(e=>r[e]===void 0)?Object.freeze({...i,...r}):void 0};function Oe(e,t,n=`module`){let r;for(let i of Object.keys(be))if(Ce.includes(i)&&Te(e,i)!==void 0&&Te(t,i)!==void 0){Ee(i,e,t,n);let a=De(i,e,t);a&&((r??={})[i]=a)}else e[i]===void 0&&t[i]!==void 0&&((r??={})[i]=t[i]);for(let n of b)t[n]===void 0||Object.keys(t[n]).every(t=>Object.hasOwn(e[n]??{},t))||((r??={})[n]=Object.freeze(D([...Object.entries(t[n]),...Object.entries(e[n]??{})])));return r===void 0?e:S({...e,...r})}function ke(e,t,n,r,i){let a={};for(let[i,o]of Object.entries(be))a[i]=r.includes(i)?o(e,t,n):void 0;for(let o of b)a[o]=r.includes(o)?ye(o,e,{...t,[o]:i(o)},n):void 0;return a}function Ae(e,t,n,r=x){let{name:i,version:a,ecosystem:o}=e;C(o===void 0||typeof o==`string`),E(e.files)||C(!1,`${n}: module '${t}' files must be an object`);let s=D(Object.entries(e.files));return S({name:i,version:a??void 0,ecosystem:o,...ke(t,{...e,files:s},n,r,t=>e[t]),files:s})}function je(e,{scope:t=`full`}={}){let n=new Set;for(let[r,{files:i}]of e)if(t===`full`||M(r))for(let e of Object.keys(i))n.add(m(r,e));return n}function Me(e,{what:t,files:n,formats:r,scope:i}){if(e.includes(`\\`))return`holds a '\\'`;if(k(e))return`escapes the root`;if(i!==`full`&&!M(e))return`is outside node_modules, which a '${i}'-scope ${t} does not record`;if(!n.has(e))return`names no file the ${t} records`;let a=r.get(e);return a===`directory`?`is a directory capture, not a file`:l(a)?`is a payload-free '${a}' record, not a file`:null}function Ne(e,{what:t,files:n,formats:r,scope:i}){for(let a of e){let e=Me(a,{what:t,files:n,formats:r,scope:i});C(e===null,`${t}: executable entry '${a}' ${e}`)}}function Pe(e,t,n,r){C(Array.isArray(e),`${t} must be an array of file paths`);let i=new Set;for(let t of e)r(t),C(!i.has(t),`${n} '${t}' is listed twice`),i.add(t);return i}function Fe(e,{what:t,files:n,formats:r,scope:i=`full`}){if(e===void 0)return new Set;let a=`${t}: executable entry`,o=Pe(e,`${t}: executable`,a,e=>C(typeof e==`string`&&e!==``,`${a} must be a non-empty string`));return Ne(o,{what:t,files:n,formats:r,scope:i}),o}function Ie(e,{what:t,modules:n,formats:r,scope:i}){if(e.size!==0)return Ne(e,{what:t,files:je(n,{scope:i}),formats:r,scope:i}),O(e)}function C(e,t){if(!e)throw Error(t)}var Le=`stasis.lock.json`,Re=new Set([`node_modules`,`full`]),ze=(e,t)=>C(Re.has(e),`${t} scope must be node_modules or full, got ${JSON.stringify(e)}`),Be=e=>{let t=e.slice(e.lastIndexOf(`/`)+1).toLowerCase();return t===Le||t.endsWith(`.${Le}`)},Ve=/(?:^|\/)(?:\.git(?:\/|$)|(?:\.npm-extension\.[cm]?[jt]s|\.?pnpmfile\.[cm]?[jt]s|\.npmrc|\.yarnrc(?:\.yml)?|\.?bunfig\.toml|\.pnp\.(?:c?js|loader\.mjs|data\.json))$)/iu,He=/(?:^|\/)node_modules\/(?:[^/]*\/)*(?:pnpm-workspace\.yaml|\.env\.[^/]*|[^/]*\.env)$/iu,Ue=e=>Be(e)||Ve.test(e)||He.test(e);function We(e,t){let n=0;for(;n<e.length&&e[n]===t[n];)n++;let r=e.length-n,i=t.length-n;if(r===0&&i===0)return 0;if(r<2)return i<2&&(e[n]??``)>(t[n]??``)?1:-1;if(i<2)return 1;if(e[n]===`*`)return-1;if(t[n]===`*`||e[n]===`node_modules`)return 1;if(t[n]===`node_modules`)return-1;let a=e.slice(n).join(`\0`),o=t.slice(n).join(`\0`);if(a<o)return-1;if(a>o)return 1;throw Error(`Unreachable`)}var w=(e,t=e=>e)=>Array.from(e,e=>({item:e,segments:t(e).split(`/`)})).toSorted((e,t)=>We(e.segments,t.segments)).map(({item:e})=>e),T=([e])=>e;function E(e){if(!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}var D=e=>Object.setPrototypeOf(Object.fromEntries(e),null),O=e=>w(e),Ge=(e,{sorted:t=!0}={})=>D((t?w(e,T):[...e]).map(([e,n])=>[e,n instanceof Map?Ge(n,{sorted:t}):n]));function Ke(e,t,n){let r=e.get(t);return r===void 0&&e.set(t,r=n()),r}var qe=(e,t)=>Ke(e,t,()=>new Map),Je=e=>new Map(Object.entries(e).map(([e,t])=>[e,E(t)?Je(t):t]));function k(e){if(e.startsWith(`/`))return!0;if(!e.includes(`..`))return!1;let t=0;for(let n of e.split(`/`))if(n!==`.`&&n!==``){if(n!==`..`)t++;else if(--t<0)return!0}return!1}var Ye=e=>e.includes(`\\`)||k(e),A=(e,t)=>C(!Ye(e),`${t}: path '${e}' escapes the root or holds a '\\'`),Xe=e=>typeof e==`string`&&e!==``&&!Ye(e),Ze=(e,t)=>C(Xe(e),`${t}: invalid entry ${JSON.stringify(e)}`),Qe=(e,t)=>Pe(e,`${t}: entries`,`${t}: entry`,e=>Ze(e,t));function $e(e,t){for(let n of e)Ze(n,t);return O(e)}function et(e,t){A(e,`formats`),C(c.has(t),`unknown format '${t}' for ${e}`)}function tt(e){C(E(e));let t=new Map;for(let[n,r]of Object.entries(e)){et(n,r);let e=n===``?`.`:n;C(!t.has(e),`duplicate format key '${e}'`),t.set(e,r)}return t}function nt(e,t,n){for(let[r,i]of e)l(i)&&t.has(r)&&C(!1,`${n}: '${r}' is a payload-free '${i}' record, yet carries content`)}function rt(e){for(let[t,n]of e)et(t,n);return Ge(e)}function it(e){for(let[,t]of e){C(t instanceof Map);for(let[e,n]of t){A(e,`imports`),C(n instanceof Map);for(let[,e]of n)if(typeof e==`string`)A(e,`imports`);else{C(e instanceof Map&&e.size>0,`import target must be a file or a non-empty {platform: file} map`);for(let[t,n]of e)C(typeof t==`string`&&t.length>0&&!t.includes(`/`),`invalid platform key '${t}'`),C(typeof n==`string`),A(n,`imports`)}}}}function at(e){C(E(e));let t=Je(e);return it(t),t}function ot(e){return it(e),Ge(e)}function st(e,{skipEmpty:t=!1,metadata:n=!0,what:r}={}){let i=n===!0?x:n===!1?[]:n,a={modules:[],sources:[]};for(let[n,o]of e){if(t&&Object.keys(o.files).length===0)continue;let e=M(n);e&&C(o.name&&o.version&&o.files);let s=D(w(Object.entries(o.files),T));a[e?`modules`:`sources`].push([n,S({...o,...ke(n,{...o,files:s},r,i,e=>ve(o[e],s)),files:s})])}return{modules:D(w(a.modules,T)),sources:D(w(a.sources,T))}}function ct(e,t,n){let r=new Map;for(let i of e.config.scope===`full`?[`modules`,`sources`]:[`modules`]){if(i===`modules`&&e.modules===void 0)continue;C(E(e[i]),`${t}: ${i} must be an object`);let a=i===`modules`;for(let[o,s]of Object.entries(e[i]))C(M(o)===a),A(o,t),C(s?.name&&(s.version||!a)&&s.files),r.set(o,Ae(s,o,t,n))}return r}function lt({config:{scope:e},entries:t,modules:n,formats:r,imports:i,executable:a},o,s){let c=e===`full`,l=st(n,{...s,what:o});return{entries:c?$e(t,o):void 0,sources:c?l.sources:void 0,modules:l.modules,formats:r===null?void 0:rt(r),imports:i===null?void 0:ot(i),executable:Ie(a,{what:o,modules:n,formats:r??new Map,scope:e})}}function ut(e,t){return!(e instanceof Map)||!(t instanceof Map)?e===t:e.size===t.size&&e.entries().every(([e,n])=>t.get(e)===n)}var dt=e=>e instanceof Map?`{${[...e].map(([e,t])=>`${e}: ${t}`).join(`, `)}}`:e;function ft(e,t,n){let r=new Map;for(let i of[e,t])for(let[e,t]of i){let i=qe(r,e);for(let[e,r]of t){let t=qe(i,e);for(let[i,a]of r)t.has(i)?C(ut(t.get(i),a),`${n}: import '${i}' from '${e}' resolves differently ('${dt(t.get(i))}' vs '${dt(a)}')`):t.set(i,a instanceof Map?new Map(a):a)}}return r}function pt(e,t,n){let r=e.get(t);e.set(t,r===void 0?n:p(n,r,t))}function mt(e,t,n){let r=new Map;try{for(let n of[e,t])for(let[e,t]of n)pt(r,e,t)}catch(e){throw Error(`${n}: ${e.message}`,{cause:e})}return r}var ht=(e,t,n,r)=>e.size===0?new Set(t):new Set(t).union(e.difference(je(n,{scope:r}))),gt=/(?:^|\/)\.{0,2}(?:\/|$)/u;function j(e,t,n){let r=m(e,t);return(r!==`.`||t!==``)&>.test(r)&&C(!1,`${n}: non-canonical file key ${JSON.stringify(r)}`),r.includes(`\\`)&&C(!1,`${n}: file key '${r}' holds a '\\', which no path may`),r}function _t(e,t,n){let r=new Map;for(let[i,{files:a}]of e){typeof i!=`string`&&C(!1,`${t}: bucket dir ${String(i)} is not a string`),A(i,t);for(let e of Object.keys(a)){let a=j(i,e,t),o=r.get(a);o!==void 0&&n(a,o,i),r.set(a,i)}}return r}var vt=(e,t)=>n=>C(!1,`duplicate file key '${n}' across ${e} buckets -- module bucketing changed between writes (a workspace package without a version now owns its own bucket); regenerate the ${t}`);function yt(e,t,n,{held:r=!1}={}){let i=new Map;for(let a of[e,t])for(let[e,t]of a){let a=i.get(e);if(a===void 0)i.set(e,S({...t,files:Object.assign(Object.create(null),t.files)}));else{C(a.name===t.name,`${n}: module '${e}' name mismatch ('${a.name}' vs '${t.name}')`),C(a.version===t.version,`${n}: module '${e}' version mismatch ('${a.version}' vs '${t.version}')`+(a.version==null==(t.version==null)?``:` -- an artifact from an older stasis may record a placeholder version for a workspace package without one; regenerate it (bundle=replace / lock=replace)`)),C(a.ecosystem===t.ecosystem,`${n}: module '${e}' ecosystem mismatch ('${a.ecosystem??`(none)`}' vs '${t.ecosystem??`(none)`}')`),i.set(e,Oe(a,t,`${n}: module '${e}'`));for(let i of Ce){if(a[i]===void 0==(t[i]===void 0)||r&&a[i]===void 0)continue;let[o,s]=a[i]===void 0?[t,a]:[a,t],c=Object.keys(s.files).find(e=>!Object.hasOwn(o.files,e));c!==void 0&&C(!1,`${n}: module '${e}' ${i} is recorded of one side's files, not of '${m(e,c)}' the other adds`)}for(let[r,i]of Object.entries(t.files))Object.hasOwn(a.files,r)?C(a.files[r]===i,`${n}: content mismatch for '${m(e,r)}'`):a.files[r]=i}}return _t(i,n,(e,t,r)=>C(!1,`${n}: file '${e}' is bucketed under both '${t}' and '${r}' -- module bucketing changed between the artifacts (a workspace package without a version now owns its own bucket); regenerate the artifact (bundle=replace / lock=replace)`)),i}var M=e=>e===`node_modules`||e.startsWith(`node_modules/`)||e.endsWith(`/node_modules`)||e.includes(`/node_modules/`),bt=`node_modules/`;function xt(e){let t=e.length;for(;(t=e.lastIndexOf(bt,t-1))!==-1;)if(t===0||e[t-1]===`/`)return t;return-1}function St(e){let t=xt(e);if(t===-1)return null;let n=t+bt.length,r=e.slice(n).split(`/`),i=r[0].startsWith(`@`)?2:1,a=r.slice(0,i);if(r.length<=i||a.includes(``))return null;let o=a.join(`/`);return{dir:e.slice(0,n)+o,rel:r.slice(i).join(`/`),name:o}}var N=1,Ct=0,wt=vt(`bundle`,`artifact (bundle=replace)`),Tt=(e,t)=>{let n=_t(e,`bundle`,wt);for(let e of n.keys())C(!Ue(e),`bundle: ${e} is a file no bundle may carry`);return nt(t,n,`bundle`),n},Et=e=>St(e)??{dir:`.`,rel:e===`.`?``:e,name:null};function Dt(e){C(E(e),`bundle: sources must be an object`);let t=new Map;for(let[n,r]of Object.entries(e)){A(n,`bundle`);let{dir:e,rel:i,name:a}=Et(n);C(!k(e)&&!k(i));let{files:o}=Ke(t,e,()=>({name:a,version:null,files:Object.create(null)}));C(!Object.hasOwn(o,i),`bundle: duplicate file key '.' (v0 '' and '.')`),o[i]=r}return t}function Ot(){throw Error(`bundle: file contents are not retained by this contents-free Bundle`)}var kt=(e,{files:t,...n})=>{let r=Object.create(null);for(let[n,i]of Object.entries(t))typeof i!=`symbol`&&C(!1,`bundle: file '${m(e,n)}' is not a placeholder`),Object.defineProperty(r,n,{get:Ot,enumerable:!0});return{...n,files:Object.freeze(r)}},P=(e,t)=>{if(e===void 0&&t===void 0)return;let n=new Map;for(let r of[e,t])for(let[e,t]of Object.entries(r??{}))Array.isArray(t)&&n.set(e,new Set([...n.get(e)??[],...t]));return D([...n.keys()].toSorted().map(e=>[e,O(n.get(e))]))},At=(e,t)=>Object.hasOwn(g,e)&&g[e](t),jt=(e,t)=>e?.github===void 0||!ne(e.github,t?.github)?void 0:D(Object.keys(g).filter(n=>e[n]!==void 0&&(n===`github`||e[n]===t[n])).map(t=>[t,e[t]])),Mt=e=>{if(!E(e)||e.root!==!0||Object.hasOwn(e,`directory`))return e;let{root:t,...n}=e;return n},Nt={npm:y,composer:y,cargo:y},Pt=(e,t)=>D(Object.keys(Nt).map(n=>{let[r,i]=[e?.[n],t?.[n]];return[n,r?.name!==void 0&&r.name===i?.name?D(Object.entries(r).filter(([e,t])=>t===i[e])):void 0]})),F=class e{static VERSION=N;#e;get repo(){return this.#e}set repo(e){this.#e=re(e)}#t;get package(){return this.#t}set package(e){this.#t=_(e,Nt,`bundle package`)}constructor({config:e={scope:`full`},entries:t,modules:n,formats:r,imports:i,executable:a,reason:o,repo:s,package:c,version:l=N}={}){C([Ct,N].includes(l)),ze(e.scope,`bundle`),this.version=l,this.config=e,this.entries=t??new Set,this.modules=n??new Map,this.formats=r??new Map,this.imports=i??new Map,this.executable=a??new Set,this.reason=o,this.repo=s,this.package=c}get sources(){let e=new Map;for(let[t,{files:n}]of this.modules)for(let[r,i]of Object.entries(n))e.set(m(t,r),i);return e}static isResourceFormat(e){return o.has(e)||e===`directory`}get hasCode(){return this.modules.entries().some(([t,{files:n}])=>Object.keys(n).some(n=>!e.isResourceFormat(this.formats.get(m(t,n)))))}static parse(t){return e.fromJSON(JSON.parse(t))}static fileKeyAt(e){let[t,n,r,i]=e;if(typeof n==`string`){if(e.length===2&&t===`sources`){let e=Et(n);return j(e.dir,e.rel,`bundle`)}if(e.length===4&&(t===`sources`||t===`modules`)&&r===`files`&&typeof i==`string`)return j(n,i,`bundle`)}}static fromJSON(t,{contents:n=!0}={}){C(t.version===N||t.version===Ct),ze(t.config?.scope,`bundle`);let r=tt(t.formats),i=t.version===N;i&&t.config.scope!==`full`&&C(t.entries===void 0&&t.sources===void 0);let a=i?ct(t,`bundle`):Dt(t.sources),o=Tt(a,r),s=at(t.imports);if(!n)for(let[e,t]of a)a.set(e,kt(e,t));return new e({version:t.version,config:t.config,entries:i&&t.entries!==void 0?Qe(t.entries,`bundle`):new Set,modules:a,formats:r,imports:s,executable:i?Fe(t.executable,{what:`bundle`,files:o,formats:r,scope:t.config.scope}):new Set,reason:E(t.reason)?t.reason:void 0,repo:Mt(t.repo),package:t.package})}serialize(){return JSON.stringify(this.#n(),void 0,2)}serializedBytes(){let e=this.#n(),t=Object.keys(e.modules);if(t.length===0)return Buffer.from(JSON.stringify(e,void 0,2));let{modules:n,...r}=e,i=JSON.stringify(r,void 0,2);C(i.endsWith(`
|
|
2
|
-
}`));let a=[],o=e=>a.push(Buffer.from(e));o(i.slice(0,-2)),o(`,
|
|
3
|
-
"modules": {
|
|
4
|
-
`);for(let[e,r]of t.entries())e>0&&o(`,
|
|
5
|
-
`),o(JSON.stringify({indent:{[r]:n[r]}},void 0,2).slice(16,-6));return o(`
|
|
6
|
-
}
|
|
7
|
-
}`),Buffer.concat(a)}#n(){Tt(this.modules,this.formats);let{entries:e,sources:t,modules:n,formats:r,imports:i,executable:a}=lt(this,`bundle`,{skipEmpty:!0});return{version:N,config:this.config,repo:this.repo,package:this.package,entries:e,formats:r,imports:i,executable:a,reason:P(this.reason,void 0),sources:t,modules:n}}withReason(t,n=[...this.sources.keys()]){let{version:r,config:i,entries:a,modules:o,formats:s,imports:c,executable:l,repo:u,package:d}=this,f=P(this.reason,{[t]:n});return new e({version:r,config:i,entries:a,modules:o,formats:s,imports:c,executable:l,reason:f,repo:u,package:d})}merge(t){return C(this.config.scope===t.config.scope,`bundle merge: scope mismatch ('${this.config.scope}' vs '${t.config.scope}')`),new e({config:{scope:this.config.scope},entries:new Set([...this.entries,...t.entries]),modules:yt(this.modules,t.modules,`bundle merge`),formats:mt(this.formats,t.formats,`bundle merge`),imports:ft(this.imports,t.imports,`bundle merge`),executable:ht(this.executable,t.executable,t.modules,this.config.scope),reason:P(this.reason,t.reason),repo:jt(this.repo,t.repo),package:Pt(this.package,t.package)})}},Ft={__proto__:null,js:`javascript`,mjs:`javascript`,cjs:`javascript`,jsx:`jsx`,ts:`typescript`,mts:`typescript`,cts:`typescript`,tsx:`tsx`,json:`json`,css:`css`,html:`markup`,htm:`markup`,xml:`markup`,svg:`markup`,yml:`yaml`,yaml:`yaml`,sh:`bash`,bash:`bash`,md:`markdown`,markdown:`markdown`,sol:`solidity`,php:`php`,phtml:`php`,rs:`rust`,rb:`ruby`,py:`python`,pyw:`python`,pyi:`python`,java:`java`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,"c++":`cpp`,hpp:`cpp`,hh:`cpp`,hxx:`cpp`,"h++":`cpp`,h:`cpp`,c:`c`,m:`objectivec`,mm:`objectivec`},It={__proto__:null,module:`javascript`,commonjs:`javascript`,"module-typescript":`typescript`,"commonjs-typescript":`typescript`,json:`json`,solidity:`solidity`,php:`php`,shell:`bash`,rust:`rust`,java:`java`,objc:`objectivec`,objcpp:`objectivec`,c:`c`,"c-header":`c`,cpp:`cpp`,"cpp-header":`cpp`,ruby:`ruby`,podspec:`ruby`,podfile:`ruby`,fastlane:`ruby`,"podfile-lock":`yaml`,xml:`markup`};function Lt(e){if(typeof e!=`string`)return!1;let t=e.length-1,n=0;for(;n<t&&/\s/u.test(e[n]);)n++;for(;t>n&&/\s/u.test(e[t]);)t--;return n<t&&e[n]===`{`&&e[t]===`}`}function Rt(e,t,n){if(typeof t==`string`&&It[t])return It[t];if(typeof e!=`string`)return null;let r=e.slice(e.lastIndexOf(`/`)+1),i=r.lastIndexOf(`.`);if(i<=0)return null;let a=r.slice(i+1).toLowerCase();return a===`map`?Lt(n)?`json`:null:Ft[a]??null}var zt=/^webpack(?:-internal)?:\/\/[^/]*\//u,Bt=/^[a-z][\d+.a-z-]*:/iu,Vt=/^file:/iu,Ht=/^(?:file|ftp|https?|wss?):/iu,Ut=/^(?:[a-z][\d+.a-z-]*:\/\/[^/]*\/?|\/\/[^/]+\/|[a-z]:\/|\/)?/iu,I=e=>Ut.exec(e)[0],L=e=>I(e).includes(`://`),R=e=>e.replace(L(e)?/[#?].*$/su:/\?.*$/su,``),Wt=e=>e.slice(e.lastIndexOf(`/`)+1),z=(e,t)=>URL.parse(e,t)?.href??null;function B(e){let t=I(e),n=t.includes(`://`)&&z(e);if(n)return n;let r=[];for(let n of e.slice(t.length).split(`/`))n===``||n===`.`||(n===`..`?r.length>0&&r.at(-1)!==`..`?r.pop():t||r.push(`..`):r.push(n));let i=/^[a-z]:\/$/iu.test(t)?t.toUpperCase():t.startsWith(`//`)?t.toLowerCase():t;return i?i.replace(/\/?$/u,`/`)+r.join(`/`):r.join(`/`)||`.`}function Gt(e,t){let n=I(t);return L(e)&&!n.includes(`:`)?z(t,e)??B(`${e}/../${t}`):B(n===`/`?I(e).replace(/\/?$/u,``)+t:n?t:`${e}/../${t}`)}function Kt(e){try{return decodeURIComponent(e)}catch{return e}}function V(e,t){let n=e.replaceAll(`\\`,`/`);if(zt.test(n))return B(n.replace(zt,``));let r=Ht.test(n)?z(n)??n:n,i=/^file:\/\/([^/#]*)([^#]*)/isu.exec(r);if(i){let[,e,t]=i;return B(Kt(e&&e.toLowerCase()!==`localhost`?`//${e}${t}`:t).replace(/^\/(?=[a-z]:\/)/iu,``))}if(Bt.test(r)&&!I(r).includes(`:`))return r;if(t===void 0)return B(r);if(Vt.test(t)&&!I(r))return V(z(r,t)??r);let a=V(t);return I(r)&&!L(a)?B(r):Gt(a,r)}var qt=/^(?:@[\dA-Za-z~-][\w.~-]*\/)?[\dA-Za-z~-][\w.~-]*$/u;function Jt(e){let t=e.split(`/`).slice(0,e.startsWith(`@`)?2:1).join(`/`);return qt.test(t)?t:null}var Yt=new Set([`.pnpm`,`.bun`,`.deno`]),Xt=/^\d+\.\d+\.\d+(?:-[\d.a-z-]+)?(?:\+[\d.a-z-]+)?$/iu;function Zt(e,t){let n=`${t.replace(`/`,`+`)}@`,r=e.startsWith(n)?e.slice(n.length).split(/[(_]/u)[0]:null;return Xt.test(r)?r:null}function Qt(e){let t=R(e).split(`/`),n=t.lastIndexOf(`node_modules`),r=n<0?null:Jt(t.slice(n+1).join(`/`));if(r===null)return null;let i=n+1+r.split(`/`).length;if(i>=t.length||t.slice(i).includes(``))return null;let a=t.slice(0,i).join(`/`);return{name:r,version:Yt.has(t[n-2])?Zt(t[n-1],r):null,root:a,path:e.slice(a.length+1)}}var $t=new Map([[`js`,`jsx`],[`mjs`,`jsx`],[`cjs`,`jsx`],[`jsx`,`jsx`],[`es`,`jsx`],[`es6`,`jsx`],[`ts`,`ts`],[`mts`,`ts`],[`cts`,`ts`],[`tsx`,`tsx`],[`json`,`json`]]);function en(e){let t=Wt(R(e));return/^[\w-]+$/u.test(t)?`jsx`:$t.get(/\.([\da-z]+)$/iu.exec(t)?.[1].toLowerCase())??null}var tn=[`.js`,`.mjs`,`.cjs`,`.jsx`,`.ts`,`.tsx`,`.mts`,`.cts`,`.json`],nn=[`.ios`,`.android`,`.web`];function rn(e){let t=e.map(e=>/\.[a-z]+(?=\.\w+$)/u.exec(Wt(R(e.path??``)))?.[0]),[[n,r],[,i]]=nn.map(e=>[e,t.filter(t=>t===e).length]).toSorted((e,t)=>t[1]-e[1]);return[...r===i?[]:[n],`.native`,``,`.browser`,`.node`]}var an=new Map([[`.js`,[`.ts`,`.tsx`]],[`.jsx`,[`.tsx`]],[`.mjs`,[`.mts`]],[`.cjs`,[`.cts`]]]),on=[`index`,`main`,`browser`,`node`],sn=[``,`src/`,`lib/`,`dist/`,`build/`],cn=new Set([`lib`,`dist`,`build`,`out`,`esm`,`cjs`]);function*ln(e,t){yield e;let n=/\.[^./]+$/u.exec(e)?.[0];for(let t of an.get(n)??[])yield e.slice(0,-n.length)+t;for(let n of e.endsWith(`/`)?[`${e}index`]:[e,`${e}/index`])for(let e of tn)for(let r of t)yield n+r+e;if(n)for(let r of t.filter(Boolean))yield e.slice(0,-n.length)+r+n}function*un(e){let t=e;for(;;){t.startsWith(`src/`)||(yield`src/${t}`),t!==e&&(yield t);let n=t.indexOf(`/`);if(n<0||!cn.has(t.slice(0,n)))return;t=t.slice(n+1)}}function dn(e){let t=new Map,n=new Map,r=new Map;for(let i of e)i.path!==null&&t.set(i.path,i),i.package&&(n.set(i.package.name,(n.get(i.package.name)??new Set).add(i.package.root)),(r.get(i.package.root)??r.set(i.package.root,[]).get(i.package.root)).push(i));return{byPath:t,roots:n,byRoot:r,platforms:rn(e),found:new Map}}function H(e,t){if(!e.found.has(t)){let n=R(t),r=ln(n,e.platforms).map(e=>e+t.slice(n.length));e.found.set(t,e.byPath.get(r.find(t=>e.byPath.has(t)))??null)}return e.found.get(t)}function fn(e,t,n){let r=e.roots.get(n);if(!r)return null;let i=t.path.split(`/`);for(let e=i.length-1;e>=0;e--){let t=[...i.slice(0,e),`node_modules`,n].join(`/`);if(r.has(t))return t}return r.size===1?[...r][0]:null}var pn=new Set(`assert.async_hooks.buffer.child_process.cluster.console.constants.crypto.dgram.diagnostics_channel.dns.domain.events.fs.http.http2.https.inspector.module.net.os.path.perf_hooks.process.punycode.querystring.readline.repl.stream.string_decoder.sys.timers.tls.trace_events.tty.url.util.v8.vm.wasi.worker_threads.zlib._http_agent._http_client._http_common._http_incoming._http_outgoing._http_server._stream_duplex._stream_passthrough._stream_readable._stream_transform._stream_wrap._stream_writable._tls_common._tls_wrap.assert/strict.dns/promises.fs/promises.inspector/promises.path/posix.path/win32.readline/promises.stream/consumers.stream/promises.stream/web.timers/promises.util/types`.split(`.`));function mn(e){if(e.startsWith(`node:`)||pn.has(e))return{builtin:!0};let t=Jt(R(e));return t===null?{}:{package:t}}function hn(){let e=[],t=new Map,n=(n,r,i)=>{let a=t.get(n)??t.set(n,new Set).get(n);a.has(r)||(a.add(r),e.push(i))};return{edges:e,add:n,link:(e,t,r)=>{e&&t&&t!==e&&n(e,t,{from:e,to:t,kind:r})}}}function gn(e,t){for(let n of on)for(let r of sn){let i=H(e,`${t}/${r}${n}`);if(i)return i}let n=e.byRoot.get(t);return n?.length===1?n[0]:null}function _n(e,t,n,r){return/^\/[^?]/u.test(n)?H(e,t+n)??un(n.slice(1)).map(n=>H(e,`${t}/${n}`)).find(Boolean):H(e,t+n)??r(e,t)}function vn(e,t,n,r=gn){let i=/^(?:\.{1,2}|[a-z]:)?\\/iu.test(n)?n.replaceAll(`\\`,`/`):n,a=Ht.test(i);if(a||/^(?:\.{1,2}(?:\/|$)|\/|[a-z]:\/)/iu.test(i)||L(i)){let n=a?V(i):Gt(t.path,i),r=H(e,n);return r?{to:r}:{to:null,path:n}}if(Bt.test(i)&&e.byPath.has(i))return{to:e.byPath.get(i)};let o=Jt(R(n)),s=o===null?null:fn(e,t,o);if(s===null)return{to:null,...mn(n)};let c=_n(e,s,n.slice(o.length),r);return c?{to:c}:{to:null,package:o}}var U=class extends Error{name=`SourceMapError`},yn=new Uint8Array(128).fill(255);for(let[e,t]of[...`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/,;`].entries())yn[t.codePointAt(0)]=e;function bn(e){let t=new Int32Array(e.length*2);return t.set(e),t}function xn(e){let{starts:t,columns:n,sources:r,names:i}=e;for(let e=0;e+1<t.length;e++){let[a,o]=[t[e],t[e+1]],s=a+1;for(;s<o&&n[s-1]<=n[s];)s++;if(s>=o)continue;let c=Array.from(n.subarray(a,o),(e,t)=>[e,r[a+t],i[a+t]]).sort((e,t)=>e[0]-t[0]);for(let[e,[t,o,s]]of c.entries())[n[a+e],r[a+e],i[a+e]]=[t,o,s]}return e}function Sn(e){let t=[0],n=new Int32Array(1024),r=new Int32Array(1024),i=new Int32Array(1024),a=0;for(let{mappings:o,files:s,line:c,column:l,names:u,nameCount:d}of e){if(typeof o!=`string`)throw new U(`mappings is not a string`);for(;t.length<=c;)t.push(a);let e=[0,0,0,0,0],f=0,p=0,m=1,h=l;for(let c=0;c<=o.length;c++){let l=c<o.length?yn[o.codePointAt(c)]??255:64;if(l<32){if(p+=l*m,f===5)throw new U(`mappings: a segment of more than 5 fields at ${c}`);e[f++]+=p%2?(1-p)/2:p/2,p=0,m=1}else if(l<64){if(p+=(l-32)*m,m*=32,m>2**30)throw new U(`mappings: a value at ${c} runs past 32 bits`)}else{if(l===255)throw new U(`mappings: ${JSON.stringify(o[c])} at ${c} is not a base64 digit`);if(m!==1)throw new U(`mappings: the value before ${c} is cut off`);if(f>0){if(f===2||f===3)throw new U(`mappings: a segment of ${f} fields before ${c}`);let t=f===1?-1:s[e[1]];if(t===void 0)throw new U(`mappings: source ${e[1]} before ${c} is not in sources`);if(e[0]<0)throw new U(`mappings: a negative generated column before ${c}`);a===n.length&&([n,r,i]=[bn(n),bn(r),bn(i)]),n[a]=e[0]+h,r[a]=t,i[a++]=f===5&&e[4]>=0&&e[4]<d?u+e[4]:-1,f=0}l===65&&(t.push(a),e[0]=0,h=0)}}}return t.push(a),xn({starts:Int32Array.from(t),columns:n.slice(0,a),sources:r.slice(0,a),names:i.slice(0,a)})}var Cn=new WeakMap,wn=e=>Cn.get(e),W=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function G(e,t){if(!e)throw new U(t)}function Tn(e,t){if(e===void 0)return[];G(Array.isArray(e),`${t} is not an array`);for(let n of e)G(typeof n==`string`||n===null,`${t} holds ${JSON.stringify(n)}`);return e}function En(e,t,n,r){let i=e.bySource.get(t);if(i!==void 0)return e.files[i].content??=n,e.files[i].ignored||=r,i;let a=t===null?null:V(t,e.mapPath);return e.files.push({source:t,path:a,package:a===null?null:Qt(a),content:n,ignored:r}),t!==null&&e.bySource.set(t,e.files.length-1),e.files.length-1}function Dn(e,t,n,r){G(e.version===3,`version ${JSON.stringify(e.version)} is not 3`),G(e.sourceRoot===void 0||typeof e.sourceRoot==`string`,`sourceRoot is not a string`);let i=Tn(e.sources,`sources`),a=Tn(e.sourcesContent,`sourcesContent`),o=e.ignoreList??e.x_google_ignoreList??[];G(Array.isArray(o)&&o.every(e=>Number.isInteger(e)&&e>=0&&e<i.length),`ignoreList is not a list of indices into sources`);let s=new Set(o),c=e.sourceRoot?e.sourceRoot.replace(/\/?$/u,`/`):``,l=i.map((e,n)=>En(t,e===null?null:c+e,a[n]??null,s.has(n))),u=Array.isArray(e.names)?e.names:[];t.parts.push({mappings:e.mappings,files:l,line:n,column:r,names:t.names.length,nameCount:u.length}),t.names.push(...u)}function On(e,t){G(e.version===3,`version ${JSON.stringify(e.version)} is not 3`),G(Array.isArray(e.sections),`sections is not an array`);for(let[n,r]of e.sections.entries()){let{offset:i,map:a}=W(r)?r:{};G(W(i)&&[i.line,i.column].every(e=>Number.isInteger(e)&&e>=0),`sections[${n}].offset is not a line and a column`),G(W(a)&&a.sections===void 0,`sections[${n}].map is not a plain source map`);let o=e.sections[n-1]?.offset;G(!o||o.line<i.line||o.line===i.line&&o.column<=i.column,`sections[${n}] starts before sections[${n-1}]`),Dn(a,t,i.line,i.column)}}function kn(e,t={}){if(!W(t))throw TypeError(`readSourceMap: options is not an object`);if(t.path!==void 0&&typeof t.path!=`string`)throw TypeError(`readSourceMap: options.path is not a string`);let n=e;if(typeof e==`string`||e instanceof Uint8Array)try{let t=typeof e==`string`?e:new TextDecoder(`utf-8`,{fatal:!0}).decode(e);n=JSON.parse(t.replace(/^\)\]\}'[^\n]*\n/u,``))}catch(e){throw new U(`not JSON: ${e.message}`,{cause:e})}G(W(n),`not a JSON object`);let r={files:[],bySource:new Map,mapPath:t.path,parts:[],names:[]};n.sections===void 0?Dn(n,r,0,0):On(n,r);let i={files:r.files};return Cn.set(i,{...Sn(r.parts),nameList:r.names}),i}var An=/\r\n?|[\n\u2028\u2029]/gu;function jn(e){let t=[0];for(let n of e.matchAll(An))t.push(n.index+n[0].length);return t}function Mn(e,t,n,r){let[i,a]=[t,n];for(;i<a;){let t=i+a>>1;e[t]<=r?i=t+1:a=t}return i-1}function K(e,t){let n=Mn(e,0,e.length,t);return[n,t-e[n]]}function Nn(e,[t,n]){if(t>=e.starts.length-1)return-1;let r=e.starts[t],i=Mn(e.columns,r,e.starts[t+1],n);return i<r?-1:i}function Pn(e,t,n,r){let i=wn(e),a=K(t,n),[o,s]=K(t,r),c=new Map,l=Nn(i,a);for(let e=a[0];e<=o&&e<i.starts.length-1;e++){let t=e===a[0]&&l>=0?l:i.starts[e];for(let n=t;n<i.starts[e+1];n++){let t=i.sources[n];if(e===o&&i.columns[n]>=s)break;t>=0&&c.set(t,(c.get(t)??0)+1)}}let[u]=[...c].reduce((e,t)=>t[1]>e[1]?t:e,[-1,0]);return u<0?null:e.files[u]}var q=/\s+/uy,Fn=`
|
|
8
|
-
\r\u2028\u2029`,J=/[\n\r\u2028\u2029]/gu,In=/[\n\r\u2028\u2029]/u,Y=/[\w$\u0080-]+/uy,Ln=new Set([`return`,`typeof`,`instanceof`,`in`,`of`,`new`,`delete`,`void`,`throw`,`case`,`default`,`extends`,`do`,`else`,`yield`,`await`]),Rn=new Set([`if`,`while`,`for`,`with`]),zn=new Set([`break`,`continue`,`debugger`]),Bn=new Set([`(`,`[`,"${",`,`,`=`,`:`,`?`,`!`,`~`,`+`,`-`,`*`,`/`,`%`,`&`,`|`,`^`,`<`,`>`]);function Vn(e,t){return e?.type===`word`?t&&[`return`,`yield`].includes(e.value)?!1:Ln.has(e.value)&&![`do`,`else`].includes(e.value):Bn.has(e?.value)}function Hn(e){let t=e.at(-1);return t?.type===`word`&&(Rn.has(t.value)||t.value===`await`&&e.at(-2)?.value===`for`)}function Un(e){return e?e.type===`word`?Ln.has(e.value)||zn.has(e.value)||e.label===!0:e.value===`)`?e.control:e.value===`}`?!e.object:e.type===`punctuator`&&![`++`,`--`,`]`].includes(e.value):!0}var Wn=(e,t)=>e.startsWith(`\r
|
|
9
|
-
`,t+1)?3:2,Gn=/\\(?:u\{([\da-f]+)\}|u([\da-f]{4})|x([\da-f]{2})|([0-3][0-7]{0,2}|[4-7][0-7]?)|(\r\n|[\n\r\u2028\u2029])|(.))/giu,Kn={b:`\b`,f:`\f`,n:`
|
|
10
|
-
`,r:`\r`,t:` `,v:`\v`};function qn(e){return e.includes(`\\`)?e.replace(Gn,(e,t,n,r,i,a,o)=>{if(a!==void 0)return``;if(i!==void 0)return String.fromCodePoint(Number.parseInt(i,8));let s=Number.parseInt(t??n??r,16);return Number.isNaN(s)?Kn[o]??o:String.fromCodePoint(Math.min(s,1114111))}):e}function Jn(e,t){let n=e[t],r=t+1;for(;r<e.length&&e[r]!==n&&!Fn.includes(e[r]);)r+=e[r]===`\\`?Wn(e,r):1;return[e[r]===n?qn(e.slice(t+1,r)):null,r+1]}function Yn(e,t){let n=t+1,r=!1;for(;n<e.length&&!Fn.includes(e[n])&&(r||e[n]!==`/`);)e[n]===`\\`?n++:e[n]===`[`?r=!0:e[n]===`]`&&(r=!1),n++;return Y.lastIndex=n+1,Y.test(e)?Y.lastIndex:n+1}function Xn(e,t,n){for(let r=t;r<e.length;r++)if(e[r]===`\\`)r++;else{if(e[r]==="`")return r+1;if(e[r]===`$`&&e[r+1]===`{`)return n.push(`template`),r+2}return e.length}function Zn(e){let t=[],n=[],r=[],i=0,a=0;for(;i<e.length;){let o=t.length;if(q.lastIndex=i,q.test(e)&&(i=q.lastIndex),i>=e.length)break;let s=e[i],c=e[i+1];if(Y.lastIndex=i,s===`/`&&c===`/`)J.lastIndex=i+2,i=J.test(e)?J.lastIndex-1:e.length;else if(s===`/`&&c===`*`){let t=e.indexOf(`*/`,i+2);i=t<0?e.length:t+2}else if(s===`"`||s===`'`){let[n,r]=Jn(e,i);t.push({type:`string`,value:n}),i=r}else if(s==="`"||s===`}`&&n.at(-1)===`template`){s===`}`&&n.pop();let r=n.length,a=Xn(e,i+1,n),o=s==="`"&&n.length===r&&e[a-1]==="`";t.push({type:`string`,value:o?qn(e.slice(i+1,a-1)):null}),n.length>r&&t.push({type:`punctuator`,value:"${"}),i=a}else if(s===`/`&&Un(t.at(-1)))i=Yn(e,i),t.push({type:`regex`});else if(Y.test(e)){let n=zn.has(t.at(-1)?.value)&&!In.test(e.slice(a,i));t.push({type:`word`,value:e.slice(i,Y.lastIndex),...n&&{label:n}}),i=Y.lastIndex}else{s===`{`&&n.push(Vn(t.at(-1),In.test(e.slice(a,i)))?`object`:`block`);let o=s===`}`?n.pop():void 0;s===`(`&&r.push(Hn(t));let l=(s===`+`||s===`-`)&&c===s||s===`=`&&c===`>`?s+c:s;t.push({type:`punctuator`,value:l,...s===`)`&&{control:r.pop()===!0},...s===`}`&&{object:o===`object`}}),i+=l.length}t.length>o&&(a=i)}return t}var Qn=e=>e?.type===`string`&&e.value!==null,$n=new Set([`type`,`typeof`]),er=(e,t)=>e[t+1]?.type===`word`&&(e[t+1].value!==`as`||e[t+2]?.type!==`word`||e[t+2].value===`as`);function tr(e,t){let n=!1;for(let r=t+1;r<e.length&&e[r].value!==`}`;r++)if(!(r>t+1&&e[r-1].value!==`,`)){if(!$n.has(e[r].value)||!er(e,r))return!1;n=!0}return n}function nr(e,t){for(let n=t;n<e.length;n++){let{value:r}=e[n];if(r===`;`||n>t&&(r===`import`||r===`export`))return null;if(r===`from`&&Qn(e[n+1]))return e[n+1].value}return null}function rr(e,t){let[n,r,i]=[e[t].value,e[t+1],e[t+2]],a=n===`import`?`import`:`export-from`;if(n===`import`&&Qn(r))return{kind:a,specifier:r.value};if($n.has(r?.value)&&![`,`,`from`].includes(i?.value)||r?.value===`{`&&tr(e,t+1)||n===`export`&&![`{`,`*`].includes(r?.value)||n===`import`&&r?.type!==`word`&&![`{`,`*`].includes(r?.value))return null;let o=nr(e,t+1);return o===null?null:{kind:a,specifier:o}}function ir(e,t){let[n,r]=[e[t+2],e[t+3]];if(n?.value!==`)`)return Qn(n)&&[`)`,`,`].includes(r?.value)?n.value:null}function ar(e,t=new Set){let n=Zn(e),r=[];for(let[e,i]of n.entries()){if(i.type!==`word`||[`.`,`#`,`function`].includes(n[e-1]?.value)||n[e-1]?.value===`=`&&n[e-3]?.value===`type`&&n[e-4]?.value===`import`)continue;let a=n[e+1]?.value===`(`,o=a?ir(n,e):void 0;if((i.value===`require`||t.has(i.value))&&o!==void 0)r.push({kind:`require`,specifier:o,...i.value!==`require`&&{callee:i.value}});else if(i.value===`import`&&a)o!==void 0&&r.push({kind:`dynamic-import`,specifier:o});else if(i.value===`import`||i.value===`export`){let t=rr(n,e);t&&r.push(t)}}return r}var or=/^[\w$]*__d\(/gmu,sr=([e,t,n,...r])=>(typeof e==`number`||typeof e==`string`)&&(t===void 0||typeof t==`object`)&&(n===void 0||typeof n==`string`)&&r.length===0;function cr(e){let t=/\);?\s*$/u.exec(e)?.index,n=null,r=t===void 0?-1:e.lastIndexOf(`},`,t);for(;r>=0&&/[\d"]/u.test(e[r+2]);){let i;try{i=JSON.parse(`[${e.slice(r+2,t)}]`)}catch{break}if(!sr(i))break;n=i,r=r>0?e.lastIndexOf(`},`,r-1):-1}return n}function lr(e){let t=/^[^(]*\(\s*(?:function\s*[\w$]*\s*)?\(([^)]*)\)/u.exec(e)?.[1].split(`,`).slice(1,4).map(e=>e.trim().replaceAll(`$`,`\\$`));if(!t?.length)return[];let n=e.matchAll(RegExp(`(?<=[^\\w$.#]|\\.\\.\\.)(?:${t.join(`|`)})\\((\\d+|"(?:[^"\\\\]|\\\\.)*")[,)]`,`gu`));return[...new Set([...n].map(e=>JSON.parse(e[1])))]}function ur(e,t){if(Array.isArray(e))return e;let n=Object.entries(e??{}).filter(([e])=>/^\d+$/u.test(e)).map(([,e])=>e);return n.length>0?n:lr(t)}function dr(e,t){let n=new Map(t.files.map((e,t)=>[e,t])),r=e.flatMap((e,t)=>e.file?[{k:t,at:n.get(e.file)}]:[]);for(let n=0;n<(r[0]?.k??0);n++)e[n].file=t.files[r[0].at-r[0].k+n]??null;for(let[n,{k:i,at:a}]of r.entries()){let o=r[n+1];if(!(o&&o.at-a!==o.k-i))for(let n=i+1;n<(o?.k??e.length);n++)e[n].file=t.files[a+n-i]??null}}function fr(e,t){let n=[...e.matchAll(or)].map(e=>e.index);if(n.length===0)return null;let r=jn(e),i=t=>e.slice(r[t],r[t+1]),a=[];for(let[o,s]of n.entries()){let[c]=K(r,s),[l]=K(r,(n[o+1]??e.length)-1),u=cr(i(l));for(;!u&&l>c;)u=cr(i(--l));if(!u)throw Error(`bundleEdges: the Metro module at line ${c+1} ends in no define params`);let d=r[l+1]??e.length;a.push({id:u[0],file:Pn(t,r,s,d),dependencies:ur(u[1],e.slice(s,d))})}dr(a,t);let o=new Map(a.map(e=>[e.id,e])),{edges:s,link:c}=hn();for(let{file:e,dependencies:t}of a)for(let n of t)c(e,o.get(n)?.file,`dependency`);return s}var pr=e=>e.path!==null&&![`json`,null].includes(en(e.path)),mr=e=>e.path!==null&&en(e.path)===null;function hr(e){let t=/^_([A-Za-z]+)\d+$/u.exec(e)?.[1];if(t)return[t,`interopRequireDefault`];let n=/^_(interopRequire(?:Default|Wildcard)|jsx(?:Dev)?Runtime|callSuper)$/u.exec(e)?.[1];return n===`callSuper`?[`getPrototypeOf`,`possibleConstructorReturn`,`interopRequireDefault`]:n?[n]:[]}var gr={jsxRuntime:`react/jsx-runtime`,jsxDevRuntime:`react/jsx-dev-runtime`};function _r(e){let{sources:t,names:n,nameList:r}=wn(e),i=new Map,a=new Map,o=e.files.map(()=>new Set);for(let e=0;e<n.length;e++)n[e]<0||t[e]<0||(a.has(n[e])||a.set(n[e],hr(r[n[e]]).length>0),a.get(n[e])&&o[t[e]].add(r[n[e]]));for(let[t,n]of o.entries()){if(n.size===0)continue;let r=e.files[t],a=new Set(Array.from((r.content??``).matchAll(/(?:function|var|let|const)\s+(_[A-Za-z]+\d*)\b/gu),e=>e[1])),o=[...n].filter(e=>!a.has(e)&&!a.has(e.replace(/\d+$/u,``))).flatMap(hr);o.length>0&&i.set(r,o.map(e=>gr[e]??`@babel/runtime/helpers/${e}`))}return i}function vr(e,t){let n=new Map;for(let[r,i]of e){let e=n.get(r)??n.set(r,new Map).get(r);for(let n of i)e.set(n,vn(t,r,n,()=>null))}let r=new Set([...n.values()].flatMap(e=>[...e.values()].map(e=>e.to))),i=(e,n)=>t.byRoot.get(n).find(e=>!r.has(e))??t.byRoot.get(n)[0];return(e,r)=>{let a=n.get(e)?.get(r);return a?.to?a:vn(t,e,r,i)}}var yr=e=>/(?:^|\/)__prelude__$/u.test(e.source??``),br=e=>e?.package?.name===`metro-runtime`&&e.package.path===`src/polyfills/require.js`;function xr(e){if(!e.files.some(yr)&&!br(e.files[0]))return null;if(!e.files.some(e=>e.content!==null&&!yr(e)&&!br(e)))throw Error("bundleEdges: the Metro map carries no sourcesContent, which its edges are read from; pass the bundle as `code`");let t=dn(e.files),n=e.files[e.files.findIndex(mr)+1],r=e.files.find(e=>e.package?.name===`metro-runtime`&&e.package.path===`src/modules/asyncRequire.js`),i=new Map(e.files.filter(e=>e.content!==null&&pr(e)).map(e=>[e,ar(e.content)])),a=_r(e),o=vr([...[...i].map(([e,t])=>[e,t.flatMap(({specifier:e})=>e===null?[]:[e])]),...a],t),{edges:s,add:c,link:l}=hn();for(let t of e.files){mr(t)&&l(t,n,`dependency`);for(let{kind:e,specifier:n}of i.get(t)??[]){let i=n===null?{to:null}:o(t,n);i.to!==t&&c(t,`${e}\0${JSON.stringify(n)}`,{from:t,kind:e,specifier:n,...i}),e===`dynamic-import`&&l(t,r,`dependency`)}for(let e of a.get(t)??[])l(t,o(t,e).to,`dependency`)}return s}var Sr=(e,t)=>t==null?xr(e):fr(t,e);function Cr(e,t){let n=Sr(e,t);if(!n)throw Error(`bundleEdges: not a Metro ${t==null?`map`:`bundle`}; edges-lite.js reads only those, edges.js reads others`);return{edges:n}}function wr(e){let t=JSON.parse(e.replace(/^\)\]\}'[^\n]*\n/u,``)),n=kn(t),r=t.sections?t.sections.reduce((e,t)=>e+(t.map.names?.length??0),0):t.names?.length??null;return{json:{version:t.version,file:t.file,sourceRoot:t.sourceRoot},map:n,namesCount:r}}function Tr(e){if(e.map)return e.map.files.flatMap(e=>e.source===null?[]:[[e.source,e.content]]);let t=e.json?.sourcesContent??[];return(e.json?.sources??[]).map((e,n)=>[e,t[n]??null])}function Er(e,t){let n=new Map;for(let{from:r,to:i,specifier:a}of t(e).edges){if(r.source===null||i?.source==null||i.source===r.source)continue;let e=typeof a==`string`?[r.source,i.source,a]:[r.source,i.source];n.set(e.join(`\0`),e)}return[...n.values()]}function Dr(e){try{return Cr(e)}catch{return{edges:[]}}}var Or=Object.freeze([]);function X(e){return e?.edges?e.edges:e?.map?(e.edges=Er(e.map,Dr),e.edges):Or}var kr=new WeakMap,Ar=new WeakMap;function jr(e){let t=X(e);if(!kr.has(t)){let e=new Map;for(let[n,r]of t)e.has(n)||e.set(n,new Set),e.get(n).add(r);kr.set(t,e)}return kr.get(t)}function Mr(e){let t=X(e);if(!Ar.has(t)){let e=new Map;for(let[n,r,i]of t)i!==void 0&&(e.has(n)||e.set(n,new Map),e.get(n).set(i,r));Ar.set(t,e)}return Ar.get(t)}var Nr=new WeakMap,Pr=new WeakMap,Fr=new WeakMap,Ir=new WeakMap,Lr=new WeakMap,Rr=new WeakMap;function Z(e){if(e?.metadataOnly)return new Map;let t=e?.bundle??e?.json;if(t&&Nr.has(t))return Nr.get(t);let n=new Map;if(!e)return n;if(e.kind===`stasis`){if(!e.bundle)return n;let t=e.bundle.formats;for(let[r,i]of e.bundle.sources)typeof i==`string`&&(F.isResourceFormat(t?.get(r))||n.set(r,i))}else if(e.kind===`sourcemap`)for(let[t,r]of Tr(e))typeof r==`string`&&n.set(t,r);return t&&Nr.set(t,n),n}function zr(e){let t=1;for(let n=e.indexOf(`
|
|
11
|
-
`);n!==-1;n=e.indexOf(`
|
|
12
|
-
`,n+1))t++;return t}var Br=new WeakMap;function Vr(e){let t=Br.get(e);if(!t){let n=[...e.keys()].toSorted();t={paths:n,numbers:new Map(n.map((e,t)=>[e,t+1]))},Br.set(e,t)}return t}function Hr(e,t){let n=Array.isArray(t)?t:[];return{integrity:e.integrity,kind:`sourcemap`,size:e.size,json:{version:3,sources:n.map(([e])=>e),sourcesContent:n.map(([,,e])=>typeof e==`string`?e:null)},fileSizes:new Map(n.map(([e,t])=>[e,t])),npmBinaries:new Map(n.filter(([,,e,t])=>typeof e!=`string`&&typeof t==`string`).map(([e,t,,n])=>[e,{size:t,digest:n}]))}}function Ur(e){let t=e?.bundle??e?.json;if(t&&Pr.has(t))return Pr.get(t);let n=new Map(Z(e));for(let[t,r]of e?.npmBinaries??[])n.set(t,{format:`digest`,...r});if(e?.kind===`stasis`&&e.bundle){let t=e.bundle.formats;for(let[r,i]of e.bundle.sources){if(typeof i!=`string`)continue;let e=t?.get(r);e===`resource`?n.set(r,i):e===`resource:base64`&&n.set(r,{format:`base64`,data:i})}}return t&&Pr.set(t,n),n}var Wr=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;function Gr(e){let t=e.endsWith(`=`);if(t?e.length%4!=0||e.at(-3)===`=`:e.length%4==1)return null;let n=t?e.slice(0,e.endsWith(`==`)?-2:-1):e;if(/[^A-Za-z0-9+/]/u.test(n))return null;let r=n.length%4;return r>1&&Wr.indexOf(n.at(-1))&(r===2?15:3)?null:Math.floor(n.length*3/4)}function Kr(e){return typeof e==`string`?t(e):e?.format===`digest`?e.size:e?.format===`base64`?Gr(e.data):null}function Q(e){if(e?.fileSizes)return e.fileSizes;let t=e?.bundle??e?.json;if(t&&Fr.has(t))return Fr.get(t);let n=new Map,r=Ur(e),i=e?.kind===`stasis`?e.bundle?.sources.keys():e&&Tr(e).map(([e])=>e);for(let e of i??[])n.set(e,Kr(r.get(e)));return t&&Fr.set(t,n),n}function qr(e){if(e?.metadataOnly)return e.unsizedFiles??new Set;let t=Q(e);if(Rr.has(t))return Rr.get(t);let n=new Set;for(let r of Ur(e).keys())t.get(r)===null&&n.add(r);return Rr.set(t,n),n}function Jr(e){let t=Q(e);if(Lr.has(t))return Lr.get(t);let n=qr(e),r=e?.kind===`stasis`?e.bundle?.formats:null,i=new Map;for(let[a,o]of t)o===null&&!n.has(a)||i.set(a,F.isResourceFormat(r?.get(a))||e?.npmBinaries?.has(a)?`resource`:`source`);return Lr.set(t,i),i}function Yr(e){let t=Q(e),n=e?.kind===`stasis`?e.bundle?.formats:null;if(!n||n.size===0)return t;if(Ir.has(t))return Ir.get(t);let r=new Map;for(let[e,i]of t)F.isResourceFormat(n.get(e))||r.set(e,i);return Ir.set(t,r),r}var Xr=new WeakMap;function Zr(e){if(e?.kind!==`stasis`||!e.bundle?.modules)return null;if(Xr.has(e.bundle))return Xr.get(e.bundle);let t=new Map;for(let[n,r]of e.bundle.modules)for(let e of Object.keys(r.files))t.set(n===`.`?e:`${n}/${e}`,n);return Xr.set(e.bundle,t),t}function Qr(e,t=null,n=(e,t)=>t.name){let r=new Map;if(e?.kind!==`stasis`||!e.bundle?.modules)return r;let i=t===null?null:Zr(e),a=t===null?null:new Set([...t].map(e=>i?.get(e)));for(let[t,i]of e.bundle.modules){if(a&&!a.has(t)||!t.includes(`node_modules`)||!i?.name||typeof i.version!=`string`||!i.version)continue;let e=n(t,i),o=r.get(e);o||(o=new Set,r.set(e,o)),o.add(i.version)}return r}var $r=Object.freeze({javascript:`JavaScript`,jsx:`JSX`,typescript:`TypeScript`,tsx:`TSX`,json:`JSON`,css:`CSS`,markup:`HTML`,yaml:`YAML`,bash:`Shell`,markdown:`Markdown`,solidity:`Solidity`,php:`PHP`,rust:`Rust`,ruby:`Ruby`,java:`Java`,cpp:`C++`,c:`C`,objectivec:`Objective-C`,python:`Python`,go:`Go`,kotlin:`Kotlin`,swift:`Swift`,dart:`Dart`,sql:`SQL`,lua:`Lua`,csharp:`C#`,scala:`Scala`,vue:`Vue`,svelte:`Svelte`}),ei=Object.freeze({py:`python`,pyw:`python`,go:`go`,kt:`kotlin`,kts:`kotlin`,swift:`swift`,dart:`dart`,sql:`sql`,lua:`lua`,cs:`csharp`,scala:`scala`,sc:`scala`,vue:`vue`,svelte:`svelte`});function ti(e){let t=typeof e==`string`?e.slice(e.lastIndexOf(`/`)+1):``,n=t.lastIndexOf(`.`),r=n>0?t.slice(n+1).trim().toLowerCase():``,i=Rt(e)??ei[r];return i?{key:i,label:$r[i]??i}:r?{key:`extension:${r}`,label:`.${r}`}:{key:`other`,label:`Other`}}function ni(e,t){let n=new Map,r=0,i=0;for(let[a,o]of e){let e=ti(a),s=n.get(e.key)??{...e,files:0,lines:0,bytes:0};s.files++,s.lines+=o,s.bytes+=t.get(a)??0,n.set(e.key,s),i+=o,r+=t.get(a)??0}return{files:e.size,lines:i,bytes:r,languages:[...n.values()].toSorted((e,t)=>t.lines-e.lines||e.label.localeCompare(t.label))}}var ri=6,$=new WeakMap,ii=new Set([`terminal`,`code`,`search`,`compare`]);function ai(e,t=null){return!!t||ii.has(e)}var oi=/^sha512-[A-Za-z0-9+/]{86}==$/u;function si(t){if(t.fileHashes)return Promise.resolve(t.fileHashes);if($.has(t))return $.get(t);let n=(async()=>{let n=[...Z(t)],r=new Map;for(let t=0;t<n.length;t+=32){let i=await Promise.all(n.slice(t,t+32).map(async([t,n])=>[t,await e(n)]));for(let[e,t]of i)r.set(e,t)}return t.fileHashes=r,r})();return $.set(t,n),n.catch(()=>$.delete(t)),n}function ci(e){if(typeof e!=`string`)return 0;let t=/\S/gu,n=/[\r\n]/gu,r=0;for(;t.test(e)&&(r++,n.lastIndex=t.lastIndex,n.test(e));)t.lastIndex=n.lastIndex;return r}function li(e){return e.lineCounts??=new Map([...Z(e)].map(([e,t])=>[e,ci(t)]))}function ui(e){return e instanceof Map?Object.fromEntries([...e].map(([e,t])=>[e,ui(t)])):e}async function di(e){let n=await si(e),r=Q(e),i=li(e),a={version:ri,integrity:e.integrity,kind:e.kind,size:e.size,codeStats:ni(i,r),files:[...r].map(([e,t])=>[e,t,n.get(e)??null,i.get(e)??null])},o=qr(e);if(o.size>0&&(a.unsized=[...o]),e.kind===`sourcemap`){let{version:n,file:r,sourceRoot:i,names:o}=e.json,s=Tr(e);a.json={version:n,file:r,sourceRoot:i,sources:s.map(([e])=>e)},a.sourceSizes=s.map(([,e])=>typeof e==`string`?t(e):null),a.namesCount=e.namesCount??o?.length??null;let c=new Map(a.files.map(([e],t)=>[e,t]));a.edges=X(e).map(([e,t,...n])=>[c.get(e),c.get(t),...n])}else{let t=e.bundle,n={version:t.version,config:t.config,repo:t.repo,package:t.package,formats:ui(t.formats),imports:ui(t.imports),reason:t.reason,executable:[...t.executable]};if(t.version===0)n.sources=Object.fromEntries([...r.keys()].map(e=>[e,null]));else{let e={},r={};for(let[n,i]of t.modules){let t=n.split(`/`).includes(`node_modules`)?e:r;Object.defineProperty(t,n,{enumerable:!0,value:{name:i.name,version:i.version,ecosystem:i.ecosystem,repo:i.repo,files:Object.fromEntries(Object.keys(i.files).map(e=>[e,null]))}})}n.modules=e,t.config.scope===`full`&&(n.sources=r,n.entries=[...t.entries])}a.bundle=n}return a}function fi(e,t){if(![1,2,3,4,5,ri].includes(e?.version)||e.integrity!==t||![`stasis`,`sourcemap`].includes(e.kind)||!Number.isSafeInteger(e.size)||e.size<0||!Array.isArray(e.files))throw Error(`Invalid bundle metadata`);let n=e.version!==ri,r=e.version===1,i=new Map,a=new Map,o=new Map;for(let t of e.files){if(!Array.isArray(t)||t.length!==4&&!(r&&t.length===3))throw Error(`Invalid bundle metadata file`);let[e,n,s,c]=t;if(typeof e!=`string`||a.has(e)||n!==null&&(!Number.isSafeInteger(n)||n<0)||s!==null&&(typeof s!=`string`||!oi.test(s))||n===null&&s!==null||r&&n!==null&&s===null||c!=null&&(!Number.isSafeInteger(c)||c<0))throw Error(`Invalid bundle metadata file`);a.set(e,n),s!==null&&i.set(e,s),c!=null&&o.set(e,c)}let s=new Set(e.unsized??[]);if(e.unsized!==void 0&&(r||!Array.isArray(e.unsized)||s.size!==e.unsized.length)||[...s].some(e=>typeof e!=`string`||!a.has(e)||a.get(e)!==null))throw Error(`Invalid bundle metadata`);let c={integrity:t,kind:e.kind,size:e.size,metadataOnly:!0,fileSizes:a,fileHashes:i,lineCounts:o,unsizedFiles:s,stale:n};if(e.kind===`stasis`){c.bundle=F.fromJSON(e.bundle);let t=c.bundle.sources;if(t.size!==a.size||[...t.keys()].some(e=>!a.has(e)))throw Error(`Invalid bundle metadata inventory`);let n=c.bundle.formats;if(!r&&[...a].some(([e,t])=>i.has(e)!==(t!==null&&!F.isResourceFormat(n.get(e))))||[...s].some(e=>n.get(e)!==`resource:base64`))throw Error(`Invalid bundle metadata inventory`)}else{if(!e.json||typeof e.json!=`object`||![null,void 0].includes(e.namesCount)&&(!Number.isSafeInteger(e.namesCount)||e.namesCount<0))throw Error(`Invalid sourcemap metadata`);if(!Array.isArray(e.json.sources)||e.json.sources.some(e=>!a.has(e))||!Array.isArray(e.sourceSizes)||e.sourceSizes.length!==e.json.sources.length||e.sourceSizes.some(e=>e!==null&&(!Number.isSafeInteger(e)||e<0))||[...a].some(([e,t])=>i.has(e)!==(t!==null))||s.size>0)throw Error(`Invalid sourcemap inventory`);c.json=e.json,c.sourceSizes=e.sourceSizes,c.namesCount=e.namesCount,e.edges!==void 0&&(c.edges=pi(e.edges,e.files))}if(e.codeStats===void 0)c.codeStats=ni(o,a);else{let t=e.codeStats,n=e=>Number.isSafeInteger(e)&&e>=0;if(!t||![t.files,t.lines,t.bytes].every(n)||!Array.isArray(t.languages)||t.languages.some(e=>!e||typeof e.key!=`string`||typeof e.label!=`string`||![e.files,e.lines,e.bytes].every(n)))throw Error(`Invalid bundle code stats`);c.codeStats=t}return c}function pi(e,t){if(!Array.isArray(e))throw Error(`Invalid sourcemap edges`);return e.map(e=>{if(!Array.isArray(e)||![2,3].includes(e.length)||e[0]===e[1]||e.length===3&&typeof e[2]!=`string`||e.slice(0,2).some(e=>!Number.isSafeInteger(e)||e<0||e>=t.length))throw Error(`Invalid sourcemap edges`);return[t[e[0]][0],t[e[1]][0],...e.slice(2)]})}function mi(e,{integrity:t,kind:n,size:r}){if(n===`stasis`)return{integrity:t,kind:n,size:r,bundle:F.parse(e)};if(n!==`sourcemap`)throw Error(`Unsupported bundle format`);return{integrity:t,kind:n,size:r,...wr(e)}}export{At as a,F as b,Rt as c,X as d,jr as e,Mr as f,Z as g,zr as h,Vr as i,Hr as j,Ur as k,Kr as l,Q as m,Jr as n,Yr as o,Zr as p,Qr as q,ni as r,ai as s,si as t,ci as u,li as v,di as w,fi as x,mi as y};
|