@exodus/stasis 1.0.0-beta.15 → 1.0.0-beta.17
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 +1 -1
- package/bin/stasis.js +26 -11
- package/package.json +10 -9
- package/src/audit-corrections.js +11 -42
- package/src/audit.js +113 -233
- package/src/babel.js +39 -122
- package/src/bundle-from-lockfile.js +9 -21
- package/src/bundle-reader.js +5 -9
- package/src/bundle.js +0 -3
- package/src/cmd/build.js +50 -166
- package/src/cmd/bundle-options.js +110 -167
- package/src/cmd/bundle.js +861 -1344
- package/src/cmd/diff.js +1 -4
- package/src/cmd/github-bundle.js +46 -27
- package/src/cmd/output.js +17 -12
- package/src/cmd/sbom.js +3 -8
- package/src/cmd/tokens.js +10 -23
- package/src/define.js +34 -97
- package/src/diff.js +72 -128
- package/src/esbuild.js +0 -4
- package/src/flow.js +10 -25
- 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 +41 -93
- package/src/loaders/cargo.js +298 -805
- package/src/loaders/foundry.js +109 -285
- package/src/loaders/paths.js +13 -13
- package/src/loaders/php.js +210 -489
- package/src/loaders/rust.js +507 -1430
- package/src/loaders/solidity-ownership.js +48 -128
- package/src/loaders/solidity.js +39 -122
- package/src/loaders/toml.js +7 -17
- package/src/lockfile.js +0 -3
- package/src/metro-assets.js +9 -33
- package/src/metro-resolver.js +20 -47
- package/src/metro-transformer.js +0 -5
- package/src/metro.js +0 -4
- package/src/mock.js +32 -80
- package/src/parse.js +2 -5
- package/src/prune.js +0 -3
- package/src/resolve-fields.js +90 -220
- package/src/resolve-node.js +27 -45
- package/src/resolve-typescript.js +109 -313
- package/src/rollup.js +0 -4
- package/src/run-installed.js +10 -0
- package/src/sbom.js +52 -128
- package/src/scan.js +136 -283
- package/src/sixel.js +18 -41
- package/src/table.js +14 -35
- package/src/validate-notes.d.ts +3 -2
- package/src/validate-notes.js +25 -19
- package/src/validate.d.ts +38 -11
- package/src/validate.js +478 -512
- package/src/vfs-bundle/entries.js +40 -57
- package/src/vfs-bundle/github.js +88 -121
- package/src/vfs-bundle/glob.js +4 -45
- package/src/vfs-bundle/lazy.js +27 -56
- package/src/vfs-bundle/prisma.js +167 -110
- package/src/vfs-bundle/soldeer.js +28 -49
- package/src/vfs-bundle/tree.js +295 -318
- package/src/vfs-bundle/yarnclean.js +10 -31
- package/src/vfs-bundle.js +23 -64
- package/src/webpack.js +0 -4
- package/src/why.js +75 -231
- package/src/installed-commits.js +0 -184
package/src/loaders/solidity.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
// Based on DeepView's Solidity loader.
|
|
2
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
44
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
137
|
-
//
|
|
138
|
-
|
|
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
|
-
//
|
|
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
|
|
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
|
-
//
|
|
187
|
-
//
|
|
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 (`
|
|
219
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
//
|
|
272
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
|
|
309
|
-
if (
|
|
310
|
-
|
|
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
|
-
//
|
|
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
|
|
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
|
-
|
|
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
|
-
//
|
|
367
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
|
|
407
|
-
|
|
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 ${
|
|
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
|
}
|
package/src/loaders/toml.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
// TOML for
|
|
2
|
-
//
|
|
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
|
-
//
|
|
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
|
|
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
|
-
//
|
|
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`
|
|
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
|
-
//
|
|
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'
|
package/src/metro-assets.js
CHANGED
|
@@ -1,38 +1,16 @@
|
|
|
1
|
-
// `stasis build --metro=PLATFORM`: a Metro asset
|
|
2
|
-
//
|
|
3
|
-
// it, from the bytes the artifact carries -- never from disk.
|
|
4
|
-
//
|
|
5
|
-
// Metro builds `require('./img/logo.png')` into (metro-transform-worker's assetTransformer, Metro's
|
|
6
|
-
// getAssetData and generateAssetCodeFileAst):
|
|
7
|
-
//
|
|
8
|
-
// module.exports = require('react-native/Libraries/Image/AssetRegistry').registerAsset({
|
|
9
|
-
// __packager_asset: true, httpServerLocation: '/assets/img', width, height,
|
|
10
|
-
// scales: [1, 2, 3], hash, name: 'logo', type: 'png' })
|
|
11
|
-
//
|
|
12
|
-
// from every file of the asset in its directory (each scale, `logo@2x.png`; those for the platform,
|
|
13
|
-
// `logo.ios.png`, where it has any): their scales, an md5 over their bytes, and the first one's image
|
|
14
|
-
// dimensions over its scale. That reading of an asset and the module built of it are @preventive/rn's
|
|
15
|
-
// (assetData, assetModule), as is where --assets-dest copies its files (assetsDestFiles). What stays
|
|
16
|
-
// here is the asset registry the module requires: React Native's Metro config's `assetRegistryPath`
|
|
17
|
-
// (@react-native/metro-config's), the one `stasis bundle --metro` carries for an asset. A project's
|
|
18
|
-
// own `assetRegistryPath`, `publicPath` (Metro's default `/assets` here) and `assetPlugins` are read off
|
|
19
|
-
// its Metro config, which is code, and aren't.
|
|
1
|
+
// `stasis build --metro=PLATFORM`: a Metro asset built into the module Metro builds of it and copied out as
|
|
2
|
+
// `--assets-dest` copies it, from the artifact's bytes, never disk: @preventive/rn's, but for the registry it requires.
|
|
20
3
|
import { posix } from 'node:path'
|
|
21
4
|
|
|
22
5
|
import { METRO_SOURCE_EXTS } from './resolve-fields.js'
|
|
23
6
|
|
|
24
|
-
//
|
|
25
|
-
// `assetRegistryPath` (@react-native/metro-config's), where a project's own isn't read, being code.
|
|
26
|
-
// `stasis bundle --metro` carries the file it resolves to for each asset.
|
|
7
|
+
// React Native's Metro config's `assetRegistryPath`: a project's own would be read off its Metro config, which is code.
|
|
27
8
|
export const ASSET_REGISTRY = 'react-native/Libraries/Image/AssetRegistry'
|
|
28
9
|
|
|
29
|
-
// The resolver of `ASSET_REGISTRY` from an asset for `platform`, as Metro resolves it, among `carried`
|
|
30
|
-
// (the code files the artifact carries: a Map or Set keyed by their paths from the project root): the
|
|
31
|
-
// copy of react-native in the nearest node_modules up from the asset's directory, else the only copy
|
|
32
|
-
// (pnpm's, linked in from node_modules/.pnpm); in it, the file Metro probes first -- each of its
|
|
33
|
-
// sourceExts, the platform's file, then the .native one, then the plain one. The copies are found once.
|
|
34
|
-
// -> (rel) => its path, throwing where the artifact carries none, or several none of them nearest
|
|
35
10
|
const REGISTRY_ROOT = /^((?:.*\/)?node_modules\/react-native)\/Libraries\/Image\/AssetRegistry\./u
|
|
11
|
+
|
|
12
|
+
// Resolved as Metro resolves it among the code files `carried` (by project path): in the react-native nearest up
|
|
13
|
+
// from the asset, else the only one (pnpm's). Throws where the artifact carries none, or several none of them nearest.
|
|
36
14
|
export function assetRegistryResolver(platform, carried) {
|
|
37
15
|
const pick = (root) => {
|
|
38
16
|
for (const ext of METRO_SOURCE_EXTS) {
|
|
@@ -43,7 +21,7 @@ export function assetRegistryResolver(platform, carried) {
|
|
|
43
21
|
}
|
|
44
22
|
return undefined
|
|
45
23
|
}
|
|
46
|
-
const roots = new Set(
|
|
24
|
+
const roots = new Set(carried.keys().map((file) => REGISTRY_ROOT.exec(file)?.[1]).filter((root) => root !== undefined && pick(root) !== undefined))
|
|
47
25
|
const nearest = (rel) => {
|
|
48
26
|
for (let dir = posix.dirname(rel); ; dir = posix.dirname(dir)) {
|
|
49
27
|
const root = posix.join(dir, 'node_modules', 'react-native')
|
|
@@ -55,10 +33,8 @@ export function assetRegistryResolver(platform, carried) {
|
|
|
55
33
|
const root = roots.size === 1 ? [...roots][0] : nearest(rel)
|
|
56
34
|
if (root !== undefined) return pick(root)
|
|
57
35
|
if (roots.size === 0) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`stasis
|
|
60
|
-
'bundle it with `stasis bundle --metro --resources=...` from a project with react-native installed'
|
|
61
|
-
)
|
|
36
|
+
throw new Error(`stasis build: --metro builds '${rel}' into a module requiring ${ASSET_REGISTRY}, which the artifact `
|
|
37
|
+
+ 'doesn\'t carry; bundle it with `stasis bundle --metro --resources=...` from a project with react-native installed')
|
|
62
38
|
}
|
|
63
39
|
throw new Error(`stasis build: --metro found several ${ASSET_REGISTRY} for '${rel}', none of them nearest: ${[...roots].join(', ')}`)
|
|
64
40
|
}
|
package/src/metro-resolver.js
CHANGED
|
@@ -4,19 +4,18 @@ import { pathToFileURL } from 'node:url'
|
|
|
4
4
|
|
|
5
5
|
import { createMetroResolver as createRnMetroResolver, defaults } from '@preventive/rn/metro-resolver.js'
|
|
6
6
|
import { diskHost } from '@exodus/stasis-core/host'
|
|
7
|
-
import {
|
|
7
|
+
import { isPlainObject, isTypeDeclaration } from '@exodus/stasis-core/util'
|
|
8
|
+
import { isDir, isSourceFile } from './resolve-typescript.js'
|
|
8
9
|
|
|
9
|
-
// Metro's module resolution is @preventive/rn's
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
// Metro's module resolution is @preventive/rn's. What stays stasis's: no `.d.ts` is a module (metroHost), a builtin
|
|
11
|
+
// Metro misses is a builtin, and answers take the shape scan.js expects (scanResolution).
|
|
12
|
+
|
|
13
|
+
export const stripTypeDeclaration = (name) => name.replace(/\.d\.[mc]?ts$/iu, '')
|
|
13
14
|
|
|
14
|
-
// A manifest as stasis has Metro read it: an entry field (one of `mainFields`) naming a `.d.ts` names
|
|
15
|
-
// its declaration-free stem instead, so the package's entry lands on the real module beside it
|
|
16
|
-
// (`dist/index.d.ts` -> `dist/index`, then `dist/index.js`). Any other manifest, or one that is no
|
|
17
|
-
// JSON object (which the resolver refuses), is read as it is.
|
|
18
15
|
const utf8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })
|
|
19
16
|
const DECLARATION = /\.d\.[cm]?ts\b/iu
|
|
17
|
+
|
|
18
|
+
// An entry field naming a `.d.ts` names its stem, so the entry lands on the real module beside it.
|
|
20
19
|
function manifestStems(bytes, mainFields) {
|
|
21
20
|
let manifest
|
|
22
21
|
try {
|
|
@@ -26,34 +25,27 @@ function manifestStems(bytes, mainFields) {
|
|
|
26
25
|
} catch {
|
|
27
26
|
return bytes
|
|
28
27
|
}
|
|
29
|
-
if (
|
|
28
|
+
if (!isPlainObject(manifest)) return bytes
|
|
30
29
|
const typed = mainFields.filter((field) => typeof manifest[field] === 'string' && isTypeDeclaration(manifest[field]))
|
|
31
30
|
if (typed.length === 0) return bytes
|
|
32
31
|
for (const field of typed) manifest[field] = stripTypeDeclaration(manifest[field])
|
|
33
32
|
return Buffer.from(JSON.stringify(manifest))
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
// `
|
|
37
|
-
// is types-only, erased at runtime, so the resolver never lands on one: no `.d.ts` is a file, and a
|
|
38
|
-
// manifest's entry naming one names its stem (manifestStems).
|
|
35
|
+
// A `.d.ts` is types-only, erased at runtime, so the resolver never lands on one.
|
|
39
36
|
export function metroHost(host, mainFields = defaults.mainFields) {
|
|
40
37
|
return {
|
|
41
|
-
isFile: (path) =>
|
|
42
|
-
isDirectory: (path) =>
|
|
38
|
+
isFile: (path) => isSourceFile(path, host),
|
|
39
|
+
isDirectory: (path) => isDir(path, host),
|
|
43
40
|
realpath: (path) => host.realpath(path),
|
|
44
41
|
readFile: (path) => (basename(path) === 'package.json' ? manifestStems(host.readFile(path), mainFields) : host.readFile(path)),
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
//
|
|
45
|
+
// Metro builds an asset of several files into the module of the lowest path (getArrayLowestItem).
|
|
49
46
|
const lowestPath = (paths) => paths.reduce((lowest, path) => (path < lowest ? path : lowest))
|
|
50
47
|
|
|
51
|
-
//
|
|
52
|
-
// resolver's answer:
|
|
53
|
-
// { url } resolved to a file, by its real path (file: URL string)
|
|
54
|
-
// { empty } a browser/react-native field mapped it to `false` (empty module)
|
|
55
|
-
// { builtin } a Node builtin Metro failed to resolve, where `builtin` says it is one
|
|
56
|
-
// null unresolved
|
|
48
|
+
// `builtin`: whether a specifier Metro failed (null) is a Node builtin.
|
|
57
49
|
export function scanResolution(resolution, builtin) {
|
|
58
50
|
if (resolution === null) return builtin ? { builtin: true } : null
|
|
59
51
|
if (resolution.type === 'empty') return { empty: true }
|
|
@@ -61,40 +53,21 @@ export function scanResolution(resolution, builtin) {
|
|
|
61
53
|
return { url: pathToFileURL(file).toString() }
|
|
62
54
|
}
|
|
63
55
|
|
|
64
|
-
//
|
|
65
|
-
// modules resolve exactly the way that project's installed Metro does. `metro-resolver` is a leaf of
|
|
66
|
-
// the Metro toolchain (it takes a context of filesystem callbacks and does no I/O of its own), so
|
|
67
|
-
// whichever copy the project ships is loaded and given the context Metro's DependencyGraph builds,
|
|
68
|
-
// over the disk (@preventive/rn's `metroResolver`). The options are Metro's resolver config, React
|
|
69
|
-
// Native's defaults where left out; Metro only prefers native suffixes off web. Metro carries no Node
|
|
70
|
-
// builtins, so a builtin it fails to resolve (one no browser map remaps) is reported as one.
|
|
56
|
+
// `--metro-resolver`: through the project's own `metro-resolver`, given the context Metro's DependencyGraph builds.
|
|
71
57
|
export function createMetroResolver({ projectDir, platform, sourceExts, mainFields, conditionNames, conditionsByPlatform, assetExts, assetResolutions, host = diskHost } = {}) {
|
|
72
|
-
// It loads the project's metro-resolver, which reads the disk: never off it.
|
|
73
58
|
if (host !== diskHost) throw new Error('createMetroResolver: metro-resolver reads the disk, so it is not supported off disk')
|
|
74
59
|
let metroResolver
|
|
75
60
|
try {
|
|
76
61
|
metroResolver = createRequire(join(projectDir, 'noop.js'))('metro-resolver')
|
|
77
62
|
} catch (cause) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
|
|
80
|
-
'resolves through the project\'s own Metro; install it (it ships with react-native/metro) ' +
|
|
81
|
-
'or drop --metro-resolver to use the built-in resolver.',
|
|
82
|
-
{ cause }
|
|
83
|
-
)
|
|
63
|
+
throw new Error(`StasisMetroResolver: couldn't load 'metro-resolver' from ${projectDir}. --metro-resolver resolves through the `
|
|
64
|
+
+ 'project\'s own Metro; install it (it ships with react-native/metro) or drop --metro-resolver to use the built-in resolver.', { cause })
|
|
84
65
|
}
|
|
85
66
|
const resolve = createRnMetroResolver({
|
|
86
|
-
host: metroHost(host, mainFields),
|
|
87
|
-
|
|
88
|
-
assetExts,
|
|
89
|
-
assetResolutions,
|
|
90
|
-
mainFields,
|
|
91
|
-
conditionNames,
|
|
92
|
-
conditionsByPlatform,
|
|
93
|
-
preferNativePlatform: platform !== 'web',
|
|
94
|
-
metroResolver,
|
|
67
|
+
host: metroHost(host, mainFields), sourceExts, assetExts, assetResolutions, mainFields, conditionNames, conditionsByPlatform,
|
|
68
|
+
preferNativePlatform: platform !== 'web', metroResolver,
|
|
95
69
|
})
|
|
96
|
-
// Metro splits `exports` on whether the edge
|
|
97
|
-
// the parent's format-derived condition set, so `import` in it is that signal.
|
|
70
|
+
// Metro splits `exports` on whether the edge is an ESM import: `import` in scan.js's format-derived conditions.
|
|
98
71
|
return (parentFile, specifier, callConditions) => {
|
|
99
72
|
const isESMImport = callConditions instanceof Set && callConditions.has('import')
|
|
100
73
|
return scanResolution(resolve(parentFile, specifier, { platform, isESMImport }), isBuiltin(specifier))
|
package/src/metro-transformer.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
// Public-export adapter: backs `@exodus/stasis/metro-transformer`. The transformer
|
|
2
|
-
// lives in @exodus/stasis-plugins (which depends on @exodus/stasis-core for State; it
|
|
3
|
-
// drives load-mode getFile directly). withStasis() wires it as Metro's `transformerPath`;
|
|
4
|
-
// wire it yourself only alongside a hand-wired serializer. See the source for the load
|
|
5
|
-
// asymmetry that lets this run per-worker without cross-worker state sync.
|
|
6
1
|
export * from '@exodus/stasis-plugins/metro-transformer'
|
package/src/metro.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
// Public-export adapter: backs `@exodus/stasis/metro`. The plugin lives in
|
|
2
|
-
// @exodus/stasis-plugins (which depends on @exodus/stasis-core for State /
|
|
3
|
-
// resolvePluginState). Internal code uses `@exodus/stasis-plugins/metro` directly;
|
|
4
|
-
// this file exists only to back the package's `exports` map.
|
|
5
1
|
export * from '@exodus/stasis-plugins/metro'
|