@nx/next 20.4.1 → 20.4.3
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 +7 -7
- package/src/generators/application/application.js +5 -0
- package/src/generators/custom-server/custom-server.js +15 -8
- package/src/generators/custom-server/files/server/main.ts__tmpl__ +1 -1
- package/src/utils/add-swc-to-custom-server.d.ts +1 -1
- package/src/utils/add-swc-to-custom-server.js +8 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/next",
|
|
3
|
-
"version": "20.4.
|
|
3
|
+
"version": "20.4.3",
|
|
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, Playwright, Cypress, and Jest. No need to configure anything: watch mode, source maps, and typings just work.",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"next": ">=14.0.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nx/devkit": "20.4.
|
|
38
|
+
"@nx/devkit": "20.4.3",
|
|
39
39
|
"@babel/plugin-proposal-decorators": "^7.22.7",
|
|
40
40
|
"@svgr/webpack": "^8.1.0",
|
|
41
41
|
"copy-webpack-plugin": "^10.2.4",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"semver": "^7.5.3",
|
|
45
45
|
"tslib": "^2.3.0",
|
|
46
46
|
"webpack-merge": "^5.8.0",
|
|
47
|
-
"@nx/js": "20.4.
|
|
48
|
-
"@nx/eslint": "20.4.
|
|
49
|
-
"@nx/react": "20.4.
|
|
50
|
-
"@nx/web": "20.4.
|
|
51
|
-
"@nx/webpack": "20.4.
|
|
47
|
+
"@nx/js": "20.4.3",
|
|
48
|
+
"@nx/eslint": "20.4.3",
|
|
49
|
+
"@nx/react": "20.4.3",
|
|
50
|
+
"@nx/web": "20.4.3",
|
|
51
|
+
"@nx/webpack": "20.4.3",
|
|
52
52
|
"@phenomnomnominal/tsquery": "~5.0.1"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
@@ -24,6 +24,7 @@ const versions_2 = require("../../utils/versions");
|
|
|
24
24
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
25
25
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
26
26
|
const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
|
|
27
|
+
const add_swc_to_custom_server_1 = require("../../utils/add-swc-to-custom-server");
|
|
27
28
|
async function applicationGenerator(host, schema) {
|
|
28
29
|
return await applicationGeneratorInternal(host, {
|
|
29
30
|
addPlugin: false,
|
|
@@ -70,6 +71,10 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
70
71
|
(0, update_jest_config_1.updateJestConfig)(host, options);
|
|
71
72
|
(0, update_cypress_tsconfig_1.updateCypressTsConfig)(host, options);
|
|
72
73
|
(0, set_defaults_1.setDefaults)(host, options);
|
|
74
|
+
if (options.swc) {
|
|
75
|
+
const swcTask = (0, add_swc_to_custom_server_1.configureForSwc)(host, options.appProjectRoot);
|
|
76
|
+
tasks.push(swcTask);
|
|
77
|
+
}
|
|
73
78
|
if (options.customServer) {
|
|
74
79
|
await (0, custom_server_1.customServerGenerator)(host, {
|
|
75
80
|
project: options.projectName,
|
|
@@ -8,20 +8,17 @@ const add_swc_to_custom_server_1 = require("../../utils/add-swc-to-custom-server
|
|
|
8
8
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
9
9
|
async function customServerGenerator(host, options) {
|
|
10
10
|
const project = (0, devkit_2.readProjectConfiguration)(host, options.project);
|
|
11
|
+
const swcServerName = '.server.swcrc';
|
|
11
12
|
const nxJson = (0, devkit_2.readNxJson)(host);
|
|
12
13
|
const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
|
|
13
14
|
? p === '@nx/next/plugin'
|
|
14
15
|
: p.plugin === '@nx/next/plugin');
|
|
15
|
-
if (project.targets?.build?.executor !== '@nx/next:build' &&
|
|
16
|
-
project.targets?.build?.executor !== '@nrwl/next:build' &&
|
|
17
|
-
!hasPlugin) {
|
|
16
|
+
if (project.targets?.build?.executor !== '@nx/next:build' && !hasPlugin) {
|
|
18
17
|
devkit_2.logger.error(`Project ${options.project} is not a Next.js project. Did you generate it with "nx g @nx/next:app"?`);
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
20
|
// In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
|
|
22
|
-
const outputPath =
|
|
23
|
-
? `dist/${project.root}`
|
|
24
|
-
: project.targets?.build?.options?.outputPath;
|
|
21
|
+
const outputPath = `dist/${project.root}-server`;
|
|
25
22
|
const root = project.root;
|
|
26
23
|
if ((!root ||
|
|
27
24
|
!outputPath ||
|
|
@@ -38,7 +35,9 @@ async function customServerGenerator(host, options) {
|
|
|
38
35
|
}
|
|
39
36
|
// In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
|
|
40
37
|
// So we need ensure the mapping is correct from dist to the project root
|
|
41
|
-
const projectPathFromDist =
|
|
38
|
+
const projectPathFromDist = hasPlugin
|
|
39
|
+
? `../../${(0, devkit_2.offsetFromRoot)(project.root)}${project.root}`
|
|
40
|
+
: `${(0, devkit_2.offsetFromRoot)(`dist/${project.root}`)}${project.root}`;
|
|
42
41
|
const offset = (0, devkit_2.offsetFromRoot)(project.root);
|
|
43
42
|
const isTsSolution = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
44
43
|
(0, devkit_2.generateFiles)(host, (0, path_1.join)(__dirname, 'files'), project.root, {
|
|
@@ -72,6 +71,9 @@ async function customServerGenerator(host, options) {
|
|
|
72
71
|
tsConfig: `${root}/tsconfig.server.json`,
|
|
73
72
|
clean: false,
|
|
74
73
|
assets: [],
|
|
74
|
+
...(options.compiler === 'tsc'
|
|
75
|
+
? {}
|
|
76
|
+
: { swcrc: `${root}/${swcServerName}` }),
|
|
75
77
|
},
|
|
76
78
|
configurations: {
|
|
77
79
|
development: {},
|
|
@@ -105,6 +107,11 @@ async function customServerGenerator(host, options) {
|
|
|
105
107
|
return json;
|
|
106
108
|
});
|
|
107
109
|
if (options.compiler === 'swc') {
|
|
108
|
-
|
|
110
|
+
// Update app swc to exlude server files
|
|
111
|
+
(0, devkit_2.updateJson)(host, (0, path_1.join)(project.root, '.swcrc'), (json) => {
|
|
112
|
+
json.exclude = [...(json.exclude ?? []), 'server/**'];
|
|
113
|
+
return json;
|
|
114
|
+
});
|
|
115
|
+
return (0, add_swc_to_custom_server_1.configureForSwc)(host, project.root, swcServerName, ['src/**/*']);
|
|
109
116
|
}
|
|
110
117
|
}
|
|
@@ -15,8 +15,8 @@ import next from 'next';
|
|
|
15
15
|
// - The fallback `__dirname` is for production builds.
|
|
16
16
|
// - Feel free to change this to suit your needs.
|
|
17
17
|
|
|
18
|
-
const dir = process.env.NX_NEXT_DIR || <%- hasPlugin ? `path.join(__dirname, '${projectPathFromDist}')` : `path.join(__dirname, '..')`; %>
|
|
19
18
|
const dev = process.env.NODE_ENV === 'development';
|
|
19
|
+
const dir = process.env.NX_NEXT_DIR || <%- hasPlugin ? `path.join(__dirname, '${projectPathFromDist}')` : `path.join(__dirname, dev ? '..' : '', '${projectPathFromDist}')`; %>
|
|
20
20
|
|
|
21
21
|
// HTTP Server options:
|
|
22
22
|
// - Feel free to change this to suit your needs.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
|
-
export declare function configureForSwc(tree: Tree, projectRoot: string): () => void;
|
|
2
|
+
export declare function configureForSwc(tree: Tree, projectRoot: string, swcConfigName?: string, additonalExludes?: string[]): () => void;
|
|
@@ -4,28 +4,24 @@ exports.configureForSwc = configureForSwc;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const versions_1 = require("@nx/js/src/utils/versions");
|
|
6
6
|
const add_swc_config_1 = require("@nx/js/src/utils/swc/add-swc-config");
|
|
7
|
-
function configureForSwc(tree, projectRoot) {
|
|
8
|
-
const swcConfigPath = (0, devkit_1.joinPathFragments)(projectRoot,
|
|
7
|
+
function configureForSwc(tree, projectRoot, swcConfigName = '.swcrc', additonalExludes = []) {
|
|
8
|
+
const swcConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, swcConfigName);
|
|
9
9
|
const rootPackageJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
10
10
|
const hasSwcDepedency = rootPackageJson.dependencies?.['@swc/core'] ||
|
|
11
11
|
rootPackageJson.devDependencies?.['@swc/core'];
|
|
12
12
|
const hasSwcCliDependency = rootPackageJson.dependencies?.['@swc/cli'] ||
|
|
13
13
|
rootPackageJson.devDependencies?.['@swc/cli'];
|
|
14
14
|
if (!tree.exists(swcConfigPath)) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
...json,
|
|
21
|
-
exclude: [...json.exclude, '.*.d.ts$'],
|
|
22
|
-
};
|
|
23
|
-
});
|
|
15
|
+
// We need to create a swc config file specific for custom server
|
|
16
|
+
(0, add_swc_config_1.addSwcConfig)(tree, projectRoot, 'commonjs', false, swcConfigName, [
|
|
17
|
+
...additonalExludes,
|
|
18
|
+
'.*.d.ts$',
|
|
19
|
+
]);
|
|
24
20
|
}
|
|
25
21
|
if (!hasSwcDepedency || !hasSwcCliDependency) {
|
|
26
22
|
addSwcDependencies(tree);
|
|
27
|
-
return () => (0, devkit_1.installPackagesTask)(tree);
|
|
28
23
|
}
|
|
24
|
+
return () => (0, devkit_1.installPackagesTask)(tree);
|
|
29
25
|
}
|
|
30
26
|
function addSwcDependencies(tree) {
|
|
31
27
|
return (0, devkit_1.addDependenciesToPackageJson)(tree, {
|