@exodus/stasis 1.0.0-beta.0 → 1.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +32 -8
  2. package/bin/stasis.js +389 -214
  3. package/package.json +52 -12
  4. package/src/audit-corrections.js +96 -0
  5. package/src/audit.js +289 -64
  6. package/src/babel-worker.cjs +65 -0
  7. package/src/babel.js +131 -0
  8. package/src/bundle-from-lockfile.js +14 -22
  9. package/src/bundle-reader.js +77 -0
  10. package/src/cmd/build.js +96 -128
  11. package/src/cmd/bundle.js +1121 -654
  12. package/src/cmd/diff.js +2 -19
  13. package/src/cmd/github-bundle.js +39 -0
  14. package/src/cmd/output.js +36 -0
  15. package/src/cmd/sbom.js +7 -19
  16. package/src/diff.js +80 -129
  17. package/src/installed-commits.js +182 -0
  18. package/src/json-stream.js +283 -0
  19. package/src/loader-mock.js +8 -15
  20. package/src/loaders/bash.js +49 -116
  21. package/src/loaders/cargo.js +1716 -0
  22. package/src/loaders/foundry.js +923 -0
  23. package/src/loaders/paths.js +33 -0
  24. package/src/loaders/php.js +375 -402
  25. package/src/loaders/rust.js +3254 -242
  26. package/src/loaders/solidity-ownership.js +531 -0
  27. package/src/loaders/solidity.js +412 -162
  28. package/src/loaders/toml.js +68 -0
  29. package/src/metro-resolver.js +150 -0
  30. package/src/metro-transformer.js +3 -2
  31. package/src/mock.js +57 -165
  32. package/src/parse.js +4 -16
  33. package/src/resolve-fields.js +370 -0
  34. package/src/resolve-node.js +419 -0
  35. package/src/resolve-typescript.js +541 -0
  36. package/src/rollup.js +5 -0
  37. package/src/sbom.js +120 -97
  38. package/src/scan.js +348 -180
  39. package/src/vfs-bundle/entries.js +144 -0
  40. package/src/vfs-bundle/github.js +202 -0
  41. package/src/vfs-bundle/prisma.js +439 -0
  42. package/src/vfs-bundle/soldeer.js +125 -0
  43. package/src/vfs-bundle/tree.js +647 -0
  44. package/src/vfs-bundle.js +80 -0
  45. package/src/why.js +434 -0
  46. package/src/apis/npm/index.js +0 -36
  47. package/src/apis/npm/semver.cjs +0 -44
  48. package/src/cmd/extract.js +0 -193
package/src/cmd/build.js CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
1
+ import { existsSync } from 'node:fs'
2
2
  import { createRequire } from 'node:module'
3
3
  import { dirname, extname, join, relative, resolve, sep } from 'node:path'
4
4
  import { pathToFileURL } from 'node:url'
@@ -7,41 +7,30 @@ import { spawnSync } from 'node:child_process'
7
7
  import { Bundle } from '@exodus/stasis-core/bundle'
8
8
  import { State } from '@exodus/stasis-core/state'
9
9
  import { StasisEsbuild } from '@exodus/stasis-plugins/esbuild'
10
+ import { HERMES_UNSUPPORTED, createBabelConfigTransform, createHermesTransform } from '../babel.js'
10
11
  import { bundleFromLockfile } from '../bundle-from-lockfile.js'
11
12
  import { parseFileWithKind } from '../parse.js'
13
+ import { writeFile } from './output.js'
12
14
 
13
- // Re-exported so `@exodus/stasis/cmd/build` keeps surfacing the lockfile->bundle
14
- // reconstruction alongside the command; the implementation lives in its own module.
15
15
  export { bundleFromLockfile }
16
16
 
17
- // JS/TS entry extensions esbuild can build. esbuild handles JSX/TSX natively (loader
18
- // 'jsx'/'tsx', derived from the extension by the load plugin), and stasis-core already
19
- // classifies .jsx/.tsx as code (CODE_EXTENSIONS), so a bundle/lockfile captured by the
20
- // esbuild/webpack plugins can carry them as entries.
21
17
  const JS_EXTS = new Set(['.js', '.cjs', '.mjs', '.ts', '.cts', '.mts', '.jsx', '.tsx'])
22
18
 
