@nx/next 24.0.0-beta.2 → 24.0.0-beta.4

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 (50) hide show
  1. package/dist/plugins/component-testing.js +19 -62
  2. package/dist/plugins/with-nx.d.ts +14 -10
  3. package/dist/plugins/with-nx.js +24 -255
  4. package/dist/src/generators/application/application.js +1 -2
  5. package/dist/src/generators/application/files/common/next.config.js__tmpl__ +0 -22
  6. package/dist/src/generators/application/lib/add-e2e.js +5 -6
  7. package/dist/src/generators/application/lib/add-linting.js +0 -1
  8. package/dist/src/generators/application/lib/add-project.js +1 -46
  9. package/dist/src/generators/application/lib/add-vitest.js +0 -1
  10. package/dist/src/generators/application/lib/normalize-options.js +0 -4
  11. package/dist/src/generators/application/schema.d.ts +0 -1
  12. package/dist/src/generators/custom-server/custom-server.js +6 -25
  13. package/dist/src/generators/custom-server/files/server/main.ts__tmpl__ +3 -3
  14. package/dist/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +1 -1
  15. package/dist/src/generators/cypress-component-configuration/cypress-component-configuration.js +1 -14
  16. package/dist/src/generators/cypress-component-configuration/schema.d.ts +0 -1
  17. package/dist/src/generators/init/init.js +14 -28
  18. package/dist/src/generators/init/schema.d.ts +0 -1
  19. package/dist/src/generators/library/lib/add-rollup-server-entry.js +7 -16
  20. package/dist/src/generators/library/lib/normalize-options.js +0 -5
  21. package/dist/src/generators/library/library.js +1 -2
  22. package/dist/src/generators/library/schema.d.ts +0 -1
  23. package/dist/src/migrations/update-24-0-0/finish-inferred-conversion.md +12 -0
  24. package/dist/src/migrations/update-24-0-0/migrate-config-helpers.md +80 -0
  25. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.d.ts +6 -0
  26. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.js +18 -0
  27. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.md +89 -0
  28. package/dist/src/utils/compose-plugins.d.ts +6 -1
  29. package/dist/src/utils/compose-plugins.js +20 -29
  30. package/dist/src/utils/deprecation.d.ts +0 -5
  31. package/dist/src/utils/deprecation.js +9 -31
  32. package/executors.json +1 -12
  33. package/migrations.json +12 -0
  34. package/package.json +13 -13
  35. package/dist/src/executors/build/build.impl.d.ts +0 -5
  36. package/dist/src/executors/build/build.impl.js +0 -154
  37. package/dist/src/executors/build/lib/check-project.d.ts +0 -1
  38. package/dist/src/executors/build/lib/check-project.js +0 -11
  39. package/dist/src/executors/build/lib/create-next-config-file.d.ts +0 -14
  40. package/dist/src/executors/build/lib/create-next-config-file.js +0 -171
  41. package/dist/src/executors/build/lib/update-package-json.d.ts +0 -3
  42. package/dist/src/executors/build/lib/update-package-json.js +0 -31
  43. package/dist/src/executors/build/schema.json +0 -98
  44. package/dist/src/executors/server/custom-server.impl.d.ts +0 -6
  45. package/dist/src/executors/server/custom-server.impl.js +0 -37
  46. package/dist/src/executors/server/schema.json +0 -85
  47. package/dist/src/executors/server/server.impl.d.ts +0 -6
  48. package/dist/src/executors/server/server.impl.js +0 -115
  49. package/dist/src/utils/runtime-version-utils.d.ts +0 -7
  50. package/dist/src/utils/runtime-version-utils.js +0 -28
@@ -5,10 +5,8 @@ const cypress_preset_1 = require("@nx/cypress/plugins/cypress-preset");
5
5
  const internal_1 = require("@nx/cypress/internal");
6
6
  const devkit_1 = require("@nx/devkit");
7
7
  const internal_2 = require("@nx/js/internal");
8
- const react_1 = require("@nx/react");
9
8
  const internal_3 = require("@nx/react/internal");
10
9
  const path_1 = require("path");
