Skip to content

Commit

Permalink
fix(angular): add $schema property to generated project configs (nrwl…
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez authored Sep 16, 2022
1 parent 1c0bebf commit e2bfaa6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { Tree } from '@nrwl/devkit';
import type { NormalizedSchema } from './normalized-schema';

import {
updateJson,
addProjectConfiguration,
getProjects,
offsetFromRoot,
readProjectConfiguration,
updateProjectConfiguration,
removeProjectConfiguration,
offsetFromRoot,
updateJson,
} from '@nrwl/devkit';
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
import { E2eTestRunner, UnitTestRunner } from '../../../utils/test-runners';
import type { NormalizedSchema } from './normalized-schema';

export function updateConfigFiles(host: Tree, options: NormalizedSchema) {
updateTsConfigOptions(host, options);
Expand Down Expand Up @@ -88,7 +87,23 @@ function updateAppAndE2EProjectConfigurations(

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) {
host.delete(`${options.appProjectRoot}/src/app/app.component.spec.ts`);
Expand Down
23 changes: 20 additions & 3 deletions packages/angular/src/generators/library/lib/update-project.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {
addProjectConfiguration,
generateFiles,
getWorkspaceLayout,
joinPathFragments,
offsetFromRoot,
readProjectConfiguration,
removeProjectConfiguration,
Tree,
updateJson,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import { replaceAppNameWithPath } from '@nrwl/workspace/src/utils/cli-config-utils';
import * as path from 'path';
import { NormalizedSchema } from './normalized-schema';
import { updateNgPackage } from './update-ng-package';
Expand Down Expand Up @@ -173,7 +174,23 @@ function fixProjectWorkspaceConfig(

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(
Expand Down

0 comments on commit e2bfaa6

Please sign in to comment.