@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
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2024 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2025 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  [![CircleCI](https://circleci.com/gh/nrwl/nx.svg?style=svg)](https://circleci.com/gh/nrwl/nx)
11
11
  [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)]()
12
- [![NPM Version](https://badge.fury.io/js/%40nrwl%2Fworkspace.svg)](https://www.npmjs.com/@nx/workspace)
12
+ [![NPM Version](https://badge.fury.io/js/nx.svg)](https://www.npmjs.com/package/nx)
13
13
  [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]()
14
14
  [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
15
15
  [![Join the chat at https://gitter.im/nrwl-nx/community](https://badges.gitter.im/nrwl-nx/community.svg)](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
package/generators.json CHANGED
@@ -19,17 +19,17 @@
19
19
  "description": "Create a E2E application for a Nx Plugin."
20
20
  },
21
21
  "migration": {
22
- "factory": "./src/generators/migration/migration#migrationGeneratorInternal",
22
+ "factory": "./src/generators/migration/migration",
23
23
  "schema": "./src/generators/migration/schema.json",
24
24
  "description": "Create a migration for an Nx Plugin."
25
25
  },
26
26
  "generator": {
27
- "factory": "./src/generators/generator/generator#generatorGeneratorInternal",
27
+ "factory": "./src/generators/generator/generator",
28
28
  "schema": "./src/generators/generator/schema.json",
29
29
  "description": "Create a generator for an Nx Plugin."
30
30
  },
31
31
  "executor": {
32
- "factory": "./src/generators/executor/executor#executorGeneratorInternal",
32
+ "factory": "./src/generators/executor/executor",
33
33
  "schema": "./src/generators/executor/schema.json",
34
34
  "description": "Create an executor for an Nx Plugin."
35
35
  },
@@ -39,7 +39,7 @@
39
39
  "description": "Adds linting configuration to validate common json files for nx plugins."
40
40
  },
41
41
  "preset": {
42
- "factory": "./src/generators/preset/generator",
42
+ "factory": "./src/generators/preset/generator#presetGeneratorInternal",
43
43
  "schema": "./src/generators/preset/schema.json",
44
44
  "description": "Initializes a workspace with an nx-plugin inside of it. Use as: `create-nx-workspace --preset @nx/plugin`.",
45
45
  "hidden": true,
package/migrations.json CHANGED
@@ -1,22 +1,3 @@
1
1
  {
2
- "generators": {
3
- "update-remove-cli-prop": {
4
- "version": "16.0.0-beta.1",
5
- "cli": "nx",
6
- "description": "Removes CLI property within schema.json files and moves generators and schematics to the proper root node in migrations.json",
7
- "factory": "./src/migrations/update-16-0-0/cli-in-schema-json"
8
- },
9
- "update-16-0-0-add-nx-packages": {
10
- "cli": "nx",
11
- "version": "16.0.0-beta.1",
12
- "description": "Replace @nrwl/nx-plugin with @nx/plugin",
13
- "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
14
- },
15
- "update-16-2-0-replace-e2e-executor": {
16
- "cli": "nx",
17
- "version": "16.2.0-beta.0",
18
- "description": "Replace @nx/plugin:e2e with @nx/jest",
19
- "implementation": "./src/migrations/update-16-2-0/replace-e2e-executor"
20
- }
21
- }
2
+ "generators": {}
22
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/plugin",
3
- "version": "0.0.0-pr-31222-862e973",
3
+ "version": "0.0.0-pr-31313-387cdca",
4
4
  "private": false,
5
5
  "description": "This plugin is used to create Nx plugins! It contains generators for generating common plugin features like generators, executors, migrations and more.",
6
6
  "repository": {
@@ -28,11 +28,10 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "tslib": "^2.3.0",
31
- "@nx/devkit": "0.0.0-pr-31222-862e973",
32
- "@nx/jest": "0.0.0-pr-31222-862e973",
33
- "@nx/js": "0.0.0-pr-31222-862e973",
34
- "@nx/eslint": "0.0.0-pr-31222-862e973",
35
- "@nrwl/nx-plugin": "0.0.0-pr-31222-862e973"
31
+ "@nx/devkit": "0.0.0-pr-31313-387cdca",
32
+ "@nx/jest": "0.0.0-pr-31313-387cdca",
33
+ "@nx/js": "0.0.0-pr-31313-387cdca",
34
+ "@nx/eslint": "0.0.0-pr-31313-387cdca"
36
35
  },
37
36
  "publishConfig": {
38
37
  "access": "public"
@@ -5,15 +5,17 @@ exports.createPackageGeneratorInternal = createPackageGeneratorInternal;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const js_1 = require("@nx/js");
7
7
  const add_tslib_dependencies_1 = require("@nx/js/src/utils/typescript/add-tslib-dependencies");
8
- const versions_1 = require("nx/src/utils/versions");
8
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
9
+ const versions_1 = require("@nx/js/src/utils/versions");
10
+ const versions_2 = require("nx/src/utils/versions");
11
+ const path_1 = require("path");
12
+ const has_generator_1 = require("../../utils/has-generator");
9
13
  const generator_1 = require("../generator/generator");
10
14
  const normalize_schema_1 = require("./utils/normalize-schema");
11
- const has_generator_1 = require("../../utils/has-generator");
12
- const path_1 = require("path");
13
- const versions_2 = require("@nx/js/src/utils/versions");
14
15
  async function createPackageGenerator(host, schema) {
15
16
  return await createPackageGeneratorInternal(host, {
16
- projectNameAndRootFormat: 'derived',
17
+ useProjectJson: true,
18
+ addPlugin: false,
17
19
  ...schema,
18
20
  });
19
21
  }
@@ -25,10 +27,11 @@ async function createPackageGeneratorInternal(host, schema) {
25
27
  tasks.push((0, add_tslib_dependencies_1.addTsLibDependencies)(host));
26
28
  }
27
29
  const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {
28
- 'create-nx-workspace': versions_1.nxVersion,
30
+ 'create-nx-workspace': versions_2.nxVersion,
29
31
  }, {});
30
32
  tasks.push(installTask);
31
- await createCliPackage(host, options, pluginPackageName);
33
+ const cliPackageTask = await createCliPackage(host, options, pluginPackageName);
34
+ tasks.push(cliPackageTask);
32
35
  if (options.e2eProject) {
33
36
  addE2eProject(host, options);
34
37
  }
@@ -46,19 +49,20 @@ async function createPackageGeneratorInternal(host, schema) {
46
49
  async function addPresetGenerator(host, schema) {
47
50
  const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.project);
48
51
  if (!(0, has_generator_1.hasGenerator)(host, schema.project, 'preset')) {
49
- await (0, generator_1.default)(host, {
52
+ await (0, generator_1.generatorGenerator)(host, {
50
53
  name: 'preset',
51
- directory: (0, path_1.join)(projectRoot, 'src/generators/preset'),
54
+ path: (0, path_1.join)(projectRoot, 'src/generators/preset/generator'),
52
55
  unitTestRunner: schema.unitTestRunner,
53
56
  skipFormat: true,
54
- nameAndDirectoryFormat: 'as-provided',
57
+ skipLintChecks: schema.linter === 'none',
55
58
  });
56
59
  }
57
60
  return (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'))?.name;
58
61
  }
59
62
  async function createCliPackage(host, options, pluginPackageName) {
60
- await (0, js_1.libraryGenerator)(host, {
63
+ const jsLibraryTask = await (0, js_1.libraryGenerator)(host, {
61
64
  ...options,
65
+ directory: options.directory,
62
66
  rootProject: false,
63
67
  config: 'project',
64
68
  publishable: true,
@@ -66,16 +70,26 @@ async function createCliPackage(host, options, pluginPackageName) {
66
70
  importPath: options.name,
67
71
  skipFormat: true,
68
72
  skipTsConfig: true,
73
+ useTscExecutor: true,
69
74
  });
70
75
  host.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'src'));
76
+ const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
71
77
  // Add the bin entry to the package.json
72
78
  (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (packageJson) => {
73
79
  packageJson.bin = {
74
80
  [options.name]: './bin/index.js',
75
81
  };
82
+ if (isTsSolutionSetup) {
83
+ packageJson.bin[options.name] = './dist/bin/index.js';
84
+ // this package only exposes a binary entry point and no JS programmatic API
85
+ delete packageJson.main;
86
+ delete packageJson.types;
87
+ delete packageJson.typings;
88
+ delete packageJson.exports;
89
+ }
76
90
  packageJson.dependencies = {
77
- 'create-nx-workspace': versions_1.nxVersion,
78
- ...(options.bundler === 'tsc' && { tslib: versions_2.tsLibVersion }),
91
+ 'create-nx-workspace': versions_2.nxVersion,
92
+ ...(options.bundler === 'tsc' && { tslib: versions_1.tsLibVersion }),
79
93
  };
80
94
  return packageJson;
81
95
  });
@@ -84,10 +98,20 @@ async function createCliPackage(host, options, pluginPackageName) {
84
98
  projectConfiguration.sourceRoot = (0, devkit_1.joinPathFragments)(options.projectRoot, 'bin');
85
99
  projectConfiguration.targets.build.options.main = (0, devkit_1.joinPathFragments)(options.projectRoot, 'bin/index.ts');
86
100
  projectConfiguration.implicitDependencies = [options.project];
101
+ if (options.isTsSolutionSetup) {
102
+ if (options.bundler === 'tsc') {
103
+ projectConfiguration.targets.build.options.generatePackageJson = false;
104
+ }
105
+ else if (options.bundler === 'swc') {
106
+ delete projectConfiguration.targets.build.options.stripLeadingPaths;
107
+ }
108
+ }
87
109
  (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
88
- // Add bin files to tsconfg.lib.json
110
+ // Add bin files and update rootDir in tsconfg.lib.json
89
111
  (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'), (tsConfig) => {
90
112
  tsConfig.include.push('bin/**/*.ts');
113
+ tsConfig.compilerOptions ??= {};
114
+ tsConfig.compilerOptions.rootDir = '.';
91
115
  return tsConfig;
92
116
  });
93
117
  (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/create-framework-package'), options.projectRoot, {
@@ -95,6 +119,7 @@ async function createCliPackage(host, options, pluginPackageName) {
95
119
  preset: pluginPackageName,
96
120
  tmpl: '',
97
121
  });
122
+ return jsLibraryTask;
98
123
  }
99
124
  /**
100
125
  * Add a test file to plugin e2e project
@@ -109,7 +134,7 @@ function addE2eProject(host, options) {
109
134
  (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/e2e'), e2eProjectConfiguration.sourceRoot, {
110
135
  pluginName: options.project,
111
136
  cliName: options.name,
112
- packageManagerCommands: (0, devkit_1.getPackageManagerCommand)('npm'),
137
+ packageManagerCommands: (0, devkit_1.getPackageManagerCommand)(),
113
138
  pluginPackageName,
114
139
  tmpl: '',
115
140
  });
@@ -11,15 +11,19 @@ async function main() {
11
11
  console.log(`Creating the workspace: ${name}`);
12
12
 
13
13
  // This assumes "<%= preset %>" and "<%= projectName %>" are at the same version
14
- // eslint-disable-next-line @typescript-eslint/no-var-requires
15
- const presetVersion = require('../package.json').version,
14
+ // eslint-disable-next-line @typescript-eslint/no-var-requires<% if (isTsSolutionSetup) { %>
15
+ const presetVersion = require('../../package.json').version;<% } else { %>
16
+ const presetVersion = require('../package.json').version;<% } %>
16
17
 
17
18
  // TODO: update below to customize the workspace
18
- const { directory } = await createWorkspace(`<%= preset %>@${presetVersion}`, {
19
- name,
20
- nxCloud: 'skip',
21
- packageManager: 'npm',
22
- });
19
+ const { directory } = await createWorkspace(
20
+ `<%= preset %>@${presetVersion}`,
21
+ {
22
+ name,
23
+ nxCloud: 'skip',
24
+ packageManager: 'npm',
25
+ }
26
+ );
23
27
 
24
28
  console.log(`Successfully created the workspace: ${directory}.`);
25
29
  }
@@ -6,11 +6,13 @@ describe('<%= cliName %>', () => {
6
6
  let projectDirectory: string;
7
7
 
8
8
  afterAll(() => {
9
- // Cleanup the test project
10
- rmSync(projectDirectory, {
11
- recursive: true,
12
- force: true,
13
- });
9
+ if (projectDirectory) {
10
+ // Cleanup the test project
11
+ rmSync(projectDirectory, {
12
+ recursive: true,
13
+ force: true,
14
+ });
15
+ }
14
16
  });
15
17
 
16
18
 
@@ -43,7 +45,7 @@ function createTestProject(extraArgs = '') {
43
45
  });
44
46
 
45
47
  execSync(
46
- `<%= packageManagerCommands.exec %> --yes <%= cliName %>@e2e ${projectName} ${extraArgs}`,
48
+ `<%= packageManagerCommands.dlx %> <%= cliName %>@e2e ${projectName} ${extraArgs}`,
47
49
  {
48
50
  cwd: dirname(projectDirectory),
49
51
  stdio: 'inherit',
@@ -1,19 +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 CreatePackageSchema {
5
4
  name: string;
6
5
  project: string;
6
+ directory: string;
7
7
 
8
8
  // options to create cli package, passed to js library generator
9
- directory?: string;
10
- projectNameAndRootFormat?: ProjectNameAndRootFormat;
11
- skipFormat: boolean;
9
+ skipFormat?: boolean;
12
10
  tags?: string;
13
- unitTestRunner: 'jest' | 'none';
14
- linter: Linter | LinterType;
15
- compiler: 'swc' | 'tsc';
11
+ unitTestRunner?: 'jest' | 'vitest' | 'none';
12
+ linter?: Linter | LinterType;
13
+ compiler?: 'swc' | 'tsc';
16
14
 
17
15
  // options to create e2e project, passed to e2e project generator
18
16
  e2eProject?: string;
17
+
18
+ useProjectJson?: boolean;
19
+ addPlugin?: boolean;
19
20
  }
@@ -7,14 +7,18 @@
7
7
  "examplesFile": "../../../docs/generators/create-package-examples.md",
8
8
  "type": "object",
9
9
  "properties": {
10
- "name": {
10
+ "directory": {
11
11
  "type": "string",
12
- "description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.",
13
- "pattern": "create-.+|^@.+/create(?:-.+)?",
12
+ "description": "A directory where the app is placed.",
14
13
  "$default": {
15
14
  "$source": "argv",
16
15
  "index": 0
17
- },
16
+ }
17
+ },
18
+ "name": {
19
+ "type": "string",
20
+ "description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.",
21
+ "pattern": "create-.+|^@.+/create(?:-.+)?",
18
22
  "x-priority": "important"
19
23
  },
20
24
  "project": {
@@ -29,24 +33,13 @@
29
33
  },
30
34
  "unitTestRunner": {
31
35
  "type": "string",
32
- "enum": ["jest", "none"],
33
- "description": "Test runner to use for unit tests.",
34
- "default": "jest"
35
- },
36
- "directory": {
37
- "type": "string",
38
- "description": "A directory where the app is placed."
39
- },
40
- "projectNameAndRootFormat": {
41
- "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`).",
42
- "type": "string",
43
- "enum": ["as-provided", "derived"]
36
+ "enum": ["none", "jest", "vitest"],
37
+ "description": "Test runner to use for unit tests."
44
38
  },
45
39
  "linter": {
46
40
  "description": "The tool to use for running lint checks.",
47
41
  "type": "string",
48
- "enum": ["eslint"],
49
- "default": "eslint"
42
+ "enum": ["none", "eslint"]
50
43
  },
51
44
  "tags": {
52
45
  "type": "string",
@@ -69,7 +62,11 @@
69
62
  "type": "string",
70
63
  "description": "The name of the e2e project.",
71
64
  "x-prompt": "What is the name of the e2e project? Leave blank to skip e2e tests"
65
+ },
66
+ "useProjectJson": {
67
+ "type": "boolean",
68
+ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
72
69
  }
73
70
  },
74
- "required": ["name", "project"]
71
+ "required": ["directory", "name", "project"]
75
72
  }
@@ -1,8 +1,14 @@
1
1
  import { Tree } from '@nx/devkit';
2
+ import type { LinterType } from '@nx/eslint';
2
3
  import { CreatePackageSchema } from '../schema';
3
4
  export interface NormalizedSchema extends CreatePackageSchema {
4
5
  bundler: 'swc' | 'tsc';
5
6
  projectName: string;
6
7
  projectRoot: string;
8
+ unitTestRunner: 'jest' | 'vitest' | 'none';
9
+ linter: LinterType;
10
+ useProjectJson: boolean;
11
+ addPlugin: boolean;
12
+ isTsSolutionSetup: boolean;
7
13
  }
8
14
  export declare function normalizeSchema(host: Tree, schema: CreatePackageSchema): Promise<NormalizedSchema>;
@@ -1,21 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeSchema = normalizeSchema;
4
+ const devkit_1 = require("@nx/devkit");
4
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");
5
8
  async function normalizeSchema(host, schema) {
6
- const { projectName, names: projectNames, projectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
9
+ const linter = await (0, generator_prompts_1.normalizeLinterOption)(host, schema.linter);
10
+ const unitTestRunner = await (0, generator_prompts_1.normalizeUnitTestRunnerOption)(host, schema.unitTestRunner, ['jest']);
11
+ if (!schema.directory) {
12
+ throw new Error(`Please provide the --directory option. It should be the directory containing the project '${schema.project}'.`);
13
+ }
14
+ const { projectName, names: projectNames, projectRoot, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
7
15
  name: schema.name,
8
16
  projectType: 'library',
9
17
  directory: schema.directory,
10
- projectNameAndRootFormat: schema.projectNameAndRootFormat,
11
- callingGenerator: '@nx/plugin:create-package',
12
18
  });
13
- schema.projectNameAndRootFormat = projectNameAndRootFormat;
19
+ const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
20
+ const nxJson = (0, devkit_1.readNxJson)(host);
21
+ const addPlugin = schema.addPlugin ??
22
+ (isTsSolutionSetup &&
23
+ process.env.NX_ADD_PLUGINS !== 'false' &&
24
+ nxJson.useInferencePlugins !== false);
14
25
  return {
15
26
  ...schema,
16
27
  bundler: schema.compiler ?? 'tsc',
17
28
  projectName,
18
29
  projectRoot,
19
30
  name: projectNames.projectSimpleName,
31
+ linter,
32
+ unitTestRunner,
33
+ // We default to generate a project.json file if the new setup is not being used
34
+ useProjectJson: schema.useProjectJson ?? !isTsSolutionSetup,
35
+ addPlugin,
36
+ isTsSolutionSetup,
20
37
  };
21
38
  }
@@ -1,5 +1,4 @@
1
- import type { Tree } from '@nx/devkit';
2
- import { GeneratorCallback } from '@nx/devkit';
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
3
2
  import type { Schema } from './schema';
4
3
  export declare function e2eProjectGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
5
4
  export declare function e2eProjectGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
@@ -4,48 +4,41 @@ exports.e2eProjectGenerator = e2eProjectGenerator;
4
4
  exports.e2eProjectGeneratorInternal = e2eProjectGeneratorInternal;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
7
+ const eslint_1 = require("@nx/eslint");
7
8
  const jest_1 = require("@nx/jest");
8
9
  const js_1 = require("@nx/js");
9
10
  const generator_1 = require("@nx/js/src/generators/setup-verdaccio/generator");
10
11
  const add_local_registry_scripts_1 = require("@nx/js/src/utils/add-local-registry-scripts");
11
- const eslint_1 = require("@nx/eslint");
12
+ const generator_prompts_1 = require("@nx/js/src/utils/generator-prompts");
13
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
12
14
  const path_1 = require("path");
13
15
  async function normalizeOptions(host, options) {
16
+ const linter = await (0, generator_prompts_1.normalizeLinterOption)(host, options.linter);
14
17
  const projectName = options.rootProject ? 'e2e' : `${options.pluginName}-e2e`;
15
18
  const nxJson = (0, devkit_1.readNxJson)(host);
16
- const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
17
- nxJson.useInferencePlugins !== false;
18
- options.addPlugin ??= addPlugin;
19
+ const addPlugin = options.addPlugin ??
20
+ (process.env.NX_ADD_PLUGINS !== 'false' &&
21
+ nxJson.useInferencePlugins !== false);
19
22
  let projectRoot;
20
- if (options.projectNameAndRootFormat === 'as-provided') {
21
- const projectNameAndRootOptions = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
22
- name: projectName,
23
- projectType: 'application',
24
- directory: options.rootProject || !options.projectDirectory
25
- ? projectName
26
- : `${options.projectDirectory}-e2e`,
27
- projectNameAndRootFormat: `as-provided`,
28
- callingGenerator: '@nx/plugin:e2e-project',
29
- });
30
- projectRoot = projectNameAndRootOptions.projectRoot;
31
- }
32
- else {
33
- const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.projectDirectory);
34
- const { appsDir: defaultAppsDir } = (0, devkit_1.getWorkspaceLayout)(host);
35
- const appsDir = layoutDirectory ?? defaultAppsDir;
36
- projectRoot = options.rootProject
23
+ const projectNameAndRootOptions = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
24
+ name: projectName,
25
+ projectType: 'application',
26
+ directory: options.rootProject || !options.projectDirectory
37
27
  ? projectName
38
- : projectDirectory
39
- ? (0, devkit_1.joinPathFragments)(appsDir, `${projectDirectory}-e2e`)
40
- : (0, devkit_1.joinPathFragments)(appsDir, projectName);
41
- }
28
+ : `${options.projectDirectory}-e2e`,
29
+ });
30
+ projectRoot = projectNameAndRootOptions.projectRoot;
42
31
  const pluginPropertyName = (0, devkit_1.names)(options.pluginName).propertyName;
32
+ const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
43
33
  return {
44
34
  ...options,
45
35
  projectName,
46
- linter: options.linter ?? eslint_1.Linter.EsLint,
36
+ linter,
47
37
  pluginPropertyName,
48
38
  projectRoot,
39
+ addPlugin,
40
+ useProjectJson: options.useProjectJson ?? !isTsSolutionSetup,
41
+ isTsSolutionSetup,
49
42
  };
50
43
  }
51
44
  function validatePlugin(host, pluginName) {
@@ -59,22 +52,36 @@ function validatePlugin(host, pluginName) {
59
52
  function addFiles(host, options) {
60
53
  const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.pluginName);
61
54
  const { name: pluginPackageName } = (0, devkit_1.readJson)(host, (0, path_1.join)(projectConfiguration.root, 'package.json'));
55
+ const simplePluginName = options.pluginName.split('/').pop();
62
56
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.projectRoot, {
63
57
  ...options,
64
58
  tmpl: '',
65
59
  rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
66
- packageManagerCommands: (0, devkit_1.getPackageManagerCommand)('npm'),
60
+ packageManagerCommands: (0, devkit_1.getPackageManagerCommand)(),
67
61
  pluginPackageName,
62
+ simplePluginName,
68
63
  });
69
64
  }
70
65
  async function addJest(host, options) {
71
- (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
66
+ const projectConfiguration = {
67
+ name: options.projectName,
72
68
  root: options.projectRoot,
73
69
  projectType: 'application',
74
70
  sourceRoot: `${options.projectRoot}/src`,
75
- targets: {},
76
71
  implicitDependencies: [options.pluginName],
77
- });
72
+ };
73
+ if (options.isTsSolutionSetup) {
74
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), {
75
+ name: options.projectName,
76
+ version: '0.0.1',
77
+ private: true,
78
+ });
79
+ (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
80
+ }
81
+ else {
82
+ projectConfiguration.targets = {};
83
+ (0, devkit_1.addProjectConfiguration)(host, options.projectName, projectConfiguration);
84
+ }
78
85
  const jestTask = await (0, jest_1.configurationGenerator)(host, {
79
86
  project: options.projectName,
80
87
  targetName: 'e2e',
@@ -83,11 +90,13 @@ async function addJest(host, options) {
83
90
  skipSerializers: true,
84
91
  skipFormat: true,
85
92
  addPlugin: options.addPlugin,
93
+ compiler: options.isTsSolutionSetup ? 'swc' : undefined,
86
94
  });
87
95
  const { startLocalRegistryPath, stopLocalRegistryPath } = (0, add_local_registry_scripts_1.addLocalRegistryScripts)(host);
88
96
  (0, jest_1.addPropertyToJestConfig)(host, (0, path_1.join)(options.projectRoot, 'jest.config.ts'), 'globalSetup', (0, path_1.join)((0, devkit_1.offsetFromRoot)(options.projectRoot), startLocalRegistryPath));
89
97
  (0, jest_1.addPropertyToJestConfig)(host, (0, path_1.join)(options.projectRoot, 'jest.config.ts'), 'globalTeardown', (0, path_1.join)((0, devkit_1.offsetFromRoot)(options.projectRoot), stopLocalRegistryPath));
90
98
  const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
99
+ project.targets ??= {};
91
100
  const e2eTarget = project.targets.e2e;
92
101
  project.targets.e2e = {
93
102
  ...e2eTarget,
@@ -114,10 +123,18 @@ async function addLintingToApplication(tree, options) {
114
123
  });
115
124
  return lintTask;
116
125
  }
126
+ function updatePluginPackageJson(tree, options) {
127
+ const { root } = (0, devkit_1.readProjectConfiguration)(tree, options.pluginName);
128
+ (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(root, 'package.json'), (json) => {
129
+ // to publish the plugin, we need to remove the private flag
130
+ delete json.private;
131
+ return json;
132
+ });
133
+ }
117
134
  async function e2eProjectGenerator(host, schema) {
118
135
  return await e2eProjectGeneratorInternal(host, {
119
136
  addPlugin: false,
120
- projectNameAndRootFormat: 'derived',
137
+ useProjectJson: true,
121
138
  ...schema,
122
139
  });
123
140
  }
@@ -130,11 +147,29 @@ async function e2eProjectGeneratorInternal(host, schema) {
130
147
  skipFormat: true,
131
148
  }));
132
149
  tasks.push(await addJest(host, options));
133
- if (options.linter !== eslint_1.Linter.None) {
150
+ updatePluginPackageJson(host, options);
151
+ if (options.linter !== 'none') {
134
152
  tasks.push(await addLintingToApplication(host, {
135
153
  ...options,
136
154
  }));
137
155
  }
156
+ if (options.isTsSolutionSetup && !options.rootProject) {
157
+ // update root tsconfig.json references with the new lib tsconfig
158
+ (0, devkit_1.updateJson)(host, 'tsconfig.json', (json) => {
159
+ json.references ??= [];
160
+ json.references.push({
161
+ path: options.projectRoot.startsWith('./')
162
+ ? options.projectRoot
163
+ : './' + options.projectRoot,
164
+ });
165
+ return json;
166
+ });
167
+ }
168
+ // If we are using the new TS solution
169
+ // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
170
+ if (options.isTsSolutionSetup) {
171
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
172
+ }
138
173
  if (!options.skipFormat) {
139
174
  await (0, devkit_1.formatFiles)(host);
140
175
  }