@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.
Files changed (67) hide show
  1. package/README.md +2 -1
  2. package/bin/stasis.js +99 -16
  3. package/package.json +22 -9
  4. package/src/audit-corrections.js +11 -42
  5. package/src/audit.js +241 -190
  6. package/src/babel.js +39 -122
  7. package/src/bundle-from-lockfile.js +9 -21
  8. package/src/bundle-reader.js +5 -9
  9. package/src/bundle.js +0 -3
  10. package/src/cmd/build.js +82 -174
  11. package/src/cmd/bundle-options.js +113 -167
  12. package/src/cmd/bundle.js +942 -1294
  13. package/src/cmd/diff.js +1 -4
  14. package/src/cmd/github-bundle.js +21 -26
  15. package/src/cmd/output.js +15 -12
  16. package/src/cmd/sbom.js +3 -8
  17. package/src/cmd/tokens.js +16 -23
  18. package/src/define.js +36 -94
  19. package/src/diff.js +72 -128
  20. package/src/esbuild.js +0 -4
  21. package/src/flow.js +18 -13
  22. package/src/installed.js +265 -0
  23. package/src/json-stream.js +4 -9
  24. package/src/loader-mock.js +3 -8
  25. package/src/loader.js +1 -5
  26. package/src/loaders/bash.js +41 -93
  27. package/src/loaders/cargo.js +298 -805
  28. package/src/loaders/foundry.js +109 -285
  29. package/src/loaders/paths.js +13 -13
  30. package/src/loaders/php.js +210 -489
  31. package/src/loaders/rust.js +507 -1430
  32. package/src/loaders/solidity-ownership.js +48 -128
  33. package/src/loaders/solidity.js +39 -122
  34. package/src/loaders/toml.js +7 -17
  35. package/src/lockfile.js +0 -3
  36. package/src/metro-assets.js +10 -384
  37. package/src/metro-resolver.js +58 -134
  38. package/src/metro-transformer.js +0 -5
  39. package/src/metro.js +0 -4
  40. package/src/mock.js +32 -80
  41. package/src/parse.js +4 -4
  42. package/src/prune.js +0 -3
  43. package/src/resolve-fields.js +137 -532
  44. package/src/resolve-node.js +27 -45
  45. package/src/resolve-typescript.js +166 -298
  46. package/src/rollup.js +0 -4
  47. package/src/run-installed.js +10 -0
  48. package/src/sbom.js +52 -128
  49. package/src/scan.js +142 -284
  50. package/src/sixel.js +310 -0
  51. package/src/table.js +63 -31
  52. package/src/validate-notes.d.ts +19 -0
  53. package/src/validate-notes.js +72 -0
  54. package/src/validate.d.ts +159 -0
  55. package/src/validate.js +596 -522
  56. package/src/vfs-bundle/entries.js +40 -57
  57. package/src/vfs-bundle/github.js +80 -122
  58. package/src/vfs-bundle/glob.js +4 -45
  59. package/src/vfs-bundle/lazy.js +27 -56
  60. package/src/vfs-bundle/prisma.js +235 -105
  61. package/src/vfs-bundle/soldeer.js +28 -49
  62. package/src/vfs-bundle/tree.js +295 -318
  63. package/src/vfs-bundle/yarnclean.js +10 -31
  64. package/src/vfs-bundle.js +23 -64
  65. package/src/webpack.js +0 -4
  66. package/src/why.js +78 -232
  67. package/src/installed-commits.js +0 -184
package/src/diff.js CHANGED
@@ -1,53 +1,40 @@
1
- import { reposAgree, sortPaths } from '@exodus/stasis-core/util'
1
+ import { ATTESTED_METADATA, extSetsEqual, moduleFileKey, REPO_FIELDS, sameGithub, sortPaths, upsert } from '@exodus/stasis-core/util'
2
2
 
