Skip to content

Commit d94bc90

Browse files
tinesoftxiongemi
authored andcommitted
feat(testing): allow customizing the default address used to start the local registry
1 parent 8c25c02 commit d94bc90

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/js/src/plugins/jest/start-local-registry.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ import { execSync, fork } from 'child_process';
66
* @param storage the storage location for the local registry
77
* @param verbose whether to log verbose output
88
* @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`)
910
*/
1011
export function startLocalRegistry({
1112
localRegistryTarget,
1213
storage,
1314
verbose,
1415
clearStorage,
16+
listenAddress = 'localhost',
1517
}: {
1618
localRegistryTarget: string;
1719
storage?: string;
1820
verbose?: boolean;
1921
clearStorage?: boolean;
22+
listenAddress?: string;
2023
}) {
2124
if (!localRegistryTarget) {
2225
throw new Error(`localRegistryTarget is required`);
@@ -36,17 +39,21 @@ export function startLocalRegistry({
3639
const listener = (data) => {
3740
if (verbose) {
3841
process.stdout.write(data);
42+
console.log('Waiting for local registry to start...');
3943
}
40-
if (data.toString().includes('http://localhost:')) {
44+
if (data.toString().includes(`http://${listenAddress}:`)) {
4145
const port = parseInt(
42-
data.toString().match(/localhost:(?<port>\d+)/)?.groups?.port
46+
data.toString().match(new RegExp(`${listenAddress}:(?<port>\\d+)`))
47+
?.groups?.port
4348
);
44-
console.log('Local registry started on port ' + port);
4549

46-
const registry = `http://localhost:${port}`;
50+
const registry = `http://${listenAddress}:${port}`;
51+
52+
console.log(`Local registry started on ${registry}`);
53+
4754
process.env.npm_config_registry = registry;
4855
execSync(
49-
`npm config set //localhost:${port}/:_authToken "secretVerdaccioToken"`,
56+
`npm config set //${listenAddress}:${port}/:_authToken "secretVerdaccioToken"`,
5057
{
5158
windowsHide: false,
5259
}
@@ -56,13 +63,13 @@ export function startLocalRegistry({
5663
process.env.YARN_REGISTRY = registry;
5764
// yarnv2
5865
process.env.YARN_NPM_REGISTRY_SERVER = registry;
59-
process.env.YARN_UNSAFE_HTTP_WHITELIST = 'localhost';
66+
process.env.YARN_UNSAFE_HTTP_WHITELIST = listenAddress;
6067

6168
console.log('Set npm and yarn config registry to ' + registry);
6269

6370
resolve(() => {
6471
childProcess.kill();
65-
execSync(`npm config delete //localhost:${port}/:_authToken`, {
72+
execSync(`npm config delete //${listenAddress}:${port}/:_authToken`, {
6673
windowsHide: false,
6774
});
6875
});

0 commit comments

Comments
 (0)