@@ -6,17 +6,20 @@ import { execSync, fork } from 'child_process';
6
6
* @param storage the storage location for the local registry
7
7
* @param verbose whether to log verbose output
8
8
* @param clearStorage whether to clear the verdaccio storage before running the registry
9
+ * @param listenAddress the address that verdaccio should listen to (default to `localhost`)
9
10
*/
10
11
export function startLocalRegistry ( {
11
12
localRegistryTarget,
12
13
storage,
13
14
verbose,
14
15
clearStorage,
16
+ listenAddress = 'localhost' ,
15
17
} : {
16
18
localRegistryTarget : string ;
17
19
storage ?: string ;
18
20
verbose ?: boolean ;
19
21
clearStorage ?: boolean ;
22
+ listenAddress ?: string ;
20
23
} ) {
21
24
if ( ! localRegistryTarget ) {
22
25
throw new Error ( `localRegistryTarget is required` ) ;
@@ -36,17 +39,21 @@ export function startLocalRegistry({
36
39
const listener = ( data ) => {
37
40
if ( verbose ) {
38
41
process . stdout . write ( data ) ;
42
+ console . log ( 'Waiting for local registry to start...' ) ;
39
43
}
40
- if ( data . toString ( ) . includes ( ' http://localhost:' ) ) {
44
+ if ( data . toString ( ) . includes ( ` http://${ listenAddress } :` ) ) {
41
45
const port = parseInt (
42
- data . toString ( ) . match ( / l o c a l h o s t : (?< port > \d + ) / ) ?. groups ?. port
46
+ data . toString ( ) . match ( new RegExp ( `${ listenAddress } :(?<port>\\d+)` ) )
47
+ ?. groups ?. port
43
48
) ;
44
- console . log ( 'Local registry started on port ' + port ) ;
45
49
46
- const registry = `http://localhost:${ port } ` ;
50
+ const registry = `http://${ listenAddress } :${ port } ` ;
51
+
52
+ console . log ( `Local registry started on ${ registry } ` ) ;
53
+
47
54
process . env . npm_config_registry = registry ;
48
55
execSync (
49
- `npm config set //localhost :${ port } /:_authToken "secretVerdaccioToken"` ,
56
+ `npm config set //${ listenAddress } :${ port } /:_authToken "secretVerdaccioToken"` ,
50
57
{
51
58
windowsHide : false ,
52
59
}
@@ -56,13 +63,13 @@ export function startLocalRegistry({
56
63
process . env . YARN_REGISTRY = registry ;
57
64
// yarnv2
58
65
process . env . YARN_NPM_REGISTRY_SERVER = registry ;
59
- process . env . YARN_UNSAFE_HTTP_WHITELIST = 'localhost' ;
66
+ process . env . YARN_UNSAFE_HTTP_WHITELIST = listenAddress ;
60
67
61
68
console . log ( 'Set npm and yarn config registry to ' + registry ) ;
62
69
63
70
resolve ( ( ) => {
64
71
childProcess . kill ( ) ;
65
- execSync ( `npm config delete //localhost :${ port } /:_authToken` , {
72
+ execSync ( `npm config delete //${ listenAddress } :${ port } /:_authToken` , {
66
73
windowsHide : false ,
67
74
} ) ;
68
75
} ) ;
0 commit comments