-
Notifications
You must be signed in to change notification settings - Fork 160
fix(schematics): ng add for all projects #11761 #11870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -156,24 +156,21 @@ const addHammerToConfig = | |||
const includeDependencies = async (pkgJson: any, context: SchematicContext, tree: Tree): Promise<void> => { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this variable used anywhere in this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, on line 170
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you turn this in a forEach loop for consistency with the code above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot, because of the await, few lines below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
projects.forEach(async (project) => {
await addHammerToConfig(project, tree, 'build', context);
await addHammerToConfig(project, tree, 'test', context);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lipata This is I/O code. I don't see how it executing more efficiently makes it worse than a more inefficient implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.MD
updates for the feature docsREADME.MD
CHANGELOG.MD
updates for newly added functionalityng update
migrations for the breaking changes (migrations guidelines)