11
- const internal_4 = require("@nx/devkit/internal");
12
10
  function nxComponentTestingPreset(pathToConfig, options) {
13
11
  if (global.NX_GRAPH_CREATION) {
14
12
  // this is only used by plugins, so we don't need the component testing
@@ -16,57 +14,15 @@ function nxComponentTestingPreset(pathToConfig, options) {
16
14
  return (0, cypress_preset_1.nxBaseCypressPreset)(pathToConfig);
17
15
  }
18
16
  (0, internal_3.assertPackageIsInstalled)('@nx/webpack', '@nx/next/plugins/component-testing');
19
- const { composePluginsSync, withNx, } = require('@nx/webpack');
20
- const { suppressWebpackComposeHelperWarnings, } = require('@nx/webpack/internal');
17
+ const { applyBaseConfig, applyWebConfig, } = require('@nx/webpack/internal');
21
18
  const graph = (0, devkit_1.readCachedProjectGraph)();
22
19
  const { targets: ctTargets, name: ctProjectName } = (0, internal_1.getProjectConfigByPath)(graph, pathToConfig);
23
20
  const ctTargetName = options?.ctTargetName || 'component-test';
24
21
  const ctConfigurationName = process.env.NX_CYPRESS_TARGET_CONFIGURATION;
25
22
  const ctExecutorContext = (0, internal_1.createExecutorContext)(graph, ctTargets, ctProjectName, ctTargetName, ctConfigurationName);
26
- let buildTarget = options?.buildTarget;
27
- if (!buildTarget) {
28
- const ctExecutorOptions = (0, devkit_1.readTargetOptions)({
29
- project: ctProjectName,
30
- target: ctTargetName,
31
- configuration: ctConfigurationName,
32
- }, ctExecutorContext);
33
- buildTarget = ctExecutorOptions.devServerTarget;
34
- }
35
- let buildAssets = [];
36
- let buildFileReplacements = [];
37
- let buildOuputPath = `dist/${ctProjectName}/.next`;
38
- if (buildTarget) {
39
- const parsedBuildTarget = (0, devkit_1.parseTargetString)(buildTarget, {
40
- cwd: process.cwd(),
41
- root: devkit_1.workspaceRoot,
42
- projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(graph),
43
- nxJsonConfiguration: (0, internal_4.readNxJsonFromDisk)(devkit_1.workspaceRoot),
44
- isVerbose: false,
45
- projectName: ctProjectName,
46
- projectGraph: graph,
47
- });
48
- const buildProjectConfig = graph.nodes[parsedBuildTarget.project]?.data;
49
- if (buildProjectConfig?.targets?.[parsedBuildTarget.target]?.executor !==
50
- '@nx/next:build') {
51
- throw new Error(`The '${parsedBuildTarget.target}' target of the '${[
52
- parsedBuildTarget.project,
53
- ]}' project is not using the '@nx/next:build' executor. ` +
54
- `Please make sure to use '@nx/next:build' executor in that target to use Cypress Component Testing.`);
55
- }
56
- const buildExecutorContext = (0, internal_1.createExecutorContext)(graph, buildProjectConfig.targets, parsedBuildTarget.project, parsedBuildTarget.target, parsedBuildTarget.configuration);
57
- const buildExecutorOptions = (0, devkit_1.readTargetOptions)({
58
- project: parsedBuildTarget.project,
59
- target: parsedBuildTarget.target,
60
- configuration: parsedBuildTarget.configuration,
61
- }, buildExecutorContext);
62
- buildAssets ??= buildExecutorOptions.assets;
63
- buildFileReplacements ??= buildExecutorOptions.fileReplacements;
64
- buildOuputPath ??= buildExecutorOptions.outputPath;
65
- }
66
23
  const ctProjectConfig = graph.nodes[ctProjectName]?.data;
67
24
  if (!ctProjectConfig) {
68
25
  throw new Error((0, devkit_1.stripIndents) `Unable to load project configs from the project graph.
69
- Provided build target, ${buildTarget}.
70
26
  Able to find CT project, ${!!ctProjectConfig}.`);
71
27
  }
72
28
  const webpackOptions = {
@@ -75,27 +31,28 @@ Able to find CT project, ${!!ctProjectConfig}.`);
75
31
  sourceRoot: (0, internal_2.getProjectSourceRoot)(ctProjectConfig),
76
32
  main: '',
77
33
  useTsconfigPaths: undefined,
78
- fileReplacements: buildFileReplacements,
79
- assets: buildAssets,
80
- outputPath: buildOuputPath,
34
+ fileReplacements: [],
35
+ assets: [],
36
+ outputPath: `dist/${ctProjectName}/.next`,
81
37
  outputFileName: 'main.js',
82
38
  compiler: options?.compiler || 'swc',
83
39
  tsConfig: (0, path_1.join)(ctExecutorContext.root, ctProjectConfig.root, 'tsconfig.json'),
84
40
  };
85
- // Nx composes these helpers internally for the Cypress CT preset; suppress
86
- // their deprecation warning so it fires only for user-authored configs.
87
- const webpackConfig = suppressWebpackComposeHelperWarnings(() => (0, internal_3.suppressReactComposeHelperWarnings)(() => {
88
- const configure = composePluginsSync(withNx({
89
- target: 'web',
90
- styles: [],
91
- scripts: [],
92
- postcssConfig: ctProjectConfig.root,
93
- }), (0, react_1.withReact)({}));
94
- return configure({}, {
95
- options: webpackOptions,
96
- context: ctExecutorContext,
97
- });
98
- }));
41
+ const webpackConfig = {};
42
+ const configOptions = {
43
+ ...webpackOptions,
44
+ target: 'web',
45
+ styles: [],
46
+ scripts: [],
47
+ postcssConfig: ctProjectConfig.root,
48
+ projectName: ctExecutorContext.projectName,
49
+ targetName: ctExecutorContext.targetName,
50
+ configurationName: ctExecutorContext.configurationName,
51
+ projectGraph: ctExecutorContext.projectGraph,
52
+ };
53
+ applyBaseConfig(configOptions, webpackConfig);
54
+ applyWebConfig(configOptions, webpackConfig);
55
+ (0, internal_3.applyReactConfig)({}, webpackConfig);
99
56
  return {
100
57
  ...(0, cypress_preset_1.nxBaseCypressPreset)(pathToConfig),
101
58
  specPattern: '**/*.cy.{js,jsx,ts,tsx}',
@@ -1,10 +1,5 @@
1
- /**
2
- * WARNING: Do not add development dependencies to top-level imports.
3
- * Instead, `require` them inline during the build phase.
4
- */
5
1
  import type { NextConfig } from 'next';
6
2
  import type { NextConfigFn } from '../src/utils/config';
7
- import { type ProjectGraphProjectNode } from '@nx/devkit';
8
3
  import type { AssetGlobPattern } from '@nx/webpack';
9
4
  export interface WithNxOptions extends NextConfig {
10
5
  nx?: {
@@ -21,10 +16,19 @@ export interface WithNxContext {
21
16
  libsDir: string;
22
17
  }
23
18
  /**
24
- * Try to read output dir from project, and default to '.next' if executing outside of Nx (e.g. dist is added to a docker image).
19
+ * @deprecated Export the Next.js config directly and compose
20
+ * any other wrappers yourself.
21
+ * This inert stub will be removed in Nx v25.
22
+ */
23
+ declare function withNx(config?: WithNxOptions, _context?: WithNxContext): NextConfigFn;
24
+ /**
25
+ * @deprecated Use the Next.js config object directly.
26
+ * This inert stub will be removed in Nx v25.
27
+ */
28
+ export declare function getNextConfig(nextConfig?: WithNxOptions, _context?: WithNxContext): NextConfig;
29
+ /**
30
+ * @deprecated Next.js resolves tsconfig `paths` natively.
31
+ * This inert stub will be removed in Nx v25.
25
32
  */
26
- declare function withNx(_nextConfig?: WithNxOptions, context?: WithNxContext): NextConfigFn;
27
- export declare function getNextConfig(nextConfig?: WithNxOptions, context?: WithNxContext): NextConfig;
28
- export declare function getAliasForProject(node: ProjectGraphProjectNode, paths: Record<string, string[]>): null | string;
29
- export declare function forNextVersion(range: string, fn: () => void): void;
33
+ export declare function getAliasForProject(_node: unknown, _paths: Record<string, string[]>): null | string;
30
34
  export { withNx };
@@ -2,276 +2,45 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNextConfig = getNextConfig;
4
4
  exports.getAliasForProject = getAliasForProject;
5
- exports.forNextVersion = forNextVersion;
6
5
  exports.withNx = withNx;
7
- const semver_1 = require("semver");
8
- function regexEqual(x, y) {
9
- return (x instanceof RegExp &&
10
- y instanceof RegExp &&
11
- x.source === y.source &&
12
- x.global === y.global &&
13
- x.ignoreCase === y.ignoreCase &&
14
- x.multiline === y.multiline);
15
- }
16
- /**
17
- * Do not remove or rename this function. Production builds inline `with-nx.js` file with a replacement
18
- * To this function that hard-codes the libsDir.
19
- */
20
- function getWithNxContext() {
21
- const { workspaceRoot, workspaceLayout } = require('@nx/devkit');
22
- return {
23
- workspaceRoot,
24
- libsDir: workspaceLayout().libsDir,
25
- };
26
- }
27
- function getNxContext(graph, target) {
28
- const { parseTargetString, workspaceRoot } = require('@nx/devkit');
29
- const projectNode = graph.nodes[target.project];
30
- const targetConfig = projectNode.data.targets[target.target];
31
- const targetOptions = targetConfig.options;
32
- if (target.configuration) {
33
- Object.assign(targetOptions, targetConfig.configurations[target.configuration]);
34
- }
35
- const partialExecutorContext = {
36
- projectName: target.project,
37
- targetName: target.target,
38
- projectGraph: graph,
39
- configurationName: target.configuration,
40
- root: workspaceRoot,
41
- };
42
- if (targetOptions.devServerTarget) {
43
- // Executors such as @nx/cypress:cypress define the devServerTarget option.
44
- return getNxContext(graph, parseTargetString(targetOptions.devServerTarget, partialExecutorContext));
45
- }
46
- else if (targetOptions.buildTarget) {
47
- // Executors such as @nx/next:server define the buildTarget option.
48
- return getNxContext(graph, parseTargetString(targetOptions.buildTarget, partialExecutorContext));
49
- }
50
- // Default case, return info for current target.
51
- // This could be a build using @nx/next:build or run-commands without using our executors.
52
- return {
53
- node: graph.nodes[target.project],
54
- options: targetOptions,
55
- projectName: target.project,
56
- targetName: target.target,
57
- configurationName: target.configuration,
58
- };
59
- }
6
+ // TODO(v25): remove the inert config-helper stubs in this file.
60
7
  /**
61
- * Try to read output dir from project, and default to '.next' if executing outside of Nx (e.g. dist is added to a docker image).
8
+ * @deprecated Export the Next.js config directly and compose
9
+ * any other wrappers yourself.
10
+ * This inert stub will be removed in Nx v25.
62
11
  */
63
- function withNx(_nextConfig = {}, context = getWithNxContext()) {
12
+ function withNx(config = {}, _context) {
64
13
  return async (phase) => {
65
- const { PHASE_PRODUCTION_SERVER, PHASE_DEVELOPMENT_SERVER, } = require('next/constants');
66
- // Three scenarios where we want to skip graph creation:
67
- // 1. Running production server means the build is already done so we just need to start the Next.js server.
68
- // 2. During graph creation (i.e. create nodes), we won't have a graph to read, and it is not needed anyway since it's a build-time concern.
69
- // 3. Running outside of Nx, we don't have a graph to read.
70
- //
71
- // NOTE: Avoid any `require(...)` or `import(...)` statements here. Development dependencies are not available at production runtime.
72
- if (PHASE_PRODUCTION_SERVER === phase ||
73
- global.NX_GRAPH_CREATION ||
74
- !process.env.NX_TASK_TARGET_TARGET) {
75
- const { nx, ...validNextConfig } = _nextConfig;
76
- return {
77
- distDir: '.next',
78
- ...validNextConfig,
79
- };
80
- }
81
- else {
82
- const { readCachedProjectGraph, joinPathFragments, offsetFromRoot, workspaceRoot, } = require('@nx/devkit');
83
- // Resolved from the workspace (not bundled) so the deprecation warning is
84
- // not inlined into production builds. Reached only on the active Nx-task
85
- // path; the production-server phase returns above.
14
+ const { PHASE_PRODUCTION_SERVER } = require('next/constants');
15
+ // Copied into production builds, so only resolve the warning on Nx task runs.
16
+ if (phase !== PHASE_PRODUCTION_SERVER &&
17
+ !global.NX_GRAPH_CREATION &&
18
+ process.env.NX_TASK_TARGET_TARGET) {
19
+ const { workspaceRoot } = require('@nx/devkit');
86
20
  const { warnWithNxDeprecation } = require(require.resolve('@nx/next/src/utils/deprecation', {
87
21
  paths: [workspaceRoot],
88
22
  }));
89
23
  warnWithNxDeprecation();
90
- // Since this is invoked by an Nx task, the graph is already cached.
91
- const graph = readCachedProjectGraph();
92
- const originalTarget = {
93
- project: process.env.NX_TASK_TARGET_PROJECT,
94
- target: process.env.NX_TASK_TARGET_TARGET,
95
- configuration: process.env.NX_TASK_TARGET_CONFIGURATION,
96
- };
97
- const { node: projectNode, options, projectName: project, } = getNxContext(graph, originalTarget);
98
- const projectDirectory = projectNode.data.root;
99
- // Get next config
100
- const nextConfig = getNextConfig(_nextConfig, context);
101
- // For Next.js 13.1 and greater, make sure workspace libs are transpiled.
102
- forNextVersion('>=13.1.0', () => {
103
- if (!graph.dependencies[project])
104
- return;
105
- const { readTsConfigPaths } = require('@nx/js');
106
- const { findAllProjectNodeDependencies, } = require('@nx/devkit/internal');
107
- const paths = readTsConfigPaths();
108
- const deps = findAllProjectNodeDependencies(project);
109
- nextConfig.transpilePackages ??= [];
110
- for (const dep of deps) {
111
- const alias = getAliasForProject(graph.nodes[dep], paths);
112
- if (alias) {
113
- nextConfig.transpilePackages.push(alias);
114
- }
115
- }
116
- });
117
- // process.env.NX_NEXT_OUTPUT_PATH is set when running @nx/next:build
118
- options.outputPath =
119
- process.env.NX_NEXT_OUTPUT_PATH || options.outputPath;
120
- // outputPath may be undefined if using run-commands or other executors other than @nx/next:build.
121
- // In this case, the user should set distDir in their next.config.js.
122
- if (options.outputPath && phase !== PHASE_DEVELOPMENT_SERVER) {
123
- const outputDir = `${offsetFromRoot(projectDirectory)}${options.outputPath}`;
124
- // If running dev-server, we should keep `.next` inside project directory since Turbopack expects this.
125
- // See: https://github.com/nrwl/nx/issues/19365
126
- nextConfig.distDir =
127
- nextConfig.distDir && nextConfig.distDir !== '.next'
128
- ? joinPathFragments(outputDir, nextConfig.distDir)
129
- : joinPathFragments(outputDir, '.next');
130
- }
131
- // If we are running a static serve of the Next.js app, we need to change the output to 'export' and the distDir to 'out'.
132
- if (process.env.NX_SERVE_STATIC_BUILD_RUNNING === 'true') {
133
- nextConfig.output = 'export';
134
- nextConfig.distDir = 'out';
135
- }
136
- const userWebpackConfig = nextConfig.webpack;
137
- const { createWebpackConfig } = require(require.resolve('@nx/next/src/utils/config', {
138
- paths: [workspaceRoot],
139
- }));
140
- // If we have file replacements or assets, inside of the next config we pass the workspaceRoot as a join of the workspaceRoot and the projectDirectory
141
- // Because the file replacements and assets are relative to the projectRoot, not the workspaceRoot
142
- nextConfig.webpack = (a, b) => createWebpackConfig(_nextConfig.nx?.fileReplacements
143
- ? joinPathFragments(workspaceRoot, projectDirectory)
144
- : workspaceRoot, projectDirectory, _nextConfig.nx?.fileReplacements || options.fileReplacements, _nextConfig.nx?.assets || options.assets)(userWebpackConfig ? userWebpackConfig(a, b) : a, b);
145
- return nextConfig;
146
24
  }
25
+ return config;
147
26
  };
148
27
  }
149
- function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
150
- // If `next-compose-plugins` is used, the context argument is invalid.
151
- if (!context.libsDir || !context.workspaceRoot) {
152
- context = getWithNxContext();
153
- }
154
- const userWebpack = nextConfig.webpack || ((x) => x);
155
- const { nx, ...validNextConfig } = nextConfig;
156
- const baseConfig = {
157
- ...validNextConfig,
158
- };
159
- const nextJsVersion = require('next/package.json')?.version ?? '16.0.1';
160
- if ((0, semver_1.satisfies)(nextJsVersion, '<16.0.0', { includePrerelease: true })) {
161
- baseConfig.eslint = {
162
- ignoreDuringBuilds: true,
163
- ...(validNextConfig.eslint ?? {}),
164
- };
165
- }
166
- return {
167
- ...baseConfig,
168
- webpack: (config, options) => {
169
- /**
170
- * To support ESM library export, we need to ensure the extensionAlias contains both `.js` and `.ts` extensions.
171
- * This is because Webpack uses the `extensionAlias` to resolve the correct file extension when importing modules.
172
- */
173
- config.resolve.extensionAlias = {
174
- ...(config.resolve.extensionAlias || {}),
175
- '.js': ['.ts', '.tsx', '.js', '.jsx'],
176
- '.mjs': ['.mts', '.mjs'],
177
- '.cjs': ['.cts', '.cjs'],
178
- '.jsx': ['.tsx', '.jsx'],
179
- };
180
- /*
181
- * Update babel to support our monorepo setup.
182
- * The 'upward' mode allows the root babel.config.json and per-project .babelrc files to be picked up.
183
- */
184
- if (nx?.babelUpwardRootMode) {
185
- options.defaultLoaders.babel.options.babelrc = true;
186
- options.defaultLoaders.babel.options.rootMode = 'upward';
187
- }
188
- /*
189
- * Modify the Next.js webpack config to allow workspace libs to use css modules.
190
- * Note: This would be easier if Next.js exposes css-loader and sass-loader on `defaultLoaders`.
191
- */
192
- // Include workspace libs in css/sass loaders
193
- const includes = [
194
- require('path').join(context.workspaceRoot, context.libsDir),
195
- ];
196
- const nextCssLoaders = config.module.rules.find((rule) => typeof rule.oneOf === 'object');
197
- // webpack config is not as expected
198
- if (!nextCssLoaders)
199
- return config;
200
- /*
201
- * 1. Modify css loader to enable module support for workspace libs
202
- */
203
- const nextCssLoader = nextCssLoaders.oneOf.find((rule) => rule.sideEffects === false && regexEqual(rule.test, /\.module\.css$/));
204
- // Might not be found if Next.js webpack config changes in the future
205
- if (nextCssLoader && nextCssLoader.issuer) {
206
- nextCssLoader.issuer.or = nextCssLoader.issuer.and
207
- ? nextCssLoader.issuer.and.concat(includes)
208
- : includes;
209
- delete nextCssLoader.issuer.and;
210
- }
211
- /*
212
- * 2. Modify sass loader to enable module support for workspace libs
213
- */
214
- const nextSassLoader = nextCssLoaders.oneOf.find((rule) => rule.sideEffects === false &&
215
- regexEqual(rule.test, /\.module\.(scss|sass)$/));
216
- // Might not be found if Next.js webpack config changes in the future
217
- if (nextSassLoader && nextSassLoader.issuer) {
218
- nextSassLoader.issuer.or = nextSassLoader.issuer.and
219
- ? nextSassLoader.issuer.and.concat(includes)
220
- : includes;
221
- delete nextSassLoader.issuer.and;
222
- }
223
- /*
224
- * 3. Modify error loader to ignore css modules used by workspace libs
225
- */
226
- const nextErrorCssModuleLoader = nextCssLoaders.oneOf.find((rule) => rule.use &&
227
- rule.use.loader === 'error-loader' &&
228
- rule.use.options &&
229
- (rule.use.options.reason ===
230
- 'CSS Modules \u001b[1mcannot\u001b[22m be imported from within \u001b[1mnode_modules\u001b[22m.\n' +
231
- 'Read more: https://err.sh/next.js/css-modules-npm' ||
232
- rule.use.options.reason ===
233
- 'CSS Modules cannot be imported from within node_modules.\nRead more: https://err.sh/next.js/css-modules-npm'));
234
- // Might not be found if Next.js webpack config changes in the future
235
- if (nextErrorCssModuleLoader) {
236
- nextErrorCssModuleLoader.exclude = includes;
237
- }
238
- /**
239
- * 4. Modify css loader to allow global css from node_modules to be imported from workspace libs
240
- */
241
- const nextGlobalCssLoader = nextCssLoaders.oneOf.find((rule) => rule.include?.and?.find((include) => regexEqual(include, /node_modules/)));
242
- // Might not be found if Next.js webpack config changes in the future
243
- if (nextGlobalCssLoader && nextGlobalCssLoader.issuer) {
244
- nextGlobalCssLoader.issuer.or = nextGlobalCssLoader.issuer.and
245
- ? nextGlobalCssLoader.issuer.and.concat(includes)
246
- : includes;
247
- delete nextGlobalCssLoader.issuer.and;
248
- }
249
- return userWebpack(config, options);
250
- },
251
- };
28
+ /**
29
+ * @deprecated Use the Next.js config object directly.
30
+ * This inert stub will be removed in Nx v25.
31
+ */
32
+ function getNextConfig(nextConfig = {}, _context) {
33
+ return nextConfig;
252
34
  }
253
- function getAliasForProject(node, paths) {
254
- // Match workspace libs to their alias in tsconfig paths.
255
- for (const [alias, lookup] of Object.entries(paths ?? {})) {
256
- const lookupContainsDepNode = lookup.some((lookupPath) => lookupPath.startsWith(node?.data?.root) ||
257
- lookupPath.startsWith('./' + node?.data?.root));
258
- if (lookupContainsDepNode) {
259
- return alias;
260
- }
261
- }
35
+ /**
36
+ * @deprecated Next.js resolves tsconfig `paths` natively.
37
+ * This inert stub will be removed in Nx v25.
38
+ */
39
+ function getAliasForProject(_node, _paths) {
262
40
  return null;
263
41
  }
264
- // Runs a function if the Next.js version satisfies the range.
265
- function forNextVersion(range, fn) {
266
- const semver = require('semver');
267
- const nextJsVersion = require('next/package.json').version;
268
- if (semver.satisfies(nextJsVersion, range, { includePrerelease: true })) {
269
- fn();
270
- }
271
- }
272
- // Support for older generated code: `const withNx = require('@nx/next/plugins/with-nx');`
42
+ // Both import forms exist in generated configs and copied production configs.
273
43
  module.exports = withNx;
274
- // Support for newer generated code: `const { withNx } = require(...);`
275
44
  module.exports.withNx = withNx;
276
45
  module.exports.getNextConfig = getNextConfig;
277
46
  module.exports.getAliasForProject = getAliasForProject;
@@ -25,7 +25,6 @@ const add_swc_to_custom_server_1 = require("../../utils/add-swc-to-custom-server
25
25
  const jest_config_util_1 = require("../../utils/jest-config-util");
26
26
  async function applicationGenerator(host, schema) {
27
27
  return await applicationGeneratorInternal(host, {
28
- addPlugin: false,
29
28
  useProjectJson: true,
30
29
  ...schema,
31
30
  });
@@ -33,7 +32,7 @@ async function applicationGenerator(host, schema) {
33
32
  async function applicationGeneratorInternal(host, schema) {
34
33
  (0, assert_supported_next_version_1.assertSupportedNextVersion)(host);
35
34
  const tasks = [];
36
- const addTsPlugin = (0, internal_3.shouldConfigureTsSolutionSetup)(host, schema.addPlugin, schema.useTsSolution);
35
+ const addTsPlugin = (0, internal_3.shouldConfigureTsSolutionSetup)(host, schema.useTsSolution);
37
36
  const jsInitTask = await (0, js_1.initGenerator)(host, {
38
37
  js: schema.js,
39
38
  skipPackageJson: schema.skipPackageJson,
@@ -1,5 +1,4 @@
1
1
  //@ts-check
2
- <% if (addPlugin) { -%>
3
2
 
4
3
  /** @type {import('next').NextConfig} */
5
4
  const nextConfig = {
@@ -8,24 +7,3 @@ const nextConfig = {
8
7
  };
9
8
 
10
9
  module.exports = nextConfig;
11
- <% } else { -%>
12
-
13
- // eslint-disable-next-line @typescript-eslint/no-var-requires
14
- const { composePlugins, withNx } = require('@nx/next');
15
-
16
- /**
17
- * @type {import('@nx/next/plugins/with-nx').WithNxOptions}
18
- **/
19
- const nextConfig = {
20
- // Use this to set Nx-specific options
21
- // See: https://nx.dev/docs/technologies/react/next/Guides/next-config-setup
22
- nx: {},
23
- };
24
-
25
- const plugins = [
26
- // Add more Next.js plugins to this list if needed.
27
- withNx,
28
- ];
29
-
30
- module.exports = composePlugins(...plugins)(nextConfig);
31
- <% } -%>
@@ -11,7 +11,7 @@ async function addE2e(host, options) {
11
11
  const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
12
12
  ? p === '@nx/next/plugin'
13
13
  : p.plugin === '@nx/next/plugin');
14
- const e2eWebServerInfo = await getNextE2EWebServerInfo(host, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'next.config.js'), options.addPlugin);
14
+ const e2eWebServerInfo = await getNextE2EWebServerInfo(host, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'next.config.js'));
15
15
  if (options.e2eTestRunner === 'cypress') {
16
16
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
17
17
  if (!hasPlugin) {
@@ -98,16 +98,15 @@ async function addE2e(host, options) {
98
98
  enableTypedLinting: (0, internal_2.isTypedLintingEnabled)(options),
99
99
  webServerAddress: e2eWebServerInfo.e2eCiBaseUrl,
100
100
  webServerCommand: e2eWebServerInfo.e2eWebServerCommand,
101
- addPlugin: options.addPlugin,
102
101
  });
103
102
  return e2eTask;
104
103
  }
105
104
  return () => { };
106
105
  }
107
- async function getNextE2EWebServerInfo(tree, projectName, configFilePath, isPluginBeingAdded) {
106
+ async function getNextE2EWebServerInfo(tree, projectName, configFilePath) {
108
107
  const nxJson = (0, devkit_1.readNxJson)(tree);
109
- let e2ePort = isPluginBeingAdded ? 3000 : 4200;
110
- const defaultServeTarget = isPluginBeingAdded ? 'dev' : 'serve';
108
+ let e2ePort = 3000;
109
+ const defaultServeTarget = 'dev';
111
110
  const serveTargetOptions = (0, internal_1.readTargetDefaultsForTarget)(defaultServeTarget, nxJson.targetDefaults)?.options;
112
111
  if (serveTargetOptions?.port) {
113
112
  e2ePort = serveTargetOptions.port;
@@ -123,5 +122,5 @@ async function getNextE2EWebServerInfo(tree, projectName, configFilePath, isPlug
123
122
  defaultE2EWebServerAddress: `http://127.0.0.1:${e2ePort}`,
124
123
  defaultE2ECiBaseUrl: `http://localhost:${e2ePort}`,
125
124
  defaultE2EPort: e2ePort,
126
- }, isPluginBeingAdded);
125
+ });
127
126
  }
