@nx/next 16.8.0-beta.0 → 16.8.0-beta.2

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/generators.json CHANGED
@@ -40,7 +40,7 @@
40
40
  "hidden": true
41
41
  },
42
42
  "application": {
43
- "factory": "./src/generators/application/application#applicationGenerator",
43
+ "factory": "./src/generators/application/application#applicationGeneratorInternal",
44
44
  "schema": "./src/generators/application/schema.json",
45
45
  "aliases": ["app"],
46
46
  "x-type": "application",
@@ -57,7 +57,7 @@
57
57
  "description": "Create a component."
58
58
  },
59
59
  "library": {
60
- "factory": "./src/generators/library/library#libraryGenerator",
60
+ "factory": "./src/generators/library/library#libraryGeneratorInternal",
61
61
  "schema": "./src/generators/library/schema.json",
62
62
  "aliases": ["lib"],
63
63
  "x-type": "library",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/next",
3
- "version": "16.8.0-beta.0",
3
+ "version": "16.8.0-beta.2",
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, Cypress, and Jest. No need to configure anything: watch mode, source maps, and typings just work.",
6
6
  "repository": {
@@ -35,17 +35,16 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@babel/plugin-proposal-decorators": "^7.22.7",
38
- "@nrwl/next": "16.8.0-beta.0",
39
- "@nx/devkit": "16.8.0-beta.0",
40
- "@nx/js": "16.8.0-beta.0",
41
- "@nx/linter": "16.8.0-beta.0",
42
- "@nx/react": "16.8.0-beta.0",
43
- "@nx/web": "16.8.0-beta.0",
44
- "@nx/workspace": "16.8.0-beta.0",
38
+ "@nrwl/next": "16.8.0-beta.2",
39
+ "@nx/devkit": "16.8.0-beta.2",
40
+ "@nx/js": "16.8.0-beta.2",
41
+ "@nx/linter": "16.8.0-beta.2",
42
+ "@nx/react": "16.8.0-beta.2",
43
+ "@nx/web": "16.8.0-beta.2",
44
+ "@nx/workspace": "16.8.0-beta.2",
45
45
  "@svgr/webpack": "^8.0.1",
46
46
  "chalk": "^4.1.0",
47
47
  "copy-webpack-plugin": "^10.2.4",
48
- "dotenv": "~16.3.1",
49
48
  "fs-extra": "^11.1.0",
50
49
  "ignore": "^5.0.4",
51
50
  "semver": "7.5.3",
@@ -57,5 +56,5 @@
57
56
  "access": "public"
58
57
  },
59
58
  "type": "commonjs",
60
- "gitHead": "818352404283c1d34ab303d91b3bd16474f54916"
59
+ "gitHead": "9bcc04742f9e1516d8c1ddbfb1907770c347876f"
61
60
  }
@@ -1,4 +1,3 @@
1
- import 'dotenv/config';
2
1
  import { ExecutorContext } from '@nx/devkit';
3
2
  import { NextBuildBuilderOptions } from '../../utils/types';
4
3
  export default function buildExecutor(options: NextBuildBuilderOptions, context: ExecutorContext): Promise<{
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- require("dotenv/config");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const js_1 = require("@nx/js");
7
6
  const path_1 = require("path");
@@ -1,4 +1,3 @@
1
- import 'dotenv/config';
2
1
  import { ExecutorContext } from '@nx/devkit';
3
2
  import { NextExportBuilderOptions } from '../../utils/types';
4
3
  /**
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- require("dotenv/config");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const export_1 = require("next/dist/export");
7
6
  const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
@@ -1,4 +1,3 @@
1
- import 'dotenv/config';
2
1
  import { ExecutorContext } from '@nx/devkit';
3
2
  import { NextServeBuilderOptions } from '../../utils/types';
4
3
  export default function serveExecutor(options: NextServeBuilderOptions, context: ExecutorContext): AsyncGenerator<{
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- require("dotenv/config");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const path_1 = require("path");
7
6
  function serveExecutor(options, context) {
@@ -1,4 +1,3 @@
1
- import 'dotenv/config';
2
1
  import { ExecutorContext } from '@nx/devkit';
3
2
  import { NextServeBuilderOptions } from '../../utils/types';
4
3
  export default function serveExecutor(options: NextServeBuilderOptions, context: ExecutorContext): AsyncGenerator<{
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- require("dotenv/config");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const path_1 = require("path");
7
6
  const child_process_1 = require("child_process");
@@ -1,4 +1,5 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
3
  export declare function applicationGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export declare function applicationGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
5
  export declare const applicationSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applicationSchematic = exports.applicationGenerator = void 0;
3
+ exports.applicationSchematic = exports.applicationGeneratorInternal = exports.applicationGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const normalize_options_1 = require("./lib/normalize-options");
@@ -17,9 +17,15 @@ const custom_server_1 = require("../custom-server/custom-server");
17
17
  const update_cypress_tsconfig_1 = require("./lib/update-cypress-tsconfig");
18
18
  const show_possible_warnings_1 = require("./lib/show-possible-warnings");
19
19
  function applicationGenerator(host, schema) {
20
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
+ return yield applicationGeneratorInternal(host, Object.assign({ projectNameAndRootFormat: 'derived' }, schema));
22
+ });
23
+ }
24
+ exports.applicationGenerator = applicationGenerator;
25
+ function applicationGeneratorInternal(host, schema) {
20
26
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
27
  const tasks = [];
22
- const options = (0, normalize_options_1.normalizeOptions)(host, schema);
28
+ const options = yield (0, normalize_options_1.normalizeOptions)(host, schema);
23
29
  (0, show_possible_warnings_1.showPossibleWarnings)(host, options);
24
30
  const nextTask = yield (0, init_1.nextInitGenerator)(host, Object.assign(Object.assign({}, options), { skipFormat: true }));
25
31
  tasks.push(nextTask);
@@ -41,7 +47,7 @@ function applicationGenerator(host, schema) {
41
47
  (0, set_defaults_1.setDefaults)(host, options);
42
48
  if (options.customServer) {
43
49
  yield (0, custom_server_1.customServerGenerator)(host, {
44
- project: options.name,
50
+ project: options.projectName,
45
51
  compiler: options.swc ? 'swc' : 'tsc',
46
52
  });
47
53
  }
@@ -51,5 +57,5 @@ function applicationGenerator(host, schema) {
51
57
  return (0, devkit_1.runTasksInSerial)(...tasks);
52
58
  });
53
59
  }
54
- exports.applicationGenerator = applicationGenerator;
60
+ exports.applicationGeneratorInternal = applicationGeneratorInternal;
55
61
  exports.applicationSchematic = (0, devkit_1.convertNxGenerator)(applicationGenerator);
@@ -9,7 +9,9 @@ function addE2e(host, options) {
9
9
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
10
  if (options.e2eTestRunner === 'cypress') {
11
11
  const { cypressProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
12
- return cypressProjectGenerator(host, Object.assign(Object.assign({}, options), { linter: linter_1.Linter.EsLint, name: options.e2eProjectName, directory: options.directory, project: options.projectName, skipFormat: true }));
12
+ return cypressProjectGenerator(host, Object.assign(Object.assign({}, options), { linter: linter_1.Linter.EsLint, name: options.e2eProjectName, directory: options.e2eProjectRoot,
13
+ // the name and root are already normalized, instruct the generator to use them as is
14
+ projectNameAndRootFormat: 'as-provided', project: options.projectName, skipFormat: true }));
13
15
  }
14
16
  else if (options.e2eTestRunner === 'playwright') {
15
17
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_1.nxVersion);
@@ -28,7 +30,7 @@ function addE2e(host, options) {
28
30
  linter: options.linter,
29
31
  setParserOptionsProject: options.setParserOptionsProject,
30
32
  webServerAddress: 'http://127.0.0.1:4200',
31
- webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.name}`,
33
+ webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.projectName}`,
32
34
  });
33
35
  }
34
36
  return () => { };
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const linter_1 = require("@nx/linter");
6
6
  const devkit_1 = require("@nx/devkit");
7
7
  const lint_1 = require("@nx/react/src/utils/lint");
8
+ const eslint_file_1 = require("@nx/linter/src/generators/utils/eslint-file");
8
9
  function addLinting(host, options) {
9
10
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
11
  const lintTask = yield (0, linter_1.lintProjectGenerator)(host, {
@@ -18,46 +19,38 @@ function addLinting(host, options) {
18
19
  skipFormat: true,
19
20
  rootProject: options.rootProject,
20
21
  });
21
- if (options.linter === linter_1.Linter.EsLint) {
22
- (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, '.eslintrc.json'), (json) => {
23
- var _a, _b, _c;
24
- json = (0, lint_1.extendReactEslintJson)(json);
25
- // Turn off @next/next/no-html-link-for-pages since there is an issue with nextjs throwing linting errors
26
- // TODO(nicholas): remove after Vercel updates nextjs linter to only lint ["*.ts", "*.tsx", "*.js", "*.jsx"]
27
- json.ignorePatterns = [...json.ignorePatterns, '.next/**/*'];
28
- json.rules = Object.assign({ '@next/next/no-html-link-for-pages': 'off' }, json.rules);
29
- // Find the override that handles both TS and JS files.
30
- const commonOverride = (_a = json.overrides) === null || _a === void 0 ? void 0 : _a.find((o) => ['*.ts', '*.tsx', '*.js', '*.jsx'].every((ext) => o.files.includes(ext)));
31
- if (commonOverride) {
32
- // Only set parserOptions.project if it already exists (defined by options.setParserOptionsProject)
33
- if ((_b = commonOverride.parserOptions) === null || _b === void 0 ? void 0 : _b.project) {
34
- commonOverride.parserOptions.project = [
35
- `${options.appProjectRoot}/tsconfig(.*)?.json`,
36
- ];
37
- }
38
- // Configure custom pages directory for next rule
39
- if (commonOverride.rules) {
40
- commonOverride.rules = Object.assign(Object.assign({}, commonOverride.rules), { '@next/next/no-html-link-for-pages': [
41
- 'error',
42
- `${options.appProjectRoot}/pages`,
43
- ] });
44
- }
45
- }
46
- (_c = json.extends) !== null && _c !== void 0 ? _c : (json.extends = []);
47
- if (typeof json.extends === 'string') {
48
- json.extends = [json.extends];
49
- }
50
- // add next.js configuration
51
- json.extends.unshift(...['next', 'next/core-web-vitals']);
52
- // remove nx/react plugin, as it conflicts with the next.js one
53
- json.extends = json.extends.filter((name) => name !== 'plugin:@nx/react' && name !== 'plugin:@nrwl/nx/react');
54
- json.extends.unshift('plugin:@nx/react-typescript');
55
- if (!json.env) {
56
- json.env = {};
57
- }
58
- json.env.jest = true;
59
- return json;
60
- });
22
+ if (options.linter === linter_1.Linter.EsLint && (0, eslint_file_1.isEslintConfigSupported)(host)) {
23
+ (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, [
24
+ 'plugin:@nx/react-typescript',
25
+ 'next',
26
+ 'next/core-web-vitals',
27
+ ]);
28
+ // Turn off @next/next/no-html-link-for-pages since there is an issue with nextjs throwing linting errors
29
+ // TODO(nicholas): remove after Vercel updates nextjs linter to only lint ["*.ts", "*.tsx", "*.js", "*.jsx"]
30
+ (0, eslint_file_1.addOverrideToLintConfig)(host, options.appProjectRoot, {
31
+ files: ['*.*'],
32
+ rules: {
33
+ '@next/next/no-html-link-for-pages': 'off',
34
+ },
35
+ }, { insertAtTheEnd: false });
36
+ (0, eslint_file_1.updateOverrideInLintConfig)(host, options.appProjectRoot, (o) => Array.isArray(o.files) &&
37
+ o.files.some((f) => f.match(/\*\.ts$/)) &&
38
+ o.files.some((f) => f.match(/\*\.tsx$/)) &&
39
+ o.files.some((f) => f.match(/\*\.js$/)) &&
40
+ o.files.some((f) => f.match(/\*\.jsx$/)), (o) => (Object.assign(Object.assign({}, o), { rules: Object.assign(Object.assign({}, o.rules), { '@next/next/no-html-link-for-pages': [
41
+ 'error',
42
+ `${options.appProjectRoot}/pages`,
43
+ ] }) })));
44
+ // add jest specific config
45
+ if (options.unitTestRunner === 'jest') {
46
+ (0, eslint_file_1.addOverrideToLintConfig)(host, options.appProjectRoot, {
47
+ files: ['*.spec.ts', '*.spec.tsx', '*.spec.js', '*.spec.jsx'],
48
+ env: {
49
+ jest: true,
50
+ },
51
+ });
52
+ }
53
+ (0, eslint_file_1.addIgnoresToLintConfig)(host, options.appProjectRoot, ['.next/**/*']);
61
54
  }
