Skip to content

Commit

Permalink
chore: create a patch to allow customzing listenAddress of verdaccio
Browse files Browse the repository at this point in the history
Until nrwl/nx#29050 is merged and released
  • Loading branch information
tinesoft committed Nov 24, 2024
1 parent c255b0a commit c7d2db6
Show file tree
Hide file tree
Showing 3 changed files with 3,014 additions and 3,005 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,10 @@
"nx": {
"includedScripts": []
},
"packageManager": "[email protected]+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a"
"packageManager": "[email protected]+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a",
"pnpm": {
"patchedDependencies": {
"@nx/[email protected]": "patches/@[email protected]"
}
}
}
71 changes: 71 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
diff --git a/src/plugins/jest/start-local-registry.d.ts b/src/plugins/jest/start-local-registry.d.ts
index 46e1a3f09e6828e03ece78b0a0534bc77ce693c1..544e1d9d3d8775a7375d98897dd145a3d51216e7 100644
--- a/src/plugins/jest/start-local-registry.d.ts
+++ b/src/plugins/jest/start-local-registry.d.ts
@@ -4,11 +4,13 @@
* @param storage the storage location for the local registry
* @param verbose whether to log verbose output
* @param clearStorage whether to clear the verdaccio storage before running the registry
+ * @param listenAddress the address that verdaccio should listen to (default to `localhost`)
*/
-export declare function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorage, }: {
+export declare function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorage, listenAddress}: {
localRegistryTarget: string;
storage?: string;
verbose?: boolean;
clearStorage?: boolean;
+ listenAddress?: string;
}): Promise<() => void>;
export default startLocalRegistry;
diff --git a/src/plugins/jest/start-local-registry.js b/src/plugins/jest/start-local-registry.js
index e5d04ad4f1f54752e2493eed672c1567bfb301d8..94c4d731d7cf4a19944d369992222f0454790286 100644
--- a/src/plugins/jest/start-local-registry.js
+++ b/src/plugins/jest/start-local-registry.js
@@ -8,8 +8,9 @@ const child_process_1 = require("child_process");
* @param storage the storage location for the local registry
* @param verbose whether to log verbose output
* @param clearStorage whether to clear the verdaccio storage before running the registry
+ * @param listenAddress the address that verdaccio should listen to (default to `localhost`)
*/
-function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorage, }) {
+function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorage, listenAddress = 'localhost', }) {
if (!localRegistryTarget) {
throw new Error(`localRegistryTarget is required`);
}
@@ -17,28 +18,28 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorag
const childProcess = (0, child_process_1.fork)(require.resolve('nx'), [
...`run ${localRegistryTarget} --location none --clear ${clearStorage ?? true}`.split(' '),
...(storage ? [`--storage`, storage] : []),
- ], { stdio: 'pipe' });
+ ], { stdio: verbose ? 'inherit' : 'pipe' });
const listener = (data) => {
if (verbose) {
process.stdout.write(data);
}
- if (data.toString().includes('http://localhost:')) {
- const port = parseInt(data.toString().match(/localhost:(?<port>\d+)/)?.groups?.port);
- console.log('Local registry started on port ' + port);
- const registry = `http://localhost:${port}`;
+ if (data.toString().includes(`http://${listenAddress}:`)) {
+ const port = parseInt(data.toString().match(new RegExp(`${listenAddress}:(?<port>\\d+)`))?.groups?.port);
+ const registry = `http://${listenAddress}:${port}`;
+ console.log(`Local registry started on ${registry}`);
process.env.npm_config_registry = registry;
- (0, child_process_1.execSync)(`npm config set //localhost:${port}/:_authToken "secretVerdaccioToken"`, {
+ (0, child_process_1.execSync)(`npm config set //${listenAddress}:${port}/:_authToken "secretVerdaccioToken"`, {
windowsHide: false,
});
// yarnv1
process.env.YARN_REGISTRY = registry;
// yarnv2
process.env.YARN_NPM_REGISTRY_SERVER = registry;
- process.env.YARN_UNSAFE_HTTP_WHITELIST = 'localhost';
+ process.env.YARN_UNSAFE_HTTP_WHITELIST = listenAddress;
console.log('Set npm and yarn config registry to ' + registry);
resolve(() => {
childProcess.kill();
- (0, child_process_1.execSync)(`npm config delete //localhost:${port}/:_authToken`, {
+ (0, child_process_1.execSync)(`npm config delete //${listenAddress}:${port}/:_authToken`, {
windowsHide: false,
});
});
Loading

0 comments on commit c7d2db6

Please sign in to comment.