@nx/next 17.0.4 → 17.0.6

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.
Files changed (73) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/generators.json +2 -2
  4. package/migrations.json +0 -24
  5. package/package.json +10 -12
  6. package/plugins/component-testing.d.ts +11 -1
  7. package/plugins/component-testing.js +10 -26
  8. package/plugins/with-nx.d.ts +1 -1
  9. package/plugins/with-nx.js +86 -68
  10. package/plugins/with-stylus.js +1 -1
  11. package/src/executors/build/build.impl.js +9 -20
  12. package/src/executors/build/lib/create-next-config-file.js +2 -5
  13. package/src/executors/build/lib/test-fixtures/ensure-exts/baz.json +0 -1
  14. package/src/executors/build/lib/update-package-json.js +1 -10
  15. package/src/executors/build/schema.json +1 -1
  16. package/src/executors/export/export.impl.js +9 -9
  17. package/src/executors/server/custom-server.impl.js +2 -3
  18. package/src/executors/server/schema.json +0 -4
  19. package/src/executors/server/server.impl.js +11 -13
  20. package/src/generators/application/application.js +0 -24
  21. package/src/generators/application/files/app/page.tsx__tmpl__ +1 -1
  22. package/src/generators/application/files/common/specs/__fileName__.spec.tsx__tmpl__ +3 -10
  23. package/src/generators/application/files/common/tsconfig.json__tmpl__ +5 -5
  24. package/src/generators/application/files/pages/__fileName__.tsx__tmpl__ +1 -1
  25. package/src/generators/application/lib/add-e2e.js +3 -27
  26. package/src/generators/application/lib/add-linting.js +16 -13
  27. package/src/generators/application/lib/add-project.js +33 -43
  28. package/src/generators/application/lib/create-application-files.helpers.js +5 -67
  29. package/src/generators/application/lib/create-application-files.js +11 -23
  30. package/src/generators/application/lib/normalize-options.d.ts +0 -3
  31. package/src/generators/application/lib/normalize-options.js +0 -31
  32. package/src/generators/application/schema.d.ts +0 -2
  33. package/src/generators/application/schema.json +3 -9
  34. package/src/generators/component/component.d.ts +4 -4
  35. package/src/generators/component/component.js +2 -3
  36. package/src/generators/component/schema.json +7 -7
  37. package/src/generators/custom-server/custom-server.d.ts +1 -1
  38. package/src/generators/custom-server/custom-server.js +9 -34
  39. package/src/generators/custom-server/files/server/main.ts__tmpl__ +4 -4
  40. package/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +0 -2
  41. package/src/generators/custom-server/schema.json +1 -1
  42. package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +0 -1
  43. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +10 -23
  44. package/src/generators/cypress-component-configuration/schema.d.ts +0 -1
  45. package/src/generators/cypress-component-configuration/schema.json +1 -1
  46. package/src/generators/init/init.d.ts +3 -4
  47. package/src/generators/init/init.js +44 -30
  48. package/src/generators/init/schema.d.ts +4 -3
  49. package/src/generators/init/schema.json +23 -11
  50. package/src/generators/library/lib/normalize-options.js +0 -5
  51. package/src/generators/library/library.js +1 -19
  52. package/src/generators/library/schema.d.ts +1 -2
  53. package/src/generators/library/schema.json +3 -3
  54. package/src/generators/page/page.js +4 -21
  55. package/src/generators/page/schema.d.ts +3 -3
  56. package/src/generators/page/schema.json +5 -5
  57. package/src/utils/add-gitignore-entry.js +1 -1
  58. package/src/utils/styles.d.ts +4 -4
  59. package/src/utils/types.d.ts +0 -1
  60. package/src/utils/versions.d.ts +2 -6
  61. package/src/utils/versions.js +3 -7
  62. package/plugin.d.ts +0 -1
  63. package/plugin.js +0 -5
  64. package/src/generators/application/lib/add-plugin.d.ts +0 -2
  65. package/src/generators/application/lib/add-plugin.js +0 -25
  66. package/src/generators/init/lib/add-plugin.d.ts +0 -2
  67. package/src/generators/init/lib/add-plugin.js +0 -26
  68. package/src/migrations/update-17-2-7/remove-eslint-rules-patch.d.ts +0 -2
  69. package/src/migrations/update-17-2-7/remove-eslint-rules-patch.js +0 -15
  70. package/src/plugins/plugin.d.ts +0 -11
  71. package/src/plugins/plugin.js +0 -184
  72. package/src/utils/add-swc-to-custom-server.d.ts +0 -2
  73. package/src/utils/add-swc-to-custom-server.js +0 -37
