@nx/next 0.0.0-pr-27957-a99d5ea → 0.0.0-pr-28229-afe192c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/generators.json CHANGED
@@ -17,12 +17,12 @@
17
17
  "description": "Create an application."
18
18
  },
19
19
  "page": {
20
- "factory": "./src/generators/page/page#pageGeneratorInternal",
20
+ "factory": "./src/generators/page/page",
21
21
  "schema": "./src/generators/page/schema.json",
22
22
  "description": "Create a page."
23
23
  },
24
24
  "component": {
25
- "factory": "./src/generators/component/component#componentGeneratorInternal",
25
+ "factory": "./src/generators/component/component",
26
26
  "schema": "./src/generators/component/schema.json",
27
27
  "description": "Create a component."
28
28
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/next",
3
- "version": "0.0.0-pr-27957-a99d5ea",
3
+ "version": "0.0.0-pr-28229-afe192c",
4
4
  "private": false,
5
5
  "description": "The Next.js plugin for Nx contains executors and generators for managing Next.js applications and libraries within an Nx workspace. It provides:\n\n\n- Scaffolding for creating, building, serving, linting, and testing Next.js applications.\n\n- Integration with building, serving, and exporting a Next.js application.\n\n- Integration with React libraries within the workspace. \n\nWhen using Next.js in Nx, you get the out-of-the-box support for TypeScript, Playwright, Cypress, and Jest. No need to configure anything: watch mode, source maps, and typings just work.",
6
6
  "repository": {
@@ -35,29 +35,26 @@
35
35
  "next": ">=14.0.0"
36
36
  },
37
37
  "dependencies": {
38
- "@nx/devkit": "0.0.0-pr-27957-a99d5ea",
38
+ "@nx/devkit": "0.0.0-pr-28229-afe192c",
39
39
  "@babel/plugin-proposal-decorators": "^7.22.7",
40
40
  "@svgr/webpack": "^8.0.1",
41
- "chalk": "^4.1.0",
42
41
  "copy-webpack-plugin": "^10.2.4",
43
42
  "file-loader": "^6.2.0",
44
- "fs-extra": "^11.1.0",
45
43
  "ignore": "^5.0.4",
44
+ "picocolors": "^1.1.0",
46
45
  "semver": "^7.5.3",
47
46
  "tslib": "^2.3.0",
48
47
  "webpack-merge": "^5.8.0",
49
- "@nx/js": "0.0.0-pr-27957-a99d5ea",
50
- "@nx/eslint": "0.0.0-pr-27957-a99d5ea",
51
- "@nx/react": "0.0.0-pr-27957-a99d5ea",
52
- "@nx/web": "0.0.0-pr-27957-a99d5ea",
53
- "@nx/webpack": "0.0.0-pr-27957-a99d5ea",
54
- "@nx/workspace": "0.0.0-pr-27957-a99d5ea",
55
- "@phenomnomnominal/tsquery": "~5.0.1",
56
- "@nrwl/next": "0.0.0-pr-27957-a99d5ea"
48
+ "@nx/js": "0.0.0-pr-28229-afe192c",
49
+ "@nx/eslint": "0.0.0-pr-28229-afe192c",
50
+ "@nx/react": "0.0.0-pr-28229-afe192c",
51
+ "@nx/web": "0.0.0-pr-28229-afe192c",
52
+ "@nx/webpack": "0.0.0-pr-28229-afe192c",
53
+ "@phenomnomnominal/tsquery": "~5.0.1"
57
54
  },
58
55
  "publishConfig": {
59
56
  "access": "public"
60
57
  },
61
58
  "type": "commonjs",
62
59
  "types": "./index.d.ts"
63
- }
60
+ }
@@ -4,9 +4,9 @@ exports.default = buildExecutor;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const js_1 = require("@nx/js");
6
6
  const path_1 = require("path");
7
- const fs_extra_1 = require("fs-extra");
7
+ const node_fs_1 = require("node:fs");
8
+ const promises_1 = require("node:fs/promises");
8
9
  const semver_1 = require("semver");
9
- const fileutils_1 = require("@nx/workspace/src/utilities/fileutils");
10
10
  const semver_2 = require("@nx/devkit/src/utils/semver");
11
11
  const update_package_json_1 = require("./lib/update-package-json");
12
12
  const create_next_config_file_1 = require("./lib/create-next-config-file");
