From 27edf71cef852687aba5b07304ea905596e99302 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Tue, 1 Oct 2024 09:29:44 -0400 Subject: [PATCH] feat(misc): make directory a required option for generators (#28093) ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # --------- Co-authored-by: Colum Ferry Co-authored-by: Nicholas Cunningham --- .../angular/generators/application.json | 19 +- .../angular/generators/federate-module.json | 5 - .../packages/angular/generators/host.json | 21 +- .../packages/angular/generators/library.json | 14 +- .../packages/angular/generators/move.json | 5 - .../packages/angular/generators/remote.json | 21 +- .../detox/generators/application.json | 22 +- .../packages/expo/generators/application.json | 23 +- .../packages/expo/generators/library.json | 18 +- .../express/generators/application.json | 25 +- .../packages/js/generators/library.json | 18 +- .../packages/nest/generators/application.json | 20 +- .../packages/nest/generators/library.json | 21 +- .../packages/next/generators/application.json | 20 +- .../packages/next/generators/library.json | 20 +- .../packages/node/generators/application.json | 20 +- .../packages/node/generators/library.json | 21 +- .../packages/nuxt/generators/application.json | 20 +- .../plugin/generators/create-package.json | 17 +- .../plugin/generators/e2e-project.json | 5 - .../packages/plugin/generators/plugin.json | 20 +- .../react-native/generators/application.json | 23 +- .../react-native/generators/library.json | 19 +- .../react/generators/application.json | 25 +- .../react/generators/federate-module.json | 5 - .../packages/react/generators/host.json | 20 +- .../packages/react/generators/library.json | 19 +- .../packages/react/generators/remote.json | 20 +- .../remix/generators/application.json | 24 +- .../packages/remix/generators/library.json | 19 +- .../rspack/generators/application.json | 19 +- .../storybook/generators/cypress-project.json | 5 - .../packages/vue/generators/application.json | 19 +- .../packages/vue/generators/library.json | 20 +- .../packages/web/generators/application.json | 20 +- .../packages/workspace/generators/move.json | 5 - .../workspace/generators/npm-package.json | 19 +- .../plugins/organization-specific-plugin.md | 3 - .../module-federation/federate-a-module.md | 4 +- e2e/angular/src/config.test.ts | 8 +- .../src/cypress-component-tests.test.ts | 10 +- e2e/angular/src/misc.test.ts | 18 +- e2e/angular/src/module-federation.test.ts | 28 +- e2e/angular/src/ngrx.test.ts | 18 +- e2e/angular/src/plugin.test.ts | 1 - e2e/angular/src/projects.test.ts | 32 +- e2e/angular/src/tailwind.test.ts | 16 +- e2e/cypress/src/cypress.test.ts | 6 +- e2e/detox/src/detox-legacy.test.ts | 6 +- e2e/detox/src/detox.test.ts | 4 +- e2e/eslint/src/linter-legacy.test.ts | 29 +- e2e/eslint/src/linter.test.ts | 56 +-- e2e/expo/src/expo-legacy.test.ts | 12 +- e2e/expo/src/expo.test.ts | 4 +- e2e/gradle/src/gradle-import.test.ts | 1 - e2e/jest/src/jest-legacy.test.ts | 13 +- e2e/jest/src/jest-root.test.ts | 14 +- e2e/jest/src/jest.test.ts | 14 +- e2e/js/src/js-executor-node.test.ts | 14 +- e2e/js/src/js-executor-swc.test.ts | 12 +- e2e/js/src/js-executor-tsc.test.ts | 20 +- e2e/js/src/js-generators.ts | 26 +- e2e/js/src/js-inlining.test.ts | 18 +- e2e/js/src/js-packaging.test.ts | 16 +- e2e/next/src/next-component-tests.test.ts | 7 +- e2e/next/src/next-playwright.test.ts | 4 +- e2e/next/src/next-storybook.test.ts | 2 +- e2e/next/src/next.test.ts | 12 +- e2e/node/src/node-esbuild.test.ts | 2 +- e2e/node/src/node-server.test.ts | 20 +- e2e/node/src/node-webpack.test.ts | 4 +- e2e/node/src/node.test.ts | 42 +- e2e/nuxt/src/nuxt.test.ts | 3 +- e2e/nx/src/affected-graph.test.ts | 22 +- e2e/nx/src/cache.test.ts | 8 +- e2e/nx/src/extras.test.ts | 14 +- e2e/nx/src/import.test.ts | 1 - e2e/nx/src/invoke-runner.test.ts | 2 +- e2e/nx/src/misc.test.ts | 14 +- e2e/nx/src/nx-cloud.test.ts | 1 - e2e/nx/src/run.test.ts | 22 +- e2e/nx/src/watch.test.ts | 6 +- e2e/nx/src/workspace-legacy.test.ts | 2 +- e2e/nx/src/workspace.test.ts | 54 +-- e2e/playwright/src/playwright.test.ts | 5 +- e2e/plugin/src/nx-plugin.test.ts | 12 +- .../src/react-native-legacy.test.ts | 6 +- e2e/react-native/src/react-native.test.ts | 2 +- e2e/react/src/cypress-component-tests.test.ts | 6 +- e2e/react/src/playwright.test.ts | 4 +- .../react-module-federation.rspack.test.ts | 50 +- e2e/react/src/react-module-federation.test.ts | 32 +- e2e/react/src/react-package-legacy.test.ts | 12 +- e2e/react/src/react-package.test.ts | 14 +- e2e/react/src/react-vite.test.ts | 14 +- e2e/react/src/react-webpack.test.ts | 4 +- e2e/react/src/react.test.ts | 34 +- e2e/release/src/circular-dependencies.test.ts | 1 - .../src/conventional-commits-config.test.ts | 1 - e2e/release/src/create-github-release.test.ts | 1 - e2e/release/src/custom-registries.test.ts | 1 - e2e/release/src/first-release.test.ts | 1 - e2e/release/src/independent-projects.test.ts | 1 - e2e/release/src/lock-file-updates.test.ts | 1 - .../src/multiple-release-branches.test.ts | 1 - .../src/nx-release-git-operations.test.ts | 1 - e2e/release/src/pre-version-command.test.ts | 1 - e2e/release/src/private-js-packages.test.ts | 1 - e2e/release/src/release.test.ts | 1 - e2e/release/src/version-plans-check.test.ts | 1 - .../src/version-plans-only-touched.test.ts | 1 - e2e/release/src/version-plans.test.ts | 1 - e2e/remix/src/nx-remix.test.ts | 12 +- e2e/rspack/tests/rspack.spec.ts | 2 +- e2e/storybook/src/storybook-angular.test.ts | 5 +- e2e/storybook/src/storybook-nested.test.ts | 2 +- e2e/storybook/src/storybook.test.ts | 5 +- e2e/utils/create-project-utils.ts | 10 - e2e/vite/src/vite-esm.test.ts | 5 +- e2e/vite/src/vite-legacy.test.ts | 14 +- e2e/vite/src/vite.test.ts | 4 +- e2e/vue/src/vue-legacy.test.ts | 1 - e2e/vue/src/vue-storybook.test.ts | 5 +- e2e/vue/src/vue-tailwind.test.ts | 2 +- e2e/vue/src/vue.test.ts | 1 - e2e/web/src/file-server.test.ts | 8 +- e2e/web/src/web-legacy.test.ts | 10 +- e2e/web/src/web-vite.test.ts | 6 +- e2e/web/src/web.test.ts | 14 +- e2e/webpack/src/webpack.legacy.test.ts | 3 +- e2e/webpack/src/webpack.test.ts | 2 +- .../src/create-nx-workspace-npm.test.ts | 56 +-- .../application/application.spec.ts | 55 +-- .../application/lib/normalize-options.ts | 28 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 19 +- .../component-story/component-story.spec.ts | 2 +- .../component-test/component-test.spec.ts | 10 +- .../cypress-component-configuration.spec.ts | 40 +- .../federate-module/federate-module.spec.ts | 1 + .../federate-module/lib/add-remote.ts | 2 - .../generators/federate-module/schema.d.ts | 2 - .../generators/federate-module/schema.json | 5 - .../angular/src/generators/host/host.spec.ts | 54 +-- packages/angular/src/generators/host/host.ts | 23 +- .../angular/src/generators/host/schema.d.ts | 6 +- .../angular/src/generators/host/schema.json | 23 +- .../library/lib/normalize-options.ts | 7 +- .../library/lib/normalized-schema.ts | 4 +- .../src/generators/library/library.spec.ts | 23 +- .../src/generators/library/schema.d.ts | 6 +- .../src/generators/library/schema.json | 20 +- .../angular/src/generators/move/move.spec.ts | 23 +- .../angular/src/generators/move/schema.d.ts | 3 - .../angular/src/generators/move/schema.json | 5 - .../ngrx-feature-store.spec.ts | 4 +- .../ngrx-root-store/ngrx-root-store.spec.ts | 4 +- .../angular/src/generators/ngrx/ngrx.spec.ts | 6 +- .../src/generators/remote/remote.spec.ts | 40 +- .../angular/src/generators/remote/remote.ts | 10 +- .../angular/src/generators/remote/schema.d.ts | 6 +- .../angular/src/generators/remote/schema.json | 23 +- .../scam-to-standalone.spec.ts | 2 +- .../src/generators/setup-mf/setup-mf.spec.ts | 12 +- .../generators/setup-ssr/setup-ssr.spec.ts | 60 ++- .../generators/stories/stories-app.spec.ts | 2 +- .../generators/stories/stories-lib.spec.ts | 2 +- .../storybook-configuration.spec.ts | 2 +- .../angular/src/generators/utils/testing.ts | 9 +- .../generators/web-worker/web-worker.spec.ts | 5 +- .../remove-browserlist-config.spec.ts | 2 +- .../update-typescript-target.spec.ts | 4 +- .../update-workspace-config.spec.ts | 2 +- .../update-testing-tsconfig.spec.ts | 4 +- .../update-16-2-0/update-cy-tsconfig.spec.ts | 8 +- packages/cypress/src/utils/project-name.ts | 6 +- .../application/application.spec.ts | 15 +- .../application/lib/add-linting.spec.ts | 6 +- .../application/lib/add-project.spec.ts | 4 +- .../application/lib/create-files.spec.ts | 2 +- .../application/lib/normalize-options.spec.ts | 6 +- .../application/lib/normalize-options.ts | 6 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 22 +- packages/devkit/package.json | 3 +- .../project-name-and-root-utils.spec.ts | 457 +++--------------- .../generators/project-name-and-root-utils.ts | 214 ++++---- .../application/application.spec.ts | 20 +- .../src/generators/application/lib/add-e2e.ts | 1 - .../application/lib/normalize-options.spec.ts | 28 +- .../application/lib/normalize-options.ts | 10 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 25 +- .../generators/component/component.spec.ts | 4 +- .../library/lib/normalize-options.ts | 9 +- .../src/generators/library/library.spec.ts | 5 +- .../expo/src/generators/library/schema.d.ts | 6 +- .../expo/src/generators/library/schema.json | 18 +- packages/expo/src/utils/add-linting.spec.ts | 3 +- .../application/application.spec.ts | 9 +- .../src/generators/application/application.ts | 23 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 25 +- .../convert-to-swc/convert-to-swc.spec.ts | 26 +- .../js/src/generators/library/library.spec.ts | 207 +++----- packages/js/src/generators/library/library.ts | 8 +- .../js/src/generators/library/schema.d.ts | 4 +- .../js/src/generators/library/schema.json | 18 +- .../application/application.spec.ts | 22 +- .../application/lib/normalize-options.ts | 26 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 20 +- .../library/lib/normalize-options.ts | 8 +- .../src/generators/library/library.spec.ts | 73 +-- .../nest/src/generators/library/schema.d.ts | 6 +- .../nest/src/generators/library/schema.json | 23 +- .../application/application.spec.ts | 92 ++-- .../application/lib/add-linting.spec.ts | 2 +- .../application/lib/normalize-options.ts | 26 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 27 +- .../generators/component/component.spec.ts | 6 +- .../custom-server/custom-server.spec.ts | 6 +- .../cypress-component-configuration.spec.ts | 9 +- .../library/lib/normalize-options.spec.ts | 2 +- .../library/lib/normalize-options.ts | 18 +- .../src/generators/library/library.spec.ts | 18 +- .../next/src/generators/library/schema.d.ts | 6 +- .../next/src/generators/library/schema.json | 27 +- .../next/src/generators/page/page.spec.ts | 6 +- .../application/application.legacy.spec.ts | 3 +- .../application/application.spec.ts | 40 +- .../src/generators/application/application.ts | 26 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 20 +- .../e2e-project/e2e-project.spec.ts | 9 +- .../src/generators/e2e-project/e2e-project.ts | 6 +- .../src/generators/e2e-project/schema.d.ts | 3 - .../src/generators/e2e-project/schema.json | 5 - .../src/generators/library/library.spec.ts | 18 +- .../node/src/generators/library/library.ts | 9 +- .../node/src/generators/library/schema.d.ts | 6 +- .../node/src/generators/library/schema.json | 23 +- .../setup-docker/setup-docker.spec.ts | 6 +- .../application/application.spec.ts | 39 +- .../application/lib/normalize-options.ts | 38 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 32 +- .../configuration.spec.ts | 3 +- ...emove-project-name-and-root-format.spec.ts | 5 +- .../create-package/create-package.spec.ts | 2 - .../create-package/create-package.ts | 1 + .../src/generators/create-package/schema.d.ts | 4 +- .../src/generators/create-package/schema.json | 23 +- .../create-package/utils/normalize-schema.ts | 10 +- .../__snapshots__/e2e.spec.ts.snap | 2 +- .../src/generators/e2e-project/e2e.spec.ts | 28 +- .../plugin/src/generators/e2e-project/e2e.ts | 39 +- .../src/generators/e2e-project/schema.d.ts | 2 - .../src/generators/e2e-project/schema.json | 5 - .../src/generators/executor/executor.spec.ts | 6 +- .../generators/generator/generator.spec.ts | 6 +- .../generators/lint-checks/generator.spec.ts | 2 +- .../generators/migration/migration.spec.ts | 1 - .../src/generators/plugin/plugin.spec.ts | 8 +- .../plugin/src/generators/plugin/plugin.ts | 2 - .../plugin/src/generators/plugin/schema.d.ts | 6 +- .../plugin/src/generators/plugin/schema.json | 20 +- .../plugin/utils/normalize-schema.ts | 10 +- .../plugin/src/generators/preset/generator.ts | 4 +- .../update-16-0-0/cli-in-schema-json.spec.ts | 2 +- .../application/application.spec.ts | 22 +- .../src/generators/application/lib/add-e2e.ts | 1 - .../application/lib/normalize-options.spec.ts | 32 +- .../application/lib/normalize-options.ts | 11 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 23 +- .../library/lib/normalize-options.ts | 9 +- .../src/generators/library/library.spec.ts | 14 +- .../src/generators/library/schema.d.ts | 6 +- .../src/generators/library/schema.json | 21 +- .../src/utils/testing-generators.ts | 3 +- .../application/application.legacy.spec.ts | 7 +- .../application/application.spec.ts | 39 +- .../application/lib/normalize-options.ts | 27 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 27 +- .../component-story/component-story.spec.ts | 3 +- .../component-test/component-test.spec.ts | 38 +- .../cypress-component-configuration.spec.ts | 48 +- .../federate-module/federate-module.spec.ts | 13 +- .../federate-module/federate-module.ts | 40 +- .../generators/federate-module/schema.d.ts | 1 - .../generators/federate-module/schema.json | 5 - .../src/generators/host/host.rspack.spec.ts | 32 +- packages/react/src/generators/host/host.ts | 3 +- .../src/generators/host/host.webpack.spec.ts | 32 +- .../generators/host/lib/normalize-remote.ts | 3 +- .../react/src/generators/host/schema.d.ts | 6 +- .../react/src/generators/host/schema.json | 22 +- .../library/lib/normalize-options.spec.ts | 14 +- .../library/lib/normalize-options.ts | 7 +- .../src/generators/library/library.spec.ts | 14 +- .../react/src/generators/library/schema.d.ts | 6 +- .../react/src/generators/library/schema.json | 26 +- .../react/src/generators/redux/redux.spec.ts | 6 +- .../generators/remote/remote.rspack.spec.ts | 27 +- .../react/src/generators/remote/remote.ts | 2 + .../generators/remote/remote.webpack.spec.ts | 27 +- .../react/src/generators/remote/schema.d.ts | 6 +- .../react/src/generators/remote/schema.json | 22 +- .../generators/setup-ssr/setup-ssr.spec.ts | 3 +- .../generators/stories/stories.app.spec.ts | 3 +- .../generators/stories/stories.lib.spec.ts | 3 +- .../generators/stories/stories.nextjs.spec.ts | 3 +- .../configuration.spec.ts | 6 +- .../update-ssr-server-port.spec.ts | 10 +- .../react/src/utils/testing-generators.ts | 3 +- .../application.impl.spec.ts.snap | 42 +- .../application/application.impl.spec.ts | 337 ++++++------- .../application/lib/normalize-options.ts | 17 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 26 +- ...press-component-configuration.impl.spec.ts | 2 +- .../__snapshots__/library.impl.spec.ts.snap | 12 +- .../library/lib/normalize-options.ts | 18 +- .../generators/library/library.impl.spec.ts | 257 +++++----- .../src/generators/library/library.impl.ts | 1 - .../remix/src/generators/library/schema.d.ts | 6 +- .../remix/src/generators/library/schema.json | 21 +- .../src/generators/preset/preset.impl.ts | 1 + .../setup-tailwind.impl.spec.ts | 2 + .../src/generators/application/application.ts | 2 +- .../application/lib/normalize-options.spec.ts | 56 ++- .../application/lib/normalize-options.ts | 43 +- .../src/generators/application/schema.d.ts | 4 +- .../src/generators/application/schema.json | 21 +- .../rspack/src/generators/preset/preset.ts | 1 + .../configuration/configuration.spec.ts | 15 +- .../cypress-project/cypress-project.spec.ts | 3 - .../cypress-project/cypress-project.ts | 24 +- .../generators/cypress-project/schema.json | 5 - packages/storybook/src/utils/testing.ts | 2 +- .../configuration/configuration.spec.ts | 8 +- .../application/application.spec.ts | 2 +- .../application/lib/normalize-options.ts | 25 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 21 +- .../library/lib/normalize-options.ts | 7 +- .../src/generators/library/library.spec.ts | 6 +- .../vue/src/generators/library/schema.d.ts | 7 +- .../vue/src/generators/library/schema.json | 22 +- .../stories/lib/component-story.spec.ts | 3 +- .../generators/stories/stories.app.spec.ts | 3 +- .../generators/stories/stories.lib.spec.ts | 3 +- .../configuration.spec.ts | 6 +- packages/vue/src/utils/test-utils.ts | 3 +- .../application/application.legacy.spec.ts | 5 +- .../application/application.spec.ts | 93 ++-- .../src/generators/application/application.ts | 25 +- .../src/generators/application/schema.d.ts | 6 +- .../src/generators/application/schema.json | 20 +- .../convert-to-monorepo.spec.ts | 13 +- .../convert-to-monorepo.ts | 1 - .../move/lib/check-destination.spec.ts | 6 +- .../move/lib/move-project-files.spec.ts | 3 +- .../move/lib/normalize-schema.spec.ts | 2 - .../generators/move/lib/normalize-schema.ts | 19 +- .../move/lib/update-cypress-config.spec.ts | 3 +- .../move/lib/update-eslint-config.spec.ts | 35 +- .../move/lib/update-imports.spec.ts | 94 ++-- .../move/lib/update-jest-config.spec.ts | 13 +- .../move/lib/update-package-json.spec.ts | 3 +- .../lib/update-project-root-files.spec.ts | 6 +- .../generators/move/lib/update-readme.spec.ts | 6 +- .../move/lib/update-storybook-config.spec.ts | 15 +- .../src/generators/move/move.spec.ts | 14 +- .../workspace/src/generators/move/schema.d.ts | 3 - .../workspace/src/generators/move/schema.json | 5 - .../src/generators/npm-package/npm-package.ts | 9 +- .../src/generators/npm-package/schema.json | 20 +- .../workspace/src/generators/preset/preset.ts | 20 - .../remove/lib/remove-project.spec.ts | 2 +- .../remove/lib/update-jest-config.spec.ts | 2 +- .../remove/lib/update-tsconfig.spec.ts | 12 +- .../run-commands/run-commands.spec.ts | 2 +- ...ve-workspace-generators-to-local-plugin.ts | 3 +- 387 files changed, 2488 insertions(+), 4087 deletions(-) diff --git a/docs/generated/packages/angular/generators/application.json b/docs/generated/packages/angular/generators/application.json index 7eef7559d3c40..43a703df81352 100644 --- a/docs/generated/packages/angular/generators/application.json +++ b/docs/generated/packages/angular/generators/application.json @@ -9,22 +9,17 @@ "type": "object", "cli": "nx", "properties": { - "name": { - "description": "The name of the application.", - "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" - }, "directory": { "description": "The directory of the new application.", "type": "string", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "style": { "description": "The file extension to be used for style files.", @@ -184,7 +179,7 @@ } }, "additionalProperties": false, - "required": ["name"], + "required": ["directory"], "examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nx/angular:application apps/my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Specify directory and style extension\" %}\n\nCreate an application named `my-app` in the `my-dir` directory and use `scss` for styles:\n\n{% callout type=\"note\" title=\"Directory Flag Behavior Changes\" %}\nThe command below uses the `as-provided` directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the `derived` option, use `--directory=my-dir`. See the [as-provided vs. derived documentation](/deprecated/as-provided-vs-derived) for more details.\n{% /callout %}\n\n```bash\nnx g @nx/angular:app my-dir/my-app --style=scss\n```\n\n{% /tab %}\n\n{% tab label=\"Single File Components application\" %}\n\nCreate an application with Single File Components (inline styles and inline templates):\n\n```bash\nnx g @nx/angular:app apps/my-app --inlineStyle --inlineTemplate\n```\n\n{% /tab %}\n\n{% tab label=\"Set custom prefix and tags\" %}\n\nSet the prefix to apply to generated selectors and add tags to the application (used for linting).\n\n```bash\nnx g @nx/angular:app apps/my-app --prefix=admin --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n", "presets": [] }, diff --git a/docs/generated/packages/angular/generators/federate-module.json b/docs/generated/packages/angular/generators/federate-module.json index 73e1c917dc77a..1c978a84bdc94 100644 --- a/docs/generated/packages/angular/generators/federate-module.json +++ b/docs/generated/packages/angular/generators/federate-module.json @@ -37,11 +37,6 @@ "description": "The directory of the new remote application if one needs to be created.", "type": "string" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files for the remote if one needs to be created.", "type": "string", diff --git a/docs/generated/packages/angular/generators/host.json b/docs/generated/packages/angular/generators/host.json index ec92ae8ceef32..98e630227e4b2 100644 --- a/docs/generated/packages/angular/generators/host.json +++ b/docs/generated/packages/angular/generators/host.json @@ -15,11 +15,17 @@ } ], "properties": { + "directory": { + "description": "The directory of the new application.", + "type": "string", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" + }, "name": { "type": "string", "description": "The name to give to the host Angular application.", - "$default": { "$source": "argv", "index": 0 }, - "pattern": "^[a-zA-Z][^:]*$" + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "remotes": { "type": "array", @@ -31,15 +37,6 @@ "description": "Should the host application use dynamic federation?", "default": false }, - "directory": { - "description": "The directory of the new application.", - "type": "string" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -178,7 +175,7 @@ } }, "additionalProperties": false, - "required": ["name"], + "required": ["directory"], "presets": [] }, "x-type": "application", diff --git a/docs/generated/packages/angular/generators/library.json b/docs/generated/packages/angular/generators/library.json index e50b564a932c5..13db7611a0d24 100644 --- a/docs/generated/packages/angular/generators/library.json +++ b/docs/generated/packages/angular/generators/library.json @@ -12,19 +12,13 @@ "name": { "type": "string", "description": "The name of the library.", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" + "x-priority": "important" }, "directory": { "type": "string", "description": "A directory where the library is placed.", - "x-priority": "important" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the library in?" }, "publishable": { "type": "boolean", @@ -203,7 +197,7 @@ } }, "additionalProperties": false, - "required": ["name"], + "required": ["directory"], "examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Library\" %}\n\nCreates the `my-ui-lib` library with an `ui` tag:\n\n```bash\nnx g @nx/angular:library libs/my-ui-lib --tags=ui\n```\n\n{% /tab %}\n\n{% tab label=\"Publishable Library\" %}\n\nCreates the `my-lib` library that can be built producing an output following the Angular Package Format (APF) to be distributed as an NPM package:\n\n```bash\nnx g @nx/angular:library libs/my-lib --publishable --import-path=@my-org/my-lib\n```\n\n{% /tab %}\n\n{% tab label=\"Buildable Library\" %}\n\nCreates the `my-lib` library with support for incremental builds:\n\n```bash\nnx g @nx/angular:library libs/my-lib --buildable\n```\n\n{% /tab %}\n\n{% tab label=\"Nested Folder & Import\"%}\nCreates the `my-lib` library in the `nested` directory and sets the import path to `@myorg/nested/my-lib`:\n\n{% callout type=\"note\" title=\"Directory Flag Behavior Changes\" %}\nThe command below uses the `as-provided` directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the `derived` option, use `--directory=nested`. See the [as-provided vs. derived documentation](/deprecated/as-provided-vs-derived) for more details.\n{% /callout %}\n\n```bash\nnx g @nx/angular:library libs/nested/my-lib --importPath=@myorg/nested/my-lib\n```\n\n{% /tab %}\n", "presets": [] }, diff --git a/docs/generated/packages/angular/generators/move.json b/docs/generated/packages/angular/generators/move.json index 049afe97b8133..9179b04d53680 100644 --- a/docs/generated/packages/angular/generators/move.json +++ b/docs/generated/packages/angular/generators/move.json @@ -35,11 +35,6 @@ "$default": { "$source": "argv", "index": 0 }, "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the new project name and destination as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "importPath": { "type": "string", "description": "The new import path to use in the `tsconfig.base.json`." diff --git a/docs/generated/packages/angular/generators/remote.json b/docs/generated/packages/angular/generators/remote.json index 937783ecd7a0f..93929e8012dfd 100644 --- a/docs/generated/packages/angular/generators/remote.json +++ b/docs/generated/packages/angular/generators/remote.json @@ -15,11 +15,17 @@ } ], "properties": { + "directory": { + "description": "The directory of the new application.", + "type": "string", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" + }, "name": { "type": "string", "description": "The name to give to the remote Angular app.", - "$default": { "$source": "argv", "index": 0 }, - "pattern": "^[a-zA-Z][^:]*$" + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "host": { "type": "string", @@ -31,15 +37,6 @@ "type": "number", "description": "The port on which this app should be served." }, - "directory": { - "description": "The directory of the new application.", - "type": "string" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -171,7 +168,7 @@ } }, "additionalProperties": false, - "required": ["name"], + "required": ["directory"], "presets": [] }, "x-type": "application", diff --git a/docs/generated/packages/detox/generators/application.json b/docs/generated/packages/detox/generators/application.json index 5b7611478117b..05910a98402e3 100644 --- a/docs/generated/packages/detox/generators/application.json +++ b/docs/generated/packages/detox/generators/application.json @@ -13,12 +13,15 @@ "$default": { "$source": "projectName" }, "x-prompt": "What is the name of the frontend project to test?" }, - "e2eName": { + "e2eDirectory": { "type": "string", - "description": "Name of the E2E Project.", + "description": "A directory where the project is placed relative current working directory (CWD).", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the E2E project?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the E2E project in?" + }, + "e2eName": { + "type": "string", + "description": "Name of the E2E Project." }, "appName": { "type": "string", @@ -34,15 +37,6 @@ "enum": ["react-native", "expo"], "x-prompt": "What app framework should detox test?" }, - "e2eDirectory": { - "type": "string", - "description": "A directory where the project is placed relative to apps directory." - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -66,7 +60,7 @@ "default": false } }, - "required": ["e2eName", "appProject", "framework"], + "required": ["e2eDirectory", "appProject", "framework"], "presets": [] }, "aliases": ["app"], diff --git a/docs/generated/packages/expo/generators/application.json b/docs/generated/packages/expo/generators/application.json index c9648c5cf6c07..2207ca6aa84d7 100644 --- a/docs/generated/packages/expo/generators/application.json +++ b/docs/generated/packages/expo/generators/application.json @@ -18,27 +18,22 @@ ], "type": "object", "properties": { + "directory": { + "description": "The directory of the new application.", + "type": "string", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" + }, "name": { "description": "The name of the application.", "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "displayName": { "description": "The display name to show in the application. Defaults to name.", "type": "string" }, - "directory": { - "description": "The directory of the new application.", - "type": "string", - "x-priority": "important" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "skipFormat": { "description": "Skip formatting files", "type": "boolean", @@ -90,7 +85,7 @@ "default": false } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["app"], diff --git a/docs/generated/packages/expo/generators/library.json b/docs/generated/packages/expo/generators/library.json index f2b97f63283b4..ec955911b9797 100644 --- a/docs/generated/packages/expo/generators/library.json +++ b/docs/generated/packages/expo/generators/library.json @@ -14,22 +14,16 @@ } ], "properties": { - "name": { - "type": "string", - "description": "Library name", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" - }, "directory": { "type": "string", "description": "A directory where the lib is placed.", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the library in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Library name", + "x-priority": "important" }, "linter": { "description": "The tool to use for running lint checks.", @@ -94,7 +88,7 @@ "default": false } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["lib"], diff --git a/docs/generated/packages/express/generators/application.json b/docs/generated/packages/express/generators/application.json index ecbccb407158b..eacbd36bd225f 100644 --- a/docs/generated/packages/express/generators/application.json +++ b/docs/generated/packages/express/generators/application.json @@ -9,22 +9,17 @@ "description": "Nx Application Options Schema.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the node application?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { + "description": "The name of the application.", + "pattern": "^[a-zA-Z][^:]*$", "type": "string" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "skipFormat": { "description": "Skip formatting files.", "type": "boolean", @@ -71,19 +66,13 @@ "description": "Generate JavaScript files rather than TypeScript files.", "default": false }, - "standaloneConfig": { - "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`.", - "type": "boolean", - "default": true, - "x-deprecated": "Nx only supports standaloneConfig" - }, "setParserOptionsProject": { "type": "boolean", "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", "default": false } }, - "required": [], + "required": ["directory"], "presets": [] }, "aliases": ["app"], diff --git a/docs/generated/packages/js/generators/library.json b/docs/generated/packages/js/generators/library.json index 420ee5907d648..158fc05d2a2ac 100644 --- a/docs/generated/packages/js/generators/library.json +++ b/docs/generated/packages/js/generators/library.json @@ -9,16 +9,15 @@ "description": "Create a TypeScript Library.", "type": "object", "properties": { - "name": { + "directory": { "type": "string", - "description": "Library name.", + "description": "A directory where the lib is placed.", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" + "x-prompt": "Which directory do you want to create the library in?" }, - "directory": { + "name": { "type": "string", - "description": "A directory where the lib is placed.", + "description": "Library name.", "x-priority": "important" }, "bundler": { @@ -39,11 +38,6 @@ "enum": ["none", "jest", "vitest"], "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "tags": { "type": "string", "description": "Add tags to the library (used for linting)." @@ -141,7 +135,7 @@ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file." } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "---\ntitle: JS library generator examples\ndescription: This page contains examples for the @nx/js:lib generator.\n---\n\nThe `@nx/js:lib` generator will generate a library for you, and it will configure it according to the options you provide.\n\n```bash\nnpx nx g @nx/js:lib libs/mylib\n```\n\nBy default, the library that is generated when you use this executor without passing any options, like the example above, will be a buildable library, using the `@nx/js:tsc` executor as a builder.\n\nYou may configure the tools you want to use to build your library, or bundle it too, by passing the `--bundler` flag. The `--bundler` flag controls the compiler and/or the bundler that will be used to build your library. If you choose `tsc` or `swc`, the result will be a buildable library using either `tsc` or `swc` as the compiler. If you choose `rollup` or `vite`, the result will be a buildable library using `rollup` or `vite` as the bundler. In the case of `rollup`, it will default to the `tsc` compiler. If you choose `esbuild`, you may use the [`esbuildOptions` property](https://esbuild.github.io/api/) in your `project.json` under the `build` target options to specify whether you wish to bundle your library or not.\n\n## Examples\n\n{% tabs %}\n\n{% tab label=\"Buildable with default compiler (tsc)\" %}\n\nGenerate a buildable library using the `@nx/js:tsc` executor. This uses `tsc` as the compiler.\n\n```bash\nnpx nx g @nx/js:lib libs/mylib\n```\n\n{% /tab %}\n\n{% tab label=\"Buildable with SWC compiler\" %}\n\nGenerate a buildable library using [SWC](https://swc.rs) as the compiler. This will use the `@nx/js:swc` executor.\n\n```bash\nnpx nx g @nx/js:lib libs/mylib --bundler=swc\n```\n\n{% /tab %}\n\n{% tab label=\"Buildable with tsc\" %}\n\nGenerate a buildable library using tsc as the compiler. This will use the `@nx/js:tsc` executor.\n\n```bash\nnpx nx g @nx/js:lib libs/mylib --bundler=tsc\n```\n\n{% /tab %}\n\n{% tab label=\"Buildable, with Rollup as a bundler\" %}\n\nGenerate a buildable library using [Rollup](https://rollupjs.org) as the bundler. This will use the `@nx/rollup:rollup` executor. It will also use [SWC](https://swc.rs) as the compiler.\n\n```bash\nnpx nx g @nx/js:lib libs/mylib --bundler=rollup\n```\n\nIf you do not want to use `swc` as the compiler, and want to use the default `babel` compiler, you can do so in your `project.json` under the `build` target options, using the [`compiler` property](/nx-api/rollup/executors/rollup#compiler):\n\n```jsonc {% fileName=\"libs/mylib/project.json\" %}\n\"build\": {\n \"executor\": \"@nx/rollup:rollup\",\n \"options\": {\n //...\n \"compiler\": \"babel\"\n }\n}\n```\n\n{% /tab %}\n\n{% tab label=\"Buildable, with Vite as a bundler\" %}\n\nGenerate a buildable library using [Vite](https://vitejs.dev/) as the bundler. This will use the `@nx/vite:build` executor.\n\n```bash\nnpx nx g @nx/js:lib libs/mylib --bundler=vite\n```\n\n{% /tab %}\n\n{% tab label=\"Using ESBuild\" %}\n\nGenerate a buildable library using [ESBuild](https://esbuild.github.io/) as the bundler. This will use the `@nx/esbuild:esbuild` executor.\n\n```bash\nnpx nx g @nx/js:lib libs/mylib --bundler=esbuild\n```\n\nIf you want to specify whether you want to bundle your library or not, you can do so in your `project.json` under the `build` target options, using the [`esbuildOptions` property](https://esbuild.github.io/api/):\n\n```jsonc {% fileName=\"libs/mylib/project.json\" %}\n\"build\": {\n \"executor\": \"@nx/esbuild:esbuild\",\n \"options\": {\n //...\n \"esbuildOptions\": {\n \"bundle\": true\n }\n }\n}\n```\n\n{% /tab %}\n\n{% tab label=\"Minimal publishing target\" %}\n\nGenerate a **publishable** library with a minimal publishing target. The result will be a buildable library using the `@nx/js:tsc` executor, using `tsc` as the compiler. You can change the compiler or the bundler by passing the `--bundler` flag.\n\n```bash\nnpx nx g lib libs/mylib --publishable\n```\n\n{% /tab %}\n\n{% tab label=\"Using directory flag\" %}\n\nGenerate a library named `mylib` and put it under a directory named `myapp` (`libs/myapp/mylib`)\n\n{% callout type=\"note\" title=\"Directory Flag Behavior Changes\" %}\nThe command below uses the `as-provided` directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the `derived` option, use `--directory=myapp`. See the [as-provided vs. derived documentation](/deprecated/as-provided-vs-derived) for more details.\n{% /callout %}\n\n```shell\nnpx nx g lib libs/nested/mylib\n```\n\n{% /tab %}\n\n{% tab label=\"Non-buildable library\" %}\n\nGenerate a non-buildable library.\n\n```bash\nnpx nx g @nx/js:lib libs/mylib --bundler=none\n```\n\n{% /tab %}\n\n{% /tabs %}\n", "presets": [] }, diff --git a/docs/generated/packages/nest/generators/application.json b/docs/generated/packages/nest/generators/application.json index 304141f665d42..c77f46a1aac85 100644 --- a/docs/generated/packages/nest/generators/application.json +++ b/docs/generated/packages/nest/generators/application.json @@ -9,21 +9,17 @@ "cli": "nx", "type": "object", "properties": { - "name": { - "description": "The name of the application.", - "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the node application?", - "pattern": "^[a-zA-Z][^:]*$" - }, "directory": { "description": "The directory of the new application.", - "type": "string" + "type": "string", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "skipFormat": { "description": "Skip formatting files.", @@ -82,7 +78,7 @@ } }, "additionalProperties": false, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["app"], diff --git a/docs/generated/packages/nest/generators/library.json b/docs/generated/packages/nest/generators/library.json index f811ec86a38fb..f8e967fa0818d 100644 --- a/docs/generated/packages/nest/generators/library.json +++ b/docs/generated/packages/nest/generators/library.json @@ -15,22 +15,17 @@ } ], "properties": { - "name": { - "description": "Library name.", - "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" - }, "directory": { "description": "A directory where the library is placed.", "type": "string", - "alias": "dir" + "alias": "dir", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the library in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided"] + "name": { + "description": "Library name.", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", + "type": "string" }, "linter": { "description": "The tool to use for running lint checks.", @@ -143,7 +138,7 @@ } }, "additionalProperties": false, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["lib"], diff --git a/docs/generated/packages/next/generators/application.json b/docs/generated/packages/next/generators/application.json index 88bb2ffed54cc..9fdb8144b2d59 100644 --- a/docs/generated/packages/next/generators/application.json +++ b/docs/generated/packages/next/generators/application.json @@ -9,24 +9,18 @@ "description": "Create a Next.js Application for Nx.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", - "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "directory": { "description": "The directory of the new application.", "type": "string", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "style": { "description": "The file extension to be used for style files.", @@ -142,7 +136,7 @@ "x-priority": "internal" } }, - "required": [], + "required": ["directory"], "examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Create app in a directory\" %}\n\n{% callout type=\"note\" title=\"Directory Flag Behavior Changes\" %}\nThe command below uses the `as-provided` directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the `derived` option, use `--directory=nested`. See the [as-provided vs. derived documentation](/deprecated/as-provided-vs-derived) for more details.\n{% /callout %}\n\n```shell\nnx g app apps/nested/myapp\n```\n\n{% /tab %}\n{% tab label=\"Use a custom Express server\" %}\n\n```shell\nnx g app apps/myapp --custom-server\n```\n\n{% /tab %}\n{% tab label=\"Use plain JavaScript (not TypeScript)\" %}\n\n```shell\nnx g app apps/myapp --js\n```\n\n{% /tab %}\n{% /tabs %}\n", "presets": [] }, diff --git a/docs/generated/packages/next/generators/library.json b/docs/generated/packages/next/generators/library.json index bf6b004c76226..19a4977ccd637 100644 --- a/docs/generated/packages/next/generators/library.json +++ b/docs/generated/packages/next/generators/library.json @@ -9,24 +9,18 @@ "description": "Create a React Library for an Nx workspace.", "type": "object", "properties": { - "name": { - "type": "string", - "description": "Library name", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", - "x-priority": "important" - }, "directory": { "type": "string", "description": "A directory where the lib is placed.", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the library in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Library name", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", + "x-priority": "important" }, "style": { "description": "The file extension to be used for style files.", @@ -143,7 +137,7 @@ "x-priority": "internal" } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Create a new lib\" %}\n\n```shell\nnx g lib libs/my-lib\n```\n\n{% /tab %}\n{% tab label=\"Create a new lib under a directory\" %}\n\nThe following will create a library at `libs/shared/my-lib`.\n\n```shell\nnx g lib libs/shared/my-lib\n```\n\n{% /tab %}\n{% /tabs %}\n", "presets": [] }, diff --git a/docs/generated/packages/node/generators/application.json b/docs/generated/packages/node/generators/application.json index 40113b7e1e27c..903ead6c595e6 100644 --- a/docs/generated/packages/node/generators/application.json +++ b/docs/generated/packages/node/generators/application.json @@ -9,23 +9,17 @@ "description": "Nx Application Options Schema.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", - "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the node application?", - "x-priority": "important", - "pattern": "^[a-zA-Z][^:]*$" - }, "directory": { "description": "The directory of the new application.", "type": "string", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "skipFormat": { "description": "Skip formatting files", @@ -126,7 +120,7 @@ "description": "Add a docker build target" } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["app"], diff --git a/docs/generated/packages/node/generators/library.json b/docs/generated/packages/node/generators/library.json index a7b9bc38ffd93..fada543625113 100644 --- a/docs/generated/packages/node/generators/library.json +++ b/docs/generated/packages/node/generators/library.json @@ -15,26 +15,21 @@ } ], "properties": { - "name": { - "type": "string", - "description": "Library name", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" - }, "directory": { "type": "string", "description": "A directory where the lib is placed", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the library in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Library name", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", + "x-priority": "important" }, "simpleModuleName": { - "description": "Keep the module name simple (when using `--directory`).", + "description": "Keep the module name simple.", "type": "boolean", "default": false }, @@ -126,7 +121,7 @@ "default": false } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["lib"], diff --git a/docs/generated/packages/nuxt/generators/application.json b/docs/generated/packages/nuxt/generators/application.json index 54312d2c1ae81..f13819fe0bea5 100644 --- a/docs/generated/packages/nuxt/generators/application.json +++ b/docs/generated/packages/nuxt/generators/application.json @@ -9,24 +9,18 @@ "description": "Create a Nuxt Application for Nx.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", - "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "directory": { "description": "The directory of the new application.", "type": "string", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "linter": { "description": "The tool to use for running lint checks.", @@ -105,7 +99,7 @@ "default": false } }, - "required": [], + "required": ["directory"], "examplesFile": "---\ntitle: Nuxt application generator examples\ndescription: This page contains examples for the @nx/nuxt:app generator.\n---\n\nYour new Nuxt application will be generated with the following directory structure, following the suggested [directory structure](https://nuxt.com/docs/guide/directory-structure) for Nuxt applications:\n\n```text\nmy-nuxt-app\n├── nuxt.config.ts\n├── project.json\n├── src\n│   ├── app.vue\n│   ├── assets\n│   │   └── css\n│   │   └── styles.css\n│   ├── components\n│   │   └── NxWelcome.vue\n│   ├── pages\n│   │   ├── about.vue\n│   │   └── index.vue\n│   ├── public\n│   │   └── favicon.ico\n│   └── server\n│   ├── api\n│   │   └── greet.ts\n│   └── tsconfig.json\n├── tsconfig.app.json\n├── tsconfig.json\n├── tsconfig.spec.json\n└── vitest.config.ts\n```\n\nYour new app will contain the following:\n\n- Two pages (home and about) under `pages`\n- A component (`NxWelcome`) under `components`\n- A `greet` API endpoint that returns a JSON response under `/api/greet`\n- Configuration for `vitest`\n- Your app's entrypoint (`app.vue`) will contain the navigation links to the home and about pages, and the `nuxt-page` component to display the contents of your pages.\n\n## Examples\n\n{% tabs %}\n{% tab label=\"Create app in a directory\" %}\n\n{% callout type=\"note\" title=\"Directory Flag Behavior Changes\" %}\nThe command below uses the `as-provided` directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the `derived` option, use `--directory=nested`. See the [as-provided vs. derived documentation](/deprecated/as-provided-vs-derived) for more details.\n{% /callout %}\n\n```shell\nnx g @nx/nuxt:app =apps/nested/myapp\n```\n\n{% /tab %}\n\n{% tab label=\"Create app with vitest configured\" %}\n\n```shell\nnx g @nx/nuxt:app apps/nested/myapp --unitTestRunner=vitest\n```\n\n{% /tab %}\n\n{% tab label=\"Use plain JavaScript (not TypeScript)\" %}\n\n```shell\nnx g @nx/nuxt:app apps/myapp --js\n```\n\n{% /tab %}\n{% /tabs %}\n\n## Generate pages and components\n\nYou can use the the [`@nx/vue:component` generator](/nx-api/vue/generators/component) to generate new pages and components for your application. You can read more on the [`@nx/vue:component` generator documentation page](/nx-api/vue/generators/component), but here are some examples:\n\n{% tabs %}\n{% tab label=\"New page\" %}\n\n```shell\nnx g @nx/nuxt:component my-app/src/pages/my-page\n```\n\n{% /tab %}\n\n{% tab label=\"New component\" %}\n\n```shell\nnx g @nx/nuxt:component my-app/src/components/my-cmp\n```\n\n{% /tab %}\n{% /tabs %}\n", "presets": [] }, diff --git a/docs/generated/packages/plugin/generators/create-package.json b/docs/generated/packages/plugin/generators/create-package.json index 63c1daa77d45c..b0fb581ca10f6 100644 --- a/docs/generated/packages/plugin/generators/create-package.json +++ b/docs/generated/packages/plugin/generators/create-package.json @@ -10,11 +10,15 @@ "examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Basic executable\" %}\n\nCreate an executable that initializes an Nx workspace with {my-plugin}'s preset:\n\n```bash\nnx g @nx/plugin:create-package create-my-plugin --project my-plugin\n```\n\n{% /tab %}\n{% /tabs %}\n", "type": "object", "properties": { + "directory": { + "type": "string", + "description": "A directory where the app is placed.", + "$default": { "$source": "argv", "index": 0 } + }, "name": { "type": "string", "description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.", "pattern": "create-.+|^@.+/create(?:-.+)?", - "$default": { "$source": "argv", "index": 0 }, "x-priority": "important" }, "project": { @@ -31,15 +35,6 @@ "description": "Test runner to use for unit tests.", "default": "jest" }, - "directory": { - "type": "string", - "description": "A directory where the app is placed." - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -69,7 +64,7 @@ "x-prompt": "What is the name of the e2e project? Leave blank to skip e2e tests" } }, - "required": ["name", "project"], + "required": ["directory", "name", "project"], "presets": [] }, "description": "Create a package which can be used by npx to create a new workspace", diff --git a/docs/generated/packages/plugin/generators/e2e-project.json b/docs/generated/packages/plugin/generators/e2e-project.json index 6956a0e498ffa..32c73bff79ba0 100644 --- a/docs/generated/packages/plugin/generators/e2e-project.json +++ b/docs/generated/packages/plugin/generators/e2e-project.json @@ -24,11 +24,6 @@ "type": "string", "description": "the directory where the plugin is placed." }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "pluginOutputPath": { "type": "string", "description": "the output path of the plugin after it builds.", diff --git a/docs/generated/packages/plugin/generators/plugin.json b/docs/generated/packages/plugin/generators/plugin.json index e48665c9a6c74..8035a100da276 100644 --- a/docs/generated/packages/plugin/generators/plugin.json +++ b/docs/generated/packages/plugin/generators/plugin.json @@ -15,22 +15,16 @@ } ], "properties": { - "name": { - "type": "string", - "description": "Plugin name", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the plugin?", - "x-priority": "important", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" - }, "directory": { "type": "string", - "description": "A directory where the plugin is placed." + "description": "A directory where the plugin is placed.", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the plugin in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Plugin name", + "x-priority": "important" }, "importPath": { "type": "string", @@ -100,7 +94,7 @@ "default": false } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "description": "Create a Nx Plugin.", diff --git a/docs/generated/packages/react-native/generators/application.json b/docs/generated/packages/react-native/generators/application.json index bf6339be6147f..a151285fec4fc 100644 --- a/docs/generated/packages/react-native/generators/application.json +++ b/docs/generated/packages/react-native/generators/application.json @@ -19,26 +19,21 @@ ], "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" }, - "displayName": { - "description": "The display name to show in the application. Defaults to name.", + "name": { + "description": "The name of the application.", + "pattern": "^[a-zA-Z][^:]*$", "type": "string" }, - "directory": { - "description": "The directory of the new application.", + "displayName": { + "description": "The display name to show in the application. Defaults to name.", "type": "string" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "skipFormat": { "description": "Skip formatting files", "type": "boolean", @@ -99,7 +94,7 @@ "x-priority": "important" } }, - "required": [], + "required": ["directory"], "presets": [] }, "aliases": ["app"], diff --git a/docs/generated/packages/react-native/generators/library.json b/docs/generated/packages/react-native/generators/library.json index 00e67ac13216b..4123a73aa224b 100644 --- a/docs/generated/packages/react-native/generators/library.json +++ b/docs/generated/packages/react-native/generators/library.json @@ -15,23 +15,18 @@ } ], "properties": { - "name": { - "type": "string", - "description": "Library name.", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" - }, "directory": { "type": "string", "description": "A directory where the lib is placed.", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the library in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Library name.", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", + "x-priority": "important" }, "linter": { "description": "The tool to use for running lint checks.", @@ -97,7 +92,7 @@ "x-priority": "internal" } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["lib"], diff --git a/docs/generated/packages/react/generators/application.json b/docs/generated/packages/react/generators/application.json index ba8bb34998c1a..0103fc3d12a2b 100644 --- a/docs/generated/packages/react/generators/application.json +++ b/docs/generated/packages/react/generators/application.json @@ -9,37 +9,32 @@ "description": "Create a React application for Nx.", "examples": [ { - "command": "nx g app myapp --directory=myorg", + "command": "nx g app apps/myorg/myapp", "description": "Generate `apps/myorg/myapp` and `apps/myorg/myapp-e2e`" }, { - "command": "nx g app myapp --classComponent", + "command": "nx g app apps/myapp --classComponent", "description": "Use class components instead of functional components" }, { - "command": "nx g app myapp --routing", + "command": "nx g app apps/myapp --routing", "description": "Set up React Router" } ], "type": "object", "properties": { - "name": { - "description": "The name of the application.", - "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" - }, "directory": { "description": "The directory of the new application.", "type": "string", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "style": { "description": "The file extension to be used for style files.", @@ -184,7 +179,7 @@ "default": false } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nx/react:application apps/my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Application using Vite as bundler\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nx/react:app apps/my-app --bundler=vite\n```\n\nWhen choosing `vite` as the bundler, your unit tests will be set up with `vitest`, unless you choose `none` for `unitTestRunner`.\n\n{% /tab %}\n\n{% tab label=\"Specify directory and style extension\" %}\n\nCreate an application named `my-app` in the `my-dir` directory and use `scss` for styles:\n\n{% callout type=\"note\" title=\"Directory Flag Behavior Changes\" %}\nThe command below uses the `as-provided` directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the `derived` option, use `--directory=my-dir`. See the [as-provided vs. derived documentation](/deprecated/as-provided-vs-derived) for more details.\n{% /callout %}\n\n```bash\nnx g @nx/react:app apps/my-dir/my-app --style=scss\n```\n\n{% /tab %}\n\n{% tab label=\"Add tags\" %}\n\nAdd tags to the application (used for linting).\n\n```bash\nnx g @nx/react:app apps/my-app --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n", "presets": [] }, diff --git a/docs/generated/packages/react/generators/federate-module.json b/docs/generated/packages/react/generators/federate-module.json index 147ad0c03a7da..9a045541050f4 100644 --- a/docs/generated/packages/react/generators/federate-module.json +++ b/docs/generated/packages/react/generators/federate-module.json @@ -37,11 +37,6 @@ "description": "The directory of the new remote application if one needs to be created.", "type": "string" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", diff --git a/docs/generated/packages/react/generators/host.json b/docs/generated/packages/react/generators/host.json index 56b555af58a9d..453632040b3bb 100644 --- a/docs/generated/packages/react/generators/host.json +++ b/docs/generated/packages/react/generators/host.json @@ -9,24 +9,18 @@ "description": "Create Module Federation configuration files for given React Host Application.", "type": "object", "properties": { - "name": { - "type": "string", - "description": "The name of the host application to generate the Module Federation configuration", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use as the host application?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "directory": { "description": "The directory of the new application.", "type": "string", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "The name of the host application to generate the Module Federation configuration", + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "style": { "description": "The file extension to be used for style files.", @@ -181,7 +175,7 @@ "x-priority": "important" } }, - "required": ["name"], + "required": ["directory"], "additionalProperties": false, "presets": [] }, diff --git a/docs/generated/packages/react/generators/library.json b/docs/generated/packages/react/generators/library.json index a6c32afe0efd1..1366c05768ddc 100644 --- a/docs/generated/packages/react/generators/library.json +++ b/docs/generated/packages/react/generators/library.json @@ -19,24 +19,17 @@ } ], "properties": { - "name": { - "type": "string", - "description": "Library name", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", - "x-priority": "important" - }, "directory": { "type": "string", "description": "A directory where the lib is placed.", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the library in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Library name", + "x-priority": "important" }, "style": { "description": "The file extension to be used for style files.", @@ -186,7 +179,7 @@ "default": false } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["lib"], diff --git a/docs/generated/packages/react/generators/remote.json b/docs/generated/packages/react/generators/remote.json index 576a47290fc0a..1d6b34b7accb8 100644 --- a/docs/generated/packages/react/generators/remote.json +++ b/docs/generated/packages/react/generators/remote.json @@ -9,24 +9,18 @@ "description": "Create Module Federation configuration files for given React Remote Application.", "type": "object", "properties": { - "name": { - "type": "string", - "description": "The name of the remote application to generate the Module Federation configuration", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use as the remote application?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" - }, "directory": { "description": "The directory of the new application.", "type": "string", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "The name of the remote application to generate the Module Federation configuration", + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "dynamic": { "type": "boolean", @@ -180,7 +174,7 @@ "x-priority": "important" } }, - "required": ["name"], + "required": ["directory"], "additionalProperties": false, "presets": [] }, diff --git a/docs/generated/packages/remix/generators/application.json b/docs/generated/packages/remix/generators/application.json index 9ca0db27d70f9..431fe31f8d75e 100644 --- a/docs/generated/packages/remix/generators/application.json +++ b/docs/generated/packages/remix/generators/application.json @@ -8,28 +8,23 @@ "description": "Generate a new Remix application.", "type": "object", "properties": { - "name": { + "directory": { "type": "string", - "description": "", + "description": "A directory where the app is placed.", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What is the name of the application?" + "x-prompt": "Which directory do you want to create the application in?" + }, + "name": { + "type": "string", + "description": "The name of the application.", + "x-priority": "important" }, "js": { "type": "boolean", "description": "Generate JavaScript files rather than TypeScript files.", "default": false }, - "directory": { - "type": "string", - "description": "A directory where the app is placed.", - "alias": "dir", - "x-priority": "important" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -66,6 +61,7 @@ "default": false } }, + "required": ["directory"], "presets": [] }, "description": "Generate a new Remix application", diff --git a/docs/generated/packages/remix/generators/library.json b/docs/generated/packages/remix/generators/library.json index 2baa96204a6ee..f4400b418cb26 100644 --- a/docs/generated/packages/remix/generators/library.json +++ b/docs/generated/packages/remix/generators/library.json @@ -14,23 +14,18 @@ } ], "properties": { - "name": { - "type": "string", - "description": "Library name", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "^[a-zA-Z].*$" - }, "directory": { "type": "string", "description": "A directory where the lib is placed.", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the library in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Library name", + "pattern": "^[a-zA-Z].*$", + "x-priority": "important" }, "tags": { "type": "string", @@ -70,7 +65,7 @@ "x-priority": "internal" } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "description": "Generate a new library", diff --git a/docs/generated/packages/rspack/generators/application.json b/docs/generated/packages/rspack/generators/application.json index 5671e424cd53d..fed144b73d3f4 100644 --- a/docs/generated/packages/rspack/generators/application.json +++ b/docs/generated/packages/rspack/generators/application.json @@ -9,18 +9,21 @@ "description": "React + Rspack application generator.", "examples": [ { - "command": "nx g app myapp --directory=myorg", + "command": "nx g app myorg/myapp", "description": "Generate `apps/myorg/myapp` and `apps/myorg/myapp-e2e`" } ], "properties": { + "directory": { + "type": "string", + "description": "The directory to nest the app under.", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "What directory would you like to use for the application?" + }, "name": { "description": "The name of the application.", "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z].*$", - "x-priority": "important" + "pattern": "^[a-zA-Z].*$" }, "framework": { "type": "string", @@ -69,10 +72,6 @@ "enum": ["none", "cypress"], "default": "cypress" }, - "directory": { - "type": "string", - "description": "The directory to nest the app under." - }, "tags": { "type": "string", "description": "Add tags to the application (used for linting).", @@ -85,7 +84,7 @@ }, "rootProject": { "type": "boolean", "x-priority": "internal" } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["app"], diff --git a/docs/generated/packages/storybook/generators/cypress-project.json b/docs/generated/packages/storybook/generators/cypress-project.json index 6ad6af0e5ff60..38fd06719f4b6 100644 --- a/docs/generated/packages/storybook/generators/cypress-project.json +++ b/docs/generated/packages/storybook/generators/cypress-project.json @@ -44,11 +44,6 @@ "type": "boolean", "default": false, "x-priority": "internal" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] } }, "required": ["name"], diff --git a/docs/generated/packages/vue/generators/application.json b/docs/generated/packages/vue/generators/application.json index df2b65918104d..0a194f4fc05dc 100644 --- a/docs/generated/packages/vue/generators/application.json +++ b/docs/generated/packages/vue/generators/application.json @@ -19,23 +19,18 @@ ], "type": "object", "properties": { - "name": { - "description": "The name of the application.", - "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" - }, "directory": { "description": "The directory of the new application.", "type": "string", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "style": { "description": "The file extension to be used for style files.", @@ -129,7 +124,7 @@ "hidden": true } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "---\ntitle: Vue application generator examples\ndescription: This page contains examples for the @nx/vue:app generator.\n---\n\n## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```shell\nnx g @nx/vue:app apps/my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Specify directory and style extension\" %}\n\nCreate an application named `my-app` in the `my-dir` directory and use `scss` for styles:\n\n{% callout type=\"note\" title=\"Directory Flag Behavior Changes\" %}\nThe command below uses the `as-provided` directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the `derived` option, use `--directory=my-dir`. See the [as-provided vs. derived documentation](/deprecated/as-provided-vs-derived) for more details.\n{% /callout %}\n\n```shell\nnx g @nx/vue:app apps/my-dir/my-app --style=scss\n```\n\n{% /tab %}\n\n{% tab label=\"Add tags\" %}\n\nAdd tags to the application (used for linting).\n\n```shell\nnx g @nx/vue:app apps/my-app --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n", "presets": [] }, diff --git a/docs/generated/packages/vue/generators/library.json b/docs/generated/packages/vue/generators/library.json index 9635e3ac10fa8..664b2b97a1307 100644 --- a/docs/generated/packages/vue/generators/library.json +++ b/docs/generated/packages/vue/generators/library.json @@ -19,24 +19,18 @@ } ], "properties": { - "name": { - "type": "string", - "description": "Library name", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", - "x-priority": "important" - }, "directory": { "type": "string", "description": "A directory where the lib is placed.", "alias": "dir", - "x-priority": "important" + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the library in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Library name", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", + "x-priority": "important" }, "linter": { "description": "The tool to use for running lint checks.", @@ -129,7 +123,7 @@ "default": false } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "aliases": ["lib"], diff --git a/docs/generated/packages/web/generators/application.json b/docs/generated/packages/web/generators/application.json index d43a64ea75ca5..17ad23a39f77e 100644 --- a/docs/generated/packages/web/generators/application.json +++ b/docs/generated/packages/web/generators/application.json @@ -9,21 +9,17 @@ "description": "Create a web application using `swc` or `babel` as compiler.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", - "type": "string", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" - }, "directory": { "description": "The directory of the new application.", - "type": "string" + "type": "string", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "style": { "description": "The file extension to be used for style files.", @@ -111,7 +107,7 @@ "x-deprecated": "Nx only supports standaloneConfig" } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "## Examples\n\n{% tabs %}\n{% tab label=\"Simple Application\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nx/web:application apps/my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Application using Vite as bundler\" %}\n\nCreate an application named `my-app`:\n\n```bash\nnx g @nx/web:app apps/my-app --bundler=vite\n```\n\nWhen choosing `vite` as the bundler, your unit tests will be set up with `vitest`, unless you choose `none` for `unitTestRunner`.\n\n{% /tab %}\n\n{% tab label=\"Specify directory\" %}\n\nCreate an application named `my-app` in the `my-dir` directory:\n\n{% callout type=\"note\" title=\"Directory Flag Behavior Changes\" %}\nThe command below uses the `as-provided` directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the `derived` option, use `--directory=my-dir`. See the [as-provided vs. derived documentation](/deprecated/as-provided-vs-derived) for more details.\n{% /callout %}\n\n```bash\nnx g @nx/web:app apps/my-dir/my-app\n```\n\n{% /tab %}\n\n{% tab label=\"Add tags\" %}\n\nAdd tags to the application (used for linting).\n\n```bash\nnx g @nx/web:app apps/my-app --tags=scope:admin,type:ui\n```\n\n{% /tab %}\n{% /tabs %}\n", "presets": [] }, diff --git a/docs/generated/packages/workspace/generators/move.json b/docs/generated/packages/workspace/generators/move.json index 7b7675c53a2ef..44d0664e7e7f2 100644 --- a/docs/generated/packages/workspace/generators/move.json +++ b/docs/generated/packages/workspace/generators/move.json @@ -33,11 +33,6 @@ "description": "The folder to move the project into.", "$default": { "$source": "argv", "index": 0 } }, - "projectNameAndRootFormat": { - "description": "Whether to generate the new project name and destination as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "importPath": { "type": "string", "description": "The new import path to use in the `tsconfig.base.json`." diff --git a/docs/generated/packages/workspace/generators/npm-package.json b/docs/generated/packages/workspace/generators/npm-package.json index 62a4d8f769533..ee0fd2cb17d16 100644 --- a/docs/generated/packages/workspace/generators/npm-package.json +++ b/docs/generated/packages/workspace/generators/npm-package.json @@ -9,25 +9,16 @@ "cli": "nx", "type": "object", "properties": { - "name": { - "type": "string", - "description": "Package name.", - "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name of your npm package?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" - }, "directory": { "type": "string", "description": "A directory where the package is placed.", - "alias": "dir" + "alias": "dir", + "$default": { "$source": "argv", "index": 0 }, + "x-prompt": "Which directory do you want to create the package in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - } + "name": { "type": "string", "description": "Package name." } }, - "required": ["name"], + "required": ["directory"], "presets": [] }, "description": "Create a minimal NPM package.", diff --git a/docs/shared/plugins/organization-specific-plugin.md b/docs/shared/plugins/organization-specific-plugin.md index 26c40565871dc..5249f81a5e62a 100644 --- a/docs/shared/plugins/organization-specific-plugin.md +++ b/docs/shared/plugins/organization-specific-plugin.md @@ -48,7 +48,6 @@ export async function libraryGenerator( ) { const callbackAfterFilesUpdated = await reactLibraryGenerator(tree, { ...options, - projectNameAndRootFormat: 'as-provided', linter: Linter.EsLint, style: 'css', unitTestRunner: 'vitest', @@ -214,7 +213,6 @@ export async function libraryGenerator( ...options, tags: `scope:${options.scope}`, directory: options.directory || `${options.scope}/${options.name}`, - projectNameAndRootFormat: 'as-provided', linter: Linter.EsLint, style: 'css', unitTestRunner: 'vitest', @@ -261,7 +259,6 @@ export async function libraryGenerator( ...options, tags: `scope:${options.scope}`, directory, - projectNameAndRootFormat: 'as-provided', linter: Linter.EsLint, style: 'css', unitTestRunner: 'vitest', diff --git a/docs/shared/recipes/module-federation/federate-a-module.md b/docs/shared/recipes/module-federation/federate-a-module.md index f0ec4397f13b1..3e4f47675bfaa 100644 --- a/docs/shared/recipes/module-federation/federate-a-module.md +++ b/docs/shared/recipes/module-federation/federate-a-module.md @@ -46,14 +46,14 @@ Now that we have created the module, we need to configure it to be federated. {%tab label="React"%} ```shell -nx generate @nx/react:federate-module hello/src/index.ts --name=hello --remote=greeting --projectNameAndRootFormat=as-provided +nx generate @nx/react:federate-module hello/src/index.ts --name=hello --remote=greeting ``` {% /tab %} {%tab label="Angular"%} ```shell -nx generate @nx/angular:federate-module hello/src/index.ts --name=hello --remote=greeting --projectNameAndRootFormat=as-provided +nx generate @nx/angular:federate-module hello/src/index.ts --name=hello --remote=greeting ``` {% /tab %} diff --git a/e2e/angular/src/config.test.ts b/e2e/angular/src/config.test.ts index a201c1024bf97..f19ae00cab59e 100644 --- a/e2e/angular/src/config.test.ts +++ b/e2e/angular/src/config.test.ts @@ -13,9 +13,7 @@ describe('angular.json v1 config', () => { beforeAll(() => { newProject({ packages: ['@nx/angular'] }); - runCLI( - `generate @nx/angular:app ${app1} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:app ${app1} --no-interactive`); // reset workspace to use v1 config updateFile(`angular.json`, angularV1Json(app1)); removeFile(`${app1}/project.json`); @@ -33,9 +31,7 @@ describe('angular.json v1 config', () => { it('should generate new app with project.json and keep the existing in angular.json', async () => { // create new app const app2 = uniq('app2'); - runCLI( - `generate @nx/angular:app ${app2} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:app ${app2} --no-interactive`); // should generate project.json for new projects checkFilesExist(`${app2}/project.json`); diff --git a/e2e/angular/src/cypress-component-tests.test.ts b/e2e/angular/src/cypress-component-tests.test.ts index d595509752c45..b780433646e3c 100644 --- a/e2e/angular/src/cypress-component-tests.test.ts +++ b/e2e/angular/src/cypress-component-tests.test.ts @@ -133,7 +133,7 @@ describe('Angular Cypress Component Tests', () => { function createApp(appName: string) { runCLI( - `generate @nx/angular:app ${appName} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${appName} --bundler=webpack --no-interactive` ); runCLI( `generate @nx/angular:component ${appName}/src/lib/fancy-component/fancy-component --no-interactive` @@ -141,9 +141,7 @@ function createApp(appName: string) { } function createLib(projectName: string, appName: string, libName: string) { - runCLI( - `generate @nx/angular:lib ${libName} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:lib ${libName} --no-interactive`); runCLI( `generate @nx/angular:component ${libName}/src/lib/btn/btn --inlineTemplate --inlineStyle --export --no-interactive` ); @@ -186,9 +184,7 @@ export class BtnStandaloneComponent { function createBuildableLib(projectName: string, libName: string) { // create lib - runCLI( - `generate @nx/angular:lib ${libName} --buildable --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:lib ${libName} --buildable --no-interactive`); // create cmp for lib runCLI( `generate @nx/angular:component ${libName}/src/lib/input/input --inlineTemplate --inlineStyle --export --no-interactive` diff --git a/e2e/angular/src/misc.test.ts b/e2e/angular/src/misc.test.ts index 1ff47b5565d81..a6199b0549d79 100644 --- a/e2e/angular/src/misc.test.ts +++ b/e2e/angular/src/misc.test.ts @@ -20,9 +20,7 @@ describe('Move Angular Project', () => { app1 = uniq('app1'); app2 = uniq('app2'); newPath = `subfolder/${app2}`; - runCLI( - `generate @nx/angular:app ${app1} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:app ${app1} --no-interactive`); }); afterAll(() => cleanupProject()); @@ -32,7 +30,7 @@ describe('Move Angular Project', () => { */ it('should work for apps', () => { const moveOutput = runCLI( - `generate @nx/angular:move --project ${app1} ${newPath} --project-name-and-root-format=as-provided` + `generate @nx/angular:move --project ${app1} ${newPath} ` ); // just check the output @@ -76,7 +74,7 @@ describe('Move Angular Project', () => { ` ); const moveOutput = runCLI( - `generate @nx/angular:move --projectName=${app1}-e2e --destination=${newPath}-e2e --project-name-and-root-format=as-provided` + `generate @nx/angular:move --projectName=${app1}-e2e --destination=${newPath}-e2e` ); // just check that the cypress.config.ts is updated correctly @@ -97,17 +95,13 @@ describe('Move Angular Project', () => { it('should work for libraries', () => { const lib1 = uniq('mylib'); const lib2 = uniq('mylib'); - runCLI( - `generate @nx/angular:lib ${lib1} --no-standalone --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:lib ${lib1} --no-standalone --no-interactive`); /** * Create a library which imports the module from the other lib */ - runCLI( - `generate @nx/angular:lib ${lib2} --no-standalone --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:lib ${lib2} --no-standalone --no-interactive`); updateFile( `${lib2}/src/lib/${lib2}.module.ts`, @@ -117,7 +111,7 @@ describe('Move Angular Project', () => { ); const moveOutput = runCLI( - `generate @nx/angular:move --projectName=${lib1} --destination=shared/${lib1} --newProjectName=shared-${lib1} --project-name-and-root-format=as-provided` + `generate @nx/angular:move --projectName=${lib1} --destination=shared/${lib1} --newProjectName=shared-${lib1}` ); const newPath = `shared/${lib1}`; diff --git a/e2e/angular/src/module-federation.test.ts b/e2e/angular/src/module-federation.test.ts index deaaa562c2a1f..45f95c31e1f1e 100644 --- a/e2e/angular/src/module-federation.test.ts +++ b/e2e/angular/src/module-federation.test.ts @@ -40,11 +40,11 @@ describe('Angular Module Federation', () => { // generate host app runCLI( - `generate @nx/angular:host ${hostApp} --style=css --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:host ${hostApp} --style=css --no-standalone --no-interactive` ); // generate remote app runCLI( - `generate @nx/angular:remote ${remoteApp1} --host=${hostApp} --port=${remotePort} --style=css --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:remote ${remoteApp1} --host=${hostApp} --port=${remotePort} --style=css --no-standalone --no-interactive` ); // check files are generated without the layout directory ("apps/") @@ -59,7 +59,7 @@ describe('Angular Module Federation', () => { // generate a shared lib with a seconary entry point runCLI( - `generate @nx/angular:library ${sharedLib} --buildable --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:library ${sharedLib} --buildable --no-standalone --no-interactive` ); runCLI( `generate @nx/angular:library-secondary-entry-point --library=${sharedLib} --name=${secondaryEntry} --no-interactive` @@ -67,7 +67,7 @@ describe('Angular Module Federation', () => { // Add a library that will be accessed via a wildcard in tspath mappings runCLI( - `generate @nx/angular:library ${wildcardLib} --buildable --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:library ${wildcardLib} --buildable --no-standalone --no-interactive` ); updateJson('tsconfig.base.json', (json) => { @@ -180,10 +180,10 @@ describe('Angular Module Federation', () => { // generate apps runCLI( - `generate @nx/angular:application ${app1} --routing --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:application ${app1} --routing --bundler=webpack --no-interactive` ); runCLI( - `generate @nx/angular:application ${app2} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:application ${app2} --bundler=webpack --no-interactive` ); // convert apps @@ -221,7 +221,7 @@ describe('Angular Module Federation', () => { // generate remote apps runCLI( - `generate @nx/angular:host ${host} --ssr --remotes=${remote1},${remote2} --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:host ${host} --ssr --remotes=${remote1},${remote2} --no-interactive` ); // ports @@ -283,12 +283,10 @@ test('renders remotes', async ({ page }) => { const hostPort = 4200; runCLI( - `generate @nx/angular:host ${host} --remotes=${remote} --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided` + `generate @nx/angular:host ${host} --remotes=${remote} --e2eTestRunner=cypress --no-interactive` ); - runCLI( - `generate @nx/js:lib ${lib} --no-interactive --projectNameAndRootFormat=as-provided` - ); + runCLI(`generate @nx/js:lib ${lib} --no-interactive`); // Federate Module runCLI( @@ -357,16 +355,14 @@ test('renders remotes', async ({ page }) => { const hostPort = 4200; runCLI( - `generate @nx/angular:host ${host} --remotes=${remote} --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided` + `generate @nx/angular:host ${host} --remotes=${remote} --e2eTestRunner=cypress --no-interactive` ); - runCLI( - `generate @nx/js:lib ${lib} --no-interactive --projectNameAndRootFormat=as-provided` - ); + runCLI(`generate @nx/js:lib ${lib} --no-interactive`); // Federate Module runCLI( - `generate @nx/angular:federate-module ${lib}/src/index.ts --name=${module} --remote=${childRemote} --no-interactive` + `generate @nx/angular:federate-module ${lib}/src/index.ts --name=${module} --remote=${childRemote} --remoteDirectory=${childRemote} --no-interactive` ); updateFile(`${lib}/src/index.ts`, `export { isEven } from './lib/${lib}';`); diff --git a/e2e/angular/src/ngrx.test.ts b/e2e/angular/src/ngrx.test.ts index 2a0d94457a259..e58dab427cc9f 100644 --- a/e2e/angular/src/ngrx.test.ts +++ b/e2e/angular/src/ngrx.test.ts @@ -21,7 +21,7 @@ describe('Angular Package', () => { it('should work', async () => { const myapp = uniq('myapp'); runCLI( - `generate @nx/angular:app ${myapp} --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${myapp} --no-standalone --no-interactive` ); // Generate root ngrx state management @@ -36,9 +36,7 @@ describe('Angular Package', () => { const mylib = uniq('mylib'); // Generate feature library and ngrx state within that library - runCLI( - `g @nx/angular:lib ${mylib} --prefix=fl --no-standalone --project-name-and-root-format=as-provided` - ); + runCLI(`g @nx/angular:lib ${mylib} --prefix=fl --no-standalone`); runCLI( `generate @nx/angular:ngrx flights --parent=${mylib}/src/lib/${mylib}.module.ts --facade` ); @@ -54,7 +52,7 @@ describe('Angular Package', () => { it('should work with creators', async () => { const myapp = uniq('myapp'); runCLI( - `generate @nx/angular:app ${myapp} --routing --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${myapp} --routing --no-standalone --no-interactive` ); // Generate root ngrx state management @@ -71,9 +69,7 @@ describe('Angular Package', () => { const mylib = uniq('mylib'); // Generate feature library and ngrx state within that library - runCLI( - `g @nx/angular:lib ${mylib} --prefix=fl --no-standalone --project-name-and-root-format=as-provided` - ); + runCLI(`g @nx/angular:lib ${mylib} --prefix=fl --no-standalone`); const flags = `--facade --barrels`; runCLI( @@ -91,7 +87,7 @@ describe('Angular Package', () => { it('should work with creators using --module', async () => { const myapp = uniq('myapp'); runCLI( - `generate @nx/angular:app ${myapp} --routing --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${myapp} --routing --no-standalone --no-interactive` ); // Generate root ngrx state management @@ -108,9 +104,7 @@ describe('Angular Package', () => { const mylib = uniq('mylib'); // Generate feature library and ngrx state within that library - runCLI( - `g @nx/angular:lib ${mylib} --prefix=fl --no-standalone --project-name-and-root-format=as-provided` - ); + runCLI(`g @nx/angular:lib ${mylib} --prefix=fl --no-standalone`); const flags = `--facade --barrels`; runCLI( diff --git a/e2e/angular/src/plugin.test.ts b/e2e/angular/src/plugin.test.ts index bf9b2e1910930..dc80e58868130 100644 --- a/e2e/angular/src/plugin.test.ts +++ b/e2e/angular/src/plugin.test.ts @@ -25,7 +25,6 @@ describe('Angular Crystal Plugin', () => { beforeAll(() => { proj = newProject({ packages: ['@nx/angular'], - unsetProjectNameAndRootFormat: false, }); if (getSelectedPackageManager() === 'pnpm') { diff --git a/e2e/angular/src/projects.test.ts b/e2e/angular/src/projects.test.ts index f191fbe9d13bb..5fbdac544e98b 100644 --- a/e2e/angular/src/projects.test.ts +++ b/e2e/angular/src/projects.test.ts @@ -34,14 +34,12 @@ describe('Angular Projects', () => { beforeAll(() => { proj = newProject({ packages: ['@nx/angular'] }); runCLI( - `generate @nx/angular:app ${app1} --no-standalone --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${app1} --no-standalone --bundler=webpack --no-interactive` ); runCLI( - `generate @nx/angular:app ${esbuildApp} --bundler=esbuild --no-standalone --project-name-and-root-format=as-provided --no-interactive` - ); - runCLI( - `generate @nx/angular:lib ${lib1} --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${esbuildApp} --bundler=esbuild --no-standalone --no-interactive` ); + runCLI(`generate @nx/angular:lib ${lib1} --no-interactive`); app1DefaultModule = readFile(`${app1}/src/app/app.module.ts`); app1DefaultComponentTemplate = readFile( `${app1}/src/app/app.component.html` @@ -72,12 +70,12 @@ describe('Angular Projects', () => { it('should successfully generate apps and libs and work correctly', async () => { const standaloneApp = uniq('standalone-app'); runCLI( - `generate @nx/angular:app ${standaloneApp} --directory=my-dir/${standaloneApp} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app my-dir/${standaloneApp} --bundler=webpack --no-interactive` ); const esbuildStandaloneApp = uniq('esbuild-app'); runCLI( - `generate @nx/angular:app ${esbuildStandaloneApp} --bundler=esbuild --directory=my-dir/${esbuildStandaloneApp} --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app my-dir/${esbuildStandaloneApp} --bundler=esbuild --no-interactive` ); updateFile( @@ -155,7 +153,7 @@ describe('Angular Projects', () => { const app = uniq('app'); runCLI( - `generate @nx/angular:app ${app} --e2eTestRunner=playwright --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${app} --e2eTestRunner=playwright --no-interactive` ); if (runE2ETests('playwright')) { @@ -219,10 +217,10 @@ describe('Angular Projects', () => { const buildableChildLib = uniq('buildlib2'); runCLI( - `generate @nx/angular:library ${buildableLib} --buildable=true --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:library ${buildableLib} --buildable=true --no-standalone --no-interactive` ); runCLI( - `generate @nx/angular:library ${buildableChildLib} --buildable=true --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:library ${buildableChildLib} --buildable=true --no-standalone --no-interactive` ); // update the app module to include a ref to the buildable lib @@ -463,14 +461,14 @@ describe('Angular Projects', () => { const entryPoint = uniq('entrypoint'); runCLI( - `generate @nx/angular:lib ${lib} --publishable --importPath=@${proj}/${lib} --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:lib ${lib} --publishable --importPath=@${proj}/${lib} --no-standalone --no-interactive` ); runCLI( `generate @nx/angular:secondary-entry-point --name=${entryPoint} --library=${lib} --no-interactive` ); runCLI( - `generate @nx/angular:library ${childLib} --publishable=true --importPath=@${proj}/${childLib} --no-standalone --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:library ${childLib} --publishable=true --importPath=@${proj}/${childLib} --no-standalone --no-interactive` ); runCLI( `generate @nx/angular:secondary-entry-point --name=sub --library=${childLib} --no-interactive` @@ -504,12 +502,10 @@ describe('Angular Projects', () => { expect(() => runCLI(`lint ${childLib} --fix`)).not.toThrow(); }); - it('should support generating libraries with a scoped name when --project-name-and-root-format=as-provided', () => { + it('should support generating libraries with a scoped name when', () => { const libName = uniq('@my-org/lib1'); - runCLI( - `generate @nx/angular:lib ${libName} --buildable --standalone --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/angular:lib ${libName} --buildable --standalone`); // check files are generated without the layout directory ("libs/") and // using the project name as the directory when no directory is provided @@ -530,7 +526,7 @@ describe('Angular Projects', () => { const webpackApp = uniq('webpack-app'); runCLI( - `generate @nx/angular:app ${esbuildApp} --bundler=esbuild --ssr --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${esbuildApp} --bundler=esbuild --ssr --no-interactive` ); // check build produces both the browser and server bundles @@ -541,7 +537,7 @@ describe('Angular Projects', () => { ); runCLI( - `generate @nx/angular:app ${webpackApp} --bundler=webpack --ssr --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${webpackApp} --bundler=webpack --ssr --no-interactive` ); // check build only produces the browser bundle diff --git a/e2e/angular/src/tailwind.test.ts b/e2e/angular/src/tailwind.test.ts index 135fb63d1204d..4072723b2e258 100644 --- a/e2e/angular/src/tailwind.test.ts +++ b/e2e/angular/src/tailwind.test.ts @@ -187,7 +187,7 @@ describe('Tailwind support', () => { it('should generate a buildable library with tailwind and build correctly', () => { runCLI( - `generate @nx/angular:lib ${buildLibWithTailwind.name} --buildable --add-tailwind --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:lib ${buildLibWithTailwind.name} --buildable --add-tailwind --no-interactive` ); updateTailwindConfig( `${buildLibWithTailwind.name}/tailwind.config.js`, @@ -209,7 +209,7 @@ describe('Tailwind support', () => { it('should set up tailwind in a previously generated buildable library and build correctly', () => { const buildLibSetupTailwind = uniq('build-lib-setup-tailwind'); runCLI( - `generate @nx/angular:lib ${buildLibSetupTailwind} --buildable --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:lib ${buildLibSetupTailwind} --buildable --no-interactive` ); runCLI( `generate @nx/angular:setup-tailwind ${buildLibSetupTailwind} --no-interactive` @@ -228,7 +228,7 @@ describe('Tailwind support', () => { it('should correctly build a buildable library with a tailwind.config.js file in the project root or workspace root', () => { const buildLibNoProjectConfig = uniq('build-lib-no-project-config'); runCLI( - `generate @nx/angular:lib ${buildLibNoProjectConfig} --buildable --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:lib ${buildLibNoProjectConfig} --buildable --no-interactive` ); createTailwindConfigFile( `${buildLibNoProjectConfig}/tailwind.config.js`, @@ -253,7 +253,7 @@ describe('Tailwind support', () => { it('should generate a publishable library with tailwind and build correctly', () => { runCLI( - `generate @nx/angular:lib ${pubLibWithTailwind.name} --publishable --add-tailwind --importPath=@${project}/${pubLibWithTailwind.name} --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:lib ${pubLibWithTailwind.name} --publishable --add-tailwind --importPath=@${project}/${pubLibWithTailwind.name} --no-interactive` ); updateTailwindConfig( `${pubLibWithTailwind.name}/tailwind.config.js`, @@ -275,7 +275,7 @@ describe('Tailwind support', () => { it('should set up tailwind in a previously generated publishable library and build correctly', () => { const pubLibSetupTailwind = uniq('pub-lib-setup-tailwind'); runCLI( - `generate @nx/angular:lib ${pubLibSetupTailwind} --publishable --importPath=@${project}/${pubLibSetupTailwind} --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:lib ${pubLibSetupTailwind} --publishable --importPath=@${project}/${pubLibSetupTailwind} --no-interactive` ); runCLI( `generate @nx/angular:setup-tailwind ${pubLibSetupTailwind} --no-interactive` @@ -294,7 +294,7 @@ describe('Tailwind support', () => { it('should correctly build a publishable library with a tailwind.config.js file in the project root or workspace root', () => { const pubLibNoProjectConfig = uniq('pub-lib-no-project-config'); runCLI( - `generate @nx/angular:lib ${pubLibNoProjectConfig} --publishable --importPath=@${project}/${pubLibNoProjectConfig} --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:lib ${pubLibNoProjectConfig} --publishable --importPath=@${project}/${pubLibNoProjectConfig} --no-interactive` ); createTailwindConfigFile( `${pubLibNoProjectConfig}/tailwind.config.js`, @@ -379,7 +379,7 @@ describe('Tailwind support', () => { it('should build correctly and only output the tailwind utilities used', async () => { const appWithTailwind = uniq('app-with-tailwind'); runCLI( - `generate @nx/angular:app ${appWithTailwind} --add-tailwind --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${appWithTailwind} --add-tailwind --no-interactive` ); setupTailwindAndProjectDependencies(appWithTailwind); @@ -398,7 +398,7 @@ describe('Tailwind support', () => { it('should build correctly and only output the tailwind utilities used when using webpack and incremental builds', async () => { const appWithTailwind = uniq('app-with-tailwind'); runCLI( - `generate @nx/angular:app ${appWithTailwind} --add-tailwind --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/angular:app ${appWithTailwind} --add-tailwind --bundler=webpack --no-interactive` ); setupTailwindAndProjectDependencies(appWithTailwind); updateJson(join(appWithTailwind, 'project.json'), (config) => { diff --git a/e2e/cypress/src/cypress.test.ts b/e2e/cypress/src/cypress.test.ts index 047d7de53f742..1d29edee458c0 100644 --- a/e2e/cypress/src/cypress.test.ts +++ b/e2e/cypress/src/cypress.test.ts @@ -26,7 +26,7 @@ describe('Cypress E2E Test runner', () => { 'should generate an app with the Cypress as e2e test runner', () => { runCLI( - `generate @nx/react:app ${myapp} --directory=apps/${myapp} --e2eTestRunner=cypress --linter=eslint` + `generate @nx/react:app apps/${myapp} --e2eTestRunner=cypress --linter=eslint` ); // Making sure the package.json file contains the Cypress dependency @@ -155,7 +155,7 @@ export default defineConfig({ async () => { const appName = uniq('next-cy-app'); runCLI( - `generate @nx/next:app ${appName} --directory=apps/${appName} --e2eTestRunner=none --no-interactive --projectNameAndRootFormat=as-provided` + `generate @nx/next:app apps/${appName} --e2eTestRunner=none --no-interactive ` ); runCLI( `generate @nx/next:component apps/${appName}/components/btn --no-interactive` @@ -183,7 +183,7 @@ export default defineConfig({ async () => { let appName = uniq(`angular-cy-app`); runCLI( - `generate @nx/angular:app ${appName} --directory=apps/${appName} --e2eTestRunner=none --no-interactive --bundler=webpack` + `generate @nx/angular:app apps/${appName} --e2eTestRunner=none --no-interactive --bundler=webpack` ); runCLI( `generate @nx/angular:component apps/${appName}/src/app/btn/btn --no-interactive` diff --git a/e2e/detox/src/detox-legacy.test.ts b/e2e/detox/src/detox-legacy.test.ts index c9f982b442738..47235659371b7 100644 --- a/e2e/detox/src/detox-legacy.test.ts +++ b/e2e/detox/src/detox-legacy.test.ts @@ -26,7 +26,7 @@ describe('@nx/detox (legacy)', () => { it('should create files and run lint command for react-native apps', async () => { runCLI( - `generate @nx/react-native:app ${appName} --directory=apps/${appName} --e2eTestRunner=detox --linter=eslint --install=false` + `generate @nx/react-native:app apps/${appName} --e2eTestRunner=detox --linter=eslint --install=false` ); checkFilesExist(`apps/${appName}-e2e/.detoxrc.json`); checkFilesExist(`apps/${appName}-e2e/tsconfig.json`); @@ -43,7 +43,7 @@ describe('@nx/detox (legacy)', () => { it('should create files and run lint command for expo apps', async () => { const expoAppName = uniq('myapp'); runCLI( - `generate @nx/expo:app ${expoAppName} --directory=apps/${expoAppName} --e2eTestRunner=detox --linter=eslint` + `generate @nx/expo:app apps/${expoAppName} --e2eTestRunner=detox --linter=eslint` ); checkFilesExist(`apps/${expoAppName}-e2e/.detoxrc.json`); checkFilesExist(`apps/${expoAppName}-e2e/tsconfig.json`); @@ -61,7 +61,7 @@ describe('@nx/detox (legacy)', () => { const appName = uniq('app1'); runCLI( - `generate @nx/react-native:app ${appName} --e2eTestRunner=detox --linter=eslint --install=false --project-name-and-root-format=as-provided --interactive=false` + `generate @nx/react-native:app ${appName} --e2eTestRunner=detox --linter=eslint --install=false --interactive=false` ); // check files are generated without the layout directory ("apps/") and diff --git a/e2e/detox/src/detox.test.ts b/e2e/detox/src/detox.test.ts index f2ac2096ff1fc..c068e9de380b2 100644 --- a/e2e/detox/src/detox.test.ts +++ b/e2e/detox/src/detox.test.ts @@ -17,10 +17,10 @@ describe('@nx/detox', () => { reactNativeAppName = uniq('appTest'); expoAppName = uniq('expoAppTest'); runCLI( - `generate @nx/react-native:app ${reactNativeAppName} --e2eTestRunner=detox --install=false --project-name-and-root-format=as-provided --interactive=false` + `generate @nx/react-native:app ${reactNativeAppName} --e2eTestRunner=detox --install=false --interactive=false` ); runCLI( - `generate @nx/expo:app ${expoAppName} --e2eTestRunner=detox --project-name-and-root-format=as-provided --interactive=false` + `generate @nx/expo:app ${expoAppName} --e2eTestRunner=detox --interactive=false` ); updateAppDetoxJson(reactNativeAppName); updateAppDetoxJson(expoAppName); diff --git a/e2e/eslint/src/linter-legacy.test.ts b/e2e/eslint/src/linter-legacy.test.ts index 6d7c0d2f2bca4..0e33e0b910740 100644 --- a/e2e/eslint/src/linter-legacy.test.ts +++ b/e2e/eslint/src/linter-legacy.test.ts @@ -27,13 +27,10 @@ describe('Linter (legacy)', () => { newProject({ packages: ['@nx/react', '@nx/js', '@nx/eslint'], }); - runCLI( - `generate @nx/react:app ${myapp} --tags=validtag --directory=apps/${myapp}`, - { - env: { NX_ADD_PLUGINS: 'false' }, - } - ); - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`, { + runCLI(`generate @nx/react:app apps/${myapp} --tags=validtag`, { + env: { NX_ADD_PLUGINS: 'false' }, + }); + runCLI(`generate @nx/js:lib apps/${mylib}`, { env: { NX_ADD_PLUGINS: 'false' }, }); }); @@ -138,18 +135,12 @@ describe('Linter (legacy)', () => { bundler: 'vite', e2eTestRunner: 'none', }); - runCLI( - `generate @nx/js:lib ${mylib} --directory libs/${mylib} --projectNameAndRootFormat as-provided`, - { - env: { NX_ADD_PLUGINS: 'false' }, - } - ); - runCLI( - `generate @nx/js:lib ${mylib2} --directory libs/${mylib2} --projectNameAndRootFormat as-provided`, - { - env: { NX_ADD_PLUGINS: 'false' }, - } - ); + runCLI(`generate @nx/js:lib libs/${mylib}`, { + env: { NX_ADD_PLUGINS: 'false' }, + }); + runCLI(`generate @nx/js:lib libs/${mylib2}`, { + env: { NX_ADD_PLUGINS: 'false' }, + }); // migrate to flat structure runCLI(`generate @nx/eslint:convert-to-flat-config`, { diff --git a/e2e/eslint/src/linter.test.ts b/e2e/eslint/src/linter.test.ts index d3cb8d71e5639..055a804f98d82 100644 --- a/e2e/eslint/src/linter.test.ts +++ b/e2e/eslint/src/linter.test.ts @@ -35,10 +35,8 @@ describe('Linter', () => { projScope = newProject({ packages: ['@nx/react', '@nx/js', '@nx/eslint'], }); - runCLI( - `generate @nx/react:app ${myapp} --tags=validtag --directory=apps/${myapp}` - ); - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/react:app apps/${myapp} --tags=validtag`); + runCLI(`generate @nx/js:lib libs/${mylib}`); }); afterAll(() => cleanupProject()); @@ -211,14 +209,10 @@ describe('Linter', () => { const invalidtaglib = uniq('invalidtaglib'); const validtaglib = uniq('validtaglib'); - runCLI(`generate @nx/react:app ${myapp2} --directory=apps/${myapp2}`); - runCLI(`generate @nx/react:lib ${lazylib} --directory=libs/${lazylib}`); - runCLI( - `generate @nx/js:lib ${invalidtaglib} --tags=invalidtag --directory=libs/${invalidtaglib}` - ); - runCLI( - `generate @nx/js:lib ${validtaglib} --tags=validtag --directory=libs/${validtaglib}` - ); + runCLI(`generate @nx/react:app apps/${myapp2}`); + runCLI(`generate @nx/react:lib libs/${lazylib}`); + runCLI(`generate @nx/js:lib libs/${invalidtaglib} --tags=invalidtag`); + runCLI(`generate @nx/js:lib libs/${validtaglib} --tags=validtag`); const eslint = readJson('.eslintrc.json'); eslint.overrides[0].rules[ @@ -280,15 +274,9 @@ describe('Linter', () => { beforeAll(() => { // make these libs non-buildable to avoid dep-checks triggering lint errors - runCLI( - `generate @nx/js:lib ${libA} --bundler=none --directory=libs/${libA}` - ); - runCLI( - `generate @nx/js:lib ${libB} --bundler=none --directory=libs/${libB}` - ); - runCLI( - `generate @nx/js:lib ${libC} --bundler=none --directory=libs/${libC}` - ); + runCLI(`generate @nx/js:lib libs/${libA} --bundler=none`); + runCLI(`generate @nx/js:lib libs/${libB} --bundler=none`); + runCLI(`generate @nx/js:lib libs/${libC} --bundler=none`); /** * create tslib-a structure @@ -602,12 +590,8 @@ describe('Linter', () => { const reactLib = uniq('react-lib'); const jsLib = uniq('js-lib'); - runCLI( - `generate @nx/react:lib ${reactLib} --directory=${reactLib} --projectNameAndRootFormat=as-provided` - ); - runCLI( - `generate @nx/js:lib ${jsLib} --directory=${jsLib} --projectNameAndRootFormat=as-provided` - ); + runCLI(`generate @nx/react:lib ${reactLib}`); + runCLI(`generate @nx/js:lib ${jsLib}`); checkFilesExist( `${reactLib}/eslint.config.js`, @@ -686,7 +670,7 @@ describe('Linter', () => { const mylib = uniq('mylib'); runCLI( - `generate @nx/react:app ${myapp} --unitTestRunner=jest --rootProject=true` + `generate @nx/react:app --name=${myapp} --unitTestRunner=jest --directory="."` ); verifySuccessfulStandaloneSetup(myapp); @@ -700,9 +684,7 @@ describe('Linter', () => { let e2eOverrides = JSON.stringify(e2eEslint.overrides); expect(e2eOverrides).toContain('plugin:@nx/javascript'); - runCLI( - `generate @nx/js:lib ${mylib} --unitTestRunner=jest --directory=libs/${mylib}` - ); + runCLI(`generate @nx/js:lib libs/${mylib} --unitTestRunner=jest`); verifySuccessfulMigratedSetup(myapp, mylib); appEslint = readJson(`.eslintrc.json`); @@ -722,7 +704,7 @@ describe('Linter', () => { const mylib = uniq('mylib'); runCLI( - `generate @nx/angular:app ${myapp} --rootProject=true --no-interactive` + `generate @nx/angular:app --name=${myapp} --directory="." --no-interactive` ); verifySuccessfulStandaloneSetup(myapp); @@ -735,9 +717,7 @@ describe('Linter', () => { let e2eOverrides = JSON.stringify(e2eEslint.overrides); expect(e2eOverrides).toContain('plugin:@nx/javascript'); - runCLI( - `generate @nx/js:lib ${mylib} --no-interactive --directory=libs/${mylib}` - ); + runCLI(`generate @nx/js:lib libs/${mylib} --no-interactive`); verifySuccessfulMigratedSetup(myapp, mylib); appEslint = readJson(`.eslintrc.json`); @@ -755,7 +735,7 @@ describe('Linter', () => { const mylib = uniq('mylib'); runCLI( - `generate @nx/node:app ${myapp} --rootProject=true --no-interactive` + `generate @nx/node:app --name=${myapp} --directory="." --no-interactive` ); verifySuccessfulStandaloneSetup(myapp); @@ -770,9 +750,7 @@ describe('Linter', () => { expect(e2eOverrides).toContain('plugin:@nx/javascript'); expect(e2eOverrides).toContain('plugin:@nx/typescript'); - runCLI( - `generate @nx/js:lib ${mylib} --no-interactive --directory=libs/${mylib}` - ); + runCLI(`generate @nx/js:lib libs/${mylib} --no-interactive`); verifySuccessfulMigratedSetup(myapp, mylib); appEslint = readJson(`.eslintrc.json`); diff --git a/e2e/expo/src/expo-legacy.test.ts b/e2e/expo/src/expo-legacy.test.ts index fd13afb1a7616..82f852de687a3 100644 --- a/e2e/expo/src/expo-legacy.test.ts +++ b/e2e/expo/src/expo-legacy.test.ts @@ -40,10 +40,10 @@ describe('@nx/expo (legacy)', () => { return nxJson; }); runCLI( - `generate @nx/expo:application ${appName} --directory=apps/${appName} --e2eTestRunner=cypress --no-interactive` + `generate @nx/expo:application apps/${appName} --e2eTestRunner=cypress --no-interactive` ); runCLI( - `generate @nx/expo:library ${libName} --directory=libs/${libName} --buildable --publishable --importPath=${proj}/${libName}` + `generate @nx/expo:library libs/${libName} --buildable --publishable --importPath=${proj}/${libName}` ); }); afterAll(() => { @@ -210,9 +210,7 @@ describe('@nx/expo (legacy)', () => { const appName = uniq('app1'); const libName = uniq('@my-org/lib1'); - runCLI( - `generate @nx/expo:application ${appName} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/expo:application ${appName} --no-interactive`); // check files are generated without the layout directory ("apps/") and // using the project name as the directory when no directory is provided @@ -223,9 +221,7 @@ describe('@nx/expo (legacy)', () => { `Successfully ran target test for project ${appName}` ); - runCLI( - `generate @nx/expo:library ${libName} --buildable --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/expo:library ${libName} --buildable`); // check files are generated without the layout directory ("libs/") and // using the project name as the directory when no directory is provided diff --git a/e2e/expo/src/expo.test.ts b/e2e/expo/src/expo.test.ts index d480ec85cbef7..3e5dfc7a7d638 100644 --- a/e2e/expo/src/expo.test.ts +++ b/e2e/expo/src/expo.test.ts @@ -23,9 +23,7 @@ describe('@nx/expo', () => { beforeAll(() => { newProject(); appName = uniq('app'); - runCLI( - `generate @nx/expo:app ${appName} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/expo:app ${appName} --no-interactive`); }); afterAll(() => cleanupProject()); diff --git a/e2e/gradle/src/gradle-import.test.ts b/e2e/gradle/src/gradle-import.test.ts index 6f618d8cbc819..18f14d75d6a70 100644 --- a/e2e/gradle/src/gradle-import.test.ts +++ b/e2e/gradle/src/gradle-import.test.ts @@ -22,7 +22,6 @@ describe('Nx Import Gradle', () => { beforeAll(() => { proj = newProject({ packages: ['@nx/js'], - unsetProjectNameAndRootFormat: false, }); if (getSelectedPackageManager() === 'pnpm') { diff --git a/e2e/jest/src/jest-legacy.test.ts b/e2e/jest/src/jest-legacy.test.ts index c749dac0ab53b..a78d7d0fc46df 100644 --- a/e2e/jest/src/jest-legacy.test.ts +++ b/e2e/jest/src/jest-legacy.test.ts @@ -18,14 +18,11 @@ describe('Jest', () => { it('should support multiple `coverageReporters` when using @nx/jest:jest executor', async () => { const mylib = uniq('mylib'); - runCLI( - `generate @nx/js:lib ${mylib} --directory=libs/${mylib} --unitTestRunner=jest`, - { - env: { - NX_ADD_PLUGINS: 'false', - }, - } - ); + runCLI(`generate @nx/js:lib libs/${mylib} --unitTestRunner=jest`, { + env: { + NX_ADD_PLUGINS: 'false', + }, + }); updateFile( `libs/${mylib}/src/lib/${mylib}.spec.ts`, diff --git a/e2e/jest/src/jest-root.test.ts b/e2e/jest/src/jest-root.test.ts index 151c9eba6673b..562ba69b83db9 100644 --- a/e2e/jest/src/jest-root.test.ts +++ b/e2e/jest/src/jest-root.test.ts @@ -8,10 +8,9 @@ describe('Jest root projects', () => { beforeAll(() => { newProject({ packages: ['@nx/angular'], - unsetProjectNameAndRootFormat: false, }); runCLI( - `generate @nx/angular:app ${myapp} --directory . --rootProject --projectNameAndRootFormat as-provided --no-interactive` + `generate @nx/angular:app --name=${myapp} --directory . --rootProject --no-interactive` ); }); @@ -20,9 +19,7 @@ describe('Jest root projects', () => { }, 300_000); it('should add lib project and tests should still work', async () => { - runCLI( - `generate @nx/angular:lib ${mylib} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:lib ${mylib} --no-interactive`); expect(() => runCLI(`test ${mylib}`)).not.toThrow(); expect(() => runCLI(`test ${myapp}`)).not.toThrow(); @@ -33,10 +30,9 @@ describe('Jest root projects', () => { beforeAll(() => { newProject({ packages: ['@nx/react'], - unsetProjectNameAndRootFormat: false, }); runCLI( - `generate @nx/react:app ${myapp} --directory . --rootProject --projectNameAndRootFormat as-provided` + `generate @nx/react:app --name=${myapp} --directory . --rootProject` ); }); @@ -45,9 +41,7 @@ describe('Jest root projects', () => { }, 300_000); it('should add lib project and tests should still work', async () => { - runCLI( - `generate @nx/react:lib ${mylib} --unitTestRunner=jest --projectNameAndRootFormat as-provided` - ); + runCLI(`generate @nx/react:lib ${mylib} --unitTestRunner=jest`); expect(() => runCLI(`test ${mylib}`)).not.toThrow(); expect(() => runCLI(`test ${myapp}`)).not.toThrow(); diff --git a/e2e/jest/src/jest.test.ts b/e2e/jest/src/jest.test.ts index 517f1c717bbfe..afb824d03a757 100644 --- a/e2e/jest/src/jest.test.ts +++ b/e2e/jest/src/jest.test.ts @@ -43,10 +43,10 @@ describe('Jest', () => { const mylib = uniq('mylib'); const utilLib = uniq('util-lib'); runCLI( - `generate @nx/js:lib ${mylib} --directory=libs/${mylib} --unitTestRunner=jest --no-interactive` + `generate @nx/js:lib libs/${mylib} --unitTestRunner=jest --no-interactive` ); runCLI( - `generate @nx/js:lib ${utilLib} --directory=libs/${utilLib} --importPath=@global-fun/globals --unitTestRunner=jest --no-interactive` + `generate @nx/js:lib libs/${utilLib} --importPath=@global-fun/globals --unitTestRunner=jest --no-interactive` ); updateFile( `libs/${utilLib}/src/index.ts`, @@ -122,9 +122,7 @@ describe('Jest', () => { it('should set the NODE_ENV to `test`', async () => { const mylib = uniq('mylib'); - runCLI( - `generate @nx/js:lib ${mylib} --directory=libs/${mylib} --unitTestRunner=jest` - ); + runCLI(`generate @nx/js:lib libs/${mylib} --unitTestRunner=jest`); updateFile( `libs/${mylib}/src/lib/${mylib}.spec.ts`, @@ -143,7 +141,7 @@ describe('Jest', () => { it('should be able to test node lib with babel-jest', async () => { const libName = uniq('babel-test-lib'); runCLI( - `generate @nx/node:lib ${libName} --directory=libs/${libName} --buildable --importPath=@some-org/babel-test --publishable --babelJest` + `generate @nx/node:lib libs/${libName} --buildable --importPath=@some-org/babel-test --publishable --babelJest` ); const cliResults = await runCLIAsync(`test ${libName}`); @@ -154,9 +152,7 @@ describe('Jest', () => { it('should be able to run e2e tests split by tasks', async () => { const libName = uniq('lib'); - runCLI( - `generate @nx/js:lib ${libName} --directory=libs/${libName} --unitTestRunner=jest` - ); + runCLI(`generate @nx/js:lib libs/${libName} --unitTestRunner=jest`); updateJson('nx.json', (json) => { const jestPlugin = json.plugins.find( (plugin) => plugin.plugin === '@nx/jest/plugin' diff --git a/e2e/js/src/js-executor-node.test.ts b/e2e/js/src/js-executor-node.test.ts index c05ce6de62bcd..31a554cae4622 100644 --- a/e2e/js/src/js-executor-node.test.ts +++ b/e2e/js/src/js-executor-node.test.ts @@ -21,7 +21,7 @@ describe('js:node executor', () => { const esbuildLib = uniq('esbuildlib'); runCLI( - `generate @nx/js:lib ${esbuildLib} --directory=libs/${esbuildLib} --bundler=esbuild --no-interactive` + `generate @nx/js:lib libs/${esbuildLib} --bundler=esbuild --no-interactive` ); updateFile(`libs/${esbuildLib}/src/index.ts`, () => { @@ -55,7 +55,7 @@ describe('js:node executor', () => { const rollupLib = uniq('rolluplib'); runCLI( - `generate @nx/js:lib ${rollupLib} --directory=libs/${rollupLib} --bundler=rollup --no-interactive` + `generate @nx/js:lib libs/${rollupLib} --bundler=rollup --no-interactive` ); updateFile(`libs/${rollupLib}/src/index.ts`, () => { @@ -82,9 +82,7 @@ describe('js:node executor', () => { it('should execute library compiled with tsc', async () => { const tscLib = uniq('tsclib'); - runCLI( - `generate @nx/js:lib ${tscLib} --directory=libs/${tscLib} --bundler=tsc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${tscLib} --bundler=tsc --no-interactive`); updateFile(`libs/${tscLib}/src/index.ts`, () => { return ` @@ -110,9 +108,7 @@ describe('js:node executor', () => { it('should execute library compiled with swc', async () => { const swcLib = uniq('swclib'); - runCLI( - `generate @nx/js:lib ${swcLib} --directory=libs/${swcLib} --bundler=swc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${swcLib} --bundler=swc --no-interactive`); updateFile(`libs/${swcLib}/src/index.ts`, () => { return ` @@ -139,7 +135,7 @@ describe('js:node executor', () => { const webpackProject = uniq('webpackproject'); runCLI( - `generate @nx/node:application ${webpackProject} --directory=apps/${webpackProject} --bundler=webpack --no-interactive` + `generate @nx/node:application apps/${webpackProject} --bundler=webpack --no-interactive` ); updateFile(`apps/${webpackProject}/src/main.ts`, () => { diff --git a/e2e/js/src/js-executor-swc.test.ts b/e2e/js/src/js-executor-swc.test.ts index 2f5e9b6840653..63cd5e2b07296 100644 --- a/e2e/js/src/js-executor-swc.test.ts +++ b/e2e/js/src/js-executor-swc.test.ts @@ -24,9 +24,7 @@ describe('js:swc executor', () => { it('should create libs with js executors (--bundler=swc)', async () => { const lib = uniq('lib'); - runCLI( - `generate @nx/js:lib ${lib} --directory=libs/${lib} --bundler=swc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${lib} --bundler=swc --no-interactive`); const libPackageJson = readJson(`libs/${lib}/package.json`); expect(libPackageJson.scripts).toBeUndefined(); @@ -50,9 +48,7 @@ describe('js:swc executor', () => { it('should handle swcrc path mappings', async () => { const lib = uniq('lib'); - runCLI( - `generate @nx/js:lib ${lib} --directory=libs/${lib} --bundler=swc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${lib} --bundler=swc --no-interactive`); // add a dummy x.ts file for path mappings updateFile( @@ -99,9 +95,7 @@ myLib(); it('should support --strip-leading-paths option', () => { const lib = uniq('lib'); - runCLI( - `generate @nx/js:lib ${lib} --directory=libs/${lib} --bundler=swc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${lib} --bundler=swc --no-interactive`); runCLI(`build ${lib} --stripLeadingPaths`); diff --git a/e2e/js/src/js-executor-tsc.test.ts b/e2e/js/src/js-executor-tsc.test.ts index 704a5aea5c3e1..d4685d8a74ae7 100644 --- a/e2e/js/src/js-executor-tsc.test.ts +++ b/e2e/js/src/js-executor-tsc.test.ts @@ -28,9 +28,7 @@ describe('js:tsc executor', () => { it('should create libs with js executors (--compiler=tsc)', async () => { const lib = uniq('lib'); - runCLI( - `generate @nx/js:lib ${lib} --directory=libs/${lib} --bundler=tsc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${lib} --bundler=tsc --no-interactive`); const libPackageJson = readJson(`libs/${lib}/package.json`); expect(libPackageJson.scripts).toBeUndefined(); @@ -112,7 +110,7 @@ describe('js:tsc executor', () => { const parentLib = uniq('parentlib'); runCLI( - `generate @nx/js:lib ${parentLib} --directory=libs/${parentLib} --bundler=tsc --no-interactive` + `generate @nx/js:lib libs/${parentLib} --bundler=tsc --no-interactive` ); const parentLibPackageJson = readJson(`libs/${parentLib}/package.json`); expect(parentLibPackageJson.scripts).toBeUndefined(); @@ -217,7 +215,7 @@ describe('js:tsc executor', () => { it('should not create a `.babelrc` file when creating libs with js executors (--compiler=tsc)', () => { const lib = uniq('lib'); runCLI( - `generate @nx/js:lib ${lib} --compiler=tsc --directory=libs/${lib}--includeBabelRc=false --no-interactive` + `generate @nx/js:lib libs/${lib} --compiler=tsc --includeBabelRc=false --no-interactive` ); checkFilesDoNotExist(`libs/${lib}/.babelrc`); @@ -225,14 +223,10 @@ describe('js:tsc executor', () => { it('should allow wildcard ts path alias', async () => { const base = uniq('base'); - runCLI( - `generate @nx/js:lib ${base} --directory=libs/${base} --bundler=tsc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${base} --bundler=tsc --no-interactive`); const lib = uniq('lib'); - runCLI( - `generate @nx/js:lib ${lib} --directory=libs/${lib} --bundler=tsc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${lib} --bundler=tsc --no-interactive`); updateFile(`libs/${base}/src/index.ts`, () => { return ` @@ -282,9 +276,7 @@ export function ${lib}Wildcard() { it('should update package.json with detected dependencies', async () => { const pmc = getPackageManagerCommand(); const lib = uniq('lib'); - runCLI( - `generate @nx/js:lib ${lib} --directory=libs/${lib} --bundler=tsc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${lib} --bundler=tsc --no-interactive`); // Add a dependency for this lib to check the built package.json runCommand(`${pmc.addProd} react`); diff --git a/e2e/js/src/js-generators.ts b/e2e/js/src/js-generators.ts index c8533d230f055..0f0022936a435 100644 --- a/e2e/js/src/js-generators.ts +++ b/e2e/js/src/js-generators.ts @@ -25,7 +25,7 @@ describe('js e2e', () => { it('should create libs with npm scripts', () => { const npmScriptsLib = uniq('npmscriptslib'); runCLI( - `generate @nx/js:lib ${npmScriptsLib} --directory=libs/${npmScriptsLib} --config=npm-scripts --no-interactive` + `generate @nx/js:lib libs/${npmScriptsLib} --config=npm-scripts --no-interactive` ); const libPackageJson = readJson(`libs/${npmScriptsLib}/package.json`); expect(libPackageJson.scripts.test).toBeDefined(); @@ -43,7 +43,7 @@ describe('js e2e', () => { const dirName = uniq('dir'); runCLI( - `generate @nx/js:lib ${dirName}-${libName} --directory libs/${dirName}/${libName}` + `generate @nx/js:lib --name=${dirName}-${libName} --directory libs/${dirName}/${libName}` ); checkFilesExist( @@ -67,9 +67,7 @@ describe('js e2e', () => { it('should be able to add build to non-buildable projects', () => { const nonBuildable = uniq('nonbuildable'); - runCLI( - `generate @nx/js:lib ${nonBuildable} --directory=libs/${nonBuildable} --bundler=none` - ); + runCLI(`generate @nx/js:lib libs/${nonBuildable} --bundler=none`); expect(() => runCLI(`build ${nonBuildable}`)).toThrow(); checkFilesDoNotExist(`dist/libs/${nonBuildable}/src/index.js`); @@ -83,12 +81,8 @@ describe('js e2e', () => { it('should build buildable libraries using the task graph and handle more scenarios than current implementation', () => { const lib1 = uniq('lib1'); const lib2 = uniq('lib2'); - runCLI( - `generate @nx/js:lib ${lib1} --directory=libs/${lib1} --bundler=tsc --no-interactive` - ); - runCLI( - `generate @nx/js:lib ${lib2} --directory=libs/${lib2} --bundler=tsc --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${lib1} --bundler=tsc --no-interactive`); + runCLI(`generate @nx/js:lib libs/${lib2} --bundler=tsc --no-interactive`); // add dep between lib1 and lib2 updateFile( @@ -152,10 +146,10 @@ describe('js e2e', () => { updateFile('nx.json', () => originalNxJson); }); - it('should generate project with name and directory as provided when --project-name-and-root-format=as-provided', async () => { + it('should generate project with name and directory as provided', async () => { const lib1 = uniq('lib1'); runCLI( - `generate @nx/js:lib ${lib1} --directory=shared --bundler=tsc --project-name-and-root-format=as-provided` + `generate @nx/js:lib --name=${lib1} --directory=shared --bundler=tsc` ); // check files are generated without the layout directory ("libs/") and @@ -172,12 +166,10 @@ describe('js e2e', () => { ); }, 500_000); - it('should support generating with a scoped project name when --project-name-and-root-format=as-provided', async () => { + it('should support generating with a scoped project name', async () => { const scopedLib = uniq('@my-org/lib1'); - runCLI( - `generate @nx/js:lib ${scopedLib} --bundler=tsc --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/js:lib ${scopedLib} --bundler=tsc`); // check files are generated without the layout directory ("libs/") and // using the project name as the directory when no directory is provided diff --git a/e2e/js/src/js-inlining.test.ts b/e2e/js/src/js-inlining.test.ts index 9e7e8b05d5227..3ab1a817017d2 100644 --- a/e2e/js/src/js-inlining.test.ts +++ b/e2e/js/src/js-inlining.test.ts @@ -23,22 +23,22 @@ describe('inlining', () => { async (bundler) => { const parent = uniq('parent'); runCLI( - `generate @nx/js:lib ${parent} --directory=libs/${parent} --bundler=${bundler} --no-interactive` + `generate @nx/js:lib libs/${parent} --bundler=${bundler} --no-interactive` ); const buildable = uniq('buildable'); runCLI( - `generate @nx/js:lib ${buildable} --directory=libs/${buildable} --bundler=${bundler} --no-interactive` + `generate @nx/js:lib libs/${buildable} --bundler=${bundler} --no-interactive` ); const buildableTwo = uniq('buildabletwo'); runCLI( - `generate @nx/js:lib ${buildableTwo} --directory=libs/${buildableTwo} --bundler=${bundler} --no-interactive` + `generate @nx/js:lib libs/${buildableTwo} --bundler=${bundler} --no-interactive` ); const nonBuildable = uniq('nonbuildable'); runCLI( - `generate @nx/js:lib ${nonBuildable} --directory=libs/${nonBuildable} --bundler=none --no-interactive` + `generate @nx/js:lib libs/${nonBuildable} --bundler=none --no-interactive` ); updateFile(`libs/${parent}/src/lib/${parent}.ts`, () => { @@ -102,18 +102,14 @@ describe('inlining', () => { it('should inline nesting libraries', async () => { const parent = uniq('parent'); - runCLI( - `generate @nx/js:lib ${parent} --directory=libs/${parent} --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${parent} --no-interactive`); const child = uniq('child'); - runCLI( - `generate @nx/js:lib ${child} --directory=libs/${child} --bundler=none --no-interactive` - ); + runCLI(`generate @nx/js:lib libs/${child} --bundler=none --no-interactive`); const grandChild = uniq('grandchild'); runCLI( - `generate @nx/js:lib ${grandChild} --directory=libs/${grandChild} --bundler=none --no-interactive` + `generate @nx/js:lib libs/${grandChild} --bundler=none --no-interactive` ); updateFile(`libs/${parent}/src/lib/${parent}.ts`, () => { diff --git a/e2e/js/src/js-packaging.test.ts b/e2e/js/src/js-packaging.test.ts index f5ead3bc49e12..3a4b3c4ab633c 100644 --- a/e2e/js/src/js-packaging.test.ts +++ b/e2e/js/src/js-packaging.test.ts @@ -30,13 +30,13 @@ describe('packaging libs', () => { const rollupLib = uniq('rolluplib'); runCLI( - `generate @nx/js:lib ${esbuildLib} --directory=libs/${esbuildLib} --bundler=esbuild --no-interactive` + `generate @nx/js:lib libs/${esbuildLib} --bundler=esbuild --no-interactive` ); runCLI( - `generate @nx/js:lib ${viteLib} --directory=libs/${viteLib} --bundler=vite --no-interactive` + `generate @nx/js:lib libs/${viteLib} --bundler=vite --no-interactive` ); runCLI( - `generate @nx/js:lib ${rollupLib} --directory=libs/${rollupLib} --bundler=rollup --no-interactive` + `generate @nx/js:lib libs/${rollupLib} --bundler=rollup --no-interactive` ); updateFile(`libs/${rollupLib}/src/index.ts`, (content) => { // Test that default functions work in ESM (Node). @@ -139,17 +139,15 @@ describe('packaging libs', () => { const tscEsmLib = uniq('tscesmlib'); const swcEsmLib = uniq('swcesmlib'); + runCLI(`generate @nx/js:lib libs/${tscLib} --bundler=tsc --no-interactive`); runCLI( - `generate @nx/js:lib ${tscLib} --directory=libs/${tscLib} --bundler=tsc --no-interactive` + `generate @nx/js:lib libs/${swcLib} --bundler=swc --no-interactive` ); runCLI( - `generate @nx/js:lib ${swcLib} --directory=libs/${swcLib} --bundler=swc --no-interactive` + `generate @nx/js:lib libs/${tscEsmLib} --bundler=tsc --no-interactive` ); runCLI( - `generate @nx/js:lib ${tscEsmLib} --directory=libs/${tscEsmLib} --bundler=tsc --no-interactive` - ); - runCLI( - `generate @nx/js:lib ${swcEsmLib} --directory=libs/${swcEsmLib} --bundler=swc --no-interactive` + `generate @nx/js:lib libs/${swcEsmLib} --bundler=swc --no-interactive` ); // Change module format to ESM diff --git a/e2e/next/src/next-component-tests.test.ts b/e2e/next/src/next-component-tests.test.ts index b540f9fa3ca7e..290463f879464 100644 --- a/e2e/next/src/next-component-tests.test.ts +++ b/e2e/next/src/next-component-tests.test.ts @@ -118,7 +118,7 @@ function addBabelSupport(path: string) { function createAppWithCt(appName: string) { runCLI( - `generate @nx/next:app ${appName} --directory=apps/${appName} --no-interactive --appDir=false --src=false --projectNameAndRootFormat=as-provided` + `generate @nx/next:app apps/${appName} --no-interactive --appDir=false --src=false` ); runCLI( `generate @nx/next:component apps/${appName}/components/button --no-interactive` @@ -213,9 +213,7 @@ export default Button; } function createLibWithCtCypress(libName: string) { - runCLI( - `generate @nx/next:lib ${libName} --no-interactive --projectNameAndRootFormat=as-provided` - ); + runCLI(`generate @nx/next:lib ${libName} --no-interactive`); runCLI( `generate @nx/next:cypress-component-configuration --project=${libName} --no-interactive` @@ -254,6 +252,7 @@ function createLibWithCtCypress(libName: string) { ` ); } + function addTailwindToLib(libName: string) { createFile(`libs/${libName}/src/lib/styles.css`, ``); runCLI( diff --git a/e2e/next/src/next-playwright.test.ts b/e2e/next/src/next-playwright.test.ts index 30d3dc16632a3..833012b77d2f9 100644 --- a/e2e/next/src/next-playwright.test.ts +++ b/e2e/next/src/next-playwright.test.ts @@ -18,7 +18,7 @@ describe('Next Playwright e2e tests', () => { packages: ['@nx/next'], }); runCLI( - `generate @nx/next:app ${appName} --e2eTestRunner=playwright --projectNameAndRootFormat=as-provided --no-interactive` + `generate @nx/next:app ${appName} --e2eTestRunner=playwright --no-interactive` ); }); @@ -35,7 +35,7 @@ describe('Next Playwright e2e tests', () => { it('should execute e2e tests using playwright with a library used in the app', () => { runCLI( - `generate @nx/js:library ${usedInAppLibName} --unitTestRunner=none --importPath=@mylib --projectNameAndRootFormat=as-provided --no-interactive` + `generate @nx/js:library ${usedInAppLibName} --unitTestRunner=none --importPath=@mylib --no-interactive` ); updateFile( diff --git a/e2e/next/src/next-storybook.test.ts b/e2e/next/src/next-storybook.test.ts index 15ab50ad17148..bfff89e910db2 100644 --- a/e2e/next/src/next-storybook.test.ts +++ b/e2e/next/src/next-storybook.test.ts @@ -15,7 +15,7 @@ describe('Next.js Storybook', () => { packages: ['@nx/next', '@nx/react'], }); runCLI( - `generate @nx/next:app ${appName} --e2eTestRunner=none --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/next:app ${appName} --e2eTestRunner=none --no-interactive` ); runCLI( `generate @nx/next:component ${appName}/components/foo/foo --no-interactive` diff --git a/e2e/next/src/next.test.ts b/e2e/next/src/next.test.ts index 7b96f2b61bb25..3a98be9f5ddf9 100644 --- a/e2e/next/src/next.test.ts +++ b/e2e/next/src/next.test.ts @@ -37,9 +37,7 @@ describe('Next.js Applications', () => { const appName = uniq('app1'); const libName = uniq('@my-org/lib1'); - runCLI( - `generate @nx/next:app ${appName} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/next:app ${appName} --no-interactive`); // check files are generated without the layout directory ("apps/") and // using the project name as the directory when no directory is provided @@ -54,9 +52,7 @@ describe('Next.js Applications', () => { `Successfully ran target test for project ${appName}` ); - runCLI( - `generate @nx/next:lib ${libName} --buildable --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/next:lib ${libName} --buildable --no-interactive`); // check files are generated without the layout directory ("libs/") and // using the project name as the directory when no directory is provided @@ -189,9 +185,7 @@ describe('Next.js Applications', () => { it('should run e2e-ci test', async () => { const appName = uniq('app'); - runCLI( - `generate @nx/next:app ${appName} --no-interactive --style=css --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/next:app ${appName} --no-interactive --style=css`); if (runE2ETests('cypress')) { const e2eResults = runCLI(`e2e-ci ${appName}-e2e --verbose`, { diff --git a/e2e/node/src/node-esbuild.test.ts b/e2e/node/src/node-esbuild.test.ts index 7d0c6c54000cb..e3531b48dcf4a 100644 --- a/e2e/node/src/node-esbuild.test.ts +++ b/e2e/node/src/node-esbuild.test.ts @@ -24,7 +24,7 @@ describe('Node Applications + esbuild', () => { const app = uniq('nodeapp'); runCLI( - `generate @nx/node:app ${app} --bundler=esbuild --directory=apps/${app} --no-interactive` + `generate @nx/node:app apps/${app} --bundler=esbuild --no-interactive` ); checkFilesDoNotExist(`apps/${app}/webpack.config.js`); diff --git a/e2e/node/src/node-server.test.ts b/e2e/node/src/node-server.test.ts index e259c1e1b0ab6..cf5361fdebb8c 100644 --- a/e2e/node/src/node-server.test.ts +++ b/e2e/node/src/node-server.test.ts @@ -80,21 +80,19 @@ describe('Node Applications + webpack', () => { const nestApp = uniq('nest'); beforeAll(() => { - runCLI(`generate @nx/node:lib ${testLib1} --directory=libs/${testLib1}`); + runCLI(`generate @nx/node:lib libs/${testLib1}`); + runCLI(`generate @nx/node:lib libs/${testLib2} --importPath=@acme/test2`); runCLI( - `generate @nx/node:lib ${testLib2} --directory=libs/${testLib2} --importPath=@acme/test2` + `generate @nx/node:app apps/${expressApp} --framework=express --port=7000 --no-interactive` ); runCLI( - `generate @nx/node:app ${expressApp} --directory=apps/${expressApp} --framework=express --port=7000 --no-interactive` + `generate @nx/node:app apps/${fastifyApp} --framework=fastify --port=7001 --no-interactive` ); runCLI( - `generate @nx/node:app ${fastifyApp} --directory=apps/${fastifyApp} --framework=fastify --port=7001 --no-interactive` + `generate @nx/node:app apps/${koaApp} --framework=koa --port=7002 --no-interactive` ); runCLI( - `generate @nx/node:app ${koaApp} --directory=apps/${koaApp} --framework=koa --port=7002 --no-interactive` - ); - runCLI( - `generate @nx/node:app ${nestApp} --directory=apps/${nestApp} --framework=nest --port=7003 --bundler=webpack --no-interactive` + `generate @nx/node:app apps/${nestApp} --framework=nest --port=7003 --bundler=webpack --no-interactive` ); addLibImport(expressApp, testLib1); @@ -167,7 +165,7 @@ describe('Node Applications + webpack', () => { const expressApp = 'docker-express-app'; // needs to be consistent for the Dockerfile snapshot runCLI( - `generate @nx/node:app ${expressApp} --framework=express --directory=apps/${expressApp} --docker --no-interactive` + `generate @nx/node:app apps/${expressApp} --framework=express --docker --no-interactive` ); checkFilesExist(`apps/${expressApp}/Dockerfile`); @@ -181,10 +179,10 @@ describe('Node Applications + webpack', () => { // Set ports to avoid conflicts with other tests that might run in parallel runCLI( - `generate @nx/node:app ${nodeApp1} --directory=apps/${nodeApp1} --framework=none --no-interactive --port=4444` + `generate @nx/node:app apps/${nodeApp1} --framework=none --no-interactive --port=4444` ); runCLI( - `generate @nx/node:app ${nodeApp2} --directory=apps/${nodeApp2} --framework=none --no-interactive --port=4445` + `generate @nx/node:app apps/${nodeApp2} --framework=none --no-interactive --port=4445` ); updateJson(join('apps', nodeApp1, 'project.json'), (config) => { config.targets.serve.options.waitUntilTargets = [`${nodeApp2}:build`]; diff --git a/e2e/node/src/node-webpack.test.ts b/e2e/node/src/node-webpack.test.ts index de738d090cd6c..f38b87f752f66 100644 --- a/e2e/node/src/node-webpack.test.ts +++ b/e2e/node/src/node-webpack.test.ts @@ -30,7 +30,7 @@ describe('Node Applications + webpack', () => { // This fails with Crystal enabled because `--optimization` is not a correct flag to pass to `webpack`. runCLI( - `generate @nx/node:app ${app} --directory=apps/${app} --bundler=webpack --no-interactive`, + `generate @nx/node:app apps/${app} --bundler=webpack --no-interactive`, { env: { NX_ADD_PLUGINS: 'false' }, } @@ -66,7 +66,7 @@ describe('Node Applications + webpack', () => { // Test that serve can re-run dependency builds. const lib = uniq('nodelib'); runCLI( - `generate @nx/js:lib ${lib} --bundler=esbuild --directory=libs/${lib} --no-interactive` + `generate @nx/js:lib libs/${lib} --bundler=esbuild --no-interactive` ); updateJson(join('apps', app, 'project.json'), (config) => { diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index 0b4e3af01bc81..8c1ef40c18465 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -72,7 +72,7 @@ describe('Node Applications', () => { const port = getRandomPort(); process.env.PORT = `${port}`; runCLI( - `generate @nx/node:app ${nodeapp} --port=${port} --directory=apps/${nodeapp} --linter=eslint` + `generate @nx/node:app apps/${nodeapp} --port=${port} --linter=eslint` ); const lintResults = runCLI(`lint ${nodeapp}`); @@ -92,9 +92,7 @@ describe('Node Applications', () => { // TODO(crystal, @ndcunningham): This does not work because NxWebpackPlugin({}) outputFilename does not work. xit('should be able to generate the correct outputFileName in options', async () => { const nodeapp = uniq('nodeapp'); - runCLI( - `generate @nx/node:app ${nodeapp} --directory=apps/${nodeapp} --linter=eslint` - ); + runCLI(`generate @nx/node:app apps/${nodeapp} --linter=eslint`); updateJson(join('apps', nodeapp, 'project.json'), (config) => { config.targets.build.options.outputFileName = 'index.js'; @@ -110,7 +108,7 @@ describe('Node Applications', () => { const port = getRandomPort(); process.env.PORT = `${port}`; runCLI( - `generate @nx/node:app ${nodeapp} --directory=apps/${nodeapp} --port=${port} --linter=eslint --bundler=webpack` + `generate @nx/node:app apps/${nodeapp} --port=${port} --linter=eslint --bundler=webpack` ); const lintResults = runCLI(`lint ${nodeapp}`); @@ -192,7 +190,7 @@ module.exports = { const nodeapp = uniq('nodeapp'); runCLI( - `generate @nx/node:app ${nodeapp} --directory=apps/${nodeapp} --linter=eslint --bundler=webpack --framework=none` + `generate @nx/node:app apps/${nodeapp} --linter=eslint --bundler=webpack --framework=none` ); updateFile('.env', `NX_FOOBAR="test foo bar"`); @@ -229,9 +227,7 @@ module.exports = { it("should exclude 'test' target from e2e project that uses jest", async () => { const appName = uniq('nodeapp'); - runCLI( - `generate @nx/node:app ${appName} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/node:app ${appName} --no-interactive`); const nxJson = JSON.parse(readFile('nx.json')); expect(nxJson.plugins).toBeDefined(); @@ -250,7 +246,7 @@ module.exports = { process.env.PORT = `${port}`; runCLI( - `generate @nx/express:app ${nodeapp} --directory=apps/${nodeapp} --port=${port} --linter=eslint` + `generate @nx/express:app apps/${nodeapp} --port=${port} --linter=eslint` ); const lintResults = runCLI(`lint ${nodeapp}`); @@ -300,9 +296,7 @@ module.exports = { it('should be able to generate a nest application', async () => { const nestapp = uniq('nestapp'); const port = 3335; - runCLI( - `generate @nx/nest:app ${nestapp} --directory=apps/${nestapp} --linter=eslint` - ); + runCLI(`generate @nx/nest:app apps/${nestapp} --linter=eslint`); const lintResults = runCLI(`lint ${nestapp}`); expect(lintResults).toContain('Successfully ran target lint'); @@ -350,7 +344,7 @@ module.exports = { const nestapp = 'node-nest-docker-test'; runCLI( - `generate @nx/node:app ${nestapp} --project-name-and-root-format=as-provided --bundler=webpack --framework=nest --docker` + `generate @nx/node:app ${nestapp} --bundler=webpack --framework=nest --docker` ); checkFilesExist(`${nestapp}/Dockerfile`); @@ -430,9 +424,7 @@ describe('Build Node apps', () => { xit('should generate a package.json with the `--generatePackageJson` flag', async () => { const packageManager = detectPackageManager(tmpProjPath()); const nestapp = uniq('nestapp'); - runCLI( - `generate @nx/nest:app ${nestapp} --linter=eslint --directory=apps/${nestapp}` - ); + runCLI(`generate @nx/nest:app apps/${nestapp} --linter=eslint`); await runCLIAsync(`build ${nestapp} --generatePackageJson`); @@ -537,7 +529,7 @@ ${jslib}(); process.env.PORT = `${port}`; runCLI( - `generate @nx/node:app ${appName} --port=${port} --no-interactive --directory=apps/${appName}` + `generate @nx/node:app apps/${appName} --port=${port} --no-interactive` ); // deleteOutputPath should default to true @@ -577,9 +569,7 @@ ${jslib}(); const port = getRandomPort(); process.env.PORT = `${port}`; - runCLI( - `generate @nx/node:app ${appName} --project-name-and-root-format=as-provided --port=${port} --no-interactive` - ); + runCLI(`generate @nx/node:app ${appName} --port=${port} --no-interactive`); // check files are generated without the layout directory ("apps/") and // using the project name as the directory when no directory is provided @@ -594,9 +584,7 @@ ${jslib}(); `Successfully ran target test for project ${appName}` ); - runCLI( - `generate @nx/node:lib ${libName} --buildable --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/node:lib ${libName} --buildable --no-interactive`); // check files are generated without the layout directory ("libs/") and // using the project name as the directory when no directory is provided @@ -671,7 +659,7 @@ ${jslib}(); describe('nest libraries', function () { it('should be able to generate a nest library', async () => { const nestlib = uniq('nestlib'); - runCLI(`generate @nx/nest:lib ${nestlib} --directory=libs/${nestlib}`); + runCLI(`generate @nx/nest:lib libs/${nestlib}`); const lintResults = runCLI(`lint ${nestlib}`); expect(lintResults).toContain('Successfully ran target lint'); @@ -726,9 +714,7 @@ ${jslib}(); it('should have plugin output if specified in `transformers`', async () => { const nestlib = uniq('nestlib'); - runCLI( - `generate @nx/nest:lib ${nestlib} --buildable --directory=libs/${nestlib}` - ); + runCLI(`generate @nx/nest:lib libs/${nestlib} --buildable`); packageInstall('@nestjs/swagger', undefined, '^7.0.0'); diff --git a/e2e/nuxt/src/nuxt.test.ts b/e2e/nuxt/src/nuxt.test.ts index 34290f4900455..88ad5973d8473 100644 --- a/e2e/nuxt/src/nuxt.test.ts +++ b/e2e/nuxt/src/nuxt.test.ts @@ -14,10 +14,9 @@ describe('Nuxt Plugin', () => { beforeAll(() => { newProject({ packages: ['@nx/nuxt'], - unsetProjectNameAndRootFormat: false, }); runCLI( - `generate @nx/nuxt:app ${app} --unitTestRunner=vitest --projectNameAndRootFormat=as-provided --e2eTestRunner=cypress` + `generate @nx/nuxt:app ${app} --unitTestRunner=vitest --e2eTestRunner=cypress` ); runCLI( `generate @nx/nuxt:component ${app}/src/components/one/one --name=one --unitTestRunner=vitest` diff --git a/e2e/nx/src/affected-graph.test.ts b/e2e/nx/src/affected-graph.test.ts index 4b5d368f51c9f..badc76a74fa78 100644 --- a/e2e/nx/src/affected-graph.test.ts +++ b/e2e/nx/src/affected-graph.test.ts @@ -31,12 +31,12 @@ describe('Nx Affected and Graph Tests', () => { const mylib = uniq('mylib'); const mylib2 = uniq('mylib2'); const mypublishablelib = uniq('mypublishablelib'); - runCLI(`generate @nx/web:app ${myapp} --directory apps/${myapp}`); - runCLI(`generate @nx/web:app ${myapp2} --directory apps/${myapp2}`); - runCLI(`generate @nx/js:lib ${mylib} --directory libs/${mylib}`); - runCLI(`generate @nx/js:lib ${mylib2} --directory libs/${mylib2}`); + runCLI(`generate @nx/web:app apps/${myapp}`); + runCLI(`generate @nx/web:app apps/${myapp2}`); + runCLI(`generate @nx/js:lib libs/${mylib}`); + runCLI(`generate @nx/js:lib libs/${mylib2}`); runCLI( - `generate @nx/js:lib ${mypublishablelib} --directory libs/${mypublishablelib} --publishable --importPath=@${proj}/${mypublishablelib} --tags=ui` + `generate @nx/js:lib libs/${mypublishablelib} --publishable --importPath=@${proj}/${mypublishablelib} --tags=ui` ); updateFile( @@ -193,26 +193,26 @@ describe('Nx Affected and Graph Tests', () => { }); function generateAll() { - runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`); - runCLI(`generate @nx/web:app ${myapp2} --directory=apps/${myapp2}`); - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/web:app apps/${myapp}`); + runCLI(`generate @nx/web:app apps/${myapp2}`); + runCLI(`generate @nx/js:lib libs/${mylib}`); runCommand(`git add . && git commit -am "add all"`); } it('should not affect other projects by generating a new project', () => { // TODO: investigate why affected gives different results on windows if (isNotWindows()) { - runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`); + runCLI(`generate @nx/web:app apps/${myapp}`); expect(runCLI('show projects --affected')).toContain(myapp); runCommand(`git add . && git commit -am "add ${myapp}"`); - runCLI(`generate @nx/web:app ${myapp2} --directory=apps/${myapp2}`); + runCLI(`generate @nx/web:app apps/${myapp2}`); let output = runCLI('show projects --affected'); expect(output).not.toContain(myapp); expect(output).toContain(myapp2); runCommand(`git add . && git commit -am "add ${myapp2}"`); - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/js:lib libs/${mylib}`); output = runCLI('show projects --affected'); expect(output).not.toContain(myapp); expect(output).not.toContain(myapp2); diff --git a/e2e/nx/src/cache.test.ts b/e2e/nx/src/cache.test.ts index 67986a3d364a3..352307470ae1f 100644 --- a/e2e/nx/src/cache.test.ts +++ b/e2e/nx/src/cache.test.ts @@ -248,9 +248,9 @@ describe('cache', () => { const parent = uniq('parent'); const child1 = uniq('child1'); const child2 = uniq('child2'); - runCLI(`generate @nx/js:lib ${parent} --directory=libs/${parent}`); - runCLI(`generate @nx/js:lib ${child1} --directory=libs/${child1}`); - runCLI(`generate @nx/js:lib ${child2} --directory=libs/${child2}`); + runCLI(`generate @nx/js:lib libs/${parent}`); + runCLI(`generate @nx/js:lib libs/${child1}`); + runCLI(`generate @nx/js:lib libs/${child2}`); updateJson(`nx.json`, (c) => { c.namedInputs = { default: ['{projectRoot}/**/*'], @@ -315,7 +315,7 @@ describe('cache', () => { it('should support ENV as an input', () => { const lib = uniq('lib'); - runCLI(`generate @nx/js:lib ${lib} --directory=libs/${lib}`); + runCLI(`generate @nx/js:lib libs/${lib}`); updateJson(`nx.json`, (c) => { c.targetDefaults = { echo: { diff --git a/e2e/nx/src/extras.test.ts b/e2e/nx/src/extras.test.ts index 17ea18ca54916..8c48e06c3db27 100644 --- a/e2e/nx/src/extras.test.ts +++ b/e2e/nx/src/extras.test.ts @@ -20,7 +20,7 @@ describe('Extra Nx Misc Tests', () => { describe('Output Style', () => { it('should stream output', async () => { const myapp = 'abcdefghijklmon'; - runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`); + runCLI(`generate @nx/web:app apps/${myapp}`); updateJson(join('apps', myapp, 'project.json'), (c) => { c.targets['inner'] = { @@ -103,7 +103,7 @@ describe('Extra Nx Misc Tests', () => { describe('Run Commands', () => { const mylib = uniq('lib'); beforeAll(() => { - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/js:lib libs/${mylib}`); }); it('should not override environment variables already set when setting a custom env file path', async () => { @@ -249,7 +249,7 @@ describe('Extra Nx Misc Tests', () => { const folder = `dist/libs/${mylib}/some-folder`; - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/js:lib libs/${mylib}`); runCLI( `generate @nx/workspace:run-commands build --command=echo --outputs=${folder}/ --project=${mylib}` @@ -296,7 +296,7 @@ describe('Extra Nx Misc Tests', () => { beforeAll(() => { runCLI( - `generate @nx/js:lib ${libName} --directory=libs/${libName} --bundler=none --unitTestRunner=none --no-interactive` + `generate @nx/js:lib libs/${libName} --bundler=none --unitTestRunner=none --no-interactive` ); }); @@ -366,7 +366,7 @@ NX_USERNAME=$FIRSTNAME $LASTNAME` const baseLib = 'lib-base-123'; beforeAll(() => { - runCLI(`generate @nx/js:lib ${baseLib} --directory=libs/${baseLib}`); + runCLI(`generate @nx/js:lib libs/${baseLib}`); }); it('should correctly expand default task inputs', () => { @@ -387,9 +387,7 @@ NX_USERNAME=$FIRSTNAME $LASTNAME` it('should correctly expand dependent task inputs', () => { const dependentLib = 'lib-dependent-123'; - runCLI( - `generate @nx/js:lib ${dependentLib} --directory=libs/${dependentLib}` - ); + runCLI(`generate @nx/js:lib libs/${dependentLib}`); updateJson(join('libs', baseLib, 'project.json'), (config) => { config.targets['build'].inputs = ['default', '^default']; diff --git a/e2e/nx/src/import.test.ts b/e2e/nx/src/import.test.ts index 116839a5ee4ae..1ede6f69683bb 100644 --- a/e2e/nx/src/import.test.ts +++ b/e2e/nx/src/import.test.ts @@ -19,7 +19,6 @@ describe('Nx Import', () => { beforeAll(() => { proj = newProject({ packages: ['@nx/js'], - unsetProjectNameAndRootFormat: false, }); if (getSelectedPackageManager() === 'pnpm') { diff --git a/e2e/nx/src/invoke-runner.test.ts b/e2e/nx/src/invoke-runner.test.ts index 6d610cc7bf7a4..a8ce6a954773b 100644 --- a/e2e/nx/src/invoke-runner.test.ts +++ b/e2e/nx/src/invoke-runner.test.ts @@ -16,7 +16,7 @@ describe('Invoke Runner', () => { it('should invoke runner imperatively ', async () => { const mylib = uniq('mylib'); - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/js:lib libs/${mylib}`); updateJson(join('libs', mylib, 'project.json'), (c) => { c.targets['prebuild'] = { command: 'echo prebuild', diff --git a/e2e/nx/src/misc.test.ts b/e2e/nx/src/misc.test.ts index a91dc202a5e1e..7c7076b1e4538 100644 --- a/e2e/nx/src/misc.test.ts +++ b/e2e/nx/src/misc.test.ts @@ -43,10 +43,8 @@ describe('Nx Commands', () => { runCLI('show projects').replace(/.*nx show projects( --verbose)?\n/, '') ).toEqual(''); - runCLI( - `generate @nx/web:app ${app1} --tags e2etag --directory=apps/${app1}` - ); - runCLI(`generate @nx/web:app ${app2} --directory=apps/${app2}`); + runCLI(`generate @nx/web:app apps/${app1} --tags e2etag`); + runCLI(`generate @nx/web:app apps/${app2}`); const s = runCLI('show projects').split('\n'); @@ -70,7 +68,7 @@ describe('Nx Commands', () => { it('should show detailed project info', () => { const app = uniq('myapp'); - runCLI(`generate @nx/web:app ${app} --directory=apps/${app}`); + runCLI(`generate @nx/web:app apps/${app}`); const project: ProjectConfiguration = JSON.parse( runCLI(`show project ${app}`) ); @@ -80,7 +78,7 @@ describe('Nx Commands', () => { it('should open project details view', async () => { const app = uniq('myapp'); - runCLI(`generate @nx/web:app ${app} --directory=apps/${app}`); + runCLI(`generate @nx/web:app apps/${app}`); let url: string; let port: number; const child_process = await runCommandUntil( @@ -182,8 +180,8 @@ describe('Nx Commands', () => { const mylib = uniq('mylib'); beforeAll(async () => { - runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`); - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/web:app apps/${myapp}`); + runCLI(`generate @nx/js:lib libs/${mylib}`); }); beforeEach(() => { diff --git a/e2e/nx/src/nx-cloud.test.ts b/e2e/nx/src/nx-cloud.test.ts index 6ae66cff749b8..34d7e357b9864 100644 --- a/e2e/nx/src/nx-cloud.test.ts +++ b/e2e/nx/src/nx-cloud.test.ts @@ -3,7 +3,6 @@ import { cleanupProject, newProject, runCLI } from '@nx/e2e/utils'; describe('Nx Cloud', () => { beforeAll(() => newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }) ); diff --git a/e2e/nx/src/run.test.ts b/e2e/nx/src/run.test.ts index 5842ba8edf08e..fe2442986fc60 100644 --- a/e2e/nx/src/run.test.ts +++ b/e2e/nx/src/run.test.ts @@ -37,7 +37,7 @@ describe('Nx Running Tests', () => { describe('(forwarding params)', () => { let proj = uniq('proj'); beforeAll(() => { - runCLI(`generate @nx/js:lib ${proj} --directory=libs/${proj}`); + runCLI(`generate @nx/js:lib libs/${proj}`); updateJson(`libs/${proj}/project.json`, (c) => { c.targets['echo'] = { command: 'echo ECHO:', @@ -107,7 +107,7 @@ describe('Nx Running Tests', () => { it('should execute long running tasks', () => { const myapp = uniq('myapp'); - runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`); + runCLI(`generate @nx/web:app apps/${myapp}`); updateJson(`apps/${myapp}/project.json`, (c) => { c.targets['counter'] = { executor: '@nx/workspace:counter', @@ -127,7 +127,7 @@ describe('Nx Running Tests', () => { it('should run npm scripts', async () => { const mylib = uniq('mylib'); - runCLI(`generate @nx/node:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/node:lib libs/${mylib}`); // Used to restore targets to lib after test const original = readJson(`libs/${mylib}/project.json`); @@ -172,7 +172,7 @@ describe('Nx Running Tests', () => { beforeAll(async () => { app = uniq('myapp'); - runCLI(`generate @nx/web:app ${app} --directory=apps/${app}`); + runCLI(`generate @nx/web:app apps/${app}`); }); it('should support using {projectRoot} in options blocks in project.json', async () => { @@ -236,7 +236,7 @@ describe('Nx Running Tests', () => { it('should pass env option to nx:run-commands executor', () => { const mylib = uniq('mylib'); - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/js:lib libs/${mylib}`); updateJson(`libs/${mylib}/project.json`, (c) => { c.targets['echo'] = { @@ -257,7 +257,7 @@ describe('Nx Running Tests', () => { it('should not run dependencies if --no-dependencies is passed', () => { const mylib = uniq('mylib'); - runCLI(`generate @nx/js:lib ${mylib} --directory=libs/${mylib}`); + runCLI(`generate @nx/js:lib libs/${mylib}`); updateJson(`libs/${mylib}/project.json`, (c) => { c.targets['one'] = { @@ -294,8 +294,8 @@ describe('Nx Running Tests', () => { it('should stop executing all tasks when one of the tasks fails', async () => { const myapp1 = uniq('a'); const myapp2 = uniq('b'); - runCLI(`generate @nx/web:app ${myapp1} --directory=apps/${myapp1}`); - runCLI(`generate @nx/web:app ${myapp2} --directory=apps/${myapp2}`); + runCLI(`generate @nx/web:app apps/${myapp1}`); + runCLI(`generate @nx/web:app apps/${myapp2}`); updateJson(`apps/${myapp1}/project.json`, (c) => { c.targets['error'] = { command: 'echo boom1 && exit 1', @@ -343,14 +343,14 @@ describe('Nx Running Tests', () => { describe('run-one', () => { it('should build a specific project', () => { const myapp = uniq('app'); - runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`); + runCLI(`generate @nx/web:app apps/${myapp}`); runCLI(`build ${myapp}`); }, 10000); it('should support project name positional arg non-consecutive to target', () => { const myapp = uniq('app'); - runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`); + runCLI(`generate @nx/web:app apps/${myapp}`); runCLI(`build --verbose ${myapp}`); }, 10000); @@ -361,7 +361,7 @@ describe('Nx Running Tests', () => { const expectedOutput = uniq('myEchoedString'); const expectedEnvOutput = uniq('myEnvString'); - runCLI(`generate @nx/web:app ${myapp} --directory=apps/${myapp}`); + runCLI(`generate @nx/web:app apps/${myapp}`); updateFile( `apps/${myapp}/package.json`, JSON.stringify({ diff --git a/e2e/nx/src/watch.test.ts b/e2e/nx/src/watch.test.ts index 9fb1c0c1b168f..4f563a1f13452 100644 --- a/e2e/nx/src/watch.test.ts +++ b/e2e/nx/src/watch.test.ts @@ -31,9 +31,9 @@ describe('Nx Watch', () => { let proj3 = uniq('proj3'); beforeAll(() => { newProject({ packages: ['@nx/js'] }); - runCLI(`generate @nx/js:lib ${proj1} --directory=libs/${proj1}`); - runCLI(`generate @nx/js:lib ${proj2} --directory=libs/${proj2}`); - runCLI(`generate @nx/js:lib ${proj3} --directory=libs/${proj3}`); + runCLI(`generate @nx/js:lib libs/${proj1}`); + runCLI(`generate @nx/js:lib libs/${proj2}`); + runCLI(`generate @nx/js:lib libs/${proj3}`); runCLI('daemon --start', { env: { NX_DAEMON: 'true', diff --git a/e2e/nx/src/workspace-legacy.test.ts b/e2e/nx/src/workspace-legacy.test.ts index 5f080812c5f73..ae7c96ec6f5f6 100644 --- a/e2e/nx/src/workspace-legacy.test.ts +++ b/e2e/nx/src/workspace-legacy.test.ts @@ -19,7 +19,7 @@ describe('@nx/workspace:convert-to-monorepo', () => { it('should convert a standalone webpack and jest react project to a monorepo (legacy)', async () => { const reactApp = uniq('reactapp'); runCLI( - `generate @nx/react:app ${reactApp} --rootProject=true --bundler=webpack --unitTestRunner=jest --e2eTestRunner=cypress --no-interactive`, + `generate @nx/react:app --name=${reactApp} --directory="." --bundler=webpack --unitTestRunner=jest --e2eTestRunner=cypress --no-interactive`, { env: { NX_ADD_PLUGINS: 'false', diff --git a/e2e/nx/src/workspace.test.ts b/e2e/nx/src/workspace.test.ts index f456026a30a15..2da91e6a129e5 100644 --- a/e2e/nx/src/workspace.test.ts +++ b/e2e/nx/src/workspace.test.ts @@ -32,7 +32,7 @@ describe('@nx/workspace:infer-targets', () => { // default case, everything is generated with crystal, everything should be skipped const remixApp = uniq('remix'); runCLI( - `generate @nx/remix:app ${remixApp} --dir apps/${remixApp} --unitTestRunner jest --e2eTestRunner=playwright --projectNameAndDirectoryFormat=as-provided --no-interactive` + `generate @nx/remix:app apps/${remixApp} --unitTestRunner jest --e2eTestRunner=playwright --projectNameAndDirectoryFormat=as-provided --no-interactive` ); const output = runCLI(`generate infer-targets --no-interactive`); @@ -70,7 +70,7 @@ describe('@nx/workspace:infer-targets', () => { // default case, everything is generated with crystal, relevant plugins should be skipped const remixApp = uniq('remix'); runCLI( - `generate @nx/remix:app ${remixApp} --dir apps/${remixApp} --unitTestRunner jest --e2eTestRunner=playwright --projectNameAndDirectoryFormat=as-provided --no-interactive` + `generate @nx/remix:app apps/${remixApp} --unitTestRunner jest --e2eTestRunner=playwright --projectNameAndDirectoryFormat=as-provided --no-interactive` ); const output = runCLI( @@ -116,7 +116,7 @@ describe('@nx/workspace:infer-targets', () => { // even if we make sure there are executors for remix & remix-e2e, only remix conversions will run with --project option const remixApp = uniq('remix'); runCLI( - `generate @nx/remix:app ${remixApp} --dir apps/${remixApp} --unitTestRunner jest --e2eTestRunner=playwright --projectNameAndDirectoryFormat=as-provided --no-interactive` + `generate @nx/remix:app apps/${remixApp} --unitTestRunner jest --e2eTestRunner=playwright --projectNameAndDirectoryFormat=as-provided --no-interactive` ); updateJson('nx.json', (json) => { @@ -167,7 +167,7 @@ describe('@nx/workspace:convert-to-monorepo', () => { it('should be convert a standalone vite and playwright react project to a monorepo', async () => { const reactApp = uniq('reactapp'); runCLI( - `generate @nx/react:app ${reactApp} --rootProject=true --bundler=vite --unitTestRunner vitest --e2eTestRunner=playwright --no-interactive` + `generate @nx/react:app --name=${reactApp} --directory="." --rootProject=true --bundler=vite --unitTestRunner vitest --e2eTestRunner=playwright --no-interactive` ); runCLI('generate @nx/workspace:convert-to-monorepo --no-interactive'); @@ -226,7 +226,7 @@ describe('Workspace Tests', () => { const lib2 = uniq('mylib'); const lib3 = uniq('mylib'); runCLI( - `generate @nx/js:lib ${lib1}-data-access --directory=${lib1}/data-access --unitTestRunner=jest --project-name-and-root-format=as-provided` + `generate @nx/js:lib --name=${lib1}-data-access --directory=${lib1}/data-access --unitTestRunner=jest` ); updateFile( @@ -244,7 +244,7 @@ describe('Workspace Tests', () => { */ runCLI( - `generate @nx/js:lib ${lib2}-ui --directory=${lib2}/ui --unitTestRunner=jest --project-name-and-root-format=as-provided` + `generate @nx/js:lib --name=${lib2}-ui --directory=${lib2}/ui --unitTestRunner=jest` ); updateFile( @@ -258,9 +258,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI( - `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`); updateFile(join(lib3, 'project.json'), (content) => { const data = JSON.parse(content); data.implicitDependencies = [`${lib1}-data-access`]; @@ -272,7 +270,7 @@ describe('Workspace Tests', () => { */ const moveOutput = runCLI( - `generate @nx/workspace:move --project ${lib1}-data-access shared/${lib1}/data-access --newProjectName=shared-${lib1}-data-access --project-name-and-root-format=as-provided` + `generate @nx/workspace:move --project ${lib1}-data-access shared/${lib1}/data-access --newProjectName=shared-${lib1}-data-access` ); expect(moveOutput).toContain(`DELETE ${lib1}/data-access`); @@ -365,7 +363,7 @@ describe('Workspace Tests', () => { const lib2 = uniq('mylib'); const lib3 = uniq('mylib'); runCLI( - `generate @nx/js:lib ${lib1}-data-access --directory=${lib1}/data-access --importPath=${importPath} --unitTestRunner=jest --project-name-and-root-format=as-provided` + `generate @nx/js:lib --name=${lib1}-data-access --directory=${lib1}/data-access --importPath=${importPath} --unitTestRunner=jest` ); updateFile( @@ -383,7 +381,7 @@ describe('Workspace Tests', () => { */ runCLI( - `generate @nx/js:lib ${lib2}-ui --directory=${lib2}/ui --unitTestRunner=jest --project-name-and-root-format=as-provided` + `generate @nx/js:lib --name=${lib2}-ui --directory=${lib2}/ui --unitTestRunner=jest` ); updateFile( @@ -397,9 +395,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI( - `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`); updateFile(join(lib3, 'project.json'), (content) => { const data = JSON.parse(content); data.implicitDependencies = [`${lib1}-data-access`]; @@ -411,7 +407,7 @@ describe('Workspace Tests', () => { */ const moveOutput = runCLI( - `generate @nx/workspace:move --project ${lib1}-data-access shared/${lib1}/data-access --newProjectName=shared-${lib1}-data-access --project-name-and-root-format=as-provided` + `generate @nx/workspace:move --project ${lib1}-data-access shared/${lib1}/data-access --newProjectName=shared-${lib1}-data-access` ); expect(moveOutput).toContain(`DELETE ${lib1}/data-access`); @@ -494,9 +490,7 @@ describe('Workspace Tests', () => { const lib1 = uniq('lib1'); const lib2 = uniq('lib2'); const lib3 = uniq('lib3'); - runCLI( - `generate @nx/js:lib ${lib1} --unitTestRunner=jest --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/js:lib ${lib1} --unitTestRunner=jest`); updateFile( `${lib1}/src/lib/${lib1}.ts`, @@ -510,7 +504,7 @@ describe('Workspace Tests', () => { */ runCLI( - `generate @nx/js:lib ${lib2}-ui --directory=${lib2}/ui --unitTestRunner=jest --project-name-and-root-format=as-provided` + `generate @nx/js:lib --name=${lib2}-ui --directory=${lib2}/ui --unitTestRunner=jest` ); updateFile( @@ -524,9 +518,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI( - `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`); updateFile(join(lib3, 'project.json'), (content) => { const data = JSON.parse(content); data.implicitDependencies = [lib1]; @@ -538,7 +530,7 @@ describe('Workspace Tests', () => { */ const moveOutput = runCLI( - `generate @nx/workspace:move --project ${lib1} ${lib1}/data-access --newProjectName=${lib1}-data-access --project-name-and-root-format=as-provided` + `generate @nx/workspace:move --project ${lib1} ${lib1}/data-access --newProjectName=${lib1}-data-access` ); expect(moveOutput).toContain(`DELETE ${lib1}/project.json`); @@ -626,7 +618,7 @@ describe('Workspace Tests', () => { const lib2 = uniq('mylib'); const lib3 = uniq('mylib'); runCLI( - `generate @nx/js:lib ${lib1}-data-access --directory=${lib1}/data-access --unitTestRunner=jest --project-name-and-root-format=as-provided` + `generate @nx/js:lib --name=${lib1}-data-access --directory=${lib1}/data-access --unitTestRunner=jest` ); let rootTsConfig = readJson('tsconfig.base.json'); expect( @@ -651,7 +643,7 @@ describe('Workspace Tests', () => { */ runCLI( - `generate @nx/js:lib ${lib2}-ui --directory=${lib2}/ui --unitTestRunner=jest --project-name-and-root-format=as-provided` + `generate @nx/js:lib --name${lib2}-ui --directory=${lib2}/ui --unitTestRunner=jest` ); updateFile( @@ -665,9 +657,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI( - `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/js:lib ${lib3} --unitTestRunner=jest`); updateFile(join(lib3, 'project.json'), (content) => { const data = JSON.parse(content); data.implicitDependencies = [`${lib1}-data-access`]; @@ -679,7 +669,7 @@ describe('Workspace Tests', () => { */ const moveOutput = runCLI( - `generate @nx/workspace:move --project ${lib1}-data-access shared/${lib1}/data-access --newProjectName=shared-${lib1}-data-access --project-name-and-root-format=as-provided` + `generate @nx/workspace:move --project ${lib1}-data-access shared/${lib1}/data-access --newProjectName=shared-${lib1}-data-access` ); expect(moveOutput).toContain(`DELETE ${lib1}/data-access`); @@ -752,9 +742,7 @@ describe('Workspace Tests', () => { * Create a library which has an implicit dependency on lib1 */ - runCLI( - `generate @nx/js:lib ${lib2} --directory=libs/${lib2} --unitTestRunner=jest` - ); + runCLI(`generate @nx/js:lib libs/${lib2} --unitTestRunner=jest`); updateFile(join('libs', lib2, 'project.json'), (content) => { const data = JSON.parse(content); data.implicitDependencies = [lib1]; diff --git a/e2e/playwright/src/playwright.test.ts b/e2e/playwright/src/playwright.test.ts index 62c54b1e2f5d1..93dc170f433c9 100644 --- a/e2e/playwright/src/playwright.test.ts +++ b/e2e/playwright/src/playwright.test.ts @@ -76,7 +76,6 @@ describe('Playwright E2E Test Runner - legacy', () => { env = process.env.NX_ADD_PLUGINS; newProject({ name: uniq('playwright'), - unsetProjectNameAndRootFormat: false, }); process.env.NX_ADD_PLUGINS = 'false'; }); @@ -98,7 +97,7 @@ describe('Playwright E2E Test Runner - legacy', () => { const pmc = getPackageManagerCommand(); runCLI( - `g @nx/web:app demo-e2e --directory apps/demo-e2e --unitTestRunner=none --bundler=vite --e2eTestRunner=none --style=css --no-interactive --projectNameAndRootFormat=as-provided` + `g @nx/web:app demo-e2e --directory apps/demo-e2e --unitTestRunner=none --bundler=vite --e2eTestRunner=none --style=css --no-interactive` ); runCLI( `g @nx/playwright:configuration --project demo-e2e --webServerCommand="${pmc.runNx} serve demo-e2e" --webServerAddress="http://localhost:4200"` @@ -121,7 +120,7 @@ describe('Playwright E2E Test Runner - legacy', () => { const pmc = getPackageManagerCommand(); runCLI( - `g @nx/web:app demo-js-e2e --directory apps/demo-js-e2e --unitTestRunner=none --bundler=vite --e2eTestRunner=none --style=css --no-interactive --projectNameAndRootFormat=as-provided` + `g @nx/web:app demo-js-e2e --directory apps/demo-js-e2e --unitTestRunner=none --bundler=vite --e2eTestRunner=none --style=css --no-interactive` ); runCLI( `g @nx/playwright:configuration --project demo-js-e2e --js --webServerCommand="${pmc.runNx} serve demo-e2e" --webServerAddress="http://localhost:4200"` diff --git a/e2e/plugin/src/nx-plugin.test.ts b/e2e/plugin/src/nx-plugin.test.ts index 19faa994f325a..a2c361d4d53b1 100644 --- a/e2e/plugin/src/nx-plugin.test.ts +++ b/e2e/plugin/src/nx-plugin.test.ts @@ -407,7 +407,7 @@ describe('Nx Plugin', () => { it('should create a plugin in the specified directory', async () => { const plugin = uniq('plugin'); runCLI( - `generate @nx/plugin:plugin ${plugin} --linter=eslint --directory libs/subdir/${plugin} --e2eTestRunner=jest` + `generate @nx/plugin:plugin libs/subdir/${plugin} --linter=eslint --e2eTestRunner=jest` ); checkFilesExist(`libs/subdir/${plugin}/package.json`); const pluginProject = readJson( @@ -438,7 +438,7 @@ describe('Nx Plugin', () => { `generate @nx/plugin:plugin ${plugin} --e2eTestRunner jest --publishable` ); runCLI( - `generate @nx/plugin:create-package ${createAppName} --project=${plugin}` + `generate @nx/plugin:create-package ${createAppName} --name=${createAppName} --project=${plugin} --verbose` ); const buildResults = runCLI(`build ${createAppName}`); @@ -458,7 +458,7 @@ describe('Nx Plugin', () => { `generate @nx/plugin:plugin ${plugin} --e2eTestRunner jest --publishable` ); runCLI( - `generate @nx/plugin:create-package ${createAppName} --project=${plugin} --e2eProject=${plugin}-e2e` + `generate @nx/plugin:create-package ${createAppName} --name=${createAppName} --project=${plugin} --e2eProject=${plugin}-e2e --verbose` ); const buildResults = runCLI(`build ${createAppName}`); @@ -477,7 +477,7 @@ describe('Nx Plugin', () => { const plugin = uniq('plugin'); expect(() => runCLI( - `generate @nx/plugin:create-package create-${plugin} --project=invalid-plugin` + `generate @nx/plugin:create-package create-${plugin} --name=create-${plugin} --project=invalid-plugin` ) ).toThrow(); }); @@ -487,7 +487,7 @@ describe('Nx Plugin', () => { const createAppName = `create-${plugin}-app`; runCLI( - `generate @nx/plugin:plugin ${plugin} --e2eTestRunner jest --publishable --project-name-and-root-format=as-provided` + `generate @nx/plugin:plugin ${plugin} --e2eTestRunner jest --publishable` ); // check files are generated without the layout directory ("libs/") and @@ -504,7 +504,7 @@ describe('Nx Plugin', () => { ); runCLI( - `generate @nx/plugin:create-package ${createAppName} --project=${plugin} --e2eProject=${plugin}-e2e --project-name-and-root-format=as-provided` + `generate @nx/plugin:create-package ${createAppName} --name=${createAppName} --project=${plugin} --e2eProject=${plugin}-e2e` ); // check files are generated without the layout directory ("libs/") and diff --git a/e2e/react-native/src/react-native-legacy.test.ts b/e2e/react-native/src/react-native-legacy.test.ts index a063609752d5c..4b5186a01a139 100644 --- a/e2e/react-native/src/react-native-legacy.test.ts +++ b/e2e/react-native/src/react-native-legacy.test.ts @@ -265,7 +265,7 @@ describe('@nx/react-native (legacy)', () => { const libName = uniq('@my-org/lib1'); runCLI( - `generate @nx/react-native:application ${appName} --project-name-and-root-format=as-provided --install=false --no-interactive` + `generate @nx/react-native:application ${appName} --install=false --no-interactive` ); // check files are generated without the layout directory ("apps/") and @@ -274,9 +274,7 @@ describe('@nx/react-native (legacy)', () => { // check tests pass expect(() => runCLI(`test ${appName}`)).not.toThrow(); - runCLI( - `generate @nx/react-native:library ${libName} --buildable --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/react-native:library ${libName} --buildable`); // check files are generated without the layout directory ("libs/") and // using the project name as the directory when no directory is provided diff --git a/e2e/react-native/src/react-native.test.ts b/e2e/react-native/src/react-native.test.ts index a1806eb4ea669..28cac4386c3b1 100644 --- a/e2e/react-native/src/react-native.test.ts +++ b/e2e/react-native/src/react-native.test.ts @@ -18,7 +18,7 @@ describe('@nx/react-native', () => { newProject(); appName = uniq('app'); runCLI( - `generate @nx/react-native:app ${appName} --project-name-and-root-format=as-provided --install=false --no-interactive` + `generate @nx/react-native:app ${appName} --install=false --no-interactive` ); }); diff --git a/e2e/react/src/cypress-component-tests.test.ts b/e2e/react/src/cypress-component-tests.test.ts index 22d46e96d7c56..7fd6de4b58ec9 100644 --- a/e2e/react/src/cypress-component-tests.test.ts +++ b/e2e/react/src/cypress-component-tests.test.ts @@ -27,7 +27,7 @@ describe('React Cypress Component Tests', () => { ensureCypressInstallation(); runCLI( - `generate @nx/react:app ${appName} --directory=apps/${appName} --bundler=webpack --no-interactive` + `generate @nx/react:app apps/${appName} --bundler=webpack --no-interactive` ); updateJson('nx.json', (json) => ({ @@ -46,7 +46,7 @@ describe('React Cypress Component Tests', () => { `generate @nx/react:component apps/${appName}/src/app/fancy-cmp/fancy-cmp --no-interactive` ); runCLI( - `generate @nx/react:lib ${usedInAppLibName} --directory=libs/${usedInAppLibName} --no-interactive --unitTestRunner=jest` + `generate @nx/react:lib libs/${usedInAppLibName} --no-interactive --unitTestRunner=jest` ); runCLI( `generate @nx/react:component libs/${usedInAppLibName}/src/lib/btn/btn --export --no-interactive` @@ -108,7 +108,7 @@ export default App;` ); runCLI( - `generate @nx/react:lib ${buildableLibName} --directory=libs/${buildableLibName} --buildable --no-interactive --unitTestRunner=jest` + `generate @nx/react:lib libs/${buildableLibName} --buildable --no-interactive --unitTestRunner=jest` ); runCLI( `generate @nx/react:component libs/${buildableLibName}/src/lib/input/input --export --no-interactive` diff --git a/e2e/react/src/playwright.test.ts b/e2e/react/src/playwright.test.ts index 9bd7894c96664..4686d33163a3e 100644 --- a/e2e/react/src/playwright.test.ts +++ b/e2e/react/src/playwright.test.ts @@ -18,7 +18,7 @@ describe('React Playwright e2e tests', () => { packages: ['@nx/react'], }); runCLI( - `generate @nx/react:app ${appName} --e2eTestRunner=playwright --bundler=vite --projectNameAndRootFormat=as-provided --no-interactive` + `generate @nx/react:app ${appName} --e2eTestRunner=playwright --bundler=vite --no-interactive` ); }); @@ -35,7 +35,7 @@ describe('React Playwright e2e tests', () => { it('should execute e2e tests using playwright with a library used in the app', () => { runCLI( - `generate @nx/js:library ${usedInAppLibName} --unitTestRunner=none --importPath=@mylib --projectNameAndRootFormat=as-provided --no-interactive` + `generate @nx/js:library ${usedInAppLibName} --unitTestRunner=none --importPath=@mylib --no-interactive` ); updateFile( diff --git a/e2e/react/src/react-module-federation.rspack.test.ts b/e2e/react/src/react-module-federation.rspack.test.ts index 15b883b69174a..d8b3c478867ad 100644 --- a/e2e/react/src/react-module-federation.rspack.test.ts +++ b/e2e/react/src/react-module-federation.rspack.test.ts @@ -40,7 +40,7 @@ describe('React Rspack Module Federation', () => { const remote3 = uniq('remote3'); runCLI( - `generate @nx/react:host ${shell} --directory=apps/${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --e2eTestRunner=cypress --style=css --no-interactive --skipFormat --js=${js}` + `generate @nx/react:host apps/${shell} --name=${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --e2eTestRunner=cypress --style=css --no-interactive --skipFormat --js=${js}` ); checkFilesExist( @@ -132,7 +132,7 @@ describe('React Rspack Module Federation', () => { const remote3 = uniq('remote3'); runCLI( - `generate @nx/react:host ${shell} --directory=apps/${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --e2eTestRunner=playwright --style=css --no-interactive --skipFormat` + `generate @nx/react:host apps/${shell} --name=${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --e2eTestRunner=playwright --style=css --no-interactive --skipFormat` ); checkFilesExist(`apps/${shell}/module-federation.config.ts`); @@ -198,11 +198,11 @@ describe('React Rspack Module Federation', () => { const remote2 = uniq('remote2'); runCLI( - `generate @nx/react:host ${shell} --directory=apps/${shell} --remotes=${remote1} --bundler=webpack --e2eTestRunner=cypress --style=css --no-interactive --skipFormat` + `generate @nx/react:host apps/${shell} --name=${shell} --remotes=${remote1} --bundler=webpack --e2eTestRunner=cypress --style=css --no-interactive --skipFormat` ); runCLI( - `generate @nx/react:remote ${remote2} --directory=apps/${remote2} --host=${shell} --bundler=rspack --style=css --no-interactive --skipFormat` + `generate @nx/react:remote apps/${remote2} --name=${remote2} --host=${shell} --bundler=rspack --style=css --no-interactive --skipFormat` ); updateFile( @@ -267,11 +267,11 @@ describe('React Rspack Module Federation', () => { const remote1 = uniq('remote1'); const remote2 = uniq('remote2'); runCLI( - `generate @nx/react:host ${shell} --directory=apps/${shell} --remotes=${remote1} --bundler=rspack --e2eTestRunner=cypress --style=css --no-interactive --skipFormat` + `generate @nx/react:host apps/${shell} --name=${shell} --remotes=${remote1} --bundler=rspack --e2eTestRunner=cypress --style=css --no-interactive --skipFormat` ); runCLI( - `generate @nx/react:remote ${remote2} --directory=apps/${remote2} --host=${shell} --bundler=webpack --style=css --no-interactive --skipFormat` + `generate @nx/react:remote apps/${remote2} --name=${remote2} --host=${shell} --bundler=webpack --style=css --no-interactive --skipFormat` ); updateFile( @@ -327,7 +327,7 @@ describe('React Rspack Module Federation', () => { const remote3 = uniq('remote3'); await runCLIAsync( - `generate @nx/react:host ${shell} --ssr --directory=apps/${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --style=css --no-interactive --skipFormat` + `generate @nx/react:host apps/${shell} --ssr --name=${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --style=css --no-interactive --skipFormat` ); expect(readPort(shell)).toEqual(4200); @@ -358,7 +358,7 @@ describe('React Rspack Module Federation', () => { const remote3 = uniq('remote3'); await runCLIAsync( - `generate @nx/react:host ${shell} --ssr --directory=apps/${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --style=css --e2eTestRunner=cypress --no-interactive --skipFormat` + `generate @nx/react:host apps/${shell} --ssr --name=${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --style=css --e2eTestRunner=cypress --no-interactive --skipFormat` ); const serveResult = await runCommandUntil(`serve ${shell}`, (output) => @@ -375,7 +375,7 @@ describe('React Rspack Module Federation', () => { const remote3 = uniq('remote3'); await runCLIAsync( - `generate @nx/react:host ${shell} --ssr --directory=apps/${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --style=css --e2eTestRunner=cypress --no-interactive --skipFormat` + `generate @nx/react:host apps/${shell} --ssr --name=${shell} --remotes=${remote1},${remote2},${remote3} --bundler=rspack --style=css --e2eTestRunner=cypress --no-interactive --skipFormat` ); const capitalize = (s: string) => @@ -418,11 +418,9 @@ describe('React Rspack Module Federation', () => { const shell = uniq('shell'); const remote = uniq('remote'); + runCLI(`generate @nx/react:host ${shell} --no-interactive --skipFormat`); runCLI( - `generate @nx/react:host ${shell} --project-name-and-root-format=as-provided --no-interactive --skipFormat` - ); - runCLI( - `generate @nx/react:remote ${remote} --host=${shell} --bundler=rspack --project-name-and-root-format=as-provided --no-interactive --skipFormat` + `generate @nx/react:remote ${remote} --host=${shell} --bundler=rspack --no-interactive --skipFormat` ); const shellPort = readPort(shell); @@ -495,16 +493,14 @@ describe('React Rspack Module Federation', () => { const host = uniq('host'); runCLI( - `generate @nx/react:host ${host} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` + `generate @nx/react:host ${host} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --no-interactive --skipFormat` ); - runCLI( - `generate @nx/js:lib ${lib} --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` - ); + runCLI(`generate @nx/js:lib ${lib} --no-interactive --skipFormat`); // Federate Module runCLI( - `generate @nx/react:federate-module ${lib}/src/index.ts --name=${module} --remote=${remote} --bundler=rspack --no-interactive --skipFormat` + `generate @nx/react:federate-module ${lib}/src/index.ts --name=${module} --remote=${remote} --remoteDirectory=${remote} --bundler=rspack --no-interactive --skipFormat` ); updateFile( @@ -596,16 +592,14 @@ describe('React Rspack Module Federation', () => { const host = uniq('host'); runCLI( - `generate @nx/react:host ${host} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` + `generate @nx/react:host ${host} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --no-interactive --skipFormat` ); - runCLI( - `generate @nx/js:lib ${lib} --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` - ); + runCLI(`generate @nx/js:lib ${lib} --no-interactive --skipFormat`); // Federate Module runCLI( - `generate @nx/react:federate-module ${lib}/src/index.ts --name=${module} --remote=${childRemote} --bundler=rspack --no-interactive --skipFormat` + `generate @nx/react:federate-module ${lib}/src/index.ts --name=${module} --remote=${childRemote} --remoteDirectory=${childRemote} --bundler=rspack --no-interactive --skipFormat` ); updateFile( @@ -704,7 +698,7 @@ describe('React Rspack Module Federation', () => { const host = uniq('host'); runCLI( - `generate @nx/react:host ${host} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided --typescriptConfiguration=false --skipFormat` + `generate @nx/react:host ${host} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --no-interactive --typescriptConfiguration=false --skipFormat` ); // Update remote to be loaded via script @@ -838,11 +832,11 @@ describe('React Rspack Module Federation', () => { const lib = uniq('lib'); runCLI( - `generate @nx/react:host ${shell} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` + `generate @nx/react:host ${shell} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --no-interactive --skipFormat` ); runCLI( - `generate @nx/js:lib ${lib} --importPath=@acme/${lib} --publishable=true --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` + `generate @nx/js:lib ${lib} --importPath=@acme/${lib} --publishable=true --no-interactive --skipFormat` ); const shellPort = readPort(shell); @@ -986,7 +980,7 @@ describe('React Rspack Module Federation', () => { const remote = uniq('remote'); runCLI( - `generate @nx/react:host ${shell} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --project-name-and-root-format=as-provided --no-interactive --skipFormat` + `generate @nx/react:host ${shell} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --no-interactive --skipFormat` ); const shellPort = readPort(shell); @@ -1122,7 +1116,7 @@ describe('React Rspack Module Federation', () => { const remotePort = 4205; runCLI( - `generate @nx/react:host ${shell} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --dynamic=true --project-name-and-root-format=as-provided --no-interactive --skipFormat` + `generate @nx/react:host ${shell} --remotes=${remote} --bundler=rspack --e2eTestRunner=cypress --dynamic=true --no-interactive --skipFormat` ); updateJson(`${remote}/project.json`, (project) => { diff --git a/e2e/react/src/react-module-federation.test.ts b/e2e/react/src/react-module-federation.test.ts index 2dd9130991f11..9b4cf2eebde0c 100644 --- a/e2e/react/src/react-module-federation.test.ts +++ b/e2e/react/src/react-module-federation.test.ts @@ -133,7 +133,7 @@ describe('React Module Federation', () => { const remote3 = uniq('remote3'); runCLI( - `generate @nx/react:host ${shell} --directory=apps/${shell} --remotes=${remote1},${remote2},${remote3} --bundler=webpack --e2eTestRunner=playwright --style=css --no-interactive --skipFormat` + `generate @nx/react:host apps/${shell} --name=${shell} --remotes=${remote1},${remote2},${remote3} --bundler=webpack --e2eTestRunner=playwright --style=css --no-interactive --skipFormat` ); checkFilesExist(`apps/${shell}/module-federation.config.ts`); @@ -292,10 +292,10 @@ describe('React Module Federation', () => { const remote = uniq('remote'); runCLI( - `generate @nx/react:host ${shell} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive --skipFormat` + `generate @nx/react:host ${shell} --bundler=webpack --no-interactive --skipFormat` ); runCLI( - `generate @nx/react:remote ${remote} --bundler=webpack --host=${shell} --project-name-and-root-format=as-provided --no-interactive --skipFormat` + `generate @nx/react:remote ${remote} --bundler=webpack --host=${shell} --no-interactive --skipFormat` ); const shellPort = readPort(shell); @@ -368,16 +368,14 @@ describe('React Module Federation', () => { const host = uniq('host'); runCLI( - `generate @nx/react:host ${host} --bundler=webpack --remotes=${remote} --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` + `generate @nx/react:host ${host} --bundler=webpack --remotes=${remote} --e2eTestRunner=cypress --no-interactive --skipFormat` ); - runCLI( - `generate @nx/js:lib ${lib} --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` - ); + runCLI(`generate @nx/js:lib ${lib} --no-interactive --skipFormat`); // Federate Module runCLI( - `generate @nx/react:federate-module ${lib}/src/index.ts --bundler=webpack --name=${module} --remote=${remote} --no-interactive --skipFormat` + `generate @nx/react:federate-module ${lib}/src/index.ts --bundler=webpack --name=${module} --remote=${remote} --remoteDirectory=${remote} --no-interactive --skipFormat` ); updateFile( @@ -469,16 +467,14 @@ describe('React Module Federation', () => { const host = uniq('host'); runCLI( - `generate @nx/react:host ${host} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` + `generate @nx/react:host ${host} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --no-interactive --skipFormat` ); - runCLI( - `generate @nx/js:lib ${lib} --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` - ); + runCLI(`generate @nx/js:lib ${lib} --no-interactive --skipFormat`); // Federate Module runCLI( - `generate @nx/react:federate-module ${lib}/src/index.ts --bundler=webpack --name=${module} --remote=${childRemote} --no-interactive --skipFormat` + `generate @nx/react:federate-module ${lib}/src/index.ts --bundler=webpack --name=${module} --remote=${childRemote} --remoteDirectory=${childRemote} --no-interactive --skipFormat` ); updateFile( @@ -577,7 +573,7 @@ describe('React Module Federation', () => { const host = uniq('host'); runCLI( - `generate @nx/react:host ${host} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided --typescriptConfiguration=false --skipFormat` + `generate @nx/react:host ${host} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --no-interactive --typescriptConfiguration=false --skipFormat` ); // Update remote to be loaded via script @@ -711,11 +707,11 @@ describe('React Module Federation', () => { const lib = uniq('lib'); runCLI( - `generate @nx/react:host ${shell} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` + `generate @nx/react:host ${shell} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --no-interactive --skipFormat` ); runCLI( - `generate @nx/js:lib ${lib} --importPath=@acme/${lib} --publishable=true --no-interactive --projectNameAndRootFormat=as-provided --skipFormat` + `generate @nx/js:lib ${lib} --importPath=@acme/${lib} --publishable=true --no-interactive --skipFormat` ); const shellPort = readPort(shell); @@ -861,7 +857,7 @@ describe('React Module Federation', () => { const remote = uniq('remote'); runCLI( - `generate @nx/react:host ${shell} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --project-name-and-root-format=as-provided --no-interactive --skipFormat` + `generate @nx/react:host ${shell} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --no-interactive --skipFormat` ); const shellPort = readPort(shell); @@ -997,7 +993,7 @@ describe('React Module Federation', () => { const remotePort = 4205; runCLI( - `generate @nx/react:host ${shell} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --dynamic=true --project-name-and-root-format=as-provided --no-interactive --skipFormat` + `generate @nx/react:host ${shell} --remotes=${remote} --bundler=webpack --e2eTestRunner=cypress --dynamic=true --no-interactive --skipFormat` ); updateJson(`${remote}/project.json`, (project) => { diff --git a/e2e/react/src/react-package-legacy.test.ts b/e2e/react/src/react-package-legacy.test.ts index fbd9560309117..1fb4a7404f945 100644 --- a/e2e/react/src/react-package-legacy.test.ts +++ b/e2e/react/src/react-package-legacy.test.ts @@ -66,9 +66,7 @@ describe('Build React libraries and apps', () => { ); }; - runCLI( - `generate @nx/react:app ${app} --directory=apps/${app} --no-interactive` - ); + runCLI(`generate @nx/react:app apps/${app} --no-interactive`); updateJson('nx.json', (json) => ({ ...json, generators: { @@ -82,13 +80,13 @@ describe('Build React libraries and apps', () => { })); // generate buildable libs runCLI( - `generate @nx/react:library ${parentLib} --bundler=rollup --directory=libs/${parentLib} --importPath=@${proj}/${parentLib} --no-interactive --unitTestRunner=jest --skipFormat` + `generate @nx/react:library libs/${parentLib} --bundler=rollup --importPath=@${proj}/${parentLib} --no-interactive --unitTestRunner=jest --skipFormat` ); runCLI( - `generate @nx/react:library ${childLib} --bundler=rollup --directory=libs/${childLib} --importPath=@${proj}/${childLib} --no-interactive --unitTestRunner=jest --skipFormat` + `generate @nx/react:library libs/${childLib} --bundler=rollup --importPath=@${proj}/${childLib} --no-interactive --unitTestRunner=jest --skipFormat` ); runCLI( - `generate @nx/react:library ${childLib2} --bundler=rollup --directory=libs/${childLib2} --importPath=@${proj}/${childLib2} --no-interactive --unitTestRunner=jest --skipFormat` + `generate @nx/react:library libs/${childLib2} --bundler=rollup --importPath=@${proj}/${childLib2} --no-interactive --unitTestRunner=jest --skipFormat` ); createDep(parentLib, [childLib, childLib2]); @@ -187,7 +185,7 @@ export async function h() { return 'c'; } const libName = uniq('lib'); runCLI( - `generate @nx/react:lib ${libName} --bundler=rollup --directory=libs/${libName} --importPath=@${proj}/${libName} --no-interactive --unitTestRunner=jest` + `generate @nx/react:lib libs/${libName} --bundler=rollup --importPath=@${proj}/${libName} --no-interactive --unitTestRunner=jest` ); const mainPath = `libs/${libName}/src/lib/${libName}.tsx`; diff --git a/e2e/react/src/react-package.test.ts b/e2e/react/src/react-package.test.ts index 65a48dfb902e9..f5b72a9af6b20 100644 --- a/e2e/react/src/react-package.test.ts +++ b/e2e/react/src/react-package.test.ts @@ -61,9 +61,7 @@ describe('Build React libraries and apps', () => { ); }; - runCLI( - `generate @nx/react:app ${app} --directory=apps/${app} --no-interactive` - ); + runCLI(`generate @nx/react:app apps/${app} --no-interactive`); updateJson('nx.json', (json) => ({ ...json, generators: { @@ -77,13 +75,13 @@ describe('Build React libraries and apps', () => { })); // generate buildable libs runCLI( - `generate @nx/react:library ${parentLib} --bundler=rollup --directory=libs/${parentLib} --importPath=@${proj}/${parentLib} --no-interactive --unitTestRunner=jest --skipFormat` + `generate @nx/react:library libs/${parentLib} --bundler=rollup --importPath=@${proj}/${parentLib} --no-interactive --unitTestRunner=jest --skipFormat` ); runCLI( - `generate @nx/react:library ${childLib} --bundler=rollup --directory=libs/${childLib} --importPath=@${proj}/${childLib} --no-interactive --unitTestRunner=jest --skipFormat` + `generate @nx/react:library libs/${childLib} --bundler=rollup --importPath=@${proj}/${childLib} --no-interactive --unitTestRunner=jest --skipFormat` ); runCLI( - `generate @nx/react:library ${childLib2} --bundler=rollup --directory=libs/${childLib2} --importPath=@${proj}/${childLib2} --no-interactive --unitTestRunner=jest --skipFormat` + `generate @nx/react:library libs/${childLib2} --bundler=rollup --importPath=@${proj}/${childLib2} --no-interactive --unitTestRunner=jest --skipFormat` ); createDep(parentLib, [childLib, childLib2]); @@ -158,7 +156,7 @@ module.exports = withNx( // Setup const myLib = uniq('my-lib'); runCLI( - `generate @nx/react:library ${myLib} --bundler=rollup --directory=libs/${myLib} --publishable --importPath="@mproj/${myLib}" --no-interactive --unitTestRunner=jest` + `generate @nx/react:library libs/${myLib} --bundler=rollup --publishable --importPath="@mproj/${myLib}" --no-interactive --unitTestRunner=jest` ); /** @@ -209,7 +207,7 @@ module.exports = withNx( const libName = uniq('lib'); runCLI( - `generate @nx/react:lib ${libName} --directory=libs/${libName} --bundler=rollup --importPath=@${proj}/${libName} --no-interactive --unitTestRunner=jest` + `generate @nx/react:lib libs/${libName} --bundler=rollup --importPath=@${proj}/${libName} --no-interactive --unitTestRunner=jest` ); const mainPath = `libs/${libName}/src/lib/${libName}.tsx`; diff --git a/e2e/react/src/react-vite.test.ts b/e2e/react/src/react-vite.test.ts index 111025c8e0e29..29193e84965a1 100644 --- a/e2e/react/src/react-vite.test.ts +++ b/e2e/react/src/react-vite.test.ts @@ -22,7 +22,7 @@ describe('Build React applications and libraries with Vite', () => { const viteApp = uniq('viteapp'); runCLI( - `generate @nx/react:app ${viteApp} --bundler=vite --directory=apps/${viteApp} --compiler=babel --unitTestRunner=vitest --no-interactive` + `generate @nx/react:app apps/${viteApp} --bundler=vite --compiler=babel --unitTestRunner=vitest --no-interactive` ); const appTestResults = await runCLIAsync(`test ${viteApp}`); @@ -43,7 +43,7 @@ describe('Build React applications and libraries with Vite', () => { const viteApp = uniq('viteapp'); runCLI( - `generate @nx/react:app ${viteApp} --bundler=vite --directory=apps/${viteApp} --compiler=swc --unitTestRunner=vitest --no-interactive` + `generate @nx/react:app apps/${viteApp} --bundler=vite --compiler=swc --unitTestRunner=vitest --no-interactive` ); const appTestResults = await runCLIAsync(`test ${viteApp}`); @@ -65,7 +65,7 @@ describe('Build React applications and libraries with Vite', () => { const viteLib = uniq('vitelib'); runCLI( - `generate @nx/react:app ${viteApp} --bundler=vite --directory=apps/${viteApp} --unitTestRunner=vitest --inSourceTests --no-interactive` + `generate @nx/react:app apps/${viteApp} --bundler=vite --unitTestRunner=vitest --inSourceTests --no-interactive` ); expect(() => { checkFilesExist(`apps/${viteApp}/src/app/app.spec.tsx`); @@ -85,7 +85,7 @@ describe('Build React applications and libraries with Vite', () => { checkFilesExist(`dist/apps/${viteApp}/index.html`); runCLI( - `generate @nx/react:lib ${viteLib} --bundler=vite --directory=libs/${viteLib} --inSourceTests --unitTestRunner=vitest --no-interactive` + `generate @nx/react:lib libs/${viteLib} --bundler=vite --inSourceTests --unitTestRunner=vitest --no-interactive` ); expect(() => { checkFilesExist(`libs/${viteLib}/src/lib/${viteLib}.spec.tsx`); @@ -125,7 +125,7 @@ describe('Build React applications and libraries with Vite', () => { const viteLib = uniq('vitelib'); runCLI( - `generate @nx/react:lib ${viteLib} --bundler=vite --directory=libs/${viteLib} --no-interactive --unit-test-runner=none` + `generate @nx/react:lib libs/${viteLib} --bundler=vite --no-interactive --unit-test-runner=none` ); await runCLIAsync(`build ${viteLib}`); @@ -139,7 +139,7 @@ describe('Build React applications and libraries with Vite', () => { // Convert non-buildable lib to buildable one const nonBuildableLib = uniq('nonbuildablelib'); runCLI( - `generate @nx/react:lib ${nonBuildableLib} --no-interactive --directory=libs/${nonBuildableLib} --unitTestRunner=jest` + `generate @nx/react:lib libs/${nonBuildableLib} --no-interactive --unitTestRunner=jest` ); runCLI( `generate @nx/vite:configuration ${nonBuildableLib} --uiFramework=react --no-interactive` @@ -157,7 +157,7 @@ describe('Build React applications and libraries with Vite', () => { const viteApp = uniq('viteapp'); runCLI( - `generate @nx/react:app ${viteApp} --directory=apps/${viteApp} --bundler=vite --unitTestRunner=jest --no-interactive` + `generate @nx/react:app apps/${viteApp} --bundler=vite --unitTestRunner=jest --no-interactive` ); const appTestResults = await runCLIAsync(`test ${viteApp}`); diff --git a/e2e/react/src/react-webpack.test.ts b/e2e/react/src/react-webpack.test.ts index 40e1ddf1501c5..9fb22144aa5fa 100644 --- a/e2e/react/src/react-webpack.test.ts +++ b/e2e/react/src/react-webpack.test.ts @@ -26,7 +26,7 @@ describe('Build React applications and libraries with Vite', () => { const appName = uniq('app'); runCLI( - `generate @nx/react:app ${appName} --directory=apps/${appName} --bundler=webpack --compiler=babel --unitTestRunner=none --no-interactive` + `generate @nx/react:app apps/${appName} --bundler=webpack --compiler=babel --unitTestRunner=none --no-interactive` ); createFile( `apps/${appName}/src/app/nx.svg`, @@ -67,7 +67,7 @@ describe('Build React applications and libraries with Vite', () => { const appName = uniq('app'); runCLI( - `generate @nx/react:app ${appName} --directory=apps/${appName} --bundler=webpack --compiler=babel --unitTestRunner=none --no-interactive` + `generate @nx/react:app apps/${appName} --bundler=webpack --compiler=babel --unitTestRunner=none --no-interactive` ); createFile( `apps/${appName}/src/app/nx.svg`, diff --git a/e2e/react/src/react.test.ts b/e2e/react/src/react.test.ts index e5a8fcfbfe7e0..7d108b20794a2 100644 --- a/e2e/react/src/react.test.ts +++ b/e2e/react/src/react.test.ts @@ -34,10 +34,10 @@ describe('React Applications', () => { const libName = uniq('lib'); runCLI( - `generate @nx/react:app ${appName} --directory=apps/${appName} --bundler=vite --no-interactive --skipFormat` + `generate @nx/react:app apps/${appName} --name=${appName} --bundler=vite --no-interactive --skipFormat` ); runCLI( - `generate @nx/react:lib ${libName} --directory=libs/${libName} --bundler=none --no-interactive --unit-test-runner=vitest --skipFormat` + `generate @nx/react:lib libs/${libName} --bundler=none --no-interactive --unit-test-runner=vitest --skipFormat` ); // Library generated with Vite @@ -107,13 +107,13 @@ describe('React Applications', () => { const redSvg = ``; runCLI( - `generate @nx/react:app ${appName} --directory=apps/${appName} --style=css --bundler=webpack --unit-test-runner=jest --no-interactive --skipFormat` + `generate @nx/react:app apps/${appName} --style=css --bundler=webpack --unit-test-runner=jest --no-interactive --skipFormat` ); runCLI( - `generate @nx/react:lib ${libName} --directory=libs${libName} --style=css --no-interactive --unit-test-runner=jest --skipFormat` + `generate @nx/react:lib libs/${libName} --style=css --no-interactive --unit-test-runner=jest --skipFormat` ); runCLI( - `generate @nx/react:lib ${libWithNoComponents} --directory=libs/${libWithNoComponents} --no-interactive --no-component --unit-test-runner=jest --skipFormat` + `generate @nx/react:lib libs/${libWithNoComponents} --no-interactive --no-component --unit-test-runner=jest --skipFormat` ); // Libs should not include package.json by default @@ -199,7 +199,7 @@ describe('React Applications', () => { const appName = uniq('app'); runCLI( - `generate @nx/react:app ${appName} --directory=apps/${appName} --routing --bundler=webpack --no-interactive --skipFormat` + `generate @nx/react:app apps/${appName} --routing --bundler=webpack --no-interactive --skipFormat` ); runCLI(`build ${appName}`); @@ -216,13 +216,13 @@ describe('React Applications', () => { const libName = uniq('lib'); runCLI( - `g @nx/react:app ${appName} --directory=apps/${appName} --bundler=webpack --no-interactive --skipFormat` + `g @nx/react:app apps/${appName} --bundler=webpack --no-interactive --skipFormat` ); runCLI( `g @nx/react:redux apps/${appName}/src/app/lemon/lemon --skipFormat` ); runCLI( - `g @nx/react:lib ${libName} --directory=libs/${libName} --unit-test-runner=jest --no-interactive --skipFormat` + `g @nx/react:lib libs/${libName} --unit-test-runner=jest --no-interactive --skipFormat` ); runCLI( `g @nx/react:redux libs/${libName}/src/lib/orange/orange --skipFormat` @@ -252,7 +252,7 @@ describe('React Applications', () => { const libName = uniq('@my-org/lib1'); runCLI( - `generate @nx/react:app ${appName} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive --skipFormat` + `generate @nx/react:app ${appName} --bundler=webpack --no-interactive --skipFormat` ); // check files are generated without the layout directory ("apps/") and @@ -269,7 +269,7 @@ describe('React Applications', () => { ); runCLI( - `generate @nx/react:lib ${libName} --unit-test-runner=jest --buildable --project-name-and-root-format=as-provided --no-interactive --skipFormat` + `generate @nx/react:lib ${libName} --unit-test-runner=jest --buildable --no-interactive --skipFormat` ); // check files are generated without the layout directory ("libs/") and @@ -340,7 +340,7 @@ describe('React Applications', () => { it('should support tailwind', async () => { const appName = uniq('app'); runCLI( - `generate @nx/react:app ${appName} --directory=apps/${appName} --style=tailwind --bundler=vite --no-interactive --skipFormat` + `generate @nx/react:app apps/${appName} --style=tailwind --bundler=vite --no-interactive --skipFormat` ); // update app to use styled-jsx @@ -414,15 +414,15 @@ describe('React Applications', () => { const plainJsLib = uniq('jslib'); runCLI( - `generate @nx/react:app ${appName} --directory=apps/${appName} --bundler=webpack --unit-test-runner=jest --no-interactive --js --skipFormat` + `generate @nx/react:app apps/${appName} --bundler=webpack --unit-test-runner=jest --no-interactive --js --skipFormat` ); runCLI( - `generate @nx/react:lib ${libName} --directory=libs/${libName} --no-interactive --js --unit-test-runner=none --skipFormat` + `generate @nx/react:lib libs/${libName} --no-interactive --js --unit-test-runner=none --skipFormat` ); // Make sure plain JS libs can be imported as well. // There was an issue previously: https://github.com/nrwl/nx/issues/10990 runCLI( - `generate @nx/js:lib ${plainJsLib} --directory=libs/${plainJsLib} --js --unit-test-runner=none --bundler=none --compiler=tsc --no-interactive --skipFormat` + `generate @nx/js:lib libs/${plainJsLib} --js --unit-test-runner=none --bundler=none --compiler=tsc --no-interactive --skipFormat` ); const mainPath = `apps/${appName}/src/main.js`; @@ -448,7 +448,7 @@ describe('React Applications', () => { `('should support global and css modules', async ({ style }) => { const appName = uniq('app'); runCLI( - `generate @nx/react:app ${appName} --directory=apps/${appName} --style=${style} --bundler=webpack --no-interactive --skipFormat` + `generate @nx/react:app apps/${appName} --style=${style} --bundler=webpack --no-interactive --skipFormat` ); // make sure stylePreprocessorOptions works @@ -484,10 +484,10 @@ describe('React Applications', () => { const libName = uniq('lib'); runCLI( - `g @nx/react:app ${appName} --directory=apps/${appName} --bundler=webpack --no-interactive --skipFormat` + `g @nx/react:app apps/${appName} --bundler=webpack --no-interactive --skipFormat` ); runCLI( - `g @nx/react:lib ${libName} --directory=libs/${libName} --no-interactive --unit-test-runner=none --skipFormat` + `g @nx/react:lib libs/${libName} --no-interactive --unit-test-runner=none --skipFormat` ); const mainPath = `apps/${appName}/src/main.tsx`; diff --git a/e2e/release/src/circular-dependencies.test.ts b/e2e/release/src/circular-dependencies.test.ts index 6d858e94ce9b0..7e5556225bd79 100644 --- a/e2e/release/src/circular-dependencies.test.ts +++ b/e2e/release/src/circular-dependencies.test.ts @@ -50,7 +50,6 @@ describe('nx release circular dependencies', () => { beforeAll(async () => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/conventional-commits-config.test.ts b/e2e/release/src/conventional-commits-config.test.ts index a8e3e8b8c79eb..1f081101bbae2 100644 --- a/e2e/release/src/conventional-commits-config.test.ts +++ b/e2e/release/src/conventional-commits-config.test.ts @@ -50,7 +50,6 @@ describe('nx release conventional commits config', () => { beforeAll(async () => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/create-github-release.test.ts b/e2e/release/src/create-github-release.test.ts index de6c4cfe0f291..c00c90c652686 100644 --- a/e2e/release/src/create-github-release.test.ts +++ b/e2e/release/src/create-github-release.test.ts @@ -46,7 +46,6 @@ describe('nx release create github release', () => { beforeAll(async () => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/custom-registries.test.ts b/e2e/release/src/custom-registries.test.ts index e273b81bcee1b..3afd01b5f5f8f 100644 --- a/e2e/release/src/custom-registries.test.ts +++ b/e2e/release/src/custom-registries.test.ts @@ -24,7 +24,6 @@ describe('nx release - custom npm registries', () => { // We are testing some more advanced scoped registry features that only npm has within this file process.env.SELECTED_PM = 'npm'; newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); }, 60000); diff --git a/e2e/release/src/first-release.test.ts b/e2e/release/src/first-release.test.ts index 86f35fbd799fa..653104a76ea62 100644 --- a/e2e/release/src/first-release.test.ts +++ b/e2e/release/src/first-release.test.ts @@ -46,7 +46,6 @@ describe('nx release first run', () => { beforeAll(async () => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/independent-projects.test.ts b/e2e/release/src/independent-projects.test.ts index 16f547da391d0..80196a8402de6 100644 --- a/e2e/release/src/independent-projects.test.ts +++ b/e2e/release/src/independent-projects.test.ts @@ -65,7 +65,6 @@ describe('nx release - independent projects', () => { beforeAll(() => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/lock-file-updates.test.ts b/e2e/release/src/lock-file-updates.test.ts index 55da4e278105a..28fc24633ffe7 100644 --- a/e2e/release/src/lock-file-updates.test.ts +++ b/e2e/release/src/lock-file-updates.test.ts @@ -58,7 +58,6 @@ describe('nx release lock file updates', () => { process.env.SELECTED_PM = packageManager; newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], packageManager, }); diff --git a/e2e/release/src/multiple-release-branches.test.ts b/e2e/release/src/multiple-release-branches.test.ts index 18935443ef65e..0c2a2ea257db2 100644 --- a/e2e/release/src/multiple-release-branches.test.ts +++ b/e2e/release/src/multiple-release-branches.test.ts @@ -61,7 +61,6 @@ describe('nx release multiple release branches', () => { beforeEach(() => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/nx-release-git-operations.test.ts b/e2e/release/src/nx-release-git-operations.test.ts index dfa34edcbc728..1ac784ccdbbd1 100644 --- a/e2e/release/src/nx-release-git-operations.test.ts +++ b/e2e/release/src/nx-release-git-operations.test.ts @@ -46,7 +46,6 @@ describe('nx release git operations', () => { beforeAll(async () => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/pre-version-command.test.ts b/e2e/release/src/pre-version-command.test.ts index bb66ebb963b62..ef46bec5bb1fa 100644 --- a/e2e/release/src/pre-version-command.test.ts +++ b/e2e/release/src/pre-version-command.test.ts @@ -42,7 +42,6 @@ describe('nx release pre-version command', () => { beforeAll(() => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/private-js-packages.test.ts b/e2e/release/src/private-js-packages.test.ts index d095fd43537b0..47351dc545dd2 100644 --- a/e2e/release/src/private-js-packages.test.ts +++ b/e2e/release/src/private-js-packages.test.ts @@ -47,7 +47,6 @@ describe('nx release - private JS packages', () => { beforeAll(() => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/release.test.ts b/e2e/release/src/release.test.ts index 9d5bae1dc2f88..62db28b99b9ff 100644 --- a/e2e/release/src/release.test.ts +++ b/e2e/release/src/release.test.ts @@ -53,7 +53,6 @@ describe('nx release', () => { beforeAll(() => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/version-plans-check.test.ts b/e2e/release/src/version-plans-check.test.ts index d93093d8b0102..f42c90422ed72 100644 --- a/e2e/release/src/version-plans-check.test.ts +++ b/e2e/release/src/version-plans-check.test.ts @@ -52,7 +52,6 @@ describe('nx release version plans check command', () => { beforeEach(async () => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/version-plans-only-touched.test.ts b/e2e/release/src/version-plans-only-touched.test.ts index afad362d641f3..ec193dae4ed84 100644 --- a/e2e/release/src/version-plans-only-touched.test.ts +++ b/e2e/release/src/version-plans-only-touched.test.ts @@ -49,7 +49,6 @@ describe('nx release version plans only touched', () => { beforeEach(async () => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/release/src/version-plans.test.ts b/e2e/release/src/version-plans.test.ts index e8d2a7cf00af1..c94bf7a72df09 100644 --- a/e2e/release/src/version-plans.test.ts +++ b/e2e/release/src/version-plans.test.ts @@ -54,7 +54,6 @@ describe('nx release version plans', () => { beforeEach(async () => { newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/js'], }); diff --git a/e2e/remix/src/nx-remix.test.ts b/e2e/remix/src/nx-remix.test.ts index 88da1de8d1ca2..edb4e7f2450c8 100644 --- a/e2e/remix/src/nx-remix.test.ts +++ b/e2e/remix/src/nx-remix.test.ts @@ -26,9 +26,7 @@ describe('Remix E2E Tests', () => { it('should not cause peer dependency conflicts', async () => { const plugin = uniq('remix'); - runCLI( - `generate @nx/remix:app ${plugin} --projectNameAndRootFormat=as-provided` - ); + runCLI(`generate @nx/remix:app ${plugin}`); await runCommandAsync('npm install'); }, 120000); @@ -55,10 +53,10 @@ describe('Remix E2E Tests', () => { }, 120000); describe('--directory', () => { - it('should create src in the specified directory --projectNameAndRootFormat=as-provided', async () => { + it('should create src in the specified directory', async () => { const plugin = uniq('remix'); runCLI( - `generate @nx/remix:app ${plugin} --directory=subdir --projectNameAndRootFormat=as-provided --rootProject=false --no-interactive` + `generate @nx/remix:app --name=${plugin} --directory=subdir --rootProject=false --no-interactive` ); const result = runCLI(`build ${plugin}`); @@ -71,7 +69,7 @@ describe('Remix E2E Tests', () => { it('should add tags to the project', async () => { const plugin = uniq('remix'); runCLI( - `generate @nx/remix:app --directory=apps/${plugin} ${plugin} --tags e2etag,e2ePackage` + `generate @nx/remix:app apps/${plugin} --tags e2etag,e2ePackage` ); const project = readJson(`apps/${plugin}/project.json`); expect(project.tags).toEqual(['e2etag', 'e2ePackage']); @@ -120,7 +118,7 @@ describe('Remix E2E Tests', () => { beforeAll(async () => { runCLI( - `generate @nx/remix:app ${plugin} --directory=apps/${plugin} --tags e2etag,e2ePackage` + `generate @nx/remix:app apps/${plugin} --tags e2etag,e2ePackage` ); }, 120000); diff --git a/e2e/rspack/tests/rspack.spec.ts b/e2e/rspack/tests/rspack.spec.ts index abeac82f237a9..0d629a14801a9 100644 --- a/e2e/rspack/tests/rspack.spec.ts +++ b/e2e/rspack/tests/rspack.spec.ts @@ -32,7 +32,7 @@ describe('rspack e2e', () => { it('should create rspack root project and additional apps', async () => { const project = uniq('myapp'); runCLI( - `generate @nx/rspack:preset ${project} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress` + `generate @nx/rspack:preset ${project} --framework=react --unitTestRunner=jest --e2eTestRunner=cypress --verbose` ); // Added this so that the nx-ecosystem-ci tests don't throw jest error diff --git a/e2e/storybook/src/storybook-angular.test.ts b/e2e/storybook/src/storybook-angular.test.ts index 738ca5bc94f26..5252f47380519 100644 --- a/e2e/storybook/src/storybook-angular.test.ts +++ b/e2e/storybook/src/storybook-angular.test.ts @@ -13,11 +13,8 @@ describe('Storybook executors for Angular', () => { beforeAll(() => { newProject({ packages: ['@nx/angular'], - unsetProjectNameAndRootFormat: false, }); - runCLI( - `g @nx/angular:library ${angularStorybookLib} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`g @nx/angular:library ${angularStorybookLib} --no-interactive`); runCLI( `generate @nx/angular:storybook-configuration ${angularStorybookLib} --generateStories --no-interactive` ); diff --git a/e2e/storybook/src/storybook-nested.test.ts b/e2e/storybook/src/storybook-nested.test.ts index 4b559bb152793..9a6ed39028cc1 100644 --- a/e2e/storybook/src/storybook-nested.test.ts +++ b/e2e/storybook/src/storybook-nested.test.ts @@ -75,7 +75,7 @@ describe('Storybook generators and executors for standalone workspaces - using R it('should build a React based storybook that references another lib and uses Vite', () => { runCLI( - `generate @nx/react:lib my-lib --bundler=vite --unitTestRunner=none --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/react:lib my-lib --bundler=vite --unitTestRunner=none --no-interactive` ); // create a component and a story in the first lib to reference the cmp from the 2nd lib diff --git a/e2e/storybook/src/storybook.test.ts b/e2e/storybook/src/storybook.test.ts index 4c22b6ee7f3c1..ea69bb48ffb63 100644 --- a/e2e/storybook/src/storybook.test.ts +++ b/e2e/storybook/src/storybook.test.ts @@ -20,10 +20,9 @@ describe('Storybook generators and executors for monorepos', () => { beforeAll(async () => { proj = newProject({ packages: ['@nx/react'], - unsetProjectNameAndRootFormat: false, }); runCLI( - `generate @nx/react:app ${reactStorybookApp} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/react:app ${reactStorybookApp} --bundler=webpack --no-interactive` ); runCLI( `generate @nx/react:storybook-configuration ${reactStorybookApp} --generateStories --no-interactive --bundler=webpack` @@ -59,7 +58,7 @@ describe('Storybook generators and executors for monorepos', () => { // This test makes sure path resolution works it('should build a React based storybook that references another lib and uses rollup', () => { runCLI( - `generate @nx/react:lib my-lib --bundler=rollup --unitTestRunner=none --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/react:lib my-lib --bundler=rollup --unitTestRunner=none --no-interactive` ); // create a component in the first lib to reference the cmp from the 2nd lib diff --git a/e2e/utils/create-project-utils.ts b/e2e/utils/create-project-utils.ts index 5cac030113445..25bf031ba8554 100644 --- a/e2e/utils/create-project-utils.ts +++ b/e2e/utils/create-project-utils.ts @@ -75,12 +75,10 @@ type NxPackage = (typeof nxPackages)[number]; export function newProject({ name = uniq('proj'), packageManager = getSelectedPackageManager(), - unsetProjectNameAndRootFormat = true, packages, }: { name?: string; packageManager?: 'npm' | 'yarn' | 'pnpm' | 'bun'; - unsetProjectNameAndRootFormat?: boolean; readonly packages?: Array; } = {}): string { const newProjectStart = performance.mark('new-project:start'); @@ -105,14 +103,6 @@ export function newProject({ createNxWorkspaceEnd.name ); - 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' - ); - createFile('apps/.gitkeep'); - createFile('libs/.gitkeep'); - } - // Temporary hack to prevent installing with `--frozen-lockfile` if (isCI && packageManager === 'pnpm') { updateFile( diff --git a/e2e/vite/src/vite-esm.test.ts b/e2e/vite/src/vite-esm.test.ts index fa19cb0311ce5..484a79a4b0f13 100644 --- a/e2e/vite/src/vite-esm.test.ts +++ b/e2e/vite/src/vite-esm.test.ts @@ -12,16 +12,13 @@ import { describe('Vite ESM tests', () => { beforeAll(() => newProject({ - unsetProjectNameAndRootFormat: false, packages: ['@nx/react'], }) ); it('should build with Vite when it is ESM-only', async () => { const appName = uniq('viteapp'); - runCLI( - `generate @nx/react:app ${appName} --bundler=vite --project-name-and-root-format=as-provided` - ); + runCLI(`generate @nx/react:app ${appName} --bundler=vite`); // .mts file is needed because Nx will transpile .ts files as CJS renameFile(`${appName}/vite.config.ts`, `${appName}/vite.config.mts`); diff --git a/e2e/vite/src/vite-legacy.test.ts b/e2e/vite/src/vite-legacy.test.ts index b64dae09dcd75..33841fa4bdca3 100644 --- a/e2e/vite/src/vite-legacy.test.ts +++ b/e2e/vite/src/vite-legacy.test.ts @@ -48,9 +48,7 @@ describe('Vite Plugin', () => { beforeAll(() => { myApp = uniq('my-app'); - runCLI( - `generate @nx/react:app ${myApp} --bundler=vite --directory=${myApp} --projectNameAndRootFormat=as-provided` - ); + runCLI(`generate @nx/react:app ${myApp} --bundler=vite`); }); afterEach(() => { @@ -97,7 +95,7 @@ describe('Vite Plugin', () => { beforeEach(() => { myApp = uniq('my-app'); runCLI( - `generate @nx/web:app ${myApp} --bundler=vite --directory=${myApp} --projectNameAndRootFormat=as-provided` + `generate @nx/web:app ${myApp} --bundler=vite --directory=${myApp}` ); }); it('should build application', async () => { @@ -189,22 +187,22 @@ describe('Vite Plugin', () => { packages: ['@nx/react'], }); runCLI( - `generate @nx/react:app ${app} --bundler=vite --no-interactive --directory=${app} --projectNameAndRootFormat=as-provided` + `generate @nx/react:app ${app} --bundler=vite --no-interactive --directory=${app}` ); // only this project will be directly used from dist runCLI( - `generate @nx/react:lib ${lib}-buildable --unitTestRunner=none --bundler=vite --importPath="@acme/buildable" --no-interactive --directory=${lib}-buildable --projectNameAndRootFormat=as-provided` + `generate @nx/react:lib ${lib}-buildable --unitTestRunner=none --bundler=vite --importPath="@acme/buildable" --no-interactive --directory=${lib}-buildable` ); runCLI( - `generate @nx/react:lib ${lib} --unitTestRunner=none --bundler=none --importPath="@acme/non-buildable" --no-interactive --directory=${lib} --projectNameAndRootFormat=as-provided` + `generate @nx/react:lib ${lib} --unitTestRunner=none --bundler=none --importPath="@acme/non-buildable" --no-interactive --directory=${lib}` ); // because the default js lib builds as cjs it cannot be loaded from dist // so the paths plugin should always resolve to the libs source runCLI( - `generate @nx/js:lib ${lib}-js --bundler=tsc --importPath="@acme/js-lib" --no-interactive --directory=${lib}-js --projectNameAndRootFormat=as-provided` + `generate @nx/js:lib ${lib}-js --bundler=tsc --importPath="@acme/js-lib" --no-interactive --directory=${lib}-js` ); const buildableLibCmp = names(`${lib}-buildable`).className; const nonBuildableLibCmp = names(lib).className; diff --git a/e2e/vite/src/vite.test.ts b/e2e/vite/src/vite.test.ts index 28ec3e3a9df40..7d7dc9639e63e 100644 --- a/e2e/vite/src/vite.test.ts +++ b/e2e/vite/src/vite.test.ts @@ -155,7 +155,7 @@ describe('@nx/vite/plugin', () => { it('should support importing .js and .css files in tsconfig path', () => { const mylib = uniq('mylib'); runCLI( - `generate @nx/react:library ${mylib} --bundler=none --unitTestRunner=vitest --directory=libs/${mylib} --project-name-and-root-format=as-provided` + `generate @nx/react:library libs/${mylib} --bundler=none --unitTestRunner=vitest` ); updateFile(`libs/${mylib}/src/styles.css`, `.foo {}`); updateFile(`libs/${mylib}/src/foo.mts`, `export const foo = 'foo';`); @@ -187,7 +187,7 @@ describe('@nx/vite/plugin', () => { packages: ['@nx/vite', '@nx/react'], }); runCLI( - `generate @nx/react:app ${reactVitest} --bundler=webpack --unitTestRunner=vitest --e2eTestRunner=none --projectNameAndRootFormat=as-provided` + `generate @nx/react:app ${reactVitest} --bundler=webpack --unitTestRunner=vitest --e2eTestRunner=none` ); }); diff --git a/e2e/vue/src/vue-legacy.test.ts b/e2e/vue/src/vue-legacy.test.ts index 4d92318a772b3..851fb7620266a 100644 --- a/e2e/vue/src/vue-legacy.test.ts +++ b/e2e/vue/src/vue-legacy.test.ts @@ -6,7 +6,6 @@ describe('Vue Plugin (legacy)', () => { beforeAll(() => { proj = newProject({ packages: ['@nx/vue'], - unsetProjectNameAndRootFormat: false, }); }); diff --git a/e2e/vue/src/vue-storybook.test.ts b/e2e/vue/src/vue-storybook.test.ts index a68fbf7b2aa1d..3af588889ed84 100644 --- a/e2e/vue/src/vue-storybook.test.ts +++ b/e2e/vue/src/vue-storybook.test.ts @@ -16,11 +16,8 @@ describe('Storybook generators and executors for Vue projects', () => { process.env.NX_ADD_PLUGINS = 'true'; proj = newProject({ packages: ['@nx/vue'], - unsetProjectNameAndRootFormat: false, }); - runCLI( - `generate @nx/vue:app ${vueStorybookApp} --project-name-and-root-format=as-provided --no-interactive` - ); + runCLI(`generate @nx/vue:app ${vueStorybookApp} --no-interactive`); runCLI( `generate @nx/vue:storybook-configuration ${vueStorybookApp} --generateStories --no-interactive` ); diff --git a/e2e/vue/src/vue-tailwind.test.ts b/e2e/vue/src/vue-tailwind.test.ts index b174ab57f3e71..604a385fbe89c 100644 --- a/e2e/vue/src/vue-tailwind.test.ts +++ b/e2e/vue/src/vue-tailwind.test.ts @@ -10,7 +10,7 @@ import { describe('vue tailwind support', () => { beforeAll(() => { - newProject({ unsetProjectNameAndRootFormat: false, packages: ['@nx/vue'] }); + newProject({ packages: ['@nx/vue'] }); }); afterAll(() => { diff --git a/e2e/vue/src/vue.test.ts b/e2e/vue/src/vue.test.ts index a9c65bf97dc32..2857d081d57a1 100644 --- a/e2e/vue/src/vue.test.ts +++ b/e2e/vue/src/vue.test.ts @@ -6,7 +6,6 @@ describe('Vue Plugin', () => { beforeAll(() => { proj = newProject({ packages: ['@nx/vue'], - unsetProjectNameAndRootFormat: false, }); }); diff --git a/e2e/web/src/file-server.test.ts b/e2e/web/src/file-server.test.ts index dc7669060327a..5bb1a4da8d721 100644 --- a/e2e/web/src/file-server.test.ts +++ b/e2e/web/src/file-server.test.ts @@ -22,9 +22,7 @@ describe('file-server', () => { const appName = uniq('app'); const port = 4301; - runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --no-interactive` - ); + runCLI(`generate @nx/web:app apps/${appName} --no-interactive`); updateJson(join('apps', appName, 'project.json'), (config) => { config.targets['serve'] = { executor: '@nx/web:file-server', @@ -54,9 +52,7 @@ describe('file-server', () => { const appName = uniq('app'); const port = 4301; - runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --no-interactive` - ); + runCLI(`generate @nx/web:app apps/${appName} --no-interactive`); // Used to copy index.html rather than the normal webpack build. updateFile( `apps/${appName}/copy-index.js`, diff --git a/e2e/web/src/web-legacy.test.ts b/e2e/web/src/web-legacy.test.ts index ec2b7d42865ec..c19cf9a576daf 100644 --- a/e2e/web/src/web-legacy.test.ts +++ b/e2e/web/src/web-legacy.test.ts @@ -22,7 +22,7 @@ describe('Web Components Applications (legacy)', () => { const libName = uniq('lib'); runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=webpack --no-interactive --compiler swc`, + `generate @nx/web:app apps/${appName} --bundler=webpack --no-interactive --compiler swc`, { env: { NX_ADD_PLUGINS: 'false', @@ -30,7 +30,7 @@ describe('Web Components Applications (legacy)', () => { } ); runCLI( - `generate @nx/react:lib ${libName} --directory=libs/${libName} --bundler=rollup --no-interactive --compiler swc --unitTestRunner=jest`, + `generate @nx/react:lib libs/${libName} --bundler=rollup --no-interactive --compiler swc --unitTestRunner=jest`, { env: { NX_ADD_PLUGINS: 'false', @@ -71,7 +71,7 @@ describe('Web Components Applications (legacy)', () => { it('should support custom webpackConfig option', async () => { const appName = uniq('app'); runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=webpack --no-interactive`, + `generate @nx/web:app apps/${appName} --bundler=webpack --no-interactive`, { env: { NX_ADD_PLUGINS: 'false', @@ -136,7 +136,7 @@ describe('Build Options (legacy) ', () => { const appName = uniq('app'); runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=webpack --no-interactive`, + `generate @nx/web:app apps/${appName} --bundler=webpack --no-interactive`, { env: { NX_ADD_PLUGINS: 'false', @@ -223,7 +223,7 @@ describe('index.html interpolation (legacy)', () => { const appName = uniq('app'); runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=webpack --no-interactive`, + `generate @nx/web:app apps/${appName} --bundler=webpack --no-interactive`, { env: { NX_ADD_PLUGINS: 'false', diff --git a/e2e/web/src/web-vite.test.ts b/e2e/web/src/web-vite.test.ts index 59b8d03190cf3..ebe91c0e358b7 100644 --- a/e2e/web/src/web-vite.test.ts +++ b/e2e/web/src/web-vite.test.ts @@ -19,7 +19,7 @@ describe('Web Components Applications with bundler set as vite', () => { it('should be able to generate a web app', async () => { const appName = uniq('app'); runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=vite --no-interactive` + `generate @nx/web:app apps/${appName} --bundler=vite --no-interactive` ); const lintResults = runCLI(`lint ${appName}`); @@ -50,10 +50,10 @@ describe('Web Components Applications with bundler set as vite', () => { const libName = uniq('lib'); runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=vite --no-interactive` + `generate @nx/web:app apps/${appName} --bundler=vite --no-interactive` ); runCLI( - `generate @nx/react:lib ${libName} --directory=libs/${libName} --bundler=vite --no-interactive --unitTestRunner=vitest` + `generate @nx/react:lib libs/${libName} --bundler=vite --no-interactive --unitTestRunner=vitest` ); createFile(`dist/apps/${appName}/_should_remove.txt`); diff --git a/e2e/web/src/web.test.ts b/e2e/web/src/web.test.ts index d2afe6f64ca00..f71e44e4176b2 100644 --- a/e2e/web/src/web.test.ts +++ b/e2e/web/src/web.test.ts @@ -26,7 +26,7 @@ describe('Web Components Applications', () => { it('should be able to generate a web app', async () => { const appName = uniq('app'); runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=webpack --no-interactive` + `generate @nx/web:app apps/${appName} --bundler=webpack --no-interactive` ); const lintResults = runCLI(`lint ${appName}`); @@ -110,7 +110,7 @@ describe('Web Components Applications', () => { it('should emit decorator metadata when --compiler=babel and it is enabled in tsconfig', async () => { const appName = uniq('app'); runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=webpack --compiler=babel --no-interactive` + `generate @nx/web:app apps/${appName} --bundler=webpack --compiler=babel --no-interactive` ); updateFile(`apps/${appName}/src/app/app.element.ts`, (content) => { @@ -175,7 +175,7 @@ describe('Web Components Applications', () => { it('should emit decorator metadata when using --compiler=swc', async () => { const appName = uniq('app'); runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=webpack --compiler=swc --no-interactive` + `generate @nx/web:app apps/${appName} --bundler=webpack --compiler=swc --no-interactive` ); updateFile(`apps/${appName}/src/app/app.element.ts`, (content) => { @@ -223,7 +223,7 @@ describe('Web Components Applications', () => { const appName = uniq('app1'); runCLI( - `generate @nx/web:app ${appName} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` + `generate @nx/web:app ${appName} --bundler=webpack --no-interactive` ); // check files are generated without the layout directory ("apps/") and @@ -285,7 +285,7 @@ describe('CLI - Environment Variables', () => { `; runCLI( - `generate @nx/web:app ${appName} --directory=apps/${appName} --bundler=webpack --no-interactive --compiler=babel` + `generate @nx/web:app apps/${appName} --bundler=webpack --no-interactive --compiler=babel` ); const content = readFile(main); @@ -310,7 +310,7 @@ describe('CLI - Environment Variables', () => { const newCode2 = `const envVars = [process.env.NODE_ENV, process.env.NX_PUBLIC_WS_BASE, process.env.NX_PUBLIC_WS_ENV_LOCAL, process.env.NX_PUBLIC_WS_LOCAL_ENV, process.env.NX_PUBLIC_APP_BASE, process.env.NX_PUBLIC_APP_ENV_LOCAL, process.env.NX_PUBLIC_APP_LOCAL_ENV, process.env.NX_PUBLIC_SHARED_ENV];`; runCLI( - `generate @nx/web:app ${appName2} --directory=apps/${appName2} --bundler=webpack --no-interactive --compiler=babel` + `generate @nx/web:app apps/${appName2} --bundler=webpack --no-interactive --compiler=babel` ); const content2 = readFile(main2); @@ -351,7 +351,7 @@ describe('index.html interpolation', () => { const appName = uniq('app'); runCLI( - `generate @nx/web:app ${appName} --bundler=webpack --directory=apps/${appName} --no-interactive` + `generate @nx/web:app apps/${appName} --bundler=webpack --no-interactive` ); const srcPath = `apps/${appName}/src`; diff --git a/e2e/webpack/src/webpack.legacy.test.ts b/e2e/webpack/src/webpack.legacy.test.ts index a96f5c87edeba..f1e5b9b63701c 100644 --- a/e2e/webpack/src/webpack.legacy.test.ts +++ b/e2e/webpack/src/webpack.legacy.test.ts @@ -22,7 +22,6 @@ describe('Webpack Plugin (legacy)', () => { process.env.NX_ADD_PLUGINS = 'false'; newProject({ packages: ['@nx/react'], - unsetProjectNameAndRootFormat: false, }); runCLI( `generate @nx/react:app ${appName} --bundler webpack --e2eTestRunner=cypress --rootProject --no-interactive` @@ -154,7 +153,7 @@ describe('Webpack Plugin (legacy)', () => { it('should convert withNx webpack config to a standard config using NxWebpackPlugin', () => { const appName = 'app3224373'; // Needs to be reserved so that the snapshot projectName matches runCLI( - `generate @nx/web:app ${appName} --bundler webpack --e2eTestRunner=playwright --projectNameAndRootFormat=as-provided` + `generate @nx/web:app ${appName} --bundler webpack --e2eTestRunner=playwright` ); updateFile( `${appName}/src/main.ts`, diff --git a/e2e/webpack/src/webpack.test.ts b/e2e/webpack/src/webpack.test.ts index de70314cc9d5d..b57164a5321d3 100644 --- a/e2e/webpack/src/webpack.test.ts +++ b/e2e/webpack/src/webpack.test.ts @@ -137,7 +137,7 @@ describe('Webpack Plugin', () => { it('should be able to build with NxWebpackPlugin and a standard webpack config file', () => { const appName = uniq('app'); runCLI( - `generate @nx/web:app ${appName} --bundler webpack --directory=apps/${appName} --projectNameAndRootFormat=as-provided` + `generate @nx/web:app ${appName} --bundler webpack --directory=apps/${appName}` ); updateFile(`apps/${appName}/src/main.ts`, `console.log('Hello');\n`); updateFile(`apps/${appName}/src/foo.ts`, `console.log('Foo');\n`); diff --git a/e2e/workspace-create/src/create-nx-workspace-npm.test.ts b/e2e/workspace-create/src/create-nx-workspace-npm.test.ts index 5343b5ebffea9..1bd60c0fa7069 100644 --- a/e2e/workspace-create/src/create-nx-workspace-npm.test.ts +++ b/e2e/workspace-create/src/create-nx-workspace-npm.test.ts @@ -53,9 +53,7 @@ describe('create-nx-workspace --preset=npm', () => { const appName = uniq('my-app'); expect(() => { - runCLI( - `generate @nx/angular:app packages/${appName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:app packages/${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }, 1_000_000); @@ -65,9 +63,7 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI( - `generate @nx/angular:lib packages/${libName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/angular:lib packages/${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -82,9 +78,7 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => - runCLI( - `generate @nx/js:library packages/${libName} --projectNameAndRootFormat as-provided --no-interactive` - ) + runCLI(`generate @nx/js:library packages/${libName} --no-interactive`) ).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -99,9 +93,7 @@ describe('create-nx-workspace --preset=npm', () => { const appName = uniq('my-app'); expect(() => - runCLI( - `generate @nx/web:app packages/${appName} --projectNameAndRootFormat as-provided --no-interactive` - ) + runCLI(`generate @nx/web:app packages/${appName} --no-interactive`) ).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); @@ -112,9 +104,7 @@ describe('create-nx-workspace --preset=npm', () => { const appName = uniq('my-app'); expect(() => { - runCLI( - `generate @nx/react:app packages/${appName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/react:app packages/${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); @@ -125,9 +115,7 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI( - `generate @nx/react:lib packages/${libName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/react:lib packages/${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -142,9 +130,7 @@ describe('create-nx-workspace --preset=npm', () => { const appName = uniq('my-app'); expect(() => { - runCLI( - `generate @nx/next:app packages/${appName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/next:app packages/${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); @@ -155,9 +141,7 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI( - `generate @nx/next:lib packages/${libName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/next:lib packages/${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -174,7 +158,7 @@ describe('create-nx-workspace --preset=npm', () => { expect(() => { runCLI( - `generate @nx/react-native:app packages/${appName} --install=false --projectNameAndRootFormat as-provided --no-interactive` + `generate @nx/react-native:app packages/${appName} --install=false --no-interactive` ); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); @@ -187,7 +171,7 @@ describe('create-nx-workspace --preset=npm', () => { expect(() => { runCLI( - `generate @nx/react-native:lib packages/${libName} --projectNameAndRootFormat as-provided --no-interactive` + `generate @nx/react-native:lib packages/${libName} --no-interactive` ); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); @@ -203,9 +187,7 @@ describe('create-nx-workspace --preset=npm', () => { const appName = uniq('my-app'); expect(() => { - runCLI( - `generate @nx/node:app packages/${appName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/node:app packages/${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); @@ -216,9 +198,7 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI( - `generate @nx/node:lib packages/${libName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/node:lib packages/${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -233,9 +213,7 @@ describe('create-nx-workspace --preset=npm', () => { const appName = uniq('my-app'); expect(() => { - runCLI( - `generate @nx/nest:app packages/${appName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/nest:app packages/${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); @@ -246,9 +224,7 @@ describe('create-nx-workspace --preset=npm', () => { const libName = uniq('lib'); expect(() => { - runCLI( - `generate @nx/nest:lib packages/${libName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/nest:lib packages/${libName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); const tsconfig = readJson(`tsconfig.base.json`); @@ -263,9 +239,7 @@ describe('create-nx-workspace --preset=npm', () => { const appName = uniq('my-app'); expect(() => { - runCLI( - `generate @nx/express:app packages/${appName} --projectNameAndRootFormat as-provided --no-interactive` - ); + runCLI(`generate @nx/express:app packages/${appName} --no-interactive`); }).not.toThrowError(); checkFilesExist('tsconfig.base.json'); }); diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index d4a1adff29c71..47720e3a74d43 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -265,14 +265,13 @@ describe('app', () => { describe('nested', () => { it('should create project configs', async () => { - await generateApp(appTree, 'my-app', { directory: 'my-dir/my-app' }); + await generateApp(appTree, 'my-dir/my-app'); expect(readProjectConfiguration(appTree, 'my-app')).toMatchSnapshot(); expect(readProjectConfiguration(appTree, 'my-app-e2e')).toMatchSnapshot(); }); it('should update tags + implicit dependencies', async () => { - await generateApp(appTree, 'my-app', { - directory: 'my-dir/my-app', + await generateApp(appTree, 'my-dir/my-app', { tags: 'one,two,my-app', }); const projects = devkit.getProjects(appTree); @@ -297,7 +296,7 @@ describe('app', () => { expect(lookupFn(content)).toEqual(expectedValue); }; - await generateApp(appTree, 'my-app', { directory: 'my-dir/my-app' }); + await generateApp(appTree, 'my-dir/my-app'); const appModulePath = 'my-dir/my-app/src/app/app.module.ts'; expect(appTree.read(appModulePath, 'utf-8')).toContain('class AppModule'); @@ -339,7 +338,7 @@ describe('app', () => { it('should extend from tsconfig.base.json', async () => { // ACT - await generateApp(appTree, 'app', { directory: 'my-dir/app' }); + await generateApp(appTree, 'my-dir/app'); // ASSERT const appTsConfig = readJson(appTree, 'my-dir/app/tsconfig.json'); @@ -351,7 +350,7 @@ describe('app', () => { appTree.rename('tsconfig.base.json', 'tsconfig.json'); // ACT - await generateApp(appTree, 'app', { directory: 'my-dir/app' }); + await generateApp(appTree, 'my-dir/app'); // ASSERT const appTsConfig = readJson(appTree, 'my-dir/app/tsconfig.json'); @@ -370,9 +369,7 @@ describe('app', () => { it('should accept numbers in the path', async () => { // ACT - await generateApp(appTree, 'my-app', { - directory: 'src/9-websites/my-app', - }); + await generateApp(appTree, 'src/9-websites/my-app'); // ASSERT @@ -387,7 +384,7 @@ describe('app', () => { expect(lookupFn(content)).toEqual(expectedValue); }; - await generateApp(appTree, 'my-app', { directory: 'my-dir/my-app' }); + await generateApp(appTree, 'my-dir/my-app'); const appModulePath = 'my-dir/my-app/src/app/app.module.ts'; expect(appTree.read(appModulePath, 'utf-8')).toContain('class AppModule'); @@ -428,7 +425,7 @@ describe('app', () => { }); it('should set esModuleInterop when using the application builder', async () => { - await generateApp(appTree, 'my-app', { rootProject: true }); + await generateApp(appTree, '.', { name: 'my-app' }); expect( readJson(appTree, 'tsconfig.json').compilerOptions.esModuleInterop @@ -436,8 +433,8 @@ describe('app', () => { }); it('should not set esModuleInterop when using the browser builder', async () => { - await generateApp(appTree, 'my-app', { - rootProject: true, + await generateApp(appTree, '.', { + name: 'my-app', bundler: 'webpack', }); @@ -449,8 +446,8 @@ describe('app', () => { describe('routing', () => { it('should include RouterModule', async () => { - await generateApp(appTree, 'myApp', { - directory: 'my-dir/my-app', + await generateApp(appTree, 'my-dir/my-app', { + name: 'myApp', }); expect( appTree.read('my-dir/my-app/src/app/app.module.ts', 'utf-8') @@ -461,8 +458,8 @@ describe('app', () => { }); it('should not modify tests when --skip-tests is set', async () => { - await generateApp(appTree, 'myApp', { - directory: 'my-dir/my-app', + await generateApp(appTree, 'mydir/my-app', { + name: 'myApp', skipTests: true, }); expect( @@ -473,15 +470,14 @@ describe('app', () => { describe('template generation mode', () => { it('should create Nx specific `app.component.html` template', async () => { - await generateApp(appTree, 'my-app', { directory: 'my-dir/my-app' }); + await generateApp(appTree, 'my-dir/my-app'); expect( appTree.read('my-dir/my-app/src/app/app.component.html', 'utf-8') ).toContain(''); }); it("should update `template`'s property of AppComponent with Nx content", async () => { - await generateApp(appTree, 'my-app', { - directory: 'my-dir/my-app', + await generateApp(appTree, 'my-dir/my-app', { inlineTemplate: true, }); expect( @@ -490,15 +486,14 @@ describe('app', () => { }); it('should create Nx specific `nx-welcome.component.ts` file', async () => { - await generateApp(appTree, 'my-app', { directory: 'my-dir/my-app' }); + await generateApp(appTree, 'my-dir/my-app'); expect( appTree.read('my-dir/my-app/src/app/nx-welcome.component.ts', 'utf-8') ).toContain('Hello there'); }); it('should update the AppComponent spec to target Nx content', async () => { - await generateApp(appTree, 'my-app', { - directory: 'my-dir/my-app', + await generateApp(appTree, 'my-dir/my-app', { inlineTemplate: true, }); const testFileContent = appTree.read( @@ -956,10 +951,10 @@ describe('app', () => { `); }); - describe('--root-project', () => { + describe('--directory="." (--root-project)', () => { it('should create files at the root', async () => { - await generateApp(appTree, 'my-app', { - rootProject: true, + await generateApp(appTree, '.', { + name: 'my-app', }); expect(appTree.exists('src/main.ts')).toBe(true); @@ -972,9 +967,9 @@ describe('app', () => { }); it('should generate playwright with root project', async () => { - await generateApp(appTree, 'root-app', { + await generateApp(appTree, '.', { e2eTestRunner: E2eTestRunner.Playwright, - rootProject: true, + name: 'root-app', }); expect(appTree.exists('e2e/playwright.config.ts')).toBeTruthy(); expect(appTree.exists('e2e/src/example.spec.ts')).toBeTruthy(); @@ -1279,7 +1274,7 @@ describe('app', () => { dependencies: { ...json.dependencies, '@angular/core': '~17.0.0' }, })); - await generateApp(appTree, 'my-app', { rootProject: true }); + await generateApp(appTree, '.', { name: 'my-app' }); const project = readProjectConfiguration(appTree, 'my-app'); expect(project.targets.build.options.assets).toStrictEqual([ @@ -1296,7 +1291,7 @@ async function generateApp( options: Partial = {} ) { await generateTestApplication(appTree, { - name, + directory: name, skipFormat: true, e2eTestRunner: E2eTestRunner.Cypress, unitTestRunner: UnitTestRunner.Jest, diff --git a/packages/angular/src/generators/application/lib/normalize-options.ts b/packages/angular/src/generators/application/lib/normalize-options.ts index ed4d2bfdb0a44..2fc11b4cb03ac 100644 --- a/packages/angular/src/generators/application/lib/normalize-options.ts +++ b/packages/angular/src/generators/application/lib/normalize-options.ts @@ -1,5 +1,8 @@ import { joinPathFragments, readNxJson, type Tree } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Linter } from '@nx/eslint'; import { E2eTestRunner, UnitTestRunner } from '../../../utils/test-runners'; import type { Schema } from '../schema'; @@ -10,21 +13,15 @@ export async function normalizeOptions( host: Tree, options: Partial ): Promise { - const { - projectName: appProjectName, - projectRoot: appProjectRoot, - projectNameAndRootFormat, - } = await determineProjectNameAndRootOptions(host, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - rootProject: options.rootProject, - }); + await ensureProjectName(host, options as Schema, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(host, { + name: options.name, + projectType: 'application', + directory: options.directory, + rootProject: options.rootProject, + }); options.rootProject = appProjectRoot === '.'; - options.projectNameAndRootFormat = projectNameAndRootFormat; - - const nxJson = readNxJson(host); const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`; const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`; @@ -52,6 +49,7 @@ export async function normalizeOptions( linter: Linter.EsLint, strict: true, standalone: true, + directory: appProjectRoot, ...options, prefix: options.prefix || 'app', name: appProjectName, diff --git a/packages/angular/src/generators/application/schema.d.ts b/packages/angular/src/generators/application/schema.d.ts index ad14d65145275..855f9e718f014 100644 --- a/packages/angular/src/generators/application/schema.d.ts +++ b/packages/angular/src/generators/application/schema.d.ts @@ -1,10 +1,10 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners'; import type { Styles } from '../utils/types'; export interface Schema { - name: string; + directory: string; + name?: string; addTailwind?: boolean; skipFormat?: boolean; inlineStyle?: boolean; @@ -14,8 +14,6 @@ export interface Schema { prefix?: string; style?: Styles; skipTests?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; linter?: Linter | LinterType; unitTestRunner?: UnitTestRunner; diff --git a/packages/angular/src/generators/application/schema.json b/packages/angular/src/generators/application/schema.json index fcc25a34e7e6d..ec1dce93c52b2 100644 --- a/packages/angular/src/generators/application/schema.json +++ b/packages/angular/src/generators/application/schema.json @@ -6,26 +6,21 @@ "type": "object", "cli": "nx", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { + "description": "The name of the application.", "type": "string", + "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -187,6 +182,6 @@ } }, "additionalProperties": false, - "required": ["name"], + "required": ["directory"], "examplesFile": "../../../docs/application-examples.md" } diff --git a/packages/angular/src/generators/component-story/component-story.spec.ts b/packages/angular/src/generators/component-story/component-story.spec.ts index c0d919885fe20..899a0030e1aeb 100644 --- a/packages/angular/src/generators/component-story/component-story.spec.ts +++ b/packages/angular/src/generators/component-story/component-story.spec.ts @@ -16,7 +16,7 @@ describe('componentStory generator', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestLibrary(tree, { name: libName, skipFormat: true }); + await generateTestLibrary(tree, { directory: libName, skipFormat: true }); await componentGenerator(tree, { name: 'test-button', path: `${libName}/src/lib/test-button`, diff --git a/packages/angular/src/generators/component-test/component-test.spec.ts b/packages/angular/src/generators/component-test/component-test.spec.ts index 295ebf3de23e1..1de44cccdb6bc 100644 --- a/packages/angular/src/generators/component-test/component-test.spec.ts +++ b/packages/angular/src/generators/component-test/component-test.spec.ts @@ -25,7 +25,7 @@ describe('Angular Cypress Component Test Generator', () => { it('should handle component w/o inputs', async () => { await generateTestLibrary(tree, { - name: 'my-lib', + directory: 'my-lib', unitTestRunner: UnitTestRunner.None, linter: Linter.None, skipFormat: true, @@ -49,7 +49,7 @@ describe('Angular Cypress Component Test Generator', () => { it('should generate a component test', async () => { await generateTestLibrary(tree, { - name: 'my-lib', + directory: 'my-lib', unitTestRunner: UnitTestRunner.None, linter: Linter.None, skipFormat: true, @@ -103,7 +103,7 @@ export class MyLibComponent implements OnInit { it('should work with standalone components', async () => { await generateTestLibrary(tree, { - name: 'my-lib', + directory: 'my-lib', unitTestRunner: UnitTestRunner.None, linter: Linter.None, skipFormat: true, @@ -156,7 +156,7 @@ export class MyLibComponent implements OnInit { it('should not overwrite an existing component test', async () => { await generateTestLibrary(tree, { - name: 'my-lib', + directory: 'my-lib', unitTestRunner: UnitTestRunner.None, linter: Linter.None, skipFormat: true, @@ -187,7 +187,7 @@ export class MyLibComponent implements OnInit { it('should be idempotent', async () => { await generateTestLibrary(tree, { - name: 'my-lib', + directory: 'my-lib', unitTestRunner: UnitTestRunner.None, linter: Linter.None, skipFormat: true, 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 2faf6d0b184dd..494bb2710415c 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 @@ -55,11 +55,11 @@ describe('Cypress Component Testing Configuration', () => { describe('updateProjectConfig', () => { it('should add project config with --target=:', async () => { await generateTestApplication(tree, { - name: 'fancy-app', + directory: 'fancy-app', skipFormat: true, }); await generateTestLibrary(tree, { - name: 'fancy-lib', + directory: 'fancy-lib', skipFormat: true, }); await componentGenerator(tree, { @@ -121,11 +121,11 @@ describe('Cypress Component Testing Configuration', () => { it('should add project config with --target=::', async () => { await generateTestApplication(tree, { - name: 'fancy-app', + directory: 'fancy-app', skipFormat: true, }); await generateTestLibrary(tree, { - name: 'fancy-lib', + directory: 'fancy-lib', skipFormat: true, }); await componentGenerator(tree, { @@ -187,11 +187,11 @@ describe('Cypress Component Testing Configuration', () => { it('should not throw with invalid --build-target', async () => { await generateTestApplication(tree, { - name: 'fancy-app', + directory: 'fancy-app', skipFormat: true, }); await generateTestLibrary(tree, { - name: 'fancy-lib', + directory: 'fancy-lib', skipFormat: true, }); await componentGenerator(tree, { @@ -246,7 +246,7 @@ describe('Cypress Component Testing Configuration', () => { it('should use own project config', async () => { await generateTestApplication(tree, { - name: 'fancy-app', + directory: 'fancy-app', bundler: 'webpack', skipFormat: true, }); @@ -290,12 +290,12 @@ describe('Cypress Component Testing Configuration', () => { it('should use the project graph to find the correct project config', async () => { await generateTestApplication(tree, { - name: 'fancy-app', + directory: 'fancy-app', bundler: 'webpack', skipFormat: true, }); await generateTestLibrary(tree, { - name: 'fancy-lib', + directory: 'fancy-lib', skipFormat: true, }); await componentGenerator(tree, { @@ -358,7 +358,7 @@ describe('Cypress Component Testing Configuration', () => { it('should setup angular specific configs', async () => { await generateTestLibrary(tree, { - name: 'my-lib', + directory: 'my-lib', skipFormat: true, }); await setup(tree, { @@ -418,7 +418,7 @@ describe('Cypress Component Testing Configuration', () => { it('should exclude Cypress-related files from tsconfig.editor.json for applications', async () => { await generateTestApplication(tree, { - name: 'fancy-app', + directory: 'fancy-app', bundler: 'webpack', skipFormat: true, }); @@ -462,7 +462,7 @@ describe('Cypress Component Testing Configuration', () => { it('should work with simple components', async () => { await generateTestLibrary(tree, { - name: 'my-lib', + directory: 'my-lib', skipFormat: true, }); await setup(tree, { @@ -516,7 +516,7 @@ describe('Cypress Component Testing Configuration', () => { it('should work with standalone component', async () => { await generateTestLibrary(tree, { - name: 'my-lib-standalone', + directory: 'my-lib-standalone', skipFormat: true, }); await setup(tree, { @@ -569,7 +569,7 @@ describe('Cypress Component Testing Configuration', () => { it('should work with complex component', async () => { await generateTestLibrary(tree, { - name: 'with-inputs-cmp', + directory: 'with-inputs-cmp', skipFormat: true, }); await setup(tree, { @@ -625,7 +625,7 @@ describe('Cypress Component Testing Configuration', () => { it('should work with complex standalone component', async () => { await generateTestLibrary(tree, { - name: 'with-inputs-standalone-cmp', + directory: 'with-inputs-standalone-cmp', skipFormat: true, }); await setup(tree, { @@ -680,11 +680,11 @@ describe('Cypress Component Testing Configuration', () => { it('should work with secondary entry point libs', async () => { await generateTestApplication(tree, { - name: 'my-cool-app', + directory: 'my-cool-app', skipFormat: true, }); await generateTestLibrary(tree, { - name: 'secondary', + directory: 'secondary', buildable: true, skipFormat: true, }); @@ -747,7 +747,7 @@ describe('Cypress Component Testing Configuration', () => { it('should not overwrite existing component test', async () => { await generateTestLibrary(tree, { - name: 'cool-lib', + directory: 'cool-lib', flat: true, skipFormat: true, }); @@ -809,7 +809,7 @@ describe('Cypress Component Testing Configuration', () => { // TODO: should we support this? it.skip('should handle multiple components per file', async () => { await generateTestLibrary(tree, { - name: 'multiple-components', + directory: 'multiple-components', flat: true, skipFormat: true, }); @@ -898,7 +898,7 @@ async function setup( } ) { await generateTestApplication(tree, { - name: options.name, + directory: options.name, standalone: options.standalone, skipFormat: true, }); diff --git a/packages/angular/src/generators/federate-module/federate-module.spec.ts b/packages/angular/src/generators/federate-module/federate-module.spec.ts index 4ad9dcfcb0eea..7797000d39884 100644 --- a/packages/angular/src/generators/federate-module/federate-module.spec.ts +++ b/packages/angular/src/generators/federate-module/federate-module.spec.ts @@ -54,6 +54,7 @@ describe('federate-module', () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); let remoteSchema: remoteSchma = { name: 'my-remote', + directory: 'my-remote', e2eTestRunner: E2eTestRunner.Cypress, skipFormat: true, linter: Linter.EsLint, diff --git a/packages/angular/src/generators/federate-module/lib/add-remote.ts b/packages/angular/src/generators/federate-module/lib/add-remote.ts index a5cbab3bc2917..17164bf5a32bf 100644 --- a/packages/angular/src/generators/federate-module/lib/add-remote.ts +++ b/packages/angular/src/generators/federate-module/lib/add-remote.ts @@ -17,7 +17,6 @@ export async function addRemote(tree: Tree, schema: Schema) { directory: schema.remoteDirectory, host: schema.host, standalone: schema.standalone, - projectNameAndRootFormat: schema.projectNameAndRootFormat, unitTestRunner: schema.unitTestRunner ?? UnitTestRunner.Jest, e2eTestRunner: schema.e2eTestRunner ?? E2eTestRunner.Cypress, skipFormat: true, @@ -29,7 +28,6 @@ export async function addRemote(tree: Tree, schema: Schema) { name: schema.remote, directory: schema.remoteDirectory, projectType: 'application', - projectNameAndRootFormat: schema.projectNameAndRootFormat, }); projectRoot = remoteRoot; diff --git a/packages/angular/src/generators/federate-module/schema.d.ts b/packages/angular/src/generators/federate-module/schema.d.ts index 3a60ea70eba4a..fcd19cc8dcf22 100644 --- a/packages/angular/src/generators/federate-module/schema.d.ts +++ b/packages/angular/src/generators/federate-module/schema.d.ts @@ -1,4 +1,3 @@ -import { type ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { UnitTestRunner, E2eTestRunner } from '../utils/testing'; export interface Schema { @@ -7,7 +6,6 @@ export interface Schema { remote: string; remoteDirectory?: string; host?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; unitTestRunner?: UnitTestRunner; e2eTestRunner?: E2eTestRunner; standalone?: boolean; diff --git a/packages/angular/src/generators/federate-module/schema.json b/packages/angular/src/generators/federate-module/schema.json index a9807819c7923..8abbcde9663c7 100644 --- a/packages/angular/src/generators/federate-module/schema.json +++ b/packages/angular/src/generators/federate-module/schema.json @@ -37,11 +37,6 @@ "description": "The directory of the new remote application if one needs to be created.", "type": "string" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files for the remote if one needs to be created.", "type": "string", diff --git a/packages/angular/src/generators/host/host.spec.ts b/packages/angular/src/generators/host/host.spec.ts index 936368a23f275..4425f4ef8305e 100644 --- a/packages/angular/src/generators/host/host.spec.ts +++ b/packages/angular/src/generators/host/host.spec.ts @@ -20,7 +20,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', typescriptConfiguration: false, standalone: false, skipFormat: true, @@ -35,7 +35,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', typescriptConfiguration: true, standalone: false, skipFormat: true, @@ -50,7 +50,7 @@ describe('Host App Generator', () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestRemoteApplication(tree, { - name: 'remote', + directory: 'remote', typescriptConfiguration: false, standalone: false, skipFormat: true, @@ -58,7 +58,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', remotes: ['remote'], typescriptConfiguration: false, standalone: false, @@ -74,7 +74,7 @@ describe('Host App Generator', () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestRemoteApplication(tree, { - name: 'remote', + directory: 'remote', typescriptConfiguration: true, standalone: false, skipFormat: true, @@ -82,7 +82,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', remotes: ['remote'], typescriptConfiguration: true, standalone: false, @@ -101,7 +101,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'host-app', + directory: 'host-app', remotes: ['remote1', 'remote2'], typescriptConfiguration: false, standalone: false, @@ -133,7 +133,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'host-app', + directory: 'host-app', remotes: ['remote1', 'remote2'], typescriptConfiguration: true, standalone: false, @@ -162,7 +162,7 @@ describe('Host App Generator', () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestRemoteApplication(tree, { - name: 'remote1', + directory: 'remote1', typescriptConfiguration: false, standalone: false, skipFormat: true, @@ -170,7 +170,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'host-app', + directory: 'host-app', remotes: ['remote1', 'remote2', 'remote3'], typescriptConfiguration: false, standalone: false, @@ -190,7 +190,7 @@ describe('Host App Generator', () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestRemoteApplication(tree, { - name: 'remote1', + directory: 'remote1', typescriptConfiguration: true, standalone: false, skipFormat: true, @@ -198,7 +198,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'host-app', + directory: 'host-app', remotes: ['remote1', 'remote2', 'remote3'], typescriptConfiguration: true, standalone: false, @@ -218,7 +218,7 @@ describe('Host App Generator', () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestRemoteApplication(tree, { - name: 'remote1', + directory: 'remote1', typescriptConfiguration: false, standalone: false, skipFormat: true, @@ -226,7 +226,6 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'host-app', directory: 'foo/host-app', remotes: ['remote1', 'remote2', 'remote3'], typescriptConfiguration: false, @@ -247,7 +246,7 @@ describe('Host App Generator', () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestRemoteApplication(tree, { - name: 'remote1', + directory: 'remote1', typescriptConfiguration: true, standalone: false, skipFormat: true, @@ -255,7 +254,6 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'host-app', directory: 'foo/host-app', remotes: ['remote1', 'remote2', 'remote3'], typescriptConfiguration: true, @@ -278,7 +276,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'host', + directory: 'host', remotes: ['remote1'], skipFormat: true, }); @@ -297,7 +295,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'host', + directory: 'host', remotes: ['remote1'], skipFormat: true, }); @@ -314,7 +312,6 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'dashboard', remotes: ['remote1'], directory: 'test/dashboard', skipFormat: true, @@ -332,7 +329,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'dashboard', + directory: 'dashboard', remotes: ['remote1'], e2eTestRunner: E2eTestRunner.None, standalone: false, @@ -352,7 +349,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', ssr: true, typescriptConfiguration: false, standalone: false, @@ -388,7 +385,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', ssr: true, typescriptConfiguration: true, standalone: false, @@ -425,7 +422,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', ssr: true, typescriptConfiguration: false, }); @@ -464,7 +461,7 @@ describe('Host App Generator', () => { // ACT await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', ssr: true, typescriptConfiguration: true, skipFormat: true, @@ -509,7 +506,7 @@ describe('Host App Generator', () => { })); await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', ssr: true, skipFormat: true, }); @@ -527,7 +524,7 @@ describe('Host App Generator', () => { })); await generateTestHostApplication(tree, { - name: 'host', + directory: 'host', remotes: ['remote1'], skipFormat: true, }); @@ -551,7 +548,7 @@ describe('Host App Generator', () => { }); await generateTestHostApplication(tree, { - name: 'test', + directory: 'test', ssr: true, skipFormat: true, skipPackageJson: true, @@ -567,10 +564,9 @@ describe('Host App Generator', () => { await expect( generateTestHostApplication(tree, { - name: 'myhostapp', + directory: 'myhostapp', remotes: [remote], dynamic: true, - projectNameAndRootFormat: 'as-provided', e2eTestRunner: E2eTestRunner.None, linter: Linter.None, style: 'css', diff --git a/packages/angular/src/generators/host/host.ts b/packages/angular/src/generators/host/host.ts index c3ac97da4afde..c181eea3f1a54 100644 --- a/packages/angular/src/generators/host/host.ts +++ b/packages/angular/src/generators/host/host.ts @@ -5,7 +5,10 @@ import { runTasksInSerial, Tree, } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { E2eTestRunner } from '../../utils/test-runners'; import applicationGenerator from '../application/application'; import remoteGenerator from '../remote/remote'; @@ -47,17 +50,13 @@ export async function host(tree: Tree, schema: Schema) { }); } - const { - projectName: hostProjectName, - projectNameAndRootFormat, - projectRoot: appRoot, - } = await determineProjectNameAndRootOptions(tree, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - }); - options.projectNameAndRootFormat = projectNameAndRootFormat; + await ensureProjectName(tree, options, 'application'); + const { projectName: hostProjectName, projectRoot: appRoot } = + await determineProjectNameAndRootOptions(tree, { + name: options.name, + projectType: 'application', + directory: options.directory, + }); const appInstallTask = await applicationGenerator(tree, { ...options, diff --git a/packages/angular/src/generators/host/schema.d.ts b/packages/angular/src/generators/host/schema.d.ts index 402f3af46d507..7269786bed725 100644 --- a/packages/angular/src/generators/host/schema.d.ts +++ b/packages/angular/src/generators/host/schema.d.ts @@ -1,10 +1,10 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners'; import type { Styles } from '../utils/types'; export interface Schema { - name: string; + directory: string; + name?: string; remotes?: string[]; dynamic?: boolean; setParserOptionsProject?: boolean; @@ -14,8 +14,6 @@ export interface Schema { prefix?: string; style?: Styles; skipTests?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; linter?: Linter | LinterType; unitTestRunner?: UnitTestRunner; diff --git a/packages/angular/src/generators/host/schema.json b/packages/angular/src/generators/host/schema.json index 9e23a200ecfbf..8320fc13ca42a 100644 --- a/packages/angular/src/generators/host/schema.json +++ b/packages/angular/src/generators/host/schema.json @@ -12,14 +12,20 @@ } ], "properties": { - "name": { + "directory": { + "description": "The directory of the new application.", "type": "string", - "description": "The name to give to the host Angular application.", "$default": { "$source": "argv", "index": 0 }, - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" + }, + "name": { + "type": "string", + "description": "The name to give to the host Angular application.", + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "remotes": { "type": "array", @@ -31,15 +37,6 @@ "description": "Should the host application use dynamic federation?", "default": false }, - "directory": { - "description": "The directory of the new application.", - "type": "string" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -181,5 +178,5 @@ } }, "additionalProperties": false, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/angular/src/generators/library/lib/normalize-options.ts b/packages/angular/src/generators/library/lib/normalize-options.ts index e5b71079b7980..73096691429d2 100644 --- a/packages/angular/src/generators/library/lib/normalize-options.ts +++ b/packages/angular/src/generators/library/lib/normalize-options.ts @@ -1,5 +1,8 @@ import { names, Tree } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Linter } from '@nx/eslint'; import { UnitTestRunner } from '../../../utils/test-runners'; import { Schema } from '../schema'; @@ -26,6 +29,7 @@ export async function normalizeOptions( ...schema, }; + await ensureProjectName(host, options, 'library'); const { projectName, names: projectNames, @@ -36,7 +40,6 @@ export async function normalizeOptions( projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); const fileName = options.simpleName diff --git a/packages/angular/src/generators/library/lib/normalized-schema.ts b/packages/angular/src/generators/library/lib/normalized-schema.ts index 7cce213ec03c3..706be2c9c4315 100644 --- a/packages/angular/src/generators/library/lib/normalized-schema.ts +++ b/packages/angular/src/generators/library/lib/normalized-schema.ts @@ -3,12 +3,12 @@ import type { Linter, LinterType } from '@nx/eslint'; export interface NormalizedSchema { libraryOptions: { - name: string; + directory: string; + name?: string; addTailwind?: boolean; skipFormat?: boolean; simpleName?: boolean; addModuleSpec?: boolean; - directory?: string; sourceDir?: string; buildable?: boolean; publishable?: boolean; diff --git a/packages/angular/src/generators/library/library.spec.ts b/packages/angular/src/generators/library/library.spec.ts index ba024058bfce3..e5f2def48f33f 100644 --- a/packages/angular/src/generators/library/library.spec.ts +++ b/packages/angular/src/generators/library/library.spec.ts @@ -37,7 +37,7 @@ describe('lib', () => { async function runLibraryGeneratorWithOpts(opts: Partial = {}) { await generateTestLibrary(tree, { - name: 'my-lib', + directory: 'my-lib', publishable: false, buildable: false, linter: Linter.EsLint, @@ -62,7 +62,10 @@ describe('lib', () => { it('should run the library generator without erroring if the directory has a trailing slash', async () => { // ACT & ASSERT await expect( - runLibraryGeneratorWithOpts({ directory: 'mylib/shared/' }) + runLibraryGeneratorWithOpts({ + directory: 'mylib/shared/', + name: 'my-lib', + }) ).resolves.not.toThrow(); }); @@ -421,7 +424,7 @@ describe('lib', () => { it('should generate files', async () => { // ACT await runLibraryGeneratorWithOpts(); - await runLibraryGeneratorWithOpts({ name: 'my-lib2' }); + await runLibraryGeneratorWithOpts({ directory: 'my-lib2' }); // ASSERT expect(tree.exists(`my-lib/jest.config.ts`)).toBeTruthy(); @@ -1128,7 +1131,7 @@ describe('lib', () => { // ACT & ASSERT await expect( runLibraryGeneratorWithOpts({ - name: 'my-lib2', + directory: 'my-lib2', publishable: true, importPath: '@myorg/lib', }) @@ -1594,7 +1597,7 @@ describe('lib', () => { it('should generate a library with a standalone component as entry point with routing setup and attach it to parent module as direct child', async () => { // ARRANGE await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', routing: true, skipFormat: true, }); @@ -1619,7 +1622,7 @@ describe('lib', () => { it('should generate a library with a standalone component as entry point with routing setup and attach it to parent module as a lazy child', async () => { // ARRANGE await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', routing: true, skipFormat: true, }); @@ -1645,7 +1648,7 @@ describe('lib', () => { it('should generate a library with a standalone component as entry point with routing setup and attach it to standalone parent module as direct child', async () => { // ARRANGE await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', routing: true, standalone: true, skipFormat: true, @@ -1673,7 +1676,7 @@ describe('lib', () => { it('should generate a library with a standalone component as entry point with routing setup and attach it to standalone parent module as a lazy child', async () => { // ARRANGE await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', routing: true, standalone: true, skipFormat: true, @@ -1707,7 +1710,7 @@ describe('lib', () => { // ACT await runLibraryGeneratorWithOpts({ - name: 'second', + directory: 'second', standalone: true, routing: true, parent: 'my-lib/src/lib/lib.routes.ts', @@ -1728,7 +1731,7 @@ describe('lib', () => { // ACT await runLibraryGeneratorWithOpts({ - name: 'second', + directory: 'second', standalone: true, routing: true, lazy: true, diff --git a/packages/angular/src/generators/library/schema.d.ts b/packages/angular/src/generators/library/schema.d.ts index 042ccda988a79..5b75bcefda355 100644 --- a/packages/angular/src/generators/library/schema.d.ts +++ b/packages/angular/src/generators/library/schema.d.ts @@ -1,15 +1,13 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { UnitTestRunner } from '../../utils/test-runners'; export interface Schema { - name: string; + directory: string; + name?: string; addTailwind?: boolean; skipFormat?: boolean; simpleName?: boolean; addModuleSpec?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; sourceDir?: string; buildable?: boolean; publishable?: boolean; diff --git a/packages/angular/src/generators/library/schema.json b/packages/angular/src/generators/library/schema.json index a3f47f1b03573..ab24380e60dc9 100644 --- a/packages/angular/src/generators/library/schema.json +++ b/packages/angular/src/generators/library/schema.json @@ -9,22 +9,16 @@ "name": { "type": "string", "description": "The name of the library.", - "$default": { - "$source": "argv", - "index": 0 - }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" + "x-priority": "important" }, "directory": { "type": "string", "description": "A directory where the library is placed.", - "x-priority": "important" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] + "$default": { + "$source": "argv", + "index": 0 + }, + "x-prompt": "Which directory do you want to create the library in?" }, "publishable": { "type": "boolean", @@ -203,6 +197,6 @@ } }, "additionalProperties": false, - "required": ["name"], + "required": ["directory"], "examplesFile": "../../../docs/library-examples.md" } diff --git a/packages/angular/src/generators/move/move.spec.ts b/packages/angular/src/generators/move/move.spec.ts index e44e5a1985415..629355f2fd22c 100644 --- a/packages/angular/src/generators/move/move.spec.ts +++ b/packages/angular/src/generators/move/move.spec.ts @@ -34,7 +34,7 @@ describe('@nx/angular:move', () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestLibrary(tree, { - name: 'my-lib', + directory: 'my-lib', buildable: false, linter: Linter.EsLint, publishable: false, @@ -57,7 +57,6 @@ describe('@nx/angular:move', () => { newProjectName: 'mynewlib', destination: 'mynewlib', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -66,7 +65,7 @@ describe('@nx/angular:move', () => { it('should update ng-package.json dest property', async () => { await generateTestLibrary(tree, { - name: 'mylib2', + directory: 'mylib2', buildable: true, skipFormat: true, }); @@ -76,7 +75,6 @@ describe('@nx/angular:move', () => { projectName: 'mylib2', destination: 'mynewlib2', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -86,7 +84,7 @@ describe('@nx/angular:move', () => { it('should update secondary entry points readme file', async () => { await generateTestLibrary(tree, { - name: 'mylib2', + directory: 'mylib2', buildable: true, skipFormat: true, }); @@ -102,7 +100,6 @@ describe('@nx/angular:move', () => { newProjectName: 'mynewlib2', destination: 'mynewlib2', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -122,7 +119,6 @@ describe('@nx/angular:move', () => { projectName: 'my-lib', destination: 'my/lib', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -134,7 +130,7 @@ describe('@nx/angular:move', () => { describe('move to subfolder', () => { beforeEach(async () => { await generateTestLibrary(tree, { - name: 'my-lib2', + directory: 'my-lib2', buildable: false, linter: Linter.EsLint, publishable: false, @@ -187,7 +183,6 @@ describe('@nx/angular:move', () => { newProjectName: 'shared-my-lib', destination: 'shared/my-lib', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -226,7 +221,6 @@ describe('@nx/angular:move', () => { newProjectName: 'shared-my-lib', destination: 'shared/my-lib', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -250,7 +244,6 @@ describe('@nx/angular:move', () => { newProjectName: 'shared-my-lib', destination: 'shared/my-lib', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -264,7 +257,7 @@ describe('@nx/angular:move', () => { describe('rename', () => { beforeEach(async () => { await generateTestLibrary(tree, { - name: 'my-importer', + directory: 'my-importer', buildable: false, linter: Linter.EsLint, publishable: false, @@ -289,7 +282,6 @@ describe('@nx/angular:move', () => { newProjectName: 'my-destination', destination: 'my-destination', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -312,7 +304,6 @@ describe('@nx/angular:move', () => { newProjectName: 'my-destination', destination: 'my-destination', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -336,7 +327,6 @@ describe('@nx/angular:move', () => { newProjectName: 'my-destination', destination: 'my-destination', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); @@ -350,7 +340,7 @@ describe('@nx/angular:move', () => { // create different project whose main module name starts with the same // name of the project we're moving await generateTestLibrary(tree, { - name: 'my-lib-demo', + directory: 'my-lib-demo', buildable: false, linter: Linter.EsLint, publishable: false, @@ -366,7 +356,6 @@ describe('@nx/angular:move', () => { newProjectName: 'my-destination', destination: 'my-destination', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); diff --git a/packages/angular/src/generators/move/schema.d.ts b/packages/angular/src/generators/move/schema.d.ts index dff7858362f85..dfdefc742c3e7 100644 --- a/packages/angular/src/generators/move/schema.d.ts +++ b/packages/angular/src/generators/move/schema.d.ts @@ -1,5 +1,3 @@ -import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; - export interface Schema { projectName: string; destination: string; @@ -7,5 +5,4 @@ export interface Schema { importPath?: string; skipFormat?: boolean; newProjectName?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; } diff --git a/packages/angular/src/generators/move/schema.json b/packages/angular/src/generators/move/schema.json index 87f1c441d6515..b1ad8d7328304 100644 --- a/packages/angular/src/generators/move/schema.json +++ b/packages/angular/src/generators/move/schema.json @@ -35,11 +35,6 @@ }, "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the new project name and destination as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "importPath": { "type": "string", "description": "The new import path to use in the `tsconfig.base.json`." diff --git a/packages/angular/src/generators/ngrx-feature-store/ngrx-feature-store.spec.ts b/packages/angular/src/generators/ngrx-feature-store/ngrx-feature-store.spec.ts index df0332ea9fa92..55334679a167e 100644 --- a/packages/angular/src/generators/ngrx-feature-store/ngrx-feature-store.spec.ts +++ b/packages/angular/src/generators/ngrx-feature-store/ngrx-feature-store.spec.ts @@ -578,7 +578,7 @@ describe('ngrx-feature-store', () => { async function addNgModuleLib(tree: Tree, name = 'feature-module') { await libraryGenerator(tree, { - name, + directory: name, standalone: false, skipFormat: true, }); @@ -586,7 +586,7 @@ async function addNgModuleLib(tree: Tree, name = 'feature-module') { async function addStandaloneLib(tree: Tree, name = 'feature') { await libraryGenerator(tree, { - name, + directory: name, standalone: true, routing: true, skipFormat: true, diff --git a/packages/angular/src/generators/ngrx-root-store/ngrx-root-store.spec.ts b/packages/angular/src/generators/ngrx-root-store/ngrx-root-store.spec.ts index 7148489abe09b..f2efe3c98d5fc 100644 --- a/packages/angular/src/generators/ngrx-root-store/ngrx-root-store.spec.ts +++ b/packages/angular/src/generators/ngrx-root-store/ngrx-root-store.spec.ts @@ -459,7 +459,7 @@ describe('NgRxRootStoreGenerator', () => { async function createNgModuleApp(tree: Tree, name = 'my-app') { await generateTestApplication(tree, { - name, + directory: name, standalone: false, routing: true, skipFormat: true, @@ -468,7 +468,7 @@ async function createNgModuleApp(tree: Tree, name = 'my-app') { async function createStandaloneApp(tree: Tree, name = 'my-app') { await generateTestApplication(tree, { - name, + directory: name, standalone: true, routing: true, skipFormat: true, diff --git a/packages/angular/src/generators/ngrx/ngrx.spec.ts b/packages/angular/src/generators/ngrx/ngrx.spec.ts index fa1319c7dc067..c3e2316312ef2 100644 --- a/packages/angular/src/generators/ngrx/ngrx.spec.ts +++ b/packages/angular/src/generators/ngrx/ngrx.spec.ts @@ -514,7 +514,7 @@ describe('ngrx', () => { jest.clearAllMocks(); tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'my-app', + directory: 'my-app', standalone: true, routing: true, skipFormat: true, @@ -666,7 +666,7 @@ export const appRoutes: Routes = [{ path: 'home', component: NxWelcomeComponent jest.clearAllMocks(); tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'myapp', + directory: 'myapp', standalone: false, skipFormat: true, }); @@ -712,7 +712,7 @@ export const appRoutes: Routes = [{ path: 'home', component: NxWelcomeComponent beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'myapp', + directory: 'myapp', standalone: false, skipFormat: true, }); diff --git a/packages/angular/src/generators/remote/remote.spec.ts b/packages/angular/src/generators/remote/remote.spec.ts index 38cda8a19350c..1c2458d0b0fa4 100644 --- a/packages/angular/src/generators/remote/remote.spec.ts +++ b/packages/angular/src/generators/remote/remote.spec.ts @@ -22,7 +22,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', port: 4201, typescriptConfiguration: false, standalone: false, @@ -43,7 +43,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', port: 4201, typescriptConfiguration: true, standalone: false, @@ -59,7 +59,7 @@ describe('MF Remote App Generator', () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestHostApplication(tree, { - name: 'host', + directory: 'host', typescriptConfiguration: false, standalone: false, skipFormat: true, @@ -67,7 +67,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', host: 'host', typescriptConfiguration: false, standalone: false, @@ -84,7 +84,7 @@ describe('MF Remote App Generator', () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestHostApplication(tree, { - name: 'host', + directory: 'host', typescriptConfiguration: true, standalone: false, skipFormat: true, @@ -92,7 +92,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', host: 'host', typescriptConfiguration: true, standalone: false, @@ -111,7 +111,7 @@ describe('MF Remote App Generator', () => { // ACT try { await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', host: 'host', standalone: false, skipFormat: true, @@ -128,7 +128,7 @@ describe('MF Remote App Generator', () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestRemoteApplication(tree, { - name: 'existing', + directory: 'existing', port: 4201, standalone: false, skipFormat: true, @@ -136,7 +136,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', standalone: false, skipFormat: true, }); @@ -152,7 +152,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', standalone: false, skipFormat: true, }); @@ -168,7 +168,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', port: 4201, standalone: false, skipFormat: true, @@ -185,7 +185,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', typescriptConfiguration: false, }); @@ -218,7 +218,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', typescriptConfiguration: true, skipFormat: true, }); @@ -248,7 +248,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'remote1', + directory: 'remote1', e2eTestRunner: E2eTestRunner.None, standalone: false, skipFormat: true, @@ -265,7 +265,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', inlineTemplate: true, standalone: false, skipFormat: true, @@ -291,7 +291,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', skipFormat: true, }); @@ -309,7 +309,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', ssr: true, typescriptConfiguration: false, standalone: false, @@ -357,7 +357,7 @@ describe('MF Remote App Generator', () => { // ACT await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', ssr: true, typescriptConfiguration: true, standalone: false, @@ -411,7 +411,7 @@ describe('MF Remote App Generator', () => { })); await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', ssr: true, skipFormat: true, }); @@ -433,7 +433,7 @@ describe('MF Remote App Generator', () => { }); await generateTestRemoteApplication(tree, { - name: 'test', + directory: 'test', port: 4201, ssr: true, skipFormat: true, diff --git a/packages/angular/src/generators/remote/remote.ts b/packages/angular/src/generators/remote/remote.ts index 063ecd5c744c2..3d26a6821fe00 100644 --- a/packages/angular/src/generators/remote/remote.ts +++ b/packages/angular/src/generators/remote/remote.ts @@ -5,7 +5,10 @@ import { runTasksInSerial, Tree, } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { E2eTestRunner } from '../../utils/test-runners'; import { applicationGenerator } from '../application/application'; import { setupMf } from '../setup-mf/setup-mf'; @@ -25,14 +28,13 @@ export async function remote(tree: Tree, schema: Schema) { ); } - const { projectName: remoteProjectName, projectNameAndRootFormat } = + await ensureProjectName(tree, options, 'application'); + const { projectName: remoteProjectName } = await determineProjectNameAndRootOptions(tree, { name: options.name, projectType: 'application', directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); - options.projectNameAndRootFormat = projectNameAndRootFormat; const port = options.port ?? findNextAvailablePort(tree); diff --git a/packages/angular/src/generators/remote/schema.d.ts b/packages/angular/src/generators/remote/schema.d.ts index 345e5944782a6..36e9fac09b841 100644 --- a/packages/angular/src/generators/remote/schema.d.ts +++ b/packages/angular/src/generators/remote/schema.d.ts @@ -1,10 +1,10 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners'; import type { Styles } from '../utils/types'; export interface Schema { - name: string; + directory: string; + name?: string; host?: string; port?: number; setParserOptionsProject?: boolean; @@ -13,8 +13,6 @@ export interface Schema { prefix?: string; style?: Styles; skipTests?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; linter?: Linter | LinterType; unitTestRunner?: UnitTestRunner; diff --git a/packages/angular/src/generators/remote/schema.json b/packages/angular/src/generators/remote/schema.json index 65454c2ea9ea5..132af1320b17b 100644 --- a/packages/angular/src/generators/remote/schema.json +++ b/packages/angular/src/generators/remote/schema.json @@ -12,14 +12,20 @@ } ], "properties": { - "name": { + "directory": { + "description": "The directory of the new application.", "type": "string", - "description": "The name to give to the remote Angular app.", "$default": { "$source": "argv", "index": 0 }, - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" + }, + "name": { + "type": "string", + "description": "The name to give to the remote Angular app.", + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "host": { "type": "string", @@ -31,15 +37,6 @@ "type": "number", "description": "The port on which this app should be served." }, - "directory": { - "description": "The directory of the new application.", - "type": "string" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -174,5 +171,5 @@ } }, "additionalProperties": false, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.spec.ts b/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.spec.ts index bc2ea7adaf1bb..ca125af33de47 100644 --- a/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.spec.ts +++ b/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.spec.ts @@ -8,7 +8,7 @@ import { scamToStandalone } from './scam-to-standalone'; describe('scam-to-standalone', () => { it('should convert an inline scam to standalone', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { name: 'foo', skipFormat: true }); + await generateTestApplication(tree, { directory: 'foo', skipFormat: true }); await scamGenerator(tree, { name: 'bar', path: 'foo/src/app/bar/bar', diff --git a/packages/angular/src/generators/setup-mf/setup-mf.spec.ts b/packages/angular/src/generators/setup-mf/setup-mf.spec.ts index aaed57ced1c27..5490e9e781c11 100644 --- a/packages/angular/src/generators/setup-mf/setup-mf.spec.ts +++ b/packages/angular/src/generators/setup-mf/setup-mf.spec.ts @@ -18,13 +18,13 @@ describe('Init MF', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', routing: true, standalone: false, skipFormat: true, }); await generateTestApplication(tree, { - name: 'remote1', + directory: 'remote1', routing: true, standalone: false, skipFormat: true, @@ -347,7 +347,7 @@ describe('Init MF', () => { it('should add a remote application and add it to a specified host applications webpack config that contains a remote application already', async () => { // ARRANGE await generateTestApplication(tree, { - name: 'remote2', + directory: 'remote2', standalone: false, skipFormat: true, }); @@ -389,7 +389,7 @@ describe('Init MF', () => { it('should add a remote application and add it to a specified host applications webpack config that contains a remote application already when --typescriptConfiguration=true', async () => { // ARRANGE await generateTestApplication(tree, { - name: 'remote2', + directory: 'remote2', standalone: false, skipFormat: true, }); @@ -431,7 +431,7 @@ describe('Init MF', () => { it('should add a remote application and add it to a specified host applications router config', async () => { // ARRANGE await generateTestApplication(tree, { - name: 'remote2', + directory: 'remote2', routing: true, standalone: false, skipFormat: true, @@ -474,7 +474,7 @@ describe('Init MF', () => { it('should modify the associated cypress project to add the workaround correctly', async () => { // ARRANGE await generateTestApplication(tree, { - name: 'test-app', + directory: 'test-app', routing: true, standalone: false, skipFormat: true, diff --git a/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts b/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts index ce3fc2c1fef02..b952e36c79037 100644 --- a/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts +++ b/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts @@ -25,7 +25,7 @@ describe('setupSSR', () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', standalone: false, skipFormat: true, }); @@ -103,7 +103,10 @@ describe('setupSSR', () => { it('should create the files correctly for ssr when app is standalone', async () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { name: 'app1', skipFormat: true }); + await generateTestApplication(tree, { + directory: 'app1', + skipFormat: true, + }); // ACT await setupSsr(tree, { project: 'app1' }); @@ -149,7 +152,10 @@ describe('setupSSR', () => { it('should support object output option using a custom "outputPath.browser" and "outputPath.server" values', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { name: 'app1', skipFormat: true }); + await generateTestApplication(tree, { + directory: 'app1', + skipFormat: true, + }); const project = readProjectConfiguration(tree, 'app1'); project.targets.build.options.outputPath = { base: project.targets.build.options.outputPath, @@ -168,7 +174,10 @@ describe('setupSSR', () => { it('should remove "outputPath.browser" when it is an empty string', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { name: 'app1', skipFormat: true }); + await generateTestApplication(tree, { + directory: 'app1', + skipFormat: true, + }); const project = readProjectConfiguration(tree, 'app1'); project.targets.build.options.outputPath = { base: project.targets.build.options.outputPath, @@ -192,7 +201,7 @@ describe('setupSSR', () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', standalone: false, bundler: 'webpack', skipFormat: true, @@ -286,7 +295,7 @@ describe('setupSSR', () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', bundler: 'webpack', skipFormat: true, }); @@ -350,7 +359,7 @@ describe('setupSSR', () => { it('should update build target output path', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', standalone: false, bundler: 'webpack', skipFormat: true, @@ -370,7 +379,10 @@ describe('setupSSR', () => { it('should install the correct dependencies', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { name: 'app1', skipFormat: true }); + await generateTestApplication(tree, { + directory: 'app1', + skipFormat: true, + }); await setupSsr(tree, { project: 'app1', skipFormat: true }); @@ -388,7 +400,10 @@ describe('setupSSR', () => { it('should not touch the package.json when run with `--skipPackageJson`', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { name: 'app1', skipFormat: true }); + await generateTestApplication(tree, { + directory: 'app1', + skipFormat: true, + }); let initialPackageJson; updateJson(tree, 'package.json', (json) => { json.dependencies = {}; @@ -413,7 +428,7 @@ describe('setupSSR', () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', standalone: false, skipFormat: true, }); @@ -454,7 +469,7 @@ describe('setupSSR', () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', skipFormat: true, }); @@ -500,7 +515,7 @@ describe('setupSSR', () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', standalone: false, skipFormat: true, }); @@ -536,7 +551,10 @@ describe('setupSSR', () => { it('should set "withEnabledBlockingInitialNavigation()" in "provideRouter" features when hydration=false', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { name: 'app1', skipFormat: true }); + await generateTestApplication(tree, { + directory: 'app1', + skipFormat: true, + }); await setupSsr(tree, { project: 'app1', @@ -563,7 +581,7 @@ describe('setupSSR', () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', standalone: false, skipFormat: true, }); @@ -601,7 +619,7 @@ describe('setupSSR', () => { })); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', standalone: false, skipFormat: true, }); @@ -641,7 +659,10 @@ describe('setupSSR', () => { dependencies: { ...json.dependencies, '@angular/core': '^16.2.0' }, })); - await generateTestApplication(tree, { name: 'app1', skipFormat: true }); + await generateTestApplication(tree, { + directory: 'app1', + skipFormat: true, + }); // ACT await setupSsr(tree, { project: 'app1', skipFormat: true }); @@ -669,7 +690,7 @@ describe('setupSSR', () => { }, })); await generateTestApplication(tree, { - name: 'app1', + directory: 'app1', standalone: false, skipFormat: true, }); @@ -687,7 +708,10 @@ describe('setupSSR', () => { '@angular/core': '16.2.0', }, })); - await generateTestApplication(tree, { name: 'app1', skipFormat: true }); + await generateTestApplication(tree, { + directory: 'app1', + skipFormat: true, + }); await setupSsr(tree, { project: 'app1', skipFormat: true }); diff --git a/packages/angular/src/generators/stories/stories-app.spec.ts b/packages/angular/src/generators/stories/stories-app.spec.ts index ca8639b7ad7d5..2c6dedb466f7a 100644 --- a/packages/angular/src/generators/stories/stories-app.spec.ts +++ b/packages/angular/src/generators/stories/stories-app.spec.ts @@ -15,7 +15,7 @@ describe('angularStories generator: applications', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await generateTestApplication(tree, { - name: appName, + directory: appName, skipFormat: true, }); }); diff --git a/packages/angular/src/generators/stories/stories-lib.spec.ts b/packages/angular/src/generators/stories/stories-lib.spec.ts index ef566ccf7d75d..4e736fb316ddb 100644 --- a/packages/angular/src/generators/stories/stories-lib.spec.ts +++ b/packages/angular/src/generators/stories/stories-lib.spec.ts @@ -20,7 +20,7 @@ describe('angularStories generator: libraries', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestLibrary(tree, { name: libName, skipFormat: true }); + await generateTestLibrary(tree, { directory: libName, skipFormat: true }); }); it('should not fail on empty NgModule declarations', () => { diff --git a/packages/angular/src/generators/storybook-configuration/storybook-configuration.spec.ts b/packages/angular/src/generators/storybook-configuration/storybook-configuration.spec.ts index 80bf6b56d8a11..4349c2d7617e7 100644 --- a/packages/angular/src/generators/storybook-configuration/storybook-configuration.spec.ts +++ b/packages/angular/src/generators/storybook-configuration/storybook-configuration.spec.ts @@ -186,7 +186,7 @@ describe('StorybookConfiguration generator', () => { }); it('should exclude Storybook-related files from tsconfig.editor.json for applications', async () => { - await generateTestApplication(tree, { name: 'test-app' }); + await generateTestApplication(tree, { directory: 'test-app' }); await storybookConfigurationGenerator(tree, { project: 'test-app', diff --git a/packages/angular/src/generators/utils/testing.ts b/packages/angular/src/generators/utils/testing.ts index b5f1e3e5cfd82..04c2723d7f761 100644 --- a/packages/angular/src/generators/utils/testing.ts +++ b/packages/angular/src/generators/utils/testing.ts @@ -19,7 +19,6 @@ export async function generateTestApplication( ): Promise { tree.write('.gitignore', ''); await applicationGenerator(tree, { - projectNameAndRootFormat: 'as-provided', ...options, }); } @@ -29,7 +28,7 @@ export async function generateTestHostApplication( options: HostOptions ): Promise { tree.write('.gitignore', ''); - await host(tree, { projectNameAndRootFormat: 'as-provided', ...options }); + await host(tree, { ...options }); } export async function generateTestRemoteApplication( @@ -37,7 +36,7 @@ export async function generateTestRemoteApplication( options: RemoteOptions ): Promise { tree.write('.gitignore', ''); - await remote(tree, { projectNameAndRootFormat: 'as-provided', ...options }); + await remote(tree, { ...options }); } export async function generateTestLibrary( @@ -46,7 +45,6 @@ export async function generateTestLibrary( ): Promise { tree.write('.gitignore', ''); await libraryGenerator(tree, { - projectNameAndRootFormat: 'as-provided', ...options, }); } @@ -58,14 +56,13 @@ export async function createStorybookTestWorkspaceForLib( tree.write('.gitignore', ''); await libraryGenerator(tree, { - name: libName, + directory: libName, buildable: false, linter: Linter.EsLint, publishable: false, simpleName: false, skipFormat: true, unitTestRunner: UnitTestRunner.Jest, - projectNameAndRootFormat: 'as-provided', standalone: false, }); diff --git a/packages/angular/src/generators/web-worker/web-worker.spec.ts b/packages/angular/src/generators/web-worker/web-worker.spec.ts index fc298a45d93ab..ad109b64b7494 100644 --- a/packages/angular/src/generators/web-worker/web-worker.spec.ts +++ b/packages/angular/src/generators/web-worker/web-worker.spec.ts @@ -12,7 +12,10 @@ describe('webWorker generator', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { name: appName, skipFormat: true }); + await generateTestApplication(tree, { + directory: appName, + skipFormat: true, + }); jest.clearAllMocks(); }); diff --git a/packages/angular/src/migrations/update-15-2-0/remove-browserlist-config.spec.ts b/packages/angular/src/migrations/update-15-2-0/remove-browserlist-config.spec.ts index f7a8988ff7806..5d0cadfd2173b 100644 --- a/packages/angular/src/migrations/update-15-2-0/remove-browserlist-config.spec.ts +++ b/packages/angular/src/migrations/update-15-2-0/remove-browserlist-config.spec.ts @@ -17,7 +17,7 @@ describe('Migration to delete Browserslist configurations', () => { .spyOn(devkit, 'formatFiles') .mockImplementation(() => Promise.resolve()); await generateTestApplication(tree, { - name: 'test', + directory: 'test', skipFormat: true, }); }); diff --git a/packages/angular/src/migrations/update-15-2-0/update-typescript-target.spec.ts b/packages/angular/src/migrations/update-15-2-0/update-typescript-target.spec.ts index 0440da09c07f9..23c7f5dfac23f 100644 --- a/packages/angular/src/migrations/update-15-2-0/update-typescript-target.spec.ts +++ b/packages/angular/src/migrations/update-15-2-0/update-typescript-target.spec.ts @@ -21,12 +21,12 @@ describe('Migration to update target and add useDefineForClassFields', () => { .spyOn(devkit, 'formatFiles') .mockImplementation(() => Promise.resolve()); await generateTestApplication(tree, { - name: 'test', + directory: 'test', bundler: 'webpack', skipFormat: true, }); await generateTestApplication(tree, { - name: 'karma', + directory: 'karma', unitTestRunner: UnitTestRunner.None, bundler: 'webpack', skipFormat: true, diff --git a/packages/angular/src/migrations/update-15-2-0/update-workspace-config.spec.ts b/packages/angular/src/migrations/update-15-2-0/update-workspace-config.spec.ts index 6054512ab2cb3..d519e32522aae 100644 --- a/packages/angular/src/migrations/update-15-2-0/update-workspace-config.spec.ts +++ b/packages/angular/src/migrations/update-15-2-0/update-workspace-config.spec.ts @@ -17,7 +17,7 @@ describe(`Migration to remove bundleDependencies`, () => { .spyOn(devkit, 'formatFiles') .mockImplementation(() => Promise.resolve()); await generateTestApplication(tree, { - name: 'test', + directory: 'test', skipFormat: true, }); diff --git a/packages/angular/src/migrations/update-15-9-0/update-testing-tsconfig.spec.ts b/packages/angular/src/migrations/update-15-9-0/update-testing-tsconfig.spec.ts index bd1073c9280f1..844e62332caab 100644 --- a/packages/angular/src/migrations/update-15-9-0/update-testing-tsconfig.spec.ts +++ b/packages/angular/src/migrations/update-15-9-0/update-testing-tsconfig.spec.ts @@ -78,7 +78,7 @@ describe('Jest+Ng - 15.9.0 - tsconfig updates', () => { async function setup(tree: Tree, name: string) { await generateTestApplication(tree, { - name, + directory: name, skipPackageJson: true, skipFormat: true, }); @@ -102,7 +102,7 @@ async function setup(tree: Tree, name: string) { }); await generateTestLibrary(tree, { - name: `${name}-lib`, + directory: `${name}-lib`, skipFormat: true, }); diff --git a/packages/cypress/src/migrations/update-16-2-0/update-cy-tsconfig.spec.ts b/packages/cypress/src/migrations/update-16-2-0/update-cy-tsconfig.spec.ts index 64daf8d5ff1c5..672e613f3508c 100644 --- a/packages/cypress/src/migrations/update-16-2-0/update-cy-tsconfig.spec.ts +++ b/packages/cypress/src/migrations/update-16-2-0/update-cy-tsconfig.spec.ts @@ -18,7 +18,7 @@ describe('Cypress Migration - update-cy-tsconfig', () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); it('should do nothing if cypress/tsconfig.json exists', async () => { - await libraryGenerator(tree, { name: 'libs/my-lib' }); + await libraryGenerator(tree, { directory: 'libs/my-lib' }); addCyExecutor(tree, 'my-lib'); const tsconfig = { extends: '../tsconfig.json', @@ -51,7 +51,7 @@ describe('Cypress Migration - update-cy-tsconfig', () => { }); it('should move cypress/tsconfig.cy.json to cypress/tsconfig.json', async () => { - await libraryGenerator(tree, { name: 'libs/my-lib' }); + await libraryGenerator(tree, { directory: 'libs/my-lib' }); addCyExecutor(tree, 'my-lib'); const tsconfig = { extends: '../tsconfig.json', @@ -94,7 +94,7 @@ describe('Cypress Migration - update-cy-tsconfig', () => { }); it('should move tsconfig.cy.json to cypress/tsconfig.json', async () => { - await libraryGenerator(tree, { name: 'libs/my-lib' }); + await libraryGenerator(tree, { directory: 'libs/my-lib' }); addCyExecutor(tree, 'my-lib'); const tsconfig = { extends: './tsconfig.json', @@ -151,7 +151,7 @@ describe('Cypress Migration - update-cy-tsconfig', () => { }); it('should be idepotent', async () => { - await libraryGenerator(tree, { name: 'libs/my-lib' }); + await libraryGenerator(tree, { directory: 'libs/my-lib' }); addCyExecutor(tree, 'my-lib'); const tsconfig = { extends: './tsconfig.json', diff --git a/packages/cypress/src/utils/project-name.ts b/packages/cypress/src/utils/project-name.ts index 4328190317559..38a4216d12262 100644 --- a/packages/cypress/src/utils/project-name.ts +++ b/packages/cypress/src/utils/project-name.ts @@ -1,5 +1,4 @@ import { names } from '@nx/devkit'; -import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; export function getUnscopedLibName(libRoot: string) { return libRoot.slice(libRoot.lastIndexOf('/') + 1); @@ -8,10 +7,9 @@ export function getUnscopedLibName(libRoot: string) { export function getE2eProjectName( targetProjectName: string, targetLibRoot: string, - cypressDirectory?: string, - nameAndProjectRootFormat: ProjectNameAndRootFormat = 'as-provided' + cypressDirectory?: string ) { - if (cypressDirectory && nameAndProjectRootFormat !== 'as-provided') { + if (cypressDirectory) { return `${filePathPrefix(cypressDirectory)}-${getUnscopedLibName( targetLibRoot )}-e2e`; diff --git a/packages/detox/src/generators/application/application.spec.ts b/packages/detox/src/generators/application/application.spec.ts index 1bca1d9098cb3..d0318e695edb3 100644 --- a/packages/detox/src/generators/application/application.spec.ts +++ b/packages/detox/src/generators/application/application.spec.ts @@ -26,11 +26,10 @@ describe('detox application generator', () => { }); await detoxApplicationGenerator(tree, { - e2eName: 'my-app-e2e', + e2eDirectory: 'my-app-e2e', appProject: 'my-app', linter: Linter.None, framework: 'react-native', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); }); @@ -102,7 +101,6 @@ describe('detox application generator', () => { appProject: 'my-dir-my-app', linter: Linter.None, framework: 'react-native', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); }); @@ -174,7 +172,6 @@ describe('detox application generator', () => { appProject: 'my-dir-my-app', linter: Linter.None, framework: 'react-native', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); }); @@ -241,11 +238,10 @@ describe('detox application generator', () => { }); await detoxApplicationGenerator(tree, { - e2eName: 'my-dir/my-app-e2e', + e2eDirectory: 'my-dir/my-app-e2e', appProject: 'my-dir-my-app', linter: Linter.None, framework: 'react-native', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); }); @@ -311,11 +307,10 @@ describe('detox application generator', () => { }); await detoxApplicationGenerator(tree, { - e2eName: 'my-dir/my-app-e2e', + e2eDirectory: 'my-dir/my-app-e2e', appProject: 'my-dir-my-app', linter: Linter.None, framework: 'expo', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); }); @@ -394,7 +389,7 @@ describe('detox application generator', () => { it('should extend from tsconfig.base.json', async () => { await detoxApplicationGenerator(tree, { - e2eName: 'my-app-e2e', + e2eDirectory: 'my-app-e2e', appProject: 'my-app', linter: Linter.None, framework: 'react-native', @@ -409,7 +404,7 @@ describe('detox application generator', () => { tree.rename('tsconfig.base.json', 'tsconfig.json'); await detoxApplicationGenerator(tree, { - e2eName: 'my-app-e2e', + e2eDirectory: 'my-app-e2e', appProject: 'my-app', linter: Linter.None, framework: 'react-native', diff --git a/packages/detox/src/generators/application/lib/add-linting.spec.ts b/packages/detox/src/generators/application/lib/add-linting.spec.ts index a7a818d116475..114f716b90a1d 100644 --- a/packages/detox/src/generators/application/lib/add-linting.spec.ts +++ b/packages/detox/src/generators/application/lib/add-linting.spec.ts @@ -10,7 +10,7 @@ describe('Add Linting', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); addProject(tree, { - e2eName: 'my-app-e2e', + e2eDirectory: 'my-app-e2e', e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'apps/my-app-e2e', appProject: 'my-app', @@ -26,7 +26,7 @@ describe('Add Linting', () => { it('should update configuration when eslint is passed', async () => { await addLinting(tree, { - e2eName: 'my-app-e2e', + e2eDirectory: 'my-app-e2e', e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'apps/my-app-e2e', appProject: 'my-app', @@ -44,7 +44,7 @@ describe('Add Linting', () => { it('should not add lint target when "none" is passed', async () => { await addLinting(tree, { - e2eName: 'my-app-e2e', + e2eDirectory: 'my-app-e2e', e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'apps/my-app-e2e', appProject: 'my-app', diff --git a/packages/detox/src/generators/application/lib/add-project.spec.ts b/packages/detox/src/generators/application/lib/add-project.spec.ts index 989e0c763aafd..4a351574b6e63 100644 --- a/packages/detox/src/generators/application/lib/add-project.spec.ts +++ b/packages/detox/src/generators/application/lib/add-project.spec.ts @@ -29,7 +29,7 @@ describe('Add Project', () => { describe('app at root', () => { beforeEach(() => { addProject(tree, { - e2eName: 'my-app-e2e', + e2eDirectory: 'my-app-e2e', e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'apps/my-app-e2e', appProject: 'my-app', @@ -78,7 +78,7 @@ describe('Add Project', () => { describe('app with directory', () => { beforeEach(() => { addProject(tree, { - e2eName: 'my-dir-my-app-e2e', + e2eDirectory: 'my-dir-my-app-e2e', e2eProjectName: 'my-dir-my-app-e2e', e2eProjectRoot: 'apps/my-dir/my-app-e2e', appProject: 'my-dir-my-app', diff --git a/packages/detox/src/generators/application/lib/create-files.spec.ts b/packages/detox/src/generators/application/lib/create-files.spec.ts index 603a02f6f4fdc..31effd55eb844 100644 --- a/packages/detox/src/generators/application/lib/create-files.spec.ts +++ b/packages/detox/src/generators/application/lib/create-files.spec.ts @@ -12,7 +12,7 @@ describe('Create Files', () => { it('should generate files', () => { createFiles(tree, { - e2eName: 'my-app-e2e', + e2eDirectory: 'my-app-e2e', e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'apps/my-app-e2e', appProject: 'my-app', diff --git a/packages/detox/src/generators/application/lib/normalize-options.spec.ts b/packages/detox/src/generators/application/lib/normalize-options.spec.ts index 98d5953303d5d..8a36daf82ad0e 100644 --- a/packages/detox/src/generators/application/lib/normalize-options.spec.ts +++ b/packages/detox/src/generators/application/lib/normalize-options.spec.ts @@ -19,7 +19,7 @@ describe('Normalize Options', () => { }); const schema: Schema = { framework: 'react-native', - e2eName: 'apps/my-app-e2e', + e2eDirectory: 'apps/my-app-e2e', appProject: 'my-app', linter: Linter.EsLint, }; @@ -28,6 +28,7 @@ describe('Normalize Options', () => { addPlugin: true, framework: 'react-native', e2eName: 'my-app-e2e', + e2eDirectory: 'apps/my-app-e2e', e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'apps/my-app-e2e', appProject: 'my-app', @@ -47,7 +48,7 @@ describe('Normalize Options', () => { }); const schema: Schema = { framework: 'react-native', - e2eName: 'apps/my-app-e2e', + e2eDirectory: 'apps/my-app-e2e', appProject: 'my-app', appDisplayName: 'app display name', }; @@ -60,6 +61,7 @@ describe('Normalize Options', () => { appFileName: 'my-app', appRoot: 'apps/my-app', e2eName: 'my-app-e2e', + e2eDirectory: 'apps/my-app-e2e', appProject: 'my-app', e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'apps/my-app-e2e', diff --git a/packages/detox/src/generators/application/lib/normalize-options.ts b/packages/detox/src/generators/application/lib/normalize-options.ts index febefb210c152..f6739a2169cb6 100644 --- a/packages/detox/src/generators/application/lib/normalize-options.ts +++ b/packages/detox/src/generators/application/lib/normalize-options.ts @@ -1,5 +1,8 @@ import { names, readNxJson, readProjectConfiguration, Tree } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Schema } from '../schema'; export interface NormalizedSchema extends Schema { @@ -20,7 +23,6 @@ export async function normalizeOptions( name: options.e2eName, projectType: 'application', directory: options.e2eDirectory, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); const nxJson = readNxJson(host); const addPlugin = diff --git a/packages/detox/src/generators/application/schema.d.ts b/packages/detox/src/generators/application/schema.d.ts index 0c52d2d96fab9..68e5c28020f58 100644 --- a/packages/detox/src/generators/application/schema.d.ts +++ b/packages/detox/src/generators/application/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { appProject: string; // name of the project app to be tested (directory + app name), case insensitive appDisplayName?: string; // display name of the app to be tested appName?: string; // name of app to be tested if different form appProject, case insensitive - e2eDirectory?: string; // the directory where e2e app going to be located - projectNameAndRootFormat?: ProjectNameAndRootFormat; - e2eName: string; // name of the e2e app + e2eDirectory: string; // the directory where e2e app going to be located + e2eName?: string; // name of the e2e app linter?: Linter | LinterType; js?: boolean; skipFormat?: boolean; diff --git a/packages/detox/src/generators/application/schema.json b/packages/detox/src/generators/application/schema.json index a62b3353afaf1..9e15e450172a1 100644 --- a/packages/detox/src/generators/application/schema.json +++ b/packages/detox/src/generators/application/schema.json @@ -12,15 +12,18 @@ }, "x-prompt": "What is the name of the frontend project to test?" }, - "e2eName": { + "e2eDirectory": { "type": "string", - "description": "Name of the E2E Project.", + "description": "A directory where the project is placed relative current working directory (CWD).", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the E2E project?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the E2E project in?" + }, + "e2eName": { + "type": "string", + "description": "Name of the E2E Project." }, "appName": { "type": "string", @@ -36,15 +39,6 @@ "enum": ["react-native", "expo"], "x-prompt": "What app framework should detox test?" }, - "e2eDirectory": { - "type": "string", - "description": "A directory where the project is placed relative to apps directory." - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -68,5 +62,5 @@ "default": false } }, - "required": ["e2eName", "appProject", "framework"] + "required": ["e2eDirectory", "appProject", "framework"] } diff --git a/packages/devkit/package.json b/packages/devkit/package.json index c02d125e8d3f8..8aef0a72bb695 100644 --- a/packages/devkit/package.json +++ b/packages/devkit/package.json @@ -34,7 +34,8 @@ "tslib": "^2.3.0", "semver": "^7.5.3", "yargs-parser": "21.1.1", - "minimatch": "9.0.3" + "minimatch": "9.0.3", + "enquirer": "~2.3.6" }, "peerDependencies": { "nx": ">= 17 <= 20" 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 37692ddad43d7..28a0dee4d734c 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 @@ -18,107 +18,90 @@ describe('determineProjectNameAndRootOptions', () => { jest.clearAllMocks(); }); - it('should return the project name and directory as provided', async () => { + it('should return the last part of the directory as name', async () => { const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - directory: 'shared', + directory: 'shared/lib-name', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }); expect(result).toStrictEqual({ - projectName: 'libName', + projectName: 'lib-name', names: { - projectSimpleName: 'libName', - projectFileName: 'libName', + projectSimpleName: 'lib-name', + projectFileName: 'lib-name', }, - importPath: '@proj/libName', - projectRoot: 'shared', - projectNameAndRootFormat: 'as-provided', + importPath: '@proj/lib-name', + projectRoot: 'shared/lib-name', }); }); - it(`should handle window's style paths correctly when format is "as-provided"`, async () => { + it('should use "@" scoped directory as the project name and import path', async () => { const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - directory: 'shared\\libName', + directory: 'packages/@scope/lib-name', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }); - expect(result).toStrictEqual({ - projectName: 'libName', + expect(result).toEqual({ + projectName: '@scope/lib-name', names: { - projectSimpleName: 'libName', - projectFileName: 'libName', + projectSimpleName: 'lib-name', + projectFileName: 'lib-name', }, - importPath: '@proj/libName', - projectRoot: 'shared/libName', - projectNameAndRootFormat: 'as-provided', + importPath: '@scope/lib-name', + projectRoot: 'packages/@scope/lib-name', }); }); - it('should use a scoped package name as the project name and import path when format is "as-provided"', async () => { + it('should use "@" scoped directory as the project name and import path in deeply nested directory', async () => { const result = await determineProjectNameAndRootOptions(tree, { - name: '@scope/libName', - directory: 'shared', + directory: 'packages/shared/@scope/lib-name', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }); expect(result).toEqual({ - projectName: '@scope/libName', + projectName: '@scope/lib-name', names: { - projectSimpleName: 'libName', - projectFileName: 'libName', + projectSimpleName: 'lib-name', + projectFileName: 'lib-name', }, - importPath: '@scope/libName', - projectRoot: 'shared', - projectNameAndRootFormat: 'as-provided', + importPath: '@scope/lib-name', + projectRoot: 'packages/shared/@scope/lib-name', }); }); - it('should use provided import path over scoped name when format is "as-provided"', async () => { + it('should handle Windows path correctly', async () => { const result = await determineProjectNameAndRootOptions(tree, { - name: '@scope/libName', - directory: 'shared', + directory: 'shared\\lib-name', projectType: 'library', - projectNameAndRootFormat: 'as-provided', - importPath: '@custom-scope/lib-name', }); - expect(result).toEqual({ - projectName: '@scope/libName', + expect(result).toStrictEqual({ + projectName: 'lib-name', names: { - projectSimpleName: 'libName', - projectFileName: 'libName', + projectSimpleName: 'lib-name', + projectFileName: 'lib-name', }, - importPath: '@custom-scope/lib-name', - projectRoot: 'shared', - projectNameAndRootFormat: 'as-provided', + importPath: '@proj/lib-name', + projectRoot: 'shared/lib-name', }); }); - it('should return the directory as the project name when directory is not provided and format is "as-provided"', async () => { - updateJson(tree, 'package.json', (json) => { - json.name = 'lib-name'; - return json; - }); + it('should use provided import path over scoped name', async () => { const result = await determineProjectNameAndRootOptions(tree, { - name: '@scope/libName', + name: '@scope/lib-name', + directory: 'shared', projectType: 'library', - projectNameAndRootFormat: 'as-provided', + importPath: '@custom-scope/lib-name', }); expect(result).toEqual({ - projectName: '@scope/libName', + projectName: '@scope/lib-name', names: { - projectSimpleName: 'libName', - projectFileName: 'libName', + projectSimpleName: 'lib-name', + projectFileName: 'lib-name', }, - importPath: '@scope/libName', - projectRoot: '@scope/libName', - projectNameAndRootFormat: 'as-provided', + importPath: '@custom-scope/lib-name', + projectRoot: 'shared', }); }); @@ -128,21 +111,18 @@ describe('determineProjectNameAndRootOptions', () => { process.env.INIT_CWD = join(workspaceRoot, 'some/path'); const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', directory: 'nested/lib-name', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }); expect(result).toEqual({ - projectName: 'libName', + projectName: 'lib-name', names: { - projectSimpleName: 'libName', - projectFileName: 'libName', + projectSimpleName: 'lib-name', + projectFileName: 'lib-name', }, - importPath: '@proj/libName', + importPath: '@proj/lib-name', projectRoot: 'some/path/nested/lib-name', - projectNameAndRootFormat: 'as-provided', }); // restore original cwd @@ -159,21 +139,18 @@ describe('determineProjectNameAndRootOptions', () => { process.env.INIT_CWD = join(workspaceRoot, 'some/path'); const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', directory: 'some/path/nested/lib-name', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }); expect(result).toEqual({ - projectName: 'libName', + projectName: 'lib-name', names: { - projectSimpleName: 'libName', - projectFileName: 'libName', + projectSimpleName: 'lib-name', + projectFileName: 'lib-name', }, - importPath: '@proj/libName', + importPath: '@proj/lib-name', projectRoot: 'some/path/nested/lib-name', - projectNameAndRootFormat: 'as-provided', }); // restore original cwd @@ -184,56 +161,24 @@ describe('determineProjectNameAndRootOptions', () => { } }); - it('should return the directory considering the cwd when directory is not provided and format is "as-provided"', async () => { + it('should return the directory considering the cwd', async () => { // simulate running in a subdirectory const originalInitCwd = process.env.INIT_CWD; process.env.INIT_CWD = join(workspaceRoot, 'some/path'); const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: 'libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@proj/libName', - projectRoot: 'some/path/libName', - projectNameAndRootFormat: 'as-provided', - }); - - // restore original cwd - if (originalInitCwd === undefined) { - delete process.env.INIT_CWD; - } else { - process.env.INIT_CWD = originalInitCwd; - } - }); - - it('should not duplicate project name in the directory when directory is not provided and format is "as-provided"', async () => { - // simulate running in a subdirectory - const originalInitCwd = process.env.INIT_CWD; - process.env.INIT_CWD = join(workspaceRoot, 'some/path/libName'); - - const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', + directory: 'lib-name', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }); expect(result).toEqual({ - projectName: 'libName', + projectName: 'lib-name', names: { - projectSimpleName: 'libName', - projectFileName: 'libName', + projectSimpleName: 'lib-name', + projectFileName: 'lib-name', }, - importPath: '@proj/libName', - projectRoot: 'some/path/libName', - projectNameAndRootFormat: 'as-provided', + importPath: '@proj/lib-name', + projectRoot: 'some/path/lib-name', }); // restore original cwd @@ -246,321 +191,68 @@ describe('determineProjectNameAndRootOptions', () => { it('should return the project name and directory as provided for root projects', async () => { updateJson(tree, 'package.json', (json) => { - json.name = 'libName'; + json.name = 'lib-name'; return json; }); const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', + name: 'lib-name', + directory: '.', projectType: 'library', - projectNameAndRootFormat: 'as-provided', rootProject: true, }); expect(result).toEqual({ - projectName: 'libName', + projectName: 'lib-name', names: { - projectSimpleName: 'libName', - projectFileName: 'libName', + projectSimpleName: 'lib-name', + projectFileName: 'lib-name', }, - importPath: 'libName', + importPath: 'lib-name', projectRoot: '.', - projectNameAndRootFormat: 'as-provided', }); }); - it('should throw when an invalid name is provided', async () => { + it('should throw when an invalid directory is provided', async () => { await expect( determineProjectNameAndRootOptions(tree, { - name: '!scope/libName', - directory: 'shared', + directory: '!scope/lib-name', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }) - ).rejects.toThrowError(); - }); - - it('should handle providing a path as the project name when format is "as-provided"', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: 'shared/libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: 'libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@proj/libName', - projectRoot: 'shared/libName', - projectNameAndRootFormat: 'as-provided', - }); - }); - - it('should handle providing a path including "@" as the project name when format is "as-provided"', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: 'shared/@scope/libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: '@scope/libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@scope/libName', - projectRoot: 'shared/@scope/libName', - projectNameAndRootFormat: 'as-provided', - }); - }); - - it('should handle providing a path including "@" with multiple segments as the project name when format is "as-provided"', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: 'shared/@scope/libName/testing', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: '@scope/libName/testing', - names: { - projectSimpleName: 'testing', - projectFileName: 'libName-testing', - }, - importPath: '@scope/libName/testing', - projectRoot: 'shared/@scope/libName/testing', - projectNameAndRootFormat: 'as-provided', - }); - }); - - it('should handle providing a path including multiple "@" as the project name when format is "as-provided"', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: 'shared/@foo/@scope/libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: '@scope/libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@scope/libName', - projectRoot: 'shared/@foo/@scope/libName', - projectNameAndRootFormat: 'as-provided', - }); - }); - }); - - describe('with layout', () => { - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - jest.clearAllMocks(); - }); - - it('should return the project name and directory as provided', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - directory: 'shared', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: 'libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@proj/libName', - projectRoot: 'shared', - projectNameAndRootFormat: 'as-provided', - }); - }); - - it(`should handle window's style paths correctly when format is "as-provided"`, async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - directory: 'shared\\libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toStrictEqual({ - projectName: 'libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@proj/libName', - projectRoot: 'shared/libName', - projectNameAndRootFormat: 'as-provided', - }); - }); - - it('should use a scoped package name as the project name and import path when format is "as-provided"', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: '@scope/libName', - directory: 'shared', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: '@scope/libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@scope/libName', - projectRoot: 'shared', - projectNameAndRootFormat: 'as-provided', - }); - }); - - it('should use provided import path over scoped name when format is "as-provided"', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: '@scope/libName', - directory: 'shared', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - importPath: '@custom-scope/lib-name', - }); - - expect(result).toEqual({ - projectName: '@scope/libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@custom-scope/lib-name', - projectRoot: 'shared', - projectNameAndRootFormat: 'as-provided', - }); - }); - - it('should return the directory as the project name when directory is not provided and format is "as-provided"', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: '@scope/libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: '@scope/libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@scope/libName', - projectRoot: '@scope/libName', - projectNameAndRootFormat: 'as-provided', - }); - }); - - it('should return the project name and directory as provided for root projects', async () => { - updateJson(tree, 'package.json', (json) => { - json.name = 'libName'; - return json; - }); - - const result = await determineProjectNameAndRootOptions(tree, { - name: 'libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - rootProject: true, - }); - - expect(result).toEqual({ - projectName: 'libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: 'libName', - projectRoot: '.', - projectNameAndRootFormat: 'as-provided', - }); + ).rejects.toThrow(/directory should match/); }); it('should throw when an invalid name is provided', async () => { await expect( determineProjectNameAndRootOptions(tree, { - name: '!scope/libName', + name: '!scope/lib-name', directory: 'shared', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }) - ).rejects.toThrowError(); - }); - - it('should handle providing a path as the project name when format is "as-provided"', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: 'shared/libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: 'libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@proj/libName', - projectRoot: 'shared/libName', - projectNameAndRootFormat: 'as-provided', - }); - }); - - it('should handle providing a path including "@" as the project name when format is "as-provided"', async () => { - const result = await determineProjectNameAndRootOptions(tree, { - name: 'shared/@scope/libName', - projectType: 'library', - projectNameAndRootFormat: 'as-provided', - }); - - expect(result).toEqual({ - projectName: '@scope/libName', - names: { - projectSimpleName: 'libName', - projectFileName: 'libName', - }, - importPath: '@scope/libName', - projectRoot: 'shared/@scope/libName', - projectNameAndRootFormat: 'as-provided', - }); + ).rejects.toThrow(/name should match/); }); - it('should handle providing a path including "@" with multiple segments as the project name when format is "as-provided"', async () => { + it('should handle providing a path including "@" with multiple segments as the project name', async () => { const result = await determineProjectNameAndRootOptions(tree, { - name: 'shared/@scope/libName/testing', + directory: 'shared/@scope/lib-name/testing', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }); expect(result).toEqual({ - projectName: '@scope/libName/testing', + projectName: '@scope/lib-name/testing', names: { projectSimpleName: 'testing', - projectFileName: 'libName-testing', + projectFileName: 'lib-name-testing', }, - importPath: '@scope/libName/testing', - projectRoot: 'shared/@scope/libName/testing', - projectNameAndRootFormat: 'as-provided', + importPath: '@scope/lib-name/testing', + projectRoot: 'shared/@scope/lib-name/testing', }); }); - it('should handle providing a path including multiple "@" as the project name when format is "as-provided"', async () => { + it('should handle providing a path including multiple "@" as the project name', async () => { const result = await determineProjectNameAndRootOptions(tree, { - name: 'shared/@foo/@scope/libName', + directory: 'shared/@foo/@scope/libName', projectType: 'library', - projectNameAndRootFormat: 'as-provided', }); expect(result).toEqual({ @@ -571,7 +263,6 @@ describe('determineProjectNameAndRootOptions', () => { }, importPath: '@scope/libName', projectRoot: 'shared/@foo/@scope/libName', - projectNameAndRootFormat: 'as-provided', }); }); }); 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 516de5a37881a..85bf3a180f699 100644 --- a/packages/devkit/src/generators/project-name-and-root-utils.ts +++ b/packages/devkit/src/generators/project-name-and-root-utils.ts @@ -1,30 +1,26 @@ +import { prompt } from 'enquirer'; import { joinPathFragments, normalizePath, - readJson, - workspaceRoot, type ProjectType, + readJson, type Tree, + workspaceRoot, } from 'nx/src/devkit-exports'; -import { join, relative } from 'path'; - -// TODO(leo): remove in a follow up -export type ProjectNameAndRootFormat = 'as-provided'; +import { relative } from 'path'; export type ProjectGenerationOptions = { - name: string; + directory: string; + name?: string; projectType: ProjectType; - directory?: string; importPath?: string; rootProject?: boolean; - projectNameAndRootFormat?: ProjectNameAndRootFormat; }; export type ProjectNameAndRootOptions = { /** * Normalized full project name, including scope if name was provided with - * scope (e.g., `@scope/name`, only available when `projectNameAndRootFormat` - * is `as-provided`). + * scope (e.g., `@scope/name`) */ projectName: string; /** @@ -52,104 +48,43 @@ export type ProjectNameAndRootOptions = { export async function determineProjectNameAndRootOptions( tree: Tree, options: ProjectGenerationOptions -): Promise< - ProjectNameAndRootOptions & { - // TODO(leo): remove in a follow up - projectNameAndRootFormat: ProjectNameAndRootFormat; - } -> { - validateName(options.name); - const projectNameAndRootOptions = getProjectNameAndRootOptions(tree, options); - - return { - ...projectNameAndRootOptions, - projectNameAndRootFormat: 'as-provided', - }; -} - -function validateName(name: string): void { - /** - * Matches two types of project names: - * - * 1. Valid npm package names (e.g., '@scope/name' or 'name'). - * 2. Names starting with a letter and can contain any character except whitespace and ':'. - * - * The second case is to support the legacy behavior (^[a-zA-Z].*$) with the difference - * that it doesn't allow the ":" character. It was wrong to allow it because it would - * conflict with the notation for tasks. - */ - const pattern = - '(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$'; - const validationRegex = new RegExp(pattern); - if (!validationRegex.test(name)) { - throw new Error( - `The project name should match the pattern "${pattern}". The provided value "${name}" does not match.` - ); - } -} - -function getProjectNameAndRootOptions( - tree: Tree, - options: ProjectGenerationOptions -): ProjectNameAndRootOptions { - const directory = options.directory - ? normalizePath(options.directory.replace(/^\.?\//, '')) - : undefined; - - const { name: asProvidedParsedName, directory: asProvidedParsedDirectory } = - parseNameForAsProvided(options.name); - - if (asProvidedParsedDirectory && directory) { - throw new Error( - `You can't specify both a directory (${options.directory}) and a name with a directory path (${options.name}). ` + - `Please specify either a directory or a name with a directory path.` - ); - } - - const asProvidedOptions = getAsProvidedOptions(tree, { - ...options, - directory: directory ?? asProvidedParsedDirectory, - name: asProvidedParsedName, - }); +): Promise { + validateOptions(options); - return asProvidedOptions; -} + const directory = normalizePath(options.directory); + const name = + options.name ?? + directory.match(/(@[^@/]+(\/[^@/]+)+)/)?.[1] ?? + directory.substring(directory.lastIndexOf('/') + 1); -function getAsProvidedOptions( - tree: Tree, - options: ProjectGenerationOptions -): ProjectNameAndRootOptions { let projectSimpleName: string; let projectFileName: string; - if (options.name.startsWith('@')) { - const [_scope, ...rest] = options.name.split('/'); + if (name.startsWith('@')) { + const [_scope, ...rest] = name.split('/'); projectFileName = rest.join('-'); projectSimpleName = rest.pop(); } else { - projectSimpleName = options.name; - projectFileName = options.name; + projectSimpleName = name; + projectFileName = name; } let projectRoot: string; const relativeCwd = getRelativeCwd(); - if (options.directory) { + if (directory) { // append the directory to the current working directory if it doesn't start with it - if ( - options.directory === relativeCwd || - options.directory.startsWith(`${relativeCwd}/`) - ) { - projectRoot = options.directory; + if (directory === relativeCwd || directory.startsWith(`${relativeCwd}/`)) { + projectRoot = directory; } else { - projectRoot = joinPathFragments(relativeCwd, options.directory); + projectRoot = joinPathFragments(relativeCwd, directory); } } else if (options.rootProject) { projectRoot = '.'; } else { projectRoot = relativeCwd; // append the project name to the current working directory if it doesn't end with it - if (!relativeCwd.endsWith(options.name)) { - projectRoot = joinPathFragments(relativeCwd, options.name); + if (!relativeCwd.endsWith(name)) { + projectRoot = joinPathFragments(relativeCwd, name); } } @@ -158,21 +93,21 @@ function getAsProvidedOptions( importPath = options.importPath; if (!importPath) { - if (options.name.startsWith('@')) { - importPath = options.name; + if (name.startsWith('@')) { + importPath = name; } else { const npmScope = getNpmScope(tree); importPath = projectRoot === '.' ? readJson<{ name?: string }>(tree, 'package.json').name ?? - getImportPath(npmScope, options.name) - : getImportPath(npmScope, options.name); + getImportPath(npmScope, name) + : getImportPath(npmScope, name); } } } return { - projectName: options.name, + projectName: name, names: { projectSimpleName, projectFileName, @@ -182,6 +117,62 @@ function getAsProvidedOptions( }; } +export async function ensureProjectName( + tree: Tree, + options: Omit, + projectType: 'application' | 'library' +): Promise { + if (!options.name) { + if (options.directory === '.' && getRelativeCwd() === '') { + const result = await prompt<{ name: string }>({ + type: 'input', + name: 'name', + message: `What do you want to name the ${projectType}?`, + }).then(({ name }) => (options.name = name)); + } + const { projectName } = await determineProjectNameAndRootOptions(tree, { + ...options, + projectType, + }); + options.name = projectName; + } +} + +function validateOptions(options: ProjectGenerationOptions): void { + if (options.directory === '.') { + /** + * Root projects must provide name option + */ + if (!options.name) { + throw new Error(`Root projects must also specify name option.`); + } + } else { + /** + * Both directory and name (if present) must match one of two cases: + * + * 1. Valid npm package names (e.g., '@scope/name' or 'name'). + * 2. Names starting with a letter and can contain any character except whitespace and ':'. + * + * The second case is to support the legacy behavior (^[a-zA-Z].*$) with the difference + * that it doesn't allow the ":" character. It was wrong to allow it because it would + * conflict with the notation for tasks. + */ + const pattern = + '(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$'; + const validationRegex = new RegExp(pattern); + if (options.name && !validationRegex.test(options.name)) { + throw new Error( + `The name should match the pattern "${pattern}". The provided value "${options.name}" does not match.` + ); + } + if (!validationRegex.test(options.directory)) { + throw new Error( + `The directory should match the pattern "${pattern}". The provided value "${options.directory}" does not match.` + ); + } + } +} + function getImportPath(npmScope: string | undefined, name: string) { return npmScope ? `${npmScope === '@' ? '' : '@'}${npmScope}/${name}` : name; } @@ -209,38 +200,3 @@ function getCwd(): string { function getRelativeCwd(): string { return normalizePath(relative(workspaceRoot, getCwd())).replace(/\/$/, ''); } - -/** - * Function for setting cwd during testing - */ -export function setCwd(path: string): void { - process.env.INIT_CWD = join(workspaceRoot, path); -} - -function parseNameForAsProvided(rawName: string): { - name: string; - directory: string | undefined; -} { - const directory = normalizePath(rawName); - - if (rawName.includes('@')) { - const index = directory.lastIndexOf('@'); - - if (index === 0) { - return { name: rawName, directory: undefined }; - } - - const name = directory.substring(index); - - return { name, directory }; - } - - if (rawName.includes('/')) { - const index = directory.lastIndexOf('/'); - const name = directory.substring(index + 1); - - return { name, directory }; - } - - return { name: rawName, directory: undefined }; -} diff --git a/packages/expo/src/generators/application/application.spec.ts b/packages/expo/src/generators/application/application.spec.ts index 6e1942d03259c..f51d0690f7c2c 100644 --- a/packages/expo/src/generators/application/application.spec.ts +++ b/packages/expo/src/generators/application/application.spec.ts @@ -21,14 +21,13 @@ describe('app', () => { it('should update workspace', async () => { await expoApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', linter: Linter.EsLint, e2eTestRunner: 'none', skipFormat: false, js: false, unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); const projects = getProjects(appTree); @@ -37,7 +36,7 @@ describe('app', () => { it('should update nx.json', async () => { await expoApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', tags: 'one,two', linter: Linter.EsLint, @@ -45,7 +44,6 @@ describe('app', () => { skipFormat: false, js: false, unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); const projectConfiguration = readProjectConfiguration(appTree, 'my-app'); @@ -56,14 +54,13 @@ describe('app', () => { it('should generate files', async () => { await expoApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', linter: Linter.EsLint, e2eTestRunner: 'none', skipFormat: false, js: false, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }); expect(appTree.exists('my-app/src/app/App.tsx')).toBeTruthy(); expect(appTree.exists('my-app/src/app/App.spec.tsx')).toBeTruthy(); @@ -76,14 +73,13 @@ describe('app', () => { it('should generate js files', async () => { await expoApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', linter: Linter.EsLint, e2eTestRunner: 'none', skipFormat: false, js: true, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }); expect(appTree.exists('my-app/src/app/App.js')).toBeTruthy(); expect(appTree.exists('my-app/src/app/App.spec.js')).toBeTruthy(); @@ -104,7 +100,6 @@ describe('app', () => { js: false, skipFormat: false, unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); expect(appTree.exists('my-dir-e2e/.detoxrc.json')).toBeTruthy(); @@ -160,13 +155,12 @@ describe('app', () => { it('should create e2e app without directory', async () => { await expoApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', linter: Linter.EsLint, e2eTestRunner: 'detox', js: false, skipFormat: false, unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); expect(appTree.exists('my-app-e2e/.detoxrc.json')).toBeTruthy(); @@ -221,7 +215,7 @@ describe('app', () => { it('should create e2e app with display name', async () => { await expoApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'my app name', linter: Linter.EsLint, e2eTestRunner: 'detox', @@ -294,7 +288,6 @@ describe('app', () => { js: false, skipFormat: false, unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); @@ -320,7 +313,6 @@ describe('app', () => { js: false, skipFormat: false, unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); diff --git a/packages/expo/src/generators/application/lib/add-e2e.ts b/packages/expo/src/generators/application/lib/add-e2e.ts index 71f0242024133..67d16a84e15c5 100644 --- a/packages/expo/src/generators/application/lib/add-e2e.ts +++ b/packages/expo/src/generators/application/lib/add-e2e.ts @@ -167,7 +167,6 @@ export async function addE2e( ...options, e2eName: options.e2eProjectName, e2eDirectory: options.e2eProjectRoot, - projectNameAndRootFormat: 'as-provided', appProject: options.projectName, appDisplayName: options.displayName, appName: options.name, diff --git a/packages/expo/src/generators/application/lib/normalize-options.spec.ts b/packages/expo/src/generators/application/lib/normalize-options.spec.ts index 5ceeb32822f3b..841e51a571223 100644 --- a/packages/expo/src/generators/application/lib/normalize-options.spec.ts +++ b/packages/expo/src/generators/application/lib/normalize-options.spec.ts @@ -13,25 +13,24 @@ describe('Normalize Options', () => { it('should normalize options with name in kebab case', async () => { const schema: Schema = { - name: 'my-app', + directory: 'my-app', linter: Linter.EsLint, e2eTestRunner: 'none', skipFormat: false, js: true, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }; const options = await normalizeOptions(appTree, schema); expect(options).toEqual({ addPlugin: true, appProjectRoot: 'my-app', className: 'MyApp', + directory: 'my-app', displayName: 'MyApp', lowerCaseName: 'myapp', name: 'my-app', parsedTags: [], projectName: 'my-app', - projectNameAndRootFormat: 'as-provided', linter: Linter.EsLint, e2eTestRunner: 'none', unitTestRunner: 'jest', @@ -45,25 +44,24 @@ describe('Normalize Options', () => { it('should normalize options with name in camel case', async () => { const schema: Schema = { - name: 'myApp', + directory: 'myApp', linter: Linter.EsLint, e2eTestRunner: 'none', skipFormat: false, js: true, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }; const options = await normalizeOptions(appTree, schema); expect(options).toEqual({ addPlugin: true, appProjectRoot: 'myApp', className: 'MyApp', + directory: 'myApp', displayName: 'MyApp', lowerCaseName: 'myapp', name: 'myApp', parsedTags: [], projectName: 'myApp', - projectNameAndRootFormat: 'as-provided', linter: Linter.EsLint, e2eTestRunner: 'none', skipFormat: false, @@ -84,7 +82,6 @@ describe('Normalize Options', () => { skipFormat: false, js: true, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }; const options = await normalizeOptions(appTree, schema); expect(options).toEqual({ @@ -97,7 +94,6 @@ describe('Normalize Options', () => { directory: 'directory', parsedTags: [], projectName: 'my-app', - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'none', unitTestRunner: 'jest', linter: Linter.EsLint, @@ -111,25 +107,24 @@ describe('Normalize Options', () => { it('should normalize options that has directory in its name', async () => { const schema: Schema = { - name: 'directory/my-app', + directory: 'directory/my-app', linter: Linter.EsLint, e2eTestRunner: 'none', skipFormat: false, js: true, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }; const options = await normalizeOptions(appTree, schema); expect(options).toEqual({ addPlugin: true, appProjectRoot: 'directory/my-app', - className: 'DirectoryMyApp', - displayName: 'DirectoryMyApp', - lowerCaseName: 'directorymyapp', + className: 'MyApp', + directory: 'directory/my-app', + displayName: 'MyApp', + lowerCaseName: 'myapp', name: 'my-app', parsedTags: [], projectName: 'my-app', - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'none', unitTestRunner: 'jest', linter: Linter.EsLint, @@ -143,26 +138,25 @@ describe('Normalize Options', () => { it('should normalize options with display name', async () => { const schema: Schema = { - name: 'my-app', + directory: 'my-app', displayName: 'My App', linter: Linter.EsLint, e2eTestRunner: 'none', skipFormat: false, js: true, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }; const options = await normalizeOptions(appTree, schema); expect(options).toEqual({ addPlugin: true, appProjectRoot: 'my-app', + directory: 'my-app', className: 'MyApp', displayName: 'My App', lowerCaseName: 'myapp', name: 'my-app', parsedTags: [], projectName: 'my-app', - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'none', unitTestRunner: 'jest', linter: Linter.EsLint, diff --git a/packages/expo/src/generators/application/lib/normalize-options.ts b/packages/expo/src/generators/application/lib/normalize-options.ts index d98b4dbe76a89..f38a267b08270 100644 --- a/packages/expo/src/generators/application/lib/normalize-options.ts +++ b/packages/expo/src/generators/application/lib/normalize-options.ts @@ -1,7 +1,9 @@ import { names, readNxJson, Tree } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Schema } from '../schema'; -import { ExpoPluginOptions } from '../../../../plugins/plugin'; export interface NormalizedSchema extends Schema { className: string; @@ -18,18 +20,16 @@ export async function normalizeOptions( host: Tree, options: Schema ): Promise { + await ensureProjectName(host, options, 'application'); const { projectName: appProjectName, names: projectNames, projectRoot: appProjectRoot, - projectNameAndRootFormat, } = await determineProjectNameAndRootOptions(host, { name: options.name, projectType: 'application', directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); - options.projectNameAndRootFormat = projectNameAndRootFormat; const nxJson = readNxJson(host); const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && diff --git a/packages/expo/src/generators/application/schema.d.ts b/packages/expo/src/generators/application/schema.d.ts index 242f6db05677f..d62942760e071 100644 --- a/packages/expo/src/generators/application/schema.d.ts +++ b/packages/expo/src/generators/application/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { - name: string; + directory: string; + name?: string; displayName?: string; style?: string; skipFormat: boolean; // default is false - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; unitTestRunner: 'jest' | 'none'; // default is jest classComponent?: boolean; diff --git a/packages/expo/src/generators/application/schema.json b/packages/expo/src/generators/application/schema.json index d4358034acc75..bbfcb6875fe6e 100644 --- a/packages/expo/src/generators/application/schema.json +++ b/packages/expo/src/generators/application/schema.json @@ -15,29 +15,24 @@ ], "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" - }, - "displayName": { - "description": "The display name to show in the application. Defaults to name.", - "type": "string" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { + "description": "The name of the application.", "type": "string", + "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] + "displayName": { + "description": "The display name to show in the application. Defaults to name.", + "type": "string" }, "skipFormat": { "description": "Skip formatting files", @@ -90,5 +85,5 @@ "default": false } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/expo/src/generators/component/component.spec.ts b/packages/expo/src/generators/component/component.spec.ts index f6b7e52db2444..004cbb2f0566d 100644 --- a/packages/expo/src/generators/component/component.spec.ts +++ b/packages/expo/src/generators/component/component.spec.ts @@ -29,7 +29,7 @@ describe('component', () => { }; await expoApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', linter: Linter.EsLint, e2eTestRunner: 'none', skipFormat: false, @@ -37,7 +37,7 @@ describe('component', () => { unitTestRunner: 'jest', }); await expoLibraryGenerator(appTree, { - name: projectName, + directory: projectName, linter: Linter.EsLint, skipFormat: false, skipTsConfig: false, diff --git a/packages/expo/src/generators/library/lib/normalize-options.ts b/packages/expo/src/generators/library/lib/normalize-options.ts index b072a56ccfae9..3bd1c67964889 100644 --- a/packages/expo/src/generators/library/lib/normalize-options.ts +++ b/packages/expo/src/generators/library/lib/normalize-options.ts @@ -1,5 +1,8 @@ -import { Tree, readNxJson } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { readNxJson, Tree } from '@nx/devkit'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Schema } from '../schema'; export interface NormalizedSchema extends Schema { @@ -15,6 +18,7 @@ export async function normalizeOptions( host: Tree, options: Schema ): Promise { + await ensureProjectName(host, options, 'library'); const { projectName, names: projectNames, @@ -25,7 +29,6 @@ export async function normalizeOptions( projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); const nxJson = readNxJson(host); const addPluginDefault = diff --git a/packages/expo/src/generators/library/library.spec.ts b/packages/expo/src/generators/library/library.spec.ts index 3272c365e0744..887140b01d750 100644 --- a/packages/expo/src/generators/library/library.spec.ts +++ b/packages/expo/src/generators/library/library.spec.ts @@ -17,7 +17,7 @@ describe('lib', () => { let appTree: Tree; const defaultSchema: Schema = { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, skipFormat: false, skipTsConfig: false, @@ -170,6 +170,7 @@ describe('lib', () => { await expoLibraryGenerator(appTree, { ...defaultSchema, directory: 'my-dir', + name: 'my-lib', }); const tsconfigJson = readJson(appTree, '/tsconfig.base.json'); expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ @@ -383,7 +384,7 @@ describe('lib', () => { try { await expoLibraryGenerator(appTree, { ...defaultSchema, - name: 'my-lib2', + directory: 'my-lib2', publishable: true, importPath: '@myorg/lib', }); diff --git a/packages/expo/src/generators/library/schema.d.ts b/packages/expo/src/generators/library/schema.d.ts index 7ffb5dc8439c2..83ccb2a7cbfe0 100644 --- a/packages/expo/src/generators/library/schema.d.ts +++ b/packages/expo/src/generators/library/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; /** * Same as the @nx/react library schema, except it removes keys: style, component, routing, appProject */ export interface Schema { - name: string; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; + name?: string; skipTsConfig: boolean; // default is false skipFormat: boolean; // default is false tags?: string; diff --git a/packages/expo/src/generators/library/schema.json b/packages/expo/src/generators/library/schema.json index 0f03862cff891..5425019828b83 100644 --- a/packages/expo/src/generators/library/schema.json +++ b/packages/expo/src/generators/library/schema.json @@ -11,26 +11,20 @@ } ], "properties": { - "name": { + "directory": { "type": "string", - "description": "Library name", + "description": "A directory where the lib is placed.", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" + "x-prompt": "Which directory do you want to create the library in?" }, - "directory": { + "name": { "type": "string", - "description": "A directory where the lib is placed.", + "description": "Library name", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -94,5 +88,5 @@ "default": false } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/expo/src/utils/add-linting.spec.ts b/packages/expo/src/utils/add-linting.spec.ts index e6c8cac411c1e..213d72aacfd7a 100644 --- a/packages/expo/src/utils/add-linting.spec.ts +++ b/packages/expo/src/utils/add-linting.spec.ts @@ -12,9 +12,8 @@ describe('Add Linting', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace(); await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.None, - projectNameAndRootFormat: 'as-provided', }); }); diff --git a/packages/express/src/generators/application/application.spec.ts b/packages/express/src/generators/application/application.spec.ts index cbda2842afdd1..954fc1ba1d0e3 100644 --- a/packages/express/src/generators/application/application.spec.ts +++ b/packages/express/src/generators/application/application.spec.ts @@ -12,8 +12,7 @@ describe('app', () => { it('should generate files', async () => { await applicationGenerator(appTree, { - name: 'my-node-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-node-app', } as Schema); const mainFile = appTree.read('my-node-app/src/main.ts').toString(); @@ -79,8 +78,7 @@ describe('app', () => { it('should add types to the tsconfig.app.json', async () => { await applicationGenerator(appTree, { - name: 'my-node-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-node-app', } as Schema); const tsconfig = readJson(appTree, 'my-node-app/tsconfig.app.json'); expect(tsconfig.compilerOptions.types).toContain('express'); @@ -110,9 +108,8 @@ describe('app', () => { describe('--js flag', () => { it('should generate js files instead of ts files', async () => { await applicationGenerator(appTree, { - name: 'my-node-app', + directory: 'my-node-app', js: true, - projectNameAndRootFormat: 'as-provided', } as Schema); expect(appTree.exists('my-node-app/src/main.js')).toBeTruthy(); diff --git a/packages/express/src/generators/application/application.ts b/packages/express/src/generators/application/application.ts index 21e76aa83a36f..594a4bfbb4b7e 100644 --- a/packages/express/src/generators/application/application.ts +++ b/packages/express/src/generators/application/application.ts @@ -7,7 +7,10 @@ import { toJS, updateJson, } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { applicationGenerator as nodeApplicationGenerator } from '@nx/node'; import { tslibVersion } from '@nx/node/src/utils/versions'; import { join } from 'path'; @@ -102,17 +105,13 @@ async function normalizeOptions( host: Tree, options: Schema ): Promise { - const { - projectName: appProjectName, - projectRoot: appProjectRoot, - projectNameAndRootFormat, - } = await determineProjectNameAndRootOptions(host, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - }); - options.projectNameAndRootFormat = projectNameAndRootFormat; + await ensureProjectName(host, options, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(host, { + name: options.name, + projectType: 'application', + directory: options.directory, + }); const nxJson = readNxJson(host); const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' && diff --git a/packages/express/src/generators/application/schema.d.ts b/packages/express/src/generators/application/schema.d.ts index 1aabb58b411a1..7c0353b2bbd9b 100644 --- a/packages/express/src/generators/application/schema.d.ts +++ b/packages/express/src/generators/application/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { UnitTestRunner } from '../../utils/test-runners'; export interface Schema { - name: string; + directory: string; + name?: string; skipFormat: boolean; skipPackageJson: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; unitTestRunner: UnitTestRunner; tags?: string; linter: Linter | LinterType; diff --git a/packages/express/src/generators/application/schema.json b/packages/express/src/generators/application/schema.json index 1b50eaae85320..a8a24d18cab04 100644 --- a/packages/express/src/generators/application/schema.json +++ b/packages/express/src/generators/application/schema.json @@ -6,25 +6,20 @@ "description": "Nx Application Options Schema.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the node application?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { + "description": "The name of the application.", + "pattern": "^[a-zA-Z][^:]*$", "type": "string" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "skipFormat": { "description": "Skip formatting files.", "type": "boolean", @@ -71,17 +66,11 @@ "description": "Generate JavaScript files rather than TypeScript files.", "default": false }, - "standaloneConfig": { - "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`.", - "type": "boolean", - "default": true, - "x-deprecated": "Nx only supports standaloneConfig" - }, "setParserOptionsProject": { "type": "boolean", "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", "default": false } }, - "required": [] + "required": ["directory"] } diff --git a/packages/js/src/generators/convert-to-swc/convert-to-swc.spec.ts b/packages/js/src/generators/convert-to-swc/convert-to-swc.spec.ts index bcfa9bb823b0d..b1d2d8f864e22 100644 --- a/packages/js/src/generators/convert-to-swc/convert-to-swc.spec.ts +++ b/packages/js/src/generators/convert-to-swc/convert-to-swc.spec.ts @@ -10,17 +10,18 @@ import { convertToSwcGenerator } from './convert-to-swc'; describe('convert to swc', () => { let tree: Tree; - const defaultLibGenerationOptions: Omit = { - skipTsConfig: false, - unitTestRunner: 'jest', - skipFormat: false, - linter: 'eslint', - testEnvironment: 'jsdom', - js: false, - strict: true, - config: 'project', - bundler: 'tsc', - }; + const defaultLibGenerationOptions: Omit = + { + skipTsConfig: false, + unitTestRunner: 'jest', + skipFormat: false, + linter: 'eslint', + testEnvironment: 'jsdom', + js: false, + strict: true, + config: 'project', + bundler: 'tsc', + }; beforeAll(() => { tree = createTreeWithEmptyWorkspace(); @@ -31,9 +32,8 @@ describe('convert to swc', () => { it('should convert tsc to swc', async () => { await jsLibraryGenerator(tree, { ...defaultLibGenerationOptions, - name: 'tsc-lib', + directory: 'tsc-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); expect( diff --git a/packages/js/src/generators/library/library.spec.ts b/packages/js/src/generators/library/library.spec.ts index d2b45cb654577..6089f45741361 100644 --- a/packages/js/src/generators/library/library.spec.ts +++ b/packages/js/src/generators/library/library.spec.ts @@ -15,7 +15,7 @@ import type { LibraryGeneratorSchema } from './schema'; describe('lib', () => { let tree: Tree; - const defaultOptions: Omit = { + const defaultOptions: Partial = { skipTsConfig: false, includeBabelRc: false, unitTestRunner: 'jest', @@ -37,9 +37,8 @@ describe('lib', () => { it('should generate an empty ts lib using --config=npm-scripts', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', config: 'npm-scripts', - projectNameAndRootFormat: 'as-provided', }); expect(readJson(tree, '/my-lib/package.json')).toEqual({ name: '@proj/my-lib', @@ -63,9 +62,8 @@ describe('lib', () => { it('should generate an empty ts lib using --config=project', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', config: 'project', - projectNameAndRootFormat: 'as-provided', }); const projectConfig = readProjectConfiguration(tree, 'my-lib'); expect(projectConfig.root).toEqual('my-lib'); @@ -74,9 +72,8 @@ describe('lib', () => { it('should generate an empty ts lib using --config=workspace', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', config: 'workspace', - projectNameAndRootFormat: 'as-provided', }); const projectConfig = readProjectConfiguration(tree, 'my-lib'); expect(projectConfig.root).toEqual('my-lib'); @@ -88,9 +85,8 @@ describe('lib', () => { it('should update tags', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', tags: 'one,two', - projectNameAndRootFormat: 'as-provided', }); const projects = Object.fromEntries(getProjects(tree)); expect(projects).toMatchObject({ @@ -103,8 +99,7 @@ describe('lib', () => { it('should update root tsconfig.base.json', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ @@ -117,8 +112,7 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, 'tsconfig.json'); @@ -135,8 +129,7 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ @@ -147,8 +140,7 @@ describe('lib', () => { it('should create a local tsconfig.json', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, 'my-lib/tsconfig.json'); expect(tsconfigJson).toMatchInlineSnapshot(` @@ -183,8 +175,7 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, 'my-lib/tsconfig.json'); @@ -199,7 +190,6 @@ describe('lib', () => { name: 'my-lib', directory: 'my-dir/my-lib', tags: 'one', - projectNameAndRootFormat: 'as-provided', }); let projects = Object.fromEntries(getProjects(tree)); expect(projects).toMatchObject({ @@ -213,7 +203,6 @@ describe('lib', () => { name: 'my-lib2', directory: 'my-dir/my-lib-2', tags: 'one,two', - projectNameAndRootFormat: 'as-provided', }); projects = Object.fromEntries(getProjects(tree)); expect(projects).toMatchObject({ @@ -231,7 +220,6 @@ describe('lib', () => { ...defaultOptions, name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`my-dir/my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.exists('my-dir/my-lib/src/index.ts')).toBeTruthy(); @@ -250,7 +238,6 @@ describe('lib', () => { name: 'my-lib', directory: 'my-dir/my-lib', config: 'workspace', - projectNameAndRootFormat: 'as-provided', }); expect(readProjectConfiguration(tree, 'my-lib').root).toEqual( @@ -263,7 +250,6 @@ describe('lib', () => { ...defaultOptions, name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ @@ -279,7 +265,6 @@ describe('lib', () => { ...defaultOptions, name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, '/tsconfig.json'); @@ -294,7 +279,6 @@ describe('lib', () => { ...defaultOptions, name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, 'my-dir/my-lib/tsconfig.json'); @@ -313,7 +297,6 @@ describe('lib', () => { ...defaultOptions, name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, 'my-dir/my-lib/tsconfig.json'); @@ -327,7 +310,6 @@ describe('lib', () => { ...defaultOptions, name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, 'my-dir/my-lib/tsconfig.json'); @@ -339,9 +321,8 @@ describe('lib', () => { it('should update the projects tsconfig with strict false', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', strict: false, - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, '/my-lib/tsconfig.json'); @@ -366,8 +347,7 @@ describe('lib', () => { it('should default to strict true', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, '/my-lib/tsconfig.json'); @@ -389,7 +369,6 @@ describe('lib', () => { name: 'my-lib', directory: 'my-dir/my-lib', importPath: '@myorg/lib', - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); @@ -399,17 +378,15 @@ describe('lib', () => { it('should fail if the same importPath has already been used', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'myLib1', + directory: 'myLib1', importPath: '@myorg/lib', - projectNameAndRootFormat: 'as-provided', }); try { await libraryGenerator(tree, { ...defaultOptions, - name: 'myLib2', + directory: 'myLib2', importPath: '@myorg/lib', - projectNameAndRootFormat: 'as-provided', }); } catch (e) { expect(e.message).toContain( @@ -423,8 +400,7 @@ describe('lib', () => { it('should provide a default import path using npm scope', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); @@ -440,9 +416,8 @@ describe('lib', () => { }); await libraryGenerator(tree, { ...defaultOptions, - rootProject: true, name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: '.', }); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); @@ -455,8 +430,7 @@ describe('lib', () => { it('should add eslint dependencies', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const packageJson = readJson(tree, 'package.json'); @@ -469,8 +443,7 @@ describe('lib', () => { it('should create a local .eslintrc.json', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const eslintJson = readJson(tree, 'my-lib/.eslintrc.json'); @@ -534,7 +507,6 @@ describe('lib', () => { ...defaultOptions, name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); const eslintJson = readJson(tree, 'my-dir/my-lib/.eslintrc.json'); @@ -596,9 +568,8 @@ describe('lib', () => { it('should generate js files instead of ts files', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', js: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`my-lib/jest.config.js`)).toBeTruthy(); expect(tree.exists('my-lib/src/index.js')).toBeTruthy(); @@ -609,9 +580,8 @@ describe('lib', () => { it('should update tsconfig.json with compilerOptions.allowJs: true', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', js: true, - projectNameAndRootFormat: 'as-provided', }); expect( readJson(tree, 'my-lib/tsconfig.json').compilerOptions.allowJs @@ -621,9 +591,8 @@ describe('lib', () => { it('should update tsconfig.lib.json include with src/**/*.js glob', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', js: true, - projectNameAndRootFormat: 'as-provided', }); expect(readJson(tree, 'my-lib/tsconfig.lib.json').include).toEqual([ 'src/**/*.ts', @@ -634,9 +603,8 @@ describe('lib', () => { it('should update root tsconfig.json with a js file path', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', js: true, - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ @@ -650,7 +618,6 @@ describe('lib', () => { name: 'my-lib', directory: 'my-dir/my-lib', js: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`my-dir/my-lib/jest.config.js`)).toBeTruthy(); expect(tree.exists('my-dir/my-lib/src/index.js')).toBeTruthy(); @@ -667,7 +634,6 @@ describe('lib', () => { name: 'my-lib', directory: 'my-dir/my-lib', js: true, - projectNameAndRootFormat: 'as-provided', }); expect(readJson(tree, 'my-dir/my-lib/.eslintrc.json')) .toMatchInlineSnapshot(` @@ -729,9 +695,8 @@ describe('lib', () => { it('should generate test configuration', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/tsconfig.spec.json')).toBeTruthy(); @@ -759,11 +724,10 @@ describe('lib', () => { it('should generate test configuration with swc and js', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', unitTestRunner: 'jest', bundler: 'swc', js: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/tsconfig.spec.json')).toBeTruthy(); @@ -780,9 +744,8 @@ describe('lib', () => { it('should NOT generate the build target if bundler is none', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'none', - projectNameAndRootFormat: 'as-provided', }); const config = readProjectConfiguration(tree, 'my-lib'); @@ -792,8 +755,7 @@ describe('lib', () => { it('should still generate the build target if bundler is undefined', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const config = readProjectConfiguration(tree, 'my-lib'); @@ -803,9 +765,8 @@ describe('lib', () => { it('should generate the build target', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const config = readProjectConfiguration(tree, 'my-lib'); @@ -824,9 +785,8 @@ describe('lib', () => { it('should generate the build target for swc', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'swc', - projectNameAndRootFormat: 'as-provided', }); const config = readProjectConfiguration(tree, 'my-lib'); @@ -845,9 +805,8 @@ describe('lib', () => { it('should generate swcrc for swc', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'swc', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/.swcrc')).toBeTruthy(); @@ -856,9 +815,8 @@ describe('lib', () => { it('should setup jest project using swc', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'swc', - projectNameAndRootFormat: 'as-provided', }); const jestConfig = tree.read('my-lib/jest.config.ts').toString(); @@ -868,9 +826,8 @@ describe('lib', () => { it('should generate a package.json file', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/package.json')).toBeTruthy(); @@ -881,10 +838,9 @@ describe('lib', () => { it('should generate the build target', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', buildable: true, compiler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const config = readProjectConfiguration(tree, 'my-lib'); @@ -903,10 +859,9 @@ describe('lib', () => { it('should generate the build target for swc', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', buildable: true, compiler: 'swc', - projectNameAndRootFormat: 'as-provided', }); const config = readProjectConfiguration(tree, 'my-lib'); @@ -925,10 +880,9 @@ describe('lib', () => { it('should generate swcrc for swc', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', buildable: true, compiler: 'swc', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/.swcrc')).toBeTruthy(); @@ -937,10 +891,9 @@ describe('lib', () => { it('should setup jest project using swc', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', buildable: true, compiler: 'swc', - projectNameAndRootFormat: 'as-provided', }); const jestConfig = tree.read('my-lib/jest.config.ts').toString(); @@ -950,10 +903,9 @@ describe('lib', () => { it('should generate a package.json file', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', buildable: true, compiler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/package.json')).toBeTruthy(); @@ -964,9 +916,8 @@ describe('lib', () => { it('should generate correct options for build', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'rollup', - projectNameAndRootFormat: 'as-provided', }); const pkgJson = readJson(tree, 'my-lib/package.json'); @@ -976,9 +927,8 @@ describe('lib', () => { it('should always set compiler to swc if bundler is rollup', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'rollup', - projectNameAndRootFormat: 'as-provided', }); }); }); @@ -987,11 +937,10 @@ describe('lib', () => { it('should generate the build target', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const config = readProjectConfiguration(tree, 'my-lib'); @@ -1010,11 +959,10 @@ describe('lib', () => { it('should update the nx-release-publish target to specify dist/{projectRoot} as the package root', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const config = readProjectConfiguration(tree, 'my-lib'); @@ -1038,11 +986,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const nxJson = readJson(tree, 'nx.json'); @@ -1061,11 +1008,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const nxJson = readJson(tree, 'nx.json'); @@ -1094,11 +1040,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const nxJson = readJson(tree, 'nx.json'); @@ -1123,11 +1068,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const nxJson = readJson(tree, 'nx.json'); @@ -1151,11 +1095,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const nxJson = readJson(tree, 'nx.json'); @@ -1179,11 +1122,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', tags: 'one,two', }); @@ -1212,7 +1154,6 @@ describe('lib', () => { publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', directory: 'packages/my-lib', }); @@ -1237,11 +1178,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const nxJson = readJson(tree, 'nx.json'); @@ -1265,11 +1205,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const nxJson = readJson(tree, 'nx.json'); @@ -1301,11 +1240,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const nxJson = readJson(tree, 'nx.json'); @@ -1343,11 +1281,10 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath: '@proj/my-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const nxJson = readJson(tree, 'nx.json'); @@ -1375,9 +1312,8 @@ describe('lib', () => { it('should generate a .babelrc when flag is set to true', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', includeBabelRc: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/.babelrc')).toBeTruthy(); @@ -1386,9 +1322,8 @@ describe('lib', () => { it('should not generate a .babelrc when flag is set to false', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', includeBabelRc: false, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/.babelrc')).toBeFalsy(); @@ -1397,10 +1332,9 @@ describe('lib', () => { it('should not generate a .babelrc when bundler is swc (even if flag is set to true)', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'swc', includeBabelRc: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/.babelrc')).toBeFalsy(); @@ -1414,9 +1348,8 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', includeBabelRc: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/.babelrc')).toBeTruthy(); @@ -1447,9 +1380,8 @@ describe('lib', () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', includeBabelRc: undefined, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/.babelrc')).toBeFalsy(); @@ -1461,10 +1393,9 @@ describe('lib', () => { it('should add build with esbuild', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'esbuild', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); const project = readProjectConfiguration(tree, 'my-lib'); @@ -1493,10 +1424,9 @@ describe('lib', () => { it('should add build with rollup', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'rollup', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); expect(readJson(tree, 'my-lib/.eslintrc.json').overrides).toContainEqual({ @@ -1521,9 +1451,8 @@ describe('lib', () => { it('should generate a README.md when minimal is set to false', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', minimal: false, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/README.md')).toBeTruthy(); @@ -1532,9 +1461,8 @@ describe('lib', () => { it('should not generate a README.md when minimal is set to true', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', minimal: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/README.md')).toBeFalsy(); @@ -1543,10 +1471,9 @@ describe('lib', () => { it('should generate a README.md and add it to the build assets when buildable is true and minimal is false', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'tsc', minimal: false, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/README.md')).toBeTruthy(); @@ -1560,10 +1487,9 @@ describe('lib', () => { it('should not generate a README.md when both bundler and minimal are set', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'tsc', minimal: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/README.md')).toBeFalsy(); @@ -1580,7 +1506,6 @@ describe('lib', () => { name: 'my-lib', simpleName: true, directory: 'web/my-lib', - projectNameAndRootFormat: 'as-provided', }); expect(tree.read('web/my-lib/src/index.ts', 'utf-8')).toContain( @@ -1594,7 +1519,7 @@ describe('lib', () => { it('should generate a vite config with testEnvironment set to node', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-node-lib', + directory: 'my-node-lib', unitTestRunner: 'vitest', testEnvironment: 'node', }); @@ -1607,7 +1532,7 @@ describe('lib', () => { it('should generate a vite config with testEnvironment set to jsdom by default', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-jsdom-lib', + directory: 'my-jsdom-lib', unitTestRunner: 'vitest', testEnvironment: undefined, }); @@ -1622,12 +1547,11 @@ describe('lib', () => { it('should generate the nx configuration in the package.json file when using --useProjectJson=false', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'none', linter: 'none', unitTestRunner: 'none', useProjectJson: false, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/project.json')).toBe(false); @@ -1647,10 +1571,9 @@ describe('lib', () => { it('should generate the nx configuration in the project.json file when using --useProjectJson=true', async () => { await libraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'none', useProjectJson: true, - projectNameAndRootFormat: 'as-provided', }); expect(readJson(tree, 'my-lib/project.json')).toMatchInlineSnapshot(` diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 26a6d99ee5716..3d59cec6ec0ac 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -22,7 +22,11 @@ import { updateProjectConfiguration, writeJson, } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; + import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils'; import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command'; import { prompt } from 'enquirer'; @@ -690,6 +694,7 @@ async function normalizeOptions( tree: Tree, options: LibraryGeneratorSchema ): Promise { + await ensureProjectName(tree, options, 'library'); const nxJson = readNxJson(tree); options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false' && @@ -871,7 +876,6 @@ async function normalizeOptions( projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, rootProject: options.rootProject, }); options.rootProject = projectRoot === '.'; diff --git a/packages/js/src/generators/library/schema.d.ts b/packages/js/src/generators/library/schema.d.ts index d50cafce2386d..8b77ff9062a79 100644 --- a/packages/js/src/generators/library/schema.d.ts +++ b/packages/js/src/generators/library/schema.d.ts @@ -10,8 +10,8 @@ export type Compiler = 'tsc' | 'swc'; export type Bundler = 'swc' | 'tsc' | 'rollup' | 'vite' | 'esbuild' | 'none'; export interface LibraryGeneratorSchema { - name: string; - directory?: string; + directory: string; + name?: string; projectNameAndRootFormat?: ProjectNameAndRootFormat; skipFormat?: boolean; tags?: string; diff --git a/packages/js/src/generators/library/schema.json b/packages/js/src/generators/library/schema.json index 4c7af83132d1b..04cecb924f83e 100644 --- a/packages/js/src/generators/library/schema.json +++ b/packages/js/src/generators/library/schema.json @@ -6,19 +6,18 @@ "description": "Create a TypeScript Library.", "type": "object", "properties": { - "name": { + "directory": { "type": "string", - "description": "Library name.", + "description": "A directory where the lib is placed.", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" + "x-prompt": "Which directory do you want to create the library in?" }, - "directory": { + "name": { "type": "string", - "description": "A directory where the lib is placed.", + "description": "Library name.", "x-priority": "important" }, "bundler": { @@ -39,11 +38,6 @@ "enum": ["none", "jest", "vitest"], "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "tags": { "type": "string", "description": "Add tags to the library (used for linting)." @@ -141,6 +135,6 @@ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file." } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "../../../docs/library-examples.md" } diff --git a/packages/nest/src/generators/application/application.spec.ts b/packages/nest/src/generators/application/application.spec.ts index 9d07d119fff43..9bb132cc26458 100644 --- a/packages/nest/src/generators/application/application.spec.ts +++ b/packages/nest/src/generators/application/application.spec.ts @@ -5,7 +5,6 @@ import { applicationGenerator } from './application'; describe('application generator', () => { let tree: Tree; - const appName = 'my-node-app'; const appDirectory = 'my-node-app'; beforeEach(() => { @@ -15,8 +14,7 @@ describe('application generator', () => { it('should generate project configurations', async () => { await applicationGenerator(tree, { - name: appName, - projectNameAndRootFormat: 'as-provided', + directory: appDirectory, }); const projectConfigurations = devkit.getProjects(tree); @@ -27,8 +25,7 @@ describe('application generator', () => { it('should generate files', async () => { await applicationGenerator(tree, { - name: appName, - projectNameAndRootFormat: 'as-provided', + directory: appDirectory, }); expect(tree.exists(`${appDirectory}/src/main.ts`)).toBeTruthy(); @@ -47,8 +44,7 @@ describe('application generator', () => { it('should configure tsconfig correctly', async () => { await applicationGenerator(tree, { - name: appName, - projectNameAndRootFormat: 'as-provided', + directory: appDirectory, }); const tsConfig = devkit.readJson(tree, `${appDirectory}/tsconfig.app.json`); @@ -63,9 +59,8 @@ describe('application generator', () => { it('should add strict checks with --strict', async () => { await applicationGenerator(tree, { - name: appName, + directory: appDirectory, strict: true, - projectNameAndRootFormat: 'as-provided', }); const tsConfig = devkit.readJson(tree, `${appDirectory}/tsconfig.app.json`); @@ -83,8 +78,7 @@ describe('application generator', () => { jest.spyOn(devkit, 'formatFiles'); await applicationGenerator(tree, { - name: appName, - projectNameAndRootFormat: 'as-provided', + directory: appDirectory, }); expect(devkit.formatFiles).toHaveBeenCalled(); @@ -94,9 +88,8 @@ describe('application generator', () => { jest.spyOn(devkit, 'formatFiles'); await applicationGenerator(tree, { - name: appName, + directory: appDirectory, skipFormat: true, - projectNameAndRootFormat: 'as-provided', }); expect(devkit.formatFiles).not.toHaveBeenCalled(); @@ -106,9 +99,8 @@ describe('application generator', () => { describe('--e2e-test-runner none', () => { it('should not generate e2e test project', async () => { await applicationGenerator(tree, { - name: appName, + directory: appDirectory, e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); const projectConfigurations = devkit.getProjects(tree); diff --git a/packages/nest/src/generators/application/lib/normalize-options.ts b/packages/nest/src/generators/application/lib/normalize-options.ts index 3636f3b72d7f7..e1b30132fd86e 100644 --- a/packages/nest/src/generators/application/lib/normalize-options.ts +++ b/packages/nest/src/generators/application/lib/normalize-options.ts @@ -1,5 +1,8 @@ import { Tree, readNxJson } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Linter } from '@nx/eslint'; import type { Schema as NodeApplicationGeneratorOptions } from '@nx/node/src/generators/application/schema'; import type { ApplicationGeneratorOptions, NormalizedOptions } from '../schema'; @@ -8,19 +11,15 @@ export async function normalizeOptions( tree: Tree, options: ApplicationGeneratorOptions ): Promise { - const { - projectName: appProjectName, - projectRoot: appProjectRoot, - projectNameAndRootFormat, - } = await determineProjectNameAndRootOptions(tree, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - rootProject: options.rootProject, - }); + await ensureProjectName(tree, options, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(tree, { + name: options.name, + projectType: 'application', + directory: options.directory, + rootProject: options.rootProject, + }); options.rootProject = appProjectRoot === '.'; - options.projectNameAndRootFormat = projectNameAndRootFormat; const nxJson = readNxJson(tree); const addPlugin = @@ -46,7 +45,6 @@ export function toNodeApplicationGeneratorOptions( name: options.name, directory: options.directory, frontendProject: options.frontendProject, - projectNameAndRootFormat: options.projectNameAndRootFormat, linter: options.linter, skipFormat: true, skipPackageJson: options.skipPackageJson, diff --git a/packages/nest/src/generators/application/schema.d.ts b/packages/nest/src/generators/application/schema.d.ts index 79f86a024e0bb..05d781e9d612f 100644 --- a/packages/nest/src/generators/application/schema.d.ts +++ b/packages/nest/src/generators/application/schema.d.ts @@ -1,10 +1,8 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface ApplicationGeneratorOptions { - name: string; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; + name?: string; frontendProject?: string; linter?: Linter | LinterType; skipFormat?: boolean; diff --git a/packages/nest/src/generators/application/schema.json b/packages/nest/src/generators/application/schema.json index f75c0487da7eb..f74ea1d563a71 100644 --- a/packages/nest/src/generators/application/schema.json +++ b/packages/nest/src/generators/application/schema.json @@ -6,24 +6,20 @@ "cli": "nx", "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the node application?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", - "type": "string" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "skipFormat": { "description": "Skip formatting files.", @@ -82,5 +78,5 @@ } }, "additionalProperties": false, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/nest/src/generators/library/lib/normalize-options.ts b/packages/nest/src/generators/library/lib/normalize-options.ts index 5f15e9c8fbec9..f3b84309e0ef7 100644 --- a/packages/nest/src/generators/library/lib/normalize-options.ts +++ b/packages/nest/src/generators/library/lib/normalize-options.ts @@ -1,5 +1,8 @@ import { Tree, readNxJson } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { getNpmScope } from '@nx/js/src/utils/package-json/get-npm-scope'; import type { LibraryGeneratorSchema as JsLibraryGeneratorSchema } from '@nx/js/src/generators/library/schema'; import { Linter } from '@nx/eslint'; @@ -9,6 +12,7 @@ export async function normalizeOptions( tree: Tree, options: LibraryGeneratorOptions ): Promise { + await ensureProjectName(tree, options, 'library'); const { projectName, names: projectNames, @@ -19,7 +23,6 @@ export async function normalizeOptions( projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); const nxJson = readNxJson(tree); const addPlugin = @@ -75,7 +78,6 @@ export function toJsLibraryGeneratorOptions( unitTestRunner: options.unitTestRunner, config: options.standaloneConfig ? 'project' : 'workspace', setParserOptionsProject: options.setParserOptionsProject, - projectNameAndRootFormat: options.projectNameAndRootFormat, addPlugin: options.addPlugin, }; } diff --git a/packages/nest/src/generators/library/library.spec.ts b/packages/nest/src/generators/library/library.spec.ts index cec5efab34155..e71093a8ae464 100644 --- a/packages/nest/src/generators/library/library.spec.ts +++ b/packages/nest/src/generators/library/library.spec.ts @@ -15,8 +15,7 @@ describe('lib', () => { describe('not nested', () => { it('should update project configuration', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', addPlugin: true, }); @@ -36,9 +35,8 @@ describe('lib', () => { it('should include a controller', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', controller: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`my-lib/src/lib/my-lib.controller.ts`)).toBeTruthy(); @@ -46,9 +44,8 @@ describe('lib', () => { it('should include a service', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', service: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`my-lib/src/lib/my-lib.service.ts`)).toBeTruthy(); @@ -56,9 +53,8 @@ describe('lib', () => { it('should add the @Global decorator', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', global: true, - projectNameAndRootFormat: 'as-provided', }); expect( @@ -68,9 +64,8 @@ describe('lib', () => { it('should remove the default file from @nx/node:lib', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', global: true, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`my-lib/src/lib/my-lib.spec.ts`)).toBeFalsy(); @@ -79,10 +74,9 @@ describe('lib', () => { it('should provide the controller and service', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', controller: true, service: true, - projectNameAndRootFormat: 'as-provided', }); expect( @@ -96,9 +90,8 @@ describe('lib', () => { it('should update tags', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', tags: 'one,two', - projectNameAndRootFormat: 'as-provided', }); const projects = Object.fromEntries(devkit.getProjects(tree)); @@ -111,8 +104,7 @@ describe('lib', () => { it('should update root tsconfig.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); @@ -123,8 +115,7 @@ describe('lib', () => { it('should create a local tsconfig.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, `my-lib/tsconfig.json`); @@ -133,8 +124,7 @@ describe('lib', () => { it('should extend the local tsconfig.json with tsconfig.spec.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, `my-lib/tsconfig.spec.json`); @@ -143,8 +133,7 @@ describe('lib', () => { it('should extend the local tsconfig.json with tsconfig.lib.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, `my-lib/tsconfig.lib.json`); @@ -158,8 +147,7 @@ describe('lib', () => { it('should generate files', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); expect(tree.exists(`my-lib/jest.config.ts`)).toBeTruthy(); @@ -172,10 +160,8 @@ describe('lib', () => { describe('nested', () => { it('should update tags', async () => { await libraryGenerator(tree, { - name: 'my-lib', directory: 'my-dir/my-lib', tags: 'one,two', - projectNameAndRootFormat: 'as-provided', }); const projects = Object.fromEntries(devkit.getProjects(tree)); @@ -188,9 +174,7 @@ describe('lib', () => { it('should generate files', async () => { await libraryGenerator(tree, { - name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`my-dir/my-lib/jest.config.ts`)).toBeTruthy(); @@ -200,9 +184,7 @@ describe('lib', () => { it('should update tsconfig.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); @@ -214,9 +196,7 @@ describe('lib', () => { it('should create a local tsconfig.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', }); expect(readJson(tree, `my-dir/my-lib/tsconfig.json`)).toMatchSnapshot(); @@ -226,9 +206,8 @@ describe('lib', () => { describe('--strict', () => { it('should update the projects tsconfig with strict true', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', strict: true, - projectNameAndRootFormat: 'as-provided', }); const tsConfig = readJson(tree, `/my-lib/tsconfig.lib.json`); @@ -245,9 +224,8 @@ describe('lib', () => { describe('--unit-test-runner none', () => { it('should not generate test configuration', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`my-lib/tsconfig.spec.json`)).toBeFalsy(); @@ -262,10 +240,9 @@ describe('lib', () => { const importPath = `@proj/myLib`; await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', publishable: true, importPath, - projectNameAndRootFormat: 'as-provided', }); const packageJson = readJson(tree, `my-lib/package.json`); @@ -276,8 +253,7 @@ describe('lib', () => { describe('compiler options target', () => { it('should set target to es6 in tsconfig.lib.json by default', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const tsconfigJson = readJson(tree, `my-lib/tsconfig.lib.json`); @@ -286,9 +262,8 @@ describe('lib', () => { it('should set target to es2021 in tsconfig.lib.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', target: 'es2021', - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, `my-lib/tsconfig.lib.json`); @@ -301,8 +276,7 @@ describe('lib', () => { jest.spyOn(devkit, 'formatFiles'); await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); expect(devkit.formatFiles).toHaveBeenCalled(); @@ -312,9 +286,8 @@ describe('lib', () => { jest.spyOn(devkit, 'formatFiles'); await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', skipFormat: true, - projectNameAndRootFormat: 'as-provided', }); expect(devkit.formatFiles).not.toHaveBeenCalled(); @@ -324,8 +297,7 @@ describe('lib', () => { describe('--testEnvironment', () => { it('should set target jest testEnvironment to node by default', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); expect(tree.read(`my-lib/jest.config.ts`, 'utf-8')).toMatchSnapshot(); @@ -333,9 +305,8 @@ describe('lib', () => { it('should set target jest testEnvironment to jsdom', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', testEnvironment: 'jsdom', - projectNameAndRootFormat: 'as-provided', }); expect(tree.read(`my-lib/jest.config.ts`, 'utf-8')).toMatchSnapshot(); @@ -345,12 +316,10 @@ describe('lib', () => { describe('--simpleName', () => { it('should generate a library with a simple name', async () => { await libraryGenerator(tree, { - name: 'my-lib', simpleName: true, directory: 'api/my-lib', service: true, controller: true, - projectNameAndRootFormat: 'as-provided', }); const indexFile = tree.read('api/my-lib/src/index.ts', 'utf-8'); diff --git a/packages/nest/src/generators/library/schema.d.ts b/packages/nest/src/generators/library/schema.d.ts index 32e2c032198b1..1339b791f8cb6 100644 --- a/packages/nest/src/generators/library/schema.d.ts +++ b/packages/nest/src/generators/library/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { UnitTestRunner } from '../utils'; export interface LibraryGeneratorOptions { - name: string; + directory: string; + name?: string; buildable?: boolean; controller?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; global?: boolean; importPath?: string; linter?: Linter | LinterType; diff --git a/packages/nest/src/generators/library/schema.json b/packages/nest/src/generators/library/schema.json index 3af2b19519e0c..63e70db440af0 100644 --- a/packages/nest/src/generators/library/schema.json +++ b/packages/nest/src/generators/library/schema.json @@ -12,25 +12,20 @@ } ], "properties": { - "name": { - "description": "Library name.", + "directory": { + "description": "A directory where the library is placed.", "type": "string", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" - }, - "directory": { - "description": "A directory where the library is placed.", - "type": "string", - "alias": "dir" + "x-prompt": "Which directory do you want to create the library in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided"] + "name": { + "description": "Library name.", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", + "type": "string" }, "linter": { "description": "The tool to use for running lint checks.", @@ -143,5 +138,5 @@ } }, "additionalProperties": false, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/next/src/generators/application/application.spec.ts b/packages/next/src/generators/application/application.spec.ts index 677ab1328edb2..efd890f613c52 100644 --- a/packages/next/src/generators/application/application.spec.ts +++ b/packages/next/src/generators/application/application.spec.ts @@ -21,9 +21,8 @@ describe('app', () => { it('should add a .gitkeep file to the public directory', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`${name}/public/.gitkeep`)).toBe(true); @@ -32,10 +31,9 @@ describe('app', () => { it('should update tags and implicit dependencies', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', tags: 'one,two', - projectNameAndRootFormat: 'as-provided', }); const projects = Object.fromEntries(getProjects(tree)); @@ -56,9 +54,8 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); const tsConfig = readJson(tree, `${name}/tsconfig.json`); @@ -69,9 +66,8 @@ describe('app', () => { it('should generate files for app layout', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); const tsConfig = readJson(tree, `${name}/tsconfig.json`); @@ -97,10 +93,9 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { name, + directory: '.', style: 'css', appDir: true, - rootProject: true, - projectNameAndRootFormat: 'as-provided', }); const tsConfig = readJson(tree, 'tsconfig.json'); @@ -119,10 +114,9 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { name, + directory: '.', style: 'none', appDir: true, - rootProject: true, - projectNameAndRootFormat: 'as-provided', }); const content = tree.read('src/app/page.tsx').toString(); @@ -137,11 +131,10 @@ describe('app', () => { it('should generate files for pages layout', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', appDir: false, src: false, - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`${name}/tsconfig.json`)).toBeTruthy(); expect(tree.exists(`${name}/pages/index.tsx`)).toBeTruthy(); @@ -152,9 +145,8 @@ describe('app', () => { it('should update configurations', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); expect(readProjectConfiguration(tree, name).root).toEqual(name); @@ -166,11 +158,10 @@ describe('app', () => { it('should generate an unstyled component page', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'none', appDir: false, src: false, - projectNameAndRootFormat: 'as-provided', }); const content = tree.read(`${name}/pages/index.tsx`).toString(); @@ -185,9 +176,8 @@ describe('app', () => { it('should generate scss styles', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'scss', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`${name}/src/app/page.module.scss`)).toBeTruthy(); @@ -224,9 +214,8 @@ describe('app', () => { it('should generate less styles', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'less', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`${name}/src/app/page.module.less`)).toBeTruthy(); @@ -263,9 +252,8 @@ describe('app', () => { it('should generate styled-components styles', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'styled-components', - projectNameAndRootFormat: 'as-provided', }); expect( @@ -347,9 +335,8 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: '@emotion/styled', - projectNameAndRootFormat: 'as-provided', }); expect( @@ -369,9 +356,8 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: '@emotion/styled', - projectNameAndRootFormat: 'as-provided', }); const tsconfigJson = readJson(tree, `${name}/tsconfig.json`); @@ -387,9 +373,8 @@ describe('app', () => { const name = 'my-app'; await applicationGenerator(tree, { - name, + directory: name, style: 'styled-jsx', - projectNameAndRootFormat: 'as-provided', }); const indexContent = tree.read(`${name}/src/app/page.tsx`, 'utf-8'); @@ -452,9 +437,8 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); expect(tree.read(`${name}/jest.config.ts`, 'utf-8')).toContain( @@ -466,9 +450,8 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); expect(tree.read(`${name}/jest.config.ts`, 'utf-8')).toContain( @@ -480,9 +463,8 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); expect(tree.read(join(name, 'next.config.js'), 'utf-8')) @@ -517,10 +499,9 @@ describe('app', () => { it('should not generate test configuration', async () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('jest.config.ts')).toBeFalsy(); expect(tree.exists(`${name}/specs/index.spec.tsx`)).toBeFalsy(); @@ -532,10 +513,9 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists(`${name}-e2e`)).toBeFalsy(); }); @@ -546,10 +526,9 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', e2eTestRunner: 'cypress', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(readNxJson(tree).targetDefaults['e2e-ci--**/*']) @@ -568,10 +547,9 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', e2eTestRunner: 'playwright', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(readNxJson(tree).targetDefaults['e2e-ci--**/*']) @@ -589,9 +567,8 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); const appContent = tree.read(`${name}/src/app/page.tsx`, 'utf-8'); @@ -606,9 +583,8 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); expect(tree.read(`${name}/eslint.config.js`, 'utf-8')) @@ -638,9 +614,8 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', }); const packageJson = readJson(tree, '/package.json'); @@ -705,10 +680,9 @@ describe('app', () => { await applicationGenerator(tree, { name, + directory: '.', style: 'css', appDir: true, - rootProject: true, - projectNameAndRootFormat: 'as-provided', }); const eslintJSON = readJson(tree, '.eslintrc.json'); @@ -730,10 +704,9 @@ describe('app', () => { await applicationGenerator(tree, { name, + directory: '.', style: 'css', appDir: true, - rootProject: true, - projectNameAndRootFormat: 'as-provided', src: true, }); @@ -755,10 +728,9 @@ describe('app', () => { await applicationGenerator(tree, { name, + directory: '.', style: 'css', appDir: true, - rootProject: true, - projectNameAndRootFormat: 'as-provided', src: false, }); @@ -780,10 +752,9 @@ describe('app', () => { await applicationGenerator(tree, { name, + directory: '.', style: 'css', appDir: false, - rootProject: true, - projectNameAndRootFormat: 'as-provided', src: false, }); @@ -804,7 +775,7 @@ describe('app', () => { const name = uniq(); await applicationGenerator(tree, { - name, + directory: name, style: 'css', js: true, }); @@ -829,12 +800,11 @@ describe('app (legacy)', () => { let originalEnv; const schema: Schema = { - name: 'app', + directory: 'app', appDir: true, unitTestRunner: 'jest', style: 'css', e2eTestRunner: 'cypress', - projectNameAndRootFormat: 'as-provided', }; beforeAll(() => { diff --git a/packages/next/src/generators/application/lib/add-linting.spec.ts b/packages/next/src/generators/application/lib/add-linting.spec.ts index e123896686cd5..cba4e0f3d2099 100644 --- a/packages/next/src/generators/application/lib/add-linting.spec.ts +++ b/packages/next/src/generators/application/lib/add-linting.spec.ts @@ -17,6 +17,7 @@ describe('updateEslint', () => { schema = { projectName: 'my-app', appProjectRoot: 'my-app', + directory: 'my-app', linter: Linter.EsLint, unitTestRunner: 'jest', e2eProjectName: 'my-app-e2e', @@ -27,7 +28,6 @@ describe('updateEslint', () => { fileName: 'index', e2eTestRunner: 'cypress', styledModule: null, - projectNameAndRootFormat: 'as-provided', }; tree = createTreeWithEmptyWorkspace(); const project: ProjectConfiguration = { diff --git a/packages/next/src/generators/application/lib/normalize-options.ts b/packages/next/src/generators/application/lib/normalize-options.ts index f34e6e8dc53f6..5b8782ed724d3 100644 --- a/packages/next/src/generators/application/lib/normalize-options.ts +++ b/packages/next/src/generators/application/lib/normalize-options.ts @@ -1,9 +1,11 @@ import { joinPathFragments, names, readNxJson, Tree } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Linter } from '@nx/eslint'; import { assertValidStyle } from '@nx/react/src/utils/assertion'; import { Schema } from '../schema'; -import { NextPluginOptions } from '../../../plugins/plugin'; export interface NormalizedSchema extends Schema { projectName: string; @@ -21,19 +23,15 @@ export async function normalizeOptions( host: Tree, options: Schema ): Promise { - const { - projectName: appProjectName, - projectRoot: appProjectRoot, - projectNameAndRootFormat, - } = await determineProjectNameAndRootOptions(host, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - rootProject: options.rootProject, - }); + await ensureProjectName(host, options, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(host, { + name: options.name, + projectType: 'application', + directory: options.directory, + rootProject: options.rootProject, + }); options.rootProject = appProjectRoot === '.'; - options.projectNameAndRootFormat = projectNameAndRootFormat; const nxJson = readNxJson(host); const addPlugin = diff --git a/packages/next/src/generators/application/schema.d.ts b/packages/next/src/generators/application/schema.d.ts index b1e865f2fe7d0..205f3ed4d1467 100644 --- a/packages/next/src/generators/application/schema.d.ts +++ b/packages/next/src/generators/application/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { SupportedStyles } from '@nx/react'; export interface Schema { - name: string; + directory: string; + name?: string; style?: SupportedStyles; skipFormat?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; unitTestRunner?: 'jest' | 'none'; e2eTestRunner?: 'cypress' | 'playwright' | 'none'; diff --git a/packages/next/src/generators/application/schema.json b/packages/next/src/generators/application/schema.json index 57fa43c312f86..b9a0a81af2a33 100644 --- a/packages/next/src/generators/application/schema.json +++ b/packages/next/src/generators/application/schema.json @@ -6,28 +6,22 @@ "description": "Create a Next.js Application for Nx.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { + "description": "The name of the application.", "type": "string", - "alias": "dir", + "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -37,7 +31,10 @@ "message": "Which stylesheet format would you like to use?", "type": "list", "items": [ - { "value": "css", "label": "CSS" }, + { + "value": "css", + "label": "CSS" + }, { "value": "scss", "label": "SASS(.scss) [ https://sass-lang.com ]" @@ -145,6 +142,6 @@ "x-priority": "internal" } }, - "required": [], + "required": ["directory"], "examplesFile": "../../../docs/application-examples.md" } diff --git a/packages/next/src/generators/component/component.spec.ts b/packages/next/src/generators/component/component.spec.ts index 9c6533f3b8d70..7ee0934f6b802 100644 --- a/packages/next/src/generators/component/component.spec.ts +++ b/packages/next/src/generators/component/component.spec.ts @@ -13,18 +13,16 @@ describe('component', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace(); await applicationGenerator(tree, { - name: appName, + directory: appName, style: 'css', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { - name: libName, + directory: libName, linter: Linter.EsLint, style: 'css', skipFormat: true, skipTsConfig: false, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }); }); diff --git a/packages/next/src/generators/custom-server/custom-server.spec.ts b/packages/next/src/generators/custom-server/custom-server.spec.ts index 46d082189610b..cd5472b304664 100644 --- a/packages/next/src/generators/custom-server/custom-server.spec.ts +++ b/packages/next/src/generators/custom-server/custom-server.spec.ts @@ -13,9 +13,8 @@ describe('app', () => { const name = uniq('custom-server'); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', customServer: true, }); @@ -31,9 +30,8 @@ describe('app', () => { const name = uniq('custom-server-swc'); await applicationGenerator(tree, { - name, + directory: name, style: 'css', - projectNameAndRootFormat: 'as-provided', customServer: true, swc: true, }); diff --git a/packages/next/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts b/packages/next/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts index 40feba723bb82..36b019767a66f 100644 --- a/packages/next/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts +++ b/packages/next/src/generators/cypress-component-configuration/cypress-component-configuration.spec.ts @@ -16,9 +16,8 @@ describe('cypress-component-configuration generator', () => { it('should setup nextjs app', async () => { await applicationGenerator(tree, { - name: 'demo', + directory: 'demo', style: 'css', - projectNameAndRootFormat: 'as-provided', }); await cypressComponentConfiguration(tree, { generateTests: true, @@ -107,9 +106,8 @@ describe('cypress-component-configuration generator', () => { it('should add styles setup in app', async () => { await applicationGenerator(tree, { - name: 'demo', + directory: 'demo', style: 'css', - projectNameAndRootFormat: 'as-provided', }); await setupTailwindGenerator(tree, { project: 'demo' }); await cypressComponentConfiguration(tree, { @@ -132,12 +130,11 @@ describe('cypress-component-configuration generator', () => { it('should setup nextjs lib', async () => { await libraryGenerator(tree, { - name: 'demo', + directory: 'demo', linter: Linter.EsLint, style: 'css', unitTestRunner: 'jest', component: true, - projectNameAndRootFormat: 'as-provided', }); await cypressComponentConfiguration(tree, { generateTests: true, diff --git a/packages/next/src/generators/library/lib/normalize-options.spec.ts b/packages/next/src/generators/library/lib/normalize-options.spec.ts index d5ce9890f9d11..68c6d00d041c5 100644 --- a/packages/next/src/generators/library/lib/normalize-options.spec.ts +++ b/packages/next/src/generators/library/lib/normalize-options.spec.ts @@ -12,7 +12,7 @@ describe('normalizeOptions', () => { it('should set importPath and projectRoot', async () => { const options = await normalizeOptions(tree, { - name: 'my-lib', + directory: 'my-lib', style: 'css', linter: Linter.None, unitTestRunner: 'jest', diff --git a/packages/next/src/generators/library/lib/normalize-options.ts b/packages/next/src/generators/library/lib/normalize-options.ts index 49bb6b3fc935a..a77b07a9623fe 100644 --- a/packages/next/src/generators/library/lib/normalize-options.ts +++ b/packages/next/src/generators/library/lib/normalize-options.ts @@ -1,5 +1,8 @@ -import { Tree, readNxJson } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { readNxJson, Tree } from '@nx/devkit'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Schema } from '../schema'; export interface NormalizedSchema extends Schema { @@ -11,15 +14,16 @@ export async function normalizeOptions( host: Tree, options: Schema ): Promise { - const { projectRoot, importPath, projectNameAndRootFormat } = - await determineProjectNameAndRootOptions(host, { + await ensureProjectName(host, options, 'library'); + const { projectRoot, importPath } = await determineProjectNameAndRootOptions( + host, + { name: options.name, projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, - }); - options.projectNameAndRootFormat = projectNameAndRootFormat; + } + ); const nxJson = readNxJson(host); const addPlugin = diff --git a/packages/next/src/generators/library/library.spec.ts b/packages/next/src/generators/library/library.spec.ts index d5ee8da5f8fa0..f1f42cc9a19d4 100644 --- a/packages/next/src/generators/library/library.spec.ts +++ b/packages/next/src/generators/library/library.spec.ts @@ -15,20 +15,19 @@ describe('next library', () => { > = installedCypressVersion as never; it('should use @nx/next images.d.ts file', async () => { const baseOptions: Schema = { - name: '', + directory: '', linter: Linter.EsLint, skipFormat: false, skipTsConfig: false, unitTestRunner: 'jest', style: 'css', component: true, - projectNameAndRootFormat: 'as-provided', }; const appTree = createTreeWithEmptyWorkspace(); await libraryGenerator(appTree, { ...baseOptions, - name: 'my-lib', + directory: 'my-lib', }); const tsconfigTypes = readJson(appTree, 'my-lib/tsconfig.lib.json') .compilerOptions.types; @@ -38,25 +37,24 @@ describe('next library', () => { it('should add jsxImportSource in tsconfig.json for @emotion/styled', async () => { const baseOptions: Schema = { - name: '', + directory: '', linter: Linter.EsLint, skipFormat: false, skipTsConfig: false, unitTestRunner: 'jest', style: 'css', component: true, - projectNameAndRootFormat: 'as-provided', }; const appTree = createTreeWithEmptyWorkspace(); await libraryGenerator(appTree, { ...baseOptions, - name: 'my-lib', + directory: 'my-lib', }); await libraryGenerator(appTree, { ...baseOptions, - name: 'my-lib2', + directory: 'my-lib2', style: '@emotion/styled', }); @@ -72,14 +70,13 @@ describe('next library', () => { const appTree = createTreeWithEmptyWorkspace(); await libraryGenerator(appTree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, skipFormat: false, skipTsConfig: false, unitTestRunner: 'jest', style: 'css', component: true, - projectNameAndRootFormat: 'as-provided', }); expect(appTree.read('my-lib/src/index.ts', 'utf-8')).toContain( @@ -100,14 +97,13 @@ describe('next library', () => { const appTree = createTreeWithEmptyWorkspace(); await libraryGenerator(appTree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, skipFormat: false, skipTsConfig: false, unitTestRunner: 'jest', style: 'css', component: false, - projectNameAndRootFormat: 'as-provided', }); expect( diff --git a/packages/next/src/generators/library/schema.d.ts b/packages/next/src/generators/library/schema.d.ts index 9bc9a4b159025..72c7a282a4504 100644 --- a/packages/next/src/generators/library/schema.d.ts +++ b/packages/next/src/generators/library/schema.d.ts @@ -1,11 +1,9 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { SupportedStyles } from '@nx/react'; export interface Schema { - name: string; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; + name?: string; style: SupportedStyles; skipTsConfig?: boolean; skipFormat?: boolean; diff --git a/packages/next/src/generators/library/schema.json b/packages/next/src/generators/library/schema.json index 1a383b6da94a2..76fbfe2338c19 100644 --- a/packages/next/src/generators/library/schema.json +++ b/packages/next/src/generators/library/schema.json @@ -6,28 +6,22 @@ "description": "Create a React Library for an Nx workspace.", "type": "object", "properties": { - "name": { + "directory": { "type": "string", - "description": "Library name", + "description": "A directory where the lib is placed.", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", - "x-priority": "important" + "x-prompt": "Which directory do you want to create the library in?" }, - "directory": { + "name": { "type": "string", - "description": "A directory where the lib is placed.", - "alias": "dir", + "description": "Library name", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -37,7 +31,10 @@ "message": "Which stylesheet format would you like to use?", "type": "list", "items": [ - { "value": "css", "label": "CSS" }, + { + "value": "css", + "label": "CSS" + }, { "value": "scss", "label": "SASS(.scss) [ https://sass-lang.com ]" @@ -146,6 +143,6 @@ "x-priority": "internal" } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "../../../docs/library-examples.md" } diff --git a/packages/next/src/generators/page/page.spec.ts b/packages/next/src/generators/page/page.spec.ts index d1371d3a7cdb1..0fc16cce702de 100644 --- a/packages/next/src/generators/page/page.spec.ts +++ b/packages/next/src/generators/page/page.spec.ts @@ -13,16 +13,14 @@ describe('component', () => { appRouterProjectName = 'my-app-router'; tree = createTreeWithEmptyWorkspace(); await applicationGenerator(tree, { - name: projectName, + directory: projectName, style: 'css', appDir: false, - projectNameAndRootFormat: 'as-provided', }); await applicationGenerator(tree, { - name: appRouterProjectName, + directory: appRouterProjectName, style: 'css', - projectNameAndRootFormat: 'as-provided', }); }); diff --git a/packages/node/src/generators/application/application.legacy.spec.ts b/packages/node/src/generators/application/application.legacy.spec.ts index 21044e90c13f4..b10c2f89ab80d 100644 --- a/packages/node/src/generators/application/application.legacy.spec.ts +++ b/packages/node/src/generators/application/application.legacy.spec.ts @@ -22,9 +22,8 @@ describe('node app generator (legacy)', () => { it('should not skip the build target', async () => { await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', bundler: 'webpack', - projectNameAndRootFormat: 'as-provided', addPlugin: false, }); const project = readProjectConfiguration(tree, 'my-node-app'); diff --git a/packages/node/src/generators/application/application.spec.ts b/packages/node/src/generators/application/application.spec.ts index 164c31c95eab2..d4e1a1af545d0 100644 --- a/packages/node/src/generators/application/application.spec.ts +++ b/packages/node/src/generators/application/application.spec.ts @@ -26,9 +26,8 @@ describe('app', () => { describe('not nested', () => { it('should update project config', async () => { await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', bundler: 'webpack', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); const project = readProjectConfiguration(tree, 'my-node-app'); @@ -94,9 +93,8 @@ describe('app', () => { it('should update tags', async () => { await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', tags: 'one,two', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); const projects = Object.fromEntries(getProjects(tree)); @@ -109,8 +107,7 @@ describe('app', () => { it('should generate files', async () => { await applicationGenerator(tree, { - name: 'my-node-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-node-app', addPlugin: true, }); expect(tree.exists(`my-node-app/jest.config.ts`)).toBeTruthy(); @@ -186,8 +183,7 @@ describe('app', () => { tree.rename('tsconfig.base.json', 'tsconfig.json'); await applicationGenerator(tree, { - name: 'my-node-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-node-app', addPlugin: true, }); @@ -199,9 +195,7 @@ describe('app', () => { describe('nested', () => { it('should update project config', async () => { await applicationGenerator(tree, { - name: 'my-node-app', directory: 'my-dir/my-node-app', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); const project = readProjectConfiguration(tree, 'my-node-app'); @@ -349,7 +343,7 @@ describe('app', () => { describe('--unit-test-runner none', () => { it('should not generate test configuration', async () => { await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', unitTestRunner: 'none', addPlugin: true, }); @@ -364,11 +358,11 @@ describe('app', () => { describe('--frontendProject', () => { it('should configure proxy', async () => { await angularApplicationGenerator(tree, { - name: 'my-frontend', + directory: 'my-frontend', }); await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', frontendProject: 'my-frontend', addPlugin: true, }); @@ -381,17 +375,17 @@ describe('app', () => { it('should configure proxies for multiple node projects with the same frontend app', async () => { await angularApplicationGenerator(tree, { - name: 'my-frontend', + directory: 'my-frontend', }); await applicationGenerator(tree, { - name: 'cart', + directory: 'cart', frontendProject: 'my-frontend', addPlugin: true, }); await applicationGenerator(tree, { - name: 'billing', + directory: 'billing', frontendProject: 'my-frontend', addPlugin: true, }); @@ -408,7 +402,7 @@ describe('app', () => { describe('--swcJest', () => { it('should use @swc/jest for jest', async () => { await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', tags: 'one,two', swcJest: true, addPlugin: true, @@ -434,7 +428,7 @@ describe('app', () => { describe('--babelJest (deprecated)', () => { it('should use babel for jest', async () => { await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', tags: 'one,two', babelJest: true, addPlugin: true, @@ -460,7 +454,7 @@ describe('app', () => { describe('--js flag', () => { it('should generate js files instead of ts files', async () => { await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', js: true, addPlugin: true, } as Schema); @@ -487,7 +481,7 @@ describe('app', () => { it('should add project config', async () => { await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', js: true, addPlugin: true, } as Schema); @@ -514,7 +508,7 @@ describe('app', () => { jest.spyOn(devkit, 'formatFiles'); await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', addPlugin: true, }); @@ -525,7 +519,7 @@ describe('app', () => { jest.spyOn(devkit, 'formatFiles'); await applicationGenerator(tree, { - name: 'my-node-app', + directory: 'my-node-app', skipFormat: true, addPlugin: true, }); @@ -542,7 +536,7 @@ describe('app', () => { ])('--unitTestRunner', (framework, checkSpecFile) => { it('should generate test target and spec file by default', async () => { await applicationGenerator(tree, { - name: 'api', + directory: 'api', framework, addPlugin: true, }); diff --git a/packages/node/src/generators/application/application.ts b/packages/node/src/generators/application/application.ts index 6266e73c806e7..454005c5c8c1e 100644 --- a/packages/node/src/generators/application/application.ts +++ b/packages/node/src/generators/application/application.ts @@ -20,7 +20,10 @@ import { updateProjectConfiguration, updateTsConfigsToJs, } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { configurationGenerator } from '@nx/jest'; import { getRelativePathToRootTsConfig, @@ -489,7 +492,6 @@ export async function applicationGeneratorInternal(tree: Tree, schema: Schema) { projectType: options.framework === 'none' ? 'cli' : 'server', name: options.rootProject ? 'e2e' : `${options.name}-e2e`, directory: options.rootProject ? 'e2e' : `${options.appProjectRoot}-e2e`, - projectNameAndRootFormat: 'as-provided', project: options.name, port: options.port, isNest: options.isNest, @@ -531,19 +533,15 @@ async function normalizeOptions( host: Tree, options: Schema ): Promise { - const { - projectName: appProjectName, - projectRoot: appProjectRoot, - projectNameAndRootFormat, - } = await determineProjectNameAndRootOptions(host, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - rootProject: options.rootProject, - }); + await ensureProjectName(host, options, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(host, { + name: options.name, + projectType: 'application', + directory: options.directory, + rootProject: options.rootProject, + }); options.rootProject = appProjectRoot === '.'; - options.projectNameAndRootFormat = projectNameAndRootFormat; options.bundler = options.bundler ?? 'esbuild'; options.e2eTestRunner = options.e2eTestRunner ?? 'jest'; diff --git a/packages/node/src/generators/application/schema.d.ts b/packages/node/src/generators/application/schema.d.ts index 22a7074ec7a4a..e5a15e8a94968 100644 --- a/packages/node/src/generators/application/schema.d.ts +++ b/packages/node/src/generators/application/schema.d.ts @@ -1,12 +1,10 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { - name: string; + directory: string; + name?: string; skipFormat?: boolean; skipPackageJson?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; unitTestRunner?: 'jest' | 'none'; e2eTestRunner?: 'jest' | 'none'; linter?: Linter | LinterType; diff --git a/packages/node/src/generators/application/schema.json b/packages/node/src/generators/application/schema.json index ed0f3aa67a1df..ed4a8ae569346 100644 --- a/packages/node/src/generators/application/schema.json +++ b/packages/node/src/generators/application/schema.json @@ -6,27 +6,21 @@ "description": "Nx Application Options Schema.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the node application?", - "x-priority": "important", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { + "description": "The name of the application.", "type": "string", + "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "skipFormat": { "description": "Skip formatting files", "type": "boolean", @@ -126,5 +120,5 @@ "description": "Add a docker build target" } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/node/src/generators/e2e-project/e2e-project.spec.ts b/packages/node/src/generators/e2e-project/e2e-project.spec.ts index b2b142c03a6a5..2ac6fc5983a16 100644 --- a/packages/node/src/generators/e2e-project/e2e-project.spec.ts +++ b/packages/node/src/generators/e2e-project/e2e-project.spec.ts @@ -13,10 +13,9 @@ describe('e2eProjectGenerator', () => { it('should generate default spec for server app (integrated)', async () => { await applicationGenerator(tree, { - name: 'api', + directory: 'api', framework: 'express', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); await e2eProjectGenerator(tree, { @@ -30,11 +29,10 @@ describe('e2eProjectGenerator', () => { it('should generate default spec for server app (standalone)', async () => { await applicationGenerator(tree, { - name: 'api', + directory: 'api', framework: 'express', e2eTestRunner: 'none', rootProject: true, - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); await e2eProjectGenerator(tree, { @@ -49,10 +47,9 @@ describe('e2eProjectGenerator', () => { it('should generate cli project', async () => { await applicationGenerator(tree, { - name: 'api', + directory: 'api', framework: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); await e2eProjectGenerator(tree, { diff --git a/packages/node/src/generators/e2e-project/e2e-project.ts b/packages/node/src/generators/e2e-project/e2e-project.ts index 7ab3806e924ae..44cf8afbc1f20 100644 --- a/packages/node/src/generators/e2e-project/e2e-project.ts +++ b/packages/node/src/generators/e2e-project/e2e-project.ts @@ -184,14 +184,12 @@ async function normalizeOptions( ): Promise< Omit & { e2eProjectRoot: string; e2eProjectName: string } > { + options.directory = options.directory ?? `${options.project}-e2e`; const { projectName: e2eProjectName, projectRoot: e2eProjectRoot } = await determineProjectNameAndRootOptions(tree, { - name: options.name ?? `${options.project}-e2e`, + name: options.name, projectType: 'library', directory: options.rootProject ? 'e2e' : options.directory, - projectNameAndRootFormat: options.rootProject - ? 'as-provided' - : options.projectNameAndRootFormat, }); const nxJson = readNxJson(tree); diff --git a/packages/node/src/generators/e2e-project/schema.d.ts b/packages/node/src/generators/e2e-project/schema.d.ts index 84553f19a0e62..de6eeaee1f455 100644 --- a/packages/node/src/generators/e2e-project/schema.d.ts +++ b/packages/node/src/generators/e2e-project/schema.d.ts @@ -1,10 +1,7 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; - export interface Schema { project: string; projectType: 'server' | 'cli'; directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; name?: string; port?: number; linter?: 'eslint' | 'none'; diff --git a/packages/node/src/generators/e2e-project/schema.json b/packages/node/src/generators/e2e-project/schema.json index 35171878fdb78..7add1fb212098 100644 --- a/packages/node/src/generators/e2e-project/schema.json +++ b/packages/node/src/generators/e2e-project/schema.json @@ -18,11 +18,6 @@ "type": "string", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "name": { "description": "The name of the e2e project. Defaults to the project name with '-e2e' suffix.", "type": "string" diff --git a/packages/node/src/generators/library/library.spec.ts b/packages/node/src/generators/library/library.spec.ts index e2cc0c8155ae5..ae8b2c5b43a5e 100644 --- a/packages/node/src/generators/library/library.spec.ts +++ b/packages/node/src/generators/library/library.spec.ts @@ -12,9 +12,8 @@ import { Schema } from './schema.d'; import { libraryGenerator } from './library'; const baseLibraryConfig = { - name: 'my-lib', + directory: 'my-lib', compiler: 'tsc' as const, - projectNameAndRootFormat: 'as-provided' as const, addPlugin: true, }; @@ -378,7 +377,7 @@ describe('lib', () => { it('should update package.json', async () => { await libraryGenerator(tree, { ...baseLibraryConfig, - name: 'mylib', + directory: 'mylib', publishable: true, importPath: '@proj/mylib', }); @@ -409,7 +408,7 @@ describe('lib', () => { it('should fail if the same importPath has already been used', async () => { await libraryGenerator(tree, { ...baseLibraryConfig, - name: 'my-lib1', + directory: 'my-lib1', publishable: true, importPath: '@myorg/lib', }); @@ -417,7 +416,7 @@ describe('lib', () => { try { await libraryGenerator(tree, { ...baseLibraryConfig, - name: 'my-lib2', + directory: 'my-lib2', publishable: true, importPath: '@myorg/lib', }); @@ -434,7 +433,7 @@ describe('lib', () => { describe(`--babelJest`, () => { it('should use babel for jest', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', babelJest: true, } as Schema); @@ -457,7 +456,7 @@ describe('lib', () => { describe('--js flag', () => { it('should generate js files instead of ts files', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', js: true, } as Schema); @@ -484,7 +483,7 @@ describe('lib', () => { }); it('should update root tsconfig.json with a js file path', async () => { - await libraryGenerator(tree, { name: 'my-lib', js: true } as Schema); + await libraryGenerator(tree, { directory: 'my-lib', js: true } as Schema); const tsconfigJson = readJson(tree, '/tsconfig.base.json'); expect(tsconfigJson.compilerOptions.paths['@proj/my-lib']).toEqual([ 'my-lib/src/index.js', @@ -493,7 +492,7 @@ describe('lib', () => { it('should update architect builder when --buildable', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', buildable: true, js: true, } as Schema); @@ -511,7 +510,6 @@ describe('lib', () => { name: 'my-lib', directory: 'my-dir/my-lib', js: true, - projectNameAndRootFormat: 'as-provided', } as Schema); expect(tree.exists(`my-dir/my-lib/jest.config.js`)).toBeTruthy(); expect(tree.exists('my-dir/my-lib/src/index.js')).toBeTruthy(); diff --git a/packages/node/src/generators/library/library.ts b/packages/node/src/generators/library/library.ts index 40ffc95c9fc29..d2dc70409a2d6 100644 --- a/packages/node/src/generators/library/library.ts +++ b/packages/node/src/generators/library/library.ts @@ -14,7 +14,10 @@ import { updateProjectConfiguration, updateTsConfigsToJs, } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { libraryGenerator as jsLibraryGenerator } from '@nx/js'; import { addSwcConfig } from '@nx/js/src/utils/swc/add-swc-config'; import { addSwcDependencies } from '@nx/js/src/utils/swc/add-swc-dependencies'; @@ -86,20 +89,18 @@ async function normalizeOptions( tree: Tree, options: Schema ): Promise { + await ensureProjectName(tree, options, 'library'); const { projectName, names: projectNames, projectRoot, importPath, - projectNameAndRootFormat, } = await determineProjectNameAndRootOptions(tree, { name: options.name, projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); - options.projectNameAndRootFormat = projectNameAndRootFormat; const nxJson = readNxJson(tree); const addPluginDefault = diff --git a/packages/node/src/generators/library/schema.d.ts b/packages/node/src/generators/library/schema.d.ts index 927b59c3e9fa2..ffe32d161a35d 100644 --- a/packages/node/src/generators/library/schema.d.ts +++ b/packages/node/src/generators/library/schema.d.ts @@ -1,10 +1,8 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { - name: string; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; + name?: string; simpleModuleName?: boolean; skipTsConfig?: boolean; skipFormat?: boolean; diff --git a/packages/node/src/generators/library/schema.json b/packages/node/src/generators/library/schema.json index 55ab62c5542f6..51124a0a3f973 100644 --- a/packages/node/src/generators/library/schema.json +++ b/packages/node/src/generators/library/schema.json @@ -12,29 +12,24 @@ } ], "properties": { - "name": { + "directory": { "type": "string", - "description": "Library name", + "description": "A directory where the lib is placed", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" + "x-prompt": "Which directory do you want to create the library in?" }, - "directory": { + "name": { "type": "string", - "description": "A directory where the lib is placed", - "alias": "dir", + "description": "Library name", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "simpleModuleName": { - "description": "Keep the module name simple (when using `--directory`).", + "description": "Keep the module name simple.", "type": "boolean", "default": false }, @@ -126,5 +121,5 @@ "default": false } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/node/src/generators/setup-docker/setup-docker.spec.ts b/packages/node/src/generators/setup-docker/setup-docker.spec.ts index 7f344b7feea78..6d39ca5093d0d 100644 --- a/packages/node/src/generators/setup-docker/setup-docker.spec.ts +++ b/packages/node/src/generators/setup-docker/setup-docker.spec.ts @@ -15,11 +15,10 @@ describe('setupDockerGenerator', () => { const projectName = 'integreated-api'; await applicationGenerator(tree, { - name: projectName, + directory: projectName, framework: 'express', e2eTestRunner: 'none', docker: true, - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); @@ -45,10 +44,9 @@ describe('setupDockerGenerator', () => { await applicationGenerator(tree, { name: projectName, + directory: '.', framework: 'fastify', - rootProject: true, docker: true, - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); diff --git a/packages/nuxt/src/generators/application/application.spec.ts b/packages/nuxt/src/generators/application/application.spec.ts index d59e487fe07bb..f26160511b18b 100644 --- a/packages/nuxt/src/generators/application/application.spec.ts +++ b/packages/nuxt/src/generators/application/application.spec.ts @@ -17,8 +17,7 @@ describe('app', () => { it('should not add targets', async () => { await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', + directory: name, unitTestRunner: 'vitest', }); @@ -32,8 +31,7 @@ describe('app', () => { it('should create all new files in the correct location', async () => { await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', + directory: name, unitTestRunner: 'vitest', }); @@ -43,8 +41,7 @@ describe('app', () => { it('should add nuxt entries in .gitignore', async () => { await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', + directory: name, unitTestRunner: 'vitest', }); @@ -53,8 +50,7 @@ describe('app', () => { it('should configure nuxt correctly', async () => { await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', + directory: name, unitTestRunner: 'vitest', }); @@ -67,8 +63,7 @@ describe('app', () => { tree.write('eslint.config.js', ''); await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', + directory: name, unitTestRunner: 'vitest', }); @@ -79,8 +74,7 @@ describe('app', () => { it('should configure eslint correctly (eslintrc)', async () => { await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', + directory: name, unitTestRunner: 'vitest', }); @@ -91,8 +85,7 @@ describe('app', () => { it('should configure vitest correctly', async () => { await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', + directory: name, unitTestRunner: 'vitest', }); @@ -109,8 +102,7 @@ describe('app', () => { it('should configure tsconfig and project.json correctly', async () => { await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', + directory: name, unitTestRunner: 'vitest', }); @@ -120,8 +112,7 @@ describe('app', () => { it('should add the nuxt and vitest plugins', async () => { await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', + directory: name, unitTestRunner: 'vitest', }); @@ -163,8 +154,7 @@ describe('app', () => { }); it('should configure css', async () => { await applicationGenerator(tree, { - name: 'myapp1', - projectNameAndRootFormat: 'as-provided', + directory: 'myapp1', unitTestRunner: 'none', style: 'css', }); @@ -174,8 +164,7 @@ describe('app', () => { it('should configure scss', async () => { await applicationGenerator(tree, { - name: 'myapp2', - projectNameAndRootFormat: 'as-provided', + directory: 'myapp2', unitTestRunner: 'none', style: 'scss', }); @@ -185,8 +174,7 @@ describe('app', () => { it('should configure less', async () => { await applicationGenerator(tree, { - name: 'myapp3', - projectNameAndRootFormat: 'as-provided', + directory: 'myapp3', unitTestRunner: 'none', style: 'less', }); @@ -196,8 +184,7 @@ describe('app', () => { it('should not configure styles', async () => { await applicationGenerator(tree, { - name: 'myapp4', - projectNameAndRootFormat: 'as-provided', + directory: 'myapp4', unitTestRunner: 'none', style: 'none', }); diff --git a/packages/nuxt/src/generators/application/lib/normalize-options.ts b/packages/nuxt/src/generators/application/lib/normalize-options.ts index 84ea866b25c4f..d35182f941624 100644 --- a/packages/nuxt/src/generators/application/lib/normalize-options.ts +++ b/packages/nuxt/src/generators/application/lib/normalize-options.ts @@ -1,35 +1,23 @@ -import { Tree, extractLayoutDirectory, names, readNxJson } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { names, Tree } from '@nx/devkit'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { NormalizedSchema, Schema } from '../schema'; -import { NuxtPluginOptions } from '../../../plugins/plugin'; - -export function normalizeDirectory(options: Schema) { - options.directory = options.directory?.replace(/\\{1,2}/g, '/'); - const { projectDirectory } = extractLayoutDirectory(options.directory); - return projectDirectory - ? `${names(projectDirectory).fileName}/${names(options.name).fileName}` - : names(options.name).fileName; -} export async function normalizeOptions( host: Tree, options: Schema ): Promise { - const { - projectName: appProjectName, - projectRoot: appProjectRoot, - projectNameAndRootFormat, - } = await determineProjectNameAndRootOptions(host, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - rootProject: options.rootProject, - }); + await ensureProjectName(host, options, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(host, { + name: options.name, + projectType: 'application', + directory: options.directory, + rootProject: options.rootProject, + }); options.rootProject = appProjectRoot === '.'; - options.projectNameAndRootFormat = projectNameAndRootFormat; - - const nxJson = readNxJson(host); const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`; const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`; diff --git a/packages/nuxt/src/generators/application/schema.d.ts b/packages/nuxt/src/generators/application/schema.d.ts index 596b214406539..a758930a817ad 100644 --- a/packages/nuxt/src/generators/application/schema.d.ts +++ b/packages/nuxt/src/generators/application/schema.d.ts @@ -1,10 +1,8 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { - name: string; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; + name?: string; linter?: Linter | LinterType; skipFormat?: boolean; unitTestRunner?: 'vitest' | 'none'; diff --git a/packages/nuxt/src/generators/application/schema.json b/packages/nuxt/src/generators/application/schema.json index ab2e6a12bf841..effd221b7efea 100644 --- a/packages/nuxt/src/generators/application/schema.json +++ b/packages/nuxt/src/generators/application/schema.json @@ -6,28 +6,22 @@ "description": "Create a Nuxt Application for Nx.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { + "description": "The name of the application.", "type": "string", - "alias": "dir", + "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -86,7 +80,10 @@ "message": "Which stylesheet format would you like to use?", "type": "list", "items": [ - { "value": "css", "label": "CSS" }, + { + "value": "css", + "label": "CSS" + }, { "value": "scss", "label": "SASS(.scss) [ https://sass-lang.com ]" @@ -95,7 +92,10 @@ "value": "less", "label": "LESS [ https://lesscss.org ]" }, - { "value": "none", "label": "None" } + { + "value": "none", + "label": "None" + } ] } }, @@ -105,6 +105,6 @@ "default": false } }, - "required": [], + "required": ["directory"], "examplesFile": "../../../docs/application-examples.md" } diff --git a/packages/nuxt/src/generators/storybook-configuration/configuration.spec.ts b/packages/nuxt/src/generators/storybook-configuration/configuration.spec.ts index 7e9ff2d087c3b..9c7d6e3505de2 100644 --- a/packages/nuxt/src/generators/storybook-configuration/configuration.spec.ts +++ b/packages/nuxt/src/generators/storybook-configuration/configuration.spec.ts @@ -88,9 +88,8 @@ export async function createTestApp( skipFormat: false, style: 'css', unitTestRunner: 'none', - name: appName, + directory: appName, js: plainJS, - projectNameAndRootFormat: 'as-provided', }); await componentGenerator(appTree, { diff --git a/packages/nx/src/migrations/update-16-9-0/remove-project-name-and-root-format.spec.ts b/packages/nx/src/migrations/update-16-9-0/remove-project-name-and-root-format.spec.ts index 40398573651f6..598cc9c72c8ca 100644 --- a/packages/nx/src/migrations/update-16-9-0/remove-project-name-and-root-format.spec.ts +++ b/packages/nx/src/migrations/update-16-9-0/remove-project-name-and-root-format.spec.ts @@ -24,7 +24,6 @@ describe('removeProjectNameAndRootFormat', () => { const nxJson: any = { workspaceLayout: { libsDir: 'libs', - projectNameAndRootFormat: 'as-provided', }, }; writeJson(tree, 'nx.json', nxJson); @@ -36,9 +35,7 @@ describe('removeProjectNameAndRootFormat', () => { it('should remove workspaceLayout if it is present', async () => { const nxJson: any = { - workspaceLayout: { - projectNameAndRootFormat: 'as-provided', - }, + workspaceLayout: {}, }; writeJson(tree, 'nx.json', nxJson); await removeProjectNameAndRootFormat(tree); diff --git a/packages/plugin/src/generators/create-package/create-package.spec.ts b/packages/plugin/src/generators/create-package/create-package.spec.ts index e0e497ac11145..2a1cf22537206 100644 --- a/packages/plugin/src/generators/create-package/create-package.spec.ts +++ b/packages/plugin/src/generators/create-package/create-package.spec.ts @@ -28,7 +28,6 @@ const getSchema: ( skipLintChecks: false, linter: Linter.EsLint, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', ...overrides, }); @@ -47,7 +46,6 @@ describe('NxPlugin Create Package Generator', () => { skipLintChecks: false, linter: Linter.EsLint, unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }); }); diff --git a/packages/plugin/src/generators/create-package/create-package.ts b/packages/plugin/src/generators/create-package/create-package.ts index 8b0325d5bb5ba..f9a7c649c4993 100644 --- a/packages/plugin/src/generators/create-package/create-package.ts +++ b/packages/plugin/src/generators/create-package/create-package.ts @@ -86,6 +86,7 @@ async function createCliPackage( ) { await jsLibraryGenerator(host, { ...options, + directory: options.directory, rootProject: false, config: 'project', publishable: true, diff --git a/packages/plugin/src/generators/create-package/schema.d.ts b/packages/plugin/src/generators/create-package/schema.d.ts index 9c25eba17a79a..c82b40925e55f 100644 --- a/packages/plugin/src/generators/create-package/schema.d.ts +++ b/packages/plugin/src/generators/create-package/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface CreatePackageSchema { name: string; project: string; + directory: string; // options to create cli package, passed to js library generator - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; skipFormat: boolean; tags?: string; unitTestRunner: 'jest' | 'none'; diff --git a/packages/plugin/src/generators/create-package/schema.json b/packages/plugin/src/generators/create-package/schema.json index 5bd26ec53a78d..0a64414121d68 100644 --- a/packages/plugin/src/generators/create-package/schema.json +++ b/packages/plugin/src/generators/create-package/schema.json @@ -7,14 +7,18 @@ "examplesFile": "../../../docs/generators/create-package-examples.md", "type": "object", "properties": { - "name": { + "directory": { "type": "string", - "description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.", - "pattern": "create-.+|^@.+/create(?:-.+)?", + "description": "A directory where the app is placed.", "$default": { "$source": "argv", "index": 0 - }, + } + }, + "name": { + "type": "string", + "description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.", + "pattern": "create-.+|^@.+/create(?:-.+)?", "x-priority": "important" }, "project": { @@ -33,15 +37,6 @@ "description": "Test runner to use for unit tests.", "default": "jest" }, - "directory": { - "type": "string", - "description": "A directory where the app is placed." - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -71,5 +66,5 @@ "x-prompt": "What is the name of the e2e project? Leave blank to skip e2e tests" } }, - "required": ["name", "project"] + "required": ["directory", "name", "project"] } diff --git a/packages/plugin/src/generators/create-package/utils/normalize-schema.ts b/packages/plugin/src/generators/create-package/utils/normalize-schema.ts index 56b22369e9791..5ddfe741d265a 100644 --- a/packages/plugin/src/generators/create-package/utils/normalize-schema.ts +++ b/packages/plugin/src/generators/create-package/utils/normalize-schema.ts @@ -1,4 +1,4 @@ -import { Tree } from '@nx/devkit'; +import { readProjectConfiguration, Tree } from '@nx/devkit'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { CreatePackageSchema } from '../schema'; @@ -12,18 +12,20 @@ export async function normalizeSchema( host: Tree, schema: CreatePackageSchema ): Promise { + if (!schema.directory) { + throw new Error( + `Please provide the --directory option. It should be the directory containing the project '${schema.project}'.` + ); + } const { projectName, names: projectNames, projectRoot, - projectNameAndRootFormat, } = await determineProjectNameAndRootOptions(host, { name: schema.name, projectType: 'library', directory: schema.directory, - projectNameAndRootFormat: schema.projectNameAndRootFormat, }); - schema.projectNameAndRootFormat = projectNameAndRootFormat; return { ...schema, diff --git a/packages/plugin/src/generators/e2e-project/__snapshots__/e2e.spec.ts.snap b/packages/plugin/src/generators/e2e-project/__snapshots__/e2e.spec.ts.snap index a560b0e5d99a4..deebe254b8cfb 100644 --- a/packages/plugin/src/generators/e2e-project/__snapshots__/e2e.spec.ts.snap +++ b/packages/plugin/src/generators/e2e-project/__snapshots__/e2e.spec.ts.snap @@ -2,7 +2,7 @@ exports[`NxPlugin e2e-project Generator should setup the eslint builder 1`] = ` "{ - "extends": ["../../.eslintrc.json"], + "extends": ["../.eslintrc.json"], "ignorePatterns": ["!**/*"], "overrides": [ { diff --git a/packages/plugin/src/generators/e2e-project/e2e.spec.ts b/packages/plugin/src/generators/e2e-project/e2e.spec.ts index d5fb89da1dd02..976416d6092c4 100644 --- a/packages/plugin/src/generators/e2e-project/e2e.spec.ts +++ b/packages/plugin/src/generators/e2e-project/e2e.spec.ts @@ -54,10 +54,8 @@ describe('NxPlugin e2e-project Generator', () => { addPlugin: true, }); - expect(tree.exists('apps/my-plugin-e2e/tsconfig.json')).toBeTruthy(); - expect( - tree.exists('apps/my-plugin-e2e/src/my-plugin.spec.ts') - ).toBeTruthy(); + expect(tree.exists('my-plugin-e2e/tsconfig.json')).toBeTruthy(); + expect(tree.exists('my-plugin-e2e/src/my-plugin.spec.ts')).toBeTruthy(); }); it('should extend from root tsconfig.base.json', async () => { @@ -68,8 +66,8 @@ describe('NxPlugin e2e-project Generator', () => { addPlugin: true, }); - const tsConfig = readJson(tree, 'apps/my-plugin-e2e/tsconfig.json'); - expect(tsConfig.extends).toEqual('../../tsconfig.base.json'); + const tsConfig = readJson(tree, 'my-plugin-e2e/tsconfig.json'); + expect(tsConfig.extends).toEqual('../tsconfig.base.json'); }); it('should extend from root tsconfig.json when no tsconfig.base.json', async () => { @@ -82,8 +80,8 @@ describe('NxPlugin e2e-project Generator', () => { addPlugin: true, }); - const tsConfig = readJson(tree, 'apps/my-plugin-e2e/tsconfig.json'); - expect(tsConfig.extends).toEqual('../../tsconfig.json'); + const tsConfig = readJson(tree, 'my-plugin-e2e/tsconfig.json'); + expect(tsConfig.extends).toEqual('../tsconfig.json'); }); it('should set project root with the directory option', async () => { @@ -96,7 +94,7 @@ describe('NxPlugin e2e-project Generator', () => { }); const project = readProjectConfiguration(tree, 'my-plugin-e2e'); - expect(project.root).toBe('apps/namespace/my-plugin-e2e'); + expect(project.root).toBe('namespace/my-plugin-e2e'); }); it('should update the implicit dependencies', async () => { @@ -125,7 +123,7 @@ describe('NxPlugin e2e-project Generator', () => { const project = readProjectConfiguration(tree, 'my-plugin-e2e'); expect(project).toBeTruthy(); - expect(project.root).toEqual('apps/my-plugin-e2e'); + expect(project.root).toEqual('my-plugin-e2e'); expect(project.targets.e2e).toBeTruthy(); expect(project.targets.e2e).toMatchInlineSnapshot(` { @@ -134,7 +132,7 @@ describe('NxPlugin e2e-project Generator', () => { ], "executor": "@nx/jest:jest", "options": { - "jestConfig": "apps/my-plugin-e2e/jest.config.ts", + "jestConfig": "my-plugin-e2e/jest.config.ts", "runInBand": true, }, "outputs": [ @@ -156,12 +154,12 @@ describe('NxPlugin e2e-project Generator', () => { expect(project.targets.e2e).toMatchObject({ options: expect.objectContaining({ - jestConfig: 'apps/my-plugin-e2e/jest.config.ts', + jestConfig: 'my-plugin-e2e/jest.config.ts', }), }); - expect(tree.exists('apps/my-plugin-e2e/tsconfig.spec.json')).toBeTruthy(); - expect(tree.exists('apps/my-plugin-e2e/jest.config.ts')).toBeTruthy(); + expect(tree.exists('my-plugin-e2e/tsconfig.spec.json')).toBeTruthy(); + expect(tree.exists('my-plugin-e2e/jest.config.ts')).toBeTruthy(); }); it('should setup the eslint builder', async () => { @@ -173,7 +171,7 @@ describe('NxPlugin e2e-project Generator', () => { }); expect( - tree.read('apps/my-plugin-e2e/.eslintrc.json', 'utf-8') + tree.read('my-plugin-e2e/.eslintrc.json', 'utf-8') ).toMatchSnapshot(); }); }); diff --git a/packages/plugin/src/generators/e2e-project/e2e.ts b/packages/plugin/src/generators/e2e-project/e2e.ts index aa7d671bc4971..6979c7b8c36f6 100644 --- a/packages/plugin/src/generators/e2e-project/e2e.ts +++ b/packages/plugin/src/generators/e2e-project/e2e.ts @@ -46,33 +46,18 @@ async function normalizeOptions( options.addPlugin ??= addPlugin; let projectRoot: string; - if (options.projectNameAndRootFormat === 'as-provided') { - const projectNameAndRootOptions = await determineProjectNameAndRootOptions( - host, - { - name: projectName, - projectType: 'application', - directory: - options.rootProject || !options.projectDirectory - ? projectName - : `${options.projectDirectory}-e2e`, - projectNameAndRootFormat: `as-provided`, - } - ); - projectRoot = projectNameAndRootOptions.projectRoot; - } else { - const { layoutDirectory, projectDirectory } = extractLayoutDirectory( - options.projectDirectory - ); - const { appsDir: defaultAppsDir } = getWorkspaceLayout(host); - const appsDir = layoutDirectory ?? defaultAppsDir; - - projectRoot = options.rootProject - ? projectName - : projectDirectory - ? joinPathFragments(appsDir, `${projectDirectory}-e2e`) - : joinPathFragments(appsDir, projectName); - } + const projectNameAndRootOptions = await determineProjectNameAndRootOptions( + host, + { + name: projectName, + projectType: 'application', + directory: + options.rootProject || !options.projectDirectory + ? projectName + : `${options.projectDirectory}-e2e`, + } + ); + projectRoot = projectNameAndRootOptions.projectRoot; const pluginPropertyName = names(options.pluginName).propertyName; diff --git a/packages/plugin/src/generators/e2e-project/schema.d.ts b/packages/plugin/src/generators/e2e-project/schema.d.ts index 98423d1e14689..14d72bef2806d 100644 --- a/packages/plugin/src/generators/e2e-project/schema.d.ts +++ b/packages/plugin/src/generators/e2e-project/schema.d.ts @@ -1,11 +1,9 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { pluginName: string; npmPackageName: string; projectDirectory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; pluginOutputPath?: string; jestConfig?: string; linter?: Linter | LinterType; diff --git a/packages/plugin/src/generators/e2e-project/schema.json b/packages/plugin/src/generators/e2e-project/schema.json index a5de92ffdbaa2..60b91cdbed8c6 100644 --- a/packages/plugin/src/generators/e2e-project/schema.json +++ b/packages/plugin/src/generators/e2e-project/schema.json @@ -21,11 +21,6 @@ "type": "string", "description": "the directory where the plugin is placed." }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "pluginOutputPath": { "type": "string", "description": "the output path of the plugin after it builds.", diff --git a/packages/plugin/src/generators/executor/executor.spec.ts b/packages/plugin/src/generators/executor/executor.spec.ts index c46e1d9542d63..93d60122feac4 100644 --- a/packages/plugin/src/generators/executor/executor.spec.ts +++ b/packages/plugin/src/generators/executor/executor.spec.ts @@ -18,11 +18,10 @@ describe('NxPlugin Executor Generator', () => { setCwd(''); await pluginGenerator(tree, { - name: projectName, + directory: projectName, unitTestRunner: 'jest', linter: Linter.EsLint, compiler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); }); @@ -110,9 +109,8 @@ describe('NxPlugin Executor Generator', () => { it('should create executors.json if it is not present', async () => { await jsLibraryGenerator(tree, { - name: 'test-js-lib', + directory: 'test-js-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const libConfig = readProjectConfiguration(tree, 'test-js-lib'); diff --git a/packages/plugin/src/generators/generator/generator.spec.ts b/packages/plugin/src/generators/generator/generator.spec.ts index c4776eaf76499..bd67b9fd0e298 100644 --- a/packages/plugin/src/generators/generator/generator.spec.ts +++ b/packages/plugin/src/generators/generator/generator.spec.ts @@ -22,8 +22,7 @@ describe('NxPlugin Generator Generator', () => { tree = createTreeWithEmptyWorkspace(); setCwd(''); await pluginGenerator(tree, { - name: projectName, - projectNameAndRootFormat: 'as-provided', + directory: projectName, unitTestRunner: 'jest', linter: Linter.EsLint, compiler: 'tsc', @@ -187,9 +186,8 @@ describe('NxPlugin Generator Generator', () => { it('should create generators.json if it is not present', async () => { await jsLibraryGenerator(tree, { - name: 'test-js-lib', + directory: 'test-js-lib', bundler: 'tsc', - projectNameAndRootFormat: 'as-provided', }); const libConfig = readProjectConfiguration(tree, 'test-js-lib'); await generatorGenerator(tree, { diff --git a/packages/plugin/src/generators/lint-checks/generator.spec.ts b/packages/plugin/src/generators/lint-checks/generator.spec.ts index 2a608f226b2e2..88b10111efb7c 100644 --- a/packages/plugin/src/generators/lint-checks/generator.spec.ts +++ b/packages/plugin/src/generators/lint-checks/generator.spec.ts @@ -26,7 +26,7 @@ describe('lint-checks generator', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await pluginGenerator(tree, { - name: 'plugin', + directory: 'plugin', importPath: '@acme/plugin', compiler: 'tsc', linter: Linter.EsLint, diff --git a/packages/plugin/src/generators/migration/migration.spec.ts b/packages/plugin/src/generators/migration/migration.spec.ts index c6194f58df2a0..3909ac86f8678 100644 --- a/packages/plugin/src/generators/migration/migration.spec.ts +++ b/packages/plugin/src/generators/migration/migration.spec.ts @@ -19,7 +19,6 @@ describe('NxPlugin migration generator', () => { await pluginGenerator(tree, { name: projectName, directory: 'packages/my-plugin', - projectNameAndRootFormat: 'as-provided', unitTestRunner: 'jest', linter: Linter.EsLint, compiler: 'tsc', diff --git a/packages/plugin/src/generators/plugin/plugin.spec.ts b/packages/plugin/src/generators/plugin/plugin.spec.ts index bc5efb005ed78..82f66a7ae6db7 100644 --- a/packages/plugin/src/generators/plugin/plugin.spec.ts +++ b/packages/plugin/src/generators/plugin/plugin.spec.ts @@ -17,7 +17,7 @@ import { Schema } from './schema'; const getSchema: (overrides?: Partial) => Schema = ( overrides = {} ) => ({ - name: 'my-plugin', + directory: 'my-plugin', compiler: 'tsc', skipTsConfig: false, skipFormat: false, @@ -91,7 +91,7 @@ describe('NxPlugin Plugin Generator', () => { await pluginGenerator( tree, getSchema({ - name: 'my-plugin', + directory: 'my-plugin', }) ); const project = readProjectConfiguration(tree, 'my-plugin'); @@ -126,7 +126,7 @@ describe('NxPlugin Plugin Generator', () => { tree, getSchema({ name: 'my-plugin', - rootProject: true, + directory: '.', }) ); const project = readProjectConfiguration(tree, 'my-plugin'); @@ -163,7 +163,7 @@ describe('NxPlugin Plugin Generator', () => { await pluginGenerator( tree, getSchema({ - name: 'my-plugin', + directory: 'my-plugin', unitTestRunner: 'none', }) ); diff --git a/packages/plugin/src/generators/plugin/plugin.ts b/packages/plugin/src/generators/plugin/plugin.ts index 7395cbf4cc47e..c5a561226a8f2 100644 --- a/packages/plugin/src/generators/plugin/plugin.ts +++ b/packages/plugin/src/generators/plugin/plugin.ts @@ -86,7 +86,6 @@ export async function pluginGenerator(host: Tree, schema: Schema) { bundler: options.bundler, publishable: options.publishable, importPath: options.npmPackageName, - projectNameAndRootFormat: 'as-provided', skipFormat: true, }) ); @@ -129,7 +128,6 @@ export async function pluginGenerator(host: Tree, schema: Schema) { npmPackageName: options.npmPackageName, skipFormat: true, rootProject: options.rootProject, - projectNameAndRootFormat: options.projectNameAndRootFormat, }) ); } diff --git a/packages/plugin/src/generators/plugin/schema.d.ts b/packages/plugin/src/generators/plugin/schema.d.ts index 1f6a6ae9abc44..3ca1321201740 100644 --- a/packages/plugin/src/generators/plugin/schema.d.ts +++ b/packages/plugin/src/generators/plugin/schema.d.ts @@ -1,10 +1,8 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { - name: string; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; + name?: string; importPath?: string; skipTsConfig?: boolean; // default is false skipFormat?: boolean; // default is false diff --git a/packages/plugin/src/generators/plugin/schema.json b/packages/plugin/src/generators/plugin/schema.json index 93312df508bde..62e49547400c0 100644 --- a/packages/plugin/src/generators/plugin/schema.json +++ b/packages/plugin/src/generators/plugin/schema.json @@ -12,25 +12,19 @@ } ], "properties": { - "name": { + "directory": { "type": "string", - "description": "Plugin name", + "description": "A directory where the plugin is placed.", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the plugin?", - "x-priority": "important", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" + "x-prompt": "Which directory do you want to create the plugin in?" }, - "directory": { - "type": "string", - "description": "A directory where the plugin is placed." - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Plugin name", + "x-priority": "important" }, "importPath": { "type": "string", @@ -100,5 +94,5 @@ "default": false } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/plugin/src/generators/plugin/utils/normalize-schema.ts b/packages/plugin/src/generators/plugin/utils/normalize-schema.ts index e40803cafc43c..c2453d6222d52 100644 --- a/packages/plugin/src/generators/plugin/utils/normalize-schema.ts +++ b/packages/plugin/src/generators/plugin/utils/normalize-schema.ts @@ -1,5 +1,8 @@ import { Tree, extractLayoutDirectory, getWorkspaceLayout } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Schema } from '../schema'; export interface NormalizedSchema extends Schema { @@ -12,24 +15,23 @@ export interface NormalizedSchema extends Schema { bundler: 'swc' | 'tsc'; publishable: boolean; } + export async function normalizeOptions( host: Tree, options: Schema ): Promise { + await ensureProjectName(host, options, 'application'); const { projectName, projectRoot, importPath: npmPackageName, - projectNameAndRootFormat, } = await determineProjectNameAndRootOptions(host, { name: options.name, projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, rootProject: options.rootProject, }); - options.projectNameAndRootFormat = projectNameAndRootFormat; options.rootProject = projectRoot === '.'; const projectDirectory = projectRoot; diff --git a/packages/plugin/src/generators/preset/generator.ts b/packages/plugin/src/generators/preset/generator.ts index 9e213af0c402c..e42d1a7126a98 100644 --- a/packages/plugin/src/generators/preset/generator.ts +++ b/packages/plugin/src/generators/preset/generator.ts @@ -26,7 +26,6 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) { const pluginTask = await pluginGenerator(tree, { compiler: 'tsc', linter: Linter.EsLint, - name: pluginProjectName, skipFormat: true, unitTestRunner: 'jest', importPath: options.pluginName, @@ -36,7 +35,7 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) { directory: options.createPackageName && options.createPackageName !== 'false' ? `packages/${pluginProjectName}` - : undefined, + : pluginProjectName, rootProject: options.createPackageName ? false : true, }); tasks.push(pluginTask); @@ -62,6 +61,7 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) { return runTasksInSerial(...tasks); } + function moveNxPluginToDevDeps(tree: Tree) { updateJson(tree, 'package.json', (json) => { const nxPluginEntry = json.dependencies['@nx/plugin']; diff --git a/packages/plugin/src/migrations/update-16-0-0/cli-in-schema-json.spec.ts b/packages/plugin/src/migrations/update-16-0-0/cli-in-schema-json.spec.ts index 2143268bc85f3..e3f821bb3d0fa 100644 --- a/packages/plugin/src/migrations/update-16-0-0/cli-in-schema-json.spec.ts +++ b/packages/plugin/src/migrations/update-16-0-0/cli-in-schema-json.spec.ts @@ -253,7 +253,7 @@ describe('updateCliPropsForPlugins', () => { async function createPlugin(tree: Tree) { await pluginGenerator(tree, { - name: 'my-plugin', + directory: 'my-plugin', compiler: 'tsc', linter: Linter.EsLint, unitTestRunner: 'jest', diff --git a/packages/react-native/src/generators/application/application.spec.ts b/packages/react-native/src/generators/application/application.spec.ts index 6b7b5b4be25e8..6dc0ea743aa17 100644 --- a/packages/react-native/src/generators/application/application.spec.ts +++ b/packages/react-native/src/generators/application/application.spec.ts @@ -20,12 +20,11 @@ describe('app', () => { it('should update configuration', async () => { await reactNativeApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', linter: Linter.EsLint, e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', unitTestRunner: 'none', bundler: 'vite', }); @@ -36,13 +35,12 @@ describe('app', () => { it('should update nx.json', async () => { await reactNativeApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', tags: 'one,two', linter: Linter.EsLint, e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', unitTestRunner: 'none', bundler: 'vite', }); @@ -55,12 +53,11 @@ describe('app', () => { it('should generate files', async () => { await reactNativeApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', linter: Linter.EsLint, e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', unitTestRunner: 'jest', bundler: 'vite', }); @@ -101,12 +98,11 @@ describe('app', () => { it('should generate targets', async () => { await reactNativeApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', linter: Linter.EsLint, e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', unitTestRunner: 'jest', bundler: 'vite', }); @@ -118,12 +114,11 @@ describe('app', () => { appTree.rename('tsconfig.base.json', 'tsconfig.json'); await reactNativeApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', linter: Linter.EsLint, e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', unitTestRunner: 'none', bundler: 'vite', }); @@ -140,7 +135,6 @@ describe('app', () => { linter: Linter.EsLint, e2eTestRunner: 'detox', install: false, - projectNameAndRootFormat: 'as-provided', bundler: 'vite', unitTestRunner: 'none', }); @@ -188,11 +182,10 @@ describe('app', () => { it('should create e2e app without directory', async () => { await reactNativeApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', linter: Linter.EsLint, e2eTestRunner: 'detox', install: false, - projectNameAndRootFormat: 'as-provided', bundler: 'vite', unitTestRunner: 'none', }); @@ -243,13 +236,12 @@ describe('app', () => { const packageJsonBefore = readJson(appTree, 'package.json'); await reactNativeApplicationGenerator(appTree, { - name: 'my-app', + directory: 'my-app', displayName: 'myApp', linter: Linter.EsLint, e2eTestRunner: 'none', install: false, skipPackageJson: true, - projectNameAndRootFormat: 'as-provided', unitTestRunner: 'none', bundler: 'webpack', }); diff --git a/packages/react-native/src/generators/application/lib/add-e2e.ts b/packages/react-native/src/generators/application/lib/add-e2e.ts index 6aff1fc81dd2f..a1be66b8be745 100644 --- a/packages/react-native/src/generators/application/lib/add-e2e.ts +++ b/packages/react-native/src/generators/application/lib/add-e2e.ts @@ -36,7 +36,6 @@ export async function addE2e( ...options, e2eName: options.e2eProjectName, e2eDirectory: options.e2eProjectRoot, - projectNameAndRootFormat: 'as-provided', appProject: options.projectName, appDisplayName: options.displayName, appName: options.name, diff --git a/packages/react-native/src/generators/application/lib/normalize-options.spec.ts b/packages/react-native/src/generators/application/lib/normalize-options.spec.ts index 7801876477c6b..c0d54f4bf5979 100644 --- a/packages/react-native/src/generators/application/lib/normalize-options.spec.ts +++ b/packages/react-native/src/generators/application/lib/normalize-options.spec.ts @@ -13,11 +13,10 @@ describe('Normalize Options', () => { it('should normalize options with name in kebab case', async () => { const schema: Schema = { - name: 'my-app', + directory: 'my-app', linter: Linter.EsLint, e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', unitTestRunner: 'none', bundler: 'vite', }; @@ -28,13 +27,13 @@ describe('Normalize Options', () => { appProjectRoot: 'my-app', fileName: 'my-app', className: 'MyApp', + directory: 'my-app', displayName: 'MyApp', iosProjectRoot: 'my-app/ios', lowerCaseName: 'myapp', name: 'my-app', parsedTags: [], projectName: 'my-app', - projectNameAndRootFormat: 'as-provided', linter: Linter.EsLint, entryFile: 'src/main.tsx', e2eTestRunner: 'none', @@ -49,10 +48,9 @@ describe('Normalize Options', () => { it('should normalize options with name in camel case', async () => { const schema: Schema = { - name: 'myApp', + directory: 'myApp', e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', linter: Linter.None, unitTestRunner: 'none', bundler: 'vite', @@ -64,13 +62,13 @@ describe('Normalize Options', () => { appProjectRoot: 'myApp', className: 'MyApp', fileName: 'my-app', + directory: 'myApp', displayName: 'MyApp', iosProjectRoot: 'myApp/ios', lowerCaseName: 'myapp', name: 'myApp', parsedTags: [], projectName: 'myApp', - projectNameAndRootFormat: 'as-provided', entryFile: 'src/main.tsx', e2eTestRunner: 'none', unitTestRunner: 'none', @@ -89,7 +87,6 @@ describe('Normalize Options', () => { directory: 'directory/my-app', e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', linter: Linter.None, unitTestRunner: 'none', bundler: 'vite', @@ -101,14 +98,13 @@ describe('Normalize Options', () => { appProjectRoot: 'directory/my-app', className: 'MyApp', fileName: 'my-app', + directory: 'directory/my-app', displayName: 'MyApp', iosProjectRoot: 'directory/my-app/ios', lowerCaseName: 'myapp', name: 'my-app', - directory: 'directory/my-app', parsedTags: [], projectName: 'my-app', - projectNameAndRootFormat: 'as-provided', entryFile: 'src/main.tsx', e2eTestRunner: 'none', unitTestRunner: 'none', @@ -123,10 +119,9 @@ describe('Normalize Options', () => { it('should normalize options that has directory in its name', async () => { const schema: Schema = { - name: 'directory/my-app', + directory: 'directory/my-app', e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', linter: Linter.None, unitTestRunner: 'none', bundler: 'vite', @@ -136,15 +131,15 @@ describe('Normalize Options', () => { addPlugin: true, androidProjectRoot: 'directory/my-app/android', appProjectRoot: 'directory/my-app', - className: 'DirectoryMyApp', - fileName: 'directory/my-app', - displayName: 'DirectoryMyApp', + className: 'MyApp', + directory: 'directory/my-app', + fileName: 'my-app', + displayName: 'MyApp', iosProjectRoot: 'directory/my-app/ios', - lowerCaseName: 'directorymyapp', + lowerCaseName: 'myapp', name: 'my-app', parsedTags: [], projectName: 'my-app', - projectNameAndRootFormat: 'as-provided', entryFile: 'src/main.tsx', e2eTestRunner: 'none', unitTestRunner: 'none', @@ -159,11 +154,10 @@ describe('Normalize Options', () => { it('should normalize options with display name', async () => { const schema: Schema = { - name: 'my-app', + directory: 'my-app', displayName: 'My App', e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', linter: Linter.None, unitTestRunner: 'none', bundler: 'vite', @@ -175,13 +169,13 @@ describe('Normalize Options', () => { appProjectRoot: 'my-app', className: 'MyApp', fileName: 'my-app', + directory: 'my-app', displayName: 'My App', iosProjectRoot: 'my-app/ios', lowerCaseName: 'myapp', name: 'my-app', parsedTags: [], projectName: 'my-app', - projectNameAndRootFormat: 'as-provided', entryFile: 'src/main.tsx', e2eTestRunner: 'none', unitTestRunner: 'none', diff --git a/packages/react-native/src/generators/application/lib/normalize-options.ts b/packages/react-native/src/generators/application/lib/normalize-options.ts index 275c19477f52d..685ac7b57d317 100644 --- a/packages/react-native/src/generators/application/lib/normalize-options.ts +++ b/packages/react-native/src/generators/application/lib/normalize-options.ts @@ -1,8 +1,9 @@ import { joinPathFragments, names, readNxJson, Tree } from '@nx/devkit'; -import { VitePluginOptions } from '@nx/vite/src/plugins/plugin'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Schema } from '../schema'; -import { ReactNativePluginOptions } from '../../../../plugins/plugin'; export interface NormalizedSchema extends Schema { className: string; // app name in class case @@ -23,18 +24,16 @@ export async function normalizeOptions( host: Tree, options: Schema ): Promise { + await ensureProjectName(host, options, 'application'); const { projectName: appProjectName, names: projectNames, projectRoot: appProjectRoot, - projectNameAndRootFormat, } = await determineProjectNameAndRootOptions(host, { name: options.name, projectType: 'application', directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); - options.projectNameAndRootFormat = projectNameAndRootFormat; const nxJson = readNxJson(host); const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && diff --git a/packages/react-native/src/generators/application/schema.d.ts b/packages/react-native/src/generators/application/schema.d.ts index 8559280626967..b0066e4bd8a99 100644 --- a/packages/react-native/src/generators/application/schema.d.ts +++ b/packages/react-native/src/generators/application/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { - name: string; + directory: string; + name?: string; displayName?: string; style?: string; skipFormat?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; unitTestRunner: 'jest' | 'none'; // default is jest classComponent?: boolean; diff --git a/packages/react-native/src/generators/application/schema.json b/packages/react-native/src/generators/application/schema.json index ff383d32b2847..a788cc695dd87 100644 --- a/packages/react-native/src/generators/application/schema.json +++ b/packages/react-native/src/generators/application/schema.json @@ -16,29 +16,24 @@ ], "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" }, - "displayName": { - "description": "The display name to show in the application. Defaults to name.", + "name": { + "description": "The name of the application.", + "pattern": "^[a-zA-Z][^:]*$", "type": "string" }, - "directory": { - "description": "The directory of the new application.", + "displayName": { + "description": "The display name to show in the application. Defaults to name.", "type": "string" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "skipFormat": { "description": "Skip formatting files", "type": "boolean", @@ -99,5 +94,5 @@ "x-priority": "important" } }, - "required": [] + "required": ["directory"] } diff --git a/packages/react-native/src/generators/library/lib/normalize-options.ts b/packages/react-native/src/generators/library/lib/normalize-options.ts index cdf361a435093..ec916e3aa2c70 100644 --- a/packages/react-native/src/generators/library/lib/normalize-options.ts +++ b/packages/react-native/src/generators/library/lib/normalize-options.ts @@ -1,5 +1,8 @@ -import { Tree, readNxJson } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { readNxJson, Tree } from '@nx/devkit'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Schema } from '../schema'; export interface NormalizedSchema extends Schema { @@ -16,6 +19,7 @@ export async function normalizeOptions( host: Tree, options: Schema ): Promise { + await ensureProjectName(host, options, 'library'); const { projectName, names: projectNames, @@ -26,7 +30,6 @@ export async function normalizeOptions( projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); const nxJson = readNxJson(host); diff --git a/packages/react-native/src/generators/library/library.spec.ts b/packages/react-native/src/generators/library/library.spec.ts index d8aa486ceca00..d9c0d403381e0 100644 --- a/packages/react-native/src/generators/library/library.spec.ts +++ b/packages/react-native/src/generators/library/library.spec.ts @@ -15,13 +15,12 @@ describe('lib', () => { let appTree: Tree; const defaultSchema: Schema = { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, skipFormat: false, skipTsConfig: false, unitTestRunner: 'jest', strict: true, - projectNameAndRootFormat: 'as-provided', addPlugin: true, }; @@ -112,6 +111,7 @@ describe('lib', () => { it('should update nx.json', async () => { await libraryGenerator(appTree, { ...defaultSchema, + name: 'my-lib', directory: 'my-dir', tags: 'one', }); @@ -140,6 +140,7 @@ describe('lib', () => { it('should update root tsconfig.base.json', async () => { await libraryGenerator(appTree, { ...defaultSchema, + name: 'my-lib', directory: 'my-dir', }); const tsconfigJson = readJson(appTree, '/tsconfig.base.json'); @@ -156,6 +157,7 @@ describe('lib', () => { await libraryGenerator(appTree, { ...defaultSchema, + name: 'my-lib', directory: 'my-dir', }); @@ -171,6 +173,7 @@ describe('lib', () => { it('should create a local tsconfig.json', async () => { await libraryGenerator(appTree, { ...defaultSchema, + name: 'my-lib', directory: 'my-dir', }); @@ -191,6 +194,7 @@ describe('lib', () => { await libraryGenerator(appTree, { ...defaultSchema, + name: 'my-lib', directory: 'my-dir', }); @@ -313,6 +317,7 @@ describe('lib', () => { try { await libraryGenerator(appTree, { ...defaultSchema, + name: 'my-lib', directory: 'my-dir', publishable: true, }); @@ -352,6 +357,7 @@ describe('lib', () => { await libraryGenerator(appTree, { ...defaultSchema, publishable: true, + name: 'my-lib', directory: 'my-dir', importPath: '@myorg/lib', }); @@ -367,7 +373,7 @@ describe('lib', () => { it('should fail if the same importPath has already been used', async () => { await libraryGenerator(appTree, { ...defaultSchema, - name: 'my-lib1', + directory: 'my-lib1', publishable: true, importPath: '@myorg/lib', }); @@ -375,7 +381,7 @@ describe('lib', () => { try { await libraryGenerator(appTree, { ...defaultSchema, - name: 'my-lib2', + directory: 'my-lib2', publishable: true, importPath: '@myorg/lib', }); diff --git a/packages/react-native/src/generators/library/schema.d.ts b/packages/react-native/src/generators/library/schema.d.ts index a8755a9683d31..63a11185cf23c 100644 --- a/packages/react-native/src/generators/library/schema.d.ts +++ b/packages/react-native/src/generators/library/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; /** * Same as the @nx/react library schema, except it removes keys: style, component, routing, appProject */ export interface Schema { - name: string; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; + name?: string; skipTsConfig: boolean; skipFormat: boolean; tags?: string; diff --git a/packages/react-native/src/generators/library/schema.json b/packages/react-native/src/generators/library/schema.json index f7a48eb14dd3e..5ba6c57225040 100644 --- a/packages/react-native/src/generators/library/schema.json +++ b/packages/react-native/src/generators/library/schema.json @@ -12,27 +12,22 @@ } ], "properties": { - "name": { + "directory": { "type": "string", - "description": "Library name.", + "description": "A directory where the lib is placed.", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" + "x-prompt": "Which directory do you want to create the library in?" }, - "directory": { + "name": { "type": "string", - "description": "A directory where the lib is placed.", - "alias": "dir", + "description": "Library name.", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -97,5 +92,5 @@ "x-priority": "internal" } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/react-native/src/utils/testing-generators.ts b/packages/react-native/src/utils/testing-generators.ts index 7592008601ca6..61c00cad55af9 100644 --- a/packages/react-native/src/utils/testing-generators.ts +++ b/packages/react-native/src/utils/testing-generators.ts @@ -8,10 +8,9 @@ export async function createApp(tree: Tree, appName: string): Promise { skipFormat: true, style: 'css', unitTestRunner: 'none', - name: appName, + directory: appName, e2eTestRunner: 'none', install: false, - projectNameAndRootFormat: 'as-provided', bundler: 'webpack', }); } diff --git a/packages/react/src/generators/application/application.legacy.spec.ts b/packages/react/src/generators/application/application.legacy.spec.ts index 0e423d866b132..1cd0e0fbd7468 100644 --- a/packages/react/src/generators/application/application.legacy.spec.ts +++ b/packages/react/src/generators/application/application.legacy.spec.ts @@ -15,11 +15,10 @@ describe('react app generator (legacy)', () => { compiler: 'babel', e2eTestRunner: 'cypress', skipFormat: false, - name: 'my-app', + directory: 'my-app', linter: Linter.EsLint, style: 'css', strict: true, - projectNameAndRootFormat: 'as-provided', addPlugin: false, }; let mockedInstalledCypressVersion: jest.Mock< @@ -34,7 +33,7 @@ describe('react app generator (legacy)', () => { it('should setup webpack config that is compatible without project targets', async () => { await applicationGenerator(appTree, { ...schema, - name: 'my-app', + directory: 'my-app', bundler: 'webpack', }); @@ -133,7 +132,7 @@ describe('react app generator (legacy)', () => { it('should setup vite', async () => { await applicationGenerator(appTree, { ...schema, - name: 'my-vite-app', + directory: 'my-vite-app', bundler: 'vite', skipFormat: true, }); diff --git a/packages/react/src/generators/application/application.spec.ts b/packages/react/src/generators/application/application.spec.ts index b5f5ffb143076..143cd83f2807a 100644 --- a/packages/react/src/generators/application/application.spec.ts +++ b/packages/react/src/generators/application/application.spec.ts @@ -25,11 +25,10 @@ describe('app', () => { compiler: 'babel', e2eTestRunner: 'cypress', skipFormat: true, - name: 'my-app', + directory: 'my-app', linter: Linter.EsLint, style: 'css', strict: true, - projectNameAndRootFormat: 'as-provided', addPlugin: true, }; let mockedInstalledCypressVersion: jest.Mock< @@ -509,7 +508,7 @@ describe('app', () => { }); it('should setup jest with tsx support', async () => { - await applicationGenerator(appTree, { ...schema, name: 'my-app' }); + await applicationGenerator(appTree, { ...schema, directory: 'my-app' }); expect(appTree.read('my-app/jest.config.ts').toString()).toContain( `moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],` @@ -517,7 +516,7 @@ describe('app', () => { }); it('should setup jest with babel-jest support', async () => { - await applicationGenerator(appTree, { ...schema, name: 'my-app' }); + await applicationGenerator(appTree, { ...schema, directory: 'my-app' }); expect(appTree.read('my-app/jest.config.ts').toString()).toContain( "['babel-jest', { presets: ['@nx/react/babel'] }]" @@ -525,7 +524,7 @@ describe('app', () => { }); it('should setup jest without serializers', async () => { - await applicationGenerator(appTree, { ...schema, name: 'my-app' }); + await applicationGenerator(appTree, { ...schema, directory: 'my-app' }); expect(appTree.read('my-app/jest.config.ts').toString()).not.toContain( `'jest-preset-angular/build/AngularSnapshotSerializer.js',` @@ -535,7 +534,7 @@ describe('app', () => { it('should setup webpack', async () => { await applicationGenerator(appTree, { ...schema, - name: 'my-app', + directory: 'my-app', bundler: 'webpack', }); @@ -545,7 +544,7 @@ describe('app', () => { it('should setup vite if bundler is vite', async () => { await applicationGenerator(appTree, { ...schema, - name: 'my-app', + directory: 'my-app', bundler: 'vite', }); @@ -556,7 +555,7 @@ describe('app', () => { it('should setup vite if bundler is vite (--js)', async () => { await applicationGenerator(appTree, { ...schema, - name: 'my-app', + directory: 'my-app', bundler: 'vite', js: true, }); @@ -568,7 +567,7 @@ describe('app', () => { it('should setup the nx vite dev server builder if bundler is vite', async () => { await applicationGenerator(appTree, { ...schema, - name: 'my-app', + directory: 'my-app', bundler: 'vite', }); @@ -576,7 +575,7 @@ describe('app', () => { }); it('should setup the eslint builder', async () => { - await applicationGenerator(appTree, { ...schema, name: 'my-app' }); + await applicationGenerator(appTree, { ...schema, directory: 'my-app' }); expect(appTree.exists('my-app/.eslintrc.json')).toBeTruthy(); }); @@ -957,7 +956,7 @@ describe('app', () => { it('should create default application without Nx welcome component', async () => { await applicationGenerator(appTree, { ...schema, - name: 'plain', + directory: 'plain', minimal: true, }); expect(appTree.exists('plain/src/app/nx-welcome.tsx')).toBeFalsy(); @@ -1018,12 +1017,12 @@ describe('app', () => { }); }); - describe('--root-project', () => { + describe('--directory="." (--root-project)', () => { it('should create files at the root', async () => { await applicationGenerator(appTree, { ...schema, name: 'my-app2', - rootProject: true, + directory: '.', bundler: 'vite', }); expect(appTree.read('/src/main.tsx')).toBeDefined(); @@ -1038,7 +1037,7 @@ describe('app', () => { await applicationGenerator(appTree, { ...schema, name: 'my-app3', - rootProject: true, + directory: '.', e2eTestRunner: 'playwright', }); @@ -1084,7 +1083,7 @@ describe('app', () => { await applicationGenerator(viteAppTree, { ...schema, - name: 'insourceTests', + directory: 'insourceTests', bundler: 'vite', inSourceTests: true, }); @@ -1106,7 +1105,7 @@ describe('app', () => { style, bundler: 'vite', unitTestRunner: 'vitest', - name: style, + directory: style, }); expect(readJson(viteAppTree, 'package.json')).toMatchObject({ @@ -1127,7 +1126,7 @@ describe('app', () => { // ACT await applicationGenerator(tree, { - name: 'myapp', + directory: 'myapp', addPlugin: false, linter: Linter.None, style: 'none', @@ -1155,7 +1154,7 @@ describe('app', () => { // ACT await applicationGenerator(tree, { - name: 'myapp', + directory: 'myapp', addPlugin: true, linter: Linter.None, style: 'none', @@ -1184,7 +1183,7 @@ describe('app', () => { // ACT await applicationGenerator(tree, { - name: 'myapp', + directory: 'myapp', addPlugin: true, linter: Linter.None, style: 'none', @@ -1220,7 +1219,7 @@ describe('app', () => { // ACT await applicationGenerator(tree, { - name: 'myapp', + directory: 'myapp', addPlugin: true, linter: Linter.None, style: 'none', diff --git a/packages/react/src/generators/application/lib/normalize-options.ts b/packages/react/src/generators/application/lib/normalize-options.ts index aab61f24f0b9e..6cb6a6080ef67 100644 --- a/packages/react/src/generators/application/lib/normalize-options.ts +++ b/packages/react/src/generators/application/lib/normalize-options.ts @@ -1,10 +1,11 @@ import { Tree, extractLayoutDirectory, names, readNxJson } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { assertValidStyle } from '../../../utils/assertion'; import { NormalizedSchema, Schema } from '../schema'; import { findFreePort } from './find-free-port'; -import { VitePluginOptions } from '@nx/vite/src/plugins/plugin'; -import { WebpackPluginOptions } from '@nx/webpack/src/plugins/plugin'; export function normalizeDirectory(options: Schema) { options.directory = options.directory?.replace(/\\{1,2}/g, '/'); @@ -22,17 +23,14 @@ export async function normalizeOptions( host: Tree, options: Schema ): Promise> { - const { - projectName: appProjectName, - projectRoot: appProjectRoot, - projectNameAndRootFormat, - } = await determineProjectNameAndRootOptions(host, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - rootProject: options.rootProject, - }); + await ensureProjectName(host, options, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(host, { + name: options.name, + projectType: 'application', + directory: options.directory, + rootProject: options.rootProject, + }); const nxJson = readNxJson(host); const addPlugin = @@ -42,7 +40,6 @@ export async function normalizeOptions( options.addPlugin ??= addPlugin; options.rootProject = appProjectRoot === '.'; - options.projectNameAndRootFormat = projectNameAndRootFormat; const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`; const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`; diff --git a/packages/react/src/generators/application/schema.d.ts b/packages/react/src/generators/application/schema.d.ts index c6a32a5a425e9..c0acac95870e0 100644 --- a/packages/react/src/generators/application/schema.d.ts +++ b/packages/react/src/generators/application/schema.d.ts @@ -1,13 +1,11 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { SupportedStyles } from '../../../typings/style'; export interface Schema { - name: string; + directory: string; + name?: string; style: SupportedStyles; skipFormat?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; unitTestRunner?: 'jest' | 'vitest' | 'none'; inSourceTests?: boolean; diff --git a/packages/react/src/generators/application/schema.json b/packages/react/src/generators/application/schema.json index d368e1996d763..0e331b3bccb9d 100644 --- a/packages/react/src/generators/application/schema.json +++ b/packages/react/src/generators/application/schema.json @@ -6,41 +6,36 @@ "description": "Create a React application for Nx.", "examples": [ { - "command": "nx g app myapp --directory=myorg", + "command": "nx g app apps/myorg/myapp", "description": "Generate `apps/myorg/myapp` and `apps/myorg/myapp-e2e`" }, { - "command": "nx g app myapp --classComponent", + "command": "nx g app apps/myapp --classComponent", "description": "Use class components instead of functional components" }, { - "command": "nx g app myapp --routing", + "command": "nx g app apps/myapp --routing", "description": "Set up React Router" } ], "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { + "description": "The name of the application.", "type": "string", - "alias": "dir", + "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -190,6 +185,6 @@ "default": false } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "../../../docs/application-examples.md" } diff --git a/packages/react/src/generators/component-story/component-story.spec.ts b/packages/react/src/generators/component-story/component-story.spec.ts index 397a5b6c0bd40..22290a367e67a 100644 --- a/packages/react/src/generators/component-story/component-story.spec.ts +++ b/packages/react/src/generators/component-story/component-story.spec.ts @@ -599,14 +599,13 @@ describe('react:component-story', () => { export async function createTestUILib(libName: string): Promise { let appTree = createTreeWithEmptyWorkspace(); await libraryGenerator(appTree, { - name: libName, + directory: libName, linter: Linter.EsLint, component: true, skipFormat: true, skipTsConfig: false, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }); const currentWorkspaceJson = getProjects(appTree); diff --git a/packages/react/src/generators/component-test/component-test.spec.ts b/packages/react/src/generators/component-test/component-test.spec.ts index c738c4470f85b..65e5cd9423865 100644 --- a/packages/react/src/generators/component-test/component-test.spec.ts +++ b/packages/react/src/generators/component-test/component-test.spec.ts @@ -20,7 +20,7 @@ describe(componentTestGenerator.name, () => { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', @@ -40,7 +40,7 @@ describe(componentTestGenerator.name, () => { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', @@ -61,7 +61,7 @@ describe(componentTestGenerator.name, () => { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', @@ -83,7 +83,7 @@ describe(componentTestGenerator.name, () => { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', @@ -103,7 +103,7 @@ describe(componentTestGenerator.name, () => { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', @@ -124,7 +124,7 @@ describe(componentTestGenerator.name, () => { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', @@ -164,7 +164,7 @@ export function AnotherCmp(props: AnotherCmpProps) { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', @@ -196,13 +196,12 @@ export function AnotherCmp() { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); tree.write( @@ -240,13 +239,12 @@ export function AnotherCmp2() { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); tree.write( @@ -286,13 +284,12 @@ export function AnotherCmp2() { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); tree.write( @@ -326,13 +323,12 @@ export function AnotherCmp(props: AnotherCmpProps) { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); tree.write( @@ -362,13 +358,12 @@ export function AnotherCmp(props: AnotherCmpProps) { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); tree.write( @@ -399,13 +394,12 @@ export function AnotherCmp(props: AnotherCmpProps) { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); await componentTestGenerator(tree, { project: 'some-lib', @@ -421,13 +415,12 @@ export function AnotherCmp(props: AnotherCmpProps) { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); tree.write( @@ -460,13 +453,12 @@ export default function AnotherCmp(props: AnotherCmpProps) { mockedAssertMinimumCypressVersion.mockReturnValue(); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); tree.write( 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 d0fe2ac2c0f16..76d354e913cf4 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 @@ -68,19 +68,17 @@ describe('React:CypressComponentTestConfiguration', () => { skipFormat: true, style: 'scss', unitTestRunner: 'none', - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); projectGraph = { @@ -126,19 +124,17 @@ describe('React:CypressComponentTestConfiguration', () => { skipFormat: true, style: 'scss', unitTestRunner: 'none', - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); // --build-target still needs to build the graph in order for readTargetOptions to work projectGraph = { @@ -195,19 +191,17 @@ describe('React:CypressComponentTestConfiguration', () => { skipFormat: true, style: 'scss', unitTestRunner: 'none', - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); projectGraph = { @@ -263,19 +257,17 @@ describe('React:CypressComponentTestConfiguration', () => { skipFormat: true, style: 'scss', unitTestRunner: 'none', - name: 'my-app', + directory: 'my-app', bundler: 'webpack', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); projectGraph = { @@ -330,19 +322,17 @@ describe('React:CypressComponentTestConfiguration', () => { skipFormat: true, style: 'scss', unitTestRunner: 'none', - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'jest', component: true, - projectNameAndRootFormat: 'as-provided', }); await componentGenerator(tree, { name: 'another-cmp', @@ -377,19 +367,17 @@ describe('React:CypressComponentTestConfiguration', () => { skipFormat: true, style: 'scss', unitTestRunner: 'none', - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'jest', js: true, - projectNameAndRootFormat: 'as-provided', }); await componentGenerator(tree, { name: 'some-cmp', @@ -434,18 +422,16 @@ describe('React:CypressComponentTestConfiguration', () => { skipFormat: true, style: 'scss', unitTestRunner: 'none', - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { - name: 'some-lib', + directory: 'some-lib', style: 'scss', unitTestRunner: 'none', linter: Linter.None, skipFormat: false, skipTsConfig: false, - projectNameAndRootFormat: 'as-provided', }); const appConfig = readProjectConfiguration(tree, 'my-app'); appConfig.targets['build'].executor = 'something/else'; @@ -492,19 +478,17 @@ describe('React:CypressComponentTestConfiguration', () => { skipFormat: true, style: 'scss', unitTestRunner: 'none', - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { linter: Linter.EsLint, - name: 'some-lib', + directory: 'some-lib', skipFormat: true, skipTsConfig: false, style: 'scss', unitTestRunner: 'none', component: true, - projectNameAndRootFormat: 'as-provided', }); projectGraph = { diff --git a/packages/react/src/generators/federate-module/federate-module.spec.ts b/packages/react/src/generators/federate-module/federate-module.spec.ts index d134c513daf1f..1f784206cb430 100644 --- a/packages/react/src/generators/federate-module/federate-module.spec.ts +++ b/packages/react/src/generators/federate-module/federate-module.spec.ts @@ -13,6 +13,7 @@ describe('federate-module', () => { let schema: Schema = { name: 'my-federated-module', remote: 'my-remote', + remoteDirectory: 'my-remote', path: 'my-remote/src/my-federated-module.ts', style: 'css', skipFormat: true, @@ -77,7 +78,7 @@ describe('federate-module', () => { describe('with remote', () => { let remoteSchema: remoteSchma = { - name: 'my-remote', + directory: 'my-existing-remote', e2eTestRunner: 'none', skipFormat: false, linter: Linter.EsLint, @@ -93,7 +94,7 @@ describe('federate-module', () => { it('should append the new path to the module federation config', async () => { let content = tree.read( - `${remoteSchema.name}/module-federation.config.ts`, + `${remoteSchema.directory}/module-federation.config.ts`, 'utf-8' ); @@ -103,11 +104,11 @@ describe('federate-module', () => { await federateModuleGenerator(tree, { ...schema, - remote: remoteSchema.name, + remoteDirectory: remoteSchema.directory, }); content = tree.read( - `${remoteSchema.name}/module-federation.config.ts`, + `${remoteSchema.directory}/module-federation.config.ts`, 'utf-8' ); expect(content).toContain( @@ -116,9 +117,7 @@ describe('federate-module', () => { const tsconfig = JSON.parse(tree.read('tsconfig.base.json', 'utf-8')); expect( - tsconfig.compilerOptions.paths[ - `${remoteSchema.name}/my-federated-module` - ] + tsconfig.compilerOptions.paths[`${schema.remote}/my-federated-module`] ).toEqual(['my-remote/src/my-federated-module.ts']); }); }); diff --git a/packages/react/src/generators/federate-module/federate-module.ts b/packages/react/src/generators/federate-module/federate-module.ts index e134db8f9daf3..daa96c85b14c6 100644 --- a/packages/react/src/generators/federate-module/federate-module.ts +++ b/packages/react/src/generators/federate-module/federate-module.ts @@ -13,7 +13,10 @@ import { Schema } from './schema'; import { remoteGenerator } from '../remote/remote'; import { addPathToExposes, checkRemoteExists } from './lib/utils'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { addTsConfigPath, getRootTsConfigPathInTree } from '@nx/js'; export async function federateModuleGenerator(tree: Tree, schema: Schema) { @@ -24,16 +27,22 @@ export async function federateModuleGenerator(tree: Tree, schema: Schema) { Path: ${schema.path}`); } const tasks: GeneratorCallback[] = []; - // Check remote exists - const remote = checkRemoteExists(tree, schema.remote); - let projectRoot, remoteName; + const { projectName: remoteName, projectRoot: remoteRoot } = + await determineProjectNameAndRootOptions(tree, { + name: schema.remote, + directory: schema.remoteDirectory, + projectType: 'application', + }); + + // Check remote exists + const remote = checkRemoteExists(tree, remoteName); if (!remote) { // create remote const remoteGeneratorTask = await remoteGenerator(tree, { - name: schema.remote, - directory: schema.remoteDirectory, + name: remoteName, + directory: remoteRoot, e2eTestRunner: schema.e2eTestRunner, skipFormat: schema.skipFormat, linter: schema.linter, @@ -41,32 +50,17 @@ export async function federateModuleGenerator(tree: Tree, schema: Schema) { unitTestRunner: schema.unitTestRunner, host: schema.host, bundler: schema.bundler ?? 'rspack', - projectNameAndRootFormat: schema.projectNameAndRootFormat, }); tasks.push(remoteGeneratorTask); - - const { projectName, projectRoot: remoteRoot } = - await determineProjectNameAndRootOptions(tree, { - name: schema.remote, - directory: schema.remoteDirectory, - projectType: 'application', - projectNameAndRootFormat: schema.projectNameAndRootFormat, - }); - - projectRoot = remoteRoot; - remoteName = projectName; - } else { - projectRoot = remote.root; - remoteName = remote.name; } // add path to exposes property const normalizedModulePath = schema.bundler === 'rspack' - ? joinPathFragments(offsetFromRoot(projectRoot), schema.path) + ? joinPathFragments(offsetFromRoot(remoteRoot), schema.path) : schema.path; - addPathToExposes(tree, projectRoot, schema.name, normalizedModulePath); + addPathToExposes(tree, remoteRoot, schema.name, normalizedModulePath); // Add new path to tsconfig const rootJSON = readJson(tree, getRootTsConfigPathInTree(tree)); diff --git a/packages/react/src/generators/federate-module/schema.d.ts b/packages/react/src/generators/federate-module/schema.d.ts index 2906f803fef3a..afad22612ddb3 100644 --- a/packages/react/src/generators/federate-module/schema.d.ts +++ b/packages/react/src/generators/federate-module/schema.d.ts @@ -5,7 +5,6 @@ export interface Schema { path: string; remote: string; remoteDirectory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; e2eTestRunner?: 'cypress' | 'playwright' | 'none'; host?: string; linter?: Linter | LinterType; diff --git a/packages/react/src/generators/federate-module/schema.json b/packages/react/src/generators/federate-module/schema.json index c2c381ed63c6e..e6fe54eb6ccad 100644 --- a/packages/react/src/generators/federate-module/schema.json +++ b/packages/react/src/generators/federate-module/schema.json @@ -37,11 +37,6 @@ "description": "The directory of the new remote application if one needs to be created.", "type": "string" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", diff --git a/packages/react/src/generators/host/host.rspack.spec.ts b/packages/react/src/generators/host/host.rspack.spec.ts index 199d5baf01cdd..2925acf8b316e 100644 --- a/packages/react/src/generators/host/host.rspack.spec.ts +++ b/packages/react/src/generators/host/host.rspack.spec.ts @@ -108,12 +108,11 @@ xdescribe('hostGenerator', () => { describe('bundler=rspack', () => { it('should generate host files and configs when --js=true', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, skipFormat: true, js: true, @@ -129,12 +128,11 @@ xdescribe('hostGenerator', () => { it('should generate host files and configs when --js=false', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'rspack', }); @@ -148,12 +146,11 @@ xdescribe('hostGenerator', () => { it('should generate host files and configs when --typescriptConfiguration=true', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, skipFormat: true, bundler: 'rspack', @@ -174,12 +171,11 @@ xdescribe('hostGenerator', () => { it('should generate host files and configs when --typescriptConfiguration=false', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'rspack', }); @@ -200,12 +196,11 @@ xdescribe('hostGenerator', () => { it('should install @nx/web for the file-server executor', async () => { const tree = createTreeWithEmptyWorkspace(); await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', skipFormat: true, bundler: 'rspack', }); @@ -216,13 +211,12 @@ xdescribe('hostGenerator', () => { it('should generate host files and configs for SSR', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', ssr: true, style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'rspack', }); @@ -263,13 +257,12 @@ xdescribe('hostGenerator', () => { it('should generate host files and configs for SSR when --typescriptConfiguration=true', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', ssr: true, style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, bundler: 'rspack', }); @@ -308,14 +301,12 @@ xdescribe('hostGenerator', () => { ).toMatchSnapshot(); }); - it('should generate a host and remotes in a directory correctly when using --projectNameAndRootFormat=as-provided', async () => { + it('should generate a host and remotes in a directory correctly', async () => { const tree = createTreeWithEmptyWorkspace(); await hostGenerator(tree, { - name: 'host-app', directory: 'foo/host-app', remotes: ['remote1', 'remote2', 'remote3'], - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'none', linter: Linter.None, style: 'css', @@ -332,14 +323,12 @@ xdescribe('hostGenerator', () => { ).toContain(`'remote1', 'remote2', 'remote3'`); }); - it('should generate a host and remotes in a directory correctly when using --projectNameAndRootFormat=as-provided and --typescriptConfiguration=true', async () => { + it('should generate a host and remotes in a directory correctly when using --typescriptConfiguration=true', async () => { const tree = createTreeWithEmptyWorkspace(); await hostGenerator(tree, { - name: 'host-app', directory: 'foo/host-app', remotes: ['remote1', 'remote2', 'remote3'], - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'none', linter: Linter.None, style: 'css', @@ -362,10 +351,9 @@ xdescribe('hostGenerator', () => { await expect( hostGenerator(tree, { - name: 'myhostapp', + directory: 'myhostapp', remotes: [remote], dynamic: true, - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'none', linter: Linter.None, style: 'css', diff --git a/packages/react/src/generators/host/host.ts b/packages/react/src/generators/host/host.ts index 39cc8fcaa4993..95a7393b09c3a 100644 --- a/packages/react/src/generators/host/host.ts +++ b/packages/react/src/generators/host/host.ts @@ -24,6 +24,7 @@ import { NormalizedSchema, Schema } from './schema'; import { addMfEnvToTargetDefaultInputs } from '../../utils/add-mf-env-to-inputs'; import { isValidVariable } from '@nx/js'; import { moduleFederationEnhancedVersion } from '../../utils/versions'; +import { ensureProjectName } from '@nx/devkit/src/generators/project-name-and-root-utils'; export async function hostGenerator( host: Tree, @@ -55,6 +56,7 @@ export async function hostGenerator( }); } + await ensureProjectName(host, options, 'application'); const initTask = await applicationGenerator(host, { ...options, name: options.projectName, @@ -82,7 +84,6 @@ export async function hostGenerator( devServerPort: remotePort, ssr: options.ssr, skipFormat: true, - projectNameAndRootFormat: options.projectNameAndRootFormat, typescriptConfiguration: options.typescriptConfiguration, js: options.js, dynamic: options.dynamic, diff --git a/packages/react/src/generators/host/host.webpack.spec.ts b/packages/react/src/generators/host/host.webpack.spec.ts index fd9ccead74fd7..7f4a836377e4a 100644 --- a/packages/react/src/generators/host/host.webpack.spec.ts +++ b/packages/react/src/generators/host/host.webpack.spec.ts @@ -107,12 +107,11 @@ describe('hostGenerator', () => { describe('bundler=webpack', () => { it('should generate host files and configs when --js=true', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, skipFormat: true, js: true, @@ -128,12 +127,11 @@ describe('hostGenerator', () => { it('should generate host files and configs when --js=false', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'webpack', }); @@ -147,12 +145,11 @@ describe('hostGenerator', () => { it('should generate host files and configs when --typescriptConfiguration=true', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, skipFormat: true, bundler: 'webpack', @@ -173,12 +170,11 @@ describe('hostGenerator', () => { it('should generate host files and configs when --typescriptConfiguration=false', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'webpack', }); @@ -199,12 +195,11 @@ describe('hostGenerator', () => { it('should install @nx/web for the file-server executor', async () => { const tree = createTreeWithEmptyWorkspace(); await hostGenerator(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', skipFormat: true, bundler: 'webpack', }); @@ -215,13 +210,12 @@ describe('hostGenerator', () => { it('should generate host files and configs for SSR', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', ssr: true, style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'webpack', }); @@ -262,13 +256,12 @@ describe('hostGenerator', () => { it('should generate host files and configs for SSR when --typescriptConfiguration=true', async () => { await hostGenerator(tree, { - name: 'test', + directory: 'test', ssr: true, style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, bundler: 'webpack', }); @@ -307,14 +300,12 @@ describe('hostGenerator', () => { ).toMatchSnapshot(); }); - it('should generate a host and remotes in a directory correctly when using --projectNameAndRootFormat=as-provided', async () => { + it('should generate a host and remotes in a directory correctly', async () => { const tree = createTreeWithEmptyWorkspace(); await hostGenerator(tree, { - name: 'host-app', directory: 'foo/host-app', remotes: ['remote1', 'remote2', 'remote3'], - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'none', linter: Linter.None, style: 'css', @@ -331,14 +322,12 @@ describe('hostGenerator', () => { ).toContain(`'remote1', 'remote2', 'remote3'`); }); - it('should generate a host and remotes in a directory correctly when using --projectNameAndRootFormat=as-provided and --typescriptConfiguration=true', async () => { + it('should generate a host and remotes in a directory correctly when using --typescriptConfiguration=true', async () => { const tree = createTreeWithEmptyWorkspace(); await hostGenerator(tree, { - name: 'host-app', directory: 'foo/host-app', remotes: ['remote1', 'remote2', 'remote3'], - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'none', linter: Linter.None, style: 'css', @@ -361,10 +350,9 @@ describe('hostGenerator', () => { await expect( hostGenerator(tree, { - name: 'myhostapp', + directory: 'myhostapp', remotes: [remote], dynamic: true, - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'none', linter: Linter.None, style: 'css', diff --git a/packages/react/src/generators/host/lib/normalize-remote.ts b/packages/react/src/generators/host/lib/normalize-remote.ts index dfcd1c5ee0df4..dac4afa1f6ed8 100644 --- a/packages/react/src/generators/host/lib/normalize-remote.ts +++ b/packages/react/src/generators/host/lib/normalize-remote.ts @@ -1,4 +1,4 @@ -import { Tree, joinPathFragments } from '@nx/devkit'; +import { joinPathFragments, Tree } from '@nx/devkit'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { NormalizedSchema } from '../schema'; @@ -13,7 +13,6 @@ export async function normalizeRemoteName( name: remote, projectType: 'application', directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, } ); diff --git a/packages/react/src/generators/host/schema.d.ts b/packages/react/src/generators/host/schema.d.ts index b070fc79014d2..431ce0d77ce56 100644 --- a/packages/react/src/generators/host/schema.d.ts +++ b/packages/react/src/generators/host/schema.d.ts @@ -1,4 +1,3 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { SupportedStyles } from '../../../typings/style'; @@ -6,13 +5,12 @@ export interface Schema { classComponent?: boolean; compiler?: 'babel' | 'swc'; devServerPort?: number; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; e2eTestRunner: 'cypress' | 'playwright' | 'none'; globalCss?: boolean; js?: boolean; linter: Linter | LinterType; - name: string; + name?: string; remotes?: string[]; setParserOptionsProject?: boolean; skipFormat?: boolean; diff --git a/packages/react/src/generators/host/schema.json b/packages/react/src/generators/host/schema.json index 6001de3cf8739..0c6143a53fcb0 100644 --- a/packages/react/src/generators/host/schema.json +++ b/packages/react/src/generators/host/schema.json @@ -6,28 +6,22 @@ "description": "Create Module Federation configuration files for given React Host Application.", "type": "object", "properties": { - "name": { + "directory": { + "description": "The directory of the new application.", "type": "string", - "description": "The name of the host application to generate the Module Federation configuration", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use as the host application?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { "type": "string", - "alias": "dir", + "description": "The name of the host application to generate the Module Federation configuration", + "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -187,6 +181,6 @@ "x-priority": "important" } }, - "required": ["name"], + "required": ["directory"], "additionalProperties": false } diff --git a/packages/react/src/generators/library/lib/normalize-options.spec.ts b/packages/react/src/generators/library/lib/normalize-options.spec.ts index 0e1bafc067fbd..4df5ca1698b01 100644 --- a/packages/react/src/generators/library/lib/normalize-options.spec.ts +++ b/packages/react/src/generators/library/lib/normalize-options.spec.ts @@ -12,7 +12,7 @@ describe('normalizeOptions', () => { it('should set unitTestRunner=jest and bundler=none by default', async () => { const options = await normalizeOptions(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, unitTestRunner: 'jest', @@ -28,7 +28,7 @@ describe('normalizeOptions', () => { it('should set buildable to true when bundler is not "none"', async () => { let options = await normalizeOptions(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, bundler: 'rollup', @@ -40,7 +40,7 @@ describe('normalizeOptions', () => { }); options = await normalizeOptions(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, bundler: 'vite', @@ -54,7 +54,7 @@ describe('normalizeOptions', () => { it('should set unitTestRunner=vitest by default when bundler is vite', async () => { const options = await normalizeOptions(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, bundler: 'vite', @@ -71,7 +71,7 @@ describe('normalizeOptions', () => { it('should set maintain unitTestRunner when bundler is vite', async () => { const options = await normalizeOptions(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, bundler: 'vite', @@ -88,7 +88,7 @@ describe('normalizeOptions', () => { it('should set bundler to rollup if buildable is true not no bundler is passed', async () => { const options = await normalizeOptions(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, buildable: true, @@ -104,7 +104,7 @@ describe('normalizeOptions', () => { it('should set bundler to rollup if buildable is true and bundler is none ', async () => { const options = await normalizeOptions(tree, { - name: 'test', + directory: 'test', style: 'css', linter: Linter.None, buildable: true, diff --git a/packages/react/src/generators/library/lib/normalize-options.ts b/packages/react/src/generators/library/lib/normalize-options.ts index 5f0eb7da00a1a..389c2b74cd93b 100644 --- a/packages/react/src/generators/library/lib/normalize-options.ts +++ b/packages/react/src/generators/library/lib/normalize-options.ts @@ -6,7 +6,10 @@ import { readNxJson, Tree, } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { assertValidStyle } from '../../../utils/assertion'; import { NormalizedSchema, Schema } from '../schema'; @@ -14,6 +17,7 @@ export async function normalizeOptions( host: Tree, options: Schema ): Promise { + await ensureProjectName(host, options, 'library'); const { projectName, names: projectNames, @@ -24,7 +28,6 @@ export async function normalizeOptions( projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); const nxJson = readNxJson(host); const addPlugin = diff --git a/packages/react/src/generators/library/library.spec.ts b/packages/react/src/generators/library/library.spec.ts index 2ce45894ed4db..0f738d2fe2637 100644 --- a/packages/react/src/generators/library/library.spec.ts +++ b/packages/react/src/generators/library/library.spec.ts @@ -23,7 +23,7 @@ describe('lib', () => { ReturnType > = installedCypressVersion as never; let defaultSchema: Schema = { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, skipFormat: true, skipTsConfig: false, @@ -460,17 +460,15 @@ describe('lib', () => { linter: Linter.EsLint, skipFormat: true, unitTestRunner: 'jest', - name: 'my-app', + directory: 'my-app', routing: true, style: 'css', bundler: 'webpack', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { ...defaultSchema, appProject: 'my-app', - projectNameAndRootFormat: 'as-provided', }); const appSource = tree.read('my-app/src/app/app.tsx', 'utf-8'); @@ -489,16 +487,14 @@ describe('lib', () => { linter: Linter.EsLint, skipFormat: true, unitTestRunner: 'jest', - name: 'my-app', + directory: 'my-app', style: 'css', bundler: 'webpack', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { ...defaultSchema, appProject: 'my-app', - projectNameAndRootFormat: 'as-provided', }); const appSource = tree.read('my-app/src/app/app.tsx', 'utf-8'); @@ -732,7 +728,7 @@ module.exports = withNx( it('should fail if the same importPath has already been used', async () => { await libraryGenerator(tree, { ...defaultSchema, - name: 'my-lib-1', + directory: 'my-lib-1', publishable: true, importPath: '@myorg/lib', }); @@ -740,7 +736,7 @@ module.exports = withNx( try { await libraryGenerator(tree, { ...defaultSchema, - name: 'my-lib-2', + directory: 'my-lib-2', publishable: true, importPath: '@myorg/lib', }); diff --git a/packages/react/src/generators/library/schema.d.ts b/packages/react/src/generators/library/schema.d.ts index 6e8d0953c614c..8bcd42b369ea0 100644 --- a/packages/react/src/generators/library/schema.d.ts +++ b/packages/react/src/generators/library/schema.d.ts @@ -1,4 +1,3 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { SupportedStyles } from '../../../typings/style'; @@ -8,14 +7,13 @@ export interface Schema { bundler?: 'none' | 'rollup' | 'vite'; compiler?: 'babel' | 'swc'; component?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; globalCss?: boolean; importPath?: string; inSourceTests?: boolean; js?: boolean; linter: Linter | LinterType; - name: string; + name?: string; publishable?: boolean; routing?: boolean; setParserOptionsProject?: boolean; diff --git a/packages/react/src/generators/library/schema.json b/packages/react/src/generators/library/schema.json index aa604bb570fc8..cdac0a30d5271 100644 --- a/packages/react/src/generators/library/schema.json +++ b/packages/react/src/generators/library/schema.json @@ -16,28 +16,21 @@ } ], "properties": { - "name": { + "directory": { "type": "string", - "description": "Library name", + "description": "A directory where the lib is placed.", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", - "x-priority": "important" + "x-prompt": "Which directory do you want to create the library in?" }, - "directory": { + "name": { "type": "string", - "description": "A directory where the lib is placed.", - "alias": "dir", + "description": "Library name", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -47,7 +40,10 @@ "message": "Which stylesheet format would you like to use?", "type": "list", "items": [ - { "value": "css", "label": "CSS" }, + { + "value": "css", + "label": "CSS" + }, { "value": "scss", "label": "SASS(.scss) [ https://sass-lang.com ]" @@ -189,5 +185,5 @@ "default": false } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/react/src/generators/redux/redux.spec.ts b/packages/react/src/generators/redux/redux.spec.ts index c4580f076508a..cadeef50a39ea 100644 --- a/packages/react/src/generators/redux/redux.spec.ts +++ b/packages/react/src/generators/redux/redux.spec.ts @@ -13,13 +13,12 @@ describe('redux', () => { beforeEach(async () => { appTree = createTreeWithEmptyWorkspace(); await libraryGenerator(appTree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, skipFormat: true, skipTsConfig: false, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', }); }); @@ -54,8 +53,7 @@ describe('redux', () => { skipFormat: true, style: 'css', unitTestRunner: 'none', - name: 'my-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-app', }); await reduxGenerator(appTree, { name: 'my-slice', diff --git a/packages/react/src/generators/remote/remote.rspack.spec.ts b/packages/react/src/generators/remote/remote.rspack.spec.ts index e3b312be5fd44..5d439679334ca 100644 --- a/packages/react/src/generators/remote/remote.rspack.spec.ts +++ b/packages/react/src/generators/remote/remote.rspack.spec.ts @@ -104,14 +104,13 @@ xdescribe('remote generator', () => { it('should create the remote with the correct config files', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: true, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'rspack', }); @@ -137,14 +136,13 @@ xdescribe('remote generator', () => { it('should create the remote with the correct config files when --js=true', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: true, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, js: true, bundler: 'rspack', @@ -171,14 +169,13 @@ xdescribe('remote generator', () => { it('should create the remote with the correct config files when --typescriptConfiguration=true', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: false, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, bundler: 'rspack', }); @@ -199,14 +196,13 @@ xdescribe('remote generator', () => { it('should install @nx/web for the file-server executor', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: true, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', bundler: 'rspack', }); @@ -217,14 +213,13 @@ xdescribe('remote generator', () => { it('should not set the remote as the default project', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: true, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', bundler: 'rspack', }); @@ -236,7 +231,7 @@ xdescribe('remote generator', () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, @@ -244,7 +239,6 @@ xdescribe('remote generator', () => { style: 'css', unitTestRunner: 'jest', ssr: true, - projectNameAndRootFormat: 'as-provided', bundler: 'rspack', }); @@ -257,7 +251,7 @@ xdescribe('remote generator', () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, @@ -265,7 +259,6 @@ xdescribe('remote generator', () => { style: 'css', unitTestRunner: 'jest', ssr: true, - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'rspack', }); @@ -287,7 +280,7 @@ xdescribe('remote generator', () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, @@ -295,7 +288,6 @@ xdescribe('remote generator', () => { style: 'css', unitTestRunner: 'jest', ssr: true, - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, bundler: 'rspack', }); @@ -318,7 +310,7 @@ xdescribe('remote generator', () => { const name = 'invalid-dynamic-remote-name'; await expect( remote(tree, { - name, + directory: name, devServerPort: 4209, dynamic: true, e2eTestRunner: 'cypress', @@ -327,7 +319,6 @@ xdescribe('remote generator', () => { style: 'css', unitTestRunner: 'jest', ssr: true, - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, bundler: 'rspack', }) diff --git a/packages/react/src/generators/remote/remote.ts b/packages/react/src/generators/remote/remote.ts index 71daaf5be947e..c5d52219bb865 100644 --- a/packages/react/src/generators/remote/remote.ts +++ b/packages/react/src/generators/remote/remote.ts @@ -26,6 +26,7 @@ import { addMfEnvToTargetDefaultInputs } from '../../utils/add-mf-env-to-inputs' import { maybeJs } from '../../utils/maybe-js'; import { isValidVariable } from '@nx/js'; import { moduleFederationEnhancedVersion } from '../../utils/versions'; +import { ensureProjectName } from '@nx/devkit/src/generators/project-name-and-root-utils'; export function addModuleFederationFiles( host: Tree, @@ -114,6 +115,7 @@ export async function remoteGenerator(host: Tree, schema: Schema) { } } + await ensureProjectName(host, options, 'application'); const initAppTask = await applicationGenerator(host, { ...options, name: options.projectName, diff --git a/packages/react/src/generators/remote/remote.webpack.spec.ts b/packages/react/src/generators/remote/remote.webpack.spec.ts index 296487058c0f8..bdbd69e053b4c 100644 --- a/packages/react/src/generators/remote/remote.webpack.spec.ts +++ b/packages/react/src/generators/remote/remote.webpack.spec.ts @@ -103,14 +103,13 @@ describe('remote generator', () => { it('should create the remote with the correct config files', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: true, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'webpack', }); @@ -136,14 +135,13 @@ describe('remote generator', () => { it('should create the remote with the correct config files when --js=true', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: true, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, js: true, bundler: 'webpack', @@ -170,14 +168,13 @@ describe('remote generator', () => { it('should create the remote with the correct config files when --typescriptConfiguration=true', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: false, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, bundler: 'webpack', }); @@ -198,14 +195,13 @@ describe('remote generator', () => { it('should install @nx/web for the file-server executor', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: true, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', bundler: 'webpack', }); @@ -216,14 +212,13 @@ describe('remote generator', () => { it('should not set the remote as the default project', async () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, skipFormat: true, style: 'css', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', bundler: 'webpack', }); @@ -235,7 +230,7 @@ describe('remote generator', () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, @@ -243,7 +238,6 @@ describe('remote generator', () => { style: 'css', unitTestRunner: 'jest', ssr: true, - projectNameAndRootFormat: 'as-provided', bundler: 'webpack', }); @@ -256,7 +250,7 @@ describe('remote generator', () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, @@ -264,7 +258,6 @@ describe('remote generator', () => { style: 'css', unitTestRunner: 'jest', ssr: true, - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: false, bundler: 'webpack', }); @@ -286,7 +279,7 @@ describe('remote generator', () => { const tree = createTreeWithEmptyWorkspace(); await remote(tree, { - name: 'test', + directory: 'test', devServerPort: 4201, e2eTestRunner: 'cypress', linter: Linter.EsLint, @@ -294,7 +287,6 @@ describe('remote generator', () => { style: 'css', unitTestRunner: 'jest', ssr: true, - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, bundler: 'webpack', }); @@ -317,7 +309,7 @@ describe('remote generator', () => { const name = 'invalid-dynamic-remote-name'; await expect( remote(tree, { - name, + directory: name, devServerPort: 4209, dynamic: true, e2eTestRunner: 'cypress', @@ -326,7 +318,6 @@ describe('remote generator', () => { style: 'css', unitTestRunner: 'jest', ssr: true, - projectNameAndRootFormat: 'as-provided', typescriptConfiguration: true, bundler: 'webpack', }) diff --git a/packages/react/src/generators/remote/schema.d.ts b/packages/react/src/generators/remote/schema.d.ts index 9a133e03c617c..b268628178f3f 100644 --- a/packages/react/src/generators/remote/schema.d.ts +++ b/packages/react/src/generators/remote/schema.d.ts @@ -1,4 +1,3 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; import type { SupportedStyles } from '../../../typings/style'; import type { NormalizedSchema as ApplicationNormalizedSchema } from '../application/schema'; @@ -7,14 +6,13 @@ export interface Schema { classComponent?: boolean; compiler?: 'babel' | 'swc'; devServerPort?: number; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; e2eTestRunner: 'cypress' | 'playwright' | 'none'; globalCss?: boolean; host?: string; js?: boolean; linter: Linter | LinterType; - name: string; + name?: string; routing?: boolean; setParserOptionsProject?: boolean; skipFormat: boolean; diff --git a/packages/react/src/generators/remote/schema.json b/packages/react/src/generators/remote/schema.json index 7d3e3cded263d..3d3331765e5d4 100644 --- a/packages/react/src/generators/remote/schema.json +++ b/packages/react/src/generators/remote/schema.json @@ -6,28 +6,22 @@ "description": "Create Module Federation configuration files for given React Remote Application.", "type": "object", "properties": { - "name": { + "directory": { + "description": "The directory of the new application.", "type": "string", - "description": "The name of the remote application to generate the Module Federation configuration", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use as the remote application?", - "pattern": "^[a-zA-Z][^:]*$", - "x-priority": "important" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { "type": "string", - "alias": "dir", + "description": "The name of the remote application to generate the Module Federation configuration", + "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "dynamic": { "type": "boolean", "description": "Should the host application use dynamic federation?", @@ -186,6 +180,6 @@ "x-priority": "important" } }, - "required": ["name"], + "required": ["directory"], "additionalProperties": false } diff --git a/packages/react/src/generators/setup-ssr/setup-ssr.spec.ts b/packages/react/src/generators/setup-ssr/setup-ssr.spec.ts index f68b403873eca..b400220264ef9 100644 --- a/packages/react/src/generators/setup-ssr/setup-ssr.spec.ts +++ b/packages/react/src/generators/setup-ssr/setup-ssr.spec.ts @@ -112,12 +112,11 @@ describe('setupSsrGenerator', () => { tree = createTreeWithEmptyWorkspace(); applicationGenerator(tree, { - name: appName, + directory: appName, style: 'css', linter: Linter.None, unitTestRunner: 'none', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', skipFormat: true, }); }); diff --git a/packages/react/src/generators/stories/stories.app.spec.ts b/packages/react/src/generators/stories/stories.app.spec.ts index 40f26b33e6e9b..e136e976dac44 100644 --- a/packages/react/src/generators/stories/stories.app.spec.ts +++ b/packages/react/src/generators/stories/stories.app.spec.ts @@ -325,9 +325,8 @@ export async function createTestUIApp( skipFormat: true, style: 'css', unitTestRunner: 'none', - name: libName, + directory: libName, js: plainJS, - projectNameAndRootFormat: 'as-provided', }); return appTree; } diff --git a/packages/react/src/generators/stories/stories.lib.spec.ts b/packages/react/src/generators/stories/stories.lib.spec.ts index c54203fe189a4..71bba6f9af691 100644 --- a/packages/react/src/generators/stories/stories.lib.spec.ts +++ b/packages/react/src/generators/stories/stories.lib.spec.ts @@ -239,8 +239,7 @@ export async function createTestUILib( skipTsConfig: false, style: 'css', unitTestRunner: 'none', - name: libName, - projectNameAndRootFormat: 'as-provided', + directory: libName, }); return appTree; diff --git a/packages/react/src/generators/stories/stories.nextjs.spec.ts b/packages/react/src/generators/stories/stories.nextjs.spec.ts index bc54fe60a6170..9e70a4ddc1379 100644 --- a/packages/react/src/generators/stories/stories.nextjs.spec.ts +++ b/packages/react/src/generators/stories/stories.nextjs.spec.ts @@ -91,8 +91,7 @@ export async function createTestUIApp(name: string): Promise { skipFormat: true, style: 'css', unitTestRunner: 'none', - name, - projectNameAndRootFormat: 'as-provided', + directory: name, }); return tree; diff --git a/packages/react/src/generators/storybook-configuration/configuration.spec.ts b/packages/react/src/generators/storybook-configuration/configuration.spec.ts index 081517a016bbd..144bd4d8afa41 100644 --- a/packages/react/src/generators/storybook-configuration/configuration.spec.ts +++ b/packages/react/src/generators/storybook-configuration/configuration.spec.ts @@ -139,8 +139,7 @@ export async function createTestUILib( skipTsConfig: false, style: 'css', unitTestRunner: 'none', - name: libName, - projectNameAndRootFormat: 'as-provided', + directory: libName, addPlugin: true, }); return appTree; @@ -158,9 +157,8 @@ export async function createTestAppLib( skipFormat: false, style: 'css', unitTestRunner: 'none', - name: libName, + directory: libName, js: plainJS, - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); diff --git a/packages/react/src/migrations/update-19-6-0/update-ssr-server-port.spec.ts b/packages/react/src/migrations/update-19-6-0/update-ssr-server-port.spec.ts index b6cf62fb8327d..12309384fb2f5 100644 --- a/packages/react/src/migrations/update-19-6-0/update-ssr-server-port.spec.ts +++ b/packages/react/src/migrations/update-19-6-0/update-ssr-server-port.spec.ts @@ -3,6 +3,7 @@ import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports'; import hostGenerator from '../../generators/host/host'; import { Linter } from '@nx/eslint'; import updateSsrServerPort from './update-ssr-server-port'; + describe('update-19-6-0 update-ssr-server-port migration', () => { let tree: Tree; @@ -12,12 +13,11 @@ describe('update-19-6-0 update-ssr-server-port migration', () => { it('should update host and remote port server files', async () => { await hostGenerator(tree, { - name: 'shell', + directory: 'shell', e2eTestRunner: 'none', unitTestRunner: 'none', ssr: true, linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', style: 'css', remotes: ['product'], bundler: 'webpack', @@ -128,12 +128,11 @@ describe('update-19-6-0 update-ssr-server-port migration', () => { it('should update a host project server file', async () => { await hostGenerator(tree, { - name: 'host', + directory: 'host', e2eTestRunner: 'none', unitTestRunner: 'none', ssr: true, linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', style: 'css', bundler: 'webpack', }); @@ -180,12 +179,11 @@ describe('update-19-6-0 update-ssr-server-port migration', () => { it('should not update a mfe project that is not ssr', async () => { await hostGenerator(tree, { - name: 'shell-not-ssr', + directory: 'shell-not-ssr', e2eTestRunner: 'none', unitTestRunner: 'none', ssr: false, linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', style: 'css', bundler: 'webpack', }); diff --git a/packages/react/src/utils/testing-generators.ts b/packages/react/src/utils/testing-generators.ts index e495057985a63..248511c54b12c 100644 --- a/packages/react/src/utils/testing-generators.ts +++ b/packages/react/src/utils/testing-generators.ts @@ -9,8 +9,7 @@ export async function createApp(tree: Tree, appName: string): Promise { skipFormat: true, style: 'css', unitTestRunner: 'none', - name: appName, - projectNameAndRootFormat: 'as-provided', + directory: appName, }); } diff --git a/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap b/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap index a4d9d5c2d891a..80f44ab280dc3 100644 --- a/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap +++ b/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --directory should create the application correctly 1`] = ` +exports[`Remix Application Integrated Repo --directory should create the application correctly 1`] = ` "import { createWatchPaths } from '@nx/remix'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; @@ -21,7 +21,7 @@ export default { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --directory should create the application correctly 2`] = ` +exports[`Remix Application Integrated Repo --directory should create the application correctly 2`] = ` "import type { MetaFunction } from '@remix-run/node'; import { Links, @@ -59,7 +59,7 @@ export default function App() { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --directory should create the application correctly 3`] = ` +exports[`Remix Application Integrated Repo --directory should create the application correctly 3`] = ` "import NxWelcome from '../nx-welcome'; export default function Index() { @@ -72,7 +72,7 @@ export default function Index() { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --directory should extract the layout directory from the directory options if it exists 1`] = ` +exports[`Remix Application Integrated Repo --directory should extract the layout directory from the directory options if it exists 1`] = ` "import { createWatchPaths } from '@nx/remix'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; @@ -93,7 +93,7 @@ export default { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --directory should extract the layout directory from the directory options if it exists 2`] = ` +exports[`Remix Application Integrated Repo --directory should extract the layout directory from the directory options if it exists 2`] = ` "import type { MetaFunction } from '@remix-run/node'; import { Links, @@ -131,7 +131,7 @@ export default function App() { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --directory should extract the layout directory from the directory options if it exists 3`] = ` +exports[`Remix Application Integrated Repo --directory should extract the layout directory from the directory options if it exists 3`] = ` "import NxWelcome from '../nx-welcome'; export default function Index() { @@ -144,7 +144,7 @@ export default function Index() { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --e2eTestRunner should generate a cypress e2e application for the app 1`] = ` +exports[`Remix Application Integrated Repo --e2eTestRunner should generate a cypress e2e application for the app 1`] = ` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; import { defineConfig } from 'cypress'; @@ -166,7 +166,7 @@ export default defineConfig({ " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --e2eTestRunner should generate a playwright e2e application for the app 1`] = ` +exports[`Remix Application Integrated Repo --e2eTestRunner should generate a playwright e2e application for the app 1`] = ` "import { defineConfig, devices } from '@playwright/test'; import { nxE2EPreset } from '@nx/playwright/preset'; @@ -239,7 +239,7 @@ export default defineConfig({ " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --js should create the application correctly 1`] = ` +exports[`Remix Application Integrated Repo --js should create the application correctly 1`] = ` "import { createWatchPaths } from '@nx/remix'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; @@ -260,7 +260,7 @@ export default { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --js should create the application correctly 2`] = ` +exports[`Remix Application Integrated Repo --js should create the application correctly 2`] = ` "import { Links, LiveReload, @@ -295,7 +295,7 @@ export default function App() { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --js should create the application correctly 3`] = ` +exports[`Remix Application Integrated Repo --js should create the application correctly 3`] = ` "import NxWelcome from '../nx-welcome'; export default function Index() { return ( @@ -307,7 +307,7 @@ export default function Index() { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --unitTestRunner should generate the correct files for testing using jest 1`] = ` +exports[`Remix Application Integrated Repo --unitTestRunner should generate the correct files for testing using jest 1`] = ` "import { createWatchPaths } from '@nx/remix'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; @@ -328,7 +328,7 @@ export default { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --unitTestRunner should generate the correct files for testing using jest 2`] = ` +exports[`Remix Application Integrated Repo --unitTestRunner should generate the correct files for testing using jest 2`] = ` "export default { displayName: 'test', preset: '../jest.preset.js', @@ -341,14 +341,14 @@ exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provide " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --unitTestRunner should generate the correct files for testing using jest 3`] = ` +exports[`Remix Application Integrated Repo --unitTestRunner should generate the correct files for testing using jest 3`] = ` "import { installGlobals } from '@remix-run/node'; import '@testing-library/jest-dom/matchers'; installGlobals(); " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --unitTestRunner should generate the correct files for testing using vitest 1`] = ` +exports[`Remix Application Integrated Repo --unitTestRunner should generate the correct files for testing using vitest 1`] = ` "import { createWatchPaths } from '@nx/remix'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; @@ -369,7 +369,7 @@ export default { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --unitTestRunner should generate the correct files for testing using vitest 2`] = ` +exports[`Remix Application Integrated Repo --unitTestRunner should generate the correct files for testing using vitest 2`] = ` "/// import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; @@ -400,14 +400,14 @@ export default defineConfig({ " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --unitTestRunner should generate the correct files for testing using vitest 3`] = ` +exports[`Remix Application Integrated Repo --unitTestRunner should generate the correct files for testing using vitest 3`] = ` "import { installGlobals } from '@remix-run/node'; import '@testing-library/jest-dom/matchers'; installGlobals(); " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --unitTestRunner should generate the correct files for testing using vitest 4`] = ` +exports[`Remix Application Integrated Repo --unitTestRunner should generate the correct files for testing using vitest 4`] = ` "{ "extends": "./tsconfig.json", "compilerOptions": { @@ -440,7 +440,7 @@ exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provide " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided should create the application correctly 1`] = ` +exports[`Remix Application Integrated Repo should create the application correctly 1`] = ` "import { createWatchPaths } from '@nx/remix'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; @@ -461,7 +461,7 @@ export default { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided should create the application correctly 2`] = ` +exports[`Remix Application Integrated Repo should create the application correctly 2`] = ` "import type { MetaFunction } from '@remix-run/node'; import { Links, @@ -499,7 +499,7 @@ export default function App() { " `; -exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided should create the application correctly 3`] = ` +exports[`Remix Application Integrated Repo should create the application correctly 3`] = ` "import NxWelcome from '../nx-welcome'; export default function Index() { diff --git a/packages/remix/src/generators/application/application.impl.spec.ts b/packages/remix/src/generators/application/application.impl.spec.ts index c80c16f7b2cbf..8ba7f29cd7535 100644 --- a/packages/remix/src/generators/application/application.impl.spec.ts +++ b/packages/remix/src/generators/application/application.impl.spec.ts @@ -3,7 +3,6 @@ import 'nx/src/internal-testing-utils/mock-project-graph'; import { joinPathFragments, readJson, readNxJson, type Tree } from '@nx/devkit'; import * as devkitExports from 'nx/src/devkit-exports'; -import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import applicationGenerator from './application.impl'; import { join } from 'path'; @@ -24,7 +23,7 @@ describe('Remix Application', () => { // ACT await applicationGenerator(tree, { name: 'test', - rootProject: true, + directory: '.', addPlugin: true, }); @@ -49,6 +48,7 @@ describe('Remix Application', () => { // ACT await applicationGenerator(tree, { name: 'test', + directory: '.', js: true, rootProject: true, addPlugin: true, @@ -71,6 +71,7 @@ describe('Remix Application', () => { // ACT await applicationGenerator(tree, { name: 'test', + directory: '.', unitTestRunner: 'vitest', rootProject: true, addPlugin: true, @@ -95,6 +96,7 @@ describe('Remix Application', () => { // ACT await applicationGenerator(tree, { name: 'test', + directory: '.', unitTestRunner: 'jest', rootProject: true, addPlugin: true, @@ -121,6 +123,7 @@ describe('Remix Application', () => { // ACT await applicationGenerator(tree, { name: 'test', + directory: '.', e2eTestRunner: 'cypress', rootProject: true, addPlugin: true, @@ -148,6 +151,7 @@ describe('Remix Application', () => { // ACT await applicationGenerator(tree, { name: 'test', + directory: '.', e2eTestRunner: 'playwright', rootProject: true, addPlugin: true, @@ -168,17 +172,36 @@ describe('Remix Application', () => { }); }); - describe.each([['as-provided', 'test', 'test-e2e']])( - 'Integrated Repo --projectNameAndRootFormat=%s', - (projectNameAndRootFormat: ProjectNameAndRootFormat, appDir, e2eDir) => { + describe.each([['test', 'test-e2e']])('Integrated Repo', (appDir, e2eDir) => { + it('should create the application correctly', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + + // ACT + await applicationGenerator(tree, { + directory: 'test', + addPlugin: true, + }); + + // ASSERT + expectTargetsToBeCorrect(tree, appDir); + + expect(tree.read(`${appDir}/remix.config.js`, 'utf-8')).toMatchSnapshot(); + expect(tree.read(`${appDir}/app/root.tsx`, 'utf-8')).toMatchSnapshot(); + expect( + tree.read(`${appDir}/app/routes/_index.tsx`, 'utf-8') + ).toMatchSnapshot(); + }); + + describe('--js', () => { it('should create the application correctly', async () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); // ACT await applicationGenerator(tree, { - name: 'test', - projectNameAndRootFormat, + directory: 'test', + js: true, addPlugin: true, }); @@ -188,199 +211,157 @@ describe('Remix Application', () => { expect( tree.read(`${appDir}/remix.config.js`, 'utf-8') ).toMatchSnapshot(); - expect(tree.read(`${appDir}/app/root.tsx`, 'utf-8')).toMatchSnapshot(); + expect(tree.read(`${appDir}/app/root.js`, 'utf-8')).toMatchSnapshot(); expect( - tree.read(`${appDir}/app/routes/_index.tsx`, 'utf-8') + tree.read(`${appDir}/app/routes/_index.js`, 'utf-8') ).toMatchSnapshot(); }); + }); + describe('--directory', () => { + it('should create the application correctly', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + const newAppDir = 'demo'; - describe('--js', () => { - it('should create the application correctly', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - // ACT - await applicationGenerator(tree, { - name: 'test', - js: true, - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - expectTargetsToBeCorrect(tree, appDir); - - expect( - tree.read(`${appDir}/remix.config.js`, 'utf-8') - ).toMatchSnapshot(); - expect(tree.read(`${appDir}/app/root.js`, 'utf-8')).toMatchSnapshot(); - expect( - tree.read(`${appDir}/app/routes/_index.js`, 'utf-8') - ).toMatchSnapshot(); + // ACT + await applicationGenerator(tree, { + name: 'test', + directory: 'demo', + addPlugin: true, }); + + // ASSERT + expectTargetsToBeCorrect(tree, newAppDir); + + expect( + tree.read(`${newAppDir}/remix.config.js`, 'utf-8') + ).toMatchSnapshot(); + expect( + tree.read(`${newAppDir}/app/root.tsx`, 'utf-8') + ).toMatchSnapshot(); + expect( + tree.read(`${newAppDir}/app/routes/_index.tsx`, 'utf-8') + ).toMatchSnapshot(); }); - describe('--directory', () => { - it('should create the application correctly', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - const newAppDir = - projectNameAndRootFormat === 'as-provided' - ? 'demo' - : 'apps/demo/test'; - - // ACT - await applicationGenerator(tree, { - name: 'test', - directory: 'demo', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - expectTargetsToBeCorrect(tree, newAppDir); - - expect( - tree.read(`${newAppDir}/remix.config.js`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${newAppDir}/app/root.tsx`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${newAppDir}/app/routes/_index.tsx`, 'utf-8') - ).toMatchSnapshot(); - }); - it('should extract the layout directory from the directory options if it exists', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - const newAppDir = - projectNameAndRootFormat === 'as-provided' - ? 'apps/demo' - : 'apps/demo/test'; - - // ACT - await applicationGenerator(tree, { - name: 'test', - directory: 'apps/demo', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - expectTargetsToBeCorrect(tree, newAppDir); - - expect( - tree.read(`${newAppDir}/remix.config.js`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${newAppDir}/app/root.tsx`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${newAppDir}/app/routes/_index.tsx`, 'utf-8') - ).toMatchSnapshot(); + it('should extract the layout directory from the directory options if it exists', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + const newAppDir = 'apps/demo'; + + // ACT + await applicationGenerator(tree, { + name: 'test', + directory: 'apps/demo', + addPlugin: true, }); + + // ASSERT + expectTargetsToBeCorrect(tree, newAppDir); + + expect( + tree.read(`${newAppDir}/remix.config.js`, 'utf-8') + ).toMatchSnapshot(); + expect( + tree.read(`${newAppDir}/app/root.tsx`, 'utf-8') + ).toMatchSnapshot(); + expect( + tree.read(`${newAppDir}/app/routes/_index.tsx`, 'utf-8') + ).toMatchSnapshot(); }); + }); - describe('--unitTestRunner', () => { - it('should generate the correct files for testing using vitest', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - // ACT - await applicationGenerator(tree, { - name: 'test', - unitTestRunner: 'vitest', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - expectTargetsToBeCorrect(tree, appDir); - - expect( - tree.read(`${appDir}/remix.config.js`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${appDir}/vitest.config.ts`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${appDir}/test-setup.ts`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${appDir}/tsconfig.spec.json`, 'utf-8') - ).toMatchSnapshot(); + describe('--unitTestRunner', () => { + it('should generate the correct files for testing using vitest', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + + // ACT + await applicationGenerator(tree, { + directory: 'test', + unitTestRunner: 'vitest', + addPlugin: true, }); - it('should generate the correct files for testing using jest', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - // ACT - await applicationGenerator(tree, { - name: 'test', - unitTestRunner: 'jest', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - expectTargetsToBeCorrect(tree, appDir); - - expect( - tree.read(`${appDir}/remix.config.js`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${appDir}/jest.config.ts`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${appDir}/test-setup.ts`, 'utf-8') - ).toMatchSnapshot(); + // ASSERT + expectTargetsToBeCorrect(tree, appDir); + + expect( + tree.read(`${appDir}/remix.config.js`, 'utf-8') + ).toMatchSnapshot(); + expect( + tree.read(`${appDir}/vitest.config.ts`, 'utf-8') + ).toMatchSnapshot(); + expect(tree.read(`${appDir}/test-setup.ts`, 'utf-8')).toMatchSnapshot(); + expect( + tree.read(`${appDir}/tsconfig.spec.json`, 'utf-8') + ).toMatchSnapshot(); + }); + + it('should generate the correct files for testing using jest', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + + // ACT + await applicationGenerator(tree, { + directory: 'test', + unitTestRunner: 'jest', + addPlugin: true, }); + + // ASSERT + expectTargetsToBeCorrect(tree, appDir); + + expect( + tree.read(`${appDir}/remix.config.js`, 'utf-8') + ).toMatchSnapshot(); + expect( + tree.read(`${appDir}/jest.config.ts`, 'utf-8') + ).toMatchSnapshot(); + expect(tree.read(`${appDir}/test-setup.ts`, 'utf-8')).toMatchSnapshot(); }); + }); + + describe('--e2eTestRunner', () => { + it('should generate a cypress e2e application for the app', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - describe('--e2eTestRunner', () => { - it('should generate a cypress e2e application for the app', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - // ACT - await applicationGenerator(tree, { - name: 'test', - e2eTestRunner: 'cypress', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - expectTargetsToBeCorrect(tree, appDir); - - expect( - tree.read(`${appDir}-e2e/cypress.config.ts`, 'utf-8') - ).toMatchSnapshot(); + // ACT + await applicationGenerator(tree, { + directory: 'test', + e2eTestRunner: 'cypress', + addPlugin: true, }); - it('should generate a playwright e2e application for the app', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + // ASSERT + expectTargetsToBeCorrect(tree, appDir); - // ACT - await applicationGenerator(tree, { - name: 'test', - e2eTestRunner: 'playwright', - projectNameAndRootFormat, - addPlugin: true, - }); + expect( + tree.read(`${appDir}-e2e/cypress.config.ts`, 'utf-8') + ).toMatchSnapshot(); + }); - // ASSERT - expectTargetsToBeCorrect(tree, appDir); + it('should generate a playwright e2e application for the app', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - expect( - tree.read(`${appDir}-e2e/playwright.config.ts`, 'utf-8') - ).toMatchSnapshot(); + // ACT + await applicationGenerator(tree, { + directory: 'test', + e2eTestRunner: 'playwright', + addPlugin: true, }); + + // ASSERT + expectTargetsToBeCorrect(tree, appDir); + + expect( + tree.read(`${appDir}-e2e/playwright.config.ts`, 'utf-8') + ).toMatchSnapshot(); }); - } - ); + }); + }); }); function expectTargetsToBeCorrect(tree: Tree, projectRoot: string) { diff --git a/packages/remix/src/generators/application/lib/normalize-options.ts b/packages/remix/src/generators/application/lib/normalize-options.ts index 4f5f9942aedbb..afc8f4cead7cb 100644 --- a/packages/remix/src/generators/application/lib/normalize-options.ts +++ b/packages/remix/src/generators/application/lib/normalize-options.ts @@ -1,8 +1,10 @@ import { readNxJson, type Tree } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { type NxRemixGeneratorSchema } from '../schema'; import { Linter } from '@nx/eslint'; -import { RemixPluginOptions } from '../../../plugins/plugin'; export interface NormalizedSchema extends NxRemixGeneratorSchema { projectName: string; @@ -16,16 +18,17 @@ export async function normalizeOptions( tree: Tree, options: NxRemixGeneratorSchema ): Promise { - const { projectName, projectRoot, projectNameAndRootFormat } = - await determineProjectNameAndRootOptions(tree, { + await ensureProjectName(tree, options, 'application'); + const { projectName, projectRoot } = await determineProjectNameAndRootOptions( + tree, + { name: options.name, projectType: 'application', directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, rootProject: options.rootProject, - }); + } + ); options.rootProject = projectRoot === '.'; - options.projectNameAndRootFormat = projectNameAndRootFormat; const nxJson = readNxJson(tree); const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && diff --git a/packages/remix/src/generators/application/schema.d.ts b/packages/remix/src/generators/application/schema.d.ts index d893899011047..e3a31477a1fcf 100644 --- a/packages/remix/src/generators/application/schema.d.ts +++ b/packages/remix/src/generators/application/schema.d.ts @@ -1,12 +1,10 @@ -import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface NxRemixGeneratorSchema { - name: string; + directory: string; + name?: string; tags?: string; js?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; linter?: Linter | LinterType; unitTestRunner?: 'vitest' | 'jest' | 'none'; e2eTestRunner?: 'cypress' | 'playwright' | 'none'; diff --git a/packages/remix/src/generators/application/schema.json b/packages/remix/src/generators/application/schema.json index 2c0c86716b7f7..4992be7de5f47 100644 --- a/packages/remix/src/generators/application/schema.json +++ b/packages/remix/src/generators/application/schema.json @@ -5,31 +5,26 @@ "description": "Generate a new Remix application.", "type": "object", "properties": { - "name": { + "directory": { "type": "string", - "description": "", + "description": "A directory where the app is placed.", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What is the name of the application?" + "x-prompt": "Which directory do you want to create the application in?" + }, + "name": { + "type": "string", + "description": "The name of the application.", + "x-priority": "important" }, "js": { "type": "boolean", "description": "Generate JavaScript files rather than TypeScript files.", "default": false }, - "directory": { - "type": "string", - "description": "A directory where the app is placed.", - "alias": "dir", - "x-priority": "important" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -65,5 +60,6 @@ "x-priority": "internal", "default": false } - } + }, + "required": ["directory"] } diff --git a/packages/remix/src/generators/cypress-component-configuration/cypress-component-configuration.impl.spec.ts b/packages/remix/src/generators/cypress-component-configuration/cypress-component-configuration.impl.spec.ts index 0ecf702ea4da3..8ce9f4a51b53e 100644 --- a/packages/remix/src/generators/cypress-component-configuration/cypress-component-configuration.impl.spec.ts +++ b/packages/remix/src/generators/cypress-component-configuration/cypress-component-configuration.impl.spec.ts @@ -13,7 +13,7 @@ describe('CypressComponentConfiguration', () => { const tree = createTreeWithEmptyWorkspace(); await libraryGenerator(tree, { - name: 'cypress-test', + directory: 'cypress-test', unitTestRunner: 'vitest', style: 'css', addPlugin: false, diff --git a/packages/remix/src/generators/library/__snapshots__/library.impl.spec.ts.snap b/packages/remix/src/generators/library/__snapshots__/library.impl.spec.ts.snap index b133758e06287..9d626fb56415e 100644 --- a/packages/remix/src/generators/library/__snapshots__/library.impl.spec.ts.snap +++ b/packages/remix/src/generators/library/__snapshots__/library.impl.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Remix Library Generator -projectNameAndRootFormat=as-provided --unitTestRunner should create the correct config files for testing with jest 1`] = ` +exports[`Remix Library Generator --unitTestRunner should create the correct config files for testing with jest 1`] = ` "export default { setupFilesAfterEnv: ['./src/test-setup.ts'], displayName: 'test', @@ -15,14 +15,14 @@ exports[`Remix Library Generator -projectNameAndRootFormat=as-provided --unitTes " `; -exports[`Remix Library Generator -projectNameAndRootFormat=as-provided --unitTestRunner should create the correct config files for testing with jest 2`] = ` +exports[`Remix Library Generator --unitTestRunner should create the correct config files for testing with jest 2`] = ` "import { installGlobals } from '@remix-run/node'; import '@testing-library/jest-dom/matchers'; installGlobals(); " `; -exports[`Remix Library Generator -projectNameAndRootFormat=as-provided --unitTestRunner should create the correct config files for testing with vitest 1`] = ` +exports[`Remix Library Generator --unitTestRunner should create the correct config files for testing with vitest 1`] = ` "import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; @@ -49,14 +49,14 @@ export default defineConfig({ " `; -exports[`Remix Library Generator -projectNameAndRootFormat=as-provided --unitTestRunner should create the correct config files for testing with vitest 2`] = ` +exports[`Remix Library Generator --unitTestRunner should create the correct config files for testing with vitest 2`] = ` "import { installGlobals } from '@remix-run/node'; import '@testing-library/jest-dom/matchers'; installGlobals(); " `; -exports[`Remix Library Generator -projectNameAndRootFormat=as-provided should generate a library correctly 1`] = ` +exports[`Remix Library Generator should generate a library correctly 1`] = ` [ "test.module.css", "test.spec.tsx", @@ -64,7 +64,7 @@ exports[`Remix Library Generator -projectNameAndRootFormat=as-provided should ge ] `; -exports[`Remix Library Generator -projectNameAndRootFormat=as-provided should generate a library correctly 2`] = ` +exports[`Remix Library Generator should generate a library correctly 2`] = ` { "@proj/test": [ "test/src/index.ts", diff --git a/packages/remix/src/generators/library/lib/normalize-options.ts b/packages/remix/src/generators/library/lib/normalize-options.ts index 9f08c0e77f095..8351fc042f134 100644 --- a/packages/remix/src/generators/library/lib/normalize-options.ts +++ b/packages/remix/src/generators/library/lib/normalize-options.ts @@ -1,5 +1,8 @@ -import { type Tree, readNxJson } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { readNxJson, type Tree } from '@nx/devkit'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { getImportPath } from '@nx/js/src/utils/get-import-path'; import type { NxRemixGeneratorSchema } from '../schema'; @@ -12,13 +15,15 @@ export async function normalizeOptions( tree: Tree, options: NxRemixGeneratorSchema ): Promise { - const { projectName, projectRoot, projectNameAndRootFormat } = - await determineProjectNameAndRootOptions(tree, { + await ensureProjectName(tree, options, 'application'); + const { projectName, projectRoot } = await determineProjectNameAndRootOptions( + tree, + { name: options.name, projectType: 'library', directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - }); + } + ); const nxJson = readNxJson(tree); const addPluginDefault = @@ -34,6 +39,5 @@ export async function normalizeOptions( importPath, projectName, projectRoot, - projectNameAndRootFormat, }; } diff --git a/packages/remix/src/generators/library/library.impl.spec.ts b/packages/remix/src/generators/library/library.impl.spec.ts index fe1f2d7e71b2d..6c983760de0d6 100644 --- a/packages/remix/src/generators/library/library.impl.spec.ts +++ b/packages/remix/src/generators/library/library.impl.spec.ts @@ -1,153 +1,132 @@ import 'nx/src/internal-testing-utils/mock-project-graph'; import { readJson, readProjectConfiguration } from '@nx/devkit'; -import { type ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import applicationGenerator from '../application/application.impl'; import libraryGenerator from './library.impl'; describe('Remix Library Generator', () => { - describe.each([['as-provided', 'test']])( - '-projectNameAndRootFormat=%s', - (projectNameAndRootFormat: ProjectNameAndRootFormat, libDir) => { - it('should generate a library correctly', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - // ACT - await libraryGenerator(tree, { - name: 'test', - style: 'css', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - const tsconfig = readJson(tree, 'tsconfig.base.json'); - expect(tree.exists(`${libDir}/src/server.ts`)); - expect(tree.children(`${libDir}/src/lib`)).toMatchSnapshot(); - expect(tsconfig.compilerOptions.paths).toMatchSnapshot(); - }, 25_000); - - describe('Standalone Project Repo', () => { - it('should update the tsconfig paths correctly', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace(); - await applicationGenerator(tree, { - name: 'demo', - rootProject: true, - addPlugin: true, - }); - const originalBaseTsConfig = readJson(tree, 'tsconfig.json'); - - // ACT - await libraryGenerator(tree, { - name: 'test', - style: 'css', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - const updatedBaseTsConfig = readJson(tree, 'tsconfig.base.json'); - expect( - Object.keys(originalBaseTsConfig.compilerOptions.paths) - ).toContain('~/*'); - expect( - Object.keys(updatedBaseTsConfig.compilerOptions.paths) - ).toContain('~/*'); - }); + it('should generate a library correctly', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + + // ACT + await libraryGenerator(tree, { + directory: 'test', + style: 'css', + addPlugin: true, + }); + + // ASSERT + const tsconfig = readJson(tree, 'tsconfig.base.json'); + expect(tree.exists(`test/src/server.ts`)); + expect(tree.children(`test/src/lib`)).toMatchSnapshot(); + expect(tsconfig.compilerOptions.paths).toMatchSnapshot(); + }, 25_000); + + describe('Standalone Project Repo', () => { + it('should update the tsconfig paths correctly', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace(); + await applicationGenerator(tree, { + name: 'demo', + directory: '.', + rootProject: true, + addPlugin: true, }); + const originalBaseTsConfig = readJson(tree, 'tsconfig.json'); - describe('--unitTestRunner', () => { - it('should not create config files when unitTestRunner=none', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - // ACT - await libraryGenerator(tree, { - name: 'test', - style: 'css', - unitTestRunner: 'none', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - expect(tree.exists(`${libDir}/jest.config.ts`)).toBeFalsy(); - expect(tree.exists(`${libDir}/vite.config.ts`)).toBeFalsy(); - }); - - it('should create the correct config files for testing with jest', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - // ACT - await libraryGenerator(tree, { - name: 'test', - style: 'css', - unitTestRunner: 'jest', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - expect( - tree.read(`${libDir}/jest.config.ts`, 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read(`${libDir}/src/test-setup.ts`, 'utf-8') - ).toMatchSnapshot(); - }); - - it('should create the correct config files for testing with vitest', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - // ACT - await libraryGenerator(tree, { - name: 'test', - style: 'css', - unitTestRunner: 'vitest', - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - expect( - tree.read(`${libDir}/vite.config.ts`, 'utf-8') - ).toMatchSnapshot(); - - expect( - tree.read(`${libDir}/src/test-setup.ts`, 'utf-8') - ).toMatchSnapshot(); - }, 25_000); + // ACT + await libraryGenerator(tree, { + directory: 'test', + style: 'css', + addPlugin: true, }); - // TODO(Colum): Unskip this when buildable is investigated correctly - xit('should generate the config files correctly when the library is buildable', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - // ACT - await libraryGenerator(tree, { - name: 'test', - style: 'css', - buildable: true, - projectNameAndRootFormat, - addPlugin: true, - }); - - // ASSERT - const project = readProjectConfiguration(tree, 'test'); - const pkgJson = readJson(tree, `${libDir}/package.json`); - expect(project.targets.build.options.format).toEqual(['cjs']); - expect(project.targets.build.options.outputPath).toEqual( - `${libDir}/dist` - ); - expect(pkgJson.main).toEqual('./dist/index.cjs.js'); - expect(pkgJson.typings).toEqual('./dist/index.d.ts'); + // ASSERT + const updatedBaseTsConfig = readJson(tree, 'tsconfig.base.json'); + expect(Object.keys(originalBaseTsConfig.compilerOptions.paths)).toContain( + '~/*' + ); + expect(Object.keys(updatedBaseTsConfig.compilerOptions.paths)).toContain( + '~/*' + ); + }); + }); + + describe('--unitTestRunner', () => { + it('should not create config files when unitTestRunner=none', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + + // ACT + await libraryGenerator(tree, { + directory: 'test', + style: 'css', + unitTestRunner: 'none', + addPlugin: true, }); - } - ); + + // ASSERT + expect(tree.exists(`test/jest.config.ts`)).toBeFalsy(); + expect(tree.exists(`test/vite.config.ts`)).toBeFalsy(); + }); + + it('should create the correct config files for testing with jest', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + + // ACT + await libraryGenerator(tree, { + directory: 'test', + style: 'css', + unitTestRunner: 'jest', + addPlugin: true, + }); + + // ASSERT + expect(tree.read(`test/jest.config.ts`, 'utf-8')).toMatchSnapshot(); + expect(tree.read(`test/src/test-setup.ts`, 'utf-8')).toMatchSnapshot(); + }); + + it('should create the correct config files for testing with vitest', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + + // ACT + await libraryGenerator(tree, { + directory: 'test', + style: 'css', + unitTestRunner: 'vitest', + addPlugin: true, + }); + + // ASSERT + expect(tree.read(`test/vite.config.ts`, 'utf-8')).toMatchSnapshot(); + + expect(tree.read(`test/src/test-setup.ts`, 'utf-8')).toMatchSnapshot(); + }, 25_000); + }); + + // TODO(Colum): Unskip this when buildable is investigated correctly + xit('should generate the config files correctly when the library is buildable', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + + // ACT + await libraryGenerator(tree, { + directory: 'test', + style: 'css', + buildable: true, + addPlugin: true, + }); + + // ASSERT + const project = readProjectConfiguration(tree, 'test'); + const pkgJson = readJson(tree, `test/package.json`); + expect(project.targets.build.options.format).toEqual(['cjs']); + expect(project.targets.build.options.outputPath).toEqual(`test/dist`); + expect(pkgJson.main).toEqual('./dist/index.cjs.js'); + expect(pkgJson.typings).toEqual('./dist/index.d.ts'); + }); }); diff --git a/packages/remix/src/generators/library/library.impl.ts b/packages/remix/src/generators/library/library.impl.ts index ac94969c3597b..6473918c77811 100644 --- a/packages/remix/src/generators/library/library.impl.ts +++ b/packages/remix/src/generators/library/library.impl.ts @@ -31,7 +31,6 @@ export async function remixLibraryGeneratorInternal( tags: options.tags, importPath: options.importPath, directory: options.projectRoot, - projectNameAndRootFormat: 'as-provided', skipFormat: true, skipTsConfig: false, linter: Linter.EsLint, diff --git a/packages/remix/src/generators/library/schema.d.ts b/packages/remix/src/generators/library/schema.d.ts index c332d633c8a4d..41283df98c462 100644 --- a/packages/remix/src/generators/library/schema.d.ts +++ b/packages/remix/src/generators/library/schema.d.ts @@ -1,11 +1,9 @@ -import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { SupportedStyles } from '@nx/react'; export interface NxRemixGeneratorSchema { - name: string; + directory: string; + name?: string; style: SupportedStyles; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; importPath?: string; buildable?: boolean; diff --git a/packages/remix/src/generators/library/schema.json b/packages/remix/src/generators/library/schema.json index a0853c6d422ca..e2e9bae514ee0 100644 --- a/packages/remix/src/generators/library/schema.json +++ b/packages/remix/src/generators/library/schema.json @@ -11,27 +11,22 @@ } ], "properties": { - "name": { + "directory": { "type": "string", - "description": "Library name", + "description": "A directory where the lib is placed.", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "^[a-zA-Z].*$" + "x-prompt": "Which directory do you want to create the library in?" }, - "directory": { + "name": { "type": "string", - "description": "A directory where the lib is placed.", - "alias": "dir", + "description": "Library name", + "pattern": "^[a-zA-Z].*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "tags": { "type": "string", "description": "Add tags to the library (used for linting)" @@ -70,5 +65,5 @@ "x-priority": "internal" } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/remix/src/generators/preset/preset.impl.ts b/packages/remix/src/generators/preset/preset.impl.ts index af27b68a39231..c023fe203a4b1 100644 --- a/packages/remix/src/generators/preset/preset.impl.ts +++ b/packages/remix/src/generators/preset/preset.impl.ts @@ -20,6 +20,7 @@ export default async function (tree: Tree, _options: RemixGeneratorSchema) { const appGenTask = await applicationGenerator(tree, { name: options.appName, + directory: '.', tags: options.tags, skipFormat: true, rootProject: true, diff --git a/packages/remix/src/generators/setup-tailwind/setup-tailwind.impl.spec.ts b/packages/remix/src/generators/setup-tailwind/setup-tailwind.impl.spec.ts index 00833faa9b247..1a5fc07d7fe80 100644 --- a/packages/remix/src/generators/setup-tailwind/setup-tailwind.impl.spec.ts +++ b/packages/remix/src/generators/setup-tailwind/setup-tailwind.impl.spec.ts @@ -11,6 +11,7 @@ describe('setup-tailwind generator', () => { const tree = createTreeWithEmptyWorkspace(); await applicationGenerator(tree, { name: 'test', + directory: '.', rootProject: true, }); @@ -34,6 +35,7 @@ describe('setup-tailwind generator', () => { const tree = createTreeWithEmptyWorkspace(); await applicationGenerator(tree, { name: 'test', + directory: '.', js: true, rootProject: true, }); diff --git a/packages/rspack/src/generators/application/application.ts b/packages/rspack/src/generators/application/application.ts index 10e65626395a3..77ae88c8680b6 100644 --- a/packages/rspack/src/generators/application/application.ts +++ b/packages/rspack/src/generators/application/application.ts @@ -18,7 +18,7 @@ export default async function ( }); tasks.push(initTask); - const options = normalizeOptions(tree, _options); + const options = await normalizeOptions(tree, _options); options.style ??= 'css'; diff --git a/packages/rspack/src/generators/application/lib/normalize-options.spec.ts b/packages/rspack/src/generators/application/lib/normalize-options.spec.ts index 3e560296fc41e..cae0549f3db41 100644 --- a/packages/rspack/src/generators/application/lib/normalize-options.spec.ts +++ b/packages/rspack/src/generators/application/lib/normalize-options.spec.ts @@ -9,43 +9,51 @@ describe('normalizeOptions', () => { tree = createTreeWithEmptyWorkspace(); }); - it('should set { rootProject: true } when --rootProject=true is passed', () => { + it('should set { rootProject: true } when --rootProject=true is passed', async () => { expect( - normalizeOptions(tree, { - name: 'demo', - style: 'css', - rootProject: true, - }).rootProject + ( + await normalizeOptions(tree, { + directory: 'demo', + style: 'css', + rootProject: true, + }) + ).rootProject ).toBeTruthy(); }); - it('should set { rootProject: false } when --rootProject=undefined is passed', () => { + it('should set { rootProject: false } when --rootProject=undefined is passed', async () => { expect( - normalizeOptions(tree, { - name: 'demo', - style: 'css', - }).rootProject + ( + await normalizeOptions(tree, { + directory: 'demo', + style: 'css', + }) + ).rootProject ).toBeFalsy(); }); - it('should set { rootProject: false } when --rootProject=false is passed', () => { + it('should set { rootProject: false } when --rootProject=false is passed', async () => { expect( - normalizeOptions(tree, { - name: 'demo', - style: 'css', - rootProject: false, - }).rootProject + ( + await normalizeOptions(tree, { + directory: 'demo', + style: 'css', + rootProject: false, + }) + ).rootProject ).toBeFalsy(); }); - it('should set { rootProject: false } when --monorepo=true and --rootProject=true is passed', () => { + it('should set { rootProject: false } when --monorepo=true and --rootProject=true is passed', async () => { expect( - normalizeOptions(tree, { - name: 'demo', - style: 'css', - monorepo: true, - rootProject: true, - }).rootProject + ( + await normalizeOptions(tree, { + directory: 'demo', + style: 'css', + monorepo: true, + rootProject: true, + }) + ).rootProject ).toBeFalsy(); }); }); diff --git a/packages/rspack/src/generators/application/lib/normalize-options.ts b/packages/rspack/src/generators/application/lib/normalize-options.ts index 72c03ffec87c2..f2ac7f5d02715 100644 --- a/packages/rspack/src/generators/application/lib/normalize-options.ts +++ b/packages/rspack/src/generators/application/lib/normalize-options.ts @@ -1,41 +1,26 @@ -import { - extractLayoutDirectory, - getWorkspaceLayout, - names, - normalizePath, - Tree, -} from '@nx/devkit'; +import { names, Tree } from '@nx/devkit'; import { ApplicationGeneratorSchema, NormalizedSchema } from '../schema'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; -export function normalizeDirectory(options: ApplicationGeneratorSchema) { - const { projectDirectory } = extractLayoutDirectory(options.directory); - return projectDirectory - ? `${names(projectDirectory).fileName}/${names(options.name).fileName}` - : names(options.name).fileName; -} - -export function normalizeProjectName(options: ApplicationGeneratorSchema) { - return normalizeDirectory(options).replace(new RegExp('/', 'g'), '-'); -} - -export function normalizeOptions( +export async function normalizeOptions( host: Tree, options: ApplicationGeneratorSchema -): NormalizedSchema { +): Promise { + await ensureProjectName(host, options, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(host, { + ...options, + projectType: 'application', + }); // --monorepo takes precedence over --rootProject // This won't be needed once we add --bundler=rspack to the @nx/react:app preset const rootProject = !options.monorepo && options.rootProject; - const appDirectory = normalizeDirectory(options); - const appProjectName = normalizeProjectName(options); const e2eProjectName = options.rootProject ? 'e2e' - : `${names(options.name).fileName}-e2e`; - - const { layoutDirectory } = extractLayoutDirectory(options.directory); - const appsDir = layoutDirectory ?? getWorkspaceLayout(host).appsDir; - const appProjectRoot = rootProject - ? '.' - : normalizePath(`${appsDir}/${appDirectory}`); + : `${names(appProjectName).fileName}-e2e`; const normalized = { ...options, diff --git a/packages/rspack/src/generators/application/schema.d.ts b/packages/rspack/src/generators/application/schema.d.ts index c14d74bf346f7..6a9950eebd03c 100644 --- a/packages/rspack/src/generators/application/schema.d.ts +++ b/packages/rspack/src/generators/application/schema.d.ts @@ -1,10 +1,10 @@ export interface ApplicationGeneratorSchema { - name: string; + directory: string; + name?: string; framework?: Framework; style: 'css' | 'scss' | 'less' | 'styl'; unitTestRunner?: 'none' | 'jest'; e2eTestRunner?: 'none' | 'cypress'; - directory?: string; tags?: string; rootProject?: boolean; monorepo?: boolean; diff --git a/packages/rspack/src/generators/application/schema.json b/packages/rspack/src/generators/application/schema.json index aac817b81adef..d93008f298569 100644 --- a/packages/rspack/src/generators/application/schema.json +++ b/packages/rspack/src/generators/application/schema.json @@ -6,21 +6,24 @@ "description": "React + Rspack application generator.", "examples": [ { - "command": "nx g app myapp --directory=myorg", + "command": "nx g app myorg/myapp", "description": "Generate `apps/myorg/myapp` and `apps/myorg/myapp-e2e`" } ], "properties": { - "name": { - "description": "The name of the application.", + "directory": { "type": "string", + "description": "The directory to nest the app under.", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z].*$", - "x-priority": "important" + "x-prompt": "What directory would you like to use for the application?" + }, + "name": { + "description": "The name of the application.", + "type": "string", + "pattern": "^[a-zA-Z].*$" }, "framework": { "type": "string", @@ -75,10 +78,6 @@ "enum": ["none", "cypress"], "default": "cypress" }, - "directory": { - "type": "string", - "description": "The directory to nest the app under." - }, "tags": { "type": "string", "description": "Add tags to the application (used for linting).", @@ -94,5 +93,5 @@ "x-priority": "internal" } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/rspack/src/generators/preset/preset.ts b/packages/rspack/src/generators/preset/preset.ts index 69bec32baa5c0..5c1b88419bc0a 100644 --- a/packages/rspack/src/generators/preset/preset.ts +++ b/packages/rspack/src/generators/preset/preset.ts @@ -6,6 +6,7 @@ import { PresetGeneratorSchema } from './schema'; export default async function (tree: Tree, options: PresetGeneratorSchema) { const appTask = applicationGenerator(tree, { ...options, + directory: '.', // Since `--style` is not passed down to custom preset, we're using individual flags for now. style: options.sass ? 'scss' diff --git a/packages/storybook/src/generators/configuration/configuration.spec.ts b/packages/storybook/src/generators/configuration/configuration.spec.ts index dba7f2182df02..cff1ca36696d4 100644 --- a/packages/storybook/src/generators/configuration/configuration.spec.ts +++ b/packages/storybook/src/generators/configuration/configuration.spec.ts @@ -32,9 +32,8 @@ describe('@nx/storybook:configuration for Storybook v7', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await libraryGenerator(tree, { - name: 'test-ui-lib', + directory: 'test-ui-lib', bundler: 'none', - projectNameAndRootFormat: 'as-provided', skipFormat: true, addPlugin: true, }); @@ -399,9 +398,8 @@ describe('@nx/storybook:configuration for Storybook v7', () => { return json; }); await libraryGenerator(tree, { - name: 'test-ui-lib', + directory: 'test-ui-lib', bundler: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); writeJson(tree, 'package.json', { @@ -479,9 +477,8 @@ describe('@nx/storybook:configuration for Storybook v7', () => { it("should update the project's .eslintrc.json if config exists", async () => { await libraryGenerator(tree, { - name: 'test-ui-lib2', + directory: 'test-ui-lib2', linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); @@ -511,9 +508,8 @@ describe('@nx/storybook:configuration for Storybook v7', () => { it('should have the proper typings', async () => { await libraryGenerator(tree, { - name: 'test-ui-lib2', + directory: 'test-ui-lib2', linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); @@ -589,9 +585,8 @@ describe('@nx/storybook:configuration for Storybook v7', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await libraryGenerator(tree, { - name: 'test-ui-lib', + directory: 'test-ui-lib', bundler: 'none', - projectNameAndRootFormat: 'as-provided', skipFormat: true, addPlugin: true, }); diff --git a/packages/storybook/src/generators/cypress-project/cypress-project.spec.ts b/packages/storybook/src/generators/cypress-project/cypress-project.spec.ts index 296e5af7a6cb4..936b881b1f0d2 100644 --- a/packages/storybook/src/generators/cypress-project/cypress-project.spec.ts +++ b/packages/storybook/src/generators/cypress-project/cypress-project.spec.ts @@ -23,7 +23,6 @@ describe('@nx/storybook:cypress-project', () => { await libraryGenerator(tree, { name: 'test-ui-lib', directory: 'apps/test-ui-lib', - projectNameAndRootFormat: 'as-provided', }); }); afterEach(() => jest.clearAllMocks()); @@ -32,7 +31,6 @@ describe('@nx/storybook:cypress-project', () => { await cypressProjectGenerator(tree, { name: 'test-ui-lib', directory: 'apps/test-ui-lib-e2e', - projectNameAndRootFormat: 'as-provided', linter: Linter.EsLint, }); @@ -48,7 +46,6 @@ describe('@nx/storybook:cypress-project', () => { await cypressProjectGenerator(tree, { name: 'test-ui-lib', directory: 'apps/test-ui-lib-e2e', - projectNameAndRootFormat: 'as-provided', linter: Linter.EsLint, }); const project = readProjectConfiguration(tree, 'test-ui-lib-e2e'); diff --git a/packages/storybook/src/generators/cypress-project/cypress-project.ts b/packages/storybook/src/generators/cypress-project/cypress-project.ts index 98c2fc61e11e6..ee2af4b0cdaa5 100644 --- a/packages/storybook/src/generators/cypress-project/cypress-project.ts +++ b/packages/storybook/src/generators/cypress-project/cypress-project.ts @@ -14,10 +14,7 @@ import { updateProjectConfiguration, } from '@nx/devkit'; import { Linter, LinterType } from '@nx/eslint'; -import { - determineProjectNameAndRootOptions, - type ProjectNameAndRootFormat, -} from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { join } from 'path'; import { safeFileDelete } from '../../utils/utilities'; @@ -31,7 +28,6 @@ export interface CypressConfigureSchema { standaloneConfig?: boolean; ciTargetName?: string; skipFormat?: boolean; - projectNameAndRootFormat?: ProjectNameAndRootFormat; } export async function cypressProjectGenerator( @@ -52,7 +48,6 @@ export async function cypressProjectGenerator( name: e2eName, projectType: 'application', directory: schema.directory, - projectNameAndRootFormat: schema.projectNameAndRootFormat, } ); const libConfig = readProjectConfiguration(tree, schema.name); @@ -74,12 +69,7 @@ export async function cypressProjectGenerator( skipFormat: true, }); - const generatedCypressProjectName = getE2eProjectName( - schema.name, - libRoot, - schema.directory, - schema.projectNameAndRootFormat - ); + const generatedCypressProjectName = projectName; removeUnneededFiles(tree, generatedCypressProjectName, schema.js); const project = readProjectConfiguration(tree, generatedCypressProjectName); @@ -219,14 +209,4 @@ function updateAngularJsonBuilder( updateProjectConfiguration(tree, opts.e2eProjectName, project); } -function projectAlreadyHasCypress(tree: Tree): boolean { - const packageJsonContents = readJson(tree, 'package.json'); - return ( - (packageJsonContents?.['devDependencies']?.['@nx/cypress'] || - packageJsonContents?.['dependencies']?.['@nx/cypress']) && - (packageJsonContents?.['devDependencies']?.['cypress'] || - packageJsonContents?.['dependencies']?.['cypress']) - ); -} - export default cypressProjectGenerator; diff --git a/packages/storybook/src/generators/cypress-project/schema.json b/packages/storybook/src/generators/cypress-project/schema.json index 36c49ecc3555d..4499b15119ac2 100644 --- a/packages/storybook/src/generators/cypress-project/schema.json +++ b/packages/storybook/src/generators/cypress-project/schema.json @@ -44,11 +44,6 @@ "type": "boolean", "default": false, "x-priority": "internal" - }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] } }, "required": ["name"] diff --git a/packages/storybook/src/utils/testing.ts b/packages/storybook/src/utils/testing.ts index c09e372f98864..919c6b7a178f6 100644 --- a/packages/storybook/src/utils/testing.ts +++ b/packages/storybook/src/utils/testing.ts @@ -12,7 +12,7 @@ export async function createTestUILibNoNgDevkit( skipFormat: true, skipTsConfig: false, unitTestRunner: 'none', - name: libName, + directory: libName, }); return appTree; diff --git a/packages/vite/src/generators/configuration/configuration.spec.ts b/packages/vite/src/generators/configuration/configuration.spec.ts index e00fa9f28cedf..7b3da15c89312 100644 --- a/packages/vite/src/generators/configuration/configuration.spec.ts +++ b/packages/vite/src/generators/configuration/configuration.spec.ts @@ -252,7 +252,7 @@ describe('@nx/vite:configuration', () => { }); describe('js library with --bundler=vite', () => { - const defaultOptions: Omit = { + const defaultOptions: Omit = { skipTsConfig: false, includeBabelRc: false, unitTestRunner: 'jest', @@ -271,10 +271,9 @@ describe('@nx/vite:configuration', () => { it('should add build and test targets with vite and vitest', async () => { await jsLibraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'vite', unitTestRunner: 'vitest', - projectNameAndRootFormat: 'as-provided', }); expect(tree.exists('my-lib/vite.config.ts')).toBeTruthy(); @@ -307,10 +306,9 @@ describe('@nx/vite:configuration', () => { async ({ unitTestRunner, configPath }) => { await jsLibraryGenerator(tree, { ...defaultOptions, - name: 'my-lib', + directory: 'my-lib', bundler: 'vite', unitTestRunner, - projectNameAndRootFormat: 'as-provided', }); expect(tree.read('my-lib/README.md', 'utf-8')).toMatchSnapshot(); diff --git a/packages/vue/src/generators/application/application.spec.ts b/packages/vue/src/generators/application/application.spec.ts index f839e3cf86e71..244728a729667 100644 --- a/packages/vue/src/generators/application/application.spec.ts +++ b/packages/vue/src/generators/application/application.spec.ts @@ -16,7 +16,7 @@ import { PackageManagerCommands } from 'nx/src/utils/package-manager'; describe('application generator', () => { let tree: Tree; - const options: Schema = { name: 'test' } as Schema; + const options: Schema = { directory: 'test' } as Schema; beforeEach(() => { tree = createTreeWithEmptyWorkspace(); diff --git a/packages/vue/src/generators/application/lib/normalize-options.ts b/packages/vue/src/generators/application/lib/normalize-options.ts index 12d4884cbcdce..bfefcd687d59f 100644 --- a/packages/vue/src/generators/application/lib/normalize-options.ts +++ b/packages/vue/src/generators/application/lib/normalize-options.ts @@ -1,24 +1,23 @@ import { Tree } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { NormalizedSchema, Schema } from '../schema'; export async function normalizeOptions( host: Tree, options: Schema ): Promise { - const { - projectName: appProjectName, - projectRoot: appProjectRoot, - projectNameAndRootFormat, - } = await determineProjectNameAndRootOptions(host, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - rootProject: options.rootProject, - }); + await ensureProjectName(host, options, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(host, { + name: options.name, + projectType: 'application', + directory: options.directory, + rootProject: options.rootProject, + }); options.rootProject = appProjectRoot === '.'; - options.projectNameAndRootFormat = projectNameAndRootFormat; const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`; const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`; diff --git a/packages/vue/src/generators/application/schema.d.ts b/packages/vue/src/generators/application/schema.d.ts index 35abd5f6e365d..46d4eb6e28715 100644 --- a/packages/vue/src/generators/application/schema.d.ts +++ b/packages/vue/src/generators/application/schema.d.ts @@ -1,12 +1,10 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { - name: string; + directory: string; + name?: string; style: 'none' | 'css' | 'scss' | 'less'; skipFormat?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; unitTestRunner?: 'vitest' | 'none'; inSourceTests?: boolean; diff --git a/packages/vue/src/generators/application/schema.json b/packages/vue/src/generators/application/schema.json index d1cba1bbee40a..a063888fd1011 100644 --- a/packages/vue/src/generators/application/schema.json +++ b/packages/vue/src/generators/application/schema.json @@ -16,27 +16,22 @@ ], "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" + "x-prompt": "Which directory do you want to create the application in?" }, - "directory": { - "description": "The directory of the new application.", + "name": { + "description": "The name of the application.", "type": "string", - "alias": "dir", + "pattern": "^[a-zA-Z][^:]*$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "style": { "description": "The file extension to be used for style files.", "type": "string", @@ -135,6 +130,6 @@ "hidden": true } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "../../../docs/application-examples.md" } diff --git a/packages/vue/src/generators/library/lib/normalize-options.ts b/packages/vue/src/generators/library/lib/normalize-options.ts index b6f4401668aee..2a91e17a1c734 100644 --- a/packages/vue/src/generators/library/lib/normalize-options.ts +++ b/packages/vue/src/generators/library/lib/normalize-options.ts @@ -5,13 +5,17 @@ import { readNxJson, Tree, } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { NormalizedSchema, Schema } from '../schema'; export async function normalizeOptions( host: Tree, options: Schema ): Promise { + await ensureProjectName(host, options, 'library'); const { projectName, names: projectNames, @@ -22,7 +26,6 @@ export async function normalizeOptions( projectType: 'library', directory: options.directory, importPath: options.importPath, - projectNameAndRootFormat: options.projectNameAndRootFormat, }); const fileName = projectNames.projectFileName; diff --git a/packages/vue/src/generators/library/library.spec.ts b/packages/vue/src/generators/library/library.spec.ts index a4f235b6b97ff..94092f41301e2 100644 --- a/packages/vue/src/generators/library/library.spec.ts +++ b/packages/vue/src/generators/library/library.spec.ts @@ -16,7 +16,7 @@ describe('library', () => { let tree: Tree; let defaultSchema: Schema = { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, skipFormat: false, skipTsConfig: false, @@ -390,7 +390,7 @@ module.exports = [ it('should fail if the same importPath has already been used', async () => { await libraryGenerator(tree, { ...defaultSchema, - name: 'my-lib1', + directory: 'my-lib1', publishable: true, importPath: '@myorg/lib', }); @@ -398,7 +398,7 @@ module.exports = [ try { await libraryGenerator(tree, { ...defaultSchema, - name: 'myLib2', + directory: 'myLib2', publishable: true, importPath: '@myorg/lib', }); diff --git a/packages/vue/src/generators/library/schema.d.ts b/packages/vue/src/generators/library/schema.d.ts index 59104ca38312c..198e8cd5840ba 100644 --- a/packages/vue/src/generators/library/schema.d.ts +++ b/packages/vue/src/generators/library/schema.d.ts @@ -1,18 +1,15 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; -import type { SupportedStyles } from '../../../typings/style'; export interface Schema { appProject?: string; bundler?: 'none' | 'vite'; component?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; importPath?: string; inSourceTests?: boolean; js?: boolean; linter: Linter | LinterType; - name: string; + name?: string; publishable?: boolean; routing?: boolean; setParserOptionsProject?: boolean; diff --git a/packages/vue/src/generators/library/schema.json b/packages/vue/src/generators/library/schema.json index d27398bd14c55..7ca310f6b938d 100644 --- a/packages/vue/src/generators/library/schema.json +++ b/packages/vue/src/generators/library/schema.json @@ -16,28 +16,22 @@ } ], "properties": { - "name": { + "directory": { "type": "string", - "description": "Library name", + "description": "A directory where the lib is placed.", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the library?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", - "x-priority": "important" + "x-prompt": "Which directory do you want to create the library in?" }, - "directory": { + "name": { "type": "string", - "description": "A directory where the lib is placed.", - "alias": "dir", + "description": "Library name", + "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$", "x-priority": "important" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -129,5 +123,5 @@ "default": false } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/vue/src/generators/stories/lib/component-story.spec.ts b/packages/vue/src/generators/stories/lib/component-story.spec.ts index e0a47ec44562f..4bf0b4555a417 100644 --- a/packages/vue/src/generators/stories/lib/component-story.spec.ts +++ b/packages/vue/src/generators/stories/lib/component-story.spec.ts @@ -111,13 +111,12 @@ describe('vue:component-story', () => { export async function createTestUILib(libName: string): Promise { let appTree = createTreeWithEmptyWorkspace(); await libraryGenerator(appTree, { - name: libName, + directory: libName, linter: Linter.EsLint, component: true, skipFormat: true, skipTsConfig: false, unitTestRunner: 'vitest', - projectNameAndRootFormat: 'as-provided', }); const currentWorkspaceJson = getProjects(appTree); diff --git a/packages/vue/src/generators/stories/stories.app.spec.ts b/packages/vue/src/generators/stories/stories.app.spec.ts index cead472d3001c..c1f60e8f9f690 100644 --- a/packages/vue/src/generators/stories/stories.app.spec.ts +++ b/packages/vue/src/generators/stories/stories.app.spec.ts @@ -249,9 +249,8 @@ export async function createTestUIApp( skipFormat: true, style: 'css', unitTestRunner: 'none', - name: libName, + directory: libName, js: plainJS, - projectNameAndRootFormat: 'as-provided', }); return appTree; } diff --git a/packages/vue/src/generators/stories/stories.lib.spec.ts b/packages/vue/src/generators/stories/stories.lib.spec.ts index 99960d0ca3d53..585f7cf28ffd7 100644 --- a/packages/vue/src/generators/stories/stories.lib.spec.ts +++ b/packages/vue/src/generators/stories/stories.lib.spec.ts @@ -182,8 +182,7 @@ export async function createTestUILib( skipFormat: true, skipTsConfig: false, unitTestRunner: 'none', - name: libName, - projectNameAndRootFormat: 'as-provided', + directory: libName, }); return appTree; diff --git a/packages/vue/src/generators/storybook-configuration/configuration.spec.ts b/packages/vue/src/generators/storybook-configuration/configuration.spec.ts index 570a2cf924183..7866fccd315f0 100644 --- a/packages/vue/src/generators/storybook-configuration/configuration.spec.ts +++ b/packages/vue/src/generators/storybook-configuration/configuration.spec.ts @@ -146,8 +146,7 @@ export async function createTestUILib(libName: string): Promise { skipFormat: true, skipTsConfig: false, unitTestRunner: 'none', - name: libName, - projectNameAndRootFormat: 'as-provided', + directory: libName, }); return appTree; } @@ -164,9 +163,8 @@ export async function createTestAppLib( skipFormat: false, style: 'css', unitTestRunner: 'none', - name: libName, + directory: libName, js: plainJS, - projectNameAndRootFormat: 'as-provided', }); await componentGenerator(appTree, { diff --git a/packages/vue/src/utils/test-utils.ts b/packages/vue/src/utils/test-utils.ts index 3331c053f2065..9c109e85af942 100644 --- a/packages/vue/src/utils/test-utils.ts +++ b/packages/vue/src/utils/test-utils.ts @@ -9,8 +9,7 @@ export async function createApp(tree: Tree, appName: string): Promise { skipFormat: true, style: 'css', unitTestRunner: 'none', - name: appName, - projectNameAndRootFormat: 'as-provided', + directory: appName, }); } diff --git a/packages/web/src/generators/application/application.legacy.spec.ts b/packages/web/src/generators/application/application.legacy.spec.ts index 55616211d8b51..e4ebafa642261 100644 --- a/packages/web/src/generators/application/application.legacy.spec.ts +++ b/packages/web/src/generators/application/application.legacy.spec.ts @@ -38,8 +38,7 @@ describe('web app generator (legacy)', () => { it('should setup webpack configuration', async () => { await applicationGenerator(tree, { - name: 'my-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-app', }); const project = readProjectConfiguration(tree, 'my-app'); expect(project).toMatchInlineSnapshot(` @@ -145,7 +144,7 @@ describe('web app generator (legacy)', () => { it('should add targets for vite', async () => { await applicationGenerator(tree, { - name: 'my-vite-app', + directory: 'my-vite-app', bundler: 'vite', }); const projects = getProjects(tree); diff --git a/packages/web/src/generators/application/application.spec.ts b/packages/web/src/generators/application/application.spec.ts index 6e2ad9bc330ea..e30f5ae87411b 100644 --- a/packages/web/src/generators/application/application.spec.ts +++ b/packages/web/src/generators/application/application.spec.ts @@ -41,8 +41,7 @@ describe('app', () => { describe('not nested', () => { it('should update configuration', async () => { await applicationGenerator(tree, { - name: 'my-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-app', addPlugin: true, }); expect(readProjectConfiguration(tree, 'my-app').root).toEqual('my-app'); @@ -61,9 +60,8 @@ describe('app', () => { it('should update tags and implicit dependencies', async () => { await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', tags: 'one,two', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); const projects = Object.fromEntries(getProjects(tree)); @@ -80,8 +78,7 @@ describe('app', () => { it('should generate files', async () => { await applicationGenerator(tree, { - name: 'my-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-app', addPlugin: true, }); expect(tree.exists('my-app/src/main.ts')).toBeTruthy(); @@ -168,10 +165,9 @@ describe('app', () => { it('should setup playwright e2e project', async () => { await applicationGenerator(tree, { - name: 'cool-app', + directory: 'cool-app', e2eTestRunner: 'playwright', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(tree.exists('cool-app-e2e/playwright.config.ts')).toBeTruthy(); @@ -179,10 +175,9 @@ describe('app', () => { it('should setup cypress e2e project correctly for vite', async () => { await applicationGenerator(tree, { - name: 'cool-app', + directory: 'cool-app', e2eTestRunner: 'cypress', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', bundler: 'vite', addPlugin: true, }); @@ -213,10 +208,9 @@ describe('app', () => { it('should setup cypress e2e project correctly for webpack', async () => { await applicationGenerator(tree, { - name: 'cool-app', + directory: 'cool-app', e2eTestRunner: 'cypress', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', bundler: 'webpack', addPlugin: true, }); @@ -246,10 +240,9 @@ describe('app', () => { it('should setup playwright e2e project correctly for webpack', async () => { await applicationGenerator(tree, { - name: 'cool-app', + directory: 'cool-app', e2eTestRunner: 'playwright', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', bundler: 'webpack', addPlugin: true, }); @@ -270,9 +263,8 @@ describe('app', () => { }); updateNxJson(tree, nxJson); await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'playwright', addPlugin: true, }); @@ -304,9 +296,8 @@ describe('app', () => { it('should use serve target and port if bundler=vite, e2eTestRunner=playwright, addPlugin=false', async () => { await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', e2eTestRunner: 'playwright', }); expect( @@ -318,8 +309,7 @@ describe('app', () => { tree.rename('tsconfig.base.json', 'tsconfig.json'); await applicationGenerator(tree, { - name: 'my-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-app', addPlugin: true, }); @@ -331,9 +321,7 @@ describe('app', () => { describe('nested', () => { it('should update configuration', async () => { await applicationGenerator(tree, { - name: 'my-app', directory: 'my-dir/my-app', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(readProjectConfiguration(tree, 'my-app').root).toEqual( @@ -346,10 +334,8 @@ describe('app', () => { it('should update tags and implicit dependencies', async () => { await applicationGenerator(tree, { - name: 'my-app', directory: 'my-dir/my-app', tags: 'one,two', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); const projects = Object.fromEntries(getProjects(tree)); @@ -371,9 +357,7 @@ describe('app', () => { expect(lookupFn(config)).toEqual(expectedValue); }; await applicationGenerator(tree, { - name: 'my-app', directory: 'my-dir/my-app', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); @@ -409,9 +393,7 @@ describe('app', () => { it('should extend from root tsconfig.base.json', async () => { await applicationGenerator(tree, { - name: 'my-app', directory: 'my-dir/my-app', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); @@ -423,9 +405,7 @@ describe('app', () => { tree.rename('tsconfig.base.json', 'tsconfig.json'); await applicationGenerator(tree, { - name: 'my-app', directory: 'my-dir/my-app', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); @@ -435,9 +415,7 @@ describe('app', () => { it('should create Nx specific template', async () => { await applicationGenerator(tree, { - name: 'my-app', directory: 'my-dir/my-app', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect( @@ -452,9 +430,8 @@ describe('app', () => { describe('--style scss', () => { it('should generate scss styles', async () => { await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', style: 'scss', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(tree.exists('my-app/src/app/app.element.scss')).toEqual(true); @@ -463,8 +440,7 @@ describe('app', () => { it('should setup jest without serializers', async () => { await applicationGenerator(tree, { - name: 'my-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-app', addPlugin: true, }); @@ -475,8 +451,7 @@ describe('app', () => { it('should setup the web build builder', async () => { await applicationGenerator(tree, { - name: 'my-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-app', addPlugin: true, }); expect(tree.read('my-app/webpack.config.js', 'utf-8')).toMatchSnapshot(); @@ -484,8 +459,7 @@ describe('app', () => { it('should setup the web dev server', async () => { await applicationGenerator(tree, { - name: 'my-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-app', addPlugin: true, }); @@ -494,8 +468,7 @@ describe('app', () => { it('should setup eslint', async () => { await applicationGenerator(tree, { - name: 'my-app', - projectNameAndRootFormat: 'as-provided', + directory: 'my-app', addPlugin: true, }); expect(tree.read('my-app/.eslintrc.json', 'utf-8')).toMatchSnapshot(); @@ -504,9 +477,8 @@ describe('app', () => { describe('--prefix', () => { it('should use the prefix in the index.html', async () => { await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', prefix: 'prefix', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); @@ -519,9 +491,8 @@ describe('app', () => { describe('--unit-test-runner', () => { it('--unit-test-runner=none', async () => { await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(tree.exists('jest.config.ts')).toBeFalsy(); @@ -532,9 +503,8 @@ describe('app', () => { it('--bundler=none should use jest as the default', async () => { await applicationGenerator(tree, { - name: 'my-cool-app', + directory: 'my-cool-app', bundler: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(tree.exists('my-cool-app/jest.config.ts')).toBeTruthy(); @@ -553,11 +523,10 @@ describe('app', () => { // then use vitest it('--bundler=vite --unitTestRunner=jest respects unitTestRunner given', async () => { await applicationGenerator(tree, { - name: 'my-vite-app', + directory: 'my-vite-app', bundler: 'vite', unitTestRunner: 'jest', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(tree.exists('my-vite-app/vite.config.ts')).toBeTruthy(); @@ -566,10 +535,9 @@ describe('app', () => { it('--bundler=vite --unitTestRunner=none', async () => { await applicationGenerator(tree, { - name: 'my-vite-app', + directory: 'my-vite-app', bundler: 'vite', unitTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(tree.exists('my-vite-app/vite.config.ts')).toBeTruthy(); @@ -581,10 +549,9 @@ describe('app', () => { it('--bundler=webpack --unitTestRunner=vitest', async () => { await applicationGenerator(tree, { - name: 'my-webpack-app', + directory: 'my-webpack-app', bundler: 'webpack', unitTestRunner: 'vitest', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(tree.exists('my-webpack-app/vite.config.ts')).toBeTruthy(); @@ -607,9 +574,8 @@ describe('app', () => { describe('--e2e-test-runner none', () => { it('should not generate test configuration', async () => { await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', e2eTestRunner: 'none', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); expect(tree.exists('my-app-e2e')).toBeFalsy(); @@ -619,9 +585,8 @@ describe('app', () => { describe('--compiler', () => { it('should support babel compiler', async () => { await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', compiler: 'babel', - projectNameAndRootFormat: 'as-provided', addPlugin: true, } as Schema); @@ -646,9 +611,8 @@ describe('app', () => { it('should support swc compiler', async () => { await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', compiler: 'swc', - projectNameAndRootFormat: 'as-provided', addPlugin: true, } as Schema); @@ -673,9 +637,8 @@ describe('app', () => { it('should be strict by default', async () => { await applicationGenerator(tree, { - name: 'my-app', + directory: 'my-app', compiler: 'swc', - projectNameAndRootFormat: 'as-provided', addPlugin: true, } as Schema); @@ -689,9 +652,8 @@ describe('app', () => { beforeAll(async () => { viteAppTree = createTreeWithEmptyWorkspace(); await applicationGenerator(viteAppTree, { - name: 'my-app', + directory: 'my-app', bundler: 'vite', - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); }); @@ -723,10 +685,9 @@ describe('app', () => { ); await applicationGenerator(viteAppTree, { - name: 'insourceTests', + directory: 'insourceTests', bundler: 'vite', inSourceTests: true, - projectNameAndRootFormat: 'as-provided', addPlugin: true, }); diff --git a/packages/web/src/generators/application/application.ts b/packages/web/src/generators/application/application.ts index b8d02b1e08753..46fd9785f9740 100644 --- a/packages/web/src/generators/application/application.ts +++ b/packages/web/src/generators/application/application.ts @@ -20,7 +20,10 @@ import { updateProjectConfiguration, writeJson, } from '@nx/devkit'; -import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { + determineProjectNameAndRootOptions, + ensureProjectName, +} from '@nx/devkit/src/generators/project-name-and-root-utils'; import { getRelativePathToRootTsConfig, initGenerator as jsInitGenerator, @@ -43,8 +46,6 @@ import { addE2eCiTargetDefaults, } from '@nx/devkit/src/generators/target-defaults-utils'; import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command'; -import { VitePluginOptions } from '@nx/vite/src/plugins/plugin'; -import { WebpackPluginOptions } from '@nx/webpack/src/plugins/plugin'; import staticServeConfiguration from '../static-serve/static-serve-configuration'; import { findPluginForConfigFile } from '@nx/devkit/src/utils/find-plugin-for-config-file'; import { E2EWebServerDetails } from '@nx/devkit/src/generators/e2e-web-server-info-utils'; @@ -603,17 +604,13 @@ async function normalizeOptions( host: Tree, options: Schema ): Promise { - const { - projectName: appProjectName, - projectRoot: appProjectRoot, - projectNameAndRootFormat, - } = await determineProjectNameAndRootOptions(host, { - name: options.name, - projectType: 'application', - directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, - }); - options.projectNameAndRootFormat = projectNameAndRootFormat; + await ensureProjectName(host, options, 'application'); + const { projectName: appProjectName, projectRoot: appProjectRoot } = + await determineProjectNameAndRootOptions(host, { + name: options.name, + projectType: 'application', + directory: options.directory, + }); const nxJson = readNxJson(host); const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && diff --git a/packages/web/src/generators/application/schema.d.ts b/packages/web/src/generators/application/schema.d.ts index 4943850f605ff..1a21df09e764f 100644 --- a/packages/web/src/generators/application/schema.d.ts +++ b/packages/web/src/generators/application/schema.d.ts @@ -1,15 +1,13 @@ -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; import type { Linter, LinterType } from '@nx/eslint'; export interface Schema { - name: string; + directory: string; + name?: string; prefix?: string; style?: string; bundler?: 'webpack' | 'none' | 'vite'; compiler?: 'babel' | 'swc'; skipFormat?: boolean; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; tags?: string; unitTestRunner?: 'jest' | 'vitest' | 'none'; inSourceTests?: boolean; diff --git a/packages/web/src/generators/application/schema.json b/packages/web/src/generators/application/schema.json index 1da0fa56f6531..288feee9a88ef 100644 --- a/packages/web/src/generators/application/schema.json +++ b/packages/web/src/generators/application/schema.json @@ -6,24 +6,20 @@ "description": "Create a web application using `swc` or `babel` as compiler.", "type": "object", "properties": { - "name": { - "description": "The name of the application.", + "directory": { + "description": "The directory of the new application.", "type": "string", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name would you like to use for the application?", - "pattern": "^[a-zA-Z][^:]*$" - }, - "directory": { - "description": "The directory of the new application.", - "type": "string" + "x-prompt": "Which directory do you want to create the application in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { + "description": "The name of the application.", "type": "string", - "enum": ["as-provided", "derived"] + "pattern": "^[a-zA-Z][^:]*$", + "x-priority": "important" }, "style": { "description": "The file extension to be used for style files.", @@ -114,6 +110,6 @@ "x-deprecated": "Nx only supports standaloneConfig" } }, - "required": ["name"], + "required": ["directory"], "examplesFile": "../../../docs/application-examples.md" } diff --git a/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.spec.ts b/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.spec.ts index 0c9be5cd6a8dd..9f114ad19cee2 100644 --- a/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.spec.ts +++ b/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.spec.ts @@ -23,8 +23,12 @@ describe('monorepo generator', () => { tree.write('README.md', ''); tree.write('tools/scripts/custom_script.sh', ''); - await libraryGenerator(tree, { name: 'my-lib', rootProject: true }); - await libraryGenerator(tree, { name: 'other-lib' }); + await libraryGenerator(tree, { + name: 'my-lib', + directory: '.', + rootProject: true, + }); + await libraryGenerator(tree, { directory: 'other-lib' }); await monorepoGenerator(tree, { appsDir: 'apps', @@ -60,6 +64,7 @@ describe('monorepo generator', () => { it('should convert root React app (Vite, Vitest)', async () => { await reactAppGenerator(tree, { name: 'demo', + directory: '.', style: 'css', bundler: 'vite', unitTestRunner: 'vitest', @@ -81,6 +86,7 @@ describe('monorepo generator', () => { it('should respect nested libraries', async () => { await reactAppGenerator(tree, { name: 'demo', + directory: '.', style: 'css', bundler: 'vite', unitTestRunner: 'vitest', @@ -109,6 +115,7 @@ describe('monorepo generator', () => { it('should convert root Next.js app with existing libraries', async () => { await nextAppGenerator(tree, { name: 'demo', + directory: '.', style: 'css', unitTestRunner: 'jest', e2eTestRunner: 'none', @@ -117,7 +124,7 @@ describe('monorepo generator', () => { linter: 'eslint', rootProject: true, }); - await libraryGenerator(tree, { name: 'util' }); + await libraryGenerator(tree, { directory: 'util' }); await monorepoGenerator(tree, {}); diff --git a/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.ts b/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.ts index a2f4a14064658..cb2b579db6d02 100644 --- a/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.ts +++ b/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.ts @@ -64,7 +64,6 @@ export async function monorepoGenerator(tree: Tree, options: {}) { project.root === '.' ? project.name : project.root ), updateImportPath: project.projectType === 'library', - projectNameAndRootFormat: 'as-provided', }); } } diff --git a/packages/workspace/src/generators/move/lib/check-destination.spec.ts b/packages/workspace/src/generators/move/lib/check-destination.spec.ts index 2eb9e7991f422..5ad1be47d0fec 100644 --- a/packages/workspace/src/generators/move/lib/check-destination.spec.ts +++ b/packages/workspace/src/generators/move/lib/check-destination.spec.ts @@ -19,8 +19,7 @@ describe('checkDestination', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); projectConfig = readProjectConfiguration(tree, 'my-lib'); }); @@ -43,8 +42,7 @@ describe('checkDestination', () => { it('should throw an error if the path already exists', async () => { await libraryGenerator(tree, { - name: 'my-other-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-other-lib', }); const schema: NormalizedSchema = { diff --git a/packages/workspace/src/generators/move/lib/move-project-files.spec.ts b/packages/workspace/src/generators/move/lib/move-project-files.spec.ts index b07564401cbda..29d48bc1d1880 100644 --- a/packages/workspace/src/generators/move/lib/move-project-files.spec.ts +++ b/packages/workspace/src/generators/move/lib/move-project-files.spec.ts @@ -19,8 +19,7 @@ describe('moveProject', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); projectConfig = readProjectConfiguration(tree, 'my-lib'); }); diff --git a/packages/workspace/src/generators/move/lib/normalize-schema.spec.ts b/packages/workspace/src/generators/move/lib/normalize-schema.spec.ts index 53f4691607daa..4ee58369e6a7a 100644 --- a/packages/workspace/src/generators/move/lib/normalize-schema.spec.ts +++ b/packages/workspace/src/generators/move/lib/normalize-schema.spec.ts @@ -37,7 +37,6 @@ xdescribe('normalizeSchema', () => { importPath: '@proj/my/library', newProjectName: 'my-library', projectName: 'my-library', - projectNameAndRootFormat: 'as-provided', relativeToRootDestination: 'libs/my/library', updateImportPath: true, }; @@ -53,7 +52,6 @@ xdescribe('normalizeSchema', () => { importPath: '@proj/my-awesome-library', newProjectName: 'my-library', projectName: 'my-library', - projectNameAndRootFormat: 'as-provided', relativeToRootDestination: 'libs/my/library', updateImportPath: true, }; diff --git a/packages/workspace/src/generators/move/lib/normalize-schema.ts b/packages/workspace/src/generators/move/lib/normalize-schema.ts index 0d93c3022ec1c..24a9ebc74d505 100644 --- a/packages/workspace/src/generators/move/lib/normalize-schema.ts +++ b/packages/workspace/src/generators/move/lib/normalize-schema.ts @@ -1,20 +1,7 @@ -import { - logger, - names, - output, - stripIndents, - type ProjectConfiguration, - type Tree, -} from '@nx/devkit'; -import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; -import { prompt } from 'enquirer'; -import { getImportPath, getNpmScope } from '../../../utilities/get-import-path'; +import { type ProjectConfiguration, type Tree } from '@nx/devkit'; +import { getNpmScope } from '../../../utilities/get-import-path'; import type { NormalizedSchema, Schema } from '../schema'; -import { - getDestination, - getNewProjectName, - normalizePathSlashes, -} from './utils'; +import { normalizePathSlashes } from './utils'; export async function normalizeSchema( tree: Tree, diff --git a/packages/workspace/src/generators/move/lib/update-cypress-config.spec.ts b/packages/workspace/src/generators/move/lib/update-cypress-config.spec.ts index ddeda61777804..b9887d4e1a7e6 100644 --- a/packages/workspace/src/generators/move/lib/update-cypress-config.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-cypress-config.spec.ts @@ -31,8 +31,7 @@ describe('updateCypressConfig', () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); projectConfig = readProjectConfiguration(tree, 'my-lib'); }); diff --git a/packages/workspace/src/generators/move/lib/update-eslint-config.spec.ts b/packages/workspace/src/generators/move/lib/update-eslint-config.spec.ts index 52da633bdd480..0a0ff080b8bb7 100644 --- a/packages/workspace/src/generators/move/lib/update-eslint-config.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-eslint-config.spec.ts @@ -35,9 +35,8 @@ describe('updateEslint', () => { it('should handle .eslintrc.json not existing', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.None, - projectNameAndRootFormat: 'as-provided', }); const projectConfig = readProjectConfiguration(tree, 'my-lib'); @@ -49,9 +48,8 @@ describe('updateEslint', () => { it('should update .eslintrc.json extends path when project is moved to subdirectory', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', }); // This step is usually handled elsewhere tree.rename( @@ -74,7 +72,6 @@ describe('updateEslint', () => { name: 'api-test', directory: 'api/test', linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', }); // This step is usually handled elsewhere tree.rename('api/test/.eslintrc.json', 'test/.eslintrc.json'); @@ -100,9 +97,8 @@ describe('updateEslint', () => { it('should preserve .eslintrc.json non-relative extends when project is moved to subdirectory', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', }); updateJson(tree, 'my-lib/.eslintrc.json', (eslintRcJson) => { eslintRcJson.extends = [ @@ -134,10 +130,9 @@ describe('updateEslint', () => { it('should update .eslintrc.json overrides parser project when project is moved', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, setParserOptionsProject: true, - projectNameAndRootFormat: 'as-provided', }); // This step is usually handled elsewhere tree.rename( @@ -163,10 +158,9 @@ describe('updateEslint', () => { it('should update multiple .eslintrc.json overrides parser project when project is moved', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, setParserOptionsProject: true, - projectNameAndRootFormat: 'as-provided', }); // Add another parser project to eslint.json @@ -205,10 +199,9 @@ describe('updateEslint', () => { it('should update .eslintrc.json parserOptions.project as a string', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, setParserOptionsProject: true, - projectNameAndRootFormat: 'as-provided', }); // Add another parser project to eslint.json @@ -255,9 +248,8 @@ describe('updateEslint (flat config)', () => { it('should handle config not existing', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.None, - projectNameAndRootFormat: 'as-provided', }); const projectConfig = readProjectConfiguration(tree, 'my-lib'); @@ -269,9 +261,8 @@ describe('updateEslint (flat config)', () => { it('should update config extends path when project is moved to subdirectory', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', }); convertToFlat(tree, 'my-lib'); // This step is usually handled elsewhere @@ -293,7 +284,6 @@ describe('updateEslint (flat config)', () => { name: 'api-test', directory: 'api/test', linter: Linter.EsLint, - projectNameAndRootFormat: 'as-provided', }); convertToFlat(tree, 'api/test'); // This step is usually handled elsewhere @@ -319,10 +309,9 @@ describe('updateEslint (flat config)', () => { it('should update config overrides parser project when project is moved', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, setParserOptionsProject: true, - projectNameAndRootFormat: 'as-provided', }); convertToFlat(tree, 'my-lib', { hasParser: true }); // This step is usually handled elsewhere @@ -345,10 +334,9 @@ describe('updateEslint (flat config)', () => { it('should update multiple config overrides parser project when project is moved', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, setParserOptionsProject: true, - projectNameAndRootFormat: 'as-provided', }); // Add another parser project to eslint.json const storybookProject = '.storybook/tsconfig.json'; @@ -376,10 +364,9 @@ describe('updateEslint (flat config)', () => { it('should update config parserOptions.project as a string', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', linter: Linter.EsLint, setParserOptionsProject: true, - projectNameAndRootFormat: 'as-provided', }); convertToFlat(tree, 'my-lib', { hasParser: true, isString: true }); diff --git a/packages/workspace/src/generators/move/lib/update-imports.spec.ts b/packages/workspace/src/generators/move/lib/update-imports.spec.ts index 2f651aa7a6c39..e8f14886da0d9 100644 --- a/packages/workspace/src/generators/move/lib/update-imports.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-imports.spec.ts @@ -26,7 +26,6 @@ describe('updateImports', () => { newProjectName: 'my-destination', destination: 'my-destination', updateImportPath: true, - projectNameAndRootFormat: 'as-provided', }; }); @@ -35,17 +34,14 @@ describe('updateImports', () => { // tree where the workspace hasn't been updated yet, so just create libs representing // source and destination to make sure that the workspace has libraries with those names. await libraryGenerator(tree, { - name: 'my-destination', + directory: 'my-destination', config: 'project', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); await libraryGenerator(tree, { - name: 'my-importer', - projectNameAndRootFormat: 'as-provided', + directory: 'my-importer', }); const importerFilePath = 'my-importer/src/importer.ts'; tree.write( @@ -74,16 +70,13 @@ describe('updateImports', () => { */ it('should not update import paths when they contain a partial match', async () => { await libraryGenerator(tree, { - name: 'table', - projectNameAndRootFormat: 'as-provided', + directory: 'table', }); await libraryGenerator(tree, { - name: 'tab', - projectNameAndRootFormat: 'as-provided', + directory: 'tab', }); await libraryGenerator(tree, { - name: 'my-importer', - projectNameAndRootFormat: 'as-provided', + directory: 'my-importer', }); const importerFilePath = 'my-importer/src/importer.ts'; tree.write( @@ -122,16 +115,13 @@ describe('updateImports', () => { it('should correctly update deep imports', async () => { await libraryGenerator(tree, { - name: 'table', - projectNameAndRootFormat: 'as-provided', + directory: 'table', }); await libraryGenerator(tree, { - name: 'tab', - projectNameAndRootFormat: 'as-provided', + directory: 'tab', }); await libraryGenerator(tree, { - name: 'my-importer', - projectNameAndRootFormat: 'as-provided', + directory: 'my-importer', }); const importerFilePath = 'my-importer/src/importer.ts'; tree.write( @@ -170,16 +160,13 @@ describe('updateImports', () => { it('should update dynamic imports', async () => { await libraryGenerator(tree, { - name: 'table', - projectNameAndRootFormat: 'as-provided', + directory: 'table', }); await libraryGenerator(tree, { - name: 'tab', - projectNameAndRootFormat: 'as-provided', + directory: 'tab', }); await libraryGenerator(tree, { - name: 'my-importer', - projectNameAndRootFormat: 'as-provided', + directory: 'my-importer', }); const importerFilePath = 'my-importer/src/importer.ts'; tree.write( @@ -223,17 +210,14 @@ describe('updateImports', () => { it('should update imports and reexports', async () => { await libraryGenerator(tree, { - name: 'my-destination', + directory: 'my-destination', config: 'project', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); await libraryGenerator(tree, { - name: 'my-importer', - projectNameAndRootFormat: 'as-provided', + directory: 'my-importer', }); const importerFilePath = 'my-importer/src/importer.ts'; tree.write( @@ -260,17 +244,14 @@ describe('updateImports', () => { it('should not throw error on export list', async () => { await libraryGenerator(tree, { - name: 'my-destination', + directory: 'my-destination', config: 'project', - projectNameAndRootFormat: 'as-provided', }); await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); await libraryGenerator(tree, { - name: 'my-importer', - projectNameAndRootFormat: 'as-provided', + directory: 'my-importer', }); const importerFilePath = 'my-importer/src/importer.ts'; tree.write( @@ -292,16 +273,13 @@ describe('updateImports', () => { it('should update require imports', async () => { await libraryGenerator(tree, { - name: 'table', - projectNameAndRootFormat: 'as-provided', + directory: 'table', }); await libraryGenerator(tree, { - name: 'tab', - projectNameAndRootFormat: 'as-provided', + directory: 'tab', }); await libraryGenerator(tree, { - name: 'my-importer', - projectNameAndRootFormat: 'as-provided', + directory: 'my-importer', }); const importerFilePath = 'my-importer/src/importer.ts'; tree.write( @@ -347,16 +325,13 @@ describe('updateImports', () => { // tree where the workspace hasn't been updated yet, so just create libs representing // source and destination to make sure that the workspace has libraries with those names. await libraryGenerator(tree, { - name: 'my-destination', - projectNameAndRootFormat: 'as-provided', + directory: 'my-destination', }); await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); await libraryGenerator(tree, { - name: 'my-importer', - projectNameAndRootFormat: 'as-provided', + directory: 'my-importer', }); const importerFilePath = 'my-importer/src/importer.ts'; tree.write( @@ -388,8 +363,7 @@ export MyExtendedClass extends MyClass {};` it('should update project ref in the root tsconfig.base.json', async () => { await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); @@ -407,8 +381,7 @@ export MyExtendedClass extends MyClass {};` it('should update project ref in the root tsconfig.base.json for secondary entry points', async () => { await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); updateJson(tree, '/tsconfig.base.json', (json) => { json.compilerOptions.paths['@proj/my-source/testing'] = [ @@ -438,8 +411,7 @@ export MyExtendedClass extends MyClass {};` it('should update project ref of a project not under libs in the root tsconfig.base.json', async () => { tree.delete('libs'); await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); @@ -458,8 +430,7 @@ export MyExtendedClass extends MyClass {};` it('should update project ref in the root tsconfig.json when no tsconfig.base.json', async () => { tree.rename('tsconfig.base.json', 'tsconfig.json'); await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); @@ -482,8 +453,7 @@ export MyExtendedClass extends MyClass {};` `// A comment\n${tree.read('tsconfig.json', 'utf-8')}` ); await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); @@ -501,8 +471,7 @@ export MyExtendedClass extends MyClass {};` it('should only update the project ref paths in the tsconfig file when --updateImportPath=false', async () => { await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); @@ -528,8 +497,7 @@ export MyExtendedClass extends MyClass {};` it("should update project ref in the root tsconfig file if it contains a secondary entry point for Next.js's server", async () => { await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); tree.write('my-source/src/server.ts', ''); diff --git a/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts b/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts index 6a256a6218b51..732afd06e2981 100644 --- a/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-jest-config.spec.ts @@ -17,8 +17,7 @@ describe('updateJestConfig', () => { it('should handle jest config not existing', async () => { await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); const schema: NormalizedSchema = { @@ -46,8 +45,7 @@ describe('updateJestConfig', () => { const jestConfigPath = 'my-destination/jest.config.ts'; const rootJestConfigPath = '/jest.config.ts'; await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); tree.write(jestConfigPath, jestConfig); @@ -83,8 +81,7 @@ describe('updateJestConfig', () => { };`; const jestConfigPath = 'my-source/data-access/jest.config.ts'; await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); tree.write(jestConfigPath, jestConfig); @@ -121,7 +118,6 @@ describe('updateJestConfig', () => { await libraryGenerator(tree, { name: 'some-test-dir-my-source', directory: 'some/test/dir/my-source', - projectNameAndRootFormat: 'as-provided', }); const projectConfig = readProjectConfiguration( tree, @@ -152,7 +148,6 @@ describe('updateJestConfig', () => { await libraryGenerator(tree, { name: 'some-test-dir-my-source', directory: 'some/test/dir/my-source', - projectNameAndRootFormat: 'as-provided', }); tree.write( rootJestConfigPath, @@ -190,7 +185,6 @@ describe('updateJestConfig', () => { await libraryGenerator(tree, { name: 'some-test-dir-my-source', directory: 'some/test/dir/my-source', - projectNameAndRootFormat: 'as-provided', }); tree.write( rootJestConfigPath, @@ -231,7 +225,6 @@ module.exports = { await libraryGenerator(tree, { name: 'some-test-dir-my-source', directory: 'some/test/dir/my-source', - projectNameAndRootFormat: 'as-provided', }); tree.write( rootJestConfigPath, diff --git a/packages/workspace/src/generators/move/lib/update-package-json.spec.ts b/packages/workspace/src/generators/move/lib/update-package-json.spec.ts index 7792ed41b12c8..e6e4bfaee6676 100644 --- a/packages/workspace/src/generators/move/lib/update-package-json.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-package-json.spec.ts @@ -24,8 +24,7 @@ describe('updatePackageJson', () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); }); diff --git a/packages/workspace/src/generators/move/lib/update-project-root-files.spec.ts b/packages/workspace/src/generators/move/lib/update-project-root-files.spec.ts index 5faaf8293c01f..645ef171da823 100644 --- a/packages/workspace/src/generators/move/lib/update-project-root-files.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-project-root-files.spec.ts @@ -27,8 +27,7 @@ describe('updateProjectRootFiles', () => { };`; const testFilePath = 'subfolder/my-destination/jest.config.js'; await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); tree.write(testFilePath, testFile); @@ -61,9 +60,8 @@ export default defineConfig({ `; const cypressConfigPath = 'apps/my-app-e2e/cypress.config.ts'; await libraryGenerator(tree, { - name: 'e2e', + directory: 'e2e', root: 'e2e', - projectNameAndRootFormat: 'as-provided', }); const projectConfig = readProjectConfiguration(tree, 'e2e'); tree.write(cypressConfigPath, cypressConfigContents); diff --git a/packages/workspace/src/generators/move/lib/update-readme.spec.ts b/packages/workspace/src/generators/move/lib/update-readme.spec.ts index 2860373686fc4..78772ba32a5cb 100644 --- a/packages/workspace/src/generators/move/lib/update-readme.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-readme.spec.ts @@ -28,8 +28,7 @@ describe('updateReadme', () => { it('should handle README.md not existing', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); const readmePath = join(schema.relativeToRootDestination, 'README.md'); tree.delete(readmePath); @@ -41,8 +40,7 @@ describe('updateReadme', () => { it('should update README.md contents', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); // This step is usually handled elsewhere tree.rename('my-lib/README.md', 'shared/my-destination/README.md'); diff --git a/packages/workspace/src/generators/move/lib/update-storybook-config.spec.ts b/packages/workspace/src/generators/move/lib/update-storybook-config.spec.ts index 1f295d7ff62fa..eb1000f689d1a 100644 --- a/packages/workspace/src/generators/move/lib/update-storybook-config.spec.ts +++ b/packages/workspace/src/generators/move/lib/update-storybook-config.spec.ts @@ -17,8 +17,7 @@ describe('updateStorybookConfig', () => { it('should handle storybook config not existing', async () => { await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); const schema: NormalizedSchema = { @@ -43,8 +42,7 @@ describe('updateStorybookConfig', () => { const storybookMainPath = 'namespace/my-destination/.storybook/main.js'; await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); tree.write(storybookMainPath, storybookMain); @@ -72,8 +70,7 @@ describe('updateStorybookConfig', () => { const storybookWebpackConfigPath = 'namespace/my-destination/.storybook/webpack.config.js'; await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); tree.write(storybookWebpackConfigPath, storybookWebpackConfig); @@ -113,8 +110,7 @@ describe('updateStorybookConfig', () => { 'namespace/my-destination/.storybook/nested/main.js'; await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); tree.write(storybookMainPath, storybookMain); @@ -157,8 +153,7 @@ describe('updateStorybookConfig', () => { 'namespace/my-destination/.storybook/nested/webpack.config.js'; await libraryGenerator(tree, { - name: 'my-source', - projectNameAndRootFormat: 'as-provided', + directory: 'my-source', }); const projectConfig = readProjectConfiguration(tree, 'my-source'); tree.write(storybookWebpackConfigPath, storybookWebpackConfig); diff --git a/packages/workspace/src/generators/move/move.spec.ts b/packages/workspace/src/generators/move/move.spec.ts index 6f8e75c6bb0b3..cdf9f52a604e5 100644 --- a/packages/workspace/src/generators/move/move.spec.ts +++ b/packages/workspace/src/generators/move/move.spec.ts @@ -23,8 +23,7 @@ describe('move', () => { it('should update jest config when moving down directories', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); await moveGenerator(tree, { @@ -32,7 +31,6 @@ describe('move', () => { importPath: '@proj/shared-mylib', updateImportPath: true, destination: 'shared/my-lib-new', - projectNameAndRootFormat: 'as-provided', }); const jestConfigPath = 'shared/my-lib-new/jest.config.ts'; @@ -46,8 +44,7 @@ describe('move', () => { it('should make sure build targets are correct when moving', async () => { await libraryGenerator(tree, { - name: 'one', - projectNameAndRootFormat: 'as-provided', + directory: 'one', }); const myLibConfig = readProjectConfiguration(tree, 'one'); @@ -73,7 +70,6 @@ describe('move', () => { newProjectName: 'two', updateImportPath: true, destination: 'shared/two', - projectNameAndRootFormat: 'as-provided', }); const myLibNewConfig = readProjectConfiguration(tree, 'two'); @@ -93,7 +89,6 @@ describe('move', () => { await libraryGenerator(tree, { name: 'shared-my-lib', directory: 'shared/my-lib', - projectNameAndRootFormat: 'as-provided', }); await moveGenerator(tree, { @@ -101,7 +96,6 @@ describe('move', () => { importPath: '@proj/mylib', updateImportPath: true, destination: 'my-lib-new', - projectNameAndRootFormat: 'as-provided', }); const jestConfigPath = 'my-lib-new/jest.config.ts'; @@ -115,8 +109,7 @@ describe('move', () => { it('should update $schema path when move', async () => { await libraryGenerator(tree, { - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', + directory: 'my-lib', }); let projectJson = readJson(tree, 'my-lib/project.json'); @@ -129,7 +122,6 @@ describe('move', () => { importPath: '@proj/shared-mylib', updateImportPath: true, destination: 'shared/my-lib-new', - projectNameAndRootFormat: 'as-provided', }); projectJson = readJson(tree, 'shared/my-lib-new/project.json'); diff --git a/packages/workspace/src/generators/move/schema.d.ts b/packages/workspace/src/generators/move/schema.d.ts index 5af363e4735a4..c4fd298ef4d32 100644 --- a/packages/workspace/src/generators/move/schema.d.ts +++ b/packages/workspace/src/generators/move/schema.d.ts @@ -1,5 +1,3 @@ -import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils'; - export interface Schema { projectName: string; destination: string; @@ -7,7 +5,6 @@ export interface Schema { updateImportPath: boolean; skipFormat?: boolean; newProjectName?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; } export interface NormalizedSchema extends Schema { diff --git a/packages/workspace/src/generators/move/schema.json b/packages/workspace/src/generators/move/schema.json index e67c483887195..ceea9a5130f21 100644 --- a/packages/workspace/src/generators/move/schema.json +++ b/packages/workspace/src/generators/move/schema.json @@ -33,11 +33,6 @@ "index": 0 } }, - "projectNameAndRootFormat": { - "description": "Whether to generate the new project name and destination as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", - "type": "string", - "enum": ["as-provided", "derived"] - }, "importPath": { "type": "string", "description": "The new import path to use in the `tsconfig.base.json`." diff --git a/packages/workspace/src/generators/npm-package/npm-package.ts b/packages/workspace/src/generators/npm-package/npm-package.ts index 5773de39ece87..0f69d707a6cf5 100644 --- a/packages/workspace/src/generators/npm-package/npm-package.ts +++ b/packages/workspace/src/generators/npm-package/npm-package.ts @@ -7,15 +7,14 @@ import { } from '@nx/devkit'; import { determineProjectNameAndRootOptions, - type ProjectNameAndRootFormat, + ensureProjectName, } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { join } from 'path'; import { getImportPath } from '../../utilities/get-import-path'; export interface ProjectOptions { - name: string; - directory?: string; - projectNameAndRootFormat?: ProjectNameAndRootFormat; + directory: string; + name?: string; } interface NormalizedProjectOptions extends ProjectOptions { @@ -26,13 +25,13 @@ async function normalizeOptions( tree: Tree, options: ProjectOptions ): Promise { + await ensureProjectName(tree, options, 'library'); const { projectName, projectRoot } = await determineProjectNameAndRootOptions( tree, { name: options.name, projectType: 'library', directory: options.directory, - projectNameAndRootFormat: options.projectNameAndRootFormat, } ); diff --git a/packages/workspace/src/generators/npm-package/schema.json b/packages/workspace/src/generators/npm-package/schema.json index 70437019d348f..a16711087073b 100644 --- a/packages/workspace/src/generators/npm-package/schema.json +++ b/packages/workspace/src/generators/npm-package/schema.json @@ -6,26 +6,20 @@ "cli": "nx", "type": "object", "properties": { - "name": { + "directory": { "type": "string", - "description": "Package name.", + "description": "A directory where the package is placed.", + "alias": "dir", "$default": { "$source": "argv", "index": 0 }, - "x-prompt": "What name of your npm package?", - "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$" - }, - "directory": { - "type": "string", - "description": "A directory where the package is placed.", - "alias": "dir" + "x-prompt": "Which directory do you want to create the package in?" }, - "projectNameAndRootFormat": { - "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).", + "name": { "type": "string", - "enum": ["as-provided", "derived"] + "description": "Package name." } }, - "required": ["name"] + "required": ["directory"] } diff --git a/packages/workspace/src/generators/preset/preset.ts b/packages/workspace/src/generators/preset/preset.ts index 7601daaa98611..4c9fc5a055fba 100644 --- a/packages/workspace/src/generators/preset/preset.ts +++ b/packages/workspace/src/generators/preset/preset.ts @@ -29,7 +29,6 @@ async function createPreset(tree: Tree, options: Schema) { return angularApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, standalone: options.standaloneApi, @@ -48,7 +47,6 @@ async function createPreset(tree: Tree, options: Schema) { return angularApplicationGenerator(tree, { name: options.name, directory: '.', - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, routing: options.routing, @@ -67,7 +65,6 @@ async function createPreset(tree: Tree, options: Schema) { return reactApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, bundler: options.bundler ?? 'webpack', @@ -82,7 +79,6 @@ async function createPreset(tree: Tree, options: Schema) { return reactApplicationGenerator(tree, { name: options.name, directory: '.', - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, rootProject: true, @@ -99,7 +95,6 @@ async function createPreset(tree: Tree, options: Schema) { return remixApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', linter: options.linter, e2eTestRunner: options.e2eTestRunner ?? 'playwright', unitTestRunner: 'vitest', @@ -113,7 +108,6 @@ async function createPreset(tree: Tree, options: Schema) { return remixApplicationGenerator(tree, { name: options.name, directory: '.', - projectNameAndRootFormat: 'as-provided', linter: options.linter, e2eTestRunner: options.e2eTestRunner ?? 'playwright', rootProject: true, @@ -128,7 +122,6 @@ async function createPreset(tree: Tree, options: Schema) { return vueApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, e2eTestRunner: options.e2eTestRunner ?? 'playwright', @@ -142,7 +135,6 @@ async function createPreset(tree: Tree, options: Schema) { return vueApplicationGenerator(tree, { name: options.name, directory: '.', - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, rootProject: true, @@ -158,7 +150,6 @@ async function createPreset(tree: Tree, options: Schema) { return nuxtApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, e2eTestRunner: options.e2eTestRunner ?? 'playwright', @@ -172,7 +163,6 @@ async function createPreset(tree: Tree, options: Schema) { return nuxtApplicationGenerator(tree, { name: options.name, directory: '.', - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, rootProject: true, @@ -188,7 +178,6 @@ async function createPreset(tree: Tree, options: Schema) { return nextApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, appDir: options.nextAppDir, @@ -202,7 +191,6 @@ async function createPreset(tree: Tree, options: Schema) { return nextApplicationGenerator(tree, { name: options.name, directory: '.', - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, appDir: options.nextAppDir, @@ -218,7 +206,6 @@ async function createPreset(tree: Tree, options: Schema) { return webApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', style: options.style, linter: options.linter, bundler: 'vite', @@ -233,7 +220,6 @@ async function createPreset(tree: Tree, options: Schema) { return nestApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', linter: options.linter, e2eTestRunner: options.e2eTestRunner ?? 'jest', addPlugin, @@ -245,7 +231,6 @@ async function createPreset(tree: Tree, options: Schema) { return expressApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', linter: options.linter, e2eTestRunner: options.e2eTestRunner ?? 'jest', addPlugin, @@ -256,7 +241,6 @@ async function createPreset(tree: Tree, options: Schema) { return reactNativeApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', linter: options.linter, e2eTestRunner: options.e2eTestRunner ?? 'detox', addPlugin, @@ -267,7 +251,6 @@ async function createPreset(tree: Tree, options: Schema) { return expoApplicationGenerator(tree, { name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', linter: options.linter, e2eTestRunner: options.e2eTestRunner ?? 'detox', addPlugin, @@ -286,7 +269,6 @@ async function createPreset(tree: Tree, options: Schema) { return libraryGenerator(tree, { name: options.name, directory: '.', - projectNameAndRootFormat: 'as-provided', bundler: 'tsc', unitTestRunner: 'vitest', testEnvironment: 'node', @@ -302,7 +284,6 @@ async function createPreset(tree: Tree, options: Schema) { bundler, name: options.name, directory: '.', - projectNameAndRootFormat: 'as-provided', linter: options.linter, standaloneConfig: options.standaloneConfig, framework: options.framework, @@ -319,7 +300,6 @@ async function createPreset(tree: Tree, options: Schema) { bundler, name: options.name, directory: join('apps', options.name), - projectNameAndRootFormat: 'as-provided', linter: options.linter, framework: options.framework, docker: options.docker, diff --git a/packages/workspace/src/generators/remove/lib/remove-project.spec.ts b/packages/workspace/src/generators/remove/lib/remove-project.spec.ts index 349040d637c5f..83603f021a1cd 100644 --- a/packages/workspace/src/generators/remove/lib/remove-project.spec.ts +++ b/packages/workspace/src/generators/remove/lib/remove-project.spec.ts @@ -15,7 +15,7 @@ describe('moveProject', () => { beforeEach(async () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', }); schema = { diff --git a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts index 89f4775e70559..11a0f707332ec 100644 --- a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts @@ -99,7 +99,7 @@ describe('updateRootJestConfig', () => { tree.delete('jest.config.ts'); await libraryGenerator(tree, { - name: 'test', + directory: 'test', bundler: 'vite', unitTestRunner: 'vitest', }); 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 876c9167e50df..50337784c5831 100644 --- a/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-tsconfig.spec.ts @@ -47,7 +47,7 @@ describe('updateTsconfig', () => { it('should delete project ref from the root tsconfig.base.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', }); graph = { @@ -72,7 +72,7 @@ describe('updateTsconfig', () => { it('should delete project ref not under libs from the root tsconfig.base.json', async () => { tree.delete('libs'); await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', }); graph = { @@ -96,7 +96,7 @@ describe('updateTsconfig', () => { it('should delete project ref with importPath from the root tsconfig.base.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', importPath: '@proj/whatever-name', }); @@ -123,7 +123,7 @@ describe('updateTsconfig', () => { it('should delete project ref from the root tsconfig.json when no tsconfig.base.json', async () => { tree.rename('tsconfig.base.json', 'tsconfig.json'); await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', }); graph = { @@ -148,7 +148,7 @@ describe('updateTsconfig', () => { it('should delete project ref with importPath from the root tsconfig.json when no tsconfig.base.json', async () => { tree.rename('tsconfig.base.json', 'tsconfig.json'); await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', importPath: '@proj/whatever-name', }); @@ -174,7 +174,7 @@ describe('updateTsconfig', () => { it('should not delete importPaths of nested projects from tsconfig.base.json', async () => { await libraryGenerator(tree, { - name: 'my-lib', + directory: 'my-lib', importPath: '@proj/whatever-name', }); diff --git a/packages/workspace/src/generators/run-commands/run-commands.spec.ts b/packages/workspace/src/generators/run-commands/run-commands.spec.ts index 55d2879898d64..54f36527c6900 100644 --- a/packages/workspace/src/generators/run-commands/run-commands.spec.ts +++ b/packages/workspace/src/generators/run-commands/run-commands.spec.ts @@ -19,7 +19,7 @@ describe('run-commands', () => { }; await libraryGenerator(tree, { - name: 'lib', + directory: 'lib', }); await runCommands(tree, opts); 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 5f934632ccb75..e2f2625d740cc 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 @@ -176,7 +176,7 @@ async function createNewPlugin(tree: Tree) { await pluginGenerator(tree, { minimal: true, - name: PROJECT_NAME, + directory: PROJECT_NAME, importPath: importPath, skipTsConfig: false, compiler: 'tsc', @@ -208,7 +208,6 @@ function moveGeneratedPlugin( newProjectName: PROJECT_NAME, updateImportPath: true, importPath: importPath, - projectNameAndRootFormat: 'as-provided', }); } }