bare-module-traverse 2.5.4 → 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.
- package/index.js +34 -3
- 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
|
-
|
|
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(
|
|
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,10 +413,15 @@ 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) {
|
|
409
|
-
|
|
421
|
+
const lexed = lex(source)
|
|
422
|
+
|
|
423
|
+
lexer.imports = lexed.imports
|
|
424
|
+
lexer.exports = lexed.exports
|
|
410
425
|
}
|
|
411
426
|
|
|
412
427
|
yield {
|
|
@@ -789,6 +804,22 @@ exports.patternMatches = function* patternMatches(pattern, parentURL, matches, o
|
|
|
789
804
|
return matches
|
|
790
805
|
}
|
|
791
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
|
+
|
|
792
823
|
function* lookupPackage(url, opts) {
|
|
793
824
|
const { packages = new Map() } = opts
|
|
794
825
|
|