nx 20.4.0-beta.1 → 20.4.0-beta.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "20.4.0-beta.1",
3
+ "version": "20.4.0-beta.2",
4
4
  "private": false,
5
5
  "description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
6
6
  "repository": {
@@ -82,16 +82,16 @@
82
82
  }
83
83
  },
84
84
  "optionalDependencies": {
85
- "@nx/nx-darwin-arm64": "20.4.0-beta.1",
86
- "@nx/nx-darwin-x64": "20.4.0-beta.1",
87
- "@nx/nx-freebsd-x64": "20.4.0-beta.1",
88
- "@nx/nx-linux-arm-gnueabihf": "20.4.0-beta.1",
89
- "@nx/nx-linux-arm64-gnu": "20.4.0-beta.1",
90
- "@nx/nx-linux-arm64-musl": "20.4.0-beta.1",
91
- "@nx/nx-linux-x64-gnu": "20.4.0-beta.1",
92
- "@nx/nx-linux-x64-musl": "20.4.0-beta.1",
93
- "@nx/nx-win32-arm64-msvc": "20.4.0-beta.1",
94
- "@nx/nx-win32-x64-msvc": "20.4.0-beta.1"
85
+ "@nx/nx-darwin-arm64": "20.4.0-beta.2",
86
+ "@nx/nx-darwin-x64": "20.4.0-beta.2",
87
+ "@nx/nx-freebsd-x64": "20.4.0-beta.2",
88
+ "@nx/nx-linux-arm-gnueabihf": "20.4.0-beta.2",
89
+ "@nx/nx-linux-arm64-gnu": "20.4.0-beta.2",
90
+ "@nx/nx-linux-arm64-musl": "20.4.0-beta.2",
91
+ "@nx/nx-linux-x64-gnu": "20.4.0-beta.2",
92
+ "@nx/nx-linux-x64-musl": "20.4.0-beta.2",
93
+ "@nx/nx-win32-arm64-msvc": "20.4.0-beta.2",
94
+ "@nx/nx-win32-x64-msvc": "20.4.0-beta.2"
95
95
  },
