fix(schematics): ng add for all projects #11761#11870
Conversation
| const workspaceHost = createHost(tree); | ||
| const { workspace } = await workspaces.readWorkspace(tree.root.path, workspaceHost); | ||
| const defaultProject = getDefaultProjectFromWorkspace(workspace); | ||
| const projects = getProjectsFromWorkspace(workspace); |
There was a problem hiding this comment.
Is this variable used anywhere in this method?
| logIncludingDependency(context, pkg, version); | ||
| addPackageToPkgJson(tree, pkg, version, entry.target); | ||
| if (pkg === 'hammerjs') { | ||
| for (let project of projects.values()) { |
There was a problem hiding this comment.
Can you turn this in a forEach loop for consistency with the code above?
There was a problem hiding this comment.
I cannot, because of the await, few lines below.
There was a problem hiding this comment.
projects.forEach(async (project) => {
await addHammerToConfig(project, tree, 'build', context);
await addHammerToConfig(project, tree, 'test', context);
});There was a problem hiding this comment.
Use Promise.all(projects.map(...)) then. I don't see why this has to be executed in sequence.
There was a problem hiding this comment.
workspace.projects type is not an array, but ProjectDefinitionCollection, which implements ReadonlyMap<string, V> . That's why the following code is needed:
await Promise.all(Array.from(workspace.projects.values()).map(async (project) => {
await addHammerToConfig(project, tree, 'build', context);
await addHammerToConfig(project, tree, 'test', context);
}));
I guess it is still faster than writing files in sequence, but as a code is not better than for of.
There was a problem hiding this comment.
@Lipata This is I/O code. I don't see how it executing more efficiently makes it worse than a more inefficient implementation?
|
|
||
| export const getDefaultProjectFromWorkspace = (workspace: workspaces.WorkspaceDefinition): workspaces.ProjectDefinition => { | ||
| return workspace.projects.get(workspace.extensions['defaultProject'] as string) || workspace.projects.values().next().value; | ||
| export const getProjectsFromWorkspace = (workspace: workspaces.WorkspaceDefinition): workspaces.ProjectDefinitionCollection => { |
There was a problem hiding this comment.
Actually I don't think we need this method as it is anymore.
|
Fix the failing tests. |
Closes #11761
Additional information (check all that apply):
Checklist:
feature/README.MDupdates for the feature docsREADME.MDCHANGELOG.MDupdates for newly added functionalityng updatemigrations for the breaking changes (migrations guidelines)