@exodus/stasis 1.0.0-beta.15 → 1.0.0-beta.16
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/README.md +1 -1
- package/bin/stasis.js +19 -6
- package/package.json +10 -9
- package/src/audit-corrections.js +11 -42
- package/src/audit.js +113 -233
- package/src/babel.js +39 -122
- package/src/bundle-from-lockfile.js +9 -21
- package/src/bundle-reader.js +5 -9
- package/src/bundle.js +0 -3
- package/src/cmd/build.js +50 -166
- package/src/cmd/bundle-options.js +110 -167
- package/src/cmd/bundle.js +853 -1344
- package/src/cmd/diff.js +1 -4
- package/src/cmd/github-bundle.js +18 -22
- package/src/cmd/output.js +15 -12
- package/src/cmd/sbom.js +3 -8
- package/src/cmd/tokens.js +10 -23
- package/src/define.js +34 -97
- package/src/diff.js +72 -128
- package/src/esbuild.js +0 -4
- package/src/flow.js +10 -25
- package/src/installed.js +265 -0
- package/src/json-stream.js +4 -9
- package/src/loader-mock.js +3 -8
- package/src/loader.js +1 -5
- package/src/loaders/bash.js +41 -93
- package/src/loaders/cargo.js +298 -805
- package/src/loaders/foundry.js +109 -285
- package/src/loaders/paths.js +13 -13
- package/src/loaders/php.js +210 -489
- package/src/loaders/rust.js +507 -1430
- package/src/loaders/solidity-ownership.js +48 -128
- package/src/loaders/solidity.js +39 -122
- package/src/loaders/toml.js +7 -17
- package/src/lockfile.js +0 -3
- package/src/metro-assets.js +9 -33
- package/src/metro-resolver.js +20 -47
- package/src/metro-transformer.js +0 -5
- package/src/metro.js +0 -4
- package/src/mock.js +32 -80
- package/src/parse.js +2 -5
- package/src/prune.js +0 -3
- package/src/resolve-fields.js +90 -220
- package/src/resolve-node.js +27 -45
- package/src/resolve-typescript.js +109 -313
- package/src/rollup.js +0 -4
- package/src/run-installed.js +10 -0
- package/src/sbom.js +52 -128
- package/src/scan.js +136 -283
- package/src/sixel.js +18 -41
- package/src/table.js +14 -35
- package/src/validate-notes.d.ts +3 -2
- package/src/validate-notes.js +25 -19
- package/src/validate.d.ts +38 -11
- package/src/validate.js +478 -512
- package/src/vfs-bundle/entries.js +40 -57
- package/src/vfs-bundle/github.js +77 -121
- package/src/vfs-bundle/glob.js +4 -45
- package/src/vfs-bundle/lazy.js +27 -56
- package/src/vfs-bundle/prisma.js +167 -110
- package/src/vfs-bundle/soldeer.js +28 -49
- package/src/vfs-bundle/tree.js +295 -318
- package/src/vfs-bundle/yarnclean.js +10 -31
- package/src/vfs-bundle.js +23 -64
- package/src/webpack.js +0 -4
- package/src/why.js +75 -231
- package/src/installed-commits.js +0 -184
package/src/installed-commits.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { hash } from 'node:crypto'
|
|
2
|
-
import { dirname, join, relative, resolve } from 'node:path'
|
|
3
|
-
|
|
4
|
-
import { toBase32 } from '@exodus/bytes/base32.js'
|
|
5
|
-
import { isValidRepoField } from '@exodus/stasis-core/bundle'
|
|
6
|
-
import { parseGithubRepository, readJson, readText } from '@exodus/stasis-core/bundle-util'
|
|
7
|
-
import { diskHost } from '@exodus/stasis-core/host'
|
|
8
|
-
import { isPlainObject, relativeEscapes, toPosix } from '@exodus/stasis-core/util'
|
|
9
|
-
import { parsePnpmLockfile } from '@preventive/lockfile/pnpm.js'
|
|
10
|
-
import { parseYarn1Lockfile } from '@preventive/lockfile/yarn1.js'
|
|
11
|
-
|
|
12
|
-
// The commit each git dependency in a node_modules on disk is installed at, as the package manager
|
|
13
|
-
// that laid it out recorded it there: npm in its hidden lockfile, pnpm in its copy of the lockfile,
|
|
14
|
-
// yarn 1 in yarn.lock, as its .yarn-integrity has it installed. Nothing on disk names a registry
|
|
15
|
-
// package's. A record missing, unreadable, or naming no full commit of a GitHub repository records
|
|
16
|
-
// nothing, and fails nothing.
|
|
17
|
-
|
|
18
|
-
// `{ github, commit }` of `repo`, a git URL, at `commit`, where that is a GitHub repository and a full
|
|
19
|
-
// commit id; else undefined.
|
|
20
|
-
function githubCommit(repo, commit) {
|
|
21
|
-
const github = parseGithubRepository(repo)
|
|
22
|
-
return github !== null && isValidRepoField('commit', commit) ? { github, commit } : undefined
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// GitHub's tarball of a commit, as yarn 1 and pnpm fetch a GitHub dependency.
|
|
26
|
-
const CODELOAD = /^https:\/\/codeload\.github\.com\/([^/]+\/[^/]+)\/tar\.gz\/([^/]+)$/u
|
|
27
|
-
const githubTarball = (url) => {
|
|
28
|
-
const [, github, commit] = CODELOAD.exec(url) ?? []
|
|
29
|
-
return isValidRepoField('github', github) ? githubCommit(github, commit) : undefined
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// githubCommit of a git or tarball resolution @preventive/lockfile reads.
|
|
33
|
-
export const resolutionCommit = (resolution) => {
|
|
34
|
-
if (resolution?.type === 'git') return githubCommit(resolution.repo, resolution.commit)
|
|
35
|
-
return resolution?.type === 'tarball' ? githubTarball(resolution.tarball ?? '') : undefined
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// The lookup of a record that finds nothing: one unreadable, or none.
|
|
39
|
-
const NONE = () => undefined
|
|
40
|
-
|
|
41
|
-
// npm's, from npm 7: the hidden lockfile it writes into `dir`'s node_modules as it lays it out, by
|
|
42
|
-
// each package's location from `dir`, where it records the version installed there. A git
|
|
43
|
-
// dependency's `resolved` is the URL npm clones, `#` and the commit.
|
|
44
|
-
function npmRecord(dir, host) {
|
|
45
|
-
const packages = readJson(join(dir, 'node_modules', '.package-lock.json'), host)?.packages
|
|
46
|
-
if (!isPlainObject(packages)) return NONE
|
|
47
|
-
return (location, version) => {
|
|
48
|
-
const entry = Object.hasOwn(packages, location) ? packages[location] : undefined
|
|
49
|
-
if (!isPlainObject(entry) || entry.version !== version || typeof entry.resolved !== 'string') return undefined
|
|
50
|
-
const { resolved } = entry
|
|
51
|
-
if (!/^git(?:\+[\w.-]+)?:/u.test(resolved)) return githubTarball(resolved)
|
|
52
|
-
const at = resolved.lastIndexOf('#')
|
|
53
|
-
return at === -1 ? undefined : githubCommit(resolved.slice(0, at), resolved.slice(at + 1))
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// yarn 1's: yarn.lock in `dir`, by the name a package is installed as, the last of its location, and
|
|
58
|
-
// its version, where one entry alone has both. The .yarn-integrity yarn writes into the node_modules
|
|
59
|
-
// it lays out has to hold the entry's resolution for each of its patterns, as yarn.lock's `resolved`
|
|
60
|
-
// spells it: a yarn.lock changed since often moves a git dependency to another commit of one version.
|
|
61
|
-
function yarnRecord(dir, host) {
|
|
62
|
-
const installed = readJson(join(dir, 'node_modules', '.yarn-integrity'), host)?.lockfileEntries
|
|
63
|
-
const text = readText(host, join(dir, 'yarn.lock'))
|
|
64
|
-
if (!isPlainObject(installed) || text === null) return NONE
|
|
65
|
-
let packages
|
|
66
|
-
try {
|
|
67
|
-
packages = parseYarn1Lockfile(text, { checkVersions: false }).packages
|
|
68
|
-
} catch {
|
|
69
|
-
return NONE // whatever the reader refuses
|
|
70
|
-
}
|
|
71
|
-
const byVersion = new Map()
|
|
72
|
-
for (const { patterns, name, version, resolution } of new Set(Object.values(packages))) {
|
|
73
|
-
let commit = resolutionCommit(resolution)
|
|
74
|
-
const resolved = resolution?.type === 'git' ? `${resolution.repo}#${resolution.commit}` : resolution?.sha1 === undefined ? resolution?.tarball : `${resolution.tarball}#${resolution.sha1}`
|
|
75
|
-
if (!patterns.every((pattern) => Object.hasOwn(installed, pattern) && installed[pattern] === resolved)) commit = undefined
|
|
76
|
-
// Of two entries of one name and version, either may be the one installed.
|
|
77
|
-
const id = `${name}@${version}`
|
|
78
|
-
byVersion.set(id, byVersion.has(id) ? undefined : commit)
|
|
79
|
-
}
|
|
80
|
-
return (location, version) => byVersion.get(`${location.slice(location.lastIndexOf('node_modules/') + 'node_modules/'.length)}@${version}`)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// What npm and yarn leave in a node_modules they lay out, and the reader of each one's record.
|
|
84
|
-
const LAYOUTS = [['.package-lock.json', npmRecord], ['.yarn-integrity', yarnRecord]]
|
|
85
|
-
|
|
86
|
-
// The names pnpm 9 to 12 may give snapshot `key`'s directory in node_modules/.pnpm, as its
|
|
87
|
-
// depPathToFilename (@pnpm/dependency-path) spells them: each character a path can't hold made `+`,
|
|
88
|
-
// `#` too from pnpm 10, and a peer's parentheses `_`; where that is too long or has a capital, cut
|
|
89
|
-
// short before `_` and a hash of it, 26 base32 of an MD5 for pnpm 9, 32 hex of a SHA-256 from pnpm 10,
|
|
90
|
-
// of which the hash alone is kept, as where it is cut depends on the install's
|
|
91
|
-
// virtualStoreDirMaxLength.
|
|
92
|
-
const STORE_NAMES = [
|
|
93
|
-
[/[\\/:*?"<>|]/gu, (name) => toBase32(hash('md5', name, 'buffer'), { padding: false }).toLowerCase()],
|
|
94
|
-
[/[\\/:*?"<>|#]/gu, (name) => hash('sha256', name).slice(0, 32)],
|
|
95
|
-
]
|
|
96
|
-
const storeNames = (key) => STORE_NAMES.flatMap(([unsafe, digest]) => {
|
|
97
|
-
let name = key.replace(unsafe, '+')
|
|
98
|
-
if (name.includes('(')) name = name.replace(/\)$/u, '').replace(/\)\(|\(|\)/gu, '_')
|
|
99
|
-
return [name, `_${digest(name)}`]
|
|
100
|
-
})
|
|
101
|
-
// The hash pnpm ends a store directory's name with where it cuts a long one short: pnpm 10's hex,
|
|
102
|
-
// or the base32 of those before.
|
|
103
|
-
export const STORE_HASH = /_(?:[\da-f]{32}|[a-z2-7]{26})$/u
|
|
104
|
-
|
|
105
|
-
// pnpm's: lock.yaml in `store`, a node_modules/.pnpm, the lockfile of what pnpm 9 to 12 installed
|
|
106
|
-
// there, by the directory there each snapshot is in. A git dependency's resolution is the repository
|
|
107
|
-
// and commit, or GitHub's tarball of the commit, and the package's `path` in it (`#path:`) where it is
|
|
108
|
-
// not at the root.
|
|
109
|
-
function pnpmRecord(store, host) {
|
|
110
|
-
const text = readText(host, join(store, 'lock.yaml'))
|
|
111
|
-
let packages
|
|
112
|
-
try {
|
|
113
|
-
packages = text === null ? undefined : parsePnpmLockfile(text).lockfile?.packages
|
|
114
|
-
} catch {
|
|
115
|
-
return NONE // whatever the reader refuses
|
|
116
|
-
}
|
|
117
|
-
const byName = new Map()
|
|
118
|
-
for (const [key, { resolution }] of Object.entries(packages ?? {})) {
|
|
119
|
-
const commit = resolutionCommit(resolution)
|
|
120
|
-
if (commit === undefined) continue
|
|
121
|
-
const directory = (resolution.path ?? '').replace(/^\/+|\/+$/gu, '')
|
|
122
|
-
const repo = { github: commit.github, ...(isValidRepoField('directory', directory) && { directory }), commit: commit.commit }
|
|
123
|
-
for (const name of storeNames(key)) byName.set(name, repo)
|
|
124
|
-
}
|
|
125
|
-
return (name) => byName.get(name) ?? byName.get(STORE_HASH.exec(name)?.[0])
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// A pnpm package's real path, <store>/<dir>/node_modules/<name>, its store a node_modules/.pnpm.
|
|
129
|
-
const PNPM_PACKAGE = /^(.*\/node_modules\/\.pnpm)\/([^/]+)\/node_modules\/(?:@[^/]+\/)?[^/]+$/u
|
|
130
|
-
|
|
131
|
-
// Each npm dependency of `bundle`, its buckets' paths from `root`, that is a git dependency of a GitHub
|
|
132
|
-
// repository, recorded as its package manager's record has it installed: that repository, over the
|
|
133
|
-
// one its package.json names (a fork's, where that names the one forked), at its root (`''`) or the
|
|
134
|
-
// subdirectory pnpm records, at that commit. A dependency is found by its real path, through the link
|
|
135
|
-
// pnpm installs it by: in a node_modules/.pnpm, by its directory there; else by its location from the
|
|
136
|
-
// nearest directory whose node_modules npm or yarn laid out, from the one its outermost node_modules
|
|
137
|
-
// below the bundle root is in up to that root, whatever a directory above the root is named: a
|
|
138
|
-
// record outside the root is another project's. Metadata, as `repo` is: never checked against the
|
|
139
|
-
// files installed.
|
|
140
|
-
export function pinInstalledCommits(bundle, root, host = diskHost) {
|
|
141
|
-
const stores = new Map()
|
|
142
|
-
const layouts = new Map()
|
|
143
|
-
let top // the bundle root's real path, as each package's is compared with it
|
|
144
|
-
// The record of `dir`'s node_modules, or null where neither npm nor yarn laid it out; where both
|
|
145
|
-
// left theirs, neither's, as which was last is not known.
|
|
146
|
-
const layoutAt = (dir) => {
|
|
147
|
-
if (!layouts.has(dir)) {
|
|
148
|
-
const found = LAYOUTS.filter(([file]) => host.stat(join(dir, 'node_modules', file)) !== null)
|
|
149
|
-
layouts.set(dir, found.length === 0 ? null : found.length === 1 ? found[0][1](dir, host) : NONE)
|
|
150
|
-
}
|
|
151
|
-
return layouts.get(dir)
|
|
152
|
-
}
|
|
153
|
-
for (const [dir, info] of bundle.modules) {
|
|
154
|
-
if (info.ecosystem !== 'npm') continue
|
|
155
|
-
let real
|
|
156
|
-
try {
|
|
157
|
-
real = toPosix(host.realpath(resolve(root, dir)))
|
|
158
|
-
} catch {
|
|
159
|
-
continue
|
|
160
|
-
}
|
|
161
|
-
let repo
|
|
162
|
-
const pnpm = PNPM_PACKAGE.exec(real)
|
|
163
|
-
if (pnpm !== null) {
|
|
164
|
-
const [, store, name] = pnpm
|
|
165
|
-
if (!stores.has(store)) stores.set(store, pnpmRecord(store, host))
|
|
166
|
-
repo = stores.get(store)(name)
|
|
167
|
-
} else {
|
|
168
|
-
try {
|
|
169
|
-
top ??= resolve(host.realpath(resolve(root)))
|
|
170
|
-
} catch {
|
|
171
|
-
return
|
|
172
|
-
}
|
|
173
|
-
const rel = relative(top, real)
|
|
174
|
-
const parts = toPosix(rel).split('/')
|
|
175
|
-
const at = parts.indexOf('node_modules')
|
|
176
|
-
if (relativeEscapes(rel) || at === -1) continue
|
|
177
|
-
let from = resolve(top, ...parts.slice(0, at))
|
|
178
|
-
while (layoutAt(from) === null && from !== top) from = dirname(from)
|
|
179
|
-
const commit = (layoutAt(from) ?? NONE)(toPosix(relative(from, real)), info.version)
|
|
180
|
-
if (commit !== undefined) repo = { github: commit.github, directory: '', commit: commit.commit }
|
|
181
|
-
}
|
|
182
|
-
if (repo !== undefined) bundle.modules.set(dir, { ...info, repo })
|
|
183
|
-
}
|
|
184
|
-
}
|