@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
@@ -1,13 +1,5 @@
1
- // Based on DeepView's Solidity loader.
2
- // https://github.com/PreventiveMeasures/deepview/blob/main/src/loaders/solidity.js
3
- // Produces a `{ sources, resolutions }` pair. Imports resolve the way solc does under the project's
4
- // build tool: remappings (discovered the way `forge build` does for a Foundry project, see
5
- // foundry.js), then a Foundry library's include path, solc's base path (the project root), and
6
- // Hardhat's/Node's node_modules lookup. The mapping/config files are read, not added to `sources`.
7
- // Dependencies are untrusted input: an import only ever reaches a `.sol` file inside the project,
8
- // a dependency's imports only its own and other dependencies' files (by real path), and nothing
9
- // is read through a link a dependency planted out of itself (solidityOwnership). The project is read
10
- // through a `host` (@exodus/stasis-core/host), the disk's by default.
1
+ // Based on DeepView's Solidity loader (https://github.com/PreventiveMeasures/deepview/blob/main/src/loaders/solidity.js).
2
+ // Dependencies are untrusted: an import never leaves the project nor crosses a link one plants (solidityOwnership).
11
3
 
12
4
  import { isAbsolute, join, posix, relative, resolve } from 'node:path'
13
5
 
@@ -28,10 +20,7 @@ import {
28
20
  import { applyToDir, isDotRelative } from './paths.js'
29
21
  import { decodeUtf8, projectOwnership, projectRelative, readUtf8OrNull, realpathOrNull, solidityOwnership } from './solidity-ownership.js'
30
22
 
31
- // --- Import scan ------------------------------------------------------------------------------
32
-
33
- // The scan's ASCII classes, by char code: identifier start [A-Za-z_$], identifier part [\w$], digit,
34
- // and a number literal's [\w.].
23
+ // By char code: identifier start [A-Za-z_$], identifier part [\w$], digit, and a number literal's [\w.].
35
24
  const isIdentStart = (c) => (c >= 97 && c <= 122) || (c >= 65 && c <= 90) || c === 95 || c === 36
36
25
  const isDigit = (c) => c >= 48 && c <= 57
37
26
  const isIdentPart = (c) => isIdentStart(c) || isDigit(c)
@@ -40,9 +29,8 @@ const STRING_ESCAPES = { n: '\n', r: '\r', t: '\t', b: '\b', f: '\f', v: '\v', 0
40
29
 
41
30
  const utf8 = (s) => [...Buffer.from(s, 'utf8')]
42
31
 
43
- // A string literal starting at `text[i]` (a quote): `{ value, end }`, `value` null when it's
44
- // unterminated on its line (solc rejects those). A literal is bytes, as in solc: `\xNN` is one
45
- // byte, `\uNNNN` and plain text their UTF-8, and the path is those bytes read as UTF-8.
32
+ // `value` null where unterminated on its line, as solc rejects it. A literal is bytes, as in solc: `\xNN` one
33
+ // byte, `\uNNNN` and plain text their UTF-8, and the path those bytes read as UTF-8.
46
34
  function readStringLiteral(text, i) {
47
35
  const quote = text.charCodeAt(i)
48
36
  let bytes = null // set at the first escape; until then the literal is a plain slice
@@ -84,11 +72,7 @@ function readStringLiteral(text, i) {
84
72
  return { value: null, end: j }
85
73
  }
86
74
 
87
- // The path of every import directive, in source order. The text is tokenized far enough to skip
88
- // comments and string literals, so a commented-out `// import "./Old.sol";` or a string holding
89
- // the word `import` is never taken for one. An import is the `import` keyword followed, before its
90
- // `;`, by the path literal: `import "p";`, `import "p" as X;`, `import * as X from "p";`,
91
- // `import {A, B as C} from "p";` -- over any number of lines.
75
+ // Tokenized far enough that a commented-out import, or a string holding the word, is never taken for one.
92
76
  export function extractSolImports(content) {
93
77
  const specs = []
94
78
  const n = content.length
@@ -128,17 +112,11 @@ export function extractSolImports(content) {
128
112
  return specs
129
113
  }
130
114
 
131
- // --- Remappings ---------------------------------------------------------------------------------
132
-
133
- // Loader-side shape: `{ context, prefix, target }` (context null = global).
134
115
  const toLoaderRemapping = ({ context, name, path }) => ({ context, prefix: name, target: path })
135
116
 
136
- // Read a mapping file -> its remappings as listed (no discovery around it) and the files read. A
137
- // foundry.toml (its selected profile, with its `extends` base) is forge's, and so is a
138
- // remappings.txt when `forge` says forge reads it: slash-terminated the way forge reads them.
139
- // Otherwise (solc, Hardhat) a remappings.txt applies as written. Messages name files `show(file)`;
140
- // files are read through `host`.
141
- function readMapping(mappingFile, { env, forge, host, show = (f) => f }) {
117
+ // A foundry.toml's and, with `forge`, a remappings.txt's are slash-terminated as forge reads them; else (solc,
118
+ // Hardhat) a remappings.txt applies as written.
119
+ function readMapping(mappingFile, { env, forge, host, show }) {
142
120
  if (mappingFile.endsWith('.toml')) {
143
121
  const { remappings, files, profiled } = readFoundryTomlRemappings(mappingFile, foundryProfile(env), { show, host })
144
122
  return { remappings: remappings.map(toSolcRemapping), files, profiled }
@@ -150,20 +128,8 @@ function readMapping(mappingFile, { env, forge, host, show = (f) => f }) {
150
128
  return { remappings: listed.map(forge ? toSolcRemapping : toLoaderRemapping), files: [mappingFile] }
151
129
  }
152
130
 
153
- // --- Resolution ---------------------------------------------------------------------------------
154
-
155
- // What resolves the imports of the project at `baseDir`:
156
- // `{ remappings, libs, ownership, files, envUsed }`.
157
- // - `mappingFile` (foundry.toml / remappings.txt): exactly the remappings it lists (see readMapping).
158
- // - else, with a foundry.toml at the root: what `forge build` uses (foundry.js) -- remappings.txt,
159
- // the profile's remappings, dependencies' own configs, auto-detected `lib/` remappings and their
160
- // contexts.
161
- // - else a remappings.txt at the root (solc / Hardhat 3), taken as written.
162
- // `libs` are forge's lib dirs whenever the root has a foundry.toml (an absolute import inside a
163
- // library resolves against it); `ownership` tells the dependencies' files from the project's
164
- // (solidityOwnership: forge's libs, Soldeer's `dependencies/`, git submodules, node_modules);
165
- // `files` the project-relative config files read (`../` for one outside the project); `envUsed`
166
- // the environment variables that shaped the result. The project is read through `host`.
131
+ // The remappings `mappingFile` lists, else what `forge build` uses with a foundry.toml at the root, else a
132
+ // root remappings.txt as written.
167
133
  export function discoverSolidityConfig(baseDir, { mappingFile, env = process.env, host = diskHost } = {}) {
168
134
  const forge = isFile(join(baseDir, FOUNDRY_TOML), host)
169
135
  if (forge && !mappingFile) return foundryProject(baseDir, { env, host })
@@ -173,8 +139,7 @@ export function discoverSolidityConfig(baseDir, { mappingFile, env = process.env
173
139
  if (mappingFile) {
174
140
  const abs = resolve(baseDir, mappingFile)
175
141
  const { remappings, files, profiled: mappingProfiled } = readMapping(abs, { env, forge, host, show })
176
- // The profile picks the mapping file's remappings (a .toml) or the root foundry.toml's libs: the
177
- // files read are both's.
142
+ // The profile picks the mapping file's remappings (a .toml) or the root foundry.toml's libs.
178
143
  const envUsed = profiled || mappingProfiled ? [`FOUNDRY_PROFILE=${env.FOUNDRY_PROFILE}`] : []
179
144
  return { remappings, libs, ownership, files: [...new Set([...files, ...libsFiles].map((f) => projectRelative(baseDir, f, host)))], envUsed }
180
145
  }
@@ -183,10 +148,8 @@ export function discoverSolidityConfig(baseDir, { mappingFile, env = process.env
183
148
  return { remappings: readMapping(txt, { env, forge, host, show }).remappings, libs, ownership, files: [REMAPPINGS_TXT], envUsed: [] }
184
149
  }
185
150
 
186
- // Solc's remapping choice for the source unit `name` imported from `fromFile`: among the
187
- // remappings whose context is a prefix of `fromFile` and whose prefix is a prefix of `name`, the
188
- // longest context wins, then the longest prefix, then the one listed last. The target replaces the
189
- // prefix verbatim (`//` collapsed). Null when none applies.
151
+ // As solc remaps: of those whose context and prefix match, the longest context wins, then the longest prefix,
152
+ // then the one listed last; its target replaces the prefix verbatim (`//` collapsed).
190
153
  export function applyRemappings(name, fromFile, remappings) {
191
154
  let best = null
192
155
  for (const r of remappings) {
@@ -199,12 +162,6 @@ export function applyRemappings(name, fromFile, remappings) {
199
162
  return posix.normalize(best.target + name.slice(best.prefix.length)).replace(/^\.\//u, '')
200
163
  }
201
164
 
202
- // A relative import (first segment `.` or `..`) as solc resolves it: against the importing file's
203
- // directory. Null when it climbs above the root: solc clamps there (`../../B.sol` from `src/A.sol`
204
- // is `B.sol`), but an import reaching out of the project is refused rather than redirected.
205
- const resolveRelativeImport = (specifier, fromFile) => applyToDir(fromFile, specifier.split('/'))
206
-
207
- // `<baseDir>/<spec>` when a real file sits there, as a clean project-relative path.
208
165
  function projectFile(baseDir, spec, host) {
209
166
  if (isAbsolute(spec)) return null
210
167
  const rel = toPosix(relative(baseDir, resolve(baseDir, spec)))
@@ -215,10 +172,8 @@ function projectFile(baseDir, spec, host) {
215
172
  // No `.`/`..`/empty segment: a bare spec can't wander out of the directory it's looked up in.
216
173
  const isPlainSpec = (spec) => spec.split('/').every((p) => p !== '' && p !== '.' && p !== '..')
217
174
 
218
- // Forge's absolute import inside a library (`lib/dep/src/A.sol` importing `src/B.sol`): tried
219
- // against each directory from the parent of the importer's up to (not including) its lib dir, as
220
- // foundry-compilers' `resolve_absolute_library` does; forge passes the matching one to solc as an
221
- // include path.
175
+ // Forge's absolute import inside a library (`src/B.sol` from `lib/dep/src/A.sol`), as foundry-compilers'
176
+ // `resolve_absolute_library` finds it, forge passing the match to solc as an include path.
222
177
  function libraryFile(baseDir, spec, fromFile, libs, host) {
223
178
  const lib = libs.map((l) => posix.normalize(toPosix(l)).replace(/\/$/u, '')).find((l) => fromFile.startsWith(`${l}/`))
224
179
  if (!lib) return null
@@ -229,9 +184,7 @@ function libraryFile(baseDir, spec, fromFile, libs, host) {
229
184
  return null
230
185
  }
231
186
 
232
- // A package import (`pkg/path.sol`, `@scope/pkg/path.sol`) by file path through node_modules, from
233
- // the importing file's directory up to the root (Hardhat and Node; a package's `exports` map
234
- // doesn't apply to Solidity sources).
187
+ // As Hardhat and Node find a package's file; its `exports` map doesn't apply to Solidity sources.
235
188
  function nodeModulesFile(baseDir, spec, fromFile, host) {
236
189
  const parts = spec.split('/')
237
190
  if (parts.length < (spec.startsWith('@') ? 3 : 2)) return null
@@ -244,11 +197,12 @@ function nodeModulesFile(baseDir, spec, fromFile, host) {
244
197
  }
245
198
  }
246
199
 
247
- // Where an import resolves, as `{ path }`, or `{ reason }` when it may not be read (`reason: null`:
248
- // it names no file). See resolveSolImport.
200
+ // `{ reason: null }` for an import naming no file.
249
201
  function resolveImport(specifier, fromFile, { remappings = [], baseDir, libs = [], ownership, host = diskHost } = {}) {
250
202
  const relativeImport = isDotRelative(specifier)
251
- const name = relativeImport ? resolveRelativeImport(specifier, fromFile) : specifier
203
+ // solc clamps a relative import climbing above the root there, but one reaching out of the project is
204
+ // refused, not redirected.
205
+ const name = relativeImport ? applyToDir(fromFile, specifier.split('/')) : specifier
252
206
  if (name === null) return { reason: 'it climbs above the project root' }
253
207
  let path = applyRemappings(name, fromFile, remappings)
254
208
  if (path === null && relativeImport) path = name
@@ -268,35 +222,17 @@ function resolveImport(specifier, fromFile, { remappings = [], baseDir, libs = [
268
222
  return { path }
269
223
  }
270
224
 
271
- // Resolve a Solidity import to a baseDir-relative POSIX path, the way solc does: a relative import
272
- // (`./`, `../`) is taken against the importing file (root escape -> null), then remappings apply
273
- // (longest context, then longest prefix; see applyRemappings). An unremapped non-relative import
274
- // is then looked up, when `baseDir` is given, inside the importer's library (forge's include path;
275
- // `libs` are forge's lib dirs), as a project file (solc's base path), and through node_modules by
276
- // file path (Hardhat / Node). Returns null when nothing resolves, or when the result isn't a `.sol`
277
- // file inside the root, crosses a link a dependency planted out of itself, or is the project's own
278
- // file imported by a dependency's -- by real path, with `ownership` (solidityOwnership's; by default
279
- // only node_modules holds dependencies). The project is read through `host`.
280
- export function resolveSolImport(specifier, fromFile, options = {}) {
281
- return resolveImport(specifier, fromFile, options).path ?? null
282
- }
225
+ // Relative, remapped, then in the importer's library, the project, node_modules; null too where refused.
226
+ export const resolveSolImport = (specifier, fromFile, options = {}) => resolveImport(specifier, fromFile, options).path ?? null
283
227
 
284
- // The files that describe a Solidity build (bundled by `--manifests`) besides the config files
285
- // discovery read: the root's dependency pins, and each package's manifests. (`hardhat.config.*` is
286
- // code that may hold keys, so it is never carried.)
228
+ // Not `hardhat.config.*`, code that may hold keys.
287
229
  export const SOLIDITY_ROOT_MANIFESTS = [FOUNDRY_TOML, REMAPPINGS_TXT, 'foundry.lock', 'soldeer.lock', '.gitmodules', 'package.json']
288
230
  export const SOLIDITY_PACKAGE_MANIFESTS = ['package.json', FOUNDRY_TOML, REMAPPINGS_TXT]
289
231
 
290
- // --- The walk -----------------------------------------------------------------------------------
291
-
292
232
  const warnUnresolved = (spec, from, reason) =>
293
233
  console.warn(`[loader.solidity] ${reason ? 'Refused' : 'Missing'} import: ${spec} from ${from}${reason ? ` (${reason})` : ''}`)
294
234
 
295
- // Build `{ sources, resolutions, missing }` from already-loaded Solidity sources plus remappings.
296
- // Imports resolve as resolveSolImport does (`libs`, `ownership`, `host`: see there); as a final
297
- // fallback a specifier naming no file but matching a stored key verbatim is accepted. `missing`
298
- // lists every `{ spec, from }` that didn't resolve or resolved outside `sources`, with the
299
- // `reason` when it was refused.
235
+ // A specifier naming no file but a stored key verbatim resolves to it.
300
236
  export function buildSolidityTree(sources, { remappings = [], baseDir, libs = [], host = diskHost, ownership = baseDir && solidityOwnership(baseDir, { host }) } = {}) {
301
237
  const resolutions = new Map()
302
238
  const missing = []
@@ -305,11 +241,9 @@ export function buildSolidityTree(sources, { remappings = [], baseDir, libs = []
305
241
  const specMap = new Map()
306
242
  for (const spec of extractSolImports(content)) {
307
243
  const r = resolveImport(spec, path, options)
308
- let resolved = r.path && sources.has(r.path) ? r.path : null
309
- if (!resolved && !r.reason && sources.has(spec)) resolved = spec
310
- if (resolved) {
311
- specMap.set(spec, resolved)
312
- } else {
244
+ const resolved = r.path && sources.has(r.path) ? r.path : !r.reason && sources.has(spec) ? spec : null
245
+ if (resolved) specMap.set(spec, resolved)
246
+ else {
313
247
  warnUnresolved(spec, path, r.reason)
314
248
  missing.push(r.reason ? { spec, from: path, reason: r.reason } : { spec, from: path })
315
249
  }
@@ -319,11 +253,7 @@ export function buildSolidityTree(sources, { remappings = [], baseDir, libs = []
319
253
  return { sources, resolutions, missing }
320
254
  }
321
255
 
322
- // Walk the project from `entries`, following resolved imports and reading each file once, a wave at
323
- // a time: the files of one, then the imports they name. Caller-listed entries are also accepted as
324
- // verbatim non-relative import targets naming no file (Foundry-style `import "src/A.sol"`). An entry
325
- // that crosses a dependency's link out of itself (see solidityOwnership) is refused. The project is
326
- // read through `host`.
256
+ // Entries are taken as verbatim import targets naming no file too (Foundry-style `import "src/A.sol"`).
327
257
  export function collectSolidityFilesFromDisk(baseDir, entries, remappings, { libs = [], host = diskHost, ownership = solidityOwnership(baseDir, { host }) } = {}) {
328
258
  const sources = new Map()
329
259
  const knownEntries = new Set(entries)
@@ -344,18 +274,13 @@ export function collectSolidityFilesFromDisk(baseDir, entries, remappings, { lib
344
274
  }
345
275
  })
346
276
  const next = []
347
- for (const entry of reads) {
348
- if (!entry) continue
349
- const [relPath, content] = entry
277
+ for (const [relPath, content] of reads.filter(Boolean)) {
350
278
  sources.set(relPath, content)
351
279
  for (const spec of extractSolImports(content)) {
352
280
  const r = resolveImport(spec, relPath, options)
353
281
  const resolved = r.path ?? (!r.reason && knownEntries.has(spec) ? spec : null)
354
- if (resolved) {
355
- if (!sources.has(resolved)) next.push(resolved)
356
- } else {
357
- warnUnresolved(spec, relPath, r.reason)
358
- }
282
+ if (resolved) next.push(resolved)
283
+ else warnUnresolved(spec, relPath, r.reason)
359
284
  }
360
285
  }
361
286
  wave = next
@@ -363,15 +288,11 @@ export function collectSolidityFilesFromDisk(baseDir, entries, remappings, { lib
363
288
  return sources
364
289
  }
365
290
 
366
- // Every `.sol` file under the project-relative directory `dir`, sorted, symlinks followed as forge
367
- // (walkdir, `follow_links`) collects a source dir: a symlinked directory whose real path is one on
368
- // the current walk (the walk root included) is a loop and skipped; anything else is walked, so two
369
- // links to one directory are two directories. A dir's real path is its parent's plus its name
370
- // unless it's a symlink.
291
+ // Symlinks followed as forge's walkdir (`follow_links`) collects a source dir: a linked directory whose real
292
+ // path is on the current walk is a loop and skipped; two links to one directory are two directories.
371
293
  function solidityFilesUnder(baseDir, dir, host) {
372
294
  const out = []
373
- // The real paths of the directories on the current walk; one may repeat (a real directory
374
- // reached again through a link is walked, as walkdir does, and checked only at links).
295
+ // One may repeat: a real directory reached again through a link is walked, as walkdir does, checked only at links.
375
296
  const stack = []
376
297
  const walk = (rel, real) => {
377
298
  stack.push(real)
@@ -395,16 +316,12 @@ function solidityFilesUnder(baseDir, dir, host) {
395
316
  return out.toSorted()
396
317
  }
397
318
 
398
- // Project-relative entries with each directory replaced by the `.sol` files under it (deduped, in
399
- // order). A `.sol` entry is kept as is (a missing one is reported by the walk); a directory that
400
- // is missing or holds no `.sol` file is skipped with a warning, as forge skips an absent `script/`,
401
- // and it's an error only when no entry yields a file (when none exists, a mistyped path). The
402
- // project is read through `host`.
319
+ // A directory missing or holding no `.sol` file is skipped with a warning, as forge skips an absent `script/`.
403
320
  export function expandSolidityEntries(baseDir, entries, host = diskHost) {
404
321
  const out = new Set()
405
322
  const shown = (entry) => (entry === '.' ? './' : `${entry}/`)
406
- for (const e of entries) {
407
- const entry = e === '' ? '.' : e
323
+ const named = entries.map((e) => (e === '' ? '.' : e))
324
+ for (const entry of named) {
408
325
  const dir = isDir(join(baseDir, entry), host)
409
326
  if (!dir && entry.endsWith('.sol')) {
410
327
  out.add(entry)
@@ -416,7 +333,7 @@ export function expandSolidityEntries(baseDir, entries, host = diskHost) {
416
333
  }
417
334
  if (out.size === 0) {
418
335
  if (entries.every((e) => host.stat(join(baseDir, e)) === null)) throw new Error(`No such file or directory: ${entries[0]}`)
419
- throw new Error(`No .sol files under ${entries.map((e) => shown(e === '' ? '.' : e)).join(', ')} (a directory entry stands for the Solidity sources under it)`)
336
+ throw new Error(`No .sol files under ${named.map(shown).join(', ')} (a directory entry stands for the Solidity sources under it)`)
420
337
  }
421
338
  return [...out]
422
339
  }
@@ -1,16 +1,11 @@
1
- // TOML for the build descriptions the loaders take -- Cargo.toml, Cargo.lock, foundry.toml -- read
2
- // by @preventive/lockfile's strict TOML 1.0 parser into a tree of tables, and refused where it
3
- // isn't TOML, or isn't the TOML those files are written in: a bad escape, an unterminated string, a
4
- // key or table defined twice, a local date, U+FFFD where a lenient decoder replaced bytes ... each a
5
- // TomlError naming the file and line, never a guessed value.
1
+ // TOML for Cargo.toml, Cargo.lock and foundry.toml, by @preventive/lockfile's strict TOML 1.0 parser:
2
+ // what isn't TOML is a TomlError naming the file and line, never a guessed value.
6
3
 
7
4
  import { TomlError, parseToml } from '@preventive/lockfile/toml.js'
8
5
 
9
6
  export { TomlError }
10
7
 
11
- // --- Bracket helpers (for the Rust scanner) ----------------------------------------------
12
-
13
- // Index of the bracket closing the one opened at `open`, or the last index when unbalanced.
8
+ // The index of the bracket closing the one at `open`; the last index when unbalanced.
14
9
  export function matchClose(text, open) {
15
10
  const close = { '[': ']', '(': ')', '{': '}' }[text[open]]
16
11
  let depth = 0
@@ -21,7 +16,7 @@ export function matchClose(text, open) {
21
16
  return text.length - 1
22
17
  }
23
18
 
24
- // Split on commas outside brackets/braces/parentheses/strings.
19
+ // Split on commas outside brackets, braces, parentheses and strings.
25
20
  export function splitTopLevel(text) {
26
21
  const parts = []
27
22
  let depth = 0
@@ -46,15 +41,10 @@ export function splitTopLevel(text) {
46
41
  return parts
47
42
  }
48
43
 
49
- // --- The reader -----------------------------------------------------------------------------
50
-
51
- // The table tree of TOML `text` (parseToml): tables are null-prototype objects, arrays arrays, and
52
- // values strings, booleans, numbers (an integer past 2^53 a BigInt), TomlFloat and TomlDateTime.
53
- // Throws a TomlError on anything else, naming `file` when given.
44
+ // Tables are null-prototype objects; an integer past 2^53 is a BigInt.
54
45
  export const readToml = (text, file = null) => nameErrors(file, () => parseToml(text))
55
46
 
56
- // `read()`, with an error of one of `classes` it throws (@preventive/lockfile's, whose message
57
- // leads with where it is) leading with `file` too, its fields kept; null `file` names none.
47
+ // `read()`, with an error of one of `classes` re-thrown with `file: ` leading its message, its fields kept.
58
48
  export function nameErrors(file, read, classes = [TomlError]) {
59
49
  try {
60
50
  return read()
@@ -64,5 +54,5 @@ export function nameErrors(file, read, classes = [TomlError]) {
64
54
  }
65
55
  }
66
56
 
67
- // Whether a TOML value is a table (a TomlFloat or TomlDateTime is an object too).
57
+ // The prototype check: a TomlFloat or TomlDateTime is an object too.
68
58
  export const isTomlTable = (value) => value !== null && typeof value === 'object' && Object.getPrototypeOf(value) === null
package/src/lockfile.js CHANGED
@@ -1,4 +1 @@
1
- // Public-export adapter: backs `@exodus/stasis/lockfile`. The implementation lives in
2
- // @exodus/stasis-core; internal tooling and tests import `@exodus/stasis-core/lockfile`
3
- // directly, so this file exists only to back the package's `exports` map.
4
1
  export * from '@exodus/stasis-core/lockfile'