23
- // Allowlist (NOT a blocklist) of per-file formats `stasis build` accepts in an artifact:
24
- // the JS/TS/JSON code formats esbuild builds, plus the non-code payload formats
25
- // (resource/directory) that are inert unless the SELECTED entry imports them. An allowlist
26
- // so a new language format added to `stasis bundle` later (e.g. a future `go`) is rejected
27
- // here by default, rather than slipping through to a cryptic esbuild failure in the build.
19
+ // Allowlist (not blocklist) of per-file formats `stasis build` accepts, so a bundle
20
+ // format added later fails closed here rather than in a cryptic esbuild error.
28
21
  const BUILDABLE_FORMATS = new Set([
29
22
  'module', 'commonjs', 'json', 'module-typescript', 'commonjs-typescript',
30
- 'resource', 'resource:base64', 'directory',
23
+ 'resource', 'resource:base64', 'directory', 'stat:file', 'stat:directory',
31
24
  ])
32
25
 
33
- // esbuild is an OPTIONAL peer dependency: `stasis build` is the only command that
34
- // needs a bundler, so we don't force every stasis install to pull one in. Resolve it
35
- // from the local install first (a peer dep hoisted into the project's node_modules, or
36
- // an npx-provided copy), then fall back to a global install, with an actionable error
37
- // if neither is present.
26
+ // esbuild is an optional peer dep; resolve it from the local install, else fall back
27
+ // to a global one.
38
28
  async function importEsbuild() {
39
29
  let mod
40
30
  try {
41
31
  mod = await import('esbuild')
42
32
  } catch (cause) {
43
- // Only a genuine "not installed" miss falls through to the global lookup; a
44
- // different failure (a corrupt install, a syntax error in esbuild) is surfaced.
33
+ // Only a genuine "not installed" miss falls through to the global lookup; surface other failures.
45
34
  if (cause?.code !== 'ERR_MODULE_NOT_FOUND' && cause?.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
46
35
  throw cause
47
36
  }
@@ -56,14 +45,10 @@ async function importEsbuild() {
56
45
  }
57
46
  mod = await import(pathToFileURL(globalMain).href)
58
47
  }
59
- // esbuild ships a CJS module exposing named exports (build, context, ...); Node's
60
- // interop surfaces them directly. A globally-imported CJS copy may instead land its
61
- // exports on `default` -- accept both shapes.
48
+ // A globally-imported CJS copy may land its exports on `default` -- accept both shapes.
62
49
  return typeof mod.build === 'function' ? mod : mod.default
63
50
  }
64
51
 
