@nx/plugin 20.1.0 → 20.2.0-beta.0
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 +3 -3
- package/package.json +5 -5
- package/src/generators/create-package/create-package.d.ts +1 -0
- package/src/generators/create-package/create-package.js +47 -11
- package/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +3 -2
- package/src/generators/create-package/schema.d.ts +7 -4
- package/src/generators/create-package/schema.json +7 -5
- package/src/generators/create-package/utils/normalize-schema.d.ts +6 -0
- package/src/generators/create-package/utils/normalize-schema.js +17 -0
- package/src/generators/e2e-project/e2e.d.ts +1 -2
- package/src/generators/e2e-project/e2e.js +57 -10
- package/src/generators/e2e-project/schema.d.ts +2 -0
- package/src/generators/e2e-project/schema.json +5 -2
- package/src/generators/executor/executor.d.ts +1 -1
- package/src/generators/executor/executor.js +29 -17
- package/src/generators/executor/files/executor/{executor.spec.ts.template → __fileName__.spec.ts.template} +1 -1
- package/src/generators/generator/files/generator/{generator.spec.ts.template → __fileName__.spec.ts.template} +1 -1
- package/src/generators/generator/generator.js +25 -13
- package/src/generators/migration/migration.d.ts +1 -1
- package/src/generators/migration/migration.js +30 -26
- package/src/generators/plugin/plugin.d.ts +2 -1
- package/src/generators/plugin/plugin.js +41 -30
- package/src/generators/plugin/schema.d.ts +5 -3
- package/src/generators/plugin/schema.json +9 -5
- package/src/generators/plugin/utils/normalize-schema.d.ts +8 -2
- package/src/generators/plugin/utils/normalize-schema.js +17 -0
- package/src/generators/preset/generator.d.ts +5 -3
- package/src/generators/preset/generator.js +46 -20
- package/src/generators/preset/schema.d.ts +9 -0
- package/src/generators/preset/schema.json +4 -0
- package/src/utils/paths.d.ts +2 -0
- package/src/utils/paths.js +31 -0
- /package/src/generators/executor/files/executor/{executor.ts.template → __fileName__.ts.template} +0 -0
- /package/src/generators/generator/files/generator/{generator.ts.template → __fileName__.ts.template} +0 -0
- /package/src/generators/migration/files/migration/{__name__.spec.ts__tmpl__ → __fileName__.spec.ts__tmpl__} +0 -0
- /package/src/generators/migration/files/migration/{__name__.ts__tmpl__ → __fileName__.ts__tmpl__} +0 -0
package/generators.json
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
"extends": ["@nx/workspace"],
|
|
5
5
|
"generators": {
|
|
6
6
|
"plugin": {
|
|
7
|
-
"factory": "./src/generators/plugin/plugin",
|
|
7
|
+
"factory": "./src/generators/plugin/plugin#pluginGeneratorInternal",
|
|
8
8
|
"schema": "./src/generators/plugin/schema.json",
|
|
9
9
|
"description": "Create a Nx Plugin."
|
|
10
10
|
},
|
|
11
11
|
"create-package": {
|
|
12
|
-
"factory": "./src/generators/create-package/create-package",
|
|
12
|
+
"factory": "./src/generators/create-package/create-package#createPackageGeneratorInternal",
|
|
13
13
|
"schema": "./src/generators/create-package/schema.json",
|
|
14
14
|
"description": "Create a package which can be used by npx to create a new workspace"
|
|
15
15
|
},
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/plugin",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.2.0-beta.0",
|
|
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,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"tslib": "^2.3.0",
|
|
31
|
-
"@nx/devkit": "20.
|
|
32
|
-
"@nx/jest": "20.
|
|
33
|
-
"@nx/js": "20.
|
|
34
|
-
"@nx/eslint": "20.
|
|
31
|
+
"@nx/devkit": "20.2.0-beta.0",
|
|
32
|
+
"@nx/jest": "20.2.0-beta.0",
|
|
33
|
+
"@nx/js": "20.2.0-beta.0",
|
|
34
|
+
"@nx/eslint": "20.2.0-beta.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
2
|
import { CreatePackageSchema } from './schema';
|
|
3
3
|
export declare function createPackageGenerator(host: Tree, schema: CreatePackageSchema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function createPackageGeneratorInternal(host: Tree, schema: CreatePackageSchema): Promise<GeneratorCallback>;
|
|
4
5
|
export default createPackageGenerator;
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPackageGenerator = createPackageGenerator;
|
|
4
|
+
exports.createPackageGeneratorInternal = createPackageGeneratorInternal;
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
6
|
const js_1 = require("@nx/js");
|
|
7
|
+
const package_manager_workspaces_1 = require("@nx/js/src/utils/package-manager-workspaces");
|
|
6
8
|
const add_tslib_dependencies_1 = require("@nx/js/src/utils/typescript/add-tslib-dependencies");
|
|
7
9
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
|
-
const versions_1 = require("nx/src/utils/versions");
|
|
10
|
+
const versions_1 = require("@nx/js/src/utils/versions");
|
|
11
|
+
const versions_2 = require("nx/src/utils/versions");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const has_generator_1 = require("../../utils/has-generator");
|
|
9
14
|
const generator_1 = require("../generator/generator");
|
|
10
15
|
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
16
|
async function createPackageGenerator(host, schema) {
|
|
15
|
-
|
|
17
|
+
return await createPackageGeneratorInternal(host, {
|
|
18
|
+
useProjectJson: true,
|
|
19
|
+
addPlugin: false,
|
|
20
|
+
...schema,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async function createPackageGeneratorInternal(host, schema) {
|
|
16
24
|
const tasks = [];
|
|
17
25
|
const options = await (0, normalize_schema_1.normalizeSchema)(host, schema);
|
|
18
26
|
const pluginPackageName = await addPresetGenerator(host, options);
|
|
@@ -20,7 +28,7 @@ async function createPackageGenerator(host, schema) {
|
|
|
20
28
|
tasks.push((0, add_tslib_dependencies_1.addTsLibDependencies)(host));
|
|
21
29
|
}
|
|
22
30
|
const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {
|
|
23
|
-
'create-nx-workspace':
|
|
31
|
+
'create-nx-workspace': versions_2.nxVersion,
|
|
24
32
|
}, {});
|
|
25
33
|
tasks.push(installTask);
|
|
26
34
|
await createCliPackage(host, options, pluginPackageName);
|
|
@@ -30,6 +38,12 @@ async function createPackageGenerator(host, schema) {
|
|
|
30
38
|
if (!options.skipFormat) {
|
|
31
39
|
await (0, devkit_1.formatFiles)(host);
|
|
32
40
|
}
|
|
41
|
+
if (options.isTsSolutionSetup) {
|
|
42
|
+
const projectPackageManagerWorkspaceState = (0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceState)(host, options.projectRoot);
|
|
43
|
+
if (projectPackageManagerWorkspaceState !== 'included') {
|
|
44
|
+
tasks.push((0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceStateWarningTask)(projectPackageManagerWorkspaceState, host.root));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
33
47
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
34
48
|
}
|
|
35
49
|
/**
|
|
@@ -41,11 +55,12 @@ async function createPackageGenerator(host, schema) {
|
|
|
41
55
|
async function addPresetGenerator(host, schema) {
|
|
42
56
|
const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.project);
|
|
43
57
|
if (!(0, has_generator_1.hasGenerator)(host, schema.project, 'preset')) {
|
|
44
|
-
await (0, generator_1.
|
|
58
|
+
await (0, generator_1.generatorGenerator)(host, {
|
|
45
59
|
name: 'preset',
|
|
46
|
-
path: (0, path_1.join)(projectRoot, 'src/generators/preset'),
|
|
60
|
+
path: (0, path_1.join)(projectRoot, 'src/generators/preset/generator'),
|
|
47
61
|
unitTestRunner: schema.unitTestRunner,
|
|
48
62
|
skipFormat: true,
|
|
63
|
+
skipLintChecks: schema.linter === 'none',
|
|
49
64
|
});
|
|
50
65
|
}
|
|
51
66
|
return (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'))?.name;
|
|
@@ -61,16 +76,27 @@ async function createCliPackage(host, options, pluginPackageName) {
|
|
|
61
76
|
importPath: options.name,
|
|
62
77
|
skipFormat: true,
|
|
63
78
|
skipTsConfig: true,
|
|
79
|
+
useTscExecutor: true,
|
|
80
|
+
skipWorkspacesWarning: true,
|
|
64
81
|
});
|
|
65
82
|
host.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'src'));
|
|
83
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
66
84
|
// Add the bin entry to the package.json
|
|
67
85
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (packageJson) => {
|
|
68
86
|
packageJson.bin = {
|
|
69
87
|
[options.name]: './bin/index.js',
|
|
70
88
|
};
|
|
89
|
+
if (isTsSolutionSetup) {
|
|
90
|
+
packageJson.bin[options.name] = './dist/bin/index.js';
|
|
91
|
+
// this package only exposes a binary entry point and no JS programmatic API
|
|
92
|
+
delete packageJson.main;
|
|
93
|
+
delete packageJson.types;
|
|
94
|
+
delete packageJson.typings;
|
|
95
|
+
delete packageJson.exports;
|
|
96
|
+
}
|
|
71
97
|
packageJson.dependencies = {
|
|
72
|
-
'create-nx-workspace':
|
|
73
|
-
...(options.bundler === 'tsc' && { tslib:
|
|
98
|
+
'create-nx-workspace': versions_2.nxVersion,
|
|
99
|
+
...(options.bundler === 'tsc' && { tslib: versions_1.tsLibVersion }),
|
|
74
100
|
};
|
|
75
101
|
return packageJson;
|
|
76
102
|
});
|
|
@@ -79,10 +105,20 @@ async function createCliPackage(host, options, pluginPackageName) {
|
|
|
79
105
|
projectConfiguration.sourceRoot = (0, devkit_1.joinPathFragments)(options.projectRoot, 'bin');
|
|
80
106
|
projectConfiguration.targets.build.options.main = (0, devkit_1.joinPathFragments)(options.projectRoot, 'bin/index.ts');
|
|
81
107
|
projectConfiguration.implicitDependencies = [options.project];
|
|
108
|
+
if (options.isTsSolutionSetup) {
|
|
109
|
+
if (options.bundler === 'tsc') {
|
|
110
|
+
projectConfiguration.targets.build.options.generatePackageJson = false;
|
|
111
|
+
}
|
|
112
|
+
else if (options.bundler === 'swc') {
|
|
113
|
+
delete projectConfiguration.targets.build.options.stripLeadingPaths;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
82
116
|
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
|
|
83
|
-
// Add bin files
|
|
117
|
+
// Add bin files and update rootDir in tsconfg.lib.json
|
|
84
118
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'), (tsConfig) => {
|
|
85
119
|
tsConfig.include.push('bin/**/*.ts');
|
|
120
|
+
tsConfig.compilerOptions ??= {};
|
|
121
|
+
tsConfig.compilerOptions.rootDir = '.';
|
|
86
122
|
return tsConfig;
|
|
87
123
|
});
|
|
88
124
|
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/create-framework-package'), options.projectRoot, {
|
|
@@ -11,8 +11,9 @@ 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('
|
|
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
19
|
const { directory } = await createWorkspace(
|
|
@@ -6,12 +6,15 @@ export interface CreatePackageSchema {
|
|
|
6
6
|
directory: string;
|
|
7
7
|
|
|
8
8
|
// options to create cli package, passed to js library generator
|
|
9
|
-
skipFormat
|
|
9
|
+
skipFormat?: boolean;
|
|
10
10
|
tags?: string;
|
|
11
|
-
unitTestRunner
|
|
12
|
-
linter
|
|
13
|
-
compiler
|
|
11
|
+
unitTestRunner?: 'jest' | 'none';
|
|
12
|
+
linter?: Linter | LinterType;
|
|
13
|
+
compiler?: 'swc' | 'tsc';
|
|
14
14
|
|
|
15
15
|
// options to create e2e project, passed to e2e project generator
|
|
16
16
|
e2eProject?: string;
|
|
17
|
+
|
|
18
|
+
useProjectJson?: boolean;
|
|
19
|
+
addPlugin?: boolean;
|
|
17
20
|
}
|
|
@@ -33,15 +33,13 @@
|
|
|
33
33
|
},
|
|
34
34
|
"unitTestRunner": {
|
|
35
35
|
"type": "string",
|
|
36
|
-
"enum": ["
|
|
37
|
-
"description": "Test runner to use for unit tests."
|
|
38
|
-
"default": "jest"
|
|
36
|
+
"enum": ["none", "jest"],
|
|
37
|
+
"description": "Test runner to use for unit tests."
|
|
39
38
|
},
|
|
40
39
|
"linter": {
|
|
41
40
|
"description": "The tool to use for running lint checks.",
|
|
42
41
|
"type": "string",
|
|
43
|
-
"enum": ["eslint"]
|
|
44
|
-
"default": "eslint"
|
|
42
|
+
"enum": ["none", "eslint"]
|
|
45
43
|
},
|
|
46
44
|
"tags": {
|
|
47
45
|
"type": "string",
|
|
@@ -64,6 +62,10 @@
|
|
|
64
62
|
"type": "string",
|
|
65
63
|
"description": "The name of the e2e project.",
|
|
66
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."
|
|
67
69
|
}
|
|
68
70
|
},
|
|
69
71
|
"required": ["directory", "name", "project"]
|
|
@@ -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' | '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,8 +1,13 @@
|
|
|
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) {
|
|
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']);
|
|
6
11
|
if (!schema.directory) {
|
|
7
12
|
throw new Error(`Please provide the --directory option. It should be the directory containing the project '${schema.project}'.`);
|
|
8
13
|
}
|
|
@@ -11,11 +16,23 @@ async function normalizeSchema(host, schema) {
|
|
|
11
16
|
projectType: 'library',
|
|
12
17
|
directory: schema.directory,
|
|
13
18
|
});
|
|
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
|
|
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,19 +4,22 @@ 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");
|
|
12
|
+
const generator_prompts_1 = require("@nx/js/src/utils/generator-prompts");
|
|
13
|
+
const package_manager_workspaces_1 = require("@nx/js/src/utils/package-manager-workspaces");
|
|
11
14
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
12
|
-
const eslint_1 = require("@nx/eslint");
|
|
13
15
|
const path_1 = require("path");
|
|
14
16
|
async function normalizeOptions(host, options) {
|
|
17
|
+
const linter = await (0, generator_prompts_1.normalizeLinterOption)(host, options.linter);
|
|
15
18
|
const projectName = options.rootProject ? 'e2e' : `${options.pluginName}-e2e`;
|
|
16
19
|
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
17
|
-
const addPlugin =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const addPlugin = options.addPlugin ??
|
|
21
|
+
(process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
22
|
+
nxJson.useInferencePlugins !== false);
|
|
20
23
|
let projectRoot;
|
|
21
24
|
const projectNameAndRootOptions = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
22
25
|
name: projectName,
|
|
@@ -27,12 +30,16 @@ async function normalizeOptions(host, options) {
|
|
|
27
30
|
});
|
|
28
31
|
projectRoot = projectNameAndRootOptions.projectRoot;
|
|
29
32
|
const pluginPropertyName = (0, devkit_1.names)(options.pluginName).propertyName;
|
|
33
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
30
34
|
return {
|
|
31
35
|
...options,
|
|
32
36
|
projectName,
|
|
33
|
-
linter
|
|
37
|
+
linter,
|
|
34
38
|
pluginPropertyName,
|
|
35
39
|
projectRoot,
|
|
40
|
+
addPlugin,
|
|
41
|
+
useProjectJson: options.useProjectJson ?? !isTsSolutionSetup,
|
|
42
|
+
isTsSolutionSetup,
|
|
36
43
|
};
|
|
37
44
|
}
|
|
38
45
|
function validatePlugin(host, pluginName) {
|
|
@@ -55,13 +62,25 @@ function addFiles(host, options) {
|
|
|
55
62
|
});
|
|
56
63
|
}
|
|
57
64
|
async function addJest(host, options) {
|
|
58
|
-
|
|
65
|
+
const projectConfiguration = {
|
|
66
|
+
name: options.projectName,
|
|
59
67
|
root: options.projectRoot,
|
|
60
68
|
projectType: 'application',
|
|
61
69
|
sourceRoot: `${options.projectRoot}/src`,
|
|
62
|
-
targets: {},
|
|
63
70
|
implicitDependencies: [options.pluginName],
|
|
64
|
-
}
|
|
71
|
+
};
|
|
72
|
+
if (options.isTsSolutionSetup) {
|
|
73
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), {
|
|
74
|
+
name: (0, project_name_and_root_utils_1.resolveImportPath)(host, options.projectName, options.projectRoot),
|
|
75
|
+
version: '0.0.1',
|
|
76
|
+
private: true,
|
|
77
|
+
});
|
|
78
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
projectConfiguration.targets = {};
|
|
82
|
+
(0, devkit_1.addProjectConfiguration)(host, options.projectName, projectConfiguration);
|
|
83
|
+
}
|
|
65
84
|
const jestTask = await (0, jest_1.configurationGenerator)(host, {
|
|
66
85
|
project: options.projectName,
|
|
67
86
|
targetName: 'e2e',
|
|
@@ -75,6 +94,7 @@ async function addJest(host, options) {
|
|
|
75
94
|
(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));
|
|
76
95
|
(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));
|
|
77
96
|
const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
97
|
+
project.targets ??= {};
|
|
78
98
|
const e2eTarget = project.targets.e2e;
|
|
79
99
|
project.targets.e2e = {
|
|
80
100
|
...e2eTarget,
|
|
@@ -101,14 +121,22 @@ async function addLintingToApplication(tree, options) {
|
|
|
101
121
|
});
|
|
102
122
|
return lintTask;
|
|
103
123
|
}
|
|
124
|
+
function updatePluginPackageJson(tree, options) {
|
|
125
|
+
const { root } = (0, devkit_1.readProjectConfiguration)(tree, options.pluginName);
|
|
126
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(root, 'package.json'), (json) => {
|
|
127
|
+
// to publish the plugin, we need to remove the private flag
|
|
128
|
+
delete json.private;
|
|
129
|
+
return json;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
104
132
|
async function e2eProjectGenerator(host, schema) {
|
|
105
133
|
return await e2eProjectGeneratorInternal(host, {
|
|
106
134
|
addPlugin: false,
|
|
135
|
+
useProjectJson: true,
|
|
107
136
|
...schema,
|
|
108
137
|
});
|
|
109
138
|
}
|
|
110
139
|
async function e2eProjectGeneratorInternal(host, schema) {
|
|
111
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'plugin', 'e2e-project');
|
|
112
140
|
const tasks = [];
|
|
113
141
|
validatePlugin(host, schema.pluginName);
|
|
114
142
|
const options = await normalizeOptions(host, schema);
|
|
@@ -117,14 +145,33 @@ async function e2eProjectGeneratorInternal(host, schema) {
|
|
|
117
145
|
skipFormat: true,
|
|
118
146
|
}));
|
|
119
147
|
tasks.push(await addJest(host, options));
|
|
120
|
-
|
|
148
|
+
updatePluginPackageJson(host, options);
|
|
149
|
+
if (options.linter !== 'none') {
|
|
121
150
|
tasks.push(await addLintingToApplication(host, {
|
|
122
151
|
...options,
|
|
123
152
|
}));
|
|
124
153
|
}
|
|
154
|
+
if (options.isTsSolutionSetup && !options.rootProject) {
|
|
155
|
+
// update root tsconfig.json references with the new lib tsconfig
|
|
156
|
+
(0, devkit_1.updateJson)(host, 'tsconfig.json', (json) => {
|
|
157
|
+
json.references ??= [];
|
|
158
|
+
json.references.push({
|
|
159
|
+
path: options.projectRoot.startsWith('./')
|
|
160
|
+
? options.projectRoot
|
|
161
|
+
: './' + options.projectRoot,
|
|
162
|
+
});
|
|
163
|
+
return json;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
125
166
|
if (!options.skipFormat) {
|
|
126
167
|
await (0, devkit_1.formatFiles)(host);
|
|
127
168
|
}
|
|
169
|
+
if (options.isTsSolutionSetup && !options.skipWorkspacesWarning) {
|
|
170
|
+
const projectPackageManagerWorkspaceState = (0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceState)(host, options.projectRoot);
|
|
171
|
+
if (projectPackageManagerWorkspaceState !== 'included') {
|
|
172
|
+
tasks.push((0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceStateWarningTask)(projectPackageManagerWorkspaceState, host.root));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
128
175
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
129
176
|
}
|
|
130
177
|
exports.default = e2eProjectGenerator;
|
|
@@ -33,8 +33,7 @@
|
|
|
33
33
|
"linter": {
|
|
34
34
|
"description": "The tool to use for running lint checks.",
|
|
35
35
|
"type": "string",
|
|
36
|
-
"enum": ["
|
|
37
|
-
"default": "eslint"
|
|
36
|
+
"enum": ["none", "eslint"]
|
|
38
37
|
},
|
|
39
38
|
"minimal": {
|
|
40
39
|
"type": "boolean",
|
|
@@ -46,6 +45,10 @@
|
|
|
46
45
|
"type": "boolean",
|
|
47
46
|
"default": false,
|
|
48
47
|
"x-priority": "internal"
|
|
48
|
+
},
|
|
49
|
+
"useProjectJson": {
|
|
50
|
+
"type": "boolean",
|
|
51
|
+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
|
|
49
52
|
}
|
|
50
53
|
},
|
|
51
54
|
"required": ["pluginName", "npmPackageName"]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
2
|
import type { Schema } from './schema';
|
|
3
3
|
export declare function createExecutorsJson(host: Tree, projectRoot: string, projectName: string, skipLintChecks?: boolean): Promise<void>;
|
|
4
4
|
export declare function executorGenerator(host: Tree, schema: Schema): Promise<void>;
|
|
@@ -3,25 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createExecutorsJson = createExecutorsJson;
|
|
4
4
|
exports.executorGenerator = executorGenerator;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const generator_1 = require("../lint-checks/generator");
|
|
8
|
-
const versions_1 = require("../../utils/versions");
|
|
9
6
|
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
10
8
|
const path_1 = require("path");
|
|
9
|
+
const paths_1 = require("../../utils/paths");
|
|
10
|
+
const versions_1 = require("../../utils/versions");
|
|
11
|
+
const generator_1 = require("../lint-checks/generator");
|
|
11
12
|
function addFiles(host, options) {
|
|
12
|
-
(0, devkit_1.generateFiles)(host,
|
|
13
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files/executor'), options.directory, {
|
|
13
14
|
...options,
|
|
14
15
|
});
|
|
15
16
|
if (options.unitTestRunner === 'none') {
|
|
16
|
-
host.delete((0, devkit_1.joinPathFragments)(options.
|
|
17
|
+
host.delete((0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.spec.ts`));
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
function addHasherFiles(host, options) {
|
|
20
|
-
(0, devkit_1.generateFiles)(host,
|
|
21
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files/hasher'), options.directory, {
|
|
21
22
|
...options,
|
|
22
23
|
});
|
|
23
24
|
if (options.unitTestRunner === 'none') {
|
|
24
|
-
host.delete((0, devkit_1.joinPathFragments)(options.
|
|
25
|
+
host.delete((0, devkit_1.joinPathFragments)(options.directory, 'hasher.spec.ts'));
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
async function createExecutorsJson(host, projectRoot, projectName, skipLintChecks) {
|
|
@@ -49,6 +50,14 @@ async function updateExecutorJson(host, options) {
|
|
|
49
50
|
}
|
|
50
51
|
if (!host.exists(executorsPath)) {
|
|
51
52
|
await createExecutorsJson(host, options.projectRoot, options.project, options.skipLintChecks);
|
|
53
|
+
if (options.isTsSolutionSetup) {
|
|
54
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
55
|
+
const filesSet = new Set(json.files ?? ['dist', '!**/*.tsbuildinfo']);
|
|
56
|
+
filesSet.add('executors.json');
|
|
57
|
+
json.files = [...filesSet];
|
|
58
|
+
return json;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
62
|
// add dependencies
|
|
54
63
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
@@ -61,42 +70,45 @@ async function updateExecutorJson(host, options) {
|
|
|
61
70
|
return (0, devkit_1.updateJson)(host, executorsPath, (json) => {
|
|
62
71
|
let executors = json.executors ?? json.builders;
|
|
63
72
|
executors ||= {};
|
|
73
|
+
const dir = (0, paths_1.getArtifactMetadataDirectory)(host, options.project, options.directory, options.isTsSolutionSetup);
|
|
64
74
|
executors[options.name] = {
|
|
65
|
-
implementation:
|
|
66
|
-
schema:
|
|
75
|
+
implementation: `${dir}/${options.fileName}`,
|
|
76
|
+
schema: `${dir}/schema.json`,
|
|
67
77
|
description: options.description,
|
|
68
78
|
};
|
|
69
79
|
if (options.includeHasher) {
|
|
70
|
-
executors[options.name].hasher =
|
|
80
|
+
executors[options.name].hasher = `${dir}/hasher`;
|
|
71
81
|
}
|
|
72
82
|
json.executors = executors;
|
|
73
83
|
return json;
|
|
74
84
|
});
|
|
75
85
|
}
|
|
76
86
|
async function normalizeOptions(tree, options) {
|
|
77
|
-
const {
|
|
78
|
-
name: options.name,
|
|
87
|
+
const { artifactName: name, directory, fileName, project, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
79
88
|
path: options.path,
|
|
80
|
-
|
|
89
|
+
name: options.name,
|
|
81
90
|
});
|
|
82
|
-
const { className, propertyName } = (0, devkit_1.names)(
|
|
83
|
-
const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
91
|
+
const { className, propertyName } = (0, devkit_1.names)(name);
|
|
92
|
+
const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
84
93
|
let description;
|
|
85
94
|
if (options.description) {
|
|
86
95
|
description = options.description;
|
|
87
96
|
}
|
|
88
97
|
else {
|
|
89
|
-
description = `${
|
|
98
|
+
description = `${name} executor`;
|
|
90
99
|
}
|
|
91
100
|
return {
|
|
92
101
|
...options,
|
|
93
|
-
|
|
102
|
+
fileName,
|
|
94
103
|
project,
|
|
95
104
|
directory,
|
|
105
|
+
name,
|
|
96
106
|
className,
|
|
97
107
|
propertyName,
|
|
98
108
|
description,
|
|
99
109
|
projectRoot,
|
|
110
|
+
projectSourceRoot,
|
|
111
|
+
isTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree),
|
|
100
112
|
};
|
|
101
113
|
}
|
|
102
114
|
async function executorGenerator(host, schema) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
|
|
3
3
|
import { <%= className %>ExecutorSchema } from './schema';
|
|
4
|
-
import executor from '
|
|
4
|
+
import executor from './<%= fileName %>';
|
|
5
5
|
|
|
6
6
|
const options: <%= className %>ExecutorSchema = {};
|
|
7
7
|
const context: ExecutorContext = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
2
2
|
import { Tree, readProjectConfiguration } from '@nx/devkit';
|
|
3
3
|
|
|
4
|
-
import { <%= generatorFnName %> } from '
|
|
4
|
+
import { <%= generatorFnName %> } from './<%= fileName %>';
|
|
5
5
|
import { <%= schemaInterfaceName %> } from './schema';
|
|
6
6
|
|
|
7
7
|
describe('<%= name %> generator', () => {
|