@nx/next 24.0.0-pr.37405.acdaf31 → 24.0.0-rc.0
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/dist/plugins/component-testing.js +19 -62
- package/dist/plugins/with-nx.d.ts +14 -10
- package/dist/plugins/with-nx.js +24 -255
- package/dist/ready-check.d.ts +1 -0
- package/dist/ready-check.js +5 -0
- package/dist/src/generators/application/application.js +5 -3
- package/dist/src/generators/application/files/common/next.config.js__tmpl__ +0 -22
- package/dist/src/generators/application/lib/add-e2e.js +9 -10
- package/dist/src/generators/application/lib/add-jest.js +1 -2
- package/dist/src/generators/application/lib/add-linting.js +1 -2
- package/dist/src/generators/application/lib/add-project.js +1 -46
- package/dist/src/generators/application/lib/add-vitest.js +0 -1
- package/dist/src/generators/application/lib/normalize-options.js +0 -4
- package/dist/src/generators/application/schema.d.ts +1 -5
- package/dist/src/generators/application/schema.json +2 -7
- package/dist/src/generators/custom-server/custom-server.d.ts +1 -0
- package/dist/src/generators/custom-server/custom-server.js +10 -25
- package/dist/src/generators/custom-server/files/server/main.ts__tmpl__ +14 -4
- package/dist/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +1 -1
- package/dist/src/generators/cypress-component-configuration/cypress-component-configuration.js +1 -14
- package/dist/src/generators/cypress-component-configuration/schema.d.ts +0 -1
- package/dist/src/generators/init/init.js +14 -28
- package/dist/src/generators/init/schema.d.ts +0 -1
- package/dist/src/generators/library/lib/add-rollup-server-entry.js +7 -16
- package/dist/src/generators/library/lib/normalize-options.js +0 -5
- package/dist/src/generators/library/library.js +1 -2
- package/dist/src/generators/library/schema.d.ts +0 -5
- package/dist/src/generators/library/schema.json +0 -6
- package/dist/src/migrations/update-24-0-0/finish-inferred-conversion.md +12 -0
- package/dist/src/migrations/update-24-0-0/migrate-config-helpers.md +80 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.d.ts +6 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.js +18 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.md +89 -0
- package/dist/src/plugins/plugin.js +5 -0
- package/dist/src/utils/compose-plugins.d.ts +6 -1
- package/dist/src/utils/compose-plugins.js +20 -29
- package/dist/src/utils/deprecation.d.ts +0 -5
- package/dist/src/utils/deprecation.js +9 -31
- package/dist/src/utils/dev-server-ready-check.d.ts +10 -0
- package/dist/src/utils/dev-server-ready-check.js +49 -0
- package/executors.json +1 -12
- package/generators.json +2 -1
- package/migrations.json +12 -0
- package/package.json +21 -13
- package/dist/src/executors/build/build.impl.d.ts +0 -5
- package/dist/src/executors/build/build.impl.js +0 -154
- package/dist/src/executors/build/lib/check-project.d.ts +0 -1
- package/dist/src/executors/build/lib/check-project.js +0 -11
- package/dist/src/executors/build/lib/create-next-config-file.d.ts +0 -14
- package/dist/src/executors/build/lib/create-next-config-file.js +0 -171
- package/dist/src/executors/build/lib/update-package-json.d.ts +0 -3
- package/dist/src/executors/build/lib/update-package-json.js +0 -31
- package/dist/src/executors/build/schema.json +0 -98
- package/dist/src/executors/server/custom-server.impl.d.ts +0 -6
- package/dist/src/executors/server/custom-server.impl.js +0 -37
- package/dist/src/executors/server/schema.json +0 -85
- package/dist/src/executors/server/server.impl.d.ts +0 -6
- package/dist/src/executors/server/server.impl.js +0 -115
- package/dist/src/utils/runtime-version-utils.d.ts +0 -7
- 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 {
|
|
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:
|
|
79
|
-
assets:
|
|
80
|
-
outputPath:
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
*
|
|
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
|
|
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 };
|
package/dist/plugins/with-nx.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
*
|
|
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(
|
|
12
|
+
function withNx(config = {}, _context) {
|
|
64
13
|
return async (phase) => {
|
|
65
|
-
const { PHASE_PRODUCTION_SERVER
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
//
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { waitForNextServer as waitForDevServer } from './src/utils/dev-server-ready-check';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForDevServer = void 0;
|
|
4
|
+
var dev_server_ready_check_1 = require("./src/utils/dev-server-ready-check");
|
|
5
|
+
Object.defineProperty(exports, "waitForDevServer", { enumerable: true, get: function () { return dev_server_ready_check_1.waitForNextServer; } });
|
|
@@ -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.
|
|
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,
|
|
@@ -77,10 +76,13 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
77
76
|
tasks.push(swcTask);
|
|
78
77
|
}
|
|
79
78
|
if (options.customServer) {
|
|
80
|
-
await (0, custom_server_1.customServerGenerator)(host, {
|
|
79
|
+
const customServerTask = await (0, custom_server_1.customServerGenerator)(host, {
|
|
81
80
|
project: options.projectName,
|
|
82
81
|
compiler: options.swc ? 'swc' : 'tsc',
|
|
83
82
|
});
|
|
83
|
+
if (customServerTask) {
|
|
84
|
+
tasks.push(customServerTask);
|
|
85
|
+
}
|
|
84
86
|
}
|
|
85
87
|
if (!options.skipPackageJson) {
|
|
86
88
|
const reactVersions = await (0, internal_2.getReactDependenciesVersionsToInstall)(host);
|
|
@@ -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
|
-
<% } -%>
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addE2e = addE2e;
|
|
4
4
|
const internal_1 = require("@nx/devkit/internal");
|
|
5
|
-
const internal_2 = require("@nx/eslint/internal");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const web_1 = require("@nx/web");
|
|
8
7
|
const versions_1 = require("../../../utils/versions");
|
|
@@ -11,7 +10,7 @@ async function addE2e(host, options) {
|
|
|
11
10
|
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
|
|
12
11
|
? p === '@nx/next/plugin'
|
|
13
12
|
: p.plugin === '@nx/next/plugin');
|
|
14
|
-
const e2eWebServerInfo = await getNextE2EWebServerInfo(host, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'next.config.js')
|
|
13
|
+
const e2eWebServerInfo = await getNextE2EWebServerInfo(host, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'next.config.js'));
|
|
15
14
|
if (options.e2eTestRunner === 'cypress') {
|
|
16
15
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
17
16
|
if (!hasPlugin) {
|
|
@@ -53,7 +52,6 @@ async function addE2e(host, options) {
|
|
|
53
52
|
devServerTarget: e2eWebServerInfo.e2eDevServerTarget,
|
|
54
53
|
baseUrl: e2eWebServerInfo.e2eWebServerAddress,
|
|
55
54
|
jsx: true,
|
|
56
|
-
enableTypedLinting: (0, internal_2.isTypedLintingEnabled)(options),
|
|
57
55
|
webServerCommands: {
|
|
58
56
|
default: e2eWebServerInfo.e2eWebServerCommand,
|
|
59
57
|
},
|
|
@@ -95,19 +93,20 @@ async function addE2e(host, options) {
|
|
|
95
93
|
directory: 'src',
|
|
96
94
|
js: false,
|
|
97
95
|
linter: options.linter,
|
|
98
|
-
enableTypedLinting:
|
|
99
|
-
webServerAddress: e2eWebServerInfo.e2eCiBaseUrl,
|
|
96
|
+
enableTypedLinting: options.enableTypedLinting,
|
|
100
97
|
webServerCommand: e2eWebServerInfo.e2eWebServerCommand,
|
|
101
|
-
|
|
98
|
+
webServerAddress: e2eWebServerInfo.e2eWebServerAddress,
|
|
99
|
+
ciWebServerCommand: e2eWebServerInfo.e2eCiWebServerCommand,
|
|
100
|
+
ciWebServerAddress: e2eWebServerInfo.e2eCiBaseUrl,
|
|
102
101
|
});
|
|
103
102
|
return e2eTask;
|
|
104
103
|
}
|
|
105
104
|
return () => { };
|
|
106
105
|
}
|
|
107
|
-
async function getNextE2EWebServerInfo(tree, projectName, configFilePath
|
|
106
|
+
async function getNextE2EWebServerInfo(tree, projectName, configFilePath) {
|
|
108
107
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
109
|
-
let e2ePort =
|
|
110
|
-
const defaultServeTarget =
|
|
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
|
-
}
|
|
125
|
+
});
|
|
127
126
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addJest = addJest;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const internal_1 = require("@nx/eslint/internal");
|
|
6
5
|
const versions_1 = require("../../../utils/versions");
|
|
7
6
|
async function addJest(host, options) {
|
|
8
7
|
if (options.unitTestRunner !== 'jest') {
|
|
@@ -31,7 +30,7 @@ async function addJest(host, options) {
|
|
|
31
30
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.spec.json'), (json) => {
|
|
32
31
|
json.compilerOptions.jsx = 'react';
|
|
33
32
|
// Override exclude so typed linting doesn't fail on jest.config.ts and jest.config.cts.
|
|
34
|
-
if (
|
|
33
|
+
if (options.enableTypedLinting) {
|
|
35
34
|
const tsConfig = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.json'));
|
|
36
35
|
json.exclude = tsConfig.exclude.filter((e) => e !== 'jest.config.ts' && e !== 'jest.config.cts');
|
|
37
36
|
}
|
|
@@ -18,8 +18,7 @@ async function addLinting(host, options) {
|
|
|
18
18
|
],
|
|
19
19
|
unitTestRunner: options.unitTestRunner,
|
|
20
20
|
rootProject: options.rootProject,
|
|
21
|
-
enableTypedLinting:
|
|
22
|
-
addPlugin: options.addPlugin,
|
|
21
|
+
enableTypedLinting: options.enableTypedLinting,
|
|
23
22
|
skipPackageJson: options.skipPackageJson,
|
|
24
23
|
}));
|
|
25
24
|
// Everything below configures ESLint — predefined configs, `extends`, ignore
|