3
- // `@exodus/stasis/diff` — compare two parsed stasis artifacts (Bundle/Lockfile) at the module and
4
- // file level. Never reads disk. Comparing across kinds works by reducing every file to the same
5
- // digest space: a lockfile already holds SRI digests; a bundle holds bytes, re-hashed via the
6
- // injected `hash` — so a `hash` function is required whenever a bundle is an operand. Per-file
7
- // encoding (resource:base64 vs text) is read from the bundle's `formats` map.
3
+ // Two parsed artifacts compared by module and file, never reading disk: each file as an SRI digest, a bundle's bytes
4
+ // re-hashed by the injected `hash`.
8
5
 
9
6
  const KINDS = new Set(['lockfile', 'bundle'])
10
7
 
11
- // Reduce one file's recorded value to an SRI digest: lockfile values already are digests; a
12
- // bundle's are re-hashed, with a `resource:base64` file decoded to bytes first (others hash as text).
8
+ // One file's recorded value as an SRI digest: a bundle's re-hashed, a `resource:base64` file decoded first.
13
9
  function digestOf(kind, format, value, hash) {
14
10
  if (kind === 'lockfile') return value
15
11
  if (typeof hash !== 'function') {
16
12
  throw new Error('diff: a `hash` function is required to compare a bundle (its bytes are re-hashed into a lockfile-style digest)')
17
13
  }
18
- if (format === 'resource:base64') return hash(Buffer.from(value, 'base64'))
19
- return hash(value)
14
+ return hash(format === 'resource:base64' ? Buffer.from(value, 'base64') : value)
20
15
  }
21
16
 
22
- const projectPath = (dir, rel) => (dir === '.' ? rel : `${dir}/${rel}`)
17
+ // An artifact from before the `repo` field records none; `github` compares in any case.
18
+ const reposAgree = (a, b) => a === undefined || b === undefined ||
19
+ Object.keys(REPO_FIELDS).every((key) => (key === 'github' ? sameGithub(a.github, b.github) : a[key] === b[key]))
23
20
 
