nx 21.3.0-canary.20250627-07233f0 → 21.3.0-canary.20250701-bfdf892

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": "21.3.0-canary.20250627-07233f0",
3
+ "version": "21.3.0-canary.20250701-bfdf892",
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": {
@@ -83,16 +83,16 @@
83
83
  }
84
84
  },
85
85
  "optionalDependencies": {
86
- "@nx/nx-darwin-arm64": "21.3.0-canary.20250627-07233f0",
87
- "@nx/nx-darwin-x64": "21.3.0-canary.20250627-07233f0",
88
- "@nx/nx-freebsd-x64": "21.3.0-canary.20250627-07233f0",
89
- "@nx/nx-linux-arm-gnueabihf": "21.3.0-canary.20250627-07233f0",
90
- "@nx/nx-linux-arm64-gnu": "21.3.0-canary.20250627-07233f0",
91
- "@nx/nx-linux-arm64-musl": "21.3.0-canary.20250627-07233f0",
92
- "@nx/nx-linux-x64-gnu": "21.3.0-canary.20250627-07233f0",
93
- "@nx/nx-linux-x64-musl": "21.3.0-canary.20250627-07233f0",
94
- "@nx/nx-win32-arm64-msvc": "21.3.0-canary.20250627-07233f0",
95
- "@nx/nx-win32-x64-msvc": "21.3.0-canary.20250627-07233f0"
86
+ "@nx/nx-darwin-arm64": "21.3.0-canary.20250701-bfdf892",
87
+ "@nx/nx-darwin-x64": "21.3.0-canary.20250701-bfdf892",
88
+ "@nx/nx-freebsd-x64": "21.3.0-canary.20250701-bfdf892",
89
+ "@nx/nx-linux-arm-gnueabihf": "21.3.0-canary.20250701-bfdf892",
90
+ "@nx/nx-linux-arm64-gnu": "21.3.0-canary.20250701-bfdf892",
91
+ "@nx/nx-linux-arm64-musl": "21.3.0-canary.20250701-bfdf892",
92
+ "@nx/nx-linux-x64-gnu": "21.3.0-canary.20250701-bfdf892",
93
+ "@nx/nx-linux-x64-musl": "21.3.0-canary.20250701-bfdf892",
94
+ "@nx/nx-win32-arm64-msvc": "21.3.0-canary.20250701-bfdf892",
95
+ "@nx/nx-win32-x64-msvc": "21.3.0-canary.20250701-bfdf892"
96
96
  },
97
97
  "nx-migrations": {
98
98
  "migrations": "./migrations.json",
@@ -87,4 +87,15 @@ export declare function wrapAngularDevkitSchematic(collectionName: string, gener
87
87
  [k: string]: any;
88
88
  }) => Promise<GeneratorCallback>;
89
89
  export declare const getLogger: (isVerbose?: boolean) => logging.Logger;
90
+ /**
91
+ * Restores Nx tokens in options when possible by comparing new and previous
92
+ * options.
93
+ * The function preserves tokens in the following cases:
94
+ * 1. When the resolved previous value matches the new value exactly
95
+ * 2. When the previous value used {workspaceRoot}
96
+ * 3. When the previous value used {projectRoot} and the new value starts with
97
+ * the project root path
98
+ * Those are the only safe cases, for all other cases, the new value is used as-is.
99
+ */
100
+ export declare function restoreNxTokensInOptions<T extends Object | Array<unknown>>(newOptions: T, previousOptions: T, project: ProjectConfiguration): T;
90
101
  export {};
@@ -8,6 +8,7 @@ exports.generate = generate;
8
8
  exports.runMigration = runMigration;
9
9
  exports.mockSchematicsForTesting = mockSchematicsForTesting;
10
10
  exports.wrapAngularDevkitSchematic = wrapAngularDevkitSchematic;
11
+ exports.restoreNxTokensInOptions = restoreNxTokensInOptions;
11
12
  const core_1 = require("@angular-devkit/core");
12
13
  const node_1 = require("@angular-devkit/core/node");
13
14
  const chalk = require("chalk");
@@ -28,6 +29,7 @@ const angular_json_1 = require("./angular-json");
28
29
  const executor_utils_1 = require("../command-line/run/executor-utils");
29
30
  const plugins_1 = require("../project-graph/plugins");
30
31
  const schema_utils_1 = require("../config/schema-utils");
