@nx/next 22.0.0-beta.2 → 22.0.0-beta.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 +10 -8
- package/src/generators/library/lib/update-vite-config.d.ts +15 -0
- package/src/generators/library/lib/update-vite-config.d.ts.map +1 -0
- package/src/generators/library/lib/update-vite-config.js +34 -0
- package/src/generators/library/library.d.ts.map +1 -1
- package/src/generators/library/library.js +32 -4
- package/src/plugins/plugin.d.ts +2 -6
- package/src/plugins/plugin.d.ts.map +1 -1
- package/src/plugins/plugin.js +3 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/next",
|
|
3
|
-
"version": "22.0.0-beta.
|
|
3
|
+
"version": "22.0.0-beta.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": "22.0.0-beta.
|
|
38
|
+
"@nx/devkit": "22.0.0-beta.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,15 +44,17 @@
|
|
|
44
44
|
"semver": "^7.5.3",
|
|
45
45
|
"tslib": "^2.3.0",
|
|
46
46
|
"webpack-merge": "^5.8.0",
|
|
47
|
-
"@nx/js": "22.0.0-beta.
|
|
48
|
-
"@nx/eslint": "22.0.0-beta.
|
|
49
|
-
"@nx/react": "22.0.0-beta.
|
|
50
|
-
"@nx/web": "22.0.0-beta.
|
|
51
|
-
"@nx/webpack": "22.0.0-beta.
|
|
47
|
+
"@nx/js": "22.0.0-beta.3",
|
|
48
|
+
"@nx/eslint": "22.0.0-beta.3",
|
|
49
|
+
"@nx/react": "22.0.0-beta.3",
|
|
50
|
+
"@nx/web": "22.0.0-beta.3",
|
|
51
|
+
"@nx/webpack": "22.0.0-beta.3",
|
|
52
52
|
"@phenomnomnominal/tsquery": "~5.0.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"nx": "22.0.0-beta.
|
|
55
|
+
"@nx/cypress": "22.0.0-beta.3",
|
|
56
|
+
"@nx/playwright": "22.0.0-beta.3",
|
|
57
|
+
"nx": "22.0.0-beta.3"
|
|
56
58
|
},
|
|
57
59
|
"publishConfig": {
|
|
58
60
|
"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;
|
|
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
|
-
|
|
65
|
-
|
|
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';
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateDependencies,
|
|
1
|
+
import { CreateDependencies, CreateNodesV2 } from '@nx/devkit';
|
|
2
2
|
export interface NextPluginOptions {
|
|
3
3
|
buildTargetName?: string;
|
|
4
4
|
devTargetName?: string;
|
|
@@ -14,10 +14,6 @@ export interface NextPluginOptions {
|
|
|
14
14
|
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
|
15
15
|
*/
|
|
16
16
|
export declare const createDependencies: CreateDependencies;
|
|
17
|
+
export declare const createNodes: CreateNodesV2<NextPluginOptions>;
|
|
17
18
|
export declare const createNodesV2: CreateNodesV2<NextPluginOptions>;
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
|
|
20
|
-
* This function will change to the v2 function in Nx 21.
|
|
21
|
-
*/
|
|
22
|
-
export declare const createNodes: CreateNodes<NextPluginOptions>;
|
|
23
19
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/next/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/next/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAGlB,aAAa,EAOd,MAAM,YAAY,CAAC;AAYpB,MAAM,WAAW,iBAAiB;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAuBD;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,kBAEhC,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC,iBAAiB,CA0BxD,CAAC;AAEF,eAAO,MAAM,aAAa,kCAAc,CAAC"}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createNodesV2 = exports.createNodes = exports.createDependencies = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
6
6
|
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
@@ -31,7 +31,7 @@ const createDependencies = () => {
|
|
|
31
31
|
return [];
|
|
32
32
|
};
|
|
33
33
|
exports.createDependencies = createDependencies;
|
|
34
|
-
exports.
|
|
34
|
+
exports.createNodes = [
|
|
35
35
|
nextConfigBlob,
|
|
36
36
|
async (configFiles, options, context) => {
|
|
37
37
|
const optionsHash = (0, devkit_internals_1.hashObject)(options);
|
|
@@ -46,23 +46,7 @@ exports.createNodesV2 = [
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
];
|
|
49
|
-
|
|
50
|
-
* @deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
|
|
51
|
-
* This function will change to the v2 function in Nx 21.
|
|
52
|
-
*/
|
|
53
|
-
exports.createNodes = [
|
|
54
|
-
nextConfigBlob,
|
|
55
|
-
async (configFilePath, options, context) => {
|
|
56
|
-
devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 21, this will change to the createNodesV2 API.');
|
|
57
|
-
const optionsHash = (0, devkit_internals_1.hashObject)(options);
|
|
58
|
-
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `next-${optionsHash}.json`);
|
|
59
|
-
const targetsCache = readTargetsCache(cachePath);
|
|
60
|
-
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
|
|
61
|
-
const result = await createNodesInternal(configFilePath, options, context, targetsCache, isTsSolutionSetup);
|
|
62
|
-
writeTargetsToCache(cachePath, targetsCache);
|
|
63
|
-
return result;
|
|
64
|
-
},
|
|
65
|
-
];
|
|
49
|
+
exports.createNodesV2 = exports.createNodes;
|
|
66
50
|
async function createNodesInternal(configFilePath, options, context, targetsCache, isTsSolutionSetup) {
|
|
67
51
|
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
68
52
|
// Do not create a project if package.json and project.json isn't there.
|