@nx/plugin 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca

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.
Files changed (56) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/generators.json +4 -4
  4. package/migrations.json +1 -20
  5. package/package.json +5 -6
  6. package/src/generators/create-package/create-package.js +40 -15
  7. package/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +11 -7
  8. package/src/generators/create-package/files/e2e/__cliName__.spec.ts__tmpl__ +8 -6
  9. package/src/generators/create-package/schema.d.ts +8 -7
  10. package/src/generators/create-package/schema.json +16 -19
  11. package/src/generators/create-package/utils/normalize-schema.d.ts +6 -0
  12. package/src/generators/create-package/utils/normalize-schema.js +21 -4
  13. package/src/generators/e2e-project/e2e.d.ts +1 -2
  14. package/src/generators/e2e-project/e2e.js +67 -32
  15. package/src/generators/e2e-project/files/src/{__pluginName__.spec.ts__tmpl__ → __simplePluginName__.spec.ts__tmpl__} +9 -7
  16. package/src/generators/e2e-project/schema.d.ts +1 -2
  17. package/src/generators/e2e-project/schema.json +5 -7
  18. package/src/generators/executor/executor.d.ts +2 -3
  19. package/src/generators/executor/executor.js +31 -29
  20. package/src/generators/executor/files/executor/{executor.spec.ts.template → __fileName__.spec.ts.template} +11 -2
  21. package/src/generators/executor/schema.d.ts +3 -11
  22. package/src/generators/executor/schema.json +7 -29
  23. package/src/generators/generator/files/generator/{generator.spec.ts.template → __fileName__.spec.ts.template} +1 -1
  24. package/src/generators/generator/generator.d.ts +1 -2
  25. package/src/generators/generator/generator.js +30 -28
  26. package/src/generators/generator/schema.d.ts +3 -11
  27. package/src/generators/generator/schema.json +17 -25
  28. package/src/generators/migration/migration.d.ts +2 -3
  29. package/src/generators/migration/migration.js +39 -43
  30. package/src/generators/migration/schema.d.ts +1 -9
  31. package/src/generators/migration/schema.json +16 -22
  32. package/src/generators/plugin/plugin.d.ts +1 -1
  33. package/src/generators/plugin/plugin.js +42 -41
  34. package/src/generators/plugin/schema.d.ts +7 -7
  35. package/src/generators/plugin/schema.json +16 -18
  36. package/src/generators/plugin/utils/normalize-schema.d.ts +10 -4
  37. package/src/generators/plugin/utils/normalize-schema.js +21 -17
  38. package/src/generators/preset/generator.d.ts +5 -3
  39. package/src/generators/preset/generator.js +48 -21
  40. package/src/generators/preset/schema.d.ts +9 -0
  41. package/src/generators/preset/schema.json +4 -0
  42. package/src/utils/paths.d.ts +2 -0
  43. package/src/utils/paths.js +31 -0
  44. package/src/utils/testing-utils/async-commands.js +1 -1
  45. package/src/utils/testing-utils/commands.js +1 -1
  46. package/src/utils/testing-utils/nx-project.js +2 -2
  47. package/src/migrations/update-16-0-0/cli-in-schema-json.d.ts +0 -3
  48. package/src/migrations/update-16-0-0/cli-in-schema-json.js +0 -134
  49. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
  50. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
  51. package/src/migrations/update-16-2-0/replace-e2e-executor.d.ts +0 -7
  52. package/src/migrations/update-16-2-0/replace-e2e-executor.js +0 -32
  53. /package/src/generators/executor/files/executor/{executor.ts.template → __fileName__.ts.template} +0 -0
  54. /package/src/generators/generator/files/generator/{generator.ts.template → __fileName__.ts.template} +0 -0
  55. /package/src/generators/migration/files/migration/{__name__.spec.ts__tmpl__ → __fileName__.spec.ts__tmpl__} +0 -0
  56. /package/src/generators/migration/files/migration/{__name__.ts__tmpl__ → __fileName__.ts__tmpl__} +0 -0
@@ -1,50 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.migrationGenerator = migrationGenerator;
4
- exports.migrationGeneratorInternal = migrationGeneratorInternal;
5
4
  const devkit_1 = require("@nx/devkit");
