|
4 | 4 | /** @typedef {import('./types.js').ArchiveOptions} ArchiveOptions */
|
5 | 5 | /** @typedef {import('./types.js').ArchiveWriter} ArchiveWriter */
|
6 | 6 | /** @typedef {import('./types.js').CompartmentDescriptor} CompartmentDescriptor */
|
| 7 | +/** @typedef {import('./types.js').CompartmentMapDescriptor} CompartmentMapDescriptor */ |
7 | 8 | /** @typedef {import('./types.js').ModuleDescriptor} ModuleDescriptor */
|
8 | 9 | /** @typedef {import('./types.js').ParserImplementation} ParserImplementation */
|
9 | 10 | /** @typedef {import('./types.js').ReadFn} ReadFn */
|
@@ -243,6 +244,44 @@ const captureSourceLocations = async (sources, captureSourceLocation) => {
|
243 | 244 | }
|
244 | 245 | };
|
245 | 246 |
|
| 247 | +/** |
| 248 | + * @param {CompartmentMapDescriptor} compartmentMap |
| 249 | + * @param {Sources} sources |
| 250 | + * @returns {{archiveCompartmentMap: CompartmentMapDescriptor, archiveSources: Sources}} |
| 251 | + */ |
| 252 | +export const makeArchiveCompartmentMap = (compartmentMap, sources) => { |
| 253 | + const { |
| 254 | + compartments, |
| 255 | + entry: { compartment: entryCompartmentName, module: entryModuleSpecifier }, |
| 256 | + } = compartmentMap; |
| 257 | + |
| 258 | + const compartmentRenames = renameCompartments(compartments); |
| 259 | + const archiveCompartments = translateCompartmentMap( |
| 260 | + compartments, |
| 261 | + sources, |
| 262 | + compartmentRenames, |
| 263 | + ); |
| 264 | + const archiveEntryCompartmentName = compartmentRenames[entryCompartmentName]; |
| 265 | + const archiveSources = renameSources(sources, compartmentRenames); |
| 266 | + |
| 267 | + const archiveCompartmentMap = { |
| 268 | + tags: [], |
| 269 | + entry: { |
| 270 | + compartment: archiveEntryCompartmentName, |
| 271 | + module: entryModuleSpecifier, |
| 272 | + }, |
| 273 | + compartments: archiveCompartments, |
| 274 | + }; |
| 275 | + |
| 276 | + // Cross-check: |
| 277 | + // We assert that we have constructed a valid compartment map, not because it |
| 278 | + // might not be, but to ensure that the assertCompartmentMap function can |
| 279 | + // accept all valid compartment maps. |
| 280 | + assertCompartmentMap(archiveCompartmentMap); |
| 281 | + |
| 282 | + return { archiveCompartmentMap, archiveSources }; |
| 283 | +}; |
| 284 | + |
246 | 285 | /**
|
247 | 286 | * @param {ReadFn | ReadPowers} powers
|
248 | 287 | * @param {string} moduleLocation
|
@@ -287,7 +326,7 @@ const digestLocation = async (powers, moduleLocation, options) => {
|
287 | 326 |
|
288 | 327 | const {
|
289 | 328 | compartments,
|
290 |
| - entry: { compartment: entryCompartmentName, module: entryModuleSpecifier }, |
| 329 | + entry: { module: entryModuleSpecifier }, |
291 | 330 | } = compartmentMap;
|
292 | 331 |
|
293 | 332 | /** @type {Sources} */
|
@@ -322,28 +361,10 @@ const digestLocation = async (powers, moduleLocation, options) => {
|
322 | 361 | );
|
323 | 362 | }
|
324 | 363 |
|
325 |
| - const compartmentRenames = renameCompartments(compartments); |
326 |
| - const archiveCompartments = translateCompartmentMap( |
327 |
| - compartments, |
| 364 | + const { archiveCompartmentMap, archiveSources } = makeArchiveCompartmentMap( |
| 365 | + compartmentMap, |
328 | 366 | sources,
|
329 |
| - compartmentRenames, |
330 | 367 | );
|
331 |
| - const archiveEntryCompartmentName = compartmentRenames[entryCompartmentName]; |
332 |
| - const archiveSources = renameSources(sources, compartmentRenames); |
333 |
| - |
334 |
| - const archiveCompartmentMap = { |
335 |
| - entry: { |
336 |
| - compartment: archiveEntryCompartmentName, |
337 |
| - module: moduleSpecifier, |
338 |
| - }, |
339 |
| - compartments: archiveCompartments, |
340 |
| - }; |
341 |
| - |
342 |
| - // Cross-check: |
343 |
| - // We assert that we have constructed a valid compartment map, not because it |
344 |
| - // might not be, but to ensure that the assertCompartmentMap function can |
345 |
| - // accept all valid compartment maps. |
346 |
| - assertCompartmentMap(archiveCompartmentMap); |
347 | 368 |
|
348 | 369 | const archiveCompartmentMapText = JSON.stringify(
|
349 | 370 | archiveCompartmentMap,
|
|
0 commit comments