Skip to content

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

Merged
merged 10 commits into from
Jul 19, 2022
Merged

Conversation

Lipata
Copy link
Member

@Lipata Lipata commented Jul 15, 2022

Closes #11761

Additional information (check all that apply):

  • Bug fix
  • New functionality
  • Documentation
  • Demos
  • CI/CD

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
jackofdiamond5
jackofdiamond5 previously approved these changes Jul 18, 2022
@Lipata Lipata added ✅ status: verified Applies to PRs that have passed manual verification ❌ status: awaiting-test PRs awaiting manual verification and removed ❌ status: awaiting-test PRs awaiting manual verification ✅ status: verified Applies to PRs that have passed manual verification labels Jul 18, 2022
@Lipata Lipata requested a review from kdinev July 18, 2022 14:32

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@Lipata Lipata requested a review from jackofdiamond5 July 19, 2022 08:01
@@ -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);
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, on line 170

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@Lipata Lipata requested a review from kdinev July 19, 2022 08:51
@Lipata Lipata requested a review from jackofdiamond5 July 19, 2022 10:52
jackofdiamond5
jackofdiamond5 previously approved these changes Jul 19, 2022
logIncludingDependency(context, pkg, version);
addPackageToPkgJson(tree, pkg, version, entry.target);
if (pkg === 'hammerjs') {
for (let project of projects.values()) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@kdinev kdinev Jul 19, 2022

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);
});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kdinev I remember having the failing test when using forEach instead of for of and after going through some sources (like this) I decided to stick with for of

Copy link
Member

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.

Copy link
Member Author

@Lipata Lipata Jul 19, 2022

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.

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Lipata Lipata assigned jackofdiamond5 and unassigned valadzhov Jul 19, 2022
@jackofdiamond5 jackofdiamond5 removed the ❌ status: awaiting-test PRs awaiting manual verification label Jul 19, 2022
@jackofdiamond5 jackofdiamond5 added 💥 status: in-test PRs currently being tested ✅ status: verified Applies to PRs that have passed manual verification and removed 💥 status: in-test PRs currently being tested labels Jul 19, 2022

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 => {
Copy link
Member

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.

@jackofdiamond5 jackofdiamond5 self-requested a review July 19, 2022 11:45
kdinev
kdinev previously approved these changes Jul 19, 2022
@kdinev
Copy link
Member

kdinev commented Jul 19, 2022

Fix the failing tests.

@Lipata Lipata merged commit 151c843 into 14.0.x Jul 19, 2022
@Lipata Lipata deleted the nalipiev/add-schematics branch July 19, 2022 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ng add schematics version: 14.0.x ✅ status: verified Applies to PRs that have passed manual verification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants