@nx/next 20.2.0-beta.3 → 20.2.0-beta.5

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": "20.2.0-beta.3",
3
+ "version": "20.2.0-beta.5",
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.2.0-beta.3",
38
+ "@nx/devkit": "20.2.0-beta.5",
39
39
  "@babel/plugin-proposal-decorators": "^7.22.7",
40
40
  "@svgr/webpack": "^8.0.1",
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.2.0-beta.3",
48
- "@nx/eslint": "20.2.0-beta.3",
49
- "@nx/react": "20.2.0-beta.3",
50
- "@nx/web": "20.2.0-beta.3",
51
- "@nx/webpack": "20.2.0-beta.3",
47
+ "@nx/js": "20.2.0-beta.5",
48
+ "@nx/eslint": "20.2.0-beta.5",
49
+ "@nx/react": "20.2.0-beta.5",
50
+ "@nx/web": "20.2.0-beta.5",
51
+ "@nx/webpack": "20.2.0-beta.5",
52
52
  "@phenomnomnominal/tsquery": "~5.0.1"
53
53
  },
54
54
  "publishConfig": {
@@ -154,7 +154,7 @@ function stripOuterQuotes(str) {
154
154
  }
155
155
  // Exported for testing
156
156
  function ensureFileExtensions(files, absoluteDir) {
157
- const extensions = ['.js', '.cjs', '.mjs', '.json'];
157
+ const extensions = ['.js', '.cjs', '.mjs', '.json', '.ts'];
158
158
  return files.map((file) => {
159
159
  const providedExt = (0, path_1.extname)(file);
160
160
  if (providedExt && extensions.includes(providedExt))
@@ -3,4 +3,4 @@ import { NextServeBuilderOptions } from '../../utils/types';
3
3
  export default function serveExecutor(options: NextServeBuilderOptions, context: ExecutorContext): AsyncGenerator<{
4
4
  success: boolean;
5
5
  baseUrl: string;
6
- }, void, undefined>;
6
+ }, void, any>;
@@ -4,7 +4,6 @@ exports.applicationGenerator = applicationGenerator;
4
4
  exports.applicationGeneratorInternal = applicationGeneratorInternal;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const js_1 = require("@nx/js");
7
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
7
  const react_1 = require("@nx/react");
9
8
  const versions_1 = require("@nx/react/src/utils/versions");
10
9
  const normalize_options_1 = require("./lib/normalize-options");
@@ -22,6 +21,7 @@ const update_cypress_tsconfig_1 = require("./lib/update-cypress-tsconfig");
22
21
  const show_possible_warnings_1 = require("./lib/show-possible-warnings");
23
22
  const versions_2 = require("../../utils/versions");
24
23
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
24
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
25
25
  async function applicationGenerator(host, schema) {
26
26
  return await applicationGeneratorInternal(host, {
27
27
  addPlugin: false,
@@ -29,7 +29,6 @@ async function applicationGenerator(host, schema) {
29
29
  });
30
30
  }
31
31
  async function applicationGeneratorInternal(host, schema) {
32
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'next', 'application');
33
32
  const tasks = [];
34
33
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
35
34
  (0, show_possible_warnings_1.showPossibleWarnings)(host, options);
@@ -37,6 +36,8 @@ async function applicationGeneratorInternal(host, schema) {
37
36
  js: options.js,
38
37
  skipPackageJson: options.skipPackageJson,
39
38
  skipFormat: true,
39
+ addTsPlugin: schema.useTsSolution,
40
+ formatter: schema.formatter,
40
41
  });
41
42
  tasks.push(jsInitTask);
42
43
  const nextTask = await (0, init_1.nextInitGenerator)(host, {
@@ -82,6 +83,13 @@ async function applicationGeneratorInternal(host, schema) {
82
83
  }
83
84
  tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, { tslib: versions_2.tsLibVersion }, devDependencies));
84
85
  }
86
+ (0, ts_solution_setup_1.updateTsconfigFiles)(host, options.appProjectRoot, 'tsconfig.json', {
87
+ jsx: 'preserve',
88
+ module: 'esnext',
89
+ moduleResolution: 'bundler',
90
+ }, options.linter === 'eslint'
91
+ ? ['.next', 'eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
92
+ : ['.next'], options.src ? 'src' : '.');
85
93
  if (!options.skipFormat) {
86
94
  await (0, devkit_1.formatFiles)(host);
87
95
  }
@@ -3,16 +3,22 @@
3
3
  "compilerOptions": {
4
4
  "jsx": "preserve",
5
5
  <% if (style === '@emotion/styled') { %>"jsxImportSource": "@emotion/react",<% } %>
6
- "allowJs": true,
7
- "esModuleInterop": true,
8
- "allowSyntheticDefaultImports": true,
9
6
  "strict": true,
10
- "forceConsistentCasingInFileNames": true,
11
7
  "noEmit": true,
8
+ "esModuleInterop": true,
9
+ "module": "esnext",
10
+ "moduleResolution": "bundler",
12
11
  "resolveJsonModule": true,
13
12
  "isolatedModules": true,
13
+ "lib": ["dom", "dom.iterable", "esnext"],
14
+ "allowJs": true,
15
+ "allowSyntheticDefaultImports": true,
16
+ "forceConsistentCasingInFileNames": true,
14
17
  "incremental": true,
15
- "plugins": [{ "name": "next" }]
18
+ "plugins": [{ "name": "next" }]<% if (isUsingTsSolutionSetup) { %>,
19
+ "paths": {
20
+ "@/*": [<% if (src) { %>"./src/*"<% } else { %>"./*"<% } %>]
21
+ }<% } %>
16
22
  },
17
23
  "include": [
18
24
  "<%= rootPath %>**/*.ts",
@@ -8,6 +8,7 @@ const web_1 = require("@nx/web");
8
8
  const find_plugin_for_config_file_1 = require("@nx/devkit/src/utils/find-plugin-for-config-file");
9
9
  const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
10
10
  const e2e_web_server_info_utils_1 = require("@nx/devkit/src/generators/e2e-web-server-info-utils");
11
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
11
12
  async function addE2e(host, options) {
12
13
  const nxJson = (0, devkit_1.readNxJson)(host);
13
14
  const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
@@ -24,13 +25,28 @@ async function addE2e(host, options) {
24
25
  spa: true,
25
26
  });
26
27
  }
27
- (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
28
- root: options.e2eProjectRoot,
29
- sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
30
- targets: {},
31
- tags: [],
32
- implicitDependencies: [options.projectName],
33
- });
28
+ if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
29
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
30
+ name: options.e2eProjectName,
31
+ version: '0.0.1',
32
+ private: true,
33
+ nx: {
34
+ projectType: 'application',
35
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
36
+ implicitDependencies: [options.projectName],
37
+ },
38
+ });
39
+ }
40
+ else {
41
+ (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
42
+ root: options.e2eProjectRoot,
43
+ projectType: 'application',
44
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
45
+ targets: {},
46
+ tags: [],
47
+ implicitDependencies: [options.projectName],
48
+ });
49
+ }
34
50
  const e2eTask = await configurationGenerator(host, {
35
51
  ...options,
36
52
  linter: eslint_1.Linter.EsLint,
@@ -65,13 +81,28 @@ async function addE2e(host, options) {
65
81
  }
66
82
  else if (options.e2eTestRunner === 'playwright') {
67
83
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_1.nxVersion);
68
- (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
69
- root: options.e2eProjectRoot,
70
- sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
71
- targets: {},
72
- tags: [],
73
- implicitDependencies: [options.projectName],
74
- });
84
+ if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
85
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
86
+ name: options.e2eProjectName,
87
+ version: '0.0.1',
88
+ private: true,
89
+ nx: {
90
+ projectType: 'application',
91
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
92
+ implicitDependencies: [options.projectName],
93
+ },
94
+ });
95
+ }
96
+ else {
97
+ (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
98
+ root: options.e2eProjectRoot,
99
+ projectType: 'application',
100
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
101
+ targets: {},
102
+ tags: [],
103
+ implicitDependencies: [options.projectName],
104
+ });
105
+ }
75
106
  const e2eTask = await configurationGenerator(host, {
76
107
  rootProject: options.rootProject,
77
108
  project: options.e2eProjectName,
@@ -8,6 +8,8 @@ const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
8
8
  const versions_1 = require("../../../utils/versions");
9
9
  const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
10
10
  async function addLinting(host, options) {
11
+ if (options.linter !== 'eslint')
12
+ return () => { };
11
13
  const tasks = [];
12
14
  tasks.push(await (0, eslint_1.lintProjectGenerator)(host, {
13
15
  linter: options.linter,
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addProject = addProject;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
6
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
+ const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
8
+ const versions_1 = require("../../../utils/versions");
9
+ const react_1 = require("@nx/react");
6
10
  function addProject(host, options) {
7
11
  const targets = {};
8
12
  // Check if plugin exists in nx.json and if it doesn't then we can continue
@@ -53,7 +57,27 @@ function addProject(host, options) {
53
57
  targets,
54
58
  tags: options.parsedTags,
55
59
  };
56
- (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
57
- ...project,
58
- });
60
+ if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
61
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
62
+ name: (0, get_import_path_1.getImportPath)(host, options.name),
63
+ version: '0.0.1',
64
+ private: true,
65
+ dependencies: {
66
+ next: versions_1.nextVersion,
67
+ react: react_1.reactVersion,
68
+ 'react-dom': react_1.reactDomVersion,
69
+ },
70
+ nx: {
71
+ name: options.name,
72
+ projectType: 'application',
73
+ sourceRoot: options.appProjectRoot,
74
+ tags: options.parsedTags?.length ? options.parsedTags : undefined,
75
+ },
76
+ });
77
+ }
78
+ else {
79
+ (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
80
+ ...project,
81
+ });
82
+ }
59
83
  }
@@ -5,12 +5,12 @@ const path_1 = require("path");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const js_1 = require("@nx/js");
7
7
  const create_application_files_helpers_1 = require("./create-application-files.helpers");
8
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
9
  function createApplicationFiles(host, options) {
9
10
  const offsetFromRoot = (0, devkit_1.offsetFromRoot)(options.appProjectRoot);
10
11
  const layoutTypeSrcPath = (0, devkit_1.joinPathFragments)(offsetFromRoot, options.appProjectRoot, '.next/types/**/*.ts');
11
12
  const layoutTypeDistPath = (0, devkit_1.joinPathFragments)(offsetFromRoot, options.outputPath, '.next/types/**/*.ts');
12
- // scope tsconfig to the project directory so that it doesn't include other projects/libs
13
- const rootPath = options.rootProject
13
+ const rootPath = options.rootProject || (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)
14
14
  ? options.src
15
15
  ? 'src/'
16
16
  : options.appDir
@@ -32,6 +32,7 @@ function createApplicationFiles(host, options) {
32
32
  styleContent: (0, create_application_files_helpers_1.createStyleRules)(),
33
33
  pageStyleContent: `.page {}`,
34
34
  stylesExt: options.style === 'less' ? options.style : 'css',
35
+ isUsingTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
35
36
  };
36
37
  const generatedAppFilePath = options.src
37
38
  ? (0, path_1.join)(options.appProjectRoot, 'src')
@@ -17,6 +17,9 @@ export interface Schema {
17
17
  skipPackageJson?: boolean;
18
18
  appDir?: boolean;
19
19
  src?: boolean;
20
+ // Internal options
20
21
  rootProject?: boolean;
21
22
  addPlugin?: boolean;
23
+ useTsSolution?: boolean;
24
+ formatter?: 'prettier' | 'none';
22
25
  }
@@ -69,8 +69,10 @@
69
69
  "linter": {
70
70
  "description": "The tool to use for running lint checks.",
71
71
  "type": "string",
72
- "enum": ["eslint"],
73
- "default": "eslint"
72
+ "enum": ["eslint", "none"],
73
+ "default": "none",
74
+ "x-prompt": "Which linter would you like to use?",
75
+ "x-priority": "important"
74
76
  },
75
77
  "skipFormat": {
76
78
  "description": "Skip formatting files.",
@@ -82,7 +84,9 @@
82
84
  "type": "string",
83
85
  "enum": ["jest", "none"],
84
86
  "description": "Test runner to use for unit tests.",
85
- "default": "jest"
87
+ "default": "none",
88
+ "x-prompt": "What unit test runner should be used?",
89
+ "x-priority": "important"
86
90
  },
87
91
  "e2eTestRunner": {
88
92
  "type": "string",
@@ -8,19 +8,17 @@
8
8
  "properties": {
9
9
  "path": {
10
10
  "type": "string",
11
- "description": "Path where the component will be generated.",
11
+ "description": "The file path to the component without the file extension. Relative to the current working directory.",
12
12
  "$default": {
13
13
  "$source": "argv",
14
14
  "index": 0
15
15
  },
16
- "x-prompt": "Where should the component be generated?",
16
+ "x-prompt": "What is the component file path?",
17
17
  "x-priority": "important"
18
18
  },
19
19
  "name": {
20
20
  "type": "string",
21
- "description": "The name of the component.",
22
- "x-prompt": "What name would you like to use for the component?",
23
- "x-priority": "important"
21
+ "description": "The component symbol name. Defaults to the last segment of the file path."
24
22
  },
25
23
  "style": {
26
24
  "description": "The file extension to be used for style files.",
@@ -1,3 +1,3 @@
1
- import type { Tree } from '@nx/devkit';
1
+ import { Tree } from '@nx/devkit';
2
2
  import { CustomServerSchema } from './schema';
3
3
  export declare function customServerGenerator(host: Tree, options: CustomServerSchema): Promise<() => void>;
@@ -2,18 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.customServerGenerator = customServerGenerator;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const devkit_2 = require("@nx/devkit");
5
6
  const path_1 = require("path");
6
7
  const add_swc_to_custom_server_1 = require("../../utils/add-swc-to-custom-server");
8
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
9
  async function customServerGenerator(host, options) {
8
- const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
9
- const nxJson = (0, devkit_1.readNxJson)(host);
10
+ const project = (0, devkit_2.readProjectConfiguration)(host, options.project);
11
+ const nxJson = (0, devkit_2.readNxJson)(host);
10
12
  const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
11
13
  ? p === '@nx/next/plugin'
12
14
  : p.plugin === '@nx/next/plugin');
13
15
  if (project.targets?.build?.executor !== '@nx/next:build' &&
14
16
  project.targets?.build?.executor !== '@nrwl/next:build' &&
15
17
  !hasPlugin) {
16
- devkit_1.logger.error(`Project ${options.project} is not a Next.js project. Did you generate it with "nx g @nx/next:app"?`);
18
+ devkit_2.logger.error(`Project ${options.project} is not a Next.js project. Did you generate it with "nx g @nx/next:app"?`);
17
19
  return;
18
20
  }
19
21
  // In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
@@ -26,23 +28,28 @@ async function customServerGenerator(host, options) {
26
28
  !project.targets?.build?.configurations?.development ||
27
29
  !project.targets?.build?.configurations?.production) &&
28
30
  !hasPlugin) {
29
- devkit_1.logger.error(`Project ${options.project} has invalid config. Did you generate it with "nx g @nx/next:app"?`);
31
+ devkit_2.logger.error(`Project ${options.project} has invalid config. Did you generate it with "nx g @nx/next:app"?`);
30
32
  return;
31
33
  }
32
34
  if (project.targets?.['build-custom-server'] ||
33
35
  project.targets?.['serve-custom-server']) {
34
- devkit_1.logger.warn(`Project ${options.project} has custom server targets already: build-custom-server, serve-custom-server. Remove these targets from project and try again.`);
36
+ devkit_2.logger.warn(`Project ${options.project} has custom server targets already: build-custom-server, serve-custom-server. Remove these targets from project and try again.`);
35
37
  return;
36
38
  }
37
39
  // In Nx 18 next artifacts are inside the project root .next/ & dist/ (for custom server)
38
40
  // So we need ensure the mapping is correct from dist to the project root
39
- const projectPathFromDist = `../../${(0, devkit_1.offsetFromRoot)(project.root)}${project.root}`;
40
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files'), project.root, {
41
+ const projectPathFromDist = `../../${(0, devkit_2.offsetFromRoot)(project.root)}${project.root}`;
42
+ const offset = (0, devkit_2.offsetFromRoot)(project.root);
43
+ const isTsSolution = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
44
+ (0, devkit_2.generateFiles)(host, (0, path_1.join)(__dirname, 'files'), project.root, {
41
45
  ...options,
42
46
  hasPlugin,
43
47
  projectPathFromDist,
44
- offsetFromRoot: (0, devkit_1.offsetFromRoot)(project.root),
48
+ offsetFromRoot: offset,
45
49
  projectRoot: project.root,
50
+ baseTsConfigPath: isTsSolution
51
+ ? (0, devkit_1.joinPathFragments)(offset, 'tsconfig.base.json')
52
+ : './tsconfig.json',
46
53
  tmpl: '',
47
54
  });
48
55
  if (!hasPlugin) {
@@ -86,8 +93,8 @@ async function customServerGenerator(host, options) {
86
93
  },
87
94
  },
88
95
  };
89
- (0, devkit_1.updateProjectConfiguration)(host, options.project, project);
90
- (0, devkit_1.updateJson)(host, 'nx.json', (json) => {
96
+ (0, devkit_2.updateProjectConfiguration)(host, options.project, project);
97
+ (0, devkit_2.updateJson)(host, 'nx.json', (json) => {
91
98
  if (!json.tasksRunnerOptions?.default?.options?.cacheableOperations?.includes('build-custom-server') &&
92
99
  json.tasksRunnerOptions?.default?.options?.cacheableOperations) {
93
100
  json.tasksRunnerOptions.default.options.cacheableOperations.push('build-custom-server');
@@ -1,7 +1,8 @@
1
1
  {
2
- "extends": "./tsconfig.json",
2
+ "extends": "<%= baseTsConfigPath %>",
3
3
  "compilerOptions": {
4
- "module": "commonjs",
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
5
6
  "noEmit": false,
6
7
  "incremental": true,
7
8
  <% if(hasPlugin && compiler === 'tsc') { %>
@@ -4,7 +4,6 @@ exports.nextInitGenerator = nextInitGenerator;
4
4
  exports.nextInitGeneratorInternal = nextInitGeneratorInternal;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
7
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
7
  const versions_1 = require("@nx/react/src/utils/versions");
9
8
  const add_gitignore_entry_1 = require("../../utils/add-gitignore-entry");
10
9
  const versions_2 = require("../../utils/versions");
@@ -24,7 +23,6 @@ function nextInitGenerator(tree, schema) {
24
23
  return nextInitGeneratorInternal(tree, { addPlugin: false, ...schema });
25
24
  }
26
25
  async function nextInitGeneratorInternal(host, schema) {
27
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'next', 'init');
28
26
  const nxJson = (0, devkit_1.readNxJson)(host);
29
27
  const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
30
28
  nxJson.useInferencePlugins !== false;
@@ -5,11 +5,11 @@ exports.libraryGeneratorInternal = libraryGeneratorInternal;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const library_1 = require("@nx/react/src/generators/library/library");
7
7
  const js_1 = require("@nx/js");
8
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
9
8
  const versions_1 = require("@nx/react/src/utils/versions");
10
9
  const init_1 = require("../init/init");
11
10
  const normalize_options_1 = require("./lib/normalize-options");
12
11
  const versions_2 = require("../../utils/versions");
12
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
13
13
  async function libraryGenerator(host, rawOptions) {
14
14
  return await libraryGeneratorInternal(host, {
15
15
  addPlugin: false,
@@ -17,7 +17,6 @@ async function libraryGenerator(host, rawOptions) {
17
17
  });
18
18
  }
19
19
  async function libraryGeneratorInternal(host, rawOptions) {
20
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'next', 'library');
21
20
  const options = await (0, normalize_options_1.normalizeOptions)(host, rawOptions);
22
21
  const tasks = [];
23
22
  const jsInitTask = await (0, js_1.initGenerator)(host, {
@@ -33,7 +32,7 @@ async function libraryGeneratorInternal(host, rawOptions) {
33
32
  tasks.push(initTask);
34
33
  const libTask = await (0, library_1.libraryGenerator)(host, {
35
34
  ...options,
36
- compiler: 'swc',
35
+ bundler: 'none',
37
36
  skipFormat: true,
38
37
  });
39
38
  tasks.push(libTask);
@@ -84,6 +83,13 @@ async function libraryGeneratorInternal(host, rawOptions) {
84
83
  ];
85
84
  return json;
86
85
  });
86
+ (0, ts_solution_setup_1.updateTsconfigFiles)(host, options.projectRoot, 'tsconfig.lib.json', {
87
+ jsx: 'react-jsx',
88
+ module: 'esnext',
89
+ moduleResolution: 'bundler',
90
+ }, options.linter === 'eslint'
91
+ ? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
92
+ : undefined);
87
93
  if (!options.skipFormat) {
88
94
  await (0, devkit_1.formatFiles)(host);
89
95
  }
@@ -14,7 +14,9 @@ export interface Schema {
14
14
  linter: Linter | LinterType;
15
15
  component?: boolean;
16
16
  publishable?: boolean;
17
+ /** @deprecated Use bundler instead. */
17
18
  buildable?: boolean;
19
+ bundler?: 'none' | 'vite' | 'rollup';
18
20
  importPath?: string;
19
21
  js?: boolean;
20
22
  globalCss?: boolean;
@@ -62,17 +62,29 @@
62
62
  ]
63
63
  }
64
64
  },
65
+ "bundler": {
66
+ "type": "string",
67
+ "description": "The bundler to use. Choosing 'none' means this library is not buildable.",
68
+ "enum": ["none", "vite", "rollup"],
69
+ "default": "none",
70
+ "x-prompt": "Which bundler would you like to use to build the library? Choose 'none' to skip build setup.",
71
+ "x-priority": "important"
72
+ },
65
73
  "linter": {
66
74
  "description": "The tool to use for running lint checks.",
67
75
  "type": "string",
68
- "enum": ["eslint"],
69
- "default": "eslint"
76
+ "enum": ["eslint", "none"],
77
+ "default": "none",
78
+ "x-prompt": "Which linter would you like to use?",
79
+ "x-priority": "important"
70
80
  },
71
81
  "unitTestRunner": {
72
82
  "type": "string",
73
83
  "enum": ["vitest", "jest", "none"],
74
84
  "description": "Test runner to use for unit tests.",
75
- "default": "vitest"
85
+ "default": "none",
86
+ "x-prompt": "What unit test runner should be used?",
87
+ "x-priority": "important"
76
88
  },
77
89
  "tags": {
78
90
  "type": "string",
@@ -105,7 +117,8 @@
105
117
  "buildable": {
106
118
  "type": "boolean",
107
119
  "default": false,
108
- "description": "Generate a buildable library."
120
+ "description": "Generate a buildable library that uses rollup to bundle.",
121
+ "x-deprecated": "Use the `bundler` option for greater control (none, vite, rollup)."
109
122
  },
110
123
  "importPath": {
111
124
  "type": "string",
@@ -41,8 +41,31 @@ async function normalizeOptions(host, options) {
41
41
  // app/ is a reserved folder in nextjs so it is safe to check it's existence
42
42
  const isAppRouter = host.exists(`${project.root}/app`) ||
43
43
  host.exists(`${project.root}/src/app`);
44
+ let pageSymbolName = options.name;
45
+ if (!pageSymbolName) {
46
+ // if `name` is not provided, we use the last segment of the path
47
+ if (options.path !== '.' && options.path !== '') {
48
+ pageSymbolName = options.path.split('/').pop();
49
+ }
50
+ else {
51
+ // the user must have cd into a previously created directory, we need to
52
+ // resolve the cwd to get it
53
+ const cwd = (0, artifact_name_and_directory_utils_1.getRelativeCwd)();
54
+ if (cwd !== '.' && cwd !== '') {
55
+ pageSymbolName = cwd.split('/').pop();
56
+ }
57
+ else {
58
+ // this can only happen when running from the workspace root, in which
59
+ // case, we don't have a good way to automatically determine the name
60
+ throw new Error('Cannot determine the page name, please provide a `name` or `path` option.');
61
+ }
62
+ }
63
+ }
64
+ // the helper below expects a path to a file, but the `path` option here
65
+ // represents a directory, so we artificially add the symbol name to it
66
+ options.path = (0, devkit_1.joinPathFragments)(options.path, pageSymbolName);
44
67
  const { project: projectName, fileName } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
45
- name: options.name,
68
+ name: pageSymbolName,
46
69
  fileName: isAppRouter ? 'page' : 'index',
47
70
  path: options.path,
48
71
  fileExtension: 'tsx',
@@ -1,4 +1,3 @@
1
- import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
2
1
  import { SupportedStyles } from '@nx/react';
3
2
 
4
3
  export interface Schema {
@@ -8,19 +8,17 @@
8
8
  "properties": {
9
9
  "path": {
10
10
  "type": "string",
11
- "description": "Path where the page will be generated.",
11
+ "description": "The path to the directory where the page will be generated. Relative to the current working directory.",
12
12
  "$default": {
13
13
  "$source": "argv",
14
14
  "index": 0
15
15
  },
16
- "x-prompt": "Where should the page be generated?",
16
+ "x-prompt": "Which directory do you want to create the page in?",
17
17
  "x-priority": "important"
18
18
  },
19
19
  "name": {
20
20
  "type": "string",
21
- "description": "The name of the page.",
22
- "x-prompt": "What name would you like to use for the page?",
23
- "x-priority": "important"
21
+ "description": "The page symbol name. Defaults to the page directory name."
24
22
  },
25
23
  "style": {
26
24
  "description": "The file extension to be used for style files.",
@@ -79,12 +77,6 @@
79
77
  "description": "Generate JavaScript files rather than TypeScript files.",
80
78
  "default": false
81
79
  },
82
- "flat": {
83
- "type": "boolean",
84
- "description": "Create component at the source root rather than its own directory.",
85
- "default": false,
86
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v20."
87
- },
88
80
  "skipFormat": {
89
81
  "description": "Skip formatting files.",
90
82
  "type": "boolean",