nx 19.0.0-canary.20240502-5ded713 → 19.0.0-canary.20240503-dbad02a

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeTarget = exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeMetadata = exports.mergeProjectConfigurationIntoRootMap = void 0;
3
+ exports.normalizeTarget = exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.validateProject = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeMetadata = exports.mergeProjectConfigurationIntoRootMap = void 0;
4
4
  const logger_1 = require("../../utils/logger");
5
5
  const fileutils_1 = require("../../utils/fileutils");
6
6
  const workspace_root_1 = require("../../utils/workspace-root");
@@ -131,7 +131,7 @@ skipTargetNormalization) {
131
131
  }
132
132
  const normalizedTarget = skipTargetNormalization
133
133
  ? target
134
- : normalizeTarget(target, project);
134
+ : resolveCommandSyntacticSugar(target, project.root);
135
135
  const mergedTarget = mergeTargetConfigurations(normalizedTarget, matchingProject.targets?.[targetName], sourceMap, sourceInformation, `targets.${targetName}`);
136
136
  // We don't want the symbol to live on past the merge process
137
137
  if (mergedTarget?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET])
@@ -295,16 +295,11 @@ plugins) {
295
295
  Object.assign(externalNodes, pluginExternalNodes);
296
296
  }
297
297
  try {
298
- // We still call this just to assert that the root map
299
- // only contains valid project names. This is a safety check.
300
- //
301
- // The signature itself can't be changed as we need it to return
302
- // project configurations for use in devkit.
303
- readProjectConfigurationsFromRootMap(projectRootMap);
298
+ validateAndNormalizeProjectRootMap(projectRootMap);
304
299
  }