@@ -16,34 +16,8 @@ async function normalizeOptions(host, options) {
16
16
  });
17
17
  options.rootProject = appProjectRoot === '.';
18
18
  options.projectNameAndRootFormat = projectNameAndRootFormat;
19
- const nxJson = (0, devkit_1.readNxJson)(host);
20
- const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
21
- nxJson.useInferencePlugins !== false;
22
- options.addPlugin ??= addPlugin;
23
- let e2eWebServerTarget = options.addPlugin ? 'start' : 'serve';
24
- if (options.addPlugin) {
25
- if (nxJson.plugins) {
26
- for (const plugin of nxJson.plugins) {
27
- if (typeof plugin === 'object' &&
28
- plugin.plugin === '@nx/next/plugin' &&
29
- plugin.options.startTargetName) {
30
- e2eWebServerTarget = plugin.options
31
- .startTargetName;
32
- }
33
- }
34
- }
35
- }
36
- let e2ePort = options.addPlugin ? 3000 : 4200;
37
- if (nxJson.targetDefaults?.[e2eWebServerTarget] &&
38
- (nxJson.targetDefaults?.[e2eWebServerTarget].options?.port ||
39
- nxJson.targetDefaults?.[e2eWebServerTarget].options?.env?.PORT)) {
40
- e2ePort =
41
- nxJson.targetDefaults?.[e2eWebServerTarget].options?.port ||
42
- nxJson.targetDefaults?.[e2eWebServerTarget].options?.env?.PORT;
43
- }
44
19
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
45
20
  const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
46
- const e2eWebServerAddress = `http://localhost:${e2ePort}`;
47
21
  const name = (0, devkit_1.names)(options.name).fileName;
48
22
  const outputPath = (0, devkit_1.joinPathFragments)('dist', appProjectRoot, ...(options.rootProject ? [name] : []));
49
23
  const parsedTags = options.tags
