@exodus/stasis 1.0.0-beta.9 → 1.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +6 -2
  2. package/bin/stasis.js +222 -334
  3. package/package.json +38 -14
  4. package/src/audit-corrections.js +11 -42
  5. package/src/audit.js +256 -212
  6. package/src/babel.js +119 -82
  7. package/src/bundle-from-lockfile.js +9 -21
  8. package/src/bundle-reader.js +24 -8
  9. package/src/bundle.js +0 -3
  10. package/src/cmd/build.js +211 -117
  11. package/src/cmd/bundle-options.js +347 -0
  12. package/src/cmd/bundle.js +1664 -1001
  13. package/src/cmd/diff.js +1 -4
  14. package/src/cmd/github-bundle.js +48 -21
  15. package/src/cmd/output.js +24 -12
  16. package/src/cmd/sbom.js +6 -9
  17. package/src/cmd/tokens.js +60 -0
  18. package/src/define.js +218 -0
  19. package/src/diff.js +73 -129
  20. package/src/esbuild.js +0 -4
  21. package/src/flow.js +27 -0
  22. package/src/installed.js +265 -0
  23. package/src/json-stream.js +4 -9
  24. package/src/loader-mock.js +3 -8
  25. package/src/loader.js +1 -5
  26. package/src/loaders/bash.js +43 -120
  27. package/src/loaders/cargo.js +301 -808
  28. package/src/loaders/foundry.js +112 -290
  29. package/src/loaders/paths.js +15 -26
  30. package/src/loaders/php.js +211 -492
  31. package/src/loaders/rust.js +518 -1461
  32. package/src/loaders/solidity-ownership.js +51 -142
  33. package/src/loaders/solidity.js +42 -188
  34. package/src/loaders/toml.js +7 -17
  35. package/src/lockfile.js +0 -3
  36. package/src/metro-assets.js +41 -0
  37. package/src/metro-resolver.js +58 -133
  38. package/src/metro-transformer.js +0 -6
  39. package/src/metro.js +0 -4
  40. package/src/mock.js +32 -80
  41. package/src/parse.js +8 -7
  42. package/src/prune.js +0 -3
  43. package/src/resolve-fields.js +152 -249
  44. package/src/resolve-node.js +29 -45
  45. package/src/resolve-typescript.js +166 -298
  46. package/src/rollup.js +0 -4
  47. package/src/run-installed.js +10 -0
  48. package/src/sbom.js +70 -97
  49. package/src/scan.js +240 -282
  50. package/src/sixel.js +310 -0
  51. package/src/table.js +95 -0
  52. package/src/validate-notes.d.ts +19 -0
  53. package/src/validate-notes.js +72 -0
  54. package/src/validate.d.ts +159 -0
  55. package/src/validate.js +1315 -0
  56. package/src/vfs-bundle/entries.js +50 -46
  57. package/src/vfs-bundle/github.js +114 -94
  58. package/src/vfs-bundle/glob.js +379 -0
  59. package/src/vfs-bundle/lazy.js +99 -0
  60. package/src/vfs-bundle/prisma.js +235 -105
  61. package/src/vfs-bundle/soldeer.js +28 -49
  62. package/src/vfs-bundle/tree.js +418 -277
  63. package/src/vfs-bundle/yarnclean.js +79 -0
  64. package/src/vfs-bundle.js +24 -55
  65. package/src/webpack.js +0 -4
  66. package/src/why.js +79 -231
  67. package/src/installed-commits.js +0 -182
