nx 20.0.0-canary.20241002-1d10a19 → 20.0.0-canary.20241003-84a5c7a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/.eslintrc.json +12 -2
  2. package/migrations.json +0 -37
  3. package/package.json +11 -11
  4. package/release/changelog-renderer/index.d.ts +60 -38
  5. package/release/changelog-renderer/index.js +260 -236
  6. package/src/command-line/add/add.js +2 -2
  7. package/src/command-line/nx-commands.js +31 -10
  8. package/src/command-line/release/changelog.d.ts +2 -2
  9. package/src/command-line/release/changelog.js +28 -29
  10. package/src/command-line/release/index.d.ts +5 -2
  11. package/src/command-line/release/publish.d.ts +6 -1
  12. package/src/command-line/release/publish.js +31 -25
  13. package/src/command-line/release/utils/print-changes.js +6 -4
  14. package/src/command-line/release/utils/resolve-changelog-renderer.d.ts +2 -2
  15. package/src/command-line/release/utils/resolve-changelog-renderer.js +3 -3
  16. package/src/command-line/release/utils/resolve-nx-json-error-message.js +4 -3
  17. package/src/command-line/release/version.d.ts +3 -3
  18. package/src/command-line/yargs-utils/shared-options.js +2 -2
  19. package/src/config/nx-json.d.ts +2 -1
  20. package/src/native/nx.wasm32-wasi.wasm +0 -0
  21. package/src/nx-cloud/utilities/axios.js +1 -2
  22. package/src/nx-cloud/utilities/onboarding.js +2 -2
  23. package/src/nx-cloud/utilities/url-shorten.js +5 -5
  24. package/src/project-graph/file-utils.d.ts +2 -2
  25. package/src/project-graph/file-utils.js +2 -2
  26. package/src/tasks-runner/cache.d.ts +2 -1
  27. package/src/tasks-runner/cache.js +10 -6
  28. package/src/tasks-runner/create-task-graph.d.ts +2 -0
  29. package/src/tasks-runner/create-task-graph.js +39 -5
  30. package/src/tasks-runner/run-command.js +15 -2
  31. package/src/tasks-runner/task-orchestrator.js +1 -1
  32. package/src/utils/command-line-utils.d.ts +3 -0
  33. package/src/utils/git-utils.js +2 -2
  34. package/src/migrations/update-15-0-0/prefix-outputs.d.ts +0 -2
  35. package/src/migrations/update-15-0-0/prefix-outputs.js +0 -49
  36. package/src/migrations/update-16-0-0/remove-nrwl-cli.d.ts +0 -2
  37. package/src/migrations/update-16-0-0/remove-nrwl-cli.js +0 -16
  38. package/src/migrations/update-16-0-0/update-depends-on-to-tokens.d.ts +0 -2
  39. package/src/migrations/update-16-0-0/update-depends-on-to-tokens.js +0 -97
  40. package/src/migrations/update-16-0-0/update-nx-cloud-runner.d.ts +0 -2
  41. package/src/migrations/update-16-0-0/update-nx-cloud-runner.js +0 -29
  42. package/src/migrations/update-16-2-0/remove-run-commands-output-path.d.ts +0 -2
  43. package/src/migrations/update-16-2-0/remove-run-commands-output-path.js +0 -45
  44. package/src/migrations/update-16-8-0/escape-dollar-sign-env-variables.d.ts +0 -12
  45. package/src/migrations/update-16-8-0/escape-dollar-sign-env-variables.js +0 -67
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Cache = exports.DbCache = void 0;
4
+ exports.dbCacheEnabled = dbCacheEnabled;
4
5
  exports.getCache = getCache;
5
6
  const workspace_root_1 = require("../utils/workspace-root");
6
7
  const path_1 = require("path");
@@ -19,14 +20,17 @@ const update_manager_1 = require("../nx-cloud/update-manager");
19
20
  const get_cloud_options_1 = require("../nx-cloud/utilities/get-cloud-options");
20
21
  const is_ci_1 = require("../utils/is-ci");
21
22
  const output_1 = require("../utils/output");
