@nx/next 17.0.0-beta.6 → 17.0.0-beta.8

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#pageGenerator",
20
+ "factory": "./src/generators/page/page#pageGeneratorInternal",
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#componentGenerator",
25
+ "factory": "./src/generators/component/component#componentGeneratorInternal",
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": "17.0.0-beta.6",
3
+ "version": "17.0.0-beta.8",
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, Cypress, and Jest. No need to configure anything: watch mode, source maps, and typings just work.",
6
6
  "repository": {
@@ -44,13 +44,13 @@
44
44
  "url-loader": "^4.1.1",
45
45
  "tslib": "^2.3.0",
46
46
  "webpack-merge": "^5.8.0",
47
- "@nx/devkit": "17.0.0-beta.6",
48
- "@nx/js": "17.0.0-beta.6",
49
- "@nx/linter": "17.0.0-beta.6",
50
- "@nx/react": "17.0.0-beta.6",
51
- "@nx/web": "17.0.0-beta.6",
52
- "@nx/workspace": "17.0.0-beta.6",
53
- "@nrwl/next": "17.0.0-beta.6"
47
+ "@nx/devkit": "17.0.0-beta.8",
48
+ "@nx/js": "17.0.0-beta.8",
49
+ "@nx/eslint": "17.0.0-beta.8",
50
+ "@nx/react": "17.0.0-beta.8",
51
+ "@nx/web": "17.0.0-beta.8",
52
+ "@nx/workspace": "17.0.0-beta.8",
53
+ "@nrwl/next": "17.0.0-beta.8"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addE2e = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const linter_1 = require("@nx/linter");
5
+ const eslint_1 = require("@nx/eslint");
6
6
  const versions_1 = require("../../../utils/versions");
7
7
  async function addE2e(host, options) {
8
8
  if (options.e2eTestRunner === 'cypress') {
9
9
  const { cypressProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
10
10
  return cypressProjectGenerator(host, {
11
11
  ...options,
12
- linter: linter_1.Linter.EsLint,
12
+ linter: eslint_1.Linter.EsLint,
13
13
  name: options.e2eProjectName,
14
14
  directory: options.e2eProjectRoot,
15
15
  // the name and root are already normalized, instruct the generator to use them as is
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addLinting = void 0;
4
- const linter_1 = require("@nx/linter");
4
+ const eslint_1 = require("@nx/eslint");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const lint_1 = require("@nx/react/src/utils/lint");
7
- const eslint_file_1 = require("@nx/linter/src/generators/utils/eslint-file");
8
- const lint_project_1 = require("@nx/linter/src/generators/lint-project/lint-project");
7
+ const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
8
+ const lint_project_1 = require("@nx/eslint/src/generators/lint-project/lint-project");
9
9
  async function addLinting(host, options) {
10
- const lintTask = await (0, linter_1.lintProjectGenerator)(host, {
10
+ const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
11
11
  linter: options.linter,
12
12
  project: options.projectName,
13
13
  tsConfigPaths: [
@@ -20,7 +20,7 @@ async function addLinting(host, options) {
20
20
  skipFormat: true,
21
21
  rootProject: options.rootProject,
22
22
  });
23
- if (options.linter === linter_1.Linter.EsLint && (0, eslint_file_1.isEslintConfigSupported)(host)) {
23
+ if (options.linter === eslint_1.Linter.EsLint && (0, eslint_file_1.isEslintConfigSupported)(host)) {
24
24
  (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, [
25
25
  'plugin:@nx/react-typescript',
26
26
  'next',
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
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
- const linter_1 = require("@nx/linter");
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
9
  const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
@@ -37,7 +37,7 @@ async function normalizeOptions(host, options) {
37
37
  e2eProjectRoot,
38
38
  e2eTestRunner: options.e2eTestRunner || 'cypress',
39
39
  fileName,
40
- linter: options.linter || linter_1.Linter.EsLint,
40
+ linter: options.linter || eslint_1.Linter.EsLint,
41
41
  name,
42
42
  outputPath,
43
43
  parsedTags,
@@ -1,5 +1,5 @@
1
1
  import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
- import type { Linter } from '@nx/linter';
2
+ import type { Linter } from '@nx/eslint';
3
3
  import type { SupportedStyles } from '@nx/react';
4
4
 
5
5
  export interface Schema {
@@ -2,13 +2,27 @@ import { Tree } from '@nx/devkit';
2
2
  import type { SupportedStyles } from '@nx/react';
3
3
  interface Schema {
4
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 v18.
7
+ */
5
8
  project: string;
6
9
  style: SupportedStyles;
7
10
  directory?: string;
11
+ /**
12
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18.
13
+ */
8
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 v18.
17
+ */
9
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 v18.
21
+ */
10
22
  pascalCaseDirectory?: boolean;
23
+ nameAndDirectoryFormat?: 'as-provided' | 'derived';
11
24
  skipFormat?: boolean;
12
25
  }
13
- export declare function componentGenerator(host: Tree, options: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
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>;
14
28
  export default componentGenerator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.componentGenerator = void 0;
3
+ exports.componentGeneratorInternal = exports.componentGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const react_1 = require("@nx/react");
6
6
  const styles_1 = require("../../utils/styles");
@@ -13,15 +13,23 @@ function getDirectory(host, options) {
13
13
  ? 'components'
14
14
  : undefined;
15
15
  }
16
+ async function componentGenerator(host, schema) {
17
+ return componentGeneratorInternal(host, {
18
+ nameAndDirectoryFormat: 'derived',
19
+ ...schema,
20
+ });
21
+ }
22
+ exports.componentGenerator = componentGenerator;
16
23
  /*
17
24
  * This schematic is basically the React one, but for Next we need
18
25
  * extra dependencies for css, sass, less style options.
19
26
  */
20
- async function componentGenerator(host, options) {
27
+ async function componentGeneratorInternal(host, options) {
21
28
  const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
22
29
  const componentInstall = await (0, react_1.componentGenerator)(host, {
23
30
  ...options,
24
- directory: getDirectory(host, options),
31
+ directory: options.directory,
32
+ derivedDirectory: getDirectory(host, options),
25
33
  classComponent: false,
26
34
  routing: false,
27
35
  skipFormat: true,
@@ -35,5 +43,5 @@ async function componentGenerator(host, options) {
35
43
  }
36
44
  return (0, devkit_1.runTasksInSerial)(styledInstall, componentInstall);
37
45
  }
38
- exports.componentGenerator = componentGenerator;
46
+ exports.componentGeneratorInternal = componentGeneratorInternal;
39
47
  exports.default = componentGenerator;
@@ -13,8 +13,7 @@
13
13
  "$default": {
14
14
  "$source": "projectName"
15
15
  },
16
- "x-prompt": "What is the name of the project for this component?",
17
- "x-priority": "important"
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 v18."
18
17
  },
19
18
  "name": {
20
19
  "type": "string",
@@ -35,7 +34,10 @@
35
34
  "message": "Which stylesheet format would you like to use?",
36
35
  "type": "list",
37
36
  "items": [
38
- { "value": "css", "label": "CSS" },
37
+ {
38
+ "value": "css",
39
+ "label": "CSS"
40
+ },
39
41
  {
40
42
  "value": "scss",
41
43
  "label": "SASS(.scss) [ http://sass-lang.com ]"
@@ -71,10 +73,15 @@
71
73
  },
72
74
  "directory": {
73
75
  "type": "string",
74
- "description": "Create the component under this directory (can be nested).",
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.",
75
77
  "alias": "dir",
76
78
  "x-priority": "important"
77
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
+ },
78
85
  "export": {
79
86
  "type": "boolean",
80
87
  "description": "When true, the component is exported from the project index.ts (if it exists).",
@@ -89,19 +96,22 @@
89
96
  "flat": {
90
97
  "type": "boolean",
91
98
  "description": "Create component at the source root rather than its own directory.",
92
- "default": false
99
+ "default": false,
100
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18."
93
101
  },
94
102
  "pascalCaseFiles": {
95
103
  "type": "boolean",
96
104
  "description": "Use pascal case component file name (e.g. `App.tsx`).",
97
105
  "alias": "P",
98
- "default": false
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 v18."
99
108
  },
100
109
  "pascalCaseDirectory": {
101
110
  "type": "boolean",
102
111
  "description": "Use pascal case directory name (e.g. `App/App.tsx`).",
103
112
  "alias": "R",
104
- "default": false
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 v18."
105
115
  },
106
116
  "skipFormat": {
107
117
  "description": "Skip formatting files.",
@@ -110,6 +120,6 @@
110
120
  "x-priority": "internal"
111
121
  }
112
122
  },
113
- "required": ["name", "project"],
123
+ "required": ["name"],
114
124
  "examplesFile": "../../../docs/component-examples.md"
115
125
  }
@@ -1,5 +1,5 @@
1
1
  import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-directory-utils';
2
- import type { Linter } from '@nx/linter';
2
+ import type { Linter } from '@nx/eslint';
3
3
  import type { SupportedStyles } from '@nx/react';
4
4
 
5
5
  export interface Schema {
@@ -1,4 +1,5 @@
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>;
4
5
  export default pageGenerator;
@@ -1,16 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pageGenerator = void 0;
3
+ exports.pageGeneratorInternal = exports.pageGenerator = void 0;
4
4
  const react_1 = require("@nx/react");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const styles_1 = require("../../utils/styles");
7
+ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
8
+ async function pageGenerator(host, schema) {
9
+ return pageGeneratorInternal(host, {
10
+ nameAndDirectoryFormat: 'derived',
11
+ ...schema,
12
+ });
13
+ }
14
+ exports.pageGenerator = pageGenerator;
7
15
  /*
8
16
  * This schematic is basically the React component one, but for Next we need
9
17
  * extra dependencies for css, sass, less style options, and make sure
10
18
  * it is under `pages` folder.
11
19
  */
12
- async function pageGenerator(host, schema) {
13
- const options = normalizeOptions(host, schema);
20
+ async function pageGeneratorInternal(host, schema) {
21
+ const options = await normalizeOptions(host, schema);
14
22
  const componentTask = await (0, react_1.componentGenerator)(host, {
15
23
  ...options,
16
24
  project: schema.project,
@@ -22,25 +30,63 @@ async function pageGenerator(host, schema) {
22
30
  flat: !!options.flat,
23
31
  skipFormat: true,
24
32
  });
33
+ const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
25
34
  const styledTask = (0, styles_1.addStyleDependencies)(host, {
26
35
  style: options.style,
27
- swc: !host.exists((0, devkit_1.joinPathFragments)(options.project.root, '.babelrc')),
36
+ swc: !host.exists((0, devkit_1.joinPathFragments)(project.root, '.babelrc')),
28
37
  });
29
38
  if (!options.skipFormat) {
30
39
  await (0, devkit_1.formatFiles)(host);
31
40
  }
32
41
  return (0, devkit_1.runTasksInSerial)(componentTask, styledTask);
33
42
  }
34
- exports.pageGenerator = pageGenerator;
35
- function normalizeOptions(host, options) {
36
- const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
37
- // app/ is a reserved folder in nextjs so it is safe to check it's existence
38
- const isAppRouter = host.exists(`${project.root}/app`);
43
+ exports.pageGeneratorInternal = pageGeneratorInternal;
44
+ async function normalizeOptions(host, options) {
45
+ let isAppRouter;
46
+ if (options.project) {
47
+ // Legacy behavior, detect app vs page router from specified project.
48
+ const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
49
+ // app/ is a reserved folder in nextjs so it is safe to check it's existence
50
+ isAppRouter = host.exists(`${project.root}/app`);
51
+ }
52
+ else {
53
+ // New behavior, detect app vs page router from the positional arg or directory path
54
+ const parts = options.name.includes('/') || // mac, linux
55
+ options.name.includes('\\') // windows
56
+ ? options.name.split(/[\/\\]/)
57
+ : options.directory.split(/[\/\\]/);
58
+ if (parts.includes('pages')) {
59
+ isAppRouter = false;
60
+ }
61
+ else if (parts.includes('app')) {
62
+ isAppRouter = true;
63
+ }
64
+ else {
65
+ }
66
+ }
67
+ const { artifactName: name, project: projectName, filePath, fileName, nameAndDirectoryFormat, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
68
+ artifactType: 'component',
69
+ callingGenerator: '@nx/react:component',
70
+ name: options.name,
71
+ fileName: isAppRouter ? 'page' : 'index',
72
+ directory: options.directory,
73
+ derivedDirectory: options.directory,
74
+ flat: options.flat,
75
+ nameAndDirectoryFormat: options.nameAndDirectoryFormat,
76
+ project: options.project,
77
+ fileExtension: 'tsx',
78
+ });
39
79
  const routerDirectory = isAppRouter ? 'app' : 'pages';
40
- const directory = options.directory
80
+ const derivedDirectory = options.directory
41
81
  ? `${routerDirectory}/${options.directory}`
42
82
  : `${routerDirectory}`;
43
- const fileName = isAppRouter ? 'page' : !options.flat ? 'index' : undefined;
44
- return { ...options, project, directory, fileName };
83
+ return {
84
+ ...options,
85
+ fileName,
86
+ projectName,
87
+ derivedDirectory,
88
+ filePath,
89
+ nameAndDirectoryFormat,
90
+ };
45
91
  }
46
92
  exports.default = pageGenerator;
@@ -2,12 +2,19 @@ import { SupportedStyles } from '@nx/react';
2
2
 
3
3
  export interface Schema {
4
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 v18.
7
+ */
5
8
  project: string;
6
9
  style: SupportedStyles;
7
10
  directory?: string;
8
11
  fileName?: string;
9
12
  withTests?: boolean;
10
13
  js?: boolean;
14
+ /**
15
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18.
16
+ */
11
17
  flat?: boolean;
12
18
  skipFormat?: boolean;
19
+ nameAndDirectoryFormat?: 'as-provided' | 'derived';
13
20
  }
@@ -13,8 +13,7 @@
13
13
  "$default": {
14
14
  "$source": "projectName"
15
15
  },
16
- "x-prompt": "What is the name of the project for this component?",
17
- "x-priority": "important"
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 v18."
18
17
  },
19
18
  "name": {
20
19
  "type": "string",
@@ -28,10 +27,15 @@
28
27
  },
29
28
  "directory": {
30
29
  "type": "string",
31
- "description": "Create the page under this directory (can be nested). Will be created under `pages/`.",
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.",
32
31
  "alias": "dir",
33
32
  "x-priority": "important"
34
33
  },
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
+ },
35
39
  "style": {
36
40
  "description": "The file extension to be used for style files.",
37
41
  "type": "string",
@@ -41,7 +45,10 @@
41
45
  "message": "Which stylesheet format would you like to use?",
42
46
  "type": "list",
43
47
  "items": [
44
- { "value": "css", "label": "CSS" },
48
+ {
49
+ "value": "css",
50
+ "label": "CSS"
51
+ },
45
52
  {
46
53
  "value": "scss",
47
54
  "label": "SASS(.scss) [ http://sass-lang.com ]"
@@ -89,7 +96,8 @@
89
96
  "flat": {
90
97
  "type": "boolean",
91
98
  "description": "Create component at the source root rather than its own directory.",
92
- "default": false
99
+ "default": false,
100
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
93
101
  },
94
102
  "skipFormat": {
95
103
  "description": "Skip formatting files.",
@@ -98,6 +106,6 @@
98
106
  "x-priority": "internal"
99
107
  }
100
108
  },
101
- "required": ["name", "project"],
109
+ "required": ["name"],
102
110
  "examplesFile": "../../../docs/page-examples.md"
103
111
  }