You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ckage.json` using new `getMatchingPathRecursive`
Renamed `zWorkspaceFindRootPackageJson` to `zWorkspaceFindRootPackageJsonPath` and used it in various parts of `zenflux-jest` and `zenflux-cli` code. Optimized workspace functions to better filter packages containing `package.json` using improved path fetching method. Added the function `zWorkspaceGetRootPackageName` in `workspace.ts`, which was then implemented in `command-base.ts`.
… support multi registries
The registry handling has been updated to support multiple active registries. This includes the addition of `@list` and `@clean` commands. The Verdaccio server-running command now ensures it is not already running before starting, and locates a free port within the default range. The `@use` command is updated to allow for selection of the registry by ID.
4, because the PR introduces a significant amount of changes across multiple files and functionalities, including network operations, command line interfaces, and configuration management. The complexity of the changes, especially with the addition of new network utility functions and modifications to registry handling, requires careful review to ensure functionality and security.
🧪 Relevant tests
No
⚡ Possible issues
Possible Bug: The use of zNetCheckPortOnline with a very short timeout (10 ms) in packages/zenflux-cli/src/utils/net.ts might lead to false negatives in checking port availability due to such a brief wait period.
Error Handling: In packages/zenflux-cli/src/core/registry.ts, the function zRegistryGetNpmRc throws an error if the token cannot be found in the .npmrc file. This could be handled more gracefully to avoid crashing the application.
Performance Concern: The recursive directory search in packages/zenflux-typescript-vm/src/utils.js could potentially lead to performance issues if the directory structure is very large or deep.
Why: Adding a try-catch block around the fetch call to handle potential network errors gracefully addresses a possible bug and improves the robustness of the code. This is a significant improvement.
9
Add error handling to file reading and processing in zRegistryGetNpmRc
Refactor the zRegistryGetNpmRc function to handle potential exceptions from fs.readFileSync and crypto.createHash more gracefully by using try-catch blocks.
Why: Adding error handling to the zRegistryGetNpmRc function is a valuable improvement that increases the robustness of the code by preventing unhandled exceptions.
8
Enhancement
Enhance socket management by clearing the timeout after a connection or error
Modify the zNetCheckPortOnline function to handle the socket timeout more robustly by clearing the timeout after a connection is established or an error occurs, to prevent potential memory leaks or unexpected behavior.
Why: This suggestion enhances the robustness of the zNetCheckPortOnline function by ensuring the timeout is cleared, which prevents potential memory leaks and unexpected behavior. This is a significant improvement.
9
Performance
Use asynchronous file operations to improve performance
Replace the synchronous file operations with asynchronous ones to improve performance and avoid blocking the event loop.
-fs.writeFileSync( paths.npmRc, data );+await fs.promises.writeFile( paths.npmRc, data );
Suggestion importance[1-10]: 8
Why: Replacing synchronous file operations with asynchronous ones can improve performance and avoid blocking the event loop, which is beneficial for the application's responsiveness. This is a valuable enhancement.
8
Maintainability
Refactor server shutdown logic into a separate function
Extract the logic for server shutdown into a separate function to improve code readability and reusability.
Why: Extracting the server shutdown logic into a separate function improves code readability and reusability. This is a good practice for maintainability, though it is not critical.
7
Centralize URL formatting for logging
Replace the direct use of util.inspect with a dedicated function to format URLs for logging. This will centralize URL formatting and make it easier to adjust the formatting in one place if needed.
-ConsoleManager.$.log( `You can access the registry at ${ util.inspect( url ) }` );+ConsoleManager.$.log( `You can access the registry at ${ formatUrlForLogging(url) }` );
Suggestion importance[1-10]: 6
Why: The suggestion to centralize URL formatting for logging improves maintainability by making it easier to adjust the formatting in one place if needed. However, this change is not crucial and only brings a small improvement.
6
Possible issue
Ensure path resolutions are dependent on the successful determination of etcPath
In the zGlobalInitPaths function, ensure that workspaceEtcPath and verdaccioPath are only resolved if etcPath is successfully determined to avoid potential errors from undefined paths.
Why: This suggestion improves the reliability of the zGlobalInitPaths function by ensuring dependent paths are only resolved if the base path is successfully determined. This is a useful enhancement for preventing potential runtime errors.
7
Improve type safety by allowing workspaceName to be undefined
Consider using a more specific type for the workspaceName parameter in the zGlobalInitPaths function to ensure it is always a string and not potentially undefined. This can help avoid runtime errors when resolving paths.
Why: The suggestion to allow workspaceName to be undefined is not necessary since the current implementation assumes it is always a string. Allowing it to be undefined could introduce more complexity without significant benefit.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement, Bug fix
Description
zWorkspaceFindRootPackageJson
tozWorkspaceFindRootPackageJsonPath
and updated references.ConsoleMenu
to include selected item index.Changes walkthrough 📝
15 files
command-base.ts
Update workspace path and name initialization in CommandBase.
packages/zenflux-cli/src/base/command-base.ts
zWorkspaceFindRootPackageJson
tozWorkspaceFindRootPackageJsonPath
.zWorkspaceGetRootPackageName
function.initPathsArgs
to includeworkspaceName
.publish.ts
Enhance publish command to support multiple registries.
packages/zenflux-cli/src/commands/publish.ts
registry.ts
Add multi-registry support and new commands in Registry.
packages/zenflux-cli/src/commands/registry.ts
global.ts
Enhance global paths initialization with workspaceEtc.
packages/zenflux-cli/src/core/global.ts
workspaceEtc
path.zGlobalInitPaths
to useworkspaceEtc
.registry.ts
Add registry handling functions in core registry module.
packages/zenflux-cli/src/core/registry.ts
workspace.ts
Update workspace functions and add root package name retrieval.
packages/zenflux-cli/src/core/workspace.ts
zWorkspaceFindRootPackageJson
tozWorkspaceFindRootPackageJsonPath
.zWorkspaceGetRootPackageName
function.zenflux.ts
Update default registry host and port range.
packages/zenflux-cli/src/definitions/zenflux.ts
console-menu.ts
Enhance ConsoleMenu to include selected item index.
packages/zenflux-cli/src/modules/console/console-menu.ts
ConsoleMenu
selected item.net.ts
Add network utility functions for port management.
packages/zenflux-cli/src/utils/net.ts
free ports.
index.ts
Update workspace root package JSON path function in zenflux-jest.
packages/zenflux-jest/src/index.ts
zWorkspaceFindRootPackageJson
tozWorkspaceFindRootPackageJsonPath
.utils.d.ts
Enhance getMatchingPathsRecursive with options parameter.
packages/zenflux-typescript-vm/types/utils.d.ts
getMatchingPathsRecursive
to include options parameter.workspace-provider.js
Refactor workspace provider for improved package directory finding.
packages/zenflux-typescript-vm/src/providers/workspace-provider.js
logic.
utils.js
Enhance getMatchingPathsRecursive with options parameter.
packages/zenflux-typescript-vm/src/utils.js
getMatchingPathsRecursive
to include options parameter.package.json
Update package.json to include TypeScript config files.
packages/zenflux-cli/package.json
tsconfig.json
andtsconfig.paths.json
to files.package.json
Update package.json to include TypeScript config files.
packages/zenflux-typescript-vm/package.json
tsconfig.json
andtsconfig.import-meta.json
to files.