@@ -19,7 +19,6 @@ async function addLinting(host, options) {
19
19
  unitTestRunner: options.unitTestRunner,
20
20
  rootProject: options.rootProject,
21
21
  enableTypedLinting: (0, internal_2.isTypedLintingEnabled)(options),
22
- addPlugin: options.addPlugin,
23
22
  skipPackageJson: options.skipPackageJson,
24
23
  }));
25
24
  // Everything below configures ESLint — predefined configs, `extends`, ignore
@@ -1,55 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addProject = addProject;
4
- const internal_1 = require("@nx/devkit/internal");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const versions_1 = require("../../../utils/versions");
7
- const deprecation_1 = require("../../../utils/deprecation");
8
6
  const react_1 = require("@nx/react");
9
7
  function addProject(host, options) {
10
- const targets = {};
11
- // Check if plugin exists in nx.json and if it doesn't then we can continue
12
- // with the default targets.
13
- const nxJson = (0, devkit_1.readNxJson)(host);
14
- const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
15
- ? p === '@nx/next/plugin'
16
- : p.plugin === '@nx/next/plugin');
17
- if (!hasPlugin) {
18
- (0, deprecation_1.warnNextExecutorGenerating)();
19
- (0, internal_1.addBuildTargetDefaults)(host, '@nx/next:build');
20
- targets.build = {
21
- executor: '@nx/next:build',
22
- outputs: ['{options.outputPath}'],
23
- defaultConfiguration: 'production',
24
- options: {
25
- outputPath: options.outputPath,
26
- },
27
- configurations: {
28
- development: {
29
- outputPath: options.appProjectRoot,
30
- },
31
- production: {},
32
- },
33
- };
34
- targets.serve = {
35
- executor: '@nx/next:server',
36
- defaultConfiguration: 'development',
37
- options: {
38
- buildTarget: `${options.projectName}:build`,
39
- dev: true,
40
- },
41
- configurations: {
42
- development: {
43
- buildTarget: `${options.projectName}:build:development`,
44
- dev: true,
45
- },
46
- production: {
47
- buildTarget: `${options.projectName}:build:production`,
48
- dev: false,
49
- },
50
- },
51
- };
52
- }
53
8
  const sourceRoot = options.src
