Skip to content

Commit b1e3545

Browse files
authoredApr 27, 2023
fix(core): do not strip additional angular.json properties (#16615)
1 parent 24b2dee commit b1e3545

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed
 

‎docs/generated/devkit/nrwl_devkit.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ Path to the directory where Nx stores its cache and daemon-related files.
832832

833833
### workspaceRoot
834834

835-
`Const` **workspaceRoot**: `string`
835+
**workspaceRoot**: `string`
836836

837837
The root of the workspace
838838

‎docs/generated/packages/devkit/documents/nrwl_devkit.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ Path to the directory where Nx stores its cache and daemon-related files.
832832

833833
### workspaceRoot
834834

835-
`Const` **workspaceRoot**: `string`
835+
**workspaceRoot**: `string`
836836

837837
The root of the workspace
838838

‎packages/nx/src/adapter/angular-json.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function shouldMergeAngularProjects(
2626
}
2727
}
2828

29-
function isAngularPluginInstalled() {
29+
export function isAngularPluginInstalled() {
3030
try {
3131
require.resolve('@nx/angular');
3232
return true;

‎packages/nx/src/adapter/ngcli-adapter.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ import { parseJson } from '../utils/json';
4141
import { NX_ERROR, NX_PREFIX } from '../utils/logger';
4242
import { readModulePackageJson } from '../utils/package-json';
4343
import { detectPackageManager } from '../utils/package-manager';
44-
import { toNewFormat, toOldFormat } from './angular-json';
44+
import {
45+
isAngularPluginInstalled,
46+
toNewFormat,
47+
toOldFormat,
48+
} from './angular-json';
4549
import { normalizeExecutorSchema, Workspaces } from '../config/workspaces';
4650
import {
4751
CustomHasher,
@@ -899,7 +903,8 @@ export function wrapAngularDevkitSchematic(
899903

900904
if (event.kind === 'error') {
901905
} else if (event.kind === 'update') {
902-
if (eventPath === 'angular.json') {
906+
// Apply special handling for the angular.json file, but only when in an Nx workspace
907+
if (eventPath === 'angular.json' && isAngularPluginInstalled()) {
903908
saveProjectsConfigurationsInWrappedSchematic(
904909
host,
905910
event.content.toString()
@@ -1002,7 +1007,10 @@ function saveProjectsConfigurationsInWrappedSchematic(
10021007
? Object.keys(existingAngularJson.projects)
10031008
: [];
10041009

1005-
const newAngularJson = { projects: {} };
1010+
const newAngularJson = existingAngularJson || {};
1011+
1012+
// Reset projects in order to rebuild them, but leave other properties untouched
1013+
newAngularJson.projects = {};
10061014

10071015
Object.keys(projects).forEach((projectName) => {
10081016
if (projectsInAngularJson.includes(projectName)) {

‎packages/nx/src/utils/workspace-root.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { fileExists } from './fileutils';
44
/**
55
* The root of the workspace
66
*/
7-
export const workspaceRoot = workspaceRootInner(process.cwd(), process.cwd());
7+
export let workspaceRoot = workspaceRootInner(process.cwd(), process.cwd());
8+
9+
export function setWorkspaceRoot(root: string): void {
10+
workspaceRoot = root;
11+
}
812

913
export function workspaceRootInner(
1014
dir: string,

1 commit comments

Comments
 (1)

vercel[bot] commented on Apr 27, 2023

@vercel[bot]

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app

Please sign in to comment.