Leosvel Pérez Espinosa 3ec539065d
feat(angular): add support for angular v19 (#28847)
## Third-party deps support for Angular v19

- [x] `jest-preset-angular`
  - [x] PRs:
    - [x] https://github.com/thymikee/jest-preset-angular/pull/2835
  - [x] Released:
- [x] RC:
https://github.com/thymikee/jest-preset-angular/releases/tag/v14.4.0-rc.0
- [x] Stable:
https://github.com/thymikee/jest-preset-angular/releases/tag/v14.4.0
- [x] Angular ESLint
  - [x] PRs:
    - [x] https://github.com/angular-eslint/angular-eslint/pull/2109
  - [x] Released:
- [x]
https://github.com/angular-eslint/angular-eslint/releases/tag/v19.0.0
- [x] Storybook
  - [x] PRs:
    - [x] https://github.com/storybookjs/storybook/pull/29659
    - [x] https://github.com/storybookjs/storybook/pull/29677
  - [x] Released:
    - [x] https://github.com/storybookjs/storybook/pull/29679
- [ ] NgRx
  - [x] PRs:
    - [x] https://github.com/ngrx/platform/pull/4602
  - [ ] Released:
- [x] Beta:
https://github.com/ngrx/platform/blob/main/CHANGELOG.md#1900-beta0-2024-11-20
    - [ ] Stable:
- [ ] Analog
  - [x] PRs:
    - [x] https://github.com/analogjs/analog/pull/1447
    - [x] https://github.com/analogjs/analog/pull/1451
  - [ ] Released:
- [x] Beta:
https://github.com/analogjs/analog/releases/tag/v1.10.0-beta.6
    - [ ] Stable:

<!-- 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` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

Angular v19 is not supported.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

Angular v19 should be supported.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->
 
Fixes #29028
2024-12-02 11:43:24 -05:00

99 lines
2.6 KiB
TypeScript

import type { Tree } from '@nx/devkit';
import { formatFiles, generateFiles, joinPathFragments } from '@nx/devkit';
import { addToNgModule } from '../utils';
import { getInstalledAngularVersionInfo } from '../utils/version-utils';
import {
exportComponentInEntryPoint,
findModuleFromOptions,
normalizeOptions,
setGeneratorDefaults,
} from './lib';
import type { Schema } from './schema';
export async function componentGenerator(tree: Tree, rawOptions: Schema) {
const options = await normalizeOptions(tree, rawOptions);
const { major: angularMajorVersion } = getInstalledAngularVersionInfo(tree);
generateFiles(
tree,
joinPathFragments(__dirname, 'files'),
options.directory,
{
name: options.name,
fileName: options.fileName,
symbolName: options.symbolName,
exportDefault: options.exportDefault,
style: options.style,
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate,
standalone: options.standalone,
skipSelector: options.skipSelector,
changeDetection: options.changeDetection,
viewEncapsulation: options.viewEncapsulation,
displayBlock: options.displayBlock,
selector: options.selector,
// Angular v19 or higher defaults to true, while v18 or lower defaults to false
setStandalone:
(angularMajorVersion >= 19 && !options.standalone) ||
(angularMajorVersion < 19 && options.standalone),
angularMajorVersion,
tpl: '',
}
);
if (options.skipTests) {
const pathToSpecFile = joinPathFragments(
options.directory,
`${options.fileName}.spec.ts`
);
tree.delete(pathToSpecFile);
}
if (options.inlineTemplate) {
const pathToTemplateFile = joinPathFragments(
options.directory,
`${options.fileName}.html`
);
tree.delete(pathToTemplateFile);
}
if (options.style === 'none' || options.inlineStyle) {
const pathToStyleFile = joinPathFragments(
options.directory,
`${options.fileName}.${options.style}`
);
tree.delete(pathToStyleFile);
}
if (!options.skipImport && !options.standalone) {
const modulePath = findModuleFromOptions(
tree,
options,
options.projectRoot
);
addToNgModule(
tree,
options.directory,
modulePath,
options.name,
options.symbolName,
options.fileName,
'declarations',
true,
options.export
);
}
exportComponentInEntryPoint(tree, options);
setGeneratorDefaults(tree, options);
if (!options.skipFormat) {
await formatFiles(tree);
}
}
export default componentGenerator;