96
96
  "nx-migrations": {
97
97
  "migrations": "./migrations.json",
@@ -21,6 +21,7 @@ const prepare_source_repo_1 = require("./utils/prepare-source-repo");
21
21
  const merge_remote_source_1 = require("./utils/merge-remote-source");
22
22
  const minimatch_1 = require("minimatch");
23
23
  const configure_plugins_1 = require("../init/configure-plugins");
24
+ const check_compatible_with_plugins_1 = require("../init/implementation/check-compatible-with-plugins");
24
25
  const importRemoteName = '__tmp_nx_import__';
25
26
  async function importHandler(options) {
26
27
  process.env.NX_RUNNING_NX_IMPORT = 'true';
@@ -165,14 +166,24 @@ async function importHandler(options) {
165
166
  }
166
167
  await handleMissingWorkspacesEntry(packageManager, pmc, relativeDestination, destinationGitClient);
167
168
  let installed = await runInstallDestinationRepo(packageManager, destinationGitClient);
168
- if (installed && plugins.length > 0) {
169
- installed = await runPluginsInstall(plugins, pmc, destinationGitClient);
170
- if (installed) {
171
- const { succeededPlugins } = await (0, configure_plugins_1.configurePlugins)(plugins, updatePackageScripts, pmc, workspace_root_1.workspaceRoot, verbose);
172
- if (succeededPlugins.length > 0) {
169
+ if (installed) {
170
+ // Check compatibility with existing plugins for the workspace included new imported projects
171
+ if (nxJson.plugins?.length > 0) {
172
+ const incompatiblePlugins = await (0, check_compatible_with_plugins_1.checkCompatibleWithPlugins)();
173
+ if (Object.keys(incompatiblePlugins).length > 0) {
174
+ (0, check_compatible_with_plugins_1.updatePluginsInNxJson)(workspace_root_1.workspaceRoot, incompatiblePlugins);
173
175
  await destinationGitClient.amendCommit();
174
176
  }
175
177
  }
178
+ if (plugins.length > 0) {
179
+ installed = await runPluginsInstall(plugins, pmc, destinationGitClient);
180
+ if (installed) {
181
+ const { succeededPlugins } = await (0, configure_plugins_1.configurePlugins)(plugins, updatePackageScripts, pmc, workspace_root_1.workspaceRoot, verbose);
182
+ if (succeededPlugins.length > 0) {
183
+ await destinationGitClient.amendCommit();
184
+ }
185
+ }
186
+ }
176
187
  }
177
188
  console.log(await destinationGitClient.showStat());
178
189
  if (installed === false) {
@@ -183,6 +194,22 @@ async function importHandler(options) {
183
194
  `You may need to run "${pmc.install}" manually to resolve the issue. The error is logged above.`,
184
195
  ],
185
196
  });
197
+ if (plugins.length > 0) {
198
+ output_1.output.error({
199
+ title: `Failed to install plugins`,
200
+ bodyLines: [
201
+ 'The following plugins were not installed:',
202
+ ...plugins.map((p) => `- ${chalk.bold(p)}`),
203
+ ],
204
+ });
205
+ output_1.output.error({
206
+ title: `To install the plugins manually`,
207
+ bodyLines: [
208
+ 'You may need to run commands to install the plugins:',
209
+ ...plugins.map((p) => `- ${chalk.bold(pmc.exec + ' nx add ' + p)}`),
210
+ ],
211
+ });
212
+ }
186
213
  }
187
214
  if (source != destination) {
188
215
  output_1.output.warn({
@@ -0,0 +1,15 @@
1
+ export interface IncompatibleFiles {
2
+ [pluginIndex: number]: {
3
+ file: string;
4
+ error?: any;
5
+ }[];
6
+ }
7
+ /**
8
+ * This function checks if the imported project is compatible with the plugins.
9
+ * @returns a map of plugin names to files that are incompatible with the plugins
10
+ */
11
+ export declare function checkCompatibleWithPlugins(): Promise<IncompatibleFiles>;
12
+ /**
13
+ * This function updates the plugins in the nx.json file with the given plugin names and files to exclude.
14
+ */
15
+ export declare function updatePluginsInNxJson(root: string, pluginToExcludeFiles: IncompatibleFiles): void;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkCompatibleWithPlugins = checkCompatibleWithPlugins;
4
+ exports.updatePluginsInNxJson = updatePluginsInNxJson;
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const chalk_1 = require("chalk");
8
+ const error_types_1 = require("../../../project-graph/error-types");
9
+ const workspace_root_1 = require("../../../utils/workspace-root");
10
+ const fileutils_1 = require("../../../utils/fileutils");
11
+ const output_1 = require("../../../utils/output");
12
+ const project_graph_1 = require("../../../project-graph/project-graph");
13
+ /**
14
+ * This function checks if the imported project is compatible with the plugins.
15
+ * @returns a map of plugin names to files that are incompatible with the plugins
16
+ */
17
+ async function checkCompatibleWithPlugins() {
18
+ let pluginToExcludeFiles = {};
19
+ try {
20
+ await (0, project_graph_1.createProjectGraphAsync)();
21
+ }
22
+ catch (projectGraphError) {
23
+ if (projectGraphError instanceof error_types_1.ProjectGraphError) {
24
+ projectGraphError.getErrors()?.forEach((error) => {
25
+ const { pluginIndex, excludeFiles } = findPluginAndFilesWithError(error) ?? {};
26
+ if (pluginIndex !== undefined && excludeFiles?.length) {
27
+ pluginToExcludeFiles[pluginIndex] ??= [];
28
+ pluginToExcludeFiles[pluginIndex].push(...excludeFiles);
29
+ }
30
+ else if (!(0, error_types_1.isProjectsWithNoNameError)(error)) {
31
+ // print error if it is not ProjectsWithNoNameError and unable to exclude files
32
+ output_1.output.error({
33
+ title: error.message,
34
+ bodyLines: error.stack?.split('\n'),
35
+ });
36
+ }
37
+ });
38
+ }
39
+ else {
40
+ output_1.output.error({
41
+ title: 'Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.',
42
+ bodyLines: projectGraphError.stack?.split('\n'),
43
+ });
44
+ }
45
+ }
46
+ return pluginToExcludeFiles;
47
+ }
48
+ /**
49
+ * This function finds the plugin name and files that caused the error.
50
+ * @param error the error to find the plugin name and files for
51
+ * @returns pluginName and excludeFiles if found, otherwise undefined
52
+ */
53
+ function findPluginAndFilesWithError(error) {
54
+ let pluginIndex;
55
+ let excludeFiles = [];
56
+ if ((0, error_types_1.isAggregateCreateNodesError)(error)) {
57
+ pluginIndex = error.pluginIndex;
58
+ excludeFiles =
59
+ error.errors?.map((error) => {
60
+ return {
61
+ file: error?.[0],
62
+ error: error?.[1],
63
+ };
64
+ }) ?? [];
65
+ }
66
+ else if ((0, error_types_1.isMergeNodesError)(error)) {
67
+ pluginIndex = error.pluginIndex;
68
+ excludeFiles = [
69
+ {
70
+ file: error.file,
71
+ error: error,
72
+ },
73
+ ];
74
+ }
75
+ excludeFiles = excludeFiles.filter(Boolean);
76
+ return {
77
+ pluginIndex,
78
+ excludeFiles,
79
+ };
80
+ }
81
+ /**
82
+ * This function updates the plugins in the nx.json file with the given plugin names and files to exclude.
83
+ */
84
+ function updatePluginsInNxJson(root = workspace_root_1.workspaceRoot, pluginToExcludeFiles) {
85
+ const nxJsonPath = (0, node_path_1.join)(root, 'nx.json');
86
+ if (!(0, node_fs_1.existsSync)(nxJsonPath)) {
87
+ return;
88
+ }
89
+ let nxJson;
90
+ try {
91
+ nxJson = (0, fileutils_1.readJsonFile)(nxJsonPath);
92
+ }
93
+ catch {
94
+ // If there is an error reading the nx.json file, no need to update it
95
+ return;
96
+ }
97
+ if (!Object.keys(pluginToExcludeFiles)?.length || !nxJson?.plugins?.length) {
98
+ return;
99
+ }
100
+ Object.entries(pluginToExcludeFiles).forEach(([pluginIndex, excludeFiles]) => {
101
+ let plugin = nxJson.plugins[pluginIndex];
102
+ if (!plugin || excludeFiles.length === 0) {
103
+ return;
104
+ }
105
+ if (typeof plugin === 'string') {
106
+ plugin = { plugin };
107
+ }
108
+ output_1.output.warn({
109
+ title: `The following files were incompatible with ${plugin.plugin} and has been excluded for now:`,
110
+ bodyLines: excludeFiles
111
+ .map((file) => {
112
+ const output = [` - ${(0, chalk_1.bold)(file.file)}`];
113
+ if (file.error?.message) {
114
+ output.push(` ${file.error.message}`);
115
+ }
116
+ return output;
117
+ })
118
+ .flat(),
119
+ });
120
+ const excludes = new Set(plugin.exclude ?? []);
121
+ excludeFiles.forEach((file) => {
122
+ excludes.add(file.file);
123
+ });
124
+ plugin.exclude = Array.from(excludes);
125
+ nxJson.plugins[pluginIndex] = plugin;
126
+ });
127
+ (0, fileutils_1.writeJsonFile)(nxJsonPath, nxJson);
128
+ }
@@ -94,5 +94,12 @@ exports.DEFAULT_CONVENTIONAL_COMMITS_CONFIG = {
94
94
  hidden: true,
95
95
  },
96
96
  },
97
+ __INVALID__: {
98
+ semverBump: 'none',
99
+ changelog: {
100
+ title: 'Invalid based on conventional commits specification',
101
+ hidden: true,
102
+ },
103
+ },
97
104
  },
98
105
  };
@@ -292,7 +292,12 @@ function parseCommits(commits) {
292
292
  function parseConventionalCommitsMessage(message) {
293
293
  const match = message.match(ConventionalCommitRegex);
294
294
  if (!match) {
295
- return null;
295
+ return {
296
+ type: '__INVALID__',
297
+ scope: '',
298
+ description: message,
299
+ breaking: false,
300
+ };
296
301
  }
297
302
  return {
298
303
  type: match.groups.type || '',