bare-module-traverse 2.5.5 → 2.5.6

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 (2) hide show
  1. package/index.js +30 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -353,7 +353,7 @@ exports.preresolved = function* (url, source, resolutions, artifacts, visited, o
353
353
 
354
354
  if (typeof imports !== 'object' || imports === null) return false
355
355
 
356
- const type = moduleType(url, {}, null, opts)
356
+ let info = null
357
357
 
358
358
  for (const [specifier, entry] of Object.entries(imports)) {
359
359
  const stack = [{ entry, asset: false }]
@@ -365,8 +365,18 @@ exports.preresolved = function* (url, source, resolutions, artifacts, visited, o
365
365
  const url = new URL(entry)
366
366
 
367
367
  if (specifier === '#package') {
368
+ const scope = yield* readPackage(url, opts)
369
+
370
+ if (scope !== null && info === null) info = scope.info
371
+
368
372
  yield {
369
- children: exports.package(url, null, artifacts, visited, opts),
373
+ children: exports.package(
374
+ url,
375
+ scope === null ? null : scope.source,
376
+ artifacts,
377
+ visited,
378
+ opts
379
+ ),
370
380
  deferred: false
371
381
  }
372
382
  } else if (asset) {
@@ -403,6 +413,8 @@ exports.preresolved = function* (url, source, resolutions, artifacts, visited, o
403
413
  }
404
414
  }
405
415
 
416
+ const type = moduleType(url, {}, info, opts)
417
+
406
418
  const lexer = { imports: [], exports: [] }
407
419
 
408
420
  if (type === constants.SCRIPT || type === constants.MODULE) {
@@ -792,6 +804,22 @@ exports.patternMatches = function* patternMatches(pattern, parentURL, matches, o
792
804
  return matches
793
805
  }
794
806
 
807
+ function* readPackage(url, opts) {
808
+ const { packages = new Map() } = opts
809
+
810
+ const cached = packages.get(url.href)
811
+
812
+ if (cached !== undefined) return cached
813
+
814
+ const source = yield { module: url, artifact: false }
815
+
816
+ const scope = source === null ? null : { url, source, info: JSON.parse(source) }
817
+
818
+ packages.set(url.href, scope)
819
+
820
+ return scope
821
+ }
822
+
795
823
  function* lookupPackage(url, opts) {
796
824
  const { packages = new Map() } = opts
797
825
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module-traverse",
3
- "version": "2.5.5",
3
+ "version": "2.5.6",
4
4
  "description": "Low-level module graph traversal for Bare",
5
5
  "exports": {
6
6
  ".": {