22
- function getCache(nxJson, options) {
23
- return process.env.NX_DISABLE_DB !== 'true' &&
24
- (nxJson.enableDbCache === true || process.env.NX_DB_CACHE === 'true')
23
+ function dbCacheEnabled(nxJson = (0, nx_json_1.readNxJson)()) {
24
+ return (process.env.NX_DISABLE_DB !== 'true' &&
25
+ (nxJson.enableDbCache === true || process.env.NX_DB_CACHE === 'true'));
26
+ }
27
+ // Do not change the order of these arguments as this function is used by nx cloud
28
+ function getCache(options) {
29
+ const nxJson = (0, nx_json_1.readNxJson)();
30
+ return dbCacheEnabled(nxJson)
25
31
  ? new DbCache({
26
32
  // Remove this in Nx 21
27
- nxCloudRemoteCache: (0, nx_cloud_utils_1.isNxCloudUsed)((0, nx_json_1.readNxJson)())
28
- ? options.remoteCache
29
- : null,
33
+ nxCloudRemoteCache: (0, nx_cloud_utils_1.isNxCloudUsed)(nxJson) ? options.remoteCache : null,
30
34
  })
31
35
  : new Cache(options);
32
36
  }
@@ -18,9 +18,11 @@ export declare class ProcessTasks {
18
18
  private processTasksForMultipleProjects;
19
19
  private processTasksForSingleProject;
20
20
  private processTasksForDependencies;
21
+ private createDummyTask;
21
22
  createTask(id: string, project: ProjectGraphProjectNode, target: string, resolvedConfiguration: string | undefined, overrides: Object): Task;
22
23
  resolveConfiguration(project: ProjectGraphProjectNode, target: string, configuration: string | undefined): string;
23
24
  getId(project: string, target: string, configuration: string | undefined): string;
25
+ private filterDummyTasks;
24
26
  }
25
27
  export declare function createTaskGraph(projectGraph: ProjectGraph, extraTargetDependencies: TargetDependencies, projectNames: string[], targets: string[], configuration: string | undefined, overrides: Object, excludeTaskDependencies?: boolean): TaskGraph;
26
28
  export declare function mapTargetDefaultsToDependencies(defaults: TargetDefaults | undefined): TargetDependencies;
@@ -6,6 +6,7 @@ exports.mapTargetDefaultsToDependencies = mapTargetDefaultsToDependencies;
6
6
  const utils_1 = require("./utils");
7
7
  const project_graph_utils_1 = require("../utils/project-graph-utils");
8
8
  const output_1 = require("../utils/output");
9
+ const DUMMY_TASK_TARGET = '__nx_dummy_task__';
9
10
  class ProcessTasks {
10
11
  constructor(extraTargetDependencies, projectGraph) {
11
12
  this.extraTargetDependencies = extraTargetDependencies;
@@ -52,10 +53,11 @@ class ProcessTasks {
52
53
  this.dependencies[d] = this.dependencies[d].filter((dd) => !!initialTasks[dd]);
53
54
  }
54
55
  }
55
- for (const projectName of Object.keys(this.dependencies)) {
56
- if (this.dependencies[projectName].length > 1) {
57
- this.dependencies[projectName] = [
58
- ...new Set(this.dependencies[projectName]).values(),
56
+ this.filterDummyTasks();
57
+ for (const taskId of Object.keys(this.dependencies)) {
58
+ if (this.dependencies[taskId].length > 0) {
59
+ this.dependencies[taskId] = [
60
+ ...new Set(this.dependencies[taskId].filter((d) => d !== taskId)).values(),
59
61
  ];
60
62
  }
61
63
  }
@@ -113,6 +115,9 @@ class ProcessTasks {
113
115
  }
114
116
  }
115
117
  processTasksForDependencies(projectUsedToDeriveDependencies, dependencyConfig, configuration, task, taskOverrides, overrides) {
118
+ if (!this.projectGraph.dependencies.hasOwnProperty(projectUsedToDeriveDependencies)) {
119
+ return;
120
+ }
116
121
  for (const dep of this.projectGraph.dependencies[projectUsedToDeriveDependencies]) {
117
122
  const depProject = this.projectGraph.nodes[dep.target];
118
123
  // this is to handle external dependencies
@@ -132,10 +137,20 @@ class ProcessTasks {
132
137
  }
133
138
  }
134
139
  else {
135
- this.processTask(task, depProject.name, configuration, overrides);
140
+ const dummyId = this.getId(depProject.name, DUMMY_TASK_TARGET, undefined);
141
+ this.dependencies[task.id].push(dummyId);
142
+ this.dependencies[dummyId] = [];
143
+ const noopTask = this.createDummyTask(dummyId, task);
144
+ this.processTask(noopTask, depProject.name, configuration, overrides);
136
145
  }
137
146
  }
138
147
  }
148
+ createDummyTask(id, task) {
149
+ return {
150
+ ...task,
151
+ id,
152
+ };
153
+ }
139
154
  createTask(id, project, target, resolvedConfiguration, overrides) {
140
155
  if (!project.data.targets[target]) {
141
156
  throw new Error(`Cannot find configuration for task ${project.name}:${target}`);
@@ -173,6 +188,25 @@ class ProcessTasks {
173
188
  }
174
189
  return id;
175
190
  }
191
+ filterDummyTasks() {
192
+ for (const [key, deps] of Object.entries(this.dependencies)) {
193
+ const normalizedDeps = [];
194
+ for (const dep of deps) {
195
+ if (dep.endsWith(DUMMY_TASK_TARGET)) {
196
+ normalizedDeps.push(...this.dependencies[dep].filter((d) => !d.endsWith(DUMMY_TASK_TARGET)));
197
+ }
198
+ else {
199
+ normalizedDeps.push(dep);
200
+ }
201
+ }
202
+ this.dependencies[key] = normalizedDeps;
203
+ }
204
+ for (const key of Object.keys(this.dependencies)) {
205
+ if (key.endsWith(DUMMY_TASK_TARGET)) {
206
+ delete this.dependencies[key];
207
+ }
208
+ }
209
+ }
176
210
  }
177
211
  exports.ProcessTasks = ProcessTasks;
178
212
  function createTaskGraph(projectGraph, extraTargetDependencies, projectNames, targets, configuration, overrides, excludeTaskDependencies = false) {
@@ -511,12 +511,21 @@ function loadTasksRunner(modulePath) {
511
511
  }
512
512
  function getRunner(nxArgs, nxJson) {
513
513
  let runner = nxArgs.runner;
514
- runner = runner || 'default';
514
+ runner = runner ?? 'default';
515
515
  if (runner !== 'default' && !nxJson.tasksRunnerOptions?.[runner]) {
516
516
  throw new Error(`Could not find runner configuration for ${runner}`);
517
517
  }
518
518
  const modulePath = getTasksRunnerPath(runner, nxJson);
519
519
  try {
520
+ if (isCustomRunnerPath(modulePath)) {
521
+ output_1.output.warn({
522
+ title: `Custom task runners will no longer be supported in Nx 21.`,
523
+ bodyLines: [
524
+ `Use Nx Cloud or the Nx Powerpack caches instead.`,
525
+ `For more information, see https://nx.dev/features/powerpack/custom-caching`,
526
+ ],
527
+ });
528
+ }
520
529
  const tasksRunner = loadTasksRunner(modulePath);
521
530
  return {
522
531
  tasksRunner,
@@ -527,6 +536,7 @@ function getRunner(nxArgs, nxJson) {
527
536
  throw new Error(`Could not find runner configuration for ${runner}`);
528
537
  }
529
538
  }
539
+ const defaultTasksRunnerPath = require.resolve('./default-tasks-runner');
530
540
  function getTasksRunnerPath(runner, nxJson) {
531
541
  let modulePath = nxJson.tasksRunnerOptions?.[runner]?.runner;
532
542
  if (modulePath) {
@@ -544,7 +554,7 @@ function getTasksRunnerPath(runner, nxJson) {
544
554
  process.env.NX_CLOUD_ACCESS_TOKEN ||
545
555
  // Nx Cloud ID specified in nxJson
546
556
  nxJson.nxCloudId;
547
- return isCloudRunner ? 'nx-cloud' : require.resolve('./default-tasks-runner');
557
+ return isCloudRunner ? 'nx-cloud' : defaultTasksRunnerPath;
548
558
  }
549
559
  function getRunnerOptions(runner, nxJson, nxArgs, isCloudDefault) {
550
560
  const defaultCacheableOperations = [];
@@ -588,3 +598,6 @@ function getRunnerOptions(runner, nxJson, nxArgs, isCloudDefault) {
588
598
  }
589
599
  return result;
590
600
  }
601
+ function isCustomRunnerPath(modulePath) {
602
+ return !['nx-cloud', '@nrwl/nx-cloud', defaultTasksRunnerPath].includes(modulePath);
603
+ }
@@ -28,7 +28,7 @@ class TaskOrchestrator {
28
28
  this.daemon = daemon;
29
29
  this.outputStyle = outputStyle;
30
30
  this.taskDetails = (0, hash_task_1.getTaskDetails)();
31
- this.cache = (0, cache_1.getCache)(this.nxJson, this.options);
31
+ this.cache = (0, cache_1.getCache)(this.options);
32
32
  this.forkedProcessTaskRunner = new forked_process_task_runner_1.ForkedProcessTaskRunner(this.options);
33
33
  this.tasksSchedule = new tasks_schedule_1.TasksSchedule(this.projectGraph, this.taskGraph, this.options);
34
34
  // region internal state
@@ -7,6 +7,9 @@ export interface RawNxArgs extends NxArgs {
7
7
  export interface NxArgs {
8
8
  targets?: string[];
9
9
  configuration?: string;
10
+ /**
11
+ * @deprecated Custom task runners will no longer be supported in Nx 21. Use Nx Cloud or Nx Powerpack instead.
12
+ */
10
13
  runner?: string;
11
14
  parallel?: number;
12
15
  untracked?: boolean;
@@ -8,7 +8,7 @@ exports.commitChanges = commitChanges;
8
8
  exports.getLatestCommitSha = getLatestCommitSha;
9
9
  const child_process_1 = require("child_process");
10
10
  const path_1 = require("path");
11
- const devkit_exports_1 = require("../devkit-exports");
11
+ const logger_1 = require("./logger");
12
12
  function execAsync(command, execOptions) {
13
13
  return new Promise((res, rej) => {
14
14
  (0, child_process_1.exec)(command, execOptions, (err, stdout, stderr) => {
@@ -236,7 +236,7 @@ function commitChanges(commitMessage, directory) {
236
236
  // We don't want to throw during create-nx-workspace
237
237
  // because maybe there was an error when setting up git
238
238
  // initially.
239
- devkit_exports_1.logger.verbose(`Git may not be set up correctly for this new workspace.
239
+ logger_1.logger.verbose(`Git may not be set up correctly for this new workspace.
240
240
  ${err}`);
241
241
  }
242
242
  else {
@@ -1,2 +0,0 @@
1
- import { Tree } from '../../generators/tree';
2
- export default function (tree: Tree): Promise<void>;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = default_1;
4
- const format_changed_files_with_prettier_if_available_1 = require("../../generators/internal-utils/format-changed-files-with-prettier-if-available");
5
- const project_configuration_1 = require("../../generators/utils/project-configuration");
6
- const nx_json_1 = require("../../generators/utils/nx-json");
7
- const path_1 = require("path");
8
- const utils_1 = require("../../tasks-runner/utils");
9
- const json_1 = require("../../generators/utils/json");
10
- async function default_1(tree) {
11
- // If the workspace doesn't have a nx.json, don't make any changes
12
- if (!tree.exists('nx.json')) {
13
- return;
14
- }
15
- const nxJson = (0, nx_json_1.readNxJson)(tree);
16
- for (const [projectName, project] of (0, project_configuration_1.getProjects)(tree)) {
17
- for (const [_, target] of Object.entries(project.targets ?? {})) {
18
- if (!target.outputs) {
19
- continue;
20
- }
21
- target.outputs = (0, utils_1.transformLegacyOutputs)(project.root, target.outputs);
22
- }
23
- try {
24
- (0, project_configuration_1.updateProjectConfiguration)(tree, projectName, project);
25
- }
26
- catch {
27
- if (tree.exists((0, path_1.join)(project.root, 'package.json'))) {
28
- (0, json_1.updateJson)(tree, (0, path_1.join)(project.root, 'package.json'), (json) => {
29
- for (const target of Object.values(json.nx?.targets ?? {})) {
30
- if (target.outputs) {
31
- target.outputs = (0, utils_1.transformLegacyOutputs)(project.root, target.outputs);
32
- }
33
- }
34
- return json;
35
- });
36
- }
37
- }
38
- }
39
- if (nxJson.targetDefaults) {
40
- for (const [_, target] of Object.entries(nxJson.targetDefaults)) {
41
- if (!target.outputs) {
42
- continue;
43
- }
44
- target.outputs = (0, utils_1.transformLegacyOutputs)('{projectRoot}', target.outputs);
45
- }
46
- (0, nx_json_1.updateNxJson)(tree, nxJson);
47
- }
48
- await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree);
49
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '../../generators/tree';
2
- export default function (tree: Tree): Promise<void>;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = default_1;
4
- const format_changed_files_with_prettier_if_available_1 = require("../../generators/internal-utils/format-changed-files-with-prettier-if-available");
5
- const json_1 = require("../../generators/utils/json");
6
- async function default_1(tree) {
7
- (0, json_1.updateJson)(tree, 'package.json', (json) => {
8
- for (const deps of [json.dependencies, json.devDependencies]) {
9
- if (deps) {
10
- delete deps['@nrwl/cli'];
11
- }
12
- }
13
- return json;
14
- });
15
- await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree);
16
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '../../generators/tree';
2
- export default function (tree: Tree): Promise<void>;
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = default_1;
4
- const project_configuration_1 = require("../../generators/utils/project-configuration");
5
- const format_changed_files_with_prettier_if_available_1 = require("../../generators/internal-utils/format-changed-files-with-prettier-if-available");
6
- async function default_1(tree) {
7
- updateDependsOnAndInputsInsideNxJson(tree);
8
- const projectsConfigurations = (0, project_configuration_1.getProjects)(tree);
9
- for (const [projectName, projectConfiguration] of projectsConfigurations) {
10
- let projectChanged = false;
11
- for (const [targetName, targetConfiguration] of Object.entries(projectConfiguration.targets ?? {})) {
12
- for (const dependency of targetConfiguration.dependsOn ?? []) {
13
- if (typeof dependency !== 'string') {
14
- if (dependency.projects === 'self' ||
15
- dependency.projects === '{self}') {
16
- delete dependency.projects;
17
- projectChanged = true;
18
- }
19
- else if (dependency.projects === 'dependencies' ||
20
- dependency.projects === '{dependencies}') {
21
- delete dependency.projects;
22
- dependency.dependencies = true;
23
- projectChanged = true;
24
- }
25
- }
26
- }
27
- for (let i = 0; i < targetConfiguration.inputs?.length ?? 0; i++) {
28
- const input = targetConfiguration.inputs[i];
29
- if (typeof input !== 'string') {
30
- if ('projects' in input &&
31
- (input.projects === 'self' || input.projects === '{self}')) {
32
- delete input.projects;
33
- projectChanged = true;
34
- }
35
- else if ('projects' in input &&
36
- (input.projects === 'dependencies' ||
37
- input.projects === '{dependencies}')) {
38
- delete input.projects;
39
- targetConfiguration.inputs[i] = {
40
- ...input,
41
- dependencies: true,
42
- };
43
- projectChanged = true;
44
- }
45
- }
46
- }
47
- }
48
- if (projectChanged) {
49
- (0, project_configuration_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
50
- }
51
- }
52
- await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree);
53
- }
54
- function updateDependsOnAndInputsInsideNxJson(tree) {
55
- const nxJson = (0, project_configuration_1.readNxJson)(tree);
56
- let nxJsonChanged = false;
57
- for (const [target, defaults] of Object.entries(nxJson?.targetDefaults ?? {})) {
58
- for (const dependency of defaults.dependsOn ?? []) {
59
- if (typeof dependency !== 'string') {
60
- if (dependency.projects === 'self' ||
61
- dependency.projects === '{self}') {
62
- delete dependency.projects;
63
- nxJsonChanged = true;
64
- }
65
- else if (dependency.projects === 'dependencies' ||
66
- dependency.projects === '{dependencies}') {
67
- delete dependency.projects;
68
- dependency.dependencies = true;
69
- nxJsonChanged = true;
70
- }
71
- }
72
- }
73
- for (let i = 0; i < defaults.inputs?.length ?? 0; i++) {
74
- const input = defaults.inputs[i];
75
- if (typeof input !== 'string') {
76
- if ('projects' in input &&
77
- (input.projects === 'self' || input.projects === '{self}')) {
78
- delete input.projects;
79
- nxJsonChanged = true;
80
- }
81
- else if ('projects' in input &&
82
- (input.projects === 'dependencies' ||
83
- input.projects === '{dependencies}')) {
84
- delete input.projects;
85
- defaults.inputs[i] = {
86
- ...input,
87
- dependencies: true,
88
- };
89
- nxJsonChanged = true;
90
- }
91
- }
92
- }
93
- }
94
- if (nxJsonChanged) {
95
- (0, project_configuration_1.updateNxJson)(tree, nxJson);
96
- }
97
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '../../generators/tree';
2
- export default function (tree: Tree): Promise<void>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = default_1;
4
- const project_configuration_1 = require("../../generators/utils/project-configuration");
5
- const json_1 = require("../../generators/utils/json");
6
- const format_changed_files_with_prettier_if_available_1 = require("../../generators/internal-utils/format-changed-files-with-prettier-if-available");
7
- async function default_1(tree) {
8
- (0, json_1.updateJson)(tree, 'package.json', (json) => {
9
- if (json.dependencies && json.dependencies['@nrwl/nx-cloud']) {
10
- json.dependencies['nx-cloud'] = json.dependencies['@nrwl/nx-cloud'];
11
- delete json.dependencies['@nrwl/nx-cloud'];
12
- }
13
- if (json.devDependencies && json.devDependencies['@nrwl/nx-cloud']) {
14
- json.devDependencies['nx-cloud'] = json.devDependencies['@nrwl/nx-cloud'];
15
- delete json.devDependencies['@nrwl/nx-cloud'];
16
- }
17
- return json;
18
- });
19
- const nxJson = (0, project_configuration_1.readNxJson)(tree);
20
- if (!nxJson)
21
- return;
22
- for (let opts of Object.values(nxJson.tasksRunnerOptions ?? {})) {
23
- if (opts.runner === '@nrwl/nx-cloud') {
24
- opts.runner = 'nx-cloud';
25
- }
26
- }
27
- (0, project_configuration_1.updateNxJson)(tree, nxJson);
28
- await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree);
29
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '../../generators/tree';
2
- export default function removeRunCommandsOutputPath(tree: Tree): Promise<void>;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = removeRunCommandsOutputPath;
4
- const path_1 = require("../../utils/path");
5
- const format_changed_files_with_prettier_if_available_1 = require("../../generators/internal-utils/format-changed-files-with-prettier-if-available");
6
- const json_1 = require("../../generators/utils/json");
7
- const project_configuration_1 = require("../../generators/utils/project-configuration");
8
- async function removeRunCommandsOutputPath(tree) {
9
- for (const [project, configuration] of (0, project_configuration_1.getProjects)(tree).entries()) {
10
- const targets = configuration.targets ?? {};
11
- let changed = false;
12
- for (const [, target] of Object.entries(targets)) {
13
- changed ||= updateTargetBlock(target);
14
- }
15
- if (changed) {
16
- (0, project_configuration_1.updateProjectConfiguration)(tree, project, configuration);
17
- }
18
- }
19
- if (tree.exists('nx.json')) {
20
- (0, json_1.updateJson)(tree, 'nx.json', (json) => {
21
- for (const [, target] of Object.entries(json.targetDefaults ?? {})) {
22
- updateTargetBlock(target);
23
- }
24
- return json;
25
- });
26
- }
27
- await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree);
28
- }
29
- function updateTargetBlock(target) {
30
- let changed = false;
31
- if (target.executor === 'nx:run-commands' && target.options?.outputPath) {
32
- changed = true;
33
- const outputs = new Set(target.outputs ?? []);
34
- outputs.delete('{options.outputPath}');
35
- const newOutputs = Array.isArray(target.options.outputPath)
36
- ? target.options.outputPath.map((p) => (0, path_1.joinPathFragments)('{workspaceRoot}', p))
37
- : [(0, path_1.joinPathFragments)('{workspaceRoot}', target.options.outputPath)];
38
- for (const outputPath of newOutputs) {
39
- outputs.add(outputPath);
40
- }
41
- delete target.options.outputPath;
42
- target.outputs = Array.from(outputs);
43
- }
44
- return changed;
45
- }
@@ -1,12 +0,0 @@
1
- import { Tree } from '../../generators/tree';
2
- /**
3
- * This function escapes dollar sign in env variables
4
- * It will go through:
5
- * - '.env', '.local.env', '.env.local'
6
- * - .env.[target-name], .[target-name].env
7
- * - .env.[target-name].[configuration-name], .[target-name].[configuration-name].env
8
- * - .env.[configuration-name], .[configuration-name].env
9
- * at each project root and workspace root
10
- * @param tree
11
- */
12
- export default function escapeDollarSignEnvVariables(tree: Tree): void;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = escapeDollarSignEnvVariables;
4
- const logger_1 = require("../../utils/logger");
5
- const project_configuration_1 = require("../../generators/utils/project-configuration");
6
- /**
7
- * This function escapes dollar sign in env variables
8
- * It will go through:
9
- * - '.env', '.local.env', '.env.local'
10
- * - .env.[target-name], .[target-name].env
11
- * - .env.[target-name].[configuration-name], .[target-name].[configuration-name].env
12
- * - .env.[configuration-name], .[configuration-name].env
13
- * at each project root and workspace root
14
- * @param tree
15
- */
16
- function escapeDollarSignEnvVariables(tree) {
17
- const envFiles = ['.env', '.local.env', '.env.local'];
18
- for (const [_, configuration] of (0, project_configuration_1.getProjects)(tree).entries()) {
19
- envFiles.push(`${configuration.root}/.env`, `${configuration.root}/.local.env`, `${configuration.root}/.env.local`);
20
- for (const targetName in configuration.targets) {
21
- const task = configuration.targets[targetName];
22
- envFiles.push(`.env.${targetName}`, `.${targetName}.env`, `${configuration.root}/.env.${targetName}`, `${configuration.root}/.${targetName}.env`);
23
- if (task.configurations) {
24
- for (const configurationName in task.configurations) {
25
- envFiles.push(`.env.${targetName}.${configurationName}`, `.${targetName}.${configurationName}.env`, `.env.${configurationName}`, `.${configurationName}.env`, `${configuration.root}/.env.${targetName}.${configurationName}`, `${configuration.root}/.${targetName}.${configurationName}.env`, `${configuration.root}/.env.${configurationName}`, `${configuration.root}/.${configurationName}.env`);
26
- }
27
- }
28
- }
29
- }
30
- for (const envFile of new Set(envFiles)) {
31
- parseEnvFile(tree, envFile);
32
- }
33
- }
34
- /**
35
- * This function parse the env file and escape dollar sign
36
- * @param tree
37
- * @param envFilePath
38
- * @returns
39
- */
40
- function parseEnvFile(tree, envFilePath) {
41
- if (!tree.exists(envFilePath)) {
42
- return;
43
- }
44
- let envFileContent = tree.read(envFilePath, 'utf-8');
45
- if (!envFileContent) {
46
- // envFileContent is null if we fail to read the file for any reason
47
- // e.g. the file is not utf-8 encoded
48
- logger_1.logger.info(`Unable to update ${envFilePath}. Nx interpolates environment variables in the form of $VAR_NAME. To escape the dollar sign, use \\$VAR_NAME.`);
49
- return;
50
- }
51
- envFileContent = envFileContent
52
- .split('\n')
53
- .map((line) => {
54
- line = line.trim();
55
- if (!line || !line.includes('$')) {
56
- return line;
57
- }
58
- const declarations = line.split('=');
59
- if (declarations[1].includes('$') && !declarations[1].includes(`\\$`)) {
60
- declarations[1] = declarations[1].replace('$', `\\$`);
61
- line = declarations.join('=');
62
- }
63
- return line;
64
- })
65
- .join('\n');
66
- tree.write(envFilePath, envFileContent);
67
- }