54
9
  ? (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src')
55
10
  : options.appProjectRoot;
@@ -57,7 +12,7 @@ function addProject(host, options) {
57
12
  root: options.appProjectRoot,
58
13
  sourceRoot,
59
14
  projectType: 'application',
60
- targets,
15
+ targets: {},
61
16
  tags: options.parsedTags,
62
17
  };
63
18
  const packageJson = {
@@ -23,7 +23,6 @@ async function addVitest(host, options) {
23
23
  // Next.js builds with its own toolchain, so the project has no vite config
24
24
  // to extend. Write a standalone vitest config below instead.
25
25
  skipViteConfig: true,
26
- addPlugin: options.addPlugin,
27
26
  skipPackageJson: options.skipPackageJson,
28
27
  skipFormat: true,
29
28
  });
@@ -14,10 +14,6 @@ async function normalizeOptions(host, options) {
14
14
  rootProject: options.rootProject,
15
15
  });
16
16
  options.rootProject = appProjectRoot === '.';
17
- const nxJson = (0, devkit_1.readNxJson)(host);
18
- const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
19
- nxJson.useInferencePlugins !== false;
20
- options.addPlugin ??= addPlugin;
21
17
  const isTsSolutionSetup = options.useTsSolution || (0, internal_2.isUsingTsSolutionSetup)(host);
22
18
  const appProjectName = !isTsSolutionSetup || options.name ? projectName : importPath;
23
19
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
@@ -23,7 +23,6 @@ export interface Schema {
23
23
  src?: boolean;
24
24
  // Internal options
25
25
  rootProject?: boolean;
26
- addPlugin?: boolean;
27
26
  useTsSolution?: boolean;
28
27
  formatter?: 'prettier' | 'oxfmt' | 'none';
29
28
  useProjectJson?: boolean;