import type * as d from '../../../declarations' ; import { dirname , join , relative } from 'path' ; import { normalizePath } from '@utils' ; import { parseCollectionManifest } from './parse-collection-manifest' ; export const parseCollection = ( config , compilerCtx , buildCtx , moduleId , pkgJsonFilePath , pkgData ) => { const collectionName = pkgData . name ; let collection = compilerCtx . collections . find ( ( c ) => c . collectionName === collectionName ) ; if ( collection != null ) { return collection ; } const collectionPackageRootDir = dirname ( pkgJsonFilePath ) ; const collectionFilePath = join ( collectionPackageRootDir , pkgData . collection ) ; const relPath = relative ( config . rootDir , collectionFilePath ) ; config . logger . debug ( `load collection: ${ collectionName }, ${ relPath }` ) ; const collectionJsonStr = compilerCtx . fs . readFileSync ( collectionFilePath ) ; if ( ! collectionJsonStr ) { return null ; } const collectionDir = normalizePath ( dirname ( collectionFilePath ) ) ; collection = parseCollectionManifest ( config , compilerCtx , buildCtx , collectionName , collectionDir , collectionJsonStr ) ; collection . moduleId = moduleId ; if ( pkgData . module && pkgData . module !== pkgData . main ) { collection . hasExports = true ; } collection . moduleDir = collectionPackageRootDir ; compilerCtx . collections . push ( collection ) ; return collection ; } ;