@exodus/stasis 1.0.0-beta.15 → 1.0.0-beta.17

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 +1 -1
  2. package/bin/stasis.js +26 -11
  3. package/package.json +10 -9
  4. package/src/audit-corrections.js +11 -42
  5. package/src/audit.js +113 -233
  6. package/src/babel.js +39 -122
  7. package/src/bundle-from-lockfile.js +9 -21
  8. package/src/bundle-reader.js +5 -9
  9. package/src/bundle.js +0 -3
  10. package/src/cmd/build.js +50 -166
  11. package/src/cmd/bundle-options.js +110 -167
  12. package/src/cmd/bundle.js +861 -1344
  13. package/src/cmd/diff.js +1 -4
  14. package/src/cmd/github-bundle.js +46 -27
  15. package/src/cmd/output.js +17 -12
  16. package/src/cmd/sbom.js +3 -8
  17. package/src/cmd/tokens.js +10 -23
  18. package/src/define.js +34 -97
  19. package/src/diff.js +72 -128
  20. package/src/esbuild.js +0 -4
  21. package/src/flow.js +10 -25
  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 +41 -93
  27. package/src/loaders/cargo.js +298 -805
  28. package/src/loaders/foundry.js +109 -285
  29. package/src/loaders/paths.js +13 -13
  30. package/src/loaders/php.js +210 -489
  31. package/src/loaders/rust.js +507 -1430
  32. package/src/loaders/solidity-ownership.js +48 -128
  33. package/src/loaders/solidity.js +39 -122
  34. package/src/loaders/toml.js +7 -17
  35. package/src/lockfile.js +0 -3
  36. package/src/metro-assets.js +9 -33
  37. package/src/metro-resolver.js +20 -47
  38. package/src/metro-transformer.js +0 -5
  39. package/src/metro.js +0 -4
  40. package/src/mock.js +32 -80
  41. package/src/parse.js +2 -5
  42. package/src/prune.js +0 -3
  43. package/src/resolve-fields.js +90 -220
  44. package/src/resolve-node.js +27 -45
  45. package/src/resolve-typescript.js +109 -313
  46. package/src/rollup.js +0 -4
  47. package/src/run-installed.js +10 -0
  48. package/src/sbom.js +52 -128
  49. package/src/scan.js +136 -283
  50. package/src/sixel.js +18 -41
  51. package/src/table.js +14 -35
  52. package/src/validate-notes.d.ts +3 -2
  53. package/src/validate-notes.js +25 -19
  54. package/src/validate.d.ts +38 -11
  55. package/src/validate.js +478 -512
  56. package/src/vfs-bundle/entries.js +40 -57
  57. package/src/vfs-bundle/github.js +88 -121
  58. package/src/vfs-bundle/glob.js +4 -45
  59. package/src/vfs-bundle/lazy.js +27 -56
  60. package/src/vfs-bundle/prisma.js +167 -110
  61. package/src/vfs-bundle/soldeer.js +28 -49
  62. package/src/vfs-bundle/tree.js +295 -318
  63. package/src/vfs-bundle/yarnclean.js +10 -31
  64. package/src/vfs-bundle.js +23 -64
  65. package/src/webpack.js +0 -4
  66. package/src/why.js +75 -231
  67. package/src/installed-commits.js +0 -184
@@ -1,22 +1,17 @@
1
1
  import { createRequire } from 'node:module'
2
2
  import { posix } from 'node:path'
3
3
 
4
- // Node's own fs.globSync and path.matchesGlob over a `host` (@exodus/stasis-core/host) in place of
5
- // the disk, for a Vfs's: Node 24.22.2's and 26.13.0's internal/fs/glob.js, its globSync as it runs
6
- // without `followSymlinks`, `maxDepth` or an array `exclude`, over the minimatch 10 they vendor, an
7
- // optional dependency loaded where a pattern is first matched. Unlike Node's, matching never folds
8
- // case, whatever the OS: the tree is git's, whose names differ by case alone.
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.
9
6
 
10
7
  const { join, resolve } = posix
11
8
  const require = createRequire(import.meta.url)
12
9
 
13
10
  const MINIMATCH = 'minimatch'
14
11
  const MINIMATCH_MAJOR = '10'
15
- // Node's createMatcher's, as on Linux.
16
12
  const OPTIONS = { nocase: false, windowsPathsNoEscape: true, nonegate: true, nocomment: true, optimizationLevel: 2, platform: 'linux', nocaseMagicOnly: true }
