@nx/next 21.6.3 → 21.6.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/next",
3
- "version": "21.6.3",
3
+ "version": "21.6.4",
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": "21.6.3",
38
+ "@nx/devkit": "21.6.4",
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,15 +44,15 @@
44
44
  "semver": "^7.5.3",
45
45
  "tslib": "^2.3.0",
46
46
  "webpack-merge": "^5.8.0",
47
- "@nx/js": "21.6.3",
48
- "@nx/eslint": "21.6.3",
49
- "@nx/react": "21.6.3",
50
- "@nx/web": "21.6.3",
51
- "@nx/webpack": "21.6.3",
47
+ "@nx/js": "21.6.4",
48
+ "@nx/eslint": "21.6.4",
49
+ "@nx/react": "21.6.4",
50
+ "@nx/web": "21.6.4",
51
+ "@nx/webpack": "21.6.4",
52
52
  "@phenomnomnominal/tsquery": "~5.0.1"
53
53
  },
54
54
  "devDependencies": {
55
- "nx": "21.6.3"
55
+ "nx": "21.6.4"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"
@@ -0,0 +1,15 @@
1
+ import { Tree } from '@nx/devkit';
2
+ /**
3
+ * Updates a Vite config to support multiple entry points for Next.js libraries.
4
+ * Transforms:
5
+ * 1. entry: 'src/index.ts' -> entry: { index: 'src/index.ts', server: 'src/server.ts' }
6
+ * 2. fileName: 'index' -> fileName: (format, entryName) => `${entryName}.js`
7
+ *
8
+ * Note: We know the shape of the vite config that is being generated, therefore string manipulation is fine
9
+ *
10
+ * @param tree - The file system tree
11
+ * @param viteConfigPath - Path to the vite.config.ts file
12
+ * @returns true if the config was updated, false otherwise
13
+ */
14
+ export declare function updateViteConfigForServerEntry(tree: Tree, viteConfigPath: string): boolean;
15
+ //# sourceMappingURL=update-vite-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-vite-config.d.ts","sourceRoot":"","sources":["../../../../../../../packages/next/src/generators/library/lib/update-vite-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,IAAI,EACV,cAAc,EAAE,MAAM,GACrB,OAAO,CA4BT"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateViteConfigForServerEntry = updateViteConfigForServerEntry;
4
+ /**
5
+ * Updates a Vite config to support multiple entry points for Next.js libraries.
6
+ * Transforms:
7
+ * 1. entry: 'src/index.ts' -> entry: { index: 'src/index.ts', server: 'src/server.ts' }
8
+ * 2. fileName: 'index' -> fileName: (format, entryName) => `${entryName}.js`
9
+ *
10
+ * Note: We know the shape of the vite config that is being generated, therefore string manipulation is fine
11
+ *
12
+ * @param tree - The file system tree
13
+ * @param viteConfigPath - Path to the vite.config.ts file
14
+ * @returns true if the config was updated, false otherwise
15
+ */
16
+ function updateViteConfigForServerEntry(tree, viteConfigPath) {
17
+ if (!tree.exists(viteConfigPath)) {
18
+ return false;
19
+ }
20
+ const viteConfigContent = tree.read(viteConfigPath, 'utf-8');
21
+ // Replace single entry string with multiple entry object
22
+ const updatedViteConfig = viteConfigContent
23
+ .replace(/entry:\s*['"]src\/index\.ts['"]/, `entry: {
24
+ index: 'src/index.ts',
25
+ server: 'src/server.ts',
26
+ }`)
27
+ .replace(/fileName:\s*['"]index['"]/, `fileName: (format, entryName) => \`\${entryName}.js\``);
28
+ // Only write if changes were made
29
+ if (updatedViteConfig !== viteConfigContent) {
30
+ tree.write(viteConfigPath, updatedViteConfig);
31
+ return true;
32
+ }
33
+ return false;
34
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../../../../../packages/next/src/generators/library/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAGjB,IAAI,EAEL,MAAM,YAAY,CAAC;AASpB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAWlC,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,8BAMpE;AAED,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,8BAuJ5E;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../../../../../packages/next/src/generators/library/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAGjB,IAAI,EAEL,MAAM,YAAY,CAAC;AASpB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAalC,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,8BAMpE;AAED,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,8BA+L5E;AAED,eAAe,gBAAgB,CAAC"}
@@ -8,6 +8,7 @@ const js_1 = require("@nx/js");
8
8
  const versions_1 = require("@nx/react/src/utils/versions");
9
9
  const init_1 = require("../init/init");
10
10
  const normalize_options_1 = require("./lib/normalize-options");
11
+ const update_vite_config_1 = require("./lib/update-vite-config");
11
12
  const versions_2 = require("../../utils/versions");
12
13
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
13
14
  const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
@@ -61,14 +62,41 @@ async function libraryGeneratorInternal(host, rawOptions) {
61
62
  host.write((0, devkit_1.joinPathFragments)(options.projectRoot, 'src', `server.${options.js ? 'js' : 'ts'}`), `// Use this file to export React server components
62
63
  export * from './lib/hello-server';`);
63
64
  host.write((0, devkit_1.joinPathFragments)(options.projectRoot, 'src/lib', `hello-server.${options.js ? 'js' : 'tsx'}`), `// React server components are async so you make database or API calls.
64
- export async function HelloServer() {
65
- return <h1>Hello Server</h1>
66
- }
67
- `);
65
+ export async function HelloServer() {
66
+ return <h1>Hello Server</h1>;
67
+ }
68
+ `);
68
69
  const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
69
70
  if (!options.skipTsConfig && !isTsSolutionSetup) {
70
71
  (0, js_1.addTsConfigPath)(host, `${options.importPath}/server`, [serverEntryPath]);
71
72
  }
73
+ // Configure Vite and package.json for server entry point when using Vite bundler
74
+ if (options.bundler === 'vite') {
75
+ // Update vite.config.ts to support multiple entry points
76
+ const viteConfigPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'vite.config.ts');
77
+ (0, update_vite_config_1.updateViteConfigForServerEntry)(host, viteConfigPath);
78
+ // Update package.json to include server export
79
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
80
+ if (host.exists(packageJsonPath)) {
81
+ (0, devkit_1.updateJson)(host, packageJsonPath, (json) => {
82
+ if (!json.exports) {
83
+ json.exports = {};
84
+ }
85
+ // Add server export
86
+ const serverExport = {};
87
+ // For TS Solution setups, include development condition
88
+ if (isTsSolutionSetup) {
89
+ const customConditionName = (0, ts_solution_setup_1.getDefinedCustomConditionName)(host);
90
+ serverExport[customConditionName] = './src/server.ts';
91
+ }
92
+ serverExport.types = './dist/server.d.ts';
93
+ serverExport.import = './dist/server.js';
94
+ serverExport.default = './dist/server.js';
95
+ json.exports['./server'] = serverExport;
96
+ return json;
97
+ });
98
+ }
99
+ }
72
100
  (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
73
101
  if (options.style === '@emotion/styled') {
74
102
  json.compilerOptions.jsxImportSource = '@emotion/react';