@exodus/stasis 1.0.0-beta.9 → 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.
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 +24 -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
@@ -0,0 +1,79 @@
1
+ import { posix } from 'node:path'
2
+
3
+ import { loadMinimatch } from './glob.js'
4
+
5
+ // Yarn 1.22.22's .yarnclean (autoclean's sortFilter and matchesFilter), on minimatch, for any package manager's tree:
6
+ // each path matched from the node_modules holding its package, as Yarn hoists it (.pnpm/x@1/node_modules/x/a as x/a).
7
+
8
+ export const YARNCLEAN = '.yarnclean'
9
+
10
+ const patternLines = (lines) => lines.filter((line) => !(line === '!' || line[0] === '#' || /^\s*$/u.test(line)))
11
+
12
+ // `regex` as micromatch's makeRe makes it for Yarn (trimmed, dot, nocase), `plain` as its isMatch does by default.
13
+ const NONE = /(?!)/u
14
+ function filterOf(line, { makeRe }) {
15
+ const negation = line[0] === '!'
16
+ const pattern = (negation ? line.slice(1) : line).replace(/\/$/u, '')
17
+ return { negation, regex: makeRe(pattern.trim(), { dot: true, nocase: true }) || NONE, plain: makeRe(pattern) || NONE }
18
+ }
19
+
20
+ const matches = ({ regex, plain }, loc) => regex.test(loc) || regex.test(`/${loc}`) || regex.test(posix.basename(loc)) || plain.test(loc)
21
+
22
+ // Null for a node_modules itself or a dot-named entry of one: the package manager's own.
23
+ function packagePath(dir, path) {
24
+ const segments = path.slice(dir.length + 1).split('/')
25
+ const tail = segments.slice(segments.lastIndexOf('node_modules') + 1)
26
+ return tail.length === 0 || tail[0].startsWith('.') ? null : tail.join('/')
27
+ }
28
+
29
+ // Its `keeps`: whether a `!` pattern keeps paths, so that what is cleaned of one package turns on what the others hold.
30
+ export function yarnclean(host, cwd) {
31
+ const lines = []
32
+ for (let dir = cwd; ; dir = posix.dirname(dir)) {
33
+ const file = posix.join(dir, YARNCLEAN)
34
+ if (host.stat(file)?.isFile()) lines.push(...patternLines(host.readFile(file).toString('utf8').split('\n')))
35
+ if (dir === '/') break
36
+ }
37
+ if (lines.length === 0) return null
38
+ const minimatch = loadMinimatch(`A ${YARNCLEAN}, which cleans the node_modules a lockfile lays out,`)
39
+ const filters = lines.map((line) => filterOf(line, minimatch))
40
+ const negations = filters.filter((filter) => filter.negation)
41
+ const positives = filters.filter((filter) => !filter.negation)
42
+ return Object.assign((vfs, dir) => {
43
+ if (!vfs.isDirectory(dir)) return
44
+ const entries = [...vfs.walk(dir)].slice(1).map(({ path, type }) => ({ path, type, loc: packagePath(dir, path) })).filter(({ loc }) => loc !== null)
45
+ // A path a `!` filter matches is kept, and so is every directory holding one.
46
+ const kept = new Set()
47
+ const holdingKept = new Set()
48
+ const keep = (path) => {
49
+ kept.add(path)
50
+ for (let up = posix.dirname(path); up !== dir; up = posix.dirname(up)) holdingKept.add(up)
51
+ }
52
+ for (const { path, loc } of negations.length === 0 ? [] : entries) if (negations.some((filter) => matches(filter, loc))) keep(path)
53
+ // So is a link to either: pnpm links each package into its store, where Yarn's hoisted layout holds the package.
54
+ const leadsToKept = (path) => {
55
+ try {
56
+ const real = vfs.realpath(path)
57
+ return kept.has(real) || holdingKept.has(real)
58
+ } catch {
59
+ return false // a link to nothing, or a loop
60
+ }
61
+ }
62
+ for (const { path, type } of kept.size === 0 ? [] : entries) if (type === 'symlink' && leadsToKept(path)) keep(path)
63
+ // Any other a filter matches goes, with everything below it, but a directory holding a kept path stays with that.
64
+ const matched = new Set()
65
+ const matchedAbove = (path) => {
66
+ for (let up = posix.dirname(path); up !== dir; up = posix.dirname(up)) if (matched.has(up)) return true
67
+ return false
68
+ }
69
+ let gone = null
70
+ for (const { path, loc } of entries) {
71
+ if ((gone !== null && path.startsWith(gone)) || kept.has(path)) continue
72
+ if (positives.some((filter) => matches(filter, loc))) matched.add(path)
73
+ else if (!matchedAbove(path)) continue
74
+ if (holdingKept.has(path)) continue
75
+ vfs.rm(path, { recursive: true })
76
+ gone = `${path}/`
77
+ }
78
+ }, { keeps: negations.length > 0 })
79
+ }
package/src/vfs-bundle.js CHANGED
@@ -1,80 +1,49 @@
1
1
  import { posix } from 'node:path'
