nx
nx copied to clipboard
@nx/js/plugins/jest/local-registry - listenAddress other than 'localhost' - startLocalRegistry does not resolve promise
Current Behavior
startLocalRegistry of @nx/js/plugins/jest/local-registry does not resolve when the host is different than localhost.
Expected Behavior
I expect --listenAddress='0.0.0.0' of @nx/js:verdaccio to work with startLocalRegistry of @nx/js/plugins/jest/local-registry
GitHub Repo
No response
Steps to Reproduce
// project.json targets
{
"executor": "@nx/js:verdaccio",
"options": {
"port": 4321,
"listenAddress": "0.0.0.0",
"clear": true,
"config": "{projectRoot}/src/local-registry.yml",
"storage": ".local-registry"
}
}
startLocalRegistry has output:
Cleared local registry storage folder /Users/rob/Desktop/hdi-components/.local-registry
warn --- http address - http://0.0.0.0:4321/ - verdaccio/5.32.2
// project.json targets
{
"executor": "@nx/js:verdaccio",
"options": {
"port": 4321,
"clear": true,
"config": "{projectRoot}/src/local-registry.yml",
"storage": ".local-registry"
}
}
startLocalRegistry has output:
Cleared local registry storage folder /Users/rob/Desktop/hdi-components/.local-registry
warn --- http address - http://localhost:4321/ - verdaccio/5.32.2
The startLocalRegistry promise does not resolve because the predicate never matches https://github.com/nrwl/nx/blob/c2af06e0a12529a5c3d1a09024ccc1fabf4e5604/packages/js/src/plugins/jest/start-local-registry.ts#L40-L71
I don't have a deep understanding of @nx/js:verdaccio and verdaccio itself but i guess the executor expects the log level at least to be on warn in order to parse the registry url of the following log statement: warn --- http address - {url} - verdaccio/5.32.2
A workaround for my project is a pnpm patch for now:
if (data.toString().includes('http address')) {
const port = data.toString().match(/http:\/\/(?<host>[^:/]+)(:(?<port>\d+))?/)?.groups?.port;
In general I wonder whether its a good idea to hardcode localhost as the host - maybe it should also be parsed from the log statement aswell.
I also tried to use the listen property in the verdaccio config and omit the port arg in the @nx/js:verdaccio executor but its required - I guess it makes sense that it is required because it uses the port for the npm config shenanigans.
# verdaccio config
listen:
- 0.0.0.0:4321 # no effect
A alternative (which I haven't tested) may be to not use the @nx/js:verdaccio but verdaccios cli itself and hard code the registry in the global .npmrc to a specific value e.g. http://localhost:4321. This may be fine for lots of use cases - for mine at least it would be.
Nx Report
Node : 20.15.0 OS : darwin-arm64 Native Target : aarch64-macos pnpm : 9.11.0
nx : 19.6.4 @nx/js : 19.6.4 @nx/linter : 19.6.4 @nx/eslint : 19.6.4 @nx/workspace : 19.6.4 @nx/angular : 19.6.4 @nx/cypress : 19.6.4 @nx/devkit : 19.6.4 @nx/eslint-plugin : 19.6.4 @nx/storybook : 19.6.4 @nrwl/tao : 19.6.4 @nx/vite : 19.6.4 @nx/web : 19.6.4 @nx/webpack : 19.6.4 typescript : 5.4.4
Registered Plugins: @hdi-components/tools-tsc-plugin @hdi-components/tools-web-test-runner-plugin @hdi-components/tools-storybook-test-plugin @hdi-components/tools-stylelint-plugin @nx/eslint/plugin @nx/vite/plugin @nx/storybook/plugin
Community plugins: @compodoc/compodoc : 1.1.25 @storybook/angular : 8.3.5 ng-mocks : 14.13.1
Local workspace plugins: @hdi-components/tools-playwright @hdi-components/tools-storybook @hdi-components/tools-publish @hdi-components/tools-release @hdi-components/tools-docker @hdi-components/tools-pack
Failure Logs
No response
Package Manager Version
No response
Operating System
- [x] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)
Additional Information
No response