@nx/next 18.0.0-beta.1 → 18.0.0-beta.2

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
@@ -4,7 +4,7 @@
4
4
  "extends": ["@nx/react"],
5
5
  "generators": {
6
6
  "init": {
7
- "factory": "./src/generators/init/init#nextInitGenerator",
7
+ "factory": "./src/generators/init/init#nextInitGeneratorInternal",
8
8
  "schema": "./src/generators/init/schema.json",
9
9
  "description": "Initialize the `@nrwl/next` plugin.",
10
10
  "hidden": true
@@ -39,7 +39,7 @@
39
39
  "description": "Set up a custom server."
40
40
  },
41
41
  "cypress-component-configuration": {
42
- "factory": "./src/generators/cypress-component-configuration/cypress-component-configuration",
42
+ "factory": "./src/generators/cypress-component-configuration/cypress-component-configuration#cypressComponentConfigurationInternal",
43
43
  "schema": "./src/generators/cypress-component-configuration/schema.json",
44
44
  "description": "cypress-component-configuration generator"
45
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/next",
3
- "version": "18.0.0-beta.1",
3
+ "version": "18.0.0-beta.2",
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": {
@@ -34,7 +34,7 @@
34
34
  "next": ">=14.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@nx/devkit": "18.0.0-beta.1",
37
+ "@nx/devkit": "18.0.0-beta.2",
38
38
  "@babel/plugin-proposal-decorators": "^7.22.7",
39
39
  "@svgr/webpack": "^8.0.1",
40
40
  "chalk": "^4.1.0",
@@ -45,12 +45,12 @@
45
45
  "url-loader": "^4.1.1",
46
46
  "tslib": "^2.3.0",
47
47
  "webpack-merge": "^5.8.0",
48
- "@nx/js": "18.0.0-beta.1",
49
- "@nx/eslint": "18.0.0-beta.1",
50
- "@nx/react": "18.0.0-beta.1",
51
- "@nx/web": "18.0.0-beta.1",
52
- "@nx/workspace": "18.0.0-beta.1",
53
- "@nrwl/next": "18.0.0-beta.1"
48
+ "@nx/js": "18.0.0-beta.2",
49
+ "@nx/eslint": "18.0.0-beta.2",
50
+ "@nx/react": "18.0.0-beta.2",
51
+ "@nx/web": "18.0.0-beta.2",
52
+ "@nx/workspace": "18.0.0-beta.2",
53
+ "@nrwl/next": "18.0.0-beta.2"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
@@ -1,12 +1,2 @@
1
1
  import { NxComponentTestingOptions } from '@nx/cypress/plugins/cypress-preset';
2
- export declare function nxComponentTestingPreset(pathToConfig: string, options?: NxComponentTestingOptions): {
3
- specPattern: string;
4
- devServer: {
5
- webpackConfig: import("webpack").Configuration;
6
- framework: "react";
7
- bundler: "webpack";
8
- };
9
- videosFolder: string;
10
- screenshotsFolder: string;
11
- chromeWebSecurity: boolean;
12
- };
2
+ export declare function nxComponentTestingPreset(pathToConfig: string, options?: NxComponentTestingOptions): any;
@@ -8,17 +8,25 @@ const react_1 = require("@nx/react");
8
8
  const webpack_1 = require("@nx/webpack");
9
9
  const path_1 = require("path");
10
10
  function nxComponentTestingPreset(pathToConfig, options) {
11
+ if (global.NX_GRAPH_CREATION || global.NX_CYPRESS_INIT_GENERATOR_RUNNING) {
12
+ // this is only used by plugins, so we don't need the component testing
13
+ // options, cast to any to avoid type errors
14
+ return (0, cypress_preset_1.nxBaseCypressPreset)(pathToConfig);
15
+ }
11
16
  const graph = (0, devkit_1.readCachedProjectGraph)();
12
17
  const { targets: ctTargets, name: ctProjectName } = (0, ct_helpers_1.getProjectConfigByPath)(graph, pathToConfig);
13
18
  const ctTargetName = options?.ctTargetName || 'component-test';
14
19
  const ctConfigurationName = process.env.NX_CYPRESS_TARGET_CONFIGURATION;
15
20
  const ctExecutorContext = (0, ct_helpers_1.createExecutorContext)(graph, ctTargets, ctProjectName, ctTargetName, ctConfigurationName);
16
- const ctExecutorOptions = (0, devkit_1.readTargetOptions)({
17
- project: ctProjectName,
18
- target: ctTargetName,
19
- configuration: ctConfigurationName,
20
- }, ctExecutorContext);
21
- const buildTarget = ctExecutorOptions.devServerTarget;
21
+ let buildTarget = options?.buildTarget;
22
+ if (!buildTarget) {
23
+ const ctExecutorOptions = (0, devkit_1.readTargetOptions)({
24
+ project: ctProjectName,
25
+ target: ctTargetName,
26
+ configuration: ctConfigurationName,
27
+ }, ctExecutorContext);
28
+ buildTarget = ctExecutorOptions.devServerTarget;
29
+ }
22
30
  let buildAssets = [];
23
31
  let buildFileReplacements = [];
24
32
  let buildOuputPath = `dist/${ctProjectName}/.next`;
@@ -31,6 +39,13 @@ function nxComponentTestingPreset(pathToConfig, options) {
31
39
  projectGraph: graph,
32
40
  });
33
41
  const buildProjectConfig = graph.nodes[parsedBuildTarget.project]?.data;
42
+ if (buildProjectConfig?.targets?.[parsedBuildTarget.target]?.executor !==
43
+ '@nx/next:build') {
44
+ throw new Error(`The '${parsedBuildTarget.target}' target of the '${[
45
+ parsedBuildTarget.project,
46
+ ]}' project is not using the '@nx/next:build' executor. ` +
47
+ `Please make sure to use '@nx/next:build' executor in that target to use Cypress Component Testing.`);
48
+ }
34
49
  const buildExecutorContext = (0, ct_helpers_1.createExecutorContext)(graph, buildProjectConfig.targets, parsedBuildTarget.project, parsedBuildTarget.target, parsedBuildTarget.configuration);
35
50
  const buildExecutorOptions = (0, devkit_1.readTargetOptions)({
36
51
  project: parsedBuildTarget.project,
@@ -70,7 +85,7 @@ Able to find CT project, ${!!ctProjectConfig}.`);
70
85
  context: ctExecutorContext,
71
86
  });
72
87
  return {
73
- ...(0, cypress_preset_1.nxBaseCypressPreset)(__filename),
88
+ ...(0, cypress_preset_1.nxBaseCypressPreset)(pathToConfig),
74
89
  specPattern: '**/*.cy.{js,jsx,ts,tsx}',
75
90
  devServer: {
76
91
  ...{ framework: 'react', bundler: 'webpack' },
@@ -21,6 +21,7 @@ const versions_2 = require("../../utils/versions");
21
21
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
22
22
  async function applicationGenerator(host, schema) {
23
23
  return await applicationGeneratorInternal(host, {
24
+ addPlugin: false,
24
25
  projectNameAndRootFormat: 'derived',
25
26
  ...schema,
26
27
  });
@@ -47,6 +47,7 @@ async function addE2e(host, options) {
47
47
  setParserOptionsProject: options.setParserOptionsProject,
48
48
  webServerAddress: `http://127.0.0.1:${hasPlugin ? '3000' : '4200'}`,
49
49
  webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx ${hasPlugin ? 'start' : 'serve'} ${options.projectName}`,
50
+ addPlugin: options.addPlugin,
50
51
  });
51
52
  }
52
53
  return () => { };
@@ -18,6 +18,7 @@ async function addLinting(host, options) {
18
18
  skipFormat: true,
19
19
  rootProject: options.rootProject,
20
20
  setParserOptionsProject: options.setParserOptionsProject,
21
+ addPlugin: options.addPlugin,
21
22
  }));
22
23
  if (options.linter === eslint_1.Linter.EsLint && (0, eslint_file_1.isEslintConfigSupported)(host)) {
23
24
  (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, [
@@ -364,6 +364,25 @@ function createAppJsx(name) {
364
364
  nx g @nx/next:component ui/src/lib/button
365
365
  </pre>
366
366
  </details>
367
+ <details>
368
+ <summary>
369
+ <svg
370
+ fill="none"
371
+ stroke="currentColor"
372
+ viewBox="0 0 24 24"
373
+ xmlns="http://www.w3.org/2000/svg"
374
+ >
375
+ <path
376
+ strokeLinecap="round"
377
+ strokeLinejoin="round"
378
+ strokeWidth="2"
379
+ d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
380
+ />
381
+ </svg>
382
+ View project details
383
+ </summary>
384
+ <pre>nx show project ${name} --web</pre>
385
+ </details>
367
386
  <details>
368
387
  <summary>
369
388
  <svg
@@ -16,6 +16,7 @@ async function normalizeOptions(host, options) {
16
16
  });
17
17
  options.rootProject = appProjectRoot === '.';
18
18
  options.projectNameAndRootFormat = projectNameAndRootFormat;
19
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
19
20
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
20
21
  const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
21
22
  const name = (0, devkit_1.names)(options.name).fileName;
@@ -20,4 +20,5 @@ export interface Schema {
20
20
  appDir?: boolean;
21
21
  src?: boolean;
22
22
  rootProject?: boolean;
23
+ addPlugin?: boolean;
23
24
  }
@@ -1,4 +1,5 @@
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>;
4
5
  export default cypressComponentConfiguration;
@@ -1,36 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cypressComponentConfiguration = void 0;
3
+ exports.cypressComponentConfigurationInternal = 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
- async function cypressComponentConfiguration(tree, options) {
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) {
10
17
  const tasks = [];
11
18
  const { componentConfigurationGenerator: baseCyCtConfig } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
12
19
  tasks.push(await baseCyCtConfig(tree, {
13
20
  project: options.project,
14
21
  skipFormat: true,
15
22
  jsx: true,
23
+ addPlugin: options.addPlugin,
16
24
  }));
17
25
  const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
18
- tasks.push(await webpackInitGenerator(tree, { skipFormat: true }));
26
+ tasks.push(await webpackInitGenerator(tree, {
27
+ skipFormat: true,
28
+ addPlugin: options.addPlugin,
29
+ }));
19
30
  const { ensureDependencies } = await Promise.resolve().then(() => require('@nx/webpack/src/utils/ensure-dependencies'));
20
31
  tasks.push(ensureDependencies(tree, { compiler: 'swc', uiFramework: 'react' }));
21
32
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
22
- projectConfig.targets['component-test'].options = {
23
- ...projectConfig.targets['component-test'].options,
24
- skipServe: true,
25
- };
26
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
33
+ if (projectConfig.targets?.['component-test']?.executor ===
34
+ '@nx/cypress:cypress') {
35
+ projectConfig.targets['component-test'].options = {
36
+ ...projectConfig.targets['component-test'].options,
37
+ skipServe: true,
38
+ };
39
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
40
+ }
27
41
  await addFiles(tree, projectConfig, options);
28
42
  if (!options.skipFormat) {
29
43
  await (0, devkit_1.formatFiles)(tree);
30
44
  }
31
45
  return (0, devkit_1.runTasksInSerial)(...tasks);
32
46
  }
33
- exports.cypressComponentConfiguration = cypressComponentConfiguration;
47
+ exports.cypressComponentConfigurationInternal = cypressComponentConfigurationInternal;
34
48
  async function addFiles(tree, projectConfig, opts) {
35
49
  const { addMountDefinition, addDefaultCTConfig } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/config'));
36
50
  const ctFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'component.ts');
@@ -2,4 +2,5 @@ export interface CypressComponentConfigurationGeneratorSchema {
2
2
  project: string;
3
3
  generateTests: boolean;
4
4
  skipFormat?: boolean;
5
+ addPlugin?: boolean;
5
6
  }
@@ -1,4 +1,5 @@
1
1
  import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
2
  import type { InitSchema } from './schema';
3
- export declare function nextInitGenerator(host: Tree, schema: InitSchema): Promise<GeneratorCallback>;
3
+ export declare function nextInitGenerator(tree: Tree, schema: InitSchema): Promise<GeneratorCallback>;
4
+ export declare function nextInitGeneratorInternal(host: Tree, schema: InitSchema): Promise<GeneratorCallback>;
4
5
  export default nextInitGenerator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nextInitGenerator = void 0;
3
+ exports.nextInitGeneratorInternal = exports.nextInitGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
6
  const versions_1 = require("@nx/react/src/utils/versions");
@@ -19,8 +19,13 @@ function updateDependencies(host, schema) {
19
19
  }, undefined, schema.keepExistingVersions));
20
20
  return (0, devkit_1.runTasksInSerial)(...tasks);
21
21
  }
22
- async function nextInitGenerator(host, schema) {
23
- if (process.env.NX_PCV3 === 'true') {
22
+ function nextInitGenerator(tree, schema) {
23
+ return nextInitGeneratorInternal(tree, { addPlugin: false, ...schema });
24
+ }
25
+ exports.nextInitGenerator = nextInitGenerator;
26
+ async function nextInitGeneratorInternal(host, schema) {
27
+ schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
28
+ if (schema.addPlugin) {
24
29
  (0, add_plugin_1.addPlugin)(host);
25
30
  }
26
31
  (0, add_gitignore_entry_1.addGitIgnoreEntry)(host);
@@ -34,5 +39,5 @@ async function nextInitGenerator(host, schema) {
34
39
  }
35
40
  return installTask;
36
41
  }
37
- exports.nextInitGenerator = nextInitGenerator;
42
+ exports.nextInitGeneratorInternal = nextInitGeneratorInternal;
38
43
  exports.default = nextInitGenerator;
@@ -3,4 +3,5 @@ export interface InitSchema {
3
3
  skipPackageJson?: boolean;
4
4
  keepExistingVersions?: boolean;
5
5
  updatePackageScripts?: boolean;
6
+ addPlugin?: boolean;
6
7
  }
@@ -12,6 +12,7 @@ async function normalizeOptions(host, options) {
12
12
  callingGenerator: '@nx/next:library',
13
13
  });
14
14
  options.projectNameAndRootFormat = projectNameAndRootFormat;
15
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
15
16
  return {
16
17
  ...options,
17
18
  importPath,
@@ -10,6 +10,7 @@ const normalize_options_1 = require("./lib/normalize-options");
10
10
  const versions_2 = require("../../utils/versions");
11
11
  async function libraryGenerator(host, rawOptions) {
12
12
  return await libraryGeneratorInternal(host, {
13
+ addPlugin: false,
13
14
  projectNameAndRootFormat: 'derived',
14
15
  ...rawOptions,
15
16
  });
@@ -24,4 +24,5 @@ export interface Schema {
24
24
  strict?: boolean;
25
25
  setParserOptionsProject?: boolean;
26
26
  skipPackageJson?: boolean;
27
+ addPlugin?: boolean;
27
28
  }