import glob from 'glob' ; import { TGetTargetWorkspacePackagesAbsolutePaths } from '../../types' ; import getPathToTargetWorkspaceRootDirFromCLIArgs from './getPathToTargetWorkspaceRootDirFromCLIArgs' ; import getTargetWorkspaceLernaConfigContent from './getTargetWorkspaceLernaConfigContent' ; import getTargetWorkspaceRootPackageJsonConfigContent from './getTargetWorkspaceRootPackageJsonConfigContent' ; /**
 * Find and return all locations where we have packages in the target workspace.
 */ const getTargetWorkspacePackagesAbsolutePaths = async ( ) => { const pathToTargetWorkspaceRootDir = getPathToTargetWorkspaceRootDirFromCLIArgs ( ) ; const targetWorkspaceLernaConfigContent = await getTargetWorkspaceLernaConfigContent ( ) ; const targetWorkspaceRootPackageJsonConfigContent = await getTargetWorkspaceRootPackageJsonConfigContent ( ) ; const targetWorkspacePackagesLocations = ( targetWorkspaceLernaConfigContent . packages || targetWorkspaceRootPackageJsonConfigContent . workspaces || [ 'packages/*' , ] ) as string [ ] ; const targetWorkspacePackagesAbsolutePathsCollections = ( await Promise . all ( targetWorkspacePackagesLocations . map ( packagesLocation => new Promise ( ( resolve , reject ) => { const preparedGlobPattern = packagesLocation . endsWith ( '/' ) ? packagesLocation : `${ packagesLocation }/` ; glob ( preparedGlobPattern , { cwd : pathToTargetWorkspaceRootDir , absolute : true , } , ( err , matches ) => { if ( err ) { reject ( err ) ; } else { resolve ( matches ) ; } } ) ; } ) ) ) ) as string [ ] [ ] ; return targetWorkspacePackagesAbsolutePathsCollections . flat ( ) ; } ; export default getTargetWorkspacePackagesAbsolutePaths ;