From 9fbfe4a95a0b15d0771c950199e54b25367a4b59 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Tue, 5 Sep 2023 09:25:50 -0400 Subject: [PATCH] =?UTF-8?q?feat(misc):=20stop=20generating=20empty=20apps/?= =?UTF-8?q?libs/packages=20libs=20in=20new=20work=E2=80=A6=20(#18979)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/utils/create-project-utils.ts | 5 ++++ .../src/create-nx-workspace-npm.test.ts | 28 ++++++++++++++----- .../src/create-nx-workspace.test.ts | 7 +---- .../tools/tsconfig.tools.json | 12 -------- .../new/generate-workspace-files.spec.ts | 6 ++-- .../new/generate-workspace-files.ts | 2 -- .../workspace/src/generators/preset/preset.ts | 8 +----- 7 files changed, 31 insertions(+), 37 deletions(-) delete mode 100644 packages/workspace/src/generators/new/files-integrated-repo/tools/tsconfig.tools.json diff --git a/e2e/utils/create-project-utils.ts b/e2e/utils/create-project-utils.ts index c4440c2ce2e04..b00d2b492a695 100644 --- a/e2e/utils/create-project-utils.ts +++ b/e2e/utils/create-project-utils.ts @@ -53,10 +53,15 @@ export function newProject({ }); if (unsetProjectNameAndRootFormat) { + console.warn( + 'ATTENTION: The workspace generated for this e2e test does not use the new as-provided project name/root format. Please update this test' + ); updateJson('nx.json', (nxJson) => { delete nxJson.workspaceLayout; return nxJson; }); + createFile('apps/.gitkeep'); + createFile('libs/.gitkeep'); } // Temporary hack to prevent installing with `--frozen-lockfile` diff --git a/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts b/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts index 2a11dc1031cbb..0a927597b8820 100644 --- a/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts +++ b/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts @@ -63,7 +63,9 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI(`generate @nx/angular:lib ${libName} --no-interactive`); + runCLI( + `generate @nx/angular:lib ${libName} --directory packages/${libName} --no-interactive` + ); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -78,7 +80,9 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => - runCLI(`generate @nx/js:library ${libName} --no-interactive`) + runCLI( + `generate @nx/js:library ${libName} --directory packages/${libName} --no-interactive` + ) ).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -115,7 +119,9 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI(`generate @nx/react:lib ${libName} --no-interactive`); + runCLI( + `generate @nx/react:lib ${libName} --directory packages/${libName} --no-interactive` + ); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -141,7 +147,9 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI(`generate @nx/next:lib ${libName} --no-interactive`); + runCLI( + `generate @nx/next:lib ${libName} --directory packages/${libName} --no-interactive` + ); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -170,7 +178,9 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI(`generate @nx/react-native:lib ${libName} --no-interactive`); + runCLI( + `generate @nx/react-native:lib ${libName} --directory packages/${libName} --no-interactive` + ); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -196,7 +206,9 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI(`generate @nx/node:lib ${libName} --no-interactive`); + runCLI( + `generate @nx/node:lib ${libName} --directory packages/${libName} --no-interactive` + ); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -222,7 +234,9 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI(`generate @nx/nest:lib ${libName} --no-interactive`); + runCLI( + `generate @nx/nest:lib ${libName} --directory packages/${libName} --no-interactive` + ); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); diff --git a/e2e/workspace-create/src/create-nx-workspace.test.ts b/e2e/workspace-create/src/create-nx-workspace.test.ts index 601f84721fc01..dab4f71f77446 100644 --- a/e2e/workspace-create/src/create-nx-workspace.test.ts +++ b/e2e/workspace-create/src/create-nx-workspace.test.ts @@ -106,12 +106,7 @@ describe('create-nx-workspace', () => { packageManager, }); - checkFilesExist( - 'package.json', - packageManagerLockFile[packageManager], - 'apps/.gitkeep', - 'libs/.gitkeep' - ); + checkFilesExist('package.json', packageManagerLockFile[packageManager]); expectNoAngularDevkit(); }); diff --git a/packages/workspace/src/generators/new/files-integrated-repo/tools/tsconfig.tools.json b/packages/workspace/src/generators/new/files-integrated-repo/tools/tsconfig.tools.json deleted file mode 100644 index 99428e1473feb..0000000000000 --- a/packages/workspace/src/generators/new/files-integrated-repo/tools/tsconfig.tools.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "../tsconfig.base.json", - "compilerOptions": { - "outDir": "../dist/out-tsc/tools", - "rootDir": ".", - "module": "commonjs", - "target": "es5", - "types": ["node"], - "importHelpers": false - }, - "include": ["**/*.ts"] -} diff --git a/packages/workspace/src/generators/new/generate-workspace-files.spec.ts b/packages/workspace/src/generators/new/generate-workspace-files.spec.ts index 2ab57aac5a84a..66e5a9e2ef007 100644 --- a/packages/workspace/src/generators/new/generate-workspace-files.spec.ts +++ b/packages/workspace/src/generators/new/generate-workspace-files.spec.ts @@ -226,9 +226,6 @@ describe('@nx/workspace:generateWorkspaceFiles', () => { packageManager: 'npm', isCustomPreset: false, }); - expect(tree.exists('/proj/packages/.gitkeep')).toBe(true); - expect(tree.exists('/proj/apps/.gitkeep')).toBe(false); - expect(tree.exists('/proj/libs/.gitkeep')).toBe(false); const nx = readJson(tree, '/proj/nx.json'); expect(nx).toMatchInlineSnapshot(` { @@ -247,6 +244,9 @@ describe('@nx/workspace:generateWorkspaceFiles', () => { "runner": "nx/tasks-runners/default", }, }, + "workspaceLayout": { + "projectNameAndRootFormat": "as-provided", + }, } `); diff --git a/packages/workspace/src/generators/new/generate-workspace-files.ts b/packages/workspace/src/generators/new/generate-workspace-files.ts index c19920900fc4f..9c2e1eda71a60 100644 --- a/packages/workspace/src/generators/new/generate-workspace-files.ts +++ b/packages/workspace/src/generators/new/generate-workspace-files.ts @@ -45,7 +45,6 @@ export async function generateWorkspaceFiles( } setPresetProperty(tree, options); addNpmScripts(tree, options); - createAppsAndLibsFolders(tree, options); setUpWorkspacesInPackageJson(tree, options); await formatFiles(tree); @@ -57,7 +56,6 @@ function setPresetProperty(tree: Tree, options: NormalizedSchema) { addPropertyWithStableKeys(json, 'extends', 'nx/presets/npm.json'); delete json.implicitDependencies; delete json.targetDefaults; - delete json.workspaceLayout; } return json; }); diff --git a/packages/workspace/src/generators/preset/preset.ts b/packages/workspace/src/generators/preset/preset.ts index b3e722bcb9857..21e35e83ea183 100644 --- a/packages/workspace/src/generators/preset/preset.ts +++ b/packages/workspace/src/generators/preset/preset.ts @@ -1,10 +1,4 @@ -import { - installPackagesTask, - names, - readNxJson, - Tree, - updateNxJson, -} from '@nx/devkit'; +import { installPackagesTask, names, Tree } from '@nx/devkit'; import { Schema } from './schema'; import { Preset } from '../utils/presets'; import { join } from 'path';