diff --git a/docs/generated/devkit/index.md b/docs/generated/devkit/index.md index 5fadc33a0b622..404cb11b2f453 100644 --- a/docs/generated/devkit/index.md +++ b/docs/generated/devkit/index.md @@ -194,6 +194,7 @@ It only uses language primitives and immutable objects - [targetToTargetString](../../devkit/documents/index#targettotargetstring) - [toJS](../../devkit/documents/index#tojs) - [updateJson](../../devkit/documents/index#updatejson) +- [updateNxJson](../../devkit/documents/index#updatenxjson) - [updateProjectConfiguration](../../devkit/documents/index#updateprojectconfiguration) - [updateTsConfigsToJs](../../devkit/documents/index#updatetsconfigstojs) - [updateWorkspaceConfiguration](../../devkit/documents/index#updateworkspaceconfiguration) @@ -272,13 +273,7 @@ A plugin for Nx ### ProjectGraph -• **ProjectGraph**<`T`\>: `Object` - -#### Type parameters - -| Name | Type | -| :--- | :---- | -| `T` | `any` | +• **ProjectGraph**: `Object` --- @@ -302,13 +297,7 @@ A plugin for Nx ### ProjectGraphProjectNode -• **ProjectGraphProjectNode**<`T`\>: `Object` - -#### Type parameters - -| Name | Type | -| :--- | :---- | -| `T` | `any` | +• **ProjectGraphProjectNode**: `Object` --- @@ -544,13 +533,7 @@ A plugin for Nx ### ProjectGraphNode -Ƭ **ProjectGraphNode**<`T`\>: [`ProjectGraphProjectNode`](../../devkit/documents/index#projectgraphprojectnode)<`T`\> \| [`ProjectGraphExternalNode`](../../devkit/documents/index#projectgraphexternalnode) - -#### Type parameters - -| Name | Type | -| :--- | :---- | -| `T` | `any` | +Ƭ **ProjectGraphNode**: [`ProjectGraphProjectNode`](../../devkit/documents/index#projectgraphprojectnode) \| [`ProjectGraphExternalNode`](../../devkit/documents/index#projectgraphexternalnode) --- @@ -920,7 +903,7 @@ hierarchy. | :----------------- | :--------------------------------------------------------------------------------------------- | :--------------------------------- | | `sharedConfig` | `Record`<`string`, [`SharedLibraryConfig`](../../devkit/documents/index#sharedlibraryconfig)\> | The original Shared Config | | `additionalShared` | [`AdditionalSharedConfig`](../../devkit/documents/index#additionalsharedconfig) | The additional dependencies to add | -| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | The Nx project graph | +| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | The Nx project graph | #### Returns @@ -1095,13 +1078,13 @@ If isProduction flag is set, it wil remove devDependencies and optional peerDepe #### Parameters -| Name | Type | -| :---------------------- | :------------------------------------------------------------------ | -| `projectName` | `string` | -| `graph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | -| `options` | `Object` | -| `options.isProduction?` | `boolean` | -| `options.root?` | `string` | +| Name | Type | +| :---------------------- | :---------------------------------------------------------- | +| `projectName` | `string` | +| `graph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | +| `options` | `Object` | +| `options.isProduction?` | `boolean` | +| `options.root?` | `string` | #### Returns @@ -1165,7 +1148,7 @@ stored in the daemon process. To reset both run: `nx reset`. | `context.initiatingProject?` | `string` | | `context.nxArgs` | `NxArgs` | | `context.nxJson` | [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration)<`string`[] \| `"*"`\> | -| `context.projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | +| `context.projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | | `context.target?` | `string` | | `context.taskGraph?` | [`TaskGraph`](../../devkit/documents/index#taskgraph) | @@ -1332,10 +1315,10 @@ doesn't get confused about incorrect TypeScript files. #### Parameters -| Name | Type | -| :------------- | :------------------------------------------------------------------ | -| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | -| `name` | `string` | +| Name | Type | +| :------------- | :---------------------------------------------------------- | +| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | +| `name` | `string` | #### Returns @@ -1395,10 +1378,10 @@ Returns the list of outputs that will be cached. #### Parameters -| Name | Type | Description | -| :----- | :---------------------------------------------------------------------------------------- | :-------------------------------------------------------- | -| `task` | `Pick`<[`Task`](../../devkit/documents/index#task), `"overrides"` \| `"target"`\> | target + overrides | -| `node` | [`ProjectGraphProjectNode`](../../devkit/documents/index#projectgraphprojectnode)<`any`\> | ProjectGraphProjectNode object that the task runs against | +| Name | Type | Description | +| :----- | :-------------------------------------------------------------------------------- | :-------------------------------------------------------- | +| `task` | `Pick`<[`Task`](../../devkit/documents/index#task), `"overrides"` \| `"target"`\> | target + overrides | +| `node` | [`ProjectGraphProjectNode`](../../devkit/documents/index#projectgraphprojectnode) | ProjectGraphProjectNode object that the task runs against | #### Returns @@ -1774,10 +1757,10 @@ parseTargetString('proj:test:production', graph); // returns { project: "proj", #### Parameters -| Name | Type | Description | -| :------------- | :------------------------------------------------------------------ | :--------------- | -| `targetString` | `string` | target reference | -| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | - | +| Name | Type | Description | +| :------------- | :---------------------------------------------------------- | :--------------- | +| `targetString` | `string` | target reference | +| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | - | #### Returns @@ -1789,6 +1772,8 @@ parseTargetString('proj:test:production', graph); // returns { project: "proj", ▸ **readAllWorkspaceConfiguration**(): [`ProjectsConfigurations`](../../devkit/documents/index#projectsconfigurations) & [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) +TODO(vsavkin): Remove after Nx 16 is out + **`deprecated`** Use readProjectsConfigurationFromProjectGraph(await createProjectGraphAsync()) #### Returns @@ -1799,7 +1784,7 @@ parseTargetString('proj:test:production', graph); // returns { project: "proj", ### readCachedProjectGraph -▸ **readCachedProjectGraph**(): [`ProjectGraph`](../../devkit/documents/index#projectgraph)<[`ProjectConfiguration`](../../devkit/documents/index#projectconfiguration)\> +▸ **readCachedProjectGraph**(): [`ProjectGraph`](../../devkit/documents/index#projectgraph) Synchronously reads the latest cached copy of the workspace's ProjectGraph. @@ -1807,7 +1792,7 @@ Synchronously reads the latest cached copy of the workspace's ProjectGraph. #### Returns -[`ProjectGraph`](../../devkit/documents/index#projectgraph)<[`ProjectConfiguration`](../../devkit/documents/index#projectconfiguration)\> +[`ProjectGraph`](../../devkit/documents/index#projectgraph) --- @@ -1866,11 +1851,19 @@ Object the JSON content of the file represents ### readNxJson -▸ **readNxJson**(): [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) +▸ **readNxJson**(`tree`): [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) \| `null` + +Reads nx.json + +#### Parameters + +| Name | Type | +| :----- | :------------------------------------------ | +| `tree` | [`Tree`](../../devkit/documents/index#tree) | #### Returns -[`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) +[`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) \| `null` --- @@ -1948,6 +1941,8 @@ Read general workspace configuration such as the default project or cli settings This does _not_ provide projects configuration, use [readProjectConfiguration](../../devkit/documents/index#readprojectconfiguration) instead. +**`deprecated`** use readNxJson + #### Parameters | Name | Type | @@ -2024,9 +2019,9 @@ B will depend on A. #### Parameters -| Name | Type | -| :------ | :------------------------------------------------------------------ | -| `graph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | +| Name | Type | +| :------ | :---------------------------------------------------------- | +| `graph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | #### Returns @@ -2273,6 +2268,25 @@ Updates a JSON value to the file system tree --- +### updateNxJson + +▸ **updateNxJson**(`tree`, `nxJson`): `void` + +Update nx.json + +#### Parameters + +| Name | Type | +| :------- | :---------------------------------------------------------------------------------------------- | +| `tree` | [`Tree`](../../devkit/documents/index#tree) | +| `nxJson` | [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration)<`string`[] \| `"*"`\> | + +#### Returns + +`void` + +--- + ### updateProjectConfiguration ▸ **updateProjectConfiguration**(`tree`, `projectName`, `projectConfiguration`): `void` @@ -2322,6 +2336,8 @@ Update general workspace configuration such as the default project or cli settin This does _not_ update projects configuration, use [updateProjectConfiguration](../../devkit/documents/index#updateprojectconfiguration) or [addProjectConfiguration](../../devkit/documents/index#addprojectconfiguration) instead. +**`deprecated`** use updateNxJson + #### Parameters | Name | Type | diff --git a/docs/generated/packages/devkit/documents/index.md b/docs/generated/packages/devkit/documents/index.md index 5fadc33a0b622..404cb11b2f453 100644 --- a/docs/generated/packages/devkit/documents/index.md +++ b/docs/generated/packages/devkit/documents/index.md @@ -194,6 +194,7 @@ It only uses language primitives and immutable objects - [targetToTargetString](../../devkit/documents/index#targettotargetstring) - [toJS](../../devkit/documents/index#tojs) - [updateJson](../../devkit/documents/index#updatejson) +- [updateNxJson](../../devkit/documents/index#updatenxjson) - [updateProjectConfiguration](../../devkit/documents/index#updateprojectconfiguration) - [updateTsConfigsToJs](../../devkit/documents/index#updatetsconfigstojs) - [updateWorkspaceConfiguration](../../devkit/documents/index#updateworkspaceconfiguration) @@ -272,13 +273,7 @@ A plugin for Nx ### ProjectGraph -• **ProjectGraph**<`T`\>: `Object` - -#### Type parameters - -| Name | Type | -| :--- | :---- | -| `T` | `any` | +• **ProjectGraph**: `Object` --- @@ -302,13 +297,7 @@ A plugin for Nx ### ProjectGraphProjectNode -• **ProjectGraphProjectNode**<`T`\>: `Object` - -#### Type parameters - -| Name | Type | -| :--- | :---- | -| `T` | `any` | +• **ProjectGraphProjectNode**: `Object` --- @@ -544,13 +533,7 @@ A plugin for Nx ### ProjectGraphNode -Ƭ **ProjectGraphNode**<`T`\>: [`ProjectGraphProjectNode`](../../devkit/documents/index#projectgraphprojectnode)<`T`\> \| [`ProjectGraphExternalNode`](../../devkit/documents/index#projectgraphexternalnode) - -#### Type parameters - -| Name | Type | -| :--- | :---- | -| `T` | `any` | +Ƭ **ProjectGraphNode**: [`ProjectGraphProjectNode`](../../devkit/documents/index#projectgraphprojectnode) \| [`ProjectGraphExternalNode`](../../devkit/documents/index#projectgraphexternalnode) --- @@ -920,7 +903,7 @@ hierarchy. | :----------------- | :--------------------------------------------------------------------------------------------- | :--------------------------------- | | `sharedConfig` | `Record`<`string`, [`SharedLibraryConfig`](../../devkit/documents/index#sharedlibraryconfig)\> | The original Shared Config | | `additionalShared` | [`AdditionalSharedConfig`](../../devkit/documents/index#additionalsharedconfig) | The additional dependencies to add | -| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | The Nx project graph | +| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | The Nx project graph | #### Returns @@ -1095,13 +1078,13 @@ If isProduction flag is set, it wil remove devDependencies and optional peerDepe #### Parameters -| Name | Type | -| :---------------------- | :------------------------------------------------------------------ | -| `projectName` | `string` | -| `graph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | -| `options` | `Object` | -| `options.isProduction?` | `boolean` | -| `options.root?` | `string` | +| Name | Type | +| :---------------------- | :---------------------------------------------------------- | +| `projectName` | `string` | +| `graph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | +| `options` | `Object` | +| `options.isProduction?` | `boolean` | +| `options.root?` | `string` | #### Returns @@ -1165,7 +1148,7 @@ stored in the daemon process. To reset both run: `nx reset`. | `context.initiatingProject?` | `string` | | `context.nxArgs` | `NxArgs` | | `context.nxJson` | [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration)<`string`[] \| `"*"`\> | -| `context.projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | +| `context.projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | | `context.target?` | `string` | | `context.taskGraph?` | [`TaskGraph`](../../devkit/documents/index#taskgraph) | @@ -1332,10 +1315,10 @@ doesn't get confused about incorrect TypeScript files. #### Parameters -| Name | Type | -| :------------- | :------------------------------------------------------------------ | -| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | -| `name` | `string` | +| Name | Type | +| :------------- | :---------------------------------------------------------- | +| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | +| `name` | `string` | #### Returns @@ -1395,10 +1378,10 @@ Returns the list of outputs that will be cached. #### Parameters -| Name | Type | Description | -| :----- | :---------------------------------------------------------------------------------------- | :-------------------------------------------------------- | -| `task` | `Pick`<[`Task`](../../devkit/documents/index#task), `"overrides"` \| `"target"`\> | target + overrides | -| `node` | [`ProjectGraphProjectNode`](../../devkit/documents/index#projectgraphprojectnode)<`any`\> | ProjectGraphProjectNode object that the task runs against | +| Name | Type | Description | +| :----- | :-------------------------------------------------------------------------------- | :-------------------------------------------------------- | +| `task` | `Pick`<[`Task`](../../devkit/documents/index#task), `"overrides"` \| `"target"`\> | target + overrides | +| `node` | [`ProjectGraphProjectNode`](../../devkit/documents/index#projectgraphprojectnode) | ProjectGraphProjectNode object that the task runs against | #### Returns @@ -1774,10 +1757,10 @@ parseTargetString('proj:test:production', graph); // returns { project: "proj", #### Parameters -| Name | Type | Description | -| :------------- | :------------------------------------------------------------------ | :--------------- | -| `targetString` | `string` | target reference | -| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | - | +| Name | Type | Description | +| :------------- | :---------------------------------------------------------- | :--------------- | +| `targetString` | `string` | target reference | +| `projectGraph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | - | #### Returns @@ -1789,6 +1772,8 @@ parseTargetString('proj:test:production', graph); // returns { project: "proj", ▸ **readAllWorkspaceConfiguration**(): [`ProjectsConfigurations`](../../devkit/documents/index#projectsconfigurations) & [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) +TODO(vsavkin): Remove after Nx 16 is out + **`deprecated`** Use readProjectsConfigurationFromProjectGraph(await createProjectGraphAsync()) #### Returns @@ -1799,7 +1784,7 @@ parseTargetString('proj:test:production', graph); // returns { project: "proj", ### readCachedProjectGraph -▸ **readCachedProjectGraph**(): [`ProjectGraph`](../../devkit/documents/index#projectgraph)<[`ProjectConfiguration`](../../devkit/documents/index#projectconfiguration)\> +▸ **readCachedProjectGraph**(): [`ProjectGraph`](../../devkit/documents/index#projectgraph) Synchronously reads the latest cached copy of the workspace's ProjectGraph. @@ -1807,7 +1792,7 @@ Synchronously reads the latest cached copy of the workspace's ProjectGraph. #### Returns -[`ProjectGraph`](../../devkit/documents/index#projectgraph)<[`ProjectConfiguration`](../../devkit/documents/index#projectconfiguration)\> +[`ProjectGraph`](../../devkit/documents/index#projectgraph) --- @@ -1866,11 +1851,19 @@ Object the JSON content of the file represents ### readNxJson -▸ **readNxJson**(): [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) +▸ **readNxJson**(`tree`): [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) \| `null` + +Reads nx.json + +#### Parameters + +| Name | Type | +| :----- | :------------------------------------------ | +| `tree` | [`Tree`](../../devkit/documents/index#tree) | #### Returns -[`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) +[`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration) \| `null` --- @@ -1948,6 +1941,8 @@ Read general workspace configuration such as the default project or cli settings This does _not_ provide projects configuration, use [readProjectConfiguration](../../devkit/documents/index#readprojectconfiguration) instead. +**`deprecated`** use readNxJson + #### Parameters | Name | Type | @@ -2024,9 +2019,9 @@ B will depend on A. #### Parameters -| Name | Type | -| :------ | :------------------------------------------------------------------ | -| `graph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph)<`any`\> | +| Name | Type | +| :------ | :---------------------------------------------------------- | +| `graph` | [`ProjectGraph`](../../devkit/documents/index#projectgraph) | #### Returns @@ -2273,6 +2268,25 @@ Updates a JSON value to the file system tree --- +### updateNxJson + +▸ **updateNxJson**(`tree`, `nxJson`): `void` + +Update nx.json + +#### Parameters + +| Name | Type | +| :------- | :---------------------------------------------------------------------------------------------- | +| `tree` | [`Tree`](../../devkit/documents/index#tree) | +| `nxJson` | [`NxJsonConfiguration`](../../devkit/documents/index#nxjsonconfiguration)<`string`[] \| `"*"`\> | + +#### Returns + +`void` + +--- + ### updateProjectConfiguration ▸ **updateProjectConfiguration**(`tree`, `projectName`, `projectConfiguration`): `void` @@ -2322,6 +2336,8 @@ Update general workspace configuration such as the default project or cli settin This does _not_ update projects configuration, use [updateProjectConfiguration](../../devkit/documents/index#updateprojectconfiguration) or [addProjectConfiguration](../../devkit/documents/index#addprojectconfiguration) instead. +**`deprecated`** use updateNxJson + #### Parameters | Name | Type | diff --git a/e2e/angular-core/src/ng-add.test.ts b/e2e/angular-core/src/ng-add.test.ts index 7f31acbac108c..cd5e45a541ee0 100644 --- a/e2e/angular-core/src/ng-add.test.ts +++ b/e2e/angular-core/src/ng-add.test.ts @@ -145,9 +145,6 @@ describe('convert Angular CLI workspace to an Nx workspace', () => { affected: { defaultBase: 'main', }, - cli: { - packageManager: packageManager, - }, npmScope: 'projscope', tasksRunnerOptions: { default: { diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts index c4d49d3e54019..259bdedbd4bf0 100644 --- a/e2e/utils/index.ts +++ b/e2e/utils/index.ts @@ -108,7 +108,7 @@ export function updateProjectConfig( export function readResolvedWorkspaceConfiguration() { process.env.NX_PROJECT_GLOB_CACHE = 'false'; const ws = new Workspaces(tmpProjPath()); - return ws.readWorkspaceConfiguration(); + return ws.readProjectsConfig(); } /** @@ -687,7 +687,7 @@ function setMaxWorkers() { const ws = new Workspaces(tmpProjPath()); const workspaceFile = workspaceConfigName(); const workspaceFileExists = fileExists(tmpProjPath(workspaceFile)); - const workspace = ws.readWorkspaceConfiguration(); + const workspace = ws.readProjectsConfig(); const rawWorkspace = workspaceFileExists ? readJson(workspaceFile) : null; let requireWorkspaceFileUpdate = false; diff --git a/graph/client/src/app/feature-projects/project-list.tsx b/graph/client/src/app/feature-projects/project-list.tsx index e7c326b6089cd..c585b5392ea95 100644 --- a/graph/client/src/app/feature-projects/project-list.tsx +++ b/graph/client/src/app/feature-projects/project-list.tsx @@ -49,7 +49,7 @@ function groupProjectsByDirectory( ? workspaceLayout.appsDir : workspaceLayout.libsDir; const directories = parseParentDirectoriesFromFilePath( - project.data.root, + (project.data as any).root, workspaceRoot ); diff --git a/graph/client/src/app/feature-tasks/task-list.tsx b/graph/client/src/app/feature-tasks/task-list.tsx index c41006cc5dd01..3f59eea6237b8 100644 --- a/graph/client/src/app/feature-tasks/task-list.tsx +++ b/graph/client/src/app/feature-tasks/task-list.tsx @@ -107,7 +107,9 @@ export function TaskList({ children, }: TaskListProps) { const filteredProjects = projects - .filter((project) => project.data.targets.hasOwnProperty(selectedTarget)) + .filter((project) => + (project.data as any).targets.hasOwnProperty(selectedTarget) + ) .sort((a, b) => a.name.localeCompare(b.name)); const appProjects = getProjectsByType('app', filteredProjects); diff --git a/graph/client/src/app/util.ts b/graph/client/src/app/util.ts index 5234f989cf20f..dd6cdd2d9aa0c 100644 --- a/graph/client/src/app/util.ts +++ b/graph/client/src/app/util.ts @@ -101,7 +101,7 @@ export function groupProjectsByDirectory( ? workspaceLayout.appsDir : workspaceLayout.libsDir; const directories = parseParentDirectoriesFromFilePath( - project.data.root, + (project.data as any).root, workspaceRoot ); diff --git a/packages/angular/src/executors/file-server/file-server.impl.ts b/packages/angular/src/executors/file-server/file-server.impl.ts index 0a96dae29f550..bc32cad028d62 100644 --- a/packages/angular/src/executors/file-server/file-server.impl.ts +++ b/packages/angular/src/executors/file-server/file-server.impl.ts @@ -61,7 +61,8 @@ function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) { try { const [project, target, config] = options.buildTarget.split(':'); - const buildTarget = context.workspace.projects[project].targets[target]; + const buildTarget = + context.projectsConfigurations.projects[project].targets[target]; buildOptions = config ? { ...buildTarget.options, ...buildTarget.configurations[config] } : buildTarget.options; diff --git a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-lite.impl.spec.ts b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-lite.impl.spec.ts index ed109be87dc75..a6c6ff35c7d0e 100644 --- a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-lite.impl.spec.ts +++ b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-lite.impl.spec.ts @@ -59,7 +59,9 @@ describe('NgPackagrLite executor', () => { projectName: 'my-lib', targetName: 'build', configurationName: 'production', - workspace: { projects: { 'my-lib': { root: '/libs/my-lib' } } }, + projectsConfigurations: { + projects: { 'my-lib': { root: '/libs/my-lib' } }, + }, } as any; options = { project: 'my-lib' }; }); diff --git a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-lite.impl.ts b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-lite.impl.ts index f85fd57f91a6d..c3b205d79c467 100644 --- a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-lite.impl.ts +++ b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-lite.impl.ts @@ -36,7 +36,7 @@ async function initializeNgPackgrLite( const remappedTsConfigFilePath = createTmpTsConfig( options.tsConfig, context.root, - context.workspace.projects[context.projectName].root, + context.projectsConfigurations.projects[context.projectName].root, projectDependencies ); const tsConfig = await parseRemappedTsConfigAndMergeDefaults( diff --git a/packages/angular/src/executors/package/package.impl.spec.ts b/packages/angular/src/executors/package/package.impl.spec.ts index 6da97c5a83c7a..7f0be6f101364 100644 --- a/packages/angular/src/executors/package/package.impl.spec.ts +++ b/packages/angular/src/executors/package/package.impl.spec.ts @@ -58,7 +58,9 @@ describe('Package executor', () => { projectName: 'my-lib', targetName: 'build', configurationName: 'production', - workspace: { projects: { 'my-lib': { root: '/libs/my-lib' } } }, + projectsConfigurations: { + projects: { 'my-lib': { root: '/libs/my-lib' } }, + }, } as any; options = { project: 'my-lib' }; }); diff --git a/packages/angular/src/executors/package/package.impl.ts b/packages/angular/src/executors/package/package.impl.ts index 8cc822f068d47..d899141a762e1 100644 --- a/packages/angular/src/executors/package/package.impl.ts +++ b/packages/angular/src/executors/package/package.impl.ts @@ -41,7 +41,7 @@ async function initializeNgPackagr( const remappedTsConfigFilePath = createTmpTsConfig( options.tsConfig, context.root, - context.workspace.projects[context.projectName].root, + context.projectsConfigurations.projects[context.projectName].root, projectDependencies ); const tsConfig = await parseRemappedTsConfigAndMergeDefaults( diff --git a/packages/angular/src/generators/application/angular-v14/lib/set-app-strict-default.ts b/packages/angular/src/generators/application/angular-v14/lib/set-app-strict-default.ts index 21b2fc2a59893..cceed3b4bad58 100644 --- a/packages/angular/src/generators/application/angular-v14/lib/set-app-strict-default.ts +++ b/packages/angular/src/generators/application/angular-v14/lib/set-app-strict-default.ts @@ -1,18 +1,15 @@ import type { Tree } from '@nrwl/devkit'; -import { - readWorkspaceConfiguration, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, updateNxJson } from '@nrwl/devkit'; export function setApplicationStrictDefault(host: Tree, strict: boolean) { - const workspaceConfig = readWorkspaceConfiguration(host); + const nxJson = readNxJson(host); - workspaceConfig.generators = workspaceConfig.generators || {}; - workspaceConfig.generators['@nrwl/angular:application'] = - workspaceConfig.generators['@nrwl/angular:application'] || {}; - workspaceConfig.generators['@nrwl/angular:application'].strict = - workspaceConfig.generators['@nrwl/angular:application'].strict ?? strict; + nxJson.generators = nxJson.generators || {}; + nxJson.generators['@nrwl/angular:application'] = + nxJson.generators['@nrwl/angular:application'] || {}; + nxJson.generators['@nrwl/angular:application'].strict = + nxJson.generators['@nrwl/angular:application'].strict ?? strict; - updateWorkspaceConfiguration(host, workspaceConfig); + updateNxJson(host, nxJson); } diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index 0d5096435bd6f..5c742049778e0 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -5,8 +5,8 @@ import { NxJsonConfiguration, parseJson, readJson, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, updateJson, } from '@nrwl/devkit'; import { @@ -22,6 +22,7 @@ import { } from '../../utils/versions'; import { applicationGenerator } from './application'; import type { Schema } from './schema'; + // need to mock cypress otherwise it'll use the nx installed version from package.json // which is v9 while we are testing for the new v10 version jest.mock('@nrwl/cypress/src/utils/cypress-version'); @@ -221,15 +222,15 @@ describe('app', () => { it('should not overwrite default project if already set', async () => { // ARRANGE - const workspace = readWorkspaceConfiguration(appTree); - workspace.defaultProject = 'some-awesome-project'; - devkit.updateWorkspaceConfiguration(appTree, workspace); + const nxJson = readNxJson(appTree); + nxJson.defaultProject = 'some-awesome-project'; + devkit.updateNxJson(appTree, nxJson); // ACT await generateApp(appTree); // ASSERT - const { defaultProject } = readWorkspaceConfiguration(appTree); + const { defaultProject } = readNxJson(appTree); expect(defaultProject).toBe('some-awesome-project'); }); }); diff --git a/packages/angular/src/generators/application/application.ts b/packages/angular/src/generators/application/application.ts index 7795e206aabb6..67d3ea900fd71 100644 --- a/packages/angular/src/generators/application/application.ts +++ b/packages/angular/src/generators/application/application.ts @@ -2,9 +2,9 @@ import { formatFiles, installPackagesTask, moveFilesToNewDirectory, - readWorkspaceConfiguration, + readNxJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter'; import { convertToNxProjectGenerator } from '@nrwl/workspace/generators'; @@ -123,9 +123,9 @@ export async function applicationGenerator( updateEditorTsConfig(tree, options); if (options.rootProject) { - const workspace = readWorkspaceConfiguration(tree); - workspace.defaultProject = options.name; - updateWorkspaceConfiguration(tree, workspace); + const nxJson = readNxJson(tree); + nxJson.defaultProject = options.name; + updateNxJson(tree, nxJson); } if (options.backendProject) { diff --git a/packages/angular/src/generators/application/application.v14.spec.ts b/packages/angular/src/generators/application/application.v14.spec.ts index 085385680c8e5..9c7893f207596 100644 --- a/packages/angular/src/generators/application/application.v14.spec.ts +++ b/packages/angular/src/generators/application/application.v14.spec.ts @@ -5,8 +5,8 @@ import { NxJsonConfiguration, parseJson, readJson, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, updateJson, } from '@nrwl/devkit'; import { @@ -216,15 +216,15 @@ describe('app', () => { it('should not overwrite default project if already set', async () => { // ARRANGE - const workspace = readWorkspaceConfiguration(appTree); - workspace.defaultProject = 'some-awesome-project'; - devkit.updateWorkspaceConfiguration(appTree, workspace); + const nxJson = readNxJson(appTree); + nxJson.defaultProject = 'some-awesome-project'; + devkit.updateNxJson(appTree, nxJson); // ACT await generateApp(appTree); // ASSERT - const { defaultProject } = readWorkspaceConfiguration(appTree); + const { defaultProject } = readNxJson(appTree); expect(defaultProject).toBe('some-awesome-project'); }); }); diff --git a/packages/angular/src/generators/application/lib/set-app-strict-default.ts b/packages/angular/src/generators/application/lib/set-app-strict-default.ts index 21b2fc2a59893..f08efc78afc0d 100644 --- a/packages/angular/src/generators/application/lib/set-app-strict-default.ts +++ b/packages/angular/src/generators/application/lib/set-app-strict-default.ts @@ -1,18 +1,14 @@ import type { Tree } from '@nrwl/devkit'; - -import { - readWorkspaceConfiguration, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, updateNxJson } from '@nrwl/devkit'; export function setApplicationStrictDefault(host: Tree, strict: boolean) { - const workspaceConfig = readWorkspaceConfiguration(host); + const nxJson = readNxJson(host); - workspaceConfig.generators = workspaceConfig.generators || {}; - workspaceConfig.generators['@nrwl/angular:application'] = - workspaceConfig.generators['@nrwl/angular:application'] || {}; - workspaceConfig.generators['@nrwl/angular:application'].strict = - workspaceConfig.generators['@nrwl/angular:application'].strict ?? strict; + nxJson.generators = nxJson.generators || {}; + nxJson.generators['@nrwl/angular:application'] = + nxJson.generators['@nrwl/angular:application'] || {}; + nxJson.generators['@nrwl/angular:application'].strict = + nxJson.generators['@nrwl/angular:application'].strict ?? strict; - updateWorkspaceConfiguration(host, workspaceConfig); + updateNxJson(host, nxJson); } diff --git a/packages/angular/src/generators/component/component.spec.ts b/packages/angular/src/generators/component/component.spec.ts index 7c76194c46706..eb6122e36e9e9 100644 --- a/packages/angular/src/generators/component/component.spec.ts +++ b/packages/angular/src/generators/component/component.spec.ts @@ -436,7 +436,11 @@ describe('component Generator', () => { ); projectGraph = { nodes: { - lib1: { name: 'lib1', type: 'lib', data: { root: 'libs/lib1' } }, + lib1: { + name: 'lib1', + type: 'lib', + data: { root: 'libs/lib1' } as any, + }, }, dependencies: {}, }; diff --git a/packages/angular/src/generators/component/component.ts b/packages/angular/src/generators/component/component.ts index b6ee1dc0de43e..b1b59c82da59c 100644 --- a/packages/angular/src/generators/component/component.ts +++ b/packages/angular/src/generators/component/component.ts @@ -2,8 +2,8 @@ import type { Tree } from '@nrwl/devkit'; import { formatFiles, normalizePath, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, } from '@nrwl/devkit'; import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter'; import { pathStartsWith } from '../utils/path'; @@ -33,8 +33,7 @@ function checkPathUnderProjectRoot(tree: Tree, schema: NormalizedSchema): void { return; } - const project = - schema.project ?? readWorkspaceConfiguration(tree).defaultProject; + const project = schema.project ?? readNxJson(tree).defaultProject; const { root } = readProjectConfiguration(tree, project); let pathToComponent = normalizePath(schema.path); diff --git a/packages/angular/src/generators/component/lib/normalize-options.ts b/packages/angular/src/generators/component/lib/normalize-options.ts index 52e2c2259b1d4..49331e5c597c5 100644 --- a/packages/angular/src/generators/component/lib/normalize-options.ts +++ b/packages/angular/src/generators/component/lib/normalize-options.ts @@ -2,8 +2,8 @@ import type { Tree } from '@nrwl/devkit'; import { createProjectGraphAsync, joinPathFragments, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, } from '@nrwl/devkit'; import type { NormalizedSchema, Schema } from '../schema'; import { @@ -27,7 +27,7 @@ export async function normalizeOptions( const project = options.project ?? (await findProjectFromOptions(options)) ?? - readWorkspaceConfiguration(tree).defaultProject; + readNxJson(tree).defaultProject; if (!project) { // path is hidden, so if not provided we don't suggest setting it diff --git a/packages/angular/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts b/packages/angular/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts index cafd013724ff5..0e82b01dfffa3 100644 --- a/packages/angular/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts +++ b/packages/angular/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts @@ -63,7 +63,7 @@ describe('Cypress Component Testing Configuration', () => { ...readProjectConfiguration(tree, 'fancy-lib'), }, }, - }, + } as any, dependencies: { 'fancy-app': [ { @@ -117,13 +117,13 @@ describe('Cypress Component Testing Configuration', () => { data: { ...readProjectConfiguration(tree, 'fancy-app'), }, - }, + } as any, 'fancy-lib': { name: 'fancy-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'fancy-lib'), - }, + } as any, }, }, dependencies: { @@ -181,14 +181,14 @@ describe('Cypress Component Testing Configuration', () => { type: 'app', data: { ...appConfig, - }, + } as any, }, 'fancy-lib': { name: 'fancy-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'fancy-lib'), - }, + } as any, }, }, dependencies: { @@ -230,7 +230,7 @@ describe('Cypress Component Testing Configuration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'fancy-app'), - }, + } as any, }, }, dependencies: {}, @@ -275,14 +275,14 @@ describe('Cypress Component Testing Configuration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'fancy-app'), - }, + } as any, }, 'fancy-lib': { name: 'fancy-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'fancy-lib'), - }, + } as any, }, }, dependencies: { @@ -331,14 +331,14 @@ describe('Cypress Component Testing Configuration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'something'), - }, + } as any, }, 'my-lib': { name: 'my-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'my-lib'), - }, + } as any, }, }, dependencies: { @@ -383,14 +383,14 @@ describe('Cypress Component Testing Configuration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'something'), - }, + } as any, }, 'my-lib-standalone': { name: 'my-lib-standalone', type: 'lib', data: { ...readProjectConfiguration(tree, 'my-lib-standalone'), - }, + } as any, }, }, dependencies: { @@ -437,14 +437,14 @@ describe('Cypress Component Testing Configuration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'something'), - }, + } as any, }, 'with-inputs-cmp': { name: 'with-inputs-cmp', type: 'lib', data: { ...readProjectConfiguration(tree, 'with-inputs-cmp'), - }, + } as any, }, }, dependencies: { @@ -491,14 +491,14 @@ describe('Cypress Component Testing Configuration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'something'), - }, + } as any, }, 'with-inputs-standalone-cmp': { name: 'with-inputs-standalone-cmp', type: 'lib', data: { ...readProjectConfiguration(tree, 'with-inputs-standalone-cmp'), - }, + } as any, }, }, dependencies: { @@ -558,14 +558,14 @@ describe('Cypress Component Testing Configuration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'my-cool-app'), - }, + } as any, }, secondary: { name: 'secondary', type: 'lib', data: { ...readProjectConfiguration(tree, 'secondary'), - }, + } as any, }, }, dependencies: {}, @@ -615,14 +615,14 @@ describe('Cypress Component Testing Configuration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'abc'), - }, + } as any, }, 'cool-lib': { name: 'cool-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'cool-lib'), - }, + } as any, }, }, dependencies: {}, diff --git a/packages/angular/src/generators/init/angular-v14/init.ts b/packages/angular/src/generators/init/angular-v14/init.ts index 85ae0128bd17e..9cfe225c9191e 100755 --- a/packages/angular/src/generators/init/angular-v14/init.ts +++ b/packages/angular/src/generators/init/angular-v14/init.ts @@ -4,9 +4,9 @@ import { formatFiles, GeneratorCallback, logger, - readWorkspaceConfiguration, + readNxJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { jestInitGenerator } from '@nrwl/jest'; import { Linter } from '@nrwl/linter'; @@ -50,27 +50,27 @@ function normalizeOptions(options: Schema): Required { } function setDefaults(host: Tree, options: Schema) { - const workspace = readWorkspaceConfiguration(host); + const nxJson = readNxJson(host); - workspace.generators = workspace.generators || {}; - workspace.generators['@nrwl/angular:application'] = { + nxJson.generators = nxJson.generators || {}; + nxJson.generators['@nrwl/angular:application'] = { style: options.style, linter: options.linter, unitTestRunner: options.unitTestRunner, e2eTestRunner: options.e2eTestRunner, - ...(workspace.generators['@nrwl/angular:application'] || {}), + ...(nxJson.generators['@nrwl/angular:application'] || {}), }; - workspace.generators['@nrwl/angular:library'] = { + nxJson.generators['@nrwl/angular:library'] = { linter: options.linter, unitTestRunner: options.unitTestRunner, - ...(workspace.generators['@nrwl/angular:library'] || {}), + ...(nxJson.generators['@nrwl/angular:library'] || {}), }; - workspace.generators['@nrwl/angular:component'] = { + nxJson.generators['@nrwl/angular:component'] = { style: options.style, - ...(workspace.generators['@nrwl/angular:component'] || {}), + ...(nxJson.generators['@nrwl/angular:component'] || {}), }; - updateWorkspaceConfiguration(host, workspace); + updateNxJson(host, nxJson); } function updateDependencies(host: Tree): GeneratorCallback { diff --git a/packages/angular/src/generators/init/init.ts b/packages/angular/src/generators/init/init.ts index bafd94676e45e..819f5db4d4389 100755 --- a/packages/angular/src/generators/init/init.ts +++ b/packages/angular/src/generators/init/init.ts @@ -4,9 +4,9 @@ import { formatFiles, GeneratorCallback, logger, - readWorkspaceConfiguration, + readNxJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { jestInitGenerator } from '@nrwl/jest'; import { Linter } from '@nrwl/linter'; @@ -75,27 +75,27 @@ function normalizeOptions(options: Schema): Required { } function setDefaults(host: Tree, options: Schema) { - const workspace = readWorkspaceConfiguration(host); + const nxJson = readNxJson(host); - workspace.generators = workspace.generators || {}; - workspace.generators['@nrwl/angular:application'] = { + nxJson.generators = nxJson.generators || {}; + nxJson.generators['@nrwl/angular:application'] = { style: options.style, linter: options.linter, unitTestRunner: options.unitTestRunner, e2eTestRunner: options.e2eTestRunner, - ...(workspace.generators['@nrwl/angular:application'] || {}), + ...(nxJson.generators['@nrwl/angular:application'] || {}), }; - workspace.generators['@nrwl/angular:library'] = { + nxJson.generators['@nrwl/angular:library'] = { linter: options.linter, unitTestRunner: options.unitTestRunner, - ...(workspace.generators['@nrwl/angular:library'] || {}), + ...(nxJson.generators['@nrwl/angular:library'] || {}), }; - workspace.generators['@nrwl/angular:component'] = { + nxJson.generators['@nrwl/angular:component'] = { style: options.style, - ...(workspace.generators['@nrwl/angular:component'] || {}), + ...(nxJson.generators['@nrwl/angular:component'] || {}), }; - updateWorkspaceConfiguration(host, workspace); + updateNxJson(host, nxJson); } function updateDependencies(host: Tree): GeneratorCallback { diff --git a/packages/angular/src/generators/karma/angular-v14/karma.ts b/packages/angular/src/generators/karma/angular-v14/karma.ts index 8f0abdb42a1b9..cea1f62acf200 100644 --- a/packages/angular/src/generators/karma/angular-v14/karma.ts +++ b/packages/angular/src/generators/karma/angular-v14/karma.ts @@ -4,16 +4,16 @@ import { generateFiles, joinPathFragments, readJson, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + updateNxJson, } from '@nrwl/devkit'; import { versions } from '../../../utils/versions'; import { GeneratorOptions } from './schema'; function addTestInputs(tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - const productionFileSet = workspaceConfiguration.namedInputs?.production; + const productionFileSet = nxJson.namedInputs?.production; if (productionFileSet) { productionFileSet.push( // Exclude spec files from production fileset @@ -24,23 +24,19 @@ function addTestInputs(tree: Tree) { '!{projectRoot}/karma.conf.js' ); // Dedupe and set - workspaceConfiguration.namedInputs.production = Array.from( - new Set(productionFileSet) - ); + nxJson.namedInputs.production = Array.from(new Set(productionFileSet)); } // Test targets depend on all their project's sources + production sources of dependencies - workspaceConfiguration.targetDefaults ??= {}; - workspaceConfiguration.targetDefaults.test ??= {}; - workspaceConfiguration.targetDefaults.test.inputs ??= [ + nxJson.targetDefaults ??= {}; + nxJson.targetDefaults.test ??= {}; + nxJson.targetDefaults.test.inputs ??= [ 'default', productionFileSet ? '^production' : '^default', ]; - workspaceConfiguration.targetDefaults.test.inputs.push( - '{workspaceRoot}/karma.conf.js' - ); + nxJson.targetDefaults.test.inputs.push('{workspaceRoot}/karma.conf.js'); - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } export function karmaGenerator(tree: Tree, options: GeneratorOptions) { diff --git a/packages/angular/src/generators/karma/karma.ts b/packages/angular/src/generators/karma/karma.ts index d90d949d60e97..b742445cf7f73 100644 --- a/packages/angular/src/generators/karma/karma.ts +++ b/packages/angular/src/generators/karma/karma.ts @@ -4,8 +4,8 @@ import { generateFiles, joinPathFragments, readJson, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + updateNxJson, } from '@nrwl/devkit'; import { jasmineCoreVersion, @@ -23,9 +23,9 @@ import { getGeneratorDirectoryForInstalledAngularVersion } from '../../utils/get import { join } from 'path'; function addTestInputs(tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - const productionFileSet = workspaceConfiguration.namedInputs?.production; + const productionFileSet = nxJson.namedInputs?.production; if (productionFileSet) { productionFileSet.push( // Exclude spec files from production fileset @@ -36,23 +36,19 @@ function addTestInputs(tree: Tree) { '!{projectRoot}/karma.conf.js' ); // Dedupe and set - workspaceConfiguration.namedInputs.production = Array.from( - new Set(productionFileSet) - ); + nxJson.namedInputs.production = Array.from(new Set(productionFileSet)); } // Test targets depend on all their project's sources + production sources of dependencies - workspaceConfiguration.targetDefaults ??= {}; - workspaceConfiguration.targetDefaults.test ??= {}; - workspaceConfiguration.targetDefaults.test.inputs ??= [ + nxJson.targetDefaults ??= {}; + nxJson.targetDefaults.test ??= {}; + nxJson.targetDefaults.test.inputs ??= [ 'default', productionFileSet ? '^production' : '^default', ]; - workspaceConfiguration.targetDefaults.test.inputs.push( - '{workspaceRoot}/karma.conf.js' - ); + nxJson.targetDefaults.test.inputs.push('{workspaceRoot}/karma.conf.js'); - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } export async function karmaGenerator(tree: Tree, options: GeneratorOptions) { diff --git a/packages/angular/src/generators/library/lib/enable-strict-type-checking.ts b/packages/angular/src/generators/library/lib/enable-strict-type-checking.ts index 80c6fe21aee5d..62d324759148b 100644 --- a/packages/angular/src/generators/library/lib/enable-strict-type-checking.ts +++ b/packages/angular/src/generators/library/lib/enable-strict-type-checking.ts @@ -1,9 +1,5 @@ import type { Tree } from '@nrwl/devkit'; -import { - readWorkspaceConfiguration, - updateJson, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, updateJson, updateNxJson } from '@nrwl/devkit'; import { NormalizedSchema } from './normalized-schema'; /** @@ -19,16 +15,16 @@ export function enableStrictTypeChecking( export function setLibraryStrictDefault(host: Tree, isStrict: boolean) { // set the default so future libraries use it // unless the user has previously set this value - const workspace = readWorkspaceConfiguration(host); + const nxJson = readNxJson(host); - workspace.generators = workspace.generators || {}; + nxJson.generators = nxJson.generators || {}; - workspace.generators['@nrwl/angular:library'] = - workspace.generators['@nrwl/angular:library'] || {}; + nxJson.generators['@nrwl/angular:library'] = + nxJson.generators['@nrwl/angular:library'] || {}; - workspace.generators['@nrwl/angular:library'].strict = - workspace.generators['@nrwl/angular:library'].strict ?? isStrict; - updateWorkspaceConfiguration(host, workspace); + nxJson.generators['@nrwl/angular:library'].strict = + nxJson.generators['@nrwl/angular:library'].strict ?? isStrict; + updateNxJson(host, nxJson); } function updateTsConfig( @@ -36,7 +32,7 @@ function updateTsConfig( options: NormalizedSchema['libraryOptions'] ) { // Update the settings in the tsconfig.app.json to enable strict type checking. - // This matches the settings defined by the Angular CLI https://angular.io/guide/strict-mode + // This matches the settings defined by the Angular CL https://angular.io/guide/strict-mode updateJson(host, `${options.projectRoot}/tsconfig.json`, (json) => { // update the TypeScript settings json.compilerOptions = { diff --git a/packages/angular/src/generators/library/library.spec.ts b/packages/angular/src/generators/library/library.spec.ts index c822dcf6f3f19..20e51e0b30d26 100644 --- a/packages/angular/src/generators/library/library.spec.ts +++ b/packages/angular/src/generators/library/library.spec.ts @@ -1408,7 +1408,7 @@ describe('lib', () => { type: 'lib', data: { root: 'libs/my-lib', - }, + } as any, }, }, dependencies: {}, diff --git a/packages/angular/src/generators/move/lib/update-ng-package.ts b/packages/angular/src/generators/move/lib/update-ng-package.ts index 92408b2418011..771afbc475abe 100644 --- a/packages/angular/src/generators/move/lib/update-ng-package.ts +++ b/packages/angular/src/generators/move/lib/update-ng-package.ts @@ -41,7 +41,7 @@ export function updateNgPackage(tree: Tree, schema: Schema): void { root: project.root, targets: project.targets, }, - } + } as any ); const output = outputs[0] ?? `dist/${project.root}`; diff --git a/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap b/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap index 3eabd1dc47c78..68d48deb0f574 100644 --- a/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap +++ b/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap @@ -44,6 +44,7 @@ Object { "affected": Object { "defaultBase": "main", }, + "defaultProject": "app1", "namedInputs": Object { "default": Array [ "{projectRoot}/**/*", diff --git a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts index 0fc32bdf18fca..c9cae76f04d0c 100755 --- a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts +++ b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts @@ -40,6 +40,8 @@ export async function migrateFromAngularCli( const projects = getAllProjects(tree); const options = normalizeOptions(tree, rawOptions, projects); + const angularJson = readJson(tree, 'angular.json') as any; + if (options.preserveAngularCliLayout) { addDependenciesToPackageJson( tree, @@ -50,7 +52,7 @@ export async function migrateFromAngularCli( prettier: prettierVersion, } ); - createNxJson(tree, options); + createNxJson(tree, options, angularJson.defaultProject); decorateAngularCli(tree); updateVsCodeRecommendedExtensions(tree); await updatePrettierConfig(tree); @@ -90,7 +92,7 @@ export async function migrateFromAngularCli( version: 2, $schema: undefined, })); - createNxJson(tree, options); + createNxJson(tree, options, angularJson.defaultProject); updateWorkspaceConfigDefaults(tree); updateRootTsConfig(tree); updatePackageJson(tree); diff --git a/packages/angular/src/generators/ng-add/migrators/migrator.ts b/packages/angular/src/generators/ng-add/migrators/migrator.ts index 688cfdbb81032..eee0ed202af2f 100644 --- a/packages/angular/src/generators/ng-add/migrators/migrator.ts +++ b/packages/angular/src/generators/ng-add/migrators/migrator.ts @@ -5,9 +5,9 @@ import type { } from '@nrwl/devkit'; import { joinPathFragments, - readWorkspaceConfiguration, + readNxJson, updateJson, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { basename } from 'path'; import type { Logger } from '../utilities/logger'; @@ -31,6 +31,7 @@ export abstract class Migrator { } abstract migrate(): Promise | void; + abstract validate(): ValidationResult; protected convertAsset(asset: string | any): string | any { @@ -94,21 +95,19 @@ export abstract class Migrator { return; } - const workspaceConfig = readWorkspaceConfiguration(this.tree); - - Object.keys(workspaceConfig.tasksRunnerOptions ?? {}).forEach( - (taskRunnerName) => { - const taskRunner = workspaceConfig.tasksRunnerOptions[taskRunnerName]; - taskRunner.options.cacheableOperations = Array.from( - new Set([ - ...(taskRunner.options.cacheableOperations ?? []), - ...targetNames, - ]) - ); - } - ); + const nxJson = readNxJson(this.tree); + + Object.keys(nxJson.tasksRunnerOptions ?? {}).forEach((taskRunnerName) => { + const taskRunner = nxJson.tasksRunnerOptions[taskRunnerName]; + taskRunner.options.cacheableOperations = Array.from( + new Set([ + ...(taskRunner.options.cacheableOperations ?? []), + ...targetNames, + ]) + ); + }); - updateWorkspaceConfiguration(this.tree, workspaceConfig); + updateNxJson(this.tree, nxJson); } // TODO(leo): This should be moved to BuilderMigrator once everything is split into builder migrators. diff --git a/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.spec.ts b/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.spec.ts index 7d28155c0070b..ca8acf7569113 100644 --- a/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.spec.ts +++ b/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.spec.ts @@ -5,8 +5,8 @@ import type { } from '@nrwl/devkit'; import { readJson, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, writeJson, } from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; @@ -1619,7 +1619,7 @@ describe('app migrator', () => { await migrator.migrate(); - const { tasksRunnerOptions } = readWorkspaceConfiguration(tree); + const { tasksRunnerOptions } = readNxJson(tree); expect( tasksRunnerOptions.default.options.cacheableOperations ).toStrictEqual([ @@ -1655,7 +1655,7 @@ describe('app migrator', () => { await migrator.migrate(); - const { tasksRunnerOptions } = readWorkspaceConfiguration(tree); + const { tasksRunnerOptions } = readNxJson(tree); expect( tasksRunnerOptions.default.options.cacheableOperations ).toStrictEqual(['build', 'lint', 'test', 'e2e', 'myCustomTest']); diff --git a/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.spec.ts b/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.spec.ts index 28ca48303e254..2e1f29b49507c 100644 --- a/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.spec.ts +++ b/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.spec.ts @@ -5,8 +5,8 @@ import type { } from '@nrwl/devkit'; import { readJson, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, writeJson, } from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; @@ -1275,7 +1275,7 @@ describe('lib migrator', () => { await migrator.migrate(); - const { tasksRunnerOptions } = readWorkspaceConfiguration(tree); + const { tasksRunnerOptions } = readNxJson(tree); expect( tasksRunnerOptions.default.options.cacheableOperations ).toStrictEqual([ @@ -1305,7 +1305,7 @@ describe('lib migrator', () => { await migrator.migrate(); - const { tasksRunnerOptions } = readWorkspaceConfiguration(tree); + const { tasksRunnerOptions } = readNxJson(tree); expect( tasksRunnerOptions.default.options.cacheableOperations ).toStrictEqual(['build', 'lint', 'test', 'e2e', 'myCustomTest']); diff --git a/packages/angular/src/generators/ng-add/utilities/workspace.ts b/packages/angular/src/generators/ng-add/utilities/workspace.ts index 8f4a4080d4159..b9849cf03c7f6 100644 --- a/packages/angular/src/generators/ng-add/utilities/workspace.ts +++ b/packages/angular/src/generators/ng-add/utilities/workspace.ts @@ -4,10 +4,10 @@ import { getProjects, joinPathFragments, readJson, - readWorkspaceConfiguration, + readNxJson, updateJson, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, writeJson, } from '@nrwl/devkit'; import { Linter, lintInitGenerator } from '@nrwl/linter'; @@ -42,7 +42,11 @@ export function validateWorkspace(tree: Tree): void { - ${errors.join('\n ')}`); } -export function createNxJson(tree: Tree, options: GeneratorOptions): void { +export function createNxJson( + tree: Tree, + options: GeneratorOptions, + defaultProject: string | undefined +): void { const { npmScope } = options; const targets = getWorkspaceCommonTargets(tree); @@ -101,6 +105,7 @@ export function createNxJson(tree: Tree, options: GeneratorOptions): void { } : undefined, }, + defaultProject, }); } @@ -163,12 +168,12 @@ export function decorateAngularCli(tree: Tree): void { } export function updateWorkspaceConfigDefaults(tree: Tree): void { - const workspaceConfig = readWorkspaceConfiguration(tree); - delete (workspaceConfig as any).newProjectRoot; - if (workspaceConfig.cli) { - delete (workspaceConfig as any).defaultCollection; + const nxJson = readNxJson(tree); + delete (nxJson as any).newProjectRoot; + if (nxJson.cli) { + delete (nxJson as any).defaultCollection; } - updateWorkspaceConfiguration(tree, workspaceConfig); + updateNxJson(tree, nxJson); } export function updateRootTsConfig(tree: Tree): void { diff --git a/packages/angular/src/generators/remote/remote.spec.ts b/packages/angular/src/generators/remote/remote.spec.ts index ed80a03a6d2bf..1be7f9ac1ec72 100644 --- a/packages/angular/src/generators/remote/remote.spec.ts +++ b/packages/angular/src/generators/remote/remote.spec.ts @@ -1,7 +1,7 @@ import { getProjects, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import host from '../host/host'; @@ -103,7 +103,7 @@ describe('MF Remote App Generator', () => { }); // ASSERT - const { defaultProject } = readWorkspaceConfiguration(tree); + const { defaultProject } = readNxJson(tree); expect(defaultProject).toBeUndefined(); }); diff --git a/packages/angular/src/generators/scam-directive/lib/normalize-options.ts b/packages/angular/src/generators/scam-directive/lib/normalize-options.ts index ee28d0d5d087f..57dab1091c706 100644 --- a/packages/angular/src/generators/scam-directive/lib/normalize-options.ts +++ b/packages/angular/src/generators/scam-directive/lib/normalize-options.ts @@ -1,8 +1,8 @@ import type { Tree } from '@nrwl/devkit'; import { joinPathFragments, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, } from '@nrwl/devkit'; import type { NormalizedSchema, Schema } from '../schema'; @@ -10,8 +10,7 @@ export function normalizeOptions( tree: Tree, options: Schema ): NormalizedSchema { - const project = - options.project ?? readWorkspaceConfiguration(tree).defaultProject; + const project = options.project ?? readNxJson(tree).defaultProject; const { projectType, root, sourceRoot } = readProjectConfiguration( tree, project diff --git a/packages/angular/src/generators/scam-directive/scam-directive.ts b/packages/angular/src/generators/scam-directive/scam-directive.ts index a8a894a8fa058..30565028e6399 100644 --- a/packages/angular/src/generators/scam-directive/scam-directive.ts +++ b/packages/angular/src/generators/scam-directive/scam-directive.ts @@ -2,8 +2,8 @@ import type { Tree } from '@nrwl/devkit'; import { formatFiles, normalizePath, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, } from '@nrwl/devkit'; import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter'; import { exportScam } from '../utils/export-scam'; @@ -41,8 +41,7 @@ function checkPathUnderProjectRoot(tree: Tree, options: Partial) { return; } - const project = - options.project ?? readWorkspaceConfiguration(tree).defaultProject; + const project = options.project ?? readNxJson(tree).defaultProject; const { root } = readProjectConfiguration(tree, project); let pathToDirective = normalizePath(options.path); diff --git a/packages/angular/src/generators/scam-pipe/lib/normalize-options.ts b/packages/angular/src/generators/scam-pipe/lib/normalize-options.ts index ee28d0d5d087f..57dab1091c706 100644 --- a/packages/angular/src/generators/scam-pipe/lib/normalize-options.ts +++ b/packages/angular/src/generators/scam-pipe/lib/normalize-options.ts @@ -1,8 +1,8 @@ import type { Tree } from '@nrwl/devkit'; import { joinPathFragments, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, } from '@nrwl/devkit'; import type { NormalizedSchema, Schema } from '../schema'; @@ -10,8 +10,7 @@ export function normalizeOptions( tree: Tree, options: Schema ): NormalizedSchema { - const project = - options.project ?? readWorkspaceConfiguration(tree).defaultProject; + const project = options.project ?? readNxJson(tree).defaultProject; const { projectType, root, sourceRoot } = readProjectConfiguration( tree, project diff --git a/packages/angular/src/generators/scam-pipe/scam-pipe.ts b/packages/angular/src/generators/scam-pipe/scam-pipe.ts index 68e4f900c2625..cb9f065c6159d 100644 --- a/packages/angular/src/generators/scam-pipe/scam-pipe.ts +++ b/packages/angular/src/generators/scam-pipe/scam-pipe.ts @@ -2,8 +2,8 @@ import type { Tree } from '@nrwl/devkit'; import { formatFiles, normalizePath, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, } from '@nrwl/devkit'; import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter'; import { exportScam } from '../utils/export-scam'; @@ -41,8 +41,7 @@ function checkPathUnderProjectRoot(tree: Tree, options: Partial) { return; } - const project = - options.project ?? readWorkspaceConfiguration(tree).defaultProject; + const project = options.project ?? readNxJson(tree).defaultProject; const { root } = readProjectConfiguration(tree, project); let pathToPipe = normalizePath(options.path); diff --git a/packages/angular/src/generators/scam/lib/normalize-options.ts b/packages/angular/src/generators/scam/lib/normalize-options.ts index 5039d924cece7..1ab26ac851d33 100644 --- a/packages/angular/src/generators/scam/lib/normalize-options.ts +++ b/packages/angular/src/generators/scam/lib/normalize-options.ts @@ -1,8 +1,8 @@ import type { Tree } from '@nrwl/devkit'; import { joinPathFragments, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, } from '@nrwl/devkit'; import type { NormalizedSchema, Schema } from '../schema'; @@ -10,8 +10,7 @@ export function normalizeOptions( tree: Tree, options: Schema ): NormalizedSchema { - const project = - options.project ?? readWorkspaceConfiguration(tree).defaultProject; + const project = options.project ?? readNxJson(tree).defaultProject; const { projectType, root, sourceRoot } = readProjectConfiguration( tree, project diff --git a/packages/angular/src/generators/scam/scam.ts b/packages/angular/src/generators/scam/scam.ts index 8cad53a1296e6..a769e366e5600 100644 --- a/packages/angular/src/generators/scam/scam.ts +++ b/packages/angular/src/generators/scam/scam.ts @@ -2,8 +2,8 @@ import type { Tree } from '@nrwl/devkit'; import { formatFiles, normalizePath, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, } from '@nrwl/devkit'; import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter'; import { exportScam } from '../utils/export-scam'; @@ -41,8 +41,7 @@ function checkPathUnderProjectRoot(tree: Tree, options: Partial) { return; } - const project = - options.project ?? readWorkspaceConfiguration(tree).defaultProject; + const project = options.project ?? readNxJson(tree).defaultProject; const { root } = readProjectConfiguration(tree, project); let pathToComponent = normalizePath(options.path); diff --git a/packages/angular/src/generators/setup-mf/lib/add-remote-entry.ts b/packages/angular/src/generators/setup-mf/lib/add-remote-entry.ts index c40690a04c1fe..1edeb26017ce8 100644 --- a/packages/angular/src/generators/setup-mf/lib/add-remote-entry.ts +++ b/packages/angular/src/generators/setup-mf/lib/add-remote-entry.ts @@ -1,9 +1,5 @@ import type { Tree } from '@nrwl/devkit'; -import { - generateFiles, - joinPathFragments, - readWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { generateFiles, joinPathFragments, readNxJson } from '@nrwl/devkit'; import type { Schema } from '../schema'; import { addRoute } from '../../../utils/nx-devkit/route-utils'; @@ -12,7 +8,7 @@ export function addRemoteEntry( { appName, routing, mfType, prefix, standalone }: Schema, appRoot: string ) { - prefix = prefix ?? readWorkspaceConfiguration(tree).npmScope; + prefix = prefix ?? readNxJson(tree).npmScope; generateFiles( tree, standalone diff --git a/packages/angular/src/generators/setup-mf/lib/remove-dead-code-from-remote.ts b/packages/angular/src/generators/setup-mf/lib/remove-dead-code-from-remote.ts index 9292846f0418d..fe6980fe00b8a 100644 --- a/packages/angular/src/generators/setup-mf/lib/remove-dead-code-from-remote.ts +++ b/packages/angular/src/generators/setup-mf/lib/remove-dead-code-from-remote.ts @@ -1,10 +1,8 @@ import { Tree } from 'nx/src/generators/tree'; import { Schema } from '../schema'; -import { - readProjectConfiguration, - readWorkspaceConfiguration, -} from 'nx/src/generators/utils/project-configuration'; +import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; import { joinPathFragments } from 'nx/src/utils/path'; +import { readNxJson } from '@nrwl/devkit'; export function removeDeadCodeFromRemote(tree: Tree, options: Schema) { const projectName = options.appName; @@ -75,7 +73,7 @@ export class AppModule {}` } else { tree.delete(pathToAppComponent); - const prefix = options.prefix ?? readWorkspaceConfiguration(tree).npmScope; + const prefix = options.prefix ?? readNxJson(tree).npmScope; const remoteEntrySelector = `${prefix}-${projectName}-entry`; const pathToIndexHtml = project.targets.build.options.index; diff --git a/packages/angular/src/generators/setup-ssr/lib/normalize-options.ts b/packages/angular/src/generators/setup-ssr/lib/normalize-options.ts index fee93c9ff8fba..304238a8c4dab 100644 --- a/packages/angular/src/generators/setup-ssr/lib/normalize-options.ts +++ b/packages/angular/src/generators/setup-ssr/lib/normalize-options.ts @@ -1,10 +1,10 @@ import type { Tree } from '@nrwl/devkit'; -import { readWorkspaceConfiguration } from '@nrwl/devkit'; +import { readNxJson } from '@nrwl/devkit'; import type { Schema } from '../schema'; export function normalizeOptions(tree: Tree, options: Schema) { return { - project: options.project ?? readWorkspaceConfiguration(tree).defaultProject, + project: options.project ?? readNxJson(tree).defaultProject, appId: options.appId ?? 'serverApp', main: options.main ?? 'main.server.ts', serverFileName: options.serverFileName ?? 'server.ts', diff --git a/packages/angular/src/generators/setup-ssr/lib/update-project-config.ts b/packages/angular/src/generators/setup-ssr/lib/update-project-config.ts index e36f0a3a5e1df..6d0f73113ef6b 100644 --- a/packages/angular/src/generators/setup-ssr/lib/update-project-config.ts +++ b/packages/angular/src/generators/setup-ssr/lib/update-project-config.ts @@ -1,10 +1,10 @@ import type { Tree } from '@nrwl/devkit'; import { joinPathFragments, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, } from '@nrwl/devkit'; import type { Schema } from '../schema'; @@ -75,17 +75,17 @@ export function updateProjectConfig(tree: Tree, schema: Schema) { updateProjectConfiguration(tree, schema.project, projectConfig); - const workspaceConfig = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); if ( - workspaceConfig.tasksRunnerOptions?.default && - !workspaceConfig.tasksRunnerOptions.default.options.cacheableOperations.includes( + nxJson.tasksRunnerOptions?.default && + !nxJson.tasksRunnerOptions.default.options.cacheableOperations.includes( 'server' ) ) { - workspaceConfig.tasksRunnerOptions.default.options.cacheableOperations = [ - ...workspaceConfig.tasksRunnerOptions.default.options.cacheableOperations, + nxJson.tasksRunnerOptions.default.options.cacheableOperations = [ + ...nxJson.tasksRunnerOptions.default.options.cacheableOperations, 'server', ]; - updateWorkspaceConfiguration(tree, workspaceConfig); + updateNxJson(tree, nxJson); } } diff --git a/packages/angular/src/generators/utils/file-info.ts b/packages/angular/src/generators/utils/file-info.ts index a48243523f96e..05b539b68350b 100644 --- a/packages/angular/src/generators/utils/file-info.ts +++ b/packages/angular/src/generators/utils/file-info.ts @@ -2,8 +2,8 @@ import { joinPathFragments, names, normalizePath, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, Tree, } from '@nrwl/devkit'; @@ -46,8 +46,7 @@ function getFileInfo( options: GenerationOptions, defaultType: string ): FileInfo { - const project = - options.project ?? readWorkspaceConfiguration(tree).defaultProject; + const project = options.project ?? readNxJson(tree).defaultProject; const { root, sourceRoot, projectType } = readProjectConfiguration( tree, project diff --git a/packages/angular/src/migrations/update-13-5-0/remove-library-generator-style-default.spec.ts b/packages/angular/src/migrations/update-13-5-0/remove-library-generator-style-default.spec.ts deleted file mode 100644 index 27114e33f0527..0000000000000 --- a/packages/angular/src/migrations/update-13-5-0/remove-library-generator-style-default.spec.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, - WorkspaceConfiguration, -} from '@nrwl/devkit'; -import * as devkit from '@nrwl/devkit'; -import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import removeLibraryGeneratorStyleDefault from './remove-library-generator-style-default'; - -describe('remove-library-generator-style-default migration', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - jest.clearAllMocks(); - }); - - it('should do nothing when angular library generator is not configured', async () => { - const workspace: WorkspaceConfiguration = { - version: 2, - generators: { '@nrwl/angular:application': { style: 'scss' } }, - }; - updateWorkspaceConfiguration(tree, workspace); - - await removeLibraryGeneratorStyleDefault(tree); - - expect(readWorkspaceConfiguration(tree)).toStrictEqual(workspace); - }); - - it('should do nothing when other vertical library generator is configured with the style entry', async () => { - const workspace: WorkspaceConfiguration = { - version: 2, - generators: { '@nrwl/react:library': { style: 'scss' } }, - }; - updateWorkspaceConfiguration(tree, workspace); - - await removeLibraryGeneratorStyleDefault(tree); - - expect(readWorkspaceConfiguration(tree)).toStrictEqual(workspace); - }); - - describe('collection:generator', () => { - it('should remove style entry when configured', async () => { - const workspace: WorkspaceConfiguration = { - version: 2, - generators: { '@nrwl/angular:library': { style: 'scss' } }, - }; - updateWorkspaceConfiguration(tree, workspace); - - await removeLibraryGeneratorStyleDefault(tree); - - expect(readWorkspaceConfiguration(tree)).toStrictEqual({ - version: 2, - generators: { '@nrwl/angular:library': {} }, - }); - }); - - it('should do nothing when style is not set', async () => { - const workspace: WorkspaceConfiguration = { - version: 2, - generators: { '@nrwl/angular:library': { linter: 'eslint' } }, - }; - updateWorkspaceConfiguration(tree, workspace); - - await removeLibraryGeneratorStyleDefault(tree); - - expect(readWorkspaceConfiguration(tree)).toStrictEqual(workspace); - }); - }); - - describe('nested generator', () => { - it('should remove style entry when configured', async () => { - const workspace: WorkspaceConfiguration = { - version: 2, - generators: { '@nrwl/angular': { library: { style: 'scss' } } }, - }; - updateWorkspaceConfiguration(tree, workspace); - - await removeLibraryGeneratorStyleDefault(tree); - - expect(readWorkspaceConfiguration(tree)).toStrictEqual({ - version: 2, - generators: { '@nrwl/angular': { library: {} } }, - }); - }); - - it('should do nothing when style is not set', async () => { - const workspace: WorkspaceConfiguration = { - version: 2, - generators: { '@nrwl/angular': { library: { linter: 'eslint' } } }, - }; - updateWorkspaceConfiguration(tree, workspace); - - await removeLibraryGeneratorStyleDefault(tree); - - expect(readWorkspaceConfiguration(tree)).toStrictEqual(workspace); - }); - }); - - it('should format files', async () => { - jest.spyOn(devkit, 'formatFiles'); - const workspace: WorkspaceConfiguration = { - version: 2, - generators: { '@nrwl/angular:library': { style: 'scss' } }, - }; - updateWorkspaceConfiguration(tree, workspace); - - await removeLibraryGeneratorStyleDefault(tree); - - expect(devkit.formatFiles).toHaveBeenCalled(); - }); -}); diff --git a/packages/angular/src/migrations/update-13-5-0/remove-library-generator-style-default.ts b/packages/angular/src/migrations/update-13-5-0/remove-library-generator-style-default.ts index 4cf273311488c..984f3af785dd2 100644 --- a/packages/angular/src/migrations/update-13-5-0/remove-library-generator-style-default.ts +++ b/packages/angular/src/migrations/update-13-5-0/remove-library-generator-style-default.ts @@ -1,23 +1,18 @@ -import { - formatFiles, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; export default async function (tree: Tree) { - const workspace = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - if (!workspace.generators) { + if (!nxJson.generators) { return; } - if (workspace.generators['@nrwl/angular:library']) { - delete workspace.generators['@nrwl/angular:library'].style; - updateWorkspaceConfiguration(tree, workspace); - } else if (workspace.generators['@nrwl/angular']?.library) { - delete workspace.generators['@nrwl/angular'].library.style; - updateWorkspaceConfiguration(tree, workspace); + if (nxJson.generators['@nrwl/angular:library']) { + delete nxJson.generators['@nrwl/angular:library'].style; + updateNxJson(tree, nxJson); + } else if (nxJson.generators['@nrwl/angular']?.library) { + delete nxJson.generators['@nrwl/angular'].library.style; + updateNxJson(tree, nxJson); } await formatFiles(tree); diff --git a/packages/angular/src/migrations/update-15-0-0/add-karma-inputs.spec.ts b/packages/angular/src/migrations/update-15-0-0/add-karma-inputs.spec.ts index ca26551b415d3..0525746c5afea 100644 --- a/packages/angular/src/migrations/update-15-0-0/add-karma-inputs.spec.ts +++ b/packages/angular/src/migrations/update-15-0-0/add-karma-inputs.spec.ts @@ -1,9 +1,9 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { - Tree, addProjectConfiguration, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + Tree, + updateNxJson, } from '@nrwl/devkit'; import addKarmaInputs from './add-karma-inputs'; @@ -15,8 +15,7 @@ describe('15.0.0 migration (add-karma-inputs)', () => { }); it('should add inputs configuration for karma targets', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -43,7 +42,7 @@ describe('15.0.0 migration (add-karma-inputs)', () => { await addKarmaInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -75,7 +74,6 @@ describe('15.0.0 migration (add-karma-inputs)', () => { ], }, }, - "version": 2, } `); }); diff --git a/packages/angular/src/migrations/update-15-0-0/add-karma-inputs.ts b/packages/angular/src/migrations/update-15-0-0/add-karma-inputs.ts index 55560ead5a6c5..9b7533e766378 100644 --- a/packages/angular/src/migrations/update-15-0-0/add-karma-inputs.ts +++ b/packages/angular/src/migrations/update-15-0-0/add-karma-inputs.ts @@ -1,21 +1,14 @@ -import { - formatFiles, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; export default async function (tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); const karmaTargets = getKarmaTargetNames(tree); - const hasProductionFileset = !!workspaceConfiguration.namedInputs?.production; + const hasProductionFileset = !!nxJson.namedInputs?.production; if (karmaTargets.size > 0 && hasProductionFileset) { - const productionFileset = new Set( - workspaceConfiguration.namedInputs.production - ); + const productionFileset = new Set(nxJson.namedInputs.production); for (const exclusion of [ '!{projectRoot}/**/*.spec.[jt]s', '!{projectRoot}/tsconfig.spec.json', @@ -23,15 +16,12 @@ export default async function (tree: Tree) { ]) { productionFileset.add(exclusion); } - workspaceConfiguration.namedInputs.production = - Array.from(productionFileset); + nxJson.namedInputs.production = Array.from(productionFileset); } for (const targetName of karmaTargets) { - workspaceConfiguration.targetDefaults ??= {}; - const jestTargetDefaults = (workspaceConfiguration.targetDefaults[ - targetName - ] ??= {}); + nxJson.targetDefaults ??= {}; + const jestTargetDefaults = (nxJson.targetDefaults[targetName] ??= {}); jestTargetDefaults.inputs ??= [ 'default', @@ -42,7 +32,7 @@ export default async function (tree: Tree) { ]; } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); await formatFiles(tree); } diff --git a/packages/angular/src/utils/mf/utils.ts b/packages/angular/src/utils/mf/utils.ts index 77cb741ed28f6..1153e90e4ee22 100644 --- a/packages/angular/src/utils/mf/utils.ts +++ b/packages/angular/src/utils/mf/utils.ts @@ -40,7 +40,7 @@ export async function getModuleFederationConfig( determineRemoteUrl: (remote: string) => string, options: { isServer: boolean } = { isServer: false } ) { - let projectGraph: ProjectGraph; + let projectGraph: ProjectGraph; try { projectGraph = readCachedProjectGraph(); } catch (e) { diff --git a/packages/cypress/src/generators/cypress-component-project/cypress-component-project.ts b/packages/cypress/src/generators/cypress-component-project/cypress-component-project.ts index 058295454bb96..32d9f802a9306 100644 --- a/packages/cypress/src/generators/cypress-component-project/cypress-component-project.ts +++ b/packages/cypress/src/generators/cypress-component-project/cypress-component-project.ts @@ -5,12 +5,12 @@ import { joinPathFragments, offsetFromRoot, ProjectConfiguration, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, Tree, updateJson, updateProjectConfiguration, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { installedCypressVersion } from '../../utils/cypress-version'; @@ -39,7 +39,7 @@ export async function cypressComponentProject( addProjectFiles(tree, projectConfig, options); addTargetToProject(tree, projectConfig, options); - updateNxJson(tree); + updateNxJsonConfiguration(tree); updateTsConfigForComponentTesting(tree, projectConfig); if (!options.skipFormat) { @@ -99,17 +99,17 @@ function addTargetToProject( updateProjectConfiguration(tree, options.project, projectConfig); } -function updateNxJson(tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); - workspaceConfiguration.tasksRunnerOptions = { - ...workspaceConfiguration?.tasksRunnerOptions, +function updateNxJsonConfiguration(tree: Tree) { + const nxJson = readNxJson(tree); + nxJson.tasksRunnerOptions = { + ...nxJson?.tasksRunnerOptions, default: { - ...workspaceConfiguration?.tasksRunnerOptions?.default, + ...nxJson?.tasksRunnerOptions?.default, options: { - ...workspaceConfiguration?.tasksRunnerOptions?.default?.options, + ...nxJson?.tasksRunnerOptions?.default?.options, cacheableOperations: Array.from( new Set([ - ...(workspaceConfiguration?.tasksRunnerOptions?.default?.options + ...(nxJson?.tasksRunnerOptions?.default?.options ?.cacheableOperations ?? []), 'component-test', ]) @@ -118,11 +118,11 @@ function updateNxJson(tree: Tree) { }, }; - if (workspaceConfiguration.namedInputs) { - workspaceConfiguration.targetDefaults ??= {}; - const productionFileSet = workspaceConfiguration.namedInputs?.production; + if (nxJson.namedInputs) { + nxJson.targetDefaults ??= {}; + const productionFileSet = nxJson.namedInputs?.production; if (productionFileSet) { - workspaceConfiguration.namedInputs.production = Array.from( + nxJson.namedInputs.production = Array.from( new Set([ ...productionFileSet, '!{projectRoot}/cypress/**/*', @@ -131,13 +131,13 @@ function updateNxJson(tree: Tree) { ]) ); } - workspaceConfiguration.targetDefaults['component-test'] ??= {}; - workspaceConfiguration.targetDefaults['component-test'].inputs ??= [ + nxJson.targetDefaults['component-test'] ??= {}; + nxJson.targetDefaults['component-test'].inputs ??= [ 'default', productionFileSet ? '^production' : '^default', ]; } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } export function updateTsConfigForComponentTesting( diff --git a/packages/cypress/src/generators/init/init.ts b/packages/cypress/src/generators/init/init.ts index 745b11a3cf0f3..86a250bf46fe8 100644 --- a/packages/cypress/src/generators/init/init.ts +++ b/packages/cypress/src/generators/init/init.ts @@ -1,10 +1,10 @@ import { addDependenciesToPackageJson, convertNxGenerator, - readWorkspaceConfiguration, + readNxJson, removeDependenciesFromPackageJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { cypressVersion, @@ -14,23 +14,23 @@ import { import { Schema } from './schema'; function setupE2ETargetDefaults(tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - if (!workspaceConfiguration.namedInputs) { + if (!nxJson.namedInputs) { return; } // E2e targets depend on all their project's sources + production sources of dependencies - workspaceConfiguration.targetDefaults ??= {}; + nxJson.targetDefaults ??= {}; - const productionFileSet = !!workspaceConfiguration.namedInputs?.production; - workspaceConfiguration.targetDefaults.e2e ??= {}; - workspaceConfiguration.targetDefaults.e2e.inputs ??= [ + const productionFileSet = !!nxJson.namedInputs?.production; + nxJson.targetDefaults.e2e ??= {}; + nxJson.targetDefaults.e2e.inputs ??= [ 'default', productionFileSet ? '^production' : '^default', ]; - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } function updateDependencies(tree: Tree) { diff --git a/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts b/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts index cb1aebbc7f229..be52ef7c46c8c 100644 --- a/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts +++ b/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts @@ -402,7 +402,7 @@ export default defineConfig({ ...readProjectConfiguration(tree, libName), }, }, - }, + } as any, dependencies: { [appName]: [ { type: DependencyType.static, source: appName, target: libName }, diff --git a/packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.spec.ts b/packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.spec.ts index 7d8988004fbd9..b2337046dd589 100644 --- a/packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.spec.ts +++ b/packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.spec.ts @@ -1,9 +1,9 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { - Tree, addProjectConfiguration, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + Tree, + updateNxJson, } from '@nrwl/devkit'; import addCypressInputs from './add-cypress-inputs'; @@ -15,8 +15,7 @@ describe('15.0.0 migration (add-cypress-inputs)', () => { }); it('should add inputs configuration for cypress targets', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -43,7 +42,7 @@ describe('15.0.0 migration (add-cypress-inputs)', () => { await addCypressInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -70,14 +69,12 @@ describe('15.0.0 migration (add-cypress-inputs)', () => { ], }, }, - "version": 2, } `); }); it('should inputs configuration for cypress component testing targets', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -108,7 +105,7 @@ describe('15.0.0 migration (add-cypress-inputs)', () => { await addCypressInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -138,7 +135,6 @@ describe('15.0.0 migration (add-cypress-inputs)', () => { ], }, }, - "version": 2, } `); }); diff --git a/packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.ts b/packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.ts index 032fc2d8f0354..f433c640a4c60 100644 --- a/packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.ts +++ b/packages/cypress/src/migrations/update-15-0-0/add-cypress-inputs.ts @@ -1,22 +1,15 @@ -import { - formatFiles, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; import { CypressExecutorOptions } from '@nrwl/cypress/src/executors/cypress/cypress.impl'; export default async function (tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); const { cypressTargets, hasComponentTesting } = getCypressTargetNames(tree); - const hasProductionFileset = !!workspaceConfiguration.namedInputs?.production; + const hasProductionFileset = !!nxJson.namedInputs?.production; if (hasComponentTesting && hasProductionFileset && cypressTargets.size > 0) { - const productionFileset = new Set( - workspaceConfiguration.namedInputs.production - ); + const productionFileset = new Set(nxJson.namedInputs.production); for (const exclusion of [ '!{projectRoot}/cypress/**/*', '!{projectRoot}/**/*.cy.[jt]s?(x)', @@ -24,15 +17,12 @@ export default async function (tree: Tree) { ]) { productionFileset.add(exclusion); } - workspaceConfiguration.namedInputs.production = - Array.from(productionFileset); + nxJson.namedInputs.production = Array.from(productionFileset); } for (const targetName of cypressTargets) { - workspaceConfiguration.targetDefaults ??= {}; - const cypressTargetDefaults = (workspaceConfiguration.targetDefaults[ - targetName - ] ??= {}); + nxJson.targetDefaults ??= {}; + const cypressTargetDefaults = (nxJson.targetDefaults[targetName] ??= {}); cypressTargetDefaults.inputs ??= [ 'default', @@ -40,7 +30,7 @@ export default async function (tree: Tree) { ]; } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); await formatFiles(tree); } diff --git a/packages/cypress/src/utils/ct-helpers.ts b/packages/cypress/src/utils/ct-helpers.ts index 6d923940cd166..ec2c0eef326df 100644 --- a/packages/cypress/src/utils/ct-helpers.ts +++ b/packages/cypress/src/utils/ct-helpers.ts @@ -2,7 +2,6 @@ import type { ExecutorContext, ProjectGraph } from '@nrwl/devkit'; import { normalizePath, ProjectConfiguration, - readNxJson, stripIndents, TargetConfiguration, workspaceRoot, @@ -14,6 +13,7 @@ import { findProjectForPath, } from 'nx/src/project-graph/utils/find-project-for-path'; import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph'; +import { readNxJson } from 'nx/src/project-graph/file-utils'; export const CY_FILE_MATCHER = new RegExp(/\.cy\.[tj]sx?$/); /** @@ -94,7 +94,9 @@ export function createExecutorContext( targetName: string, configurationName: string ): ExecutorContext { - const projectConfigs = readProjectsConfigurationFromProjectGraph(graph); + const projectsConfigurations = + readProjectsConfigurationFromProjectGraph(graph); + const nxJsonConfiguration = readNxJson(); return { cwd: process.cwd(), projectGraph: graph, @@ -104,9 +106,11 @@ export function createExecutorContext( root: workspaceRoot, isVerbose: false, projectName, + projectsConfigurations, + nxJsonConfiguration, workspace: { - ...readNxJson(), - ...projectConfigs, + ...nxJsonConfiguration, + ...projectsConfigurations, }, }; } diff --git a/packages/cypress/src/utils/find-target-options.ts b/packages/cypress/src/utils/find-target-options.ts index 7b0ddb72608fe..1cd9314de0102 100644 --- a/packages/cypress/src/utils/find-target-options.ts +++ b/packages/cypress/src/utils/find-target-options.ts @@ -12,8 +12,8 @@ import { readTargetOptions, ExecutorContext, workspaceRoot, - readNxJson, } from '@nrwl/devkit'; +import { readNxJson } from 'nx/src/project-graph/file-utils'; import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph'; interface FindTargetOptions { @@ -185,7 +185,9 @@ function createExecutorContext( targetName: string, configurationName?: string ): ExecutorContext { - const projectConfigs = readProjectsConfigurationFromProjectGraph(graph); + const nxJsonConfiguration = readNxJson(); + const projectsConfigurations = + readProjectsConfigurationFromProjectGraph(graph); return { cwd: process.cwd(), projectGraph: graph, @@ -195,9 +197,11 @@ function createExecutorContext( root: workspaceRoot, isVerbose: false, projectName, + projectsConfigurations, + nxJsonConfiguration, workspace: { - ...readNxJson(), - ...projectConfigs, + ...projectsConfigurations, + ...nxJsonConfiguration, }, }; } diff --git a/packages/detox/src/executors/build/build.impl.ts b/packages/detox/src/executors/build/build.impl.ts index b3c4e985f3ac0..5d794f7498b16 100644 --- a/packages/detox/src/executors/build/build.impl.ts +++ b/packages/detox/src/executors/build/build.impl.ts @@ -14,7 +14,8 @@ export default async function* detoxBuildExecutor( options: DetoxBuildOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; try { await runCliBuild(context.root, projectRoot, options); diff --git a/packages/detox/src/executors/test/test.impl.ts b/packages/detox/src/executors/test/test.impl.ts index 5a79fa8c3c5e1..248adee6b867c 100644 --- a/packages/detox/src/executors/test/test.impl.ts +++ b/packages/detox/src/executors/test/test.impl.ts @@ -22,7 +22,8 @@ export default async function* detoxTestExecutor( options: DetoxTestOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; try { if (options.buildTarget) { diff --git a/packages/devkit/index.ts b/packages/devkit/index.ts index d52a40f966db3..b9f3b5b007f9c 100644 --- a/packages/devkit/index.ts +++ b/packages/devkit/index.ts @@ -60,7 +60,6 @@ export { Workspaces } from 'nx/src/config/workspaces'; // TODO (v16): Change this to export from 'nx/src/config/configuration' export { - readNxJson, readAllWorkspaceConfiguration, workspaceLayout, } from 'nx/src/project-graph/file-utils'; @@ -145,6 +144,8 @@ export { updateWorkspaceConfiguration, getProjects, isStandaloneProject, + readNxJson, + updateNxJson, } from 'nx/src/generators/utils/project-configuration'; /** diff --git a/packages/devkit/src/executors/read-target-options.ts b/packages/devkit/src/executors/read-target-options.ts index 5c1cf6f9fae11..77706de2fcb6b 100644 --- a/packages/devkit/src/executors/read-target-options.ts +++ b/packages/devkit/src/executors/read-target-options.ts @@ -21,7 +21,8 @@ export function readTargetOptions( const defaultProject = ws.calculateDefaultProjectName( context.cwd, - context.workspace + context.projectsConfigurations, + context.nxJsonConfiguration ); return combineOptionsForExecutor( diff --git a/packages/devkit/src/utils/convert-nx-executor.ts b/packages/devkit/src/utils/convert-nx-executor.ts index 96e1a036c5493..237128b48f962 100644 --- a/packages/devkit/src/utils/convert-nx-executor.ts +++ b/packages/devkit/src/utils/convert-nx-executor.ts @@ -16,7 +16,8 @@ import { ProjectGraph } from 'nx/src/config/project-graph'; export function convertNxExecutor(executor: Executor) { const builderFunction = (options, builderContext) => { const workspaces = new Workspaces(builderContext.workspaceRoot); - const workspaceConfig = workspaces.readWorkspaceConfiguration({ + const nxJsonConfiguration = workspaces.readNxJson(); + const projectsConfigurations = workspaces.readProjectsConfig({ _includeProjectsFromAngularJson: true, }); @@ -33,7 +34,9 @@ export function convertNxExecutor(executor: Executor) { targetName: builderContext.target.target, target: builderContext.target.target, configurationName: builderContext.target.configuration, - workspace: workspaceConfig, + projectsConfigurations, + nxJsonConfiguration, + workspace: { ...projectsConfigurations, ...nxJsonConfiguration }, cwd: process.cwd(), projectGraph, isVerbose: false, diff --git a/packages/devkit/src/utils/module-federation/dependencies.spec.ts b/packages/devkit/src/utils/module-federation/dependencies.spec.ts index 3e366122ae046..3a120b7c6dfb6 100644 --- a/packages/devkit/src/utils/module-federation/dependencies.spec.ts +++ b/packages/devkit/src/utils/module-federation/dependencies.spec.ts @@ -39,7 +39,7 @@ describe('getDependentPackagesForProject', () => { data: { root: 'libs/lib2', sourceRoot: 'libs/lib2/src' }, type: 'lib', }, - }, + } as any, }, 'shell' ); @@ -88,7 +88,7 @@ describe('getDependentPackagesForProject', () => { data: { root: 'libs/lib3', sourceRoot: 'libs/lib3/src' }, type: 'lib', }, - }, + } as any, }, 'shell' ); @@ -141,7 +141,7 @@ describe('getDependentPackagesForProject', () => { data: { root: 'libs/lib3', sourceRoot: 'libs/lib3/src' }, type: 'lib', }, - }, + } as any, }, 'shell' ); diff --git a/packages/esbuild/src/executors/esbuild/esbuild.impl.ts b/packages/esbuild/src/executors/esbuild/esbuild.impl.ts index a99571e664f6a..f45ff06ac364b 100644 --- a/packages/esbuild/src/executors/esbuild/esbuild.impl.ts +++ b/packages/esbuild/src/executors/esbuild/esbuild.impl.ts @@ -58,7 +58,7 @@ export async function* esbuildExecutor( context.projectGraph ); for (const tpd of thirdPartyDependencies) { - options.external.push(tpd.node.data.packageName); + options.external.push((tpd.node.data as any).packageName); externalDependencies.push(tpd); } } diff --git a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.spec.ts b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.spec.ts index 64c650f14a302..ef1b71fcd00f8 100644 --- a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.spec.ts +++ b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.spec.ts @@ -4,7 +4,7 @@ import { ExecutorContext } from 'nx/src/config/misc-interfaces'; describe('buildEsbuildOptions', () => { const context: ExecutorContext = { projectName: 'myapp', - workspace: { + projectsConfigurations: { version: 2, projects: { myapp: { @@ -12,6 +12,7 @@ describe('buildEsbuildOptions', () => { }, }, }, + nxJsonConfiguration: {}, isVerbose: false, root: '/', cwd: '/', diff --git a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts index cc129a5898c41..543f0c9447f1b 100644 --- a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts +++ b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts @@ -50,7 +50,8 @@ export function buildEsbuildOptions( ? [options.main, ...options.additionalEntryPoints] : [options.main]; if (!options.bundle) { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; const tsconfig = readJsonFile(path.join(context.root, options.tsConfig)); const matchedFiles = glob .sync(tsconfig.include ?? [], { diff --git a/packages/esbuild/src/executors/esbuild/lib/get-extra-dependencies.spec.ts b/packages/esbuild/src/executors/esbuild/lib/get-extra-dependencies.spec.ts index a7e7411141bac..0cec8a41bc1cb 100644 --- a/packages/esbuild/src/executors/esbuild/lib/get-extra-dependencies.spec.ts +++ b/packages/esbuild/src/executors/esbuild/lib/get-extra-dependencies.spec.ts @@ -19,7 +19,7 @@ describe('getExtraDependencies', () => { name: 'child2', data: {}, }, - }, + } as any, externalNodes: { 'npm:react': { type: 'npm', diff --git a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.spec.ts b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.spec.ts index 01611c9e2be46..1136d2e615158 100644 --- a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.spec.ts +++ b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.spec.ts @@ -123,7 +123,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/myapp', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`apps/myapp/src/main.ts`), createFile(`apps/myapp/blah.ts`), @@ -137,7 +137,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/mylib/src/index.ts`), createFile(`libs/mylib/src/deep.ts`), @@ -169,7 +169,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/myapp', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`apps/myapp/src/main.ts`), createFile(`apps/myapp/src/blah.ts`), @@ -183,7 +183,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/myapp2', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [], }, }, @@ -194,7 +194,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/myapp2/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile('libs/myapp2/mylib/src/index.ts')], }, }, @@ -216,7 +216,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/api', tags: ['api', 'domain1'], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/api/src/index.ts`)], }, }, @@ -227,7 +227,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/impl-both-domains', tags: ['impl', 'domain1', 'domain2'], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/impl-both-domains/src/index.ts`)], }, }, @@ -238,7 +238,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/impl-domain2', tags: ['impl', 'domain2'], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/impl-domain2/src/index.ts`)], }, }, @@ -249,7 +249,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/impl2', tags: ['impl', 'domain1'], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/impl2/src/index.ts`)], }, }, @@ -260,7 +260,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/impl', tags: ['impl', 'domain1'], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/impl/src/index.ts`)], }, }, @@ -271,7 +271,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/public', tags: ['public'], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/public/src/index.ts`)], }, }, @@ -282,7 +282,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/dependsOnPrivate', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/dependsOnPrivate/src/index.ts`, ['privateName']), ], @@ -295,7 +295,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/dependsOnPrivate2', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/dependsOnPrivate2/src/index.ts`, [ 'privateName', @@ -310,7 +310,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/private', tags: ['private'], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/private/src/index.ts`, [ 'untaggedName', @@ -326,7 +326,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/untagged', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/untagged/src/index.ts`)], }, }, @@ -337,7 +337,7 @@ describe('Enforce Module Boundaries (eslint)', () => { root: 'libs/tagged', tags: ['some-tag'], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/tagged/src/index.ts`)], }, }, @@ -922,7 +922,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/mylib/src/main.ts`), createFile(`libs/mylib/other.ts`), @@ -953,7 +953,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/mylib/src/main.ts`), createFile(`libs/mylib/other/index.ts`), @@ -984,7 +984,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/mylib/src/main.ts`)], }, }, @@ -995,7 +995,7 @@ Violation detected in: root: 'libs/other', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile('libs/other/src/index.ts')], }, }, @@ -1028,7 +1028,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/mylib/src/main.ts`)], }, }, @@ -1039,7 +1039,7 @@ Violation detected in: root: 'libs/other', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile('libs/other/src/index.ts')], }, }, @@ -1073,7 +1073,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/mylib/src/main.ts`), createFile(`libs/mylib/src/other.ts`), @@ -1109,7 +1109,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/mylib/src/main.ts`)], }, }, @@ -1120,7 +1120,7 @@ Violation detected in: root: 'libs/utils', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/utils/a.ts`)], }, }, @@ -1154,7 +1154,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/mylib/src/main.ts`)], }, }, @@ -1165,7 +1165,7 @@ Violation detected in: root: 'libs/other', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/other/index.ts`)], }, }, @@ -1208,7 +1208,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/mylib/src/main.ts`)], }, }, @@ -1219,7 +1219,7 @@ Violation detected in: root: 'apps/myapp', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`apps/myapp/src/index.ts`)], }, }, @@ -1251,7 +1251,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/mylib/src/main.ts`)], }, }, @@ -1262,7 +1262,7 @@ Violation detected in: root: 'apps/myapp-e2e', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`apps/myapp-e2e/src/index.ts`)], }, }, @@ -1294,7 +1294,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/mylib/src/main.ts`)], }, }, @@ -1305,7 +1305,7 @@ Violation detected in: root: 'libs/anotherlib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/anotherlib/src/main.ts`)], }, }, @@ -1316,7 +1316,7 @@ Violation detected in: root: 'apps/myapp', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`apps/myapp/src/index.ts`)], }, }, @@ -1359,7 +1359,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/mylib/src/main.ts`)], }, }, @@ -1370,7 +1370,7 @@ Violation detected in: root: 'libs/anotherlib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/anotherlib/src/main.ts`)], }, }, @@ -1381,7 +1381,7 @@ Violation detected in: root: 'apps/myapp', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`apps/myapp/src/index.ts`)], }, }, @@ -1418,7 +1418,7 @@ Violation detected in: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/mylib/src/main.ts`, ['anotherlibName'])], }, }, @@ -1429,7 +1429,7 @@ Violation detected in: root: 'libs/anotherlib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/anotherlib/src/main.ts`, ['mylibName'])], }, }, @@ -1440,7 +1440,7 @@ Violation detected in: root: 'apps/myapp', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`apps/myapp/src/index.ts`)], }, }, @@ -1484,7 +1484,7 @@ Circular file chain: root: 'libs/mylib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/mylib/src/main.ts`, ['badcirclelibName']), ], @@ -1497,7 +1497,7 @@ Circular file chain: root: 'libs/anotherlib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/anotherlib/src/main.ts`, ['mylibName']), createFile(`libs/anotherlib/src/index.ts`, ['mylibName']), @@ -1511,7 +1511,7 @@ Circular file chain: root: 'libs/badcirclelib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [ createFile(`libs/badcirclelib/src/main.ts`, ['anotherlibName']), ], @@ -1524,7 +1524,7 @@ Circular file chain: root: 'apps/myapp', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`apps/myapp/index.ts`)], }, }, @@ -1589,10 +1589,10 @@ Circular file chain: root: 'libs/buildableLib', tags: [], implicitDependencies: [], - architect: { + targets: { build: { // defines a buildable lib - builder: '@angular-devkit/build-ng-packagr:build', + executor: '@angular-devkit/build-ng-packagr:build', }, }, files: [createFile(`libs/buildableLib/src/main.ts`)], @@ -1605,7 +1605,7 @@ Circular file chain: root: 'libs/nonBuildableLib', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile(`libs/nonBuildableLib/src/main.ts`)], }, }, @@ -1687,10 +1687,10 @@ Circular file chain: root: 'libs/buildableLib', tags: [], implicitDependencies: [], - architect: { + targets: { build: { // defines a buildable lib - builder: '@angular-devkit/build-ng-packagr:build', + executor: '@angular-devkit/build-ng-packagr:build', }, }, files: [createFile(`libs/buildableLib/src/main.ts`)], @@ -1703,10 +1703,10 @@ Circular file chain: root: 'libs/anotherBuildableLib', tags: [], implicitDependencies: [], - architect: { + targets: { build: { // defines a buildable lib - builder: '@angular-devkit/build-ng-packagr:build', + executor: '@angular-devkit/build-ng-packagr:build', }, }, files: [createFile(`libs/anotherBuildableLib/src/main.ts`)], @@ -1826,10 +1826,10 @@ Circular file chain: root: 'libs/buildableLib', tags: [], implicitDependencies: [], - architect: { + targets: { build: { // defines a buildable lib - builder: '@angular-devkit/build-ng-packagr:build', + executor: '@angular-devkit/build-ng-packagr:build', }, }, files: [createFile(`libs/buildableLib/src/main.ts`)], @@ -1842,10 +1842,10 @@ Circular file chain: root: 'libs/anotherBuildableLib', tags: [], implicitDependencies: [], - architect: { + targets: { build: { // defines a buildable lib - builder: '@angular-devkit/build-ng-packagr:build', + executor: '@angular-devkit/build-ng-packagr:build', }, }, files: [createFile(`libs/anotherBuildableLib/src/main.ts`)], @@ -1925,10 +1925,10 @@ Circular file chain: root: 'libs/buildableLib', tags: [], implicitDependencies: [], - architect: { + targets: { build: { // defines a buildable lib - builder: '@angular-devkit/build-ng-packagr:build', + executor: '@angular-devkit/build-ng-packagr:build', }, }, files: [createFile(`libs/buildableLib/src/main.ts`)], @@ -1941,10 +1941,10 @@ Circular file chain: root: 'libs/anotherBuildableLib', tags: [], implicitDependencies: [], - architect: { + targets: { build: { // defines a buildable lib - builder: '@angular-devkit/build-ng-packagr:build', + executor: '@angular-devkit/build-ng-packagr:build', }, }, files: [createFile(`libs/anotherBuildableLib/src/main.ts`)], @@ -1976,10 +1976,10 @@ Circular file chain: root: 'libs/buildableLib', tags: [], implicitDependencies: [], - architect: { + targets: { build: { // defines a buildable lib - builder: '@angular-devkit/build-ng-packagr:build', + executor: '@angular-devkit/build-ng-packagr:build', }, }, files: [createFile(`libs/buildableLib/src/main.ts`)], @@ -1992,10 +1992,10 @@ Circular file chain: root: 'libs/anotherBuildableLib', tags: [], implicitDependencies: [], - architect: { + targets: { build: { // defines a buildable lib - builder: '@angular-devkit/build-ng-packagr:build', + executor: '@angular-devkit/build-ng-packagr:build', }, }, files: [createFile(`libs/anotherBuildableLib/src/main.ts`)], diff --git a/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts b/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts index 239d71c952698..ca18cc28d731e 100644 --- a/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts +++ b/packages/eslint-plugin-nx/src/rules/nx-plugin-checks.ts @@ -137,7 +137,7 @@ export default createESLintRule({ }); function normalizeOptions( - sourceProject: ProjectGraphProjectNode<{}>, + sourceProject: ProjectGraphProjectNode, options: Options[0] ): Options[0] { const base = { ...DEFAULT_OPTIONS, ...options }; diff --git a/packages/eslint-plugin-nx/src/utils/ast-utils.ts b/packages/eslint-plugin-nx/src/utils/ast-utils.ts index 222900b09c066..41239a034601a 100644 --- a/packages/eslint-plugin-nx/src/utils/ast-utils.ts +++ b/packages/eslint-plugin-nx/src/utils/ast-utils.ts @@ -31,7 +31,7 @@ export function getBarrelEntryPointByImportScope( } export function getBarrelEntryPointProjectNode( - projectNode: ProjectGraphProjectNode + projectNode: ProjectGraphProjectNode ): { path: string; importScope: string }[] | null { const tsConfigBase = tryReadBaseJson(); diff --git a/packages/eslint-plugin-nx/src/utils/project-graph-utils.ts b/packages/eslint-plugin-nx/src/utils/project-graph-utils.ts index 0bd692925330d..bb1259e13bc7c 100644 --- a/packages/eslint-plugin-nx/src/utils/project-graph-utils.ts +++ b/packages/eslint-plugin-nx/src/utils/project-graph-utils.ts @@ -1,10 +1,11 @@ -import { ProjectGraph, readCachedProjectGraph, readNxJson } from '@nrwl/devkit'; +import { ProjectGraph, readCachedProjectGraph } from '@nrwl/devkit'; import { isTerminalRun } from './runtime-lint-utils'; import * as chalk from 'chalk'; import { createProjectRootMappings, ProjectRootMappings, } from 'nx/src/project-graph/utils/find-project-for-path'; +import { readNxJson } from 'nx/src/project-graph/file-utils'; export function ensureGlobalProjectGraph(ruleName: string) { /** diff --git a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.spec.ts b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.spec.ts index 53f0ce78cacbe..0f18413115c9d 100644 --- a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.spec.ts +++ b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.spec.ts @@ -17,7 +17,7 @@ describe('hasBannedImport', () => { name: 'aLib', data: { tags: ['a'], - }, + } as any, }; const target: ProjectGraphExternalNode = { @@ -104,7 +104,7 @@ describe('dependentsHaveBannedImport + findTransitiveExternalDependencies', () = name: 'aLib', data: { tags: ['a'], - }, + } as any, }; const target: ProjectGraphProjectNode = { @@ -112,7 +112,7 @@ describe('dependentsHaveBannedImport + findTransitiveExternalDependencies', () = name: 'bLib', data: { tags: ['b'], - }, + } as any, }; const c: ProjectGraphProjectNode = { @@ -120,7 +120,7 @@ describe('dependentsHaveBannedImport + findTransitiveExternalDependencies', () = name: 'cLib', data: { tags: ['c'], - }, + } as any, }; const d: ProjectGraphProjectNode = { @@ -128,7 +128,7 @@ describe('dependentsHaveBannedImport + findTransitiveExternalDependencies', () = name: 'dLib', data: { tags: ['d'], - }, + } as any, }; const bannedTarget: ProjectGraphExternalNode = { diff --git a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts index 3cd5e9bfad2e5..f9c0baa65de40 100644 --- a/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts +++ b/packages/eslint-plugin-nx/src/utils/runtime-lint-utils.ts @@ -119,7 +119,7 @@ export function getTargetProjectBasedOnRelativeImport( projectGraph: ProjectGraph, projectRootMappings: ProjectRootMappings, sourceFilePath: string -): ProjectGraphProjectNode | undefined { +): ProjectGraphProjectNode | undefined { if (!isRelative(imp)) { return undefined; } diff --git a/packages/expo/src/executors/build-android/build-android.impl.ts b/packages/expo/src/executors/build-android/build-android.impl.ts index 71610e87ea6b9..560b5876319c4 100644 --- a/packages/expo/src/executors/build-android/build-android.impl.ts +++ b/packages/expo/src/executors/build-android/build-android.impl.ts @@ -23,7 +23,8 @@ export default async function* buildAndroidExecutor( logger.warn( '@nrwl/expo:build-android is deprecated and will be removed in Nx 16. Please switch to expo:prebuild and expo:build.' ); - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); if (options.sync) { displayNewlyAddedDepsMessage( diff --git a/packages/expo/src/executors/build-ios/build-ios.impl.ts b/packages/expo/src/executors/build-ios/build-ios.impl.ts index 3fc722b99e26e..0b03c5c7cd76c 100644 --- a/packages/expo/src/executors/build-ios/build-ios.impl.ts +++ b/packages/expo/src/executors/build-ios/build-ios.impl.ts @@ -22,7 +22,8 @@ export default async function* buildIosExecutor( logger.warn( '@nrwl/expo:build-status is deprecated and will be removed in Nx 16. Please switch to expo:prebuild and expo:build.' ); - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); if (options.sync) { displayNewlyAddedDepsMessage( diff --git a/packages/expo/src/executors/build-list/build-list.impl.ts b/packages/expo/src/executors/build-list/build-list.impl.ts index 480f8c7893060..9c49d61e8eab3 100644 --- a/packages/expo/src/executors/build-list/build-list.impl.ts +++ b/packages/expo/src/executors/build-list/build-list.impl.ts @@ -14,7 +14,8 @@ export default async function* buildListExecutor( options: ExpoEasBuildListOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); logger.info(runCliBuildList(context.root, projectRoot, options)); diff --git a/packages/expo/src/executors/build-status/build-status.impl.ts b/packages/expo/src/executors/build-status/build-status.impl.ts index 6ca0b08d633be..d0c668fe69dd0 100644 --- a/packages/expo/src/executors/build-status/build-status.impl.ts +++ b/packages/expo/src/executors/build-status/build-status.impl.ts @@ -20,7 +20,8 @@ export default async function* buildStatusExecutor( '@nrwl/expo:build-status is deprecated and will be removed in Nx 16. Please switch to expo:build-list.' ); - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/expo/src/executors/build-web/build-web.impl.ts b/packages/expo/src/executors/build-web/build-web.impl.ts index 0bdd4e298103d..06ee6e259bcb9 100644 --- a/packages/expo/src/executors/build-web/build-web.impl.ts +++ b/packages/expo/src/executors/build-web/build-web.impl.ts @@ -20,7 +20,8 @@ export default async function* buildWebExecutor( '@nrwl/expo:build-web is deprecated and will be removed in Nx 16. Please switch to expo:export --bundler webpack.' ); - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/expo/src/executors/build/build.impl.ts b/packages/expo/src/executors/build/build.impl.ts index 6e303b3b38280..ba2cd15e55c4c 100644 --- a/packages/expo/src/executors/build/build.impl.ts +++ b/packages/expo/src/executors/build/build.impl.ts @@ -16,7 +16,8 @@ export default async function* buildExecutor( options: ExpoEasBuildOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/expo/src/executors/download/download.impl.ts b/packages/expo/src/executors/download/download.impl.ts index 687db05f99186..2e897d1649404 100644 --- a/packages/expo/src/executors/download/download.impl.ts +++ b/packages/expo/src/executors/download/download.impl.ts @@ -33,7 +33,8 @@ export default async function* downloadExecutor( options: ExpoEasDownloadOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); const build = getBuild(context.root, projectRoot, options); diff --git a/packages/expo/src/executors/ensure-symlink/ensure-symlink.impl.ts b/packages/expo/src/executors/ensure-symlink/ensure-symlink.impl.ts index 440230c33d5e3..72e3566f32c3d 100644 --- a/packages/expo/src/executors/ensure-symlink/ensure-symlink.impl.ts +++ b/packages/expo/src/executors/ensure-symlink/ensure-symlink.impl.ts @@ -10,7 +10,8 @@ export default async function* ensureSymlinkExecutor( _, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); diff --git a/packages/expo/src/executors/export/export.impl.ts b/packages/expo/src/executors/export/export.impl.ts index 203b4c5611481..4c27a901a4b79 100644 --- a/packages/expo/src/executors/export/export.impl.ts +++ b/packages/expo/src/executors/export/export.impl.ts @@ -15,7 +15,8 @@ export default async function* exportExecutor( options: ExportExecutorSchema, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/expo/src/executors/install/install.impl.ts b/packages/expo/src/executors/install/install.impl.ts index c5978967f41d3..60e243ba7b78f 100644 --- a/packages/expo/src/executors/install/install.impl.ts +++ b/packages/expo/src/executors/install/install.impl.ts @@ -15,7 +15,8 @@ export default async function* installExecutor( options: ExpoInstallOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; try { await installAsync(context.root, options); diff --git a/packages/expo/src/executors/prebuild/prebuild.impl.ts b/packages/expo/src/executors/prebuild/prebuild.impl.ts index 7d44424534e76..dba9469230f7c 100644 --- a/packages/expo/src/executors/prebuild/prebuild.impl.ts +++ b/packages/expo/src/executors/prebuild/prebuild.impl.ts @@ -17,7 +17,8 @@ export default async function* prebuildExecutor( options: ExpoPrebuildOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/expo/src/executors/publish-set/publish-set.impl.ts b/packages/expo/src/executors/publish-set/publish-set.impl.ts index 522cb16f6a287..3ce0eacc9e585 100644 --- a/packages/expo/src/executors/publish-set/publish-set.impl.ts +++ b/packages/expo/src/executors/publish-set/publish-set.impl.ts @@ -19,7 +19,8 @@ export default async function* publishSetExecutor( '@nrwl/expo:publish-set is deprecated and will be removed in Nx 16.' ); - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/expo/src/executors/publish/publish.impl.ts b/packages/expo/src/executors/publish/publish.impl.ts index eab83b3105cc0..f4749efa582d6 100644 --- a/packages/expo/src/executors/publish/publish.impl.ts +++ b/packages/expo/src/executors/publish/publish.impl.ts @@ -21,7 +21,8 @@ export default async function* publishExecutor( ): AsyncGenerator { logger.warn('@nrwl/expo:publish is deprecated and will be removed in Nx 16.'); - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); if (options.sync) { displayNewlyAddedDepsMessage( diff --git a/packages/expo/src/executors/rollback/rollback.impl.ts b/packages/expo/src/executors/rollback/rollback.impl.ts index c81eeaaf00f3a..0a6abb978e190 100644 --- a/packages/expo/src/executors/rollback/rollback.impl.ts +++ b/packages/expo/src/executors/rollback/rollback.impl.ts @@ -19,7 +19,8 @@ export default async function* rollbackExecutor( '@nrwl/expo:rollback is deprecated and will be removed in Nx 16.' ); - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/expo/src/executors/run/run.impl.ts b/packages/expo/src/executors/run/run.impl.ts index 19a96e1dc2e2c..ce85a891b3693 100644 --- a/packages/expo/src/executors/run/run.impl.ts +++ b/packages/expo/src/executors/run/run.impl.ts @@ -23,7 +23,8 @@ export default async function* runExecutor( if (platform() !== 'darwin' && options.platform === 'ios') { throw new Error(`The run-ios build requires Mac to run`); } - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); if (options.sync) { displayNewlyAddedDepsMessage( diff --git a/packages/expo/src/executors/start/start.impl.ts b/packages/expo/src/executors/start/start.impl.ts index 0bf2d89cb5a60..4e79ff08b2ce4 100644 --- a/packages/expo/src/executors/start/start.impl.ts +++ b/packages/expo/src/executors/start/start.impl.ts @@ -17,7 +17,8 @@ export default async function* startExecutor( options: ExpoStartOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/expo/src/executors/sync-deps/sync-deps.impl.ts b/packages/expo/src/executors/sync-deps/sync-deps.impl.ts index b3313ee2e9ca1..a8a8e3dba3728 100644 --- a/packages/expo/src/executors/sync-deps/sync-deps.impl.ts +++ b/packages/expo/src/executors/sync-deps/sync-deps.impl.ts @@ -20,7 +20,8 @@ export default async function* syncDepsExecutor( options: ExpoSyncDepsOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; displayNewlyAddedDepsMessage( context.projectName, await syncDeps( diff --git a/packages/expo/src/executors/update/update.impl.ts b/packages/expo/src/executors/update/update.impl.ts index 12be40165562e..b44385afff761 100644 --- a/packages/expo/src/executors/update/update.impl.ts +++ b/packages/expo/src/executors/update/update.impl.ts @@ -16,7 +16,8 @@ export default async function* buildExecutor( options: ExpoEasUpdateOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/expo/src/generators/application/application.spec.ts b/packages/expo/src/generators/application/application.spec.ts index dd4b2cd4e9a26..8017202110339 100644 --- a/packages/expo/src/generators/application/application.spec.ts +++ b/packages/expo/src/generators/application/application.spec.ts @@ -1,9 +1,8 @@ import { - Tree, - readWorkspaceConfiguration, getProjects, readJson, readProjectConfiguration, + Tree, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Linter } from '@nrwl/linter'; @@ -100,7 +99,6 @@ describe('app', () => { unitTestRunner: 'none', }); - const workspaceJson = readWorkspaceConfiguration(appTree); const projects = getProjects(appTree); expect(projects.get('my-dir-my-app').root).toEqual('apps/my-dir/my-app'); @@ -181,7 +179,6 @@ describe('app', () => { unitTestRunner: 'none', }); - const workspaceJson = readWorkspaceConfiguration(appTree); const projects = getProjects(appTree); expect(projects.get('my-app').root).toEqual('apps/my-app'); @@ -258,7 +255,6 @@ describe('app', () => { unitTestRunner: 'none', }); - const workspaceJson = readWorkspaceConfiguration(appTree); const projects = getProjects(appTree); expect(projects.get('my-app').root).toEqual('apps/my-app'); diff --git a/packages/expo/src/generators/application/lib/add-project.ts b/packages/expo/src/generators/application/lib/add-project.ts index 9f1ea282f8142..ab82fd49503e0 100644 --- a/packages/expo/src/generators/application/lib/add-project.ts +++ b/packages/expo/src/generators/application/lib/add-project.ts @@ -2,10 +2,8 @@ import { addProjectConfiguration, offsetFromRoot, ProjectConfiguration, - readWorkspaceConfiguration, TargetConfiguration, Tree, - updateWorkspaceConfiguration, } from '@nrwl/devkit'; import { NormalizedSchema } from './normalize-options'; diff --git a/packages/expo/src/utils/find-all-npm-dependencies.spec.ts b/packages/expo/src/utils/find-all-npm-dependencies.spec.ts index d2e565713e4b1..afa844b21c1e5 100644 --- a/packages/expo/src/utils/find-all-npm-dependencies.spec.ts +++ b/packages/expo/src/utils/find-all-npm-dependencies.spec.ts @@ -24,7 +24,7 @@ test('findAllNpmDependencies', () => { name: 'lib3', data: { files: [] }, }, - }, + } as any, externalNodes: { 'npm:react-native-image-picker': { type: 'npm', diff --git a/packages/jest/src/executors/jest/jest.impl.spec.ts b/packages/jest/src/executors/jest/jest.impl.spec.ts index 7af56a71f2834..59710700bb177 100644 --- a/packages/jest/src/executors/jest/jest.impl.spec.ts +++ b/packages/jest/src/executors/jest/jest.impl.spec.ts @@ -37,7 +37,7 @@ describe('Jest Executor', () => { mockContext = { root: '/root', projectName: 'proj', - workspace: { + projectsConfigurations: { version: 2, projects: { proj: { @@ -49,6 +49,8 @@ describe('Jest Executor', () => { }, }, }, + }, + nxJsonConfiguration: { npmScope: 'test', }, target: { diff --git a/packages/jest/src/generators/init/init.ts b/packages/jest/src/generators/init/init.ts index 9e616c906b7b8..d2477de343a96 100644 --- a/packages/jest/src/generators/init/init.ts +++ b/packages/jest/src/generators/init/init.ts @@ -2,14 +2,14 @@ import { addDependenciesToPackageJson, convertNxGenerator, GeneratorCallback, - readWorkspaceConfiguration, + getProjects, + readNxJson, removeDependenciesFromPackageJson, stripIndents, Tree, updateJson, - updateWorkspaceConfiguration, + updateNxJson, updateProjectConfiguration, - getProjects, } from '@nrwl/devkit'; import { findRootJestConfig } from '../../utils/config/find-root-jest-files'; import { @@ -108,9 +108,9 @@ function createJestConfig(tree: Tree, options: NormalizedSchema) { } function addTestInputs(tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - const productionFileSet = workspaceConfiguration.namedInputs?.production; + const productionFileSet = nxJson.namedInputs?.production; if (productionFileSet) { // This is one of the patterns in the default jest patterns productionFileSet.push( @@ -122,23 +122,19 @@ function addTestInputs(tree: Tree) { '!{projectRoot}/jest.config.[jt]s' ); // Dedupe and set - workspaceConfiguration.namedInputs.production = Array.from( - new Set(productionFileSet) - ); + nxJson.namedInputs.production = Array.from(new Set(productionFileSet)); } // Test targets depend on all their project's sources + production sources of dependencies - workspaceConfiguration.targetDefaults ??= {}; - workspaceConfiguration.targetDefaults.test ??= {}; - workspaceConfiguration.targetDefaults.test.inputs ??= [ + nxJson.targetDefaults ??= {}; + nxJson.targetDefaults.test ??= {}; + nxJson.targetDefaults.test.inputs ??= [ 'default', productionFileSet ? '^production' : '^default', ]; - workspaceConfiguration.targetDefaults.test.inputs.push( - '{workspaceRoot}/jest.preset.js' - ); + nxJson.targetDefaults.test.inputs.push('{workspaceRoot}/jest.preset.js'); - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } function updateDependencies(tree: Tree, options: NormalizedSchema) { diff --git a/packages/jest/src/migrations/update-15-0-0/add-jest-inputs.spec.ts b/packages/jest/src/migrations/update-15-0-0/add-jest-inputs.spec.ts index 0afdd2f4f8e2f..28f4ceb4a9ebb 100644 --- a/packages/jest/src/migrations/update-15-0-0/add-jest-inputs.spec.ts +++ b/packages/jest/src/migrations/update-15-0-0/add-jest-inputs.spec.ts @@ -1,9 +1,9 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { - Tree, addProjectConfiguration, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + Tree, + updateNxJson, } from '@nrwl/devkit'; import addJestInputs from './add-jest-inputs'; @@ -15,8 +15,7 @@ describe('15.0.0 migration (add-jest-inputs)', () => { }); it('should add inputs configuration for jest targets', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -43,7 +42,7 @@ describe('15.0.0 migration (add-jest-inputs)', () => { await addJestInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -75,7 +74,6 @@ describe('15.0.0 migration (add-jest-inputs)', () => { ], }, }, - "version": 2, } `); }); diff --git a/packages/jest/src/migrations/update-15-0-0/add-jest-inputs.ts b/packages/jest/src/migrations/update-15-0-0/add-jest-inputs.ts index b8f8d4c76db6d..e99a5957452cc 100644 --- a/packages/jest/src/migrations/update-15-0-0/add-jest-inputs.ts +++ b/packages/jest/src/migrations/update-15-0-0/add-jest-inputs.ts @@ -1,21 +1,14 @@ -import { - formatFiles, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; export default async function (tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); const jestTargets = getJestTargetNames(tree); - const hasProductionFileset = !!workspaceConfiguration.namedInputs?.production; + const hasProductionFileset = !!nxJson.namedInputs?.production; if (jestTargets.size > 0 && hasProductionFileset) { - const productionFileset = new Set( - workspaceConfiguration.namedInputs.production - ); + const productionFileset = new Set(nxJson.namedInputs.production); for (const exclusion of [ '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json', @@ -23,15 +16,12 @@ export default async function (tree: Tree) { ]) { productionFileset.add(exclusion); } - workspaceConfiguration.namedInputs.production = - Array.from(productionFileset); + nxJson.namedInputs.production = Array.from(productionFileset); } for (const targetName of jestTargets) { - workspaceConfiguration.targetDefaults ??= {}; - const jestTargetDefaults = (workspaceConfiguration.targetDefaults[ - targetName - ] ??= {}); + nxJson.targetDefaults ??= {}; + const jestTargetDefaults = (nxJson.targetDefaults[targetName] ??= {}); jestTargetDefaults.inputs ??= [ 'default', @@ -42,7 +32,7 @@ export default async function (tree: Tree) { ]; } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); await formatFiles(tree); } diff --git a/packages/js/src/executors/swc/swc.impl.ts b/packages/js/src/executors/swc/swc.impl.ts index 66bbb66e88307..499623d0a7457 100644 --- a/packages/js/src/executors/swc/swc.impl.ts +++ b/packages/js/src/executors/swc/swc.impl.ts @@ -98,7 +98,8 @@ export async function* swcExecutor( _options: SwcExecutorOptions, context: ExecutorContext ) { - const { sourceRoot, root } = context.workspace.projects[context.projectName]; + const { sourceRoot, root } = + context.projectsConfigurations.projects[context.projectName]; const options = normalizeOptions(_options, context.root, sourceRoot, root); const { tmpTsConfig, dependencies } = checkDependencies( context, diff --git a/packages/js/src/executors/tsc/tsc.impl.spec.ts b/packages/js/src/executors/tsc/tsc.impl.spec.ts index c6ecb2ee13b9c..609cc97821de4 100644 --- a/packages/js/src/executors/tsc/tsc.impl.spec.ts +++ b/packages/js/src/executors/tsc/tsc.impl.spec.ts @@ -13,9 +13,11 @@ describe('tscExecutor', () => { context = { root: '/root', cwd: '/root', - workspace: { + projectsConfigurations: { version: 2, projects: {}, + }, + nxJsonConfiguration: { npmScope: 'test', }, isVerbose: false, diff --git a/packages/js/src/executors/tsc/tsc.impl.ts b/packages/js/src/executors/tsc/tsc.impl.ts index 60a15b615ccd6..65e40a3bee1f1 100644 --- a/packages/js/src/executors/tsc/tsc.impl.ts +++ b/packages/js/src/executors/tsc/tsc.impl.ts @@ -114,7 +114,8 @@ export async function* tscExecutor( _options: ExecutorOptions, context: ExecutorContext ) { - const { sourceRoot, root } = context.workspace.projects[context.projectName]; + const { sourceRoot, root } = + context.projectsConfigurations.projects[context.projectName]; const options = normalizeOptions(_options, context.root, sourceRoot, root); const { projectRoot, tmpTsConfig, target, dependencies } = checkDependencies( diff --git a/packages/js/src/utils/add-babel-inputs.ts b/packages/js/src/utils/add-babel-inputs.ts index 6d8a09525c472..26780a0c4977c 100644 --- a/packages/js/src/utils/add-babel-inputs.ts +++ b/packages/js/src/utils/add-babel-inputs.ts @@ -1,14 +1,14 @@ import { formatFiles, joinPathFragments, - readWorkspaceConfiguration, + readNxJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, writeJson, } from '@nrwl/devkit'; export async function addBabelInputs(tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); let globalBabelFile = ['babel.config.js', 'babel.config.json'].find((file) => tree.exists(file) ); @@ -20,18 +20,15 @@ export async function addBabelInputs(tree: Tree) { globalBabelFile = 'babel.config.json'; } - if (workspaceConfiguration.namedInputs?.sharedGlobals) { - const sharedGlobalFileset = new Set( - workspaceConfiguration.namedInputs.sharedGlobals - ); + if (nxJson.namedInputs?.sharedGlobals) { + const sharedGlobalFileset = new Set(nxJson.namedInputs.sharedGlobals); sharedGlobalFileset.add( joinPathFragments('{workspaceRoot}', globalBabelFile) ); - workspaceConfiguration.namedInputs.sharedGlobals = - Array.from(sharedGlobalFileset); + nxJson.namedInputs.sharedGlobals = Array.from(sharedGlobalFileset); } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); await formatFiles(tree); } diff --git a/packages/js/src/utils/assets/index.ts b/packages/js/src/utils/assets/index.ts index 6c777e0d699bb..a18aabd2c3ce3 100644 --- a/packages/js/src/utils/assets/index.ts +++ b/packages/js/src/utils/assets/index.ts @@ -23,7 +23,8 @@ export async function copyAssets( context: ExecutorContext ): Promise { const assetHandler = new CopyAssetsHandler({ - projectDir: context.workspace.projects[context.projectName].root, + projectDir: + context.projectsConfigurations.projects[context.projectName].root, rootDir: context.root, outputDir: options.outputPath, assets: options.assets, diff --git a/packages/js/src/utils/check-dependencies.ts b/packages/js/src/utils/check-dependencies.ts index 6c75352f1ed1e..06d004e402f07 100644 --- a/packages/js/src/utils/check-dependencies.ts +++ b/packages/js/src/utils/check-dependencies.ts @@ -11,7 +11,7 @@ export function checkDependencies( ): { tmpTsConfig: string | null; projectRoot: string; - target: ProjectGraphProjectNode; + target: ProjectGraphProjectNode; dependencies: DependentBuildableProjectNode[]; } { const { target, dependencies } = calculateProjectDependencies( diff --git a/packages/linter/src/executors/eslint/hasher.ts b/packages/linter/src/executors/eslint/hasher.ts index 3a302f0a5e741..a2df772513f2c 100644 --- a/packages/linter/src/executors/eslint/hasher.ts +++ b/packages/linter/src/executors/eslint/hasher.ts @@ -13,7 +13,7 @@ export default async function run( hasher: Hasher; projectGraph: ProjectGraph; taskGraph: TaskGraph; - workspaceConfig: ProjectsConfigurations; + projectsConfigurations: ProjectsConfigurations; } ): Promise { const res = await context.hasher.hashTask(task); @@ -23,7 +23,9 @@ export default async function run( const deps = allDeps(task.id, context.taskGraph, context.projectGraph); const tags = context.hasher.hashArray( - deps.map((d) => (context.workspaceConfig.projects[d].tags || []).join('|')) + deps.map((d) => + (context.projectsConfigurations.projects[d].tags || []).join('|') + ) ); const command = res.details['command']; diff --git a/packages/linter/src/executors/eslint/lint.impl.spec.ts b/packages/linter/src/executors/eslint/lint.impl.spec.ts index 57c923ac5dd39..8ce527e2014a6 100644 --- a/packages/linter/src/executors/eslint/lint.impl.spec.ts +++ b/packages/linter/src/executors/eslint/lint.impl.spec.ts @@ -83,7 +83,7 @@ describe('Linter Builder', () => { projectName, root: '/root', cwd: '/root', - workspace: { + projectsConfigurations: { version: 2, projects: { [projectName]: { @@ -92,6 +92,8 @@ describe('Linter Builder', () => { targets: {}, }, }, + }, + nxJsonConfiguration: { npmScope: 'test', }, isVerbose: false, diff --git a/packages/linter/src/executors/eslint/lint.impl.ts b/packages/linter/src/executors/eslint/lint.impl.ts index f3086ddb3d8bd..2ab24fecf4521 100644 --- a/packages/linter/src/executors/eslint/lint.impl.ts +++ b/packages/linter/src/executors/eslint/lint.impl.ts @@ -64,8 +64,8 @@ export default async function run( ) ) { let eslintConfigPathForError = `for ${projectName}`; - if (context.workspace?.projects?.[projectName]?.root) { - const { root } = context.workspace.projects[projectName]; + if (context.projectsConfigurations?.projects?.[projectName]?.root) { + const { root } = context.projectsConfigurations.projects[projectName]; eslintConfigPathForError = `\`${root}/.eslintrc.json\``; } diff --git a/packages/linter/src/generators/init/init.ts b/packages/linter/src/generators/init/init.ts index 5a83071e4a261..aae2a668b3b3f 100644 --- a/packages/linter/src/generators/init/init.ts +++ b/packages/linter/src/generators/init/init.ts @@ -1,10 +1,10 @@ import type { GeneratorCallback, Tree } from '@nrwl/devkit'; import { addDependenciesToPackageJson, - readWorkspaceConfiguration, + readNxJson, removeDependenciesFromPackageJson, updateJson, - updateWorkspaceConfiguration, + updateNxJson, writeJson, } from '@nrwl/devkit'; import { @@ -26,26 +26,24 @@ export interface LinterInitOptions { } function addTargetDefaults(tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - const productionFileSet = workspaceConfiguration.namedInputs?.production; + const productionFileSet = nxJson.namedInputs?.production; if (productionFileSet) { // Remove .eslintrc.json productionFileSet.push('!{projectRoot}/.eslintrc.json'); // Dedupe and set - workspaceConfiguration.namedInputs.production = Array.from( - new Set(productionFileSet) - ); + nxJson.namedInputs.production = Array.from(new Set(productionFileSet)); } - workspaceConfiguration.targetDefaults ??= {}; + nxJson.targetDefaults ??= {}; - workspaceConfiguration.targetDefaults.lint ??= {}; - workspaceConfiguration.targetDefaults.lint.inputs ??= [ + nxJson.targetDefaults.lint ??= {}; + nxJson.targetDefaults.lint.inputs ??= [ 'default', `{workspaceRoot}/.eslintrc.json`, ]; - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } function initEsLint(tree: Tree, options: LinterInitOptions): GeneratorCallback { diff --git a/packages/linter/src/generators/workspace-rules-project/workspace-rules-project.ts b/packages/linter/src/generators/workspace-rules-project/workspace-rules-project.ts index 97c0b27424ae0..0c130a1237e83 100644 --- a/packages/linter/src/generators/workspace-rules-project/workspace-rules-project.ts +++ b/packages/linter/src/generators/workspace-rules-project/workspace-rules-project.ts @@ -7,11 +7,11 @@ import { generateFiles, joinPathFragments, offsetFromRoot, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, Tree, updateJson, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { getRelativePathToRootTsConfig } from '@nrwl/workspace/src/utilities/typescript'; import { join } from 'path'; @@ -53,14 +53,14 @@ export async function lintWorkspaceRulesProjectGenerator(tree: Tree) { * Ensure that when workspace rules are updated they cause all projects to be affected for now. * TODO: Explore writing a ProjectGraph plugin to make this more surgical. */ - const workspaceConfig = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - if (workspaceConfig.targetDefaults?.lint?.inputs) { - workspaceConfig.targetDefaults.lint.inputs.push( + if (nxJson.targetDefaults?.lint?.inputs) { + nxJson.targetDefaults.lint.inputs.push( `{workspaceRoot}/${WORKSPACE_PLUGIN_DIR}/**/*` ); - updateWorkspaceConfiguration(tree, workspaceConfig); + updateNxJson(tree, nxJson); } // Add jest to the project and return installation task diff --git a/packages/linter/src/migrations/update-15-0-0/add-eslint-inputs.spec.ts b/packages/linter/src/migrations/update-15-0-0/add-eslint-inputs.spec.ts index 52e5be206a441..30087a7a89424 100644 --- a/packages/linter/src/migrations/update-15-0-0/add-eslint-inputs.spec.ts +++ b/packages/linter/src/migrations/update-15-0-0/add-eslint-inputs.spec.ts @@ -2,8 +2,8 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Tree, addProjectConfiguration, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + updateNxJson, } from '@nrwl/devkit'; import addEslintInputs from './add-eslint-inputs'; import { eslintConfigFileWhitelist } from '../../generators/utils/eslint-file'; @@ -15,8 +15,7 @@ describe('15.0.0 migration (add-eslint-inputs)', () => { beforeEach(() => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -49,7 +48,7 @@ describe('15.0.0 migration (add-eslint-inputs)', () => { await addEslintInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.namedInputs.production).toEqual([ 'default', @@ -65,7 +64,7 @@ describe('15.0.0 migration (add-eslint-inputs)', () => { await addEslintInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); const result = ['default', `{workspaceRoot}/${eslintConfigFilename}`]; expect(updated.targetDefaults.lint.inputs).toEqual(result); @@ -99,15 +98,11 @@ describe('15.0.0 migration (add-eslint-inputs)', () => { test.each(eslintConfigFileWhitelist)( 'should not add `!{projectRoot}/%s` if `workspaceConfiguration.namedInputs` is undefined', async (eslintConfigFilename) => { - updateWorkspaceConfiguration(tree, { - version: 2, - }); - tree.write(eslintConfigFilename, '{}'); await addEslintInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.namedInputs?.production).toBeUndefined(); } @@ -116,8 +111,7 @@ describe('15.0.0 migration (add-eslint-inputs)', () => { test.each(eslintConfigFileWhitelist)( 'should not add `!{projectRoot}/%s` if `workspaceConfiguration.namedInputs.production` is undefined', async (eslintConfigFilename) => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: {}, }); @@ -125,7 +119,7 @@ describe('15.0.0 migration (add-eslint-inputs)', () => { await addEslintInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.namedInputs?.production).toBeUndefined(); } @@ -157,8 +151,7 @@ describe('15.0.0 migration (add-eslint-inputs)', () => { test.each(eslintConfigFileWhitelist)( 'should not override `targetDefaults.lint.inputs` with `%s` as there was a default target set in the workspace config', async (eslintConfigFilename) => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { targetDefaults: { lint: { inputs: ['{workspaceRoot}/.eslintrc.default'], @@ -170,7 +163,7 @@ describe('15.0.0 migration (add-eslint-inputs)', () => { await addEslintInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.targetDefaults.lint.inputs).toEqual([ '{workspaceRoot}/.eslintrc.default', @@ -183,13 +176,9 @@ describe('15.0.0 migration (add-eslint-inputs)', () => { ); it('should return `default` if there is no globalEslintFile', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, - }); - await addEslintInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.targetDefaults.lint.inputs).toEqual(['default']); expect(updated.targetDefaults.lint2.inputs).toEqual(['default']); diff --git a/packages/linter/src/migrations/update-15-0-0/add-eslint-inputs.ts b/packages/linter/src/migrations/update-15-0-0/add-eslint-inputs.ts index c40a4057d319e..a7bb1d049744a 100644 --- a/packages/linter/src/migrations/update-15-0-0/add-eslint-inputs.ts +++ b/packages/linter/src/migrations/update-15-0-0/add-eslint-inputs.ts @@ -1,37 +1,32 @@ import { formatFiles, joinPathFragments, - readWorkspaceConfiguration, + readNxJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; import { eslintConfigFileWhitelist } from '../../generators/utils/eslint-file'; export default async function addEslintInputs(tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); const globalEslintFile = eslintConfigFileWhitelist.find((file) => tree.exists(file) ); - if (globalEslintFile && workspaceConfiguration.namedInputs?.production) { - const productionFileset = new Set( - workspaceConfiguration.namedInputs.production - ); + if (globalEslintFile && nxJson.namedInputs?.production) { + const productionFileset = new Set(nxJson.namedInputs.production); productionFileset.add(`!{projectRoot}/${globalEslintFile}`); - workspaceConfiguration.namedInputs.production = - Array.from(productionFileset); + nxJson.namedInputs.production = Array.from(productionFileset); } for (const targetName of getEslintTargets(tree)) { - workspaceConfiguration.targetDefaults ??= {}; + nxJson.targetDefaults ??= {}; - const lintTargetDefaults = (workspaceConfiguration.targetDefaults[ - targetName - ] ??= {}); + const lintTargetDefaults = (nxJson.targetDefaults[targetName] ??= {}); lintTargetDefaults.inputs ??= [ 'default', @@ -41,7 +36,7 @@ export default async function addEslintInputs(tree: Tree) { ]; } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); await formatFiles(tree); } diff --git a/packages/linter/src/utils/convert-tslint-to-eslint/project-converter.ts b/packages/linter/src/utils/convert-tslint-to-eslint/project-converter.ts index fb446fabddcfb..fb6fd20ab3663 100644 --- a/packages/linter/src/utils/convert-tslint-to-eslint/project-converter.ts +++ b/packages/linter/src/utils/convert-tslint-to-eslint/project-converter.ts @@ -1,3 +1,8 @@ +import type { + GeneratorCallback, + ProjectConfiguration, + Tree, +} from '@nrwl/devkit'; import { getProjects, installPackagesTask, @@ -5,17 +10,12 @@ import { logger, offsetFromRoot, readJson, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, removeDependenciesFromPackageJson, updateJson, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; -import type { - Tree, - GeneratorCallback, - ProjectConfiguration, } from '@nrwl/devkit'; import type { Linter } from 'eslint'; import { removeParserOptionsProjectIfNotRequired } from '../rules-requiring-type-checking'; @@ -423,9 +423,9 @@ export class ProjectConverter { /** * Update global linter configuration defaults in project configuration */ - const workspace = readWorkspaceConfiguration(this.host); - this.cleanUpGeneratorsConfig(workspace); - updateWorkspaceConfiguration(this.host, workspace); + const nxJson = readNxJson(this.host); + this.cleanUpGeneratorsConfig(nxJson); + updateNxJson(this.host, nxJson); /** * Update project-level linter configuration defaults in project configuration @@ -539,14 +539,14 @@ export class ProjectConverter { collectionName: string, defaults: Partial ) { - const workspace = readWorkspaceConfiguration(this.host); + const nxJson = readNxJson(this.host); - workspace.generators ||= {}; - workspace.generators[collectionName] ||= {}; - const prev = workspace.generators[collectionName]; + nxJson.generators ||= {}; + nxJson.generators[collectionName] ||= {}; + const prev = nxJson.generators[collectionName]; - workspace.generators = { - ...workspace.generators, + nxJson.generators = { + ...nxJson.generators, [collectionName]: { ...prev, 'convert-tslint-to-eslint': { @@ -556,6 +556,6 @@ export class ProjectConverter { }, }; - updateWorkspaceConfiguration(this.host, workspace); + updateNxJson(this.host, nxJson); } } diff --git a/packages/next/src/generators/application/lib/set-defaults.ts b/packages/next/src/generators/application/lib/set-defaults.ts index aaea71942abf8..1f96a5eba814c 100644 --- a/packages/next/src/generators/application/lib/set-defaults.ts +++ b/packages/next/src/generators/application/lib/set-defaults.ts @@ -1,20 +1,16 @@ -import { - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { NormalizedSchema } from './normalize-options'; export function setDefaults(host: Tree, options: NormalizedSchema) { - const workspace = readWorkspaceConfiguration(host); + const nxJson = readNxJson(host); - workspace.generators = workspace.generators || {}; - workspace.generators['@nrwl/next'] = workspace.generators['@nrwl/next'] || {}; - const prev = workspace.generators['@nrwl/next']; + nxJson.generators = nxJson.generators || {}; + nxJson.generators['@nrwl/next'] = nxJson.generators['@nrwl/next'] || {}; + const prev = nxJson.generators['@nrwl/next']; - workspace.generators = { - ...workspace.generators, + nxJson.generators = { + ...nxJson.generators, '@nrwl/next': { ...prev, application: { @@ -24,5 +20,5 @@ export function setDefaults(host: Tree, options: NormalizedSchema) { }, }, }; - updateWorkspaceConfiguration(host, workspace); + updateNxJson(host, nxJson); } diff --git a/packages/node/src/generators/application/application.ts b/packages/node/src/generators/application/application.ts index d49e355f21a6e..4d51745a09777 100644 --- a/packages/node/src/generators/application/application.ts +++ b/packages/node/src/generators/application/application.ts @@ -12,13 +12,11 @@ import { offsetFromRoot, ProjectConfiguration, readProjectConfiguration, - readWorkspaceConfiguration, TargetConfiguration, toJS, Tree, updateProjectConfiguration, updateTsConfigsToJs, - updateWorkspaceConfiguration, } from '@nrwl/devkit'; import { join } from 'path'; diff --git a/packages/nx/src/command-line/exec.ts b/packages/nx/src/command-line/exec.ts index 641923a6ab6ce..18ed703a4f6b5 100644 --- a/packages/nx/src/command-line/exec.ts +++ b/packages/nx/src/command-line/exec.ts @@ -79,7 +79,7 @@ function readScriptArgV(args: Record) { } function getScriptDefinition( - project: ProjectGraphProjectNode, + project: ProjectGraphProjectNode, targetName: string ): PackageJson['scripts'][string] { const scriptDefinition = readJsonFile( @@ -100,10 +100,7 @@ function getScriptDefinition( return scriptDefinition; } -function ensureNxTarget( - project: ProjectGraphProjectNode, - targetName: string -) { +function ensureNxTarget(project: ProjectGraphProjectNode, targetName: string) { if (!project.data.targets[targetName]) { output.error({ title: `Nx cannot find a target called "${targetName}" for ${project.name}`, @@ -119,7 +116,8 @@ function getProject(projectGraph: ProjectGraph) { const projectName = calculateDefaultProjectName( process.cwd(), workspaceRoot, - readProjectsConfigurationFromProjectGraph(projectGraph) + readProjectsConfigurationFromProjectGraph(projectGraph), + readNxJson() ); if (!projectName) { @@ -133,8 +131,7 @@ function getProject(projectGraph: ProjectGraph) { process.exit(1); } - const project: ProjectGraphProjectNode = - projectGraph.nodes[projectName]; + const project: ProjectGraphProjectNode = projectGraph.nodes[projectName]; return { projectName, project }; } diff --git a/packages/nx/src/command-line/generate.ts b/packages/nx/src/command-line/generate.ts index c16a85ff87be9..382734642c058 100644 --- a/packages/nx/src/command-line/generate.ts +++ b/packages/nx/src/command-line/generate.ts @@ -244,6 +244,7 @@ function throwInvalidInvocation(availableGenerators: string[]) { function readDefaultCollection(nxConfig: NxJsonConfiguration) { return nxConfig.cli ? nxConfig.cli.defaultCollection : null; } + export function printGenHelp( opts: GenerateOptions, schema: Schema, @@ -272,22 +273,18 @@ export async function generate(cwd: string, args: { [k: string]: any }) { const verbose = process.env.NX_VERBOSE_LOGGING === 'true'; const ws = new Workspaces(workspaceRoot); - const nxJson = readNxJson(); + const nxJsonConfiguration = readNxJson(); const projectGraph = await createProjectGraphAsync({ exitOnError: true }); - const projectsConfiguration = + const projectsConfigurations = readProjectsConfigurationFromProjectGraph(projectGraph); - const workspaceConfiguration = { - ...nxJson, - ...projectsConfiguration, - }; return handleErrors(verbose, async () => { const opts = await convertToGenerateOptions( args, ws, - readDefaultCollection(nxJson), + readDefaultCollection(nxJsonConfiguration), 'generate', - projectsConfiguration + projectsConfigurations ); if (opts.dryRun) { process.env.NX_DRY_RUN = 'true'; @@ -308,10 +305,15 @@ export async function generate(cwd: string, args: { [k: string]: any }) { opts.generatorOptions, opts.collectionName, normalizedGeneratorName, - workspaceConfiguration, + projectsConfigurations, + nxJsonConfiguration, schema, opts.interactive, - ws.calculateDefaultProjectName(cwd, workspaceConfiguration), + ws.calculateDefaultProjectName( + cwd, + projectsConfigurations, + nxJsonConfiguration + ), ws.relativeCwd(cwd), verbose ); diff --git a/packages/nx/src/command-line/new.ts b/packages/nx/src/command-line/new.ts index cb54a83ea61a9..035f54c30ec71 100644 --- a/packages/nx/src/command-line/new.ts +++ b/packages/nx/src/command-line/new.ts @@ -23,6 +23,7 @@ export async function newWorkspace(cwd: string, args: { [k: string]: any }) { '@nrwl/workspace/generators.json', normalizedGeneratorName, null, + null, schema, isInteractive, null, diff --git a/packages/nx/src/command-line/read-environment.ts b/packages/nx/src/command-line/read-environment.ts deleted file mode 100644 index 0075157867398..0000000000000 --- a/packages/nx/src/command-line/read-environment.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { NxJsonConfiguration } from '../config/nx-json'; -import { - readNxJson, - readAllWorkspaceConfiguration, -} from '../config/configuration'; - -export interface Environment { - nxJson: NxJsonConfiguration; - workspaceJson: any; - /** - * @deprecated the field will be removed after Nx 14 is released. It's left here - * not to break the type checker in case someone extends - * the tasks runner - */ - workspaceResults: any; -} - -/** - * @deprecated Read workspaceJson from projectGraph, and use readNxJson on its own. - */ -export function readEnvironment(): Environment { - const nxJson = readNxJson(); - const workspaceJson = readAllWorkspaceConfiguration(); - return { nxJson, workspaceJson, workspaceResults: null } as any; -} diff --git a/packages/nx/src/command-line/run-one.ts b/packages/nx/src/command-line/run-one.ts index 3e89667f753fe..9eb42dddf57c3 100644 --- a/packages/nx/src/command-line/run-one.ts +++ b/packages/nx/src/command-line/run-one.ts @@ -100,13 +100,15 @@ const targetAliases = { function parseRunOneOptions( cwd: string, parsedArgs: { [k: string]: any }, - projectGraph: ProjectGraph, + projectGraph: ProjectGraph, nxJson: NxJsonConfiguration ): { project; target; configuration; parsedArgs } { - const defaultProjectName = calculateDefaultProjectName(cwd, workspaceRoot, { - ...readProjectsConfigurationFromProjectGraph(projectGraph), - ...nxJson, - }); + const defaultProjectName = calculateDefaultProjectName( + cwd, + workspaceRoot, + readProjectsConfigurationFromProjectGraph(projectGraph), + nxJson + ); let project; let target; @@ -157,16 +159,17 @@ function parseRunOneOptions( export function calculateDefaultProjectName( cwd: string, root: string, - workspaceConfiguration: ProjectsConfigurations & NxJsonConfiguration + projectsConfigurations: ProjectsConfigurations, + nxJsonConfiguration: NxJsonConfiguration ) { let relativeCwd = cwd.replace(/\\/g, '/').split(root.replace(/\\/g, '/'))[1]; relativeCwd = relativeCwd.startsWith('/') ? relativeCwd.substring(1) : relativeCwd; - const matchingProject = Object.keys(workspaceConfiguration.projects).find( + const matchingProject = Object.keys(projectsConfigurations.projects).find( (p) => { - const projectRoot = workspaceConfiguration.projects[p].root; + const projectRoot = projectsConfigurations.projects[p].root; return ( relativeCwd == projectRoot || (relativeCwd == '' && projectRoot == '.') || @@ -176,7 +179,7 @@ export function calculateDefaultProjectName( ); if (matchingProject) return matchingProject; return ( - (workspaceConfiguration.cli as { defaultProjectName: string }) - ?.defaultProjectName || workspaceConfiguration.defaultProject + (nxJsonConfiguration.cli as { defaultProjectName: string }) + ?.defaultProjectName || nxJsonConfiguration.defaultProject ); } diff --git a/packages/nx/src/command-line/run.ts b/packages/nx/src/command-line/run.ts index 924d383e459ff..53ccce198607a 100644 --- a/packages/nx/src/command-line/run.ts +++ b/packages/nx/src/command-line/run.ts @@ -26,6 +26,7 @@ import { readProjectsConfigurationFromProjectGraph, } from '../project-graph/project-graph'; import { ProjectGraph } from '../config/project-graph'; +import { readNxJson } from '../config/configuration'; export interface Target { project: string; @@ -45,10 +46,10 @@ export function printRunHelp( } export function validateProject( - workspace: ProjectsConfigurations, + projects: ProjectsConfigurations, projectName: string ) { - const project = workspace.projects[projectName]; + const project = projects.projects[projectName]; if (!project) { throw new Error(`Could not find project "${projectName}"`); } @@ -135,22 +136,23 @@ async function runExecutorInternal( overrides: { [k: string]: any }, root: string, cwd: string, - workspace: ProjectsConfigurations & NxJsonConfiguration, + projectsConfigurations: ProjectsConfigurations, + nxJsonConfiguration: NxJsonConfiguration, projectGraph: ProjectGraph, isVerbose: boolean, printHelp: boolean ): Promise> { - validateProject(workspace, project); + validateProject(projectsConfigurations, project); const ws = new Workspaces(root); - const proj = workspace.projects[project]; + const proj = projectsConfigurations.projects[project]; const targetConfig = proj.targets?.[target] || createImplicitTargetConfig(root, proj, target) || mergePluginTargetsWithNxTargets( proj.root, proj.targets, - loadNxPlugins(workspace.plugins, [root], root) + loadNxPlugins(nxJsonConfiguration.plugins, [root], root) )[target]; if (!targetConfig) { @@ -188,7 +190,9 @@ async function runExecutorInternal( const r = implementation(combinedOptions, { root, target: targetConfig, - workspace, + workspace: { ...projectsConfigurations, ...nxJsonConfiguration }, + projectsConfigurations, + nxJsonConfiguration, projectName: project, targetName: target, configurationName: configuration, @@ -266,7 +270,8 @@ export async function runExecutor( }, context.root, context.cwd, - context.workspace, + context.projectsConfigurations, + context.nxJsonConfiguration, context.projectGraph, context.isVerbose, false @@ -287,14 +292,16 @@ export function run( ) { const projectGraph = readCachedProjectGraph(); return handleErrors(isVerbose, async () => { - const workspace = readProjectsConfigurationFromProjectGraph(projectGraph); + const projectsConfigurations = + readProjectsConfigurationFromProjectGraph(projectGraph); return iteratorToProcessStatusCode( await runExecutorInternal( targetDescription, overrides, root, cwd, - workspace, + projectsConfigurations, + readNxJson(), projectGraph, isVerbose, isHelp diff --git a/packages/nx/src/command-line/workspace-integrity-checks.spec.ts b/packages/nx/src/command-line/workspace-integrity-checks.spec.ts index c88d6b50b2524..fe48b5f6403d9 100644 --- a/packages/nx/src/command-line/workspace-integrity-checks.spec.ts +++ b/packages/nx/src/command-line/workspace-integrity-checks.spec.ts @@ -32,7 +32,7 @@ describe('WorkspaceIntegrityChecks', () => { root: 'libs/project1', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile('libs/project1/src/index.ts')], }, }, @@ -65,7 +65,7 @@ describe('WorkspaceIntegrityChecks', () => { root: 'libs/project1', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [], }, }, @@ -76,7 +76,7 @@ describe('WorkspaceIntegrityChecks', () => { root: 'libs/project2', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile('libs/project2/src/index.ts')], }, }, @@ -110,7 +110,7 @@ describe('WorkspaceIntegrityChecks', () => { root: 'libs/project1', tags: [], implicitDependencies: [], - architect: {}, + targets: {}, files: [createFile('libs/project1/src/index.ts')], }, }, diff --git a/packages/nx/src/config/configuration.ts b/packages/nx/src/config/configuration.ts index 53b579fd6d628..2b3771f8324d7 100644 --- a/packages/nx/src/config/configuration.ts +++ b/packages/nx/src/config/configuration.ts @@ -7,13 +7,13 @@ export function readNxJson(): NxJsonConfiguration { return new Workspaces(workspaceRoot).readNxJson(); } -// TODO(v16): Remove this /** + * TODO(vsavkin): Remove after Nx 16 is out * @deprecated Use readProjectsConfigurationFromProjectGraph(await createProjectGraphAsync()) */ export function readAllWorkspaceConfiguration(): ProjectsConfigurations & NxJsonConfiguration { - return new Workspaces(workspaceRoot).readWorkspaceConfiguration(); + return new Workspaces(workspaceRoot).readProjectsConfig(); } /** diff --git a/packages/nx/src/config/misc-interfaces.ts b/packages/nx/src/config/misc-interfaces.ts index 6902abc6c1c14..21a0abb2bbd2b 100644 --- a/packages/nx/src/config/misc-interfaces.ts +++ b/packages/nx/src/config/misc-interfaces.ts @@ -111,9 +111,10 @@ export type Executor = ( export interface HasherContext { hasher: Hasher; - projectGraph: ProjectGraph; + projectGraph: ProjectGraph; taskGraph: TaskGraph; - workspaceConfig: ProjectsConfigurations & NxJsonConfiguration; + projectsConfigurations: ProjectsConfigurations; + nxJsonConfiguration: NxJsonConfiguration; } export type CustomHasher = ( @@ -170,9 +171,25 @@ export interface ExecutorContext { target?: TargetConfiguration; /** + * Deprecated. Use projectsConfigurations or nxJsonConfiguration * The full workspace configuration + * @todo(vsavkin): remove after v17 */ - workspace: ProjectsConfigurations & NxJsonConfiguration; + workspace?: ProjectsConfigurations & NxJsonConfiguration; + + /** + * Projects config + * + * @todo(vsavkin): mark this as required for v17 + */ + projectsConfigurations?: ProjectsConfigurations; + + /** + * The contents of nx.json. + * + * @todo(vsavkin): mark this as required for v17 + */ + nxJsonConfiguration?: NxJsonConfiguration; /** * The current working directory @@ -188,7 +205,7 @@ export interface ExecutorContext { * A snapshot of the project graph as * it existed when the Nx command was kicked off * - * @todo(AgentEnder) mark this required for v15 + * @todo(vsavkin) mark this required for v17 */ projectGraph?: ProjectGraph; } diff --git a/packages/nx/src/config/project-graph.ts b/packages/nx/src/config/project-graph.ts index 4f280d1d57204..8638c9baecec9 100644 --- a/packages/nx/src/config/project-graph.ts +++ b/packages/nx/src/config/project-graph.ts @@ -1,5 +1,5 @@ import type { - TargetConfiguration, + ProjectConfiguration, Workspace, } from './workspace-json-project-json'; import { InputDefinition } from './workspace-json-project-json'; @@ -25,8 +25,8 @@ export interface ProjectFileMap { /** * A Graph of projects in the workspace and dependencies between them */ -export interface ProjectGraph { - nodes: Record>; +export interface ProjectGraph { + nodes: Record; externalNodes?: Record; dependencies: Record; // this is optional otherwise it might break folks who use project graph creation @@ -35,7 +35,7 @@ export interface ProjectGraph { } export interface ProjectGraphV4 { - nodes: Record>; + nodes: Record; dependencies: Record; // this is optional otherwise it might break folks who use project graph creation allWorkspaceFiles?: FileData[]; @@ -63,41 +63,20 @@ export enum DependencyType { /** * A node describing a project or an external node in a workspace */ -export type ProjectGraphNode = - | ProjectGraphProjectNode +export type ProjectGraphNode = + | ProjectGraphProjectNode | ProjectGraphExternalNode; /** * A node describing a project in a workspace */ -export interface ProjectGraphProjectNode { +export interface ProjectGraphProjectNode { type: 'app' | 'e2e' | 'lib'; name: string; /** * Additional metadata about a project */ - data: T & { - /** - * The project's root directory - */ - root: string; - sourceRoot?: string; - /** - * Named inputs associated with a project - */ - namedInputs?: { [inputName: string]: (string | InputDefinition)[] }; - /** - * Targets associated to the project - */ - targets?: { [targetName: string]: TargetConfiguration }; - /** - * Project's tags used for enforcing module boundaries - */ - tags?: string[]; - /** - * Projects on which this node implicitly depends on - */ - implicitDependencies?: string[]; + data: ProjectConfiguration & { /** * Files associated to the project */ diff --git a/packages/nx/src/config/workspaces.spec.ts b/packages/nx/src/config/workspaces.spec.ts index e4eb4a7f01fdb..f0183c200d923 100644 --- a/packages/nx/src/config/workspaces.spec.ts +++ b/packages/nx/src/config/workspaces.spec.ts @@ -65,7 +65,7 @@ describe('Workspaces', () => { ); const workspaces = new Workspaces('/root'); - const resolved = workspaces.readWorkspaceConfiguration(); + const resolved = workspaces.readProjectsConfig(); expect(resolved.projects.lib1).toEqual(standaloneConfig); }); @@ -96,7 +96,7 @@ describe('Workspaces', () => { ); const workspaces = new Workspaces('/root'); - const { projects } = workspaces.readWorkspaceConfiguration(); + const { projects } = workspaces.readProjectsConfig(); // projects got deduped so the workspace one remained expect(projects['lib1-workspace']).toEqual(lib1Config); expect(projects['lib1']).toBeUndefined(); @@ -136,7 +136,7 @@ describe('Workspaces', () => { ); const workspaces = new Workspaces('/root2'); - const resolved = workspaces.readWorkspaceConfiguration(); + const resolved = workspaces.readProjectsConfig(); expect(resolved.projects['my-package']).toEqual({ root: 'packages/my-package', sourceRoot: 'packages/my-package', diff --git a/packages/nx/src/config/workspaces.ts b/packages/nx/src/config/workspaces.ts index 7914275614cf8..10e7902277206 100644 --- a/packages/nx/src/config/workspaces.ts +++ b/packages/nx/src/config/workspaces.ts @@ -54,7 +54,7 @@ export function workspaceConfigName( } export class Workspaces { - private cachedWorkspaceConfig: ProjectsConfigurations & NxJsonConfiguration; + private cachedProjectsConfig: ProjectsConfigurations; constructor(private root: string) {} @@ -64,12 +64,13 @@ export class Workspaces { calculateDefaultProjectName( cwd: string, - wc: ProjectsConfigurations & NxJsonConfiguration + projects: ProjectsConfigurations, + nxJson: NxJsonConfiguration ) { const relativeCwd = this.relativeCwd(cwd); if (relativeCwd) { - const matchingProject = Object.keys(wc.projects).find((p) => { - const projectRoot = wc.projects[p].root; + const matchingProject = Object.keys(projects.projects).find((p) => { + const projectRoot = projects.projects[p].root; return ( relativeCwd == projectRoot || relativeCwd.startsWith(`${projectRoot}/`) @@ -77,18 +78,18 @@ export class Workspaces { }); if (matchingProject) return matchingProject; } - return wc.defaultProject; + return nxJson.defaultProject; } - readWorkspaceConfiguration(opts?: { + readProjectsConfig(opts?: { _ignorePluginInference?: boolean; _includeProjectsFromAngularJson?: boolean; - }): ProjectsConfigurations & NxJsonConfiguration { + }): ProjectsConfigurations { if ( - this.cachedWorkspaceConfig && - process.env.NX_CACHE_WORKSPACE_CONFIG !== 'false' + this.cachedProjectsConfig && + process.env.NX_CACHE_PROJECTS_CONFIG !== 'false' ) { - return this.cachedWorkspaceConfig; + return this.cachedProjectsConfig; } const nxJson = this.readNxJson(); const workspace = buildWorkspaceConfigurationFromGlobs( @@ -108,12 +109,23 @@ export class Workspaces { ); } - assertValidWorkspaceConfiguration(nxJson); - this.cachedWorkspaceConfig = { - ...this.mergeTargetDefaultsIntoProjectDescriptions(workspace, nxJson), - ...nxJson, - }; - return this.cachedWorkspaceConfig; + assertValidNxJson(nxJson); + this.cachedProjectsConfig = this.mergeTargetDefaultsIntoProjectDescriptions( + workspace, + nxJson + ); + return this.cachedProjectsConfig; + } + + /** + * Deprecated. Use readProjectsConfig + */ + readWorkspaceConfiguration(opts?: { + _ignorePluginInference?: boolean; + _includeProjectsFromAngularJson?: boolean; + }): ProjectsConfigurations & NxJsonConfiguration { + const nxJson = this.readNxJson(); + return { ...this.readProjectsConfig(opts), ...nxJson }; } private mergeWorkspaceJsonAndGlobProjects( @@ -260,19 +272,24 @@ export class Workspaces { readNxJson(): NxJsonConfiguration { const nxJson = path.join(this.root, 'nx.json'); if (existsSync(nxJson)) { - const nxJsonConfig = readJsonFile(nxJson); - if (nxJsonConfig.extends) { - const extendedNxJsonPath = require.resolve(nxJsonConfig.extends, { - paths: [dirname(nxJson)], - }); + const nxJsonConfiguration = readJsonFile(nxJson); + if (nxJsonConfiguration.extends) { + const extendedNxJsonPath = require.resolve( + nxJsonConfiguration.extends, + { + paths: [dirname(nxJson)], + } + ); const baseNxJson = readJsonFile(extendedNxJsonPath); return this.mergeTargetDefaultsAndTargetDependencies({ ...baseNxJson, - ...nxJsonConfig, + ...nxJsonConfiguration, }); } else { - return this.mergeTargetDefaultsAndTargetDependencies(nxJsonConfig); + return this.mergeTargetDefaultsAndTargetDependencies( + nxJsonConfiguration + ); } } else { try { @@ -437,9 +454,7 @@ function normalizeExecutorSchema( }; } -function assertValidWorkspaceConfiguration( - nxJson: NxJsonConfiguration & { projects?: any } -) { +function assertValidNxJson(nxJson: NxJsonConfiguration & { projects?: any }) { // Assert valid workspace configuration if (nxJson.projects) { logger.warn( diff --git a/packages/nx/src/daemon/client/client.ts b/packages/nx/src/daemon/client/client.ts index 0e4d157ace0b1..6b0213052364a 100644 --- a/packages/nx/src/daemon/client/client.ts +++ b/packages/nx/src/daemon/client/client.ts @@ -28,7 +28,7 @@ import { Message, SocketMessenger } from './socket-messenger'; const DAEMON_ENV_SETTINGS = { ...process.env, NX_PROJECT_GLOB_CACHE: 'false', - NX_CACHE_WORKSPACE_CONFIG: 'false', + NX_CACHE_PROJECTS_CONFIG: 'false', }; export type UnregisterCallback = () => void; diff --git a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts index c935ca6e28ae3..c8172e34c3c84 100644 --- a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts +++ b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts @@ -1,5 +1,4 @@ import { performance } from 'perf_hooks'; -import { readAllWorkspaceConfiguration } from '../../config/configuration'; import { FileData, ProjectFileMap } from '../../config/project-graph'; import { defaultFileHasher } from '../../hasher/file-hasher'; import { HashingImpl } from '../../hasher/hashing-impl'; @@ -16,6 +15,8 @@ import { import { fileExists } from '../../utils/fileutils'; import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets'; import { serverLogger } from './logger'; +import { Workspaces } from '../../config/workspaces'; +import { workspaceRoot } from '../../utils/workspace-root'; let cachedSerializedProjectGraphPromise: Promise<{ error: Error | null; @@ -117,7 +118,7 @@ async function processCollectedUpdatedAndDeletedFiles() { 'hash-watched-changes-end' ); defaultFileHasher.incrementalUpdate(updatedFiles, deletedFiles); - const workspaceJson = readAllWorkspaceConfiguration(); + const workspaceJson = new Workspaces(workspaceRoot).readProjectsConfig(); const workspaceConfigHash = computeWorkspaceConfigHash(workspaceJson); serverLogger.requestLog( `Updated file-hasher based on watched changes, recomputing project graph...` @@ -186,7 +187,7 @@ function copyFileMap(m: ProjectFileMap) { async function createAndSerializeProjectGraph() { try { performance.mark('create-project-graph-start'); - const workspaceJson = readAllWorkspaceConfiguration(); + const workspaceJson = new Workspaces(workspaceRoot).readProjectsConfig(); const { projectGraph, projectGraphCache } = await buildProjectGraphUsingProjectFileMap( workspaceJson, diff --git a/packages/nx/src/executors/run-script/run-script.impl.ts b/packages/nx/src/executors/run-script/run-script.impl.ts index d0ebc3f91ba4d..6455dcf238569 100644 --- a/packages/nx/src/executors/run-script/run-script.impl.ts +++ b/packages/nx/src/executors/run-script/run-script.impl.ts @@ -18,7 +18,7 @@ export default async function ( stdio: ['inherit', 'inherit', 'inherit'], cwd: path.join( context.root, - context.workspace.projects[context.projectName].root + context.projectsConfigurations.projects[context.projectName].root ), }); return { success: true }; diff --git a/packages/nx/src/executors/utils/convert-nx-executor.ts b/packages/nx/src/executors/utils/convert-nx-executor.ts index d40dadb8eb032..d61a1fb4d4f79 100644 --- a/packages/nx/src/executors/utils/convert-nx-executor.ts +++ b/packages/nx/src/executors/utils/convert-nx-executor.ts @@ -19,7 +19,7 @@ import { ProjectGraph } from '../../config/project-graph'; export function convertNxExecutor(executor: Executor) { const builderFunction = (options, builderContext) => { const workspaces = new Workspaces(builderContext.workspaceRoot); - const workspaceConfig = workspaces.readWorkspaceConfiguration(); + const projectsConfigurations = workspaces.readProjectsConfig(); const promise = async () => { let projectGraph: ProjectGraph; @@ -28,13 +28,16 @@ export function convertNxExecutor(executor: Executor) { } catch { projectGraph = await createProjectGraphAsync(); } + const nxJsonConfiguration = workspaces.readNxJson(); const context: ExecutorContext = { root: builderContext.workspaceRoot, projectName: builderContext.target.project, targetName: builderContext.target.target, target: builderContext.target.target, configurationName: builderContext.target.configuration, - workspace: workspaceConfig, + projectsConfigurations, + nxJsonConfiguration, + workspace: { ...projectsConfigurations, ...nxJsonConfiguration }, cwd: process.cwd(), projectGraph, isVerbose: false, diff --git a/packages/nx/src/generators/utils/project-configuration.spec.ts b/packages/nx/src/generators/utils/project-configuration.spec.ts index 768cbfab2cf30..df922468da29a 100644 --- a/packages/nx/src/generators/utils/project-configuration.spec.ts +++ b/packages/nx/src/generators/utils/project-configuration.spec.ts @@ -4,8 +4,8 @@ import { ProjectConfiguration } from '../../config/workspace-json-project-json'; import { createTree } from '../testing-utils/create-tree'; import { - createTreeWithEmptyWorkspace, createTreeWithEmptyV1Workspace, + createTreeWithEmptyWorkspace, } from '../testing-utils/create-tree-with-empty-workspace'; import { readJson, updateJson, writeJson } from '../utils/json'; import { @@ -13,11 +13,8 @@ import { getProjects, getWorkspacePath, readProjectConfiguration, - readWorkspaceConfiguration, removeProjectConfiguration, updateProjectConfiguration, - updateWorkspaceConfiguration, - WorkspaceConfiguration, } from './project-configuration'; import * as projectSchema from '../../../schemas/project-schema.json'; @@ -104,69 +101,6 @@ describe('project configuration', () => { }); }); - describe('readWorkspaceConfiguration', () => { - it('should read the workspace configuration', () => { - const result = readWorkspaceConfiguration(tree); - expect(result).toEqual({ - affected: { - defaultBase: 'main', - }, - npmScope: 'proj', - tasksRunnerOptions: { - default: { - options: { - cacheableOperations: ['build', 'lint', 'test', 'e2e'], - }, - runner: 'nx/tasks-runners/default', - }, - }, - version: 1, - }); - }); - }); - - describe('updateWorkspaceConfiguration', () => { - let workspaceConfiguration: WorkspaceConfiguration; - - beforeEach(() => { - workspaceConfiguration = readWorkspaceConfiguration(tree); - }); - - it('should update properties in workspace.json', () => { - workspaceConfiguration.version = 2; - - updateWorkspaceConfiguration(tree, workspaceConfiguration); - - expect(readJson(tree, 'workspace.json').version).toEqual(2); - }); - - it('should update properties in nx.json', () => { - workspaceConfiguration.npmScope = 'new-npmScope'; - - updateWorkspaceConfiguration(tree, workspaceConfiguration); - - expect(readJson(tree, 'nx.json').npmScope).toEqual('new-npmScope'); - }); - - it('should not update unknown properties', () => { - workspaceConfiguration['$schema'] = 'schema'; - - updateWorkspaceConfiguration(tree, workspaceConfiguration); - - expect(readJson(tree, 'workspace.json').$schema).not.toBeDefined(); - expect(readJson(tree, 'nx.json').$schema).not.toBeDefined(); - }); - - it('should skip properties that are identical to the extends property', () => { - workspaceConfiguration['$schema'] = 'schema'; - - updateWorkspaceConfiguration(tree, workspaceConfiguration); - - expect(readJson(tree, 'workspace.json').$schema).not.toBeDefined(); - expect(readJson(tree, 'nx.json').$schema).not.toBeDefined(); - }); - }); - describe('without nx.json', () => { beforeEach(() => tree.delete('nx.json')); @@ -409,73 +343,6 @@ describe('project configuration', () => { }); }); - describe('readWorkspaceConfiguration', () => { - it('should read the workspace configuration', () => { - const result = readWorkspaceConfiguration(tree); - expect(result).toEqual({ - affected: { - defaultBase: 'main', - }, - npmScope: 'proj', - tasksRunnerOptions: { - default: { - options: { - cacheableOperations: ['build', 'lint', 'test', 'e2e'], - }, - runner: 'nx/tasks-runners/default', - }, - }, - version: 2, - }); - }); - }); - - describe('updateWorkspaceConfiguration', () => { - let workspaceConfiguration: WorkspaceConfiguration; - - beforeEach(() => { - writeJson(tree, 'workspace.json', { - version: 2, - projects: {}, - }); - workspaceConfiguration = readWorkspaceConfiguration(tree); - }); - - it('should update properties in workspace.json', () => { - workspaceConfiguration.version = 1; - - updateWorkspaceConfiguration(tree, workspaceConfiguration); - - expect(readJson(tree, 'workspace.json').version).toEqual(1); - }); - - it('should update properties in nx.json', () => { - workspaceConfiguration.npmScope = 'new-npmScope'; - - updateWorkspaceConfiguration(tree, workspaceConfiguration); - - expect(readJson(tree, 'nx.json').npmScope).toEqual('new-npmScope'); - }); - - it('should not update unknown properties', () => { - workspaceConfiguration['$schema'] = 'schema'; - - updateWorkspaceConfiguration(tree, workspaceConfiguration); - - expect(readJson(tree, 'workspace.json').$schema).not.toBeDefined(); - expect(readJson(tree, 'nx.json').$schema).not.toBeDefined(); - }); - - it('should skip properties that are identical to the extends property', () => { - workspaceConfiguration['$schema'] = 'schema'; - - updateWorkspaceConfiguration(tree, workspaceConfiguration); - - expect(readJson(tree, 'workspace.json').$schema).not.toBeDefined(); - expect(readJson(tree, 'nx.json').$schema).not.toBeDefined(); - }); - }); - describe('getProjects', () => { it('should get a map of projects', () => { addProjectConfiguration(tree, 'proj', { @@ -655,20 +522,6 @@ describe('project configuration', () => { tree = createTree(); }); - describe('readWorkspaceConfiguration', () => { - it('should read project configuration from package.json files', () => { - writeJson(tree, 'proj/package.json', { - name: 'proj', - }); - - const workspace = readWorkspaceConfiguration(tree); - - expect(workspace).toEqual({ - version: 2, - }); - }); - }); - describe('readProjectConfiguration', () => { it('should read project configuration from package.json files', () => { writeJson(tree, 'proj/package.json', { diff --git a/packages/nx/src/generators/utils/project-configuration.ts b/packages/nx/src/generators/utils/project-configuration.ts index 6fd7006414e89..578bfc1e1b4dc 100644 --- a/packages/nx/src/generators/utils/project-configuration.ts +++ b/packages/nx/src/generators/utils/project-configuration.ts @@ -2,8 +2,8 @@ import { basename, dirname, join, relative } from 'path'; import type { NxJsonConfiguration } from '../../config/nx-json'; import { ProjectConfiguration, - RawProjectsConfigurations, ProjectsConfigurations, + RawProjectsConfigurations, } from '../../config/workspace-json-project-json'; import { buildWorkspaceConfigurationFromGlobs, @@ -19,6 +19,9 @@ import type { Tree } from '../tree'; import { readJson, updateJson, writeJson } from './json'; +/** + * @deprecated using NxJsonConfiguration + */ export type WorkspaceConfiguration = Omit & Partial; @@ -99,6 +102,7 @@ export function getProjects(tree: Tree): Map { * Read general workspace configuration such as the default project or cli settings * * This does _not_ provide projects configuration, use {@link readProjectConfiguration} instead. + * @deprecated use readNxJson */ export function readWorkspaceConfiguration(tree: Tree): WorkspaceConfiguration { const { projects, ...workspace } = readRawWorkspaceJson(tree); // Create a new object, without projects @@ -114,10 +118,37 @@ export function readWorkspaceConfiguration(tree: Tree): WorkspaceConfiguration { }; } +/** + * Update nx.json + */ +export function updateNxJson(tree: Tree, nxJson: NxJsonConfiguration): void { + if (tree.exists('nx.json')) { + updateJson(tree, 'nx.json', (json) => { + if (json.extends) { + const nxJsonExtends = readNxJsonExtends(tree, json.extends); + const changedPropsOfNxJson = {}; + Object.keys(nxJson).forEach((prop) => { + if ( + JSON.stringify(nxJson[prop], null, 2) != + JSON.stringify(nxJsonExtends[prop], null, 2) + ) { + changedPropsOfNxJson[prop] = nxJson[prop]; + } + }); + return changedPropsOfNxJson; + } else { + return nxJson; + } + }); + } +} + /** * Update general workspace configuration such as the default project or cli settings. * * This does _not_ update projects configuration, use {@link updateProjectConfiguration} or {@link addProjectConfiguration} instead. + * + * @deprecated use updateNxJson */ export function updateWorkspaceConfiguration( tree: Tree, @@ -158,25 +189,7 @@ export function updateWorkspaceConfiguration( extends: ext, }; - if (tree.exists('nx.json')) { - updateJson(tree, 'nx.json', (json) => { - if (json.extends) { - const nxJsonExtends = readNxJsonExtends(tree, json.extends); - const changedPropsOfNxJson = {}; - Object.keys(nxJson).forEach((prop) => { - if ( - JSON.stringify(nxJson[prop], null, 2) != - JSON.stringify(nxJsonExtends[prop], null, 2) - ) { - changedPropsOfNxJson[prop] = nxJson[prop]; - } - }); - return { ...json, ...changedPropsOfNxJson }; - } else { - return { ...json, ...nxJson }; - } - }); - } + updateNxJson(tree, nxJson); // Only prop in workspace.json is version. If there is no // workspace.json file, this f(x) doesn't update anything @@ -240,6 +253,9 @@ export function readProjectConfiguration( return getProjectConfiguration(projectName, workspace); } +/** + * Reads nx.json + */ export function readNxJson(tree: Tree): NxJsonConfiguration | null { if (!tree.exists('nx.json')) { return null; @@ -272,18 +288,18 @@ export function isStandaloneProject(tree: Tree, project: string): boolean { function getProjectConfiguration( projectName: string, - workspace: ProjectsConfigurations + projects: ProjectsConfigurations ): ProjectConfiguration { return { - ...readWorkspaceSection(workspace, projectName), + ...readWorkspaceSection(projects, projectName), }; } function readWorkspaceSection( - workspace: ProjectsConfigurations, + projects: ProjectsConfigurations, projectName: string ) { - return workspace.projects[projectName]; + return projects.projects[projectName]; } function setProjectConfiguration( @@ -484,6 +500,7 @@ function findDeletedProjects(tree: Tree) { let staticFSWorkspace: RawProjectsConfigurations; let cachedTree: Tree; + function readRawWorkspaceJson(tree: Tree): RawProjectsConfigurations { const path = getWorkspacePath(tree); if (path && tree.exists(path)) { @@ -540,20 +557,20 @@ function getProjectFileLocation(tree: Tree, project: string): string | null { function validateProjectConfigurationOperationsGivenWorkspaceJson( mode: 'create' | 'update' | 'delete', - workspaceJson: RawProjectsConfigurations | ProjectsConfigurations | null, + projectsConfigs: RawProjectsConfigurations | ProjectsConfigurations | null, projectName: string ) { - if (mode == 'create' && workspaceJson.projects[projectName]) { + if (mode == 'create' && projectsConfigs.projects[projectName]) { throw new Error( `Cannot create Project '${projectName}'. It already exists.` ); } - if (mode == 'update' && !workspaceJson.projects[projectName]) { + if (mode == 'update' && !projectsConfigs.projects[projectName]) { throw new Error( `Cannot update Project '${projectName}'. It does not exist.` ); } - if (mode == 'delete' && !workspaceJson.projects[projectName]) { + if (mode == 'delete' && !projectsConfigs.projects[projectName]) { throw new Error( `Cannot delete Project '${projectName}'. It does not exist.` ); diff --git a/packages/nx/src/hasher/hash-task.ts b/packages/nx/src/hasher/hash-task.ts index 85ffca69b0104..cd0a715ad5682 100644 --- a/packages/nx/src/hasher/hash-task.ts +++ b/packages/nx/src/hasher/hash-task.ts @@ -39,14 +39,17 @@ export async function hashTask( workspaces.readNxJson(), projectGraph ); + const projectsConfigurations = + readProjectsConfigurationFromProjectGraph(projectGraph); const { value, details } = await (customHasher ? customHasher(task, { hasher, projectGraph, taskGraph, - workspaceConfig: - readProjectsConfigurationFromProjectGraph(projectGraph), - }) + workspaceConfig: projectsConfigurations, // to make the change non-breaking. Remove after v18 + projectsConfigurations, + nxJsonConfiguration: workspaces.readNxJson(), + } as any) : hasher.hashTask(task)); task.hash = value; task.hashDetails = details; diff --git a/packages/nx/src/hasher/hasher.ts b/packages/nx/src/hasher/hasher.ts index c0d29b6af46c4..77f94ac682e21 100644 --- a/packages/nx/src/hasher/hasher.ts +++ b/packages/nx/src/hasher/hasher.ts @@ -231,7 +231,7 @@ class TaskHasher { task.target.target ]; const { selfInputs, depsInputs } = splitInputsIntoSelfAndDependencies( - targetData.inputs || targetDefaults?.inputs || DEFAULT_INPUTS, + targetData.inputs || targetDefaults?.inputs || (DEFAULT_INPUTS as any), namedInputs ); diff --git a/packages/nx/src/lock-file/lock-file.spec.ts b/packages/nx/src/lock-file/lock-file.spec.ts index 31cb97281f107..b7a9b14092c68 100644 --- a/packages/nx/src/lock-file/lock-file.spec.ts +++ b/packages/nx/src/lock-file/lock-file.spec.ts @@ -214,7 +214,7 @@ describe('lock-file', () => { name: 'lib1', data: { root: 'libs/lib1', - }, + } as any, }; partialGraph.dependencies['lib1'] = [ { diff --git a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts index 563d9a19ff7c8..84349b5b0698a 100644 --- a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts +++ b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts @@ -2,8 +2,8 @@ import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/cre import type { Tree } from '../../generators/tree'; import removeDefaultCollection from './remove-default-collection'; import { - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + updateNxJson, } from '../../generators/utils/project-configuration'; describe('remove-default-collection', () => { @@ -14,38 +14,36 @@ describe('remove-default-collection', () => { }); it('should remove default collection from nx.json', async () => { - const config = readWorkspaceConfiguration(tree); + const config = readNxJson(tree); config.cli = { defaultCollection: 'default-collection', defaultProjectName: 'default-project', }; - updateWorkspaceConfiguration(tree, config); + updateNxJson(tree, config); await removeDefaultCollection(tree); - expect(readWorkspaceConfiguration(tree).cli).toEqual({ + expect(readNxJson(tree).cli).toEqual({ defaultProjectName: 'default-project', }); }); it('should remove cli entirely if defaultCollection was the only setting', async () => { - const config = readWorkspaceConfiguration(tree); + const config = readNxJson(tree); config.cli = { defaultCollection: 'default-collection', }; - updateWorkspaceConfiguration(tree, config); + updateNxJson(tree, config); await removeDefaultCollection(tree); - expect( - readWorkspaceConfiguration(tree).cli?.defaultCollection - ).toBeUndefined(); + expect(readNxJson(tree).cli?.defaultCollection).toBeUndefined(); }); it('should not error when "cli" is not defined', async () => { - const config = readWorkspaceConfiguration(tree); + const config = readNxJson(tree); delete config.cli; - updateWorkspaceConfiguration(tree, config); + updateNxJson(tree, config); await expect(removeDefaultCollection(tree)).resolves.not.toThrow(); }); diff --git a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts index 4f4208f8ecedf..465697c569dc6 100644 --- a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts +++ b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts @@ -1,22 +1,19 @@ import { Tree } from '../../generators/tree'; import { - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + updateNxJson, } from '../../generators/utils/project-configuration'; import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; export default async function (tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - delete workspaceConfiguration.cli?.defaultCollection; - if ( - workspaceConfiguration.cli && - Object.keys(workspaceConfiguration.cli).length === 0 - ) { - delete workspaceConfiguration.cli; + delete nxJson.cli?.defaultCollection; + if (nxJson.cli && Object.keys(nxJson.cli).length === 0) { + delete nxJson.cli; } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); await formatChangedFilesWithPrettierIfAvailable(tree); } diff --git a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts index c7b2e6bb68016..eabb03bc1a0e1 100644 --- a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts +++ b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts @@ -1,8 +1,8 @@ import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; import type { Tree } from '../../generators/tree'; import { - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + updateNxJson, } from '../../generators/utils/project-configuration'; import createTargetDefaults from './create-target-defaults'; @@ -14,8 +14,8 @@ describe('createTargetDefaults', () => { }); it('should work', async () => { - const config = readWorkspaceConfiguration(tree); - config.targetDependencies = { + const nxJson = readNxJson(tree); + nxJson.targetDependencies = { a: [], b: [ 'bb', @@ -23,10 +23,10 @@ describe('createTargetDefaults', () => { { target: 'c', projects: 'dependencies' }, ], }; - updateWorkspaceConfiguration(tree, config); + updateNxJson(tree, nxJson); await createTargetDefaults(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.targetDefaults).toEqual({ a: { dependsOn: [] }, b: { diff --git a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts index 5d5875e175b9b..8e530e21df3bc 100644 --- a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts +++ b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts @@ -1,21 +1,19 @@ import { Tree } from '../../generators/tree'; import { - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + updateNxJson, } from '../../generators/utils/project-configuration'; import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; export default async function (tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - if (workspaceConfiguration.targetDependencies) { - workspaceConfiguration.targetDefaults = {}; - for (const targetName of Object.keys( - workspaceConfiguration.targetDependencies - )) { + if (nxJson.targetDependencies) { + nxJson.targetDefaults = {}; + for (const targetName of Object.keys(nxJson.targetDependencies)) { const dependsOn = []; - for (const c of workspaceConfiguration.targetDependencies[targetName]) { + for (const c of nxJson.targetDependencies[targetName]) { if (typeof c === 'string') { dependsOn.push(c); } else if (c.projects === 'self') { @@ -25,13 +23,13 @@ export default async function (tree: Tree) { } } - workspaceConfiguration.targetDefaults[targetName] = { + nxJson.targetDefaults[targetName] = { dependsOn, }; } } - delete workspaceConfiguration.targetDependencies; - updateWorkspaceConfiguration(tree, workspaceConfiguration); + delete nxJson.targetDependencies; + updateNxJson(tree, nxJson); await formatChangedFilesWithPrettierIfAvailable(tree); } diff --git a/packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.spec.ts b/packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.spec.ts index c33b25236b546..aff54178668da 100644 --- a/packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.spec.ts +++ b/packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.spec.ts @@ -5,13 +5,13 @@ import { import type { Tree } from '../../generators/tree'; import { addProjectConfiguration, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, - WorkspaceConfiguration, + updateNxJson, } from '../../generators/utils/project-configuration'; import { readJson, writeJson } from '../../generators/utils/json'; import migrateToInputs from './migrate-to-inputs'; +import { NxJsonConfiguration } from 'nx/src/config/nx-json'; describe('15.0.0 migration (migrate-to-inputs)', () => { let tree: Tree; @@ -21,8 +21,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); it('should add build inputs configuration to inputs', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { targetDefaults: { build: { dependsOn: ['^build'], @@ -43,7 +42,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); await migrateToInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.implicitDependencies).toBeUndefined(); expect(updated).toMatchInlineSnapshot(` @@ -69,14 +68,12 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { ], }, }, - "version": 2, } `); }); it('should not add build inputs configuration to inputs', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { targetDefaults: { prepare: { dependsOn: ['^prepare'], @@ -97,7 +94,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); await migrateToInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.implicitDependencies).toBeUndefined(); expect(updated).toMatchInlineSnapshot(` @@ -119,21 +116,19 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { ], }, }, - "version": 2, } `); }); it('should add implicitDependencies that affect all projects to sharedGlobals', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { implicitDependencies: { Jenkinsfile: '*', }, }); await migrateToInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.implicitDependencies).toBeUndefined(); expect(updated.namedInputs.sharedGlobals).toContain( @@ -142,8 +137,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); it('should not add package.json to filesets', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { implicitDependencies: { 'package.json': { dependencies: '*', @@ -153,15 +147,14 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); await migrateToInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.implicitDependencies).toBeUndefined(); expect(updated.namedInputs.sharedGlobals).toEqual([]); }); it('should handle other .json files', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { implicitDependencies: { 'config.json': { important: '*', @@ -170,7 +163,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); await migrateToInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.implicitDependencies).toBeUndefined(); expect(updated.namedInputs.sharedGlobals).toContain( @@ -179,8 +172,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); it('should add project specific implicit dependencies to project namedInputs', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { implicitDependencies: { 'tools/scripts/build-app.js': ['app1', 'app2'], }, @@ -197,7 +189,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { await migrateToInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.implicitDependencies).toBeUndefined(); expect(updated.namedInputs.projectSpecificFiles).toEqual([]); expect(updated.namedInputs.default).toContain('projectSpecificFiles'); @@ -216,8 +208,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); it('should add project specific implicit dependencies to projects with package.json', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { implicitDependencies: { 'tools/scripts/build-app.js': ['app1', 'app2'], }, @@ -236,7 +227,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { await migrateToInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.implicitDependencies).toBeUndefined(); expect(updated.namedInputs.projectSpecificFiles).toEqual([]); expect(updated.namedInputs.default).toContain('projectSpecificFiles'); @@ -255,8 +246,7 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); it('should do nothing if there are no implicitDependencies', async () => { - const workspace: WorkspaceConfiguration = { - version: 2, + const nxJson: NxJsonConfiguration = { namedInputs: { default: ['{projectRoot}/**/*'], production: ['default'], @@ -269,13 +259,13 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }, }, }; - updateWorkspaceConfiguration(tree, workspace); + updateNxJson(tree, nxJson); await migrateToInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.implicitDependencies).toBeUndefined(); - expect(updated).toEqual(workspace); + expect(updated).toEqual(nxJson); }); it('should not make any changes if there is no nx.json', async () => { @@ -287,13 +277,13 @@ describe('15.0.0 migration (migrate-to-inputs)', () => { }); it('should not make any changes if the workspace extends npm.json', async () => { - const workspace = readWorkspaceConfiguration(tree); + const workspace = readNxJson(tree); workspace.extends = 'nx/presets/npm.json'; - updateWorkspaceConfiguration(tree, workspace); + updateNxJson(tree, workspace); await migrateToInputs(tree); - const updatedWorkspace = readWorkspaceConfiguration(tree); + const updatedWorkspace = readNxJson(tree); expect(updatedWorkspace.namedInputs).not.toBeDefined(); }); }); @@ -306,8 +296,7 @@ describe('15.0.0 migration (migrate-to-inputs) (v1)', () => { }); it('should add project specific implicit dependencies to project namedInputs', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { implicitDependencies: { 'tools/scripts/build-app.js': ['app1', 'app2'], }, @@ -324,7 +313,7 @@ describe('15.0.0 migration (migrate-to-inputs) (v1)', () => { await migrateToInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.implicitDependencies).toBeUndefined(); expect(updated.namedInputs.projectSpecificFiles).toEqual([]); expect(updated.namedInputs.default).toContain('projectSpecificFiles'); diff --git a/packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.ts b/packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.ts index 604fe569e9693..0b96fa7597a26 100644 --- a/packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.ts +++ b/packages/nx/src/migrations/update-15-0-0/migrate-to-inputs.ts @@ -2,9 +2,9 @@ import { Tree } from '../../generators/tree'; import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; import { getProjects, - readWorkspaceConfiguration, + readNxJson, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, } from '../../generators/utils/project-configuration'; import { joinPathFragments } from '../../utils/path'; import { join } from 'path'; @@ -28,47 +28,41 @@ export default async function (tree: Tree) { return; } - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); // If this is a npm workspace, don't make any changes - if (workspaceConfiguration.extends === 'nx/presets/npm.json') { + if (nxJson.extends === 'nx/presets/npm.json') { return; } - workspaceConfiguration.namedInputs ??= { + nxJson.namedInputs ??= { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], production: ['default'], }; if (isBuildATarget(tree)) { - workspaceConfiguration.targetDefaults ??= {}; - workspaceConfiguration.targetDefaults.build ??= {}; - workspaceConfiguration.targetDefaults.build.inputs ??= [ - 'production', - '^production', - ]; + nxJson.targetDefaults ??= {}; + nxJson.targetDefaults.build ??= {}; + nxJson.targetDefaults.build.inputs ??= ['production', '^production']; } - if (workspaceConfiguration.implicitDependencies) { + if (nxJson.implicitDependencies) { const projects = getProjects(tree); for (const [files, dependents] of Object.entries( - workspaceConfiguration.implicitDependencies + nxJson.implicitDependencies )) { // Skip these because other plugins take care of them if (skippedFiles.includes(files)) { continue; } else if (Array.isArray(dependents)) { - workspaceConfiguration.namedInputs.projectSpecificFiles = []; + nxJson.namedInputs.projectSpecificFiles = []; const defaultFileset = new Set( - workspaceConfiguration.namedInputs.default ?? [ - '{projectRoot}/**/*', - 'sharedGlobals', - ] + nxJson.namedInputs.default ?? ['{projectRoot}/**/*', 'sharedGlobals'] ); defaultFileset.add('projectSpecificFiles'); - workspaceConfiguration.namedInputs.default = Array.from(defaultFileset); + nxJson.namedInputs.default = Array.from(defaultFileset); for (const dependent of dependents) { const project = projects.get(dependent); @@ -103,15 +97,15 @@ export default async function (tree: Tree) { } } } else { - workspaceConfiguration.namedInputs.sharedGlobals.push( + nxJson.namedInputs.sharedGlobals.push( joinPathFragments('{workspaceRoot}', files) ); } } - delete workspaceConfiguration.implicitDependencies; + delete nxJson.implicitDependencies; } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); await formatChangedFilesWithPrettierIfAvailable(tree); } diff --git a/packages/nx/src/migrations/update-15-0-0/prefix-outputs.spec.ts b/packages/nx/src/migrations/update-15-0-0/prefix-outputs.spec.ts index aa3a8c26b17e7..14f50338c9483 100644 --- a/packages/nx/src/migrations/update-15-0-0/prefix-outputs.spec.ts +++ b/packages/nx/src/migrations/update-15-0-0/prefix-outputs.spec.ts @@ -5,9 +5,9 @@ import { import type { Tree } from '../../generators/tree'; import { addProjectConfiguration, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + updateNxJson, } from '../../generators/utils/project-configuration'; import { readJson, writeJson } from '../../generators/utils/json'; import prefixOutputs from './prefix-outputs'; @@ -58,9 +58,9 @@ describe('15.0.0 migration (prefix-outputs)', () => { }); it('should prefix target default outputs', async () => { - const workspace = readWorkspaceConfiguration(tree); - updateWorkspaceConfiguration(tree, { - ...workspace, + const nxJson = readNxJson(tree); + updateNxJson(tree, { + ...nxJson, targetDefaults: { build: { outputs: ['dist', '{projectRoot}/build', '{options.outputPath}'], @@ -70,7 +70,7 @@ describe('15.0.0 migration (prefix-outputs)', () => { await prefixOutputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated.targetDefaults).toMatchInlineSnapshot(` Object { diff --git a/packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts b/packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts index 06178ef937e68..af3da26e6a51f 100644 --- a/packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts +++ b/packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts @@ -2,12 +2,12 @@ import { Tree } from '../../generators/tree'; import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; import { getProjects, - readWorkspaceConfiguration, + readNxJson, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, } from '../../generators/utils/project-configuration'; import { joinPathFragments } from '../../utils/path'; -import { join, relative } from 'path'; +import { join } from 'path'; import { transformLegacyOutputs, validateOutputs, @@ -21,7 +21,7 @@ export default async function (tree: Tree) { return; } - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); for (const [projectName, project] of getProjects(tree)) { if (!project.targets) { @@ -57,10 +57,8 @@ export default async function (tree: Tree) { } } - if (workspaceConfiguration.targetDefaults) { - for (const [_, target] of Object.entries( - workspaceConfiguration.targetDefaults - )) { + if (nxJson.targetDefaults) { + for (const [_, target] of Object.entries(nxJson.targetDefaults)) { if (!target.outputs) { continue; } @@ -72,7 +70,7 @@ export default async function (tree: Tree) { }); } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } await formatChangedFilesWithPrettierIfAvailable(tree); diff --git a/packages/nx/src/project-graph/affected/affected-project-graph-models.ts b/packages/nx/src/project-graph/affected/affected-project-graph-models.ts index 6976ecacc182c..073dc3d74ad83 100644 --- a/packages/nx/src/project-graph/affected/affected-project-graph-models.ts +++ b/packages/nx/src/project-graph/affected/affected-project-graph-models.ts @@ -7,10 +7,7 @@ import { import { ProjectConfiguration } from '../../config/workspace-json-project-json'; export interface AffectedProjectGraphContext { - projectGraphNodes: Record< - string, - ProjectGraphProjectNode - >; + projectGraphNodes: Record; nxJson: NxJsonConfiguration; touchedProjects: string[]; } @@ -18,10 +15,7 @@ export interface AffectedProjectGraphContext { export interface TouchedProjectLocator { ( fileChanges: FileChange[], - projectGraphNodes?: Record< - string, - ProjectGraphProjectNode - >, + projectGraphNodes?: Record, nxJson?: NxJsonConfiguration, packageJson?: any, projectGraph?: ProjectGraph diff --git a/packages/nx/src/project-graph/affected/affected-project-graph.spec.ts b/packages/nx/src/project-graph/affected/affected-project-graph.spec.ts index 887825b72e71e..e6708147d4a2e 100644 --- a/packages/nx/src/project-graph/affected/affected-project-graph.spec.ts +++ b/packages/nx/src/project-graph/affected/affected-project-graph.spec.ts @@ -16,7 +16,7 @@ jest.mock('nx/src/utils/workspace-root', () => ({ describe('project graph', () => { let packageJson: any; let packageLockJson: any; - let workspaceJson: ProjectsConfigurations; + let projects: ProjectsConfigurations; let tsConfigJson: any; let nxJson: NxJsonConfiguration; let filesJson: any; @@ -73,7 +73,7 @@ describe('project graph', () => { }, }, }; - workspaceJson = { + projects = { version: 2, projects: { demo: { @@ -151,7 +151,7 @@ describe('project graph', () => { './package.json': JSON.stringify(packageJson), './package-lock.json': JSON.stringify(packageLockJson), './nx.json': JSON.stringify(nxJson), - './workspace.json': JSON.stringify(workspaceJson), + './workspace.json': JSON.stringify(projects), './tsconfig.base.json': JSON.stringify(tsConfigJson), }; vol.fromJSON(filesJson, '/root'); diff --git a/packages/nx/src/project-graph/affected/affected-project-graph.ts b/packages/nx/src/project-graph/affected/affected-project-graph.ts index 63b3f20eaf123..6173061e65f59 100644 --- a/packages/nx/src/project-graph/affected/affected-project-graph.ts +++ b/packages/nx/src/project-graph/affected/affected-project-graph.ts @@ -21,7 +21,7 @@ import { getTouchedProjectsFromProjectGlobChanges } from './locators/project-glo import { workspaceRoot } from '../../utils/workspace-root'; export function filterAffected( - graph: ProjectGraph, + graph: ProjectGraph, touchedFiles: FileChange[], nxJson: NxJsonConfiguration = readNxJson(), packageJson: any = readPackageJson() diff --git a/packages/nx/src/project-graph/affected/locators/npm-packages.spec.ts b/packages/nx/src/project-graph/affected/locators/npm-packages.spec.ts index 7cba1534baa00..2cbec17014279 100644 --- a/packages/nx/src/project-graph/affected/locators/npm-packages.spec.ts +++ b/packages/nx/src/project-graph/affected/locators/npm-packages.spec.ts @@ -34,14 +34,14 @@ describe('getTouchedNpmPackages', () => { name: 'proj1', data: { files: [], - }, + } as any, }, proj2: { type: 'lib', name: 'proj2', data: { files: [], - }, + } as any, }, }, externalNodes: { @@ -297,7 +297,7 @@ describe('getTouchedNpmPackages', () => { 'any-random-name': { name: 'changed-test-pkg-name-1', type: 'lib', - data: {}, + data: {} as any, }, }, } diff --git a/packages/nx/src/project-graph/affected/locators/project-glob-changes.spec.ts b/packages/nx/src/project-graph/affected/locators/project-glob-changes.spec.ts index a9b977469712b..a4ac9c54df2c9 100644 --- a/packages/nx/src/project-graph/affected/locators/project-glob-changes.spec.ts +++ b/packages/nx/src/project-graph/affected/locators/project-glob-changes.spec.ts @@ -8,7 +8,7 @@ import { getTouchedProjectsFromProjectGlobChanges } from './project-glob-changes function makeProjectGraphNode( name, configurationFile = 'project.json' -): ProjectGraphProjectNode { +): ProjectGraphProjectNode { return { data: { files: [ diff --git a/packages/nx/src/project-graph/affected/locators/workspace-projects.spec.ts b/packages/nx/src/project-graph/affected/locators/workspace-projects.spec.ts index 3e6e2c82b1da9..359ae7cf0fe4f 100644 --- a/packages/nx/src/project-graph/affected/locators/workspace-projects.spec.ts +++ b/packages/nx/src/project-graph/affected/locators/workspace-projects.spec.ts @@ -202,7 +202,7 @@ describe('extractGlobalFilesFromInputs', () => { }, }, }, - }, + } as any, } ); expect(globalFiles).toEqual(['global1.txt', 'global2.txt', 'global3.txt']); @@ -217,7 +217,7 @@ function buildProjectGraphNodes( ([name, config]): [string, ProjectGraphProjectNode] => [ name, { - data: config, + data: config as any, name, type: config.projectType === 'application' ? 'app' : 'lib', }, diff --git a/packages/nx/src/project-graph/build-dependencies/explicit-project-dependencies.spec.ts b/packages/nx/src/project-graph/build-dependencies/explicit-project-dependencies.spec.ts index c57f57caa1204..5e477d77a7ad8 100644 --- a/packages/nx/src/project-graph/build-dependencies/explicit-project-dependencies.spec.ts +++ b/packages/nx/src/project-graph/build-dependencies/explicit-project-dependencies.spec.ts @@ -603,7 +603,7 @@ function createVirtualWorkspace(config: VirtualWorkspaceConfig) { files: config.sourceProjectFiles.map(({ path }) => ({ file: path, })), - }, + } as any, }); builder.addExternalNode({ name: 'npm:npm-package', @@ -629,7 +629,7 @@ function createVirtualWorkspace(config: VirtualWorkspaceConfig) { type: 'lib', data: { root: `libs/${projectName}`, - files: [{ file: `libs/${projectName}/index.ts` }], + files: [{ file: `libs/${projectName}/index.ts` }] as any, }, }); } diff --git a/packages/nx/src/project-graph/build-project-graph.spec.ts b/packages/nx/src/project-graph/build-project-graph.spec.ts index 9a78cda658656..a385c96469622 100644 --- a/packages/nx/src/project-graph/build-project-graph.spec.ts +++ b/packages/nx/src/project-graph/build-project-graph.spec.ts @@ -14,7 +14,7 @@ import { DependencyType } from '../config/project-graph'; describe('project graph', () => { let packageJson: any; let packageLockJson: any; - let workspaceJson: ProjectsConfigurations; + let projects: ProjectsConfigurations; let nxJson: NxJsonConfiguration; let tsConfigJson: any; let filesJson: any; @@ -82,7 +82,7 @@ describe('project graph', () => { }, }, }; - workspaceJson = { + projects = { version: 2, projects: { demo: { @@ -179,7 +179,7 @@ describe('project graph', () => { './package.json': JSON.stringify(packageJson), './package-lock.json': JSON.stringify(packageLockJson), './nx.json': JSON.stringify(nxJson), - './workspace.json': JSON.stringify(workspaceJson), + './workspace.json': JSON.stringify(projects), './tsconfig.base.json': JSON.stringify(tsConfigJson), }; vol.reset(); @@ -264,8 +264,8 @@ describe('project graph', () => { expect(graph.nodes).toMatchObject({ demo: { name: 'demo', type: 'app' }, }); - workspaceJson.projects.renamed = workspaceJson.projects.demo; - fs.writeFileSync('/root/workspace.json', JSON.stringify(workspaceJson)); + projects.projects.renamed = projects.projects.demo; + fs.writeFileSync('/root/workspace.json', JSON.stringify(projects)); graph = await buildProjectGraph(); expect(graph.nodes).toMatchObject({ diff --git a/packages/nx/src/project-graph/build-project-graph.ts b/packages/nx/src/project-graph/build-project-graph.ts index 52083f64c6c6e..f96ae2d293c6f 100644 --- a/packages/nx/src/project-graph/build-project-graph.ts +++ b/packages/nx/src/project-graph/build-project-graph.ts @@ -35,19 +35,19 @@ import { ProjectConfiguration, ProjectsConfigurations, } from '../config/workspace-json-project-json'; -import { - readAllWorkspaceConfiguration, - readNxJson, -} from '../config/configuration'; +import { readNxJson } from '../config/configuration'; import { lockFileExists, lockFileHash, mapLockFileDataToPartialGraph, parseLockFile, } from '../lock-file/lock-file'; +import { Workspaces } from '../config/workspaces'; export async function buildProjectGraph() { - const projectConfigurations = readAllWorkspaceConfiguration(); + const projectConfigurations = new Workspaces( + workspaceRoot + ).readProjectsConfig(); const { projectFileMap, allWorkspaceFiles } = createProjectFileMap( projectConfigurations, defaultFileHasher.allFileData() diff --git a/packages/nx/src/project-graph/file-utils.ts b/packages/nx/src/project-graph/file-utils.ts index b4f2bc1e00d26..8bf0e7710bc76 100644 --- a/packages/nx/src/project-graph/file-utils.ts +++ b/packages/nx/src/project-graph/file-utils.ts @@ -134,8 +134,8 @@ function defaultReadFileAtRevision( export function readWorkspaceConfig(opts: { format: 'angularCli' | 'nx'; path?: string; -}): ProjectsConfigurations & NxJsonConfiguration { - let configuration: (ProjectsConfigurations & NxJsonConfiguration) | null; +}): ProjectsConfigurations { + let configuration: ProjectsConfigurations | null = null; try { const projectGraph = readCachedProjectGraph(); configuration = { @@ -144,7 +144,7 @@ export function readWorkspaceConfig(opts: { }; } catch { const ws = new Workspaces(opts.path || process.cwd()); - configuration = ws.readWorkspaceConfiguration(); + configuration = ws.readProjectsConfig(); } if (opts.format === 'angularCli') { const formatted = toOldFormatOrNull(configuration); diff --git a/packages/nx/src/project-graph/nx-deps-cache.ts b/packages/nx/src/project-graph/nx-deps-cache.ts index 985147afed085..dd8389bde5551 100644 --- a/packages/nx/src/project-graph/nx-deps-cache.ts +++ b/packages/nx/src/project-graph/nx-deps-cache.ts @@ -145,7 +145,7 @@ export function writeCache(cache: ProjectGraphCache): void { export function shouldRecomputeWholeGraph( cache: ProjectGraphCache, packageJsonDeps: Record, - workspaceJson: ProjectsConfigurations, + projects: ProjectsConfigurations, nxJson: NxJsonConfiguration, tsConfig: { compilerOptions: { paths: { [k: string]: any } } } ): boolean { @@ -166,7 +166,7 @@ export function shouldRecomputeWholeGraph( (cache.nodes[p].type === 'app' || cache.nodes[p].type === 'lib' || cache.nodes[p].type === 'e2e') && - !workspaceJson.projects[p] + !projects.projects[p] ) ) { return true; @@ -252,7 +252,7 @@ function processProjectNode( } const fileDataFromCache = {} as any; - for (let f of cachedNode.data.files) { + for (let f of (cachedNode.data as any).files) { fileDataFromCache[f.file] = f; } diff --git a/packages/nx/src/project-graph/project-graph-builder.spec.ts b/packages/nx/src/project-graph/project-graph-builder.spec.ts index c86dce4c11863..1348b3355cc3d 100644 --- a/packages/nx/src/project-graph/project-graph-builder.spec.ts +++ b/packages/nx/src/project-graph/project-graph-builder.spec.ts @@ -16,12 +16,12 @@ describe('ProjectGraphBuilder', () => { file: 'source/second.ts', }, ], - }, + } as any, }); builder.addNode({ name: 'target', type: 'lib', - data: {}, + data: {} as any, }); }); @@ -118,7 +118,7 @@ describe('ProjectGraphBuilder', () => { builder.addNode({ name: 'target2', type: 'lib', - data: {}, + data: {} as any, }); builder.addImplicitDependency('source', 'target'); builder.addExplicitDependency('source', 'source/index.ts', 'target'); diff --git a/packages/nx/src/project-graph/project-graph.ts b/packages/nx/src/project-graph/project-graph.ts index 67c59601b4b5b..035fff60c6f00 100644 --- a/packages/nx/src/project-graph/project-graph.ts +++ b/packages/nx/src/project-graph/project-graph.ts @@ -16,7 +16,7 @@ import { daemonClient } from '../daemon/client/client'; * Synchronously reads the latest cached copy of the workspace's ProjectGraph. * @throws {Error} if there is no cached ProjectGraph to read from */ -export function readCachedProjectGraph(): ProjectGraph { +export function readCachedProjectGraph(): ProjectGraph { const projectGraphCache: ProjectGraphCache | false = readCache(); const angularSpecificError = workspaceFileName() === 'angular.json' @@ -61,7 +61,7 @@ export function readCachedProjectConfiguration( } export function readProjectsConfigurationFromProjectGraph( - projectGraph: ProjectGraph + projectGraph: ProjectGraph ): ProjectsConfigurations { return { projects: Object.fromEntries( diff --git a/packages/nx/src/project-graph/utils/find-project-for-path.spec.ts b/packages/nx/src/project-graph/utils/find-project-for-path.spec.ts index b52879e2ca6d2..c23919990b097 100644 --- a/packages/nx/src/project-graph/utils/find-project-for-path.spec.ts +++ b/packages/nx/src/project-graph/utils/find-project-for-path.spec.ts @@ -43,7 +43,7 @@ describe('get project utils', () => { type: 'lib', data: {}, }, - }, + } as any, dependencies: { 'demo-app': [ { diff --git a/packages/nx/src/tasks-runner/batch/run-batch.ts b/packages/nx/src/tasks-runner/batch/run-batch.ts index 77bdcc042cf95..8489699db23c9 100644 --- a/packages/nx/src/tasks-runner/batch/run-batch.ts +++ b/packages/nx/src/tasks-runner/batch/run-batch.ts @@ -12,6 +12,7 @@ import { createProjectGraphAsync, readProjectsConfigurationFromProjectGraph, } from '../../project-graph/project-graph'; +import { readNxJson } from '../../config/configuration'; function getBatchExecutor(executorName: string) { const workspace = new Workspaces(workspaceRoot); @@ -22,19 +23,23 @@ function getBatchExecutor(executorName: string) { async function runTasks(executorName: string, taskGraph: TaskGraph) { const input: Record = {}; const projectGraph = await createProjectGraphAsync(); - const workspaceConfig = + const projectsConfigurations = readProjectsConfigurationFromProjectGraph(projectGraph); + const nxJsonConfiguration = readNxJson(); const batchExecutor = getBatchExecutor(executorName); const tasks = Object.values(taskGraph.tasks); const context: ExecutorContext = { root: workspaceRoot, cwd: process.cwd(), - workspace: workspaceConfig, + projectsConfigurations, + nxJsonConfiguration, + workspace: { ...projectsConfigurations, ...nxJsonConfiguration }, isVerbose: false, projectGraph, }; for (const task of tasks) { - const projectConfiguration = workspaceConfig.projects[task.target.project]; + const projectConfiguration = + projectsConfigurations.projects[task.target.project]; const targetConfiguration = projectConfiguration.targets[task.target.target]; input[task.id] = combineOptionsForExecutor( diff --git a/packages/nx/src/tasks-runner/tasks-schedule.spec.ts b/packages/nx/src/tasks-runner/tasks-schedule.spec.ts index 6345dd832c925..c7c6f27b0cee5 100644 --- a/packages/nx/src/tasks-runner/tasks-schedule.spec.ts +++ b/packages/nx/src/tasks-runner/tasks-schedule.spec.ts @@ -96,7 +96,7 @@ describe('TasksSchedule', () => { }, }, }, - }, + } as any, dependencies: { app1: [ { @@ -323,7 +323,7 @@ describe('TasksSchedule', () => { }, }, }, - }, + } as any, dependencies: { app1: [ { diff --git a/packages/nx/src/utils/nx-plugin.ts b/packages/nx/src/utils/nx-plugin.ts index 153e752f49782..eb54a69a88211 100644 --- a/packages/nx/src/utils/nx-plugin.ts +++ b/packages/nx/src/utils/nx-plugin.ts @@ -173,7 +173,7 @@ function registerTSTranspiler() { } function lookupLocalPlugin(importPath: string, root = workspaceRoot) { - const workspace = new Workspaces(root).readWorkspaceConfiguration({ + const workspace = new Workspaces(root).readProjectsConfig({ _ignorePluginInference: true, }); const plugin = findNxProjectForImportPath(importPath, workspace, root); @@ -191,7 +191,7 @@ function lookupLocalPlugin(importPath: string, root = workspaceRoot) { function findNxProjectForImportPath( importPath: string, - workspace: ProjectsConfigurations, + projects: ProjectsConfigurations, root = workspaceRoot ): string | null { const tsConfigPaths: Record = readTsConfigPaths(root); @@ -200,7 +200,7 @@ function findNxProjectForImportPath( ); if (possiblePaths?.length) { const projectRootMappings = - createProjectRootMappingsFromProjectConfigurations(workspace.projects); + createProjectRootMappingsFromProjectConfigurations(projects.projects); for (const tsConfigPath of possiblePaths) { const nxProject = findProjectForPath(tsConfigPath, projectRootMappings); if (nxProject) { diff --git a/packages/nx/src/utils/params.ts b/packages/nx/src/utils/params.ts index 431107d23dfae..40c688cbc5973 100644 --- a/packages/nx/src/utils/params.ts +++ b/packages/nx/src/utils/params.ts @@ -600,17 +600,19 @@ export async function combineOptionsForGenerator( commandLineOpts: Options, collectionName: string, generatorName: string, - wc: (ProjectsConfigurations & NxJsonConfiguration) | null, + projectsConfigurations: ProjectsConfigurations, + nxJsonConfiguration: NxJsonConfiguration, schema: Schema, isInteractive: boolean, defaultProjectName: string | null, relativeCwd: string | null, isVerbose = false ) { - const generatorDefaults = wc + const generatorDefaults = projectsConfigurations ? getGeneratorDefaults( defaultProjectName, - wc, + projectsConfigurations, + nxJsonConfiguration, collectionName, generatorName ) @@ -628,7 +630,7 @@ export async function combineOptionsForGenerator( ); if (isInteractive && isTTY()) { - combined = await promptForValues(combined, schema, wc); + combined = await promptForValues(combined, schema, projectsConfigurations); } warnDeprecations(combined, schema); @@ -706,27 +708,31 @@ export function convertSmartDefaultsIntoNamedParams( function getGeneratorDefaults( projectName: string | null, - wc: (ProjectsConfigurations & NxJsonConfiguration) | null, + projectsConfigurations: ProjectsConfigurations, + nxJsonConfiguration: NxJsonConfiguration, collectionName: string, generatorName: string ) { let defaults = {}; - if (wc?.generators) { - if (wc.generators[collectionName]?.[generatorName]) { + if (nxJsonConfiguration?.generators) { + if (nxJsonConfiguration.generators[collectionName]?.[generatorName]) { defaults = { ...defaults, - ...wc.generators[collectionName][generatorName], + ...nxJsonConfiguration.generators[collectionName][generatorName], }; } - if (wc.generators[`${collectionName}:${generatorName}`]) { + if (nxJsonConfiguration.generators[`${collectionName}:${generatorName}`]) { defaults = { ...defaults, - ...wc.generators[`${collectionName}:${generatorName}`], + ...nxJsonConfiguration.generators[`${collectionName}:${generatorName}`], }; } } - if (projectName && wc?.projects[projectName]?.generators) { - const g = wc.projects[projectName].generators; + if ( + projectName && + projectsConfigurations?.projects[projectName]?.generators + ) { + const g = projectsConfigurations.projects[projectName].generators; if (g[collectionName] && g[collectionName][generatorName]) { defaults = { ...defaults, ...g[collectionName][generatorName] }; } @@ -751,7 +757,7 @@ interface Prompt { export function getPromptsForSchema( opts: Options, schema: Schema, - wc: (ProjectsConfigurations & NxJsonConfiguration) | null + projectsConfigurations: ProjectsConfigurations ): Prompt[] { const prompts: Prompt[] = []; Object.entries(schema.properties).forEach(([k, v]) => { @@ -784,10 +790,10 @@ export function getPromptsForSchema( k === 'project' || k === 'projectName' || v['x-dropdown'] === 'projects') && - wc + projectsConfigurations ) { question.type = 'autocomplete'; - question.choices = Object.keys(wc.projects); + question.choices = Object.keys(projectsConfigurations.projects); } else if (v.type === 'number' || v['x-prompt'].type == 'number') { question.message = v['x-prompt'].message; question.type = 'numeral'; @@ -829,12 +835,12 @@ export function getPromptsForSchema( async function promptForValues( opts: Options, schema: Schema, - wc: (ProjectsConfigurations & NxJsonConfiguration) | null + projectsConfigurations: ProjectsConfigurations ) { return await ( await import('enquirer') ) - .prompt(getPromptsForSchema(opts, schema, wc)) + .prompt(getPromptsForSchema(opts, schema, projectsConfigurations)) .then((values) => ({ ...opts, ...values })) .catch((e) => { console.error(e); diff --git a/packages/nx/src/utils/project-graph-utils.spec.ts b/packages/nx/src/utils/project-graph-utils.spec.ts index 5a29ca13173cf..2a0d2a45e0dcd 100644 --- a/packages/nx/src/utils/project-graph-utils.spec.ts +++ b/packages/nx/src/utils/project-graph-utils.spec.ts @@ -73,7 +73,7 @@ describe('project graph utils', () => { }, ], }, - }; + } as any; it('should correctly gather the source root dirs of the dependent projects', () => { const [paths] = getSourceDirOfDependentProjects('demo-app', projGraph); diff --git a/packages/nx/src/utils/split-target.ts b/packages/nx/src/utils/split-target.ts index e692a9488ae1f..1c10e4e39409a 100644 --- a/packages/nx/src/utils/split-target.ts +++ b/packages/nx/src/utils/split-target.ts @@ -3,7 +3,7 @@ import { ProjectConfiguration } from '../config/workspace-json-project-json'; export function splitTarget( s: string, - projectGraph: ProjectGraph + projectGraph: ProjectGraph ): [project: string, target?: string, configuration?: string] { let [project, ...segments] = splitByColons(s); const validTargets = projectGraph.nodes[project]?.data?.targets; diff --git a/packages/react-native/src/executors/build-android/build-android.impl.ts b/packages/react-native/src/executors/build-android/build-android.impl.ts index 3cb9454aca269..9895cf9f99544 100644 --- a/packages/react-native/src/executors/build-android/build-android.impl.ts +++ b/packages/react-native/src/executors/build-android/build-android.impl.ts @@ -14,7 +14,8 @@ export default async function* buildAndroidExecutor( options: ReactNativeBuildOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); chmodSync(join(projectRoot, 'android', 'gradlew'), 0o775); chmodSync(join(projectRoot, 'android', 'gradlew.bat'), 0o775); diff --git a/packages/react-native/src/executors/bundle/bundle.impl.ts b/packages/react-native/src/executors/bundle/bundle.impl.ts index 8b5023a1bde76..a097cab59447a 100644 --- a/packages/react-native/src/executors/bundle/bundle.impl.ts +++ b/packages/react-native/src/executors/bundle/bundle.impl.ts @@ -17,7 +17,8 @@ export default async function* bundleExecutor( options: ReactNativeBundleOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; options.bundleOutput = join(context.root, options.bundleOutput); diff --git a/packages/react-native/src/executors/ensure-symlink/ensure-symlink.impl.ts b/packages/react-native/src/executors/ensure-symlink/ensure-symlink.impl.ts index b07fce099eae2..f7cb5b6675753 100644 --- a/packages/react-native/src/executors/ensure-symlink/ensure-symlink.impl.ts +++ b/packages/react-native/src/executors/ensure-symlink/ensure-symlink.impl.ts @@ -9,7 +9,8 @@ export default async function* ensureSymlinkExecutor( _, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); diff --git a/packages/react-native/src/executors/run-android/run-android.impl.ts b/packages/react-native/src/executors/run-android/run-android.impl.ts index 1bfe4113b3327..e360a10483122 100644 --- a/packages/react-native/src/executors/run-android/run-android.impl.ts +++ b/packages/react-native/src/executors/run-android/run-android.impl.ts @@ -21,7 +21,8 @@ export default async function* runAndroidExecutor( options: ReactNativeRunAndroidOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); chmodSync(join(context.root, projectRoot, 'android', 'gradlew'), 0o775); chmodSync(join(context.root, projectRoot, 'android', 'gradlew.bat'), 0o775); diff --git a/packages/react-native/src/executors/run-ios/run-ios.impl.ts b/packages/react-native/src/executors/run-ios/run-ios.impl.ts index 268ad273fc980..9543f7dab4205 100644 --- a/packages/react-native/src/executors/run-ios/run-ios.impl.ts +++ b/packages/react-native/src/executors/run-ios/run-ios.impl.ts @@ -25,7 +25,8 @@ export default async function* runIosExecutor( if (platform() !== 'darwin') { throw new Error(`The run-ios build requires Mac to run`); } - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); if (options.sync) { displayNewlyAddedDepsMessage( diff --git a/packages/react-native/src/executors/start/start.impl.ts b/packages/react-native/src/executors/start/start.impl.ts index 8004423ec411f..6b80d5132cd91 100644 --- a/packages/react-native/src/executors/start/start.impl.ts +++ b/packages/react-native/src/executors/start/start.impl.ts @@ -17,7 +17,8 @@ export default async function* startExecutor( options: ReactNativeStartOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; ensureNodeModulesSymlink(context.root, projectRoot); try { diff --git a/packages/react-native/src/executors/storybook/storybook.impl.ts b/packages/react-native/src/executors/storybook/storybook.impl.ts index 2e5c5467f0929..475cf7989b159 100644 --- a/packages/react-native/src/executors/storybook/storybook.impl.ts +++ b/packages/react-native/src/executors/storybook/storybook.impl.ts @@ -16,7 +16,8 @@ export default async function* reactNatievStorybookExecutor( options: ReactNativeStorybookOptions, context: ExecutorContext ): AsyncGenerator<{ success: boolean }> { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; logger.info( `${chalk.bold.cyan( 'info' diff --git a/packages/react-native/src/executors/sync-deps/sync-deps.impl.ts b/packages/react-native/src/executors/sync-deps/sync-deps.impl.ts index 45cc9f3e20933..2eb1e3284a641 100644 --- a/packages/react-native/src/executors/sync-deps/sync-deps.impl.ts +++ b/packages/react-native/src/executors/sync-deps/sync-deps.impl.ts @@ -20,7 +20,8 @@ export default async function* syncDepsExecutor( options: ReactNativeSyncDepsOptions, context: ExecutorContext ): AsyncGenerator { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; displayNewlyAddedDepsMessage( context.projectName, await syncDeps( diff --git a/packages/react-native/src/generators/application/application.spec.ts b/packages/react-native/src/generators/application/application.spec.ts index 765b5080a8cd5..e52938ae156bf 100644 --- a/packages/react-native/src/generators/application/application.spec.ts +++ b/packages/react-native/src/generators/application/application.spec.ts @@ -1,6 +1,5 @@ import { Tree, - readWorkspaceConfiguration, getProjects, readJson, readProjectConfiguration, diff --git a/packages/react-native/src/generators/application/lib/add-project.ts b/packages/react-native/src/generators/application/lib/add-project.ts index 9dda02b76d804..52aaffdcf282e 100644 --- a/packages/react-native/src/generators/application/lib/add-project.ts +++ b/packages/react-native/src/generators/application/lib/add-project.ts @@ -1,10 +1,8 @@ import { addProjectConfiguration, ProjectConfiguration, - readWorkspaceConfiguration, TargetConfiguration, Tree, - updateWorkspaceConfiguration, } from '@nrwl/devkit'; import { NormalizedSchema } from './normalize-options'; diff --git a/packages/react-native/src/migrations/update-15-0-0/add-babel-inputs.spec.ts b/packages/react-native/src/migrations/update-15-0-0/add-babel-inputs.spec.ts index 081587e0b6d95..f6a2b99045729 100644 --- a/packages/react-native/src/migrations/update-15-0-0/add-babel-inputs.spec.ts +++ b/packages/react-native/src/migrations/update-15-0-0/add-babel-inputs.spec.ts @@ -1,9 +1,5 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { - Tree, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { Tree, readNxJson, updateNxJson } from '@nrwl/devkit'; import addBabelInputs from './add-babel-inputs'; describe('15.0.0 migration (add-babel-inputs)', () => { @@ -14,8 +10,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { }); it('should add babel.config.json to sharedGlobals', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -26,7 +21,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { await addBabelInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -41,14 +36,12 @@ describe('15.0.0 migration (add-babel-inputs)', () => { "{workspaceRoot}/babel.config.json", ], }, - "version": 2, } `); }); it('should add babel.config.js', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -59,7 +52,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { await addBabelInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -74,7 +67,6 @@ describe('15.0.0 migration (add-babel-inputs)', () => { "{workspaceRoot}/babel.config.js", ], }, - "version": 2, } `); }); diff --git a/packages/react-native/src/utils/find-all-npm-dependencies.spec.ts b/packages/react-native/src/utils/find-all-npm-dependencies.spec.ts index 440a43d405a84..41ab0b2c1a46e 100644 --- a/packages/react-native/src/utils/find-all-npm-dependencies.spec.ts +++ b/packages/react-native/src/utils/find-all-npm-dependencies.spec.ts @@ -24,7 +24,7 @@ test('findAllNpmDependencies', () => { name: 'lib3', data: { files: [] }, }, - }, + } as any, externalNodes: { 'npm:react-native-image-picker': { type: 'npm', diff --git a/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts b/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts index 563ea964f93a3..92142f0ecf50f 100644 --- a/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts +++ b/packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts @@ -18,7 +18,7 @@ export default async function* moduleFederationDevServer( context: ExecutorContext ) { let iter = devServerExecutor(options, context); - const p = context.workspace.projects[context.projectName]; + const p = context.projectsConfigurations.projects[context.projectName]; const moduleFederationConfigPath = join( context.root, diff --git a/packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts b/packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts index 9b8e70ea5435d..5482a4268c5a6 100644 --- a/packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts +++ b/packages/react/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.ts @@ -27,7 +27,7 @@ export default async function* moduleFederationSsrDevServer( context: ExecutorContext ) { let iter: any = ssrDevServerExecutor(options, context); - const p = context.workspace.projects[context.projectName]; + const p = context.projectsConfigurations.projects[context.projectName]; const moduleFederationConfigPath = join( context.root, @@ -73,7 +73,8 @@ export default async function* moduleFederationSsrDevServer( ) : mapAsyncIterable( createAsyncIterable(async ({ next, done }) => { - const remoteProject = context.workspace.projects[appName]; + const remoteProject = + context.projectsConfigurations.projects[appName]; const remoteServerOutput = join( workspaceRoot, remoteProject.targets.server.options.outputPath, diff --git a/packages/react/src/generators/application/application.spec.ts b/packages/react/src/generators/application/application.spec.ts index 7ba5704f4bc91..12c42801e930b 100644 --- a/packages/react/src/generators/application/application.spec.ts +++ b/packages/react/src/generators/application/application.spec.ts @@ -2,9 +2,9 @@ import { installedCypressVersion } from '@nrwl/cypress/src/utils/cypress-version import { getProjects, readJson, - readWorkspaceConfiguration, + readNxJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; import { Linter } from '@nrwl/linter'; @@ -44,13 +44,13 @@ describe('app', () => { }); it('should not overwrite default project if already set', async () => { - const workspace = readWorkspaceConfiguration(appTree); - workspace.defaultProject = 'some-awesome-project'; - updateWorkspaceConfiguration(appTree, workspace); + const nxJson = readNxJson(appTree); + nxJson.defaultProject = 'some-awesome-project'; + updateNxJson(appTree, nxJson); await applicationGenerator(appTree, schema); - const { defaultProject } = readWorkspaceConfiguration(appTree); + const { defaultProject } = readNxJson(appTree); expect(defaultProject).toBe('some-awesome-project'); }); @@ -585,8 +585,8 @@ describe('app', () => { it('should set defaults when style: none', async () => { await applicationGenerator(appTree, { ...schema, style: 'none' }); - const workspaceJson = readWorkspaceConfiguration(appTree); - expect(workspaceJson.generators['@nrwl/react']).toMatchObject({ + const nxJson = readNxJson(appTree); + expect(nxJson.generators['@nrwl/react']).toMatchObject({ application: { style: 'none', }, @@ -831,8 +831,8 @@ describe('app', () => { skipWorkspaceJson: false, }); - const workspaceJson = readWorkspaceConfiguration(appTree); - expect(workspaceJson.generators['@nrwl/react']).toMatchObject({ + const nxJson = readNxJson(appTree); + expect(nxJson.generators['@nrwl/react']).toMatchObject({ application: { babel: true, style: 'styled-components', diff --git a/packages/react/src/generators/application/lib/set-defaults.ts b/packages/react/src/generators/application/lib/set-defaults.ts index ea6a1d23b1bfb..4d2a1c59dac60 100644 --- a/packages/react/src/generators/application/lib/set-defaults.ts +++ b/packages/react/src/generators/application/lib/set-defaults.ts @@ -1,8 +1,4 @@ -import { - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { NormalizedSchema } from '../schema'; export function setDefaults(host: Tree, options: NormalizedSchema) { @@ -10,17 +6,16 @@ export function setDefaults(host: Tree, options: NormalizedSchema) { return; } - const workspace = readWorkspaceConfiguration(host); + const nxJson = readNxJson(host); if (options.rootProject) { - workspace.defaultProject = options.projectName; + nxJson.defaultProject = options.projectName; } - workspace.generators = workspace.generators || {}; - workspace.generators['@nrwl/react'] = - workspace.generators['@nrwl/react'] || {}; + nxJson.generators = nxJson.generators || {}; + nxJson.generators['@nrwl/react'] = nxJson.generators['@nrwl/react'] || {}; - const prev = { ...workspace.generators['@nrwl/react'] }; + const prev = { ...nxJson.generators['@nrwl/react'] }; const appDefaults = { style: options.style, @@ -38,8 +33,8 @@ export function setDefaults(host: Tree, options: NormalizedSchema) { ...prev.library, }; - workspace.generators = { - ...workspace.generators, + nxJson.generators = { + ...nxJson.generators, '@nrwl/react': { ...prev, application: appDefaults, @@ -48,5 +43,5 @@ export function setDefaults(host: Tree, options: NormalizedSchema) { }, }; - updateWorkspaceConfiguration(host, workspace); + updateNxJson(host, nxJson); } diff --git a/packages/react/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts b/packages/react/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts index 8323a14430c13..09c545f78cf83 100644 --- a/packages/react/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts +++ b/packages/react/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts @@ -64,14 +64,14 @@ describe('React:CypressComponentTestConfiguration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'my-app'), - }, + } as any, }, 'some-lib': { name: 'some-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'some-lib'), - }, + } as any, }, }, dependencies: { @@ -120,14 +120,14 @@ describe('React:CypressComponentTestConfiguration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'my-app'), - }, + } as any, }, 'some-lib': { name: 'some-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'some-lib'), - }, + } as any, }, }, dependencies: { @@ -187,14 +187,14 @@ describe('React:CypressComponentTestConfiguration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'my-app'), - }, + } as any, }, 'some-lib': { name: 'some-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'some-lib'), - }, + } as any, }, }, dependencies: { @@ -253,14 +253,14 @@ describe('React:CypressComponentTestConfiguration', () => { type: 'app', data: { ...readProjectConfiguration(tree, 'my-app'), - }, + } as any, }, 'some-lib': { name: 'some-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'some-lib'), - }, + } as any, }, }, dependencies: { @@ -422,14 +422,14 @@ describe('React:CypressComponentTestConfiguration', () => { type: 'app', data: { ...appConfig, - }, + } as any, }, 'some-lib': { name: 'some-lib', type: 'lib', data: { ...readProjectConfiguration(tree, 'some-lib'), - }, + } as any, }, }, dependencies: {}, diff --git a/packages/react/src/generators/init/init.ts b/packages/react/src/generators/init/init.ts index 35b674e64d963..171384eca47c3 100755 --- a/packages/react/src/generators/init/init.ts +++ b/packages/react/src/generators/init/init.ts @@ -3,10 +3,10 @@ import { convertNxGenerator, ensurePackage, GeneratorCallback, - readWorkspaceConfiguration, + readNxJson, removeDependenciesFromPackageJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, writeJson, } from '@nrwl/devkit'; import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial'; @@ -25,7 +25,7 @@ import { import { InitSchema } from './schema'; function setDefault(host: Tree) { - const workspace = readWorkspaceConfiguration(host); + const workspace = readNxJson(host); workspace.generators = workspace.generators || {}; const reactGenerators = workspace.generators['@nrwl/react'] || {}; @@ -40,7 +40,7 @@ function setDefault(host: Tree) { }, }; - updateWorkspaceConfiguration(host, { ...workspace, generators }); + updateNxJson(host, { ...workspace, generators }); } function updateDependencies(host: Tree, schema: InitSchema) { @@ -78,14 +78,12 @@ function initRootBabelConfig(tree: Tree, schema: InitSchema) { }); } - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - if (workspaceConfiguration.namedInputs?.sharedGlobals) { - workspaceConfiguration.namedInputs.sharedGlobals.push( - '{workspaceRoot}/babel.config.json' - ); + if (nxJson.namedInputs?.sharedGlobals) { + nxJson.namedInputs.sharedGlobals.push('{workspaceRoot}/babel.config.json'); } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } export async function reactInitGenerator(host: Tree, schema: InitSchema) { diff --git a/packages/react/src/generators/library/lib/set-defaults.ts b/packages/react/src/generators/library/lib/set-defaults.ts index 645936f94ed36..771e97ccaec43 100644 --- a/packages/react/src/generators/library/lib/set-defaults.ts +++ b/packages/react/src/generators/library/lib/set-defaults.ts @@ -1,31 +1,26 @@ -import { - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { NormalizedSchema } from '../schema'; export function setDefaults(host: Tree, options: NormalizedSchema) { - const workspace = readWorkspaceConfiguration(host); + const nxJson = readNxJson(host); - workspace.generators = workspace.generators || {}; - workspace.generators['@nrwl/react'] = - workspace.generators['@nrwl/react'] || {}; + nxJson.generators = nxJson.generators || {}; + nxJson.generators['@nrwl/react'] = nxJson.generators['@nrwl/react'] || {}; - const prev = { ...workspace.generators['@nrwl/react'] }; + const prev = { ...nxJson.generators['@nrwl/react'] }; const libDefaults = { ...prev.library, unitTestRunner: prev.library?.unitTestRunner ?? options.unitTestRunner, }; - workspace.generators = { - ...workspace.generators, + nxJson.generators = { + ...nxJson.generators, '@nrwl/react': { ...prev, library: libDefaults, }, }; - updateWorkspaceConfiguration(host, workspace); + updateNxJson(host, nxJson); } diff --git a/packages/react/src/generators/remote/remote.spec.ts b/packages/react/src/generators/remote/remote.spec.ts index b9e9fa634d1a4..0370c9fc38914 100644 --- a/packages/react/src/generators/remote/remote.spec.ts +++ b/packages/react/src/generators/remote/remote.spec.ts @@ -1,4 +1,4 @@ -import { readWorkspaceConfiguration } from '@nrwl/devkit'; +import { readNxJson } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Linter } from '@nrwl/linter'; import remote from './remote'; @@ -17,7 +17,7 @@ describe('remote generator', () => { unitTestRunner: 'jest', }); - const { defaultProject } = readWorkspaceConfiguration(tree); + const { defaultProject } = readNxJson(tree); expect(defaultProject).toBeUndefined(); }); diff --git a/packages/react/src/generators/setup-ssr/setup-ssr.ts b/packages/react/src/generators/setup-ssr/setup-ssr.ts index f0ad0db2fed86..44dcea0138c33 100644 --- a/packages/react/src/generators/setup-ssr/setup-ssr.ts +++ b/packages/react/src/generators/setup-ssr/setup-ssr.ts @@ -6,11 +6,11 @@ import { formatFiles, generateFiles, joinPathFragments, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, Tree, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, } from '@nrwl/devkit'; import initGenerator from '../init/init'; @@ -165,15 +165,15 @@ export async function setupSsrGenerator(tree: Tree, options: Schema) { updateProjectConfiguration(tree, options.project, projectConfig); - const workspace = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); if ( - workspace.tasksRunnerOptions?.default && - !workspace.tasksRunnerOptions.default.options.cacheableOperations.includes( + nxJson.tasksRunnerOptions?.default && + !nxJson.tasksRunnerOptions.default.options.cacheableOperations.includes( 'server' ) ) { - workspace.tasksRunnerOptions.default.options.cacheableOperations = [ - ...workspace.tasksRunnerOptions.default.options.cacheableOperations, + nxJson.tasksRunnerOptions.default.options.cacheableOperations = [ + ...nxJson.tasksRunnerOptions.default.options.cacheableOperations, 'server', ]; } @@ -202,7 +202,7 @@ export async function setupSsrGenerator(tree: Tree, options: Schema) { tree.write(serverEntry, changes); } - updateWorkspaceConfiguration(tree, workspace); + updateNxJson(tree, nxJson); const installTask = addDependenciesToPackageJson( tree, diff --git a/packages/react/src/module-federation/load-config.ts b/packages/react/src/module-federation/load-config.ts index 37592f55796aa..a8d249b334b5e 100644 --- a/packages/react/src/module-federation/load-config.ts +++ b/packages/react/src/module-federation/load-config.ts @@ -5,7 +5,7 @@ import { ModuleFederationConfig } from './models'; export function loadModuleFederationConfigFromContext( context: ExecutorContext ): ModuleFederationConfig { - const p = context.workspace.projects[context.projectName]; + const p = context.projectsConfigurations.projects[context.projectName]; const moduleFederationConfigPath = join( context.root, p.root, diff --git a/packages/react/src/module-federation/utils.ts b/packages/react/src/module-federation/utils.ts index b1eb5cef18942..2839d6b5ad1cc 100644 --- a/packages/react/src/module-federation/utils.ts +++ b/packages/react/src/module-federation/utils.ts @@ -18,7 +18,7 @@ export async function getModuleFederationConfig( determineRemoteUrl: (remote: string) => string, options: { isServer: boolean } = { isServer: false } ) { - let projectGraph: ProjectGraph; + let projectGraph: ProjectGraph; try { projectGraph = readCachedProjectGraph(); } catch (e) { diff --git a/packages/rollup/src/executors/rollup/lib/update-package-json.spec.ts b/packages/rollup/src/executors/rollup/lib/update-package-json.spec.ts index 02410cdc21c58..1ef3663611dc7 100644 --- a/packages/rollup/src/executors/rollup/lib/update-package-json.spec.ts +++ b/packages/rollup/src/executors/rollup/lib/update-package-json.spec.ts @@ -16,7 +16,8 @@ describe('updatePackageJson', () => { const sharedContext = { isVerbose: false, - workspace: { version: 2, projects: {} }, + projectsConfigurations: { version: 2, projects: {} }, + nxJsonConfiguration: {}, root: '', cwd: '', }; @@ -33,7 +34,7 @@ describe('updatePackageJson', () => { format: ['esm'], }, sharedContext, - { type: 'app', name: 'test', data: {} }, + { type: 'app', name: 'test', data: {} as any }, [], {} as unknown as PackageJson ); @@ -64,7 +65,7 @@ describe('updatePackageJson', () => { format: ['cjs'], }, sharedContext, - { type: 'app', name: 'test', data: {} }, + { type: 'app', name: 'test', data: {} as any }, [], {} as unknown as PackageJson ); @@ -94,7 +95,7 @@ describe('updatePackageJson', () => { format: ['esm', 'cjs'], }, sharedContext, - { type: 'app', name: 'test', data: {} }, + { type: 'app', name: 'test', data: {} as any }, [], {} as unknown as PackageJson ); @@ -126,7 +127,7 @@ describe('updatePackageJson', () => { format: ['esm'], }, sharedContext, - { type: 'app', name: 'test', data: {} }, + { type: 'app', name: 'test', data: {} as any }, [], { exports: { @@ -167,7 +168,7 @@ describe('updatePackageJson', () => { format: ['esm'], }, sharedContext, - { type: 'app', name: 'test', data: {} }, + { type: 'app', name: 'test', data: {} as any }, [], {} as unknown as PackageJson ); @@ -191,7 +192,7 @@ describe('updatePackageJson', () => { format: ['cjs'], }, sharedContext, - { type: 'app', name: 'test', data: {} }, + { type: 'app', name: 'test', data: {} as any }, [], {} as unknown as PackageJson ); @@ -214,7 +215,7 @@ describe('updatePackageJson', () => { format: ['esm', 'cjs'], }, sharedContext, - { type: 'app', name: 'test', data: {} }, + { type: 'app', name: 'test', data: {} as any }, [], {} as unknown as PackageJson ); @@ -238,7 +239,7 @@ describe('updatePackageJson', () => { format: ['esm'], }, sharedContext, - { type: 'app', name: 'test', data: {} }, + { type: 'app', name: 'test', data: {} as any }, [], { exports: { @@ -276,7 +277,7 @@ describe('updatePackageJson', () => { skipTypeField: true, }, sharedContext, - { type: 'app', name: 'test', data: {} }, + { type: 'app', name: 'test', data: {} as any }, [], {} as unknown as PackageJson ); diff --git a/packages/rollup/src/executors/rollup/rollup.impl.spec.ts b/packages/rollup/src/executors/rollup/rollup.impl.spec.ts index 502257a7ee89b..1ce20162544fe 100644 --- a/packages/rollup/src/executors/rollup/rollup.impl.spec.ts +++ b/packages/rollup/src/executors/rollup/rollup.impl.spec.ts @@ -14,9 +14,11 @@ describe('rollupExecutor', () => { context = { root: '/root', cwd: '/root', - workspace: { + projectsConfigurations: { version: 2, projects: {}, + }, + nxJsonConfiguration: { npmScope: 'test', }, isVerbose: false, diff --git a/packages/rollup/src/executors/rollup/rollup.impl.ts b/packages/rollup/src/executors/rollup/rollup.impl.ts index 4cf14b88d2fb8..84d0608c96a52 100644 --- a/packages/rollup/src/executors/rollup/rollup.impl.ts +++ b/packages/rollup/src/executors/rollup/rollup.impl.ts @@ -45,7 +45,7 @@ export async function* rollupExecutor( ) { process.env.NODE_ENV ??= 'production'; - const project = context.workspace.projects[context.projectName]; + const project = context.projectsConfigurations.projects[context.projectName]; const sourceRoot = project.sourceRoot; const { target, dependencies } = calculateProjectDependencies( context.projectGraph, diff --git a/packages/rollup/src/migrations/update-15-0-0/add-babel-inputs.spec.ts b/packages/rollup/src/migrations/update-15-0-0/add-babel-inputs.spec.ts index 081587e0b6d95..2661b34d3fb1d 100644 --- a/packages/rollup/src/migrations/update-15-0-0/add-babel-inputs.spec.ts +++ b/packages/rollup/src/migrations/update-15-0-0/add-babel-inputs.spec.ts @@ -1,9 +1,5 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { - Tree, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import addBabelInputs from './add-babel-inputs'; describe('15.0.0 migration (add-babel-inputs)', () => { @@ -14,8 +10,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { }); it('should add babel.config.json to sharedGlobals', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -26,7 +21,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { await addBabelInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -41,14 +36,12 @@ describe('15.0.0 migration (add-babel-inputs)', () => { "{workspaceRoot}/babel.config.json", ], }, - "version": 2, } `); }); it('should add babel.config.js', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -59,7 +52,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { await addBabelInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -74,7 +67,6 @@ describe('15.0.0 migration (add-babel-inputs)', () => { "{workspaceRoot}/babel.config.js", ], }, - "version": 2, } `); }); diff --git a/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts b/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts index 7c926e53fb1ca..bc25a3399da82 100644 --- a/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts +++ b/packages/storybook/src/executors/build-storybook/build-storybook.impl.spec.ts @@ -43,7 +43,7 @@ describe('Build storybook', () => { cwd: '/root', projectName: 'proj', targetName: 'storybook', - workspace: { + projectsConfigurations: { version: 2, projects: { proj: { @@ -76,6 +76,8 @@ describe('Build storybook', () => { }, }, }, + }, + nxJsonConfiguration: { npmScope: 'test', }, isVerbose: false, diff --git a/packages/storybook/src/executors/storybook/storybook.impl.spec.ts b/packages/storybook/src/executors/storybook/storybook.impl.spec.ts index 34a71c89d68c9..cbea8daea1f10 100644 --- a/packages/storybook/src/executors/storybook/storybook.impl.spec.ts +++ b/packages/storybook/src/executors/storybook/storybook.impl.spec.ts @@ -42,7 +42,7 @@ describe('@nrwl/storybook:storybook', () => { cwd: rootPath, projectName: 'proj', targetName: 'storybook', - workspace: { + projectsConfigurations: { version: 2, projects: { proj: { @@ -75,8 +75,8 @@ describe('@nrwl/storybook:storybook', () => { }, }, }, - npmScope: 'test', }, + nxJsonConfiguration: {}, isVerbose: false, }; jest.mock('fs', () => fsMock); diff --git a/packages/storybook/src/generators/change-storybook-targets/__snapshots__/change-storybook-targets.spec.ts.snap b/packages/storybook/src/generators/change-storybook-targets/__snapshots__/change-storybook-targets.spec.ts.snap index 62afbed8b4941..9ee24f1007c28 100644 --- a/packages/storybook/src/generators/change-storybook-targets/__snapshots__/change-storybook-targets.spec.ts.snap +++ b/packages/storybook/src/generators/change-storybook-targets/__snapshots__/change-storybook-targets.spec.ts.snap @@ -19,7 +19,6 @@ Object { "runner": "nx/tasks-runners/default", }, }, - "version": 1, } `; @@ -64,7 +63,6 @@ Object { "runner": "nx/tasks-runners/default", }, }, - "version": 1, } `; @@ -87,7 +85,6 @@ Object { "runner": "nx/tasks-runners/default", }, }, - "version": 1, } `; @@ -110,7 +107,6 @@ Object { "runner": "nx/tasks-runners/default", }, }, - "version": 1, } `; diff --git a/packages/storybook/src/generators/change-storybook-targets/change-storybook-targets.spec.ts b/packages/storybook/src/generators/change-storybook-targets/change-storybook-targets.spec.ts index 258b13d432ed9..901f5830dca5c 100644 --- a/packages/storybook/src/generators/change-storybook-targets/change-storybook-targets.spec.ts +++ b/packages/storybook/src/generators/change-storybook-targets/change-storybook-targets.spec.ts @@ -1,4 +1,4 @@ -import { readWorkspaceConfiguration, Tree, writeJson } from '@nrwl/devkit'; +import { readNxJson, Tree, writeJson } from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; import changeStorybookTargetsGenerator from './change-storybook-targets'; import * as defaultConfig from './test-configs/default-config.json'; @@ -19,30 +19,30 @@ describe('Change the Storybook targets for Angular projects to use native Storyb it(`should set the browserTarget correctly in the Storybook config according to the type of project`, async () => { writeJson(tree, 'workspace.json', defaultConfig); await changeStorybookTargetsGenerator(tree); - expect(readWorkspaceConfiguration(tree)).toMatchSnapshot(); + expect(readNxJson(tree)).toMatchSnapshot(); }); it(`should set the browserTarget correctly even if target names are not the default`, async () => { writeJson(tree, 'workspace.json', customNames); await changeStorybookTargetsGenerator(tree); - expect(readWorkspaceConfiguration(tree)).toMatchSnapshot(); + expect(readNxJson(tree)).toMatchSnapshot(); }); it(`should keep any extra options added in the target`, async () => { writeJson(tree, 'workspace.json', extraOptions); await changeStorybookTargetsGenerator(tree); - expect(readWorkspaceConfiguration(tree)).toMatchSnapshot(); + expect(readNxJson(tree)).toMatchSnapshot(); }); it(`should work even if build-storybook does not exist`, async () => { writeJson(tree, 'workspace.json', noStorybookBuildTarget); await changeStorybookTargetsGenerator(tree); - expect(readWorkspaceConfiguration(tree)).toMatchSnapshot(); + expect(readNxJson(tree)).toMatchSnapshot(); }); it(`should not throw an error if no Storybook exists`, async () => { writeJson(tree, 'workspace.json', noStorybook); await changeStorybookTargetsGenerator(tree); - expect(readWorkspaceConfiguration(tree)).toMatchSnapshot(); + expect(readNxJson(tree)).toMatchSnapshot(); }); }); @@ -54,7 +54,7 @@ describe('Change the Storybook targets for Angular projects to use native Storyb it(`should not change their Storybook targets`, async () => { await changeStorybookTargetsGenerator(tree); - expect(readWorkspaceConfiguration(tree)).toMatchSnapshot(); + expect(readNxJson(tree)).toMatchSnapshot(); }); }); }); diff --git a/packages/storybook/src/generators/configuration/util-functions.ts b/packages/storybook/src/generators/configuration/util-functions.ts index 19cef82796a2b..0fb7c72b737b5 100644 --- a/packages/storybook/src/generators/configuration/util-functions.ts +++ b/packages/storybook/src/generators/configuration/util-functions.ts @@ -6,13 +6,13 @@ import { offsetFromRoot, parseTargetString, readJson, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, toJS, Tree, updateJson, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, workspaceRoot, writeJson, } from '@nrwl/devkit'; @@ -298,32 +298,29 @@ export function createRootStorybookDir( tmpl: '', }); - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - if (workspaceConfiguration.namedInputs) { - const hasProductionFileset = - !!workspaceConfiguration.namedInputs?.production; + if (nxJson.namedInputs) { + const hasProductionFileset = !!nxJson.namedInputs?.production; if (hasProductionFileset) { - workspaceConfiguration.namedInputs.production.push( - '!{projectRoot}/.storybook/**/*' - ); - workspaceConfiguration.namedInputs.production.push( + nxJson.namedInputs.production.push('!{projectRoot}/.storybook/**/*'); + nxJson.namedInputs.production.push( '!{projectRoot}/**/*.stories.@(js|jsx|ts|tsx|mdx)' ); } - workspaceConfiguration.targetDefaults ??= {}; - workspaceConfiguration.targetDefaults['build-storybook'] ??= {}; - workspaceConfiguration.targetDefaults['build-storybook'].inputs ??= [ + nxJson.targetDefaults ??= {}; + nxJson.targetDefaults['build-storybook'] ??= {}; + nxJson.targetDefaults['build-storybook'].inputs ??= [ 'default', hasProductionFileset ? '^production' : '^default', ]; - workspaceConfiguration.targetDefaults['build-storybook'].inputs.push( + nxJson.targetDefaults['build-storybook'].inputs.push( '{workspaceRoot}/.storybook/**/*' ); - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } if (js) { diff --git a/packages/storybook/src/generators/init/init.ts b/packages/storybook/src/generators/init/init.ts index 2e7b6c16c5e8c..95f616be0bf1e 100644 --- a/packages/storybook/src/generators/init/init.ts +++ b/packages/storybook/src/generators/init/init.ts @@ -2,10 +2,10 @@ import { addDependenciesToPackageJson, convertNxGenerator, readJson, - readWorkspaceConfiguration, + readNxJson, Tree, updateJson, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { isFramework } from '../../utils/utilities'; @@ -13,6 +13,7 @@ import { babelCoreVersion, babelLoaderVersion, babelPresetTypescriptVersion, + htmlWebpackPluginVersion, litHtmlVersion, nxVersion, reactNativeStorybookLoader, @@ -22,7 +23,6 @@ import { urlLoaderVersion, viteBuilderVersion, webpack5Version, - htmlWebpackPluginVersion, } from '../../utils/versions'; import { Schema } from './schema'; @@ -110,33 +110,32 @@ function checkDependenciesInstalled(host: Tree, schema: Schema) { } function addCacheableOperation(tree: Tree) { - const workspace = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); if ( - !workspace.tasksRunnerOptions || - !workspace.tasksRunnerOptions.default || - (workspace.tasksRunnerOptions.default.runner !== + !nxJson.tasksRunnerOptions || + !nxJson.tasksRunnerOptions.default || + (nxJson.tasksRunnerOptions.default.runner !== '@nrwl/workspace/tasks-runners/default' && - workspace.tasksRunnerOptions.default.runner !== - 'nx/tasks-runners/default') + nxJson.tasksRunnerOptions.default.runner !== 'nx/tasks-runners/default') ) { return; } - workspace.tasksRunnerOptions.default.options = - workspace.tasksRunnerOptions.default.options || {}; + nxJson.tasksRunnerOptions.default.options = + nxJson.tasksRunnerOptions.default.options || {}; - workspace.tasksRunnerOptions.default.options.cacheableOperations = - workspace.tasksRunnerOptions.default.options.cacheableOperations || []; + nxJson.tasksRunnerOptions.default.options.cacheableOperations = + nxJson.tasksRunnerOptions.default.options.cacheableOperations || []; if ( - !workspace.tasksRunnerOptions.default.options.cacheableOperations?.includes( + !nxJson.tasksRunnerOptions.default.options.cacheableOperations?.includes( 'build-storybook' ) ) { - workspace.tasksRunnerOptions.default.options.cacheableOperations.push( + nxJson.tasksRunnerOptions.default.options.cacheableOperations.push( 'build-storybook' ); } - updateWorkspaceConfiguration(tree, workspace); + updateNxJson(tree, nxJson); } function moveToDevDependencies(tree: Tree) { diff --git a/packages/storybook/src/migrations/update-15-0-0/add-storybook-inputs.spec.ts b/packages/storybook/src/migrations/update-15-0-0/add-storybook-inputs.spec.ts index 8f677f3b1e519..bcd98076661f1 100644 --- a/packages/storybook/src/migrations/update-15-0-0/add-storybook-inputs.spec.ts +++ b/packages/storybook/src/migrations/update-15-0-0/add-storybook-inputs.spec.ts @@ -1,9 +1,9 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { - Tree, addProjectConfiguration, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, + readNxJson, + Tree, + updateNxJson, } from '@nrwl/devkit'; import addStorybookInputs from './add-storybook-inputs'; @@ -15,8 +15,7 @@ describe('15.0.0 migration (add-storybook-inputs)', () => { }); it('should add inputs configuration for storybook targets', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -43,7 +42,7 @@ describe('15.0.0 migration (add-storybook-inputs)', () => { await addStorybookInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -74,14 +73,12 @@ describe('15.0.0 migration (add-storybook-inputs)', () => { ], }, }, - "version": 2, } `); }); it('should add inputs configuration for angular storybook targets', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -108,7 +105,7 @@ describe('15.0.0 migration (add-storybook-inputs)', () => { await addStorybookInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -139,7 +136,6 @@ describe('15.0.0 migration (add-storybook-inputs)', () => { ], }, }, - "version": 2, } `); }); diff --git a/packages/storybook/src/migrations/update-15-0-0/add-storybook-inputs.ts b/packages/storybook/src/migrations/update-15-0-0/add-storybook-inputs.ts index 0ca8c4580e3a9..ab0dd9b68621c 100644 --- a/packages/storybook/src/migrations/update-15-0-0/add-storybook-inputs.ts +++ b/packages/storybook/src/migrations/update-15-0-0/add-storybook-inputs.ts @@ -1,36 +1,26 @@ -import { - formatFiles, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; export default async function (tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); const storybookTargets = getStorybookBuildTargets(tree); - const hasProductionFileset = !!workspaceConfiguration.namedInputs?.production; + const hasProductionFileset = !!nxJson.namedInputs?.production; if (storybookTargets.size > 0 && hasProductionFileset) { - const productionFileset = new Set( - workspaceConfiguration.namedInputs.production - ); + const productionFileset = new Set(nxJson.namedInputs.production); for (const exclusion of [ '!{projectRoot}/.storybook/**/*', '!{projectRoot}/**/*.stories.@(js|jsx|ts|tsx|mdx)', ]) { productionFileset.add(exclusion); } - workspaceConfiguration.namedInputs.production = - Array.from(productionFileset); + nxJson.namedInputs.production = Array.from(productionFileset); } for (const targetName of storybookTargets) { - workspaceConfiguration.targetDefaults ??= {}; - const storybookTargetDefaults = (workspaceConfiguration.targetDefaults[ - targetName - ] ??= {}); + nxJson.targetDefaults ??= {}; + const storybookTargetDefaults = (nxJson.targetDefaults[targetName] ??= {}); storybookTargetDefaults.inputs ??= [ 'default', @@ -39,7 +29,7 @@ export default async function (tree: Tree) { ]; } - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); await formatFiles(tree); } diff --git a/packages/storybook/src/utils/utilities.ts b/packages/storybook/src/utils/utilities.ts index 898278770cd26..ff2a85a40809e 100644 --- a/packages/storybook/src/utils/utilities.ts +++ b/packages/storybook/src/utils/utilities.ts @@ -173,7 +173,8 @@ export function findOrCreateConfig( config.srcRoot ); } else { - const sourceRoot = context.workspace.projects[context.projectName].root; + const sourceRoot = + context.projectsConfigurations.projects[context.projectName].root; if (statSync(join(context.root, sourceRoot, '.storybook')).isDirectory()) { return join(context.root, sourceRoot, '.storybook'); } diff --git a/packages/vite/src/executors/build/build.impl.ts b/packages/vite/src/executors/build/build.impl.ts index fd3085bf83de5..2156c58f63a4a 100644 --- a/packages/vite/src/executors/build/build.impl.ts +++ b/packages/vite/src/executors/build/build.impl.ts @@ -11,7 +11,8 @@ export default async function viteBuildExecutor( options: ViteBuildExecutorOptions, context: ExecutorContext ) { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; await runInstance(await getBuildAndSharedConfig(options, context)); diff --git a/packages/vite/src/generators/init/init.ts b/packages/vite/src/generators/init/init.ts index fff1b31df99dd..6652fc980d477 100644 --- a/packages/vite/src/generators/init/init.ts +++ b/packages/vite/src/generators/init/init.ts @@ -2,10 +2,10 @@ import { addDependenciesToPackageJson, convertNxGenerator, readJson, - readWorkspaceConfiguration, + readNxJson, Tree, updateJson, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { @@ -63,28 +63,26 @@ function moveToDevDependencies(tree: Tree) { } export function createVitestConfig(tree: Tree) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - const productionFileSet = workspaceConfiguration.namedInputs?.production; + const productionFileSet = nxJson.namedInputs?.production; if (productionFileSet) { productionFileSet.push( '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)', '!{projectRoot}/tsconfig.spec.json' ); - workspaceConfiguration.namedInputs.production = Array.from( - new Set(productionFileSet) - ); + nxJson.namedInputs.production = Array.from(new Set(productionFileSet)); } - workspaceConfiguration.targetDefaults ??= {}; - workspaceConfiguration.targetDefaults.test ??= {}; - workspaceConfiguration.targetDefaults.test.inputs ??= [ + nxJson.targetDefaults ??= {}; + nxJson.targetDefaults.test ??= {}; + nxJson.targetDefaults.test.inputs ??= [ 'default', productionFileSet ? '^production' : '^default', ]; - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } export function initGenerator(tree: Tree, schema: Schema) { diff --git a/packages/vite/src/utils/options-utils.ts b/packages/vite/src/utils/options-utils.ts index 96018868a80c6..6f9bf08e7f017 100644 --- a/packages/vite/src/utils/options-utils.ts +++ b/packages/vite/src/utils/options-utils.ts @@ -26,7 +26,8 @@ export async function getBuildAndSharedConfig( | ViteBuildExecutorOptions, context: ExecutorContext ): Promise { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; return mergeConfig({}, { mode: options.mode, @@ -59,7 +60,8 @@ export function getServerOptions( options: ViteDevServerExecutorOptions, context: ExecutorContext ): ServerOptions { - const projectRoot = context.workspace.projects[context.projectName].root; + const projectRoot = + context.projectsConfigurations.projects[context.projectName].root; let serverOptions: ServerOptions & UserConfig = {}; if (options.proxyConfig) { const proxyConfigPath = options.proxyConfig diff --git a/packages/web/src/generators/application/application.ts b/packages/web/src/generators/application/application.ts index 6994cf95c606d..2f6d5211ba71c 100644 --- a/packages/web/src/generators/application/application.ts +++ b/packages/web/src/generators/application/application.ts @@ -13,12 +13,12 @@ import { joinPathFragments, names, offsetFromRoot, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, TargetConfiguration, Tree, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, } from '@nrwl/devkit'; import { jestProjectGenerator } from '@nrwl/jest'; import { swcCoreVersion } from '@nrwl/js/src/utils/versions'; @@ -159,22 +159,22 @@ async function addProject(tree: Tree, options: NormalizedSchema) { } function setDefaults(tree: Tree, options: NormalizedSchema) { - const workspace = readWorkspaceConfiguration(tree); - workspace.generators = workspace.generators || {}; - workspace.generators['@nrwl/web:application'] = { + const nxJson = readNxJson(tree); + nxJson.generators = nxJson.generators || {}; + nxJson.generators['@nrwl/web:application'] = { style: options.style, linter: options.linter, unitTestRunner: options.unitTestRunner, e2eTestRunner: options.e2eTestRunner, - ...workspace.generators['@nrwl/web:application'], + ...nxJson.generators['@nrwl/web:application'], }; - workspace.generators['@nrwl/web:library'] = { + nxJson.generators['@nrwl/web:library'] = { style: options.style, linter: options.linter, unitTestRunner: options.unitTestRunner, - ...workspace.generators['@nrwl/web:library'], + ...nxJson.generators['@nrwl/web:library'], }; - updateWorkspaceConfiguration(tree, workspace); + updateNxJson(tree, nxJson); } export async function applicationGenerator(host: Tree, schema: Schema) { diff --git a/packages/web/src/generators/init/init.ts b/packages/web/src/generators/init/init.ts index cf6e93fa33860..831be47935695 100644 --- a/packages/web/src/generators/init/init.ts +++ b/packages/web/src/generators/init/init.ts @@ -4,11 +4,8 @@ import { convertNxGenerator, formatFiles, GeneratorCallback, - readWorkspaceConfiguration, removeDependenciesFromPackageJson, Tree, - updateWorkspaceConfiguration, - writeJson, } from '@nrwl/devkit'; import { jestInitGenerator } from '@nrwl/jest'; import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial'; diff --git a/packages/web/src/migrations/update-15-0-0/add-babel-inputs.spec.ts b/packages/web/src/migrations/update-15-0-0/add-babel-inputs.spec.ts index 081587e0b6d95..2661b34d3fb1d 100644 --- a/packages/web/src/migrations/update-15-0-0/add-babel-inputs.spec.ts +++ b/packages/web/src/migrations/update-15-0-0/add-babel-inputs.spec.ts @@ -1,9 +1,5 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { - Tree, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import addBabelInputs from './add-babel-inputs'; describe('15.0.0 migration (add-babel-inputs)', () => { @@ -14,8 +10,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { }); it('should add babel.config.json to sharedGlobals', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -26,7 +21,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { await addBabelInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -41,14 +36,12 @@ describe('15.0.0 migration (add-babel-inputs)', () => { "{workspaceRoot}/babel.config.json", ], }, - "version": 2, } `); }); it('should add babel.config.js', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -59,7 +52,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { await addBabelInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -74,7 +67,6 @@ describe('15.0.0 migration (add-babel-inputs)', () => { "{workspaceRoot}/babel.config.js", ], }, - "version": 2, } `); }); diff --git a/packages/webpack/src/executors/dev-server/dev-server.impl.ts b/packages/webpack/src/executors/dev-server/dev-server.impl.ts index 046504a74210f..34420a1ca1cb4 100644 --- a/packages/webpack/src/executors/dev-server/dev-server.impl.ts +++ b/packages/webpack/src/executors/dev-server/dev-server.impl.ts @@ -26,7 +26,7 @@ export async function* devServerExecutor( context: ExecutorContext ) { const { root: projectRoot, sourceRoot } = - context.workspace.projects[context.projectName]; + context.projectsConfigurations.projects[context.projectName]; const buildOptions = normalizeOptions( getBuildOptions(serveOptions, context), context.root, diff --git a/packages/webpack/src/executors/dev-server/lib/get-dev-server-config.ts b/packages/webpack/src/executors/dev-server/lib/get-dev-server-config.ts index 665a14f0e13e1..eae0b8b7a7605 100644 --- a/packages/webpack/src/executors/dev-server/lib/get-dev-server-config.ts +++ b/packages/webpack/src/executors/dev-server/lib/get-dev-server-config.ts @@ -19,7 +19,7 @@ export function getDevServerConfig( ): Partial { const workspaceRoot = context.root; const { root: projectRoot, sourceRoot } = - context.workspace.projects[context.projectName]; + context.projectsConfigurations.projects[context.projectName]; const webpackConfig = getWebpackConfig( context, buildOptions, diff --git a/packages/webpack/src/executors/webpack/lib/get-webpack-config.ts b/packages/webpack/src/executors/webpack/lib/get-webpack-config.ts index c04f968d60d0a..10cdf2f3a50af 100644 --- a/packages/webpack/src/executors/webpack/lib/get-webpack-config.ts +++ b/packages/webpack/src/executors/webpack/lib/get-webpack-config.ts @@ -47,7 +47,8 @@ export function getWebpackConfig( projectRoot = overrides.root; sourceRoot = overrides.sourceRoot; } else { - const project = context.workspace.projects[context.projectName]; + const project = + context.projectsConfigurations.projects[context.projectName]; projectRoot = project.root; sourceRoot = project.sourceRoot; } diff --git a/packages/webpack/src/executors/webpack/webpack.impl.ts b/packages/webpack/src/executors/webpack/webpack.impl.ts index 454dc4fd443aa..a12cf27c37f07 100644 --- a/packages/webpack/src/executors/webpack/webpack.impl.ts +++ b/packages/webpack/src/executors/webpack/webpack.impl.ts @@ -35,7 +35,7 @@ async function getWebpackConfigs( options: NormalizedWebpackExecutorOptions, context: ExecutorContext ): Promise { - const metadata = context.workspace.projects[context.projectName]; + const metadata = context.projectsConfigurations.projects[context.projectName]; const projectRoot = metadata.root; const isScriptOptimizeOn = typeof options.optimization === 'boolean' @@ -107,7 +107,7 @@ export async function* webpackExecutor( _options: WebpackExecutorOptions, context: ExecutorContext ): AsyncGenerator { - const metadata = context.workspace.projects[context.projectName]; + const metadata = context.projectsConfigurations.projects[context.projectName]; const sourceRoot = metadata.sourceRoot; const options = normalizeOptions(_options, context.root, sourceRoot); const isScriptOptimizeOn = diff --git a/packages/webpack/src/migrations/update-15-0-0/add-babel-inputs.spec.ts b/packages/webpack/src/migrations/update-15-0-0/add-babel-inputs.spec.ts index 081587e0b6d95..2661b34d3fb1d 100644 --- a/packages/webpack/src/migrations/update-15-0-0/add-babel-inputs.spec.ts +++ b/packages/webpack/src/migrations/update-15-0-0/add-babel-inputs.spec.ts @@ -1,9 +1,5 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { - Tree, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import addBabelInputs from './add-babel-inputs'; describe('15.0.0 migration (add-babel-inputs)', () => { @@ -14,8 +10,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { }); it('should add babel.config.json to sharedGlobals', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -26,7 +21,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { await addBabelInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -41,14 +36,12 @@ describe('15.0.0 migration (add-babel-inputs)', () => { "{workspaceRoot}/babel.config.json", ], }, - "version": 2, } `); }); it('should add babel.config.js', async () => { - updateWorkspaceConfiguration(tree, { - version: 2, + updateNxJson(tree, { namedInputs: { default: ['{projectRoot}/**/*', 'sharedGlobals'], sharedGlobals: [], @@ -59,7 +52,7 @@ describe('15.0.0 migration (add-babel-inputs)', () => { await addBabelInputs(tree); - const updated = readWorkspaceConfiguration(tree); + const updated = readNxJson(tree); expect(updated).toMatchInlineSnapshot(` Object { "namedInputs": Object { @@ -74,7 +67,6 @@ describe('15.0.0 migration (add-babel-inputs)', () => { "{workspaceRoot}/babel.config.js", ], }, - "version": 2, } `); }); diff --git a/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.spec.ts b/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.spec.ts index ae15df8193a27..63a1abcfdfdcf 100644 --- a/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.spec.ts +++ b/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.spec.ts @@ -159,20 +159,6 @@ describe('convert-to-nx-project', () => { expect(json.projects.lib).toEqual(config.root); }); - it('should error in v1 schema with workspace.json', async () => { - const tree = createTreeWithEmptyV1Workspace(); - await libraryGenerator(tree, { - name: 'lib', - standaloneConfig: false, - }); - try { - await convertToNxProject(tree, { project: 'lib' }); - } catch (ex) { - expect(ex).toBeDefined(); - } - expect.assertions(1); - }); - it('should format files by default', async () => { jest.spyOn(devkit, 'formatFiles'); diff --git a/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.ts b/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.ts index d6d1b4b954f51..8c7af371208f9 100644 --- a/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.ts +++ b/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.ts @@ -7,7 +7,6 @@ import { normalizePath, ProjectConfiguration, readProjectConfiguration, - readWorkspaceConfiguration, Tree, updateJson, writeJson, @@ -40,17 +39,6 @@ export async function validateSchema(schema: Schema) { } export async function convertToNxProjectGenerator(host: Tree, schema: Schema) { - const workspace = readWorkspaceConfiguration(host); - if (workspace.version < 2) { - logger.error(` -NX Only workspaces with version 2+ support project.json files. -To upgrade change the version number at the top of ${getWorkspacePath( - host - )} and run 'nx format'. -`); - throw new Error('v2+ Required'); - } - await validateSchema(schema); const projects = schema.all diff --git a/packages/workspace/src/generators/move/lib/update-default-project.spec.ts b/packages/workspace/src/generators/move/lib/update-default-project.spec.ts index f4a9c51c73480..6cebcd63180f0 100644 --- a/packages/workspace/src/generators/move/lib/update-default-project.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-default-project.spec.ts @@ -1,8 +1,8 @@ import { addProjectConfiguration, - readWorkspaceConfiguration, + readNxJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; import { NormalizedSchema } from '../schema'; @@ -18,10 +18,10 @@ describe('updateDefaultProject', () => { targets: {}, }); - const workspace = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); - updateWorkspaceConfiguration(tree, { - ...workspace, + updateNxJson(tree, { + ...nxJson, defaultProject: 'my-source', }); }); @@ -38,7 +38,7 @@ describe('updateDefaultProject', () => { updateDefaultProject(tree, schema); - const { defaultProject } = readWorkspaceConfiguration(tree); + const { defaultProject } = readNxJson(tree); expect(defaultProject).toBe('subfolder-my-destination'); }); }); diff --git a/packages/workspace/src/generators/move/lib/update-default-project.ts b/packages/workspace/src/generators/move/lib/update-default-project.ts index 9a00bb327d5e0..f1d8dc6a3c21a 100644 --- a/packages/workspace/src/generators/move/lib/update-default-project.ts +++ b/packages/workspace/src/generators/move/lib/update-default-project.ts @@ -1,8 +1,4 @@ -import { - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { NormalizedSchema } from '../schema'; /** @@ -13,14 +9,11 @@ import { NormalizedSchema } from '../schema'; * - change target references */ export function updateDefaultProject(tree: Tree, schema: NormalizedSchema) { - const workspaceConfiguration = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); // update default project (if necessary) - if ( - workspaceConfiguration.defaultProject && - workspaceConfiguration.defaultProject === schema.projectName - ) { - workspaceConfiguration.defaultProject = schema.newProjectName; - updateWorkspaceConfiguration(tree, workspaceConfiguration); + if (nxJson.defaultProject && nxJson.defaultProject === schema.projectName) { + nxJson.defaultProject = schema.newProjectName; + updateNxJson(tree, nxJson); } } diff --git a/packages/workspace/src/generators/npm-package/npm-package.spec.ts b/packages/workspace/src/generators/npm-package/npm-package.spec.ts index 9f6cc0165a6d9..8d8218721f1e9 100644 --- a/packages/workspace/src/generators/npm-package/npm-package.spec.ts +++ b/packages/workspace/src/generators/npm-package/npm-package.spec.ts @@ -1,14 +1,13 @@ import { - getProjects, + getWorkspacePath, readJson, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, Tree, - updateWorkspaceConfiguration, + updateNxJson, writeJson, } from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; -import { getWorkspacePath } from '@nrwl/devkit'; import { npmPackageGenerator } from './npm-package'; describe('@nrwl/workspace:npm-package', () => { @@ -16,12 +15,12 @@ describe('@nrwl/workspace:npm-package', () => { beforeEach(() => { tree = createTreeWithEmptyV1Workspace(); - const workspaceConfig = readWorkspaceConfiguration(tree); - workspaceConfig.workspaceLayout = { + const nxJson = readNxJson(tree); + nxJson.workspaceLayout = { appsDir: 'packages', libsDir: 'packages', }; - updateWorkspaceConfiguration(tree, workspaceConfig); + updateNxJson(tree, nxJson); }); it('should generate a minimal package', async () => { diff --git a/packages/workspace/src/generators/preset/preset.ts b/packages/workspace/src/generators/preset/preset.ts index 4b42d518b1d6a..beb5bf9f28482 100644 --- a/packages/workspace/src/generators/preset/preset.ts +++ b/packages/workspace/src/generators/preset/preset.ts @@ -1,14 +1,12 @@ import { - addDependenciesToPackageJson, formatFiles, installPackagesTask, names, - readWorkspaceConfiguration, + readNxJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { Schema } from './schema'; -import { insertStatement } from '../utils/insert-statement'; import { Preset } from '../utils/presets'; export async function presetGenerator(tree: Tree, options: Schema) { @@ -19,6 +17,7 @@ export async function presetGenerator(tree: Tree, options: Schema) { installPackagesTask(tree); }; } + export default presetGenerator; async function createPreset(tree: Tree, options: Schema) { @@ -129,12 +128,12 @@ async function createPreset(tree: Tree, options: Schema) { e2eTestRunner: 'detox', }); } else if (options.preset === Preset.TS) { - const c = readWorkspaceConfiguration(tree); + const c = readNxJson(tree); c.workspaceLayout = { appsDir: 'packages', libsDir: 'packages', }; - updateWorkspaceConfiguration(tree, c); + updateNxJson(tree, c); } else { throw new Error(`Invalid preset ${options.preset}`); } diff --git a/packages/workspace/src/generators/remove/lib/remove-project-config.spec.ts b/packages/workspace/src/generators/remove/lib/remove-project-config.spec.ts index 7cabca041aaee..dac81eb3add36 100644 --- a/packages/workspace/src/generators/remove/lib/remove-project-config.spec.ts +++ b/packages/workspace/src/generators/remove/lib/remove-project-config.spec.ts @@ -1,9 +1,9 @@ import { addProjectConfiguration, readProjectConfiguration, - readWorkspaceConfiguration, + readNxJson, Tree, - updateWorkspaceConfiguration, + updateNxJson, } from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; @@ -67,9 +67,9 @@ describe('removeProjectConfig', () => { describe('defaultProject', () => { beforeEach(async () => { - const workspaceConfig = readWorkspaceConfiguration(tree); - updateWorkspaceConfiguration(tree, { - ...workspaceConfig, + const nxJson = readNxJson(tree); + updateNxJson(tree, { + ...nxJson, defaultProject: 'ng-app', }); }); @@ -83,7 +83,7 @@ describe('removeProjectConfig', () => { removeProjectConfig(tree, schema); - const { defaultProject } = readWorkspaceConfiguration(tree); + const { defaultProject } = readNxJson(tree); expect(defaultProject).toBeUndefined(); }); @@ -96,7 +96,7 @@ describe('removeProjectConfig', () => { removeProjectConfig(tree, schema); - const { defaultProject } = readWorkspaceConfiguration(tree); + const { defaultProject } = readNxJson(tree); expect(defaultProject).toEqual('ng-app'); }); diff --git a/packages/workspace/src/generators/remove/lib/remove-project-config.ts b/packages/workspace/src/generators/remove/lib/remove-project-config.ts index 5215292160799..6f071d698835e 100644 --- a/packages/workspace/src/generators/remove/lib/remove-project-config.ts +++ b/packages/workspace/src/generators/remove/lib/remove-project-config.ts @@ -1,14 +1,12 @@ import { Schema } from '../schema'; import { getProjects, + getWorkspacePath, + readNxJson, + removeProjectConfiguration, Tree, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; -import { - readWorkspaceConfiguration, - removeProjectConfiguration, - getWorkspacePath, } from '@nrwl/devkit'; /** @@ -20,18 +18,15 @@ export function removeProjectConfig(tree: Tree, schema: Schema) { removeProjectConfiguration(tree, schema.projectName); // Unset default project if deleting the default project - const workspaceConfiguration = readWorkspaceConfiguration(tree); - if ( - workspaceConfiguration.defaultProject && - workspaceConfiguration.defaultProject === schema.projectName - ) { + const nxJson = readNxJson(tree); + if (nxJson.defaultProject && nxJson.defaultProject === schema.projectName) { const workspacePath = getWorkspacePath(tree); - delete workspaceConfiguration.defaultProject; + delete nxJson.defaultProject; console.warn( `Default project was removed in ${workspacePath} because it was "${schema.projectName}". If you want a default project you should define a new one.` ); - updateWorkspaceConfiguration(tree, workspaceConfiguration); + updateNxJson(tree, nxJson); } // Remove implicit dependencies onto removed project diff --git a/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts b/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts index d74e8930ffbfc..077d29b822821 100644 --- a/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts @@ -51,7 +51,7 @@ describe('updateTsconfig', () => { type: 'lib', data: { root: readProjectConfiguration(tree, 'my-lib').root, - }, + } as any, }, }, dependencies: {}, @@ -77,7 +77,7 @@ describe('updateTsconfig', () => { type: 'lib', data: { root: readProjectConfiguration(tree, 'my-lib').root, - }, + } as any, }, }, dependencies: {}, @@ -103,7 +103,7 @@ describe('updateTsconfig', () => { type: 'lib', data: { root: readProjectConfiguration(tree, 'my-lib').root, - }, + } as any, }, }, dependencies: {}, @@ -129,7 +129,7 @@ describe('updateTsconfig', () => { type: 'lib', data: { root: readProjectConfiguration(tree, 'my-lib').root, - }, + } as any, }, }, dependencies: {}, @@ -156,7 +156,7 @@ describe('updateTsconfig', () => { type: 'lib', data: { root: readProjectConfiguration(tree, 'my-lib').root, - }, + } as any, }, }, dependencies: {}, @@ -188,14 +188,14 @@ describe('updateTsconfig', () => { type: 'lib', data: { root: readProjectConfiguration(tree, 'my-lib').root, - }, + } as any, }, 'my-lib-nested-lib': { name: 'my-lib-nested-lib', type: 'lib', data: { root: readProjectConfiguration(tree, 'my-lib-nested-lib').root, - }, + } as any, }, }, dependencies: {}, diff --git a/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts b/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts index dedc30361efbb..fd66d6cb62d8e 100644 --- a/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts +++ b/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts @@ -1,13 +1,8 @@ -import { - formatFiles, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { output } from '../../utilities/output'; export async function setTargetDependencies(host: Tree) { - const config = readWorkspaceConfiguration(host); + const config = readNxJson(host); const strictlyOrderedTargets = config.tasksRunnerOptions?.['default']?.options ?.strictlyOrderedTargets || ['build']; delete config.tasksRunnerOptions?.['default']?.options @@ -23,7 +18,7 @@ export async function setTargetDependencies(host: Tree) { updatedStrictlyOrderedTargets.push(target); } }); - updateWorkspaceConfiguration(host, config); + updateNxJson(host, config); if (updatedStrictlyOrderedTargets.length > 0) { output.note({ diff --git a/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.spec.ts b/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.spec.ts index c8543394745ca..e11731aa86c07 100644 --- a/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.spec.ts +++ b/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.spec.ts @@ -1,10 +1,4 @@ -import { - Tree, - writeJson, - updateJson, - readWorkspaceConfiguration, - readJson, -} from '@nrwl/devkit'; +import { Tree, writeJson, updateJson, readJson } from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace, createTreeWithEmptyWorkspace, diff --git a/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.ts b/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.ts index bf2fca7ccce84..7f38998a6283d 100644 --- a/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.ts +++ b/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.ts @@ -4,13 +4,12 @@ import { NxJsonConfiguration, ProjectConfiguration, readJson, + readNxJson, readProjectConfiguration, - readWorkspaceConfiguration, Tree, updateJson, + updateNxJson, updateProjectConfiguration, - updateWorkspaceConfiguration, - WorkspaceConfiguration, writeJson, } from '@nrwl/devkit'; @@ -23,10 +22,11 @@ export default async function update(tree: Tree) { }; // updateProjectConfiguration automatically saves the project opts into workspace/project.json if (nxJson.projects) { - Object.entries(nxJson.projects).forEach(([p, nxJsonConfig]) => { + Object.entries(nxJson.projects).forEach(([p, nxJsonConfiguration]) => { const configuration = readProjectConfiguration(tree, p); - configuration.tags ??= nxJsonConfig.tags; - configuration.implicitDependencies ??= nxJsonConfig.implicitDependencies; + configuration.tags ??= nxJsonConfiguration.tags; + configuration.implicitDependencies ??= + nxJsonConfiguration.implicitDependencies; updateProjectConfiguration(tree, p, configuration); }); delete nxJson.projects; @@ -55,21 +55,21 @@ function movePropertiesAreInNewLocations(tree: Tree) { if (!workspacePath) { return; } - const wc = readWorkspaceConfiguration(tree); - updateJson(tree, workspacePath, (json) => { - wc.generators ??= json.generators ?? (json as any).schematics; - if (wc.cli) { - wc.cli.defaultCollection ??= json.cli?.defaultCollection; - wc.cli.packageManager ??= json.cli?.packageManager; + const nxJson = readNxJson(tree); + updateJson(tree, workspacePath, (json) => { + nxJson.generators ??= json.generators ?? (json as any).schematics; + if (nxJson.cli) { + nxJson.cli.defaultCollection ??= json.cli?.defaultCollection; + nxJson.cli.packageManager ??= json.cli?.packageManager; } else if (json.cli) { - wc.cli ??= json.cli; + nxJson.cli ??= json.cli; } - wc.defaultProject ??= json.defaultProject; + nxJson.defaultProject ??= json.defaultProject; delete json.cli; delete json.defaultProject; delete (json as any).schematics; delete json.generators; return json; }); - updateWorkspaceConfiguration(tree, wc); + updateNxJson(tree, nxJson); } diff --git a/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.spec.ts b/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.spec.ts index e0ebcc63e1c27..16d39e310ceb1 100644 --- a/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.spec.ts +++ b/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.spec.ts @@ -1,4 +1,4 @@ -import { Tree, writeJson, readWorkspaceConfiguration } from '@nrwl/devkit'; +import { readNxJson, Tree, writeJson } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { setDefaultBaseIfNotSet } from './set-default-base-if-not-set'; @@ -13,7 +13,7 @@ describe('add `defaultBase` in nx.json', () => { writeJson(tree, 'nx.json', { npmScope: 'unitTests' }); await setDefaultBaseIfNotSet(tree); - const config = readWorkspaceConfiguration(tree); + const config = readNxJson(tree); expect(config.affected.defaultBase).toEqual('master'); }); @@ -24,7 +24,7 @@ describe('add `defaultBase` in nx.json', () => { }); await setDefaultBaseIfNotSet(tree); - const config = readWorkspaceConfiguration(tree); + const config = readNxJson(tree); expect(config.affected.defaultBase).toEqual('main'); }); }); diff --git a/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.ts b/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.ts index 04d21c10923d4..c0e9a7ef4f54c 100644 --- a/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.ts +++ b/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.ts @@ -1,13 +1,8 @@ -import { - formatFiles, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; import { output } from '../../utilities/output'; export async function setDefaultBaseIfNotSet(host: Tree) { - const config = readWorkspaceConfiguration(host); + const config = readNxJson(host); if (!config.affected?.defaultBase) { config.affected ??= {}; config.affected.defaultBase ??= 'master'; @@ -21,7 +16,7 @@ export async function setDefaultBaseIfNotSet(host: Tree) { ], }); } - updateWorkspaceConfiguration(host, config); + updateNxJson(host, config); await formatFiles(host); } diff --git a/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts b/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts index 37f930864bf0d..ef7aa520b18a6 100644 --- a/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts +++ b/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts @@ -1,11 +1,7 @@ -import { - readWorkspaceConfiguration, - updateWorkspaceConfiguration, - Tree, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; export function updateTasksRunner(host: Tree) { - const config = readWorkspaceConfiguration(host); + const config = readNxJson(host); if ( config?.tasksRunnerOptions?.['default'] && config?.tasksRunnerOptions['default'].runner == @@ -13,7 +9,7 @@ export function updateTasksRunner(host: Tree) { ) { config.tasksRunnerOptions['default'].runner = 'nx/tasks-runners/default'; } - updateWorkspaceConfiguration(host, config); + updateNxJson(host, config); } export default updateTasksRunner; diff --git a/packages/workspace/src/migrations/update-13-2-0/set-parallel-default.ts b/packages/workspace/src/migrations/update-13-2-0/set-parallel-default.ts index 030a77515f470..b3413807b807a 100644 --- a/packages/workspace/src/migrations/update-13-2-0/set-parallel-default.ts +++ b/packages/workspace/src/migrations/update-13-2-0/set-parallel-default.ts @@ -1,12 +1,7 @@ -import { - formatFiles, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; export async function setParallelDefault(host: Tree) { - const config = readWorkspaceConfiguration(host); + const config = readNxJson(host); const defaultTaskRunnerOptions = config.tasksRunnerOptions?.['default']?.options; if (defaultTaskRunnerOptions) { @@ -17,7 +12,7 @@ export async function setParallelDefault(host: Tree) { } else { defaultTaskRunnerOptions.parallel = 1; } - updateWorkspaceConfiguration(host, config); + updateNxJson(host, config); } await formatFiles(host); } diff --git a/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.ts b/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.ts index 665518a4434b5..9bf65664d5384 100644 --- a/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.ts +++ b/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.ts @@ -1,16 +1,12 @@ -import { - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; export function removeOldTaskRunnerOptions(host: Tree) { - const workspaceConfig = readWorkspaceConfiguration(host); - const options = workspaceConfig.tasksRunnerOptions?.['default']?.options; + const nxJson = readNxJson(host); + const options = nxJson.tasksRunnerOptions?.['default']?.options; if (options) { delete options.scan; delete options.analytics; - updateWorkspaceConfiguration(host, workspaceConfig); + updateNxJson(host, nxJson); } } diff --git a/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.spec.ts b/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.spec.ts index ba26be4f1b264..4bccc319f708a 100644 --- a/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.spec.ts +++ b/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.spec.ts @@ -1,10 +1,7 @@ import { addProjectConfiguration, - readJson, readProjectConfiguration, - readWorkspaceConfiguration, Tree, - updateWorkspaceConfiguration, } from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; import changeNpmScriptExecutor from './change-npm-script-executor'; diff --git a/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.ts b/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.ts index ee5eed0caa4a7..7dac2f2c6789b 100644 --- a/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.ts +++ b/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.ts @@ -1,11 +1,8 @@ import { formatFiles, readProjectConfiguration, - readWorkspaceConfiguration, - TargetConfiguration, Tree, updateProjectConfiguration, - updateWorkspaceConfiguration, } from '@nrwl/devkit'; import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; diff --git a/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.spec.ts b/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.spec.ts deleted file mode 100644 index ccc0cab11d96b..0000000000000 --- a/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.spec.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { - readJson, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; -import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; -import changeNxJsonPresets from '@nrwl/workspace/src/migrations/update-14-0-0/change-nx-json-presets'; - -describe('changeNxJsonPresets', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyV1Workspace(); - }); - - it('should not set any new extends', async () => { - await changeNxJsonPresets(tree); - - const nxJson = readJson(tree, 'nx.json'); - expect(nxJson.extends).toBeUndefined(); - }); - - it('should change @nrwl/workspace/presets/npm.json', async () => { - updateWorkspaceConfiguration(tree, { - ...readWorkspaceConfiguration(tree), - extends: '@nrwl/workspace/presets/npm.json', - }); - - await changeNxJsonPresets(tree); - - const nxJson = readJson(tree, 'nx.json'); - expect(nxJson.extends).toEqual('nx/presets/npm.json'); - }); - - it('should change @nrwl/workspace/presets/core.json', async () => { - updateWorkspaceConfiguration(tree, { - ...readWorkspaceConfiguration(tree), - extends: '@nrwl/workspace/presets/core.json', - }); - - await changeNxJsonPresets(tree); - - const nxJson = readJson(tree, 'nx.json'); - expect(nxJson.extends).toEqual('nx/presets/core.json'); - }); -}); diff --git a/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.ts b/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.ts index aef3df3d3ef48..fd87e78ad64e2 100644 --- a/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.ts +++ b/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.ts @@ -1,20 +1,15 @@ -import { - formatFiles, - readWorkspaceConfiguration, - Tree, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; export async function changeNxJsonPresets(tree: Tree) { - const workspaceConfig = readWorkspaceConfiguration(tree); + const nxJson = readNxJson(tree); const replacements = { '@nrwl/workspace/presets/npm.json': 'nx/presets/npm.json', '@nrwl/workspace/presets/core.json': 'nx/presets/core.json', }; - if (workspaceConfig.extends && replacements[workspaceConfig.extends]) { - updateWorkspaceConfiguration(tree, { - ...workspaceConfig, - extends: replacements[workspaceConfig.extends], + if (nxJson.extends && replacements[nxJson.extends]) { + updateNxJson(tree, { + ...nxJson, + extends: replacements[nxJson.extends], }); } diff --git a/packages/workspace/src/utilities/buildable-libs-utils.ts b/packages/workspace/src/utilities/buildable-libs-utils.ts index 1a3c940b1d984..d05ef605b9a94 100644 --- a/packages/workspace/src/utilities/buildable-libs-utils.ts +++ b/packages/workspace/src/utilities/buildable-libs-utils.ts @@ -317,7 +317,7 @@ export function updatePaths( ); // Get the dependency's package name - const { root } = dep.node?.data || {}; + const { root } = (dep.node?.data || {}) as any; if (root) { // Update nested mappings to point to the dependency's output paths mappedPaths = mappedPaths.concat( diff --git a/packages/workspace/src/utilities/set-default-collection.ts b/packages/workspace/src/utilities/set-default-collection.ts index d52ddfd2deee9..4c0ad380c1fbb 100644 --- a/packages/workspace/src/utilities/set-default-collection.ts +++ b/packages/workspace/src/utilities/set-default-collection.ts @@ -1,8 +1,4 @@ -import { - Tree, - readWorkspaceConfiguration, - updateWorkspaceConfiguration, -} from '@nrwl/devkit'; +import { readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; /** * Sets the default collection within the workspace. @@ -14,14 +10,14 @@ import { * @param collectionName Name of the collection to be set as the default */ export function setDefaultCollection(host: Tree, collectionName: string) { - const workspace = readWorkspaceConfiguration(host); - workspace.cli = workspace.cli || {}; + const nxJson = readNxJson(host); + nxJson.cli = nxJson.cli || {}; - const defaultCollection = workspace.cli.defaultCollection; + const defaultCollection = nxJson.cli.defaultCollection; if (!defaultCollection || defaultCollection === '@nrwl/workspace') { - workspace.cli.defaultCollection = collectionName; + nxJson.cli.defaultCollection = collectionName; } - updateWorkspaceConfiguration(host, workspace); + updateNxJson(host, nxJson); }