@nx/workspace 19.7.4 → 19.8.0-beta.1

Sign up to get free protection for your applications and to get access to all the features.
package/generators.json CHANGED
@@ -54,6 +54,11 @@
54
54
  "factory": "./src/generators/ci-workflow/ci-workflow#ciWorkflowGenerator",
55
55
  "schema": "./src/generators/ci-workflow/schema.json",
56
56
  "description": "Generate a CI workflow."
57
+ },
58
+ "infer-targets": {
59
+ "factory": "./src/generators/infer-targets/infer-targets",
60
+ "schema": "./src/generators/infer-targets/schema.json",
61
+ "description": "Convert Nx projects to use inferred targets."
57
62
  }
58
63
  }
59
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/workspace",
3
- "version": "19.7.4",
3
+ "version": "19.8.0-beta.1",
4
4
  "private": false,
5
5
  "description": "The Workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.",
6
6
  "repository": {
@@ -61,17 +61,17 @@
61
61
  }
62
62
  },
63
63
  "dependencies": {
64
- "@nx/devkit": "19.7.4",
64
+ "@nx/devkit": "19.8.0-beta.1",
65
65
  "chalk": "^4.1.0",
66
66
  "enquirer": "~2.3.6",
67
67
  "tslib": "^2.3.0",
68
68
  "yargs-parser": "21.1.1",
69
- "nx": "19.7.4",
70
- "@nrwl/workspace": "19.7.4"
69
+ "nx": "19.8.0-beta.1",
70
+ "@nrwl/workspace": "19.8.0-beta.1"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
75
  "type": "commonjs",
76
76
  "types": "./index.d.ts"
77
- }
77
+ }
@@ -28,7 +28,8 @@ pipelines:
28
28
  <% } %>
29
29
  - <%= packageManagerInstall %>
30
30
 
31
- - <%= packageManagerPrefix %> nx-cloud record -- nx format:check
31
+ # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
32
+ # <%= packageManagerPrefix %> nx-cloud record -- echo Hello World
32
33
  # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
33
34
  - <%= packageManagerPrefix %> nx affected --base=origin/<%= mainBranch %> -t lint test build<% if(hasE2E){ %>
34
35
  - <%= packageManagerPrefix %> nx affected --base=origin/<%= mainBranch %> --parallel 1 -t e2e-ci<% } %>
