@nx/next 17.0.4 → 17.0.6
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/LICENSE +1 -1
- package/README.md +4 -9
- package/generators.json +2 -2
- package/migrations.json +0 -24
- package/package.json +10 -12
- package/plugins/component-testing.d.ts +11 -1
- package/plugins/component-testing.js +10 -26
- package/plugins/with-nx.d.ts +1 -1
- package/plugins/with-nx.js +86 -68
- package/plugins/with-stylus.js +1 -1
- package/src/executors/build/build.impl.js +9 -20
- package/src/executors/build/lib/create-next-config-file.js +2 -5
- package/src/executors/build/lib/test-fixtures/ensure-exts/baz.json +0 -1
- package/src/executors/build/lib/update-package-json.js +1 -10
- package/src/executors/build/schema.json +1 -1
- package/src/executors/export/export.impl.js +9 -9
- package/src/executors/server/custom-server.impl.js +2 -3
- package/src/executors/server/schema.json +0 -4
- package/src/executors/server/server.impl.js +11 -13
- package/src/generators/application/application.js +0 -24
- package/src/generators/application/files/app/page.tsx__tmpl__ +1 -1
- package/src/generators/application/files/common/specs/__fileName__.spec.tsx__tmpl__ +3 -10
- package/src/generators/application/files/common/tsconfig.json__tmpl__ +5 -5
- package/src/generators/application/files/pages/__fileName__.tsx__tmpl__ +1 -1
- package/src/generators/application/lib/add-e2e.js +3 -27
- package/src/generators/application/lib/add-linting.js +16 -13
- package/src/generators/application/lib/add-project.js +33 -43
- package/src/generators/application/lib/create-application-files.helpers.js +5 -67
- package/src/generators/application/lib/create-application-files.js +11 -23
- package/src/generators/application/lib/normalize-options.d.ts +0 -3
- package/src/generators/application/lib/normalize-options.js +0 -31
- package/src/generators/application/schema.d.ts +0 -2
- package/src/generators/application/schema.json +3 -9
- package/src/generators/component/component.d.ts +4 -4
- package/src/generators/component/component.js +2 -3
- package/src/generators/component/schema.json +7 -7
- package/src/generators/custom-server/custom-server.d.ts +1 -1
- package/src/generators/custom-server/custom-server.js +9 -34
- package/src/generators/custom-server/files/server/main.ts__tmpl__ +4 -4
- package/src/generators/custom-server/files/tsconfig.server.json__tmpl__ +0 -2
- package/src/generators/custom-server/schema.json +1 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +0 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +10 -23
- package/src/generators/cypress-component-configuration/schema.d.ts +0 -1
- package/src/generators/cypress-component-configuration/schema.json +1 -1
- package/src/generators/init/init.d.ts +3 -4
- package/src/generators/init/init.js +44 -30
- package/src/generators/init/schema.d.ts +4 -3
- package/src/generators/init/schema.json +23 -11
- package/src/generators/library/lib/normalize-options.js +0 -5
- package/src/generators/library/library.js +1 -19
- package/src/generators/library/schema.d.ts +1 -2
- package/src/generators/library/schema.json +3 -3
- package/src/generators/page/page.js +4 -21
- package/src/generators/page/schema.d.ts +3 -3
- package/src/generators/page/schema.json +5 -5
- package/src/utils/add-gitignore-entry.js +1 -1
- package/src/utils/styles.d.ts +4 -4
- package/src/utils/types.d.ts +0 -1
- package/src/utils/versions.d.ts +2 -6
- package/src/utils/versions.js +3 -7
- package/plugin.d.ts +0 -1
- package/plugin.js +0 -5
- package/src/generators/application/lib/add-plugin.d.ts +0 -2
- package/src/generators/application/lib/add-plugin.js +0 -25
- package/src/generators/init/lib/add-plugin.d.ts +0 -2
- package/src/generators/init/lib/add-plugin.js +0 -26
- package/src/migrations/update-17-2-7/remove-eslint-rules-patch.d.ts +0 -2
- package/src/migrations/update-17-2-7/remove-eslint-rules-patch.js +0 -15
- package/src/plugins/plugin.d.ts +0 -11
- package/src/plugins/plugin.js +0 -184
- package/src/utils/add-swc-to-custom-server.d.ts +0 -2
- package/src/utils/add-swc-to-custom-server.js +0 -37
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
<p style="text-align: center;">
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
|
4
|
-
<img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
|
5
|
-
</picture>
|
|
6
|
-
</p>
|
|
1
|
+
<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
|
|
7
2
|
|
|
8
3
|
<div style="text-align: center;">
|
|
9
4
|
|
|
@@ -20,9 +15,9 @@
|
|
|
20
15
|
|
|
21
16
|
<hr>
|
|
22
17
|
|
|
23
|
-
# Nx: Smart
|
|
18
|
+
# Nx: Smart, Fast and Extensible Build System
|
|
24
19
|
|
|
25
|
-
Nx is a build system with
|
|
20
|
+
Nx is a next generation build system with first class monorepo support and powerful integrations.
|
|
26
21
|
|
|
27
22
|
This package is a [Next.js plugin for Nx](https://nx.dev/next/overview).
|
|
28
23
|
|
|
@@ -64,5 +59,5 @@ npx nx@latest init
|
|
|
64
59
|
- [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
|
|
65
60
|
|
|
66
61
|
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
|
67
|
-
width="100%" alt="Nx - Smart
|
|
62
|
+
width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
|
|
68
63
|
|
package/generators.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"extends": ["@nx/react"],
|
|
5
5
|
"generators": {
|
|
6
6
|
"init": {
|
|
7
|
-
"factory": "./src/generators/init/init#
|
|
7
|
+
"factory": "./src/generators/init/init#nextInitGenerator",
|
|
8
8
|
"schema": "./src/generators/init/schema.json",
|
|
9
9
|
"description": "Initialize the `@nrwl/next` plugin.",
|
|
10
10
|
"hidden": true
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"description": "Set up a custom server."
|
|
40
40
|
},
|
|
41
41
|
"cypress-component-configuration": {
|
|
42
|
-
"factory": "./src/generators/cypress-component-configuration/cypress-component-configuration
|
|
42
|
+
"factory": "./src/generators/cypress-component-configuration/cypress-component-configuration",
|
|
43
43
|
"schema": "./src/generators/cypress-component-configuration/schema.json",
|
|
44
44
|
"description": "cypress-component-configuration generator"
|
|
45
45
|
}
|
package/migrations.json
CHANGED
|
@@ -23,12 +23,6 @@
|
|
|
23
23
|
"version": "16.4.0-beta.3",
|
|
24
24
|
"description": "Update package.json moving @nx/next from dependency to devDependency",
|
|
25
25
|
"implementation": "./src/migrations/update-16-4-0/update-nx-next-dependency"
|
|
26
|
-
},
|
|
27
|
-
"update-17-2-7": {
|
|
28
|
-
"cli": "nx",
|
|
29
|
-
"version": "17.2.7",
|
|
30
|
-
"description": "Remove patched eslint rule for @next/next/no-html-link-for-pages",
|
|
31
|
-
"implementation": "./src/migrations/update-17-2-7/remove-eslint-rules-patch"
|
|
32
26
|
}
|
|
33
27
|
},
|
|
34
28
|
"packageJsonUpdates": {
|
|
@@ -83,24 +77,6 @@
|
|
|
83
77
|
"alwaysAddToPackageJson": false
|
|
84
78
|
}
|
|
85
79
|
}
|
|
86
|
-
},
|
|
87
|
-
"17.3.1-beta.0": {
|
|
88
|
-
"version": "17.3.1-beta.0",
|
|
89
|
-
"packages": {
|
|
90
|
-
"next": {
|
|
91
|
-
"version": "14.0.4",
|
|
92
|
-
"alwaysAddToPackageJson": false
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
"18.0.4": {
|
|
97
|
-
"version": "18.0.4-beta.0",
|
|
98
|
-
"packages": {
|
|
99
|
-
"@swc-node/register": {
|
|
100
|
-
"version": "~1.8.0",
|
|
101
|
-
"alwaysAddToPackageJson": false
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
80
|
}
|
|
105
81
|
}
|
|
106
82
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/next",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "v17.0.6",
|
|
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": {
|
|
@@ -31,28 +31,26 @@
|
|
|
31
31
|
"migrations": "./migrations.json"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"next": ">=
|
|
34
|
+
"next": ">=13.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nx/devkit": "17.0.4",
|
|
38
37
|
"@babel/plugin-proposal-decorators": "^7.22.7",
|
|
39
38
|
"@svgr/webpack": "^8.0.1",
|
|
40
39
|
"chalk": "^4.1.0",
|
|
41
40
|
"copy-webpack-plugin": "^10.2.4",
|
|
42
|
-
"file-loader": "^6.2.0",
|
|
43
41
|
"fs-extra": "^11.1.0",
|
|
44
42
|
"ignore": "^5.0.4",
|
|
45
|
-
"semver": "
|
|
43
|
+
"semver": "7.5.3",
|
|
46
44
|
"url-loader": "^4.1.1",
|
|
47
45
|
"tslib": "^2.3.0",
|
|
48
46
|
"webpack-merge": "^5.8.0",
|
|
49
|
-
"@nx/
|
|
50
|
-
"@nx/
|
|
51
|
-
"@nx/
|
|
52
|
-
"@nx/
|
|
53
|
-
"@nx/
|
|
54
|
-
"@nx/workspace": "
|
|
55
|
-
"@nrwl/next": "
|
|
47
|
+
"@nx/devkit": "v17.0.6",
|
|
48
|
+
"@nx/js": "v17.0.6",
|
|
49
|
+
"@nx/eslint": "v17.0.6",
|
|
50
|
+
"@nx/react": "v17.0.6",
|
|
51
|
+
"@nx/web": "v17.0.6",
|
|
52
|
+
"@nx/workspace": "v17.0.6",
|
|
53
|
+
"@nrwl/next": "v17.0.6"
|
|
56
54
|
},
|
|
57
55
|
"publishConfig": {
|
|
58
56
|
"access": "public"
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import { NxComponentTestingOptions } from '@nx/cypress/plugins/cypress-preset';
|
|
2
|
-
export declare function nxComponentTestingPreset(pathToConfig: string, options?: NxComponentTestingOptions):
|
|
2
|
+
export declare function nxComponentTestingPreset(pathToConfig: string, options?: NxComponentTestingOptions): {
|
|
3
|
+
specPattern: string;
|
|
4
|
+
devServer: {
|
|
5
|
+
webpackConfig: import("webpack").Configuration;
|
|
6
|
+
framework: "react";
|
|
7
|
+
bundler: "webpack";
|
|
8
|
+
};
|
|
9
|
+
videosFolder: string;
|
|
10
|
+
screenshotsFolder: string;
|
|
11
|
+
chromeWebSecurity: boolean;
|
|
12
|
+
};
|
|
@@ -8,25 +8,17 @@ 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
|
-
if (global.NX_GRAPH_CREATION || global.NX_CYPRESS_INIT_GENERATOR_RUNNING) {
|
|
12
|
-
// this is only used by plugins, so we don't need the component testing
|
|
13
|
-
// options, cast to any to avoid type errors
|
|
14
|
-
return (0, cypress_preset_1.nxBaseCypressPreset)(pathToConfig);
|
|
15
|
-
}
|
|
16
11
|
const graph = (0, devkit_1.readCachedProjectGraph)();
|
|
17
12
|
const { targets: ctTargets, name: ctProjectName } = (0, ct_helpers_1.getProjectConfigByPath)(graph, pathToConfig);
|
|
18
13
|
const ctTargetName = options?.ctTargetName || 'component-test';
|
|
19
14
|
const ctConfigurationName = process.env.NX_CYPRESS_TARGET_CONFIGURATION;
|
|
20
15
|
const ctExecutorContext = (0, ct_helpers_1.createExecutorContext)(graph, ctTargets, ctProjectName, ctTargetName, ctConfigurationName);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}, ctExecutorContext);
|
|
28
|
-
buildTarget = ctExecutorOptions.devServerTarget;
|
|
29
|
-
}
|
|
16
|
+
const ctExecutorOptions = (0, devkit_1.readTargetOptions)({
|
|
17
|
+
project: ctProjectName,
|
|
18
|
+
target: ctTargetName,
|
|
19
|
+
configuration: ctConfigurationName,
|
|
20
|
+
}, ctExecutorContext);
|
|
21
|
+
const buildTarget = ctExecutorOptions.devServerTarget;
|
|
30
22
|
let buildAssets = [];
|
|
31
23
|
let buildFileReplacements = [];
|
|
32
24
|
let buildOuputPath = `dist/${ctProjectName}/.next`;
|
|
@@ -39,13 +31,6 @@ function nxComponentTestingPreset(pathToConfig, options) {
|
|
|
39
31
|
projectGraph: graph,
|
|
40
32
|
});
|
|
41
33
|
const buildProjectConfig = graph.nodes[parsedBuildTarget.project]?.data;
|
|
42
|
-
if (buildProjectConfig?.targets?.[parsedBuildTarget.target]?.executor !==
|
|
43
|
-
'@nx/next:build') {
|
|
44
|
-
throw new Error(`The '${parsedBuildTarget.target}' target of the '${[
|
|
45
|
-
parsedBuildTarget.project,
|
|
46
|
-
]}' project is not using the '@nx/next:build' executor. ` +
|
|
47
|
-
`Please make sure to use '@nx/next:build' executor in that target to use Cypress Component Testing.`);
|
|
48
|
-
}
|
|
49
34
|
const buildExecutorContext = (0, ct_helpers_1.createExecutorContext)(graph, buildProjectConfig.targets, parsedBuildTarget.project, parsedBuildTarget.target, parsedBuildTarget.configuration);
|
|
50
35
|
const buildExecutorOptions = (0, devkit_1.readTargetOptions)({
|
|
51
36
|
project: parsedBuildTarget.project,
|
|
@@ -71,21 +56,20 @@ Able to find CT project, ${!!ctProjectConfig}.`);
|
|
|
71
56
|
assets: buildAssets,
|
|
72
57
|
outputPath: buildOuputPath,
|
|
73
58
|
outputFileName: 'main.js',
|
|
74
|
-
compiler:
|
|
59
|
+
compiler: 'swc',
|
|
75
60
|
tsConfig: (0, path_1.join)(ctExecutorContext.root, ctProjectConfig.root, 'tsconfig.json'),
|
|
76
61
|
};
|
|
77
|
-
const configure = (0, webpack_1.composePluginsSync)((0, webpack_1.withNx)({
|
|
78
|
-
target: 'web',
|
|
62
|
+
const configure = (0, webpack_1.composePluginsSync)((0, webpack_1.withNx)(), (0, react_1.withReact)({
|
|
79
63
|
styles: [],
|
|
80
64
|
scripts: [],
|
|
81
65
|
postcssConfig: ctProjectConfig.root,
|
|
82
|
-
})
|
|
66
|
+
}));
|
|
83
67
|
const webpackConfig = configure({}, {
|
|
84
68
|
options: webpackOptions,
|
|
85
69
|
context: ctExecutorContext,
|
|
86
70
|
});
|
|
87
71
|
return {
|
|
88
|
-
...(0, cypress_preset_1.nxBaseCypressPreset)(
|
|
72
|
+
...(0, cypress_preset_1.nxBaseCypressPreset)(__filename),
|
|
89
73
|
specPattern: '**/*.cy.{js,jsx,ts,tsx}',
|
|
90
74
|
devServer: {
|
|
91
75
|
...{ framework: 'react', bundler: 'webpack' },
|
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 {
|
|
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
|
@@ -1,6 +1,42 @@
|
|
|
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 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_INVOKED_BY_RUNNER',
|
|
15
|
+
'NX_PROJECT_GRAPH_MAX_WORKERS',
|
|
16
|
+
'NX_RUNNER',
|
|
17
|
+
'NX_SKIP_NX_CACHE',
|
|
18
|
+
'NX_TASKS_RUNNER',
|
|
19
|
+
'NX_TASKS_RUNNER_DYNAMIC_OUTPUT',
|
|
20
|
+
'NX_VERBOSE_LOGGING',
|
|
21
|
+
'NX_DRY_RUN',
|
|
22
|
+
'NX_INTERACTIVE',
|
|
23
|
+
'NX_GENERATE_QUIET',
|
|
24
|
+
'NX_PREFER_TS_NODE',
|
|
25
|
+
'NX_TASK_TARGET_PROJECT',
|
|
26
|
+
'NX_TASK_TARGET_TARGET',
|
|
27
|
+
'NX_TASK_TARGET_CONFIGURATION',
|
|
28
|
+
'NX_CLI_SET',
|
|
29
|
+
'NX_LOAD_DOT_ENV_FILES',
|
|
30
|
+
'NX_WORKSPACE_ROOT',
|
|
31
|
+
'NX_TASK_HASH',
|
|
32
|
+
'NX_NEXT_DIR',
|
|
33
|
+
'NX_NEXT_OUTPUT_PATH',
|
|
34
|
+
'NX_E2E_RUN_E2E',
|
|
35
|
+
'NX_E2E_CI_CACHE_KEY',
|
|
36
|
+
'NX_MAPPINGS',
|
|
37
|
+
'NX_FILE_TO_RUN',
|
|
38
|
+
'NX_NEXT_PUBLIC_DIR',
|
|
39
|
+
];
|
|
4
40
|
function regexEqual(x, y) {
|
|
5
41
|
return (x instanceof RegExp &&
|
|
6
42
|
y instanceof RegExp &&
|
|
@@ -58,13 +94,10 @@ function getNxContext(graph, target) {
|
|
|
58
94
|
*/
|
|
59
95
|
function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
60
96
|
return async (phase) => {
|
|
61
|
-
const { PHASE_PRODUCTION_SERVER
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
// NOTE: Avoid any `require(...)` or `import(...)` statements here. Development dependencies are not available at production runtime.
|
|
67
|
-
if (PHASE_PRODUCTION_SERVER === phase || global.NX_GRAPH_CREATION) {
|
|
97
|
+
const { PHASE_PRODUCTION_SERVER } = await Promise.resolve().then(() => require('next/constants'));
|
|
98
|
+
if (phase === PHASE_PRODUCTION_SERVER) {
|
|
99
|
+
// If we are running an already built production server, just return the configuration.
|
|
100
|
+
// NOTE: Avoid any `require(...)` or `import(...)` statements here. Development dependencies are not available at production runtime.
|
|
68
101
|
const { nx, ...validNextConfig } = _nextConfig;
|
|
69
102
|
return {
|
|
70
103
|
distDir: '.next',
|
|
@@ -73,20 +106,21 @@ function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
|
73
106
|
}
|
|
74
107
|
else {
|
|
75
108
|
const { createProjectGraphAsync, joinPathFragments, offsetFromRoot, workspaceRoot, } = require('@nx/devkit');
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
throw new Error('Could not create project graph. Please ensure that your workspace is valid.', { cause: e });
|
|
82
|
-
}
|
|
109
|
+
// Otherwise, add in webpack and eslint configuration for build or test.
|
|
110
|
+
let dependencies = [];
|
|
111
|
+
const graph = await createProjectGraphAsync();
|
|
83
112
|
const originalTarget = {
|
|
84
113
|
project: process.env.NX_TASK_TARGET_PROJECT,
|
|
85
114
|
target: process.env.NX_TASK_TARGET_TARGET,
|
|
86
115
|
configuration: process.env.NX_TASK_TARGET_CONFIGURATION,
|
|
87
116
|
};
|
|
88
|
-
const { node: projectNode, options, projectName: project, } = getNxContext(graph, originalTarget);
|
|
117
|
+
const { node: projectNode, options, projectName: project, targetName, configurationName, } = getNxContext(graph, originalTarget);
|
|
89
118
|
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
|
+
}
|
|
90
124
|
// Get next config
|
|
91
125
|
const nextConfig = getNextConfig(_nextConfig, context);
|
|
92
126
|
// For Next.js 13.1 and greater, make sure workspace libs are transpiled.
|
|
@@ -110,20 +144,13 @@ function withNx(_nextConfig = {}, context = getWithNxContext()) {
|
|
|
110
144
|
process.env.NX_NEXT_OUTPUT_PATH || options.outputPath;
|
|
111
145
|
// outputPath may be undefined if using run-commands or other executors other than @nx/next:build.
|
|
112
146
|
// In this case, the user should set distDir in their next.config.js.
|
|
113
|
-
if (options.outputPath
|
|
147
|
+
if (options.outputPath) {
|
|
114
148
|
const outputDir = `${offsetFromRoot(projectDirectory)}${options.outputPath}`;
|
|
115
|
-
// If running dev-server, we should keep `.next` inside project directory since Turbopack expects this.
|
|
116
|
-
// See: https://github.com/nrwl/nx/issues/19365
|
|
117
149
|
nextConfig.distDir =
|
|
118
150
|
nextConfig.distDir && nextConfig.distDir !== '.next'
|
|
119
151
|
? joinPathFragments(outputDir, nextConfig.distDir)
|
|
120
152
|
: joinPathFragments(outputDir, '.next');
|
|
121
153
|
}
|
|
122
|
-
// 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'.
|
|
123
|
-
if (process.env.NX_SERVE_STATIC_BUILD_RUNNING === 'true') {
|
|
124
|
-
nextConfig.output = 'export';
|
|
125
|
-
nextConfig.distDir = 'out';
|
|
126
|
-
}
|
|
127
154
|
const userWebpackConfig = nextConfig.webpack;
|
|
128
155
|
const { createWebpackConfig } = require('@nx/next/src/utils/config');
|
|
129
156
|
nextConfig.webpack = (a, b) => createWebpackConfig(workspaceRoot, projectDirectory, options.fileReplacements, options.assets)(userWebpackConfig ? userWebpackConfig(a, b) : a, b);
|
|
@@ -224,51 +251,36 @@ function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
|
|
|
224
251
|
*/
|
|
225
252
|
// Default SVGR support to be on for projects.
|
|
226
253
|
if (nx?.svgr !== false) {
|
|
227
|
-
// TODO(v20): Remove file-loader and use `?react` querystring to differentiate between asset and SVGR.
|
|
228
|
-
// It should be:
|
|
229
|
-
// use: [{
|
|
230
|
-
// test: /\.svg$/i,
|
|
231
|
-
// type: 'asset',
|
|
232
|
-
// resourceQuery: /react/, // *.svg?react
|
|
233
|
-
// },
|
|
234
|
-
// {
|
|
235
|
-
// test: /\.svg$/i,
|
|
236
|
-
// issuer: /\.[jt]sx?$/,
|
|
237
|
-
// resourceQuery: { not: [/react/] }, // exclude react component if *.svg?react
|
|
238
|
-
// use: ['@svgr/webpack'],
|
|
239
|
-
// }],
|
|
240
|
-
// See:
|
|
241
|
-
// - SVGR: https://react-svgr.com/docs/webpack/#use-svgr-and-asset-svg-in-the-same-project
|
|
242
|
-
// - Vite: https://www.npmjs.com/package/vite-plugin-svgr
|
|
243
|
-
// - Rsbuild: https://github.com/web-infra-dev/rsbuild/pull/1783
|
|
244
|
-
// Note: We also need a migration for any projects that are using SVGR to convert
|
|
245
|
-
// `import { ReactComponent as X } from './x.svg` to
|
|
246
|
-
// `import X from './x.svg?react';
|
|
247
254
|
config.module.rules.push({
|
|
248
255
|
test: /\.svg$/,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
not: [
|
|
252
|
-
/__next_metadata__/,
|
|
253
|
-
/__next_metadata_route__/,
|
|
254
|
-
/__next_metadata_image_meta__/,
|
|
255
|
-
],
|
|
256
|
-
},
|
|
257
|
-
use: [
|
|
256
|
+
oneOf: [
|
|
257
|
+
// If coming from JS/TS file, then transform into React component using SVGR.
|
|
258
258
|
{
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
259
|
+
issuer: /\.[jt]sx?$/,
|
|
260
|
+
use: [
|
|
261
|
+
{
|
|
262
|
+
loader: require.resolve('@svgr/webpack'),
|
|
263
|
+
options: {
|
|
264
|
+
svgo: false,
|
|
265
|
+
titleProp: true,
|
|
266
|
+
ref: true,
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
loader: require.resolve('url-loader'),
|
|
271
|
+
options: {
|
|
272
|
+
limit: 10000,
|
|
273
|
+
name: '[name].[hash:7].[ext]',
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
],
|
|
265
277
|
},
|
|
278
|
+
// Fallback to plain URL loader if someone just imports the SVG and references it on the <img src> tag
|
|
266
279
|
{
|
|
267
|
-
loader: require.resolve('
|
|
280
|
+
loader: require.resolve('url-loader'),
|
|
268
281
|
options: {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
name: 'static/media/[name].[hash].[ext]',
|
|
282
|
+
limit: 10000,
|
|
283
|
+
name: '[name].[hash:7].[ext]',
|
|
272
284
|
},
|
|
273
285
|
},
|
|
274
286
|
],
|
|
@@ -279,19 +291,20 @@ function getNextConfig(nextConfig = {}, context = getWithNxContext()) {
|
|
|
279
291
|
};
|
|
280
292
|
}
|
|
281
293
|
exports.getNextConfig = getNextConfig;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
294
|
+
function getNonBaseVariables(oldEnv) {
|
|
295
|
+
return Object.keys(oldEnv).filter((env) => !baseNXEnvironmentVariables.includes(env));
|
|
296
|
+
}
|
|
285
297
|
function getNxEnvironmentVariables() {
|
|
286
298
|
return Object.keys(process.env)
|
|
287
|
-
.filter((env) =>
|
|
299
|
+
.filter((env) => /^NX_/i.test(env))
|
|
288
300
|
.reduce((env, key) => {
|
|
289
301
|
env[key] = process.env[key];
|
|
290
302
|
return env;
|
|
291
303
|
}, {});
|
|
292
304
|
}
|
|
305
|
+
let hasWarnedAboutDeprecatedEnvVariables = false;
|
|
293
306
|
/**
|
|
294
|
-
* TODO(
|
|
307
|
+
* TODO(v18)
|
|
295
308
|
* @deprecated Use Next.js 9.4+ built-in support for environment variables. Reference https://nextjs.org/docs/pages/api-reference/next-config-js/env
|
|
296
309
|
*/
|
|
297
310
|
function addNxEnvVariables(config) {
|
|
@@ -304,11 +317,16 @@ function addNxEnvVariables(config) {
|
|
|
304
317
|
.map(([name, value]) => [`process.env.${name}`, `"${value}"`])
|
|
305
318
|
.filter(([name]) => !maybeDefinePlugin.definitions[name])
|
|
306
319
|
.forEach(([name, value]) => (maybeDefinePlugin.definitions[name] = value));
|
|
320
|
+
const vars = getNonBaseVariables(env);
|
|
321
|
+
if (vars.length > 0 && !hasWarnedAboutDeprecatedEnvVariables) {
|
|
322
|
+
hasWarnedAboutDeprecatedEnvVariables = true;
|
|
323
|
+
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`);
|
|
324
|
+
}
|
|
307
325
|
}
|
|
308
326
|
}
|
|
309
327
|
function getAliasForProject(node, paths) {
|
|
310
328
|
// Match workspace libs to their alias in tsconfig paths.
|
|
311
|
-
for (const [alias, lookup] of Object.entries(paths
|
|
329
|
+
for (const [alias, lookup] of Object.entries(paths)) {
|
|
312
330
|
const lookupContainsDepNode = lookup.some((lookupPath) => lookupPath.startsWith(node?.data?.root) ||
|
|
313
331
|
lookupPath.startsWith('./' + node?.data?.root));
|
|
314
332
|
if (lookupContainsDepNode) {
|
package/plugins/with-stylus.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withStylus = void 0;
|
|
4
|
-
// TODO(
|
|
4
|
+
// TODO(v18): Remove file, it is here until users migrate over to SASS manually.
|
|
5
5
|
function withStylus(configOrFn) {
|
|
6
6
|
return async (phase) => {
|
|
7
7
|
throw new Error(`Stylus support has been removed and you should use the built-in SASS support. Remove the "withStylus" plugin from your Next.js config, and rename your files from .styl to .scss.`);
|
|
@@ -12,7 +12,6 @@ const create_next_config_file_1 = require("./lib/create-next-config-file");
|
|
|
12
12
|
const check_project_1 = require("./lib/check-project");
|
|
13
13
|
const child_process_1 = require("child_process");
|
|
14
14
|
const create_cli_options_1 = require("../../utils/create-cli-options");
|
|
15
|
-
const exit_codes_1 = require("nx/src/utils/exit-codes");
|
|
16
15
|
let childProcess;
|
|
17
16
|
async function buildExecutor(options, context) {
|
|
18
17
|
// Cast to any to overwrite NODE_ENV
|
|
@@ -35,14 +34,9 @@ async function buildExecutor(options, context) {
|
|
|
35
34
|
try {
|
|
36
35
|
await runCliBuild(devkit_1.workspaceRoot, projectRoot, options);
|
|
37
36
|
}
|
|
38
|
-
catch (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
devkit_1.logger.error(`Error occurred while trying to run the build command`);
|
|
44
|
-
devkit_1.logger.error(error);
|
|
45
|
-
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
devkit_1.logger.error(`Error occurred while trying to run the build command`);
|
|
39
|
+
devkit_1.logger.error(error);
|
|
46
40
|
return { success: false };
|
|
47
41
|
}
|
|
48
42
|
finally {
|
|
@@ -91,26 +85,21 @@ function runCliBuild(workspaceRoot, projectRoot, options) {
|
|
|
91
85
|
return new Promise((resolve, reject) => {
|
|
92
86
|
childProcess = (0, child_process_1.fork)(require.resolve('next/dist/bin/next'), ['build', ...args], {
|
|
93
87
|
cwd: (0, path_1.resolve)(workspaceRoot, projectRoot),
|
|
94
|
-
stdio:
|
|
88
|
+
stdio: 'inherit',
|
|
95
89
|
env: process.env,
|
|
96
90
|
});
|
|
97
91
|
// Ensure the child process is killed when the parent exits
|
|
98
92
|
process.on('exit', () => childProcess.kill());
|
|
99
|
-
process.on('SIGTERM', (
|
|
100
|
-
reject({ code: (0, exit_codes_1.signalToCode)(signal), signal });
|
|
101
|
-
});
|
|
102
|
-
process.on('SIGINT', (signal) => {
|
|
103
|
-
reject({ code: (0, exit_codes_1.signalToCode)(signal), signal });
|
|
104
|
-
});
|
|
93
|
+
process.on('SIGTERM', () => childProcess.kill());
|
|
105
94
|
childProcess.on('error', (err) => {
|
|
106
|
-
reject(
|
|
95
|
+
reject(err);
|
|
107
96
|
});
|
|
108
|
-
childProcess.on('exit', (code
|
|
97
|
+
childProcess.on('exit', (code) => {
|
|
109
98
|
if (code === 0) {
|
|
110
|
-
resolve(
|
|
99
|
+
resolve(code);
|
|
111
100
|
}
|
|
112
101
|
else {
|
|
113
|
-
reject(
|
|
102
|
+
reject(code);
|
|
114
103
|
}
|
|
115
104
|
});
|
|
116
105
|
});
|
|
@@ -41,10 +41,7 @@ function createNextConfigFile(options, context) {
|
|
|
41
41
|
const moduleFilesToCopy = getRelativeFilesToCopy(configRelativeToProjectRoot, projectRoot);
|
|
42
42
|
for (const moduleFile of moduleFilesToCopy) {
|
|
43
43
|
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)((0, path_1.join)(context.root, options.outputPath, moduleFile)));
|
|
44
|
-
|
|
45
|
-
if (moduleFile !== 'package.json') {
|
|
46
|
-
(0, fs_extra_1.copyFileSync)((0, path_1.join)(context.root, projectRoot, moduleFile), (0, path_1.join)(context.root, options.outputPath, moduleFile));
|
|
47
|
-
}
|
|
44
|
+
(0, fs_extra_1.copyFileSync)((0, path_1.join)(context.root, projectRoot, moduleFile), (0, path_1.join)(context.root, options.outputPath, moduleFile));
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
exports.createNextConfigFile = createNextConfigFile;
|
|
@@ -83,7 +80,7 @@ exports.getWithNxContent = getWithNxContent;
|
|
|
83
80
|
function findNextConfigPath(dirname, userDefinedConfigPath) {
|
|
84
81
|
if (userDefinedConfigPath) {
|
|
85
82
|
const file = userDefinedConfigPath;
|
|
86
|
-
if ((0, fs_extra_1.existsSync)(
|
|
83
|
+
if ((0, fs_extra_1.existsSync)(file))
|
|
87
84
|
return file;
|
|
88
85
|
throw new Error(`Cannot find the Next.js config file: ${userDefinedConfigPath}. Is the path correct in project.json?`);
|
|
89
86
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -10,16 +10,7 @@ function updatePackageJson(packageJson, context) {
|
|
|
10
10
|
}
|
|
11
11
|
packageJson.dependencies ??= {};
|
|
12
12
|
// These are always required for a production Next.js app to run.
|
|
13
|
-
|
|
14
|
-
// critters is required for experimental optimizing CSS
|
|
15
|
-
const requiredPackages = [
|
|
16
|
-
'react',
|
|
17
|
-
'react-dom',
|
|
18
|
-
'next',
|
|
19
|
-
'typescript',
|
|
20
|
-
'sharp',
|
|
21
|
-
'critters',
|
|
22
|
-
];
|
|
13
|
+
const requiredPackages = ['react', 'react-dom', 'next', 'typescript'];
|
|
23
14
|
for (const pkg of requiredPackages) {
|
|
24
15
|
const externalNode = context.projectGraph.externalNodes[`npm:${pkg}`];
|
|
25
16
|
if (externalNode) {
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const devkit_1 = require("@nx/devkit");
|
|
4
4
|
const export_1 = require("next/dist/export");
|
|
5
|
+
const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
|
|
5
6
|
const nextTrace = require("next/dist/trace");
|
|
6
7
|
const os_1 = require("os");
|
|
7
8
|
const child_process_1 = require("child_process");
|
|
8
9
|
const chalk = require("chalk");
|
|
9
|
-
const semver_1 = require("semver");
|
|
10
10
|
// platform specific command name
|
|
11
11
|
const pmCmd = (0, os_1.platform)() === 'win32' ? `npx.cmd` : 'npx';
|
|
12
12
|
/**
|
|
@@ -22,15 +22,15 @@ const pmCmd = (0, os_1.platform)() === 'win32' ? `npx.cmd` : 'npx';
|
|
|
22
22
|
* Read https://nextjs.org/docs/pages/building-your-application/deploying/static-exports
|
|
23
23
|
**/
|
|
24
24
|
async function exportExecutor(options, context) {
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
25
|
+
let dependencies = [];
|
|
26
|
+
if (!options.buildLibsFromSource) {
|
|
27
|
+
const result = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, 'build', // this should be generalized
|
|
28
|
+
context.configurationName);
|
|
29
|
+
dependencies = result.dependencies;
|
|
28
30
|
}
|
|
29
|
-
// Returns { project: ProjectGraphNode; target: string; configuration?: string;}
|
|
30
31
|
const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, context);
|
|
31
32
|
try {
|
|
32
|
-
const
|
|
33
|
-
const args = getBuildTargetCommand(buildTargetName);
|
|
33
|
+
const args = getBuildTargetCommand(options);
|
|
34
34
|
(0, child_process_1.execFileSync)(pmCmd, args, {
|
|
35
35
|
stdio: [0, 1, 2],
|
|
36
36
|
});
|
|
@@ -52,7 +52,7 @@ async function exportExecutor(options, context) {
|
|
|
52
52
|
return { success: true };
|
|
53
53
|
}
|
|
54
54
|
exports.default = exportExecutor;
|
|
55
|
-
function getBuildTargetCommand(
|
|
56
|
-
const cmd = ['nx', 'run', buildTarget];
|
|
55
|
+
function getBuildTargetCommand(options) {
|
|
56
|
+
const cmd = ['nx', 'run', options.buildTarget];
|
|
57
57
|
return cmd;
|
|
58
58
|
}
|