@exodus/stasis 1.0.0-beta.15 → 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/README.md +1 -1
- package/bin/stasis.js +26 -11
- 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 +861 -1344
- package/src/cmd/diff.js +1 -4
- package/src/cmd/github-bundle.js +46 -27
- package/src/cmd/output.js +17 -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 +88 -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
package/src/babel.js
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
// Per-file Babel pre-transforms for `stasis build
|
|
2
|
-
//
|
|
3
|
-
// --platform=hermes downlevels every code file to the dialect Hermes (React Native's
|
|
4
|
-
// engine) executes -- no classes, class fields, let/const, arrows, async generators or
|
|
5
|
-
// for-await. Two steps per file, then a constrained final bundle:
|
|
6
|
-
// 1. esbuild.transform lowers class fields / private members / static blocks / `using`
|
|
7
|
-
// into plain class syntax (stripping TS types and compiling JSX on the way), the
|
|
8
|
-
// shape Babel's class transform can consume.
|
|
9
|
-
// 2. A Babel worker pool applies transform-block-scoping + transform-classes -- the two
|
|
10
|
-
// lowerings esbuild refuses to do itself.
|
|
11
|
-
// 3. The final esbuild bundle runs with HERMES_UNSUPPORTED (arrow/async-generator/
|
|
12
|
-
// for-await lowered by esbuild; class and const-and-let declared unsupported both so
|
|
13
|
-
// esbuild's own helpers stay Hermes-safe and as a fail-closed check that none
|
|
14
|
-
// survived Babel).
|
|
15
|
-
//
|
|
16
|
-
// --babel instead runs each code file through the project's own babel.config.* verbatim --
|
|
17
|
-
// no esbuild pre-transform, Babel sees the original source exactly as the project's own
|
|
18
|
-
// toolchain (e.g. Metro) would hand it over.
|
|
19
|
-
//
|
|
20
|
-
// `stasis bundle --metro --babel` takes only the import aliases from that config (see
|
|
21
|
-
// createBabelAliases): the scan still reads each file's own source. `--babel-aliases` takes the same
|
|
22
|
-
// aliases from a JSON file instead, mapped here as the plugin maps them (createAliases), so nothing
|
|
23
|
-
// of the project's runs.
|
|
24
|
-
//
|
|
25
|
-
// Babel is the PROJECT's dev dependency, not stasis's: @babel/core (and, for hermes, the
|
|
26
|
-
// two transform plugins) resolve from the project directory, so the project pins its own
|
|
27
|
-
// Babel toolchain and config semantics.
|
|
1
|
+
// Per-file Babel pre-transforms for `stasis build` (--platform=hermes, --babel), and the import aliases `stasis bundle
|
|
2
|
+
// --metro --babel` takes from the project's config. Babel is the project's dev dependency, never stasis's own.
|
|
28
3
|
import { existsSync } from 'node:fs'
|
|
29
4
|
import { createRequire } from 'node:module'
|
|
30
5
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
31
6
|
|
|
7
|
+
import { memoized } from '@exodus/stasis-core/util'
|
|
8
|
+
|
|
32
9
|
const require = createRequire(import.meta.url)
|
|
33
10
|
|
|
34
11
|
// esbuild `supported` map for the FINAL hermes bundle (spread into esbuild.build options).
|
|
@@ -40,148 +17,98 @@ export const HERMES_UNSUPPORTED = {
|
|
|
40
17
|
'for-await': false,
|
|
41
18
|
}
|
|
42
19
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
'class-field'
|
|
47
|
-
'class-
|
|
48
|
-
|
|
49
|
-
'class-private-field': false,
|
|
50
|
-
'class-private-method': false,
|
|
51
|
-
'class-private-static-accessor': false,
|
|
52
|
-
'class-private-static-field': false,
|
|
53
|
-
'class-private-static-method': false,
|
|
54
|
-
'class-static-blocks': false,
|
|
55
|
-
'class-static-field': false,
|
|
56
|
-
'import-attributes': false,
|
|
57
|
-
using: false,
|
|
58
|
-
}
|
|
20
|
+
// What Babel can't take without extra plugins (and Hermes supports none of), lowered into plain classes first.
|
|
21
|
+
const PRE_TRANSFORM_UNSUPPORTED = Object.fromEntries([
|
|
22
|
+
'class-field', 'class-private-accessor', 'class-private-brand-check', 'class-private-field', 'class-private-method',
|
|
23
|
+
'class-private-static-accessor', 'class-private-static-field', 'class-private-static-method', 'class-static-blocks',
|
|
24
|
+
'class-static-field', 'import-attributes', 'using',
|
|
25
|
+
].map((feature) => [feature, false]))
|
|
59
26
|
|
|
60
27
|
const HERMES_BABEL_PLUGINS = ['@babel/plugin-transform-block-scoping', '@babel/plugin-transform-classes']
|
|
61
28
|
|
|
62
|
-
//
|
|
63
|
-
// --loader override like .svg:text) passes through untouched.
|
|
29
|
+
// Anything else the plugin serves (json, or a --loader override like .svg:text) passes through untouched.
|
|
64
30
|
const TRANSFORMABLE_LOADERS = new Set(['js', 'ts', 'jsx', 'tsx'])
|
|
65
31
|
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
// plugin paths bypass Babel's own name resolution (which would look in the wrong dir).
|
|
32
|
+
// On the main thread, so a missing install fails with instructions, not a worker crash mid-build. Absolute paths:
|
|
33
|
+
// the worker loads @babel/core by path, and plugin paths bypass Babel's own name resolution (from the wrong dir).
|
|
69
34
|
function resolveFromProject(projectDir, deps, flag, command = 'stasis build') {
|
|
70
35
|
const projectRequire = createRequire(join(projectDir, 'noop.js'))
|
|
71
36
|
try {
|
|
72
37
|
return deps.map((dep) => projectRequire.resolve(dep))
|
|
73
38
|
} catch (cause) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
|
|
76
|
-
`(e.g. \`npm i -D ${deps.join(' ')}\`); resolution failed from ${projectDir}`,
|
|
77
|
-
{ cause }
|
|
78
|
-
)
|
|
39
|
+
throw new Error(`${command}: ${flag} needs ${deps.join(', ')} installed in the project `
|
|
40
|
+
+ `(e.g. \`npm i -D ${deps.join(' ')}\`); resolution failed from ${projectDir}`, { cause })
|
|
79
41
|
}
|
|
80
42
|
}
|
|
81
43
|
|
|
82
|
-
//
|
|
83
|
-
// (source, { path, loader }) => { contents, loader } | undefined.
|
|
44
|
+
// In StasisEsbuild's load-mode `transform` hook shape: (source, { path, loader }) => { contents, loader } | undefined.
|
|
84
45
|
export function createHermesTransform({ projectDir, esbuild }) {
|
|
85
|
-
const [babelPath, ...plugins] = resolveFromProject(
|
|
86
|
-
projectDir, ['@babel/core', ...HERMES_BABEL_PLUGINS], '--platform=hermes'
|
|
87
|
-
)
|
|
46
|
+
const [babelPath, ...plugins] = resolveFromProject(projectDir, ['@babel/core', ...HERMES_BABEL_PLUGINS], '--platform=hermes')
|
|
88
47
|
const { transformAsync } = require('./babel-worker.cjs')
|
|
89
48
|
return async (source, { path, loader }) => {
|
|
90
49
|
if (!TRANSFORMABLE_LOADERS.has(loader)) return undefined
|
|
91
50
|
const { code, warnings } = await esbuild.transform(source, {
|
|
92
|
-
sourcemap: 'inline',
|
|
93
|
-
sourcefile: path,
|
|
94
|
-
loader,
|
|
95
|
-
supported: PRE_TRANSFORM_UNSUPPORTED,
|
|
51
|
+
sourcemap: 'inline', sourcefile: path, loader, supported: PRE_TRANSFORM_UNSUPPORTED,
|
|
96
52
|
})
|
|
97
53
|
if (warnings.length > 0) {
|
|
98
54
|
const formatted = await esbuild.formatMessages(warnings, { kind: 'warning', color: false })
|
|
99
55
|
for (const line of formatted) process.stderr.write(line)
|
|
100
56
|
}
|
|
101
|
-
const result = await transformAsync(babelPath, code, {
|
|
102
|
-
compact: false,
|
|
103
|
-
babelrc: false,
|
|
104
|
-
configFile: false,
|
|
105
|
-
plugins,
|
|
106
|
-
})
|
|
57
|
+
const result = await transformAsync(babelPath, code, { compact: false, babelrc: false, configFile: false, plugins })
|
|
107
58
|
// TS is stripped and JSX compiled by the pre-transform, so the result is always plain js.
|
|
108
59
|
return { contents: result.code, loader: 'js' }
|
|
109
60
|
}
|
|
110
61
|
}
|
|
111
62
|
|
|
112
|
-
//
|
|
113
|
-
// the original source. Its output must be esbuild-parseable js -- a config that leaves TS/JSX
|
|
114
|
-
// in place fails the build in Babel or esbuild, which is the project's config to fix.
|
|
63
|
+
// Its output must be esbuild-parseable js: a config that leaves TS/JSX in place is the project's to fix.
|
|
115
64
|
export function createBabelConfigTransform({ projectDir }) {
|
|
116
65
|
const configFile = findBabelConfig(projectDir, 'stasis build')
|
|
117
66
|
const [babelPath] = resolveFromProject(projectDir, ['@babel/core'], '--babel')
|
|
118
67
|
const { transformAsync } = require('./babel-worker.cjs')
|
|
119
68
|
return async (source, { path, loader }) => {
|
|
120
69
|
if (!TRANSFORMABLE_LOADERS.has(loader)) return undefined
|
|
121
|
-
// filename makes per-file config (overrides, .babelrc lookup) behave as in a real run.
|
|
122
|
-
const result = await transformAsync(babelPath, source, {
|
|
123
|
-
cwd: projectDir,
|
|
124
|
-
root: projectDir,
|
|
125
|
-
configFile,
|
|
126
|
-
filename: path,
|
|
127
|
-
compact: false,
|
|
128
|
-
})
|
|
70
|
+
// `filename` makes per-file config (overrides, .babelrc lookup) behave as in a real run.
|
|
71
|
+
const result = await transformAsync(babelPath, source, { cwd: projectDir, root: projectDir, configFile, filename: path, compact: false })
|
|
129
72
|
return { contents: result.code, loader: 'js' }
|
|
130
73
|
}
|
|
131
74
|
}
|
|
132
75
|
|
|
133
|
-
// The project's babel.config.(js|cjs|mjs|json), the one --babel takes.
|
|
134
76
|
function findBabelConfig(projectDir, command) {
|
|
135
77
|
const configFile = ['babel.config.js', 'babel.config.cjs', 'babel.config.mjs', 'babel.config.json']
|
|
136
78
|
.map((name) => join(projectDir, name))
|
|
137
79
|
.find((file) => existsSync(file))
|
|
138
|
-
if (!configFile) {
|
|
139
|
-
throw new Error(`${command}: --babel found no babel.config.(js|cjs|mjs|json) in ${projectDir}`)
|
|
140
|
-
}
|
|
80
|
+
if (!configFile) throw new Error(`${command}: --babel found no babel.config.(js|cjs|mjs|json) in ${projectDir}`)
|
|
141
81
|
return configFile
|
|
142
82
|
}
|
|
143
83
|
|
|
144
|
-
//
|
|
145
|
-
// transformer loads it (its `metro` caller, for `platform`) by @babel/core's `method` (loadPartialConfig,
|
|
146
|
-
// loadOptions) -- the config is project code, run here. -> (file) => what it loads, once a file
|
|
84
|
+
// Loaded as Metro's transformer loads it (its `metro` caller): the config is project code, run here.
|
|
147
85
|
function projectBabelConfig({ projectDir, platform }, method) {
|
|
148
86
|
const configFile = findBabelConfig(projectDir, 'stasis bundle')
|
|
149
87
|
const [babelPath] = resolveFromProject(projectDir, ['@babel/core'], '--babel', 'stasis bundle')
|
|
150
88
|
const babel = require(babelPath)
|
|
151
89
|
const caller = { name: 'metro', bundler: 'metro', platform }
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
} catch (cause) {
|
|
158
|
-
throw new Error(`stasis bundle: --babel could not load ${configFile} for ${file}`, { cause })
|
|
159
|
-
}
|
|
90
|
+
return memoized((file) => {
|
|
91
|
+
try {
|
|
92
|
+
return babel[method]({ cwd: projectDir, root: projectDir, configFile, filename: file, caller })
|
|
93
|
+
} catch (cause) {
|
|
94
|
+
throw new Error(`stasis bundle: --babel could not load ${configFile} for ${file}`, { cause })
|
|
160
95
|
}
|
|
161
|
-
|
|
162
|
-
}
|
|
96
|
+
})
|
|
163
97
|
}
|
|
164
98
|
|
|
165
|
-
// The file a plugin item names babel-plugin-module-resolver by resolves into this.
|
|
166
99
|
const MODULE_RESOLVER = /[\\/]node_modules[\\/]babel-plugin-module-resolver[\\/]/u
|
|
167
100
|
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
// resolvePath (or the config's custom one) maps each specifier, its `cwd` the project's where the
|
|
171
|
-
// config sets none, as Metro started there has it. Every instance the config lists, by name or as a
|
|
172
|
-
// value (`require`d or imported), counts, in order; one a preset adds doesn't.
|
|
173
|
-
// -> (file, specifier) => the specifier the plugin rewrites it to, else null
|
|
101
|
+
// The aliases babel-plugin-module-resolver applies under the project's babel.config.*: each instance the config lists
|
|
102
|
+
// counts, in order; one a preset adds doesn't. -> (file, specifier) => the specifier it is rewritten to, else null
|
|
174
103
|
export function createBabelAliases({ projectDir, platform }) {
|
|
175
104
|
const partialConfig = projectBabelConfig({ projectDir, platform }, 'loadPartialConfig')
|
|
176
|
-
// The project's own copy, which a config passing the plugin as a value passes
|
|
177
|
-
// project installs none.
|
|
105
|
+
// The project's own copy, which a config passing the plugin as a value passes.
|
|
178
106
|
let projectPlugin
|
|
179
107
|
try {
|
|
180
|
-
projectPlugin =
|
|
108
|
+
projectPlugin = createRequire(join(projectDir, 'noop.js'))('babel-plugin-module-resolver')
|
|
181
109
|
} catch {
|
|
182
110
|
projectPlugin = null
|
|
183
111
|
}
|
|
184
|
-
// The module of a module-resolver plugin item, else null.
|
|
185
112
|
const moduleOf = (plugin) => {
|
|
186
113
|
const resolved = plugin.file?.resolved
|
|
187
114
|
if (resolved !== undefined) return MODULE_RESOLVER.test(resolved) ? require(resolved) : null
|
|
@@ -195,21 +122,17 @@ export function createBabelAliases({ projectDir, platform }) {
|
|
|
195
122
|
const options = { cwd: projectDir, ...plugin.options }
|
|
196
123
|
const resolvePath = typeof options.resolvePath === 'function' ? options.resolvePath : module.resolvePath
|
|
197
124
|
const mapped = resolvePath(specifier, file, options)
|
|
198
|
-
// The first instance mapping it wins: the plugin marks the path it writes resolved, which
|
|
199
|
-
// later instances leave as it is.
|
|
125
|
+
// The first instance mapping it wins: the plugin marks the path it writes resolved, which later ones leave be.
|
|
200
126
|
if (mapped) return typeof mapped === 'string' && mapped !== specifier ? mapped : null
|
|
201
127
|
}
|
|
202
128
|
return null
|
|
203
129
|
}
|
|
204
130
|
}
|
|
205
131
|
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
// `onlyRemoveTypeImports`, under the project's babel.config.* (projectBabelConfig's options).
|
|
209
|
-
// -> (file) => boolean
|
|
132
|
+
// Whether Babel keeps a statement listing types alone (as `import {} from`), as `onlyRemoveTypeImports` has it.
|
|
133
|
+
// No options: the config ignores the file.
|
|
210
134
|
export function createBabelTypeImportsKept({ projectDir, platform }) {
|
|
211
135
|
const options = projectBabelConfig({ projectDir, platform }, 'loadOptions')
|
|
212
|
-
// No options: the config ignores the file.
|
|
213
136
|
return (file) => (options(file)?.plugins ?? []).some((plugin) => plugin.key === 'transform-typescript' && plugin.options?.onlyRemoveTypeImports === true)
|
|
214
137
|
}
|
|
215
138
|
|
|
@@ -221,13 +144,8 @@ const toLocalPath = (path) => {
|
|
|
221
144
|
}
|
|
222
145
|
const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')
|
|
223
146
|
|
|
224
|
-
// --babel-aliases
|
|
225
|
-
//
|
|
226
|
-
// createBabelAliases has it: a key starting with `^` or ending with `$` is a regular expression whose
|
|
227
|
-
// groups the value's `\N` take, any other matches the specifier it is or one it starts with and `/`,
|
|
228
|
-
// whose rest the value keeps; the first key matching wins. A value starting with `./` or `../` is a
|
|
229
|
-
// path from `cwd`, written relative to the importing file; any other is the specifier as it is.
|
|
230
|
-
// -> (file, specifier) => the specifier it rewrites it to, else null
|
|
147
|
+
// --babel-aliases: babel-plugin-module-resolver's `alias` option as data, mapped as the plugin maps it, the first key
|
|
148
|
+
// matching winning. A `./` or `../` value is a path from `cwd`.
|
|
231
149
|
export function createAliases(alias, cwd) {
|
|
232
150
|
const matchers = Object.entries(alias).map(([key, value]) => {
|
|
233
151
|
// As the plugin builds them: a key's own pattern, unflagged (`u` would refuse some it takes).
|
|
@@ -240,7 +158,6 @@ export function createAliases(alias, cwd) {
|
|
|
240
158
|
for (const [regExp, substitute] of matchers) {
|
|
241
159
|
const groups = regExp.exec(specifier)
|
|
242
160
|
if (groups === null) continue
|
|
243
|
-
// None where the mapping is empty.
|
|
244
161
|
const mapped = substitute(groups)
|
|
245
162
|
if (!mapped) return null
|
|
246
163
|
const rewritten = isRelativePath(mapped) ? toLocalPath(relative(dirname(file), resolve(cwd, mapped)).replace(/\\/gu, '/')) : mapped
|
|
@@ -6,10 +6,8 @@ import { Bundle } from '@exodus/stasis-core/bundle'
|
|
|
6
6
|
import { sha512integrity } from '@exodus/stasis-core/state-util'
|
|
7
7
|
import { moduleFileKey, moduleInfo, narrowExecutable } from '@exodus/stasis-core/util'
|
|
8
8
|
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// trustworthy as a `stasis run --lock=frozen` replay. `root` is what the lockfile's paths are
|
|
12
|
-
// relative to. Directory captures (format 'directory') are skipped -- not files esbuild can load.
|
|
9
|
+
// An in-memory Bundle of a lockfile, each attested file read from disk under `root` and held to its SRI digest, as a
|
|
10
|
+
// `stasis run --lock=frozen` replay holds it. A directory capture (format 'directory') is no file to load.
|
|
13
11
|
export function bundleFromLockfile(lockfile, { root }) {
|
|
14
12
|
if (!lockfile.imports) throw new Error('stasis: lockfile has no recorded import graph')
|
|
15
13
|
const formats = lockfile.formats ?? new Map()
|
|
@@ -20,27 +18,18 @@ export function bundleFromLockfile(lockfile, { root }) {
|
|
|
20
18
|
const file = moduleFileKey(dir, rel)
|
|
21
19
|
const format = formats.get(file)
|
|
22
20
|
if (format === 'directory') continue
|
|
23
|
-
const abs = resolve(root, file)
|
|
24
21
|
let bytes
|
|
25
22
|
try {
|
|
26
|
-
bytes = readFileSync(
|
|
23
|
+
bytes = readFileSync(resolve(root, file))
|
|
27
24
|
} catch (cause) {
|
|
28
25
|
throw new Error(`stasis: file attested by the lockfile is missing on disk: ${file}`, { cause })
|
|
29
26
|
}
|
|
30
|
-
// The lockfile digests raw on-disk bytes; verify before trusting the file.
|
|
31
27
|
const actual = sha512integrity(bytes)
|
|
32
|
-
if (actual !== integrity) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// content from the verified bytes -- mirror the capture side's isUtf8 guard and fail closed.
|
|
38
|
-
if (format === 'resource:base64') {
|
|
39
|
-
out[rel] = bytes.toString('base64')
|
|
40
|
-
} else {
|
|
41
|
-
if (!isUtf8(bytes)) throw new Error(`stasis: ${file} is recorded as '${format ?? 'code'}' but is not valid UTF-8`)
|
|
42
|
-
out[rel] = bytes.toString('utf8')
|
|
43
|
-
}
|
|
28
|
+
if (actual !== integrity) throw new Error(`stasis: ${file} does not match the lockfile (expected ${integrity}, got ${actual})`)
|
|
29
|
+
// Non-base64 must be UTF-8: a lossy transcode (U+FFFD) would serve other bytes than those verified.
|
|
30
|
+
const base64 = format === 'resource:base64'
|
|
31
|
+
if (!base64 && !isUtf8(bytes)) throw new Error(`stasis: ${file} is recorded as '${format ?? 'code'}' but is not valid UTF-8`)
|
|
32
|
+
out[rel] = bytes.toString(base64 ? 'base64' : 'utf8')
|
|
44
33
|
}
|
|
45
34
|
modules.set(dir, moduleInfo({ ...info, files: out }))
|
|
46
35
|
}
|
|
@@ -50,8 +39,7 @@ export function bundleFromLockfile(lockfile, { root }) {
|
|
|
50
39
|
modules,
|
|
51
40
|
imports: lockfile.imports,
|
|
52
41
|
formats,
|
|
53
|
-
//
|
|
54
|
-
// keeping Bundle.parse's rules true for a hand-built lockfile too.
|
|
42
|
+
// To the files carried (a skipped `directory` drops out), keeping Bundle.parse's rules true for a hand-built lockfile.
|
|
55
43
|
executable: narrowExecutable(lockfile.executable, { modules, formats, scope: lockfile.config.scope }),
|
|
56
44
|
})
|
|
57
45
|
}
|
package/src/bundle-reader.js
CHANGED
|
@@ -19,9 +19,8 @@ const untilAborted = (promise, signal) => (signal === undefined ? promise : new
|
|
|
19
19
|
// Left in place of each streamed file; fromJSON's contents-free mode requires one per file.
|
|
20
20
|
const STREAMED = Symbol('streamed')
|
|
21
21
|
|
|
22
|
-
// parseBundleBytes(source), without holding the decompressed bytes or the JSON text whole.
|
|
23
|
-
//
|
|
24
|
-
// validated: what it receives (format included) is provisional until readBundle resolves. See doc/file-formats.md.
|
|
22
|
+
// parseBundleBytes(source), without holding the decompressed bytes or the JSON text whole. onFile gets each file in
|
|
23
|
+
// stream order, before the bundle is validated: what it receives is provisional until readBundle resolves.
|
|
25
24
|
export async function readBundle(source, { onFile, signal } = {}) {
|
|
26
25
|
assert(onFile === undefined || typeof onFile === 'function', 'readBundle: onFile must be a function')
|
|
27
26
|
let input = source
|
|
@@ -47,10 +46,8 @@ export async function readBundle(source, { onFile, signal } = {}) {
|
|
|
47
46
|
|
|
48
47
|
// Big chunks let zlib's thread pool decompress ahead of the parser; zlib's 16 KiB default runs about 2x slower.
|
|
49
48
|
const decompress = createBrotliDecompress({ chunkSize: 1024 * 1024, readableHighWaterMark: 4 * 1024 * 1024 })
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
// Counting them here takes `input` out of pipeline's hands, so this destroys a stream on pipeline's
|
|
53
|
-
// signal, raised on any failure or abort, as pipeline would: one waiting for a chunk holds it open.
|
|
49
|
+
// Bytes given past the decoder's bytesWritten are trailing junk. Counting them takes `input` out of pipeline's
|
|
50
|
+
// hands, so this destroys it on pipeline's signal as pipeline would: one waiting for a chunk holds it open.
|
|
54
51
|
let given = 0
|
|
55
52
|
async function* counted({ signal: stop }) {
|
|
56
53
|
const destroy = () => input.destroy?.()
|
|
@@ -85,8 +82,7 @@ export async function readBundle(source, { onFile, signal } = {}) {
|
|
|
85
82
|
const bundle = Bundle.fromJSON(parser.end(), { contents: !onFile })
|
|
86
83
|
if (onFile) {
|
|
87
84
|
// fromJSON required a placeholder per file, so onFile got each one; it must have got nothing else.
|
|
88
|
-
|
|
89
|
-
for (const [, info] of bundle.modules) files += Object.keys(info.files).length
|
|
85
|
+
const files = bundle.modules.values().reduce((sum, info) => sum + Object.keys(info.files).length, 0)
|
|
90
86
|
assert(delivered.size === files, 'bundle carries file contents outside its file list')
|
|
91
87
|
// A later `formats` key replaces the one onFile was told about.
|
|
92
88
|
for (const [file, format] of delivered) {
|
package/src/bundle.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
// Public-export adapter: backs `@exodus/stasis/bundle`. The implementation lives in
|
|
2
|
-
// @exodus/stasis-core; internal tooling and tests import `@exodus/stasis-core/bundle`
|
|
3
|
-
// directly, so this file exists only to back the package's `exports` map.
|
|
4
1
|
export * from '@exodus/stasis-core/bundle'
|