@nx/next 16.8.0-beta.3 → 16.8.0-beta.5
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 -9
- package/plugins/component-testing.js +14 -8
- package/plugins/with-less.js +19 -14
- package/plugins/with-nx.js +67 -28
- package/plugins/with-stylus.js +18 -14
- package/src/executors/build/build.impl.js +60 -65
- package/src/executors/build/lib/create-next-config-file.js +2 -4
- package/src/executors/build/lib/update-package-json.js +2 -4
- package/src/executors/export/export.impl.js +29 -32
- package/src/executors/server/custom-server.impl.js +27 -45
- package/src/executors/server/server.impl.js +52 -56
- package/src/generators/application/application.js +38 -37
- package/src/generators/application/lib/add-e2e.js +35 -31
- package/src/generators/application/lib/add-jest.js +29 -26
- package/src/generators/application/lib/add-linting.js +50 -47
- package/src/generators/application/lib/add-project.js +3 -1
- package/src/generators/application/lib/create-application-files.js +26 -8
- package/src/generators/application/lib/normalize-options.js +40 -33
- package/src/generators/application/lib/set-defaults.js +5 -7
- package/src/generators/application/lib/update-cypress-tsconfig.js +4 -1
- package/src/generators/component/component.js +16 -13
- package/src/generators/custom-server/custom-server.js +68 -69
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +55 -57
- package/src/generators/init/init.js +36 -33
- package/src/generators/library/lib/normalize-options.js +14 -14
- package/src/generators/library/library.js +52 -47
- package/src/generators/page/page.js +21 -14
- package/src/migrations/update-12-10-0/fix-page-dir-for-eslint.js +23 -24
- package/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.js +13 -16
- package/src/migrations/update-13-0-0/update-emotion-setup.js +24 -27
- package/src/migrations/update-13-0-0/update-to-webpack-5.js +20 -23
- package/src/migrations/update-13-0-3/fix-less.js +15 -18
- package/src/migrations/update-13-1-1/enable-swc.js +28 -32
- package/src/migrations/update-14-0-0/add-default-development-configurations.js +22 -27
- package/src/migrations/update-14-4-3/add-dev-output-path.js +11 -15
- package/src/migrations/update-14-5-3/add-gitignore-entry.js +3 -6
- package/src/migrations/update-14-5-3/update-dev-output-path.js +14 -19
- package/src/migrations/update-14-5-7/update-next-eslint.js +18 -22
- package/src/migrations/update-15-8-8/add-style-packages.js +14 -18
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-3-0/remove-root-build-option.js +10 -13
- package/src/migrations/update-16-4-0/update-nx-next-dependency.js +12 -15
- package/src/utils/compose-plugins.js +12 -15
- package/src/utils/create-copy-plugin.js +6 -4
- package/src/utils/generate-globs.js +1 -1
- package/src/utils/styles.js +31 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/next",
|
|
3
|
-
"version": "16.8.0-beta.
|
|
3
|
+
"version": "16.8.0-beta.5",
|
|
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.22.7",
|
|
38
|
-
"@nrwl/next": "16.8.0-beta.
|
|
39
|
-
"@nx/devkit": "16.8.0-beta.
|
|
40
|
-
"@nx/js": "16.8.0-beta.
|
|
41
|
-
"@nx/linter": "16.8.0-beta.
|
|
42
|
-
"@nx/react": "16.8.0-beta.
|
|
43
|
-
"@nx/web": "16.8.0-beta.
|
|
44
|
-
"@nx/workspace": "16.8.0-beta.
|
|
38
|
+
"@nrwl/next": "16.8.0-beta.5",
|
|
39
|
+
"@nx/devkit": "16.8.0-beta.5",
|
|
40
|
+
"@nx/js": "16.8.0-beta.5",
|
|
41
|
+
"@nx/linter": "16.8.0-beta.5",
|
|
42
|
+
"@nx/react": "16.8.0-beta.5",
|
|
43
|
+
"@nx/web": "16.8.0-beta.5",
|
|
44
|
+
"@nx/workspace": "16.8.0-beta.5",
|
|
45
45
|
"@svgr/webpack": "^8.0.1",
|
|
46
46
|
"chalk": "^4.1.0",
|
|
47
47
|
"copy-webpack-plugin": "^10.2.4",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
58
|
"type": "commonjs",
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "ad2d1e8a55b2d1b358bb5e7483343d9757ff2c53"
|
|
60
60
|
}
|
|
@@ -8,10 +8,9 @@ const react_1 = require("@nx/react");
|
|
|
8
8
|
const webpack_1 = require("@nx/webpack");
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
function nxComponentTestingPreset(pathToConfig, options) {
|
|
11
|
-
var _a, _b;
|
|
12
11
|
const graph = (0, devkit_1.readCachedProjectGraph)();
|
|
13
12
|
const { targets: ctTargets, name: ctProjectName } = (0, ct_helpers_1.getProjectConfigByPath)(graph, pathToConfig);
|
|
14
|
-
const ctTargetName =
|
|
13
|
+
const ctTargetName = options?.ctTargetName || 'component-test';
|
|
15
14
|
const ctConfigurationName = process.env.NX_CYPRESS_TARGET_CONFIGURATION;
|
|
16
15
|
const ctExecutorContext = (0, ct_helpers_1.createExecutorContext)(graph, ctTargets, ctProjectName, ctTargetName, ctConfigurationName);
|
|
17
16
|
const ctExecutorOptions = (0, devkit_1.readTargetOptions)({
|
|
@@ -25,18 +24,18 @@ function nxComponentTestingPreset(pathToConfig, options) {
|
|
|
25
24
|
let buildOuputPath = `dist/${ctProjectName}/.next`;
|
|
26
25
|
if (buildTarget) {
|
|
27
26
|
const parsedBuildTarget = (0, devkit_1.parseTargetString)(buildTarget, graph);
|
|
28
|
-
const buildProjectConfig =
|
|
27
|
+
const buildProjectConfig = graph.nodes[parsedBuildTarget.project]?.data;
|
|
29
28
|
const buildExecutorContext = (0, ct_helpers_1.createExecutorContext)(graph, buildProjectConfig.targets, parsedBuildTarget.project, parsedBuildTarget.target, parsedBuildTarget.configuration);
|
|
30
29
|
const buildExecutorOptions = (0, devkit_1.readTargetOptions)({
|
|
31
30
|
project: parsedBuildTarget.project,
|
|
32
31
|
target: parsedBuildTarget.target,
|
|
33
32
|
configuration: parsedBuildTarget.configuration,
|
|
34
33
|
}, buildExecutorContext);
|
|
35
|
-
buildAssets
|
|
36
|
-
buildFileReplacements
|
|
37
|
-
buildOuputPath
|
|
34
|
+
buildAssets ??= buildExecutorOptions.assets;
|
|
35
|
+
buildFileReplacements ??= buildExecutorOptions.fileReplacements;
|
|
36
|
+
buildOuputPath ??= buildExecutorOptions.outputPath;
|
|
38
37
|
}
|
|
39
|
-
const ctProjectConfig =
|
|
38
|
+
const ctProjectConfig = graph.nodes[ctProjectName]?.data;
|
|
40
39
|
if (!ctProjectConfig) {
|
|
41
40
|
throw new Error((0, devkit_1.stripIndents) `Unable to load project configs from the project graph.
|
|
42
41
|
Provided build target, ${buildTarget}.
|
|
@@ -63,6 +62,13 @@ Able to find CT project, ${!!ctProjectConfig}.`);
|
|
|
63
62
|
options: webpackOptions,
|
|
64
63
|
context: ctExecutorContext,
|
|
65
64
|
});
|
|
66
|
-
return
|
|
65
|
+
return {
|
|
66
|
+
...(0, cypress_preset_1.nxBaseCypressPreset)(__filename),
|
|
67
|
+
specPattern: '**/*.cy.{js,jsx,ts,tsx}',
|
|
68
|
+
devServer: {
|
|
69
|
+
...{ framework: 'react', bundler: 'webpack' },
|
|
70
|
+
webpackConfig,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
67
73
|
}
|
|
68
74
|
exports.nxComponentTestingPreset = nxComponentTestingPreset;
|
package/plugins/with-less.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withLess = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
// Adapted from https://raw.githubusercontent.com/elado/next-with-less/main/src/index.js
|
|
6
5
|
const webpack_merge_1 = require("webpack-merge");
|
|
7
6
|
const addLessToRegExp = (rx) => new RegExp(rx.source.replace('|sass', '|sass|less'), rx.flags);
|
|
8
7
|
function withLess(configOrFn) {
|
|
9
|
-
return (phase) =>
|
|
10
|
-
const baseConfig = typeof configOrFn === 'function' ?
|
|
11
|
-
const { lessLoaderOptions = {}
|
|
8
|
+
return async (phase) => {
|
|
9
|
+
const baseConfig = typeof configOrFn === 'function' ? await configOrFn(phase) : configOrFn;
|
|
10
|
+
const { lessLoaderOptions = {}, ...nextConfig } = baseConfig;
|
|
12
11
|
return Object.assign({}, nextConfig, {
|
|
13
12
|
webpack(config, opts) {
|
|
14
13
|
// there are 2 relevant sass rules in next.js - css modules and global css
|
|
15
14
|
let sassModuleRule;
|
|
16
15
|
// global sass rule (does not exist in server builds)
|
|
17
16
|
let sassGlobalRule;
|
|
18
|
-
const cssRule = config.module.rules.find((rule) =>
|
|
17
|
+
const cssRule = config.module.rules.find((rule) => rule.oneOf?.find((r) => r?.[Symbol.for('__next_css_remove')]));
|
|
19
18
|
const addLessToRuleTest = (test) => {
|
|
20
19
|
if (Array.isArray(test)) {
|
|
21
20
|
return test.map((rx) => addLessToRegExp(rx));
|
|
@@ -25,28 +24,34 @@ function withLess(configOrFn) {
|
|
|
25
24
|
}
|
|
26
25
|
};
|
|
27
26
|
cssRule.oneOf.forEach((rule) => {
|
|
28
|
-
|
|
29
|
-
if ((_a = rule.options) === null || _a === void 0 ? void 0 : _a.__next_css_remove)
|
|
27
|
+
if (rule.options?.__next_css_remove)
|
|
30
28
|
return;
|
|
31
|
-
if (
|
|
29
|
+
if (rule.use?.loader === 'error-loader') {
|
|
32
30
|
rule.test = addLessToRuleTest(rule.test);
|
|
33
31
|
}
|
|
34
|
-
else if (
|
|
32
|
+
else if (rule.use?.loader?.includes('file-loader')) {
|
|
35
33
|
rule.issuer = addLessToRuleTest(rule.issuer);
|
|
36
34
|
}
|
|
37
|
-
else if (
|
|
35
|
+
else if (rule.use?.includes?.('ignore-loader')) {
|
|
38
36
|
rule.test = addLessToRuleTest(rule.test);
|
|
39
37
|
}
|
|
40
|
-
else if (
|
|
38
|
+
else if (rule.test?.source === '\\.module\\.(scss|sass)$') {
|
|
41
39
|
sassModuleRule = rule;
|
|
42
40
|
}
|
|
43
|
-
else if (
|
|
41
|
+
else if (rule.test?.source === '(?<!\\.module)\\.(scss|sass)$') {
|
|
44
42
|
sassGlobalRule = rule;
|
|
45
43
|
}
|
|
46
44
|
});
|
|
47
45
|
const lessLoader = {
|
|
48
46
|
loader: 'less-loader',
|
|
49
|
-
options:
|
|
47
|
+
options: {
|
|
48
|
+
...lessLoaderOptions,
|
|
49
|
+
lessOptions: {
|
|
50
|
+
javascriptEnabled: true,
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
...lessLoaderOptions.lessOptions,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
50
55
|
};
|
|
51
56
|
let lessModuleRule = (0, webpack_merge_1.merge)(sassModuleRule);
|
|
52
57
|
const configureLessRule = (rule) => {
|
|
@@ -67,7 +72,7 @@ function withLess(configOrFn) {
|
|
|
67
72
|
return config;
|
|
68
73
|
},
|
|
69
74
|
});
|
|
70
|
-
}
|
|
75
|
+
};
|
|
71
76
|
}
|
|
72
77
|
exports.withLess = withLess;
|
|
73
78
|
module.exports = withLess;
|
package/plugins/with-nx.js
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withNx = exports.forNextVersion = exports.getAliasForProject = exports.getNextConfig = void 0;
|
|
4
|
-
const
|
|
4
|
+
const baseNXEnvironmentVariables = [
|
|
5
|
+
'NX_BASE',
|
|
6
|
+
'NX_CACHE_DIRECTORY',
|
|
7
|
+
'NX_CACHE_PROJECT_GRAPH',
|
|
8
|
+
'NX_DAEMON',
|
|
9
|
+
'NX_DEFAULT_PROJECT',
|
|
10
|
+
'NX_HEAD',
|
|
11
|
+
'NX_PERF_LOGGING',
|
|
12
|
+
'NX_PROFILE',
|
|
13
|
+
'NX_PROJECT_GRAPH_CACHE_DIRECTORY',
|
|
14
|
+
'NX_PROJECT_GRAPH_MAX_WORKERS',
|
|
15
|
+
'NX_RUNNER',
|
|
16
|
+
'NX_SKIP_NX_CACHE',
|
|
17
|
+
'NX_TASKS_RUNNER',
|
|
18
|
+
'NX_TASKS_RUNNER_DYNAMIC_OUTPUT',
|
|
19
|
+
'NX_VERBOSE_LOGGING',
|
|
20
|
+
'NX_DRY_RUN',
|
|
21
|
+
'NX_INTERACTIVE',
|
|
22
|
+
'NX_GENERATE_QUIET',
|
|
23
|
+
'NX_PREFER_TS_NODE',
|
|
24
|
+
'NX_TASK_TARGET_PROJECT',
|
|
25
|
+
'NX_TASK_TARGET_TARGET',
|
|
26
|
+
'NX_TASK_TARGET_CONFIGURATION',
|
|
27
|
+
'NX_CLI_SET',
|
|
28
|
+
'NX_LOAD_DOT_ENV_FILES',
|
|
29
|
+
'NX_WORKSPACE_ROOT',
|
|
30
|
+
'NX_TASK_HASH',
|
|
31
|
+
'NX_NEXT_DIR',
|
|
32
|
+
];
|
|
5
33
|
function regexEqual(x, y) {
|
|
6
34
|
return (x instanceof RegExp &&
|
|
7
35
|
y instanceof RegExp &&
|
|
@@ -51,19 +79,22 @@ function getNxContext(graph, target) {
|
|
|
51
79
|
* 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).
|
|
52
80
|
*/
|
|
53
81
|
function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
54
|
-
return (phase) =>
|
|
55
|
-
const { PHASE_PRODUCTION_SERVER } =
|
|
82
|
+
return async (phase) => {
|
|
83
|
+
const { PHASE_PRODUCTION_SERVER } = await Promise.resolve().then(() => require('next/constants'));
|
|
56
84
|
if (phase === PHASE_PRODUCTION_SERVER) {
|
|
57
85
|
// If we are running an already built production server, just return the configuration.
|
|
58
86
|
// NOTE: Avoid any `require(...)` or `import(...)` statements here. Development dependencies are not available at production runtime.
|
|
59
|
-
const { nx
|
|
60
|
-
return
|
|
87
|
+
const { nx, ...validNextConfig } = _nextConfig;
|
|
88
|
+
return {
|
|
89
|
+
distDir: '.next',
|
|
90
|
+
...validNextConfig,
|
|
91
|
+
};
|
|
61
92
|
}
|
|
62
93
|
else {
|
|
63
94
|
const { createProjectGraphAsync, joinPathFragments, offsetFromRoot, workspaceRoot, } = require('@nx/devkit');
|
|
64
95
|
// Otherwise, add in webpack and eslint configuration for build or test.
|
|
65
96
|
let dependencies = [];
|
|
66
|
-
const graph =
|
|
97
|
+
const graph = await createProjectGraphAsync();
|
|
67
98
|
const originalTarget = {
|
|
68
99
|
project: process.env.NX_TASK_TARGET_PROJECT,
|
|
69
100
|
target: process.env.NX_TASK_TARGET_TARGET,
|
|
@@ -80,14 +111,13 @@ function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
|
80
111
|
const nextConfig = getNextConfig(_nextConfig, context);
|
|
81
112
|
// For Next.js 13.1 and greater, make sure workspace libs are transpiled.
|
|
82
113
|
forNextVersion('>=13.1.0', () => {
|
|
83
|
-
var _a;
|
|
84
114
|
if (!graph.dependencies[project])
|
|
85
115
|
return;
|
|
86
116
|
const { readTsConfigPaths } = require('@nx/js');
|
|
87
117
|
const { findAllProjectNodeDependencies, } = require('nx/src/utils/project-graph-utils');
|
|
88
118
|
const paths = readTsConfigPaths();
|
|
89
119
|
const deps = findAllProjectNodeDependencies(project);
|
|
90
|
-
|
|
120
|
+
nextConfig.transpilePackages ??= [];
|
|
91
121
|
for (const dep of deps) {
|
|
92
122
|
const alias = getAliasForProject(graph.nodes[dep], paths);
|
|
93
123
|
if (alias) {
|
|
@@ -112,23 +142,28 @@ function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
|
112
142
|
nextConfig.webpack = (a, b) => createWebpackConfig(workspaceRoot, projectDirectory, options.fileReplacements, options.assets)(userWebpackConfig ? userWebpackConfig(a, b) : a, b);
|
|
113
143
|
return nextConfig;
|
|
114
144
|
}
|
|
115
|
-
}
|
|
145
|
+
};
|
|
116
146
|
}
|
|
117
147
|
exports.withNx = withNx;
|
|
118
148
|
function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
|
|
119
|
-
var _a;
|
|
120
149
|
// If `next-compose-plugins` is used, the context argument is invalid.
|
|
121
150
|
if (!context.libsDir || !context.workspaceRoot) {
|
|
122
151
|
context = getWithNxContext();
|
|
123
152
|
}
|
|
124
153
|
const userWebpack = nextConfig.webpack || ((x) => x);
|
|
125
|
-
const { nx
|
|
126
|
-
return
|
|
154
|
+
const { nx, ...validNextConfig } = nextConfig;
|
|
155
|
+
return {
|
|
156
|
+
eslint: {
|
|
157
|
+
ignoreDuringBuilds: true,
|
|
158
|
+
...(validNextConfig.eslint ?? {}),
|
|
159
|
+
},
|
|
160
|
+
...validNextConfig,
|
|
161
|
+
webpack: (config, options) => {
|
|
127
162
|
/*
|
|
128
163
|
* Update babel to support our monorepo setup.
|
|
129
164
|
* The 'upward' mode allows the root babel.config.json and per-project .babelrc files to be picked up.
|
|
130
165
|
*/
|
|
131
|
-
if (nx
|
|
166
|
+
if (nx?.babelUpwardRootMode) {
|
|
132
167
|
options.defaultLoaders.babel.options.babelrc = true;
|
|
133
168
|
options.defaultLoaders.babel.options.rootMode = 'upward';
|
|
134
169
|
}
|
|
@@ -185,10 +220,7 @@ function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
|
|
|
185
220
|
/**
|
|
186
221
|
* 4. Modify css loader to allow global css from node_modules to be imported from workspace libs
|
|
187
222
|
*/
|
|
188
|
-
const nextGlobalCssLoader = nextCssLoaders.oneOf.find((rule) =>
|
|
189
|
-
var _a, _b;
|
|
190
|
-
return (_b = (_a = rule.include) === null || _a === void 0 ? void 0 : _a.and) === null || _b === void 0 ? void 0 : _b.find((include) => regexEqual(include, /node_modules/));
|
|
191
|
-
});
|
|
223
|
+
const nextGlobalCssLoader = nextCssLoaders.oneOf.find((rule) => rule.include?.and?.find((include) => regexEqual(include, /node_modules/)));
|
|
192
224
|
// Might not be found if Next.js webpack config changes in the future
|
|
193
225
|
if (nextGlobalCssLoader && nextGlobalCssLoader.issuer) {
|
|
194
226
|
nextGlobalCssLoader.issuer.or = nextGlobalCssLoader.issuer.and
|
|
@@ -204,7 +236,7 @@ function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
|
|
|
204
236
|
* 6. Add SVGR support if option is on.
|
|
205
237
|
*/
|
|
206
238
|
// Default SVGR support to be on for projects.
|
|
207
|
-
if (
|
|
239
|
+
if (nx?.svgr !== false) {
|
|
208
240
|
config.module.rules.push({
|
|
209
241
|
test: /\.svg$/,
|
|
210
242
|
oneOf: [
|
|
@@ -241,9 +273,13 @@ function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
|
|
|
241
273
|
});
|
|
242
274
|
}
|
|
243
275
|
return userWebpack(config, options);
|
|
244
|
-
}
|
|
276
|
+
},
|
|
277
|
+
};
|
|
245
278
|
}
|
|
246
279
|
exports.getNextConfig = getNextConfig;
|
|
280
|
+
function getNonBaseVariables(oldEnv) {
|
|
281
|
+
return Object.keys(oldEnv).filter((env) => !baseNXEnvironmentVariables.includes(env));
|
|
282
|
+
}
|
|
247
283
|
function getNxEnvironmentVariables() {
|
|
248
284
|
return Object.keys(process.env)
|
|
249
285
|
.filter((env) => /^NX_/i.test(env))
|
|
@@ -252,11 +288,13 @@ function getNxEnvironmentVariables() {
|
|
|
252
288
|
return env;
|
|
253
289
|
}, {});
|
|
254
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* TODO(v18)
|
|
293
|
+
* @deprecated Use Next.js 9.4+ built-in support for environment variables. Reference https://nextjs.org/docs/pages/api-reference/next-config-js/env
|
|
294
|
+
*/
|
|
255
295
|
function addNxEnvVariables(config) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
var _a;
|
|
259
|
-
return (_a = plugin.definitions) === null || _a === void 0 ? void 0 : _a['process.env.NODE_ENV'];
|
|
296
|
+
const maybeDefinePlugin = config.plugins?.find((plugin) => {
|
|
297
|
+
return plugin.definitions?.['process.env.NODE_ENV'];
|
|
260
298
|
});
|
|
261
299
|
if (maybeDefinePlugin) {
|
|
262
300
|
const env = getNxEnvironmentVariables();
|
|
@@ -264,16 +302,17 @@ function addNxEnvVariables(config) {
|
|
|
264
302
|
.map(([name, value]) => [`process.env.${name}`, `"${value}"`])
|
|
265
303
|
.filter(([name]) => !maybeDefinePlugin.definitions[name])
|
|
266
304
|
.forEach(([name, value]) => (maybeDefinePlugin.definitions[name] = value));
|
|
305
|
+
const vars = getNonBaseVariables(env);
|
|
306
|
+
if (vars.length > 0) {
|
|
307
|
+
console.warn(`Warning, in Nx 18 environment variables starting with NX_ will not be available in the browser, and currently will not work with @nx/next:server executor.\nPlease rename the following environment variables: ${vars.join(', ')} using Next.js' built-in support for environment variables. Reference https://nextjs.org/docs/pages/api-reference/next-config-js/env`);
|
|
308
|
+
}
|
|
267
309
|
}
|
|
268
310
|
}
|
|
269
311
|
function getAliasForProject(node, paths) {
|
|
270
312
|
// Match workspace libs to their alias in tsconfig paths.
|
|
271
313
|
for (const [alias, lookup] of Object.entries(paths)) {
|
|
272
|
-
const lookupContainsDepNode = lookup.some((lookupPath) =>
|
|
273
|
-
|
|
274
|
-
return lookupPath.startsWith((_a = node === null || node === void 0 ? void 0 : node.data) === null || _a === void 0 ? void 0 : _a.root) ||
|
|
275
|
-
lookupPath.startsWith('./' + ((_b = node === null || node === void 0 ? void 0 : node.data) === null || _b === void 0 ? void 0 : _b.root));
|
|
276
|
-
});
|
|
314
|
+
const lookupContainsDepNode = lookup.some((lookupPath) => lookupPath.startsWith(node?.data?.root) ||
|
|
315
|
+
lookupPath.startsWith('./' + node?.data?.root));
|
|
277
316
|
if (lookupContainsDepNode) {
|
|
278
317
|
return alias;
|
|
279
318
|
}
|
package/plugins/with-stylus.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withStylus = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
// Adapted from https://raw.githubusercontent.com/elado/next-with-less/main/src/index.js
|
|
6
5
|
const webpack_merge_1 = require("webpack-merge");
|
|
7
6
|
const addStylusToRegExp = (rx) => new RegExp(rx.source.replace('|sass', '|sass|styl'), rx.flags);
|
|
8
7
|
function withStylus(configOrFn) {
|
|
9
|
-
return (phase) =>
|
|
10
|
-
const baseConfig = typeof configOrFn === 'function' ?
|
|
11
|
-
const { stylusLoaderOptions = {}
|
|
8
|
+
return async (phase) => {
|
|
9
|
+
const baseConfig = typeof configOrFn === 'function' ? await configOrFn(phase) : configOrFn;
|
|
10
|
+
const { stylusLoaderOptions = {}, ...nextConfig } = baseConfig;
|
|
12
11
|
return Object.assign({}, nextConfig, {
|
|
13
12
|
webpack(config, opts) {
|
|
14
13
|
// there are 2 relevant sass rules in next.js - css modules and global css
|
|
15
14
|
let sassModuleRule;
|
|
16
15
|
// global sass rule (does not exist in server builds)
|
|
17
16
|
let sassGlobalRule;
|
|
18
|
-
const cssRule = config.module.rules.find((rule) =>
|
|
17
|
+
const cssRule = config.module.rules.find((rule) => rule.oneOf?.find((r) => r?.[Symbol.for('__next_css_remove')]));
|
|
19
18
|
const addStylusRuleToTest = (test) => {
|
|
20
19
|
if (Array.isArray(test)) {
|
|
21
20
|
return test.map((rx) => addStylusToRegExp(rx));
|
|
@@ -25,28 +24,33 @@ function withStylus(configOrFn) {
|
|
|
25
24
|
}
|
|
26
25
|
};
|
|
27
26
|
cssRule.oneOf.forEach((rule) => {
|
|
28
|
-
|
|
29
|
-
if ((_a = rule.options) === null || _a === void 0 ? void 0 : _a.__next_css_remove)
|
|
27
|
+
if (rule.options?.__next_css_remove)
|
|
30
28
|
return;
|
|
31
|
-
if (
|
|
29
|
+
if (rule.use?.loader === 'error-loader') {
|
|
32
30
|
rule.test = addStylusRuleToTest(rule.test);
|
|
33
31
|
}
|
|
34
|
-
else if (
|
|
32
|
+
else if (rule.use?.loader?.includes('file-loader')) {
|
|
35
33
|
rule.issuer = addStylusRuleToTest(rule.issuer);
|
|
36
34
|
}
|
|
37
|
-
else if (
|
|
35
|
+
else if (rule.use?.includes?.('ignore-loader')) {
|
|
38
36
|
rule.test = addStylusRuleToTest(rule.test);
|
|
39
37
|
}
|
|
40
|
-
else if (
|
|
38
|
+
else if (rule.test?.source === '\\.module\\.(scss|sass)$') {
|
|
41
39
|
sassModuleRule = rule;
|
|
42
40
|
}
|
|
43
|
-
else if (
|
|
41
|
+
else if (rule.test?.source === '(?<!\\.module)\\.(scss|sass)$') {
|
|
44
42
|
sassGlobalRule = rule;
|
|
45
43
|
}
|
|
46
44
|
});
|
|
47
45
|
const stylusLoader = {
|
|
48
46
|
loader: 'stylus-loader',
|
|
49
|
-
options:
|
|
47
|
+
options: {
|
|
48
|
+
...stylusLoaderOptions,
|
|
49
|
+
stylusOptions: {
|
|
50
|
+
javascriptEnabled: true,
|
|
51
|
+
...stylusLoaderOptions.stylusOptions,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
50
54
|
};
|
|
51
55
|
let stylusModuleRule = (0, webpack_merge_1.merge)({}, sassModuleRule);
|
|
52
56
|
const configureStylusRule = (rule) => {
|
|
@@ -67,7 +71,7 @@ function withStylus(configOrFn) {
|
|
|
67
71
|
return config;
|
|
68
72
|
},
|
|
69
73
|
});
|
|
70
|
-
}
|
|
74
|
+
};
|
|
71
75
|
}
|
|
72
76
|
exports.withStylus = withStylus;
|
|
73
77
|
module.exports = withStylus;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
const devkit_1 = require("@nx/devkit");
|
|
5
4
|
const js_1 = require("@nx/js");
|
|
6
5
|
const path_1 = require("path");
|
|
@@ -14,78 +13,74 @@ const check_project_1 = require("./lib/check-project");
|
|
|
14
13
|
const child_process_1 = require("child_process");
|
|
15
14
|
const create_cli_options_1 = require("../../utils/create-cli-options");
|
|
16
15
|
let childProcess;
|
|
17
|
-
function buildExecutor(options, context) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
async function buildExecutor(options, context) {
|
|
17
|
+
// Cast to any to overwrite NODE_ENV
|
|
18
|
+
process.env.NODE_ENV ||= 'production';
|
|
19
|
+
const projectRoot = context.projectGraph.nodes[context.projectName].data.root;
|
|
20
|
+
(0, check_project_1.checkPublicDirectory)(projectRoot);
|
|
21
|
+
// Set `__NEXT_REACT_ROOT` based on installed ReactDOM version
|
|
22
|
+
const packageJsonPath = (0, path_1.join)(projectRoot, 'package.json');
|
|
23
|
+
const packageJson = (0, fs_extra_1.existsSync)(packageJsonPath)
|
|
24
|
+
? (0, devkit_1.readJsonFile)(packageJsonPath)
|
|
25
|
+
: undefined;
|
|
26
|
+
const rootPackageJson = (0, devkit_1.readJsonFile)((0, path_1.join)(context.root, 'package.json'));
|
|
27
|
+
const reactDomVersion = packageJson?.dependencies?.['react-dom'] ??
|
|
28
|
+
rootPackageJson.dependencies?.['react-dom'];
|
|
29
|
+
const hasReact18 = reactDomVersion &&
|
|
30
|
+
(0, semver_1.gte)((0, semver_2.checkAndCleanWithSemver)('react-dom', reactDomVersion), '18.0.0');
|
|
31
|
+
if (hasReact18) {
|
|
32
|
+
process.env['__NEXT_REACT_ROOT'] ||= 'true';
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
await runCliBuild(devkit_1.workspaceRoot, projectRoot, options);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
devkit_1.logger.error(`Error occurred while trying to run the build command`);
|
|
39
|
+
devkit_1.logger.error(error);
|
|
40
|
+
return { success: false };
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
if (childProcess) {
|
|
44
|
+
childProcess.kill();
|
|
36
45
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
finally {
|
|
46
|
-
if (childProcess) {
|
|
47
|
-
childProcess.kill();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (!(0, fileutils_1.directoryExists)(options.outputPath)) {
|
|
51
|
-
(0, fs_extra_1.mkdir)(options.outputPath);
|
|
52
|
-
}
|
|
53
|
-
const builtPackageJson = (0, js_1.createPackageJson)(context.projectName, context.projectGraph, {
|
|
54
|
-
target: context.targetName,
|
|
55
|
-
root: context.root,
|
|
56
|
-
isProduction: !options.includeDevDependenciesInPackageJson, // By default we remove devDependencies since this is a production build.
|
|
57
|
-
});
|
|
58
|
-
// Update `package.json` to reflect how users should run the build artifacts
|
|
59
|
-
builtPackageJson.scripts = {
|
|
60
|
-
start: 'next start',
|
|
61
|
-
};
|
|
62
|
-
(0, update_package_json_1.updatePackageJson)(builtPackageJson, context);
|
|
63
|
-
(0, devkit_1.writeJsonFile)(`${options.outputPath}/package.json`, builtPackageJson);
|
|
64
|
-
if (options.generateLockfile) {
|
|
65
|
-
const lockFile = (0, js_1.createLockFile)(builtPackageJson);
|
|
66
|
-
(0, fs_extra_1.writeFileSync)(`${options.outputPath}/${(0, js_1.getLockFileName)()}`, lockFile, {
|
|
67
|
-
encoding: 'utf-8',
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
// If output path is different from source path, then copy over the config and public files.
|
|
71
|
-
// This is the default behavior when running `nx build <app>`.
|
|
72
|
-
if (options.outputPath.replace(/\/$/, '') !== projectRoot) {
|
|
73
|
-
(0, create_next_config_file_1.createNextConfigFile)(options, context);
|
|
74
|
-
(0, fs_extra_1.copySync)((0, path_1.join)(projectRoot, 'public'), (0, path_1.join)(options.outputPath, 'public'), {
|
|
75
|
-
dereference: true,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return { success: true };
|
|
46
|
+
}
|
|
47
|
+
if (!(0, fileutils_1.directoryExists)(options.outputPath)) {
|
|
48
|
+
(0, fs_extra_1.mkdir)(options.outputPath);
|
|
49
|
+
}
|
|
50
|
+
const builtPackageJson = (0, js_1.createPackageJson)(context.projectName, context.projectGraph, {
|
|
51
|
+
target: context.targetName,
|
|
52
|
+
root: context.root,
|
|
53
|
+
isProduction: !options.includeDevDependenciesInPackageJson, // By default we remove devDependencies since this is a production build.
|
|
79
54
|
});
|
|
55
|
+
// Update `package.json` to reflect how users should run the build artifacts
|
|
56
|
+
builtPackageJson.scripts = {
|
|
57
|
+
start: 'next start',
|
|
58
|
+
};
|
|
59
|
+
(0, update_package_json_1.updatePackageJson)(builtPackageJson, context);
|
|
60
|
+
(0, devkit_1.writeJsonFile)(`${options.outputPath}/package.json`, builtPackageJson);
|
|
61
|
+
if (options.generateLockfile) {
|
|
62
|
+
const packageManager = (0, devkit_1.detectPackageManager)(context.root);
|
|
63
|
+
const lockFile = (0, js_1.createLockFile)(builtPackageJson, context.projectGraph, packageManager);
|
|
64
|
+
(0, fs_extra_1.writeFileSync)(`${options.outputPath}/${(0, js_1.getLockFileName)(packageManager)}`, lockFile, {
|
|
65
|
+
encoding: 'utf-8',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// If output path is different from source path, then copy over the config and public files.
|
|
69
|
+
// This is the default behavior when running `nx build <app>`.
|
|
70
|
+
if (options.outputPath.replace(/\/$/, '') !== projectRoot) {
|
|
71
|
+
(0, create_next_config_file_1.createNextConfigFile)(options, context);
|
|
72
|
+
(0, fs_extra_1.copySync)((0, path_1.join)(projectRoot, 'public'), (0, path_1.join)(options.outputPath, 'public'), {
|
|
73
|
+
dereference: true,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return { success: true };
|
|
80
77
|
}
|
|
81
78
|
exports.default = buildExecutor;
|
|
82
79
|
function runCliBuild(workspaceRoot, projectRoot, options) {
|
|
83
|
-
var _a;
|
|
84
|
-
var _b;
|
|
85
80
|
const { experimentalAppOnly, profile, debug, outputPath } = options;
|
|
86
81
|
// Set output path here since it can also be set via CLI
|
|
87
82
|
// We can retrieve it inside plugins/with-nx
|
|
88
|
-
|
|
83
|
+
process.env.NX_NEXT_OUTPUT_PATH ??= outputPath;
|
|
89
84
|
const args = (0, create_cli_options_1.createCliOptions)({ experimentalAppOnly, profile, debug });
|
|
90
85
|
return new Promise((resolve, reject) => {
|
|
91
86
|
childProcess = (0, child_process_1.fork)(require.resolve('next/dist/bin/next'), ['build', ...args], {
|
|
@@ -53,9 +53,8 @@ function readSource(getFile) {
|
|
|
53
53
|
}
|
|
54
54
|
// Exported for testing
|
|
55
55
|
function getWithNxContent({ file, content } = readSource(() => (0, path_1.join)(__dirname, '../../../../plugins/with-nx.js'))) {
|
|
56
|
-
var _a;
|
|
57
56
|
const withNxSource = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
58
|
-
const getWithNxContextDeclaration = (
|
|
57
|
+
const getWithNxContextDeclaration = (0, typescript_1.findNodes)(withNxSource, ts.SyntaxKind.FunctionDeclaration)?.find((node) => node.name?.text === 'getWithNxContext');
|
|
59
58
|
if (getWithNxContextDeclaration) {
|
|
60
59
|
content = (0, devkit_1.applyChangesToString)(content, [
|
|
61
60
|
{
|
|
@@ -139,8 +138,7 @@ function getRelativeImports({ file, content, }) {
|
|
|
139
138
|
}
|
|
140
139
|
exports.getRelativeImports = getRelativeImports;
|
|
141
140
|
function stripOuterQuotes(str) {
|
|
142
|
-
|
|
143
|
-
return (_b = (_a = str.match(/^["'](.*)["']/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : str;
|
|
141
|
+
return str.match(/^["'](.*)["']/)?.[1] ?? str;
|
|
144
142
|
}
|
|
145
143
|
// Exported for testing
|
|
146
144
|
function ensureFileExtensions(files, absoluteDir) {
|
|
@@ -2,21 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updatePackageJson = void 0;
|
|
4
4
|
function updatePackageJson(packageJson, context) {
|
|
5
|
-
var _a, _b;
|
|
6
|
-
var _c;
|
|
7
5
|
if (!packageJson.scripts) {
|
|
8
6
|
packageJson.scripts = {};
|
|
9
7
|
}
|
|
10
8
|
if (!packageJson.scripts.start) {
|
|
11
9
|
packageJson.scripts.start = 'next start';
|
|
12
10
|
}
|
|
13
|
-
|
|
11
|
+
packageJson.dependencies ??= {};
|
|
14
12
|
// These are always required for a production Next.js app to run.
|
|
15
13
|
const requiredPackages = ['react', 'react-dom', 'next', 'typescript'];
|
|
16
14
|
for (const pkg of requiredPackages) {
|
|
17
15
|
const externalNode = context.projectGraph.externalNodes[`npm:${pkg}`];
|
|
18
16
|
if (externalNode) {
|
|
19
|
-
|
|
17
|
+
packageJson.dependencies[pkg] ??= externalNode.data.version;
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
}
|