62
55
  const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies);
63
56
  return (0, devkit_1.runTasksInSerial)(lintTask, installTask);
@@ -12,7 +12,7 @@ function createApplicationFiles(host, options) {
12
12
  const layoutTypeDistPath = (0, devkit_1.joinPathFragments)(offsetFromRoot, options.outputPath, '.next/types/**/*.ts');
13
13
  const templateVariables = Object.assign(Object.assign(Object.assign({}, (0, devkit_1.names)(options.name)), options), { dot: '.', tmpl: '', offsetFromRoot,
14
14
  layoutTypeSrcPath,
15
- layoutTypeDistPath, rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.appProjectRoot), appContent: (0, create_application_files_helpers_1.createAppJsx)(options.name), styleContent: (0, create_application_files_helpers_1.createStyleRules)(), pageStyleContent: `.page {}`, stylesExt: options.style === 'less' || options.style === 'styl'
15
+ layoutTypeDistPath, rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.appProjectRoot), appContent: (0, create_application_files_helpers_1.createAppJsx)(options.projectName), styleContent: (0, create_application_files_helpers_1.createStyleRules)(), pageStyleContent: `.page {}`, stylesExt: options.style === 'less' || options.style === 'styl'
16
16
  ? options.style
17
17
  : 'css' });
