@nx/next 23.2.0-pr.36527.2252709 → 23.2.0-pr.36838.ef8e258

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/README.md CHANGED
@@ -7,9 +7,9 @@
7
7
 
8
8
  <div style="text-align: center;">
9
9
 
10
- [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)]()
10
+ [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)](<>)
11
11
  [![NPM Version](https://badge.fury.io/js/nx.svg)](https://www.npmjs.com/package/nx)
12
- [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]()
12
+ [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](<>)
13
13
  [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
14
14
  [![Join us on the Official Nx Discord Server](https://img.shields.io/discord/1143497901675401286?label=discord)](https://go.nx.dev/community)
15
15
  [![Nx Sandboxing](https://staging.nx.app/workspaces/62d013ea0852fe0a2df74438/sandbox-badge.svg)](https://nx.dev/docs/features/ci-features/sandboxing)
@@ -66,19 +66,15 @@ async function buildExecutor(options, context) {
66
66
  start: 'next start',
67
67
  };
68
68
  (0, update_package_json_1.updatePackageJson)(builtPackageJson, context);
69
- (0, devkit_1.writeJsonFile)(`${options.outputPath}/package.json`, builtPackageJson);
69
+ const packageManager = (0, devkit_1.detectPackageManager)(context.root);
70
70
  if (options.generateLockfile) {
71
- const packageManager = (0, devkit_1.detectPackageManager)(context.root);
72
- if (packageManager === 'bun') {
73
- devkit_1.logger.warn('Bun lockfile generation is not supported. The generated package.json will not include a lockfile. Run "bun install" in the output directory after deployment if needed.');
74
- }
75
- else {
76
- const lockFile = (0, js_1.createLockFile)(builtPackageJson, context.projectGraph, packageManager);
77
- (0, node_fs_1.writeFileSync)(`${options.outputPath}/${(0, js_1.getLockFileName)(packageManager)}`, lockFile, {
78
- encoding: 'utf-8',
79
- });
80
- }
71
+ (0, js_1.generatePrunedDeployOutput)(builtPackageJson, context.projectGraph, projectRoot, {
72
+ outputDirectory: options.outputPath,
73
+ packageManager,
74
+ workspaceRoot: context.root,
75
+ });
81
76
  }
77
+ (0, devkit_1.writeJsonFile)(`${options.outputPath}/package.json`, builtPackageJson);
82
78
  // If output path is different from source path, then copy over the config and public files.
83
79
  // This is the default behavior when running `nx build <app>`.
84
80
  if (options.outputPath.replace(/\/$/, '') !== projectRoot) {
@@ -10,6 +10,7 @@ const internal_2 = require("@nx/react/internal");
10
10
  const normalize_options_1 = require("./lib/normalize-options");
11
11
  const add_e2e_1 = require("./lib/add-e2e");
12
12
  const add_jest_1 = require("./lib/add-jest");
13
+ const add_vitest_1 = require("./lib/add-vitest");
13
14
  const add_project_1 = require("./lib/add-project");
14
15
  const create_application_files_1 = require("./lib/create-application-files");
15
16
  const set_defaults_1 = require("./lib/set-defaults");
@@ -61,6 +62,8 @@ async function applicationGeneratorInternal(host, schema) {
61
62
  tasks.push(e2eTask);
62
63
  const jestTask = await (0, add_jest_1.addJest)(host, options);
63
64
  tasks.push(jestTask);
65
+ const vitestTask = await (0, add_vitest_1.addVitest)(host, options);
66
+ tasks.push(vitestTask);
64
67
  const styledTask = (0, styles_1.addStyleDependencies)(host, {
65
68
  style: options.style,
66
69
  swc: !host.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, '.babelrc')),
@@ -15,7 +15,9 @@ async function addJest(host, options) {
15
15
  supportTsx: true,
16
16
  skipSerializers: true,
17
17
  setupFile: 'none',
18
- compiler: 'babel',
18
+ // The generated config is replaced by updateJestConfig, so this only decides
19
+ // which transformer package gets installed; 'tsc' installs none.
20
+ compiler: 'tsc',
19
21
  skipFormat: true,
20
22
  runtimeTsconfigFileName: 'tsconfig.json',
21
23
  });
@@ -50,9 +50,12 @@ function addProject(host, options) {
50
50
  },
51
51
  };
52
52
  }
53
+ const sourceRoot = options.src
54
+ ? (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src')
55
+ : options.appProjectRoot;
53
56
  const project = {
54
57
  root: options.appProjectRoot,
55
- sourceRoot: options.appProjectRoot,
58
+ sourceRoot,
56
59
  projectType: 'application',
57
60
  targets,
58
61
  tags: options.parsedTags,
@@ -71,8 +74,9 @@ function addProject(host, options) {
71
74
  if (options.projectName !== options.importPath) {
72
75
  packageJson.nx = { name: options.projectName };
73
76
  }
77
+ packageJson.nx ??= {};
78
+ packageJson.nx.sourceRoot = sourceRoot;
74
79
  if (options.parsedTags?.length) {
75
- packageJson.nx ??= {};
76
80
  packageJson.nx.tags = options.parsedTags;
77
81
  }
78
82
  }
@@ -0,0 +1,3 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from './normalize-options';
3
+ export declare function addVitest(host: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addVitest = addVitest;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
6
+ const internal_1 = require("@nx/js/internal");
7
+ const versions_1 = require("../../../utils/versions");
8
+ async function addVitest(host, options) {
9
+ if (options.unitTestRunner !== 'vitest') {
10
+ return () => { };
11
+ }
12
+ (0, devkit_1.ensurePackage)('@nx/vitest', versions_1.nxVersion);
13
+ // CommonJS `require` instead of dynamic ESM `import`: `ensurePackage` exposes
14
+ // the temp install via `Module._initPaths`, which ESM ignores.
15
+ const { configurationGenerator, } = require('@nx/vitest/generators');
16
+ const { createOrEditViteConfig, } = require('@nx/vitest/internal');
17
+ const vitestTask = await configurationGenerator(host, {
18
+ project: options.projectName,
19
+ uiFramework: 'react',
20
+ coverageProvider: 'v8',
21
+ testEnvironment: 'jsdom',
22
+ runtimeTsconfigFileName: 'tsconfig.json',
23
+ // Next.js builds with its own toolchain, so the project has no vite config
24
+ // to extend. Write a standalone vitest config below instead.
25
+ skipViteConfig: true,
26
+ addPlugin: options.addPlugin,
27
+ skipPackageJson: options.skipPackageJson,
28
+ skipFormat: true,
29
+ });
30
+ // Vitest cannot resolve the `@/*` alias (or workspace-root aliases in
31
+ // non-TS-solution setups) that Next resolves itself at build time, so mirror
32
+ // the tsconfig `paths` as explicit aliases.
33
+ const tsConfigJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.json'));
34
+ const resolveAlias = {};
35
+ const collectAliases = (paths, prefix) => {
36
+ for (const [key, targets] of Object.entries(paths ?? {})) {
37
+ if (!targets?.[0]) {
38
+ continue;
39
+ }
40
+ if (key.endsWith('/*') && targets[0].endsWith('/*')) {
41
+ resolveAlias[key.slice(0, -2)] = prefix + targets[0].slice(0, -2);
42
+ }
43
+ else if (!key.includes('*')) {
44
+ resolveAlias[key] = prefix + targets[0];
45
+ }
46
+ }
47
+ };
48
+ collectAliases(tsConfigJson?.compilerOptions?.paths, '');
49
+ if (!(0, internal_1.isUsingTsSolutionSetup)(host)) {
50
+ const rootTsConfigPath = (0, js_1.getRootTsConfigPathInTree)(host);
51
+ if (rootTsConfigPath && host.exists(rootTsConfigPath)) {
52
+ const rootTsConfig = (0, devkit_1.readJson)(host, rootTsConfigPath);
53
+ // Path mappings resolve relative to `baseUrl` when the root tsconfig
54
+ // sets one.
55
+ const baseUrl = rootTsConfig?.compilerOptions?.baseUrl ?? '.';
56
+ collectAliases(rootTsConfig?.compilerOptions?.paths, (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(options.appProjectRoot), baseUrl) + '/');
57
+ }
58
+ }
59
+ createOrEditViteConfig(host, {
60
+ project: options.projectName,
61
+ includeLib: false,
62
+ includeVitest: true,
63
+ testEnvironment: 'jsdom',
64
+ // The generated spec lives in `specs/`; colocated specs may sit under
65
+ // `src/`, or under root `app/`/`pages/` when `--no-src` is used.
66
+ testInclude: [
67
+ '{src,app,pages,specs}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
68
+ ],
69
+ imports: [`import react from '@vitejs/plugin-react'`],
70
+ plugins: ['react()'],
71
+ resolveAlias,
72
+ useEsmExtension: true,
73
+ }, true, {
74
+ vitestFileName: true,
75
+ skipPackageJson: options.skipPackageJson,
76
+ skipNxPlugins: true,
77
+ });
78
+ // The generated specs live in `specs/`, which only tsconfig.json covers, so
79
+ // it needs the test types (vitest globals, node) from tsconfig.spec.json.
80
+ const tsConfigSpecJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.spec.json'));
81
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.json'), (json) => {
82
+ json.compilerOptions ??= {};
83
+ json.compilerOptions.types ??= [];
84
+ json.compilerOptions.types.push(...(tsConfigSpecJson?.compilerOptions?.types ?? []));
85
+ return json;
86
+ });
87
+ // tsconfig.spec.json extends tsconfig.base.json in TS solution setups, so
88
+ // specs would not see the app's `@/*` alias without copying it over. Its
89
+ // include also only covers `src/`, so add the `specs/` layout.
90
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.spec.json'), (json) => {
91
+ if (tsConfigJson?.compilerOptions?.paths) {
92
+ json.compilerOptions ??= {};
93
+ json.compilerOptions.paths = {
94
+ ...tsConfigJson.compilerOptions.paths,
95
+ ...json.compilerOptions.paths,
96
+ };
97
+ }
98
+ if (options.js) {
99
+ json.compilerOptions ??= {};
100
+ json.compilerOptions.allowJs = true;
101
+ }
102
+ json.include = [
103
+ ...(json.include ?? []),
104
+ 'specs/**/*.test.ts',
105
+ 'specs/**/*.spec.ts',
106
+ 'specs/**/*.test.tsx',
107
+ 'specs/**/*.spec.tsx',
108
+ 'specs/**/*.test.js',
109
+ 'specs/**/*.spec.js',
110
+ 'specs/**/*.test.jsx',
111
+ 'specs/**/*.spec.jsx',
112
+ ];
113
+ return json;
114
+ });
115
+ return vitestTask;
116
+ }
@@ -7,7 +7,7 @@ export interface Schema {
7
7
  style?: SupportedStyles;
8
8
  skipFormat?: boolean;
9
9
  tags?: string;
10
- unitTestRunner?: 'jest' | 'none';
10
+ unitTestRunner?: 'jest' | 'vitest' | 'none';
11
11
  e2eTestRunner?: 'cypress' | 'playwright' | 'none';
12
12
  linter?: LinterType;
13
13
  js?: boolean;
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "unitTestRunner": {
68
68
  "type": "string",
69
- "enum": ["jest", "none"],
69
+ "enum": ["vitest", "jest", "none"],
70
70
  "description": "Test runner to use for unit tests.",
71
71
  "default": "none",
72
72
  "x-prompt": "What unit test runner should be used?",
@@ -43,10 +43,6 @@ async function libraryGeneratorInternal(host, rawOptions) {
43
43
  tasks.push(libTask);
44
44
  if (!options.skipPackageJson) {
45
45
  const devDependencies = {};
46
- if (options.linter === 'eslint') {
47
- devDependencies['eslint-config-next'] = versions_1.eslintConfigNextVersion;
48
- devDependencies['@next/eslint-plugin-next'] = versions_1.eslintConfigNextVersion;
49
- }
50
46
  if (options.unitTestRunner && options.unitTestRunner !== 'none') {
51
47
  devDependencies['@testing-library/react'] = internal_1.testingLibraryReactVersion;
52
48
  devDependencies['@testing-library/dom'] = internal_1.testingLibraryDomVersion;
@@ -71,6 +67,27 @@ export async function HelloServer() {
71
67
  if (!options.skipTsConfig && !isTsSolutionSetup) {
72
68
  (0, js_1.addTsConfigPath)(host, `${options.importPath}/server`, [serverEntryPath]);
73
69
  }
70
+ const isBuildable = (options.bundler && options.bundler !== 'none') ||
71
+ options.buildable ||
72
+ options.publishable;
73
+ if (isTsSolutionSetup && !isBuildable) {
74
+ // Non-buildable libs resolve `.` straight to source, so `./server` does the same.
75
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
76
+ if (host.exists(packageJsonPath)) {
77
+ (0, devkit_1.updateJson)(host, packageJsonPath, (json) => {
78
+ json.exports ??= {};
79
+ const serverSource = `./src/server.${options.js ? 'js' : 'ts'}`;
80
+ json.exports['./server'] = options.js
81
+ ? serverSource
82
+ : {
83
+ types: serverSource,
84
+ import: serverSource,
85
+ default: serverSource,
86
+ };
87
+ return json;
88
+ });
89
+ }
90
+ }
74
91
  // Configure Vite and package.json for server entry point when using Vite bundler
75
92
  if (options.bundler === 'vite') {
76
93
  // Update vite.config.mts to support multiple entry points
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/schema",
3
3
  "cli": "nx",
4
- "$id": "NxReactLibrary",
5
- "title": "Create a React Library for Nx",
6
- "description": "Create a React Library for an Nx workspace.",
4
+ "$id": "NxNextLibrary",
5
+ "title": "Create a Next.js Library for Nx",
6
+ "description": "Create a Next.js library for an Nx workspace. Same output as `@nx/react:library`, plus a `server` entry point for React Server Components and the Next.js type declarations.",
7
7
  "type": "object",
8
8
  "properties": {
9
9
  "directory": {
@@ -310,17 +310,13 @@ Turbopack is now the default bundler for development.
310
310
  // BEFORE (Next.js 15)
311
311
  const nextConfig = {
312
312
  experimental: {
313
- turbopack: {
314
- /* options */
315
- },
313
+ turbopack: {/* options */},
316
314
  },
317
315
  };
318
316
 
319
317
  // AFTER (Next.js 16)
320
318
  const nextConfig = {
321
- turbopack: {
322
- /* options */
323
- },
319
+ turbopack: {/* options */},
324
320
  };
325
321
  ```
326
322
 
package/generators.json CHANGED
@@ -31,7 +31,7 @@
31
31
  "schema": "./dist/src/generators/library/schema.json",
32
32
  "aliases": ["lib"],
33
33
  "x-type": "library",
34
- "description": "Create a library."
34
+ "description": "Create a Next.js library."
35
35
  },
36
36
  "custom-server": {
37
37
  "factory": "./dist/src/generators/custom-server/custom-server#customServerGenerator",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/next",
3
- "version": "23.2.0-pr.36527.2252709",
3
+ "version": "23.2.0-pr.36838.ef8e258",
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.2.0-pr.36527.2252709"
71
+ "@nx/webpack": "23.2.0-pr.36838.ef8e258"
72
72
  },
73
73
  "peerDependenciesMeta": {
74
74
  "@nx/webpack": {
@@ -83,17 +83,18 @@
83
83
  "tslib": "^2.3.0",
84
84
  "webpack-merge": "^5.8.0",
85
85
  "@phenomnomnominal/tsquery": "~6.2.0",
86
- "@nx/devkit": "23.2.0-pr.36527.2252709",
87
- "@nx/js": "23.2.0-pr.36527.2252709",
88
- "@nx/eslint": "23.2.0-pr.36527.2252709",
89
- "@nx/react": "23.2.0-pr.36527.2252709",
90
- "@nx/web": "23.2.0-pr.36527.2252709"
86
+ "@nx/devkit": "23.2.0-pr.36838.ef8e258",
87
+ "@nx/js": "23.2.0-pr.36838.ef8e258",
88
+ "@nx/eslint": "23.2.0-pr.36838.ef8e258",
89
+ "@nx/react": "23.2.0-pr.36838.ef8e258",
90
+ "@nx/web": "23.2.0-pr.36838.ef8e258"
91
91
  },
92
92
  "devDependencies": {
93
- "@nx/cypress": "23.2.0-pr.36527.2252709",
94
- "@nx/playwright": "23.2.0-pr.36527.2252709",
95
- "@nx/webpack": "23.2.0-pr.36527.2252709",
96
- "nx": "23.2.0-pr.36527.2252709"
93
+ "@nx/cypress": "23.2.0-pr.36838.ef8e258",
94
+ "@nx/playwright": "23.2.0-pr.36838.ef8e258",
95
+ "@nx/vitest": "23.2.0-pr.36838.ef8e258",
96
+ "@nx/webpack": "23.2.0-pr.36838.ef8e258",
97
+ "nx": "23.2.0-pr.36838.ef8e258"
97
98
  },
98
99
  "publishConfig": {
99
100
  "access": "public"