@exodus/stasis 1.0.0-beta.15 → 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 +1 -1
- package/bin/stasis.js +19 -6
- package/package.json +10 -9
- package/src/audit-corrections.js +11 -42
- package/src/audit.js +113 -233
- 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 +50 -166
- package/src/cmd/bundle-options.js +110 -167
- package/src/cmd/bundle.js +853 -1344
- package/src/cmd/diff.js +1 -4
- package/src/cmd/github-bundle.js +18 -22
- package/src/cmd/output.js +15 -12
- package/src/cmd/sbom.js +3 -8
- package/src/cmd/tokens.js +10 -23
- package/src/define.js +34 -97
- package/src/diff.js +72 -128
- package/src/esbuild.js +0 -4
- package/src/flow.js +10 -25
- 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 +9 -33
- package/src/metro-resolver.js +20 -47
- package/src/metro-transformer.js +0 -5
- package/src/metro.js +0 -4
- package/src/mock.js +32 -80
- package/src/parse.js +2 -5
- package/src/prune.js +0 -3
- package/src/resolve-fields.js +90 -220
- package/src/resolve-node.js +27 -45
- package/src/resolve-typescript.js +109 -313
- package/src/rollup.js +0 -4
- package/src/run-installed.js +10 -0
- package/src/sbom.js +52 -128
- package/src/scan.js +136 -283
- package/src/sixel.js +18 -41
- package/src/table.js +14 -35
- package/src/validate-notes.d.ts +3 -2
- package/src/validate-notes.js +25 -19
- package/src/validate.d.ts +38 -11
- package/src/validate.js +478 -512
- package/src/vfs-bundle/entries.js +40 -57
- package/src/vfs-bundle/github.js +77 -121
- package/src/vfs-bundle/glob.js +4 -45
- package/src/vfs-bundle/lazy.js +27 -56
- package/src/vfs-bundle/prisma.js +167 -110
- 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 +75 -231
- package/src/installed-commits.js +0 -184
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { isAbsolute, relative, resolve } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { diskHost } from '@exodus/stasis-core/host'
|
|
4
|
-
import {
|
|
4
|
+
import { POLICY_KEYS, parsePolicy } from '@exodus/stasis-core/policy'
|
|
5
|
+
import { CONFIG_FILE, isPlainObject, JS_EXTENSIONS, parseBrotliQuality, parseResourcesOption, relativeEscapes, SCOPES, toPosix, upsert } from '@exodus/stasis-core/util'
|
|
5
6
|
import { parseFeatureList } from '../loaders/cargo.js'
|
|
6
7
|
import { parseDefineFlags } from '../define.js'
|
|
7
8
|
import { directoryEntryError, isSolidityEntry, readConfigFile } from './bundle.js'
|
|
9
|
+
import { lockfileOnlyError } from './output.js'
|
|
8
10
|
|
|
9
|
-
const CONFIG_FILE = 'stasis.config.json'
|
|
10
|
-
|
|
11
|
-
// `stasis bundle`'s flags, as parseArgs takes them.
|
|
12
11
|
export const BUNDLE_FLAGS = {
|
|
13
12
|
mapping: { type: 'string' },
|
|
14
13
|
manifests: { type: 'boolean' },
|
|
15
14
|
output: { type: 'string', short: 'o' },
|
|
16
15
|
scope: { type: 'string' },
|
|
17
16
|
lockfile: { type: 'string' },
|
|
17
|
+
'lockfile-only': { type: 'boolean' },
|
|
18
18
|
conditions: { type: 'string' },
|
|
19
19
|
mainFields: { type: 'string' },
|
|
20
20
|
metro: { type: 'boolean' },
|
|
@@ -40,153 +40,123 @@ export const BUNDLE_FLAGS = {
|
|
|
40
40
|
deptree: { type: 'boolean' },
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// The flags of the bundle as a whole
|
|
44
|
-
|
|
45
|
-
// sets per entry instead.
|
|
46
|
-
const OUTPUT_FLAGS = new Set(['output', 'lockfile', 'brotli-quality', 'add', 'deptree'])
|
|
47
|
-
// The entry flags taking a list (comma-separated, or repeated), which an entry's options may give as an array.
|
|
43
|
+
// The flags of the bundle as a whole; every other one is an entry's, which stasis.config.json's `entries` sets.
|
|
44
|
+
const OUTPUT_FLAGS = new Set(['output', 'lockfile', 'lockfile-only', 'brotli-quality', 'add', 'deptree'])
|
|
48
45
|
const LIST_FLAGS = new Set(['conditions', 'mainFields', 'platforms', 'resources', 'cargo-features'])
|
|
49
|
-
//
|
|
50
|
-
// hold one): an entry's options give them as an array, or one as a string.
|
|
46
|
+
// Given once per value, which a comma doesn't separate (a define's JSON value may hold one).
|
|
51
47
|
const REPEATED_FLAGS = new Set(['define'])
|
|
52
|
-
// The entry flags that run a program -> what they run. Set in stasis.config.json, they take effect
|
|
53
|
-
//
|
|
54
|
-
// make a bare `stasis bundle` run anything.
|
|
48
|
+
// The entry flags that run a program -> what they run. Set in stasis.config.json, they take effect only with
|
|
49
|
+
// the same flag (and value) given too, as consent: the config can't make a bare `stasis bundle` run anything.
|
|
55
50
|
const CONSENT_FLAGS = new Map([
|
|
56
51
|
['babel', "the project's Babel config"],
|
|
57
52
|
['metro-resolver', "the project's metro-resolver"],
|
|
58
53
|
['cargo', "cargo, and what the project's .cargo/config.toml names"],
|
|
59
54
|
['cargo-target', 'rustc'],
|
|
60
55
|
])
|
|
61
|
-
// A flag as given: `--name`, or `--name=value` for one taking a value.
|
|
62
56
|
const flagText = (name, value) => (value === true ? `--${name}` : `--${name}=${value}`)
|
|
63
57
|
|
|
64
|
-
|
|
58
|
+
function listFlag(value, error) {
|
|
59
|
+
if (value === undefined) return undefined
|
|
60
|
+
const list = value.split(',').map((s) => s.trim()).filter(Boolean)
|
|
61
|
+
if (list.length === 0) throw new Error(error)
|
|
62
|
+
return list
|
|
63
|
+
}
|
|
64
|
+
|
|
65
65
|
function entryKey(cwd, entry) {
|
|
66
66
|
const rel = relative(resolve(cwd), resolve(cwd, entry))
|
|
67
67
|
return relativeEscapes(rel) ? null : toPosix(rel) || '.'
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
// The
|
|
71
|
-
|
|
70
|
+
// The entryKeys of `entries`, and the first of them `config` names: it may name all of them or none, not some.
|
|
71
|
+
function configuredKeys(cwd, entries, config, prefix = '') {
|
|
72
|
+
const keys = entries.map((entry) => entryKey(cwd, entry))
|
|
73
|
+
const first = config === null ? undefined : entries.find((_, i) => config.has(keys[i]))
|
|
74
|
+
const unnamed = first === undefined ? undefined : entries.find((_, i) => !config.has(keys[i]))
|
|
75
|
+
if (unnamed !== undefined) {
|
|
76
|
+
throw new Error(`${prefix}${CONFIG_FILE}'s entries name ${first} but not ${unnamed}: bundle either the entries it names or others, not both`)
|
|
77
|
+
}
|
|
78
|
+
return { keys, first }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function prefixed(prefix, fn) {
|
|
82
|
+
try {
|
|
83
|
+
return fn()
|
|
84
|
+
} catch (cause) {
|
|
85
|
+
throw new Error(`${prefix}${cause.message}`, { cause })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const isJsEntry = (entry) => JS_EXTENSIONS.values().some((ext) => entry.endsWith(ext))
|
|
90
|
+
|
|
91
|
+
// Which language `entries` all are in, or `jsAndSol` for JS and Solidity entries together, each built apart.
|
|
72
92
|
function entriesLanguage(entries, cwd, host = diskHost) {
|
|
73
|
-
|
|
93
|
+
// Beside JS entries, a directory one is of the Solidity ones.
|
|
94
|
+
const dirError = directoryEntryError(entries.filter((f) => !isJsEntry(f)), cwd, host)
|
|
74
95
|
if (dirError !== null) throw new Error(dirError)
|
|
75
96
|
const lang = {
|
|
76
97
|
allSol: entries.every((f) => isSolidityEntry(f, cwd, host)),
|
|
77
98
|
allPhp: entries.every((f) => f.endsWith('.php')),
|
|
78
|
-
allJs: entries.every(
|
|
99
|
+
allJs: entries.every(isJsEntry),
|
|
79
100
|
allBash: entries.every((f) => /\.(?:sh|bash)$/u.test(f)),
|
|
80
101
|
allRust: entries.every((f) => f.endsWith('.rs')),
|
|
102
|
+
allTeal: entries.every((f) => f.endsWith('.teal')),
|
|
81
103
|
}
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return lang
|
|
104
|
+
if (Object.values(lang).some(Boolean)) return lang
|
|
105
|
+
if (entries.every((f) => isJsEntry(f) || isSolidityEntry(f, cwd, host))) return { ...lang, jsAndSol: true }
|
|
106
|
+
throw new Error('bundle entries must all be .sol, all be .php, all be .js/.cjs/.mjs/.ts/.cts/.mts/.jsx/.tsx, all be .sh/.bash, all be .rs, or all be .teal, or be .js/.cjs/.mjs/.ts/.cts/.mts/.jsx/.tsx and .sol together')
|
|
86
107
|
}
|
|
87
108
|
|
|
88
|
-
// bundleCommand's options for building `entries` (in `lang`, entriesLanguage's) from the parsed
|
|
89
|
-
// entry flags in `values`. A usage error throws.
|
|
90
109
|
function buildOptions(values, { allSol, allJs, allRust }) {
|
|
91
110
|
if (values.mapping && !allSol) throw new Error('--mapping is only valid for .sol bundles')
|
|
92
|
-
// --manifests: carry the Solidity build's description files (foundry.toml, remappings.txt, ...).
|
|
93
111
|
const manifests = Boolean(values.manifests)
|
|
94
112
|
if (manifests && !allSol) throw new Error('--manifests is only valid for .sol bundles')
|
|
95
|
-
// --cargo: take the Rust feature/dependency resolution from `cargo metadata` (runs cargo; opt-in).
|
|
96
113
|
const cargo = Boolean(values.cargo)
|
|
97
114
|
if (cargo && !allRust) throw new Error('--cargo is only valid for Rust bundles')
|
|
98
|
-
// --cargo-features / --cargo-no-default-features / --cargo-all-features: cargo's own feature flags
|
|
99
|
-
// for the entries' packages (`pkg/feat` targets one, or a dependency). --cargo-features is
|
|
100
|
-
// repeatable and/or comma-separated; parseFeatureList is the one splitter (the resolver reuses it).
|
|
101
115
|
const cargoFeatures = parseFeatureList(values['cargo-features'] ?? [])
|
|
102
116
|
if (values['cargo-features'] !== undefined && cargoFeatures.length === 0) {
|
|
103
117
|
throw new Error('--cargo-features must list at least one feature (e.g. --cargo-features=serde,app/tls)')
|
|
104
118
|
}
|
|
105
119
|
const cargoNoDefaultFeatures = Boolean(values['cargo-no-default-features'])
|
|
106
120
|
const cargoAllFeatures = Boolean(values['cargo-all-features'])
|
|
107
|
-
// --cargo-target=<triple|host>: the build's target, whose cfgs (from `rustc --print cfg`) decide
|
|
108
|
-
// `#[cfg(unix)]`-style code. A triple is letters, digits, `-`, `_` and `.` (`x86_64-unknown-linux-gnu`).
|
|
109
121
|
const cargoTarget = values['cargo-target'] ?? null
|
|
110
122
|
if (cargoTarget !== null && !/^[\w.-]+$/u.test(cargoTarget)) {
|
|
111
123
|
throw new Error('--cargo-target must be a target triple or "host" (e.g. --cargo-target=aarch64-apple-darwin)')
|
|
112
124
|
}
|
|
113
|
-
// --cargo-manifests: carry each bundled package's Cargo.toml and build script, the workspace
|
|
114
|
-
// Cargo.toml, Cargo.lock and .cargo/config.toml too (the Rust counterpart of --package-json).
|
|
115
125
|
const cargoManifests = Boolean(values['cargo-manifests'])
|
|
116
126
|
if (!allRust) {
|
|
117
127
|
const given = { 'cargo-features': cargoFeatures.length > 0, 'cargo-no-default-features': cargoNoDefaultFeatures, 'cargo-all-features': cargoAllFeatures, 'cargo-target': cargoTarget !== null, 'cargo-manifests': cargoManifests }
|
|
118
128
|
for (const [flag, on] of Object.entries(given)) if (on) throw new Error(`--${flag} is only valid for Rust bundles`)
|
|
119
129
|
}
|
|
120
130
|
if (values.scope && !allJs) throw new Error('--scope is only valid for JS bundles')
|
|
121
|
-
if (values.scope && !
|
|
122
|
-
throw new Error('--scope must be node_modules or full')
|
|
123
|
-
}
|
|
124
|
-
// --mainFields/--metro always emit a full-scope bundle, so they'd silently ignore a narrower --scope.
|
|
131
|
+
if (values.scope && !SCOPES.has(values.scope)) throw new Error('--scope must be node_modules or full')
|
|
125
132
|
if (values.scope !== undefined && values.scope !== 'full' && (values.mainFields !== undefined || values.metro)) {
|
|
126
133
|
throw new Error(`--scope=${values.scope} is not supported with --mainFields or --metro (they always build a full-scope bundle)`)
|
|
127
134
|
}
|
|
128
|
-
// --conditions: extra exports/imports resolution conditions merged onto Node's defaults;
|
|
129
|
-
// they don't honour legacy `mainFields` or platform suffixes (see --mainFields).
|
|
130
135
|
if (values.conditions !== undefined && !allJs) throw new Error('--conditions is only valid for JS bundles')
|
|
131
|
-
const conditions = values.conditions
|
|
132
|
-
|
|
133
|
-
: values.conditions.split(',').map((s) => s.trim()).filter(Boolean)
|
|
134
|
-
if (values.conditions !== undefined && conditions.length === 0) {
|
|
135
|
-
throw new Error('--conditions must list at least one condition name (e.g. --conditions=react-native,browser)')
|
|
136
|
-
}
|
|
137
|
-
// --metro: resolve like Metro/RN (its own conditions + mainFields, platform suffixes per
|
|
138
|
-
// --platforms target). --platforms is repeatable and/or comma-separated; the values union.
|
|
139
|
-
// It turns on --jsx and --flow, as Metro's Babel parses JSX and Flow in every file (and defines what
|
|
140
|
-
// Metro's release build does, see buildJs).
|
|
136
|
+
const conditions = listFlag(values.conditions, '--conditions must list at least one condition name (e.g. --conditions=react-native,browser)') ?? []
|
|
137
|
+
// --metro parses JSX and Flow, as Metro's Babel does in every file.
|
|
141
138
|
const metro = Boolean(values.metro)
|
|
142
|
-
// --flow: strip Flow type syntax (via stasis's own flow-remove-types) from a file marked `@flow`
|
|
143
|
-
// before parsing; JS-only.
|
|
144
139
|
if (values.flow && !allJs) throw new Error('--flow is only valid for JS bundles')
|
|
145
140
|
const flow = Boolean(values.flow) || metro
|
|
146
|
-
// --typescript: resolve like tsc -- a specifier naming a missing JS output (./x.js, .mjs, .cjs,
|
|
147
|
-
// extensionless) lands on its on-disk TS source (./x.ts, .mts, .cts); an existing .js always wins.
|
|
148
141
|
if (values.typescript && !allJs) throw new Error('--typescript is only valid for JS bundles')
|
|
149
142
|
const typescript = Boolean(values.typescript)
|
|
150
|
-
// --tsconfig: the config whose compilerOptions.paths aliases --typescript honours (default: the
|
|
151
|
-
// tsconfig.json beside each importing file's package.json). Meaningless without --typescript.
|
|
152
143
|
if (values.tsconfig !== undefined && !typescript) throw new Error('--tsconfig is only valid with --typescript')
|
|
153
|
-
// --mainFields: legacy package entry fields (e.g. react-native,browser,main) for the non-exports resolver.
|
|
154
144
|
if (values.mainFields !== undefined && !allJs) throw new Error('--mainFields is only valid for JS bundles')
|
|
155
|
-
const mainFields = values.mainFields
|
|
156
|
-
? undefined
|
|
157
|
-
: values.mainFields.split(',').map((s) => s.trim()).filter(Boolean)
|
|
158
|
-
if (values.mainFields !== undefined && mainFields.length === 0) {
|
|
159
|
-
throw new Error('--mainFields must list at least one field (e.g. --mainFields=react-native,browser,main)')
|
|
160
|
-
}
|
|
161
|
-
// --metro-resolver: resolve through the project's own metro-resolver instead of the built-in
|
|
162
|
-
// approximation. Only meaningful alongside --metro (enforced below and in classifyEntries).
|
|
145
|
+
const mainFields = listFlag(values.mainFields, '--mainFields must list at least one field (e.g. --mainFields=react-native,browser,main)')
|
|
163
146
|
const metroResolver = Boolean(values['metro-resolver'])
|
|
164
147
|
const platforms = [...new Set((values.platforms ?? []).flatMap((p) => p.split(',')).map((s) => s.trim()).filter(Boolean))]
|
|
165
|
-
// A platform name becomes an edge key
|
|
148
|
+
// A platform name becomes an edge key, so no '/' (parsers reject it) or '*' (a reserved placeholder).
|
|
166
149
|
for (const p of platforms) {
|
|
167
150
|
if (p === '*' || p.includes('/')) throw new Error(`invalid --platforms value '${p}' (a platform name can't contain '/' or be '*')`)
|
|
168
151
|
}
|
|
169
152
|
if ((metro || platforms.length > 0) && !allJs) throw new Error('--metro is only valid for JS bundles')
|
|
170
|
-
// --jsx: parse React Native's JSX-in-.js source in the static scanner (off by default; oxc,
|
|
171
|
-
// like tsc, auto-enables JSX for .jsx/.tsx only). Orthogonal to the resolver, so it pairs with
|
|
172
|
-
// plain/--mainFields/--metro alike -- JS-only, since no other entry language is scanned. On under --metro.
|
|
173
153
|
const jsx = Boolean(values.jsx) || metro
|
|
174
154
|
if (jsx && !allJs) throw new Error('--jsx is only valid for JS bundles')
|
|
175
|
-
// --package-json: fold each bundled module's package.json into the bundle. JS-only (only JS
|
|
176
|
-
// modules carry an npm package.json; the sol/php/bash/rust bucketizers have no such manifest).
|
|
177
155
|
const packageJSON = Boolean(values['package-json'])
|
|
178
156
|
if (packageJSON && !allJs) throw new Error('--package-json is only valid for JS bundles')
|
|
179
|
-
// --resources: comma-separated extension/filename allowlist for assets reached through the graph
|
|
180
|
-
// (e.g. --resources=png,svg). They're carried as resources instead of failing "can't carry" --
|
|
181
|
-
// for graphs that aren't fully loadable in JS (Metro consumes such assets). JS-only.
|
|
182
157
|
if (values.resources !== undefined && !allJs) throw new Error('--resources is only valid for JS bundles')
|
|
183
|
-
const resources = values.resources
|
|
184
|
-
|
|
185
|
-
: values.resources.split(',').map((s) => s.trim()).filter(Boolean)
|
|
186
|
-
if (values.resources !== undefined && resources.length === 0) {
|
|
187
|
-
throw new Error('--resources must list at least one extension or filename (e.g. --resources=png,svg)')
|
|
188
|
-
}
|
|
189
|
-
parseResourcesOption('--resources', resources) // validate early for a clean usage error (code exts / bad chars rejected)
|
|
158
|
+
const resources = listFlag(values.resources, '--resources must list at least one extension or filename (e.g. --resources=png,svg)')
|
|
159
|
+
parseResourcesOption('--resources', resources) // checked here, for a clean usage error
|
|
190
160
|
if (metro) {
|
|
191
161
|
if (conditions.length > 0) throw new Error("--conditions can't be combined with --metro (it sets its own conditions)")
|
|
192
162
|
if (mainFields !== undefined) throw new Error("--mainFields can't be combined with --metro (it sets its own mainFields)")
|
|
@@ -195,53 +165,42 @@ function buildOptions(values, { allSol, allJs, allRust }) {
|
|
|
195
165
|
throw new Error('--platforms is only valid with --metro')
|
|
196
166
|
}
|
|
197
167
|
if (metroResolver && !metro) throw new Error('--metro-resolver is only valid with --metro')
|
|
198
|
-
// --babel: resolve through the import aliases (babel-plugin-module-resolver) of the project's
|
|
199
|
-
// babel.config.*, which Metro runs before it resolves. Runs that config, so opt-in; --metro only.
|
|
200
168
|
const babel = Boolean(values.babel)
|
|
201
169
|
if (babel && !metro) throw new Error('--babel is only valid with --metro')
|
|
202
|
-
// --babel-aliases: the same aliases from a JSON file of the project (module-resolver's `alias` option as
|
|
203
|
-
// data), which runs nothing, so stasis.config.json's entries may set it alone. --metro only.
|
|
204
170
|
if (values['babel-aliases'] !== undefined && !metro) throw new Error('--babel-aliases is only valid with --metro')
|
|
205
171
|
if (values['babel-aliases'] !== undefined && babel) throw new Error("--babel-aliases can't be combined with --babel (both set the import aliases)")
|
|
206
|
-
// metro-resolver can't substitute .js -> .ts, so --typescript would silently not apply -- reject it.
|
|
207
172
|
if (typescript && metroResolver) throw new Error("--typescript is not supported with --metro-resolver (the project's metro-resolver doesn't substitute .js -> .ts)")
|
|
208
|
-
// --define=KEY=VALUE: a global's value (JSON), repeatable; the scan leaves out the imports of the
|
|
209
|
-
// branches the values keep from running (`if (__DEV__)` under __DEV__=false). JS-only.
|
|
210
173
|
if (values.define !== undefined && !allJs) throw new Error('--define is only valid for JS bundles')
|
|
211
174
|
const define = values.define === undefined ? undefined : parseDefineFlags(null, values.define)
|
|
212
175
|
return { mappingFile: values.mapping, manifests, scope: values.scope, conditions, mainFields, metro, metroResolver, babel, babelAliases: values['babel-aliases'], platforms, jsx, flow, typescript, tsconfig: values.tsconfig, resources, define, packageJSON, cargo, cargoFeatures, cargoNoDefaultFeatures, cargoAllFeatures, cargoTarget, cargoManifests }
|
|
213
176
|
}
|
|
214
177
|
|
|
215
|
-
// The CONSENT_FLAGS that run a program of the project's from disk,
|
|
216
|
-
// disk: none that --deptree lays out in memory.
|
|
178
|
+
// The CONSENT_FLAGS that run a program of the project's from disk, where --deptree installs nothing.
|
|
217
179
|
const DISK_RUN_FLAGS = ['babel', 'metro-resolver']
|
|
218
180
|
|
|
219
|
-
|
|
220
|
-
function outputOptions(values, { allJs, allSol }) {
|
|
181
|
+
function outputOptions(values, { allJs, allSol, jsAndSol }) {
|
|
221
182
|
if (values.lockfile && !allJs) throw new Error('--lockfile is only valid for JS bundles')
|
|
222
|
-
// --deptree: the dependencies laid out in memory from the lockfile (pnpm, yarn 1, npm or Soldeer's),
|
|
223
|
-
// never read from disk, which holds none.
|
|
224
183
|
const deptree = Boolean(values.deptree)
|
|
225
|
-
if (deptree && !allJs && !allSol) throw new Error('--deptree is only valid for JS and .sol bundles')
|
|
184
|
+
if (deptree && !allJs && !allSol && !jsAndSol) throw new Error('--deptree is only valid for JS and .sol bundles')
|
|
226
185
|
for (const flag of deptree ? DISK_RUN_FLAGS : []) {
|
|
227
186
|
if (values[flag]) throw new Error(`--${flag} can't be combined with --deptree (it runs ${CONSENT_FLAGS.get(flag)} from disk, where --deptree installs nothing)`)
|
|
228
187
|
}
|
|
229
|
-
// --brotli-quality: valid for every entry language (no allJs gate).
|
|
230
188
|
const brotliQuality = values['brotli-quality'] === undefined ? undefined : parseBrotliQuality('--brotli-quality', values['brotli-quality'])
|
|
231
|
-
// --add merges into the existing bundle at --output, so it can't target write-only stdout.
|
|
232
189
|
const add = Boolean(values.add)
|
|
233
190
|
if (add && values.output === '-') throw new Error('--add cannot be combined with --output=-')
|
|
234
|
-
|
|
191
|
+
const lockfileOnly = Boolean(values['lockfile-only'])
|
|
192
|
+
const lockfileOnlyRefused = lockfileOnly ? lockfileOnlyError({ lockfile: values.lockfile, output: values.output, add, brotliQuality: values['brotli-quality'] }) : null
|
|
193
|
+
if (lockfileOnlyRefused !== null) throw new Error(lockfileOnlyRefused)
|
|
194
|
+
return { output: values.output, lockfile: values.lockfile, lockfileOnly, brotliQuality, add, deptree }
|
|
235
195
|
}
|
|
236
196
|
|
|
237
|
-
// An entry's options in stasis.config.json's `entries`
|
|
238
|
-
//
|
|
239
|
-
// taking a value, which a list flag takes as an array too, and an array of it for a repeatable one
|
|
240
|
-
// (each of a REPEATED_FLAGS one's values, as given).
|
|
197
|
+
// An entry's options in stasis.config.json's `entries` as parseArgs would give the flags they alias: `true`
|
|
198
|
+
// for a boolean set (`false` is no flag), a list flag's array as one string, a REPEATED_FLAGS one's as given.
|
|
241
199
|
function entryFlags(what, options) {
|
|
242
200
|
if (!isPlainObject(options)) throw new Error(`${what} must be an object of stasis bundle options`)
|
|
243
201
|
const values = {}
|
|
244
202
|
for (const [flag, value] of Object.entries(options)) {
|
|
203
|
+
if (POLICY_KEYS.includes(flag)) continue
|
|
245
204
|
if (OUTPUT_FLAGS.has(flag)) throw new Error(`${what}: ${flag} is the bundle's option, not an entry's: pass --${flag}`)
|
|
246
205
|
if (!Object.hasOwn(BUNDLE_FLAGS, flag)) throw new Error(`${what}: unknown option ${JSON.stringify(flag)}`)
|
|
247
206
|
const { type, multiple } = BUNDLE_FLAGS[flag]
|
|
@@ -263,9 +222,7 @@ function entryFlags(what, options) {
|
|
|
263
222
|
return values
|
|
264
223
|
}
|
|
265
224
|
|
|
266
|
-
// The `entries` of the stasis.config.json in `cwd
|
|
267
|
-
// -> { entry: the name as written, values: its options as flags (entryFlags') }. null where there is
|
|
268
|
-
// none.
|
|
225
|
+
// The `entries` of the stasis.config.json in `cwd`, by entryKey; an entry's own Policy is held beside the config's.
|
|
269
226
|
export function readConfigEntries(cwd = process.cwd(), host = diskHost) {
|
|
270
227
|
const entries = readConfigFile(undefined, cwd, host)?.entries
|
|
271
228
|
if (entries === undefined) return null
|
|
@@ -276,29 +233,31 @@ export function readConfigEntries(cwd = process.cwd(), host = diskHost) {
|
|
|
276
233
|
const key = isAbsolute(entry) ? null : entryKey(cwd, entry)
|
|
277
234
|
if (key === null) throw new Error(`${what}: an entry must be a path relative to the directory of ${CONFIG_FILE}, within it`)
|
|
278
235
|
if (named.has(key)) throw new Error(`${what} names the same entry as ${JSON.stringify(named.get(key).entry)}`)
|
|
279
|
-
|
|
236
|
+
const values = entryFlags(what, options)
|
|
237
|
+
const policy = parsePolicy(what, options)
|
|
238
|
+
named.set(key, { entry, values, ...(policy !== null && { policy }) })
|
|
280
239
|
}
|
|
281
240
|
return named
|
|
282
241
|
}
|
|
283
242
|
|
|
284
|
-
//
|
|
285
|
-
//
|
|
286
|
-
// built with its options there, the ones with the same options together (a build each), and none
|
|
287
|
-
// may be given as a flag but the bundle's own (OUTPUT_FLAGS) and the consent to a CONSENT_FLAGS
|
|
288
|
-
// option, which an entry setting it needs and some entry must set. Where it names none, they are all
|
|
289
|
-
// built with the flags; it may not name only some. A usage error throws.
|
|
243
|
+
// Where `config` names every entry, each is built with its options there, the flags given only the bundle's own
|
|
244
|
+
// and the consent its CONSENT_FLAGS need; where it names none, all are built with the flags.
|
|
290
245
|
export function bundlePlan({ cwd = process.cwd(), entries, values, config = null }) {
|
|
291
246
|
const lang = entriesLanguage(entries, cwd)
|
|
292
247
|
const output = outputOptions(values, lang)
|
|
293
|
-
const keys
|
|
294
|
-
|
|
295
|
-
if (
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
248
|
+
const { keys, first } = configuredKeys(cwd, entries, config)
|
|
249
|
+
if (first === undefined && !lang.jsAndSol) return { ...output, entries, ...buildOptions(values, lang) }
|
|
250
|
+
if (first === undefined) {
|
|
251
|
+
return { ...output, builds: [...Map.groupBy(entries, isJsEntry).values()].map((part) => {
|
|
252
|
+
try {
|
|
253
|
+
return { entries: part, ...buildOptions(values, entriesLanguage(part, cwd)) }
|
|
254
|
+
} catch (cause) {
|
|
255
|
+
throw new Error(`${cause.message}, and ${part[0]} is not of one: give the JS and .sol entries' options apart, in ${CONFIG_FILE}'s entries`, { cause })
|
|
256
|
+
}
|
|
257
|
+
}) }
|
|
299
258
|
}
|
|
300
259
|
const flag = Object.keys(values).find((name) => !OUTPUT_FLAGS.has(name) && !CONSENT_FLAGS.has(name))
|
|
301
|
-
if (flag !== undefined) throw new Error(`--${flag} can't be given for ${
|
|
260
|
+
if (flag !== undefined) throw new Error(`--${flag} can't be given for ${first}, whose options ${CONFIG_FILE}'s entries set: set it there`)
|
|
302
261
|
const named = keys.map((key) => config.get(key))
|
|
303
262
|
for (const consent of CONSENT_FLAGS.keys()) {
|
|
304
263
|
const given = values[consent]
|
|
@@ -314,28 +273,34 @@ export function bundlePlan({ cwd = process.cwd(), entries, values, config = null
|
|
|
314
273
|
const consent = flagText(unconsented, flags[unconsented])
|
|
315
274
|
throw new Error(`${CONFIG_FILE}: entries ${JSON.stringify(name)} sets ${consent.slice(2)}, which runs ${CONSENT_FLAGS.get(unconsented)}: pass ${consent} to allow it`)
|
|
316
275
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
} catch (cause) {
|
|
321
|
-
throw new Error(`${CONFIG_FILE}: entries ${JSON.stringify(name)}: ${cause.message}`, { cause })
|
|
322
|
-
}
|
|
323
|
-
const id = JSON.stringify(options)
|
|
324
|
-
if (builds.has(id)) builds.get(id).entries.push(entry)
|
|
325
|
-
else builds.set(id, { entries: [entry], ...options })
|
|
276
|
+
const what = `${CONFIG_FILE}: entries ${JSON.stringify(name)}: `
|
|
277
|
+
const language = prefixed(what, () => entriesLanguage([entry], cwd))
|
|
278
|
+
addToBuild(builds, entry, named[i], prefixed(what, () => buildOptions(flags, language)), language)
|
|
326
279
|
}
|
|
327
|
-
return { ...output, builds:
|
|
280
|
+
return { ...output, builds: withPolicies(builds) }
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// To the build of the same language, options and Policy (the first entry's, relabelled by withPolicies).
|
|
284
|
+
function addToBuild(builds, entry, named, options, language) {
|
|
285
|
+
const id = JSON.stringify([language, options, named.policy?.key])
|
|
286
|
+
const build = upsert(builds, id, () => ({ entries: [], ...options, written: [], policy: named.policy }))
|
|
287
|
+
build.entries.push(entry)
|
|
288
|
+
build.written.push(named.entry)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function withPolicies(builds, prefix = '') {
|
|
292
|
+
return [...builds.values()].map(({ written, policy, ...build }) => (policy === undefined ? build
|
|
293
|
+
: { ...build, policy: policy.withLabel(`${prefix}${CONFIG_FILE}: entries ${written.map((entry) => JSON.stringify(entry)).join(', ')}`) }))
|
|
328
294
|
}
|
|
329
295
|
|
|
330
|
-
// buildOptions' options, each by the flag it is given as; and those whose values are a set, in
|
|
331
|
-
// whatever order given (each value of `resources` as parseResourcesOption takes it).
|
|
332
296
|
const OPTION_FLAGS = {
|
|
333
297
|
mappingFile: 'mapping', manifests: 'manifests', scope: 'scope', conditions: 'conditions', mainFields: 'mainFields', metro: 'metro', metroResolver: 'metro-resolver', babel: 'babel', babelAliases: 'babel-aliases', platforms: 'platforms', jsx: 'jsx', flow: 'flow', typescript: 'typescript', tsconfig: 'tsconfig', resources: 'resources', define: 'define', packageJSON: 'package-json', cargo: 'cargo', cargoFeatures: 'cargo-features', cargoNoDefaultFeatures: 'cargo-no-default-features', cargoAllFeatures: 'cargo-all-features', cargoTarget: 'cargo-target', cargoManifests: 'cargo-manifests',
|
|
334
298
|
}
|
|
299
|
+
// Those whose values are a set, in whatever order given.
|
|
335
300
|
const SET_OPTIONS = new Set(['conditions', 'platforms', 'resources', 'cargoFeatures'])
|
|
336
|
-
// buildOptions' options where no flag is given.
|
|
337
301
|
const DEFAULT_OPTIONS = buildOptions({}, {})
|
|
338
|
-
// An option's value as compared: a set's sorted
|
|
302
|
+
// An option's value as compared: a set's sorted (each of `resources` as parseResourcesOption takes it), defines
|
|
303
|
+
// by name, 'null' for no value or no define.
|
|
339
304
|
const comparable = (key, value) => {
|
|
340
305
|
if (value === undefined || value === null || (key === 'define' && isPlainObject(value) && Object.keys(value).length === 0)) return 'null'
|
|
341
306
|
if (key === 'resources' && Array.isArray(value)) value = value.map((v) => (typeof v === 'string' ? v.toLowerCase().replace(/^\./u, '') : v))
|
|
@@ -343,62 +308,40 @@ const comparable = (key, value) => {
|
|
|
343
308
|
if (key === 'define' && isPlainObject(value)) return JSON.stringify(Object.entries(value).toSorted(([a], [b]) => (a < b ? -1 : 1)))
|
|
344
309
|
return JSON.stringify(value)
|
|
345
310
|
}
|
|
346
|
-
// An option as its flags give it: `--jsx`, `--platforms=ios,android`, `--define=__DEV__=false`.
|
|
347
311
|
const optionText = (key, value) => (key === 'define'
|
|
348
312
|
? Object.entries(value).map(([name, v]) => `--define=${name}=${JSON.stringify(v)}`).join(' ')
|
|
349
313
|
: flagText(OPTION_FLAGS[key], Array.isArray(value) ? value.join(',') : value))
|
|
350
314
|
|
|
351
|
-
// The builds of `entries`
|
|
352
|
-
//
|
|
353
|
-
// (@exodus/stasis/vfs-bundle's): every entry it names where none are given (none, of an empty
|
|
354
|
-
// `entries`: nothing else stands in for them), as paths from `cwd`.
|
|
355
|
-
// -> { entries, builds }, each build `{ entries, ...options }` with the options there (buildOptions'),
|
|
356
|
-
// the entries with the same ones together; null where it names none of those given, or has no
|
|
357
|
-
// `entries`: they are built with `options` alone. It may not name only some. Each of `options`
|
|
358
|
-
// (buildOptions' shape) given other than at its default has to be the one each entry's options
|
|
359
|
-
// set, else it is refused, neither taken over them nor left aside; one left out is theirs. One that
|
|
360
|
-
// runs a program (CONSENT_FLAGS'), set by an entry or given, is refused: nothing of the project
|
|
361
|
-
// runs, so no option allows it. A usage error throws.
|
|
315
|
+
// The builds of `entries` (by default, all it names) the config names, for a bundle of a project it runs nothing
|
|
316
|
+
// of (vfs-bundle's), or null where it names none. Each option given off its default must be what each entry sets.
|
|
362
317
|
export function configuredBuilds(name, { cwd, host = diskHost, entries, options = {} }) {
|
|
363
|
-
const
|
|
364
|
-
try {
|
|
365
|
-
return fn()
|
|
366
|
-
} catch (cause) {
|
|
367
|
-
throw new Error(`${what}${cause.message}`, { cause })
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const config = prefixed(() => readConfigEntries(cwd, host))
|
|
318
|
+
const config = prefixed(`${name}: `, () => readConfigEntries(cwd, host))
|
|
371
319
|
if (config === null || (entries !== undefined && !Array.isArray(entries))) return null
|
|
372
320
|
if (entries === undefined) {
|
|
373
321
|
entries = [...config.keys()]
|
|
374
322
|
if (entries.length === 0) return { entries, builds: [] }
|
|
375
323
|
}
|
|
376
|
-
const keys
|
|
377
|
-
|
|
378
|
-
if (configured.length === 0) return null
|
|
379
|
-
const unnamed = entries.find((_, i) => !config.has(keys[i]))
|
|
380
|
-
if (unnamed !== undefined) {
|
|
381
|
-
throw new Error(`${name}: ${CONFIG_FILE}'s entries name ${configured[0]} but not ${unnamed}: bundle either the entries it names or others, not both`)
|
|
382
|
-
}
|
|
324
|
+
const { keys, first } = configuredKeys(cwd, entries, config, `${name}: `)
|
|
325
|
+
if (first === undefined) return null
|
|
383
326
|
const given = Object.keys(OPTION_FLAGS).filter((key) => options[key] !== undefined && comparable(key, options[key]) !== comparable(key, DEFAULT_OPTIONS[key]))
|
|
384
327
|
const builds = new Map()
|
|
385
328
|
for (const [i, entry] of entries.entries()) {
|
|
386
|
-
const
|
|
329
|
+
const named = config.get(keys[i])
|
|
330
|
+
const { entry: written, values } = named
|
|
387
331
|
const what = `${name}: ${CONFIG_FILE}: entries ${JSON.stringify(written)}`
|
|
388
332
|
const running = [...CONSENT_FLAGS.keys()].find((flag) => values[flag] !== undefined)
|
|
389
333
|
if (running !== undefined) throw new Error(`${what} sets ${running}, which runs ${CONSENT_FLAGS.get(running)}, and nothing of the project runs here`)
|
|
390
|
-
const
|
|
334
|
+
const language = prefixed(`${what}: `, () => entriesLanguage([entry], cwd, host))
|
|
335
|
+
const built = prefixed(`${what}: `, () => buildOptions(values, language))
|
|
391
336
|
for (const key of given) {
|
|
392
337
|
if (CONSENT_FLAGS.has(OPTION_FLAGS[key])) continue
|
|
393
338
|
if (comparable(key, options[key]) === comparable(key, built[key])) continue
|
|
394
339
|
const set = comparable(key, built[key]) === comparable(key, DEFAULT_OPTIONS[key]) ? `without --${OPTION_FLAGS[key]}` : `with ${optionText(key, built[key])}`
|
|
395
340
|
throw new Error(`${name}: ${optionText(key, options[key])} is given, but ${CONFIG_FILE}'s entries build ${JSON.stringify(written)} ${set}: an entry it names is built with its options there`)
|
|
396
341
|
}
|
|
397
|
-
|
|
398
|
-
if (builds.has(id)) builds.get(id).entries.push(entry)
|
|
399
|
-
else builds.set(id, { entries: [entry], ...built })
|
|
342
|
+
addToBuild(builds, entry, named, built, language)
|
|
400
343
|
}
|
|
401
344
|
const running = given.find((key) => CONSENT_FLAGS.has(OPTION_FLAGS[key]))
|
|
402
345
|
if (running !== undefined) throw new Error(`${name}: ${optionText(running, options[running])} is given, which runs ${CONSENT_FLAGS.get(OPTION_FLAGS[running])}, and nothing of the project runs here`)
|
|
403
|
-
return { entries, builds:
|
|
346
|
+
return { entries, builds: withPolicies(builds, `${name}: `) }
|
|
404
347
|
}
|