305
300
  catch (e) {
306
301
  if ((0, error_types_1.isProjectsWithNoNameError)(e) ||
307
- (0, error_types_1.isProjectsWithConflictingNamesError)(e)) {
302
+ (0, error_types_1.isMultipleProjectsWithSameNameError)(e)) {
308
303
  errors.push(e);
309
304
  }
310
305
  else {
@@ -345,34 +340,33 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
345
340
  const conflicts = new Map();
346
341
  const projectRootsWithNoName = [];
347
342
  for (const root in projectRootMap) {
348
- const configuration = projectRootMap[root];
343
+ const project = projectRootMap[root];
349
344
  // We're setting `// targets` as a comment `targets` is empty due to Project Crystal.
350
345
  // Strip it before returning configuration for usage.
351
- if (configuration['// targets'])
352
- delete configuration['// targets'];
353
- if (!configuration.name) {
354
- try {
355
- const { name } = (0, fileutils_1.readJsonFile)((0, path_1.join)(root, 'package.json'));
356
- configuration.name = name;
346
+ if (project['// targets'])
347
+ delete project['// targets'];
348
+ try {
349
+ validateProject(project, projects);
350
+ projects[project.name] = project;
351
+ }
352
+ catch (e) {
353
+ if ((0, error_types_1.isProjectWithNoNameError)(e)) {
354
+ projectRootsWithNoName.push(e.projectRoot);
357
355
  }
358
- catch {
359
- projectRootsWithNoName.push(root);
356
+ else if ((0, error_types_1.isProjectWithExistingNameError)(e)) {
357
+ const rootErrors = conflicts.get(e.projectName) ?? [
358
+ projects[e.projectName].root,
359
+ ];
360
+ rootErrors.push(e.projectRoot);
361
+ conflicts.set(e.projectName, rootErrors);
362
+ }
363
+ else {
364
+ throw e;
360
365
  }
361
- }
362
- if (configuration.name in projects) {
363
- let rootErrors = conflicts.get(configuration.name) ?? [
364
- projects[configuration.name].root,
365
- ];
366
- rootErrors.push(root);
367
- conflicts.set(configuration.name, rootErrors);
368
- projects[configuration.name] = configuration;
369
- }
370
- else {
371
- projects[configuration.name] = configuration;
372
366
  }
373
367
  }
374
368
  if (conflicts.size > 0) {
375
- throw new error_types_1.ProjectsWithConflictingNamesError(conflicts, projects);
369
+ throw new error_types_1.MultipleProjectsWithSameNameError(conflicts, projects);
376
370
  }
377
371
  if (projectRootsWithNoName.length > 0) {
378
372
  throw new error_types_1.ProjectsWithNoNameError(projectRootsWithNoName, projects);
@@ -380,6 +374,76 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
380
374
  return projects;
381
375
  }
382
376
  exports.readProjectConfigurationsFromRootMap = readProjectConfigurationsFromRootMap;
377
+ function validateAndNormalizeProjectRootMap(projectRootMap) {
378
+ // Name -> Project, used to validate that all projects have unique names
379
+ const projects = {};
380
+ // If there are projects that have the same name, that is an error.
381
+ // This object tracks name -> (all roots of projects with that name)
382
+ // to provide better error messaging.
383
+ const conflicts = new Map();
384
+ const projectRootsWithNoName = [];
385
+ for (const root in projectRootMap) {
386
+ const project = projectRootMap[root];
387
+ // We're setting `// targets` as a comment `targets` is empty due to Project Crystal.
388
+ // Strip it before returning configuration for usage.
389
+ if (project['// targets'])
390
+ delete project['// targets'];
391
+ try {
392
+ validateProject(project, projects);
393
+ projects[project.name] = project;
394
+ }
395
+ catch (e) {
396
+ if ((0, error_types_1.isProjectWithNoNameError)(e)) {
397
+ projectRootsWithNoName.push(e.projectRoot);
398
+ }
399
+ else if ((0, error_types_1.isProjectWithExistingNameError)(e)) {
400
+ const rootErrors = conflicts.get(e.projectName) ?? [
401
+ projects[e.projectName].root,
402
+ ];
403
+ rootErrors.push(e.projectRoot);
404
+ conflicts.set(e.projectName, rootErrors);
405
+ }
406
+ else {
407
+ throw e;
408
+ }
409
+ }
410
+ for (const targetName in project.targets) {
411
+ project.targets[targetName] = normalizeTarget(project.targets[targetName], project);
412
+ if (!project.targets[targetName].executor &&
413
+ !project.targets[targetName].command) {
414
+ delete project.targets[targetName];
415
+ }
416
+ }
417
+ }
418
+ if (conflicts.size > 0) {
419
+ throw new error_types_1.MultipleProjectsWithSameNameError(conflicts, projects);
420
+ }
421
+ if (projectRootsWithNoName.length > 0) {
422
+ throw new error_types_1.ProjectsWithNoNameError(projectRootsWithNoName, projects);
423
+ }
424
+ return projectRootMap;
425
+ }
426
+ function validateProject(project,
427
+ // name -> project
428
+ knownProjects) {
429
+ if (!project.name) {
430
+ try {
431
+ const { name } = (0, fileutils_1.readJsonFile)((0, path_1.join)(project.root, 'package.json'));
432
+ if (!name) {
433
+ throw new Error(`Project at ${project.root} has no name provided.`);
434
+ }
435
+ project.name = name;
436
+ }
437
+ catch {
438
+ throw new error_types_1.ProjectWithNoNameError(project.root);
439
+ }
440
+ }
441
+ else if (knownProjects[project.name] &&
442
+ knownProjects[project.name].root !== project.root) {
443
+ throw new error_types_1.ProjectWithExistingNameError(project.name, project.root);
444
+ }
445
+ }
446
+ exports.validateProject = validateProject;
383
447
  /**
384
448
  * Merges two targets.
385
449
  *
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assertWorkspaceValidity = void 0;
4
4
  const find_matching_projects_1 = require("./find-matching-projects");
5
5
  const output_1 = require("./output");
6
+ const devkit_internals_1 = require("../devkit-internals");
6
7
  function assertWorkspaceValidity(projects, nxJson) {
7
8
  const projectNames = Object.keys(projects);
8
9
  const projectGraphNodes = projectNames.reduce((graph, project) => {
@@ -67,7 +68,7 @@ function assertWorkspaceValidity(projects, nxJson) {
67
68
  })
68
69
  .join('\n\n');
69
70
  }
70
- throw new Error(`Configuration Error\n${message}`);
71
+ throw new devkit_internals_1.WorkspaceValidityError(message);
71
72
  }
72
73
  exports.assertWorkspaceValidity = assertWorkspaceValidity;
73
74
  function detectAndSetInvalidProjectGlobValues(map, sourceName, desiredImplicitDeps, projectConfigurations, projects) {