import { URL } from 'url' ; import { DOMAIN } from '../config/constants' ; /**
 * Returns a URL or a path with slash at the end
 * In production can be URL, absolute path, relative path
 * In development always will be an absolute path
 * In development can use `path` module functions for operations
 */ function getPublicUrlOrPath ( homepage ? , envPublicUrl ? ) { const stubDomain = DOMAIN ; if ( envPublicUrl ) { envPublicUrl = envPublicUrl . endsWith ( '/' ) ? envPublicUrl : envPublicUrl + '/' ; const validPublicUrl = new URL ( envPublicUrl , stubDomain ) ; return BalmJS . config . env . isDev ? envPublicUrl . startsWith ( '.' ) ? '/' : validPublicUrl . pathname : envPublicUrl ; } if ( homepage ) { homepage = homepage . endsWith ( '/' ) ? homepage : homepage + '/' ; const validHomepagePathname = new URL ( homepage , stubDomain ) . pathname ; return BalmJS . config . env . isDev ? homepage . startsWith ( '.' ) ? '/' : validHomepagePathname : homepage . startsWith ( '.' ) ? homepage : validHomepagePathname ; } return '/' ; } export default getPublicUrlOrPath ;