18
18
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/common'), options.appProjectRoot, templateVariables);
@@ -50,7 +50,7 @@ function createApplicationFiles(host, options) {
50
50
  ...(updatedJson.exclude || []),
51
51
  ...(appJSON.exclude || []),
52
52
  '**e2e/**/*',
53
- `dist/${options.name}/**/*`,
53
+ `dist/${options.projectName}/**/*`,
54
54
  ]),
55
55
  ] });
56
56
  return updatedJson;
@@ -11,4 +11,4 @@ export interface NormalizedSchema extends Schema {
11
11
  styledModule: null | string;
12
12
  js?: boolean;
13
13
  }
14
- export declare function normalizeOptions(host: Tree, options: Schema): NormalizedSchema;
14
+ export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -1,40 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const assertion_1 = require("@nx/react/src/utils/assertion");
4
+ const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
7
  const linter_1 = require("@nx/linter");
8
+ const assertion_1 = require("@nx/react/src/utils/assertion");
7
9
  function normalizeOptions(host, options) {
8
10
  var _a;
9
- const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
10
- const name = (0, devkit_1.names)(options.name).fileName;
11
- const appDirectory = projectDirectory
12
- ? `${(0, devkit_1.names)(projectDirectory).fileName}/${(0, devkit_1.names)(options.name).fileName}`
13
- : (0, devkit_1.names)(options.name).fileName;
14
- const appsDir = layoutDirectory !== null && layoutDirectory !== void 0 ? layoutDirectory : (0, devkit_1.getWorkspaceLayout)(host).appsDir;
15
- const appProjectName = appDirectory.replace(new RegExp('/', 'g'), '-');
16
- const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
17
- const appProjectRoot = options.rootProject
18
- ? '.'
19
- : (0, devkit_1.joinPathFragments)(appsDir, appDirectory);
20
- const e2eProjectRoot = options.rootProject
21
- ? 'e2e'
22
- : (0, devkit_1.joinPathFragments)(appsDir, `${appDirectory}-e2e`);
23
- const outputPath = (0, devkit_1.joinPathFragments)('dist', appProjectRoot, ...(options.rootProject ? [name] : []));
24
- const parsedTags = options.tags
25
- ? options.tags.split(',').map((s) => s.trim())
26
- : [];
27
- const fileName = 'index';
28
- const appDir = (_a = options.appDir) !== null && _a !== void 0 ? _a : true;
29
- const styledModule = /^(css|scss|less|styl)$/.test(options.style)
30
- ? null
31
- : options.style;
32
- (0, assertion_1.assertValidStyle)(options.style);
33
- return Object.assign(Object.assign({}, options), { appDir,
34
- appProjectRoot,
35
- e2eProjectName,
36
- e2eProjectRoot, e2eTestRunner: options.e2eTestRunner || 'cypress', fileName, linter: options.linter || linter_1.Linter.EsLint, name,
37
- outputPath,
38
- parsedTags, projectName: appProjectName, style: options.style || 'css', styledModule, unitTestRunner: options.unitTestRunner || 'jest' });
11
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
+ const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
13
+ name: options.name,
14
+ projectType: 'application',
15
+ directory: options.directory,
16
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
17
+ rootProject: options.rootProject,
18
+ callingGenerator: '@nx/next:application',
19
+ });
20
+ options.rootProject = appProjectRoot === '.';
21
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
22
+ const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
23
+ const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
24
+ const name = (0, devkit_1.names)(options.name).fileName;
25
+ const outputPath = (0, devkit_1.joinPathFragments)('dist', appProjectRoot, ...(options.rootProject ? [name] : []));
26
+ const parsedTags = options.tags
27
+ ? options.tags.split(',').map((s) => s.trim())
28
+ : [];
29
+ const fileName = 'index';
30
+ const appDir = (_a = options.appDir) !== null && _a !== void 0 ? _a : true;
31
+ const styledModule = /^(css|scss|less|styl)$/.test(options.style)
32
+ ? null
33
+ : options.style;
34
+ (0, assertion_1.assertValidStyle)(options.style);
35
+ return Object.assign(Object.assign({}, options), { appDir,
36
+ appProjectRoot,
37
+ e2eProjectName,
38
+ e2eProjectRoot, e2eTestRunner: options.e2eTestRunner || 'cypress', fileName, linter: options.linter || linter_1.Linter.EsLint, name,
39
+ outputPath,
40
+ parsedTags, projectName: appProjectName, style: options.style || 'css', styledModule, unitTestRunner: options.unitTestRunner || 'jest' });
41
+ });
39
42
  }
