1- /* Provides functions to create an archive (zip file with a 
1+ /** 
2+  * Provides functions to create an archive (zip file with a 
23 * compartment-map.json) from a partially completed compartment map (it must 
34 * mention all packages/compartments as well as inter-compartment references 
45 * but does not contain an entry for every module reachable from its entry 
2627 * In fruition of https://github.com/endojs/endo/issues/400, we will be able to 
2728 * use original source archives on XS and Node.js, but not on the web until the 
2829 * web platform makes further progress on virtual module loaers. 
30+  * 
31+  * @module  
2932 */ 
3033
3134/* eslint no-shadow: 0 */ 
3639 *   ArchiveResult, 
3740 *   ArchiveWriter, 
3841 *   CaptureSourceLocationHook, 
39-  *   CompartmentMapDescriptor, 
4042 *   HashPowers, 
43+  *   PackageCompartmentMapDescriptor, 
4144 *   ReadFn, 
4245 *   ReadPowers, 
4346 *   Sources, 
@@ -58,16 +61,7 @@ import { digestCompartmentMap } from './digest.js';
5861
5962const  textEncoder  =  new  TextEncoder ( ) ; 
6063
61- const  {  assign,  create,  freeze }  =  Object ; 
62- 
63- /** 
64-  * @param  {string } rel - a relative URL 
65-  * @param  {string } abs - a fully qualified URL 
66-  * @returns  {string } 
67-  */ 
68- const  resolveLocation  =  ( rel ,  abs )  =>  new  URL ( rel ,  abs ) . toString ( ) ; 
69- 
70- const  {  keys }  =  Object ; 
64+ const  {  assign,  create,  freeze,  keys }  =  Object ; 
7165
7266/** 
7367 * @param  {ArchiveWriter } archive 
@@ -77,12 +71,10 @@ const addSourcesToArchive = async (archive, sources) => {
7771  await  null ; 
7872  for  ( const  compartment  of  keys ( sources ) . sort ( ) )  { 
7973    const  modules  =  sources [ compartment ] ; 
80-     const  compartmentLocation  =  resolveLocation ( `${ compartment }  /` ,  'file:///' ) ; 
8174    for  ( const  specifier  of  keys ( modules ) . sort ( ) )  { 
82-       const  {  bytes,  location }  =  modules [ specifier ] ; 
83-       if  ( location  !==  undefined )  { 
84-         const  moduleLocation  =  resolveLocation ( location ,  compartmentLocation ) ; 
85-         const  path  =  new  URL ( moduleLocation ) . pathname . slice ( 1 ) ;  // elide initial "/" 
75+       if  ( 'location'  in  modules [ specifier ] )  { 
76+         const  {  bytes,  location }  =  modules [ specifier ] ; 
77+         const  path  =  `${ compartment }  /${ location }  ` ; 
8678        if  ( bytes  !==  undefined )  { 
8779          // eslint-disable-next-line no-await-in-loop 
8880          await  archive . write ( path ,  bytes ) ; 
@@ -100,16 +92,16 @@ const captureSourceLocations = async (sources, captureSourceLocation) => {
10092  for  ( const  compartmentName  of  keys ( sources ) . sort ( ) )  { 
10193    const  modules  =  sources [ compartmentName ] ; 
10294    for  ( const  moduleSpecifier  of  keys ( modules ) . sort ( ) )  { 
103-       const   {   sourceLocation  }   =   modules [ moduleSpecifier ] ; 
104-       if   ( sourceLocation  !==   undefined )   { 
95+       if   ( ' sourceLocation'   in   modules [ moduleSpecifier ] )   { 
96+          const   {   sourceLocation }   =   modules [ moduleSpecifier ] ; 
10597        captureSourceLocation ( compartmentName ,  moduleSpecifier ,  sourceLocation ) ; 
10698      } 
10799    } 
108100  } 
109101} ; 
110102
111103/** 
112-  * @param  {CompartmentMapDescriptor } compartmentMap 
104+  * @param  {PackageCompartmentMapDescriptor } compartmentMap 
113105 * @param  {Sources } sources 
114106 * @returns  {ArchiveResult } 
115107 */ 
@@ -130,9 +122,11 @@ export const makeArchiveCompartmentMap = (compartmentMap, sources) => {
130122  } ; 
131123} ; 
132124
125+ const  noop  =  ( )  =>  { } ; 
126+ 
133127/** 
134128 * @param  {ReadFn | ReadPowers } powers 
135-  * @param  {CompartmentMapDescriptor } compartmentMap 
129+  * @param  {PackageCompartmentMapDescriptor } compartmentMap 
136130 * @param  {ArchiveLiteOptions } [options] 
137131 * @returns  {Promise<{sources: Sources, compartmentMapBytes: Uint8Array, sha512?: string}> } 
138132 */ 
@@ -146,6 +140,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
146140    policy =  undefined , 
147141    sourceMapHook =  undefined , 
148142    parserForLanguage : parserForLanguageOption  =  { } , 
143+     log : _log  =  noop , 
149144  }  =  options ; 
150145
151146  const  parserForLanguage  =  freeze ( 
@@ -179,6 +174,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
179174    importHook : consolidatedExitModuleImportHook , 
180175    sourceMapHook, 
181176  } ) ; 
177+ 
182178  // Induce importHook to record all the necessary modules to import the given module specifier. 
183179  const  {  compartment,  attenuatorsCompartment }  =  link ( compartmentMap ,  { 
184180    resolve, 
@@ -229,7 +225,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
229225
230226/** 
231227 * @param  {ReadFn | ReadPowers } powers 
232-  * @param  {CompartmentMapDescriptor } compartmentMap 
228+  * @param  {PackageCompartmentMapDescriptor } compartmentMap 
233229 * @param  {ArchiveLiteOptions } [options] 
234230 * @returns  {Promise<{bytes: Uint8Array, sha512?: string}> } 
235231 */ 
@@ -254,7 +250,7 @@ export const makeAndHashArchiveFromMap = async (
254250
255251/** 
256252 * @param  {ReadFn | ReadPowers } powers 
257-  * @param  {CompartmentMapDescriptor } compartmentMap 
253+  * @param  {PackageCompartmentMapDescriptor } compartmentMap 
258254 * @param  {ArchiveLiteOptions } [options] 
259255 * @returns  {Promise<Uint8Array> } 
260256 */ 
@@ -269,7 +265,7 @@ export const makeArchiveFromMap = async (powers, compartmentMap, options) => {
269265
270266/** 
271267 * @param  {ReadFn | ReadPowers } powers 
272-  * @param  {CompartmentMapDescriptor } compartmentMap 
268+  * @param  {PackageCompartmentMapDescriptor } compartmentMap 
273269 * @param  {ArchiveLiteOptions } [options] 
274270 * @returns  {Promise<Uint8Array> } 
275271 */ 
@@ -284,7 +280,7 @@ export const mapFromMap = async (powers, compartmentMap, options) => {
284280
285281/** 
286282 * @param  {HashPowers } powers 
287-  * @param  {CompartmentMapDescriptor } compartmentMap 
283+  * @param  {PackageCompartmentMapDescriptor } compartmentMap 
288284 * @param  {ArchiveLiteOptions } [options] 
289285 * @returns  {Promise<string> } 
290286 */ 
@@ -302,7 +298,7 @@ export const hashFromMap = async (powers, compartmentMap, options) => {
302298 * @param  {WriteFn } write 
303299 * @param  {ReadFn | ReadPowers } readPowers 
304300 * @param  {string } archiveLocation 
305-  * @param  {CompartmentMapDescriptor } compartmentMap 
301+  * @param  {PackageCompartmentMapDescriptor } compartmentMap 
306302 * @param  {ArchiveLiteOptions } [options] 
307303 */ 
308304export  const  writeArchiveFromMap  =  async  ( 
0 commit comments