@nx/next 23.3.0-beta.0 → 23.3.0-beta.1

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.
@@ -0,0 +1,8 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import type { NormalizedSchema } from './normalize-options';
3
+ /**
4
+ * Adds the server entry (`src/server.ts`, or `src/server.js` with `--js`) as a
5
+ * second Rollup entry so React Server Components are bundled separately from
6
+ * the client entry.
7
+ */
8
+ export declare function addRollupServerEntry(tree: Tree, options: NormalizedSchema): void;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addRollupServerEntry = addRollupServerEntry;
4
+ const devkit_1 = require("@nx/devkit");
5
+ /**
6
+ * Adds the server entry (`src/server.ts`, or `src/server.js` with `--js`) as a
7
+ * second Rollup entry so React Server Components are bundled separately from
8
+ * the client entry.
9
+ */
10
+ function addRollupServerEntry(tree, options) {
11
+ const serverEntry = `src/server.${options.js ? 'js' : 'ts'}`;
12
+ const rollupConfigPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'rollup.config.cjs');
13
+ if (tree.exists(rollupConfigPath)) {
14
+ const content = tree.read(rollupConfigPath, 'utf-8');
15
+ const updated = content.replace(/^(\s*)main: .*\n/m, (line, indent) => line + `${indent}additionalEntryPoints: ['./${serverEntry}'],\n`);
16
+ if (updated === content) {
17
+ throw new Error(`Could not add the server entry to ${rollupConfigPath}: "main" option not found.`);
18
+ }
19
+ tree.write(rollupConfigPath, updated);
20
+ return;
21
+ }
22
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
23
+ const build = project.targets?.build;
24
+ if (build?.executor !== '@nx/rollup:rollup') {
25
+ throw new Error(`Could not add the server entry to the "build" target of "${options.projectName}": expected the @nx/rollup:rollup executor.`);
26
+ }
27
+ build.options.additionalEntryPoints = [
28
+ (0, devkit_1.joinPathFragments)(options.projectRoot, serverEntry),
29
+ ];
30
+ (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
31
+ }
@@ -4,6 +4,7 @@ import type { LinterType } from '@nx/js';
4
4
  export interface NormalizedSchema extends Schema {
5
5
  linter: LinterType;
6
6
  importPath: string;
7
+ projectName: string;
7
8
  projectRoot: string;
8
9
  isUsingTsSolutionConfig: boolean;
9
10
  }
@@ -6,7 +6,7 @@ const internal_1 = require("@nx/devkit/internal");
6
6
  const internal_2 = require("@nx/js/internal");
