Skip to content

Commit

Permalink
fix(core): do not strip additional angular.json properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed Apr 27, 2023
1 parent fbf8d9c commit c0ec055
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/generated/devkit/nrwl_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ Path to the directory where Nx stores its cache and daemon-related files.

### workspaceRoot

`Const` **workspaceRoot**: `string`
**workspaceRoot**: `string`

The root of the workspace

Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/devkit/documents/nrwl_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ Path to the directory where Nx stores its cache and daemon-related files.

### workspaceRoot

`Const` **workspaceRoot**: `string`
**workspaceRoot**: `string`

The root of the workspace

Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/adapter/angular-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function shouldMergeAngularProjects(
}
}

function isAngularPluginInstalled() {
export function isAngularPluginInstalled() {
try {
require.resolve('@nx/angular');
return true;
Expand Down
14 changes: 11 additions & 3 deletions packages/nx/src/adapter/ngcli-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ import { parseJson } from '../utils/json';
import { NX_ERROR, NX_PREFIX } from '../utils/logger';
import { readModulePackageJson } from '../utils/package-json';
import { detectPackageManager } from '../utils/package-manager';
import { toNewFormat, toOldFormat } from './angular-json';
import {
isAngularPluginInstalled,
toNewFormat,
toOldFormat,
} from './angular-json';
import { normalizeExecutorSchema, Workspaces } from '../config/workspaces';
import {
CustomHasher,
Expand Down Expand Up @@ -899,7 +903,8 @@ export function wrapAngularDevkitSchematic(

if (event.kind === 'error') {
} else if (event.kind === 'update') {
if (eventPath === 'angular.json') {
// Apply special handling for the angular.json file, but only when in an Nx workspace
if (eventPath === 'angular.json' && isAngularPluginInstalled()) {
saveProjectsConfigurationsInWrappedSchematic(
host,
event.content.toString()
Expand Down Expand Up @@ -1002,7 +1007,10 @@ function saveProjectsConfigurationsInWrappedSchematic(
? Object.keys(existingAngularJson.projects)
: [];

const newAngularJson = { projects: {} };
const newAngularJson = existingAngularJson || {};

// Reset projects in order to rebuild them, but leave other properties untouched
newAngularJson.projects = {};

Object.keys(projects).forEach((projectName) => {
if (projectsInAngularJson.includes(projectName)) {
Expand Down
6 changes: 5 additions & 1 deletion packages/nx/src/utils/workspace-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { fileExists } from './fileutils';
/**
* The root of the workspace
*/
export const workspaceRoot = workspaceRootInner(process.cwd(), process.cwd());
export let workspaceRoot = workspaceRootInner(process.cwd(), process.cwd());

export function setWorkspaceRoot(root: string): void {
workspaceRoot = root;
}

export function workspaceRootInner(
dir: string,
Expand Down

0 comments on commit c0ec055

Please sign in to comment.