@exodus/stasis 1.0.0-beta.16 → 1.0.0-beta.17
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/bin/stasis.js +9 -7
- package/package.json +3 -3
- package/src/cmd/bundle.js +11 -3
- package/src/cmd/github-bundle.js +37 -14
- package/src/cmd/output.js +5 -3
- package/src/vfs-bundle/github.js +11 -0
package/bin/stasis.js
CHANGED
|
@@ -24,7 +24,7 @@ const HELP = `Usage:
|
|
|
24
24
|
stasis bundle [--cargo] [--cargo-features=a,b,pkg/c] [--cargo-no-default-features] [--cargo-all-features] [--cargo-target=(triple|host)] [--cargo-manifests] [--add] [--output=(path|-)] path/to/file.rs ...
|
|
25
25
|
stasis bundle [--add] [--output=(path|-)] path/to/file.(php|sh|bash) ...
|
|
26
26
|
stasis bundle [--deptree] [--babel] [--metro-resolver] [--cargo] [--cargo-target=(triple|host)] [--lockfile=path/to/stasis.lock.json [--lockfile-only]] [--brotli-quality=0..11] [--add] [--output=(path|-)] [entry ...] (the entries' options from stasis.config.json's entries)
|
|
27
|
-
stasis github-bundle (owner/name[/path]|--github=owner/name [--directory=path]) [--sha=commit|--tag=name] [--package-manager=(pnpm|yarn1|npm|soldeer) [--package-manager-version=version]] [--no-lazy] [--generate=prisma|--no-generate] [--lockfile=path/to/stasis.lock.json [--lockfile-only]
|
|
27
|
+
stasis github-bundle (owner/name[/path]|--github=owner/name [--directory=path]) [--sha=commit|--tag=name] [--package-manager=(pnpm|yarn1|npm|soldeer) [--package-manager-version=version]] [--no-lazy] [--generate=prisma|--no-generate] [--lockfile=path/to/stasis.lock.json] [--lockfile-only] [--output=(path|-)] [stasis bundle's options for the entries] [path/in/repo/to/(file.(js|ts|jsx|tsx)|file.sol|dir) ...]
|
|
28
28
|
stasis add path/to/(file|dir) ...
|
|
29
29
|
stasis build --output=(dir|file.js) [--format=(esm|cjs|iife)] [--platform=(node|browser|neutral|hermes)] [--babel|--flow] [--minify] [--sourcemap] [--define=K=V ...] [--external=pkg ...] [--loader=.ext:name ...] [--metro=(ios|android|...) [--assets-dest=dir]] path/to/(stasis.code.br|stasis.lock.json) [entry]
|
|
30
30
|
stasis extract [--output=path/to/dir] [--lock=(frozen|add|replace|ignore|none)] path/to/bundle.stasis.code.br
|
|
@@ -202,7 +202,7 @@ if (command === '-v' || command === '--version') {
|
|
|
202
202
|
if (lockfileOnly) {
|
|
203
203
|
// Before anything is fetched.
|
|
204
204
|
const { lockfileOnlyError } = await import('../src/cmd/output.js')
|
|
205
|
-
const refused = lockfileOnlyError({ lockfile: values.lockfile, output: values.output, brotliQuality: values['brotli-quality'] })
|
|
205
|
+
const refused = lockfileOnlyError({ lockfile: values.lockfile, output: values.output, brotliQuality: values['brotli-quality'], named: true })
|
|
206
206
|
if (refused !== null) fail(`Error: github-bundle: ${refused}`)
|
|
207
207
|
}
|
|
208
208
|
// Whether each option applies to the entries is buildGitHubBundle's to say.
|
|
@@ -436,24 +436,26 @@ if (command === '-v' || command === '--version') {
|
|
|
436
436
|
})
|
|
437
437
|
if (argv.length !== 1) misused('Error: stasis validate takes one bundle')
|
|
438
438
|
if (values.lockfile !== undefined && values['no-lockfile']) misused('Error: --lockfile and --no-lockfile: give one')
|
|
439
|
-
// The repository is read with
|
|
440
|
-
//
|
|
439
|
+
// The repository is read with githubToken's token and the packages with withNpmToken's, as
|
|
440
|
+
// `stasis github-bundle` reads them; its trees and the packages fetched are cached where
|
|
441
|
+
// `stasis audit` caches, each held to its id or integrity as it is read.
|
|
441
442
|
const { createClient } = await import('@preventive/upstream/github.js')
|
|
442
443
|
const { setCacheDir } = await import('@preventive/upstream/npm.js')
|
|
443
444
|
setCacheDir(userCacheDir())
|
|
445
|
+
const { githubToken, withNpmToken } = await import('../src/cmd/tokens.js')
|
|
444
446
|
const { ValidateError, exitCodeOf, validate, printValidationReport } = await import('../src/validate.js')
|
|
445
447
|
let report
|
|
446
448
|
try {
|
|
447
449
|
// Its dependencies alone only with --only-deps, and held to no lockfile only with --no-lockfile: a
|
|
448
450
|
// bundle with no repository or commit to read its own code or its lockfile of is refused otherwise.
|
|
449
|
-
report = await validate(resolve(argv[0]), {
|
|
450
|
-
client: createClient({ token:
|
|
451
|
+
report = await withNpmToken(undefined, () => validate(resolve(argv[0]), {
|
|
452
|
+
client: createClient({ token: githubToken() }),
|
|
451
453
|
github: values.github,
|
|
452
454
|
sha: values.sha,
|
|
453
455
|
directory: values.directory,
|
|
454
456
|
own: !values['only-deps'],
|
|
455
457
|
lockfile: values['no-lockfile'] ? false : values.lockfile?.map((path) => resolve(path)) ?? true,
|
|
456
|
-
})
|
|
458
|
+
}))
|
|
457
459
|
} catch (cause) {
|
|
458
460
|
if (cause instanceof ValidateError) misused(`Error: ${cause.message}`)
|
|
459
461
|
refuse(`Error: ${cause.message}`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/stasis",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.17",
|
|
4
4
|
"description": "File-level source bundles and lockfiles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -118,8 +118,8 @@
|
|
|
118
118
|
"homepage": "https://github.com/PreventiveMeasures/stasis#readme",
|
|
119
119
|
"dependencies": {
|
|
120
120
|
"@exodus/bytes": "^1.16.0",
|
|
121
|
-
"@exodus/stasis-core": "1.0.0-beta.
|
|
122
|
-
"@exodus/stasis-plugins": "1.0.0-beta.
|
|
121
|
+
"@exodus/stasis-core": "1.0.0-beta.17",
|
|
122
|
+
"@exodus/stasis-plugins": "1.0.0-beta.17",
|
|
123
123
|
"@preventive/archive": "^1.4.0",
|
|
124
124
|
"@preventive/deptree": "^1.4.1",
|
|
125
125
|
"@preventive/lockfile": "^1.3.0",
|
package/src/cmd/bundle.js
CHANGED
|
@@ -20,7 +20,7 @@ import { installedRecords, pinInstalled } from '../installed.js'
|
|
|
20
20
|
import { State } from '@exodus/stasis-core/state'
|
|
21
21
|
import { bundledIntegrity, readFileSyncMaybe } from '@exodus/stasis-core/state-util'
|
|
22
22
|
import { checkoutCommit, detectRepo, normalizeEntries, packageLookup, packageJSONStat, packageType, parseGithubRepository, readJson, readModuleManifest, readPackageJson, readRegularFileOrNull, scopeManifestOf } from '@exodus/stasis-core/bundle-util'
|
|
23
|
-
import { attestsAny, BUNDLE_FILE, CONFIG_FILE, EMPTY_MODULE_PATH, assertRealPathWithinBase, classifyFormat, dependencyEcosystem, fileInBucket, archiveIntegrity, hasNodeModulesSegment, heldToAccounts, isDotEnvFile, isPathWithin, isPlainObject, JS_EXTENSIONS, LOCK_FILE, memoized, moduleFileKey, moduleFileKeys, moduleInfo, nestedMap, nodeExtFormat, observeExecutable, parseExtraOption, parseLockfilesOption, parseResourcesOption, posixPathEscapes, relativeEscapes, splitNodeModulesPath, toPosix, upsert, withAttestedOf, withMetadataOf } from '@exodus/stasis-core/util'
|
|
23
|
+
import { attestsAny, BUNDLE_FILE, CONFIG_FILE, EMPTY_MODULE_PATH, assertRealPathWithinBase, classifyFormat, dependencyEcosystem, fileInBucket, archiveIntegrity, hasNodeModulesSegment, heldToAccounts, isDotEnvFile, isPathWithin, isPlainObject, JS_EXTENSIONS, LOCK_FILE, memoized, moduleFileKey, moduleFileKeys, moduleInfo, nestedMap, nodeExtFormat, observeExecutable, parseExtraOption, parseLockfilesOption, parseResourcesOption, posixPathEscapes, relativeEscapes, splitNodeModulesPath, toPosix, upsert, withAttestedOf, withMetadataOf, sameGithub } from '@exodus/stasis-core/util'
|
|
24
24
|
import { diskHost } from '@exodus/stasis-core/host'
|
|
25
25
|
import { linksOn, parsePolicy, recordedIn } from '@exodus/stasis-core/policy'
|
|
26
26
|
import { parseBundleBytes } from '@exodus/stasis-core/brotli'
|
|
@@ -2080,8 +2080,9 @@ function lockModeOf(root, env = process.env, host = diskHost) {
|
|
|
2080
2080
|
}
|
|
2081
2081
|
|
|
2082
2082
|
// `built()` held to the lockfile at `lockAbs` by `mode`: in add, agreeing with it on all both record; in frozen,
|
|
2083
|
-
// that too, and it must be there and attest every file built; in none, it must not be there.
|
|
2084
|
-
|
|
2083
|
+
// that too, and it must be there and attest every file built; in none, it must not be there. With `repo` (a GitHub
|
|
2084
|
+
// build's), the repo it records, where it records one, must be that; without, one it records is no matter.
|
|
2085
|
+
export function heldToLockfile(built, lockAbs, label, mode, { host = diskHost, bundle, accounts = [], repo } = {}) {
|
|
2085
2086
|
if (mode !== 'add' && mode !== 'frozen' && mode !== 'none') return undefined
|
|
2086
2087
|
const text = readFileSyncMaybe(dirname(lockAbs), basename(lockAbs), 'utf-8', host)
|
|
2087
2088
|
if (text === null && mode !== 'frozen') return undefined
|
|
@@ -2096,6 +2097,9 @@ function heldToLockfile(built, lockAbs, label, mode, { host = diskHost, bundle,
|
|
|
2096
2097
|
} catch (cause) {
|
|
2097
2098
|
throw new Error(`${label}: not a valid stasis lockfile`, { cause })
|
|
2098
2099
|
}
|
|
2100
|
+
if (repo !== undefined && lock.repo !== undefined && !repoAttested(lock.repo, repo)) {
|
|
2101
|
+
throw new Error(`${label} records the repo ${repoLabel(lock.repo)}, and the build is of ${repoLabel(repo)}`)
|
|
2102
|
+
}
|
|
2099
2103
|
const merged = lock.mergeAgreeing(fresh, label, { held: true })
|
|
2100
2104
|
heldToAccounts(lock.modules, accounts, `${label}: `)
|
|
2101
2105
|
// What it alone records of a package no account tells the install of is the build's too: kept.
|
|
@@ -2109,6 +2113,10 @@ function heldToLockfile(built, lockAbs, label, mode, { host = diskHost, bundle,
|
|
|
2109
2113
|
return fresh
|
|
2110
2114
|
}
|
|
2111
2115
|
|
|
2116
|
+
// Each field `recorded` has is `repo`'s: `github` in any case, as GitHub takes it.
|
|
2117
|
+
const repoAttested = (recorded, repo) => Object.entries(recorded).every(([key, value]) => (key === 'github' ? sameGithub(value, repo.github) : value === repo[key]))
|
|
2118
|
+
const repoLabel = ({ github = '?', commit = '?', directory }) => `${github}@${commit}${directory ? `/${directory}` : ''}`
|
|
2119
|
+
|
|
2112
2120
|
// That the bundle of `text`, to be written at `at`, loads beside the lockfile at `lockAbs` as `stasis run
|
|
2113
2121
|
// --lock=frozen --bundle=load` loads them; stasis.config.json is read without the bundle paths it names.
|
|
2114
2122
|
function loadsBeside(text, { at, lockAbs, label, root, scope, host = diskHost }) {
|
package/src/cmd/github-bundle.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
|
-
import {
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
3
|
+
import { relative, resolve } from 'node:path'
|
|
3
4
|
|
|
4
|
-
import { BUNDLE_FILE } from '@exodus/stasis-core/util'
|
|
5
|
+
import { BUNDLE_FILE, LOCK_FILE } from '@exodus/stasis-core/util'
|
|
5
6
|
import { createClient } from '@preventive/upstream/github.js'
|
|
6
7
|
import { buildGitHubBundle } from '../vfs-bundle/github.js'
|
|
7
|
-
import { debugTimed } from './bundle.js'
|
|
8
|
+
import { debugTimed, heldToLockfile } from './bundle.js'
|
|
8
9
|
import { githubToken, withNpmToken } from './tokens.js'
|
|
9
|
-
import { bundledSummary, lockedSummary, lockfileOnlyError, unpackedSummary, writeBundle, writeFile } from './output.js'
|
|
10
|
+
import { bundledSummary, heldSummary, lockedSummary, lockfileOnlyError, unpackedSummary, writeBundle, writeFile } from './output.js'
|
|
10
11
|
|
|
11
12
|
// The longest file name ext4, APFS and NTFS take: 255 bytes, or characters, ours being ASCII.
|
|
12
13
|
const NAME_MAX = 255
|
|
13
14
|
const portable = (s) => s.replaceAll(/[^\w.-]/gu, '_')
|
|
14
15
|
|
|
15
|
-
// `owner-name[.<directory, its / made ->].<commit's first 7>.stasis.code.br
|
|
16
|
-
// keeps what fits of its start, then `_` and its sha256's
|
|
17
|
-
|
|
16
|
+
// `owner-name[.<directory, its / made ->].<commit's first 7>.stasis.code.br`, or `.stasis.lock.json` for
|
|
17
|
+
// `suffix` LOCK_FILE. A directory too long for NAME_MAX keeps what fits of its start, then `_` and its sha256's
|
|
18
|
+
// first 8 (a valid `github` leaves it 91 at least, 89 of a lockfile).
|
|
19
|
+
export function githubBundleFile({ github, directory, commit }, suffix = BUNDLE_FILE) {
|
|
18
20
|
const repo = portable(github.replace('/', '-'))
|
|
19
|
-
const tail = `.${portable(commit.slice(0, 7))}.${
|
|
21
|
+
const tail = `.${portable(commit.slice(0, 7))}.${suffix}`
|
|
20
22
|
if (!directory) return `${repo}${tail}`
|
|
21
23
|
const room = NAME_MAX - `${repo}.${tail}`.length
|
|
22
24
|
let dir = portable(directory.replaceAll('/', '-'))
|
|
@@ -25,19 +27,40 @@ export function githubBundleFile({ github, directory, commit }) {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
// Run `stasis github-bundle`. Of `env`, only GITHUB_TOKEN and EXODUS_STASIS_LOCK are read.
|
|
30
|
+
// The local lockfile is `lockfile`, else the one named as the bundle would be, `.stasis.lock.json` for
|
|
31
|
+
// `.stasis.code.br`. One there holds the build, by EXODUS_STASIS_LOCK's mode, frozen without it: it must attest the
|
|
32
|
+
// build, and the repo it records the build's, and is left as it is. One not there is written, where `lockfile` or
|
|
33
|
+
// `lockfileOnly` asks for it, recording the repo as the bundle does.
|
|
28
34
|
export async function githubBundleCommand({ cwd = process.cwd(), env = process.env, home, output, lockfile, lockfileOnly = false, brotliQuality, client, ...options } = {}) {
|
|
29
|
-
const lockfileOnlyRefused = lockfileOnly ? lockfileOnlyError({ lockfile, output, brotliQuality }) : null
|
|
35
|
+
const lockfileOnlyRefused = lockfileOnly ? lockfileOnlyError({ lockfile, output, brotliQuality, named: true }) : null
|
|
30
36
|
if (lockfileOnlyRefused !== null) throw new Error(`githubBundleCommand: ${lockfileOnlyRefused}`)
|
|
31
|
-
const
|
|
37
|
+
const locks = lockfile !== undefined || lockfileOnly
|
|
38
|
+
// The local lockfile's mode is the environment's alone: a repo's `lock: frozen` pins its own stasis.lock.json.
|
|
39
|
+
const mode = env.EXODUS_STASIS_LOCK || 'frozen'
|
|
40
|
+
if (locks && (mode === 'ignore' || mode === 'none')) throw new Error(`githubBundleCommand: ${lockfile === undefined ? '--lockfile-only' : '--lockfile'}: lock = ${mode} writes no lockfile`)
|
|
41
|
+
// buildGitHubBundle reads only whether a lockfile is asked for, refusing one but of a JS bundle; it writes none.
|
|
42
|
+
const built = await withNpmToken(home, () => buildGitHubBundle({ ...options, lockfile: locks ? lockfile ?? LOCK_FILE : undefined, lock: env.EXODUS_STASIS_LOCK || undefined, client: client ?? createClient({ token: githubToken({ env, home }) }) }))
|
|
32
43
|
const { directory, bundle } = built
|
|
44
|
+
const named = (suffix) => githubBundleFile({ github: options.github, directory, commit: bundle.repo.commit }, suffix)
|
|
45
|
+
const lockTarget = lockfile ?? named(LOCK_FILE)
|
|
46
|
+
const lockAbs = resolve(cwd, lockTarget)
|
|
47
|
+
const label = relative(resolve(cwd), lockAbs)
|
|
48
|
+
// Before anything is written: the build, and the lockfile it writes, take what the one there alone attests. Of
|
|
49
|
+
// a build of none (a Solidity one), it holds nothing.
|
|
50
|
+
const present = existsSync(lockAbs)
|
|
51
|
+
const held = present && heldToLockfile(() => built.lockfile, lockAbs, label, mode, { bundle, accounts: built.accounts, repo: bundle.repo }) !== undefined
|
|
52
|
+
const writes = locks && !(present && mode === 'frozen')
|
|
33
53
|
// Built before anything is written, as `stasis bundle` builds it.
|
|
34
|
-
const lockData =
|
|
54
|
+
const lockData = writes ? built.lockfile.serialize() : undefined
|
|
35
55
|
let dest
|
|
36
56
|
// Serialized under --lockfile-only too: never write a lockfile of a bundle that couldn't be written.
|
|
37
57
|
if (lockfileOnly) bundle.serialize()
|
|
38
|
-
else dest = await debugTimed('Wrote the bundle', () => writeBundle(cwd, output ??
|
|
39
|
-
if (lockData !== undefined) writeFile(
|
|
58
|
+
else dest = await debugTimed('Wrote the bundle', () => writeBundle(cwd, output ?? named(BUNDLE_FILE), bundle.serialize(), brotliQuality))
|
|
59
|
+
if (lockData !== undefined) writeFile(lockAbs, lockData)
|
|
40
60
|
const from = `${options.github}@${bundle.repo.commit}${directory ? `/${directory}` : ''}`
|
|
61
|
+
const summarized = (summary, to) => summary(bundle.sources.size, bundle.modules, from, to)
|
|
41
62
|
console.warn(unpackedSummary(built.stats))
|
|
42
|
-
console.warn((
|
|
63
|
+
if (held) console.warn(summarized(heldSummary, label))
|
|
64
|
+
if (!lockfileOnly) console.warn(summarized(bundledSummary, dest))
|
|
65
|
+
else if (writes) console.warn(summarized(lockedSummary, lockTarget))
|
|
43
66
|
}
|
package/src/cmd/output.js
CHANGED
|
@@ -34,11 +34,13 @@ export function unpackedSummary({ unpacked, installed, dependencies, files, byte
|
|
|
34
34
|
const summary = (verb) => (count, modules, from, dest) => `[stasis] ${verb} ${count} files in ${packagesLabel(modules)} from ${from} to ${dest}`
|
|
35
35
|
export const bundledSummary = summary('Bundled')
|
|
36
36
|
export const lockedSummary = summary('Locked')
|
|
37
|
+
export const heldSummary = summary('Held')
|
|
37
38
|
|
|
38
39
|
// Why --lockfile-only can't be taken with these output options, or null where it can; `brotliQuality`
|
|
39
|
-
// counts as given, parsed or not.
|
|
40
|
-
export function lockfileOnlyError({ lockfile, output, add = false, brotliQuality }) {
|
|
41
|
-
if (
|
|
40
|
+
// counts as given, parsed or not. `named`: a lockfile left out is named by the command, so only an empty one is refused.
|
|
41
|
+
export function lockfileOnlyError({ lockfile, output, add = false, brotliQuality, named = false }) {
|
|
42
|
+
if (named && lockfile === '') return "--lockfile can't be empty: give a path, or leave it out for the default name"
|
|
43
|
+
if (!lockfile && !named) return '--lockfile-only requires --lockfile=path'
|
|
42
44
|
if (output !== undefined) return "--lockfile-only can't be combined with --output (no bundle is written)"
|
|
43
45
|
if (add) return "--lockfile-only can't be combined with --add (no bundle is merged into)"
|
|
44
46
|
if (brotliQuality !== undefined) return "--lockfile-only can't be combined with --brotli-quality (no bundle is compressed)"
|
package/src/vfs-bundle/github.js
CHANGED
|
@@ -195,6 +195,17 @@ export async function buildGitHubBundle({ github, sha, tag, directory, path, cli
|
|
|
195
195
|
built.bundle.repo = { ...repo, ...(isValidRepoField('directory', at) && { directory: at }) }
|
|
196
196
|
// Onto buildVfsBundle's own, not a copy, which would read its lockfile, built only when read.
|
|
197
197
|
built.directory = tree.directory
|
|
198
|
+
// The lockfile records the repo too, as the bundle does: a GitHub build's alone does.
|
|
199
|
+
const { get } = Object.getOwnPropertyDescriptor(built, 'lockfile')
|
|
200
|
+
Object.defineProperty(built, 'lockfile', {
|
|
201
|
+
enumerable: true,
|
|
202
|
+
configurable: true,
|
|
203
|
+
get() {
|
|
204
|
+
const lockfile = get.call(this)
|
|
205
|
+
if (lockfile !== undefined) lockfile.repo = built.bundle.repo
|
|
206
|
+
return lockfile
|
|
207
|
+
},
|
|
208
|
+
})
|
|
198
209
|
return built
|
|
199
210
|
}
|
|
200
211
|
|