@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, normalize, relative } from 'node:path'
|
|
1
|
+
import { join, normalize, posix, relative } from 'node:path'
|
|
2
2
|
import { fileURLToPath } from 'node:url'
|
|
3
3
|
|
|
4
4
|
import { readJson } from '@exodus/stasis-core/bundle-util'
|
|
@@ -12,20 +12,9 @@ import { resolveTypescriptFallback, typescriptExportsTarget } from '../resolve-t
|
|
|
12
12
|
import { checkKind, checkLazy, checkVersion, packageManagerOf, vfsHost } from './tree.js'
|
|
13
13
|
|
|
14
14
|
const JS = /\.(?:[cm]?[jt]s|[jt]sx)$/u
|
|
15
|
-
// Node's own conditions for require() and for import, which the build's are added to; with
|
|
16
|
-
// `mainFields` or `metro`, the field resolver's bundler ones instead (no `node`).
|
|
17
15
|
const NODE_CONDITIONS = [['require', 'node', 'node-addons', 'module-sync'], ['import', 'node', 'node-addons', 'module-sync']]
|
|
18
16
|
const FIELD_CONDITIONS = ['commonjs', 'module'].map((format) => resolveConditions(format))
|
|
19
17
|
|
|
20
|
-
// The entry points the package.json in `dir` names, as paths from `dir`, resolved as the JS build
|
|
21
|
-
// with the given options resolves: as Node does, `conditions` added, or with `mainFields` or
|
|
22
|
-
// `metro` through the build's field resolver, once per platform of `platforms` under `metro`; what
|
|
23
|
-
// that misses mapped as tsc maps it under `typescript`, as the build's fallback maps it. In
|
|
24
|
-
// that order: its own entry, as the build resolves `./` there (`main`, or the first of the main
|
|
25
|
-
// fields, else index); each subpath `exports` holds (but a pattern), as the package's name resolves
|
|
26
|
-
// for require() and for import, with the conditions the build adds (the RN ones under `metro`) to
|
|
27
|
-
// Node's, or with `mainFields` or `metro` to the field resolver's; and each `bin`. Only JS files in
|
|
28
|
-
// `dir` that are there, named from within it; none without a package.json.
|
|
29
18
|
function packageEntries(host, dir, { conditions = [], mainFields, metro = false, platforms = [], typescript = false } = {}) {
|
|
30
19
|
const real = host.realpath(dir)
|
|
31
20
|
const manifest = join(real, 'package.json')
|
|
@@ -39,8 +28,6 @@ function packageEntries(host, dir, { conditions = [], mainFields, metro = false,
|
|
|
39
28
|
const passes = metro || mainFields !== undefined
|
|
40
29
|
? (metro ? platforms : [null]).map((platform) => fieldResolverFor(platform, { mainFields, metro, conditions, typescript, host }))
|
|
41
30
|
: [{ extras: conditions, mainFields: ['main'] }]
|
|
42
|
-
// Node's resolution of `specifier`, else under `typescript` the miss `mapped` as tsc maps it; a
|
|
43
|
-
// real path either way, or undefined.
|
|
44
31
|
const viaNode = (specifier, names, extras, mapped) => {
|
|
45
32
|
const set = new Set([...names, ...extras])
|
|
46
33
|
try {
|
|
@@ -78,35 +65,18 @@ function packageEntries(host, dir, { conditions = [], mainFields, metro = false,
|
|
|
78
65
|
return [...found]
|
|
79
66
|
}
|
|
80
67
|
|
|
81
|
-
// Directories whose .sol files are none of a project's entry points: its tests, scripts and mocks,
|
|
82
|
-
// what it depends on or builds, and what no walk descends into.
|
|
83
68
|
const SKIPPED_DIRS = new Set(['test', 'tests', 'script', 'scripts', 'mock', 'mocks', 'lib', 'node_modules', 'dependencies', 'out', 'cache', 'artifacts', 'build'])
|
|
84
|
-
const isSkippedDir = (name) => SKIPPED_DIRS.has(name.toLowerCase()) || isAutoExcludedDir(name)
|
|
85
|
-
// A .sol file but a test or script by its name.
|
|
86
69
|
const isEntrySol = (entry) => entry.isFile() && entry.name.endsWith('.sol') && !/\.(?:t|s|test|spec)\.sol$/u.test(entry.name)
|
|
87
70
|
|
|
88
|
-
// The .sol files under the directory `rel` of `real` that are entry points by name, but those in a
|
|
89
|
-
// skipped directory; sorted. Links are not followed.
|
|
90
71
|
function solidityFiles(host, real, rel) {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
} else if (isEntrySol(entry)) {
|
|
98
|
-
out.push(path)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
walk(rel)
|
|
103
|
-
return out.toSorted()
|
|
72
|
+
const walk = (sub) => host.readdir(join(real, sub)).flatMap((entry) => {
|
|
73
|
+
const path = sub === '.' ? entry.name : `${sub}/${entry.name}`
|
|
74
|
+
if (entry.isDirectory()) return SKIPPED_DIRS.has(entry.name.toLowerCase()) || isAutoExcludedDir(entry.name) ? [] : walk(path)
|
|
75
|
+
return isEntrySol(entry) ? [path] : []
|
|
76
|
+
})
|
|
77
|
+
return walk(rel).toSorted()
|
|
104
78
|
}
|
|
105
79
|
|
|
106
|
-
// The entry points of the Soldeer project in `dir`, by name and layout, as paths from `dir`: its
|
|
107
|
-
// .sol files directly in it, then those under contracts/, then those under its source directory
|
|
108
|
-
// (its foundry.toml's default profile's `src`, else `src`); none of its tests, scripts or mocks,
|
|
109
|
-
// nor any in what it depends on or builds. A link to a directory is none.
|
|
110
80
|
function solidityEntries(host, dir) {
|
|
111
81
|
const real = host.realpath(dir)
|
|
112
82
|
const isDirectory = (rel) => !posixPathEscapes(rel) && host.stat(join(real, rel))?.isDirectory() && host.readlink(join(real, rel)) === null
|
|
@@ -116,36 +86,46 @@ function solidityEntries(host, dir) {
|
|
|
116
86
|
return [...new Set([...own, ...under('contracts'), ...(src === 'contracts' ? [] : under(src))])]
|
|
117
87
|
}
|
|
118
88
|
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
89
|
+
// `prefix*suffix`, one `*` in the last segment, whose `*` takes no leading `.`, as a shell's; null for no pattern.
|
|
90
|
+
export function entryPattern(name, entry) {
|
|
91
|
+
if (typeof entry !== 'string' || !entry.includes('*')) return null
|
|
92
|
+
const dir = entry.slice(0, entry.lastIndexOf('/') + 1)
|
|
93
|
+
const [prefix, suffix, ...more] = entry.slice(dir.length).split('*')
|
|
94
|
+
if (dir.includes('*') || more.length > 0) throw new Error(`${name}: ${JSON.stringify(entry)}: a pattern holds one *, in its last segment (prefix*suffix)`)
|
|
95
|
+
const matches = (file) => file.length >= prefix.length + suffix.length && file.startsWith(prefix) && file.endsWith(suffix) && (prefix !== '' || !file.startsWith('.'))
|
|
96
|
+
return { dir, matches }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function expandEntries(name, host, cwd, entries) {
|
|
100
|
+
if (!Array.isArray(entries)) return entries
|
|
101
|
+
return entries.flatMap((entry) => {
|
|
102
|
+
const pattern = entryPattern(name, entry)
|
|
103
|
+
if (pattern === null) return [entry]
|
|
104
|
+
const dir = posix.resolve(cwd, pattern.dir)
|
|
105
|
+
const files = host.stat(dir)?.isDirectory() ? host.readdir(dir).filter((dirent) => dirent.isFile() && pattern.matches(dirent.name)) : []
|
|
106
|
+
if (files.length === 0) throw new Error(`${name}: ${JSON.stringify(entry)} matches no file`)
|
|
107
|
+
return files.map((dirent) => `${pattern.dir}${dirent.name}`).toSorted()
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const KINDS = {
|
|
122
112
|
js: { standIn: 'index.js', entries: packageEntries, none: 'has no package.json naming a JS entry point there' },
|
|
123
113
|
sol: { standIn: 'index.sol', entries: solidityEntries, none: 'has no .sol entry point directly in it, under contracts/, or under its source directory' },
|
|
124
114
|
}
|
|
125
115
|
|
|
126
116
|
const EMPTY = vfsHost(new Vfs())
|
|
127
117
|
|
|
128
|
-
|
|
129
|
-
const CONFIGURED_NONE = 'has a stasis.config.json whose entries name none'
|
|
130
|
-
|
|
131
|
-
// -> { entries, none }: the entries a build of the project in `dir` (read through `host`) takes
|
|
132
|
-
// where none are given, as paths from `dir`, and what having none says of `dir`. Those its
|
|
133
|
-
// stasis.config.json's `entries` names, checked with `options` as the build checks them
|
|
134
|
-
// (configuredBuilds), where it has `entries`, whatever it names; else those of `kind` (KINDS'),
|
|
135
|
-
// with `options` then checked on their own, as the build checks them, which nothing completes.
|
|
136
|
-
export function defaultEntries(name, host, dir, kind, options) {
|
|
118
|
+
export function defaultEntries(name, host, dir, packageManagers, options) {
|
|
137
119
|
const configured = configuredBuilds(name, { cwd: dir, host, options })
|
|
138
|
-
if (configured !== null) return { entries: configured.entries, none:
|
|
120
|
+
if (configured !== null) return { entries: configured.entries, none: 'has a stasis.config.json whose entries name none' }
|
|
121
|
+
const kinds = new Set(packageManagers.map((pm) => packageManagerOf(name, pm).kind))
|
|
122
|
+
if (kinds.size > 1) return { entries: [], none: 'has a stasis.config.json whose lockfiles lay out JS and Solidity trees, and no entries naming which to bundle' }
|
|
123
|
+
const kind = KINDS[[...kinds][0]]
|
|
139
124
|
checkVfsOptions(name, { ...options, entries: [kind.standIn], cwd: '/', host: EMPTY, fetched: false })
|
|
140
125
|
return { entries: kind.entries(host, dir, options), none: kind.none }
|
|
141
126
|
}
|
|
142
127
|
|
|
143
|
-
//
|
|
144
|
-
// decides them: for the package manager given, else for any; over the entries given, else over one
|
|
145
|
-
// of the kind the default ones are. But for what one of them needs of another, which the options of
|
|
146
|
-
// an entry stasis.config.json names may set (`partial`), left to the build, which knows whether it
|
|
147
|
-
// names it; and `lazy`, which the package manager given has to take. -> the PACKAGE_MANAGERS entry of
|
|
148
|
-
// the one given
|
|
128
|
+
// Over an empty tree, before anything is fetched, but for what a configured entry's options may set (`partial`).
|
|
149
129
|
export function checkAhead(name, packageManager, options) {
|
|
150
130
|
checkVersion(name, { packageManager, ...options })
|
|
151
131
|
if (options.lazy !== undefined && typeof options.lazy !== 'boolean') throw new TypeError(`${name}: lazy must be a boolean`)
|
|
@@ -159,7 +139,10 @@ export function checkAhead(name, packageManager, options) {
|
|
|
159
139
|
return error
|
|
160
140
|
}
|
|
161
141
|
}
|
|
162
|
-
|
|
142
|
+
// A pattern is checked as an entry of the kind its extension names, if any (not `src/*`).
|
|
143
|
+
const told = Array.isArray(options.entries) ? options.entries.filter((entry) => !entryPattern(name, entry) || /^\.[^*]+$/u.test(posix.extname(entry))) : options.entries
|
|
144
|
+
const entries = told?.length === 0 && options.entries.length > 0 ? undefined : told
|
|
145
|
+
const refusals = entries === undefined ? (pm === undefined ? Object.values(KINDS) : [KINDS[pm.kind]]).map(({ standIn }) => refusal([standIn])) : [refusal(entries)]
|
|
163
146
|
if (!refusals.includes(null)) throw refusals[0]
|
|
164
147
|
return pm
|
|
165
148
|
}
|
package/src/vfs-bundle/github.js
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
import { posix } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { isValidRepoField } from '@exodus/stasis-core/bundle'
|
|
4
|
-
import { posixPathEscapes } from '@exodus/stasis-core/util'
|
|
4
|
+
import { CONFIG_FILE, memoized, posixPathEscapes } from '@exodus/stasis-core/util'
|
|
5
5
|
import { decompress } from '@preventive/archive/compression.js'
|
|
6
6
|
import { ArchiveError, unpack } from '@preventive/archive/tar.js'
|
|
7
7
|
import { createClient } from '@preventive/upstream/github.js'
|
|
8
8
|
import { vfsFromEntries } from '@preventive/vfs'
|
|
9
|
-
import { buildVfsBundle, debugTimed } from '../cmd/bundle.js'
|
|
10
|
-
import {
|
|
11
|
-
import { checkCache, checkTarget, detectPackageManager, installedAlone, lockfileOf, lockfilesListed, noLockfile, packageManagerOf, vfsHost } from './tree.js'
|
|
9
|
+
import { buildVfsBundle, configuredLockfiles, debugTimed, prismaClientsOf } from '../cmd/bundle.js'
|
|
10
|
+
import { checkAhead, defaultEntries, entryPattern, expandEntries } from './entries.js'
|
|
11
|
+
import { checkCache, checkTarget, detectPackageManager, installedAlone, listsFile, lockfileOf, lockfilesListed, lockfilesManagers, noLockfile, packageManagerOf, vfsHost } from './tree.js'
|
|
12
12
|
import { YARNCLEAN } from './yarnclean.js'
|
|
13
13
|
|
|
14
14
|
// As upstream's tree verification bounds a tarball's unpacked size.
|
|
15
15
|
const MAX_TAR_BYTES = 2 ** 30
|
|
16
|
-
//
|
|
16
|
+
// Upstream's verification refuses anything else from GitHub.
|
|
17
17
|
const TREE_TYPES = new Set(['file', 'directory', 'symlink'])
|
|
18
|
-
//
|
|
19
|
-
// pnpm's and yarn's specs, and package-lock.json's package keys and `resolved` paths, `..` itself
|
|
20
|
-
// (`link:..`, npm's `".."`) or under it.
|
|
18
|
+
// A lockfile's reference to `..` or under it (conservatively: any importer's).
|
|
21
19
|
const LOCKFILE_ESCAPE = /(?:link:|file:|directory: |["'])\.\.(?![^/"'\s])/u
|
|
22
20
|
const TSCONFIG = /(?:^|\/)[jt]sconfig[^/]*\.json$/u
|
|
23
21
|
|
|
24
|
-
// Whether `target`, a path relative to the file `from`, resolves outside the tree.
|
|
25
22
|
const resolvesOutside = (from, target) => target.startsWith('/') || posixPathEscapes(posix.join(posix.dirname(from), target))
|
|
26
23
|
|
|
27
|
-
//
|
|
28
|
-
// bit (upstream verifies that much), and GitHub's tarballs are written with git archive's tar.umask
|
|
29
|
-
// 0002, which makes them 664 and 775 besides.
|
|
24
|
+
// As a checkout under umask 022 makes them: git keeps only the executable bit, and GitHub's tar.umask is 0002.
|
|
30
25
|
const checkoutMode = ({ type, mode }) => (type === 'symlink' ? mode : type === 'directory' || mode & 0o100 ? 0o755 : 0o644)
|
|
31
26
|
|
|
32
|
-
// A GitHub tarball's entries, its one top directory dropped, with the modes a checkout has.
|
|
33
27
|
async function treeEntries(tarball, where) {
|
|
34
28
|
const entries = []
|
|
35
29
|
for (const entry of unpack(await decompress(tarball, 'gzip', { limit: MAX_TAR_BYTES }))) {
|
|
@@ -40,10 +34,8 @@ async function treeEntries(tarball, where) {
|
|
|
40
34
|
return entries
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
// The first symlink pointing outside the tree, which would otherwise resolve within it.
|
|
44
37
|
const escapingLink = (entries) => entries.find((entry) => entry.type === 'symlink' && resolvesOutside(entry.name, entry.linkname))
|
|
45
38
|
|
|
46
|
-
// Whether a subtree's files refer to a path above it: a lockfile link or a [jt]sconfig path.
|
|
47
39
|
function refersAbove(entries, lockfile) {
|
|
48
40
|
const text = (entry) => new TextDecoder().decode(entry.data)
|
|
49
41
|
return entries.some((entry) => entry.type === 'file' && (entry.name === lockfile
|
|
@@ -51,28 +43,24 @@ function refersAbove(entries, lockfile) {
|
|
|
51
43
|
: TSCONFIG.test(entry.name) && [...text(entry).matchAll(/"(\.\.?\/[^"]*)"/gu)].some(([, path]) => resolvesOutside(entry.name, path))))
|
|
52
44
|
}
|
|
53
45
|
|
|
54
|
-
// The
|
|
46
|
+
// The repo's root (undefined) last.
|
|
55
47
|
function ancestorsOf(directory) {
|
|
56
48
|
const out = []
|
|
57
49
|
for (let dir = posix.dirname(directory); dir !== '.'; dir = posix.dirname(dir)) out.push(dir)
|
|
58
50
|
return [...out, undefined]
|
|
59
51
|
}
|
|
60
52
|
|
|
61
|
-
//
|
|
62
|
-
// refuses a tarball whose symlinks climb above its root, unless told how far they may: as far as the
|
|
63
|
-
// repo's root, as many levels as `directory` is deep, less one (its tarball's top directory).
|
|
53
|
+
// Upstream refuses symlinks above the tarball's root (its top directory) unless told how far they may climb: to the repo's.
|
|
64
54
|
async function treeFiles(client, { github, tree, directory, where }) {
|
|
65
|
-
let files
|
|
66
55
|
try {
|
|
67
|
-
files = await treeEntries(await client.getRepoTreeTarball({ repo: github, tree, symlinksAbove: directory.split('/').length - 1 }), where)
|
|
56
|
+
const files = await treeEntries(await client.getRepoTreeTarball({ repo: github, tree, symlinksAbove: directory.split('/').length - 1 }), where)
|
|
57
|
+
return escapingLink(files) ? null : files
|
|
68
58
|
} catch (error) {
|
|
69
59
|
if (error instanceof ArchiveError) return null // e.g. a symlink out of the subtree
|
|
70
60
|
throw error
|
|
71
61
|
}
|
|
72
|
-
return escapingLink(files) ? null : files
|
|
73
62
|
}
|
|
74
63
|
|
|
75
|
-
// The whole repo's files at `sha`.
|
|
76
64
|
async function repoFiles(client, { github, sha, where }) {
|
|
77
65
|
const files = await treeEntries(await client.getRepoTarball({ repo: github, sha }), where)
|
|
78
66
|
const link = escapingLink(files)
|
|
@@ -80,8 +68,7 @@ async function repoFiles(client, { github, sha, where }) {
|
|
|
80
68
|
return files
|
|
81
69
|
}
|
|
82
70
|
|
|
83
|
-
// Checked as the Bundle checks them, before anything is fetched; a
|
|
84
|
-
// and a `path` is checked as a `directory`, which it may be.
|
|
71
|
+
// Checked as the Bundle checks them, before anything is fetched; a `path` as a `directory`, but for a pattern's `*`.
|
|
85
72
|
function checkRepo(name, { github, sha, tag, directory, path }) {
|
|
86
73
|
if (github === undefined) throw new Error(`${name}: github is required`)
|
|
87
74
|
if (tag !== undefined && (typeof tag !== 'string' || tag === '')) throw new TypeError(`${name}: tag must be a non-empty string`)
|
|
@@ -90,65 +77,45 @@ function checkRepo(name, { github, sha, tag, directory, path }) {
|
|
|
90
77
|
for (const [key, value] of Object.entries({ github, commit: sha, directory: directory || undefined })) {
|
|
91
78
|
if (value !== undefined && !isValidRepoField(key, value)) throw new Error(`${name}: invalid ${key}: ${JSON.stringify(value)}`)
|
|
92
79
|
}
|
|
93
|
-
if (path && !isValidRepoField('directory', path)) throw new Error(`${name}: invalid path: ${JSON.stringify(path)}`)
|
|
80
|
+
if (path && !isValidRepoField('directory', entryPattern(name, path) ? path.replace('*', '_') : path)) throw new Error(`${name}: invalid path: ${JSON.stringify(path)}`)
|
|
94
81
|
}
|
|
95
82
|
|
|
96
|
-
// The files that make a directory a project's root, for an entry of each kind: a JS project's
|
|
97
|
-
// package.json, and the foundry.toml or soldeer.toml Soldeer installs from.
|
|
98
|
-
const PROJECT_FILES = { js: ['package.json'], sol: ['foundry.toml', 'soldeer.toml'] }
|
|
99
|
-
// A symlink's mode in a git tree.
|
|
100
83
|
const SYMLINK = '120000'
|
|
101
84
|
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
// root (undefined) where none does, and a path from there; anything else, or what the listings can't
|
|
105
|
-
// tell (a symlink on the way), is the directory, with no entry.
|
|
106
|
-
async function splitPath(list, path) {
|
|
107
|
-
const above = ancestorsOf(path)
|
|
108
|
-
let listings
|
|
85
|
+
// Null where one is no plain directory in git (a symlink, or under one); the root's failure is GitHub's.
|
|
86
|
+
async function listingsOf(list, dirs) {
|
|
109
87
|
try {
|
|
110
|
-
|
|
88
|
+
return await Promise.all(dirs.map(list))
|
|
111
89
|
} catch {
|
|
112
|
-
// No plain directory in git (a symlink, or under one); the root's failure is GitHub's.
|
|
113
90
|
await list(undefined)
|
|
114
|
-
return
|
|
91
|
+
return null
|
|
115
92
|
}
|
|
116
|
-
const name = posix.basename(path)
|
|
117
|
-
if (!listings[0].some((entry) => entry.path === name && entry.type === 'blob' && entry.mode !== SYMLINK)) return { directory: path }
|
|
118
|
-
const files = PROJECT_FILES[path.endsWith('.sol') ? 'sol' : 'js']
|
|
119
|
-
const at = listings.findIndex((listing) => listing.some((entry) => files.includes(entry.path) && entry.type === 'blob'))
|
|
120
|
-
const directory = at === -1 ? undefined : above[at]
|
|
121
|
-
return { directory, entry: directory === undefined ? path : posix.relative(directory, path) }
|
|
122
93
|
}
|
|
123
94
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
95
|
+
async function splitPath(list, path, where) {
|
|
96
|
+
const pattern = entryPattern(where, path)
|
|
97
|
+
const matches = pattern?.matches ?? ((file) => file === posix.basename(path))
|
|
98
|
+
const above = ancestorsOf(path)
|
|
99
|
+
const listings = await listingsOf(list, above)
|
|
100
|
+
const names = (listings?.[0] ?? []).filter((entry) => entry.type === 'blob' && entry.mode !== SYMLINK && matches(entry.path)).map((entry) => entry.path).toSorted()
|
|
101
|
+
if (names.length === 0 && pattern) throw new Error(`${where}: ${JSON.stringify(path)} matches no file`)
|
|
102
|
+
if (names.length === 0) return { directory: path }
|
|
103
|
+
const files = names.every((file) => file.endsWith('.sol')) ? ['foundry.toml', 'soldeer.toml'] : ['package.json']
|
|
104
|
+
const at = listings.findIndex((listing) => listing.some((entry) => files.includes(entry.path) && entry.type === 'blob'))
|
|
105
|
+
const directory = at === -1 ? undefined : above[at]
|
|
106
|
+
const paths = names.map((file) => posix.join(posix.dirname(path), file))
|
|
107
|
+
return { directory, entries: directory === undefined ? paths : paths.map((file) => posix.relative(directory, file)) }
|
|
131
108
|
}
|
|
132
109
|
|
|
133
|
-
// Of no package manager given, the one whose lockfile alone `directory` (or the repo's root) and
|
|
134
|
-
// the directories above it list, which is then the only one that may install it; refused where
|
|
135
|
-
// none does; undefined where more than one does, or the listings can't tell, for the tree to tell.
|
|
136
110
|
async function listedPackageManager(list, { directory, where }) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
} catch {
|
|
141
|
-
// No plain directory in git (a symlink, or under one); the root's failure is GitHub's.
|
|
142
|
-
await list(undefined)
|
|
143
|
-
return undefined
|
|
144
|
-
}
|
|
111
|
+
const listings = await listingsOf(list, directory ? [directory, ...ancestorsOf(directory)] : [undefined])
|
|
112
|
+
if (listings === null) return { listed: undefined, configured: false }
|
|
113
|
+
const configured = listsFile(listings[0], CONFIG_FILE)
|
|
145
114
|
const listed = lockfilesListed(listings)
|
|
146
|
-
if (listed.length === 0) throw noLockfile(where, posix.resolve('/', directory || '.'))
|
|
147
|
-
return listed.length === 1 ? listed[0] : undefined
|
|
115
|
+
if (listed.length === 0 && !configured) throw noLockfile(where, posix.resolve('/', directory || '.'))
|
|
116
|
+
return { listed: listed.length === 1 ? listed[0] : undefined, configured }
|
|
148
117
|
}
|
|
149
118
|
|
|
150
|
-
// The files of `directory` alone, when it holds the lockfile, is installed from itself and stands
|
|
151
|
-
// alone, nor does a .yarnclean above it clean the node_modules it installs; else null.
|
|
152
119
|
async function subtreeEntries(client, list, { github, directory, packageManager, where }) {
|
|
153
120
|
const names = async (path) => (await list(path)).map((entry) => entry.path)
|
|
154
121
|
let listing
|
|
@@ -159,95 +126,86 @@ async function subtreeEntries(client, list, { github, directory, packageManager,
|
|
|
159
126
|
}
|
|
160
127
|
if (!lockfilesListed([listing]).includes(packageManager)) return null
|
|
161
128
|
const above = ancestorsOf(directory)
|
|
162
|
-
|
|
163
|
-
if (!(await installedAlone(packageManager, listing.map((entry) => entry.path),
|
|
164
|
-
if (packageManagerOf('buildGitHubBundle', packageManager).kind === 'js' && (await
|
|
129
|
+
const aboveNames = () => Promise.all(above.map(names))
|
|
130
|
+
if (!(await installedAlone(packageManager, listing.map((entry) => entry.path), aboveNames))) return null
|
|
131
|
+
if (packageManagerOf('buildGitHubBundle', packageManager).kind === 'js' && (await aboveNames()).some((dir) => dir.includes(YARNCLEAN))) return null
|
|
165
132
|
// Its tree id, as the listing above it holds it, held to that directory's own.
|
|
166
133
|
const tree = (await list(above[0])).find((entry) => entry.path === posix.basename(directory) && entry.type === 'tree')?.sha
|
|
167
134
|
const files = tree === undefined ? null : await treeFiles(client, { github, tree, directory, where })
|
|
168
135
|
return files === null || refersAbove(files, lockfileOf(packageManager)) ? null : files
|
|
169
136
|
}
|
|
170
137
|
|
|
171
|
-
// The repo as buildGitHubBundle downloads it, for `name`: at `sha`, else the commit `tag` names (an
|
|
172
|
-
// annotated tag followed to it), else the default branch's head; `directory` alone where it stands
|
|
173
|
-
// alone for the package manager installing it, else the whole repo. That package manager is
|
|
174
|
-
// `packageManager` if given, else the one the listings tell, before the tree is fetched, else the
|
|
175
|
-
// tree; `options` are checked for it once it is known. A `path` is the `directory`, or a file in
|
|
176
|
-
// it which is an entry ahead of `options.entries` (splitPath).
|
|
177
|
-
// -> { vfs, host, cwd, subtree, sha, where, packageManager, kind, directory, entries }
|
|
178
138
|
async function repoTree(name, { github, sha, tag, directory, path, client, packageManager }, options) {
|
|
179
139
|
checkAhead(name, packageManager, options)
|
|
180
140
|
checkRepo(name, { github, sha, tag, directory, path })
|
|
181
141
|
client ??= createClient({ token: null })
|
|
182
142
|
sha ??= tag === undefined ? (await client.getRepoHead({ repo: github })).oid : (await client.getRepoTag({ repo: github, tag })).oid
|
|
183
143
|
const where = `${name}: ${github}@${sha}`
|
|
184
|
-
const list =
|
|
144
|
+
const list = memoized((dir) => client.listRepoDir({ repo: github, sha, directory: dir }))
|
|
185
145
|
if (path) {
|
|
186
|
-
const split = await splitPath(list, path)
|
|
146
|
+
const split = await splitPath(list, path, where)
|
|
187
147
|
directory = split.directory
|
|
188
|
-
if (split.
|
|
189
|
-
options = { ...options, entries: [split.
|
|
148
|
+
if (split.entries !== undefined) {
|
|
149
|
+
options = { ...options, entries: [...split.entries, ...(options.entries ?? [])] }
|
|
190
150
|
checkAhead(name, packageManager, options)
|
|
191
151
|
}
|
|
192
152
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
153
|
+
const told = packageManager === undefined ? await listedPackageManager(list, { directory, where }) : { listed: packageManager }
|
|
154
|
+
let found = told.listed
|
|
155
|
+
// Unchecked where stasis.config.json may name the lockfiles in place of the one listed.
|
|
156
|
+
const checked = packageManager ?? (told.configured ? undefined : found)
|
|
157
|
+
if (checked !== packageManager) checkAhead(name, checked, options)
|
|
158
|
+
const open = (files, at) => {
|
|
159
|
+
const vfs = vfsFromEntries(files)
|
|
160
|
+
return { vfs, host: vfsHost(vfs), cwd: posix.resolve('/', at) }
|
|
161
|
+
}
|
|
162
|
+
let subtree = directory && found !== undefined ? await subtreeEntries(client, list, { github, directory, packageManager: found, where }) : null
|
|
163
|
+
let opened = open(subtree ?? await repoFiles(client, { github, sha, where }), subtree ? '.' : directory ?? '.')
|
|
164
|
+
// Lockfiles it names may climb out of the directory: the whole repo, which holds the same config there.
|
|
165
|
+
const lockfiles = configuredLockfiles(where, opened.cwd, opened.host)
|
|
166
|
+
if (lockfiles !== undefined && subtree !== null) {
|
|
167
|
+
subtree = null
|
|
168
|
+
opened = open(await repoFiles(client, { github, sha, where }), directory)
|
|
197
169
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (packageManager === undefined) {
|
|
203
|
-
const detected = detectPackageManager(where, host, cwd, { os: options.os })
|
|
204
|
-
if (detected !== found) checkAhead(name, detected, options)
|
|
205
|
-
found = detected
|
|
170
|
+
options = { ...options, entries: expandEntries(where, opened.host, opened.cwd, options.entries) }
|
|
171
|
+
if (lockfiles === undefined && packageManager === undefined) {
|
|
172
|
+
found = detectPackageManager(where, opened.host, opened.cwd, { os: options.os })
|
|
173
|
+
if (found !== checked) checkAhead(name, found, options)
|
|
206
174
|
}
|
|
207
|
-
|
|
175
|
+
// With lockfiles, none detected: a package manager given is the build's to refuse.
|
|
176
|
+
const packageManagers = lockfiles === undefined || packageManager !== undefined ? [found] : lockfilesManagers(where, lockfiles)
|
|
177
|
+
return { ...opened, client, subtree, sha, where, packageManager: lockfiles === undefined ? found : packageManager, packageManagers, directory, entries: options.entries }
|
|
208
178
|
}
|
|
209
179
|
|
|
210
|
-
//
|
|
211
|
-
// as buildVfsBundle builds it: `directory` downloaded alone where it stands alone, else the whole
|
|
212
|
-
// repo, and without a `packageManager`, the one whose lockfile installs it, where only one's does
|
|
213
|
-
// (repoTree). Without `entries`, they are the ones suggestedEntries suggests: those its
|
|
214
|
-
// stasis.config.json's `entries` names, where it has `entries`. The bundle's paths are
|
|
215
|
-
// relative to `directory`, or for a JS bundle, to the innermost package directory at or above it
|
|
216
|
-
// holding every file it bundles (buildJsBundle's innermostRoot), which is the project's root where
|
|
217
|
-
// one is outside the others; `repo` names that directory and the commit. Nothing is read from disk:
|
|
218
|
-
// the tree's bytes come from GitHub, or from the cache setCacheDir names, held to the git tree id
|
|
219
|
-
// either way (@preventive/upstream), and are unpacked into a Vfs that buildVfsBundle reads alone.
|
|
220
|
-
// `cache` and `lazy` are buildVfsBundle's, for the npm packages the tree installs: the repo's tree is
|
|
221
|
-
// cached where setCacheDir says, whatever it is, and fetched whole.
|
|
222
|
-
// `path`, in place of `directory`, is a path in the repo at the commit: a directory is the
|
|
223
|
-
// `directory`, and a file an entry ahead of `entries`, of the nearest directory at or above it with
|
|
224
|
-
// a package.json (with a foundry.toml or soldeer.toml, for a .sol file), else of the repo's root,
|
|
225
|
-
// which is then the `directory` (splitPath).
|
|
226
|
-
// -> buildVfsBundle's, and the `directory` bundled
|
|
180
|
+
// Nothing is read from disk: the tree comes from GitHub or setCacheDir's cache, held to its git tree id.
|
|
227
181
|
export async function buildGitHubBundle({ github, sha, tag, directory, path, client, packageManager, ...options } = {}) {
|
|
228
182
|
checkTarget('buildGitHubBundle', options)
|
|
229
183
|
checkCache('buildGitHubBundle', options.cache)
|
|
230
|
-
// Its own, for a Soldeer git dependency too.
|
|
231
|
-
client ??= createClient({ token: null })
|
|
232
184
|
const tree = await debugTimed('Fetched the repo', () => repoTree('buildGitHubBundle', { github, sha, tag, directory, path, client, packageManager }, options))
|
|
233
185
|
let { entries } = tree
|
|
234
186
|
if (entries === undefined) {
|
|
235
|
-
|
|
236
|
-
const suggested = defaultEntries('buildGitHubBundle', tree.host, tree.cwd, tree.kind, options)
|
|
187
|
+
const suggested = defaultEntries('buildGitHubBundle', tree.host, tree.cwd, tree.packageManagers, options)
|
|
237
188
|
entries = suggested.entries
|
|
238
189
|
if (entries.length === 0) throw new Error(`${tree.where}: no entries given, and ${tree.directory || 'the repo root'} ${suggested.none}`)
|
|
239
190
|
}
|
|
240
191
|
const repo = { github, commit: tree.sha }
|
|
241
|
-
const built = await buildVfsBundle({ ...options, entries, packageManager: tree.packageManager, vfs: tree.vfs, cwd: tree.cwd, innermostRoot: true, repo, client })
|
|
192
|
+
const built = await buildVfsBundle({ ...options, entries, packageManager: tree.packageManager, vfs: tree.vfs, cwd: tree.cwd, innermostRoot: true, repo, client: tree.client })
|
|
242
193
|
// The Vfs is the repo's tree, or the subtree at `directory`: a layout known, so its root is `''`.
|
|
243
194
|
const at = posix.join(tree.subtree ? tree.directory : '.', posix.relative('/', built.root)).replace(/^\.$/u, '')
|
|
244
|
-
built.bundle.repo = { ...repo, ...(isValidRepoField('directory', at)
|
|
245
|
-
|
|
195
|
+
built.bundle.repo = { ...repo, ...(isValidRepoField('directory', at) && { directory: at }) }
|
|
196
|
+
// Onto buildVfsBundle's own, not a copy, which would read its lockfile, built only when read.
|
|
197
|
+
built.directory = tree.directory
|
|
198
|
+
return built
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export async function repoPrismaClients({ github, sha, directory, client }) {
|
|
202
|
+
const tree = await repoTree('repoPrismaClients', { github, sha, directory: directory || undefined, client }, {})
|
|
203
|
+
const outputs = await prismaClientsOf({ vfs: tree.vfs, cwd: tree.cwd, packageManager: tree.packageManager, client })
|
|
204
|
+
const from = (path) => posix.relative(tree.cwd, path)
|
|
205
|
+
return outputs.map((output) => ({ ...output, dir: from(output.dir), schema: from(output.schema) })).filter(({ dir }) => !posixPathEscapes(dir))
|
|
246
206
|
}
|
|
247
207
|
|
|
248
|
-
// suggestedEntries of a GitHub repo, `{ github, sha, tag, directory | path, client, packageManager }`,
|
|
249
|
-
// as buildGitHubBundle downloads it: a `path` to a file, that file.
|
|
250
208
|
export async function suggestedRepoEntries(repo, resolution) {
|
|
251
209
|
const tree = await repoTree('suggestedEntries', repo, resolution)
|
|
252
|
-
return tree.entries ?? defaultEntries('suggestedEntries', tree.host, tree.cwd, tree.
|
|
210
|
+
return tree.entries ?? defaultEntries('suggestedEntries', tree.host, tree.cwd, tree.packageManagers, resolution).entries
|
|
253
211
|
}
|