40
43
  exports.normalizeOptions = normalizeOptions;
@@ -1,11 +1,13 @@
1
- import { Linter } from '@nx/linter';
2
- import { SupportedStyles } from '@nx/react';
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/linter';
3
+ import type { SupportedStyles } from '@nx/react';
3
4
 
4
5
  export interface Schema {
5
6
  name: string;
6
7
  style?: SupportedStyles;
7
8
  skipFormat?: boolean;
8
9
  directory?: string;
10
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
9
11
  tags?: string;
10
12
  unitTestRunner?: 'jest' | 'none';
11
13
  e2eTestRunner?: 'cypress' | 'playwright' | 'none';
@@ -14,7 +14,7 @@
14
14
  "index": 0
15
15
  },
16
16
  "x-prompt": "What name would you like to use for the application?",
17
- "pattern": "^[a-zA-Z].*$",
17
+ "pattern": "^[a-zA-Z][^:]*$",
18
18
  "x-priority": "important"
19
19
  },
20
20
  "directory": {
@@ -23,6 +23,11 @@
23
23
  "alias": "d",
24
24
  "x-priority": "important"
25
25
  },
26
+ "projectNameAndRootFormat": {
27
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
28
+ "type": "string",
29
+ "enum": ["as-provided", "derived"]
30
+ },
26
31
  "style": {
27
32
  "description": "The file extension to be used for style files.",
28
33
  "type": "string",
@@ -4,4 +4,4 @@ export interface NormalizedSchema extends Schema {
4
4
  importPath: string;
5
5
  projectRoot: string;
6
6
  }
7
- export declare function normalizeOptions(host: Tree, options: Schema): NormalizedSchema;
7
+ export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -1,16 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
4
+ const tslib_1 = require("tslib");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
6
  function normalizeOptions(host, options) {
7
- var _a;
8
- const name = (0, devkit_1.names)(options.name).fileName;
9
- const projectDirectory = options.directory
10
- ? `${(0, devkit_1.names)(options.directory).fileName}/${name}`
11
- : name;
12
- const { libsDir } = (0, devkit_1.getWorkspaceLayout)(host);
13
- const projectRoot = (0, devkit_1.joinPathFragments)(libsDir, projectDirectory);
14
- return Object.assign(Object.assign({}, options), { importPath: (_a = options.importPath) !== null && _a !== void 0 ? _a : (0, get_import_path_1.getImportPath)(host, projectDirectory), projectRoot });
7
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
+ const { projectRoot, importPath, projectNameAndRootFormat } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
9
+ name: options.name,
10
+ projectType: 'library',
11
+ directory: options.directory,
12
+ importPath: options.importPath,
13
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
14
+ callingGenerator: '@nx/next:library',
15
+ });
16
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
17
+ return Object.assign(Object.assign({}, options), { importPath,
18
+ projectRoot });
19
+ });
15
20
  }