6
- const path = require("path");
7
- const path_1 = require("path");
8
- const generator_1 = require("../lint-checks/generator");
5
+ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
6
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
+ const node_path_1 = require("node:path");
9
8
  const package_json_1 = require("nx/src/utils/package-json");
9
+ const paths_1 = require("../../utils/paths");
10
10
  const versions_1 = require("../../utils/versions");
11
- const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
11
+ const generator_1 = require("../lint-checks/generator");
12
12
  async function normalizeOptions(tree, options) {
13
- let name;
14
- if (options.name) {
15
- name = (0, devkit_1.names)(options.name).fileName;
16
- }
17
- else {
18
- name = (0, devkit_1.names)(`update-${options.packageVersion}`).fileName;
19
- }
20
- const { project, fileName, artifactName, filePath, directory } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
21
- artifactType: 'migration',
22
- callingGenerator: '@nx/plugin:migration',
23
- name: name,
24
- nameAndDirectoryFormat: options.nameAndDirectoryFormat,
25
- project: options.project,
26
- directory: options.directory,
27
- fileName: name,
28
- derivedDirectory: 'migrations',
13
+ const { artifactName: name, directory, fileName, project, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
14
+ path: options.path,
15
+ name: options.name,
16
+ allowedFileExtensions: ['ts'],
17
+ fileExtension: 'ts',
29
18
  });
30
- const { className, propertyName } = (0, devkit_1.names)(artifactName);
31
19
  const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
32
20
  const description = options.description ?? `Migration for v${options.packageVersion}`;
33
- // const { root: projectRoot, sourceRoot: projectSourceRoot } =
34
- // readProjectConfiguration(host, options.project);
35
21
  const normalized = {
36
22
  ...options,
37
- project,
38
- name: artifactName,
39
23
  directory,
24
+ fileName,
25
+ project,
26
+ name,
40
27
  description,
41
28
  projectRoot,
42
- projectSourceRoot,
29
+ projectSourceRoot: projectSourceRoot ?? (0, node_path_1.join)(projectRoot, 'src'),
30
+ isTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree),
43
31
  };
44
32
  return normalized;
45
33
  }
