Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): do not strip additional angular.json properties #16615

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
JamesHenry marked this conversation as resolved.
Show resolved Hide resolved
}

export function workspaceRootInner(
dir: string,
Expand Down