24
- // Project an artifact onto a uniform shape: scope + Map<dir, { name, version, ecosystem, repo,
25
- // files: Map<rel, digest> }>. `input` is { artifact, kind }; `hash` re-hashes bundle bytes only.
21
+ // `{ artifact, kind }` as scope + Map<dir, { name, version, ecosystem, repo, integrity, patch, files: Map<rel, digest> }>.
26
22
  export function normalizeArtifact(input, { hash } = {}) {
27
23
  const { artifact, kind } = input ?? {}
28
- if (!artifact || !KINDS.has(kind)) {
29
- throw new Error("diff: each input must be { artifact, kind } with kind 'lockfile' | 'bundle'")
30
- }
24
+ if (!artifact || !KINDS.has(kind)) throw new Error("diff: each input must be { artifact, kind } with kind 'lockfile' | 'bundle'")
31
25
  const formats = artifact.formats ?? new Map()
32
26
  const modules = new Map()
33
- for (const [dir, { name, version, ecosystem, repo, files }] of artifact.modules) {
34
- const digests = new Map()
35
- for (const [rel, value] of Object.entries(files)) {
36
- digests.set(rel, digestOf(kind, formats.get(projectPath(dir, rel)), value, hash))
37
- }
38
- // v0 bundles record no name/version; normalize undefined -> null for a single "unknown" sentinel.
39
- modules.set(dir, { name: name ?? null, version: version ?? null, ecosystem: ecosystem ?? null, repo, files: digests })
27
+ for (const [dir, { name, version, ecosystem, repo, integrity, patch, files }] of artifact.modules) {
28
+ const digests = new Map(Object.entries(files).map(([rel, value]) => [rel, digestOf(kind, formats.get(moduleFileKey(dir, rel)), value, hash)]))
29
+ // v0 bundles record no name/version: null is the one "unknown".
30
+ modules.set(dir, { name: name ?? null, version: version ?? null, ecosystem: ecosystem ?? null, repo, integrity, patch, files: digests })
40
31
  }
41
- // `executable` decides which files `stasis extract` chmods +x, so a change to it changes the tree
42
- // an artifact produces even when every digest matches -- it has to be part of "did these differ?".
32
+ // `executable` decides what `stasis extract` chmods +x: the tree differs even where every digest matches.
43
33
  return { scope: artifact.config?.scope ?? 'full', modules, executable: artifact.executable ?? new Set() }
44
34
  }
45
35
 
46
- // Diff two `{ artifact, kind }` operands (`left` = baseline/"from", `right` = "to"). Modules are
47
- // compared whole-package; files only within packages present on BOTH sides (a one-sided package is
48
- // reported once as an added/removed module, not per-file). A version/name/repo change is reported
49
- // only when both sides record a non-null value (an artifact from before `repo` records none). `{ imports: true }` also diffs the resolution graphs
50
- // (opt-in; verbose). `hash` is required only when a bundle is an operand.
36
+ // `left` the baseline. Files compare only within modules on BOTH sides (a one-sided module is reported once); a
37
+ // name/version/repo change only where both sides record one. `imports: true` also diffs the resolution graphs.
51
38
  export function diffArtifacts(left, right, { imports = false, hash } = {}) {
52
39
  const L = normalizeArtifact(left, { hash })
53
40
  const R = normalizeArtifact(right, { hash })
@@ -60,37 +47,29 @@ export function diffArtifacts(left, right, { imports = false, hash } = {}) {
60
47
  const filesDiffering = []
61
48
 
62
49
  const summary = (dir, m) => ({ dir, name: m.name, version: m.version, ecosystem: m.ecosystem, files: m.files.size })
63
- const dirs = new Set([...L.modules.keys(), ...R.modules.keys()])
64
- for (const dir of dirs) {
50
+ for (const dir of new Set([...L.modules.keys(), ...R.modules.keys()])) {
65
51
  const l = L.modules.get(dir)
66
52
  const r = R.modules.get(dir)
67
- if (l && !r) {
68
- modulesRemoved.push(summary(dir, l))
69
- continue
70
- }
71
- if (!l && r) {
72
- modulesAdded.push(summary(dir, r))
53
+ if (!l || !r) {
54
+ (l ? modulesRemoved : modulesAdded).push(summary(dir, l ?? r))
73
55
  continue
74
56
  }
75
57
 
76
- const change = { dir, name: r.name ?? l.name }
77
- if (l.version !== null && r.version !== null && l.version !== r.version) {
78
- change.versionChange = { from: l.version, to: r.version }
79
- }
80
- if (l.name !== null && r.name !== null && l.name !== r.name) {
81
- change.nameChange = { from: l.name, to: r.name }
58
+ const changes = {}
59
+ for (const field of ['version', 'name']) {
60
+ if (l[field] !== null && r[field] !== null && l[field] !== r[field]) changes[`${field}Change`] = { from: l[field], to: r[field] }
82
61
  }
83
62
  // A dependency's repo picks the GitHub advisories audit asks, so a change to it is one to review.
84
- if (!reposAgree(l.repo, r.repo)) {
85
- change.repoChange = { from: l.repo, to: r.repo }
63
+ if (!reposAgree(l.repo, r.repo)) changes.repoChange = { from: l.repo, to: r.repo }
64
+ for (const field of ATTESTED_METADATA) {
65
+ if (JSON.stringify(l[field]) !== JSON.stringify(r[field])) changes[`${field}Change`] = { from: l[field], to: r[field] }
86
66
  }
87
- if (change.versionChange || change.nameChange || change.repoChange) modulesChanged.push(change)
67
+ if (Object.keys(changes).length > 0) modulesChanged.push({ dir, name: r.name ?? l.name, ...changes })
88
68
 
89
- const rels = new Set([...l.files.keys(), ...r.files.keys()])
90
- for (const rel of rels) {
69
+ for (const rel of new Set([...l.files.keys(), ...r.files.keys()])) {
91
70
  const lh = l.files.get(rel)
92
71
  const rh = r.files.get(rel)
93
- const path = projectPath(dir, rel)
72
+ const path = moduleFileKey(dir, rel)
94
73
  if (lh !== undefined && rh === undefined) filesRemoved.push(path)
95
74
  else if (lh === undefined && rh !== undefined) filesAdded.push(path)
96
75
  else if (lh !== rh) filesDiffering.push(path)
@@ -98,50 +77,28 @@ export function diffArtifacts(left, right, { imports = false, hash } = {}) {
98
77
  }
99
78
 
100
79
  const byDir = (a, b) => sortPaths(a.dir, b.dir)
101
- modulesAdded.sort(byDir)
102
- modulesRemoved.sort(byDir)
103
- modulesChanged.sort(byDir)
104
- filesAdded.sort(sortPaths)
105
- filesRemoved.sort(sortPaths)
106
- filesDiffering.sort(sortPaths)
107
-
108
- // Execute-bit changes, reported for every path either side marks (not just files in shared
109
- // modules): gaining or losing +x is a real change to the extracted tree, whatever bucket it sits in.
80
+ // Of every path either side marks, not just files in shared modules.
110
81
  const onlyIn = (a, b) => [...a.difference(b)].toSorted(sortPaths)
111
- const executableAdded = onlyIn(R.executable, L.executable)
112
- const executableRemoved = onlyIn(L.executable, R.executable)
113
-
114
82
  const result = {
115
83
  scope: { left: L.scope, right: R.scope },
116
- modules: { added: modulesAdded, removed: modulesRemoved, changed: modulesChanged },
117
- files: { added: filesAdded, removed: filesRemoved, differing: filesDiffering },
118
- executable: { added: executableAdded, removed: executableRemoved },
84
+ modules: { added: modulesAdded.toSorted(byDir), removed: modulesRemoved.toSorted(byDir), changed: modulesChanged.toSorted(byDir) },
85
+ files: { added: filesAdded.toSorted(sortPaths), removed: filesRemoved.toSorted(sortPaths), differing: filesDiffering.toSorted(sortPaths) },
86
+ executable: { added: onlyIn(R.executable, L.executable), removed: onlyIn(L.executable, R.executable) },
119
87
  }
120
88
  if (imports) result.imports = diffImports(left, right)
121
89
  return result
122
90
  }
123
91
 
124
- // The resolution graph an artifact attests, or null when it attests none (a legacy lockfile
125
- // predating attestation); a bundle always carries a possibly-empty map.
126
- function attestedImports({ artifact }) {
127
- return artifact.imports ?? null
128
- }
129
-
130
- // Collapse an imports map (conditions -> parent -> specifier -> target) to (parent, specifier) ->
131
- // Set<target>, unioning over conditions: a static bundle keys every edge under "*" while a runtime
132
- // lockfile uses precise sets, so keying on conditions would report identical resolutions as
133
- // removed+added. Folding conditions away makes them compare equal.
92
+ // (parent, specifier) -> Set<target>, unioned over conditions: a static bundle keys every edge under "*", a runtime
93
+ // lockfile by precise sets, and the two must agree. A `--metro` target may be a { platform: file } map.
134
94
  function resolutionsOf(imports) {
135
95
  const byPair = new Map()
136
96
  for (const [, byParent] of imports) {
137
97
  for (const [parent, specifiers] of byParent) {
138
98
  for (const [specifier, target] of specifiers) {
139
99
  const key = JSON.stringify([parent, specifier])
140
- let entry = byPair.get(key)
141
- if (!entry) byPair.set(key, (entry = { parent, specifier, targets: new Set() }))
142
- // A `--metro` edge target may be a { platform: file } map; fold each platform's file into the set.
143
- if (target instanceof Map) for (const f of target.values()) entry.targets.add(f)
144
- else entry.targets.add(target)
100
+ const { targets } = upsert(byPair, key, () => ({ parent, specifier, targets: new Set() }))
101
+ for (const f of target instanceof Map ? target.values() : [target]) targets.add(f)
145
102
  }
146
103
  }
147
104
  }
@@ -151,15 +108,12 @@ function resolutionsOf(imports) {
151
108
  const cmpStr = (a, b) => (a < b ? -1 : a > b ? 1 : 0)
152
109
  const cmpPair = (a, b) => sortPaths(a.parent, b.parent) || cmpStr(a.specifier, b.specifier)
153
110
  const sortedTargets = (set) => [...set].toSorted(sortPaths)
154
- const sameTargets = (a, b) => a.size === b.size && a.isSubsetOf(b)
155
111
 
156
- // Diff resolution graphs at the (parent, specifier) level (conditions folded away — see
157
- // resolutionsOf). Reports added/removed and changed (resolved on both sides to different targets —
158
- // a redirect a byte diff can't see). When either side doesn't attest imports, the diff is skipped
159
- // and `attested` flags why, rather than reporting one whole graph as added/removed.
160
- export function diffImports(left, right) {
161
- const li = attestedImports(left)
162
- const ri = attestedImports(right)
112
+ // Changed catches a redirect a byte diff can't see. A side attesting no imports (a lockfile predating attestation)
113
+ // skips the diff, `attested` saying which, rather than reporting the other whole graph as added/removed.
114
+ export function diffImports({ artifact: left }, { artifact: right }) {
115
+ const li = left.imports ?? null
116
+ const ri = right.imports ?? null
163
117
  const attested = { left: li !== null, right: ri !== null }
164
118
  if (li === null || ri === null) return { attested, added: [], removed: [], changed: [] }
165
119
 
@@ -173,22 +127,17 @@ export function diffImports(left, right) {
173
127
  const r = R.get(key)
174
128
  if (l && !r) removed.push({ parent: l.parent, specifier: l.specifier, from: sortedTargets(l.targets) })
175
129
  else if (!l && r) added.push({ parent: r.parent, specifier: r.specifier, to: sortedTargets(r.targets) })
176
- else if (!sameTargets(l.targets, r.targets)) {
130
+ else if (!extSetsEqual(l.targets, r.targets)) {
177
131
  changed.push({ parent: l.parent, specifier: l.specifier, from: sortedTargets(l.targets), to: sortedTargets(r.targets) })
178
132
  }
179
133
  }
180
- added.sort(cmpPair)
181
- removed.sort(cmpPair)
182
- changed.sort(cmpPair)
134
+ for (const list of [added, removed, changed]) list.sort(cmpPair)
183
135
  return { attested, added, removed, changed }
184
136
  }
185
137
 
186
- // True when the diff records any module-, file-, or import-level change. Scope alone is
187
- // informational and doesn't count (unattested imports contribute empty lists).
138
+ // Scope alone doesn't count. Only the opt-in `imports` is guarded: a guard on the others would make a renamed facet
139
+ // read as "no differences" and quietly pass a review gate.
188
140
  export function hasDifferences(diff) {
189
- // `executable` is unguarded like modules/files -- diffArtifacts always sets it, and a shape guard
190
- // here would make a renamed facet read as "no differences" and quietly pass a review gate.
191
- // `imports` is genuinely opt-in (the `imports` option), so it keeps its guard.
192
141
  const { modules, files, executable, imports } = diff
193
142
  let n =
194
143
  modules.added.length + modules.removed.length + modules.changed.length +
@@ -198,7 +147,6 @@ export function hasDifferences(diff) {
198
147
  return n > 0
199
148
  }
200
149
 
201
- const KIND_LABEL = { lockfile: 'lockfile', bundle: 'bundle' }
202
150
  const plural = (n) => (n === 1 ? '' : 's')
203
151
  const ident = ({ name, version }) => (name ? (version ? `${name}@${version}` : name) : '')
204
152
 
@@ -210,11 +158,13 @@ const CHANGED = '*'
210
158
  // `owner/name`, its commit and directory where recorded: `owner/name@0123abc (packages/x)`.
211
159
  const repoLabel = ({ github, commit, directory }) => `${github ?? '?'}${commit ? `@${commit.slice(0, 7)}` : ''}${directory ? ` (${directory})` : ''}`
212
160
 
213
- function describeModuleChange({ name, versionChange, nameChange, repoChange }) {
161
+ function describeModuleChange({ name, versionChange, nameChange, repoChange, integrityChange, patchChange }) {
214
162
  const segs = []
215
163
  if (versionChange) segs.push(`${versionChange.from} -> ${versionChange.to}`)
216
164
  if (nameChange) segs.push(`name ${nameChange.from} -> ${nameChange.to}`)
217
165
  if (repoChange) segs.push(`repo ${repoLabel(repoChange.from)} -> ${repoLabel(repoChange.to)}`)
166
+ if (integrityChange) segs.push(`integrity ${integrityChange.from ?? 'none'} -> ${integrityChange.to ?? 'none'}`)
167
+ if (patchChange) segs.push(`patch ${patchChange.from?.integrity ?? 'none'} -> ${patchChange.to?.integrity ?? 'none'}`)
218
168
  return `${name ? `${name} ` : ''}${segs.join(', ')}`
219
169
  }
220
170
 
@@ -223,44 +173,39 @@ const moduleLine = (mark, x) => {
223
173
  return ` ${mark} ${x.dir}${id ? ` ${id}` : ''} (${x.files} file${plural(x.files)})`
224
174
  }
225
175
 
226
- // `parent 'specifier'` — an edge is identified by importer + specifier (conditions folded away).
227
176
  const edgeLabel = (e) => `${e.parent} '${e.specifier}'`
228
- const targetList = (files) => files.join(', ')
229
177
 
230
- // Render the `--stat` summary (module + file change lists with counts, plus import-edge changes
231
- // when present); reports what changed, not the text. `labels` is { left, right, leftKind, rightKind }.
232
- // Returns a string ending in a newline.
178
+ // The `--stat` summary: what changed, not the text.
233
179
  export function formatDiffStat(diff, { left = '(left)', right = '(right)', leftKind, rightKind } = {}) {
234
180
  const { modules: m, files: f, executable: ex, imports: im, scope } = diff
235
- const lines = ['stasis diff --stat']
236
- const label = (kind) => (kind ? `${KIND_LABEL[kind]}, ` : '')
237
- lines.push(` ${REMOVED} ${left} (${label(leftKind)}scope=${scope.left})`)
238
- lines.push(` ${ADDED} ${right} (${label(rightKind)}scope=${scope.right})`)
181
+ const label = (kind) => (kind ? `${kind}, ` : '')
182
+ const lines = [
183
+ 'stasis diff --stat',
184
+ ` ${REMOVED} ${left} (${label(leftKind)}scope=${scope.left})`,
185
+ ` ${ADDED} ${right} (${label(rightKind)}scope=${scope.right})`,
186
+ ]
187
+ const paths = (mark, list) => {
188
+ for (const p of list) lines.push(` ${mark} ${p}`)
189
+ }
239
190
  if (scope.left !== scope.right) {
240
191
  lines.push(` note: scopes differ (${scope.left} vs ${scope.right}); files only the full-scope artifact records show as removed/added`)
241
192
  }
242
193
 
243
- lines.push('')
244
- lines.push(`Modules: ${m.added.length} added, ${m.removed.length} removed, ${m.changed.length} changed`)
194
+ lines.push('', `Modules: ${m.added.length} added, ${m.removed.length} removed, ${m.changed.length} changed`)
245
195
  for (const x of m.removed) lines.push(moduleLine(REMOVED, x))
246
196
  for (const x of m.added) lines.push(moduleLine(ADDED, x))
247
197
  for (const x of m.changed) lines.push(` ${CHANGED} ${x.dir} ${describeModuleChange(x)}`)
248
198
 
249
- lines.push('')
250
- // Counts cover only files within modules present on both sides; a wholly added/removed module's
251
- // files are summarized by its module entry above — hence the "within shared modules" label.
252
- lines.push(`Files (within shared modules): ${f.added.length} added, ${f.removed.length} removed, ${f.differing.length} differing`)
253
- for (const p of f.removed) lines.push(` ${REMOVED} ${p}`)
254
- for (const p of f.added) lines.push(` ${ADDED} ${p}`)
255
- for (const p of f.differing) lines.push(` ${CHANGED} ${p}`)
199
+ lines.push('', `Files (within shared modules): ${f.added.length} added, ${f.removed.length} removed, ${f.differing.length} differing`)
200
+ paths(REMOVED, f.removed)
201
+ paths(ADDED, f.added)
202
+ paths(CHANGED, f.differing)
256
203
 
257
- // Only rendered when something changed: an unchanged execute-bit set is the overwhelming norm,
258
- // and a permanent "0 added, 0 removed" line would be noise in every diff.
204
+ // A permanent "0 added, 0 removed" line would be noise in every diff.
259
205
  if (ex.added.length > 0 || ex.removed.length > 0) {
260
- lines.push('')
261
- lines.push(`Executable: ${ex.added.length} added, ${ex.removed.length} removed`)
262
- for (const p of ex.removed) lines.push(` ${REMOVED} ${p}`)
263
- for (const p of ex.added) lines.push(` ${ADDED} ${p}`)
206
+ lines.push('', `Executable: ${ex.added.length} added, ${ex.removed.length} removed`)
207
+ paths(REMOVED, ex.removed)
208
+ paths(ADDED, ex.added)
264
209
  }
265
210
 
266
211
  if (im) {
@@ -272,13 +217,12 @@ export function formatDiffStat(diff, { left = '(left)', right = '(right)', leftK
272
217
  lines.push(`Imports: ${which} resolutions; skipping import diff`)
273
218
  } else {
274
219
  lines.push(`Imports: ${im.added.length} added, ${im.removed.length} removed, ${im.changed.length} changed`)
275
- for (const e of im.removed) lines.push(` ${REMOVED} ${edgeLabel(e)} -> ${targetList(e.from)}`)
276
- for (const e of im.added) lines.push(` ${ADDED} ${edgeLabel(e)} -> ${targetList(e.to)}`)
277
- for (const e of im.changed) lines.push(` ${CHANGED} ${edgeLabel(e)} ${targetList(e.from)} -> ${targetList(e.to)}`)
220
+ for (const e of im.removed) lines.push(` ${REMOVED} ${edgeLabel(e)} -> ${e.from.join(', ')}`)
221
+ for (const e of im.added) lines.push(` ${ADDED} ${edgeLabel(e)} -> ${e.to.join(', ')}`)
222
+ for (const e of im.changed) lines.push(` ${CHANGED} ${edgeLabel(e)} ${e.from.join(', ')} -> ${e.to.join(', ')}`)
278
223
  }
279
224
  }
280
225
 
281
- lines.push('')
282
- lines.push(hasDifferences(diff) ? 'Artifacts differ' : 'No differences')
226
+ lines.push('', hasDifferences(diff) ? 'Artifacts differ' : 'No differences')
283
227
  return lines.join('\n') + '\n'
284
228
  }
package/src/esbuild.js CHANGED
@@ -1,5 +1 @@
1
- // Public-export adapter: backs `@exodus/stasis/esbuild`. The plugin lives in
2
- // @exodus/stasis-plugins (which depends on @exodus/stasis-core for State /
3
- // resolvePluginState). Internal code uses `@exodus/stasis-plugins/esbuild` directly;
4
- // this file exists only to back the package's `exports` map.
5
1
  export * from '@exodus/stasis-plugins/esbuild'
package/src/flow.js CHANGED
@@ -1,22 +1,27 @@
1
- // --flow, for `stasis bundle` (the scan) and `stasis build`: Flow type syntax stripped from a JS-family
2
- // file the parser can't read otherwise, by flow-remove-types -- stasis's own dependency, resolved from
3
- // stasis itself (never from the project) and loaded lazily, only under --flow.
1
+ // --flow (which --metro turns on): Flow type syntax stripped as Metro's Babel (@react-native/babel-preset) strips it,
2
+ // by flow-remove-types -- stasis's own dependency, never the project's, loaded lazily.
4
3
  import { createRequire } from 'node:module'
5
4
 
6
- // Flow type syntax lives in the JS (non-TS) family: flow-remove-types over a .ts/.tsx file would
7
- // corrupt TS-only constructs. .jsx is included (JS + JSX, which can carry Flow types like .js);
8
- // flow-remove-types preserves JSX.
5
+ // The JS family alone: flow-remove-types would corrupt TS-only constructs. It preserves JSX.
9
6
  export const FLOW_EXTS = new Set(['.js', '.cjs', '.mjs', '.jsx'])
10
7
 
8
+ // Anywhere in the file, as React Native's Babel preset finds it (/@flow/), to parse the file as Flow throughout.
9
+ export const hasFlowPragma = (source) => source.includes('@flow')
10
+
11
+ // In a file marked `@noflow`, flow-remove-types reads syntax both Flow and JS can read (`f<T>(x)`, `a < b > (c)`) as
12
+ // JS (hermes-parser's `flow: 'detect'`). NOFLOW_STRIPPED is what it leaves of the comment.
13
+ const NOFLOW = '\n/* @noflow */'
14
+ const NOFLOW_STRIPPED = `\n/* ${' '.repeat('@noflow'.length)} */`
15
+
11
16
  let flowRemoveTypes
12
17
 
13
- // `source` with its Flow type syntax blanked to whitespace in place, so byte offsets and every import
14
- // specifier are kept. `all: true` ignores the @flow/@noflow pragma (React Native's sources mix both).
15
- // Types only: Flow syntax that is code -- `component` and `hook` declarations, `enum`s -- stays. An
16
- // import listing types alone (`import { type A } from`) stays as `import {} from`, or with
17
- // `removeEmptyImports` goes whole, as Babel's Flow transform drops it. Throws where flow-remove-types
18
- // can't parse `source`.
18
+ // `source` with its Flow types blanked in place (offsets kept): one marked `@flow` as Flow throughout (`f<T>(x)` a
19
+ // call), any other as a `@noflow` file, marked so past its end. Flow code (`enum`s) stays. Throws where it can't parse.
19
20
  export function stripFlowTypes(source, { removeEmptyImports = false } = {}) {
20
21
  flowRemoveTypes ??= createRequire(import.meta.url)('flow-remove-types')
21
- return flowRemoveTypes(source, { all: true, removeEmptyImports }).toString()
22
+ if (hasFlowPragma(source)) return flowRemoveTypes(source, { all: true, removeEmptyImports }).toString()
23
+ if (source.includes('@noflow')) return flowRemoveTypes(source, { removeEmptyImports }).toString()
24
+ const stripped = flowRemoveTypes(source + NOFLOW, { removeEmptyImports }).toString()
25
+ if (!stripped.endsWith(NOFLOW_STRIPPED)) throw new Error('flow-remove-types left the @noflow comment stasis appended')
26
+ return stripped.slice(0, -NOFLOW_STRIPPED.length)
22
27
  }