3
3
4
4
/** @typedef {import('./types.js').Language } Language */
5
5
/** @typedef {import('./types.js').ReadFn } ReadFn */
6
+ /** @typedef {import('./types.js').MaybeReadFn } MaybeReadFn */
6
7
/** @typedef {import('./types.js').CanonicalFn } CanonicalFn */
7
8
/** @typedef {import('./types.js').CompartmentMapDescriptor } CompartmentMapDescriptor */
8
9
/** @typedef {import('./types.js').ModuleDescriptor } ModuleDescriptor */
9
10
/** @typedef {import('./types.js').ScopeDescriptor } ScopeDescriptor */
10
11
/** @typedef {import('./types.js').CompartmentDescriptor } CompartmentDescriptor */
11
12
/** @typedef {import('./types.js').ReadPowers } ReadPowers */
13
+ /** @typedef {import('./types.js').MaybeReadPowers } MaybeReadPowers */
12
14
13
15
/**
14
16
* The graph is an intermediate object model that the functions of this module
@@ -83,15 +85,13 @@ const basename = location => {
83
85
} ;
84
86
85
87
/**
86
- * @param {ReadFn } read
88
+ * @param {MaybeReadFn } maybeRead
87
89
* @param {string } packageLocation
88
90
* @returns {Promise<object> }
89
91
*/
90
- const readDescriptor = async ( read , packageLocation ) => {
92
+ const readDescriptor = async ( maybeRead , packageLocation ) => {
91
93
const descriptorLocation = resolveLocation ( 'package.json' , packageLocation ) ;
92
- const descriptorBytes = await read ( descriptorLocation ) . catch (
93
- _error => undefined ,
94
- ) ;
94
+ const descriptorBytes = await maybeRead ( descriptorLocation ) ;
95
95
if ( descriptorBytes === undefined ) {
96
96
return undefined ;
97
97
}
@@ -102,16 +102,16 @@ const readDescriptor = async (read, packageLocation) => {
102
102
103
103
/**
104
104
* @param {Record<string, object> } memo
105
- * @param {ReadFn } read
105
+ * @param {MaybeReadFn } maybeRead
106
106
* @param {string } packageLocation
107
107
* @returns {Promise<object> }
108
108
*/
109
- const readDescriptorWithMemo = async ( memo , read , packageLocation ) => {
109
+ const readDescriptorWithMemo = async ( memo , maybeRead , packageLocation ) => {
110
110
let promise = memo [ packageLocation ] ;
111
111
if ( promise !== undefined ) {
112
112
return promise ;
113
113
}
114
- promise = readDescriptor ( read , packageLocation ) ;
114
+ promise = readDescriptor ( maybeRead , packageLocation ) ;
115
115
memo [ packageLocation ] = promise ;
116
116
return promise ;
117
117
} ;
@@ -479,7 +479,7 @@ const gatherDependency = async (
479
479
* the URL that was used as the key of graph).
480
480
* The URLs in dependencies will all exist as other keys of graph.
481
481
*
482
- * @param {ReadFn } read
482
+ * @param {MaybeReadFn } maybeRead
483
483
* @param {CanonicalFn } canonical
484
484
* @param {string } packageLocation - location of the main package.
485
485
* @param {Set<string> } tags
@@ -490,7 +490,7 @@ const gatherDependency = async (
490
490
* @param {Record<string,string> } [commonDependencies] - dependencies to be added to all packages
491
491
*/
492
492
const graphPackages = async (
493
- read ,
493
+ maybeRead ,
494
494
canonical ,
495
495
packageLocation ,
496
496
tags ,
@@ -504,7 +504,7 @@ const graphPackages = async (
504
504
* @returns {Promise<object> }
505
505
*/
506
506
const readDescriptor = packageLocation =>
507
- readDescriptorWithMemo ( memo , read , packageLocation ) ;
507
+ readDescriptorWithMemo ( memo , maybeRead , packageLocation ) ;
508
508
509
509
if ( mainPackageDescriptor !== undefined ) {
510
510
memo [ packageLocation ] = Promise . resolve ( mainPackageDescriptor ) ;
@@ -697,7 +697,7 @@ const translateGraph = (
697
697
} ;
698
698
699
699
/**
700
- * @param {ReadFn | ReadPowers } readPowers
700
+ * @param {ReadFn | ReadPowers | MaybeReadPowers } readPowers
701
701
* @param {string } packageLocation
702
702
* @param {Set<string> } tags
703
703
* @param {object } packageDescriptor
@@ -717,9 +717,9 @@ export const compartmentMapForNodeModules = async (
717
717
options = { } ,
718
718
) => {
719
719
const { dev = false , commonDependencies, policy } = options ;
720
- const { read , canonical } = unpackReadPowers ( readPowers ) ;
720
+ const { maybeRead , canonical } = unpackReadPowers ( readPowers ) ;
721
721
const graph = await graphPackages (
722
- read ,
722
+ maybeRead ,
723
723
canonical ,
724
724
packageLocation ,
725
725
tags ,
0 commit comments