16
21
  exports.normalizeOptions = normalizeOptions;
@@ -1,5 +1,6 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
3
  export declare function libraryGenerator(host: Tree, rawOptions: Schema): Promise<GeneratorCallback>;
4
+ export declare function libraryGeneratorInternal(host: Tree, rawOptions: Schema): Promise<GeneratorCallback>;
4
5
  export default libraryGenerator;
5
6
  export declare const librarySchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.librarySchematic = exports.libraryGenerator = void 0;
3
+ exports.librarySchematic = exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const library_1 = require("@nx/react/src/generators/library/library");
@@ -9,7 +9,13 @@ const init_1 = require("../init/init");
9
9
  const normalize_options_1 = require("./lib/normalize-options");
10
10
  function libraryGenerator(host, rawOptions) {
11
11
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- const options = (0, normalize_options_1.normalizeOptions)(host, rawOptions);
12
+ return yield libraryGeneratorInternal(host, Object.assign({ projectNameAndRootFormat: 'derived' }, rawOptions));
13
+ });
14
+ }
15
+ exports.libraryGenerator = libraryGenerator;
16
+ function libraryGeneratorInternal(host, rawOptions) {
17
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
18
+ const options = yield (0, normalize_options_1.normalizeOptions)(host, rawOptions);
13
19
  const tasks = [];
14
20
  const initTask = yield (0, init_1.nextInitGenerator)(host, Object.assign(Object.assign({}, options), { skipFormat: true }));
15
21
  tasks.push(initTask);
@@ -58,6 +64,6 @@ function libraryGenerator(host, rawOptions) {
58
64
  return (0, devkit_1.runTasksInSerial)(...tasks);
59
65
  });
60
66
  }
61
- exports.libraryGenerator = libraryGenerator;
67
+ exports.libraryGeneratorInternal = libraryGeneratorInternal;
62
68
  exports.default = libraryGenerator;
63
69
  exports.librarySchematic = (0, devkit_1.convertNxGenerator)(libraryGenerator);
@@ -1,9 +1,11 @@
1
- import { Linter } from '@nx/linter';
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-directory-utils';
2
+ import type { Linter } from '@nx/linter';
2
3
  import type { SupportedStyles } from '@nx/react';
3
4
 
4
5
  export interface Schema {
5
6
  name: string;
6
7
  directory?: string;
8
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
7
9
  style: SupportedStyles;
8
10
  skipTsConfig?: boolean;
9
11
  skipFormat?: boolean;
@@ -14,7 +14,7 @@
14
14
  "index": 0
15
15
  },
16
16
  "x-prompt": "What name would you like to use for the library?",
17
- "pattern": "^[a-zA-Z].*$",
17
+ "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$",
18
18
  "x-priority": "important"
19
19
  },
20
20
  "directory": {
@@ -23,6 +23,11 @@
23
23
  "alias": "dir",
24
24
  "x-priority": "important"
25
25
  },
26
+ "projectNameAndRootFormat": {
27
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
28
+ "type": "string",
29
+ "enum": ["as-provided", "derived"]
30
+ },
26
31
  "style": {
27
32
  "description": "The file extension to be used for style files.",
28
33
  "type": "string",