17
13
 
18
14
  let minimatch
19
- // minimatch, or a refusal naming `what` needs it where it isn't installed.
20
15
  export function loadMinimatch(what) {
21
16
  if (minimatch) return minimatch
22
17
  const needs = `${what} needs the optional '${MINIMATCH}' ${MINIMATCH_MAJOR} dependency`
@@ -34,13 +29,10 @@ export function loadMinimatch(what) {
34
29
 
35
30
  const lazyMinimatch = () => loadMinimatch("A glob over a Vfs (stasis.config.json's extra)")
36
31
 
37
- // Throws where globbing a Vfs can't load minimatch, before anything else is done.
38
32
  export const checkGlob = () => void lazyMinimatch()
39
33
 
40
34
  const createMatcher = (pattern) => new (lazyMinimatch().Minimatch)(pattern, OPTIONS)
41
35
 
42
- // What `host` holds at `path`, its last link not followed, as far as the walk asks of lstat's
43
- // Dirent; null where nothing is.
44
36
  function lstatOf(host, path) {
45
37
  let link
46
38
  try {
@@ -164,9 +156,7 @@ class Pattern {
164
156
  }
165
157
  }
166
158
 
167
- // Node's, but for `exclude`: given each path's absolute path (where Node gives its Dirent with
168
- // `withFileTypes`), and in #addSubpattern, the path from the root (where Node's lstat takes it, as
169
- // spelled from the root, from the process's cwd).
159
+ // Node's, but `exclude` takes absolute paths, and #addSubpattern stats paths from the root, not the process's cwd.
170
160
  class Glob {
171
161
  #root
172
162
  #exclude
@@ -231,23 +221,19 @@ class Glob {
231
221
  const isFirst = pattern.isFirst()
232
222
 
233
223
  if (isFirst && pattern.at(0) === '') {
234
- // Absolute path, go to root
235
224
  this.#addSubpattern('/', pattern.child(new Set().add(1)))
236
225
  return
237
226
  }
238
227
  if (isFirst && pattern.at(0) === '..') {
239
- // Start with .., go to parent
240
228
  this.#addSubpattern('../', pattern.child(new Set().add(1)))
241
229
  return
242
230
  }
243
231
  if (isFirst && pattern.at(0) === '.') {
244
- // Start with ., proceed
245
232
  this.#addSubpattern('.', pattern.child(new Set().add(1)))
246
233
  return
247
234
  }
248
235
 
249
236
  if (isLast && typeof pattern.at(-1) === 'string') {
250
- // Add result if it exists
251
237
  const p = pattern.at(-1)
252
238
  const found = this.#cache.statSync(join(fullpath, p))
253
239
  if (found && (p || isDirectory)) {
@@ -258,8 +244,6 @@ class Glob {
258
244
  }
259
245
  } else if (isLast && pattern.at(-1) === lazyMinimatch().GLOBSTAR &&
260
246
  (path !== '.' || pattern.at(0) === '.' || (last === 0 && stat))) {
261
- // If pattern ends with **, add to results
262
- // if path is ".", add it only if pattern starts with "." or pattern is exactly "**"
263
247
  this.#results.add(path)
264
248
  }
265
249
 
@@ -291,7 +275,6 @@ class Glob {
291
275
  const subPatterns = new Set()
292
276
  const nSymlinks = new Set()
293
277
  for (const index of pattern.indexes) {
294
- // For each child, check potential patterns
295
278
  const current = pattern.at(index)
296
279
  const nextIndex = index + 1
297
280
  const next = pattern.at(nextIndex)
@@ -313,28 +296,18 @@ class Glob {
313
296
  continue
314
297
  }
315
298
  if (!fromSymlink && entryIsDirectory) {
316
- // If directory, add ** to its potential patterns
317
299
  subPatterns.add(index)
318
300
  } else if (!fromSymlink && index === last) {
319
- // If ** is last, add to results
320
301
  this.#results.add(entryPath)
321
302
  }
322
303
 
323
- // Any pattern after ** is also a potential pattern
324
- // so we can already test it here
325
304
  if (nextMatches && nextIndex === last && !isLast) {
326
- // If next pattern is the last one, add to results
327
305
  this.#results.add(entryPath)
328
306
  } else if (nextMatches && entryIsDirectory) {
329
- // Pattern matched, meaning two patterns forward
330
- // are also potential patterns
331
- // e.g **/b/c when entry is a/b - add c to potential patterns
332
307
  subPatterns.add(index + 2)
333
308
  }
334
309
  if ((nextMatches || pattern.at(0) === '.') &&
335
310
  entryIsDirectory && !fromSymlink) {
336
- // If pattern after ** matches, or pattern starts with "."
337
- // and entry is a directory, add to potential patterns
338
311
  subPatterns.add(nextIndex)
339
312
  }
340
313
 
@@ -343,9 +316,6 @@ class Glob {
343
316
  }
344
317
 
345
318
  if (next === '..' && entryIsDirectory) {
346
- // In case pattern is "**/..",
347
- // both parent and current directory should be added to the queue
348
- // if this is the last pattern, add to results instead
349
319
  const parent = join(path, '..')
350
320
  if (nextIndex < last) {
351
321
  if (!this.#subpatterns.has(path) && !this.#cache.seen(path, pattern, nextIndex + 1)) {
@@ -368,11 +338,8 @@ class Glob {
368
338
  }
369
339
  if (typeof current === 'string') {
370
340
  if (pattern.test(index, entry.name) && index !== last) {
371
- // If current pattern matches entry name
372
- // the next pattern is a potential pattern
373
341
  subPatterns.add(nextIndex)
374
342
  } else if (current === '.' && pattern.test(nextIndex, entry.name)) {
375
- // If current pattern is ".", proceed to test next pattern
376
343
  if (nextIndex === last) {
377
344
  this.#results.add(entryPath)
378
345
  } else {
@@ -381,8 +348,6 @@ class Glob {
381
348
  }
382
349
  }
383
350
  if (typeof current === 'object' && pattern.test(index, entry.name)) {
384
- // If current pattern is a regex that matches entry name (e.g *.js)
385
- // add next pattern to potential patterns, or to results if it's the last pattern
386
351
  if (index === last) {
387
352
  this.#results.add(entryPath)
388
353
  } else if (entryIsDirectory) {
@@ -391,24 +356,18 @@ class Glob {
391
356
  }
392
357
  }
393
358
  if (subPatterns.size > 0) {
394
- // If there are potential patterns, add to queue
395
359
  this.#addSubpattern(entryPath, pattern.child(subPatterns, nSymlinks))
396
360
  }
397
361
  }
398
362
  }
399
363
  }
400
364
 
401
- // fs.globSync(pattern, { cwd, exclude }) over `host`, `cwd` an absolute path there: the matches as
402
- // Node spells them, from `cwd` (or from `/`, of an absolute pattern), never walking into a path
403
- // `exclude` takes, given its absolute path. As Node's, it leaves out such a path where its `**`
404
- // meets it alone: one the segment after the `**` matches is still a match.
405
365
  export const globSync = (host, pattern, { cwd, exclude } = {}) => new Glob(host, pattern, { cwd, exclude }).globSync()
406
366
 
407
- // As Node's matchGlobPattern keeps them: the most recent 250 patterns' matchers.
367
+ // As Node's matchGlobPattern keeps them.
408
368
  const MATCHERS_KEPT = 250
409
369
  const matchers = new Map()
410
370
 
411
- // path.matchesGlob(path, pattern), never folding case.
412
371
  export function matchesGlob(path, pattern) {
413
372
  let matcher = matchers.get(pattern)
414
373
  if (matcher === undefined) {
@@ -1,20 +1,11 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks'
2
2
  import { posix } from 'node:path'
3
3
 
4
- // A lazy tree (@preventive/deptree's `lazy`): laid out from the lockfile alone, each package's
5
- // directory left empty until it is unpacked. The host reads synchronously, so a build reading it
6
- // cannot wait for a tarball: it runs in rounds. A round that reads under a package not yet unpacked
7
- // is void, whatever it built, and those packages are unpacked for the next; the first round that
8
- // reads none read nothing but what the full tree holds there, and is the build. What a round's scan
9
- // reads of a file is kept for the rounds after it where reading it read no such package (Scan's
10
- // `memo`), so each file is scanned once, but those that read what was not unpacked yet.
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.
11
6
 
12
- // The tree's Vfs as tree.js's vfsHost reads it (lstat, readlink, readFile and readdir). A read under
13
- // the directory of a package of `roots` not in `unpacked`, or a listing of that directory itself,
14
- // adds it to `reads.asked`, and to `reads.read` but while `reads.probing` (a check of what files the
15
- // package holds, which reads none of its code), counts in `reads.touches`, and reads what the layout
16
- // holds there. The directory itself, and those above a package's on the way to it, are as the full
17
- // tree holds them, so reading them asks for nothing.
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.
18
9
  export function lazyView(vfs, { roots, unpacked, reads }) {
19
10
  const above = new Set()
20
11
  for (const root of roots) {
@@ -32,35 +23,15 @@ export function lazyView(vfs, { roots, unpacked, reads }) {
32
23
  if (reads.probing === 0) reads.read.add(owner)
33
24
  reads.touches++
34
25
  }
35
- return {
36
- lstat(path) {
37
- touch(path, false)
38
- return vfs.lstat(path)
39
- },
40
- readlink(path) {
41
- touch(path, false)
42
- return vfs.readlink(path)
43
- },
44
- readFile(path) {
45
- touch(path, false)
46
- return vfs.readFile(path)
47
- },
48
- readdir(path) {
49
- touch(path, true)
50
- return vfs.readdir(path)
51
- },
26
+ const read = (method, listing = false) => (path) => {
27
+ touch(path, listing)
28
+ return vfs[method](path)
52
29
  }
30
+ return { lstat: read('lstat'), readlink: read('readlink'), readFile: read('readFile'), readdir: read('readdir', true) }
53
31
  }
54
32
 
55
- // A get-or-read cache, `(key, read) => read()`'s value, as for a tree that holds still: but kept only
56
- // where reading it read nothing a lazy tree does not hold yet (counted by `touches`, a lazy tree's
57
- // host's), which is read again; and kept nowhere without `cache`. With `retouch`, for a cache that
58
- // lives no longer than one round of a lazy tree, in which the tree holds still, what such a reading
59
- // gave is kept too, and each time it is taken it touches again (`retouch()`), as reading it again
60
- // would: what reads it knows it read what the tree does not hold yet, which a round's scan keeps none
61
- // of (Scan's `memo`), and it is not read again only to fail again. With `across`, a Map kept across
62
- // a lazy tree's rounds, what was read with none is kept there, for each round after, as a scan
63
- // keeps a file it read so.
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.
64
35
  export function untouchedMemo(touches = () => 0, { cache = true, retouch, across } = {}) {
65
36
  const kept = new Map()
66
37
  return (key, read) => {
@@ -80,7 +51,9 @@ export function untouchedMemo(touches = () => 0, { cache = true, retouch, across
80
51
  }
81
52
  }
82
53
 
83
- // What console.warn gives within a round, held for the round: one that is void says nothing.
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.
84
57
  const rounds = new AsyncLocalStorage()
85
58
  let holders = 0
86
59
  let passed
@@ -101,26 +74,24 @@ async function holding(held, fn) {
101
74
  }
102
75
  }
103
76
 
104
- // `attempt(reads)`'s result, of the first round whose reads ask for no package (`reads.asked`), its
105
- // warnings given then; after each round that does, `unpack(reads.asked, reads.read)`, `reads.read`
106
- // those of them it read other than by a probe (lazyView). Each round asks for one package at least
107
- // that no round before did, so there are no more rounds than packages.
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
+
108
86
  export async function inRounds(attempt, unpack) {
109
87
  for (;;) {
110
88
  const reads = { asked: new Set(), read: new Set(), probing: 0, touches: 0 }
111
- const held = []
112
- let result
113
- let failure
114
- try {
115
- // eslint-disable-next-line no-await-in-loop -- each round reads what the one before unpacked
116
- result = await holding(held, () => attempt(reads))
117
- } catch (error) {
118
- failure = { error }
119
- }
89
+ // eslint-disable-next-line no-await-in-loop -- each round reads what the one before unpacked
90
+ const round = await warningsHeld(() => attempt(reads))
120
91
  if (reads.asked.size === 0) {
121
- for (const args of held) console.warn(...args)
122
- if (failure !== undefined) throw failure.error
123
- return result
92
+ for (const args of round.warnings) console.warn(...args)
93
+ if ('error' in round) throw round.error
94
+ return round.value
124
95
  }
125
96
  // eslint-disable-next-line no-await-in-loop -- what the next round reads
126
97
  await unpack(reads.asked, reads.read)