@@ -0,0 +1,379 @@
1
+ import { createRequire } from 'node:module'
2
+ import { posix } from 'node:path'
3
+
4
+ // Node 24.22.2's and 26.13.0's fs.globSync (internal/fs/glob.js, without `followSymlinks`, `maxDepth` or an array
5
+ // `exclude`) and path.matchesGlob over a `host`. Matching never folds case: git's names may differ by case alone.
6
+
7
+ const { join, resolve } = posix
8
+ const require = createRequire(import.meta.url)
9
+
10
+ const MINIMATCH = 'minimatch'
11
+ const MINIMATCH_MAJOR = '10'
12
+ const OPTIONS = { nocase: false, windowsPathsNoEscape: true, nonegate: true, nocomment: true, optimizationLevel: 2, platform: 'linux', nocaseMagicOnly: true }
13
+
14
+ let minimatch
15
+ export function loadMinimatch(what) {
16
+ if (minimatch) return minimatch
17
+ const needs = `${what} needs the optional '${MINIMATCH}' ${MINIMATCH_MAJOR} dependency`
18
+ let version
19
+ try {
20
+ version = require(`${MINIMATCH}/package.json`).version
21
+ } catch (cause) {
22
+ throw new Error(`${needs}; install it (e.g. \`npm i ${MINIMATCH}@${MINIMATCH_MAJOR}\`)`, { cause })
23
+ }
24
+ // Another package's, found where the optional one isn't installed.
25
+ if (version.split('.')[0] !== MINIMATCH_MAJOR) throw new Error(`${needs}, not ${version}`)
26
+ minimatch = require(MINIMATCH)
27
+ return minimatch
28
+ }
29
+
30
+ const lazyMinimatch = () => loadMinimatch("A glob over a Vfs (stasis.config.json's extra)")
31
+
32
+ export const checkGlob = () => void lazyMinimatch()
33
+
34
+ const createMatcher = (pattern) => new (lazyMinimatch().Minimatch)(pattern, OPTIONS)
35
+
36
+ function lstatOf(host, path) {
37
+ let link
38
+ try {
39
+ link = host.readlink(path)
40
+ } catch {
41
+ return null
42
+ }
43
+ const directory = link === null ? host.stat(path)?.isDirectory() : false
44
+ if (directory === undefined) return null
45
+ return { isDirectory: () => directory, isSymbolicLink: () => link !== null }
46
+ }
47
+
48
+ class Cache {
49
+ #host
50
+ #cache = new Map()
51
+ #statsCache = new Map()
52
+ #readdirCache = new Map()
53
+
54
+ constructor(host) {
55
+ this.#host = host
56
+ }
57
+ statSync(path) {
58
+ const cached = this.#statsCache.get(path)
59
+ if (cached) {
60
+ return cached
61
+ }
62
+ const val = lstatOf(this.#host, path)
63
+ this.#statsCache.set(path, val)
64
+ return val
65
+ }
66
+ addToStatCache(path, val) {
67
+ this.#statsCache.set(path, val)
68
+ }
69
+ readdirSync(path) {
70
+ const cached = this.#readdirCache.get(path)
71
+ if (cached) {
72
+ return cached
73
+ }
74
+ let val
75
+ try {
76
+ val = this.#host.readdir(path)
77
+ } catch {
78
+ val = []
79
+ }
80
+ this.#readdirCache.set(path, val)
81
+ return val
82
+ }
83
+ add(path, pattern) {
84
+ let cache = this.#cache.get(path)
85
+ if (!cache) {
86
+ cache = new Set()
87
+ this.#cache.set(path, cache)
88
+ }
89
+ const originalSize = cache.size
90
+ pattern.indexes.forEach((index) => cache.add(pattern.cacheKey(index)))
91
+ return cache.size !== originalSize + pattern.indexes.size
92
+ }
93
+ seen(path, pattern, index) {
94
+ return this.#cache.get(path)?.has(pattern.cacheKey(index))
95
+ }
96
+ }
97
+
98
+ class Pattern {
99
+ #pattern
100
+ #globStrings
101
+ indexes
102
+ symlinks
103
+ last
104
+
105
+ constructor(pattern, globStrings, indexes, symlinks) {
106
+ this.#pattern = pattern
107
+ this.#globStrings = globStrings
108
+ this.indexes = indexes
109
+ this.symlinks = symlinks
110
+ this.last = pattern.length - 1
111
+ }
112
+
113
+ isLast(isDirectory) {
114
+ return this.indexes.has(this.last) ||
115
+ (this.at(-1) === '' && isDirectory &&
116
+ this.indexes.has(this.last - 1) && this.at(-2) === lazyMinimatch().GLOBSTAR)
117
+ }
118
+ isFirst() {
119
+ return this.indexes.has(0)
120
+ }
121
+ get hasSeenSymlinks() {
122
+ return [...this.indexes].some((i) => !this.symlinks.has(i))
123
+ }
124
+ at(index) {
125
+ return this.#pattern.at(index)
126
+ }
127
+ child(indexes, symlinks = new Set()) {
128
+ return new Pattern(this.#pattern, this.#globStrings, indexes, symlinks)
129
+ }
130
+ test(index, path) {
131
+ if (index > this.#pattern.length) {
132
+ return false
133
+ }
134
+ const pattern = this.#pattern[index]
135
+ if (pattern === lazyMinimatch().GLOBSTAR) {
136
+ return true
137
+ }
138
+ if (typeof pattern === 'string') {
139
+ return pattern === path
140
+ }
141
+ if (typeof pattern?.test === 'function') {
142
+ return pattern.test(path)
143
+ }
144
+ return false
145
+ }
146
+
147
+ cacheKey(index) {
148
+ let key = ''
149
+ for (let i = index; i < this.#globStrings.length; i++) {
150
+ key += this.#globStrings[i]
151
+ if (i !== this.#globStrings.length - 1) {
152
+ key += '/'
153
+ }
154
+ }
155
+ return key
156
+ }
157
+ }
158
+
159
+ // Node's, but `exclude` takes absolute paths, and #addSubpattern stats paths from the root, not the process's cwd.
160
+ class Glob {
161
+ #root
162
+ #exclude
163
+ #cache
164
+ #results = new Set()
165
+ #queue = []
166
+ #subpatterns = new Map()
167
+ #patterns
168
+
169
+ constructor(host, pattern, { cwd, exclude }) {
170
+ this.#root = cwd
171
+ this.#exclude = exclude
172
+ this.#cache = new Cache(host)
173
+ const matcher = createMatcher(pattern)
174
+ this.#patterns = matcher.set.map((set, i) => new Pattern(set, matcher.globParts[i], new Set().add(0), new Set()))
175
+ }
176
+
177
+ globSync() {
178
+ this.#queue.push({ path: '.', patterns: this.#patterns })
179
+ while (this.#queue.length > 0) {
180
+ const item = this.#queue.pop()
181
+ for (let i = 0; i < item.patterns.length; i++) {
182
+ this.#addSubpatterns(item.path, item.patterns[i])
183
+ }
184
+ this.#subpatterns.forEach((patterns, path) => this.#queue.push({ path, patterns }))
185
+ this.#subpatterns.clear()
186
+ }
187
+ return [...this.#results]
188
+ }
189
+ #isDirectorySync(stat, pattern) {
190
+ if (stat?.isDirectory()) {
191
+ return true
192
+ }
193
+ if (!stat?.isSymbolicLink()) {
194
+ return false
195
+ }
196
+ return pattern.hasSeenSymlinks
197
+ }
198
+ #addSubpattern(path, pattern) {
199
+ if (this.#exclude) {
200
+ const fullpath = resolve(this.#root, path)
201
+ if (this.#cache.statSync(fullpath) !== null && this.#exclude(fullpath)) {
202
+ return
203
+ }
204
+ }
205
+ if (!this.#subpatterns.has(path)) {
206
+ this.#subpatterns.set(path, [pattern])
207
+ } else {
208
+ this.#subpatterns.get(path).push(pattern)
209
+ }
210
+ }
211
+ #addSubpatterns(path, pattern) {
212
+ const seen = this.#cache.add(path, pattern)
213
+ if (seen) {
214
+ return
215
+ }
216
+ const fullpath = resolve(this.#root, path)
217
+ const stat = this.#cache.statSync(fullpath)
218
+ const last = pattern.last
219
+ const isDirectory = this.#isDirectorySync(stat, pattern)
220
+ const isLast = pattern.isLast(isDirectory)
221
+ const isFirst = pattern.isFirst()
222
+
223
+ if (isFirst && pattern.at(0) === '') {
224
+ this.#addSubpattern('/', pattern.child(new Set().add(1)))
225
+ return
226
+ }
227
+ if (isFirst && pattern.at(0) === '..') {
228
+ this.#addSubpattern('../', pattern.child(new Set().add(1)))
229
+ return
230
+ }
231
+ if (isFirst && pattern.at(0) === '.') {
232
+ this.#addSubpattern('.', pattern.child(new Set().add(1)))
233
+ return
234
+ }
235
+
236
+ if (isLast && typeof pattern.at(-1) === 'string') {
237
+ const p = pattern.at(-1)
238
+ const found = this.#cache.statSync(join(fullpath, p))
239
+ if (found && (p || isDirectory)) {
240
+ this.#results.add(join(path, p))
241
+ }
242
+ if (pattern.indexes.size === 1 && pattern.indexes.has(last)) {
243
+ return
244
+ }
245
+ } else if (isLast && pattern.at(-1) === lazyMinimatch().GLOBSTAR &&
246
+ (path !== '.' || pattern.at(0) === '.' || (last === 0 && stat))) {
247
+ this.#results.add(path)
248
+ }
249
+
250
+ if (!isDirectory) {
251
+ return
252
+ }
253
+
254
+ let children
255
+ const firstPattern = pattern.indexes.size === 1 && pattern.at(pattern.indexes.values().next().value)
256
+ if (typeof firstPattern === 'string') {
257
+ const child = this.#cache.statSync(join(fullpath, firstPattern))
258
+ if (child) {
259
+ child.name = firstPattern
260
+ children = [child]
261
+ } else {
262
+ return
263
+ }
264
+ } else {
265
+ children = this.#cache.readdirSync(fullpath)
266
+ }
267
+
268
+ for (let i = 0; i < children.length; i++) {
269
+ const entry = children[i]
270
+ const entryPath = join(path, entry.name)
271
+ const entryFullpath = join(fullpath, entry.name)
272
+ this.#cache.addToStatCache(entryFullpath, entry)
273
+ const entryIsDirectory = entry.isDirectory()
274
+
275
+ const subPatterns = new Set()
276
+ const nSymlinks = new Set()
277
+ for (const index of pattern.indexes) {
278
+ const current = pattern.at(index)
279
+ const nextIndex = index + 1
280
+ const next = pattern.at(nextIndex)
281
+ const fromSymlink = pattern.symlinks.has(index)
282
+
283
+ if (current === lazyMinimatch().GLOBSTAR) {
284
+ const isDot = entry.name[0] === '.'
285
+ const nextMatches = pattern.test(nextIndex, entry.name)
286
+
287
+ let nextNonGlobIndex = nextIndex
288
+ while (pattern.at(nextNonGlobIndex) === lazyMinimatch().GLOBSTAR) {
289
+ nextNonGlobIndex++
290
+ }
291
+
292
+ const matchesDot = isDot && pattern.test(nextNonGlobIndex, entry.name)
293
+
294
+ if ((isDot && !matchesDot) ||
295
+ (this.#exclude && this.#exclude(entryFullpath))) {
296
+ continue
297
+ }
298
+ if (!fromSymlink && entryIsDirectory) {
299
+ subPatterns.add(index)
300
+ } else if (!fromSymlink && index === last) {
301
+ this.#results.add(entryPath)
302
+ }
303
+
304
+ if (nextMatches && nextIndex === last && !isLast) {
305
+ this.#results.add(entryPath)
306
+ } else if (nextMatches && entryIsDirectory) {
307
+ subPatterns.add(index + 2)
308
+ }
309
+ if ((nextMatches || pattern.at(0) === '.') &&
310
+ entryIsDirectory && !fromSymlink) {
311
+ subPatterns.add(nextIndex)
312
+ }
313
+
314
+ if (entry.isSymbolicLink()) {
315
+ nSymlinks.add(index)
316
+ }
317
+
318
+ if (next === '..' && entryIsDirectory) {
319
+ const parent = join(path, '..')
320
+ if (nextIndex < last) {
321
+ if (!this.#subpatterns.has(path) && !this.#cache.seen(path, pattern, nextIndex + 1)) {
322
+ this.#subpatterns.set(path, [pattern.child(new Set().add(nextIndex + 1))])
323
+ }
324
+ if (!this.#subpatterns.has(parent) && !this.#cache.seen(parent, pattern, nextIndex + 1)) {
325
+ this.#subpatterns.set(parent, [pattern.child(new Set().add(nextIndex + 1))])
326
+ }
327
+ } else {
328
+ if (!this.#cache.seen(path, pattern, nextIndex)) {
329
+ this.#cache.add(path, pattern.child(new Set().add(nextIndex)))
330
+ this.#results.add(path)
331
+ }
332
+ if (!this.#cache.seen(path, pattern, nextIndex) || !this.#cache.seen(parent, pattern, nextIndex)) {
333
+ this.#cache.add(parent, pattern.child(new Set().add(nextIndex)))
334
+ this.#results.add(parent)
335
+ }
336
+ }
337
+ }
338
+ }
339
+ if (typeof current === 'string') {
340
+ if (pattern.test(index, entry.name) && index !== last) {
341
+ subPatterns.add(nextIndex)
342
+ } else if (current === '.' && pattern.test(nextIndex, entry.name)) {
343
+ if (nextIndex === last) {
344
+ this.#results.add(entryPath)
345
+ } else {
346
+ subPatterns.add(nextIndex + 1)
347
+ }
348
+ }
349
+ }
350
+ if (typeof current === 'object' && pattern.test(index, entry.name)) {
351
+ if (index === last) {
352
+ this.#results.add(entryPath)
353
+ } else if (entryIsDirectory) {
354
+ subPatterns.add(nextIndex)
355
+ }
356
+ }
357
+ }
358
+ if (subPatterns.size > 0) {
359
+ this.#addSubpattern(entryPath, pattern.child(subPatterns, nSymlinks))
360
+ }
361
+ }
362
+ }
363
+ }
364
+
365
+ export const globSync = (host, pattern, { cwd, exclude } = {}) => new Glob(host, pattern, { cwd, exclude }).globSync()
366
+
367
+ // As Node's matchGlobPattern keeps them.
368
+ const MATCHERS_KEPT = 250
369
+ const matchers = new Map()
370
+
371
+ export function matchesGlob(path, pattern) {
372
+ let matcher = matchers.get(pattern)
373
+ if (matcher === undefined) {
374
+ matcher = createMatcher(pattern)
375
+ matchers.set(pattern, matcher)
376
+ if (matchers.size >= MATCHERS_KEPT) matchers.delete(matchers.keys().next().value)
377
+ }
378
+ return matcher.match(path)
379
+ }
@@ -0,0 +1,99 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks'
2
+ import { posix } from 'node:path'
3
+
4
+ // A lazy tree leaves each package's directory empty until it is unpacked. The host reads synchronously, so a build runs
5
+ // in rounds: one that reads under a package not yet unpacked is void, and those packages are unpacked for the next.
6
+
7
+ // A read under a package of `roots` not yet `unpacked` (or a listing of its directory) asks for it, and reads it but
8
+ // while probing; its own directory and those above it read as the full tree holds them, asking for nothing.
9
+ export function lazyView(vfs, { roots, unpacked, reads }) {
10
+ const above = new Set()
11
+ for (const root of roots) {
12
+ for (let dir = posix.dirname(root); dir !== '/' && !above.has(dir); dir = posix.dirname(dir)) above.add(dir)
13
+ }
14
+ const ownerOf = (path) => {
15
+ for (let dir = path; dir !== '/'; dir = posix.dirname(dir)) if (roots.has(dir)) return dir
16
+ return null
17
+ }
18
+ const touch = (path, listing) => {
19
+ const owner = ownerOf(path)
20
+ if (owner === null || unpacked.has(owner)) return
21
+ if (!listing && (path === owner || above.has(path))) return
22
+ reads.asked.add(owner)
23
+ if (reads.probing === 0) reads.read.add(owner)
24
+ reads.touches++
25
+ }
26
+ const read = (method, listing = false) => (path) => {
27
+ touch(path, listing)
28
+ return vfs[method](path)
29
+ }
30
+ return { lstat: read('lstat'), readlink: read('readlink'), readFile: read('readFile'), readdir: read('readdir', true) }
31
+ }
32
+
33
+ // Keeps only what was read without `touches` of what a lazy tree has yet to unpack. With `retouch` (a cache of one
34
+ // round), a touched value is kept too and retouches on each hit; with `across` (kept across rounds), an untouched one.
35
+ export function untouchedMemo(touches = () => 0, { cache = true, retouch, across } = {}) {
36
+ const kept = new Map()
37
+ return (key, read) => {
38
+ if (across?.has(key)) return across.get(key)
39
+ const hit = kept.get(key)
40
+ if (hit !== undefined) {
41
+ if (hit.touched) retouch()
42
+ return hit.value
43
+ }
44
+ const before = touches()
45
+ const value = read()
46
+ const touched = touches() !== before
47
+ if (!cache) return value
48
+ if (!touched && across !== undefined) across.set(key, value)
49
+ else if (!touched || retouch !== undefined) kept.set(key, { value, touched })
50
+ return value
51
+ }
52
+ }
53
+
54
+ export const hostMemo = (host, options) => untouchedMemo(host.touches, { retouch: host.retouch, ...options })
55
+
56
+ // Held for the round: one that is void says nothing.
57
+ const rounds = new AsyncLocalStorage()
58
+ let holders = 0
59
+ let passed
60
+ function warnHeld(...args) {
61
+ const held = rounds.getStore()
62
+ if (held === undefined) passed.apply(console, args)
63
+ else held.push(args)
64
+ }
65
+ async function holding(held, fn) {
66
+ if (holders++ === 0) {
67
+ passed = console.warn
68
+ console.warn = warnHeld
69
+ }
70
+ try {
71
+ return await rounds.run(held, fn)
72
+ } finally {
73
+ if (--holders === 0 && console.warn === warnHeld) console.warn = passed
74
+ }
75
+ }
76
+
77
+ export async function warningsHeld(fn) {
78
+ const warnings = []
79
+ try {
80
+ return { value: await holding(warnings, fn), warnings }
81
+ } catch (error) {
82
+ return { error, warnings }
83
+ }
84
+ }
85
+
86
+ export async function inRounds(attempt, unpack) {
87
+ for (;;) {
88
+ const reads = { asked: new Set(), read: new Set(), probing: 0, touches: 0 }
89
+ // eslint-disable-next-line no-await-in-loop -- each round reads what the one before unpacked
90
+ const round = await warningsHeld(() => attempt(reads))
91
+ if (reads.asked.size === 0) {
92
+ for (const args of round.warnings) console.warn(...args)
93
+ if ('error' in round) throw round.error
94
+ return round.value
95
+ }
96
+ // eslint-disable-next-line no-await-in-loop -- what the next round reads
97
+ await unpack(reads.asked, reads.read)
98
+ }
99
+ }