@exodus/stasis 1.0.0-beta.8 → 1.0.0-rc.0
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 +7 -2
- package/bin/stasis.js +263 -446
- package/package.json +38 -13
- package/src/audit-corrections.js +11 -42
- package/src/audit.js +256 -212
- package/src/babel.js +119 -82
- package/src/bundle-from-lockfile.js +9 -21
- package/src/bundle-reader.js +24 -8
- package/src/bundle.js +0 -3
- package/src/cmd/build.js +211 -117
- package/src/cmd/bundle-options.js +347 -0
- package/src/cmd/bundle.js +1718 -908
- package/src/cmd/diff.js +1 -4
- package/src/cmd/github-bundle.js +48 -21
- package/src/cmd/output.js +24 -12
- package/src/cmd/sbom.js +6 -9
- package/src/cmd/tokens.js +60 -0
- package/src/define.js +218 -0
- package/src/diff.js +73 -129
- package/src/esbuild.js +0 -4
- package/src/flow.js +27 -0
- package/src/installed.js +265 -0
- package/src/json-stream.js +4 -9
- package/src/loader-mock.js +3 -8
- package/src/loader.js +1 -5
- package/src/loaders/bash.js +43 -120
- package/src/loaders/cargo.js +301 -808
- package/src/loaders/foundry.js +112 -290
- package/src/loaders/paths.js +15 -26
- package/src/loaders/php.js +221 -475
- package/src/loaders/rust.js +518 -1461
- package/src/loaders/solidity-ownership.js +51 -142
- package/src/loaders/solidity.js +42 -188
- package/src/loaders/toml.js +7 -17
- package/src/lockfile.js +0 -3
- package/src/metro-assets.js +41 -0
- package/src/metro-resolver.js +58 -133
- package/src/metro-transformer.js +0 -6
- package/src/metro.js +0 -4
- package/src/mock.js +32 -80
- package/src/parse.js +8 -7
- package/src/prune.js +0 -3
- package/src/resolve-fields.js +170 -235
- package/src/resolve-node.js +33 -46
- package/src/resolve-typescript.js +166 -298
- package/src/rollup.js +0 -4
- package/src/run-installed.js +10 -0
- package/src/sbom.js +70 -97
- package/src/scan.js +241 -278
- package/src/sixel.js +310 -0
- package/src/table.js +95 -0
- package/src/validate-notes.d.ts +19 -0
- package/src/validate-notes.js +72 -0
- package/src/validate.d.ts +159 -0
- package/src/validate.js +1315 -0
- package/src/vfs-bundle/entries.js +54 -46
- package/src/vfs-bundle/github.js +115 -92
- package/src/vfs-bundle/glob.js +379 -0
- package/src/vfs-bundle/lazy.js +99 -0
- package/src/vfs-bundle/prisma.js +235 -105
- package/src/vfs-bundle/soldeer.js +28 -49
- package/src/vfs-bundle/tree.js +434 -259
- package/src/vfs-bundle/yarnclean.js +79 -0
- package/src/vfs-bundle.js +25 -51
- package/src/webpack.js +0 -4
- package/src/why.js +79 -231
package/src/resolve-node.js
CHANGED
|
@@ -3,24 +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 { isPlainObject } from '@exodus/stasis-core/util'
|
|
7
|
+
import { hostMemo } from './vfs-bundle/lazy.js'
|
|
6
8
|
|
|
7
|
-
// Node's
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// ~/.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).
|
|
11
12
|
|
|
12
13
|
const codedError = (code, message) => Object.assign(new Error(message), { code })
|
|
13
14
|
|
|
14
15
|
const REQUIRE_CONDITIONS = new Set(['require', 'node', 'node-addons', 'module-sync'])
|
|
15
16
|
|
|
16
|
-
//
|
|
17
|
+
// Node's invalidSegmentRegEx also matches an empty segment, which it only deprecates: no error here.
|
|
17
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
|
|
18
19
|
const encodedSepRegEx = /%2F|%5C/iu
|
|
19
|
-
// Module._findPath's bare-package matcher: `name` or `@scope/name`, optional `/subpath`.
|
|
20
20
|
const EXPORTS_PATTERN = /^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/u
|
|
21
|
-
|
|
22
|
-
// requests that skip the node_modules lookup.
|
|
23
|
-
const RELATIVE_REQUEST = /^\.\.?(?:\/|$)/u
|
|
21
|
+
export const RELATIVE_REQUEST = /^\.\.?(?:\/|$)/u
|
|
24
22
|
const TRAILING_SLASH = /\/$|(?:^|\/)\.\.?$/u
|
|
25
23
|
const RELATIVE_LOOKUP = /^\.(?:$|[./])/u
|
|
26
24
|
|
|
@@ -55,7 +53,6 @@ function isConditionalExportsMainSugar(exports, pkgPath) {
|
|
|
55
53
|
return sugar
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
// esm/resolve.js's best `*` pattern key of `map` for `subpath`: -> [key, wildcard] or null.
|
|
59
56
|
function bestPatternMatch(map, subpath) {
|
|
60
57
|
let bestMatch = ''
|
|
61
58
|
let bestMatchSubpath
|
|
@@ -71,7 +68,6 @@ function bestPatternMatch(map, subpath) {
|
|
|
71
68
|
return bestMatch ? [bestMatch, bestMatchSubpath] : null
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
// esm/resolve.js's parsePackageName: -> { packageName, packageSubpath, isScoped }.
|
|
75
71
|
function parsePackageName(specifier, base) {
|
|
76
72
|
let separatorIndex = specifier.indexOf('/')
|
|
77
73
|
const isScoped = specifier[0] === '@'
|
|
@@ -88,8 +84,6 @@ function parsePackageName(specifier, base) {
|
|
|
88
84
|
}
|
|
89
85
|
|
|
90
86
|
export function createNodeResolver(host) {
|
|
91
|
-
// package.json reads, memoized per path; a malformed manifest, or one there that can't be read,
|
|
92
|
-
// throws ERR_INVALID_PACKAGE_CONFIG on every access.
|
|
93
87
|
const parsePackage = (pjsonPath) => {
|
|
94
88
|
let stat
|
|
95
89
|
try {
|
|
@@ -104,21 +98,18 @@ export function createNodeResolver(host) {
|
|
|
104
98
|
} catch (cause) {
|
|
105
99
|
return codedError('ERR_INVALID_PACKAGE_CONFIG', `Invalid package config ${pjsonPath}: ${cause.message}`)
|
|
106
100
|
}
|
|
107
|
-
if (
|
|
101
|
+
if (!isPlainObject(data)) return codedError('ERR_INVALID_PACKAGE_CONFIG', `Invalid package config ${pjsonPath}.`)
|
|
108
102
|
const string = (value) => (typeof value === 'string' ? value : undefined)
|
|
109
|
-
// Node keeps `exports` and `imports` only as a string, an array or an object.
|
|
110
103
|
const map = (value) => (typeof value === 'string' || (typeof value === 'object' && value !== null) ? value : undefined)
|
|
111
104
|
return { exists: true, path: pjsonPath, name: string(data.name), main: string(data.main), exports: map(data.exports), imports: map(data.imports) }
|
|
112
105
|
}
|
|
113
|
-
const
|
|
106
|
+
const packages = hostMemo(host)
|
|
114
107
|
const readPackage = (pjsonPath) => {
|
|
115
|
-
|
|
116
|
-
if (pkg === undefined) pkgCache.set(pjsonPath, pkg = parsePackage(pjsonPath))
|
|
108
|
+
const pkg = packages(pjsonPath, () => parsePackage(pjsonPath))
|
|
117
109
|
if (pkg instanceof Error) throw pkg
|
|
118
110
|
return pkg
|
|
119
111
|
}
|
|
120
112
|
|
|
121
|
-
// Node's readPackageScope: the nearest package.json, never crossing out of a node_modules dir.
|
|
122
113
|
const readPackageScope = (checkPath) => {
|
|
123
114
|
for (let dir = dirname(checkPath); basename(dir) !== 'node_modules'; dir = dirname(dir)) {
|
|
124
115
|
const pkg = readPackage(join(dir, 'package.json'))
|
|
@@ -150,12 +141,10 @@ export function createNodeResolver(host) {
|
|
|
150
141
|
if (actual) return actual
|
|
151
142
|
throw Object.assign(
|
|
152
143
|
codedError('MODULE_NOT_FOUND', `Cannot find module '${filename}'. Please verify that the package.json has a valid "main" entry`),
|
|
153
|
-
{ path: join(requestPath, 'package.json'), requestPath: originalPath },
|
|
144
|
+
{ path: join(requestPath, 'package.json'), requestPath: originalPath, target: filename },
|
|
154
145
|
)
|
|
155
146
|
}
|
|
156
147
|
|
|
157
|
-
// --- esm/resolve.js: exports / imports ---
|
|
158
|
-
|
|
159
148
|
const fileExists = (url) => stat(fileURLToPath(url)) === 0
|
|
160
149
|
|
|
161
150
|
const throwInvalidPackageTarget = (subpath, target, packageJSONUrl, internal) => {
|
|
@@ -170,7 +159,6 @@ export function createNodeResolver(host) {
|
|
|
170
159
|
const resolvePackageTargetString = (target, subpath, match, packageJSONUrl, pattern, internal, conditions) => {
|
|
171
160
|
if (subpath !== '' && !pattern && !target.endsWith('/')) throwInvalidPackageTarget(match, target, packageJSONUrl, internal)
|
|
172
161
|
if (!target.startsWith('./')) {
|
|
173
|
-
// A bare `imports` target (`"#x": "dep"`) is a package specifier, resolved the ESM way.
|
|
174
162
|
if (internal && !target.startsWith('../') && !target.startsWith('/') && !URL.canParse(target)) {
|
|
175
163
|
return packageResolve(pattern ? target.replaceAll('*', () => subpath) : target + subpath, packageJSONUrl, conditions)
|
|
176
164
|
}
|
|
@@ -253,7 +241,7 @@ export function createNodeResolver(host) {
|
|
|
253
241
|
}
|
|
254
242
|
|
|
255
243
|
const packageImportsResolve = (name, base, conditions) => {
|
|
256
|
-
//
|
|
244
|
+
// `#/x` is merely "not defined" in Node 24, so it is not screened here.
|
|
257
245
|
if (name === '#' || name.endsWith('/')) {
|
|
258
246
|
throw codedError('ERR_INVALID_MODULE_SPECIFIER', `Invalid module "${name}" is not a valid internal imports specifier name imported from ${fileURLToPath(base)}`)
|
|
259
247
|
}
|
|
@@ -284,7 +272,8 @@ export function createNodeResolver(host) {
|
|
|
284
272
|
for (const index of ['./index.js', './index.json', './index.node']) {
|
|
285
273
|
if (fileExists(guess = new URL(index, packageJSONUrl))) return guess
|
|
286
274
|
}
|
|
287
|
-
|
|
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)
|
|
288
277
|
}
|
|
289
278
|
|
|
290
279
|
// ESM-style bare resolution, reached only through a bare `imports` target (`"#x": "dep"`).
|
|
@@ -313,18 +302,15 @@ export function createNodeResolver(host) {
|
|
|
313
302
|
throw codedError('ERR_MODULE_NOT_FOUND', `Cannot find package '${packageName}' imported from ${fileURLToPath(base)}`)
|
|
314
303
|
}
|
|
315
304
|
|
|
316
|
-
// --- cjs/loader.js glue ---
|
|
317
|
-
|
|
318
305
|
const createEsmNotFoundErr = (request, path) => Object.assign(codedError('MODULE_NOT_FOUND', `Cannot find module '${request}'`), path ? { path } : {})
|
|
319
306
|
|
|
320
|
-
//
|
|
321
|
-
// 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`.
|
|
322
308
|
const viaEsm = (resolveUrl, request, errPath, parentPath, pkgDir) => {
|
|
323
309
|
let resolved
|
|
324
310
|
try {
|
|
325
311
|
resolved = resolveUrl()
|
|
326
312
|
} catch (e) {
|
|
327
|
-
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 })
|
|
328
314
|
throw e
|
|
329
315
|
}
|
|
330
316
|
if (resolved.protocol === 'node:') throw codedError('ERR_INVALID_URL_SCHEME', 'The URL must be of scheme file')
|
|
@@ -334,10 +320,9 @@ export function createNodeResolver(host) {
|
|
|
334
320
|
const filename = fileURLToPath(resolved)
|
|
335
321
|
const actual = tryFile(filename)
|
|
336
322
|
if (actual) return actual
|
|
337
|
-
throw createEsmNotFoundErr(filename, resolve(pkgDir, 'package.json'))
|
|
323
|
+
throw Object.assign(createEsmNotFoundErr(filename, resolve(pkgDir, 'package.json')), { target: filename })
|
|
338
324
|
}
|
|
339
325
|
|
|
340
|
-
// Self-reference: a request naming the enclosing package, through its `exports`.
|
|
341
326
|
const trySelf = (parentPath, request, conditions) => {
|
|
342
327
|
const pkg = readPackageScope(parentPath)
|
|
343
328
|
if (!pkg || pkg.exports == null || pkg.name === undefined) return false
|
|
@@ -348,7 +333,6 @@ export function createNodeResolver(host) {
|
|
|
348
333
|
return viaEsm(() => packageExportsResolve(pathToFileURL(pkg.path), expansion, pkg, conditions), request, pkg.path, parentPath, dirname(pkg.path))
|
|
349
334
|
}
|
|
350
335
|
|
|
351
|
-
// A bare request into `nmPath` whose package has `exports`.
|
|
352
336
|
const resolveExports = (nmPath, request, conditions) => {
|
|
353
337
|
const m = EXPORTS_PATTERN.exec(request)
|
|
354
338
|
if (!m) return false
|
|
@@ -359,7 +343,6 @@ export function createNodeResolver(host) {
|
|
|
359
343
|
return viaEsm(() => packageExportsResolve(pathToFileURL(pkg.path), `.${expansion}`, pkg, conditions), request, pkg.path, null, pkgPath)
|
|
360
344
|
}
|
|
361
345
|
|
|
362
|
-
// Module._findPath over `paths`.
|
|
363
346
|
const findPath = (request, paths, conditions) => {
|
|
364
347
|
const absoluteRequest = isAbsolute(request)
|
|
365
348
|
if (absoluteRequest) paths = ['']
|
|
@@ -384,10 +367,15 @@ export function createNodeResolver(host) {
|
|
|
384
367
|
}
|
|
385
368
|
|
|
386
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
|
+
}
|
|
387
376
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (isBuiltin(request)) return request
|
|
377
|
+
const resolveFilename = (parentFile, request, conditions, builtins) => {
|
|
378
|
+
if (builtins && isBuiltin(request)) return request
|
|
391
379
|
if (request === '') throw notFound(request, parentFile)
|
|
392
380
|
if (request[0] === '#') {
|
|
393
381
|
const pkg = readPackageScope(parentFile)
|
|
@@ -396,21 +384,20 @@ export function createNodeResolver(host) {
|
|
|
396
384
|
const paths = RELATIVE_LOOKUP.test(request) ? [dirname(parentFile)] : Module._nodeModulePaths(dirname(parentFile))
|
|
397
385
|
const hit = trySelf(parentFile, request, conditions) || findPath(request, paths, conditions)
|
|
398
386
|
if (hit) return hit
|
|
399
|
-
throw notFound(request, parentFile)
|
|
387
|
+
throw Object.assign(notFound(request, parentFile), packageMiss(request, paths))
|
|
400
388
|
}
|
|
401
389
|
|
|
402
|
-
// Node's Module._pathCache: the tree is immutable for the build.
|
|
403
|
-
const memo =
|
|
390
|
+
// As Node's Module._pathCache: the tree is immutable for the build.
|
|
391
|
+
const memo = hostMemo(host)
|
|
404
392
|
|
|
405
393
|
return {
|
|
406
|
-
//
|
|
407
|
-
|
|
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.
|
|
396
|
+
resolve(parentFile, request, conditions = REQUIRE_CONDITIONS, { builtins = true } = {}) {
|
|
408
397
|
parentFile = resolve(parentFile)
|
|
409
398
|
if (!(conditions instanceof Set)) conditions = new Set(conditions)
|
|
410
|
-
const key = `${dirname(parentFile)}\0${request}\0${[...conditions].join(',')}`
|
|
411
|
-
|
|
412
|
-
if (hit === undefined) memo.set(key, hit = resolveFilename(parentFile, request, conditions))
|
|
413
|
-
return hit
|
|
399
|
+
const key = `${dirname(parentFile)}\0${request}\0${[...conditions].join(',')}${builtins ? '' : '\0nobuiltins'}`
|
|
400
|
+
return memo(key, () => resolveFilename(parentFile, request, conditions, builtins))
|
|
414
401
|
},
|
|
415
402
|
}
|
|
416
403
|
}
|