65
- // Locate a globally-installed esbuild via the package managers' "global root" commands.
66
- // Returns the absolute path to esbuild's entry, or undefined when none is installed.
67
52
  function resolveGlobalEsbuild() {
68
53
  const probes = [
69
54
  ['npm', ['root', '-g']],
@@ -75,7 +60,7 @@ function resolveGlobalEsbuild() {
75
60
  try {
76
61
  out = spawnSync(cmd, args, { encoding: 'utf8' })
77
62
  } catch {
78
- continue // package manager not installed
63
+ continue
79
64
  }
80
65
  if (!out || out.status !== 0 || !out.stdout) continue
81
66
  const base = out.stdout.trim()
@@ -87,61 +72,77 @@ function resolveGlobalEsbuild() {
87
72
  try {
88
73
  return createRequire(join(nm, 'noop.js')).resolve('esbuild')
89
74
  } catch {
90
- // keep probing
91
75
  }
92
76
  }
93
77
  }
94
78
  return undefined
95
79
  }
96
80
 
97
- // Validate that an artifact is something esbuild can build: full scope (node_modules
98
- // scope omits the entry and workspace code, so it can't be built on its own), at least
99
- // one entry, all entries JS/TS, and only buildable per-file formats (see BUILDABLE_FORMATS).
100
- function assertBuildable(artifact, label) {
81
+ // Preconditions independent of which entry we build. Per-entry language checks are deferred
82
+ // to assertBuildableEntry, once selectEntry has picked one.
83
+ function assertBuildableArtifact(artifact, label) {
101
84
  if (artifact.config.scope !== 'full') {
102
85
  throw new Error(
103
86
  `stasis build requires a full-scope artifact; ${label} is scope='${artifact.config.scope}'. ` +
104
87
  `node_modules-scope artifacts omit the entry and workspace code, so there is nothing to build.`
105
88
  )
106
89
  }
107
- const entries = [...artifact.entries]
108
- if (entries.length === 0) {
90
+ if (artifact.entries.size === 0) {
109
91
  throw new Error(`stasis build: ${label} declares no entries to build`)
110
92
  }
111
- for (const entry of entries) {
112
- if (!JS_EXTS.has(extname(entry))) {
113
- throw new Error(`stasis build only builds JavaScript/TypeScript entries (esbuild); got non-JS entry '${entry}' in ${label}`)
93
+ }
94
+
95
+ // The entry plus its transitive imports in the recorded graph -- the exact set esbuild loads
96
+ // (all conditions buckets; a --metro edge's per-platform targets included).
97
+ function reachableFiles(entry, imports) {
98
+ const seen = new Set([entry])
99
+ const stack = [entry]
100
+ while (stack.length > 0) {
101
+ const parent = stack.pop()
102
+ for (const [, byParent] of imports) {
103
+ const specifiers = byParent.get(parent)
104
+ if (specifiers === undefined) continue
105
+ for (const [, target] of specifiers) {
106
+ // A plain edge is a file string; a --metro edge is a {platform: file} Map.
107
+ const targets = typeof target === 'string' ? [target] : [...target.values()]
108
+ for (const file of targets) {
109
+ if (!seen.has(file)) {
110
+ seen.add(file)
111
+ stack.push(file)
112
+ }
113
+ }
114
+ }
114
115
  }
115
116
  }
116
- // artifact.formats is a Map (Bundle) or may be null on a legacy lockfile (an absent map
117
- // is fine -- nothing to check). Reject any format outside the allowlist: the non-JS
118
- // LANGUAGE bundlers' formats (Solidity/PHP/Bash/Rust) and anything added later.
119
- //
120
- // NOTE: resource formats are IN the allowlist -- deliberately NOT rejected here. A resource
121
- // is recorded as a FILE but never as an import EDGE, so whether a build hits one depends on
122
- // the SELECTED entry's own source, not the artifact as a whole -- a code-only entry must
123
- // build even when the artifact carries assets for OTHER entries. An entry that does import
124
- // an asset fails at build time (esbuild can't resolve the un-graphed resource).
117
+ return seen
118
+ }
119
+
120
+ // Language checks scoped to the built entry: it must be JS/TS, and every file reachable from
121
+ // it must be buildable. A non-JS file elsewhere (another entry, or a `stasis add` attachment)
122
+ // isn't reached, so it doesn't block the build. imports/formats are null on a legacy lockfile.
123
+ function assertBuildableEntry(artifact, entry, label) {
124
+ if (!JS_EXTS.has(extname(entry))) {
125
+ throw new Error(`stasis build only builds JavaScript/TypeScript entries (esbuild); got non-JS entry '${entry}' in ${label}`)
126
+ }
127
+ const reachable = reachableFiles(entry, artifact.imports ?? new Map())
128
+ // A reachable resource (plugin captures DO record asset edges) stays allowed via BUILDABLE_FORMATS;
129
+ // an entry that imports an unbuildable asset fails later at esbuild, not here.
125
130
  for (const [file, format] of artifact.formats ?? new Map()) {
131
+ if (!reachable.has(file)) continue
126
132
  if (!BUILDABLE_FORMATS.has(format)) {
127
133
  throw new Error(`stasis build only supports JavaScript/TypeScript bundles (esbuild); ${label} carries a '${format}' file (${file})`)
128
134
  }
129
135
  }
130
136
  }
131
137
 
132
- // Pick which recorded entry to build. The build produces exactly one entry's bundle;
133
- // `entryArg` selects it. With a single recorded entry the selector is optional (that
134
- // entry is used); with several it is required, and an absent or unknown one is rejected
135
- // with the available list. The selector is matched against the artifact's recorded
136
- // (project-relative) entries -- only those are attested as graph roots, and the load
137
- // plugin's assertEntry rejects anything else -- accepting the recorded path verbatim, a
138
- // leading `./` stripped, or a cwd-relative path normalized into the project root.
138
+ // Pick which recorded entry to build; required only when several are recorded. Matched
139
+ // against the recorded project-relative entries (verbatim, `./`-stripped, or cwd-relative).
139
140
  function selectEntry(entryArg, entries, { cwd, root, label }) {
140
141
  const recorded = [...entries]
141
142
  const list = recorded.map((e) => ` ${e}`).join('\n')
142
143
  if (entryArg === undefined) {
143
144
  if (recorded.length === 1) return recorded[0]
144
- // length === 0 is impossible here (assertBuildable required >= 1 entry).
145
+ // length === 0 is impossible here (assertBuildableArtifact required >= 1 entry).
145
146
  throw new Error(`stasis build: ${label} has ${recorded.length} entry points; pass one as the second argument:\n${list}`)
146
147
  }
147
148
  const candidates = new Set([
@@ -156,13 +157,8 @@ function selectEntry(entryArg, entries, { cwd, root, label }) {
156
157
  return match
157
158
  }
158
159
 
159
- // Build a bundle-load State that serves an in-memory Bundle -- the same shape StasisEsbuild's
160
- // load path reads from (state.sources / state.resources / state.formats / state.imports /
161
- // state.entries). skipDiscovery anchors the State at `root` and does NO filesystem discovery:
162
- // no package.json walk, no on-disk config, no stray stasis.code.br read. bundle=load +
163
- // lock=ignore serve the bundle's own bytes (self-attesting -- the lockfile path already
164
- // SHA-512-verified them in bundleFromLockfile). We mirror State's on-disk load (split
165
- // sources/resources by format) and fill the maps from `bundle`.
160
+ // Build a bundle-load State that serves an in-memory Bundle. skipDiscovery does NO
161
+ // filesystem discovery (no package.json walk, no on-disk config, no stray stasis.code.br).
166
162
  function loadStateForBundle(root, bundle) {
167
163
  const state = new State(root, { bundle: 'load', lock: 'ignore', scope: bundle.config.scope, skipDiscovery: true })
168
164
  const sources = new Map()
@@ -176,50 +172,23 @@ function loadStateForBundle(root, bundle) {
176
172
  state.formats = bundle.formats
177
173
  state.imports = bundle.imports
178
174
  state.entries = new Set(bundle.entries)
179
- // Not state.modules: the load path (getImport/getFile/getFormat/assertEntry) never reads
180
- // it -- it's only written by the capture paths. The State's empty-Map default stands.
175
+ // Not state.executable either: like state.modules below, the load path never reads it, and every
176
+ // consumer narrows against state.modules -- which is empty here -- so copying it would be inert.
177
+ // Not state.modules: the load path never reads it (only the capture paths write it).
181
178
  return state
182
179
  }
183
180
 
184
- // Run the `stasis build` CLI command end-to-end: take a stasis artifact (a `stasis.code.br`
185
- // bundle, or a `stasis.lock.json` lockfile whose attested files are read + verified from
186
- // disk) and an entry point, and run esbuild over that one entry, following the artifact's
187
- // recorded import graph EXACTLY rather than esbuild's own resolver.
188
- //
189
- // `entry` selects which recorded entry to build (see selectEntry): optional when the
190
- // artifact records one, required when it records several. `output` is required: a path
191
- // ending in `.js`/`.cjs`/`.mjs` writes a single file, anything else a directory.
192
- //
193
- // The build runs entirely in memory off the artifact -- no temp files, and no package.json
194
- // required. The artifact's relative paths anchor at the artifact's OWN directory: a bundle is
195
- // self-contained (root is just a keying prefix; nothing is read from disk), and a lockfile
196
- // records its paths relative to where it sits (its project root), so its sources are read +
197
- // verified from there. A project stasis.config.json is not consulted -- the build is driven
198
- // by the artifact, not by `stasis run` config.
199
- //
200
- // The recorded graph is forced via the stasis esbuild plugin in bundle-load mode: each import
201
- // resolves to the edge stasis recorded (a specifier the artifact doesn't record is handed back
202
- // to esbuild, which externalizes it like a built-in/`external`), and each module's bytes come
203
- // from the artifact -- so the output reflects what stasis attested, not what's on disk.
204
- //
205
- // `format` (esm/cjs/iife, default esm), `platform` (node/browser/neutral, default node),
206
- // `minify`, `sourcemap`, `define` (an esbuild define map), `external` (an array of esbuild
207
- // external patterns), and `loader` (an esbuild extension->loader map, e.g. { '.js': 'jsx' }
208
- // to parse JSX in .js files) are forwarded to esbuild; the import graph is fixed by the artifact.
209
- //
210
- // `external` is esbuild's native option: it only steers specifiers esbuild itself would
211
- // resolve -- i.e. the ones the bundle does NOT record (handed back to esbuild as a miss,
212
- // typically the externals that existed at capture time). It re-declares those so esbuild
213
- // leaves them as runtime imports instead of trying (and failing) to resolve them on disk.
214
- // A specifier the artifact DOES record is still followed from the artifact -- the recorded
215
- // graph wins, so `external` never silently un-inlines an attested edge.
181
+ // Run `stasis build`: run esbuild over one recorded entry, following the artifact's
182
+ // recorded import graph EXACTLY (not esbuild's resolver). A specifier the artifact records
183
+ // is always followed from the artifact; `external` only steers the specifiers it doesn't.
216
184
  export async function buildCommand({
217
185
  cwd = process.cwd(),
218
186
  artifact,
219
187
  entry,
220
188
  output,
221
- format = 'esm',
189
+ format,
222
190
  platform = 'node',
191
+ babel = false,
223
192
  minify = false,
224
193
  sourcemap = false,
225
194
  define = {},
@@ -229,36 +198,43 @@ export async function buildCommand({
229
198
  if (!artifact) throw new Error('stasis build: an artifact (bundle or lockfile) is required')
230
199
  if (!output) throw new Error('stasis build: --output is required (a .js/.cjs/.mjs file, or a directory)')
231
200
  if (!Array.isArray(external)) throw new Error('stasis build: external must be an array of esbuild patterns')
201
+ // --platform=hermes is a stasis-level target, not an esbuild platform (esbuild gets
202
+ // 'neutral'): every code file is downleveled to Hermes' dialect before the final bundle,
203
+ // and the bundle itself must avoid ESM -- Hermes has no import/export.
204
+ const hermes = platform === 'hermes'
205
+ format ??= hermes ? 'iife' : 'esm'
206
+ if (hermes && format === 'esm') {
207
+ throw new Error('stasis build: --platform=hermes cannot emit ESM (Hermes has no import/export); use --format=iife (the hermes default) or cjs')
208
+ }
232
209
  const artifactAbs = resolve(cwd, artifact)
233
210
  const { kind, artifact: parsed } = parseFileWithKind(artifactAbs)
234
- assertBuildable(parsed, artifact)
211
+ assertBuildableArtifact(parsed, artifact)
235
212
 
236
- // Anchor the artifact's relative paths at the artifact's OWN directory. A bundle is
237
- // self-contained (root is just a keying prefix; nothing is read from disk), and a lockfile
238
- // records its paths relative to where it sits -- its project root -- so its sources are
239
- // read + verified from there. No package.json discovery, no project stasis.config.json.
213
+ // Anchor artifact-relative paths at the artifact's own directory; a lockfile's sources
214
+ // are read + verified from there.
240
215
  const root = dirname(artifactAbs)
241
216
  const selectedEntry = selectEntry(entry, parsed.entries, { cwd, root, label: artifact })
217
+ assertBuildableEntry(parsed, selectedEntry, artifact)
242
218
 
243
- // The Bundle the load State serves, entirely in memory. A bundle artifact is already a
244
- // parsed Bundle; a lockfile is reconstructed into one by reading + SHA-512-verifying its
245
- // attested files from disk (bundleFromLockfile). The plugin drives off the in-memory State.
246
219
  const bundle = kind === 'lockfile' ? bundleFromLockfile(parsed, { root }) : parsed
247
220
  const state = loadStateForBundle(root, bundle)
248
- // The selected entry is project-relative in the artifact; make it absolute against the
249
- // State's root so esbuild's entry resolution is independent of the process cwd.
221
+ // Make the entry absolute against the State's root so resolution is independent of process cwd.
250
222
  const entryPoint = resolve(state.root, selectedEntry)
251
223
 
252
224
  const esbuild = await importEsbuild()
225
+ // Per-file code rewrites the plugin applies before esbuild parses a served file:
226
+ // --babel runs the project's own babel.config.* over the original source (no esbuild
227
+ // pre-transform), and otherwise --platform=hermes uses the built-in downlevel pipeline.
228
+ // Both resolve Babel from the project (cwd), never from stasis's own dependencies.
229
+ let transform
230
+ if (babel) transform = createBabelConfigTransform({ projectDir: cwd })
231
+ else if (hermes) transform = createHermesTransform({ projectDir: cwd, esbuild })
232
+
253
233
  const outAbs = resolve(cwd, output)
254
- // A `.js`/`.cjs`/`.mjs` --output names a single output file; anything else is a directory.
255
234
  const asFile = /\.[cm]?js$/u.test(output)
256
- // Absolute paths the artifact attests -- esbuild must NEVER overwrite one. A stray
257
- // `--output=src/x.js` (or `--output=src`/`.` whose computed output basename collides with a
258
- // recorded source) would otherwise destroy an attested file: esbuild's own "refusing to
259
- // overwrite input file" check fires only AFTER it has written, and for a lockfile that
260
- // permanently breaks the file's hash. So we build with write:false and write the outputs
261
- // ourselves, refusing -- before touching disk -- to clobber any recorded file.
235
+ // Never overwrite a file the artifact attests: esbuild's own overwrite check fires only
236
+ // after writing (corrupting a lockfile's hash), so we build write:false and refuse to
237
+ // clobber any recorded file before touching disk.
262
238
  const attested = new Set([...state.sources.keys(), ...state.resources.keys()].map((f) => resolve(state.root, f)))
263
239
 
264
240
  let result
@@ -268,24 +244,21 @@ export async function buildCommand({
268
244
  absWorkingDir: state.root,
269
245
  bundle: true,
270
246
  write: false,
271
- platform,
247
+ platform: hermes ? 'neutral' : platform,
272
248
  format,
273
249
  logLevel: 'silent',
250
+ ...(hermes ? { supported: HERMES_UNSUPPORTED } : {}),
274
251
  ...(minify ? { minify: true } : {}),
275
252
  ...(sourcemap ? { sourcemap: true } : {}),
276
253
  ...(external.length > 0 ? { external } : {}),
277
254
  ...(Object.keys(define).length > 0 ? { define } : {}),
278
255
  ...(asFile ? { outfile: outAbs } : { outdir: outAbs }),
279
- // Per-extension loader overrides drive the stasis plugin's load-mode loader choice
280
- // (the plugin serves and labels every in-bundle file, so esbuild's own `loader`
281
- // option never sees them). e.g. { '.js': 'jsx' } to parse JSX in .js files.
282
- plugins: [new StasisEsbuild(state, { loaders: new Map(Object.entries(loader)) })],
256
+ // Loader overrides go through the plugin: it serves every in-bundle file, so esbuild's
257
+ // own `loader` option never sees them. e.g. { '.js': 'jsx' } to parse JSX in .js files.
258
+ plugins: [new StasisEsbuild(state, { loaders: new Map(Object.entries(loader)), transform })],
283
259
  })
284
260
  } catch (err) {
285
- // esbuild rejects with a BuildFailure carrying a formatted `.errors` array under
286
- // logLevel:'silent'. Surface those (rather than the bare wrapper) so the user sees the
287
- // actual resolve/load failure -- including an entry that imports an un-buildable asset
288
- // -- then fail the command.
261
+ // Under logLevel:'silent' esbuild puts the real errors on err.errors; surface them, then fail.
289
262
  if (Array.isArray(err?.errors) && err.errors.length > 0) {
290
263
  const formatted = await esbuild.formatMessages(err.errors, { kind: 'error', color: false })
291
264
  for (const line of formatted) process.stderr.write(line)
@@ -294,9 +267,7 @@ export async function buildCommand({
294
267
  throw err
295
268
  }
296
269
 
297
- // The build succeeded. Refuse to clobber an attested source -- checked against esbuild's
298
- // ACTUAL output paths (so it covers both `--output` file and directory), BEFORE any write,
299
- // so a rejected build leaves every recorded file intact.
270
+ // Refuse to clobber an attested source, checked against esbuild's actual output paths before any write.
300
271
  for (const file of result.outputFiles) {
301
272
  if (attested.has(file.path)) {
302
273
  throw new Error(
@@ -311,10 +282,7 @@ export async function buildCommand({
311
282
  for (const line of formatted) process.stderr.write(line)
312
283
  }
313
284
 
314
- for (const file of result.outputFiles) {
315
- mkdirSync(dirname(file.path), { recursive: true })
316
- writeFileSync(file.path, file.contents)
317
- }
285
+ for (const file of result.outputFiles) writeFile(file.path, file.contents)
318
286
 
319
287
  console.warn(`[stasis] Built ${selectedEntry} from ${kind} ${artifact} to ${output}`)
320
288
  return { entry: selectedEntry, dir: asFile ? undefined : outAbs, outfile: asFile ? outAbs : undefined }