2
2
 
3
- import { Vfs } from '@preventive/vfs'
4
- import { KINDS, checkAhead } from './vfs-bundle/entries.js'
3
+ import { configuredLockfiles, installsDevDependencies } from './cmd/bundle.js'
4
+ import { checkAhead, defaultEntries } from './vfs-bundle/entries.js'
5
5
  import { suggestedRepoEntries } from './vfs-bundle/github.js'
6
- import { NODE_MODULES_MANAGERS, checkCache, checkTarget, checkVfs, detectPackageManager, loadTree, packageManagerFor, vfsHost } from './vfs-bundle/tree.js'
6
+ import { NODE_MODULES_MANAGERS, checkCache, checkTarget, checkVfs, detectPackageManager, loadTree, lockfilesManagers, packageManagerFor, vfsHost } from './vfs-bundle/tree.js'
7
7
 
8
- // @exodus/stasis/vfs-bundle: static bundles from a project's lockfile alone, through the
9
- // dependencies its package manager would install (`packageManager`: 'pnpm', pnpm 9, 10, 11 or 12;
10
- // 'yarn1', yarn 1.22; 'npm', npm 10.9 or 11; or 'soldeer', Soldeer 0.12; without one, the one whose
11
- // lockfile installs the project, where only one's does), over the project held in a Vfs, which is
12
- // only read. The tree is laid out by @preventive/deptree into a Vfs of its own, and nothing is read
13
- // from disk or written there but the tarballs and zips: fetched from registry.npmjs.org and
14
- // Soldeer's registry, or read from npm's cache or ~/.audit's where one holds them, every copy held
15
- // to the lockfile's integrity before it is used; cached only where setCacheDir says. A Soldeer git
16
- // dependency is GitHub's tarball of its commit, fetched through the `client` buildVfsBundle is given.
17
- // buildGitHubBundle builds one from a GitHub repo at a commit, or the one a tag names (the default
18
- // branch's head without either), its tree fetched from GitHub and held to its git tree id, cached
19
- // there the same way, and its Soldeer git dependencies through the same client.
8
+ // Nothing touches disk but the tarballs and zips, each held to the lockfile's integrity, cached where setCacheDir says.
20
9
 
21
10
  export { buildVfsBundle } from './cmd/bundle.js'
22
11
  export { buildGitHubBundle } from './vfs-bundle/github.js'
23
12
  export { setCacheDir } from '@preventive/deptree/pnpm.js'
24
- export { Vfs }
13
+ export { Vfs } from '@preventive/vfs'
25
14
 
26
- // A `host` (@exodus/stasis-core/host) over `vfs` alone, its `/` the filesystem's, reading it as it is
27
- // at each call.
15
+ // Reading `vfs` as it is at each call.
28
16
  export function createVfsHost(vfs) {
29
17
  checkVfs('createVfsHost', vfs)
30
18
  return vfsHost(vfs, { cache: false })
31
19
  }
32
20
 
