@exodus/stasis 1.0.0-beta.12 → 1.0.0-beta.14
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 +4 -1
- package/bin/stasis.js +111 -139
- package/package.json +21 -12
- package/src/audit.js +3 -40
- package/src/babel.js +44 -37
- package/src/bundle-reader.js +24 -4
- package/src/cmd/build.js +194 -8
- package/src/cmd/bundle-options.js +103 -24
- package/src/cmd/bundle.js +986 -239
- package/src/cmd/github-bundle.js +17 -8
- package/src/cmd/output.js +10 -3
- package/src/cmd/tokens.js +67 -0
- package/src/diff.js +2 -2
- package/src/flow.js +22 -0
- package/src/installed-commits.js +4 -2
- package/src/loaders/bash.js +2 -27
- package/src/loaders/cargo.js +6 -6
- package/src/loaders/foundry.js +4 -6
- package/src/loaders/paths.js +4 -15
- package/src/loaders/php.js +3 -5
- package/src/loaders/rust.js +19 -39
- package/src/loaders/solidity-ownership.js +4 -15
- package/src/loaders/solidity.js +4 -67
- package/src/metro-assets.js +415 -0
- package/src/metro-resolver.js +5 -3
- package/src/parse.js +4 -3
- package/src/resolve-fields.js +60 -28
- package/src/resolve-node.js +9 -7
- package/src/resolve-typescript.js +3 -3
- package/src/scan.js +140 -53
- package/src/table.js +63 -0
- package/src/validate.js +1241 -0
- package/src/vfs-bundle/entries.js +24 -3
- package/src/vfs-bundle/github.js +72 -23
- package/src/vfs-bundle/glob.js +420 -0
- package/src/vfs-bundle/lazy.js +128 -0
- package/src/vfs-bundle/tree.js +242 -79
- package/src/vfs-bundle/yarnclean.js +100 -0
- package/src/vfs-bundle.js +26 -16
package/README.md
CHANGED
|
@@ -69,11 +69,13 @@ _Lockfiles (npm/pnpm/etc) not mentioned: they are like the "tarball" column, but
|
|
|
69
69
|
| `stasis github-bundle --github=owner/name --sha=<commit> src/index.js` | statically bundle a GitHub repo at a commit, with nothing installed |
|
|
70
70
|
| `stasis build --output=out.js app.stasis.code.br [entry]` | rebuild a runnable JS bundle with esbuild, following the bundle's recorded import graph exactly |
|
|
71
71
|
| `stasis build --output=out.js stasis.lock.json [entry]` | same, reading + verifying sources from disk against the lockfile |
|
|
72
|
-
| `stasis
|
|
72
|
+
| `stasis build --platform=hermes --metro=ios --assets-dest=dist --output=main.js app.stasis.code.br` | build a `--metro` bundle for one platform as Metro does: its `.ios` files, assets as Metro's asset modules, their files copied out |
|
|
73
|
+
| `stasis extract --lock=add app.stasis.code.br` | unpack a bundle back to sources + a `stasis.lock.json` |
|
|
73
74
|
| `stasis diff --stat a.lock.json b.stasis.code.br` | summarize module/file differences between two lockfiles/bundles |
|
|
74
75
|
| `stasis prune` | trim `node_modules` to the lockfile, verifying the rest |
|
|
75
76
|
| `stasis audit stasis.lock.json` | report advisories for a lockfile's or bundle's dependencies |
|
|
76
77
|
| `stasis audit --why app.stasis.code.br` | same, with the import chains that pull each flagged package in |
|
|
78
|
+
| `stasis validate app.stasis.code.br` | check a bundle's own code against its repository and its dependencies against their published packages, held to its lockfile |
|
|
77
79
|
| `stasis sbom --format=spdx stasis.lock.json` | export an SPDX SBOM for a lockfile or bundle |
|
|
78
80
|
| `stasis sbom --format=cyclonedx app.stasis.code.br` | export a CycloneDX SBOM for a lockfile or bundle |
|
|
79
81
|
|
|
@@ -86,6 +88,7 @@ Each command's options are documented in [doc/](https://github.com/PreventiveMea
|
|
|
86
88
|
[`diff`](https://github.com/PreventiveMeasures/stasis/blob/main/doc/diff.md),
|
|
87
89
|
[`prune`](https://github.com/PreventiveMeasures/stasis/blob/main/doc/prune.md),
|
|
88
90
|
[`audit`](https://github.com/PreventiveMeasures/stasis/blob/main/doc/audit.md),
|
|
91
|
+
[`validate`](https://github.com/PreventiveMeasures/stasis/blob/main/doc/validate.md),
|
|
89
92
|
[`sbom`](https://github.com/PreventiveMeasures/stasis/blob/main/doc/sbom.md).
|
|
90
93
|
`stasis bundle` also bundles Solidity, PHP, Bash and Rust sources, see [file formats](https://github.com/PreventiveMeasures/stasis/blob/main/doc/file-formats.md#source-language-bundles-solidity--php--bash--rust).
|
|
91
94
|
|
package/bin/stasis.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { spawn } from 'node:child_process'
|
|
4
|
-
import { once } from 'node:events'
|
|
5
3
|
import { fileURLToPath } from 'node:url'
|
|
6
4
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path'
|
|
7
5
|
import { existsSync, realpathSync } from 'node:fs'
|
|
8
|
-
import { homedir
|
|
6
|
+
import { homedir } from 'node:os'
|
|
9
7
|
import assert from 'node:assert/strict'
|
|
10
|
-
import {
|
|
8
|
+
import { parseLeadingOptions, valueFlagsOf } from '@exodus/stasis-core/util'
|
|
9
|
+
import { addCli, brotliQualityOption, extractCli, parseRunOptions, pruneCli, runProgram, setEnv, setRunEnv } from '@exodus/stasis-core/cli'
|
|
11
10
|
import pkg from '../package.json' with { type: 'json' }
|
|
12
11
|
|
|
13
12
|
const argv = [...process.argv]
|
|
@@ -20,23 +19,24 @@ assert(basename(jsname) === 'stasis' || pathsEqual(jsname, fileURLToPath(import.
|
|
|
20
19
|
|
|
21
20
|
const HELP = `Usage:
|
|
22
21
|
stasis run --lock=(add|replace|frozen|ignore) [--bundle=(add|replace|load|frozen|ignore)] [--bundle-file=path/to/bundle.br] [--resources-bundle-file=path/to/resources.br] [--dependencies] [--child-process] [--package-json] [--mock] [--import=module ...] [--fs=(sync|async)] [--resources=ext,ext] [--brotli-quality=0..11] path/to/file.js ...
|
|
23
|
-
stasis bundle [--scope=(node_modules|full)] [--conditions=cond1,cond2] [--mainFields=field1,field2] [--metro [--metro-resolver] [--babel|--babel-aliases=path/to/aliases.json] --platforms=ios,android] [--jsx] [--flow] [--typescript [--tsconfig=path/to/tsconfig.json]] [--resources=ext,ext] [--define=K=V ...] [--package-json] [--lockfile=path/to/stasis.lock.json] [--brotli-quality=0..11] [--add] [--output=(path|-)] path/to/file.(js|ts|jsx|tsx) ...
|
|
24
|
-
stasis bundle [--mapping=path/to/remappings(.txt|.toml)] [--manifests] [--add] [--output=(path|-)] path/to/(file.sol|dir) ...
|
|
22
|
+
stasis bundle [--deptree] [--scope=(node_modules|full)] [--conditions=cond1,cond2] [--mainFields=field1,field2] [--metro [--metro-resolver] [--babel|--babel-aliases=path/to/aliases.json] --platforms=ios,android] [--jsx] [--flow] [--typescript [--tsconfig=path/to/tsconfig.json]] [--resources=ext,ext] [--define=K=V ...] [--package-json] [--lockfile=path/to/stasis.lock.json] [--brotli-quality=0..11] [--add] [--output=(path|-)] path/to/file.(js|ts|jsx|tsx) ...
|
|
23
|
+
stasis bundle [--deptree] [--mapping=path/to/remappings(.txt|.toml)] [--manifests] [--add] [--output=(path|-)] path/to/(file.sol|dir) ...
|
|
25
24
|
stasis bundle [--cargo] [--cargo-features=a,b,pkg/c] [--cargo-no-default-features] [--cargo-all-features] [--cargo-target=(triple|host)] [--cargo-manifests] [--add] [--output=(path|-)] path/to/file.rs ...
|
|
26
25
|
stasis bundle [--add] [--output=(path|-)] path/to/file.(php|sh|bash) ...
|
|
27
|
-
stasis bundle [--babel] [--metro-resolver] [--
|
|
28
|
-
stasis github-bundle
|
|
26
|
+
stasis bundle [--deptree] [--babel] [--metro-resolver] [--cargo] [--cargo-target=(triple|host)] [--lockfile=path/to/stasis.lock.json] [--brotli-quality=0..11] [--add] [--output=(path|-)] [entry ...] (the entries' options from stasis.config.json's entries)
|
|
27
|
+
stasis github-bundle (owner/name[/path]|--github=owner/name [--directory=path]) [--sha=commit|--tag=name] [--package-manager=(pnpm|yarn1|npm|soldeer) [--package-manager-version=version]] [--no-lazy] [--generate=prisma] [--lockfile=path/to/stasis.lock.json] [--output=(path|-)] [stasis bundle's options for the entries] [path/in/repo/to/(file.(js|ts|jsx|tsx)|file.sol|dir) ...]
|
|
29
28
|
stasis add path/to/(file|dir) ...
|
|
30
|
-
stasis build --output=(dir|file.js) [--format=(esm|cjs|iife)] [--platform=(node|browser|neutral|hermes)] [--babel] [--minify] [--sourcemap] [--define=K=V ...] [--external=pkg ...] [--loader=.ext:name ...] path/to/(stasis.code.br|stasis.lock.json) [entry]
|
|
31
|
-
stasis extract [--output=path/to/dir] path/to/bundle.stasis.code.br
|
|
29
|
+
stasis build --output=(dir|file.js) [--format=(esm|cjs|iife)] [--platform=(node|browser|neutral|hermes)] [--babel|--flow] [--minify] [--sourcemap] [--define=K=V ...] [--external=pkg ...] [--loader=.ext:name ...] [--metro=(ios|android|...) [--assets-dest=dir]] path/to/(stasis.code.br|stasis.lock.json) [entry]
|
|
30
|
+
stasis extract [--output=path/to/dir] [--lock=(frozen|add|replace|ignore|none)] path/to/bundle.stasis.code.br
|
|
32
31
|
stasis diff --stat [--imports] path/to/(lockfile|bundle) path/to/(lockfile|bundle)
|
|
33
32
|
stasis prune [path/to/project]
|
|
34
33
|
stasis audit [--why|--why-deep] [--why-full] [--reason=consumer] [--repo-advisories] path/to/(lockfile|bundle) ...
|
|
34
|
+
stasis validate [--github=owner/name] [--sha=commit] [--directory=path] [--only-deps] [--lockfile=path | --no-lockfile] [--allow-unverified] [--show-valid] path/to/bundle
|
|
35
35
|
stasis sbom --format=(spdx|cyclonedx) [--output=(path|-)] path/to/(lockfile|bundle) ...
|
|
36
36
|
stasis --version
|
|
37
37
|
|
|
38
38
|
Each command's options: https://github.com/PreventiveMeasures/stasis/blob/main/doc/<command>.md
|
|
39
|
-
(run, bundle, github-bundle, build, extract, diff, prune, audit, sbom; add is in bundle.md)`
|
|
39
|
+
(run, bundle, github-bundle, build, extract, diff, prune, audit, validate, sbom; add is in bundle.md)`
|
|
40
40
|
|
|
41
41
|
// The help, on stderr. Exits 0 when asked for (--help), 1 when printed for want of a command.
|
|
42
42
|
function usage(asked = false) {
|
|
@@ -50,12 +50,6 @@ function fail(message) {
|
|
|
50
50
|
process.exit(1)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function setEnv(name, value) {
|
|
54
|
-
const env = process.env[name]
|
|
55
|
-
if (env && env !== value) throw new Error(`env conflict: ${name}="${env}", effective: "${value}"`)
|
|
56
|
-
process.env[name] = value === undefined ? '' : value
|
|
57
|
-
}
|
|
58
|
-
|
|
59
53
|
// The per-user cache directory, as each platform names it (XDG ignores a relative path).
|
|
60
54
|
function userCacheDir() {
|
|
61
55
|
if (isAbsolute(process.env.XDG_CACHE_HOME ?? '')) return join(process.env.XDG_CACHE_HOME, 'stasis')
|
|
@@ -72,86 +66,22 @@ if (command === '-v' || command === '--version') {
|
|
|
72
66
|
} else if (command === '-h' || command === '--help') {
|
|
73
67
|
usage(true)
|
|
74
68
|
} else if (command === 'run') {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
bundle: { type: 'string', default: 'none' },
|
|
78
|
-
'bundle-file': { type: 'string' },
|
|
79
|
-
'resources-bundle-file': { type: 'string' },
|
|
80
|
-
debug: { type: 'boolean' },
|
|
81
|
-
dependencies: { type: 'boolean' },
|
|
82
|
-
'child-process': { type: 'boolean' },
|
|
83
|
-
'package-json': { type: 'boolean' },
|
|
84
|
-
mock: { type: 'boolean' },
|
|
85
|
-
import: { type: 'string', multiple: true },
|
|
86
|
-
fs: { type: 'string' },
|
|
87
|
-
resources: { type: 'string' },
|
|
88
|
-
'brotli-quality': { type: 'string' },
|
|
89
|
-
}
|
|
90
|
-
const values = parseLeadingOptions(argv, options, {
|
|
91
|
-
valueFlags: ['--bundle', '--bundle-file', '--resources-bundle-file', '--lock', '--import', '--resources', '--brotli-quality'],
|
|
92
|
-
onError: fail,
|
|
93
|
-
})
|
|
94
|
-
if (argv.length === 0) fail('Nothing to run: no path to file given')
|
|
95
|
-
if (!['none', 'ignore', 'add', 'replace', 'frozen'].includes(values.lock)) fail('Error: invalid --lock value')
|
|
96
|
-
const lock = values.lock
|
|
97
|
-
const scope = values.dependencies ? 'node_modules' : 'full'
|
|
98
|
-
const bundle = values.bundle
|
|
99
|
-
const bundleFile = values['bundle-file'] ? resolve(values['bundle-file']) : ''
|
|
100
|
-
const resourcesBundleFile = values['resources-bundle-file'] ? resolve(values['resources-bundle-file']) : ''
|
|
101
|
-
const debug = values.debug ? '1' : ''
|
|
102
|
-
if (!['none', 'ignore', 'add', 'replace', 'load', 'frozen'].includes(bundle)) fail('Error: invalid --bundle value')
|
|
103
|
-
if (bundleFile && bundle === 'none') fail('Error: --bundle-file requires --bundle=(add|replace|load|frozen|ignore)')
|
|
104
|
-
// --resources-bundle-file needs an active bundle mode (unlike --bundle-file, inert under ignore).
|
|
105
|
-
if (resourcesBundleFile && (bundle === 'none' || bundle === 'ignore')) fail('Error: --resources-bundle-file requires --bundle=(add|replace|load|frozen)')
|
|
106
|
-
if (bundle === 'load' && lock !== 'frozen' && lock !== 'none' && lock !== 'ignore') fail('Error: --bundle=load is incompatible with --lock=(add|replace)')
|
|
107
|
-
if (lock === 'none' && bundle === 'none') fail('Error: stasis needs a lockfile or a bundle: set --lock or --bundle')
|
|
69
|
+
const run = parseRunOptions(argv, { options: { 'package-json': { type: 'boolean' }, mock: { type: 'boolean' } }, fail })
|
|
70
|
+
const { values, bundle, bundleFile, resourcesBundleFile } = run
|
|
108
71
|
if (values.mock && bundle === 'load') fail('Error: --mock is for capturing imports while building a bundle; not compatible with --bundle=load')
|
|
109
|
-
// --fs requires a bundle mode (add|replace|load); `sync` patches the sync fs readers,
|
|
110
|
-
// `async` adds their callback + fs.promises counterparts on top.
|
|
111
|
-
if (values.fs !== undefined && !['sync', 'async'].includes(values.fs)) fail("Error: --fs must be 'sync' or 'async'")
|
|
112
|
-
if (values.fs !== undefined && !['add', 'replace', 'load'].includes(bundle)) fail('Error: --fs requires --bundle=(add|replace|load)')
|
|
113
|
-
const captureFs = values.fs ?? ''
|
|
114
|
-
// --resources: comma-separated extension/filename allowlist for `--fs` captures.
|
|
115
|
-
const resources = values.resources ?? ''
|
|
116
|
-
let brotliQuality
|
|
117
|
-
if (values['brotli-quality'] !== undefined) {
|
|
118
|
-
try {
|
|
119
|
-
brotliQuality = parseBrotliQuality('--brotli-quality', values['brotli-quality'])
|
|
120
|
-
} catch (cause) {
|
|
121
|
-
fail(`Error: ${cause.message}`)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// --import: extra preload module(s) passed through to the spawned node. Node resolves each
|
|
125
|
-
// against the project cwd; they ride AFTER stasis's own loader import.
|
|
126
|
-
const imports = values.import ?? []
|
|
127
|
-
if (imports.some((s) => s === '')) fail('Error: --import requires a module specifier (e.g. --import=./instrument.mjs)')
|
|
128
72
|
// Not a usage error: plain instrumentation/setup preloads still work under the mock; only ones
|
|
129
73
|
// that need the denied surfaces (spawning helper processes, network) die, and they do so loudly.
|
|
130
|
-
if (values.mock && imports.length > 0) {
|
|
74
|
+
if (values.mock && run.imports.length > 0) {
|
|
131
75
|
console.warn("[stasis] Warning: --import preloads run under --mock's side-effect denials; a preload that spawns helper processes will fail there")
|
|
132
76
|
}
|
|
133
|
-
// --child-process: forward forked-child (e.g. Metro worker) capture to the root via per-pid shards.
|
|
134
|
-
const childProcess = values['child-process'] ? '1' : ''
|
|
135
77
|
// --package-json: auto-include every bundled module's package.json. Only meaningful while WRITING
|
|
136
78
|
// a bundle (add|replace) -- there's nothing to fold the manifests into otherwise.
|
|
137
79
|
if (values['package-json'] && bundle !== 'add' && bundle !== 'replace') {
|
|
138
80
|
fail('Error: --package-json requires --bundle=(add|replace)')
|
|
139
81
|
}
|
|
140
82
|
const packageJSON = values['package-json'] ? '1' : ''
|
|
141
|
-
|
|
142
|
-
if (debug) console.warn(`[stasis] Warning: stasis debug mode active`)
|
|
143
|
-
setEnv('EXODUS_STASIS_LOCK', lock)
|
|
144
|
-
setEnv('EXODUS_STASIS_SCOPE', scope)
|
|
145
|
-
setEnv('EXODUS_STASIS_BUNDLE', bundle)
|
|
146
|
-
setEnv('EXODUS_STASIS_BUNDLE_FILE', bundleFile)
|
|
147
|
-
setEnv('EXODUS_STASIS_RESOURCES_BUNDLE_FILE', resourcesBundleFile)
|
|
148
|
-
setEnv('EXODUS_STASIS_DEBUG', debug)
|
|
149
|
-
setEnv('EXODUS_STASIS_CHILD_PROCESS', childProcess)
|
|
83
|
+
setRunEnv('stasis', run, { ...(packageJSON && { packageJSON: true }), ...(values.mock && { mock: true }) })
|
|
150
84
|
setEnv('EXODUS_STASIS_PACKAGE_JSON', packageJSON)
|
|
151
|
-
setEnv('EXODUS_STASIS_FS', captureFs)
|
|
152
|
-
setEnv('EXODUS_STASIS_RESOURCES', resources)
|
|
153
|
-
// Only set when given; an unconditional setEnv('') would conflict with an ambient value.
|
|
154
|
-
if (brotliQuality !== undefined) setEnv('EXODUS_STASIS_BROTLI_QUALITY', String(brotliQuality))
|
|
155
85
|
// --mock: capture imports by running user code with side-effects denied (fail-closed).
|
|
156
86
|
// --permission blocks fs writes/child procs/workers/addons/inspector at the kernel level;
|
|
157
87
|
// src/mock.js neutralizes network + timers in JS (no --allow-* for those). Reads stay open
|
|
@@ -178,20 +108,13 @@ if (command === '-v' || command === '--version') {
|
|
|
178
108
|
// import map matches a non-mock run; native addons still can't load (--allow-addons off).
|
|
179
109
|
nodeArgs.push('--conditions=node-addons')
|
|
180
110
|
}
|
|
181
|
-
// --mock uses stasis's loader-mock entry (composes the mock before installing the hooks)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
// under its hooks; their module graphs pass through uncaptured unless the app graph reaches
|
|
186
|
-
// them -- then they're promoted into the capture (see core hooks.js).
|
|
187
|
-
for (const specifier of imports) nodeArgs.push('--import', specifier)
|
|
188
|
-
const child = spawn(process.execPath, [...nodeArgs, ...argv], { stdio: 'inherit' })
|
|
189
|
-
const [code, signal] = await once(child, 'close')
|
|
190
|
-
// code is null when the child died from a signal; report 128+signo (shell convention) instead of the implicit 0
|
|
191
|
-
process.exitCode = code ?? 128 + (osConstants.signals[signal] ?? 0)
|
|
111
|
+
// --mock uses stasis's loader-mock entry (composes the mock before installing the hooks), whose
|
|
112
|
+
// denials the --import preloads then run under.
|
|
113
|
+
const loader = import.meta.resolve(values.mock ? '../src/loader-mock.js' : '@exodus/stasis-core/loader')
|
|
114
|
+
await runProgram(argv, { nodeArgs, loader, imports: run.imports })
|
|
192
115
|
} else if (command === 'bundle') {
|
|
193
|
-
const { BUNDLE_FLAGS,
|
|
194
|
-
const values = parseLeadingOptions(argv, BUNDLE_FLAGS, { valueFlags:
|
|
116
|
+
const { BUNDLE_FLAGS, bundlePlan, readConfigEntries } = await import('../src/cmd/bundle-options.js')
|
|
117
|
+
const values = parseLeadingOptions(argv, BUNDLE_FLAGS, { valueFlags: valueFlagsOf(BUNDLE_FLAGS), onError: fail })
|
|
195
118
|
const cwd = process.cwd()
|
|
196
119
|
let plan
|
|
197
120
|
try {
|
|
@@ -207,13 +130,14 @@ if (command === '-v' || command === '--version') {
|
|
|
207
130
|
const { bundleCommand } = await import('../src/cmd/bundle.js')
|
|
208
131
|
await bundleCommand({ cwd, ...plan })
|
|
209
132
|
} else if (command === 'github-bundle') {
|
|
210
|
-
const
|
|
133
|
+
const options = {
|
|
211
134
|
github: { type: 'string' },
|
|
212
135
|
sha: { type: 'string' },
|
|
213
136
|
tag: { type: 'string' },
|
|
214
137
|
directory: { type: 'string' },
|
|
215
138
|
'package-manager': { type: 'string' },
|
|
216
139
|
'package-manager-version': { type: 'string' },
|
|
140
|
+
'no-lazy': { type: 'boolean' },
|
|
217
141
|
mapping: { type: 'string' },
|
|
218
142
|
manifests: { type: 'boolean' },
|
|
219
143
|
output: { type: 'string', short: 'o' },
|
|
@@ -232,22 +156,28 @@ if (command === '-v' || command === '--version') {
|
|
|
232
156
|
'package-json': { type: 'boolean' },
|
|
233
157
|
'brotli-quality': { type: 'string' },
|
|
234
158
|
generate: { type: 'string', multiple: true },
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
159
|
+
}
|
|
160
|
+
const parse = (args) => parseLeadingOptions(args, options, { valueFlags: valueFlagsOf(options), onError: fail })
|
|
161
|
+
// The repo as `owner/name[/path]`, for --github=owner/name [--directory=path]: the first argument
|
|
162
|
+
// that is no option, where no --github comes before it, with options on either side of it. The
|
|
163
|
+
// path is a directory, or a file: an entry of the nearest project above it (buildGitHubBundle's).
|
|
164
|
+
const rest = [...argv]
|
|
165
|
+
const bare = parse(rest).github === undefined && rest.length > 0 ? argv.splice(argv.length - rest.length, 1)[0] : undefined
|
|
166
|
+
const values = parse(argv)
|
|
167
|
+
let { github } = values
|
|
168
|
+
let path
|
|
169
|
+
if (bare !== undefined) {
|
|
170
|
+
if (github !== undefined || values.directory !== undefined) fail('Error: github-bundle takes owner/name[/path] or --github=owner/name [--directory=path], not both')
|
|
171
|
+
const [owner, name, ...segments] = bare.split('/')
|
|
172
|
+
if (name === undefined) fail(`Error: github-bundle: '${bare}' is not owner/name[/path], the repo to bundle`)
|
|
173
|
+
github = `${owner}/${name}`
|
|
174
|
+
path = segments.join('/') || undefined
|
|
175
|
+
}
|
|
176
|
+
if (github === undefined) fail('Error: github-bundle requires the repo to bundle: owner/name[/path], or --github=owner/name')
|
|
240
177
|
if (values.sha !== undefined && values.tag !== undefined) fail('Error: github-bundle takes --sha or --tag, not both')
|
|
241
178
|
// Whether each option applies to the entries is buildGitHubBundle's to say.
|
|
242
179
|
const list = (value) => [value ?? []].flat().flatMap((v) => v.split(',')).map((s) => s.trim()).filter(Boolean)
|
|
243
|
-
|
|
244
|
-
if (values['brotli-quality'] !== undefined) {
|
|
245
|
-
try {
|
|
246
|
-
brotliQuality = parseBrotliQuality('--brotli-quality', values['brotli-quality'])
|
|
247
|
-
} catch (cause) {
|
|
248
|
-
fail(`Error: ${cause.message}`)
|
|
249
|
-
}
|
|
250
|
-
}
|
|
180
|
+
const brotliQuality = brotliQualityOption(values['brotli-quality'], fail)
|
|
251
181
|
let define
|
|
252
182
|
if (values.define !== undefined) {
|
|
253
183
|
const { parseDefineFlags } = await import('../src/define.js')
|
|
@@ -262,12 +192,15 @@ if (command === '-v' || command === '--version') {
|
|
|
262
192
|
setCacheDir(userCacheDir())
|
|
263
193
|
const { githubBundleCommand } = await import('../src/cmd/github-bundle.js')
|
|
264
194
|
await githubBundleCommand({
|
|
265
|
-
github
|
|
195
|
+
github,
|
|
266
196
|
sha: values.sha,
|
|
267
197
|
tag: values.tag,
|
|
268
198
|
directory: values.directory,
|
|
199
|
+
path,
|
|
269
200
|
packageManager: values['package-manager'],
|
|
270
201
|
packageManagerVersion: values['package-manager-version'],
|
|
202
|
+
// Lazy where the tree can be, unless --no-lazy or stasis.config.json's lazyDependencies says not.
|
|
203
|
+
lazy: values['no-lazy'] ? false : undefined,
|
|
271
204
|
entries: argv.length === 0 ? undefined : argv,
|
|
272
205
|
mappingFile: values.mapping,
|
|
273
206
|
manifests: Boolean(values.manifests),
|
|
@@ -289,31 +222,29 @@ if (command === '-v' || command === '--version') {
|
|
|
289
222
|
brotliQuality,
|
|
290
223
|
})
|
|
291
224
|
} else if (command === 'add') {
|
|
292
|
-
|
|
293
|
-
// stasis.config.json; it takes no flags.
|
|
294
|
-
if (argv.length === 0) fail('Nothing to add: no file given')
|
|
295
|
-
if (argv.some((a) => a.startsWith('-'))) fail('Error: add takes no options; its targets and resource allowlist come from stasis.config.json')
|
|
296
|
-
const { addCommand } = await import('@exodus/stasis-core/add')
|
|
297
|
-
// Let addCommand's runtime errors propagate as-is; wrapping in fail() would bury the cause.
|
|
298
|
-
addCommand({ cwd: process.cwd(), entries: argv, logLabel: 'stasis' })
|
|
225
|
+
await addCli(argv, { label: 'stasis', fail })
|
|
299
226
|
} else if (command === 'build') {
|
|
300
227
|
const options = {
|
|
301
228
|
output: { type: 'string', short: 'o' },
|
|
302
229
|
format: { type: 'string' },
|
|
303
230
|
platform: { type: 'string' },
|
|
304
231
|
babel: { type: 'boolean' },
|
|
232
|
+
flow: { type: 'boolean' },
|
|
305
233
|
minify: { type: 'boolean' },
|
|
306
234
|
sourcemap: { type: 'boolean' },
|
|
307
235
|
// Repeatable esbuild passthroughs (--define=K=V, --external=PATTERN, --loader=.ext:name).
|
|
308
236
|
define: { type: 'string', multiple: true },
|
|
309
237
|
external: { type: 'string', multiple: true },
|
|
310
238
|
loader: { type: 'string', multiple: true },
|
|
239
|
+
// --metro=PLATFORM builds as Metro builds for PLATFORM (its per-platform edges, its asset modules);
|
|
240
|
+
// --assets-dest=DIR copies the assets' files out as `react-native bundle --assets-dest` does.
|
|
241
|
+
metro: { type: 'string' },
|
|
242
|
+
'assets-dest': { type: 'string' },
|
|
311
243
|
}
|
|
312
|
-
const values = parseLeadingOptions(argv, options, {
|
|
313
|
-
valueFlags: ['--output', '-o', '--format', '--platform', '--define', '--external', '--loader'],
|
|
314
|
-
onError: fail,
|
|
315
|
-
})
|
|
244
|
+
const values = parseLeadingOptions(argv, options, { valueFlags: valueFlagsOf(options), onError: fail })
|
|
316
245
|
if (argv.length === 0) fail('Nothing to build: no bundle or lockfile given')
|
|
246
|
+
if (values.metro !== undefined && !/^[^/,]+$/u.test(values.metro)) fail(`Error: --metro takes one platform to build for, e.g. --metro=ios (got '${values.metro}')`)
|
|
247
|
+
if (values.flow && values.babel) fail('Error: --flow and --babel don\'t combine: the project\'s Babel config compiles Flow itself')
|
|
317
248
|
if (argv.length > 2) fail('Error: build takes a bundle or lockfile and an optional entry point')
|
|
318
249
|
// esbuild output knobs; the import graph itself is fixed by the artifact, not these.
|
|
319
250
|
if (values.format !== undefined && !['esm', 'cjs', 'iife'].includes(values.format)) {
|
|
@@ -353,21 +284,17 @@ if (command === '-v' || command === '--version') {
|
|
|
353
284
|
format: values.format,
|
|
354
285
|
platform: values.platform,
|
|
355
286
|
babel: Boolean(values.babel),
|
|
287
|
+
flow: Boolean(values.flow),
|
|
356
288
|
minify: values.minify,
|
|
357
289
|
sourcemap: values.sourcemap,
|
|
358
290
|
define,
|
|
359
291
|
external: values.external ?? [],
|
|
360
292
|
loader,
|
|
293
|
+
metro: values.metro,
|
|
294
|
+
assetsDest: values['assets-dest'],
|
|
361
295
|
})
|
|
362
296
|
} else if (command === 'extract') {
|
|
363
|
-
|
|
364
|
-
output: { type: 'string', short: 'o' },
|
|
365
|
-
}
|
|
366
|
-
const values = parseLeadingOptions(argv, options, { valueFlags: ['--output', '-o'], onError: fail })
|
|
367
|
-
if (argv.length === 0) fail('Nothing to extract: no bundle file given')
|
|
368
|
-
if (argv.length > 1) fail('Error: extract takes exactly one bundle file')
|
|
369
|
-
const { extractCommand } = await import('@exodus/stasis-core/extract')
|
|
370
|
-
extractCommand({ cwd: process.cwd(), bundleFile: argv[0], output: values.output, logLabel: 'stasis' })
|
|
297
|
+
await extractCli(argv, { label: 'stasis', fail })
|
|
371
298
|
} else if (command === 'diff') {
|
|
372
299
|
const options = {
|
|
373
300
|
stat: { type: 'boolean' },
|
|
@@ -384,13 +311,10 @@ if (command === '-v' || command === '--version') {
|
|
|
384
311
|
// Exit non-zero when the artifacts differ, so it composes in CI.
|
|
385
312
|
process.exitCode = differences ? 1 : 0
|
|
386
313
|
} else if (command === 'prune') {
|
|
387
|
-
|
|
388
|
-
const root = argv[0] ? resolve(argv[0]) : process.cwd()
|
|
389
|
-
const { prune } = await import('@exodus/stasis-core/prune')
|
|
390
|
-
const { removed, validated } = prune({ root })
|
|
391
|
-
console.warn(`[stasis] prune: validated ${validated.length} file(s), removed ${removed.length} file(s)`)
|
|
314
|
+
await pruneCli(argv, { label: 'stasis', fail })
|
|
392
315
|
} else if (command === 'audit') {
|
|
393
|
-
const
|
|
316
|
+
const options = { why: { type: 'boolean' }, 'why-deep': { type: 'boolean' }, 'why-full': { type: 'boolean' }, reason: { type: 'string' }, 'repo-advisories': { type: 'boolean' } }
|
|
317
|
+
const values = parseLeadingOptions(argv, options, { valueFlags: valueFlagsOf(options), onError: fail })
|
|
394
318
|
if (argv.length === 0) fail('Nothing to audit: no path to file given')
|
|
395
319
|
const repoAdvisories = Boolean(values['repo-advisories'])
|
|
396
320
|
if (repoAdvisories && !process.env.GITHUB_TOKEN) fail('Error: --repo-advisories requires a GitHub token in GITHUB_TOKEN')
|
|
@@ -406,12 +330,60 @@ if (command === '-v' || command === '--version') {
|
|
|
406
330
|
const report = await audit(files, { why: Boolean(values.why), whyDeep: Boolean(values['why-deep']), whyFull: Boolean(values['why-full']), reason: values.reason, repoAdvisories, github })
|
|
407
331
|
printAuditReport(report)
|
|
408
332
|
process.exitCode = report.rows.length === 0 ? 0 : 1
|
|
333
|
+
} else if (command === 'validate') {
|
|
334
|
+
// Exits 0 where the bundle is valid, 1 where it is invalid, 2 where a file it was to check went
|
|
335
|
+
// unverified (unless --allow-unverified), and 3 where it refused the bundle, or failed.
|
|
336
|
+
const refuse = (message) => {
|
|
337
|
+
console.error(message)
|
|
338
|
+
process.exit(3)
|
|
339
|
+
}
|
|
340
|
+
const misused = (message) => refuse(`${message}\nRun 'stasis --help' for usage.`)
|
|
341
|
+
const values = parseLeadingOptions(argv, {
|
|
342
|
+
github: { type: 'string' },
|
|
343
|
+
sha: { type: 'string' },
|
|
344
|
+
directory: { type: 'string' },
|
|
345
|
+
'only-deps': { type: 'boolean' },
|
|
346
|
+
lockfile: { type: 'string', multiple: true },
|
|
347
|
+
'no-lockfile': { type: 'boolean' },
|
|
348
|
+
'allow-unverified': { type: 'boolean' },
|
|
349
|
+
'show-valid': { type: 'boolean' },
|
|
350
|
+
}, {
|
|
351
|
+
valueFlags: ['--github', '--sha', '--directory', '--lockfile'],
|
|
352
|
+
onError: misused,
|
|
353
|
+
})
|
|
354
|
+
if (argv.length !== 1) misused('Error: stasis validate takes one bundle')
|
|
355
|
+
if (values.lockfile !== undefined && values['no-lockfile']) misused('Error: --lockfile and --no-lockfile: give one')
|
|
356
|
+
// The repository is read with GITHUB_TOKEN where it is set; its trees and the packages fetched are
|
|
357
|
+
// cached where `stasis audit` caches, each held to its id or integrity as it is read.
|
|
358
|
+
const { createClient } = await import('@preventive/upstream/github.js')
|
|
359
|
+
const { setCacheDir } = await import('@preventive/upstream/npm.js')
|
|
360
|
+
setCacheDir(userCacheDir())
|
|
361
|
+
const { ValidateError, exitCodeOf, validate, printValidationReport } = await import('../src/validate.js')
|
|
362
|
+
let report
|
|
363
|
+
try {
|
|
364
|
+
// Its dependencies alone only with --only-deps, and held to no lockfile only with --no-lockfile: a
|
|
365
|
+
// bundle with no repository or commit to read its own code or its lockfile of is refused otherwise.
|
|
366
|
+
report = await validate(resolve(argv[0]), {
|
|
367
|
+
client: createClient({ token: process.env.GITHUB_TOKEN || null }),
|
|
368
|
+
github: values.github,
|
|
369
|
+
sha: values.sha,
|
|
370
|
+
directory: values.directory,
|
|
371
|
+
own: !values['only-deps'],
|
|
372
|
+
lockfile: values['no-lockfile'] ? false : values.lockfile?.map((path) => resolve(path)) ?? true,
|
|
373
|
+
})
|
|
374
|
+
} catch (cause) {
|
|
375
|
+
if (cause instanceof ValidateError) misused(`Error: ${cause.message}`)
|
|
376
|
+
refuse(`Error: ${cause.message}`)
|
|
377
|
+
}
|
|
378
|
+
// In colour where each stream takes colours: a terminal's, or CI's log.
|
|
379
|
+
printValidationReport(report, { showValid: values['show-valid'] })
|
|
380
|
+
process.exitCode = exitCodeOf(report, { allowUnverified: values['allow-unverified'] })
|
|
409
381
|
} else if (command === 'sbom') {
|
|
410
382
|
const options = {
|
|
411
383
|
format: { type: 'string' },
|
|
412
384
|
output: { type: 'string', short: 'o' },
|
|
413
385
|
}
|
|
414
|
-
const values = parseLeadingOptions(argv, options, { valueFlags:
|
|
386
|
+
const values = parseLeadingOptions(argv, options, { valueFlags: valueFlagsOf(options), onError: fail })
|
|
415
387
|
if (!values.format) fail('Error: stasis sbom requires --format=(spdx|cyclonedx)')
|
|
416
388
|
if (!['spdx', 'cyclonedx'].includes(values.format)) fail('Error: --format must be spdx or cyclonedx')
|
|
417
389
|
if (argv.length === 0) fail('Nothing to export: no lockfile or bundle given')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/stasis",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.14",
|
|
4
4
|
"description": "File-level source bundles and lockfiles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"./prune": "./src/prune.js",
|
|
21
21
|
"./sbom": "./src/sbom.js",
|
|
22
22
|
"./audit-corrections": "./src/audit-corrections.js",
|
|
23
|
+
"./validate": "./src/validate.js",
|
|
23
24
|
"./vfs-bundle": "./src/vfs-bundle.js",
|
|
24
25
|
"./logo.svg": "./logo.svg"
|
|
25
26
|
},
|
|
@@ -40,9 +41,11 @@
|
|
|
40
41
|
"src/cmd/github-bundle.js",
|
|
41
42
|
"src/cmd/output.js",
|
|
42
43
|
"src/cmd/sbom.js",
|
|
44
|
+
"src/cmd/tokens.js",
|
|
43
45
|
"src/define.js",
|
|
44
46
|
"src/diff.js",
|
|
45
47
|
"src/esbuild.js",
|
|
48
|
+
"src/flow.js",
|
|
46
49
|
"src/installed-commits.js",
|
|
47
50
|
"src/json-stream.js",
|
|
48
51
|
"src/loader.js",
|
|
@@ -58,6 +61,7 @@
|
|
|
58
61
|
"src/loaders/paths.js",
|
|
59
62
|
"src/lockfile.js",
|
|
60
63
|
"src/metro.js",
|
|
64
|
+
"src/metro-assets.js",
|
|
61
65
|
"src/metro-resolver.js",
|
|
62
66
|
"src/metro-transformer.js",
|
|
63
67
|
"src/mock.js",
|
|
@@ -68,13 +72,18 @@
|
|
|
68
72
|
"src/resolve-typescript.js",
|
|
69
73
|
"src/rollup.js",
|
|
70
74
|
"src/sbom.js",
|
|
75
|
+
"src/table.js",
|
|
76
|
+
"src/validate.js",
|
|
71
77
|
"src/scan.js",
|
|
72
78
|
"src/vfs-bundle.js",
|
|
73
79
|
"src/vfs-bundle/entries.js",
|
|
74
80
|
"src/vfs-bundle/github.js",
|
|
81
|
+
"src/vfs-bundle/glob.js",
|
|
82
|
+
"src/vfs-bundle/lazy.js",
|
|
75
83
|
"src/vfs-bundle/prisma.js",
|
|
76
84
|
"src/vfs-bundle/soldeer.js",
|
|
77
85
|
"src/vfs-bundle/tree.js",
|
|
86
|
+
"src/vfs-bundle/yarnclean.js",
|
|
78
87
|
"src/webpack.js",
|
|
79
88
|
"src/why.js"
|
|
80
89
|
],
|
|
@@ -97,19 +106,19 @@
|
|
|
97
106
|
"homepage": "https://github.com/PreventiveMeasures/stasis#readme",
|
|
98
107
|
"dependencies": {
|
|
99
108
|
"@exodus/bytes": "^1.16.0",
|
|
100
|
-
"@exodus/stasis-core": "1.0.0-beta.
|
|
101
|
-
"@exodus/stasis-plugins": "1.0.0-beta.
|
|
102
|
-
"@preventive/archive": "^1.2.
|
|
103
|
-
"@preventive/deptree": "^1.
|
|
109
|
+
"@exodus/stasis-core": "1.0.0-beta.14",
|
|
110
|
+
"@exodus/stasis-plugins": "1.0.0-beta.14",
|
|
111
|
+
"@preventive/archive": "^1.2.2",
|
|
112
|
+
"@preventive/deptree": "^1.3.3",
|
|
104
113
|
"@preventive/lockfile": "^1.2.0",
|
|
105
|
-
"@preventive/upstream": "^1.
|
|
106
|
-
"@preventive/vfs": "1.
|
|
114
|
+
"@preventive/upstream": "^1.4.0",
|
|
115
|
+
"@preventive/vfs": "^1.1.0",
|
|
116
|
+
"flow-remove-types": "^2.322.0",
|
|
107
117
|
"oxc-parser": "^0.152.0"
|
|
108
118
|
},
|
|
109
119
|
"peerDependencies": {
|
|
110
120
|
"@prisma/client-generator-ts": "7.10.0",
|
|
111
|
-
"esbuild": "*"
|
|
112
|
-
"flow-remove-types": "*"
|
|
121
|
+
"esbuild": "*"
|
|
113
122
|
},
|
|
114
123
|
"peerDependenciesMeta": {
|
|
115
124
|
"@prisma/client-generator-ts": {
|
|
@@ -117,9 +126,9 @@
|
|
|
117
126
|
},
|
|
118
127
|
"esbuild": {
|
|
119
128
|
"optional": true
|
|
120
|
-
},
|
|
121
|
-
"flow-remove-types": {
|
|
122
|
-
"optional": true
|
|
123
129
|
}
|
|
130
|
+
},
|
|
131
|
+
"optionalDependencies": {
|
|
132
|
+
"minimatch": "^10.2.6"
|
|
124
133
|
}
|
|
125
134
|
}
|
package/src/audit.js
CHANGED
|
@@ -3,6 +3,9 @@ import { dependencyEcosystem, moduleFileKey, packageRecords, sameGithub } from '
|
|
|
3
3
|
import { advisories } from '@preventive/upstream/advisories.js'
|
|
4
4
|
import { compareVersions, valid } from '@preventive/upstream/semver.js'
|
|
5
5
|
import { isEvidenceFile } from './audit-corrections.js'
|
|
6
|
+
import { formatTable } from './table.js'
|
|
7
|
+
|
|
8
|
+
export { formatTable }
|
|
6
9
|
import { parseFile, parseFileWithKind } from './parse.js'
|
|
7
10
|
import { collectWhy, invertReason } from './why.js'
|
|
8
11
|
|
|
@@ -251,46 +254,6 @@ export function flattenAdvisories(found, reasonsByPkg = new Map(), whyByPkg = nu
|
|
|
251
254
|
return rows
|
|
252
255
|
}
|
|
253
256
|
|
|
254
|
-
// Strip line breaks (LF/CR/CRLF, U+2028/U+2029) from advisory titles so they can't break the box layout.
|
|
255
|
-
const cell = (v) => String(v ?? '').replace(/[\r\n\u2028\u2029]+/gu, ' ')
|
|
256
|
-
|
|
257
|
-
// Split a value into the physical lines a cell occupies. Non-multiline columns
|
|
258
|
-
// collapse every line break to a space via `cell` (one line). A column named in
|
|
259
|
-
// `multiline` (the `--why` reason column) keeps intentional `\n` breaks -- one
|
|
260
|
-
// physical line per entry -- while still flattening stray CR/separators in each.
|
|
261
|
-
const cellLines = (v, multiline) =>
|
|
262
|
-
multiline ? String(v ?? '').split('\n').map((s) => cell(s)) : [cell(v)]
|
|
263
|
-
|
|
264
|
-
export function formatTable(rows, columns, { multiline = [] } = {}) {
|
|
265
|
-
if (rows.length === 0) return ''
|
|
266
|
-
const ml = new Set(multiline)
|
|
267
|
-
const linesOf = (obj) => columns.map((c) => cellLines(obj[c], ml.has(c)))
|
|
268
|
-
const header = columns.map((c) => [c])
|
|
269
|
-
const body = rows.map((r) => linesOf(r))
|
|
270
|
-
const widths = columns.map((c, i) =>
|
|
271
|
-
Math.max(c.length, ...body.map((cells) => Math.max(0, ...cells[i].map((l) => l.length))))
|
|
272
|
-
)
|
|
273
|
-
const pad = (s, w) => s.padEnd(w)
|
|
274
|
-
const line = (l, m, r, fill) => l + widths.map((w) => fill.repeat(w + 2)).join(m) + r
|
|
275
|
-
// A row spans as many physical lines as its tallest cell; shorter cells pad
|
|
276
|
-
// out with blanks so the borders stay aligned.
|
|
277
|
-
const render = (cells) => {
|
|
278
|
-
const height = Math.max(...cells.map((c) => c.length))
|
|
279
|
-
const out = []
|
|
280
|
-
for (let i = 0; i < height; i++) {
|
|
281
|
-
out.push('│ ' + cells.map((c, j) => pad(c[i] ?? '', widths[j])).join(' │ ') + ' │')
|
|
282
|
-
}
|
|
283
|
-
return out.join('\n')
|
|
284
|
-
}
|
|
285
|
-
return [
|
|
286
|
-
line('┌', '┬', '┐', '─'),
|
|
287
|
-
render(header),
|
|
288
|
-
line('├', '┼', '┤', '─'),
|
|
289
|
-
...body.map(render),
|
|
290
|
-
line('└', '┴', '┘', '─'),
|
|
291
|
-
].join('\n')
|
|
292
|
-
}
|
|
293
|
-
|
|
294
257
|
// `repoAdvisories` and `github` (a @preventive/upstream/github.js client) go to advisories() as they
|
|
295
258
|
// are; a Soldeer package or a GitHub repo needs the client, their repository being their only source.
|
|
296
259
|
// A package that cannot be audited is `skipped`, with why (`because`), and asked for nothing.
|