@nx/plugin 0.0.0-pr-22179-271588f

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 (97) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +72 -0
  3. package/executors.json +10 -0
  4. package/generators.d.ts +6 -0
  5. package/generators.js +9 -0
  6. package/generators.json +49 -0
  7. package/index.d.ts +0 -0
  8. package/index.js +0 -0
  9. package/migrations.json +40 -0
  10. package/package.json +44 -0
  11. package/src/executors/e2e/e2e.impl.d.ts +6 -0
  12. package/src/executors/e2e/e2e.impl.js +43 -0
  13. package/src/executors/e2e/schema.d.ts +6 -0
  14. package/src/executors/e2e/schema.json +220 -0
  15. package/src/generators/create-package/create-package.d.ts +5 -0
  16. package/src/generators/create-package/create-package.js +112 -0
  17. package/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +27 -0
  18. package/src/generators/create-package/files/e2e/__cliName__.spec.ts__tmpl__ +56 -0
  19. package/src/generators/create-package/schema.d.ts +19 -0
  20. package/src/generators/create-package/schema.json +79 -0
  21. package/src/generators/create-package/utils/normalize-schema.d.ts +8 -0
  22. package/src/generators/create-package/utils/normalize-schema.js +22 -0
  23. package/src/generators/e2e-project/e2e.d.ts +6 -0
  24. package/src/generators/e2e-project/e2e.js +144 -0
  25. package/src/generators/e2e-project/files/src/__pluginName__.spec.ts__tmpl__ +66 -0
  26. package/src/generators/e2e-project/files/tsconfig.json__tmpl__ +6 -0
  27. package/src/generators/e2e-project/schema.d.ts +15 -0
  28. package/src/generators/e2e-project/schema.json +57 -0
  29. package/src/generators/executor/executor.d.ts +6 -0
  30. package/src/generators/executor/executor.js +126 -0
  31. package/src/generators/executor/files/executor/executor.spec.ts.template +11 -0
  32. package/src/generators/executor/files/executor/executor.ts.template +11 -0
  33. package/src/generators/executor/files/executor/schema.d.ts.template +1 -0
  34. package/src/generators/executor/files/executor/schema.json.template +9 -0
  35. package/src/generators/executor/files/hasher/hasher.spec.ts.template +23 -0
  36. package/src/generators/executor/files/hasher/hasher.ts.template +12 -0
  37. package/src/generators/executor/schema.d.ts +17 -0
  38. package/src/generators/executor/schema.json +76 -0
  39. package/src/generators/generator/files/generator/generator.spec.ts.template +20 -0
  40. package/src/generators/generator/files/generator/generator.ts.template +26 -0
  41. package/src/generators/generator/files/generator/schema.d.ts.template +3 -0
  42. package/src/generators/generator/files/generator/schema.json.template +18 -0
  43. package/src/generators/generator/generator.d.ts +6 -0
  44. package/src/generators/generator/generator.js +127 -0
  45. package/src/generators/generator/schema.d.ts +16 -0
  46. package/src/generators/generator/schema.json +70 -0
  47. package/src/generators/lint-checks/generator.d.ts +7 -0
  48. package/src/generators/lint-checks/generator.js +187 -0
  49. package/src/generators/lint-checks/schema.d.ts +4 -0
  50. package/src/generators/lint-checks/schema.json +31 -0
  51. package/src/generators/migration/files/migration/__name__.spec.ts__tmpl__ +17 -0
  52. package/src/generators/migration/files/migration/__name__.ts__tmpl__ +6 -0
  53. package/src/generators/migration/migration.d.ts +5 -0
  54. package/src/generators/migration/migration.js +135 -0
  55. package/src/generators/migration/schema.d.ts +16 -0
  56. package/src/generators/migration/schema.json +68 -0
  57. package/src/generators/plugin/files/plugin/src/index.ts__tmpl__ +0 -0
  58. package/src/generators/plugin/plugin.d.ts +5 -0
  59. package/src/generators/plugin/plugin.js +107 -0
  60. package/src/generators/plugin/schema.d.ts +20 -0
  61. package/src/generators/plugin/schema.json +104 -0
  62. package/src/generators/plugin/utils/normalize-schema.d.ts +13 -0
  63. package/src/generators/plugin/utils/normalize-schema.js +44 -0
  64. package/src/generators/preset/generator.d.ts +3 -0
  65. package/src/generators/preset/generator.js +58 -0
  66. package/src/generators/preset/schema.d.ts +4 -0
  67. package/src/generators/preset/schema.json +30 -0
  68. package/src/migrations/update-15-0-0/specify-output-capture.d.ts +2 -0
  69. package/src/migrations/update-15-0-0/specify-output-capture.js +53 -0
  70. package/src/migrations/update-15-9-0/jest-29-configs.d.ts +3 -0
  71. package/src/migrations/update-15-9-0/jest-29-configs.js +147 -0
  72. package/src/migrations/update-15-9-0/jest-29-tests.d.ts +5 -0
  73. package/src/migrations/update-15-9-0/jest-29-tests.js +61 -0
  74. package/src/migrations/update-16-0-0/cli-in-schema-json.d.ts +3 -0
  75. package/src/migrations/update-16-0-0/cli-in-schema-json.js +135 -0
  76. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  77. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  78. package/src/migrations/update-16-2-0/replace-e2e-executor.d.ts +2 -0
  79. package/src/migrations/update-16-2-0/replace-e2e-executor.js +32 -0
  80. package/src/utils/has-generator.d.ts +2 -0
  81. package/src/utils/has-generator.js +16 -0
  82. package/src/utils/testing-utils/async-commands.d.ts +28 -0
  83. package/src/utils/testing-utils/async-commands.js +50 -0
  84. package/src/utils/testing-utils/commands.d.ts +17 -0
  85. package/src/utils/testing-utils/commands.js +63 -0
  86. package/src/utils/testing-utils/index.d.ts +5 -0
  87. package/src/utils/testing-utils/index.js +8 -0
  88. package/src/utils/testing-utils/nx-project.d.ts +25 -0
  89. package/src/utils/testing-utils/nx-project.js +70 -0
  90. package/src/utils/testing-utils/paths.d.ts +15 -0
  91. package/src/utils/testing-utils/paths.js +32 -0
  92. package/src/utils/testing-utils/utils.d.ts +80 -0
  93. package/src/utils/testing-utils/utils.js +144 -0
  94. package/src/utils/versions.d.ts +2 -0
  95. package/src/utils/versions.js +5 -0
  96. package/testing.d.ts +1 -0
  97. package/testing.js +4 -0
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPackageGeneratorInternal = exports.createPackageGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
6
+ const versions_1 = require("nx/src/utils/versions");
7
+ const generator_1 = require("../generator/generator");
8
+ const normalize_schema_1 = require("./utils/normalize-schema");
9
+ const has_generator_1 = require("../../utils/has-generator");
10
+ const path_1 = require("path");
11
+ async function createPackageGenerator(host, schema) {
12
+ return await createPackageGeneratorInternal(host, {
13
+ projectNameAndRootFormat: 'derived',
14
+ ...schema,
15
+ });
16
+ }
17
+ exports.createPackageGenerator = createPackageGenerator;
18
+ async function createPackageGeneratorInternal(host, schema) {
19
+ const tasks = [];
20
+ const options = await (0, normalize_schema_1.normalizeSchema)(host, schema);
21
+ const pluginPackageName = await addPresetGenerator(host, options);
22
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {
23
+ 'create-nx-workspace': versions_1.nxVersion,
24
+ }, {});
25
+ tasks.push(installTask);
26
+ await createCliPackage(host, options, pluginPackageName);
27
+ if (options.e2eProject) {
28
+ addE2eProject(host, options);
29
+ }
30
+ if (!options.skipFormat) {
31
+ await (0, devkit_1.formatFiles)(host);
32
+ }
33
+ return (0, devkit_1.runTasksInSerial)(...tasks);
34
+ }
35
+ exports.createPackageGeneratorInternal = createPackageGeneratorInternal;
36
+ /**
37
+ * Add a preset generator to the plugin if it doesn't exist
38
+ * @param host
39
+ * @param schema
40
+ * @returns package name of the plugin
41
+ */
42
+ async function addPresetGenerator(host, schema) {
43
+ const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.project);
44
+ if (!(0, has_generator_1.hasGenerator)(host, schema.project, 'preset')) {
45
+ await (0, generator_1.default)(host, {
46
+ name: 'preset',
47
+ directory: (0, path_1.join)(projectRoot, 'src/generators/preset'),
48
+ unitTestRunner: schema.unitTestRunner,
49
+ skipFormat: true,
50
+ nameAndDirectoryFormat: 'as-provided',
51
+ });
52
+ }
53
+ return (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'))?.name;
54
+ }
55
+ async function createCliPackage(host, options, pluginPackageName) {
56
+ await (0, js_1.libraryGenerator)(host, {
57
+ ...options,
58
+ rootProject: false,
59
+ config: 'project',
60
+ publishable: true,
61
+ bundler: options.bundler,
62
+ importPath: options.name,
63
+ skipFormat: true,
64
+ skipTsConfig: true,
65
+ });
66
+ host.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'src'));
67
+ // Add the bin entry to the package.json
68
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (packageJson) => {
69
+ packageJson.bin = {
70
+ [options.name]: './bin/index.js',
71
+ };
72
+ packageJson.dependencies = {
73
+ 'create-nx-workspace': versions_1.nxVersion,
74
+ };
75
+ return packageJson;
76
+ });
77
+ // update project build target to use the bin entry
78
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
79
+ projectConfiguration.sourceRoot = (0, devkit_1.joinPathFragments)(options.projectRoot, 'bin');
80
+ projectConfiguration.targets.build.options.main = (0, devkit_1.joinPathFragments)(options.projectRoot, 'bin/index.ts');
81
+ projectConfiguration.implicitDependencies = [options.project];
82
+ (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
83
+ // Add bin files to tsconfg.lib.json
84
+ (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'), (tsConfig) => {
85
+ tsConfig.include.push('bin/**/*.ts');
86
+ return tsConfig;
87
+ });
88
+ (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/create-framework-package'), options.projectRoot, {
89
+ ...options,
90
+ preset: pluginPackageName,
91
+ tmpl: '',
92
+ });
93
+ }
94
+ /**
95
+ * Add a test file to plugin e2e project
96
+ * @param host
97
+ * @param options
98
+ * @returns
99
+ */
100
+ function addE2eProject(host, options) {
101
+ const e2eProjectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.e2eProject);
102
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.project);
103
+ const { name: pluginPackageName } = (0, devkit_1.readJson)(host, (0, path_1.join)(projectConfiguration.root, 'package.json'));
104
+ (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/e2e'), e2eProjectConfiguration.sourceRoot, {
105
+ pluginName: options.project,
106
+ cliName: options.name,
107
+ packageManagerCommands: (0, devkit_1.getPackageManagerCommand)('npm'),
108
+ pluginPackageName,
109
+ tmpl: '',
110
+ });
111
+ }
112
+ exports.default = createPackageGenerator;
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { createWorkspace } from 'create-nx-workspace';
4
+
5
+ async function main() {
6
+ const name = process.argv[2]; // TODO: use libraries like yargs or enquirer to set your workspace name
7
+ if (!name) {
8
+ throw new Error('Please provide a name for the workspace');
9
+ }
10
+
11
+ console.log(`Creating the workspace: ${name}`);
12
+
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,
16
+
17
+ // TODO: update below to customize the workspace
18
+ const { directory } = await createWorkspace(`<%= preset %>@${presetVersion}`, {
19
+ name,
20
+ nxCloud: 'skip',
21
+ packageManager: 'npm',
22
+ });
23
+
24
+ console.log(`Successfully created the workspace: ${directory}.`);
25
+ }
26
+
27
+ main();
@@ -0,0 +1,56 @@
1
+ import { execSync } from 'child_process';
2
+ import { join, dirname } from 'path';
3
+ import { mkdirSync, rmSync } from 'fs';
4
+
5
+ describe('<%= cliName %>', () => {
6
+ let projectDirectory: string;
7
+
8
+ afterAll(() => {
9
+ // Cleanup the test project
10
+ rmSync(projectDirectory, {
11
+ recursive: true,
12
+ force: true,
13
+ });
14
+ });
15
+
16
+
17
+ it('should be installed', () => {
18
+ projectDirectory = createTestProject();
19
+
20
+ // npm ls will fail if the package is not installed properly
21
+ execSync('<%= packageManagerCommands.list %> <%= pluginPackageName %>', {
22
+ cwd: projectDirectory,
23
+ stdio: 'inherit',
24
+ });
25
+ });
26
+ });
27
+
28
+ /**
29
+ * Creates a test project with create-nx-workspace and installs the plugin
30
+ * @returns The directory where the test project was created
31
+ */
32
+ function createTestProject(extraArgs = '') {
33
+ const projectName = 'test-project';
34
+ const projectDirectory = join(process.cwd(), 'tmp', projectName);
35
+
36
+ // Ensure projectDirectory is empty
37
+ rmSync(projectDirectory, {
38
+ recursive: true,
39
+ force: true,
40
+ });
41
+ mkdirSync(dirname(projectDirectory), {
42
+ recursive: true,
43
+ });
44
+
45
+ execSync(
46
+ `<%= packageManagerCommands.exec %> --yes <%= cliName %>@e2e ${projectName} ${extraArgs}`,
47
+ {
48
+ cwd: dirname(projectDirectory),
49
+ stdio: 'inherit',
50
+ env: process.env,
51
+ }
52
+ );
53
+ console.log(`Created test project in "${projectDirectory}"`);
54
+
55
+ return projectDirectory;
56
+ }
@@ -0,0 +1,19 @@
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/eslint';
3
+
4
+ export interface CreatePackageSchema {
5
+ name: string;
6
+ project: string;
7
+
8
+ // options to create cli package, passed to js library generator
9
+ directory?: string;
10
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
11
+ skipFormat: boolean;
12
+ tags?: string;
13
+ unitTestRunner: 'jest' | 'none';
14
+ linter: Linter;
15
+ compiler: 'swc' | 'tsc';
16
+
17
+ // options to create e2e project, passed to e2e project generator
18
+ e2eProject?: string;
19
+ }
@@ -0,0 +1,79 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxPluginCreatePackage",
5
+ "title": "Create a framework package",
6
+ "description": "Create a framework package that uses Nx CLI.",
7
+ "examplesFile": "../../../docs/generators/create-package-examples.md",
8
+ "type": "object",
9
+ "properties": {
10
+ "name": {
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(?:-.+)?",
14
+ "$default": {
15
+ "$source": "argv",
16
+ "index": 0
17
+ },
18
+ "x-priority": "important"
19
+ },
20
+ "project": {
21
+ "type": "string",
22
+ "description": "The name of the generator project.",
23
+ "alias": "p",
24
+ "$default": {
25
+ "$source": "projectName"
26
+ },
27
+ "x-prompt": "What is the name of the project for the generator?",
28
+ "x-priority": "important"
29
+ },
30
+ "unitTestRunner": {
31
+ "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"]
44
+ },
45
+ "linter": {
46
+ "description": "The tool to use for running lint checks.",
47
+ "type": "string",
48
+ "enum": ["eslint"],
49
+ "default": "eslint"
50
+ },
51
+ "tags": {
52
+ "type": "string",
53
+ "description": "Add tags to the library (used for linting).",
54
+ "alias": "t"
55
+ },
56
+ "skipFormat": {
57
+ "description": "Skip formatting files.",
58
+ "type": "boolean",
59
+ "default": false,
60
+ "x-priority": "internal"
61
+ },
62
+ "compiler": {
63
+ "type": "string",
64
+ "enum": ["tsc", "swc"],
65
+ "default": "tsc",
66
+ "description": "The compiler used by the build and test targets."
67
+ },
68
+ "e2eProject": {
69
+ "type": "string",
70
+ "description": "The name of the e2e project.",
71
+ "alias": "p",
72
+ "$default": {
73
+ "$source": "projectName"
74
+ },
75
+ "x-prompt": "What is the name of the e2e project?"
76
+ }
77
+ },
78
+ "required": ["name", "project"]
79
+ }
@@ -0,0 +1,8 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { CreatePackageSchema } from '../schema';
3
+ export interface NormalizedSchema extends CreatePackageSchema {
4
+ bundler: 'swc' | 'tsc';
5
+ projectName: string;
6
+ projectRoot: string;
7
+ }
8
+ export declare function normalizeSchema(host: Tree, schema: CreatePackageSchema): Promise<NormalizedSchema>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeSchema = void 0;
4
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
5
+ async function normalizeSchema(host, schema) {
6
+ const { projectName, names: projectNames, projectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
7
+ name: schema.name,
8
+ projectType: 'library',
9
+ directory: schema.directory,
10
+ projectNameAndRootFormat: schema.projectNameAndRootFormat,
11
+ callingGenerator: '@nx/plugin:create-package',
12
+ });
13
+ schema.projectNameAndRootFormat = projectNameAndRootFormat;
14
+ return {
15
+ ...schema,
16
+ bundler: schema.compiler ?? 'tsc',
17
+ projectName,
18
+ projectRoot,
19
+ name: projectNames.projectSimpleName,
20
+ };
21
+ }
22
+ exports.normalizeSchema = normalizeSchema;
@@ -0,0 +1,6 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import { GeneratorCallback } from '@nx/devkit';
3
+ import type { Schema } from './schema';
4
+ export declare function e2eProjectGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
5
+ export declare function e2eProjectGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
6
+ export default e2eProjectGenerator;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.e2eProjectGeneratorInternal = exports.e2eProjectGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ const jest_1 = require("@nx/jest");
7
+ const js_1 = require("@nx/js");
8
+ const generator_1 = require("@nx/js/src/generators/setup-verdaccio/generator");
9
+ const add_local_registry_scripts_1 = require("@nx/js/src/utils/add-local-registry-scripts");
10
+ const eslint_1 = require("@nx/eslint");
11
+ const path_1 = require("path");
12
+ async function normalizeOptions(host, options) {
13
+ const projectName = options.rootProject ? 'e2e' : `${options.pluginName}-e2e`;
14
+ const nxJson = (0, devkit_1.readNxJson)(host);
15
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
16
+ nxJson.useInferencePlugins !== false;
17
+ options.addPlugin ??= addPlugin;
18
+ let projectRoot;
19
+ if (options.projectNameAndRootFormat === 'as-provided') {
20
+ const projectNameAndRootOptions = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
21
+ name: projectName,
22
+ projectType: 'application',
23
+ directory: options.rootProject || !options.projectDirectory
24
+ ? projectName
25
+ : `${options.projectDirectory}-e2e`,
26
+ projectNameAndRootFormat: `as-provided`,
27
+ callingGenerator: '@nx/plugin:e2e-project',
28
+ });
29
+ projectRoot = projectNameAndRootOptions.projectRoot;
30
+ }
31
+ else {
32
+ const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.projectDirectory);
33
+ const { appsDir: defaultAppsDir } = (0, devkit_1.getWorkspaceLayout)(host);
34
+ const appsDir = layoutDirectory ?? defaultAppsDir;
35
+ projectRoot = options.rootProject
36
+ ? projectName
37
+ : projectDirectory
38
+ ? (0, devkit_1.joinPathFragments)(appsDir, `${projectDirectory}-e2e`)
39
+ : (0, devkit_1.joinPathFragments)(appsDir, projectName);
40
+ }
41
+ const pluginPropertyName = (0, devkit_1.names)(options.pluginName).propertyName;
42
+ return {
43
+ ...options,
44
+ projectName,
45
+ linter: options.linter ?? eslint_1.Linter.EsLint,
46
+ pluginPropertyName,
47
+ projectRoot,
48
+ };
49
+ }
50
+ function validatePlugin(host, pluginName) {
51
+ try {
52
+ (0, devkit_1.readProjectConfiguration)(host, pluginName);
53
+ }
54
+ catch {
55
+ throw new Error(`Project name "${pluginName}" doesn't not exist.`);
56
+ }
57
+ }
58
+ function addFiles(host, options) {
59
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.pluginName);
60
+ const { name: pluginPackageName } = (0, devkit_1.readJson)(host, (0, path_1.join)(projectConfiguration.root, 'package.json'));
61
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.projectRoot, {
62
+ ...options,
63
+ tmpl: '',
64
+ rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
65
+ packageManagerCommands: (0, devkit_1.getPackageManagerCommand)('npm'),
66
+ pluginPackageName,
67
+ });
68
+ }
69
+ async function addJest(host, options) {
70
+ (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
71
+ root: options.projectRoot,
72
+ projectType: 'application',
73
+ sourceRoot: `${options.projectRoot}/src`,
74
+ targets: {},
75
+ implicitDependencies: [options.pluginName],
76
+ });
77
+ const jestTask = await (0, jest_1.configurationGenerator)(host, {
78
+ project: options.projectName,
79
+ targetName: 'e2e',
80
+ setupFile: 'none',
81
+ supportTsx: false,
82
+ skipSerializers: true,
83
+ skipFormat: true,
84
+ addPlugin: options.addPlugin,
85
+ });
86
+ const { startLocalRegistryPath, stopLocalRegistryPath } = (0, add_local_registry_scripts_1.addLocalRegistryScripts)(host);
87
+ (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));
88
+ (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));
89
+ const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
90
+ const e2eTarget = project.targets.e2e;
91
+ project.targets.e2e = {
92
+ ...e2eTarget,
93
+ dependsOn: [`^build`],
94
+ options: {
95
+ ...e2eTarget.options,
96
+ runInBand: true,
97
+ },
98
+ };
99
+ (0, devkit_1.updateProjectConfiguration)(host, options.projectName, project);
100
+ return jestTask;
101
+ }
102
+ async function addLintingToApplication(tree, options) {
103
+ const lintTask = await (0, eslint_1.lintProjectGenerator)(tree, {
104
+ linter: options.linter,
105
+ project: options.projectName,
106
+ tsConfigPaths: [
107
+ (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.app.json'),
108
+ ],
109
+ unitTestRunner: 'jest',
110
+ skipFormat: true,
111
+ setParserOptionsProject: false,
112
+ addPlugin: options.addPlugin,
113
+ });
114
+ return lintTask;
115
+ }
116
+ async function e2eProjectGenerator(host, schema) {
117
+ return await e2eProjectGeneratorInternal(host, {
118
+ addPlugin: false,
119
+ projectNameAndRootFormat: 'derived',
120
+ ...schema,
121
+ });
122
+ }
123
+ exports.e2eProjectGenerator = e2eProjectGenerator;
124
+ async function e2eProjectGeneratorInternal(host, schema) {
125
+ const tasks = [];
126
+ validatePlugin(host, schema.pluginName);
127
+ const options = await normalizeOptions(host, schema);
128
+ addFiles(host, options);
129
+ tasks.push(await (0, generator_1.setupVerdaccio)(host, {
130
+ skipFormat: true,
131
+ }));
132
+ tasks.push(await addJest(host, options));
133
+ if (options.linter !== eslint_1.Linter.None) {
134
+ tasks.push(await addLintingToApplication(host, {
135
+ ...options,
136
+ }));
137
+ }
138
+ if (!options.skipFormat) {
139
+ await (0, devkit_1.formatFiles)(host);
140
+ }
141
+ return (0, devkit_1.runTasksInSerial)(...tasks);
142
+ }
143
+ exports.e2eProjectGeneratorInternal = e2eProjectGeneratorInternal;
144
+ exports.default = e2eProjectGenerator;
@@ -0,0 +1,66 @@
1
+ import { execSync } from 'child_process';
2
+ import { join, dirname } from 'path';
3
+ import { mkdirSync, rmSync } from 'fs';
4
+
5
+ describe('<%= pluginName %>', () => {
6
+ let projectDirectory: string;
7
+
8
+ beforeAll(() => {
9
+ projectDirectory = createTestProject();
10
+
11
+ // The plugin has been built and published to a local registry in the jest globalSetup
12
+ // Install the plugin built with the latest source code into the test repo
13
+ execSync(`<%= packageManagerCommands.install %> <%= pluginPackageName %>@e2e`, {
14
+ cwd: projectDirectory,
15
+ stdio: 'inherit',
16
+ env: process.env,
17
+ });
18
+ });
19
+
20
+ afterAll(() => {
21
+ // Cleanup the test project
22
+ rmSync(projectDirectory, {
23
+ recursive: true,
24
+ force: true,
25
+ });
26
+ });
27
+
28
+
29
+ it('should be installed', () => {
30
+ // npm ls will fail if the package is not installed properly
31
+ execSync('<%= packageManagerCommands.list %> <%= pluginPackageName %>', {
32
+ cwd: projectDirectory,
33
+ stdio: 'inherit',
34
+ });
35
+ });
36
+ });
37
+
38
+ /**
39
+ * Creates a test project with create-nx-workspace and installs the plugin
40
+ * @returns The directory where the test project was created
41
+ */
42
+ function createTestProject() {
43
+ const projectName = 'test-project';
44
+ const projectDirectory = join(process.cwd(), 'tmp', projectName);
45
+
46
+ // Ensure projectDirectory is empty
47
+ rmSync(projectDirectory, {
48
+ recursive: true,
49
+ force: true,
50
+ });
51
+ mkdirSync(dirname(projectDirectory), {
52
+ recursive: true,
53
+ });
54
+
55
+ execSync(
56
+ `<%= packageManagerCommands.exec %> --yes create-nx-workspace@latest ${projectName} --preset apps --nxCloud=skip --no-interactive`,
57
+ {
58
+ cwd: dirname(projectDirectory),
59
+ stdio: 'inherit',
60
+ env: process.env,
61
+ }
62
+ );
63
+ console.log(`Created test project in "${projectDirectory}"`);
64
+
65
+ return projectDirectory;
66
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "<%= rootTsConfigPath %>",
3
+ "files": [],
4
+ "include": [],
5
+ "references": []
6
+ }
@@ -0,0 +1,15 @@
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/eslint';
3
+
4
+ export interface Schema {
5
+ pluginName: string;
6
+ npmPackageName: string;
7
+ projectDirectory?: string;
8
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
9
+ pluginOutputPath?: string;
10
+ jestConfig?: string;
11
+ linter?: Linter;
12
+ skipFormat?: boolean;
13
+ rootProject?: boolean;
14
+ addPlugin?: boolean;
15
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NxPluginE2E",
5
+ "title": "Create an E2E app for a Nx Plugin",
6
+ "description": "Create an E2E app for a Nx Plugin.",
7
+ "examplesFile": "../../../docs/generators/e2e-project-examples.md",
8
+ "type": "object",
9
+ "properties": {
10
+ "pluginName": {
11
+ "type": "string",
12
+ "description": "the project name of the plugin to be tested.",
13
+ "x-priority": "important"
14
+ },
15
+ "npmPackageName": {
16
+ "type": "string",
17
+ "description": "the package name of the plugin as it would be published to NPM.",
18
+ "x-priority": "important"
19
+ },
20
+ "projectDirectory": {
21
+ "type": "string",
22
+ "description": "the directory where the plugin is placed."
23
+ },
24
+ "projectNameAndRootFormat": {
25
+ "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`).",
26
+ "type": "string",
27
+ "enum": ["as-provided", "derived"]
28
+ },
29
+ "pluginOutputPath": {
30
+ "type": "string",
31
+ "description": "the output path of the plugin after it builds.",
32
+ "x-priority": "important"
33
+ },
34
+ "jestConfig": {
35
+ "type": "string",
36
+ "description": "Jest config file."
37
+ },
38
+ "linter": {
39
+ "description": "The tool to use for running lint checks.",
40
+ "type": "string",
41
+ "enum": ["eslint", "none"],
42
+ "default": "eslint"
43
+ },
44
+ "minimal": {
45
+ "type": "boolean",
46
+ "description": "Generate the e2e project with a minimal setup. This would involve not generating tests for a default executor and generator.",
47
+ "default": false
48
+ },
49
+ "skipFormat": {
50
+ "description": "Skip formatting files.",
51
+ "type": "boolean",
52
+ "default": false,
53
+ "x-priority": "internal"
54
+ }
55
+ },
56
+ "required": ["pluginName", "npmPackageName"]
57
+ }
@@ -0,0 +1,6 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { Schema } from './schema';
3
+ export declare function createExecutorsJson(host: Tree, projectRoot: string, projectName: string, skipLintChecks?: boolean): Promise<void>;
4
+ export declare function executorGenerator(tree: Tree, rawOptions: Schema): Promise<void>;
5
+ export declare function executorGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
6
+ export default executorGenerator;