32
+ const project_configuration_utils_1 = require("../project-graph/utils/project-configuration-utils");
31
33
  async function createBuilderContext(builderInfo, context) {
32
34
  require('./compat');
33
35
  const fsHost = new NxScopedHostForBuilders(context.root);
@@ -296,10 +298,32 @@ class NxScopedHost extends core_1.virtualFs.ScopedHost {
296
298
  const projects = configV2.projects;
297
299
  const allObservables = [];
298
300
  Object.keys(projects).forEach((projectName) => {
299
- if (projectsInAngularJson.includes(projectName)) {
300
- // ignore updates to angular.json
301
- }
302
- else {
301
+ if (!projectsInAngularJson.includes(projectName)) {
302
+ // Restore tokens in options if they were present before
303
+ const previousProject = existingConfig.projects[projectName];
304
+ const newProject = projects[projectName];
305
+ if (previousProject &&
306
+ newProject.targets &&
307
+ previousProject.targets) {
308
+ for (const [targetName, target] of Object.entries(newProject.targets)) {
309
+ const previousTarget = previousProject.targets[targetName];
310
+ if (target.options &&
311
+ previousTarget &&
312
+ previousTarget.options) {
313
+ target.options = restoreNxTokensInOptions(target.options, previousTarget.options, newProject);
314
+ }
315
+ if (target.configurations &&
316
+ previousTarget &&
317
+ previousTarget.configurations) {
318
+ for (const [configName, config] of Object.entries(target.configurations)) {
319
+ if (previousTarget.configurations[configName]) {
320
+ target.configurations[configName] =
321
+ restoreNxTokensInOptions(config, previousTarget.configurations[configName], newProject);
322
+ }
323
+ }
324
+ }
325
+ }
326
+ }
303
327
  (0, project_configuration_1.updateProjectConfiguration)({
304
328
  root,
305
329
  exists: () => true,
@@ -430,9 +454,23 @@ class NxScopeHostUsedForWrappedSchematics extends NxScopedHost {
430
454
  read(path) {
431
455
  if ((path === 'angular.json' || path === '/angular.json') &&
432
456
  (0, angular_json_1.isAngularPluginInstalled)()) {
433
- const projectJsonConfig = (0, angular_json_1.toOldFormat)({
434
- projects: Object.fromEntries((0, project_configuration_1.getProjects)(this.host)),
435
- });
457
+ // Replace the Nx-specific tokens in all target options
458
+ const projects = Object.fromEntries((0, project_configuration_1.getProjects)(this.host));
459
+ for (const [projectName, project] of Object.entries(projects)) {
460
+ if (project.targets) {
461
+ for (const [targetName, target] of Object.entries(project.targets)) {
462
+ if (target.options) {
463
+ target.options = (0, project_configuration_utils_1.resolveNxTokensInOptions)(target.options, { ...project, name: projectName }, `${projectName}:${targetName}`);
464
+ }
465
+ if (target.configurations) {
466
+ for (const [configName, config] of Object.entries(target.configurations)) {
467
+ target.configurations[configName] = (0, project_configuration_utils_1.resolveNxTokensInOptions)(config, { ...project, name: projectName }, `${projectName}:${targetName}:${configName}`);
468
+ }
469
+ }
470
+ }
471
+ }
472
+ }
473
+ const projectJsonConfig = (0, angular_json_1.toOldFormat)({ projects });
436
474
  return super.readExistingAngularJson().pipe((0, operators_1.map)((angularJson) => {
437
475
  if (angularJson) {
438
476
  return Buffer.from(JSON.stringify({
@@ -852,3 +890,59 @@ async function getWrappedWorkspaceNodeModulesArchitectHost(workspace, root, proj
852
890
  }
853
891
  return new WrappedWorkspaceNodeModulesArchitectHost(workspace, root, projects);
854
892
  }
893
+ /**
894
+ * Restores Nx tokens in options when possible by comparing new and previous
895
+ * options.
896
+ * The function preserves tokens in the following cases:
897
+ * 1. When the resolved previous value matches the new value exactly
898
+ * 2. When the previous value used {workspaceRoot}
899
+ * 3. When the previous value used {projectRoot} and the new value starts with
900
+ * the project root path
901
+ * Those are the only safe cases, for all other cases, the new value is used as-is.
902
+ */
903
+ function restoreNxTokensInOptions(newOptions, previousOptions, project) {
904
+ if (!newOptions || !previousOptions) {
905
+ return newOptions;
906
+ }
907
+ const result = Array.isArray(newOptions)
908
+ ? [...newOptions]
909
+ : { ...newOptions };
910
+ const resolvedPreviousOptions = (0, project_configuration_utils_1.resolveNxTokensInOptions)(previousOptions, project, '');
911
+ for (const key of Object.keys(newOptions)) {
912
+ const newValue = newOptions[key];
913
+ const previousValue = previousOptions[key];
914
+ if (typeof newValue === 'string' && typeof previousValue === 'string') {
915
+ if (resolvedPreviousOptions[key] === newValue) {
916
+ // If the resolved previous value matches the new value, use the previous
917
+ // value (potentially with tokens)
918
+ result[key] = previousValue;
919
+ }
920
+ else if (previousValue.startsWith('{workspaceRoot}/')) {
921
+ // If the previous value started with {workspaceRoot}, prefix the new
922
+ // value with {workspaceRoot}
923
+ result[key] = `{workspaceRoot}/${newValue.replace(/^\//, '')}`;
924
+ }
925
+ else if (previousValue.startsWith('{projectRoot}/') &&
926
+ newValue.startsWith(`${project.root}/`)) {
927
+ // If the previous value started with {projectRoot} and the new value
928
+ // starts with the project root, replace the project root with the
929
+ // {projectRoot} token
930
+ result[key] = newValue.replace(`${project.root}/`, '{projectRoot}/');
931
+ }
932
+ else {
933
+ // Otherwise, use the new value as-is
934
+ result[key] = newValue;
935
+ }
936
+ }
937
+ else if (typeof newValue === 'object' &&
938
+ typeof previousValue === 'object' &&
939
+ newValue &&
940
+ previousValue) {
941
+ result[key] = restoreNxTokensInOptions(newValue, previousValue, project);
942
+ }
943
+ else {
944
+ result[key] = newValue;
945
+ }
946
+ }
947
+ return result;
948
+ }