@@ -51,7 +25,6 @@ async function normalizeOptions(host, options) {
51
25
  : [];
52
26
  const fileName = 'index';
53
27
  const appDir = options.appDir ?? true;
54
- const src = options.src ?? true;
55
28
  const styledModule = /^(css|scss|less)$/.test(options.style)
56
29
  ? null
57
30
  : options.style;
@@ -59,13 +32,9 @@ async function normalizeOptions(host, options) {
59
32
  return {
60
33
  ...options,
61
34
  appDir,
62
- src,
63
35
  appProjectRoot,
64
36
  e2eProjectName,
65
37
  e2eProjectRoot,
66
- e2eWebServerAddress,
67
- e2eWebServerTarget,
68
- e2ePort,
69
38
  e2eTestRunner: options.e2eTestRunner || 'cypress',
70
39
  fileName,
71
40
  linter: options.linter || eslint_1.Linter.EsLint,
@@ -18,7 +18,5 @@ export interface Schema {
18
18
  customServer?: boolean;
19
19
  skipPackageJson?: boolean;
20
20
  appDir?: boolean;
21
- src?: boolean;
22
21
  rootProject?: boolean;
23
- addPlugin?: boolean;
24
22
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxNextApp",
5
5
  "title": "Create a Next.js Application for Nx",
@@ -40,11 +40,11 @@
40
40
  { "value": "css", "label": "CSS" },
41
41
  {
42
42
  "value": "scss",
43
- "label": "SASS(.scss) [ https://sass-lang.com ]"
43
+ "label": "SASS(.scss) [ http://sass-lang.com ]"
44
44
  },
45
45
  {
46
46
  "value": "less",
47
- "label": "LESS [ https://lesscss.org ]"
47
+ "label": "LESS [ http://lesscss.org ]"
48
48
  },
49
49
  {
50
50
  "value": "styled-components",
@@ -127,12 +127,6 @@
127
127
  "description": "Enable the App Router for this project.",
128
128
  "x-prompt": "Would you like to use the App Router (recommended)?"
129
129
  },
130
- "src": {
131
- "type": "boolean",
132
- "default": true,
133
- "description": "Generate a `src` directory for the project.",
134
- "x-prompt": "Would you like to use `src/` directory?"
135
- },
136
130
  "rootProject": {
137
131
  "description": "Create an application at the root of the workspace.",
138
132
  "type": "boolean",
@@ -3,21 +3,21 @@ import type { SupportedStyles } from '@nx/react';
3
3
  interface Schema {
4
4
  name: string;
5
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 v19.
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
7
  */
8
8
  project?: string;
9
9
  style: SupportedStyles;
10
10
  directory?: string;
11
11
  /**
12
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
12
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18.
13
13
  */
14
14
  flat?: boolean;
15
15
  /**
16
- * @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
16
+ * @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v18.
17
17
  */
18
18
  pascalCaseFiles?: boolean;
19
19
  /**
20
- * @deprecated Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
20
+ * @deprecated Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v18.
21
21
  */
22
22
  pascalCaseDirectory?: boolean;
23
23
  nameAndDirectoryFormat?: 'as-provided' | 'derived';
@@ -5,7 +5,7 @@ const devkit_1 = require("@nx/devkit");
5
5
  const react_1 = require("@nx/react");
6
6
  const styles_1 = require("../../utils/styles");
7
7
  const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
8
- // TODO(v19): Remove this logic once we no longer derive directory.
8
+ // TODO(v18): Remove this logic once we no longer derive directory.
9
9
  function maybeGetDerivedDirectory(host, options) {
10
10
  if (!options.project)
11
11
  return options.directory;
@@ -44,8 +44,7 @@ async function componentGeneratorInternal(host, options) {
44
44
  });
45
45
  const componentInstall = await (0, react_1.componentGenerator)(host, {
46
46
  ...options,
47
- name,
48
- nameAndDirectoryFormat: 'as-provided', // already determined the directory so use as is
47
+ nameAndDirectoryFormat: 'as-provided',
49
48
  project: undefined,
50
49
  directory,
51
50
  classComponent: false,
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxNextReactComponent",
5
5
  "title": "Create a React Component for Next",
@@ -13,7 +13,7 @@
13
13
  "$default": {
14
14
  "$source": "projectName"
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 v19."
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."
17
17
  },
18
18
  "name": {
19
19
  "type": "string",
@@ -40,11 +40,11 @@
40
40
  },
41
41
  {
42
42
  "value": "scss",
43
- "label": "SASS(.scss) [ https://sass-lang.com ]"
43
+ "label": "SASS(.scss) [ http://sass-lang.com ]"
44
44
  },
45
45
  {
46
46
  "value": "less",
47
- "label": "LESS [ https://lesscss.org ]"
47
+ "label": "LESS [ http://lesscss.org ]"
48
48
  },
49
49
  {
50
50
  "value": "styled-components",
@@ -97,21 +97,21 @@
97
97
  "type": "boolean",
98
98
  "description": "Create component at the source root rather than its own directory.",
99
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."
100
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18."
101
101
  },
102
102
  "pascalCaseFiles": {
103
103
  "type": "boolean",
104
104
  "description": "Use pascal case component file name (e.g. `App.tsx`).",
105
105
  "alias": "P",
106
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."
107
+ "x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v18."
108
108
  },
109
109
  "pascalCaseDirectory": {
110
110
  "type": "boolean",
111
111
  "description": "Use pascal case directory name (e.g. `App/App.tsx`).",
112
112
  "alias": "R",
113
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."
114
+ "x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v18."
115
115
  },
116
116
  "skipFormat": {
117
117
  "description": "Skip formatting files.",
@@ -1,3 +1,3 @@
1
1
  import type { Tree } from '@nx/devkit';
2
2
  import { CustomServerSchema } from './schema';
3
- export declare function customServerGenerator(host: Tree, options: CustomServerSchema): Promise<() => void>;
3
+ export declare function customServerGenerator(host: Tree, options: CustomServerSchema): Promise<void>;
@@ -3,29 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.customServerGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const path_1 = require("path");
6
- const add_swc_to_custom_server_1 = require("../../utils/add-swc-to-custom-server");
7
6
  async function customServerGenerator(host, options) {
8
7
  const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
9
- const nxJson = (0, devkit_1.readNxJson)(host);
10
- const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
11
- ? p === '@nx/next/plugin'
12
- : p.plugin === '@nx/next/plugin');
13
8
  if (project.targets?.build?.executor !== '@nx/next:build' &&
14
- project.targets?.build?.executor !== '@nrwl/next:build' &&
15
- !hasPlugin) {
9
+ project.targets?.build?.executor !== '@nrwl/next:build') {
16
10
  devkit_1.logger.error(`Project ${options.project} is not a Next.js project. Did you generate it with "nx g @nx/next:app"?`);
17
11
  return;
18
12
  }
19
- // In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
20
- const outputPath = hasPlugin
21
- ? `dist/${project.root}`
22
- : project.targets?.build?.options?.outputPath;
13
+ const outputPath = project.targets?.build?.options?.outputPath;
23
14
  const root = project.root;
24
- if ((!root ||
15
+ if (!root ||
25
16
  !outputPath ||
26
17
  !project.targets?.build?.configurations?.development ||
27
- !project.targets?.build?.configurations?.production) &&
28
- !hasPlugin) {
18
+ !project.targets?.build?.configurations?.production) {
29
19
  devkit_1.logger.error(`Project ${options.project} has invalid config. Did you generate it with "nx g @nx/next:app"?`);
30
20
  return;
31
21
  }
@@ -34,30 +24,18 @@ async function customServerGenerator(host, options) {
34
24
  devkit_1.logger.warn(`Project ${options.project} has custom server targets already: build-custom-server, serve-custom-server. Remove these targets from project and try again.`);
35
25
  return;
36
26
  }
37
- // In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
38
- // So we need ensure the mapping is correct from dist to the project root
39
- const projectPathFromDist = `../../${(0, devkit_1.offsetFromRoot)(project.root)}${project.root}`;
40
27
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files'), project.root, {
41
28
  ...options,
42
- hasPlugin,
43
- projectPathFromDist,
44
29
  offsetFromRoot: (0, devkit_1.offsetFromRoot)(project.root),
45
30
  projectRoot: project.root,
46
31
  tmpl: '',
47
32
  });
48
- if (!hasPlugin) {
49
- project.targets.build.dependsOn = ['build-custom-server'];
50
- project.targets.serve.options.customServerTarget = `${options.project}:serve-custom-server`;
51
- project.targets.serve.configurations.development.customServerTarget = `${options.project}:serve-custom-server:development`;
52
- project.targets.serve.configurations.production.customServerTarget = `${options.project}:serve-custom-server:production`;
53
- }
54
- else {
55
- project.targets['build'] = {
56
- dependsOn: ['^build', 'build-custom-server'],
57
- };
58
- }
33
+ project.targets.build.dependsOn = ['build-custom-server'];
34
+ project.targets.serve.options.customServerTarget = `${options.project}:serve-custom-server`;
35
+ project.targets.serve.configurations.development.customServerTarget = `${options.project}:serve-custom-server:development`;
36
+ project.targets.serve.configurations.production.customServerTarget = `${options.project}:serve-custom-server:production`;
59
37
  project.targets['build-custom-server'] = {
60
- executor: options.compiler === 'tsc' ? '@nx/js:tsc' : '@nx/js:swc',
38
+ executor: '@nx/js:tsc',
61
39
  defaultConfiguration: 'production',
62
40
  options: {
63
41
  outputPath,
@@ -97,8 +75,5 @@ async function customServerGenerator(host, options) {
97
75
  json.targetDefaults['build-custom-server'].cache ??= true;
98
76
  return json;
99
77
  });
100
- if (options.compiler === 'swc') {
101
- return (0, add_swc_to_custom_server_1.configureForSwc)(host, project.root);
102
- }
103
78
  }
104
79
  exports.customServerGenerator = customServerGenerator;
@@ -2,8 +2,9 @@
2
2
  * This is only a minimal custom server to get started.
3
3
  * You may want to consider using Express or another server framework, and enable security features such as CORS.
4
4
  *
5
- * For an example, see the Next.js repo:
6
- * Node - https://github.com/vercel/next.js/blob/canary/examples/custom-server
5
+ * For more examples, see the Next.js repo:
6
+ * - Express: https://github.com/vercel/next.js/tree/canary/examples/custom-server-express
7
+ * - Hapi: https://github.com/vercel/next.js/tree/canary/examples/custom-server-hapi
7
8
  */
8
9
  import { createServer } from 'http';
9
10
  import { parse } from 'node:url';
@@ -14,8 +15,7 @@ import next from 'next';
14
15
  // - The environment variable is set by `@nx/next:server` when running the dev server.
15
16
  // - The fallback `__dirname` is for production builds.
16
17
  // - Feel free to change this to suit your needs.
17
-
18
- const dir = process.env.NX_NEXT_DIR || <%- hasPlugin ? `path.join(__dirname, '${projectPathFromDist}')` : `path.join(__dirname, '..')`; %>
18
+ const dir = process.env.NX_NEXT_DIR || path.join(__dirname, '..');
19
19
  const dev = process.env.NODE_ENV === 'development';
20
20
 
21
21
  // HTTP Server options:
@@ -4,9 +4,7 @@
4
4
  "module": "commonjs",
5
5
  "noEmit": false,
6
6
  "incremental": true,
7
- <% if(hasPlugin && compiler === 'tsc') { %>
8
7
  "tsBuildInfoFile": "<%= offsetFromRoot %>tmp/buildcache/<%= projectRoot %>/server",
9
- <% } %>
10
8
  "types": [
11
9
  "node"
12
10
  ]
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxNextCustomServer",
5
5
  "title": "Add custom server",
@@ -1,5 +1,4 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { CypressComponentConfigurationGeneratorSchema } from './schema';
3
3
  export declare function cypressComponentConfiguration(tree: Tree, options: CypressComponentConfigurationGeneratorSchema): Promise<GeneratorCallback>;
4
- export declare function cypressComponentConfigurationInternal(tree: Tree, options: CypressComponentConfigurationGeneratorSchema): Promise<GeneratorCallback>;
5
4
  export default cypressComponentConfiguration;
@@ -1,51 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cypressComponentConfigurationInternal = exports.cypressComponentConfiguration = void 0;
3
+ exports.cypressComponentConfiguration = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const ct_utils_1 = require("@nx/react/src/utils/ct-utils");
6
6
  const versions_1 = require("../../utils/versions");
7
7
  const react_1 = require("@nx/react");
8
8
  const path_1 = require("path");
9
- function cypressComponentConfiguration(tree, options) {
10
- return cypressComponentConfigurationInternal(tree, {
11
- addPlugin: false,
12
- ...options,
13
- });
14
- }
15
- exports.cypressComponentConfiguration = cypressComponentConfiguration;
16
- async function cypressComponentConfigurationInternal(tree, options) {
9
+ async function cypressComponentConfiguration(tree, options) {
17
10
  const tasks = [];
18
11
  const { componentConfigurationGenerator: baseCyCtConfig } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
19
12
  tasks.push(await baseCyCtConfig(tree, {
20
13
  project: options.project,
21
14
  skipFormat: true,
22
- framework: 'next',
23
15
  jsx: true,
24
- addPlugin: options.addPlugin,
25
16
  }));
26
17
  const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
27
18
  tasks.push(await webpackInitGenerator(tree, {
19
+ compiler: 'swc',
20
+ uiFramework: 'react',
28
21
  skipFormat: true,
29
- addPlugin: options.addPlugin,
30
22
  }));
31
- const { ensureDependencies } = await Promise.resolve().then(() => require('@nx/webpack/src/utils/ensure-dependencies'));
32
- tasks.push(ensureDependencies(tree, { compiler: 'swc', uiFramework: 'react' }));
33
23
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
34
- if (projectConfig.targets?.['component-test']?.executor ===
35
- '@nx/cypress:cypress') {
36
- projectConfig.targets['component-test'].options = {
37
- ...projectConfig.targets['component-test'].options,
38
- skipServe: true,
39
- };
40
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
41
- }
24
+ projectConfig.targets['component-test'].options = {
25
+ ...projectConfig.targets['component-test'].options,
26
+ skipServe: true,
27
+ };
28
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
42
29
  await addFiles(tree, projectConfig, options);
43
30
  if (!options.skipFormat) {
44
31
  await (0, devkit_1.formatFiles)(tree);
45
32
  }
46
33
  return (0, devkit_1.runTasksInSerial)(...tasks);
47
34
  }
48
- exports.cypressComponentConfigurationInternal = cypressComponentConfigurationInternal;
35
+ exports.cypressComponentConfiguration = cypressComponentConfiguration;
49
36
  async function addFiles(tree, projectConfig, opts) {
50
37
  const { addMountDefinition, addDefaultCTConfig } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/config'));
51
38
  const ctFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'component.ts');
@@ -2,5 +2,4 @@ export interface CypressComponentConfigurationGeneratorSchema {
2
2
  project: string;
3
3
  generateTests: boolean;
4
4
  skipFormat?: boolean;
5
- addPlugin?: boolean;
6
5
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "CypressComponentConfiguration",
5
5
  "title": "NextJS Component Testing Configuration",
@@ -1,5 +1,4 @@
1
- import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
- import type { InitSchema } from './schema';
3
- export declare function nextInitGenerator(tree: Tree, schema: InitSchema): Promise<GeneratorCallback>;
4
- export declare function nextInitGeneratorInternal(host: Tree, schema: InitSchema): Promise<GeneratorCallback>;
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { InitSchema } from './schema';
3
+ export declare function nextInitGenerator(host: Tree, schema: InitSchema): Promise<GeneratorCallback>;
5
4
  export default nextInitGenerator;
@@ -1,46 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nextInitGeneratorInternal = exports.nextInitGenerator = void 0;
3
+ exports.nextInitGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
5
  const versions_1 = require("@nx/react/src/utils/versions");
7
- const add_gitignore_entry_1 = require("../../utils/add-gitignore-entry");
6
+ const init_1 = require("@nx/react/src/generators/init/init");
7
+ const js_1 = require("@nx/js");
8
8
  const versions_2 = require("../../utils/versions");
9
- const add_plugin_1 = require("./lib/add-plugin");
10
- function updateDependencies(host, schema) {
11
- const tasks = [];
12
- tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/next'], []));
13
- tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {
9
+ const add_gitignore_entry_1 = require("../../utils/add-gitignore-entry");
10
+ function updateDependencies(host) {
11
+ return (0, devkit_1.addDependenciesToPackageJson)(host, {
14
12
  next: versions_2.nextVersion,
15
13
  react: versions_1.reactVersion,
16
14
  'react-dom': versions_1.reactDomVersion,
15
+ tslib: versions_2.tsLibVersion,
17
16
  }, {
18
17
  '@nx/next': versions_2.nxVersion,
19
- }, undefined, schema.keepExistingVersions));
20
- return (0, devkit_1.runTasksInSerial)(...tasks);
18
+ 'eslint-config-next': versions_2.eslintConfigNextVersion,
19
+ });
21
20
  }
22
- function nextInitGenerator(tree, schema) {
23
- return nextInitGeneratorInternal(tree, { addPlugin: false, ...schema });
24
- }
25
- exports.nextInitGenerator = nextInitGenerator;
26
- async function nextInitGeneratorInternal(host, schema) {
27
- const nxJson = (0, devkit_1.readNxJson)(host);
28
- const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
29
- nxJson.useInferencePlugins !== false;
30
- schema.addPlugin ??= addPluginDefault;
31
- if (schema.addPlugin) {
32
- (0, add_plugin_1.addPlugin)(host);
21
+ async function nextInitGenerator(host, schema) {
22
+ const tasks = [];
23
+ tasks.push(await (0, js_1.initGenerator)(host, {
24
+ ...schema,
25
+ skipFormat: true,
26
+ }));
27
+ if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
28
+ const { jestInitGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_2.nxVersion);
29
+ const jestTask = await jestInitGenerator(host, schema);
30
+ tasks.push(jestTask);
33
31
  }
34
- (0, add_gitignore_entry_1.addGitIgnoreEntry)(host);
35
- let installTask = () => { };
36
- if (!schema.skipPackageJson) {
37
- installTask = updateDependencies(host, schema);
32
+ if (schema.e2eTestRunner === 'cypress') {
33
+ const { cypressInitGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_2.nxVersion);
34
+ const cypressTask = await cypressInitGenerator(host, {});
35
+ tasks.push(cypressTask);
38
36
  }
39
- if (schema.updatePackageScripts) {
40
- const { createNodes } = await Promise.resolve().then(() => require('../../plugins/plugin'));
41
- await (0, update_package_scripts_1.updatePackageScripts)(host, createNodes);
37
+ else if (schema.e2eTestRunner === 'playwright') {
38
+ const { initGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_2.nxVersion);
39
+ const playwrightTask = await initGenerator(host, {
40
+ skipFormat: true,
41
+ skipPackageJson: schema.skipPackageJson,
42
+ });
43
+ tasks.push(playwrightTask);
44
+ }
45
+ // @ts-ignore
46
+ // TODO(jack): remove once the React Playwright PR lands first
47
+ const reactTask = await (0, init_1.default)(host, {
48
+ ...schema,
49
+ skipFormat: true,
50
+ });
51
+ tasks.push(reactTask);
52
+ if (!schema.skipPackageJson) {
53
+ const installTask = updateDependencies(host);
54
+ tasks.push(installTask);
42
55
  }
43
- return installTask;
56
+ (0, add_gitignore_entry_1.addGitIgnoreEntry)(host);
57
+ return (0, devkit_1.runTasksInSerial)(...tasks);
44
58
  }
45
- exports.nextInitGeneratorInternal = nextInitGeneratorInternal;
59
+ exports.nextInitGenerator = nextInitGenerator;
46
60
  exports.default = nextInitGenerator;
@@ -1,7 +1,8 @@
1
1
  export interface InitSchema {
2
+ unitTestRunner?: 'jest' | 'none';
3
+ e2eTestRunner?: 'cypress' | 'playwright' | 'none';
2
4
  skipFormat?: boolean;
5
+ js?: boolean;
3
6
  skipPackageJson?: boolean;
4
- keepExistingVersions?: boolean;
5
- updatePackageScripts?: boolean;
6
- addPlugin?: boolean;
7
+ rootProject?: boolean;
7
8
  }
@@ -1,33 +1,45 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxNextNgInit",
5
5
  "title": "Init Next Plugin",
6
6
  "description": "Init Next Plugin.",
7
7
  "type": "object",
8
8
  "properties": {
9
+ "unitTestRunner": {
10
+ "description": "Adds the specified unit test runner.",
11
+ "type": "string",
12
+ "enum": ["jest", "none"],
13
+ "default": "jest"
14
+ },
15
+ "e2eTestRunner": {
16
+ "description": "Adds the specified e2e test runner.",
17
+ "type": "string",
18
+ "enum": ["cypress", "none"],
19
+ "default": "cypress"
20
+ },
9
21
  "skipFormat": {
10
22
  "description": "Skip formatting files.",
11
23
  "type": "boolean",
12
24
  "default": false
13
25
  },
26
+ "js": {
27
+ "type": "boolean",
28
+ "default": false,
29
+ "description": "Use JavaScript instead of TypeScript"
30
+ },
14
31
  "skipPackageJson": {
15
32
  "type": "boolean",
16
33
  "default": false,
17
34
  "description": "Do not add dependencies to `package.json`.",
18
35
  "x-priority": "internal"
19
36
  },
20
- "keepExistingVersions": {
37
+ "rootProject": {
38
+ "description": "Create an application at the root of the workspace.",
21
39
  "type": "boolean",
22
- "x-priority": "internal",
23
- "description": "Keep existing dependencies versions",
24
- "default": false
25
- },
26
- "updatePackageScripts": {
27
- "type": "boolean",
28
- "x-priority": "internal",
29
- "description": "Update `package.json` scripts with inferred targets",
30
- "default": false
40
+ "default": false,
41
+ "hidden": true,
42
+ "x-priority": "internal"
31
43
  }
32
44
  },
33
45
  "required": []
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
4
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
5
  async function normalizeOptions(host, options) {
7
6
  const { projectRoot, importPath, projectNameAndRootFormat } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
@@ -13,10 +12,6 @@ async function normalizeOptions(host, options) {
13
12
  callingGenerator: '@nx/next:library',
14
13
  });
15
14
  options.projectNameAndRootFormat = projectNameAndRootFormat;
16
- const nxJson = (0, devkit_1.readNxJson)(host);
17
- const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
18
- nxJson.useInferencePlugins !== false;
19
- options.addPlugin ??= addPlugin;
20
15
  return {
21
16
  ...options,
22
17
  importPath,