@exodus/stasis 1.0.0-beta.8 → 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.
- package/README.md +7 -2
- package/bin/stasis.js +263 -446
- package/package.json +38 -13
- package/src/audit-corrections.js +11 -42
- package/src/audit.js +256 -212
- package/src/babel.js +119 -82
- package/src/bundle-from-lockfile.js +9 -21
- package/src/bundle-reader.js +24 -8
- package/src/bundle.js +0 -3
- package/src/cmd/build.js +211 -117
- package/src/cmd/bundle-options.js +347 -0
- package/src/cmd/bundle.js +1718 -908
- package/src/cmd/diff.js +1 -4
- package/src/cmd/github-bundle.js +48 -21
- package/src/cmd/output.js +24 -12
- package/src/cmd/sbom.js +6 -9
- package/src/cmd/tokens.js +60 -0
- package/src/define.js +218 -0
- package/src/diff.js +73 -129
- package/src/esbuild.js +0 -4
- package/src/flow.js +27 -0
- 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 +43 -120
- package/src/loaders/cargo.js +301 -808
- package/src/loaders/foundry.js +112 -290
- package/src/loaders/paths.js +15 -26
- package/src/loaders/php.js +221 -475
- package/src/loaders/rust.js +518 -1461
- package/src/loaders/solidity-ownership.js +51 -142
- package/src/loaders/solidity.js +42 -188
- package/src/loaders/toml.js +7 -17
- package/src/lockfile.js +0 -3
- package/src/metro-assets.js +41 -0
- package/src/metro-resolver.js +58 -133
- package/src/metro-transformer.js +0 -6
- package/src/metro.js +0 -4
- package/src/mock.js +32 -80
- package/src/parse.js +8 -7
- package/src/prune.js +0 -3
- package/src/resolve-fields.js +170 -235
- package/src/resolve-node.js +33 -46
- package/src/resolve-typescript.js +166 -298
- package/src/rollup.js +0 -4
- package/src/run-installed.js +10 -0
- package/src/sbom.js +70 -97
- package/src/scan.js +241 -278
- package/src/sixel.js +310 -0
- package/src/table.js +95 -0
- 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 +1315 -0
- package/src/vfs-bundle/entries.js +54 -46
- package/src/vfs-bundle/github.js +115 -92
- package/src/vfs-bundle/glob.js +379 -0
- package/src/vfs-bundle/lazy.js +99 -0
- package/src/vfs-bundle/prisma.js +235 -105
- package/src/vfs-bundle/soldeer.js +28 -49
- package/src/vfs-bundle/tree.js +434 -259
- package/src/vfs-bundle/yarnclean.js +79 -0
- package/src/vfs-bundle.js +25 -51
- package/src/webpack.js +0 -4
- package/src/why.js +79 -231
package/src/json-stream.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// Incremental JSON parser over UTF-8 bytes, holding only the value being built and one token in flight
|
|
2
|
-
//
|
|
3
|
-
// so a bundle read in a stream can't parse differently from one read whole. Pure: no Node builtins.
|
|
1
|
+
// Incremental JSON parser over UTF-8 bytes, holding only the value being built and one token in flight: exactly
|
|
2
|
+
// JSON.parse(Buffer.concat(chunks).toString('utf8')) for any chunking (json-stream.test.js checks it), no Node builtins.
|
|
4
3
|
// Not mirrored: Node 24+'s JSON.parse can return a stale escaped key cached by an earlier call (a V8 bug).
|
|
5
4
|
|
|
6
5
|
const QUOTE = 0x22
|
|
@@ -127,7 +126,8 @@ export class JsonStreamParser {
|
|
|
127
126
|
const state = this.#state
|
|
128
127
|
const isArray = Array.isArray(this.#stack.at(-1))
|
|
129
128
|
if ((state === AFTER || state === ARRAY_FIRST || state === OBJECT_FIRST) && b === (isArray ? 0x5d : 0x7d)) {
|
|
130
|
-
this.#
|
|
129
|
+
this.#path.pop()
|
|
130
|
+
this.#value(this.#stack.pop())
|
|
131
131
|
return i + 1
|
|
132
132
|
}
|
|
133
133
|
if (state === AFTER) {
|
|
@@ -256,11 +256,6 @@ export class JsonStreamParser {
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
#close() {
|
|
260
|
-
this.#path.pop()
|
|
261
|
-
this.#value(this.#stack.pop())
|
|
262
|
-
}
|
|
263
|
-
|
|
264
259
|
#value(value) {
|
|
265
260
|
const depth = this.#stack.length
|
|
266
261
|
if (depth === 0) {
|
package/src/loader-mock.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// builtins, so stasis keeps reading/writing through real fs;
|
|
4
|
-
// 2. ./mock.js -- neutralizes the network/timer builtins and fs writers, then calls
|
|
5
|
-
// syncBuiltinESMExports() so user code's later ESM imports resolve to the mocks.
|
|
6
|
-
// Only THEN install() the hooks (so mock.js never goes through them / becomes the bundle entry).
|
|
1
|
+
// `--mock`'s loader, in load-bearing order: the hooks lib, snapshotting stasis's own fs bindings off the real builtins;
|
|
2
|
+
// ./mock.js, mocking them for user code; then install(), so mock.js neither goes through the hooks nor is the entry.
|
|
7
3
|
import { install } from '@exodus/stasis-core/hooks'
|
|
8
|
-
// `export *` (mock.js has no exports)
|
|
9
|
-
// no-unassigned-import lint rule; ESM still evaluates it here in source order.
|
|
4
|
+
// `export *` (mock.js has no exports), not a bare import, for the no-unassigned-import lint rule.
|
|
10
5
|
export * from './mock.js'
|
|
11
6
|
|
|
12
7
|
install()
|
package/src/loader.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
//
|
|
2
|
-
// @exodus/stasis/loader`). The loader lives in @exodus/stasis-core; importing
|
|
3
|
-
// this evaluates it (registering Node's module hooks) for its side effect.
|
|
4
|
-
// Internal code uses `@exodus/stasis-core/loader` directly, so this file exists
|
|
5
|
-
// only to back the package's `exports` map.
|
|
1
|
+
// `node --import @exodus/stasis/loader`: importing the core loader registers Node's module hooks.
|
|
6
2
|
export * from '@exodus/stasis-core/loader'
|
package/src/loaders/bash.js
CHANGED
|
@@ -1,95 +1,63 @@
|
|
|
1
|
-
// Bash loader: `{ sources, resolutions, missing }` from a set of scripts. A
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// paths, absolute/escaping paths) is best-effort and dropped. A dynamically
|
|
5
|
-
// sourced path can be pinned by a `# shellcheck source=...` directive.
|
|
1
|
+
// Bash loader: `{ sources, resolutions, missing }` from a set of scripts. A .sh/.bash reference landing
|
|
2
|
+
// inside the bundle root must resolve to an in-set script, else it is `missing`; everything else (PATH
|
|
3
|
+
// commands, `$VAR` paths, absolute or escaping paths) is best-effort and dropped.
|
|
6
4
|
|
|
7
5
|
import { isUtf8 } from 'node:buffer'
|
|
8
6
|
import { realpathSync } from 'node:fs'
|
|
9
7
|
import { readFile } from 'node:fs/promises'
|
|
10
|
-
import {
|
|
8
|
+
import { join } from 'node:path'
|
|
11
9
|
|
|
12
10
|
import { assertRealPathWithinBase } from '@exodus/stasis-core/util'
|
|
13
11
|
import { isFile } from '../resolve-typescript.js'
|
|
14
|
-
import { applyToDir
|
|
12
|
+
import { applyToDir } from './paths.js'
|
|
15
13
|
|
|
16
|
-
// The capture class excludes backtick
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
// `source script.sh`, `. script.sh`, `. ./script.sh`
|
|
14
|
+
// The capture class excludes backtick, `(` and `)` so a ref inside a command substitution
|
|
15
|
+
// (`` `source x.sh` ``, `$(bash x.sh)`) doesn't swallow the closing delimiter.
|
|
20
16
|
const SOURCE_RE = /(?:^|\n|;|&&|\|\||`|\$\()\s*(?:source|\.)\s+["']?([^\s"';&|#`()]+)["']?/gu
|
|
21
|
-
|
|
22
|
-
// `bash`/`sh script.sh`, incl. `/usr/bin/env bash`, `/bin/sh`, `/usr/bin/bash`.
|
|
23
17
|
const EXEC_RE = /(?:^|\n|;|&&|\|\||`|\$\()\s*(?:\/usr\/bin\/env\s+|\/bin\/|\/usr\/bin\/)?(?:ba)?sh\s+["']?([^\s"';&|#`()]+)["']?/gu
|
|
24
|
-
|
|
25
|
-
// Direct invocation: `./script.sh`, `../lib/helper.bash`, `/path/to/script.sh`
|
|
26
18
|
const DIRECT_RE = /(?:^|\n|;|&&|\|\||`|\$\()\s*["']?(\.\.?\/[^\s"';&|#`()]+\.(?:sh|bash))["']?/gu
|
|
27
|
-
|
|
28
|
-
// Dependency hint comment: `# Depends on: example.sh`
|
|
29
19
|
const COMMENT_RE = /^# Depends on: ([^ ]+\.(?:sh|bash))( |$)/gmu
|
|
30
|
-
|
|
31
|
-
// shellcheck `source=` directive: `# shellcheck source=../lib/config.sh`, the
|
|
32
|
-
// explicit way to point at a dynamically sourced (`$VAR`) file. Resolved relative
|
|
33
|
-
// to the script. `source=/dev/null` is shellcheck's "don't follow" sentinel, ignored below.
|
|
20
|
+
// Pins a dynamically sourced (`$VAR`) file; `source=/dev/null` is shellcheck's "don't follow".
|
|
34
21
|
const SHELLCHECK_SOURCE_RE = /#\s*shellcheck\s[^\n]*?\bsource=["']?([^\s"'#]+)["']?/gu
|
|
35
22
|
|
|
36
|
-
//
|
|
37
|
-
// (never bundle-able); resolveBashCall decides which of the rest name a real file.
|
|
23
|
+
// `$VAR` expansions and `-flags` are never bundle-able.
|
|
38
24
|
export function extractBashCalls(content) {
|
|
39
25
|
const calls = new Set()
|
|
40
26
|
for (const re of [SOURCE_RE, EXEC_RE, DIRECT_RE, COMMENT_RE, SHELLCHECK_SOURCE_RE]) {
|
|
41
|
-
for (const
|
|
42
|
-
|
|
43
|
-
if (ref.includes('$') || ref.startsWith('-') || ref === '/dev/null') continue
|
|
44
|
-
calls.add(ref)
|
|
27
|
+
for (const [, ref] of content.matchAll(re)) {
|
|
28
|
+
if (!ref.includes('$') && !ref.startsWith('-') && ref !== '/dev/null') calls.add(ref)
|
|
45
29
|
}
|
|
46
30
|
}
|
|
47
31
|
return [...calls]
|
|
48
32
|
}
|
|
49
33
|
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
// with neither, only path computation happens. Handling differs by kind (below).
|
|
34
|
+
// A bash reference as a baseDir-relative POSIX path. Existence is checked against `knownFiles`
|
|
35
|
+
// (tree mode) or the filesystem under `baseDir` (walk mode); with neither, nothing exists.
|
|
53
36
|
export function resolveBashCall(ref, fromFile, { knownFiles, baseDir } = {}) {
|
|
54
37
|
const present = (p) => {
|
|
55
38
|
if (!p) return false
|
|
56
39
|
if (knownFiles) return knownFiles.has(p)
|
|
57
|
-
|
|
58
|
-
return false
|
|
40
|
+
return Boolean(baseDir) && isFile(join(baseDir, p))
|
|
59
41
|
}
|
|
60
|
-
|
|
61
42
|
// Null when it escapes baseDir or names baseDir itself.
|
|
62
43
|
const resolveRel = (r) => applyToDir(fromFile, r.split('/')) || null
|
|
63
44
|
|
|
64
|
-
//
|
|
45
|
+
// An absolute path is accepted only if it exists in the project (so `/etc/...` is dropped).
|
|
65
46
|
if (ref.startsWith('/')) {
|
|
66
47
|
const stripped = ref.replace(/^\/+/u, '')
|
|
67
48
|
return present(stripped) ? stripped : null
|
|
68
49
|
}
|
|
69
|
-
|
|
70
|
-
// Path with a slash → computed against the caller's dir; existence deferred to the caller.
|
|
50
|
+
// Existence deferred to the caller.
|
|
71
51
|
if (ref.includes('/')) return resolveRel(ref)
|
|
72
52
|
|
|
73
|
-
// Bare name → only accept a real file.
|
|
74
53
|
const sibling = resolveRel(ref)
|
|
75
54
|
if (present(sibling)) return sibling
|
|
76
55
|
if (sibling !== ref && present(ref)) return ref
|
|
77
|
-
|
|
78
|
-
for (const known of knownFiles) {
|
|
79
|
-
const base = known.includes('/') ? known.slice(known.lastIndexOf('/') + 1) : known
|
|
80
|
-
if (base === ref) return known
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return null
|
|
56
|
+
return knownFiles?.values().find((known) => known.slice(known.lastIndexOf('/') + 1) === ref) ?? null
|
|
84
57
|
}
|
|
85
58
|
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// Build the triple from already-loaded scripts. A ref is `missing` (fatal) only
|
|
90
|
-
// when it resolves INSIDE the bundle root but wasn't collected (a dangling
|
|
91
|
-
// `source ./lib.sh`); null-resolving refs are external and tolerated, and
|
|
92
|
-
// self-refs/non-script exts are dropped silently.
|
|
59
|
+
// Null-resolving refs are external and tolerated; self-refs and an extensionless `source ./env`
|
|
60
|
+
// that isn't there are dropped silently.
|
|
93
61
|
export function buildBashTree(sources) {
|
|
94
62
|
const knownFiles = new Set(sources.keys())
|
|
95
63
|
const resolutions = new Map()
|
|
@@ -97,12 +65,11 @@ export function buildBashTree(sources) {
|
|
|
97
65
|
for (const [path, content] of sources) {
|
|
98
66
|
const specMap = new Map()
|
|
99
67
|
for (const ref of extractBashCalls(content)) {
|
|
100
|
-
//
|
|
101
|
-
// in knownFiles is a genuine dangling dep; a null target is external.
|
|
68
|
+
// A slash ref resolves unchecked, so a target not in knownFiles is a genuine dangling dep.
|
|
102
69
|
const target = resolveBashCall(ref, path, { knownFiles })
|
|
103
70
|
if (target && knownFiles.has(target)) {
|
|
104
|
-
if (target !== path) specMap.set(ref, target)
|
|
105
|
-
} else if (target &&
|
|
71
|
+
if (target !== path) specMap.set(ref, target)
|
|
72
|
+
} else if (target && (ref.endsWith('.sh') || ref.endsWith('.bash'))) {
|
|
106
73
|
console.warn(`[loader.bash] Missing file: ${ref} from ${path}`)
|
|
107
74
|
missing.push({ spec: ref, from: path })
|
|
108
75
|
}
|
|
@@ -112,79 +79,35 @@ export function buildBashTree(sources) {
|
|
|
112
79
|
return { sources, resolutions, missing }
|
|
113
80
|
}
|
|
114
81
|
|
|
115
|
-
// A
|
|
116
|
-
async function readScript(baseDir, relPath) {
|
|
117
|
-
const bytes = await readFile(join(baseDir, relPath))
|
|
118
|
-
if (!isUtf8(bytes)) throw new Error(`Shell script is not valid UTF-8: ${relPath}`)
|
|
119
|
-
return bytes.toString('utf8')
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Walk from `entries` following resolved refs, reading each script once; a ref
|
|
123
|
-
// missing on disk warns and is skipped without aborting the walk.
|
|
82
|
+
// A ref missing on disk warns and is skipped without aborting the walk.
|
|
124
83
|
export async function collectBashFilesFromDisk(baseDir, entries) {
|
|
125
84
|
const sources = new Map()
|
|
126
85
|
const realBase = realpathSync(baseDir)
|
|
127
86
|
|
|
87
|
+
const read = async (relPath) => {
|
|
88
|
+
try {
|
|
89
|
+
assertRealPathWithinBase(realBase, baseDir, relPath)
|
|
90
|
+
const bytes = await readFile(join(baseDir, relPath))
|
|
91
|
+
if (!isUtf8(bytes)) throw new Error(`Shell script is not valid UTF-8: ${relPath}`)
|
|
92
|
+
return [relPath, bytes.toString('utf8')]
|
|
93
|
+
} catch (err) {
|
|
94
|
+
// A slash ref can resolve to a directory (`source ./lib`).
|
|
95
|
+
if (err.code !== 'ENOENT' && err.code !== 'EISDIR') throw err
|
|
96
|
+
console.warn(`[loader.bash] ${err.code === 'ENOENT' ? 'Missing file' : 'Skipping directory reference'}: ${relPath}`)
|
|
97
|
+
return null
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
128
101
|
const processWave = async (wave) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
toLoad.map(async (relPath) => {
|
|
133
|
-
try {
|
|
134
|
-
assertRealPathWithinBase(realBase, baseDir, relPath)
|
|
135
|
-
return [relPath, await readScript(baseDir, relPath)]
|
|
136
|
-
} catch (err) {
|
|
137
|
-
if (err.code === 'ENOENT') {
|
|
138
|
-
console.warn(`[loader.bash] Missing file: ${relPath}`)
|
|
139
|
-
return null
|
|
140
|
-
}
|
|
141
|
-
// A slash ref can resolve to a directory (`source ./lib`) → EISDIR; skip, don't abort.
|
|
142
|
-
if (err.code === 'EISDIR') {
|
|
143
|
-
console.warn(`[loader.bash] Skipping directory reference: ${relPath}`)
|
|
144
|
-
return null
|
|
145
|
-
}
|
|
146
|
-
throw err
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
)
|
|
150
|
-
const next = []
|
|
151
|
-
for (const entry of reads) {
|
|
152
|
-
if (!entry) continue
|
|
153
|
-
const [relPath, content] = entry
|
|
102
|
+
if (wave.size === 0) return
|
|
103
|
+
const next = new Set()
|
|
104
|
+
for (const [relPath, content] of (await Promise.all([...wave].map(read))).filter(Boolean)) {
|
|
154
105
|
sources.set(relPath, content)
|
|
155
|
-
for (const ref of extractBashCalls(content)) {
|
|
156
|
-
const resolved = resolveBashCall(ref, relPath, { baseDir })
|
|
157
|
-
if (resolved && !sources.has(resolved)) next.push(resolved)
|
|
158
|
-
}
|
|
106
|
+
for (const ref of extractBashCalls(content)) next.add(resolveBashCall(ref, relPath, { baseDir }))
|
|
159
107
|
}
|
|
160
|
-
await processWave(next)
|
|
108
|
+
await processWave(new Set([...next].filter((p) => p && !sources.has(p))))
|
|
161
109
|
}
|
|
162
110
|
|
|
163
|
-
await processWave(entries)
|
|
111
|
+
await processWave(new Set(entries))
|
|
164
112
|
return sources
|
|
165
113
|
}
|
|
166
|
-
|
|
167
|
-
// High-level entry: reads the scripts named in a `.sh.txt` listing (relative to
|
|
168
|
-
// it). Unlike loadRust, the listing is authoritative — bash sourcing is too
|
|
169
|
-
// dynamic to walk — so exactly the listed files are read, resolutions computed among them.
|
|
170
|
-
export async function loadBash(shTxtFile) {
|
|
171
|
-
const baseDir = dirname(resolve(shTxtFile))
|
|
172
|
-
const listing = await readFile(shTxtFile, 'utf8')
|
|
173
|
-
const lines = listing.split('\n').map((l) => l.trim()).filter(Boolean)
|
|
174
|
-
.map((l) => l.replace(/^\.\//u, ''))
|
|
175
|
-
if (lines.length === 0) throw new Error(`Empty bash listing: ${shTxtFile}`)
|
|
176
|
-
|
|
177
|
-
if (!lines.every((line) => ['', '.sh', '.bash'].includes(extname(line)))) {
|
|
178
|
-
throw new Error(`Bash listing must only contain .sh/.bash files: ${shTxtFile}`)
|
|
179
|
-
}
|
|
180
|
-
for (const line of lines) assertWithinBase(baseDir, line, 'Entry path')
|
|
181
|
-
|
|
182
|
-
const realBase = realpathSync(baseDir)
|
|
183
|
-
const reads = await Promise.all(
|
|
184
|
-
lines.map(async (relPath) => {
|
|
185
|
-
assertRealPathWithinBase(realBase, baseDir, relPath)
|
|
186
|
-
return [relPath, await readScript(baseDir, relPath)]
|
|
187
|
-
}),
|
|
188
|
-
)
|
|
189
|
-
return buildBashTree(new Map(reads))
|
|
190
|
-
}
|