@nx/next 16.4.0 → 16.5.0-beta.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/package.json +9 -10
- package/plugins/with-nx.d.ts +4 -0
- package/plugins/with-nx.js +29 -48
- package/src/executors/server/server.impl.js +4 -1
- package/src/utils/config.d.ts +1 -2
- package/src/utils/config.js +1 -41
- package/src/utils/config.fixture.d.ts +0 -0
- package/src/utils/config.fixture.js +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/next",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.5.0-beta.0",
|
|
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": {
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@babel/plugin-proposal-decorators": "^7.14.5",
|
|
38
|
-
"@nrwl/next": "16.
|
|
39
|
-
"@nx/devkit": "16.
|
|
40
|
-
"@nx/js": "16.
|
|
41
|
-
"@nx/linter": "16.
|
|
42
|
-
"@nx/react": "16.
|
|
43
|
-
"@nx/web": "16.
|
|
44
|
-
"@nx/workspace": "16.
|
|
38
|
+
"@nrwl/next": "16.5.0-beta.0",
|
|
39
|
+
"@nx/devkit": "16.5.0-beta.0",
|
|
40
|
+
"@nx/js": "16.5.0-beta.0",
|
|
41
|
+
"@nx/linter": "16.5.0-beta.0",
|
|
42
|
+
"@nx/react": "16.5.0-beta.0",
|
|
43
|
+
"@nx/web": "16.5.0-beta.0",
|
|
44
|
+
"@nx/workspace": "16.5.0-beta.0",
|
|
45
45
|
"@svgr/webpack": "^8.0.1",
|
|
46
46
|
"chalk": "^4.1.0",
|
|
47
47
|
"copy-webpack-plugin": "^10.2.4",
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"semver": "7.5.3",
|
|
54
54
|
"ts-node": "10.9.1",
|
|
55
55
|
"tsconfig-paths": "^4.1.2",
|
|
56
|
-
"tsconfig-paths-webpack-plugin": "4.0.0",
|
|
57
56
|
"url-loader": "^4.1.1",
|
|
58
57
|
"webpack-merge": "^5.8.0"
|
|
59
58
|
},
|
|
@@ -61,5 +60,5 @@
|
|
|
61
60
|
"access": "public"
|
|
62
61
|
},
|
|
63
62
|
"types": "./index.d.ts",
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "376d656cfc7f6390ff1cd6d9de348baf7bccbf33"
|
|
65
64
|
}
|
package/plugins/with-nx.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WARNING: Do not add development dependencies to top-level imports.
|
|
3
|
+
* Instead, `require` them inline during the build phase.
|
|
4
|
+
*/
|
|
1
5
|
import type { NextConfig } from 'next';
|
|
2
6
|
import type { NextConfigFn } from '../src/utils/config';
|
|
3
7
|
import type { ProjectGraphProjectNode } from '@nx/devkit';
|
package/plugins/with-nx.js
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withNx = exports.forNextVersion = exports.getAliasForProject = exports.getNextConfig = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
/**
|
|
6
|
-
* WARNING: Do not add development dependencies to top-level imports.
|
|
7
|
-
* Instead, `require` them inline during the build phase.
|
|
8
|
-
*/
|
|
9
|
-
const path = require("path");
|
|
10
5
|
function regexEqual(x, y) {
|
|
11
6
|
return (x instanceof RegExp &&
|
|
12
7
|
y instanceof RegExp &&
|
|
@@ -26,49 +21,31 @@ function getWithNxContext() {
|
|
|
26
21
|
libsDir: workspaceLayout().libsDir,
|
|
27
22
|
};
|
|
28
23
|
}
|
|
29
|
-
function getTargetConfig(graph, target) {
|
|
30
|
-
const projectNode = graph.nodes[target.project];
|
|
31
|
-
return projectNode.data.targets[target.target];
|
|
32
|
-
}
|
|
33
|
-
function getOptions(graph, target) {
|
|
34
|
-
const targetConfig = getTargetConfig(graph, target);
|
|
35
|
-
const options = targetConfig.options;
|
|
36
|
-
if (target.configuration) {
|
|
37
|
-
Object.assign(options, targetConfig.configurations[target.configuration]);
|
|
38
|
-
}
|
|
39
|
-
return options;
|
|
40
|
-
}
|
|
41
24
|
function getNxContext(graph, target) {
|
|
42
25
|
const { parseTargetString } = require('@nx/devkit');
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
options: getOptions(graph, target),
|
|
49
|
-
projectName: target.project,
|
|
50
|
-
targetName: target.target,
|
|
51
|
-
configurationName: target.configuration,
|
|
52
|
-
};
|
|
26
|
+
const projectNode = graph.nodes[target.project];
|
|
27
|
+
const targetConfig = projectNode.data.targets[target.target];
|
|
28
|
+
const targetOptions = targetConfig.options;
|
|
29
|
+
if (target.configuration) {
|
|
30
|
+
Object.assign(targetOptions, targetConfig.configurations[target.configuration]);
|
|
53
31
|
}
|
|
54
|
-
const targetOptions = getOptions(graph, target);
|
|
55
|
-
// If we are running serve or export pull the options from the dependent target first (ex. build)
|
|
56
32
|
if (targetOptions.devServerTarget) {
|
|
57
|
-
|
|
58
|
-
return getNxContext(graph, devServerTarget);
|
|
59
|
-
}
|
|
60
|
-
else if ([
|
|
61
|
-
'@nx/next:server',
|
|
62
|
-
'@nx/next:export',
|
|
63
|
-
'@nrwl/next:server',
|
|
64
|
-
'@nrwl/next:export',
|
|
65
|
-
].includes(targetConfig.executor)) {
|
|
66
|
-
const buildTarget = parseTargetString(targetOptions.buildTarget, graph);
|
|
67
|
-
return getNxContext(graph, buildTarget);
|
|
33
|
+
// Executors such as @nx/cypress:cypress define the devServerTarget option.
|
|
34
|
+
return getNxContext(graph, parseTargetString(targetOptions.devServerTarget, graph));
|
|
68
35
|
}
|
|
69
|
-
else {
|
|
70
|
-
|
|
36
|
+
else if (targetOptions.buildTarget) {
|
|
37
|
+
// Executors such as @nx/next:server or @nx/next:export define the buildTarget option.
|
|
38
|
+
return getNxContext(graph, parseTargetString(targetOptions.buildTarget, graph));
|
|
71
39
|
}
|
|
40
|
+
// Default case, return info for current target.
|
|
41
|
+
// This could be a build using @nx/next:build or run-commands without using our executors.
|
|
42
|
+
return {
|
|
43
|
+
node: graph.nodes[target.project],
|
|
44
|
+
options: targetOptions,
|
|
45
|
+
projectName: target.project,
|
|
46
|
+
targetName: target.target,
|
|
47
|
+
configurationName: target.configuration,
|
|
48
|
+
};
|
|
72
49
|
}
|
|
73
50
|
/**
|
|
74
51
|
* 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).
|
|
@@ -118,14 +95,18 @@ function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
|
118
95
|
}
|
|
119
96
|
}
|
|
120
97
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
98
|
+
// outputPath may be undefined if using run-commands or other executors other than @nx/next:build.
|
|
99
|
+
// In this case, the user should set distDir in their next.config.js.
|
|
100
|
+
if (options.outputPath) {
|
|
101
|
+
const outputDir = `${offsetFromRoot(projectDirectory)}${options.outputPath}`;
|
|
102
|
+
nextConfig.distDir =
|
|
103
|
+
nextConfig.distDir && nextConfig.distDir !== '.next'
|
|
104
|
+
? joinPathFragments(outputDir, nextConfig.distDir)
|
|
105
|
+
: joinPathFragments(outputDir, '.next');
|
|
106
|
+
}
|
|
126
107
|
const userWebpackConfig = nextConfig.webpack;
|
|
127
108
|
const { createWebpackConfig } = require('../src/utils/config');
|
|
128
|
-
nextConfig.webpack = (a, b) => createWebpackConfig(workspaceRoot, projectDirectory, options.fileReplacements, options.assets
|
|
109
|
+
nextConfig.webpack = (a, b) => createWebpackConfig(workspaceRoot, projectDirectory, options.fileReplacements, options.assets)(userWebpackConfig ? userWebpackConfig(a, b) : a, b);
|
|
129
110
|
return nextConfig;
|
|
130
111
|
}
|
|
131
112
|
});
|
|
@@ -27,7 +27,10 @@ function serveExecutor(options, context) {
|
|
|
27
27
|
: 'production';
|
|
28
28
|
// Setting port that the custom server should use.
|
|
29
29
|
process.env.PORT = `${options.port}`;
|
|
30
|
-
const args = (0, create_cli_options_1.createCliOptions)({ port,
|
|
30
|
+
const args = (0, create_cli_options_1.createCliOptions)({ port, hostname });
|
|
31
|
+
if (keepAliveTimeout && !options.dev) {
|
|
32
|
+
args.push(`--keepAliveTimeout=${keepAliveTimeout}`);
|
|
33
|
+
}
|
|
31
34
|
const nextDir = (0, path_1.resolve)(context.root, buildOptions.outputPath);
|
|
32
35
|
const mode = options.dev ? 'dev' : 'start';
|
|
33
36
|
const turbo = options.turbo && options.dev ? '--turbo' : '';
|
package/src/utils/config.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { NextConfig } from 'next';
|
|
2
2
|
import { Configuration } from 'webpack';
|
|
3
3
|
import { FileReplacement } from './types';
|
|
4
|
-
import { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils';
|
|
5
4
|
export interface NextConfigFn {
|
|
6
5
|
(phase: string, context?: any): Promise<NextConfig> | NextConfig;
|
|
7
6
|
}
|
|
@@ -11,4 +10,4 @@ export interface NextPlugin {
|
|
|
11
10
|
export interface NextPluginThatReturnsConfigFn {
|
|
12
11
|
(config: NextConfig): NextConfigFn;
|
|
13
12
|
}
|
|
14
|
-
export declare function createWebpackConfig(workspaceRoot: string, projectRoot: string, fileReplacements?: FileReplacement[], assets?: any
|
|
13
|
+
export declare function createWebpackConfig(workspaceRoot: string, projectRoot: string, fileReplacements?: FileReplacement[], assets?: any): (a: any, b: any) => Configuration;
|
package/src/utils/config.js
CHANGED
|
@@ -2,24 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createWebpackConfig = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin");
|
|
6
5
|
const create_copy_plugin_1 = require("./create-copy-plugin");
|
|
7
|
-
|
|
8
|
-
function createWebpackConfig(workspaceRoot, projectRoot, fileReplacements = [], assets = null, dependencies = [], libsDir = '') {
|
|
6
|
+
function createWebpackConfig(workspaceRoot, projectRoot, fileReplacements = [], assets = null) {
|
|
9
7
|
return function webpackConfig(config, { isServer, }) {
|
|
10
|
-
const mainFields = ['es2015', 'module', 'main'];
|
|
11
|
-
const extensions = ['.ts', '.tsx', '.mjs', '.js', '.jsx'];
|
|
12
|
-
let tsConfigPath = (0, path_1.join)(workspaceRoot, projectRoot, 'tsconfig.json');
|
|
13
|
-
if (dependencies.length > 0) {
|
|
14
|
-
tsConfigPath = (0, buildable_libs_utils_1.createTmpTsConfig)(tsConfigPath, workspaceRoot, projectRoot, dependencies);
|
|
15
|
-
}
|
|
16
|
-
config.resolve.plugins = [
|
|
17
|
-
new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({
|
|
18
|
-
configFile: tsConfigPath,
|
|
19
|
-
extensions,
|
|
20
|
-
mainFields,
|
|
21
|
-
}),
|
|
22
|
-
];
|
|
23
8
|
fileReplacements
|
|
24
9
|
.map((fileReplacement) => ({
|
|
25
10
|
replace: (0, path_1.resolve)(workspaceRoot, fileReplacement.replace),
|
|
@@ -29,22 +14,6 @@ function createWebpackConfig(workspaceRoot, projectRoot, fileReplacements = [],
|
|
|
29
14
|
alias[replacement.replace] = replacement.with;
|
|
30
15
|
return alias;
|
|
31
16
|
}, config.resolve.alias);
|
|
32
|
-
// Apply any rules that work on ts files to the libsDir as well
|
|
33
|
-
const rulesToAdd = [];
|
|
34
|
-
for (const r of config.module.rules) {
|
|
35
|
-
if (typeof r === 'string') {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (isTsRule(r)) {
|
|
39
|
-
rulesToAdd.push(Object.assign(Object.assign({}, r), { include: [libsDir] }));
|
|
40
|
-
}
|
|
41
|
-
else if (r.oneOf && r.oneOf.find(isTsRule)) {
|
|
42
|
-
rulesToAdd.push(Object.assign(Object.assign({}, r), { oneOf: r.oneOf
|
|
43
|
-
.filter(isTsRule)
|
|
44
|
-
.map((subRule) => (Object.assign(Object.assign({}, subRule), { include: [libsDir] }))) }));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
config.module.rules.push(...rulesToAdd);
|
|
48
17
|
// Copy (shared) assets to `public` folder during client-side compilation
|
|
49
18
|
if (!isServer && Array.isArray(assets) && assets.length > 0) {
|
|
50
19
|
config.plugins.push((0, create_copy_plugin_1.createCopyPlugin)(assets, workspaceRoot, projectRoot));
|
|
@@ -53,12 +22,3 @@ function createWebpackConfig(workspaceRoot, projectRoot, fileReplacements = [],
|
|
|
53
22
|
};
|
|
54
23
|
}
|
|
55
24
|
exports.createWebpackConfig = createWebpackConfig;
|
|
56
|
-
function isTsRule(r) {
|
|
57
|
-
if (typeof r === 'string') {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
if (!(r.test instanceof RegExp)) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return r.test.test('a.ts');
|
|
64
|
-
}
|
|
File without changes
|