46
34
  function addFiles(host, options) {
47
- (0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/migration'), options.directory, { ...options, tmpl: '' });
35
+ (0, devkit_1.generateFiles)(host, (0, node_path_1.join)(__dirname, 'files/migration'), options.directory, {
36
+ ...options,
37
+ tmpl: '',
38
+ });
48
39
  }
49
40
  function updateMigrationsJson(host, options) {
50
41
  const configuredMigrationPath = (0, package_json_1.readNxMigrateConfig)((0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'))).migrations;
@@ -53,10 +44,11 @@ function updateMigrationsJson(host, options) {
53
44
  ? (0, devkit_1.readJson)(host, migrationsPath)
54
45
  : {};
55
46
  const generators = migrations.generators ?? {};
47
+ const dir = (0, paths_1.getArtifactMetadataDirectory)(host, options.project, options.directory, options.isTsSolutionSetup);
56
48
  generators[options.name] = {
57
49
  version: options.packageVersion,
58
50
  description: options.description,
59
- implementation: `./${(0, devkit_1.joinPathFragments)((0, path_1.relative)(options.projectRoot, options.directory), options.name)}`,
51
+ implementation: `${dir}/${options.fileName}`,
60
52
  };
61
53
  migrations.generators = generators;
62
54
  if (options.packageJsonUpdates) {
@@ -72,10 +64,17 @@ function updateMigrationsJson(host, options) {
72
64
  (0, devkit_1.writeJson)(host, migrationsPath, migrations);
73
65
  }
74
66
  function updatePackageJson(host, options) {
75
- (0, devkit_1.updateJson)(host, path.join(options.projectRoot, 'package.json'), (json) => {
67
+ (0, devkit_1.updateJson)(host, (0, node_path_1.join)(options.projectRoot, 'package.json'), (json) => {
68
+ const addFile = (file) => {
69
+ if (options.isTsSolutionSetup) {
70
+ const filesSet = new Set(json.files ?? ['dist', '!**/*.tsbuildinfo']);
71
+ filesSet.add(file.replace(/^\.\//, ''));
72
+ json.files = [...filesSet];
73
+ }
74
+ };
76
75
  const migrationKey = json['ng-update'] ? 'ng-update' : 'nx-migrations';
77
- const preexistingValue = json[migrationKey];
78
- if (typeof preexistingValue === 'string') {
76
+ if (typeof json[migrationKey] === 'string') {
77
+ addFile(json[migrationKey]);
79
78
  return json;
80
79
  }
81
80
  else if (!json[migrationKey]) {
@@ -83,9 +82,10 @@ function updatePackageJson(host, options) {
83
82
  migrations: './migrations.json',
84
83
  };
85
84
  }
86
- else if (preexistingValue.migrations) {
87
- preexistingValue.migrations = './migrations.json';
85
+ else if (json[migrationKey].migrations) {
86
+ json[migrationKey].migrations = './migrations.json';
88
87
  }
88
+ addFile(json[migrationKey].migrations);
89
89
  // add dependencies
90
90
  json.dependencies = {
91
91
  '@nx/devkit': versions_1.nxVersion,
@@ -95,6 +95,9 @@ function updatePackageJson(host, options) {
95
95
  });
96
96
  }
97
97
  function updateProjectConfig(host, options) {
98
+ if (options.isTsSolutionSetup) {
99
+ return;
100
+ }
98
101
  const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
99
102
  const assets = project.targets.build?.options?.assets;
100
103
  if (assets &&
@@ -110,19 +113,12 @@ function updateProjectConfig(host, options) {
110
113
  (0, devkit_1.updateProjectConfiguration)(host, options.project, project);
111
114
  }
112
115
  }
113
- async function migrationGenerator(tree, rawOptions) {
114
- await migrationGeneratorInternal(tree, {
115
- nameAndDirectoryFormat: 'derived',
116
- ...rawOptions,
117
- });
118
- }
119
- async function migrationGeneratorInternal(host, schema) {
116
+ async function migrationGenerator(host, schema) {
120
117
  const options = await normalizeOptions(host, schema);
121
118
  addFiles(host, options);
119
+ updatePackageJson(host, options);
122
120
  updateMigrationsJson(host, options);
123
121
  updateProjectConfig(host, options);
124
- updateMigrationsJson(host, options);
125
- updatePackageJson(host, options);
126
122
  if (!host.exists('migrations.json')) {
127
123
  const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
128
124
  (0, generator_1.addMigrationJsonChecks)(host, { projectName: options.project }, (0, devkit_1.readJson)(host, packageJsonPath));
@@ -1,16 +1,8 @@
1
- import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
2
-
3
1
  export interface Schema {
2
+ path: string;
4
3
  name?: string;
5
- directory?: string;
6
4
  description?: string;
7
5
  packageVersion: string;
8
6
  packageJsonUpdates?: boolean;
9
7
  skipFormat?: boolean;
10
- nameAndDirectoryFormat?: NameAndDirectoryFormat;
11
-
12
- /**
13
- * @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v20.
14
- */
15
- project?: string;
16
8
  }
@@ -7,24 +7,32 @@
7
7
  "type": "object",
8
8
  "examples": [
9
9
  {
10
- "command": "nx g migration my-migration --project=my-plugin --version=1.0.0",
11
- "description": "Adds a new migration to the project `my-plugin`, which will be triggered when migrating to version 1.0.0 or above from a previous version."
10
+ "description": "Generate a migration exported with the name matching the file name, which will be triggered when migrating to version 1.0.0 or above from a previous version. It results in the migration `foo` at `mylib/src/migrations/foo.ts`",
11
+ "command": "nx g @nx/plugin:migration mylib/src/migrations/foo.ts -v=1.0.0"
12
+ },
13
+ {
14
+ "description": "Generate a migration without providing the file extension, which will be triggered when migrating to version 1.0.0 or above from a previous version. It results in the migration `foo` at `mylib/src/migrations/foo.ts`",
15
+ "command": "nx g @nx/plugin:migration mylib/src/migrations/foo -v=1.0.0"
16
+ },
17
+ {
18
+ "description": "Generate a migration exported with a different name from the file name, which will be triggered when migrating to version 1.0.0 or above from a previous version. It results in the migration `custom` at `mylib/src/migrations/foo.ts`",
19
+ "command": "nx g @nx/plugin:migration mylib/src/migrations/foo --name=custom -v=1.0.0"
12
20
  }
13
21
  ],
14
22
  "properties": {
15
- "name": {
23
+ "path": {
16
24
  "type": "string",
17
- "description": "Migration name.",
25
+ "description": "The file path to the migration without the file extension. Relative to the current working directory.",
18
26
  "$default": {
19
27
  "$source": "argv",
20
28
  "index": 0
21
29
  },
30
+ "x-prompt": "What is the migration file path?",
22
31
  "x-priority": "important"
23
32
  },
24
- "directory": {
33
+ "name": {
25
34
  "type": "string",
26
- "description": "The directory at which to create the migration file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
27
- "aliases": ["dir"]
35
+ "description": "The migration name to export in the plugin migrations collection."
28
36
  },
29
37
  "description": {
30
38
  "type": "string",
@@ -37,15 +45,6 @@
37
45
  "x-prompt": "What version would you like to use for the migration?",
38
46
  "x-priority": "important"
39
47
  },
40
- "project": {
41
- "type": "string",
42
- "description": "The name of the project.",
43
- "alias": "p",
44
- "$default": {
45
- "$source": "projectName"
46
- },
47
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20."
48
- },
49
48
  "packageJsonUpdates": {
50
49
  "type": "boolean",
51
50
  "description": "Whether or not to include `package.json` updates.",
@@ -56,13 +55,8 @@
56
55
  "type": "boolean",
57
56
  "default": false,
58
57
  "description": "Do not eslint configuration for plugin json files."
59
- },
60
- "nameAndDirectoryFormat": {
61
- "description": "Whether to generate the migration in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
62
- "type": "string",
63
- "enum": ["as-provided", "derived"]
64
58
  }
65
59
  },
66
- "required": ["packageVersion"],
60
+ "required": ["packageVersion", "path"],
67
61
  "additionalProperties": false
68
62
  }
@@ -1,5 +1,5 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import type { Schema } from './schema';
3
- export declare function pluginGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
3
+ export declare function pluginGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
4
  export declare function pluginGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
5
5
  export default pluginGenerator;
@@ -5,13 +5,11 @@ exports.pluginGeneratorInternal = pluginGeneratorInternal;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const js_1 = require("@nx/js");
7
7
  const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
8
- const eslint_1 = require("@nx/eslint");
8
+ const add_tslib_dependencies_1 = require("@nx/js/src/utils/typescript/add-tslib-dependencies");
9
9
  const path = require("path");
10
10
  const e2e_1 = require("../e2e-project/e2e");
11
11
  const generator_1 = require("../lint-checks/generator");
12
12
  const normalize_schema_1 = require("./utils/normalize-schema");
13
- const add_tslib_dependencies_1 = require("@nx/js/src/utils/typescript/add-tslib-dependencies");
14
- const add_swc_dependencies_2 = require("@nx/js/src/utils/swc/add-swc-dependencies");
15
13
  const nxVersion = require('../../../package.json').version;
16
14
  async function addFiles(host, options) {
17
15
  host.delete((0, devkit_1.normalizePath)(`${options.projectRoot}/src/lib`));
@@ -21,39 +19,30 @@ async function addFiles(host, options) {
21
19
  });
22
20
  }
23
21
  function updatePluginConfig(host, options) {
24
- const project = (0, devkit_1.readProjectConfiguration)(host, options.name);
22
+ const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
25
23
  if (project.targets.build) {
26
- project.targets.build.options.assets ??= [];
27
- const root = options.projectRoot === '.' ? '.' : './' + options.projectRoot;
24
+ if (options.isTsSolutionSetup && options.bundler === 'tsc') {
25
+ project.targets.build.options.rootDir =
26
+ project.sourceRoot ?? (0, devkit_1.joinPathFragments)(project.root, 'src');
27
+ project.targets.build.options.generatePackageJson = false;
28
+ }
28
29
  project.targets.build.options.assets = [
29
- ...project.targets.build.options.assets,
30
- {
31
- input: `${root}/src`,
32
- glob: '**/!(*.ts)',
33
- output: './src',
34
- },
35
- {
36
- input: `${root}/src`,
37
- glob: '**/*.d.ts',
38
- output: './src',
39
- },
40
- {
41
- input: root,
42
- glob: 'generators.json',
43
- output: '.',
44
- },
45
- {
46
- input: root,
47
- glob: 'executors.json',
48
- output: '.',
49
- },
30
+ ...(project.targets.build.options.assets ?? []),
50
31
  ];
51
- (0, devkit_1.updateProjectConfiguration)(host, options.name, project);
32
+ const root = options.projectRoot === '.' ? '.' : './' + options.projectRoot;
33
+ if (options.isTsSolutionSetup) {
34
+ project.targets.build.options.assets.push({ input: `${root}/src`, glob: '**/!(*.ts)', output: '.' }, { input: `${root}/src`, glob: '**/*.d.ts', output: '.' });
35
+ }
36
+ else {
37
+ project.targets.build.options.assets.push({ input: `${root}/src`, glob: '**/!(*.ts)', output: './src' }, { input: `${root}/src`, glob: '**/*.d.ts', output: './src' }, { input: root, glob: 'generators.json', output: '.' }, { input: root, glob: 'executors.json', output: '.' });
38
+ }
39
+ (0, devkit_1.updateProjectConfiguration)(host, options.projectName, project);
52
40
  }
53
41
  }
54
- async function pluginGenerator(host, schema) {
55
- return await pluginGeneratorInternal(host, {
56
- projectNameAndRootFormat: 'derived',
42
+ async function pluginGenerator(tree, schema) {
43
+ return await pluginGeneratorInternal(tree, {
44
+ useProjectJson: true,
45
+ addPlugin: false,
57
46
  ...schema,
58
47
  });
59
48
  }
@@ -67,39 +56,51 @@ async function pluginGeneratorInternal(host, schema) {
67
56
  config: 'project',
68
57
  bundler: options.bundler,
69
58
  publishable: options.publishable,
70
- importPath: options.npmPackageName,
71
- projectNameAndRootFormat: 'as-provided',
59
+ importPath: options.importPath,
60
+ linter: options.linter,
61
+ unitTestRunner: options.unitTestRunner,
62
+ useProjectJson: options.useProjectJson,
63
+ addPlugin: options.addPlugin,
72
64
  skipFormat: true,
65
+ useTscExecutor: true,
73
66
  }));
67
+ if (options.isTsSolutionSetup) {
68
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
69
+ delete json.type;
70
+ return json;
71
+ });
72
+ }
74
73
  if (options.bundler === 'tsc') {
75
74
  tasks.push((0, add_tslib_dependencies_1.addTsLibDependencies)(host));
76
75
  }
77
76
  tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {
78
77
  '@nx/devkit': nxVersion,
79
78
  }, {
80
- '@nx/jest': nxVersion,
79
+ [options.unitTestRunner === 'vitest' ? '@nx/vite' : '@nx/jest']: nxVersion,
81
80
  '@nx/js': nxVersion,
82
81
  '@nx/plugin': nxVersion,
83
82
  }));
84
83
  // Ensures Swc Deps are installed to handle running
85
84
  // local plugin generators and executors
86
85
  tasks.push((0, add_swc_dependencies_1.addSwcDependencies)(host));
87
- tasks.push((0, add_swc_dependencies_2.addSwcRegisterDependencies)(host));
86
+ tasks.push((0, add_swc_dependencies_1.addSwcRegisterDependencies)(host));
88
87
  await addFiles(host, options);
89
88
  updatePluginConfig(host, options);
90
89
  if (options.e2eTestRunner !== 'none') {
91
90
  tasks.push(await (0, e2e_1.e2eProjectGenerator)(host, {
92
- pluginName: options.name,
91
+ pluginName: options.projectName,
93
92
  projectDirectory: options.projectDirectory,
94
- pluginOutputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : options.projectRoot),
95
- npmPackageName: options.npmPackageName,
93
+ pluginOutputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.projectName : options.projectRoot),
94
+ npmPackageName: options.importPath,
96
95
  skipFormat: true,
97
96
  rootProject: options.rootProject,
98
- projectNameAndRootFormat: options.projectNameAndRootFormat,
97
+ linter: options.linter,
98
+ useProjectJson: options.useProjectJson,
99
+ addPlugin: options.addPlugin,
99
100
  }));
100
101
  }
101
- if (options.linter === eslint_1.Linter.EsLint && !options.skipLintChecks) {
102
- await (0, generator_1.default)(host, { projectName: options.name });
102
+ if (options.linter === 'eslint' && !options.skipLintChecks) {
103
+ await (0, generator_1.default)(host, { projectName: options.projectName });
103
104
  }
104
105
  if (!options.skipFormat) {
105
106
  await (0, devkit_1.formatFiles)(host);
@@ -1,20 +1,20 @@
1
- import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
1
  import type { Linter, LinterType } from '@nx/eslint';
3
2
 
4
3
  export interface Schema {
5
- name: string;
6
- directory?: string;
7
- projectNameAndRootFormat?: ProjectNameAndRootFormat;
4
+ directory: string;
5
+ name?: string;
8
6
  importPath?: string;
9
7
  skipTsConfig?: boolean; // default is false
10
8
  skipFormat?: boolean; // default is false
11
9
  skipLintChecks?: boolean; // default is false
12
10
  e2eTestRunner?: 'jest' | 'none';
13
11
  tags?: string;
14
- unitTestRunner: 'jest' | 'none';
15
- linter: Linter | LinterType;
12
+ unitTestRunner?: 'jest' | 'vitest' | 'none';
13
+ linter?: Linter | LinterType;
16
14
  setParserOptionsProject?: boolean;
17
- compiler: 'swc' | 'tsc';
15
+ compiler?: 'swc' | 'tsc';
18
16
  rootProject?: boolean;
19
17
  publishable?: boolean;
18
+ useProjectJson?: boolean;
19
+ addPlugin?: boolean;
20
20
  }
@@ -12,25 +12,19 @@
12
12
  }
13
13
  ],
14
14
  "properties": {
15
- "name": {
15
+ "directory": {
16
16
  "type": "string",
17
- "description": "Plugin name",
17
+ "description": "A directory where the plugin is placed.",
18
18
  "$default": {
19
19
  "$source": "argv",
20
20
  "index": 0
21
21
  },
22
- "x-prompt": "What name would you like to use for the plugin?",
23
- "x-priority": "important",
24
- "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$"
25
- },
26
- "directory": {
27
- "type": "string",
28
- "description": "A directory where the plugin is placed."
22
+ "x-prompt": "Which directory do you want to create the plugin in?"
29
23
  },
30
- "projectNameAndRootFormat": {
31
- "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`).",
24
+ "name": {
32
25
  "type": "string",
33
- "enum": ["as-provided", "derived"]
26
+ "description": "Plugin name",
27
+ "x-priority": "important"
34
28
  },
35
29
  "importPath": {
36
30
  "type": "string",
@@ -40,14 +34,14 @@
40
34
  "linter": {
41
35
  "description": "The tool to use for running lint checks.",
42
36
  "type": "string",
43
- "enum": ["eslint"],
44
- "default": "eslint"
37
+ "enum": ["none", "eslint"],
38
+ "x-priority": "important"
45
39
  },
46
40
  "unitTestRunner": {
47
- "type": "string",
48
- "enum": ["jest", "none"],
49
41
  "description": "Test runner to use for unit tests.",
50
- "default": "jest"
42
+ "type": "string",
43
+ "enum": ["none", "jest", "vitest"],
44
+ "x-priority": "important"
51
45
  },
52
46
  "tags": {
53
47
  "type": "string",
@@ -98,7 +92,11 @@
98
92
  "type": "boolean",
99
93
  "description": "Generates a boilerplate for publishing the plugin to npm.",
100
94
  "default": false
95
+ },
96
+ "useProjectJson": {
97
+ "type": "boolean",
98
+ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
101
99
  }
102
100
  },
103
- "required": ["name"]
101
+ "required": ["directory"]
104
102
  }
@@ -1,13 +1,19 @@
1
- import { Tree } from '@nx/devkit';
2
- import { Schema } from '../schema';
1
+ import { type Tree } from '@nx/devkit';
2
+ import type { LinterType } from '@nx/eslint';
3
+ import type { Schema } from '../schema';
3
4
  export interface NormalizedSchema extends Schema {
4
- name: string;
5
+ projectName: string;
5
6
  fileName: string;
6
7
  projectRoot: string;
7
8
  projectDirectory: string;
8
9
  parsedTags: string[];
9
- npmPackageName: string;
10
+ importPath: string;
10
11
  bundler: 'swc' | 'tsc';
11
12
  publishable: boolean;
13
+ unitTestRunner: 'jest' | 'vitest' | 'none';
14
+ linter: LinterType;
15
+ useProjectJson: boolean;
16
+ addPlugin: boolean;
17
+ isTsSolutionSetup: boolean;
12
18
  }
13
19
  export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -3,29 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = normalizeOptions;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ const generator_prompts_1 = require("@nx/js/src/utils/generator-prompts");
7
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
6
8
  async function normalizeOptions(host, options) {
7
- const { projectName, projectRoot, importPath: npmPackageName, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
9
+ const linter = await (0, generator_prompts_1.normalizeLinterOption)(host, options.linter);
10
+ const unitTestRunner = await (0, generator_prompts_1.normalizeUnitTestRunnerOption)(host, options.unitTestRunner, ['jest', 'vitest']);
11
+ const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
12
+ const nxJson = (0, devkit_1.readNxJson)(host);
13
+ const addPlugin = options.addPlugin ??
14
+ (isTsSolutionSetup &&
15
+ process.env.NX_ADD_PLUGINS !== 'false' &&
16
+ nxJson.useInferencePlugins !== false);
17
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
18
+ const { projectName, projectRoot, importPath } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
19
  name: options.name,
9
20
  projectType: 'library',
10
21
  directory: options.directory,
11
22
  importPath: options.importPath,
12
- projectNameAndRootFormat: options.projectNameAndRootFormat,
13
23
  rootProject: options.rootProject,
14
- callingGenerator: '@nx/plugin:plugin',
15
24
  });
16
- options.projectNameAndRootFormat = projectNameAndRootFormat;
17
25
  options.rootProject = projectRoot === '.';
18
- let projectDirectory = projectRoot;
19
- if (options.projectNameAndRootFormat === 'derived') {
20
- let { layoutDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
21
- if (!layoutDirectory) {
22
- const { libsDir } = (0, devkit_1.getWorkspaceLayout)(host);
23
- layoutDirectory = libsDir;
24
- }
25
- if (projectRoot.startsWith(`${layoutDirectory}/`)) {
26
- projectDirectory = projectRoot.replace(`${layoutDirectory}/`, '');
27
- }
28
- }
26
+ const projectDirectory = projectRoot;
29
27
  const parsedTags = options.tags
30
28
  ? options.tags.split(',').map((s) => s.trim())
31
29
  : [];
@@ -33,11 +31,17 @@ async function normalizeOptions(host, options) {
33
31
  ...options,
34
32
  bundler: options.compiler ?? 'tsc',
35
33
  fileName: projectName,
36
- name: projectName,
34
+ projectName: isTsSolutionSetup && !options.name ? importPath : projectName,
37
35
  projectRoot,
38
36
  projectDirectory,
39
37
  parsedTags,
40
- npmPackageName,
38
+ importPath,
41
39
  publishable: options.publishable ?? false,
40
+ linter,
41
+ unitTestRunner,
42
+ // We default to generate a project.json file if the new setup is not being used
43
+ useProjectJson: options.useProjectJson ?? !isTsSolutionSetup,
44
+ addPlugin,
45
+ isTsSolutionSetup,
42
46
  };
43
47
  }
@@ -1,3 +1,5 @@
1
- import { GeneratorCallback, Tree } from '@nx/devkit';
2
- import { PresetGeneratorSchema } from './schema';
3
- export default function (tree: Tree, options: PresetGeneratorSchema): Promise<GeneratorCallback>;
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
+ import type { PresetGeneratorSchema } from './schema';
3
+ export declare function presetGenerator(tree: Tree, rawOptions: PresetGeneratorSchema): Promise<GeneratorCallback>;
4
+ export declare function presetGeneratorInternal(tree: Tree, rawOptions: PresetGeneratorSchema): Promise<GeneratorCallback>;
5
+ export default presetGenerator;