Workspace utilities API and internals cleanup #388
Merged
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.
Overview
Massive cleanup and coherence improvements to the APIs related to monorepo workspaces/packages...
In addition to the naming changes detailed below, the structure of per-manager utilities has been greatly simplified and deduped:
workspaces/implementations/<manager>.tsONLY includes the internals that vary by manager: getting the workspace patterns or paths, and getting the catalogs if applicable. These internals throw on error.wrapWorkspaceUtility, which is called by each main function (e.g.getWorkspaceInfos)| undefinedand return undefined rather than empty arrays (or in some cases empty objects) if there was an error or nothing was found. APIs following that pattern will log rather than throwing on error.getYarnWorkspaces, several functions now have an optionalmanagerparamDetails and API changes
getWorkspaces/getWorkspaceAsynchas been renamed togetWorkspaceInfos/getWorkspaceInfosAsync, and the deprecatedWorkspaceInfotype has been removed (useWorkspaceInfos).getWorkspaceRoothas been renamed togetWorkspaceManagerRoot. (getWorkspaceManagerAndRootis now exported too, if you also want to know the manager.)string[] | undefinedinstead of returning an empty array on error:getAllPackageJsonFiles/getAllPackageJsonFilesAsyncgetWorkspacePackagePaths/getWorkspacePackagePathsAsyncgetWorkspaceInfos/getWorkspaceInfosAsyncmanagerparam to force using a specific manager. Manager-specificget___WorkspaceRootandget___Workspaceshave been removed.getWorkspaceManagerRootfindProjectRoot(falls back to the git root and throws if neither is found)getWorkspacePackagePaths/getWorkspacePackagePathsAsyncgetWorkspacePatterns(new)getWorkspaceInfos/getWorkspaceInfosAsyncgetCatalogslistOfWorkspacePackageNamesis removed since it's trivially replaced byworkspaces.map(w => w.name).