diff --git a/docs/generated/devkit/NxJsonConfiguration.md b/docs/generated/devkit/NxJsonConfiguration.md index 630091b22a9b96..f34b5f3318dc18 100644 --- a/docs/generated/devkit/NxJsonConfiguration.md +++ b/docs/generated/devkit/NxJsonConfiguration.md @@ -27,7 +27,6 @@ Nx.json configuration - [implicitDependencies](../../devkit/documents/NxJsonConfiguration#implicitdependencies): ImplicitDependencyEntry<T> - [installation](../../devkit/documents/NxJsonConfiguration#installation): NxInstallationConfiguration - [namedInputs](../../devkit/documents/NxJsonConfiguration#namedinputs): Object -- [npmScope](../../devkit/documents/NxJsonConfiguration#npmscope): string - [nxCloudAccessToken](../../devkit/documents/NxJsonConfiguration#nxcloudaccesstoken): string - [nxCloudEncryptionKey](../../devkit/documents/NxJsonConfiguration#nxcloudencryptionkey): string - [nxCloudUrl](../../devkit/documents/NxJsonConfiguration#nxcloudurl): string @@ -66,11 +65,10 @@ Default generator collection. It is used when no collection is provided. #### Type declaration -| Name | Type | Description | -| :-------------------- | :-------------------------------------------------------- | :--------------------------------------------------------------------- | -| `defaultCollection?` | `string` | **`Deprecated`** - defaultCollection is deprecated and will be removed | -| `defaultProjectName?` | `string` | - | -| `packageManager?` | [`PackageManager`](../../devkit/documents/PackageManager) | - | +| Name | Type | +| :-------------------- | :-------------------------------------------------------- | +| `defaultProjectName?` | `string` | +| `packageManager?` | [`PackageManager`](../../devkit/documents/PackageManager) | --- @@ -151,17 +149,6 @@ Named inputs targets can refer to reduce duplication --- -### npmScope - -• `Optional` **npmScope**: `string` - -**`Deprecated`** - -This is inferred from the package.json in the workspace root. Please use getNpmScope instead. -NPM Scope that the workspace uses - ---- - ### nxCloudAccessToken • `Optional` **nxCloudAccessToken**: `string` diff --git a/docs/generated/devkit/README.md b/docs/generated/devkit/README.md index 9ff7a125e01a02..0137ec749db3c4 100644 --- a/docs/generated/devkit/README.md +++ b/docs/generated/devkit/README.md @@ -85,7 +85,6 @@ It only uses language primitives and immutable objects - [StringChange](../../devkit/documents/StringChange) - [TargetDefaults](../../devkit/documents/TargetDefaults) - [TaskGraphExecutor](../../devkit/documents/TaskGraphExecutor) -- [WorkspaceConfiguration](../../devkit/documents/WorkspaceConfiguration) - [WorkspaceJsonConfiguration](../../devkit/documents/WorkspaceJsonConfiguration) ### Variables @@ -117,11 +116,9 @@ It only uses language primitives and immutable objects - [getPackageManagerVersion](../../devkit/documents/getPackageManagerVersion) - [getProjects](../../devkit/documents/getProjects) - [getWorkspaceLayout](../../devkit/documents/getWorkspaceLayout) -- [getWorkspacePath](../../devkit/documents/getWorkspacePath) - [glob](../../devkit/documents/glob) - [hashArray](../../devkit/documents/hashArray) - [installPackagesTask](../../devkit/documents/installPackagesTask) -- [isStandaloneProject](../../devkit/documents/isStandaloneProject) - [joinPathFragments](../../devkit/documents/joinPathFragments) - [moveFilesToNewDirectory](../../devkit/documents/moveFilesToNewDirectory) - [names](../../devkit/documents/names) @@ -136,7 +133,6 @@ It only uses language primitives and immutable objects - [readProjectConfiguration](../../devkit/documents/readProjectConfiguration) - [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph) - [readTargetOptions](../../devkit/documents/readTargetOptions) -- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration) - [removeDependenciesFromPackageJson](../../devkit/documents/removeDependenciesFromPackageJson) - [removeProjectConfiguration](../../devkit/documents/removeProjectConfiguration) - [reverse](../../devkit/documents/reverse) @@ -151,7 +147,6 @@ It only uses language primitives and immutable objects - [updateNxJson](../../devkit/documents/updateNxJson) - [updateProjectConfiguration](../../devkit/documents/updateProjectConfiguration) - [updateTsConfigsToJs](../../devkit/documents/updateTsConfigsToJs) -- [updateWorkspaceConfiguration](../../devkit/documents/updateWorkspaceConfiguration) - [validateDependency](../../devkit/documents/validateDependency) - [visitNotIgnoredFiles](../../devkit/documents/visitNotIgnoredFiles) - [workspaceLayout](../../devkit/documents/workspaceLayout) diff --git a/docs/generated/devkit/Workspace.md b/docs/generated/devkit/Workspace.md index b10eb82517971a..152a8e4e90a272 100644 --- a/docs/generated/devkit/Workspace.md +++ b/docs/generated/devkit/Workspace.md @@ -25,7 +25,6 @@ use ProjectsConfigurations or NxJsonConfiguration - [implicitDependencies](../../devkit/documents/Workspace#implicitdependencies): ImplicitDependencyEntry<string[] | "\*"> - [installation](../../devkit/documents/Workspace#installation): NxInstallationConfiguration - [namedInputs](../../devkit/documents/Workspace#namedinputs): Object -- [npmScope](../../devkit/documents/Workspace#npmscope): string - [nxCloudAccessToken](../../devkit/documents/Workspace#nxcloudaccesstoken): string - [nxCloudEncryptionKey](../../devkit/documents/Workspace#nxcloudencryptionkey): string - [nxCloudUrl](../../devkit/documents/Workspace#nxcloudurl): string @@ -74,11 +73,10 @@ Default generator collection. It is used when no collection is provided. #### Type declaration -| Name | Type | Description | -| :-------------------- | :-------------------------------------------------------- | :--------------------------------------------------------------------- | -| `defaultCollection?` | `string` | **`Deprecated`** - defaultCollection is deprecated and will be removed | -| `defaultProjectName?` | `string` | - | -| `packageManager?` | [`PackageManager`](../../devkit/documents/PackageManager) | - | +| Name | Type | +| :-------------------- | :-------------------------------------------------------- | +| `defaultProjectName?` | `string` | +| `packageManager?` | [`PackageManager`](../../devkit/documents/PackageManager) | #### Inherited from @@ -187,21 +185,6 @@ Named inputs targets can refer to reduce duplication --- -### npmScope - -• `Optional` **npmScope**: `string` - -**`Deprecated`** - -This is inferred from the package.json in the workspace root. Please use getNpmScope instead. -NPM Scope that the workspace uses - -#### Inherited from - -[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[npmScope](../../devkit/documents/NxJsonConfiguration#npmscope) - ---- - ### nxCloudAccessToken • `Optional` **nxCloudAccessToken**: `string` diff --git a/docs/generated/devkit/WorkspaceConfiguration.md b/docs/generated/devkit/WorkspaceConfiguration.md deleted file mode 100644 index 7c006695f25444..00000000000000 --- a/docs/generated/devkit/WorkspaceConfiguration.md +++ /dev/null @@ -1,7 +0,0 @@ -# Type alias: WorkspaceConfiguration - -Ƭ **WorkspaceConfiguration**: `Omit`<[`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations), `"projects"`\> & `Partial`<[`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\> - -**`Deprecated`** - -using NxJsonConfiguration diff --git a/docs/generated/devkit/getWorkspaceLayout.md b/docs/generated/devkit/getWorkspaceLayout.md index da7038f5e44fb5..fbcfc611d92acc 100644 --- a/docs/generated/devkit/getWorkspaceLayout.md +++ b/docs/generated/devkit/getWorkspaceLayout.md @@ -8,7 +8,7 @@ and the default scope. Example: ```typescript -{ appsDir: 'apps', libsDir: 'libs', npmScope: 'myorg' } +{ appsDir: 'apps', libsDir: 'libs' } ``` #### Parameters @@ -21,9 +21,8 @@ Example: `Object` -| Name | Type | Description | -| :-------------------- | :-------- | :----------------------------------------------------------------------- | -| `appsDir` | `string` | - | -| `libsDir` | `string` | - | -| `npmScope` | `string` | **`Deprecated`** This will be removed in Nx 17. Use getNpmScope instead. | -| `standaloneAsDefault` | `boolean` | - | +| Name | Type | +| :-------------------- | :-------- | +| `appsDir` | `string` | +| `libsDir` | `string` | +| `standaloneAsDefault` | `boolean` | diff --git a/docs/generated/devkit/getWorkspacePath.md b/docs/generated/devkit/getWorkspacePath.md deleted file mode 100644 index 4a88bca3d9543b..00000000000000 --- a/docs/generated/devkit/getWorkspacePath.md +++ /dev/null @@ -1,17 +0,0 @@ -# Function: getWorkspacePath - -▸ **getWorkspacePath**(`tree`): `"angular.json"` \| `"workspace.json"` - -#### Parameters - -| Name | Type | -| :----- | :------------------------------------ | -| `tree` | [`Tree`](../../devkit/documents/Tree) | - -#### Returns - -`"angular.json"` \| `"workspace.json"` - -**`Deprecated`** - -all projects are configured using project.json diff --git a/docs/generated/devkit/isStandaloneProject.md b/docs/generated/devkit/isStandaloneProject.md deleted file mode 100644 index e4547ff615456b..00000000000000 --- a/docs/generated/devkit/isStandaloneProject.md +++ /dev/null @@ -1,20 +0,0 @@ -# Function: isStandaloneProject - -▸ **isStandaloneProject**(`tree`, `project`): `boolean` - -Returns if a project has a standalone configuration (project.json). - -#### Parameters - -| Name | Type | Description | -| :-------- | :------------------------------------ | :------------------- | -| `tree` | [`Tree`](../../devkit/documents/Tree) | the file system tree | -| `project` | `string` | the project name | - -#### Returns - -`boolean` - -**`Deprecated`** - -non-standalone projects were deprecated diff --git a/docs/generated/devkit/readWorkspaceConfiguration.md b/docs/generated/devkit/readWorkspaceConfiguration.md deleted file mode 100644 index 353e75819b177f..00000000000000 --- a/docs/generated/devkit/readWorkspaceConfiguration.md +++ /dev/null @@ -1,21 +0,0 @@ -# Function: readWorkspaceConfiguration - -▸ **readWorkspaceConfiguration**(`tree`): [`WorkspaceConfiguration`](../../devkit/documents/WorkspaceConfiguration) - -Read general workspace configuration such as the default project or cli settings - -This does _not_ provide projects configuration, use [readProjectConfiguration](../../devkit/documents/readProjectConfiguration) instead. - -#### Parameters - -| Name | Type | -| :----- | :------------------------------------ | -| `tree` | [`Tree`](../../devkit/documents/Tree) | - -#### Returns - -[`WorkspaceConfiguration`](../../devkit/documents/WorkspaceConfiguration) - -**`Deprecated`** - -use readNxJson diff --git a/docs/generated/devkit/updateWorkspaceConfiguration.md b/docs/generated/devkit/updateWorkspaceConfiguration.md deleted file mode 100644 index 3088473a6442c8..00000000000000 --- a/docs/generated/devkit/updateWorkspaceConfiguration.md +++ /dev/null @@ -1,22 +0,0 @@ -# Function: updateWorkspaceConfiguration - -▸ **updateWorkspaceConfiguration**(`tree`, `workspaceConfig`): `void` - -Update general workspace configuration such as the default project or cli settings. - -This does _not_ update projects configuration, use [updateProjectConfiguration](../../devkit/documents/updateProjectConfiguration) or [addProjectConfiguration](../../devkit/documents/addProjectConfiguration) instead. - -#### Parameters - -| Name | Type | -| :---------------- | :------------------------------------------------------------------------ | -| `tree` | [`Tree`](../../devkit/documents/Tree) | -| `workspaceConfig` | [`WorkspaceConfiguration`](../../devkit/documents/WorkspaceConfiguration) | - -#### Returns - -`void` - -**`Deprecated`** - -use updateNxJson diff --git a/docs/generated/packages/angular/generators/ng-add.json b/docs/generated/packages/angular/generators/ng-add.json index 62b08d00d378f2..dde983e2b1e1c2 100644 --- a/docs/generated/packages/angular/generators/ng-add.json +++ b/docs/generated/packages/angular/generators/ng-add.json @@ -9,11 +9,6 @@ "description": "Migrates an Angular CLI workspace to Nx or adds the Angular plugin to an Nx workspace. NOTE: Does not work in the `--dry-run` mode.", "type": "object", "properties": { - "npmScope": { - "type": "string", - "description": "Npm scope for importing libs. NOTE: only used if running the generator in an Angular CLI workspace.", - "x-deprecated": "This will be inferred from your root package.json" - }, "defaultBase": { "type": "string", "description": "Default base branch for affected. NOTE: only used if running the generator in an Angular CLI workspace.", diff --git a/docs/generated/packages/devkit/documents/nx_devkit.md b/docs/generated/packages/devkit/documents/nx_devkit.md index 9ff7a125e01a02..0137ec749db3c4 100644 --- a/docs/generated/packages/devkit/documents/nx_devkit.md +++ b/docs/generated/packages/devkit/documents/nx_devkit.md @@ -85,7 +85,6 @@ It only uses language primitives and immutable objects - [StringChange](../../devkit/documents/StringChange) - [TargetDefaults](../../devkit/documents/TargetDefaults) - [TaskGraphExecutor](../../devkit/documents/TaskGraphExecutor) -- [WorkspaceConfiguration](../../devkit/documents/WorkspaceConfiguration) - [WorkspaceJsonConfiguration](../../devkit/documents/WorkspaceJsonConfiguration) ### Variables @@ -117,11 +116,9 @@ It only uses language primitives and immutable objects - [getPackageManagerVersion](../../devkit/documents/getPackageManagerVersion) - [getProjects](../../devkit/documents/getProjects) - [getWorkspaceLayout](../../devkit/documents/getWorkspaceLayout) -- [getWorkspacePath](../../devkit/documents/getWorkspacePath) - [glob](../../devkit/documents/glob) - [hashArray](../../devkit/documents/hashArray) - [installPackagesTask](../../devkit/documents/installPackagesTask) -- [isStandaloneProject](../../devkit/documents/isStandaloneProject) - [joinPathFragments](../../devkit/documents/joinPathFragments) - [moveFilesToNewDirectory](../../devkit/documents/moveFilesToNewDirectory) - [names](../../devkit/documents/names) @@ -136,7 +133,6 @@ It only uses language primitives and immutable objects - [readProjectConfiguration](../../devkit/documents/readProjectConfiguration) - [readProjectsConfigurationFromProjectGraph](../../devkit/documents/readProjectsConfigurationFromProjectGraph) - [readTargetOptions](../../devkit/documents/readTargetOptions) -- [readWorkspaceConfiguration](../../devkit/documents/readWorkspaceConfiguration) - [removeDependenciesFromPackageJson](../../devkit/documents/removeDependenciesFromPackageJson) - [removeProjectConfiguration](../../devkit/documents/removeProjectConfiguration) - [reverse](../../devkit/documents/reverse) @@ -151,7 +147,6 @@ It only uses language primitives and immutable objects - [updateNxJson](../../devkit/documents/updateNxJson) - [updateProjectConfiguration](../../devkit/documents/updateProjectConfiguration) - [updateTsConfigsToJs](../../devkit/documents/updateTsConfigsToJs) -- [updateWorkspaceConfiguration](../../devkit/documents/updateWorkspaceConfiguration) - [validateDependency](../../devkit/documents/validateDependency) - [visitNotIgnoredFiles](../../devkit/documents/visitNotIgnoredFiles) - [workspaceLayout](../../devkit/documents/workspaceLayout) diff --git a/docs/shared/deprecated/default-collection.md b/docs/shared/deprecated/default-collection.md index 98642f41b9a662..171555e6933961 100644 --- a/docs/shared/deprecated/default-collection.md +++ b/docs/shared/deprecated/default-collection.md @@ -1,5 +1,9 @@ # defaultCollection +{% callout type="caution" title="Experimental" %} +Configuring `defaultCollection` will no longer have any effect in Nx 17+ +{% /callout %} + In the `nx.json` you can set a `defaultCollection` property like this: ```jsonc diff --git a/docs/shared/reference/nx-json.md b/docs/shared/reference/nx-json.md index bdfd125d0d7040..97081730af2443 100644 --- a/docs/shared/reference/nx-json.md +++ b/docs/shared/reference/nx-json.md @@ -53,7 +53,7 @@ The `npmScope` property of the `nx.json` file is deprecated as of version 16.2.0 In Nx 16, if the `npmScope` property is present, it will be used as a prefix. If the `npmScope` property is not present, the `name` property of the root `package.json` file will be used to infer the prefix. -In Nx 17, the `npmScope` property will be ignored. +In Nx 17, the `npmScope` property is ignored. ### Affected diff --git a/e2e/plugin/src/nx-plugin.test.ts b/e2e/plugin/src/nx-plugin.test.ts index 8f00ccd053074f..44cde5e6fe1aad 100644 --- a/e2e/plugin/src/nx-plugin.test.ts +++ b/e2e/plugin/src/nx-plugin.test.ts @@ -23,10 +23,10 @@ import { import { join } from 'path'; describe('Nx Plugin', () => { - let npmScope: string; + let workspaceName: string; beforeAll(() => { - npmScope = newProject(); + workspaceName = newProject(); }); afterAll(() => cleanupProject()); @@ -292,7 +292,7 @@ describe('Nx Plugin', () => { // Register plugin in nx.json (required for inference) updateFile(`nx.json`, (nxJson) => { const nx = JSON.parse(nxJson); - nx.plugins = [`@${npmScope}/${plugin}`]; + nx.plugins = [`@${workspaceName}/${plugin}`]; return JSON.stringify(nx, null, 2); }); @@ -315,7 +315,7 @@ describe('Nx Plugin', () => { const nx = JSON.parse(nxJson); nx.plugins = [ { - plugin: `@${npmScope}/${plugin}`, + plugin: `@${workspaceName}/${plugin}`, options: { inferredTags: ['my-tag'] }, }, ]; @@ -351,13 +351,13 @@ describe('Nx Plugin', () => { ); runCLI( - `generate @${npmScope}/${plugin}:${generator} --name ${generatedProject}` + `generate @${workspaceName}/${plugin}:${generator} --name ${generatedProject}` ); updateFile(`libs/${generatedProject}/project.json`, (f) => { const project: ProjectConfiguration = JSON.parse(f); project.targets['execute'] = { - executor: `@${npmScope}/${plugin}:${executor}`, + executor: `@${workspaceName}/${plugin}:${executor}`, }; return JSON.stringify(project, null, 2); }); @@ -383,7 +383,9 @@ describe('Nx Plugin', () => { ); runCLI( - `generate @${npmScope}/${plugin}:${generator} --name ${uniq('test')}` + `generate @${workspaceName}/${plugin}:${generator} --name ${uniq( + 'test' + )}` ); }).not.toThrow(); updateFile('package.json', JSON.stringify(oldPackageJson, null, 2)); diff --git a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts index cccf256a10c3a4..2cf6e5c517ccfb 100644 --- a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts +++ b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts @@ -213,13 +213,6 @@ describe('workspace', () => { expect(tree.exists('angular.json')).toBe(false); }); - it('should set the default collection to @nx/angular', async () => { - await migrateFromAngularCli(tree, {}); - expect( - readJson(tree, 'nx.json').cli?.defaultCollection - ).not.toBeDefined(); - }); - it('should set the default project correctly', async () => { await migrateFromAngularCli(tree, {}); expect(readJson(tree, 'nx.json').defaultProject).toBe('myApp'); diff --git a/packages/angular/src/generators/ng-add/schema.d.ts b/packages/angular/src/generators/ng-add/schema.d.ts index c8b70ab4f93bb6..eb37f86ee1249a 100644 --- a/packages/angular/src/generators/ng-add/schema.d.ts +++ b/packages/angular/src/generators/ng-add/schema.d.ts @@ -3,10 +3,6 @@ import { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners'; import type { Styles } from '../utils/types'; export interface GeneratorOptions { - /** - * @deprecated This should be inferred with {@link getNpmScope} - */ - npmScope?: string; defaultBase?: string; unitTestRunner?: UnitTestRunner; diff --git a/packages/angular/src/generators/ng-add/schema.json b/packages/angular/src/generators/ng-add/schema.json index 6a816d34498124..8ada29d6e3b51f 100644 --- a/packages/angular/src/generators/ng-add/schema.json +++ b/packages/angular/src/generators/ng-add/schema.json @@ -6,11 +6,6 @@ "description": "Migrates an Angular CLI workspace to Nx or adds the Angular plugin to an Nx workspace. NOTE: Does not work in the `--dry-run` mode.", "type": "object", "properties": { - "npmScope": { - "type": "string", - "description": "Npm scope for importing libs. NOTE: only used if running the generator in an Angular CLI workspace.", - "x-deprecated": "This will be inferred from your root package.json" - }, "defaultBase": { "type": "string", "description": "Default base branch for affected. NOTE: only used if running the generator in an Angular CLI workspace.", diff --git a/packages/angular/test-setup.ts b/packages/angular/test-setup.ts index 0ded8a0f312262..40120202cd8d5a 100644 --- a/packages/angular/test-setup.ts +++ b/packages/angular/test-setup.ts @@ -11,7 +11,6 @@ const allowedProjectExtensions = [ const allowedWorkspaceExtensions = [ 'implicitDependencies', 'affected', - 'npmScope', 'tasksRunnerOptions', 'workspaceLayout', 'plugins', diff --git a/packages/devkit/src/generators/project-name-and-root-utils.spec.ts b/packages/devkit/src/generators/project-name-and-root-utils.spec.ts index 9ebc0d11a98ae7..7a46f01096a4a5 100644 --- a/packages/devkit/src/generators/project-name-and-root-utils.spec.ts +++ b/packages/devkit/src/generators/project-name-and-root-utils.spec.ts @@ -5,6 +5,7 @@ import { updateJson } from 'nx/src/generators/utils/json'; import { workspaceRoot } from 'nx/src/utils/workspace-root'; import { join } from 'path'; import { determineProjectNameAndRootOptions } from './project-name-and-root-utils'; +import { setCwd } from '../../internal-testing-utils'; describe('determineProjectNameAndRootOptions', () => { let tree: Tree; @@ -33,6 +34,9 @@ describe('determineProjectNameAndRootOptions', () => { describe('no layout', () => { beforeEach(() => { tree = createTreeWithEmptyWorkspace(); + + setCwd(''); + jest.clearAllMocks(); }); @@ -297,23 +301,6 @@ describe('determineProjectNameAndRootOptions', () => { }); }); - it('should derive import path for root projects when package.json does not have a name and format is as-provided', async () => { - updateJson(tree, 'package.json', (json) => { - json.name = undefined; - return json; - }); - - const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - rootProject: true, - callingGenerator: '', - }); - - expect(result.importPath).toBe('@proj/libName'); - }); - it('should throw when an invalid name is provided', async () => { await expect( determineProjectNameAndRootOptions(tree, { @@ -384,23 +371,6 @@ describe('determineProjectNameAndRootOptions', () => { }); }); - it('should derive import path for root projects when package.json does not have a name and format is "derived"', async () => { - updateJson(tree, 'package.json', (json) => { - json.name = undefined; - return json; - }); - - const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - projectType: 'library', - projectNameAndRootFormat: 'derived', - rootProject: true, - callingGenerator: '', - }); - - expect(result.importPath).toBe('@proj/lib-name'); - }); - it(`should handle window's style paths correctly when format is "derived"`, async () => { const result = await determineProjectNameAndRootOptions(tree, { name: 'libName', @@ -650,23 +620,6 @@ describe('determineProjectNameAndRootOptions', () => { }); }); - it('should derive import path for root projects when package.json does not have a name and format is "as-provided"', async () => { - updateJson(tree, 'package.json', (json) => { - json.name = undefined; - return json; - }); - - const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - rootProject: true, - callingGenerator: '', - }); - - expect(result.importPath).toBe('@proj/libName'); - }); - it('should throw when an invalid name is provided', async () => { await expect( determineProjectNameAndRootOptions(tree, { @@ -759,23 +712,6 @@ describe('determineProjectNameAndRootOptions', () => { }); }); - it('should derive import path for root projects when package.json does not have a name and format is "derived"', async () => { - updateJson(tree, 'package.json', (json) => { - json.name = undefined; - return json; - }); - - const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - projectType: 'library', - projectNameAndRootFormat: 'derived', - rootProject: true, - callingGenerator: '', - }); - - expect(result.importPath).toBe('@proj/lib-name'); - }); - it('should prompt for the project name and root format', async () => { // simulate interactive mode ensureInteractiveMode(); diff --git a/packages/devkit/src/generators/project-name-and-root-utils.ts b/packages/devkit/src/generators/project-name-and-root-utils.ts index cc4b5093ae337b..7700d23f625d5c 100644 --- a/packages/devkit/src/generators/project-name-and-root-utils.ts +++ b/packages/devkit/src/generators/project-name-and-root-utils.ts @@ -1,7 +1,7 @@ import { prompt } from 'enquirer'; import type { ProjectType } from 'nx/src/config/workspace-json-project-json'; import type { Tree } from 'nx/src/generators/tree'; -import { relative } from 'path'; +import { join, relative } from 'path'; import { requireNx } from '../../nx'; import { extractLayoutDirectory, @@ -14,8 +14,6 @@ const { normalizePath, logger, readJson, - readNxJson, - updateNxJson, stripIndents, workspaceRoot, } = requireNx(); @@ -329,13 +327,6 @@ function getImportPath(npmScope: string | undefined, name: string) { } function getNpmScope(tree: Tree): string | undefined { - const nxJson = readNxJson(tree); - - // TODO(v17): Remove reading this from nx.json - if (nxJson?.npmScope) { - return nxJson.npmScope; - } - const { name } = tree.exists('package.json') ? readJson<{ name?: string }>(tree, 'package.json') : { name: null }; @@ -358,3 +349,10 @@ function getCwd(): string { ? process.env.INIT_CWD : process.cwd(); } + +/** + * Function for setting cwd during testing + */ +export function setCwd(path: string): void { + process.env.INIT_CWD = join(workspaceRoot, path); +} diff --git a/packages/devkit/src/utils/get-workspace-layout.ts b/packages/devkit/src/utils/get-workspace-layout.ts index 5564e44495fd85..a173c5d193cc1c 100644 --- a/packages/devkit/src/utils/get-workspace-layout.ts +++ b/packages/devkit/src/utils/get-workspace-layout.ts @@ -10,7 +10,7 @@ const { readNxJson } = requireNx(); * Example: * * ```typescript - * { appsDir: 'apps', libsDir: 'libs', npmScope: 'myorg' } + * { appsDir: 'apps', libsDir: 'libs' } * ``` * @param tree - file system tree */ @@ -18,10 +18,6 @@ export function getWorkspaceLayout(tree: Tree): { appsDir: string; libsDir: string; standaloneAsDefault: boolean; - /** - * @deprecated This will be removed in Nx 17. Use {@link getNpmScope} instead. - */ - npmScope: string; } { const nxJson = readNxJson(tree); return { @@ -31,7 +27,6 @@ export function getWorkspaceLayout(tree: Tree): { libsDir: nxJson?.workspaceLayout?.libsDir ?? inOrderOfPreference(tree, ['libs', 'packages'], '.'), - npmScope: nxJson?.npmScope, standaloneAsDefault: true, }; } diff --git a/packages/eslint/src/executors/lint/lint.impl.spec.ts b/packages/eslint/src/executors/lint/lint.impl.spec.ts index b00e7c6a84fa91..96a2cef5935972 100644 --- a/packages/eslint/src/executors/lint/lint.impl.spec.ts +++ b/packages/eslint/src/executors/lint/lint.impl.spec.ts @@ -103,9 +103,7 @@ describe('Linter Builder', () => { }, }, }, - nxJsonConfiguration: { - npmScope: 'test', - }, + nxJsonConfiguration: {}, isVerbose: false, }; mockLintFiles.mockImplementation(() => mockReports); diff --git a/packages/jest/src/executors/jest/jest.impl.spec.ts b/packages/jest/src/executors/jest/jest.impl.spec.ts index bae58de6da8d03..26728946853423 100644 --- a/packages/jest/src/executors/jest/jest.impl.spec.ts +++ b/packages/jest/src/executors/jest/jest.impl.spec.ts @@ -50,9 +50,7 @@ describe('Jest Executor', () => { }, }, }, - nxJsonConfiguration: { - npmScope: 'test', - }, + nxJsonConfiguration: {}, target: { executor: '@nx/jest:jest', }, diff --git a/packages/js/src/executors/tsc/tsc.impl.spec.ts b/packages/js/src/executors/tsc/tsc.impl.spec.ts index 266b134cd13e72..8842387c2d8bf0 100644 --- a/packages/js/src/executors/tsc/tsc.impl.spec.ts +++ b/packages/js/src/executors/tsc/tsc.impl.spec.ts @@ -15,9 +15,7 @@ describe('tscExecutor', () => { version: 2, projects: {}, }, - nxJsonConfiguration: { - npmScope: 'test', - }, + nxJsonConfiguration: {}, isVerbose: false, projectName: 'example', targetName: 'build', diff --git a/packages/js/src/generators/setup-verdaccio/generator.spec.ts b/packages/js/src/generators/setup-verdaccio/generator.spec.ts index 47591785d2ec83..62663a75c6d851 100644 --- a/packages/js/src/generators/setup-verdaccio/generator.spec.ts +++ b/packages/js/src/generators/setup-verdaccio/generator.spec.ts @@ -17,7 +17,7 @@ describe('setup-verdaccio generator', () => { await generator(tree, options); const config = readJson(tree, 'project.json'); expect(config).toEqual({ - name: 'test-name', + name: '@proj/source', $schema: 'node_modules/nx/schemas/project-schema.json', targets: { 'local-registry': { @@ -51,7 +51,7 @@ describe('setup-verdaccio generator', () => { await generator(tree, options); const config = readJson(tree, 'project.json'); expect(config).toEqual({ - name: 'test-name', + name: '@proj/source', $schema: 'node_modules/nx/schemas/project-schema.json', targets: { 'local-registry': { diff --git a/packages/js/src/utils/package-json/get-npm-scope.ts b/packages/js/src/utils/package-json/get-npm-scope.ts index 61da6228c7d344..b309b757b0c50c 100644 --- a/packages/js/src/utils/package-json/get-npm-scope.ts +++ b/packages/js/src/utils/package-json/get-npm-scope.ts @@ -1,16 +1,9 @@ -import { Tree, readNxJson, readJson } from '@nx/devkit'; +import { readJson, Tree } from '@nx/devkit'; /** * Read the npm scope that a workspace should use by default */ export function getNpmScope(tree: Tree): string | undefined { - const nxJson = readNxJson(tree); - - // TODO(v17): Remove reading this from nx.json - if (nxJson?.npmScope) { - return nxJson.npmScope; - } - const { name } = tree.exists('package.json') ? readJson<{ name?: string }>(tree, 'package.json') : { name: null }; diff --git a/packages/nuxt/src/generators/init/__snapshots__/init.spec.ts.snap b/packages/nuxt/src/generators/init/__snapshots__/init.spec.ts.snap index 458afd4b89914d..4c421e02ed6b15 100644 --- a/packages/nuxt/src/generators/init/__snapshots__/init.spec.ts.snap +++ b/packages/nuxt/src/generators/init/__snapshots__/init.spec.ts.snap @@ -16,6 +16,6 @@ exports[`init should add nuxt dependencies 1`] = ` "vue": "^3.3.4", "vue-router": "^4.2.4", }, - "name": "test-name", + "name": "@proj/source", } `; diff --git a/packages/nx/migrations.json b/packages/nx/migrations.json index c65caa6ee065df..bea9737741c84f 100644 --- a/packages/nx/migrations.json +++ b/packages/nx/migrations.json @@ -71,6 +71,11 @@ "version": "17.0.0-beta.3", "description": "Use minimal config for tasksRunnerOptions", "implementation": "./src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options" + }, + "rm-default-collection-npm-scope": { + "version": "17.0.0-rc.1", + "description": "Migration for v17.0.0-rc.1", + "implementation": "./src/migrations/update-17-0-0/rm-default-collection-npm-scope" } } } diff --git a/packages/nx/plugins/package-json-workspaces.ts b/packages/nx/plugins/package-json-workspaces.ts index a4d3ec12c86901..6cf5e16c4feb10 100644 --- a/packages/nx/plugins/package-json-workspaces.ts +++ b/packages/nx/plugins/package-json-workspaces.ts @@ -56,12 +56,6 @@ export function buildProjectConfigurationFromPackageJson( } let name = packageJson.name ?? toProjectName(normalizedPath); - if (nxJson?.npmScope) { - const npmPrefix = `@${nxJson.npmScope}/`; - if (name.startsWith(npmPrefix)) { - name = name.replace(npmPrefix, ''); - } - } const projectType = nxJson?.workspaceLayout?.appsDir != nxJson?.workspaceLayout?.libsDir && nxJson?.workspaceLayout?.appsDir && diff --git a/packages/nx/schemas/nx-schema.json b/packages/nx/schemas/nx-schema.json index 14b80116fb82bc..6d27dac5d72975 100644 --- a/packages/nx/schemas/nx-schema.json +++ b/packages/nx/schemas/nx-schema.json @@ -20,11 +20,6 @@ }, "additionalProperties": false }, - "npmScope": { - "type": "string", - "description": "NPM Scope that the workspace uses.", - "deprecated": "This is inferred from the package.json in the workspace root instead." - }, "tasksRunnerOptions": { "type": "object", "additionalProperties": { @@ -221,10 +216,6 @@ "type": "string", "description": "The default package manager to use.", "enum": ["yarn", "pnpm", "npm"] - }, - "defaultCollection": { - "type": "string", - "description": "The default generator collection to use." } } }, diff --git a/packages/nx/src/adapter/compat.ts b/packages/nx/src/adapter/compat.ts index 399f07b264f227..4a122afa3c713f 100644 --- a/packages/nx/src/adapter/compat.ts +++ b/packages/nx/src/adapter/compat.ts @@ -53,7 +53,6 @@ export const allowedProjectExtensions = [ export const allowedWorkspaceExtensions = [ 'implicitDependencies', 'affected', - 'npmScope', 'tasksRunnerOptions', 'workspaceLayout', 'plugins', diff --git a/packages/nx/src/command-line/generate/generate.ts b/packages/nx/src/command-line/generate/generate.ts index 1d46352662f371..257f0ee4fb5781 100644 --- a/packages/nx/src/command-line/generate/generate.ts +++ b/packages/nx/src/command-line/generate/generate.ts @@ -22,8 +22,6 @@ import { workspaceRoot } from '../../utils/workspace-root'; import { NxJsonConfiguration } from '../../config/nx-json'; import { calculateDefaultProjectName } from '../../config/calculate-default-project-name'; import { findInstalledPlugins } from '../../utils/plugins/installed-plugins'; -import type { Arguments } from 'yargs'; -import { output } from '../../utils/output'; import { getGeneratorInformation } from './generator-utils'; export interface GenerateOptions { @@ -204,7 +202,6 @@ export function parseGeneratorString(value: string): { async function convertToGenerateOptions( generatorOptions: { [p: string]: any }, - defaultCollectionName: string, mode: 'generate' | 'new', projectsConfiguration?: ProjectsConfigurations ): Promise { @@ -219,7 +216,7 @@ async function convertToGenerateOptions( if (collection) { collectionName = collection; generatorName = generator; - } else if (!defaultCollectionName) { + } else { const generatorString = await promptForCollection( generatorDescriptor, interactive, @@ -228,9 +225,6 @@ async function convertToGenerateOptions( const parsedGeneratorString = parseGeneratorString(generatorString); collectionName = parsedGeneratorString.collection; generatorName = parsedGeneratorString.generator; - } else { - collectionName = defaultCollectionName; - generatorName = generatorDescriptor; } } else { collectionName = generatorOptions.collection as string; @@ -270,11 +264,6 @@ function throwInvalidInvocation(availableGenerators: string[]) { )})` ); } - -function readDefaultCollection(nxConfig: NxJsonConfiguration) { - return nxConfig.cli ? nxConfig.cli.defaultCollection : null; -} - export function printGenHelp( opts: GenerateOptions, schema: Schema, @@ -310,7 +299,6 @@ export async function generate(cwd: string, args: { [k: string]: any }) { return handleErrors(verbose, async () => { const opts = await convertToGenerateOptions( args, - readDefaultCollection(nxJsonConfiguration), 'generate', projectsConfigurations ); diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index 1abe6235872a64..cd583b164af28f 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -102,11 +102,6 @@ export interface NxJsonConfiguration { * Dependencies between different target names across all projects */ targetDefaults?: TargetDefaults; - /** - * @deprecated This is inferred from the package.json in the workspace root. Please use {@link getNpmScope} instead. - * NPM Scope that the workspace uses - */ - npmScope?: string; /** * Default options for `nx affected` */ @@ -158,10 +153,6 @@ export interface NxJsonConfiguration { cli?: { packageManager?: PackageManager; - /** - * @deprecated - defaultCollection is deprecated and will be removed - */ - defaultCollection?: string; defaultProjectName?: string; }; /** diff --git a/packages/nx/src/config/workspaces.spec.ts b/packages/nx/src/config/workspaces.spec.ts index 16c8511ac86fcb..1cb3f0c259eaf6 100644 --- a/packages/nx/src/config/workspaces.spec.ts +++ b/packages/nx/src/config/workspaces.spec.ts @@ -41,77 +41,6 @@ describe('Workspaces', () => { fs.cleanup(); }); - describe('readWorkspaceConfiguration', () => { - it('should be able to inline project configurations', async () => { - const standaloneConfig = libConfig('lib1'); - - const config = { - version: 2, - projects: { - lib1: 'libs/lib1', - lib2: libConfig('lib2'), - }, - }; - await fs.createFiles({ - 'libs/lib1/project.json': JSON.stringify(standaloneConfig), - 'libs/lib2/package.json': JSON.stringify({}), - 'libs/domain/lib3/package.json': JSON.stringify({}), - 'libs/domain/lib4/project.json': JSON.stringify({}), - 'workspace.json': JSON.stringify(config), - }); - - const workspaces = new Workspaces(fs.tempDir); - const resolved = workspaces.readWorkspaceConfiguration(); - expect(resolved.projects.lib1).toEqual(standaloneConfig); - }); - - it('should build project configurations from glob', async () => { - const lib1Config = libConfig('lib1'); - const lib2Config = packageLibConfig('libs/lib2'); - const domainPackageConfig = packageLibConfig( - 'libs/domain/lib3', - 'domain-lib3' - ); - const domainLibConfig = libConfig('domain/lib4'); - - await fs.createFiles({ - 'libs/lib1/project.json': JSON.stringify(lib1Config), - 'libs/lib1/package.json': JSON.stringify({ name: 'some-other-name' }), - 'libs/lib2/package.json': JSON.stringify({ name: 'lib2' }), - 'libs/domain/lib3/package.json': JSON.stringify({ - name: 'domain-lib3', - }), - 'libs/domain/lib4/project.json': JSON.stringify(domainLibConfig), - 'libs/domain/lib4/package.json': JSON.stringify({}), - 'package.json': JSON.stringify({ - name: 'package-name', - workspaces: ['**/package.json'], - }), - }); - - const workspaces = new Workspaces(fs.tempDir); - const { projects } = workspaces.readWorkspaceConfiguration(); - - // projects got merged for lib1 - expect(projects['lib1']).toEqual({ - name: 'lib1', - root: 'libs/lib1', - sourceRoot: 'libs/lib1/src', - projectType: 'library', - targets: { - 'nx-release-publish': { - dependsOn: ['^nx-release-publish'], - executor: '@nx/js:release-publish', - options: {}, - }, - }, - }); - expect(projects.lib2).toEqual(lib2Config); - expect(projects['domain-lib3']).toEqual(domainPackageConfig); - expect(projects['lib4']).toEqual(domainLibConfig); - }); - }); - describe('to project name', () => { it('should lowercase names', () => { const appResults = toProjectName('my-apps/directory/my-app/package.json'); diff --git a/packages/nx/src/devkit-exports.ts b/packages/nx/src/devkit-exports.ts index a14192dbc115f3..da6318e68f5913 100644 --- a/packages/nx/src/devkit-exports.ts +++ b/packages/nx/src/devkit-exports.ts @@ -122,17 +122,6 @@ export { */ export { glob } from './generators/utils/glob'; -/** - * @category Generators - */ -export { - readWorkspaceConfiguration, - updateWorkspaceConfiguration, - isStandaloneProject, - WorkspaceConfiguration, - getWorkspacePath, -} from './generators/utils/deprecated'; - /** * @category Generators */ diff --git a/packages/nx/src/generators/testing-utils/create-tree-with-empty-workspace.ts b/packages/nx/src/generators/testing-utils/create-tree-with-empty-workspace.ts index f3254d41feb5e0..f945aae2548d04 100644 --- a/packages/nx/src/generators/testing-utils/create-tree-with-empty-workspace.ts +++ b/packages/nx/src/generators/testing-utils/create-tree-with-empty-workspace.ts @@ -25,7 +25,7 @@ function addCommonFiles(tree: Tree, addAppsAndLibsFolders: boolean): Tree { tree.write( '/package.json', JSON.stringify({ - name: 'test-name', + name: '@proj/source', dependencies: {}, devDependencies: {}, }) @@ -33,7 +33,6 @@ function addCommonFiles(tree: Tree, addAppsAndLibsFolders: boolean): Tree { tree.write( '/nx.json', JSON.stringify({ - npmScope: 'proj', affected: { defaultBase: 'main', }, diff --git a/packages/nx/src/generators/utils/deprecated.ts b/packages/nx/src/generators/utils/deprecated.ts deleted file mode 100644 index 8fb25778fed7e7..00000000000000 --- a/packages/nx/src/generators/utils/deprecated.ts +++ /dev/null @@ -1,110 +0,0 @@ -import type { NxJsonConfiguration } from '../../config/nx-json'; -import { ProjectsConfigurations } from '../../config/workspace-json-project-json'; - -import type { Tree } from '../tree'; -import { readNxJson, updateNxJson } from './nx-json'; - -// TODO(v16): Remove this -/** - * @deprecated using NxJsonConfiguration - */ -export type WorkspaceConfiguration = Omit & - Partial; - -// TODO(v16): Remove this -/** - * 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, - workspaceConfig: WorkspaceConfiguration -): void { - const { - // Nx Json Properties - affected, - cacheDirectory, - cli, - defaultProject, - extends: ext, - generators, - implicitDependencies, - installation, - namedInputs, - npmScope, - nxCloudAccessToken, - nxCloudEncryptionKey, - nxCloudUrl, - parallel, - plugins, - pluginsConfig, - release, - targetDefaults, - tasksRunnerOptions, - useDaemonProcess, - workspaceLayout, - } = workspaceConfig; - - const nxJson: Required = { - affected, - cacheDirectory, - cli, - defaultProject, - extends: ext, - generators, - implicitDependencies, - installation, - namedInputs, - npmScope, - nxCloudAccessToken, - nxCloudEncryptionKey, - nxCloudUrl, - parallel, - plugins, - pluginsConfig, - release, - targetDefaults, - tasksRunnerOptions, - useDaemonProcess, - workspaceLayout, - }; - - updateNxJson(tree, nxJson); -} - -// TODO(v16): Remove this -/** - * Returns if a project has a standalone configuration (project.json). - * - * @param tree - the file system tree - * @param project - the project name - * - * @deprecated non-standalone projects were deprecated - */ -export function isStandaloneProject(tree: Tree, project: string): boolean { - return true; -} - -// TODO(v16): Remove this -/** - * 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 { - return readNxJson(tree) as any; -} - -// TODO(v16): Remove this -/** - * @deprecated all projects are configured using project.json - */ -export function getWorkspacePath(tree: Tree) { - if (tree.exists('workspace.json')) return 'workspace.json'; - if (tree.exists('angular.json')) return 'angular.json'; - return null; -} diff --git a/packages/nx/src/generators/utils/project-configuration.ts b/packages/nx/src/generators/utils/project-configuration.ts index 985d02b940eda7..9130323a8a46ab 100644 --- a/packages/nx/src/generators/utils/project-configuration.ts +++ b/packages/nx/src/generators/utils/project-configuration.ts @@ -26,13 +26,6 @@ import type { Tree } from '../tree'; import minimatch = require('minimatch'); export { readNxJson, updateNxJson } from './nx-json'; -export { - readWorkspaceConfiguration, - updateWorkspaceConfiguration, - isStandaloneProject, - getWorkspacePath, - WorkspaceConfiguration, -} from './deprecated'; /** * Adds project configuration to the Nx workspace. diff --git a/packages/nx/src/migrations/update-17-0-0/rm-default-collection-npm-scope.spec.ts b/packages/nx/src/migrations/update-17-0-0/rm-default-collection-npm-scope.spec.ts new file mode 100644 index 00000000000000..cee4a5649c4d4d --- /dev/null +++ b/packages/nx/src/migrations/update-17-0-0/rm-default-collection-npm-scope.spec.ts @@ -0,0 +1,53 @@ +import { createTree } from '../../generators/testing-utils/create-tree'; +import update from './rm-default-collection-npm-scope'; +import { readJson, updateJson, writeJson } from '../../generators/utils/json'; +import { NxJsonConfiguration } from '../../config/nx-json'; +import { Tree } from '../../generators/tree'; + +describe('rm-default-collection-npm-scope migration', () => { + let tree: Tree; + beforeEach(() => { + tree = createTree(); + }); + + describe('with nx.json', () => { + beforeEach(() => { + writeJson(tree, 'nx.json', { + affected: { + defaultBase: 'master', + }, + npmScope: 'scope', + cli: { + defaultCollection: 'collection', + }, + } as NxJsonConfiguration & { npmScope: string; cli: { defaultCollection: string } }); + }); + + it('should remove npmScope', async () => { + await update(tree); + expect(readJson(tree, 'nx.json').npmScope).not.toBeDefined(); + }); + + it('should remove defaultCollection', async () => { + updateJson(tree, 'nx.json', (json) => { + json.cli.packageManager = 'npm'; + return json; + }); + await update(tree); + expect(readJson(tree, 'nx.json').cli).toEqual({ + packageManager: 'npm', + }); + }); + + it('should remove cli', async () => { + await update(tree); + expect(readJson(tree, 'nx.json').cli).not.toBeDefined(); + }); + }); + + describe('without nx.json', () => { + it('should run successfully', async () => { + await update(tree); + }); + }); +}); diff --git a/packages/nx/src/migrations/update-17-0-0/rm-default-collection-npm-scope.ts b/packages/nx/src/migrations/update-17-0-0/rm-default-collection-npm-scope.ts new file mode 100644 index 00000000000000..940ada93aab4fb --- /dev/null +++ b/packages/nx/src/migrations/update-17-0-0/rm-default-collection-npm-scope.ts @@ -0,0 +1,96 @@ +import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; +import { Tree } from '../../generators/tree'; +import { readNxJson, updateNxJson } from '../../generators/utils/nx-json'; +import { readJson } from '../../generators/utils/json'; +import { logger } from '../../utils/logger'; +import { NxJsonConfiguration } from '../../config/nx-json'; +import { joinPathFragments } from '../../utils/path'; + +export default async function update(tree: Tree) { + if (!tree.exists('nx.json')) { + return; + } + + const nxJson = readNxJson(tree); + + delete nxJson.cli?.['defaultCollection']; + + if (Object.keys(nxJson.cli).length < 1) { + delete nxJson.cli; + } + + warnNpmScopeHasChanged(tree, nxJson); + + delete nxJson['npmScope']; + + updateNxJson(tree, nxJson); + + await formatChangedFilesWithPrettierIfAvailable(tree); +} + +function warnNpmScopeHasChanged( + tree: Tree, + nxJson: NxJsonConfiguration +): boolean { + const originalScope = nxJson['npmScope']; + + // There was no original scope + if (!originalScope) { + return false; + } + + // package.json does not exist + if (!tree.exists('package.json')) { + return false; + } + + const newScope = getNpmScopeFromPackageJson(tree); + + // New and Original scope are the same. + if (originalScope === newScope) { + return false; + } + + const packageJsonName = readJson(tree, 'package.json').name; + + if (newScope) { + logger.warn({ + title: 'npmScope has been removed from nx.json', + bodyLines: [ + 'This will now be read from package.json', + `Old value which was in nx.json: ${originalScope}`, + `New value from package.json: ${newScope}`, + `Typescript path mappings for new libraries will now be generated as such: @${newScope}/new-lib instead of @${originalScope}/new-lib`, + `If you would like to change this back, change the name in package.json to ${packageJsonName.replace( + newScope, + originalScope + )}`, + ], + }); + } else { + // There is no scope in package.json + logger.warn({ + title: 'npmScope has been removed from nx.json', + bodyLines: [ + 'This will now be read from package.json', + `Old value which was in nx.json: ${originalScope}`, + `New value from package.json: null`, + `Typescript path mappings for new libraries will now be generated as such: new-lib instead of @${originalScope}/new-lib`, + `If you would like to change this back, change the name in package.json to ${joinPathFragments( + `@${originalScope}`, + packageJsonName + )}`, + ], + }); + } +} + +function getNpmScopeFromPackageJson(tree: Tree) { + const { name } = tree.exists('package.json') + ? readJson<{ name?: string }>(tree, 'package.json') + : { name: null }; + + if (name?.startsWith('@')) { + return name.split('/')[0].substring(1); + } +} diff --git a/packages/nx/src/plugins/js/project-graph/affected/npm-packages.spec.ts b/packages/nx/src/plugins/js/project-graph/affected/npm-packages.spec.ts index 957d5a9addcf36..b5c7992a4ed857 100644 --- a/packages/nx/src/plugins/js/project-graph/affected/npm-packages.spec.ts +++ b/packages/nx/src/plugins/js/project-graph/affected/npm-packages.spec.ts @@ -16,9 +16,7 @@ describe('getTouchedNpmPackages', () => { proj2: {}, }, }; - nxJson = { - npmScope: 'scope', - }; + nxJson = {}; projectGraph = { nodes: { proj1: { diff --git a/packages/nx/src/plugins/js/project-graph/affected/tsconfig-json-changes.spec.ts b/packages/nx/src/plugins/js/project-graph/affected/tsconfig-json-changes.spec.ts index aa55a54aa4a2c2..75c82d7b034c6e 100644 --- a/packages/nx/src/plugins/js/project-graph/affected/tsconfig-json-changes.spec.ts +++ b/packages/nx/src/plugins/js/project-graph/affected/tsconfig-json-changes.spec.ts @@ -56,9 +56,7 @@ describe('getTouchedProjectsFromTsConfig', () => { }, ], {}, - { - npmScope: 'proj', - } + {} ); expect(result).toEqual([]); }); diff --git a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.spec.ts b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.spec.ts index a565b7db1b9c50..5cf832fb6f26e7 100644 --- a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.spec.ts +++ b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.spec.ts @@ -31,9 +31,7 @@ describe('explicit package json dependencies', () => { }, }; - const nxJsonConfiguration = { - npmScope: 'proj', - }; + const nxJsonConfiguration = {}; await tempFs.createFiles({ './package.json': `{ diff --git a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.ts b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.ts index cb5f9d3eac0831..58ba45c8843b86 100644 --- a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.ts +++ b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.ts @@ -25,9 +25,7 @@ export function buildExplicitPackageJsonDependencies( Object.values(ctx.filesToProcess.projectFileMap[source]).forEach((f) => { if (isPackageJsonAtProjectRoot(nodes, f.file)) { // we only create the package name map once and only if a package.json file changes - packageNameMap = - packageNameMap || - createPackageNameMap(ctx.nxJsonConfiguration, ctx.projects); + packageNameMap = packageNameMap || createPackageNameMap(ctx.projects); processPackageJson(source, f.file, ctx, res, packageNameMap); } }); @@ -35,24 +33,14 @@ export function buildExplicitPackageJsonDependencies( return res; } -function createPackageNameMap( - nxJsonConfiguration: NxJsonConfiguration, - projects: ProjectsConfigurations['projects'] -) { +function createPackageNameMap(projects: ProjectsConfigurations['projects']) { const res = {}; for (let projectName of Object.keys(projects)) { try { const packageJson = parseJson( defaultFileRead(join(projects[projectName].root, 'package.json')) ); - // TODO(v17): Stop reading nx.json for the npmScope - const npmScope = nxJsonConfiguration.npmScope; - res[ - packageJson.name ?? - (npmScope - ? `${npmScope === '@' ? '' : '@'}${npmScope}/${projectName}` - : projectName) - ] = projectName; + res[packageJson.name ?? projectName] = projectName; } catch (e) {} } return res; diff --git a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.spec.ts b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.spec.ts index 65f180f588a8c9..b3207602f642ef 100644 --- a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.spec.ts +++ b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.spec.ts @@ -476,9 +476,7 @@ interface VirtualWorkspaceConfig { async function createContext( config: VirtualWorkspaceConfig ): Promise { - const nxJson = { - npmScope: 'proj', - }; + const nxJson = {}; const projectsFs = { [`./libs/${config.source}/project.json`]: JSON.stringify({ name: config.source, diff --git a/packages/nx/src/project-graph/affected/locators/workspace-json-changes.spec.ts b/packages/nx/src/project-graph/affected/locators/workspace-json-changes.spec.ts index 9e1ffcff45bcd3..b9d7328001afe2 100644 --- a/packages/nx/src/project-graph/affected/locators/workspace-json-changes.spec.ts +++ b/packages/nx/src/project-graph/affected/locators/workspace-json-changes.spec.ts @@ -13,9 +13,7 @@ describe('getTouchedProjectsInWorkspaceJson', () => { }, ], {}, - { - npmScope: 'proj', - } + {} ); expect(result).toEqual([]); }); diff --git a/packages/nx/src/project-graph/nx-deps-cache.spec.ts b/packages/nx/src/project-graph/nx-deps-cache.spec.ts index e0960c3cdbaa64..18e14441eda80b 100644 --- a/packages/nx/src/project-graph/nx-deps-cache.spec.ts +++ b/packages/nx/src/project-graph/nx-deps-cache.spec.ts @@ -346,7 +346,6 @@ describe('nx deps utils', () => { function createNxJson(p: Partial): NxJsonConfiguration { const defaults: NxJsonConfiguration = { - npmScope: '', workspaceLayout: {} as any, plugins: ['plugin'], }; diff --git a/packages/nx/src/tasks-runner/run-command.spec.ts b/packages/nx/src/tasks-runner/run-command.spec.ts index b8a8f61465d7f3..786033792ea743 100644 --- a/packages/nx/src/tasks-runner/run-command.spec.ts +++ b/packages/nx/src/tasks-runner/run-command.spec.ts @@ -10,9 +10,7 @@ describe('getRunner', () => { let overrides: any; beforeEach(() => { - nxJson = { - npmScope: 'proj', - }; + nxJson = {}; mockRunner = jest.fn(); }); diff --git a/packages/plugin/src/generators/plugin/plugin.spec.ts b/packages/plugin/src/generators/plugin/plugin.spec.ts index 20ca43d2d73a4c..0fa3c8f1e092f5 100644 --- a/packages/plugin/src/generators/plugin/plugin.spec.ts +++ b/packages/plugin/src/generators/plugin/plugin.spec.ts @@ -4,6 +4,7 @@ import { readJson, readProjectConfiguration, Tree, + updateJson, } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { Linter } from '@nx/eslint'; @@ -242,10 +243,10 @@ describe('NxPlugin Plugin Generator', () => { }); it('should correctly setup npmScope less workspaces', async () => { - // remove the npmScope from nx.json - const nxJson = JSON.parse(tree.read('nx.json')!.toString()); - delete nxJson.npmScope; - tree.write('nx.json', JSON.stringify(nxJson)); + updateJson(tree, 'package.json', (j) => { + j.name = 'source'; + return j; + }); await pluginGenerator(tree, getSchema()); diff --git a/packages/plugin/src/generators/preset/generator.spec.ts b/packages/plugin/src/generators/preset/generator.spec.ts index 3fbaea373763a2..14dfc06ffbbbac 100644 --- a/packages/plugin/src/generators/preset/generator.spec.ts +++ b/packages/plugin/src/generators/preset/generator.spec.ts @@ -19,6 +19,5 @@ describe('preset generator', () => { expect(config).toBeDefined(); const packageJson = readJson(tree, 'package.json'); expect(packageJson.dependencies).toHaveProperty('@nx/devkit'); - expect(readJson(tree, 'nx.json').npmScope).not.toBeDefined(); }); }); diff --git a/packages/plugin/src/generators/preset/generator.ts b/packages/plugin/src/generators/preset/generator.ts index 5f9478cbf8dcdc..7eb0626183c4e5 100644 --- a/packages/plugin/src/generators/preset/generator.ts +++ b/packages/plugin/src/generators/preset/generator.ts @@ -1,12 +1,10 @@ import { - Tree, - updateJson, - updateNxJson, - readNxJson, formatFiles, - runTasksInSerial, GeneratorCallback, names, + runTasksInSerial, + Tree, + updateJson, } from '@nx/devkit'; import { Linter } from '@nx/eslint'; import { PackageJson } from 'nx/src/utils/package-json'; @@ -43,7 +41,6 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) { }); tasks.push(pluginTask); - removeNpmScope(tree); moveNxPluginToDevDeps(tree); if (options.createPackageName) { @@ -65,11 +62,6 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) { return runTasksInSerial(...tasks); } - -function removeNpmScope(tree: Tree) { - updateNxJson(tree, { ...readNxJson(tree), npmScope: undefined }); -} - function moveNxPluginToDevDeps(tree: Tree) { updateJson(tree, 'package.json', (json) => { const nxPluginEntry = json.dependencies['@nx/plugin']; diff --git a/packages/rollup/src/executors/rollup/rollup.impl.spec.ts b/packages/rollup/src/executors/rollup/rollup.impl.spec.ts index e088a2f7c05afb..aaa69f167b2c28 100644 --- a/packages/rollup/src/executors/rollup/rollup.impl.spec.ts +++ b/packages/rollup/src/executors/rollup/rollup.impl.spec.ts @@ -18,9 +18,7 @@ describe('rollupExecutor', () => { version: 2, projects: {}, }, - nxJsonConfiguration: { - npmScope: 'test', - }, + nxJsonConfiguration: {}, isVerbose: false, projectName: 'example', targetName: 'build', diff --git a/packages/storybook/src/generators/init/__snapshots__/init.spec.ts.snap b/packages/storybook/src/generators/init/__snapshots__/init.spec.ts.snap index c573aff615cf1c..f2a4c23267d6ed 100644 --- a/packages/storybook/src/generators/init/__snapshots__/init.spec.ts.snap +++ b/packages/storybook/src/generators/init/__snapshots__/init.spec.ts.snap @@ -20,6 +20,6 @@ exports[`@nx/storybook:init dependencies for package.json should add angular rel "prettier": "^2.6.2", "typescript": "~5.1.3", }, - "name": "test-name", + "name": "@proj/source", } `; diff --git a/packages/storybook/src/migrations/update-16-5-0/__snapshots__/move-storybook-tsconfig.spec.ts.snap b/packages/storybook/src/migrations/update-16-5-0/__snapshots__/move-storybook-tsconfig.spec.ts.snap index e79a3cdd5ed04b..09131788e0d6c2 100644 --- a/packages/storybook/src/migrations/update-16-5-0/__snapshots__/move-storybook-tsconfig.spec.ts.snap +++ b/packages/storybook/src/migrations/update-16-5-0/__snapshots__/move-storybook-tsconfig.spec.ts.snap @@ -103,7 +103,6 @@ exports[`Ignore @nx/react/plugins/storybook in Storybook eslint plugin should up "!{projectRoot}/tsconfig.storybook.json", ], }, - "npmScope": "proj", "targetDefaults": { "build": { "cache": true, diff --git a/packages/vite/src/generators/init/__snapshots__/init.spec.ts.snap b/packages/vite/src/generators/init/__snapshots__/init.spec.ts.snap index 727d5d2647a6c9..71e71aead066db 100644 --- a/packages/vite/src/generators/init/__snapshots__/init.spec.ts.snap +++ b/packages/vite/src/generators/init/__snapshots__/init.spec.ts.snap @@ -18,7 +18,7 @@ exports[`@nx/vite:init dependencies for package.json should add vite packages an "vite": "~4.3.9", "vitest": "~0.32.0", }, - "name": "test-name", + "name": "@proj/source", } `; @@ -37,7 +37,7 @@ exports[`@nx/vite:init dependencies for package.json should support --testEnviro "vite": "~4.3.9", "vitest": "~0.32.0", }, - "name": "test-name", + "name": "@proj/source", } `; @@ -56,7 +56,7 @@ exports[`@nx/vite:init dependencies for package.json should support --testEnviro "vite": "~4.3.9", "vitest": "~0.32.0", }, - "name": "test-name", + "name": "@proj/source", } `; @@ -75,6 +75,6 @@ exports[`@nx/vite:init dependencies for package.json should support --testEnviro "vite": "~4.3.9", "vitest": "~0.32.0", }, - "name": "test-name", + "name": "@proj/source", } `; diff --git a/packages/vue/src/generators/init/__snapshots__/init.spec.ts.snap b/packages/vue/src/generators/init/__snapshots__/init.spec.ts.snap index 64b850d100fecf..3cddc31b16801b 100644 --- a/packages/vue/src/generators/init/__snapshots__/init.spec.ts.snap +++ b/packages/vue/src/generators/init/__snapshots__/init.spec.ts.snap @@ -18,6 +18,6 @@ exports[`init should add vue dependencies 1`] = ` "prettier": "^2.6.2", "typescript": "~5.1.3", }, - "name": "test-name", + "name": "@proj/source", } `; diff --git a/packages/vue/src/generators/library/__snapshots__/library.spec.ts.snap b/packages/vue/src/generators/library/__snapshots__/library.spec.ts.snap index 7cf8e38de5aaa1..ece74394dd505a 100644 --- a/packages/vue/src/generators/library/__snapshots__/library.spec.ts.snap +++ b/packages/vue/src/generators/library/__snapshots__/library.spec.ts.snap @@ -66,7 +66,7 @@ exports[`lib should add correct jest.config.ts and dependencies to package.json "ts-node": "10.9.1", "typescript": "~5.1.3", }, - "name": "test-name", + "name": "@proj/source", } `; @@ -262,7 +262,7 @@ exports[`lib should add vue, vite and vitest to package.json 1`] = ` "vite": "~4.3.9", "vitest": "~0.32.0", }, - "name": "test-name", + "name": "@proj/source", } `; diff --git a/packages/web/src/generators/application/application.ts b/packages/web/src/generators/application/application.ts index 3e61bea6a99659..8b48d39fe53892 100644 --- a/packages/web/src/generators/application/application.ts +++ b/packages/web/src/generators/application/application.ts @@ -27,6 +27,7 @@ import { join } from 'path'; import { nxVersion, swcLoaderVersion } from '../../utils/versions'; import { webInitGenerator } from '../init/init'; import { Schema } from './schema'; +import { getNpmScope } from '@nx/js/src/utils/package-json/get-npm-scope'; interface NormalizedSchema extends Schema { projectName: string; @@ -385,7 +386,7 @@ async function normalizeOptions( const e2eProjectName = `${appProjectName}-e2e`; const e2eProjectRoot = `${appProjectRoot}-e2e`; - const { npmScope } = getWorkspaceLayout(host); + const npmScope = getNpmScope(host); const parsedTags = options.tags ? options.tags.split(',').map((s) => s.trim()) diff --git a/packages/workspace/src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin.ts b/packages/workspace/src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin.ts index 0194c9c0844fd1..5f934632ccb756 100644 --- a/packages/workspace/src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin.ts +++ b/packages/workspace/src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin.ts @@ -22,6 +22,7 @@ import { moveGenerator } from '../../generators/move/move'; import { nxVersion } from '../../utils/versions'; import { PackageJson } from 'nx/src/utils/package-json'; import { posix } from 'path'; +import { getNpmScope } from '../../utilities/get-import-path'; const PROJECT_NAME = 'workspace-plugin'; const DESTINATION = `tools/${PROJECT_NAME}`; @@ -170,7 +171,7 @@ async function createNewPlugin(tree: Tree) { // nx-ignore-next-line const { Linter } = ensurePackage('@nx/eslint', nxVersion); - const { npmScope } = getWorkspaceLayout(tree); + const npmScope = getNpmScope(tree); const importPath = npmScope ? `@${npmScope}/${PROJECT_NAME}` : PROJECT_NAME; await pluginGenerator(tree, { diff --git a/packages/workspace/src/utilities/get-import-path.ts b/packages/workspace/src/utilities/get-import-path.ts index 6f2bc2e8f164c8..054c1cefc18a10 100644 --- a/packages/workspace/src/utilities/get-import-path.ts +++ b/packages/workspace/src/utilities/get-import-path.ts @@ -1,5 +1,4 @@ import { Tree } from 'nx/src/generators/tree'; -import { readNxJson } from 'nx/src/generators/utils/nx-json'; import { readJson } from 'nx/src/generators/utils/json'; export function getImportPath(tree: Tree, projectDirectory: string): string { @@ -10,13 +9,6 @@ export function getImportPath(tree: Tree, projectDirectory: string): string { } export function getNpmScope(tree: Tree) { - const nxJson = readNxJson(tree); - - // TODO(v17): Remove reading this from nx.json - if (nxJson.npmScope) { - return nxJson.npmScope; - } - const { name } = tree.exists('package.json') ? readJson<{ name?: string }>(tree, 'package.json') : { name: null };