@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.
- package/README.md +2 -1
- package/bin/stasis.js +99 -16
- package/package.json +22 -9
- package/src/audit-corrections.js +11 -42
- package/src/audit.js +241 -190
- 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 +82 -174
- package/src/cmd/bundle-options.js +113 -167
- package/src/cmd/bundle.js +942 -1294
- package/src/cmd/diff.js +1 -4
- package/src/cmd/github-bundle.js +21 -26
- package/src/cmd/output.js +15 -12
- package/src/cmd/sbom.js +3 -8
- package/src/cmd/tokens.js +16 -23
- package/src/define.js +36 -94
- package/src/diff.js +72 -128
- package/src/esbuild.js +0 -4
- package/src/flow.js +18 -13
- 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 +10 -384
- package/src/metro-resolver.js +58 -134
- package/src/metro-transformer.js +0 -5
- package/src/metro.js +0 -4
- package/src/mock.js +32 -80
- package/src/parse.js +4 -4
- package/src/prune.js +0 -3
- package/src/resolve-fields.js +137 -532
- package/src/resolve-node.js +27 -45
- package/src/resolve-typescript.js +166 -298
- package/src/rollup.js +0 -4
- package/src/run-installed.js +10 -0
- package/src/sbom.js +52 -128
- package/src/scan.js +142 -284
- package/src/sixel.js +310 -0
- package/src/table.js +63 -31
- package/src/validate-notes.d.ts +19 -0
- package/src/validate-notes.js +72 -0
- package/src/validate.d.ts +159 -0
- package/src/validate.js +596 -522
- package/src/vfs-bundle/entries.js +40 -57
- package/src/vfs-bundle/github.js +80 -122
- package/src/vfs-bundle/glob.js +4 -45
- package/src/vfs-bundle/lazy.js +27 -56
- package/src/vfs-bundle/prisma.js +235 -105
- 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 +78 -232
- package/src/installed-commits.js +0 -184
package/src/resolve-node.js
CHANGED
|
@@ -3,25 +3,22 @@ import { basename, dirname, isAbsolute, join, normalize, resolve } from 'node:pa
|
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
4
4
|
|
|
5
5
|
import { packageJSONStat, packageJSONText } from '@exodus/stasis-core/bundle-util'
|
|
6
|
-
import {
|
|
6
|
+
import { isPlainObject } from '@exodus/stasis-core/util'
|
|
7
|
+
import { hostMemo } from './vfs-bundle/lazy.js'
|
|
7
8
|
|
|
8
|
-
// Node's
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// ~/.node_modules) are not consulted: a virtual tree resolves hermetically.
|
|
9
|
+
// Node's `createRequire(parent).resolve(spec, { conditions })` over a `host`, mirroring cjs/loader.js and esm/resolve.js
|
|
10
|
+
// step for step, error codes included. Global folders (NODE_PATH, ~/.node_modules) aren't consulted: a tree is hermetic.
|
|
11
|
+
// A miss carries `target`, the missing file it would have resolved to, where it names one (Scan's missTargets).
|
|
12
12
|
|
|
13
13
|
const codedError = (code, message) => Object.assign(new Error(message), { code })
|
|
14
14
|
|
|
15
15
|
const REQUIRE_CONDITIONS = new Set(['require', 'node', 'node-addons', 'module-sync'])
|
|
16
16
|
|
|
17
|
-
//
|
|
17
|
+
// Node's invalidSegmentRegEx also matches an empty segment, which it only deprecates: no error here.
|
|
18
18
|
const deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/iu
|
|
19
19
|
const encodedSepRegEx = /%2F|%5C/iu
|
|
20
|
-
// Module._findPath's bare-package matcher: `name` or `@scope/name`, optional `/subpath`.
|
|
21
20
|
const EXPORTS_PATTERN = /^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/u
|
|
22
|
-
|
|
23
|
-
// requests that skip the node_modules lookup.
|
|
24
|
-
const RELATIVE_REQUEST = /^\.\.?(?:\/|$)/u
|
|
21
|
+
export const RELATIVE_REQUEST = /^\.\.?(?:\/|$)/u
|
|
25
22
|
const TRAILING_SLASH = /\/$|(?:^|\/)\.\.?$/u
|
|
26
23
|
const RELATIVE_LOOKUP = /^\.(?:$|[./])/u
|
|
27
24
|
|
|
@@ -56,7 +53,6 @@ function isConditionalExportsMainSugar(exports, pkgPath) {
|
|
|
56
53
|
return sugar
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
// esm/resolve.js's best `*` pattern key of `map` for `subpath`: -> [key, wildcard] or null.
|
|
60
56
|
function bestPatternMatch(map, subpath) {
|
|
61
57
|
let bestMatch = ''
|
|
62
58
|
let bestMatchSubpath
|
|
@@ -72,7 +68,6 @@ function bestPatternMatch(map, subpath) {
|
|
|
72
68
|
return bestMatch ? [bestMatch, bestMatchSubpath] : null
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
// esm/resolve.js's parsePackageName: -> { packageName, packageSubpath, isScoped }.
|
|
76
71
|
function parsePackageName(specifier, base) {
|
|
77
72
|
let separatorIndex = specifier.indexOf('/')
|
|
78
73
|
const isScoped = specifier[0] === '@'
|
|
@@ -88,13 +83,7 @@ function parsePackageName(specifier, base) {
|
|
|
88
83
|
return { packageName, packageSubpath: `.${separatorIndex === -1 ? '' : specifier.slice(separatorIndex)}`, isScoped }
|
|
89
84
|
}
|
|
90
85
|
|
|
91
|
-
// `host.touches`, where it has one, counts the reads it makes of what a tree does not hold yet
|
|
92
|
-
// (vfs-bundle/tree.js's vfsHost of a lazy tree): what is read with none is cached alone, or with
|
|
93
|
-
// `host.retouch`, what is read with some too (untouchedMemo's `retouch`).
|
|
94
86
|
export function createNodeResolver(host) {
|
|
95
|
-
const touches = host.touches ?? (() => 0)
|
|
96
|
-
// package.json reads, memoized per path; a malformed manifest, or one there that can't be read,
|
|
97
|
-
// throws ERR_INVALID_PACKAGE_CONFIG on every access.
|
|
98
87
|
const parsePackage = (pjsonPath) => {
|
|
99
88
|
let stat
|
|
100
89
|
try {
|
|
@@ -109,20 +98,18 @@ export function createNodeResolver(host) {
|
|
|
109
98
|
} catch (cause) {
|
|
110
99
|
return codedError('ERR_INVALID_PACKAGE_CONFIG', `Invalid package config ${pjsonPath}: ${cause.message}`)
|
|
111
100
|
}
|
|
112
|
-
if (
|
|
101
|
+
if (!isPlainObject(data)) return codedError('ERR_INVALID_PACKAGE_CONFIG', `Invalid package config ${pjsonPath}.`)
|
|
113
102
|
const string = (value) => (typeof value === 'string' ? value : undefined)
|
|
114
|
-
// Node keeps `exports` and `imports` only as a string, an array or an object.
|
|
115
103
|
const map = (value) => (typeof value === 'string' || (typeof value === 'object' && value !== null) ? value : undefined)
|
|
116
104
|
return { exists: true, path: pjsonPath, name: string(data.name), main: string(data.main), exports: map(data.exports), imports: map(data.imports) }
|
|
117
105
|
}
|
|
118
|
-
const packages =
|
|
106
|
+
const packages = hostMemo(host)
|
|
119
107
|
const readPackage = (pjsonPath) => {
|
|
120
108
|
const pkg = packages(pjsonPath, () => parsePackage(pjsonPath))
|
|
121
109
|
if (pkg instanceof Error) throw pkg
|
|
122
110
|
return pkg
|
|
123
111
|
}
|
|
124
112
|
|
|
125
|
-
// Node's readPackageScope: the nearest package.json, never crossing out of a node_modules dir.
|
|
126
113
|
const readPackageScope = (checkPath) => {
|
|
127
114
|
for (let dir = dirname(checkPath); basename(dir) !== 'node_modules'; dir = dirname(dir)) {
|
|
128
115
|
const pkg = readPackage(join(dir, 'package.json'))
|
|
@@ -154,12 +141,10 @@ export function createNodeResolver(host) {
|
|
|
154
141
|
if (actual) return actual
|
|
155
142
|
throw Object.assign(
|
|
156
143
|
codedError('MODULE_NOT_FOUND', `Cannot find module '${filename}'. Please verify that the package.json has a valid "main" entry`),
|
|
157
|
-
{ path: join(requestPath, 'package.json'), requestPath: originalPath },
|
|
144
|
+
{ path: join(requestPath, 'package.json'), requestPath: originalPath, target: filename },
|
|
158
145
|
)
|
|
159
146
|
}
|
|
160
147
|
|
|
161
|
-
// --- esm/resolve.js: exports / imports ---
|
|
162
|
-
|
|
163
148
|
const fileExists = (url) => stat(fileURLToPath(url)) === 0
|
|
164
149
|
|
|
165
150
|
const throwInvalidPackageTarget = (subpath, target, packageJSONUrl, internal) => {
|
|
@@ -174,7 +159,6 @@ export function createNodeResolver(host) {
|
|
|
174
159
|
const resolvePackageTargetString = (target, subpath, match, packageJSONUrl, pattern, internal, conditions) => {
|
|
175
160
|
if (subpath !== '' && !pattern && !target.endsWith('/')) throwInvalidPackageTarget(match, target, packageJSONUrl, internal)
|
|
176
161
|
if (!target.startsWith('./')) {
|
|
177
|
-
// A bare `imports` target (`"#x": "dep"`) is a package specifier, resolved the ESM way.
|
|
178
162
|
if (internal && !target.startsWith('../') && !target.startsWith('/') && !URL.canParse(target)) {
|
|
179
163
|
return packageResolve(pattern ? target.replaceAll('*', () => subpath) : target + subpath, packageJSONUrl, conditions)
|
|
180
164
|
}
|
|
@@ -257,7 +241,7 @@ export function createNodeResolver(host) {
|
|
|
257
241
|
}
|
|
258
242
|
|
|
259
243
|
const packageImportsResolve = (name, base, conditions) => {
|
|
260
|
-
//
|
|
244
|
+
// `#/x` is merely "not defined" in Node 24, so it is not screened here.
|
|
261
245
|
if (name === '#' || name.endsWith('/')) {
|
|
262
246
|
throw codedError('ERR_INVALID_MODULE_SPECIFIER', `Invalid module "${name}" is not a valid internal imports specifier name imported from ${fileURLToPath(base)}`)
|
|
263
247
|
}
|
|
@@ -288,7 +272,8 @@ export function createNodeResolver(host) {
|
|
|
288
272
|
for (const index of ['./index.js', './index.json', './index.node']) {
|
|
289
273
|
if (fileExists(guess = new URL(index, packageJSONUrl))) return guess
|
|
290
274
|
}
|
|
291
|
-
|
|
275
|
+
const target = packageConfig.main === undefined ? {} : { target: fileURLToPath(new URL(`./${packageConfig.main}`, packageJSONUrl)) }
|
|
276
|
+
throw Object.assign(codedError('ERR_MODULE_NOT_FOUND', `Cannot find package '${fileURLToPath(new URL('.', packageJSONUrl))}' imported from ${fileURLToPath(base)}`), target)
|
|
292
277
|
}
|
|
293
278
|
|
|
294
279
|
// ESM-style bare resolution, reached only through a bare `imports` target (`"#x": "dep"`).
|
|
@@ -317,18 +302,15 @@ export function createNodeResolver(host) {
|
|
|
317
302
|
throw codedError('ERR_MODULE_NOT_FOUND', `Cannot find package '${packageName}' imported from ${fileURLToPath(base)}`)
|
|
318
303
|
}
|
|
319
304
|
|
|
320
|
-
// --- cjs/loader.js glue ---
|
|
321
|
-
|
|
322
305
|
const createEsmNotFoundErr = (request, path) => Object.assign(codedError('MODULE_NOT_FOUND', `Cannot find module '${request}'`), path ? { path } : {})
|
|
323
306
|
|
|
324
|
-
//
|
|
325
|
-
// file that exists, and an ESM "not found" becomes MODULE_NOT_FOUND naming `request`.
|
|
307
|
+
// finalizeEsmResolution: an ESM "not found" becomes MODULE_NOT_FOUND naming `request`.
|
|
326
308
|
const viaEsm = (resolveUrl, request, errPath, parentPath, pkgDir) => {
|
|
327
309
|
let resolved
|
|
328
310
|
try {
|
|
329
311
|
resolved = resolveUrl()
|
|
330
312
|
} catch (e) {
|
|
331
|
-
if (e.code === 'ERR_MODULE_NOT_FOUND') throw createEsmNotFoundErr(request, errPath)
|
|
313
|
+
if (e.code === 'ERR_MODULE_NOT_FOUND') throw Object.assign(createEsmNotFoundErr(request, errPath), e.target === undefined ? {} : { target: e.target })
|
|
332
314
|
throw e
|
|
333
315
|
}
|
|
334
316
|
if (resolved.protocol === 'node:') throw codedError('ERR_INVALID_URL_SCHEME', 'The URL must be of scheme file')
|
|
@@ -338,10 +320,9 @@ export function createNodeResolver(host) {
|
|
|
338
320
|
const filename = fileURLToPath(resolved)
|
|
339
321
|
const actual = tryFile(filename)
|
|
340
322
|
if (actual) return actual
|
|
341
|
-
throw createEsmNotFoundErr(filename, resolve(pkgDir, 'package.json'))
|
|
323
|
+
throw Object.assign(createEsmNotFoundErr(filename, resolve(pkgDir, 'package.json')), { target: filename })
|
|
342
324
|
}
|
|
343
325
|
|
|
344
|
-
// Self-reference: a request naming the enclosing package, through its `exports`.
|
|
345
326
|
const trySelf = (parentPath, request, conditions) => {
|
|
346
327
|
const pkg = readPackageScope(parentPath)
|
|
347
328
|
if (!pkg || pkg.exports == null || pkg.name === undefined) return false
|
|
@@ -352,7 +333,6 @@ export function createNodeResolver(host) {
|
|
|
352
333
|
return viaEsm(() => packageExportsResolve(pathToFileURL(pkg.path), expansion, pkg, conditions), request, pkg.path, parentPath, dirname(pkg.path))
|
|
353
334
|
}
|
|
354
335
|
|
|
355
|
-
// A bare request into `nmPath` whose package has `exports`.
|
|
356
336
|
const resolveExports = (nmPath, request, conditions) => {
|
|
357
337
|
const m = EXPORTS_PATTERN.exec(request)
|
|
358
338
|
if (!m) return false
|
|
@@ -363,7 +343,6 @@ export function createNodeResolver(host) {
|
|
|
363
343
|
return viaEsm(() => packageExportsResolve(pathToFileURL(pkg.path), `.${expansion}`, pkg, conditions), request, pkg.path, null, pkgPath)
|
|
364
344
|
}
|
|
365
345
|
|
|
366
|
-
// Module._findPath over `paths`.
|
|
367
346
|
const findPath = (request, paths, conditions) => {
|
|
368
347
|
const absoluteRequest = isAbsolute(request)
|
|
369
348
|
if (absoluteRequest) paths = ['']
|
|
@@ -388,9 +367,13 @@ export function createNodeResolver(host) {
|
|
|
388
367
|
}
|
|
389
368
|
|
|
390
369
|
const notFound = (request, parentFile) => Object.assign(codedError('MODULE_NOT_FOUND', `Cannot find module '${request}'\nRequire stack:\n- ${parentFile}`), { requireStack: [parentFile] })
|
|
370
|
+
// A bare request missing a package without `exports`: `target` is the file it names in the nearest package so named.
|
|
371
|
+
const packageMiss = (request, paths) => {
|
|
372
|
+
const name = !RELATIVE_LOOKUP.test(request) && !isAbsolute(request) && EXPORTS_PATTERN.exec(request)?.[1]
|
|
373
|
+
const at = name ? paths.find((curPath) => stat(resolve(curPath, name)) === 1) : undefined
|
|
374
|
+
return at === undefined ? {} : { target: resolve(at, request) }
|
|
375
|
+
}
|
|
391
376
|
|
|
392
|
-
// Module._resolveFilename: -> the file's real path, or a builtin's id. Without `builtins`, a
|
|
393
|
-
// request naming a builtin is looked up like any bare name (see resolve).
|
|
394
377
|
const resolveFilename = (parentFile, request, conditions, builtins) => {
|
|
395
378
|
if (builtins && isBuiltin(request)) return request
|
|
396
379
|
if (request === '') throw notFound(request, parentFile)
|
|
@@ -401,16 +384,15 @@ export function createNodeResolver(host) {
|
|
|
401
384
|
const paths = RELATIVE_LOOKUP.test(request) ? [dirname(parentFile)] : Module._nodeModulePaths(dirname(parentFile))
|
|
402
385
|
const hit = trySelf(parentFile, request, conditions) || findPath(request, paths, conditions)
|
|
403
386
|
if (hit) return hit
|
|
404
|
-
throw notFound(request, parentFile)
|
|
387
|
+
throw Object.assign(notFound(request, parentFile), packageMiss(request, paths))
|
|
405
388
|
}
|
|
406
389
|
|
|
407
|
-
// Node's Module._pathCache: the tree is immutable for the build.
|
|
408
|
-
const memo =
|
|
390
|
+
// As Node's Module._pathCache: the tree is immutable for the build.
|
|
391
|
+
const memo = hostMemo(host)
|
|
409
392
|
|
|
410
393
|
return {
|
|
411
|
-
//
|
|
412
|
-
// `
|
|
413
|
-
// is the installed package of that name, through its `exports` like any other.
|
|
394
|
+
// A builtin returns its id. `builtins: false` resolves for a target with no Node builtins: a bare builtin name
|
|
395
|
+
// (`buffer`) is the installed package of that name, through its `exports` like any other.
|
|
414
396
|
resolve(parentFile, request, conditions = REQUIRE_CONDITIONS, { builtins = true } = {}) {
|
|
415
397
|
parentFile = resolve(parentFile)
|
|
416
398
|
if (!(conditions instanceof Set)) conditions = new Set(conditions)
|