33
- // -> { root, vfs, projects, host, stats, installed, packageManager, packageManagerVersion }, as
34
- // 'pnpm', 'yarn1' or 'npm' installs node_modules: the directory in the project's Vfs it installs cwd
35
- // from, which holds the lockfile; the Vfs the tree is laid out into, rooted there; the projects'
36
- // directories from there; the host reading the project through the tree; deptree's counts, and the
37
- // packages it installs (each by its `path` from there, with the `commit` its version document
38
- // names, where it names a full one); and the
39
- // package manager reproduced, at `packageManagerVersion` if given, else the one the root
40
- // package.json's packageManager pins, else pnpm 10.33.4, yarn 1.22.22 or npm 11.21.0 (which nothing
41
- // pins: npm reads no packageManager). The host caches what it reads, of the project's Vfs too, so
42
- // neither is to change while it is used.
43
- // `os`, `cpu` and `libc` ('glibc', 'musl' or 'unknown', pnpm's and npm's, which takes 'unknown' for
44
- // none) are the machine packages are matched against: this one's but for what is given (for another
45
- // os, libc defaults to 'unknown'). Without a `packageManager`, it is the one of the three whose
46
- // lockfile installs cwd, where only one's does. `cache` is where the packages' tarballs and version
47
- // documents are kept, as @preventive/upstream's CacheOptions take it: left out, in setCacheDir's
48
- // cache; a store with `read` and `write`, in place of it; or false, nowhere.
21
+ // The host caches what it reads, so neither Vfs is to change meanwhile.
49
22
  export async function loadNodeModules({ vfs, packageManager, cwd = '/', packageManagerVersion, os, cpu, libc, cache } = {}) {
50
- checkVfs('loadNodeModules', vfs)
51
- checkTarget('loadNodeModules', { os, cpu, libc })
52
- checkCache('loadNodeModules', cache)
23
+ const name = 'loadNodeModules'
24
+ checkVfs(name, vfs)
25
+ checkTarget(name, { os, cpu, libc })
26
+ checkCache(name, cache)
53
27
  const project = vfsHost(vfs)
54
- // A real path, as detection and the layout take it.
55
28
  cwd = project.realpath(posix.resolve('/', cwd))
56
- packageManager = packageManagerFor('loadNodeModules', project, cwd, { packageManager, packageManagerVersion, os }, NODE_MODULES_MANAGERS)
57
- return loadTree({ project, packageManager, cwd, packageManagerVersion, os, cpu, libc, cache })
29
+ packageManager = packageManagerFor(name, project, cwd, { packageManager, packageManagerVersion, os }, NODE_MODULES_MANAGERS)
30
+ const installDevDependencies = installsDevDependencies(name, cwd, project)
31
+ return loadTree({ project, packageManager, cwd, packageManagerVersion, os, cpu, libc, cache, installDevDependencies })
58
32
  }
59
33
 
60
- // -> the entries buildGitHubBundle takes where none are given, as paths from the project's
61
- // directory, of the kind its package manager builds: `packageManager` if given, else the one
62
- // detected as the build detects it. For pnpm and yarn 1, the entry points its package.json names,
63
- // resolved as the build resolves them with the same `conditions`, `mainFields`, `metro`,
64
- // `platforms` and `typescript` (packageEntries); for Soldeer, its .sol entry points by name
65
- // and layout (solidityEntries). The options are checked as the build checks them, and `os`, the
66
- // one the build is for, detects the package manager as there. Of the project held in `vfs`, from
67
- // `cwd`; or of a GitHub repo, `{ github, sha, tag, directory, client }` as buildGitHubBundle takes
68
- // them, downloaded as it downloads them.
69
34
  export async function suggestedEntries({ vfs, cwd = '/', packageManager, conditions, mainFields, metro, platforms, jsx, typescript, os, ...repo } = {}) {
70
- checkTarget('suggestedEntries', { os })
35
+ const name = 'suggestedEntries'
36
+ checkTarget(name, { os })
71
37
  const resolution = { conditions, mainFields, metro, platforms, jsx, typescript }
72
- if (vfs === undefined && repo.github === undefined) throw new Error('suggestedEntries: a vfs or a github repo is required')
73
- if (vfs !== undefined && repo.github !== undefined) throw new Error('suggestedEntries: takes a vfs or a github repo, not both')
38
+ if (vfs === undefined && repo.github === undefined) throw new Error(`${name}: a vfs or a github repo is required`)
39
+ if (vfs !== undefined && repo.github !== undefined) throw new Error(`${name}: takes a vfs or a github repo, not both`)
74
40
  if (vfs === undefined) return suggestedRepoEntries({ ...repo, packageManager }, { ...resolution, os })
75
- checkVfs('suggestedEntries', vfs)
41
+ checkVfs(name, vfs)
76
42
  const host = vfsHost(vfs)
77
43
  const at = posix.resolve('/', cwd)
78
- const pm = checkAhead('suggestedEntries', packageManager ?? detectPackageManager('suggestedEntries', host, at, { os }), resolution)
79
- return KINDS[pm.kind].entries(host, at, resolution)
44
+ // As the build lays them out: a tree of each lockfile stasis.config.json names, none detected.
45
+ const lockfiles = packageManager === undefined ? configuredLockfiles(name, at, host) : undefined
46
+ const one = lockfiles === undefined ? packageManager ?? detectPackageManager(name, host, at, { os }) : undefined
47
+ checkAhead(name, one, resolution)
48
+ return defaultEntries(name, host, at, lockfiles === undefined ? [one] : lockfilesManagers(name, lockfiles), resolution).entries
80
49
  }
package/src/webpack.js CHANGED
@@ -1,5 +1 @@
1
- // Public-export adapter: backs `@exodus/stasis/webpack`. The plugin lives in
2
- // @exodus/stasis-plugins (which depends on @exodus/stasis-core for State /
3
- // resolvePluginState). Internal code uses `@exodus/stasis-plugins/webpack` directly;
4
- // this file exists only to back the package's `exports` map.
5
1
  export * from '@exodus/stasis-plugins/webpack'