import fs from "fs-extra" ; import * as path from "path" ; import getPublicUrlOrPath from "./get-public-url-or-path" ; const appDirectory = fs . realpathSync ( process . cwd ( ) ) ; const resolveApp = ( relativePath ) => path . resolve ( appDirectory , relativePath ) ; interface AppPackageJson { homepage ? : string ; } export const publicUrlOrPath = getPublicUrlOrPath ( process . env . NODE_ENV === "development" , ( fs . readJSONSync ( resolveApp ( "package.json" ) ) as AppPackageJson ) . homepage , process . env . PUBLIC_URL ) ; const buildPath = process . env . BUILD_PATH || "build" ; export const moduleFileExtensions = [ "web.mjs" , "mjs" , "web.js" , "js" , "web.ts" , "ts" , "web.tsx" , "tsx" , "json" , "web.jsx" , "jsx" , ] ; export const resolveModule = ( resolveFn , filePath ) : string => { const extension = moduleFileExtensions . find ( ( extension ) => fs . existsSync ( resolveFn ( `${ filePath }.${ extension }` ) ) ) ; if ( extension ) { return resolveFn ( `${ filePath }.${ extension }` ) ; } return resolveFn ( `${ filePath }.js` ) ; } ; export const ownPath = path . dirname ( path . join ( __dirname , ".." , ".." ) ) ; const resolveOwn = ( relativePath ) => path . resolve ( ownPath , relativePath ) ; export const dotenv = resolveApp ( ".env" ) ; export const appPath = resolveApp ( "." ) ; export const appBuild = resolveApp ( buildPath ) ; export const appPublic = resolveApp ( "public" ) ; export const appHtml = resolveApp ( "public/index.html" ) ; export const appIndexJs = resolveModule ( resolveApp , "src/index" ) ; export const appPackageJson = resolveApp ( "package.json" ) ; export const appSrc = resolveApp ( "src" ) ; export const appTsConfig = resolveApp ( "tsconfig.json" ) ; export const yarnLockFile = resolveApp ( "yarn.lock" ) ; export const testsSetup = resolveModule ( resolveApp , "src/setupTests" ) ; export const proxySetup = resolveApp ( "src/setupProxy.js" ) ; export const appNodeModules = resolveApp ( "node_modules" ) ; export const swSrc = resolveModule ( resolveApp , "src/service-worker" ) ; export const ownNodeModules = resolveOwn ( "node_modules" ) ; export const appTypeDeclarations = resolveApp ( "src/react-app-env.d.ts" ) ; export const ownTypeDeclarations = resolveOwn ( "react-app.d.ts" ) ; export const NODE_PATH = ( process . env . NODE_PATH || "" ) . split ( path . delimiter ) . filter ( ( folder ) => folder && ! path . isAbsolute ( folder ) ) . map ( ( folder ) => path . resolve ( appDirectory , folder ) ) ;