@nx/next 17.2.0-beta.9 → 17.2.0-canary.20231207-b8d24e6
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/package.json +8 -8
- package/plugin.d.ts +1 -0
- package/plugin.js +5 -0
- package/plugins/with-nx.d.ts +1 -1
- package/plugins/with-nx.js +18 -13
- package/src/executors/export/export.impl.js +5 -3
- package/src/executors/server/server.impl.js +1 -1
- package/src/generators/application/lib/add-e2e.js +8 -4
- package/src/generators/application/lib/add-plugin.d.ts +2 -0
- package/src/generators/application/lib/add-plugin.js +25 -0
- package/src/generators/application/lib/add-project.js +41 -33
- package/src/generators/component/component.js +1 -0
- package/src/generators/init/init.js +4 -0
- package/src/generators/init/lib/add-plugin.d.ts +2 -0
- package/src/generators/init/lib/add-plugin.js +25 -0
- package/src/plugins/plugin.d.ts +8 -0
- package/src/plugins/plugin.js +145 -0
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/next",
|
|
3
|
-
"version": "17.2.0-
|
|
3
|
+
"version": "17.2.0-canary.20231207-b8d24e6",
|
|
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,6 +34,7 @@
|
|
|
34
34
|
"next": ">=13.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@nx/devkit": "17.2.0-canary.20231207-b8d24e6",
|
|
37
38
|
"@babel/plugin-proposal-decorators": "^7.22.7",
|
|
38
39
|
"@svgr/webpack": "^8.0.1",
|
|
39
40
|
"chalk": "^4.1.0",
|
|
@@ -44,13 +45,12 @@
|
|
|
44
45
|
"url-loader": "^4.1.1",
|
|
45
46
|
"tslib": "^2.3.0",
|
|
46
47
|
"webpack-merge": "^5.8.0",
|
|
47
|
-
"@nx/
|
|
48
|
-
"@nx/
|
|
49
|
-
"@nx/
|
|
50
|
-
"@nx/
|
|
51
|
-
"@nx/
|
|
52
|
-
"@
|
|
53
|
-
"@nrwl/next": "17.2.0-beta.9"
|
|
48
|
+
"@nx/js": "17.2.0-canary.20231207-b8d24e6",
|
|
49
|
+
"@nx/eslint": "17.2.0-canary.20231207-b8d24e6",
|
|
50
|
+
"@nx/react": "17.2.0-canary.20231207-b8d24e6",
|
|
51
|
+
"@nx/web": "17.2.0-canary.20231207-b8d24e6",
|
|
52
|
+
"@nx/workspace": "17.2.0-canary.20231207-b8d24e6",
|
|
53
|
+
"@nrwl/next": "17.2.0-canary.20231207-b8d24e6"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
package/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createNodes, NextPluginOptions } from './src/plugins/plugin';
|
package/plugin.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNodes = void 0;
|
|
4
|
+
var plugin_1 = require("./src/plugins/plugin");
|
|
5
|
+
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
package/plugins/with-nx.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { NextConfig } from 'next';
|
|
6
6
|
import type { NextConfigFn } from '../src/utils/config';
|
|
7
|
-
import type
|
|
7
|
+
import { type ProjectGraphProjectNode } from '@nx/devkit';
|
|
8
8
|
export interface WithNxOptions extends NextConfig {
|
|
9
9
|
nx?: {
|
|
10
10
|
svgr?: boolean;
|
package/plugins/with-nx.js
CHANGED
|
@@ -36,6 +36,7 @@ const baseNXEnvironmentVariables = [
|
|
|
36
36
|
'NX_MAPPINGS',
|
|
37
37
|
'NX_FILE_TO_RUN',
|
|
38
38
|
'NX_NEXT_PUBLIC_DIR',
|
|
39
|
+
'NX_CYPRESS_COMPONENT_TEST',
|
|
39
40
|
];
|
|
40
41
|
function regexEqual(x, y) {
|
|
41
42
|
return (x instanceof RegExp &&
|
|
@@ -94,8 +95,9 @@ function getNxContext(graph, target) {
|
|
|
94
95
|
*/
|
|
95
96
|
function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
96
97
|
return async (phase) => {
|
|
97
|
-
const { PHASE_PRODUCTION_SERVER } = await Promise.resolve().then(() => require('next/constants'));
|
|
98
|
-
if (
|
|
98
|
+
const { PHASE_PRODUCTION_SERVER, PHASE_DEVELOPMENT_SERVER } = await Promise.resolve().then(() => require('next/constants'));
|
|
99
|
+
if (PHASE_PRODUCTION_SERVER === phase ||
|
|
100
|
+
!process.env.NX_TASK_TARGET_TARGET) {
|
|
99
101
|
// If we are running an already built production server, just return the configuration.
|
|
100
102
|
// NOTE: Avoid any `require(...)` or `import(...)` statements here. Development dependencies are not available at production runtime.
|
|
101
103
|
const { nx, ...validNextConfig } = _nextConfig;
|
|
@@ -105,22 +107,23 @@ function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
|
105
107
|
};
|
|
106
108
|
}
|
|
107
109
|
else {
|
|
108
|
-
const { createProjectGraphAsync, joinPathFragments, offsetFromRoot, workspaceRoot, } = require('@nx/devkit');
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
const { createProjectGraphAsync, readCachedProjectGraph, joinPathFragments, offsetFromRoot, workspaceRoot, } = require('@nx/devkit');
|
|
111
|
+
let graph = readCachedProjectGraph();
|
|
112
|
+
if (!graph) {
|
|
113
|
+
try {
|
|
114
|
+
graph = await createProjectGraphAsync();
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
throw new Error('Could not create project graph. Please ensure that your workspace is valid.');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
112
120
|
const originalTarget = {
|
|
113
121
|
project: process.env.NX_TASK_TARGET_PROJECT,
|
|
114
122
|
target: process.env.NX_TASK_TARGET_TARGET,
|
|
115
123
|
configuration: process.env.NX_TASK_TARGET_CONFIGURATION,
|
|
116
124
|
};
|
|
117
|
-
const { node: projectNode, options, projectName: project,
|
|
125
|
+
const { node: projectNode, options, projectName: project, } = getNxContext(graph, originalTarget);
|
|
118
126
|
const projectDirectory = projectNode.data.root;
|
|
119
|
-
if (options.buildLibsFromSource === false && targetName) {
|
|
120
|
-
const { calculateProjectDependencies, } = require('@nx/js/src/utils/buildable-libs-utils');
|
|
121
|
-
const result = calculateProjectDependencies(graph, workspaceRoot, project, targetName, configurationName);
|
|
122
|
-
dependencies = result.dependencies;
|
|
123
|
-
}
|
|
124
127
|
// Get next config
|
|
125
128
|
const nextConfig = getNextConfig(_nextConfig, context);
|
|
126
129
|
// For Next.js 13.1 and greater, make sure workspace libs are transpiled.
|
|
@@ -144,8 +147,10 @@ function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
|
144
147
|
process.env.NX_NEXT_OUTPUT_PATH || options.outputPath;
|
|
145
148
|
// outputPath may be undefined if using run-commands or other executors other than @nx/next:build.
|
|
146
149
|
// In this case, the user should set distDir in their next.config.js.
|
|
147
|
-
if (options.outputPath) {
|
|
150
|
+
if (options.outputPath && phase !== PHASE_DEVELOPMENT_SERVER) {
|
|
148
151
|
const outputDir = `${offsetFromRoot(projectDirectory)}${options.outputPath}`;
|
|
152
|
+
// If running dev-server, we should keep `.next` inside project directory since Turbopack expects this.
|
|
153
|
+
// See: https://github.com/nrwl/nx/issues/19365
|
|
149
154
|
nextConfig.distDir =
|
|
150
155
|
nextConfig.distDir && nextConfig.distDir !== '.next'
|
|
151
156
|
? joinPathFragments(outputDir, nextConfig.distDir)
|
|
@@ -28,9 +28,11 @@ async function exportExecutor(options, context) {
|
|
|
28
28
|
context.configurationName);
|
|
29
29
|
dependencies = result.dependencies;
|
|
30
30
|
}
|
|
31
|
+
// Returns { project: ProjectGraphNode; target: string; configuration?: string;}
|
|
31
32
|
const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, context);
|
|
32
33
|
try {
|
|
33
|
-
const
|
|
34
|
+
const buildTargetName = (0, devkit_1.targetToTargetString)(buildTarget);
|
|
35
|
+
const args = getBuildTargetCommand(buildTargetName);
|
|
34
36
|
(0, child_process_1.execFileSync)(pmCmd, args, {
|
|
35
37
|
stdio: [0, 1, 2],
|
|
36
38
|
});
|
|
@@ -52,7 +54,7 @@ async function exportExecutor(options, context) {
|
|
|
52
54
|
return { success: true };
|
|
53
55
|
}
|
|
54
56
|
exports.default = exportExecutor;
|
|
55
|
-
function getBuildTargetCommand(
|
|
56
|
-
const cmd = ['nx', 'run',
|
|
57
|
+
function getBuildTargetCommand(buildTarget) {
|
|
58
|
+
const cmd = ['nx', 'run', buildTarget];
|
|
57
59
|
return cmd;
|
|
58
60
|
}
|
|
@@ -11,7 +11,7 @@ async function* serveExecutor(options, context) {
|
|
|
11
11
|
if (options.customServerTarget) {
|
|
12
12
|
return yield* (0, custom_server_impl_1.default)(options, context);
|
|
13
13
|
}
|
|
14
|
-
const buildOptions = (0, devkit_1.readTargetOptions)((0, devkit_1.parseTargetString)(options.buildTarget, context
|
|
14
|
+
const buildOptions = (0, devkit_1.readTargetOptions)((0, devkit_1.parseTargetString)(options.buildTarget, context), context);
|
|
15
15
|
const projectRoot = context.workspace.projects[context.projectName].root;
|
|
16
16
|
const { port, keepAliveTimeout, hostname } = options;
|
|
17
17
|
// This is required for the default custom server to work. See the @nx/next:app generator.
|
|
@@ -5,6 +5,10 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const eslint_1 = require("@nx/eslint");
|
|
6
6
|
const versions_1 = require("../../../utils/versions");
|
|
7
7
|
async function addE2e(host, options) {
|
|
8
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
9
|
+
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
|
|
10
|
+
? p === '@nx/next/plugin'
|
|
11
|
+
: p.plugin === '@nx/next/plugin');
|
|
8
12
|
if (options.e2eTestRunner === 'cypress') {
|
|
9
13
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
10
14
|
(0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
|
|
@@ -20,8 +24,8 @@ async function addE2e(host, options) {
|
|
|
20
24
|
project: options.e2eProjectName,
|
|
21
25
|
directory: 'src',
|
|
22
26
|
skipFormat: true,
|
|
23
|
-
devServerTarget: `${options.projectName}:serve`,
|
|
24
|
-
baseUrl:
|
|
27
|
+
devServerTarget: `${options.projectName}:${hasPlugin ? 'start' : 'serve'}`,
|
|
28
|
+
baseUrl: `http://localhost:${hasPlugin ? '3000' : '4200'}`,
|
|
25
29
|
jsx: true,
|
|
26
30
|
});
|
|
27
31
|
}
|
|
@@ -41,8 +45,8 @@ async function addE2e(host, options) {
|
|
|
41
45
|
js: false,
|
|
42
46
|
linter: options.linter,
|
|
43
47
|
setParserOptionsProject: options.setParserOptionsProject,
|
|
44
|
-
webServerAddress:
|
|
45
|
-
webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.projectName}`,
|
|
48
|
+
webServerAddress: `http://127.0.0.1:${hasPlugin ? '3000' : '4200'}`,
|
|
49
|
+
webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx ${hasPlugin ? 'start' : 'serve'} ${options.projectName}`,
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
52
|
return () => { };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addPlugin = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function addPlugin(tree) {
|
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
7
|
+
nxJson.plugins ??= [];
|
|
8
|
+
for (const plugin of nxJson.plugins) {
|
|
9
|
+
if (typeof plugin === 'string'
|
|
10
|
+
? plugin === '@nx/next/plugin'
|
|
11
|
+
: plugin.plugin === '@nx/next/plugin') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
nxJson.plugins.push({
|
|
16
|
+
plugin: '@nx/next/plugin',
|
|
17
|
+
options: {
|
|
18
|
+
buildTargetName: 'build',
|
|
19
|
+
serveTargetName: 'serve',
|
|
20
|
+
exportTargetName: 'export',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
24
|
+
}
|
|
25
|
+
exports.addPlugin = addPlugin;
|
|
@@ -4,44 +4,52 @@ exports.addProject = void 0;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
function addProject(host, options) {
|
|
6
6
|
const targets = {};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
// Check if plugin exists in nx.json and if it doesn't then we can continue
|
|
8
|
+
// with the default targets.
|
|
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
|
+
if (!hasPlugin) {
|
|
14
|
+
targets.build = {
|
|
15
|
+
executor: '@nx/next:build',
|
|
16
|
+
outputs: ['{options.outputPath}'],
|
|
17
|
+
defaultConfiguration: 'production',
|
|
18
|
+
options: {
|
|
19
|
+
outputPath: options.outputPath,
|
|
17
20
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
buildTarget: `${options.projectName}:build:development`,
|
|
21
|
+
configurations: {
|
|
22
|
+
development: {
|
|
23
|
+
outputPath: options.appProjectRoot,
|
|
24
|
+
},
|
|
25
|
+
production: {},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
targets.serve = {
|
|
29
|
+
executor: '@nx/next:server',
|
|
30
|
+
defaultConfiguration: 'development',
|
|
31
|
+
options: {
|
|
32
|
+
buildTarget: `${options.projectName}:build`,
|
|
31
33
|
dev: true,
|
|
32
34
|
},
|
|
33
|
-
|
|
35
|
+
configurations: {
|
|
36
|
+
development: {
|
|
37
|
+
buildTarget: `${options.projectName}:build:development`,
|
|
38
|
+
dev: true,
|
|
39
|
+
},
|
|
40
|
+
production: {
|
|
41
|
+
buildTarget: `${options.projectName}:build:production`,
|
|
42
|
+
dev: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
targets.export = {
|
|
47
|
+
executor: '@nx/next:export',
|
|
48
|
+
options: {
|
|
34
49
|
buildTarget: `${options.projectName}:build:production`,
|
|
35
|
-
dev: false,
|
|
36
50
|
},
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
targets.export = {
|
|
40
|
-
executor: '@nx/next:export',
|
|
41
|
-
options: {
|
|
42
|
-
buildTarget: `${options.projectName}:build:production`,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
45
53
|
const project = {
|
|
46
54
|
root: options.appProjectRoot,
|
|
47
55
|
sourceRoot: options.appProjectRoot,
|
|
@@ -7,6 +7,7 @@ const init_1 = require("@nx/react/src/generators/init/init");
|
|
|
7
7
|
const js_1 = require("@nx/js");
|
|
8
8
|
const versions_2 = require("../../utils/versions");
|
|
9
9
|
const add_gitignore_entry_1 = require("../../utils/add-gitignore-entry");
|
|
10
|
+
const add_plugin_1 = require("./lib/add-plugin");
|
|
10
11
|
function updateDependencies(host) {
|
|
11
12
|
return (0, devkit_1.addDependenciesToPackageJson)(host, {
|
|
12
13
|
next: versions_2.nextVersion,
|
|
@@ -54,6 +55,9 @@ async function nextInitGenerator(host, schema) {
|
|
|
54
55
|
tasks.push(installTask);
|
|
55
56
|
}
|
|
56
57
|
(0, add_gitignore_entry_1.addGitIgnoreEntry)(host);
|
|
58
|
+
if (process.env.NX_PCV3 === 'true') {
|
|
59
|
+
(0, add_plugin_1.addPlugin)(host);
|
|
60
|
+
}
|
|
57
61
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
58
62
|
}
|
|
59
63
|
exports.nextInitGenerator = nextInitGenerator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addPlugin = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function addPlugin(tree) {
|
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
7
|
+
nxJson.plugins ??= [];
|
|
8
|
+
for (const plugin of nxJson.plugins) {
|
|
9
|
+
if (typeof plugin === 'string'
|
|
10
|
+
? plugin === '@nx/next/plugin'
|
|
11
|
+
: plugin.plugin === '@nx/next/plugin') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
nxJson.plugins.push({
|
|
16
|
+
plugin: '@nx/next/plugin',
|
|
17
|
+
options: {
|
|
18
|
+
buildTargetName: 'build',
|
|
19
|
+
devTargetName: 'dev',
|
|
20
|
+
startTargetName: 'start',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
24
|
+
}
|
|
25
|
+
exports.addPlugin = addPlugin;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CreateDependencies, CreateNodes } from '@nx/devkit';
|
|
2
|
+
export interface NextPluginOptions {
|
|
3
|
+
buildTargetName?: string;
|
|
4
|
+
devTargetName?: string;
|
|
5
|
+
startTargetName?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const createDependencies: CreateDependencies;
|
|
8
|
+
export declare const createNodes: CreateNodes<NextPluginOptions>;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNodes = exports.createDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
9
|
+
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
10
|
+
const constants_1 = require("next/constants");
|
|
11
|
+
const js_1 = require("@nx/js");
|
|
12
|
+
const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'next.hash');
|
|
13
|
+
const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
|
|
14
|
+
const calculatedTargets = {};
|
|
15
|
+
function readTargetsCache() {
|
|
16
|
+
return (0, devkit_1.readJsonFile)(cachePath);
|
|
17
|
+
}
|
|
18
|
+
function writeTargetsToCache(targets) {
|
|
19
|
+
(0, devkit_1.writeJsonFile)(cachePath, targets);
|
|
20
|
+
}
|
|
21
|
+
const createDependencies = () => {
|
|
22
|
+
writeTargetsToCache(calculatedTargets);
|
|
23
|
+
return [];
|
|
24
|
+
};
|
|
25
|
+
exports.createDependencies = createDependencies;
|
|
26
|
+
// TODO(nicholas): Add support for .mjs files
|
|
27
|
+
exports.createNodes = [
|
|
28
|
+
'**/next.config.{js, cjs}',
|
|
29
|
+
async (configFilePath, options, context) => {
|
|
30
|
+
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
31
|
+
// Do not create a project if package.json and project.json isn't there.
|
|
32
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
33
|
+
if (!siblingFiles.includes('package.json') &&
|
|
34
|
+
!siblingFiles.includes('project.json')) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
options = normalizeOptions(options);
|
|
38
|
+
const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
|
|
39
|
+
(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
|
|
40
|
+
]);
|
|
41
|
+
const targets = targetsCache[hash] ??
|
|
42
|
+
(await buildNextTargets(configFilePath, projectRoot, options, context));
|
|
43
|
+
calculatedTargets[hash] = targets;
|
|
44
|
+
return {
|
|
45
|
+
projects: {
|
|
46
|
+
[projectRoot]: {
|
|
47
|
+
root: projectRoot,
|
|
48
|
+
targets,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
async function buildNextTargets(nextConfigPath, projectRoot, options, context) {
|
|
55
|
+
const nextConfig = getNextConfig(nextConfigPath, context);
|
|
56
|
+
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
57
|
+
const targets = {};
|
|
58
|
+
targets[options.buildTargetName] = await getBuildTargetConfig(namedInputs, projectRoot, nextConfig);
|
|
59
|
+
targets[options.devTargetName] = getDevTargetConfig(projectRoot);
|
|
60
|
+
targets[options.startTargetName] = getStartTargetConfig(options, projectRoot);
|
|
61
|
+
return targets;
|
|
62
|
+
}
|
|
63
|
+
async function getBuildTargetConfig(namedInputs, projectRoot, nextConfig) {
|
|
64
|
+
// Set output path here so that `withNx` can pick it up.
|
|
65
|
+
const targetConfig = {
|
|
66
|
+
command: `next build`,
|
|
67
|
+
options: {
|
|
68
|
+
cwd: projectRoot,
|
|
69
|
+
},
|
|
70
|
+
dependsOn: ['^build'],
|
|
71
|
+
cache: true,
|
|
72
|
+
inputs: getInputs(namedInputs),
|
|
73
|
+
outputs: [await getOutputs(projectRoot, nextConfig)],
|
|
74
|
+
};
|
|
75
|
+
return targetConfig;
|
|
76
|
+
}
|
|
77
|
+
function getDevTargetConfig(projectRoot) {
|
|
78
|
+
const targetConfig = {
|
|
79
|
+
command: `next dev`,
|
|
80
|
+
options: {
|
|
81
|
+
cwd: projectRoot,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
return targetConfig;
|
|
85
|
+
}
|
|
86
|
+
function getStartTargetConfig(options, projectRoot) {
|
|
87
|
+
const targetConfig = {
|
|
88
|
+
command: `next start`,
|
|
89
|
+
options: {
|
|
90
|
+
cwd: projectRoot,
|
|
91
|
+
},
|
|
92
|
+
dependsOn: [options.buildTargetName],
|
|
93
|
+
};
|
|
94
|
+
return targetConfig;
|
|
95
|
+
}
|
|
96
|
+
async function getOutputs(projectRoot, nextConfig) {
|
|
97
|
+
let dir = '.next';
|
|
98
|
+
if (typeof nextConfig === 'function') {
|
|
99
|
+
// Works for both async and sync functions.
|
|
100
|
+
const configResult = await Promise.resolve(nextConfig(constants_1.PHASE_PRODUCTION_BUILD, { defaultConfig: {} }));
|
|
101
|
+
if (configResult?.distDir) {
|
|
102
|
+
dir = configResult?.distDir;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (typeof nextConfig === 'object' && nextConfig?.distDir) {
|
|
106
|
+
// If nextConfig is an object, directly use its 'distDir' property.
|
|
107
|
+
dir = nextConfig.distDir;
|
|
108
|
+
}
|
|
109
|
+
return `{workspaceRoot}/${projectRoot}/${dir}`;
|
|
110
|
+
}
|
|
111
|
+
function getNextConfig(configFilePath, context) {
|
|
112
|
+
const resolvedPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
|
|
113
|
+
const module = load(resolvedPath);
|
|
114
|
+
return module.default ?? module;
|
|
115
|
+
}
|
|
116
|
+
function normalizeOptions(options) {
|
|
117
|
+
options ??= {};
|
|
118
|
+
options.buildTargetName ??= 'build';
|
|
119
|
+
options.devTargetName ??= 'dev';
|
|
120
|
+
options.startTargetName ??= 'start';
|
|
121
|
+
return options;
|
|
122
|
+
}
|
|
123
|
+
function getInputs(namedInputs) {
|
|
124
|
+
return [
|
|
125
|
+
...('production' in namedInputs
|
|
126
|
+
? ['default', '^production']
|
|
127
|
+
: ['default', '^default']),
|
|
128
|
+
{
|
|
129
|
+
externalDependencies: ['next'],
|
|
130
|
+
},
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Load the module after ensuring that the require cache is cleared.
|
|
135
|
+
*/
|
|
136
|
+
function load(path) {
|
|
137
|
+
// Clear cache if the path is in the cache
|
|
138
|
+
if (require.cache[path]) {
|
|
139
|
+
for (const k of Object.keys(require.cache)) {
|
|
140
|
+
delete require.cache[k];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Then require
|
|
144
|
+
return require(path);
|
|
145
|
+
}
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
|
-
export declare const nextVersion = "13.4.
|
|
3
|
-
export declare const eslintConfigNextVersion = "13.4.
|
|
2
|
+
export declare const nextVersion = "13.4.4";
|
|
3
|
+
export declare const eslintConfigNextVersion = "13.4.4";
|
|
4
4
|
export declare const sassVersion = "1.62.1";
|
|
5
5
|
export declare const lessLoader = "11.1.0";
|
|
6
6
|
export declare const emotionServerVersion = "11.11.0";
|
package/src/utils/versions.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tsLibVersion = exports.babelPluginStyledComponentsVersion = exports.emotionServerVersion = exports.lessLoader = exports.sassVersion = exports.eslintConfigNextVersion = exports.nextVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
|
-
exports.nextVersion = '13.4.
|
|
6
|
-
exports.eslintConfigNextVersion = '13.4.
|
|
5
|
+
exports.nextVersion = '13.4.4';
|
|
6
|
+
exports.eslintConfigNextVersion = '13.4.4';
|
|
7
7
|
exports.sassVersion = '1.62.1';
|
|
8
8
|
exports.lessLoader = '11.1.0';
|
|
9
9
|
exports.emotionServerVersion = '11.11.0';
|