@exodus/stasis-core 1.0.0-beta.10 → 1.0.0-beta.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/stasis-core",
3
- "version": "1.0.0-beta.10",
3
+ "version": "1.0.0-beta.11",
4
4
  "description": "Zero-dependency stasis runtime",
5
5
  "type": "module",
6
6
  "exports": {
@@ -197,9 +197,34 @@ export function withMetadataOf(record, other) {
197
197
  return moduleInfo({ ...record, repo, ...merged })
198
198
  }
199
199
 
200
- // A record's `vendored` and `subpackages` as `what` writes them: the entries holding one of `files`, validated.
201
- const carriedDirMetadata = (dir, info, files, what) => fromEntries(Object.keys(DIR_METADATA).map((field) =>
202
- [field, normalizeDirMetadata(field, dir, { ...info, files, [field]: carriedEntries(info[field], files) }, what)]))
200
+ // A record's `vendored` and `subpackages` as `what` writes them: the entries holding one of `files`, validated;
201
+ // a field not in `fields` left out.
202
+ const carriedDirMetadata = (dir, info, files, what, fields) => fromEntries(Object.keys(DIR_METADATA).map((field) =>
203
+ [field, fields.includes(field) ? normalizeDirMetadata(field, dir, { ...info, files, [field]: carriedEntries(info[field], files) }, what) : undefined]))
204
+
205
+ // The packages a module map records, for what looks at each of them (`stasis audit`): every record, as it is,
206
+ // and after a dependency's, each `vendored` copy in it as a record of its own, at the copy's directory in the
207
+ // project (`node_modules/next/dist/compiled/react-is`): its `name` and `version`, its host's `ecosystem`,
208
+ // `vendoredIn` its host's dir, and `files`, those the copy holds (each counted for the deepest entry holding
209
+ // it), relative to that directory. A host keeps all its files, the copies' too: they are shipped as its.
210
+ // File values are carried over as they are (a contents-free bundle's locked ones unread).
211
+ export function* packageRecords(modules) {
212
+ for (const [dir, record] of modules) {
213
+ yield [dir, record]
214
+ if (record.vendored === undefined) continue
215
+ const held = new Map()
216
+ for (const rel of Object.keys(record.files)) {
217
+ const sub = entryDirOf(record.vendored, rel)
218
+ if (sub === undefined) continue
219
+ if (!held.has(sub)) held.set(sub, Object.create(null))
220
+ Object.defineProperty(held.get(sub), rel.slice(sub.length + 1), Object.getOwnPropertyDescriptor(record.files, rel))
221
+ }
222
+ for (const [sub, files] of held) {
223
+ const { name, version } = record.vendored[sub]
224
+ yield [moduleFileKey(dir, sub), { name, version, ecosystem: record.ecosystem, vendoredIn: dir, files }]
225
+ }
226
+ }
227
+ }
203
228
 
204
229
  // A parsed bucket `dir` of a `what` artifact: an absent version has one spelling (a literal null folds
205
230
  // into undefined so identity comparisons and JSON round-trips can't split on it), `repo`, `vendored` and
@@ -455,9 +480,11 @@ export function serializeImports(imports) {
455
480
 
456
481
  // A module map as the serialized `modules` (node_modules buckets) and `sources` (the rest) objects
457
482
  // of a `what` artifact, buckets and files path-sorted so the bytes are canonical. Each record's
458
- // `vendored` and `subpackages` keep the entries holding one of the files it carries. `metadata: false`
459
- // leaves each record's `repo`, `vendored` and `subpackages` out: metadata, which a lockfile never carries.
460
- export function groupModules(modules, { skipEmpty = false, metadata = true, what } = {}) {
483
+ // `vendored` and `subpackages` keep the entries holding one of the files it carries. `metadata` names the
484
+ // metadata fields written (a lockfile carries `vendored` alone, so it can be audited on its own), or is
485
+ // `true` for every one and `false` for none, as the option once was.
486
+ export function groupModules(modules, { skipEmpty = false, metadata: written = true, what } = {}) {
487
+ const metadata = written === true ? ['repo', ...Object.keys(DIR_METADATA)] : written === false ? [] : written
461
488
  const grouped = { modules: [], sources: [] }
462
489
  for (const [dir, info] of modules) {
463
490
  if (skipEmpty && Object.keys(info.files).length === 0) continue
@@ -466,8 +493,8 @@ export function groupModules(modules, { skipEmpty = false, metadata = true, what
466
493
  const files = fromEntries(Object.entries(info.files).toSorted(byPath))
467
494
  grouped[inNodeModules ? 'modules' : 'sources'].push([dir, moduleInfo({
468
495
  ...info,
469
- repo: metadata ? normalizeModuleRepo(dir, info, what) : undefined,
470
- ...(metadata ? carriedDirMetadata(dir, info, files, what) : { vendored: undefined, subpackages: undefined }),
496
+ repo: metadata.includes('repo') ? normalizeModuleRepo(dir, info, what) : undefined,
497
+ ...carriedDirMetadata(dir, info, files, what, metadata),
471
498
  files,
472
499
  })])
473
500
  }
package/src/lockfile.js CHANGED
@@ -4,8 +4,10 @@ const VERSION = 0
4
4
 
5
5
  const duplicateKey = duplicateKeyError('lockfile', 'lockfile (lock=replace)')
6
6
 
7
- // A record as a lockfile holds it: without `repo`, `vendored` and `subpackages`, metadata a bundle carries and nothing attests.
8
- const lockRecord = ({ repo: _repo, vendored: _vendored, subpackages: _subpackages, ...info }) => info
7
+ // A record as a lockfile holds it: without `repo` and `subpackages`, metadata a bundle carries and nothing attests.
8
+ // `vendored` it keeps, unattested too, so the copies a dependency ships can be audited from a lockfile alone.
9
+ const LOCK_METADATA = ['vendored']
10
+ const lockRecord = ({ repo: _repo, subpackages: _subpackages, ...info }) => info
9
11
 
10
12
  export class Lockfile {
11
13
  static VERSION = VERSION
@@ -81,7 +83,7 @@ export class Lockfile {
81
83
  serialize() {
82
84
  // Never write an artifact that parse would reject.
83
85
  flatFileKeys(this.modules, 'lockfile', duplicateKey)
84
- const { modules, sources } = groupModules(this.modules, { metadata: false, what: 'lockfile' })
86
+ const { modules, sources } = groupModules(this.modules, { metadata: LOCK_METADATA, what: 'lockfile' })
85
87
  const store = { version: this.version, config: this.config }
86
88
  if (this.config.scope === 'full') Object.assign(store, { entries: serializeEntries(this.entries, 'lockfile'), sources })
87
89
  store.modules = modules