@exodus/stasis 1.0.0-beta.14 → 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 +2 -1
- package/bin/stasis.js +99 -16
- package/package.json +22 -9
- package/src/audit-corrections.js +11 -42
- package/src/audit.js +241 -190
- 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 +82 -174
- package/src/cmd/bundle-options.js +113 -167
- package/src/cmd/bundle.js +942 -1294
- package/src/cmd/diff.js +1 -4
- package/src/cmd/github-bundle.js +21 -26
- package/src/cmd/output.js +15 -12
- package/src/cmd/sbom.js +3 -8
- package/src/cmd/tokens.js +16 -23
- package/src/define.js +36 -94
- package/src/diff.js +72 -128
- package/src/esbuild.js +0 -4
- package/src/flow.js +18 -13
- 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 +10 -384
- package/src/metro-resolver.js +58 -134
- package/src/metro-transformer.js +0 -5
- package/src/metro.js +0 -4
- package/src/mock.js +32 -80
- package/src/parse.js +4 -4
- package/src/prune.js +0 -3
- package/src/resolve-fields.js +137 -532
- package/src/resolve-node.js +27 -45
- package/src/resolve-typescript.js +166 -298
- package/src/rollup.js +0 -4
- package/src/run-installed.js +10 -0
- package/src/sbom.js +52 -128
- package/src/scan.js +142 -284
- package/src/sixel.js +310 -0
- package/src/table.js +63 -31
- package/src/validate-notes.d.ts +19 -0
- package/src/validate-notes.js +72 -0
- package/src/validate.d.ts +159 -0
- package/src/validate.js +596 -522
- package/src/vfs-bundle/entries.js +40 -57
- package/src/vfs-bundle/github.js +80 -122
- package/src/vfs-bundle/glob.js +4 -45
- package/src/vfs-bundle/lazy.js +27 -56
- package/src/vfs-bundle/prisma.js +235 -105
- 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 +78 -232
- package/src/installed-commits.js +0 -184
package/src/mock.js
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
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
|
-
//
|
|
22
|
-
//
|
|
23
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
47
|
-
//
|
|
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 = (
|
|
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(
|
|
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
|
-
|
|
74
|
-
'node:
|
|
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
|
-
//
|
|
102
|
-
//
|
|
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
|
-
//
|
|
119
|
-
if (process.report
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
154
|
-
//
|
|
155
|
-
|
|
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
|
-
//
|
|
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
|
|
182
|
-
//
|
|
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,
|
|
195
|
-
|
|
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,11 @@ 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
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// JSON — sniff the leading byte to route to the right parser so its diagnostic surfaces on failure.
|
|
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.
|
|
10
9
|
export function parseFileWithKind(file) {
|
|
10
|
+
if (file instanceof Lockfile) return { kind: 'lockfile', artifact: file }
|
|
11
|
+
if (file instanceof Bundle) return { kind: 'bundle', artifact: file }
|
|
11
12
|
let buf
|
|
12
13
|
try {
|
|
13
14
|
buf = readFileSync(file)
|
|
@@ -36,7 +37,6 @@ export function parseFileWithKind(file) {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
// Thin wrapper over parseFileWithKind that drops the `kind` (for callers like audit/sbom).
|
|
40
40
|
export function parseFile(file) {
|
|
41
41
|
return parseFileWithKind(file).artifact
|
|
42
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'
|