@@ -22,7 +22,7 @@ async function buildExecutor(options, context) {
22
22
  (0, check_project_1.checkPublicDirectory)(projectRoot);
23
23
  // Set `__NEXT_REACT_ROOT` based on installed ReactDOM version
24
24
  const packageJsonPath = (0, path_1.join)(projectRoot, 'package.json');
25
- const packageJson = (0, fs_extra_1.existsSync)(packageJsonPath)
25
+ const packageJson = (0, node_fs_1.existsSync)(packageJsonPath)
26
26
  ? (0, devkit_1.readJsonFile)(packageJsonPath)
27
27
  : undefined;
28
28
  const rootPackageJson = (0, devkit_1.readJsonFile)((0, path_1.join)(context.root, 'package.json'));
@@ -51,9 +51,7 @@ async function buildExecutor(options, context) {
51
51
  childProcess.kill();
52
52
  }
53
53
  }
54
- if (!(0, fileutils_1.directoryExists)(options.outputPath)) {
55
- (0, fs_extra_1.mkdir)(options.outputPath);
56
- }
54
+ await (0, promises_1.mkdir)(options.outputPath, { recursive: true });
57
55
  const builtPackageJson = (0, js_1.createPackageJson)(context.projectName, context.projectGraph, {
58
56
  target: context.targetName,
59
57
  root: context.root,
@@ -70,7 +68,7 @@ async function buildExecutor(options, context) {
70
68
  if (options.generateLockfile) {
71
69
  const packageManager = (0, devkit_1.detectPackageManager)(context.root);
72
70
  const lockFile = (0, js_1.createLockFile)(builtPackageJson, context.projectGraph, packageManager);
73
- (0, fs_extra_1.writeFileSync)(`${options.outputPath}/${(0, js_1.getLockFileName)(packageManager)}`, lockFile, {
71
+ (0, node_fs_1.writeFileSync)(`${options.outputPath}/${(0, js_1.getLockFileName)(packageManager)}`, lockFile, {
74
72
  encoding: 'utf-8',
75
73
  });
76
74
  }
@@ -78,8 +76,9 @@ async function buildExecutor(options, context) {
78
76
  // This is the default behavior when running `nx build <app>`.
79
77
  if (options.outputPath.replace(/\/$/, '') !== projectRoot) {
80
78
  (0, create_next_config_file_1.createNextConfigFile)(options, context);
81
- (0, fs_extra_1.copySync)((0, path_1.join)(projectRoot, 'public'), (0, path_1.join)(options.outputPath, 'public'), {
79
+ (0, node_fs_1.cpSync)((0, path_1.join)(projectRoot, 'public'), (0, path_1.join)(options.outputPath, 'public'), {
82
80
  dereference: true,
81
+ recursive: true,
83
82
  });
84
83
  }
85
84
  return { success: true };
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkPublicDirectory = checkPublicDirectory;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const fs_extra_1 = require("fs-extra");
5
+ const node_fs_1 = require("node:fs");
6
6
  const path_1 = require("path");
7
7
  function checkPublicDirectory(root) {
8
- if ((0, fs_extra_1.readdirSync)((0, path_1.join)(root, 'public')).length === 0) {
8
+ if ((0, node_fs_1.readdirSync)((0, path_1.join)(root, 'public')).length === 0) {
9
9
  devkit_1.logger.warn('public directory cannot be empty. This may result in errors during the deployment. Consider adding a public/.gitkeep file');
10
10
  }
11
11
  }
@@ -8,7 +8,7 @@ exports.getRelativeImports = getRelativeImports;
8
8
  exports.ensureFileExtensions = ensureFileExtensions;
9
9
  const devkit_1 = require("@nx/devkit");
10
10
  const ts = require("typescript");
11
- const fs_extra_1 = require("fs-extra");
11
+ const node_fs_1 = require("node:fs");
12
12
  const path_1 = require("path");
13
13
  const js_1 = require("@nx/js");
14
14
  function createNextConfigFile(options, context) {
@@ -22,21 +22,21 @@ function createNextConfigFile(options, context) {
22
22
  // If user passed a config then it is relative to the workspace root, need to normalize it to be relative to the project root.
23
23
  options.nextConfig ? (0, path_1.relative)(projectRoot, options.nextConfig) : undefined);
24
24
  const configAbsolutePath = (0, path_1.join)(projectRoot, configRelativeToProjectRoot);
25
- if (!(0, fs_extra_1.existsSync)(configAbsolutePath)) {
25
+ if (!(0, node_fs_1.existsSync)(configAbsolutePath)) {
26
26
  throw new Error('next.config.js not found');
27
27
  }
28
28
  // Copy config file and our `.nx-helpers` folder to remove dependency on @nrwl/next for production build.
29
29
  const helpersPath = (0, path_1.join)(options.outputPath, '.nx-helpers');
30
- (0, fs_extra_1.mkdirSync)(helpersPath, { recursive: true });
31
- (0, fs_extra_1.copyFileSync)((0, path_1.join)(__dirname, '../../../utils/compose-plugins.js'), (0, path_1.join)(helpersPath, 'compose-plugins.js'));
32
- (0, fs_extra_1.writeFileSync)((0, path_1.join)(helpersPath, 'with-nx.js'), getWithNxContent());
33
- (0, fs_extra_1.writeFileSync)((0, path_1.join)(helpersPath, 'compiled.js'), `
30
+ (0, node_fs_1.mkdirSync)(helpersPath, { recursive: true });
31
+ (0, node_fs_1.copyFileSync)((0, path_1.join)(__dirname, '../../../utils/compose-plugins.js'), (0, path_1.join)(helpersPath, 'compose-plugins.js'));
32
+ (0, node_fs_1.writeFileSync)((0, path_1.join)(helpersPath, 'with-nx.js'), getWithNxContent());
33
+ (0, node_fs_1.writeFileSync)((0, path_1.join)(helpersPath, 'compiled.js'), `
34
34
  const withNx = require('./with-nx');
35
35
  module.exports = withNx;
36
36
  module.exports.withNx = withNx;
37
37
  module.exports.composePlugins = require('./compose-plugins').composePlugins;
38
38
  `);
39
- (0, fs_extra_1.writeFileSync)((0, path_1.join)(options.outputPath, configRelativeToProjectRoot), (0, fs_extra_1.readFileSync)(configAbsolutePath)
39
+ (0, node_fs_1.writeFileSync)((0, path_1.join)(options.outputPath, configRelativeToProjectRoot), (0, node_fs_1.readFileSync)(configAbsolutePath)
40
40
  .toString()
41
41
  .replace(/["']@nx\/next["']/, `'./.nx-helpers/compiled.js'`)
42
42
  // TODO(v17): Remove this once users have all migrated to new @nx scope and import from '@nx/next' not the deep import paths.
@@ -45,17 +45,18 @@ function createNextConfigFile(options, context) {
45
45
  // Find all relative imports needed by next.config.js and copy them to the dist folder.
46
46
  const moduleFilesToCopy = getRelativeFilesToCopy(configRelativeToProjectRoot, projectRoot);
47
47
  for (const moduleFile of moduleFilesToCopy) {
48
- (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)((0, path_1.join)(context.root, options.outputPath, moduleFile)));
48
+ const moduleFileDir = (0, path_1.dirname)((0, path_1.join)(context.root, options.outputPath, moduleFile));
49
+ (0, node_fs_1.mkdirSync)(moduleFileDir, { recursive: true });
49
50
  // We already generate a build version of package.json in the dist folder.
50
51
  if (moduleFile !== 'package.json') {
51
- (0, fs_extra_1.copyFileSync)((0, path_1.join)(context.root, projectRoot, moduleFile), (0, path_1.join)(context.root, options.outputPath, moduleFile));
52
+ (0, node_fs_1.copyFileSync)((0, path_1.join)(context.root, projectRoot, moduleFile), (0, path_1.join)(context.root, options.outputPath, moduleFile));
52
53
  }
53
54
  }
54
55
  }
55
56
  function readSource(getFile) {
56
57
  return {
57
58
  file: getFile(),
58
- content: (0, fs_extra_1.readFileSync)(getFile()).toString(),
59
+ content: (0, node_fs_1.readFileSync)(getFile()).toString(),
59
60
  };
60
61
  }
61
62
  // Exported for testing
@@ -89,13 +90,13 @@ function getWithNxContent({ file, content } = readSource(() => (0, path_1.join)(
89
90
  function findNextConfigPath(dirname, userDefinedConfigPath) {
90
91
  if (userDefinedConfigPath) {
91
92
  const file = userDefinedConfigPath;
92
- if ((0, fs_extra_1.existsSync)((0, path_1.join)(dirname, file)))
93
+ if ((0, node_fs_1.existsSync)((0, path_1.join)(dirname, file)))
93
94
  return file;
94
95
  throw new Error(`Cannot find the Next.js config file: ${userDefinedConfigPath}. Is the path correct in project.json?`);
95
96
  }
96
97
  const candidates = ['next.config.js', 'next.config.cjs', 'next.config.mjs'];
97
98
  for (const candidate of candidates) {
98
- if ((0, fs_extra_1.existsSync)((0, path_1.join)(dirname, candidate)))
99
+ if ((0, node_fs_1.existsSync)((0, path_1.join)(dirname, candidate)))
99
100
  return candidate;
100
101
  }
101
102
  throw new Error(`Cannot find any of the following files in your project: ${candidates.join(', ')}. Is this a Next.js project?`);
@@ -110,7 +111,7 @@ function getRelativeFilesToCopy(fileName, cwd) {
110
111
  return;
111
112
  seen.add(currFile);
112
113
  const absoluteFilePath = (0, path_1.join)(cwd, currFile);
113
- const content = (0, fs_extra_1.readFileSync)(absoluteFilePath).toString();
114
+ const content = (0, node_fs_1.readFileSync)(absoluteFilePath).toString();
114
115
  const files = getRelativeImports({ file: currFile, content });
115
116
  const modules = ensureFileExtensions(files, (0, path_1.dirname)(absoluteFilePath));
116
117
  const relativeDirPath = (0, path_1.dirname)(currFile);
@@ -153,7 +154,7 @@ function ensureFileExtensions(files, absoluteDir) {
153
154
  const providedExt = (0, path_1.extname)(file);
154
155
  if (providedExt && extensions.includes(providedExt))
155
156
  return file;
156
- const ext = extensions.find((ext) => (0, fs_extra_1.existsSync)((0, path_1.join)(absoluteDir, file + ext)));
157
+ const ext = extensions.find((ext) => (0, node_fs_1.existsSync)((0, path_1.join)(absoluteDir, file + ext)));
157
158
  if (ext) {
158
159
  return file + ext;
159
160
  }
@@ -6,7 +6,7 @@ const export_1 = require("next/dist/export");
6
6
  const nextTrace = require("next/dist/trace");
7
7
  const os_1 = require("os");
8
8
  const child_process_1 = require("child_process");
9
- const chalk = require("chalk");
9
+ const pc = require("picocolors");
10
10
  const semver_1 = require("semver");
11
11
  // platform specific command name
12
12
  const pmCmd = (0, os_1.platform)() === 'win32' ? `npx.cmd` : 'npx';
@@ -37,7 +37,7 @@ async function exportExecutor(options, context) {
37
37
  });
38
38
  }
39
39
  catch {
40
- throw new Error(`Build target failed: ${chalk.bold(options.buildTarget)}`);
40
+ throw new Error(`Build target failed: ${pc.bold(options.buildTarget)}`);
41
41
  }
42
42
  const buildOptions = (0, devkit_1.readTargetOptions)(buildTarget, context);
43
43
  const projectRoot = context.projectGraph.nodes[context.projectName].data.root;
@@ -24,7 +24,6 @@ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-projec
24
24
  async function applicationGenerator(host, schema) {
25
25
  return await applicationGeneratorInternal(host, {
26
26
  addPlugin: false,
27
- projectNameAndRootFormat: 'derived',
28
27
  ...schema,
29
28
  });
30
29
  }
@@ -6,16 +6,14 @@ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project
6
6
  const eslint_1 = require("@nx/eslint");
7
7
  const assertion_1 = require("@nx/react/src/utils/assertion");
8
8
  async function normalizeOptions(host, options) {
9
- const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
9
+ await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
10
+ const { projectName: appProjectName, projectRoot: appProjectRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
11
  name: options.name,
11
12
  projectType: 'application',
12
13
  directory: options.directory,
13
- projectNameAndRootFormat: options.projectNameAndRootFormat,
14
14
  rootProject: options.rootProject,
15
- callingGenerator: '@nx/next:application',
16
15
  });
17
16
  options.rootProject = appProjectRoot === '.';
18
- options.projectNameAndRootFormat = projectNameAndRootFormat;
19
17
  const nxJson = (0, devkit_1.readNxJson)(host);
20
18
  const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
21
19
  nxJson.useInferencePlugins !== false;
@@ -1,13 +1,11 @@
1
- import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
1
  import type { Linter, LinterType } from '@nx/eslint';
3
2
  import type { SupportedStyles } from '@nx/react';
4
3
 
5
4
  export interface Schema {
6
- name: string;
5
+ directory: string;
6
+ name?: string;
7
7
  style?: SupportedStyles;
8
8
  skipFormat?: boolean;
9
- directory?: string;
10
- projectNameAndRootFormat?: ProjectNameAndRootFormat;
11
9
  tags?: string;
12
10
  unitTestRunner?: 'jest' | 'none';
13
11
  e2eTestRunner?: 'cypress' | 'playwright' | 'none';
@@ -6,28 +6,22 @@
6
6
  "description": "Create a Next.js Application for Nx.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "name": {
10
- "description": "The name of the application.",
9
+ "directory": {
10
+ "description": "The directory of the new application.",
11
11
  "type": "string",
12
+ "alias": "dir",
12
13
  "$default": {
13
14
  "$source": "argv",
14
15
  "index": 0
15
16
  },
16
- "x-prompt": "What name would you like to use for the application?",
17
- "pattern": "^[a-zA-Z][^:]*$",
18
- "x-priority": "important"
17
+ "x-prompt": "Which directory do you want to create the application in?"
19
18
  },
20
- "directory": {
21
- "description": "The directory of the new application.",
19
+ "name": {
20
+ "description": "The name of the application.",
22
21
  "type": "string",
23
- "alias": "dir",
22
+ "pattern": "^[a-zA-Z][^:]*$",
24
23
  "x-priority": "important"
25
24
  },
26
- "projectNameAndRootFormat": {
27
- "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`).",
28
- "type": "string",
29
- "enum": ["as-provided", "derived"]
30
- },
31
25
  "style": {
32
26
  "description": "The file extension to be used for style files.",
33
27
  "type": "string",
@@ -37,7 +31,10 @@
37
31
  "message": "Which stylesheet format would you like to use?",
38
32
  "type": "list",
39
33
  "items": [
40
- { "value": "css", "label": "CSS" },
34
+ {
35
+ "value": "css",
36
+ "label": "CSS"
37
+ },
41
38
  {
42
39
  "value": "scss",
43
40
  "label": "SASS(.scss) [ https://sass-lang.com ]"
@@ -145,6 +142,6 @@
145
142
  "x-priority": "internal"
146
143
  }
147
144
  },
148
- "required": [],
145
+ "required": ["directory"],
149
146
  "examplesFile": "../../../docs/application-examples.md"
150
147
  }
@@ -1,28 +1,10 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import type { SupportedStyles } from '@nx/react';
3
3
  interface Schema {
4
- name: string;
5
- /**
6
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20.
7
- */
8
- project?: string;
4
+ path: string;
5
+ name?: string;
9
6
  style: SupportedStyles;
10
- directory?: string;
11
- /**
12
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
13
- */
14
- flat?: boolean;
15
- /**
16
- * @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
17
- */
18
- pascalCaseFiles?: boolean;
19
- /**
20
- * @deprecated Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
21
- */
22
- pascalCaseDirectory?: boolean;
23
- nameAndDirectoryFormat?: 'as-provided' | 'derived';
24
7
  skipFormat?: boolean;
25
8
  }
26
- export declare function componentGenerator(host: Tree, schema: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
27
- export declare function componentGeneratorInternal(host: Tree, options: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
9
+ export declare function componentGenerator(host: Tree, options: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
28
10
  export default componentGenerator;
@@ -1,53 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentGenerator = componentGenerator;
4
- exports.componentGeneratorInternal = componentGeneratorInternal;
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const react_1 = require("@nx/react");
7
6
  const styles_1 = require("../../utils/styles");
8
7
  const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
9
- // TODO(v20): Remove this logic once we no longer derive directory.
10
- function maybeGetDerivedDirectory(host, options) {
11
- if (!options.project)
12
- return options.directory;
13
- const workspace = (0, devkit_1.getProjects)(host);
14
- const projectType = workspace.get(options.project).projectType;
15
- return options.directory
16
- ? options.directory
17
- : projectType === 'application'
18
- ? 'components'
19
- : undefined;
20
- }
21
- async function componentGenerator(host, schema) {
22
- return componentGeneratorInternal(host, {
23
- nameAndDirectoryFormat: 'derived',
24
- ...schema,
25
- });
26
- }
27
8
  /*
28
9
  * This schematic is basically the React one, but for Next we need
29
10
  * extra dependencies for css, sass, less style options.
30
11
  */
31
- async function componentGeneratorInternal(host, options) {
12
+ async function componentGenerator(host, options) {
32
13
  const { artifactName: name, directory, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
33
- artifactType: 'component',
34
- callingGenerator: '@nx/next:component',
35
14
  name: options.name,
36
- directory: options.directory,
37
- derivedDirectory: maybeGetDerivedDirectory(host, options),
38
- flat: options.flat,
39
- nameAndDirectoryFormat: options.nameAndDirectoryFormat,
40
- project: options.project,
15
+ path: options.path,
41
16
  fileExtension: 'tsx',
42
- pascalCaseFile: options.pascalCaseFiles,
43
- pascalCaseDirectory: options.pascalCaseDirectory,
44
17
  });
45
18
  const componentInstall = await (0, react_1.componentGenerator)(host, {
46
19
  ...options,
47
20
  name,
48
- nameAndDirectoryFormat: 'as-provided', // already determined the directory so use as is
49
- project: undefined,
50
- directory,
51
21
  classComponent: false,
52
22
  routing: false,
53
23
  skipFormat: true,
@@ -6,22 +6,19 @@
6
6
  "description": "Create a React Component for Next.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "project": {
9
+ "path": {
10
10
  "type": "string",
11
- "description": "The name of the project.",
12
- "alias": "p",
11
+ "description": "Path where the component will be generated.",
13
12
  "$default": {
14
- "$source": "projectName"
13
+ "$source": "argv",
14
+ "index": 0
15
15
  },
16
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20."
16
+ "x-prompt": "Where should the component be generated?",
17
+ "x-priority": "important"
17
18
  },
18
19
  "name": {
19
20
  "type": "string",
20
21
  "description": "The name of the component.",
21
- "$default": {
22
- "$source": "argv",
23
- "index": 0
24
- },
25
22
  "x-prompt": "What name would you like to use for the component?",
26
23
  "x-priority": "important"
27
24
  },
@@ -71,17 +68,6 @@
71
68
  "default": false,
72
69
  "x-priority": "internal"
73
70
  },
74
- "directory": {
75
- "type": "string",
76
- "description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
77
- "alias": "dir",
78
- "x-priority": "important"
79
- },
80
- "nameAndDirectoryFormat": {
81
- "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
82
- "type": "string",
83
- "enum": ["as-provided", "derived"]
84
- },
85
71
  "export": {
86
72
  "type": "boolean",
87
73
  "description": "When true, the component is exported from the project index.ts (if it exists).",
@@ -93,26 +79,6 @@
93
79
  "description": "Generate JavaScript files rather than TypeScript files.",
94
80
  "default": false
95
81
  },
96
- "flat": {
97
- "type": "boolean",
98
- "description": "Create component at the source root rather than its own directory.",
99
- "default": false,
100
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19."
101
- },
102
- "pascalCaseFiles": {
103
- "type": "boolean",
104
- "description": "Use pascal case component file name (e.g. `App.tsx`).",
105
- "alias": "P",
106
- "default": false,
107
- "x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
108
- },
109
- "pascalCaseDirectory": {
110
- "type": "boolean",
111
- "description": "Use pascal case directory name (e.g. `App/App.tsx`).",
112
- "alias": "R",
113
- "default": false,
114
- "x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
115
- },
116
82
  "skipFormat": {
117
83
  "description": "Skip formatting files.",
118
84
  "type": "boolean",
@@ -120,6 +86,6 @@
120
86
  "x-priority": "internal"
121
87
  }
122
88
  },
123
- "required": ["name"],
89
+ "required": ["path"],
124
90
  "examplesFile": "../../../docs/component-examples.md"
125
91
  }
@@ -4,15 +4,13 @@ exports.normalizeOptions = normalizeOptions;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
6
  async function normalizeOptions(host, options) {
7
- const { projectRoot, importPath, projectNameAndRootFormat } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
7
+ await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'library');
8
+ const { projectRoot, importPath } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
9
  name: options.name,
9
10
  projectType: 'library',
10
11
  directory: options.directory,
11
12
  importPath: options.importPath,
12
- projectNameAndRootFormat: options.projectNameAndRootFormat,
13
- callingGenerator: '@nx/next:library',
14
13
  });
15
- options.projectNameAndRootFormat = projectNameAndRootFormat;
16
14
  const nxJson = (0, devkit_1.readNxJson)(host);
17
15
  const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
18
16
  nxJson.useInferencePlugins !== false;
@@ -12,7 +12,6 @@ const versions_2 = require("../../utils/versions");
12
12
  async function libraryGenerator(host, rawOptions) {
13
13
  return await libraryGeneratorInternal(host, {
14
14
  addPlugin: false,
15
- projectNameAndRootFormat: 'derived',
16
15
  ...rawOptions,
17
16
  });
18
17
  }
@@ -1,16 +1,13 @@
1
- import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
1
  import type { Linter, LinterType } from '@nx/eslint';
3
2
  import type { SupportedStyles } from '@nx/react';
4
3
 
5
4
  export interface Schema {
6
- name: string;
7
- directory?: string;
8
- projectNameAndRootFormat?: ProjectNameAndRootFormat;
5
+ directory: string;
6
+ name?: string;
9
7
  style: SupportedStyles;
10
8
  skipTsConfig?: boolean;
11
9
  skipFormat?: boolean;
12
10
  tags?: string;
13
- pascalCaseFiles?: boolean;
14
11
  routing?: boolean;
15
12
  appProject?: string;
16
13
  unitTestRunner: 'jest' | 'vitest' | 'none';
@@ -6,28 +6,22 @@
6
6
  "description": "Create a React Library for an Nx workspace.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "name": {
9
+ "directory": {
10
10
  "type": "string",
11
- "description": "Library name",
11
+ "description": "A directory where the lib is placed.",
12
+ "alias": "dir",
12
13
  "$default": {
13
14
  "$source": "argv",
14
15
  "index": 0
15
16
  },
16
- "x-prompt": "What name would you like to use for the library?",
17
- "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$",
18
- "x-priority": "important"
17
+ "x-prompt": "Which directory do you want to create the library in?"
19
18
  },
20
- "directory": {
19
+ "name": {
21
20
  "type": "string",
22
- "description": "A directory where the lib is placed.",
23
- "alias": "dir",
21
+ "description": "Library name",
22
+ "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$",
24
23
  "x-priority": "important"
25
24
  },
26
- "projectNameAndRootFormat": {
27
- "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`).",
28
- "type": "string",
29
- "enum": ["as-provided", "derived"]
30
- },
31
25
  "style": {
32
26
  "description": "The file extension to be used for style files.",
33
27
  "type": "string",
@@ -37,7 +31,10 @@
37
31
  "message": "Which stylesheet format would you like to use?",
38
32
  "type": "list",
39
33
  "items": [
40
- { "value": "css", "label": "CSS" },
34
+ {
35
+ "value": "css",
36
+ "label": "CSS"
37
+ },
41
38
  {
42
39
  "value": "scss",
43
40
  "label": "SASS(.scss) [ https://sass-lang.com ]"
@@ -73,8 +70,9 @@
73
70
  },
74
71
  "unitTestRunner": {
75
72
  "type": "string",
76
- "enum": ["jest", "vitest", "none"],
77
- "description": "Test runner to use for unit tests."
73
+ "enum": ["vitest", "jest", "none"],
74
+ "description": "Test runner to use for unit tests.",
75
+ "default": "vitest"
78
76
  },
79
77
  "tags": {
80
78
  "type": "string",
@@ -91,12 +89,6 @@
91
89
  "default": false,
92
90
  "description": "Do not update tsconfig.json for development experience."
93
91
  },
94
- "pascalCaseFiles": {
95
- "type": "boolean",
96
- "description": "Use pascal case component file name (e.g. `App.tsx`).",
97
- "alias": "P",
98
- "default": false
99
- },
100
92
  "routing": {
101
93
  "type": "boolean",
102
94
  "description": "Generate library with routes."
@@ -151,6 +143,6 @@
151
143
  "x-priority": "internal"
152
144
  }
153
145
  },
154
- "required": ["name"],
146
+ "required": ["directory"],
155
147
  "examplesFile": "../../../docs/library-examples.md"
156
148
  }
@@ -1,5 +1,4 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
3
  export declare function pageGenerator(host: Tree, schema: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
4
- export declare function pageGeneratorInternal(host: Tree, schema: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
5
4
  export default pageGenerator;
@@ -1,28 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pageGenerator = pageGenerator;
4
- exports.pageGeneratorInternal = pageGeneratorInternal;
5
4
  const react_1 = require("@nx/react");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const styles_1 = require("../../utils/styles");
8
7
  const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
9
- async function pageGenerator(host, schema) {
10
- return pageGeneratorInternal(host, {
11
- nameAndDirectoryFormat: 'derived',
12
- ...schema,
13
- });
14
- }
15
8
  /*
16
9
  * This schematic is basically the React component one, but for Next we need
17
10
  * extra dependencies for css, sass, less style options, and make sure
18
11
  * it is under `pages` folder.
19
12
  */
20
- async function pageGeneratorInternal(host, schema) {
13
+ async function pageGenerator(host, schema) {
21
14
  const options = await normalizeOptions(host, schema);
22
15
  const componentTask = await (0, react_1.componentGenerator)(host, {
23
16
  ...options,
24
17
  isNextPage: true,
25
- nameAndDirectoryFormat: 'as-provided', // already determined the directory so use as is
26
18
  export: false,
27
19
  classComponent: false,
28
20
  routing: false,
@@ -40,54 +32,23 @@ async function pageGeneratorInternal(host, schema) {
40
32
  return (0, devkit_1.runTasksInSerial)(componentTask, styledTask);
41
33
  }
42
34
  async function normalizeOptions(host, options) {
43
- let isAppRouter;
44
- let derivedDirectory;
45
- let routerDirectory;
46
- if (options.project) {
47
- // Legacy behavior, detect app vs page router from specified project.
48
- // TODO(v20): remove this logic
49
- const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
50
- // app/ is a reserved folder in nextjs so it is safe to check it's existence
51
- isAppRouter =
52
- host.exists(`${project.root}/app`) ||
53
- host.exists(`${project.root}/src/app`);
54
- routerDirectory = isAppRouter ? 'app' : 'pages';
55
- derivedDirectory = options.directory
56
- ? `${routerDirectory}/${options.directory}`
57
- : `${routerDirectory}`;
58
- }
59
- else {
60
- // Get the project name first so we can determine the router directory
61
- const { project: determinedProjectName } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
62
- artifactType: 'page',
63
- callingGenerator: '@nx/next:page',
64
- name: options.name,
65
- directory: options.directory,
66
- });
67
- const project = (0, devkit_1.readProjectConfiguration)(host, determinedProjectName);
68
- // app/ is a reserved folder in nextjs so it is safe to check it's existence
69
- isAppRouter =
70
- host.exists(`${project.root}/app`) ||
71
- host.exists(`${project.root}/src/app`);
72
- routerDirectory = isAppRouter ? 'app' : 'pages';
73
- // New behavior, use directory as is without detecting whether we're using app or pages router.
74
- derivedDirectory = options.directory;
75
- }
76
- const { artifactName: name, project: projectName, fileName, directory, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
77
- artifactType: 'page',
78
- callingGenerator: '@nx/next:page',
35
+ // Get the project name first so we can determine the router directory
36
+ const { project: determinedProjectName } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
37
+ name: options.name,
38
+ path: options.path,
39
+ });
40
+ const project = (0, devkit_1.readProjectConfiguration)(host, determinedProjectName);
41
+ // app/ is a reserved folder in nextjs so it is safe to check it's existence
42
+ const isAppRouter = host.exists(`${project.root}/app`) ||
43
+ host.exists(`${project.root}/src/app`);
44
+ const { project: projectName, fileName } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
79
45
  name: options.name,
80
46
  fileName: isAppRouter ? 'page' : 'index',
81
- directory: options.directory,
82
- derivedDirectory,
83
- flat: options.flat,
84
- nameAndDirectoryFormat: options.nameAndDirectoryFormat,
85
- project: options.project,
47
+ path: options.path,
86
48
  fileExtension: 'tsx',
87
49
  });
88
50
  return {
89
51
  ...options,
90
- directory,
91
52
  fileName,
92
53
  projectName,
93
54
  };
@@ -1,20 +1,12 @@
1
+ import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
1
2
  import { SupportedStyles } from '@nx/react';
2
3
 
3
4
  export interface Schema {
4
- name: string;
5
- /**
6
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20.
7
- */
8
- project?: string;
5
+ path: string;
6
+ name?: string;
9
7
  style: SupportedStyles;
10
- directory?: string;
11
8
  fileName?: string;
12
9
  withTests?: boolean;
13
10
  js?: boolean;
14
- /**
15
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
16
- */
17
- flat?: boolean;
18
11
  skipFormat?: boolean;
19
- nameAndDirectoryFormat?: 'as-provided' | 'derived';
20
12
  }
@@ -6,36 +6,22 @@
6
6
  "description": "Create a Page for Next.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "project": {
9
+ "path": {
10
10
  "type": "string",
11
- "description": "The name of the project.",
12
- "alias": "p",
13
- "$default": {
14
- "$source": "projectName"
15
- },
16
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20."
17
- },
18
- "name": {
19
- "type": "string",
20
- "description": "The name of the component.",
11
+ "description": "Path where the page will be generated.",
21
12
  "$default": {
22
13
  "$source": "argv",
23
14
  "index": 0
24
15
  },
25
- "x-prompt": "What name would you like to use for the component?",
16
+ "x-prompt": "Where should the page be generated?",
26
17
  "x-priority": "important"
27
18
  },
28
- "directory": {
19
+ "name": {
29
20
  "type": "string",
30
- "description": "The directory at which to create the page file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
31
- "alias": "dir",
21
+ "description": "The name of the page.",
22
+ "x-prompt": "What name would you like to use for the page?",
32
23
  "x-priority": "important"
33
24
  },
34
- "nameAndDirectoryFormat": {
35
- "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
36
- "type": "string",
37
- "enum": ["as-provided", "derived"]
38
- },
39
25
  "style": {
40
26
  "description": "The file extension to be used for style files.",
41
27
  "type": "string",
@@ -106,6 +92,6 @@
106
92
  "x-priority": "internal"
107
93
  }
108
94
  },
109
- "required": ["name"],
95
+ "required": ["path"],
110
96
  "examplesFile": "../../../docs/page-examples.md"
111
97
  }