fix(angular): add $schema property to generated project configs (#12031)

This commit is contained in:
Leosvel Pérez Espinosa 2022-09-16 10:11:46 +01:00 committed by GitHub
parent 1c0bebf194
commit e2bfaa68f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 10 deletions

View File

@ -1,16 +1,15 @@
import type { Tree } from '@nrwl/devkit'; import type { Tree } from '@nrwl/devkit';
import type { NormalizedSchema } from './normalized-schema';
import { import {
updateJson, addProjectConfiguration,
getProjects, getProjects,
readProjectConfiguration,
updateProjectConfiguration,
removeProjectConfiguration,
offsetFromRoot, offsetFromRoot,
readProjectConfiguration,
removeProjectConfiguration,
updateJson,
} from '@nrwl/devkit'; } from '@nrwl/devkit';
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils'; import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
import { E2eTestRunner, UnitTestRunner } from '../../../utils/test-runners'; import { E2eTestRunner, UnitTestRunner } from '../../../utils/test-runners';
import type { NormalizedSchema } from './normalized-schema';
export function updateConfigFiles(host: Tree, options: NormalizedSchema) { export function updateConfigFiles(host: Tree, options: NormalizedSchema) {
updateTsConfigOptions(host, options); updateTsConfigOptions(host, options);
@ -88,7 +87,23 @@ function updateAppAndE2EProjectConfigurations(
project.tags = options.parsedTags; project.tags = options.parsedTags;
updateProjectConfiguration(host, options.name, project); /**
* The "$schema" property on our configuration files is only added when the
* project configuration is added and not when updating it. It's done this
* way to avoid re-adding "$schema" when updating a project configuration
* and that property was intentionally removed by the devs.
*
* Since the project gets created by the Angular application schematic,
* the "$schema" property is not added, so we remove the project and add
* it back to workaround that.
*/
removeProjectConfiguration(host, options.name);
addProjectConfiguration(
host,
options.name,
project,
options.standaloneConfig
);
if (options.unitTestRunner === UnitTestRunner.None) { if (options.unitTestRunner === UnitTestRunner.None) {
host.delete(`${options.appProjectRoot}/src/app/app.component.spec.ts`); host.delete(`${options.appProjectRoot}/src/app/app.component.spec.ts`);

View File

@ -1,15 +1,16 @@
import { import {
addProjectConfiguration,
generateFiles, generateFiles,
getWorkspaceLayout, getWorkspaceLayout,
joinPathFragments, joinPathFragments,
offsetFromRoot, offsetFromRoot,
readProjectConfiguration, readProjectConfiguration,
removeProjectConfiguration,
Tree, Tree,
updateJson, updateJson,
updateProjectConfiguration,
} from '@nrwl/devkit'; } from '@nrwl/devkit';
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript'; import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
import * as path from 'path'; import * as path from 'path';
import { NormalizedSchema } from './normalized-schema'; import { NormalizedSchema } from './normalized-schema';
import { updateNgPackage } from './update-ng-package'; import { updateNgPackage } from './update-ng-package';
@ -173,7 +174,23 @@ function fixProjectWorkspaceConfig(
delete project.targets.test; delete project.targets.test;
updateProjectConfiguration(host, options.name, project); /**
* The "$schema" property on our configuration files is only added when the
* project configuration is added and not when updating it. It's done this
* way to avoid re-adding "$schema" when updating a project configuration
* and that property was intentionally removed by the devs.
*
* Since the project gets created by the Angular application schematic,
* the "$schema" property is not added, so we remove the project and add
* it back to workaround that.
*/
removeProjectConfiguration(host, options.name);
addProjectConfiguration(
host,
options.name,
project,
options.standaloneConfig
);
} }
function updateProjectTsConfig( function updateProjectTsConfig(