7
7
  async function normalizeOptions(host, options) {
8
8
  await (0, internal_1.ensureRootProjectName)(options, 'library');
9
- const { projectRoot, importPath } = await (0, internal_1.determineProjectNameAndRootOptions)(host, {
9
+ const { projectName, projectRoot, importPath } = await (0, internal_1.determineProjectNameAndRootOptions)(host, {
10
10
  name: options.name,
11
11
  projectType: 'library',
12
12
  directory: options.directory,
@@ -23,6 +23,8 @@ async function normalizeOptions(host, options) {
23
23
  // `=== 'eslint'`, and an unresolved `undefined` would skip all of it.
24
24
  linter: await (0, internal_2.normalizeLinterOption)(host, options.linter),
25
25
  importPath,
26
+ // Same rule as the React library generator, which registers the project.
27
+ projectName: isUsingTsSolutionConfig && !options.name ? importPath : projectName,
26
28
  projectRoot,
27
29
  isUsingTsSolutionConfig,
28
30
  useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig,
@@ -10,6 +10,7 @@ const init_1 = require("../init/init");
10
10
  const assert_supported_next_version_1 = require("../../utils/assert-supported-next-version");
11
11
  const normalize_options_1 = require("./lib/normalize-options");
12
12
  const update_vite_config_1 = require("./lib/update-vite-config");
13
+ const add_rollup_server_entry_1 = require("./lib/add-rollup-server-entry");
13
14
  const versions_1 = require("../../utils/versions");
14
15
  const internal_2 = require("@nx/js/internal");
15
16
  async function libraryGenerator(host, rawOptions) {
@@ -67,10 +68,25 @@ export async function HelloServer() {
67
68
  if (!options.skipTsConfig && !isTsSolutionSetup) {
68
69
  (0, js_1.addTsConfigPath)(host, `${options.importPath}/server`, [serverEntryPath]);
69
70
  }
70
- const isBuildable = (options.bundler && options.bundler !== 'none') ||
71
- options.buildable ||
72
- options.publishable;
73
- if (isTsSolutionSetup && !isBuildable) {
71
+ // The React library generator defaults buildable and publishable libraries to Rollup.
72
+ const bundler = options.bundler && options.bundler !== 'none'
73
+ ? options.bundler
74
+ : options.buildable || options.publishable
75
+ ? 'rollup'
76
+ : 'none';
77
+ if (bundler === 'vite') {
78
+ (0, update_vite_config_1.updateViteConfigForServerEntry)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'vite.config.mts'));
79
+ addServerExport(host, options, './dist/server.js');
80
+ }
81
+ else if (bundler === 'rollup') {
82
+ (0, add_rollup_server_entry_1.addRollupServerEntry)(host, options);
83
+ if (isTsSolutionSetup) {
84
+ // Other setups publish no exports field, and introducing one would close
85
+ // every other subpath of the package.
86
+ addServerExport(host, options, './dist/server.esm.js');
87
+ }
88
+ }
89
+ else if (bundler === 'none' && isTsSolutionSetup) {
74
90
  // Non-buildable libs resolve `.` straight to source, so `./server` does the same.
75
91
  const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
76
92
  if (host.exists(packageJsonPath)) {
@@ -88,33 +104,6 @@ export async function HelloServer() {
88
104
  });
89
105
  }
90
106
  }
91
- // Configure Vite and package.json for server entry point when using Vite bundler
92
- if (options.bundler === 'vite') {
93
- // Update vite.config.mts to support multiple entry points
94
- const viteConfigPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'vite.config.mts');
95
- (0, update_vite_config_1.updateViteConfigForServerEntry)(host, viteConfigPath);
96
- // Update package.json to include server export
97
- const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
98
- if (host.exists(packageJsonPath)) {
99
- (0, devkit_1.updateJson)(host, packageJsonPath, (json) => {
100
- if (!json.exports) {
101
- json.exports = {};
102
- }
103
- // Add server export
104
- const serverExport = {};
105
- // For TS Solution setups, include development condition
106
- if (isTsSolutionSetup) {
107
- const customConditionName = (0, internal_2.getDefinedCustomConditionName)(host);
108
- serverExport[customConditionName] = './src/server.ts';
109
- }
110
- serverExport.types = './dist/server.d.ts';
111
- serverExport.import = './dist/server.js';
112
- serverExport.default = './dist/server.js';
113
- json.exports['./server'] = serverExport;
114
- return json;
115
- });
116
- }
117
- }
118
107
  (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'), (json) => {
119
108
  if (!json.compilerOptions) {
120
109
  json.compilerOptions = {
@@ -147,4 +136,27 @@ export async function HelloServer() {
147
136
  }
148
137
  return (0, devkit_1.runTasksInSerial)(...tasks);
149
138
  }
139
+ function addServerExport(host, options, distFile) {
140
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
141
+ if (!host.exists(packageJsonPath)) {
142
+ return;
143
+ }
144
+ (0, devkit_1.updateJson)(host, packageJsonPath, (json) => {
145
+ json.exports ??= {};
146
+ const serverExport = {};
147
+ if (options.isUsingTsSolutionConfig) {
148
+ const customConditionName = (0, internal_2.getDefinedCustomConditionName)(host);
149
+ if (customConditionName) {
150
+ serverExport[customConditionName] = `./src/server.${options.js ? 'js' : 'ts'}`;
151
+ }
152
+ }
153
+ // Both bundlers name the declaration after the entry, without the format
154
+ // suffix the JavaScript output carries.
155
+ serverExport.types = './dist/server.d.ts';
156
+ serverExport.import = distFile;
157
+ serverExport.default = distFile;
158
+ json.exports['./server'] = serverExport;
159
+ return json;
160
+ });
161
+ }
150
162
  exports.default = libraryGenerator;
@@ -74,8 +74,8 @@ async function buildNextTargets(nextConfigPath, projectRoot, options, context, i
74
74
  const namedInputs = (0, internal_1.getNamedInputs)(projectRoot, context);
75
75
  const targets = {};
76
76
  targets[options.buildTargetName] = await getBuildTargetConfig(namedInputs, projectRoot, nextConfig, isTsSolutionSetup);
77
- targets[options.devTargetName] = getDevTargetConfig(projectRoot, isTsSolutionSetup);
78
- const startTarget = getStartTargetConfig(options, projectRoot);
77
+ targets[options.devTargetName] = getDevTargetConfig(namedInputs, projectRoot, isTsSolutionSetup);
78
+ const startTarget = getStartTargetConfig(namedInputs, options, projectRoot);
79
79
  targets[options.startTargetName] = startTarget;
80
80
  targets[options.serveStaticTargetName] = startTarget;
81
81
  (0, internal_2.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmc);
@@ -104,20 +104,21 @@ async function getBuildTargetConfig(namedInputs, projectRoot, nextConfig, isTsSo
104
104
  }
105
105
  return targetConfig;
106
106
  }
107
- function getDevTargetConfig(projectRoot, isTsSolutionSetup) {
107
+ function getDevTargetConfig(namedInputs, projectRoot, isTsSolutionSetup) {
108
108
  const targetConfig = {
109
109
  continuous: true,
110
110
  command: `next dev`,
111
111
  options: {
112
112
  cwd: projectRoot,
113
113
  },
114
+ inputs: getInputs(namedInputs),
114
115
  };
115
116
  if (isTsSolutionSetup) {
116
117
  targetConfig.syncGenerators = ['@nx/js:typescript-sync'];
117
118
  }
118
119
  return targetConfig;
119
120
  }
120
- function getStartTargetConfig(options, projectRoot) {
121
+ function getStartTargetConfig(namedInputs, options, projectRoot) {
121
122
  const targetConfig = {
122
123
  continuous: true,
123
124
  command: `next start`,
@@ -125,6 +126,7 @@ function getStartTargetConfig(options, projectRoot) {
125
126
  cwd: projectRoot,
126
127
  },
127
128
  dependsOn: [options.buildTargetName],
129
+ inputs: getInputs(namedInputs),
128
130
  };
129
131
  return targetConfig;
130
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/next",
3
- "version": "23.3.0-beta.0",
3
+ "version": "23.3.0-beta.1",
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": {
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "peerDependencies": {
70
70
  "next": ">=14.0.0 <17.0.0",
71
- "@nx/webpack": "23.3.0-beta.0"
71
+ "@nx/webpack": "23.3.0-beta.1"
72
72
  },
73
73
  "peerDependenciesMeta": {
74
74
  "@nx/webpack": {
@@ -83,18 +83,19 @@
83
83
  "tslib": "^2.3.0",
84
84
  "webpack-merge": "^5.8.0",
85
85
  "@phenomnomnominal/tsquery": "~6.2.0",
86
- "@nx/devkit": "23.3.0-beta.0",
87
- "@nx/js": "23.3.0-beta.0",
88
- "@nx/eslint": "23.3.0-beta.0",
89
- "@nx/react": "23.3.0-beta.0",
90
- "@nx/web": "23.3.0-beta.0"
86
+ "@nx/devkit": "23.3.0-beta.1",
87
+ "@nx/js": "23.3.0-beta.1",
88
+ "@nx/eslint": "23.3.0-beta.1",
89
+ "@nx/react": "23.3.0-beta.1",
90
+ "@nx/web": "23.3.0-beta.1"
91
91
  },
92
92
  "devDependencies": {
93
- "@nx/cypress": "23.3.0-beta.0",
94
- "@nx/playwright": "23.3.0-beta.0",
95
- "@nx/vitest": "23.3.0-beta.0",
96
- "@nx/webpack": "23.3.0-beta.0",
97
- "nx": "23.3.0-beta.0"
93
+ "next": "15.5.25",
94
+ "@nx/cypress": "23.3.0-beta.1",
95
+ "@nx/playwright": "23.3.0-beta.1",
96
+ "@nx/vitest": "23.3.0-beta.1",
97
+ "@nx/webpack": "23.3.0-beta.1",
98
+ "nx": "23.3.0-beta.1"
98
99
  },
99
100
  "publishConfig": {
100
101
  "access": "public"