-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(tools): bump northstar packages v9 deps on dep mismatch resolution #25806
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,31 +2,32 @@ import * as semver from 'semver'; | |
| import { Tree, formatFiles, updateJson, readJson, readProjectConfiguration } from '@nrwl/devkit'; | ||
|
|
||
| import { getProjectConfig, getProjects, isPackageVersionPrerelease } from '../../utils'; | ||
| import { PackageJson } from '../../types'; | ||
| import type { PackageJson } from '../../types'; | ||
|
|
||
| export default async function (tree: Tree) { | ||
| const projects = getProjects(tree); | ||
|
|
||
| projects.forEach((_project, projectName) => { | ||
| const config = getProjectConfig(tree, { packageName: projectName }); | ||
|
|
||
| const { tags = [] } = readProjectConfiguration(tree, projectName); | ||
| // Ignore northstar packages | ||
| if (tags.includes('react-northstar')) { | ||
| return; | ||
| } | ||
| const scope = getProjectScope(config); | ||
|
|
||
| updateJson(tree, config.paths.packageJson, (packageJson: PackageJson) => { | ||
| if (packageJson.dependencies) { | ||
| packageJson.dependencies = getUpdatedDependencies(tree, packageJson.dependencies); | ||
| packageJson.dependencies = getUpdatedDependencies(tree, { dependencies: packageJson.dependencies, scope }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. more args needed -> refactored to options pattern |
||
| } | ||
|
|
||
| if (packageJson.devDependencies) { | ||
| packageJson.devDependencies = getUpdatedDependencies(tree, packageJson.devDependencies); | ||
| packageJson.devDependencies = getUpdatedDependencies(tree, { | ||
| dependencies: packageJson.devDependencies, | ||
| scope, | ||
| }); | ||
| } | ||
|
|
||
| if (packageJson.peerDependencies) { | ||
| packageJson.peerDependencies = getUpdatedDependencies(tree, packageJson.peerDependencies); | ||
| packageJson.peerDependencies = getUpdatedDependencies(tree, { | ||
| dependencies: packageJson.peerDependencies, | ||
| scope, | ||
| }); | ||
| } | ||
|
|
||
| return packageJson; | ||
|
|
@@ -46,7 +47,11 @@ function isProjectInWorkspace(tree: Tree, projectName: string) { | |
| } | ||
| } | ||
|
|
||
| function getUpdatedDependencies(tree: Tree, dependencies: Record<string, string>) { | ||
| function getUpdatedDependencies( | ||
| tree: Tree, | ||
| options: { dependencies: Record<string, string>; scope: ReturnType<typeof getProjectScope> }, | ||
| ) { | ||
| const { dependencies, scope } = options; | ||
| return Object.entries(dependencies).reduce((acc, [dependencyName, versionRange]) => { | ||
| if (versionRange === '*') { | ||
| return acc; | ||
|
|
@@ -62,9 +67,15 @@ function getUpdatedDependencies(tree: Tree, dependencies: Record<string, string> | |
| return acc; | ||
| } | ||
|
|
||
| const shouldHaveCaret = !isPackageVersionPrerelease(minVersion.raw) || versionRange[0] === '^'; | ||
|
|
||
| const depPackageConfig = getProjectConfig(tree, { packageName: dependencyName }); | ||
| const depScope = getProjectScope(depPackageConfig); | ||
|
|
||
| const isNorthstarUnsupportedDepBump = scope.isReactNorthstarPackage && !depScope.isReactComponentsPackage; | ||
| if (isNorthstarUnsupportedDepBump) { | ||
| return acc; | ||
| } | ||
|
|
||
| const shouldHaveCaret = !isPackageVersionPrerelease(minVersion.raw) || versionRange[0] === '^'; | ||
|
|
||
| acc[dependencyName] = `${shouldHaveCaret ? '^' : ''}${ | ||
| readJson<PackageJson>(tree, depPackageConfig.paths.packageJson).version | ||
|
|
@@ -73,3 +84,11 @@ function getUpdatedDependencies(tree: Tree, dependencies: Record<string, string> | |
| return acc; | ||
| }, dependencies); | ||
| } | ||
|
|
||
| function getProjectScope(project: ReturnType<typeof getProjectConfig>) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this to utils?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I was hesitant about that :D , we can do that later if we find shared usage for this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do a follow - normalizing all tags and tweaking this to utils |
||
| const tags = project.projectConfig.tags ?? []; | ||
| const isReactPackage = tags.includes('v8'); | ||
| const isReactNorthstarPackage = tags.includes('react-northstar'); | ||
| const isReactComponentsPackage = tags.includes('vNext'); | ||
| return { isReactPackage, isReactNorthstarPackage, isReactComponentsPackage }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,7 +197,7 @@ export function isPackageVersionConverged(versionString: string) { | |
|
|
||
| export function isPackageVersionPrerelease(versionString: string) { | ||
| const version = semver.parse(versionString); | ||
| return version?.prerelease?.length && version?.prerelease?.length > 0; | ||
| return Boolean(version?.prerelease?.length && version?.prerelease?.length > 0); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. casted to explicitly return |
||
| } | ||
|
|
||
| export function isPackageConverged(tree: Tree, project: ProjectConfiguration) { | ||
|
|
||
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.
these awaits dont do anything as readTargetPackageJson is sync