-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular): install @typescript-eslint/utils when using relevant an…
…gular eslint v18 packages (#26418) <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> Angular ESLint v18 packages now have `@typescript-eslint/utils` as a peer dependency, but new projects don't install it, and existing projects are not getting it installed in a migration. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> The `@typescript-eslint/utils` should be installed when creating new Angular projects and when migrating when the workspace has the relevant Angular ESLint packages in v18. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #26408
- Loading branch information
1 parent
cfcedb4
commit 15e1f78
Showing
6 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/angular/src/migrations/update-19-2-1/add-typescript-eslint-utils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { readJson, updateJson, type Tree } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import migration, { | ||
typescriptEslintUtilsVersion, | ||
} from './add-typescript-eslint-utils'; | ||
|
||
describe('add-typescript-eslint-utils migration', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it.each` | ||
pkgName | version | ||
${'@angular-eslint/eslint-plugin'} | ${'18.0.0'} | ||
${'@angular-eslint/eslint-plugin'} | ${'~18.0.0'} | ||
${'@angular-eslint/eslint-plugin'} | ${'^18.0.0'} | ||
${'@angular-eslint/eslint-plugin'} | ${'^19.0.0'} | ||
${'@angular-eslint/eslint-plugin-template'} | ${'18.0.0'} | ||
${'@angular-eslint/eslint-plugin-template'} | ${'~18.0.0'} | ||
${'@angular-eslint/eslint-plugin-template'} | ${'^18.0.0'} | ||
${'@angular-eslint/eslint-plugin-template'} | ${'^19.0.0'} | ||
`( | ||
'should add "@typescript-eslint/utils" as devDependencies when "$pkgName" is installed with version "$version"', | ||
async ({ pkgName, version }) => { | ||
updateJson(tree, 'package.json', (json) => { | ||
json.devDependencies = { | ||
...json.devDependencies, | ||
[`${[pkgName]}`]: `${version}`, | ||
}; | ||
return json; | ||
}); | ||
|
||
await migration(tree); | ||
|
||
const { devDependencies } = readJson(tree, 'package.json'); | ||
expect(devDependencies['@typescript-eslint/utils']).toBe( | ||
typescriptEslintUtilsVersion | ||
); | ||
} | ||
); | ||
|
||
it.each` | ||
pkgName | version | ||
${'@angular-eslint/eslint-plugin'} | ${'17.0.0'} | ||
${'@angular-eslint/eslint-plugin'} | ${'~17.0.0'} | ||
${'@angular-eslint/eslint-plugin'} | ${'^17.0.0'} | ||
${'@angular-eslint/eslint-plugin-template'} | ${'17.0.0'} | ||
${'@angular-eslint/eslint-plugin-template'} | ${'~17.0.0'} | ||
${'@angular-eslint/eslint-plugin-template'} | ${'^17.0.0'} | ||
`( | ||
'should not add "@typescript-eslint/utils" when "$pkgName" is installed with version "$version"', | ||
async ({ pkgName, version }) => { | ||
updateJson(tree, 'package.json', (json) => { | ||
json.devDependencies = { | ||
...json.devDependencies, | ||
[`${[pkgName]}`]: `${version}`, | ||
}; | ||
return json; | ||
}); | ||
|
||
await migration(tree); | ||
|
||
const { devDependencies } = readJson(tree, 'package.json'); | ||
expect(devDependencies['@typescript-eslint/utils']).toBeUndefined(); | ||
} | ||
); | ||
|
||
it('should not add "@typescript-eslint/utils" when "@angular-eslint/eslint-plugin" and "@angular-eslint/eslint-plugin-template" are not installed', async () => { | ||
await migration(tree); | ||
|
||
const { devDependencies } = readJson(tree, 'package.json'); | ||
expect(devDependencies['@typescript-eslint/utils']).toBeUndefined(); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/angular/src/migrations/update-19-2-1/add-typescript-eslint-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
addDependenciesToPackageJson, | ||
formatFiles, | ||
type Tree, | ||
} from '@nx/devkit'; | ||
import { | ||
getInstalledPackageVersion, | ||
getInstalledPackageVersionInfo, | ||
} from '../../generators/utils/version-utils'; | ||
|
||
export const typescriptEslintUtilsVersion = '^8.0.0-alpha.28'; | ||
|
||
export default async function (tree: Tree) { | ||
if (getInstalledPackageVersion(tree, '@typescript-eslint/utils')) { | ||
return; | ||
} | ||
|
||
const eslintPluginVersionInfo = | ||
getInstalledPackageVersionInfo(tree, '@angular-eslint/eslint-plugin') ?? | ||
getInstalledPackageVersionInfo( | ||
tree, | ||
'@angular-eslint/eslint-plugin-template' | ||
); | ||
if (!eslintPluginVersionInfo || eslintPluginVersionInfo.major < 18) { | ||
return; | ||
} | ||
|
||
addDependenciesToPackageJson( | ||
tree, | ||
{}, | ||
{ '@typescript-eslint/utils': typescriptEslintUtilsVersion } | ||
); | ||
|
||
await formatFiles(tree); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters