@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
package/src/mock.js CHANGED
@@ -1,29 +1,15 @@
1
- // Imported by src/loader-mock.js (the `stasis run --mock` entry) after the core hooks lib is
2
- // evaluated but before its hooks are installed. Captures the import graph by running user code
3
- // with side-effects denied. Pairs with Node's `--permission` (see bin/stasis.js), which denies fs
4
- // writes/child procs/workers/addons/inspector at the runtime boundary; this file covers what
5
- // `--permission` can't -- there is no `--allow-net`, so the network builtins are neutralized in JS.
6
- //
7
- // FAIL CLOSED, WHOLE MODULE: replace *every* callable on a denied builtin with a thrower, not a
8
- // curated method list -- higher-level clients (axios/undici/ws) fall closed too since they bottom
9
- // out at node:net/tls/dns, and anything unmodelled still throws rather than silently succeeding.
10
- //
11
- // Mechanism: go through `createRequire` to grab the *mutable* CJS exports object -- ESM namespace
12
- // objects freeze their bindings, so mocking them throws "Cannot redefine property". ESM live-bindings
13
- // track CJS mutation for builtins, so importers loading *after* us see the mocks; modules linked
14
- // before (the loader's own state.js) keep their real bindings.
1
+ // `stasis run --mock`'s side-effect denials (loader-mock.js), for what Node's `--permission` (bin/stasis.js) can't
2
+ // deny, the network above all: EVERY callable of a denied builtin throws, so clients bottoming out at it fail closed.
3
+ // Mocked on the mutable CJS exports (ESM namespaces are frozen): importers linked after this see the mocks.
15
4
 
16
5
  import { mock } from 'node:test'
17
6
  import { createRequire, syncBuiltinESMExports } from 'node:module'
18
7
 
19
8
  const require = createRequire(import.meta.url)
20
9
 
21
- // Force lazy init of process.std{in,out,err} before mocking net/tls: they're lazy getters that
22
- // build a net.Socket/tty.WriteStream on first read, which syncBuiltinESMExports() below would
23
- // otherwise trigger through our mock mid-setup. Reading once here caches the real Socket/TTY.
24
- void process.stdin
25
- void process.stdout
26
- void process.stderr
10
+ // process.std{in,out,err} build a net.Socket/tty.WriteStream on first read, which syncBuiltinESMExports() below would
11
+ // otherwise trigger through our mock mid-setup: read once here, they cache the real ones.
12
+ for (const name of ['stdin', 'stdout', 'stderr']) void process[name]
27
13
 
28
14
  const MARKER = '[stasis --mock]'
29
15
 
@@ -35,21 +21,16 @@ const blocked = (label) => {
35
21
  return err
36
22
  }
37
23
 
38
- // A *regular* (constructable) function so both `mod.factory()` and `new mod.Constructor()` throw
39
- // our error; an arrow would make `new` fail with a confusing "is not a constructor".
24
+ // Not an arrow, so `new mod.Constructor()` throws our error too rather than "is not a constructor".
40
25
  const denyFn = (label) => function () { throw blocked(label) }
41
26
 
42
- // Promise-shaped version: rejects instead of sync-throwing, so fire-and-forget callers surface via
43
- // the unhandledRejection trap below rather than crashing the script synchronously.
27
+ // Rejecting, so a fire-and-forget caller meets the unhandledRejection trap below rather than a sync crash.
44
28
  const denyFnAsync = (label) => function () { return Promise.reject(blocked(label)) }
45
29
 
46
- // Replace every own function on `mod` (and one level down on `mod.promises`) with a thrower.
47
- // Promise-shaped surfaces use denyFnAsync so fire-and-forget callers reject quietly -- except
48
- // class-shaped exports (PascalCase): `new Class()` returning a Promise yields the Promise as the
49
- // constructed value, so classes sync-throw to give a clean error in both `new` and call form.
30
+ // Every own function on `mod` and `mod.promises` a thrower, a rejecting one on a promise surface but for a class
31
+ // (PascalCase), which `new` would make the Promise of.
50
32
  const isClassName = (key) => /^[A-Z]/.test(key)
