@exodus/stasis 1.0.0-beta.9 → 1.0.0-rc.1
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 +6 -2
- package/bin/stasis.js +222 -334
- package/package.json +38 -14
- 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 +1664 -1001
- package/src/cmd/diff.js +1 -4
- package/src/cmd/github-bundle.js +48 -21
- package/src/cmd/output.js +25 -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 +211 -492
- 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 +152 -249
- package/src/resolve-node.js +29 -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 +70 -97
- package/src/scan.js +240 -282
- 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 +50 -46
- package/src/vfs-bundle/github.js +114 -94
- 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 +418 -277
- package/src/vfs-bundle/yarnclean.js +79 -0
- package/src/vfs-bundle.js +24 -55
- package/src/webpack.js +0 -4
- package/src/why.js +79 -231
- package/src/installed-commits.js +0 -182
package/src/rollup.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
// Public-export adapter: backs `@exodus/stasis/rollup`. The plugin lives in
|
|
2
|
-
// @exodus/stasis-plugins (which depends on @exodus/stasis-core for State /
|
|
3
|
-
// resolvePluginState). Internal code uses `@exodus/stasis-plugins/rollup` directly;
|
|
4
|
-
// this file exists only to back the package's `exports` map.
|
|
5
1
|
export * from '@exodus/stasis-plugins/rollup'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { INSTALLED } from '@exodus/stasis-core/util'
|
|
2
|
+
import { installedRecords } from './installed.js'
|
|
3
|
+
|
|
4
|
+
// `stasis run` preloads this before the loader; what it reads is kept across a run's calls.
|
|
5
|
+
const cache = { stores: new Map(), layouts: new Map() }
|
|
6
|
+
globalThis[INSTALLED] = (modules, root) => {
|
|
7
|
+
const accounts = installedRecords(modules, root, undefined, cache)
|
|
8
|
+
for (const [dir, { repo: _repo, ...account }] of accounts) accounts.set(dir, account)
|
|
9
|
+
return accounts
|
|
10
|
+
}
|
package/src/sbom.js
CHANGED
|
@@ -1,59 +1,38 @@
|
|
|
1
1
|
import { compareVersions, valid } from '@preventive/upstream/semver.js'
|
|
2
2
|
import pkg from '../package.json' with { type: 'json' }
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
// Deliberately free of file/transport concerns (no disk, no brotli); the disk-reading CLI glue is src/cmd/sbom.js.
|
|
4
|
+
// An SPDX 2.3 or CycloneDX 1.5 SBOM of parsed artifacts, free of disk and brotli (the CLI's glue is src/cmd/sbom.js).
|
|
6
5
|
|
|
7
|
-
// Tool/creator identity stamped into every generated SBOM.
|
|
8
6
|
const DEFAULT_TOOL = { name: '@exodus/stasis', version: pkg.version, vendor: 'Exodus Movement, Inc.' }
|
|
9
7
|
|
|
10
|
-
// Web Crypto (global) instead of node:crypto, keeping this module dependency-light.
|
|
11
8
|
const newUuid = () => globalThis.crypto.randomUUID()
|
|
12
9
|
|
|
13
|
-
// purl types we can mint
|
|
14
|
-
//
|
|
15
|
-
// crates.io's crate of that name, which it may not be.
|
|
10
|
+
// purl types we can mint: `soldeer` has no registered type, and `pkg:cargo` names crates.io's crate, which a
|
|
11
|
+
// crate vendored from git or from a source not known (`cargo-git`, `cargo-unknown`) may not be.
|
|
16
12
|
const PURL_TYPES = new Set(['npm', 'composer', 'cargo', 'github'])
|
|
17
13
|
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
function detectEcosystem(artifact) {
|
|
22
|
-
const formats = artifact.formats
|
|
23
|
-
if (formats && typeof formats.values === 'function') {
|
|
24
|
-
for (const format of formats.values()) {
|
|
25
|
-
if (format === 'php') return 'composer'
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return 'npm'
|
|
29
|
-
}
|
|
14
|
+
// An artifact's ecosystem by its formats, PHP's Composer, any other npm: its untagged buckets', and every
|
|
15
|
+
// bucket's in an artifact predating the per-dependency `ecosystem` field.
|
|
16
|
+
const detectEcosystem = (artifact) => ([...(artifact.formats?.values?.() ?? [])].includes('php') ? 'composer' : 'npm')
|
|
30
17
|
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
// a path segment, as stasis-core's hasNodeModulesSegment has it: `foo_node_modules/x` is first-party.
|
|
18
|
+
// For a pre-`ecosystem` artifact: a dir is first-party outside a `node_modules` segment (`foo_node_modules/x` is),
|
|
19
|
+
// but in a Composer bundle, whose vendor packages live outside one.
|
|
34
20
|
function classifyScope(ecosystem, dir) {
|
|
35
21
|
if (dir === '.') return 'workspace'
|
|
36
22
|
if (ecosystem === 'composer') return 'dependency'
|
|
37
23
|
return dir.split('/').includes('node_modules') ? 'dependency' : 'workspace'
|
|
38
24
|
}
|
|
39
25
|
|
|
40
|
-
//
|
|
41
|
-
// vendors and GitHub owners use the segment before the first slash; cargo and bare names have none.
|
|
26
|
+
// The purl/CycloneDX namespace (group): an npm scope, a Composer vendor or a GitHub owner.
|
|
42
27
|
function splitName(ecosystem, name) {
|
|
43
|
-
const namespaced = ecosystem === 'composer' || ecosystem === 'github' ||
|
|
44
|
-
|
|
45
|
-
if (namespaced
|
|
46
|
-
|
|
47
|
-
return { group: name.slice(0, slash), name: name.slice(slash + 1) }
|
|
48
|
-
}
|
|
49
|
-
return { group: undefined, name }
|
|
28
|
+
const namespaced = ecosystem === 'composer' || ecosystem === 'github' || (ecosystem === 'npm' && name.startsWith('@'))
|
|
29
|
+
const slash = name.indexOf('/')
|
|
30
|
+
if (!namespaced || slash === -1) return { group: undefined, name }
|
|
31
|
+
return { group: name.slice(0, slash), name: name.slice(slash + 1) }
|
|
50
32
|
}
|
|
51
33
|
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
// `@` before the version stay literal; Composer and GitHub names are lowercased, per the purl spec.
|
|
55
|
-
// The version qualifier is optional in the purl spec, so a versionless workspace package mints a
|
|
56
|
-
// bare-name purl rather than a fabricated version.
|
|
34
|
+
// A Package URL (purl), or null for an ecosystem with no purl type: each segment percent-encoded (npm's `@`
|
|
35
|
+
// scope -> `%40`), Composer and GitHub names lowercased, per the purl spec; with no version, a bare-name purl.
|
|
57
36
|
export function buildPurl(ecosystem, rawName, version) {
|
|
58
37
|
if (!PURL_TYPES.has(ecosystem)) return null
|
|
59
38
|
let { group, name } = splitName(ecosystem, rawName)
|
|
@@ -68,7 +47,7 @@ export function buildPurl(ecosystem, rawName, version) {
|
|
|
68
47
|
|
|
69
48
|
function compareComponents(a, b) {
|
|
70
49
|
if (a.name !== b.name) return a.name < b.name ? -1 : 1
|
|
71
|
-
//
|
|
50
|
+
// As '': comparing raw undefined would be order-unstable.
|
|
72
51
|
const [av, bv] = [a.version ?? '', b.version ?? '']
|
|
73
52
|
if (av !== bv) {
|
|
74
53
|
if (valid(av) && valid(bv)) return compareVersions(av, bv)
|
|
@@ -77,100 +56,89 @@ function compareComponents(a, b) {
|
|
|
77
56
|
return a.ecosystem < b.ecosystem ? -1 : a.ecosystem > b.ecosystem ? 1 : 0
|
|
78
57
|
}
|
|
79
58
|
|
|
80
|
-
//
|
|
81
|
-
// (
|
|
82
|
-
//
|
|
83
|
-
// and so are DEPENDENCY buckets without a version (v0 partial metadata: unverifiable identity) --
|
|
84
|
-
// but a workspace package may legitimately omit version (private/unpublished) and is kept, since
|
|
85
|
-
// dropping it would silently lose the document's own first-party subject. Dedup is by
|
|
86
|
-
// ecosystem+name+version; a package seen as workspace in any artifact stays workspace regardless
|
|
87
|
-
// of argument order, so output doesn't depend on how artifacts are listed.
|
|
59
|
+
// The artifacts' named packages, deduped by ecosystem+name+version and sorted: a dependency only with a version,
|
|
60
|
+
// a first-party one ('workspace' where any artifact has it so) with or without. A dependency's `vendored` copies
|
|
61
|
+
// ride on it, by `dir`, a purl only beside a version (Next.js's React copy, `react-builtin`, names no release).
|
|
88
62
|
export function collectComponents(artifacts) {
|
|
89
63
|
const seen = new Map()
|
|
90
64
|
for (const artifact of artifacts) {
|
|
91
65
|
const records = [...artifact.modules]
|
|
92
|
-
//
|
|
93
|
-
// if no bucket carries it, the artifact predates the field and we use the heuristic for everything.
|
|
66
|
+
// An artifact where no bucket carries `ecosystem` predates the field: classifyScope tells deps apart.
|
|
94
67
|
const tagged = records.some(([, m]) => m.ecosystem !== undefined)
|
|
95
68
|
const fileEcosystem = detectEcosystem(artifact)
|
|
96
|
-
for (const [dir, { name, version, ecosystem }] of records) {
|
|
69
|
+
for (const [dir, { name, version, ecosystem, vendored }] of records) {
|
|
97
70
|
if (!name) continue
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
scope = 'dependency'
|
|
101
|
-
eco = ecosystem
|
|
102
|
-
} else if (tagged) {
|
|
103
|
-
// Untagged bucket in a modern artifact: first-party workspace code; ecosystem inferred.
|
|
104
|
-
scope = 'workspace'
|
|
105
|
-
eco = fileEcosystem
|
|
106
|
-
} else {
|
|
107
|
-
scope = classifyScope(fileEcosystem, dir)
|
|
108
|
-
eco = fileEcosystem
|
|
109
|
-
}
|
|
71
|
+
const eco = ecosystem ?? fileEcosystem
|
|
72
|
+
const scope = ecosystem !== undefined ? 'dependency' : tagged ? 'workspace' : classifyScope(fileEcosystem, dir)
|
|
110
73
|
if (!version && scope !== 'workspace') continue
|
|
111
74
|
const key = `${eco} ${name} ${version ?? ''}`
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
if (scope === 'workspace')
|
|
115
|
-
|
|
75
|
+
let component = seen.get(key)
|
|
76
|
+
if (component) {
|
|
77
|
+
if (scope === 'workspace') component.scope = 'workspace'
|
|
78
|
+
} else {
|
|
79
|
+
seen.set(key, component = { name, version: version ?? undefined, scope, ecosystem: eco, purl: buildPurl(eco, name, version) })
|
|
80
|
+
}
|
|
81
|
+
// Across artifacts, the union by directory; the first to list one names its package.
|
|
82
|
+
for (const [sub, v] of Object.entries(vendored ?? {})) {
|
|
83
|
+
component.vendored ??= new Map()
|
|
84
|
+
if (component.vendored.has(sub)) continue
|
|
85
|
+
component.vendored.set(sub, { dir: sub, name: v.name, version: v.version, ecosystem: eco, purl: v.version === undefined ? null : buildPurl(eco, v.name, v.version) })
|
|
116
86
|
}
|
|
117
|
-
seen.set(key, { name, version: version ?? undefined, scope, ecosystem: eco, purl: buildPurl(eco, name, version) })
|
|
118
87
|
}
|
|
119
88
|
}
|
|
89
|
+
for (const component of seen.values()) {
|
|
90
|
+
if (component.vendored) component.vendored = [...component.vendored.values()].toSorted((a, b) => (a.dir < b.dir ? -1 : 1))
|
|
91
|
+
}
|
|
120
92
|
return [...seen.values()].toSorted(compareComponents)
|
|
121
93
|
}
|
|
122
94
|
|
|
123
|
-
//
|
|
124
|
-
// there is exactly one; with zero or several workspace roots there's no single subject, so every
|
|
125
|
-
// package is a plain component. `rest` is everything that is not the primary.
|
|
95
|
+
// The component the SBOM is *about*: the lone workspace package, none with zero or several.
|
|
126
96
|
function selectPrimary(components) {
|
|
127
97
|
const workspace = components.filter((c) => c.scope === 'workspace')
|
|
128
98
|
const primary = workspace.length === 1 ? workspace[0] : null
|
|
129
99
|
return { primary, rest: primary ? components.filter((c) => c !== primary) : components }
|
|
130
100
|
}
|
|
131
101
|
|
|
132
|
-
//
|
|
102
|
+
// RFC 3339 to whole seconds.
|
|
133
103
|
const isoSeconds = (date) => date.toISOString().replace(/\.\d{3}Z$/u, 'Z')
|
|
134
104
|
|
|
135
|
-
//
|
|
136
|
-
// ecosystem+name(+version) (unique by construction -- it's the dedup key).
|
|
105
|
+
// Unique by construction: the purl, else the dedup key.
|
|
137
106
|
const bomRef = (c) => c.purl ?? `${c.ecosystem}:${c.name}${c.version == null ? '' : `@${c.version}`}`
|
|
138
107
|
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
108
|
+
// An SPDX 2.3 document: it DESCRIBES its primary, which DEPENDS_ON each dependency (flat), else the workspace
|
|
109
|
+
// packages, else every package. A package vendored into a dependency comes after the rest, CONTAINED by that
|
|
110
|
+
// dependency, its directory there its `packageFileName`.
|
|
142
111
|
export function toSpdx(components, { tool = DEFAULT_TOOL, now = new Date(), uuid = newUuid() } = {}) {
|
|
143
112
|
const { primary, rest } = selectPrimary(components)
|
|
144
113
|
const ordered = primary ? [primary, ...rest] : components
|
|
145
114
|
const ids = new Map(ordered.map((c, i) => [c, `SPDXRef-Package-${i}`]))
|
|
146
115
|
|
|
147
|
-
const
|
|
148
|
-
SPDXID:
|
|
116
|
+
const spdxPackage = (id, c, purpose, extra = {}) => ({
|
|
117
|
+
SPDXID: id,
|
|
149
118
|
name: c.name,
|
|
150
|
-
// SPDX versionInfo is optional; omit it for a versionless workspace package.
|
|
151
119
|
...(c.version == null ? {} : { versionInfo: c.version }),
|
|
120
|
+
...extra,
|
|
152
121
|
downloadLocation: 'NOASSERTION',
|
|
153
122
|
filesAnalyzed: false,
|
|
154
123
|
...(c.purl && {
|
|
155
124
|
externalRefs: [{ referenceCategory: 'PACKAGE-MANAGER', referenceType: 'purl', referenceLocator: c.purl }],
|
|
156
125
|
}),
|
|
157
|
-
primaryPackagePurpose:
|
|
158
|
-
})
|
|
126
|
+
primaryPackagePurpose: purpose,
|
|
127
|
+
})
|
|
128
|
+
const packages = ordered.map((c) => spdxPackage(ids.get(c), c, c.scope === 'workspace' ? 'APPLICATION' : 'LIBRARY'))
|
|
129
|
+
const vendored = ordered.flatMap((c) => (c.vendored ?? []).map((v, i) => ({ host: c, v, id: `${ids.get(c)}-Vendored-${i}` })))
|
|
130
|
+
for (const { v, id } of vendored) packages.push(spdxPackage(id, v, 'LIBRARY', { packageFileName: v.dir }))
|
|
159
131
|
|
|
160
132
|
const relationships = []
|
|
133
|
+
const relate = (spdxElementId, relatedSpdxElement, relationshipType) => relationships.push({ spdxElementId, relatedSpdxElement, relationshipType })
|
|
161
134
|
if (primary) {
|
|
162
|
-
|
|
163
|
-
for (const c of rest)
|
|
164
|
-
if (c.scope === 'dependency') {
|
|
165
|
-
relationships.push({ spdxElementId: ids.get(primary), relatedSpdxElement: ids.get(c), relationshipType: 'DEPENDS_ON' })
|
|
166
|
-
}
|
|
167
|
-
}
|
|
135
|
+
relate('SPDXRef-DOCUMENT', ids.get(primary), 'DESCRIBES')
|
|
136
|
+
for (const c of rest) if (c.scope === 'dependency') relate(ids.get(primary), ids.get(c), 'DEPENDS_ON')
|
|
168
137
|
} else {
|
|
169
138
|
const workspace = ordered.filter((c) => c.scope === 'workspace')
|
|
170
|
-
for (const c of workspace.length > 0 ? workspace : ordered)
|
|
171
|
-
relationships.push({ spdxElementId: 'SPDXRef-DOCUMENT', relatedSpdxElement: ids.get(c), relationshipType: 'DESCRIBES' })
|
|
172
|
-
}
|
|
139
|
+
for (const c of workspace.length > 0 ? workspace : ordered) relate('SPDXRef-DOCUMENT', ids.get(c), 'DESCRIBES')
|
|
173
140
|
}
|
|
141
|
+
for (const { host, id } of vendored) relate(ids.get(host), id, 'CONTAINS')
|
|
174
142
|
|
|
175
143
|
const docName = primary
|
|
176
144
|
? (primary.version == null ? primary.name : `${primary.name}@${primary.version}`)
|
|
@@ -190,22 +158,28 @@ export function toSpdx(components, { tool = DEFAULT_TOOL, now = new Date(), uuid
|
|
|
190
158
|
}
|
|
191
159
|
}
|
|
192
160
|
|
|
193
|
-
//
|
|
194
|
-
//
|
|
161
|
+
// A CycloneDX 1.5 document: the primary (workspace root) its metadata.component, the rest `components`, with a flat
|
|
162
|
+
// `dependencies` edge from it to each dependency. A package vendored into a dependency is nested in its `components`,
|
|
163
|
+
// its directory there the location of its one occurrence.
|
|
195
164
|
export function toCyclonedx(components, { tool = DEFAULT_TOOL, now = new Date(), uuid = newUuid() } = {}) {
|
|
196
165
|
const { primary, rest } = selectPrimary(components)
|
|
197
|
-
const
|
|
166
|
+
const component = (c, type, ref, tail) => {
|
|
198
167
|
const { group, name } = splitName(c.ecosystem, c.name)
|
|
199
168
|
return {
|
|
200
|
-
type
|
|
201
|
-
'bom-ref':
|
|
169
|
+
type,
|
|
170
|
+
'bom-ref': ref,
|
|
202
171
|
...(group && { group }),
|
|
203
172
|
name,
|
|
204
|
-
// CycloneDX 1.5 `version` is optional; omit it for a versionless workspace package.
|
|
205
173
|
...(c.version == null ? {} : { version: c.version }),
|
|
206
174
|
...(c.purl && { purl: c.purl }),
|
|
175
|
+
...tail,
|
|
207
176
|
}
|
|
208
177
|
}
|
|
178
|
+
const toComponent = (c) => component(c, c.scope === 'workspace' ? 'application' : 'library', bomRef(c),
|
|
179
|
+
c.vendored && { components: c.vendored.map((v) => toVendoredComponent(c, v)) })
|
|
180
|
+
// Its bom-ref the host's with the directory as a purl subpath: two copies of one package (Next.js
|
|
181
|
+
// has loader-utils2 and loader-utils3, both `loader-utils`) stay apart.
|
|
182
|
+
const toVendoredComponent = (host, v) => component(v, 'library', `${bomRef(host)}#${v.dir}`, { evidence: { occurrences: [{ location: v.dir }] } })
|
|
209
183
|
|
|
210
184
|
const doc = {
|
|
211
185
|
bomFormat: 'CycloneDX',
|
|
@@ -214,7 +188,7 @@ export function toCyclonedx(components, { tool = DEFAULT_TOOL, now = new Date(),
|
|
|
214
188
|
version: 1,
|
|
215
189
|
metadata: {
|
|
216
190
|
timestamp: isoSeconds(now),
|
|
217
|
-
//
|
|
191
|
+
// Not the flat tools array, deprecated in 1.5 and removed in 1.6.
|
|
218
192
|
tools: { components: [{ type: 'application', publisher: tool.vendor, name: tool.name, version: tool.version }] },
|
|
219
193
|
...(primary && { component: toComponent(primary) }),
|
|
220
194
|
},
|
|
@@ -227,14 +201,13 @@ export function toCyclonedx(components, { tool = DEFAULT_TOOL, now = new Date(),
|
|
|
227
201
|
return doc
|
|
228
202
|
}
|
|
229
203
|
|
|
230
|
-
//
|
|
204
|
+
// `options` { tool, now, uuid } for a custom identity or deterministic output.
|
|
231
205
|
export function generateSbom(format, components, options) {
|
|
232
206
|
if (format === 'spdx') return toSpdx(components, options)
|
|
233
207
|
if (format === 'cyclonedx') return toCyclonedx(components, options)
|
|
234
208
|
throw new Error(`sbom: format must be spdx or cyclonedx, got ${format}`)
|
|
235
209
|
}
|
|
236
210
|
|
|
237
|
-
// Convenience one-shot: collectComponents then generateSbom.
|
|
238
211
|
export function sbom(format, artifacts, options) {
|
|
239
212
|
return generateSbom(format, collectComponents(artifacts), options)
|
|
240
213
|
}
|