import { Omit , repoRootDir , yarn } from "@adpt/utils" ; import * as fs from "fs-extra" ; import * as path from "path" ; import { Config } from "./local-registry" ; export const localRegistryPort = 4873 ; export const localRegistryUrl = `http://127.0.0.1:${ localRegistryPort }` ; export interface YarnProxyOpts { registry ? : string ; tag ? : string ; } export const yarnLocalProxyOpts = { registry : localRegistryUrl , tag : "unit-tests" , } ; const topLevelPackageJson = fs . readJsonSync ( path . join ( repoRootDir , "package.json" ) ) ; const configDir = path . join ( repoRootDir , "config" ) ; export const defaultPublishList = topLevelPackageJson . workspaces . packages . filter ( ( p ) => { switch ( path . basename ( p ) ) { case "scripts" : case "systemtest" : case "testutils" : return false ; default : return true ; } } ) . map ( ( p ) => path . join ( repoRootDir , p ) ) ; export async function setupLocalRegistry ( publishList , options = { } ) { const { tag , ... opts } = { ... yarnLocalProxyOpts , ... options } ; try { for ( const modDir of publishList ) { const pkgJson = await fs . readJson ( path . join ( modDir , "package.json" ) ) ; const modName = pkgJson . name ; await yarn . publish ( modDir , { tag , ... opts } ) ; await yarn . cacheClean ( modName , opts ) ; } } catch ( err ) { let output = `Local registry setup failed: ${ err . message }` ; if ( err . stderr ) output += err . stderr ; if ( err . stdout ) output += err . stdout ; console . error ( output ) ; throw new Error ( output ) ; } console . log ( `\n>> Local NPM registry started on ${ opts . registry } ` + `[loaded ${ publishList . length } modules]\n` ) ; } function setupDefault ( ) { return setupLocalRegistry ( defaultPublishList ) ; } export const configPath = path . join ( configDir , "config.yaml" ) ; export const config = { auth : { htpasswd : { file : path . join ( configDir , "verdaccio.htpasswd" ) } } , uplinks : { npmjs : { url : "https://registry.npmjs.org/" , max_fails : 100 , timeout : "3s" , fail_timeout : "0s" , agent_options : { keepAlive : true , keepAliveMsecs : 5000 , timeout : 500 , } , } } , packages : { "@adpt/*" : { access : "$all" , publish : "$all" , } , "**" : { access : "$all" , publish : "$all" , proxy : "npmjs" } , } , logs : [ { type : "stdout" , format : "pretty" , level : "error" } ] , self_path : configPath , listen : `0.0.0.0:${ localRegistryPort }` , onStart : setupDefault , clearStorage : false , } ;