51
- const denyModuleSurface = (specifier, mod, opts = {}) => {
52
- const { prefix = specifier, async: isAsync = specifier.endsWith('/promises') } = opts
33
+ const denyModuleSurface = (prefix, mod, isAsync = prefix.endsWith('/promises')) => {
53
34
  for (const key of Object.getOwnPropertyNames(mod)) {
54
35
  const value = mod[key]
55
36
  if (typeof value === 'function') {
@@ -61,24 +42,16 @@ const denyModuleSurface = (specifier, mod, opts = {}) => {
61
42
  try { mod[key] = impl } catch { /* frozen: leave as-is */ }
62
43
  }
63
44
  } else if (key === 'promises' && value && typeof value === 'object') {
64
- denyModuleSurface(specifier, value, { prefix: `${prefix}.promises`, async: true })
45
+ denyModuleSurface(`${prefix}.promises`, value, true)
65
46
  }
66
47
  }
67
48
  }
68
49
 
69
- // Every callable on these builtins is replaced with a thrower.
70
50
  const DENY_ALL = [
71
51
  // Network surface (no --allow-net counterpart -- JS-mock is the only layer).
72
- 'node:http', 'node:https', 'node:http2',
73
- 'node:net', 'node:dgram', 'node:tls',
74
- 'node:dns', 'node:dns/promises',
75
- // Process/worker/debug: already --permission-denied; duplicated for attributable errors and
76
- // defense in depth against a future --allow-* slip-up or a process.binding bypass.
77
- 'node:child_process',
78
- 'node:worker_threads',
79
- 'node:cluster',
80
- 'node:inspector',
81
- 'node:inspector/promises',
52
+ 'node:http', 'node:https', 'node:http2', 'node:net', 'node:dgram', 'node:tls', 'node:dns', 'node:dns/promises',
53
+ // Already --permission-denied: for attributable errors, and in depth against an --allow-* slip or process.binding.
54
+ 'node:child_process', 'node:worker_threads', 'node:cluster', 'node:inspector', 'node:inspector/promises',
82
55
  // Other side-effect surfaces nothing else covers:
83
56
  'node:repl', // repl.start() opens an interactive stdin loop
84
57
  'node:sqlite', // DatabaseSync can open/create SQLite files (Node 22+)
@@ -98,10 +71,8 @@ for (const specifier of DENY_ALL) {
98
71
  denyModuleSurface(specifier, mod)
99
72
  }
100
73
 
101
- // process method denials. process.exit / process.abort are deliberately left alone -- early
102
- // termination isn't a side effect we should hide. The rest mutate global process state, do real
103
- // I/O, or talk to a parent over IPC; note setUncaughtExceptionCaptureCallback would also disable
104
- // our exitCode=13 cleanup below.
74
+ // What mutates global process state, does real I/O, or talks to a parent over IPC (exit and abort are no side
75
+ // effect to hide); setUncaughtExceptionCaptureCallback would also disable the exitCode=13 cleanup below.
105
76
  const PROCESS_DENY = [
106
77
  'chdir', 'kill', 'umask', 'dlopen', 'binding',
107
78
  'setUid', 'setGid', 'setEuid', 'setEgid', 'setgroups', 'initgroups',
@@ -110,18 +81,13 @@ const PROCESS_DENY = [
110
81
  'setUncaughtExceptionCaptureCallback',
111
82
  ]
112
83
  for (const name of PROCESS_DENY) {
113
- if (typeof process[name] === 'function') {
114
- mock.method(process, name, denyFn(`process.${name}()`))
115
- }
84
+ if (typeof process[name] === 'function') mock.method(process, name, denyFn(`process.${name}()`))
116
85
  }
117
86
 
118
- // process.report.writeReport writes a diagnostic JSON file to disk; deny it too.
119
- if (process.report && typeof process.report.writeReport === 'function') {
120
- mock.method(process.report, 'writeReport', denyFn('process.report.writeReport()'))
121
- }
87
+ // It writes a diagnostic JSON file.
88
+ if (typeof process.report?.writeReport === 'function') mock.method(process.report, 'writeReport', denyFn('process.report.writeReport()'))
122
89
 
123
- // fs writers: --permission blocks these at the kernel level too, but JS-mocking gives cleaner
124
- // errors and stops user code mutating even cwd files (cwd is on --allow-fs-write for the bundle).
90
+ // --permission blocks these too, but mocking gives cleaner errors and covers cwd, on --allow-fs-write for the bundle.
125
91
  // Reads stay real so node_modules resolution keeps working.
126
92
  const fs = require('node:fs')
127
93
  const fsPromises = require('node:fs/promises')
@@ -138,25 +104,16 @@ const FS_WRITERS = [
138
104
  'createWriteStream', 'mkdtemp', 'mkdtempSync',
139
105
  ]
140
106
  for (const name of FS_WRITERS) {
141
- if (typeof fs[name] === 'function') {
142
- mock.method(fs, name, denyFn(`node:fs.${name}()`))
143
- }
144
- if (typeof fsPromises[name] === 'function') {
145
- mock.method(fsPromises, name, denyFnAsync(`node:fs/promises.${name}()`))
146
- }
107
+ if (typeof fs[name] === 'function') mock.method(fs, name, denyFn(`node:fs.${name}()`))
108
+ if (typeof fsPromises[name] === 'function') mock.method(fsPromises, name, denyFnAsync(`node:fs/promises.${name}()`))
147
109
  }
148
110
 
149
- // Refresh the node:fs ESM wrappers so ESM imports after this point see the mocked names;
150
- // bindings stasis already captured (linked before this file ran) keep their real snapshot.
111
+ // ESM imports after this see the mocks; bindings stasis linked before this ran keep their real snapshot.
151
112
  syncBuiltinESMExports()
152
113
 
153
- // Global fetch / WebSocket / EventSource come from undici, not node:http, so handle separately.
154
- // fetch returns a *forever-pending* promise (not a rejection) so an awaiter hangs and the capture
155
- // still drains to write the bundle on beforeExit; WebSocket/EventSource throw from their
156
- // constructors to preserve the synchronous shape.
157
- if (typeof globalThis.fetch === 'function') {
158
- globalThis.fetch = () => new Promise(() => {})
159
- }
114
+ // The global fetch / WebSocket / EventSource are undici's, not node:http's. fetch never settles, so an awaiter
115
+ // hangs and the capture still drains to write the bundle on beforeExit; the others throw from their constructors.
116
+ if (typeof globalThis.fetch === 'function') globalThis.fetch = () => new Promise(() => {})
160
117
  for (const name of ['WebSocket', 'EventSource']) {
161
118
  if (typeof globalThis[name] === 'function') {
162
119
  globalThis[name] = class {
@@ -165,8 +122,7 @@ for (const name of ['WebSocket', 'EventSource']) {
165
122
  }
166
123
  }
167
124
 
168
- // Our denials become unhandledRejections for fire-and-forget callers, which would tear the process
169
- // down before the loader writes the bundle. Swallow *only* our own denials; rethrow everything else.
125
+ // A fire-and-forget caller's denial would tear the process down before the loader writes the bundle.
170
126
  process.on('unhandledRejection', (reason) => {
171
127
  if (reason?.__stasisMock) return
172
128
  throw reason
@@ -178,10 +134,8 @@ process.on('exit', () => {
178
134
  if (process.exitCode === 13) process.exitCode = 0
179
135
  })
180
136
 
181
- // Timers: silently ignored. Callback timers (setTimeout/setInterval/setImmediate) become no-ops;
182
- // promise timers (node:timers/promises) return *forever-pending* promises so `await setTimeout()`
183
- // suspends forever. A pending promise doesn't keep the event loop alive, so the process still
184
- // exits cleanly and the loader's beforeExit hook writes the bundle.
137
+ // Timers are ignored: callback timers are no-ops, and promise timers never settle, which keeps no event loop
138
+ // alive, so the process still exits and the loader's beforeExit hook writes the bundle.
185
139
  const noop = () => undefined
186
140
  const pending = () => new Promise(() => {})
187
141
  const TIMERS = ['setTimeout', 'setInterval', 'setImmediate', 'clearTimeout', 'clearInterval', 'clearImmediate']
@@ -191,10 +145,8 @@ const timers = require('node:timers')
191
145
  for (const name of TIMERS) mock.method(timers, name, noop)
192
146
 
193
147
  const timersPromises = require('node:timers/promises')
194
- mock.method(timersPromises, 'setTimeout', pending)
195
- mock.method(timersPromises, 'setImmediate', pending)
196
- // setInterval returns an async iterable; each `await iter.next()` is forever-pending, so
197
- // `for await (const _ of setInterval(...))` hangs at the first iteration.
148
+ for (const name of ['setTimeout', 'setImmediate']) mock.method(timersPromises, name, pending)
149
+ // An async iterable whose `for await` hangs at the first iteration.
198
150
  mock.method(timersPromises, 'setInterval', () => ({
199
151
  [Symbol.asyncIterator]() {
200
152
  return { next: pending }
package/src/parse.js CHANGED
@@ -4,10 +4,8 @@ import { brotliDecompressStrict } from '@exodus/stasis-core/brotli'
4
4
  import { Bundle } from '@exodus/stasis-core/bundle'
5
5
  import { Lockfile } from '@exodus/stasis-core/lockfile'
6
6
 
7
- // Read a stasis artifact and parse it into a Lockfile or Bundle, reporting its `kind`
8
- // ('lockfile' | 'bundle'). Lockfiles are JSON starting with `{`; bundles are brotli-compressed
9
- // JSON — sniff the leading byte to route to the right parser so its diagnostic surfaces on failure.
10
- // A Lockfile or Bundle in place of the path (one built in memory) is taken as it is.
7
+ // A stasis artifact by its leading byte: a lockfile's JSON starts with `{`, a bundle is brotli. A Lockfile or Bundle
8
+ // in place of the path is taken as it is.
11
9
  export function parseFileWithKind(file) {
12
10
  if (file instanceof Lockfile) return { kind: 'lockfile', artifact: file }
13
11
  if (file instanceof Bundle) return { kind: 'bundle', artifact: file }
@@ -39,7 +37,6 @@ export function parseFileWithKind(file) {
39
37
  }
40
38
  }
41
39
 
42
- // Thin wrapper over parseFileWithKind that drops the `kind` (for callers like audit/sbom).
43
40
  export function parseFile(file) {
44
41
  return parseFileWithKind(file).artifact
45
42
  }
package/src/prune.js CHANGED
@@ -1,4 +1 @@
1
- // Public-export adapter: backs `@exodus/stasis/prune`. The implementation lives in
2
- // @exodus/stasis-core; internal tooling and tests import `@exodus/stasis-core/prune`
3
- // directly, so this file exists only to back the package's `exports` map.
4
1
  export * from '@exodus/stasis-core/prune'