@exodus/stasis 1.0.0-beta.9 → 1.0.0-rc.1

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 +6 -2
  2. package/bin/stasis.js +222 -334
  3. package/package.json +38 -14
  4. package/src/audit-corrections.js +11 -42
  5. package/src/audit.js +256 -212
  6. package/src/babel.js +119 -82
  7. package/src/bundle-from-lockfile.js +9 -21
  8. package/src/bundle-reader.js +24 -8
  9. package/src/bundle.js +0 -3
  10. package/src/cmd/build.js +211 -117
  11. package/src/cmd/bundle-options.js +347 -0
  12. package/src/cmd/bundle.js +1664 -1001
  13. package/src/cmd/diff.js +1 -4
  14. package/src/cmd/github-bundle.js +48 -21
  15. package/src/cmd/output.js +25 -12
  16. package/src/cmd/sbom.js +6 -9
  17. package/src/cmd/tokens.js +60 -0
  18. package/src/define.js +218 -0
  19. package/src/diff.js +73 -129
  20. package/src/esbuild.js +0 -4
  21. package/src/flow.js +27 -0
  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 +43 -120
  27. package/src/loaders/cargo.js +301 -808
  28. package/src/loaders/foundry.js +112 -290
  29. package/src/loaders/paths.js +15 -26
  30. package/src/loaders/php.js +211 -492
  31. package/src/loaders/rust.js +518 -1461
  32. package/src/loaders/solidity-ownership.js +51 -142
  33. package/src/loaders/solidity.js +42 -188
  34. package/src/loaders/toml.js +7 -17
  35. package/src/lockfile.js +0 -3
  36. package/src/metro-assets.js +41 -0
  37. package/src/metro-resolver.js +58 -133
  38. package/src/metro-transformer.js +0 -6
  39. package/src/metro.js +0 -4
  40. package/src/mock.js +32 -80
  41. package/src/parse.js +8 -7
  42. package/src/prune.js +0 -3
  43. package/src/resolve-fields.js +152 -249
  44. package/src/resolve-node.js +29 -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 +70 -97
  49. package/src/scan.js +240 -282
  50. package/src/sixel.js +310 -0
  51. package/src/table.js +95 -0
  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 +1315 -0
  56. package/src/vfs-bundle/entries.js +50 -46
  57. package/src/vfs-bundle/github.js +114 -94
  58. package/src/vfs-bundle/glob.js +379 -0
  59. package/src/vfs-bundle/lazy.js +99 -0
  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 +418 -277
  63. package/src/vfs-bundle/yarnclean.js +79 -0
  64. package/src/vfs-bundle.js +24 -55
  65. package/src/webpack.js +0 -4
  66. package/src/why.js +79 -231
  67. package/src/installed-commits.js +0 -182
@@ -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 CommonJS resolution (`createRequire(parent).resolve(spec, { conditions })`) over a
8
- // `host` (@exodus/stasis-core/host), mirroring lib/internal/modules/cjs/loader.js and
9
- // esm/resolve.js step for step, errors with Node's `code`s included. Global folders (NODE_PATH,
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
- // esm/resolve.js's deprecatedInvalidSegmentRegEx (an empty segment is only deprecated there, so no error here).
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
- // cjs/loader.js's character tests: relative requests, directory requests (no file probes), and
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 (data === null || typeof data !== 'object' || Array.isArray(data)) return codedError('ERR_INVALID_PACKAGE_CONFIG', `Invalid package config ${pjsonPath}.`)
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 pkgCache = new Map()
106
+ const packages = hostMemo(host)
114
107
  const readPackage = (pjsonPath) => {
115
- let pkg = pkgCache.get(pjsonPath)
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
- // (`#/x` is merely "not defined" in Node 24, so it is not screened here.)
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
- throw codedError('ERR_MODULE_NOT_FOUND', `Cannot find package '${fileURLToPath(new URL('.', packageJSONUrl))}' imported from ${fileURLToPath(base)}`)
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
- // An esm/resolve.js answer under CJS rules (finalizeEsmResolution): it must be a file URL to a
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,9 +367,13 @@ 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
- // Module._resolveFilename: -> the file's real path, or a builtin's id. Without `builtins`, a
389
- // request naming a builtin is looked up like any bare name (see resolve).
390
377
  const resolveFilename = (parentFile, request, conditions, builtins) => {
391
378
  if (builtins && isBuiltin(request)) return request
392
379
  if (request === '') throw notFound(request, parentFile)
@@ -397,23 +384,20 @@ export function createNodeResolver(host) {
397
384
  const paths = RELATIVE_LOOKUP.test(request) ? [dirname(parentFile)] : Module._nodeModulePaths(dirname(parentFile))
398
385
  const hit = trySelf(parentFile, request, conditions) || findPath(request, paths, conditions)
399
386
  if (hit) return hit
400
- throw notFound(request, parentFile)
387
+ throw Object.assign(notFound(request, parentFile), packageMiss(request, paths))
401
388
  }
402
389
 
403
- // Node's Module._pathCache: the tree is immutable for the build.
404
- const memo = new Map()
390
+ // As Node's Module._pathCache: the tree is immutable for the build.
391
+ const memo = hostMemo(host)
405
392
 
406
393
  return {
407
- // `conditions`: `require.resolve`'s own by default. A builtin returns its id, as it does.
408
- // `builtins: false` resolves for a target with no Node builtins: a bare builtin name (`buffer`)
409
- // 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.
410
396
  resolve(parentFile, request, conditions = REQUIRE_CONDITIONS, { builtins = true } = {}) {
411
397
  parentFile = resolve(parentFile)
412
398
  if (!(conditions instanceof Set)) conditions = new Set(conditions)
413
399
  const key = `${dirname(parentFile)}\0${request}\0${[...conditions].join(',')}${builtins ? '' : '\0nobuiltins'}`
414
- let hit = memo.get(key)
415
- if (hit === undefined) memo.set(key, hit = resolveFilename(parentFile, request, conditions, builtins))
416
- return hit
400
+ return memo(key, () => resolveFilename(parentFile, request, conditions, builtins))
417
401
  },
418
402
  }
419
403
  }