@@ -0,0 +1,8 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ interface Schema {
3
+ project?: string;
4
+ plugins?: string[];
5
+ skipFormat?: boolean;
6
+ }
7
+ export declare function convertToInferredGenerator(tree: Tree, options: Schema): Promise<GeneratorCallback>;
8
+ export default convertToInferredGenerator;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToInferredGenerator = convertToInferredGenerator;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const executor_to_plugin_migrator_1 = require("@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator");
6
+ const enquirer_1 = require("enquirer");
7
+ const generator_utils_1 = require("nx/src/command-line/generate/generator-utils");
8
+ const installed_plugins_1 = require("nx/src/utils/plugins/installed-plugins");
9
+ async function convertToInferredGenerator(tree, options) {
10
+ const generatorCollectionChoices = await getPossibleConvertToInferredGenerators();
11
+ if (generatorCollectionChoices.size === 0) {
12
+ devkit_1.output.error({
13
+ title: 'No inference plugin found. For information on this migration, see https://nx.dev/recipes/running-tasks/convert-to-inferred',
14
+ });
15
+ return;
16
+ }
17
+ let generatorsToRun;
18
+ if (options.plugins && options.plugins.filter((p) => !!p).length > 0) {
19
+ generatorsToRun = Array.from(generatorCollectionChoices.values())
20
+ .filter((generator) => options.plugins.includes(generator.resolvedCollectionName))
21
+ .map((generator) => generator.resolvedCollectionName);
22
+ }
23
+ else if (process.argv.includes('--no-interactive')) {
24
+ generatorsToRun = Array.from(generatorCollectionChoices.keys());
25
+ }
26
+ else {
27
+ const allChoices = Array.from(generatorCollectionChoices.keys());
28
+ generatorsToRun = (await (0, enquirer_1.prompt)({
29
+ type: 'multiselect',
30
+ name: 'generatorsToRun',
31
+ message: 'Which inference plugin do you want to use?',
32
+ choices: allChoices,
33
+ initial: allChoices,
34
+ validate: (result) => {
35
+ if (result.length === 0) {
36
+ return 'Please select at least one plugin.';
37
+ }
38
+ return true;
39
+ },
40
+ })).generatorsToRun;
41
+ }
42
+ if (generatorsToRun.length === 0) {
43
+ devkit_1.output.error({
44
+ title: 'Please select at least one plugin.',
45
+ });
46
+ return;
47
+ }
48
+ const tasks = [];
49
+ for (const generatorCollection of generatorsToRun) {
50
+ try {
51
+ const generator = generatorCollectionChoices.get(generatorCollection);
52
+ if (generator) {
53
+ const generatorFactory = generator.implementationFactory();
54
+ const callback = await generatorFactory(tree, {
55
+ project: options.project,
56
+ skipFormat: options.skipFormat,
57
+ });
58
+ if (callback) {
59
+ const task = await callback();
60
+ if (typeof task === 'function')
61
+ tasks.push(task);
62
+ }
63
+ devkit_1.output.success({
64
+ title: `${generatorCollection}:convert-to-inferred - Success`,
65
+ });
66
+ }
67
+ }
68
+ catch (e) {
69
+ if (e instanceof executor_to_plugin_migrator_1.NoTargetsToMigrateError) {
70
+ devkit_1.output.note({
71
+ title: `${generatorCollection}:convert-to-inferred - Skipped (No targets to migrate)`,
72
+ });
73
+ }
74
+ else {
75
+ devkit_1.output.error({
76
+ title: `${generatorCollection}:convert-to-inferred - Failed`,
77
+ });
78
+ throw e;
79
+ }
80
+ }
81
+ }
82
+ if (!options.skipFormat) {
83
+ await (0, devkit_1.formatFiles)(tree);
84
+ }
85
+ return (0, devkit_1.runTasksInSerial)(...tasks);
86
+ }
87
+ async function getPossibleConvertToInferredGenerators() {
88
+ const installedCollections = Array.from(new Set((0, installed_plugins_1.findInstalledPlugins)().map((x) => x.name)));
89
+ const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
90
+ const projectsConfigurations = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
91
+ const choices = new Map();
92
+ for (const collectionName of installedCollections) {
93
+ try {
94
+ const generator = (0, generator_utils_1.getGeneratorInformation)(collectionName, 'convert-to-inferred', devkit_1.workspaceRoot, projectsConfigurations.projects);
95
+ if (generator.generatorConfiguration.hidden ||
96
+ generator.generatorConfiguration['x-deprecated']) {
97
+ continue;
98
+ }
99
+ choices.set(generator.resolvedCollectionName, generator);
100
+ }
101
+ catch {
102
+ // this just means that no convert-to-inferred generator exists for a given collection, ignore
103
+ }
104
+ }
105
+ return choices;
106
+ }
107
+ exports.default = convertToInferredGenerator;
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "InferTargets",
4
+ "title": "",
5
+ "type": "object",
6
+ "description": "Convert Nx projects to use inferred targets.",
7
+ "properties": {
8
+ "project": {
9
+ "type": "string",
10
+ "description": "The project to convert to use inferred targets.",
11
+ "x-priority": "important"
12
+ },
13
+ "plugins": {
14
+ "type": "array",
15
+ "description": "The plugins used to infer targets. For example @nx/eslint or @nx/jest",
16
+ "items": {
17
+ "type": "string"
18
+ }
19
+ },
20
+ "skipFormat": {
21
+ "type": "boolean",
22
+ "description": "Whether to format files.",
23
+ "default": false
24
+ }
25
+ }
26
+ }