nx 19.1.0-beta.0 → 19.1.0-beta.1

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.
@@ -198,7 +198,7 @@ const handleWorkspaceChanges = async (err, changeEvents) => {
198
198
  });
199
199
  return;
200
200
  }
201
- if (err || !changeEvents || !changeEvents.length) {
201
+ if (err) {
202
202
  let error = typeof err === 'string' ? new Error(err) : err;
203
203
  logger_1.serverLogger.watcherLog('Unexpected workspace watcher error', error.message);
204
204
  console.error(error);
@@ -30,7 +30,8 @@ exports.readJson = readJson;
30
30
  * @param options Optional JSON Serialize Options
31
31
  */
32
32
  function writeJson(tree, path, value, options) {
33
- tree.write(path, (0, json_1.serializeJson)(value, options));
33
+ const serialized = (0, json_1.serializeJson)(value, options);
34
+ tree.write(path, `${serialized}\n`);
34
35
  }
35
36
  exports.writeJson = writeJson;
36
37
  /**
@@ -175,7 +175,16 @@ function findTarget(sourcePath, keyMap, targetName, versionRange) {
175
175
  const searchPath = `${sourcePath}node_modules/${targetName}`;
176
176
  if (keyMap.has(searchPath)) {
177
177
  const child = keyMap.get(searchPath);
178
- if (child.data.version === versionRange ||
178
+ // if the version is alias to another package we need to parse the versions to compare
179
+ if (child.data.version.startsWith('npm:') &&
180
+ versionRange.startsWith('npm:')) {
181
+ const nodeVersion = child.data.version.slice(child.data.version.indexOf('@', 5) + 1);
182
+ const depVersion = versionRange.slice(versionRange.indexOf('@', 5) + 1);
183
+ if (nodeVersion === depVersion || (0, semver_1.satisfies)(nodeVersion, depVersion)) {
184
+ return child;
185
+ }
186
+ }
187
+ else if (child.data.version === versionRange ||
179
188
  (0, semver_1.satisfies)(child.data.version, versionRange)) {
180
189
  return child;
181
190
  }
@@ -16,7 +16,7 @@ function loadPnpmHoistedDepsDefinition() {
16
16
  const fullPath = `${workspace_root_1.workspaceRoot}/node_modules/.modules.yaml`;
17
17
  if ((0, fs_1.existsSync)(fullPath)) {
18
18
  const content = (0, fs_1.readFileSync)(fullPath, 'utf-8');
19
- const { load } = require('@zkochan/js-yaml');
19
+ const { load } = require('js-yaml');
20
20
  return load(content)?.hoistedDependencies ?? {};
21
21
  }
22
22
  else {
@@ -32,7 +32,7 @@ exports.loadPnpmHoistedDepsDefinition = loadPnpmHoistedDepsDefinition;
32
32
  * https://github.com/pnpm/pnpm/blob/af3e5559d377870d4c3d303429b3ed1a4e64fedc/lockfile/lockfile-file/src/read.ts#L91
33
33
  */
34
34
  function parseAndNormalizePnpmLockfile(content) {
35
- const { load } = require('@zkochan/js-yaml');
35
+ const { load } = require('js-yaml');
36
36
  const lockFileData = load(content);
37
37
  return revertFromInlineSpecifiersFormatIfNecessary(convertFromLockfileFileMutable(lockFileData));
38
38
  }
@@ -77,7 +77,7 @@ function stringifyToPnpmYaml(lockfile) {
77
77
  const adaptedLockfile = isLockfileV6
78
78
  ? convertToInlineSpecifiersFormat(lockfile)
79
79
  : lockfile;
80
- const { dump } = require('@zkochan/js-yaml');
80
+ const { dump } = require('js-yaml');
81
81
  return dump(sortLockfileKeys(normalizeLockfile(adaptedLockfile, isLockfileV6)), LOCKFILE_YAML_FORMAT);
82
82
  }
83
83
  exports.stringifyToPnpmYaml = stringifyToPnpmYaml;
@@ -13,6 +13,11 @@ export default TargetDefaultsPlugin;
13
13
  */
14
14
  export declare function getTargetInfo(target: string, projectJsonTargets: Record<string, TargetConfiguration>, packageJsonTargets: Record<string, TargetConfiguration>): {
15
15
  command: string;
16
+ metadata: {
17
+ [x: string]: any;
18
+ description?: string;
19
+ technologies?: string[];
20
+ };
16
21
  executor?: undefined;
17
22
  options?: undefined;
18
23
  } | {
@@ -22,6 +27,11 @@ export declare function getTargetInfo(target: string, projectJsonTargets: Record
22
27
  commands?: undefined;
23
28
  script?: undefined;
24
29
  };
30
+ metadata: {
31
+ [x: string]: any;
32
+ description?: string;
33
+ technologies?: string[];
34
+ };
25
35
  command?: undefined;
26
36
  } | {
27
37
  executor: string;
@@ -30,9 +40,19 @@ export declare function getTargetInfo(target: string, projectJsonTargets: Record
30
40
  command?: undefined;
31
41
  script?: undefined;
32
42
  };
43
+ metadata: {
44
+ [x: string]: any;
45
+ description?: string;
46
+ technologies?: string[];
47
+ };
33
48
  command?: undefined;
34
49
  } | {
35
50
  executor: string;
51
+ metadata: {
52
+ [x: string]: any;
53
+ description?: string;
54
+ technologies?: string[];
55
+ };
36
56
  command?: undefined;
37
57
  options?: undefined;
38
58
  } | {
@@ -42,9 +62,20 @@ export declare function getTargetInfo(target: string, projectJsonTargets: Record
42
62
  command?: undefined;
43
63
  commands?: undefined;
44
64
  };
65
+ metadata: {
66
+ [x: string]: any;
67
+ description?: string;
68
+ technologies?: string[];
69
+ };
45
70
  command?: undefined;
71
+ } | {
72
+ executor: string;
73
+ command?: undefined;
74
+ metadata?: undefined;
75
+ options?: undefined;
46
76
  } | {
47
77
  command?: undefined;
78
+ metadata?: undefined;
48
79
  executor?: undefined;
49
80
  options?: undefined;
50
81
  };
@@ -111,9 +111,14 @@ function getTargetInfo(target, projectJsonTargets, packageJsonTargets) {
111
111
  ...packageJsonTarget?.options,
112
112
  ...projectJsonTarget?.options,
113
113
  };
114
+ const metadata = {
115
+ ...packageJsonTarget?.metadata,
116
+ ...projectJsonTarget?.metadata,
117
+ };
114
118
  if (projectJsonTarget?.command) {
115
119
  return {
116
120
  command: projectJsonTarget?.command,
121
+ metadata,
117
122
  };
118
123
  }
119
124
  if (executor === 'nx:run-commands') {
@@ -123,6 +128,7 @@ function getTargetInfo(target, projectJsonTargets, packageJsonTargets) {
123
128
  options: {
124
129
  command: targetOptions?.command,
125
130
  },
131
+ metadata,
126
132
  };
127
133
  }
128
134
  else if (targetOptions?.commands) {
@@ -131,10 +137,12 @@ function getTargetInfo(target, projectJsonTargets, packageJsonTargets) {
131
137
  options: {
132
138
  commands: targetOptions.commands,
133
139
  },
140
+ metadata,
134
141
  };
135
142
  }
136
143
  return {
137
144
  executor: 'nx:run-commands',
145
+ metadata,
138
146
  };
139
147
  }
140
148
  if (executor === 'nx:run-script') {
@@ -143,6 +151,7 @@ function getTargetInfo(target, projectJsonTargets, packageJsonTargets) {
143
151
  options: {
144
152
  script: targetOptions?.script ?? target,
145
153
  },
154
+ metadata,
146
155
  };
147
156
  }
148
157
  if (executor) {
@@ -22,15 +22,6 @@ function findMatchingProjects(patterns = [], projects) {
22
22
  }
23
23
  const projectNames = Object.keys(projects);
24
24
  const matchedProjects = new Set();
25
- // If the first pattern is an exclude pattern,
26
- // we add a wildcard pattern at the first to select
27
- // all projects, except the ones that match the exclude pattern.
28
- // e.g. ['!tag:someTag', 'project2'] will match all projects except
29
- // the ones with the tag 'someTag', and also match the project 'project2',
30
- // regardless of its tags.
31
- if (isExcludePattern(patterns[0])) {
32
- patterns.unshift('*');
33
- }
34
25
  for (const stringPattern of patterns) {
35
26
  if (!stringPattern.length) {
36
27
  continue;
@@ -148,11 +139,8 @@ function addMatchingProjectsByTag(projectNames, projects, pattern, matchedProjec
148
139
  }
149
140
  }
150
141
  }
151
- function isExcludePattern(pattern) {
152
- return pattern.startsWith('!');
153
- }
154
142
  function parseStringPattern(pattern, projects) {
155
- const isExclude = isExcludePattern(pattern);
143
+ const isExclude = pattern.startsWith('!');
156
144
  // Support for things like: `!{type}:value`
157
145
  if (isExclude) {
158
146
  pattern = pattern.substring(1);
package/src/utils/json.js CHANGED
@@ -57,6 +57,6 @@ function formatParseError(input, parseError) {
57
57
  * @returns the formatted JSON representation of the object
58
58
  */
59
59
  function serializeJson(input, options) {
60
- return JSON.stringify(input, null, options?.spaces ?? 2) + '\n';
60
+ return JSON.stringify(input, null, options?.spaces ?? 2);
61
61
  }
62
62
  exports.serializeJson = serializeJson;
@@ -65,7 +65,7 @@ export declare function normalizePackageGroup(packageGroup: PackageGroup): Array
65
65
  export declare function readNxMigrateConfig(json: Partial<PackageJson>): NxMigrationsConfiguration & {
66
66
  packageGroup?: ArrayPackageGroup;
67
67
  };
68
- export declare function buildTargetFromScript(script: string): TargetConfiguration;
68
+ export declare function buildTargetFromScript(script: string, scripts?: Record<string, string>): TargetConfiguration;
69
69
  export declare function readTargetsFromPackageJson(packageJson: PackageJson): Record<string, TargetConfiguration<any>>;
70
70
  /**
71
71
  * Uses `require.resolve` to read the package.json for a module.
@@ -6,6 +6,7 @@ const path_1 = require("path");
6
6
  const project_configuration_utils_1 = require("../project-graph/utils/project-configuration-utils");
7
7
  const fileutils_1 = require("./fileutils");
8
8
  const installation_directory_1 = require("./installation-directory");
9
+ const package_manager_1 = require("./package-manager");
9
10
  function normalizePackageGroup(packageGroup) {
10
11
  return Array.isArray(packageGroup)
11
12
  ? packageGroup.map((x) => typeof x === 'string' ? { package: x, version: '*' } : x)
@@ -38,12 +39,17 @@ function readNxMigrateConfig(json) {
38
39
  };
39
40
  }
40
41
  exports.readNxMigrateConfig = readNxMigrateConfig;
41
- function buildTargetFromScript(script) {
42
+ function buildTargetFromScript(script, scripts = {}) {
43
+ const packageManagerCommand = (0, package_manager_1.getPackageManagerCommand)();
42
44
  return {
43
45
  executor: 'nx:run-script',
44
46
  options: {
45
47
  script,
46
48
  },
49
+ metadata: {
50
+ scriptContent: scripts[script],
51
+ runCommand: packageManagerCommand.run(script),
52
+ },
47
53
  };
48
54
  }
49
55
  exports.buildTargetFromScript = buildTargetFromScript;
@@ -53,7 +59,7 @@ function readTargetsFromPackageJson(packageJson) {
53
59
  const includedScripts = nx?.includedScripts || Object.keys(scripts ?? {});
54
60
  //
55
61
  for (const script of includedScripts) {
56
- res[script] = buildTargetFromScript(script);
62
+ res[script] = buildTargetFromScript(script, scripts);
57
63
  }
58
64
  for (const targetName in nx?.targets) {
59
65
  res[targetName] = (0, project_configuration_utils_1.mergeTargetConfigurations)(nx?.targets[targetName], res[targetName]);
@@ -10,7 +10,7 @@ export interface PackageManagerCommands {
10
10
  exec: string;
11
11
  dlx: string;
12
12
  list: string;
13
- run: (script: string, args: string) => string;
13
+ run: (script: string, args?: string) => string;
14
14
  getRegistryUrl: string;
15
15
  }
16
16
  /**
@@ -74,7 +74,7 @@ function getPackageManagerCommand(packageManager = detectPackageManager(), root
74
74
  rm: 'yarn remove',
75
75
  exec: 'yarn',
76
76
  dlx: useBerry ? 'yarn dlx' : 'yarn',
77
- run: (script, args) => `yarn ${script} ${args}`,
77
+ run: (script, args) => `yarn ${script}${args ? ` ${args}` : ''}`,
78
78
  list: useBerry ? 'yarn info --name-only' : 'yarn list',
79
79
  getRegistryUrl: useBerry
80
80
  ? 'yarn config get npmRegistryServer'
@@ -95,9 +95,11 @@ function getPackageManagerCommand(packageManager = detectPackageManager(), root
95
95
  rm: 'pnpm rm',
96
96
  exec: modernPnpm ? 'pnpm exec' : 'pnpx',
97
97
  dlx: modernPnpm ? 'pnpm dlx' : 'pnpx',
98
- run: (script, args) => includeDoubleDashBeforeArgs
99
- ? `pnpm run ${script} -- ${args}`
100
- : `pnpm run ${script} ${args}`,
98
+ run: (script, args) => `pnpm run ${script}${args
99
+ ? includeDoubleDashBeforeArgs
100
+ ? ' -- ' + args
101
+ : ` ${args}`
102
+ : ''}`,
101
103
  list: 'pnpm ls --depth 100',
102
104
  getRegistryUrl: 'pnpm config get registry',
103
105
  };
@@ -114,7 +116,7 @@ function getPackageManagerCommand(packageManager = detectPackageManager(), root
114
116
  rm: 'npm rm',
115
117
  exec: 'npx',
116
118
  dlx: 'npx',
117
- run: (script, args) => `npm run ${script} -- ${args}`,
119
+ run: (script, args) => `npm run ${script}${args ? ' -- ' + args : ''}`,
118
120
  list: 'npm ls',
119
121
  getRegistryUrl: 'npm config get registry',
120
122
  };
@@ -254,11 +256,20 @@ async function resolvePackageVersionUsingRegistry(packageName, version) {
254
256
  if (!result) {
255
257
  throw new Error(`Unable to resolve version ${packageName}@${version}.`);
256
258
  }
257
- // get the last line of the output, strip the package version and quotes
258
- const resolvedVersion = result
259
- .split('\n')
260
- .pop()
261
- .split(' ')
259
+ const lines = result.split('\n');
260
+ if (lines.length === 1) {
261
+ return lines[0];
262
+ }
263
+ /**
264
+ * The output contains multiple lines ordered by release date, so the last
265
+ * version might not be the last one in the list. We need to sort it. Each
266
+ * line looks like:
267
+ *
268
+ * <package>@<version> '<version>'
269
+ */
270
+ const resolvedVersion = lines
271
+ .map((line) => line.split(' ')[1])
272
+ .sort()
262
273
  .pop()
263
274
  .replace(/'/g, '');
264
275
  return resolvedVersion;
@@ -114,7 +114,7 @@ async function listPluginCapabilities(pluginName, projects) {
114
114
  if (hasBuilders) {
115
115
  bodyLines.push(chalk.bold(chalk.green('EXECUTORS/BUILDERS')));
116
116
  bodyLines.push('');
117
- bodyLines.push(...Object.keys(plugin.executors).map((name) => `${chalk.bold(name)} : ${plugin.executors[name].description}`));
117
+ bodyLines.push(...Object.keys(plugin.executors).map((name) => `${chalk.bold(name)} : ${resolveExecutorDescription(plugin.executors[name], projects)}`));
118
118
  }
119
119
  if (hasProjectGraphExtension) {
120
120
  bodyLines.push(`✔️ Project Graph Extension`);
@@ -128,3 +128,26 @@ async function listPluginCapabilities(pluginName, projects) {
128
128
  });
129
129
  }
130
130
  exports.listPluginCapabilities = listPluginCapabilities;
131
+ function resolveExecutorDescription(executorJsonEntry, projects) {
132
+ try {
133
+ if (typeof executorJsonEntry === 'string') {
134
+ // it points to another executor, resolve it
135
+ const [pkgName, executor] = executorJsonEntry.split(':');
136
+ const collection = loadExecutorsCollection(workspace_root_1.workspaceRoot, pkgName, projects);
137
+ return resolveExecutorDescription(collection[executor], projects);
138
+ }
139
+ return executorJsonEntry.description;
140
+ }
141
+ catch {
142
+ return 'No description available';
143
+ }
144
+ }
145
+ function loadExecutorsCollection(workspaceRoot, pluginName, projects) {
146
+ const { json: packageJson, path: packageJsonPath } = (0, plugins_1.readPluginPackageJson)(pluginName, projects, (0, installation_directory_1.getNxRequirePaths)(workspaceRoot));
147
+ return {
148
+ ...tryGetCollection(packageJsonPath, packageJson.builders, 'builders'),
149
+ ...tryGetCollection(packageJsonPath, packageJson.executors, 'builders'),
150
+ ...tryGetCollection(packageJsonPath, packageJson.builders, 'executors'),
151
+ ...tryGetCollection(packageJsonPath, packageJson.executors, 'executors'),
152
+ };
153
+ }