Skip to content
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

feat(nx-plugin): fix angular 15.x and 16.x install support #481

Merged

Conversation

jeremyhofer
Copy link
Contributor

@jeremyhofer jeremyhofer commented Jun 25, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Which package are you modifying?

  • vite-plugin-angular
  • vite-plugin-nitro
  • astro-angular
  • create-analog
  • router
  • platform
  • content
  • nx-plugin
  • trpc

What is the current behavior?

Before this update the plugin would force the latest Angular version to be used within a Nx workspace regardless of the Angular version(s) supported by the user's current version of Nx. This led to some inconsistencies at time with the dependency versions used and installed, causing various install, build, serve, and similar issues.

This also addresses some installation and build related issues due to the @nrwl to @nx scope transition, and @angular-devkit/build-angular internal project path changes.

Potentially addresses #486 which was recently opened.

What is the new behavior?

This version will install consistent dependency versions for Analog and Angular.

For Nx workspaces on Nx versions older than 15.2.0 installation will not be supported as Nx did not add Angular 15 support until 15.2.0.

For Nx workspaces on Nx versions 15.2.0 through 16.0.0 the latest 15.X version of Angular will be installed (currently ~15.2.0 as of this PR). The Analog dependency versions that work for Angular 15.X are installed.

For Nx workspaces on Nx version 16.1.0 and newer the latest 16.X version of Angular will be installed (currently ~16.1.0 as of this PR). Latest Analog dependency versions are installed as Angular 16 is the current major version.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

[optional] What gif best describes this PR or how it makes you feel?

@jeremyhofer jeremyhofer force-pushed the nx-plugin-16-point-1-jhofer branch 4 times, most recently from 1a70a9c to e907d09 Compare June 30, 2023 00:51
@jeremyhofer jeremyhofer changed the title feat(nx-plugin): update version handling for Nx 16.4 and parameterize… feat(nx-plugin): fix angular 15.x and 16.x install support Jun 30, 2023
currently the nx plugin let the nx angular init generator
pick the version of angular to be installed. this meant
that when the nx angular init generator picks 16.0.0, due
to ~16.0.0 version in the nx repository, our created analog
application did not work anymore. this fix makes sure the
correct version ^16.1.0 is picked by nx tooling. unfortunately,
semver does not like ^ in its versions so we have to remove it
before finding the major version or ensuring compatibility.
@goetzrobin goetzrobin force-pushed the fix-nx-plugin-16-point-1-incompatibility branch from 15efeab to 94e756d Compare June 30, 2023 02:07
@jeremyhofer jeremyhofer marked this pull request as ready for review June 30, 2023 05:05
Copy link
Member

@goetzrobin goetzrobin left a comment

Choose a reason for hiding this comment

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

I tested it locally and we need one more change to make it work for Nx 15:

Where we add the analog dependencies we also need to remove the initially installed
platform version. This is kind of counter intuitive, but we are basically replacing the latest
platform with the one that works for the Nx workspace version. If we don't do that the newest plugin will kept and we get a file path error. Making this changes will take care of the file
changes in the angular builder.

import { addDependenciesToPackageJson, removeDependenciesFromPackageJson, Tree } from '@nx/devkit';
import { getAnalogDependencies } from '../versions/dependencies';
import { getAnalogDevDependencies } from '../versions/dev-dependencies';

export async function addAnalogDependencies(
  tree: Tree,
  nxVersion: string,
  angularVersion: string
) {
  const dependencies = getAnalogDependencies(nxVersion, angularVersion);
  const devDependencies = getAnalogDevDependencies(nxVersion);
  removeDependenciesFromPackageJson(tree, [], ['@analogjs/platform'])
  addDependenciesToPackageJson(tree, dependencies, devDependencies);
}

Another thing I noticed is that I don't believe Nx follows their own version matrix. Once I have Nx 16.0.0 Angular 16.1 gets installed (with a brand new workspace)

@jeremyhofer jeremyhofer changed the base branch from fix-nx-plugin-16-point-1-incompatibility to main June 30, 2023 20:04
Copy link
Member

@goetzrobin goetzrobin left a comment

Choose a reason for hiding this comment

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

Very excited for this to land! 🚀 🔥

@goetzrobin
Copy link
Member

@brandonroberts code changes look good from my side and locally tests pass for me. not sure why CI is timing out :(

@brandonroberts brandonroberts merged commit acbdf14 into analogjs:main Jul 1, 2023
@brandonroberts
Copy link
Member

Awesome work! @allcontributors add @jeremyhofer for code, infra

@allcontributors
Copy link
Contributor

@brandonroberts

I've put up a pull request to add @jeremyhofer! 🎉

Villanuevand pushed a commit to Villanuevand/analog that referenced this pull request Sep 12, 2023
)

Co-authored-by: Robin Goetz <tug29225@temple.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants