nx 22.1.0-rc.4 → 22.1.0-rc.5

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.
@@ -0,0 +1,2 @@
1
+ export declare function getEnvPathsForTask(projectRoot: string, target: string, configuration?: string, nonAtomizedTarget?: string): string[];
2
+ //# sourceMappingURL=task-env-paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-env-paths.d.ts","sourceRoot":"","sources":["../../../../../packages/nx/src/tasks-runner/task-env-paths.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,aAAa,CAAC,EAAE,MAAM,EACtB,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,EAAE,CA6BV"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEnvPathsForTask = getEnvPathsForTask;
4
+ function getEnvPathsForTask(projectRoot, target, configuration, nonAtomizedTarget) {
5
+ const identifiers = [];
6
+ // Configuration-specific identifier (like build.development, build.production)
7
+ if (configuration) {
8
+ identifiers.push(`${target}.${configuration}`);
9
+ if (nonAtomizedTarget) {
10
+ identifiers.push(`${nonAtomizedTarget}.${configuration}`);
11
+ }
12
+ identifiers.push(configuration);
13
+ }
14
+ // Non-configuration-specific identifier (like build, test, serve)
15
+ identifiers.push(target);
16
+ if (nonAtomizedTarget) {
17
+ identifiers.push(nonAtomizedTarget);
18
+ }
19
+ // Non-deterministic identifier (for files like .env.local, .local.env, .env)
20
+ identifiers.push('');
21
+ const envPaths = [];
22
+ // Add DotEnv Files in the project root folder
23
+ for (const identifier of identifiers) {
24
+ envPaths.push(...getEnvFileVariants(identifier, projectRoot));
25
+ }
26
+ // Add DotEnv Files in the workspace root folder
27
+ for (const identifier of identifiers) {
28
+ envPaths.push(...getEnvFileVariants(identifier));
29
+ }
30
+ return envPaths;
31
+ }
32
+ function getEnvFileVariants(identifier, root) {
33
+ const path = root ? root + '/' : '';
34
+ if (identifier) {
35
+ return [
36
+ `${path}.env.${identifier}.local`,
37
+ `${path}.env.${identifier}`,
38
+ `${path}.${identifier}.local.env`,
39
+ `${path}.${identifier}.env`,
40
+ ];
41
+ }
42
+ else {
43
+ return [`${path}.env.local`, `${path}.local.env`, `${path}.env`];
44
+ }
45
+ }
@@ -1,6 +1,7 @@
1
1
  import { Task } from '../config/task-graph';
2
+ import { ProjectGraph } from '../config/project-graph';
2
3
  export declare function getEnvVariablesForBatchProcess(skipNxCache: boolean, captureStderr: boolean): NodeJS.ProcessEnv;
3
- export declare function getTaskSpecificEnv(task: Task): NodeJS.ProcessEnv;
4
+ export declare function getTaskSpecificEnv(task: Task, graph: ProjectGraph): NodeJS.ProcessEnv;
4
5
  export declare function getEnvVariablesForTask(task: Task, taskSpecificEnv: NodeJS.ProcessEnv, forceColor: string, skipNxCache: boolean, captureStderr: boolean, outputPath: string, streamOutput: boolean): NodeJS.ProcessEnv;
5
6
  /**
6
7
  * This function loads a .env file and expands the variables in it.
@@ -15,4 +16,5 @@ export declare function loadAndExpandDotEnvFile(filename: string, environmentVar
15
16
  * @param environmentVariables
16
17
  */
17
18
  export declare function unloadDotEnvFile(filename: string, environmentVariables: NodeJS.ProcessEnv, override?: boolean): void;
19
+ export declare function getEnvFilesForTask(task: Task, graph: ProjectGraph): string[];
18
20
  //# sourceMappingURL=task-env.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"task-env.d.ts","sourceRoot":"","sources":["../../../../../packages/nx/src/tasks-runner/task-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAM5C,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,OAAO,EACpB,aAAa,EAAE,OAAO,GACrB,MAAM,CAAC,UAAU,CAWnB;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,qBAO5C;AAED,wBAAgB,sB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IG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,oBAAoB,EAAE,MAAM,CAAC,UAAU,EACvC,QAAQ,UAAQ,QASjB;AAwBD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,EAAE,CAS5E"}
@@ -5,10 +5,12 @@ exports.getTaskSpecificEnv = getTaskSpecificEnv;
5
5
  exports.getEnvVariablesForTask = getEnvVariablesForTask;
6
6
  exports.loadAndExpandDotEnvFile = loadAndExpandDotEnvFile;
7
7
  exports.unloadDotEnvFile = unloadDotEnvFile;
8
+ exports.getEnvFilesForTask = getEnvFilesForTask;
8
9
  const dotenv_1 = require("dotenv");
9
10
  const dotenv_expand_1 = require("dotenv-expand");
10
11
  const workspace_root_1 = require("../utils/workspace-root");
11
12
  const node_path_1 = require("node:path");
13
+ const task_env_paths_1 = require("./task-env-paths");
12
14
  function getEnvVariablesForBatchProcess(skipNxCache, captureStderr) {
13
15
  return {
14
16
  // User Process Env Variables override Dotenv Variables
@@ -17,11 +19,11 @@ function getEnvVariablesForBatchProcess(skipNxCache, captureStderr) {
17
19
  ...getNxEnvVariablesForForkedProcess(process.env.FORCE_COLOR === undefined ? 'true' : process.env.FORCE_COLOR, skipNxCache, captureStderr),
18
20
  };
19
21
  }
20
- function getTaskSpecificEnv(task) {
22
+ function getTaskSpecificEnv(task, graph) {
21
23
  // Unload any dot env files at the root of the workspace that were loaded on init of Nx.
22
24
  const taskEnv = unloadDotEnvFiles({ ...process.env });
23
25
  return process.env.NX_LOAD_DOT_ENV_FILES === 'true'
24
- ? loadDotEnvFilesForTask(task, taskEnv)
26
+ ? loadDotEnvFilesForTask(task, graph, taskEnv)
25
27
  : // If not loading dot env files, ensure env vars created by system are still loaded
26
28
  taskEnv;
27
29
  }
@@ -110,56 +112,30 @@ function unloadDotEnvFile(filename, environmentVariables, override = false) {
110
112
  }
111
113
  });
112
114
  }
113
- function getEnvFilesForTask(task) {
114
- // Collect dot env files that may pertain to a task
115
- return [
116
- // Load DotEnv Files for a configuration in the project root
117
- ...(task.target.configuration
118
- ? [
119
- `${task.projectRoot}/.env.${task.target.target}.${task.target.configuration}.local`,
120
- `${task.projectRoot}/.env.${task.target.target}.${task.target.configuration}`,
121
- `${task.projectRoot}/.env.${task.target.configuration}.local`,
122
- `${task.projectRoot}/.env.${task.target.configuration}`,
123
- `${task.projectRoot}/.${task.target.target}.${task.target.configuration}.local.env`,
124
- `${task.projectRoot}/.${task.target.target}.${task.target.configuration}.env`,
125
- `${task.projectRoot}/.${task.target.configuration}.local.env`,
126
- `${task.projectRoot}/.${task.target.configuration}.env`,
127
- ]
128
- : []),
129
- // Load DotEnv Files for a target in the project root
130
- `${task.projectRoot}/.env.${task.target.target}.local`,
131
- `${task.projectRoot}/.env.${task.target.target}`,
132
- `${task.projectRoot}/.${task.target.target}.local.env`,
133
- `${task.projectRoot}/.${task.target.target}.env`,
134
- `${task.projectRoot}/.env.local`,
135
- `${task.projectRoot}/.local.env`,
136
- `${task.projectRoot}/.env`,
137
- // Load DotEnv Files for a configuration in the workspace root
138
- ...(task.target.configuration
139
- ? [
140
- `.env.${task.target.target}.${task.target.configuration}.local`,
141
- `.env.${task.target.target}.${task.target.configuration}`,
142
- `.env.${task.target.configuration}.local`,
143
- `.env.${task.target.configuration}`,
144
- `.${task.target.target}.${task.target.configuration}.local.env`,
145
- `.${task.target.target}.${task.target.configuration}.env`,
146
- `.${task.target.configuration}.local.env`,
147
- `.${task.target.configuration}.env`,
148
- ]
149
- : []),
150
- // Load DotEnv Files for a target in the workspace root
151
- `.env.${task.target.target}.local`,
152
- `.env.${task.target.target}`,
153
- `.${task.target.target}.local.env`,
154
- `.${task.target.target}.env`,
155
- // Load base DotEnv Files at workspace root
156
- `.local.env`,
157
- `.env.local`,
158
- `.env`,
159
- ];
115
+ function getOwnerTargetForTask(task, graph) {
116
+ const project = graph.nodes[task.target.project];
117
+ if (project.data.metadata?.targetGroups) {
118
+ for (const targets of Object.values(project.data.metadata.targetGroups)) {
119
+ if (targets.includes(task.target.target)) {
120
+ for (const target of targets) {
121
+ if (project.data.targets[target].metadata?.nonAtomizedTarget) {
122
+ return [
123
+ target,
124
+ project.data.targets[target].metadata?.nonAtomizedTarget,
125
+ ];
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ return [task.target.target];
132
+ }
133
+ function getEnvFilesForTask(task, graph) {
134
+ const [target, nonAtomizedTarget] = getOwnerTargetForTask(task, graph);
135
+ return (0, task_env_paths_1.getEnvPathsForTask)(task.projectRoot, target, task.target.configuration, nonAtomizedTarget);
160
136
  }
161
- function loadDotEnvFilesForTask(task, environmentVariables) {
162
- const dotEnvFiles = getEnvFilesForTask(task);
137
+ function loadDotEnvFilesForTask(task, graph, environmentVariables) {
138
+ const dotEnvFiles = getEnvFilesForTask(task, graph);
163
139
  for (const file of dotEnvFiles) {
164
140
  loadAndExpandDotEnvFile((0, node_path_1.join)(workspace_root_1.workspaceRoot, file), environmentVariables);
165
141
  }
@@ -146,7 +146,7 @@ class TaskOrchestrator {
146
146
  // region Processing Scheduled Tasks
147
147
  async processTask(taskId) {
148
148
  const task = this.taskGraph.tasks[taskId];
149
- const taskSpecificEnv = (0, task_env_1.getTaskSpecificEnv)(task);
149
+ const taskSpecificEnv = (0, task_env_1.getTaskSpecificEnv)(task, this.projectGraph);
150
150
  if (!task.hash) {
151
151
  await (0, hash_task_1.hashTask)(this.hasher, this.projectGraph, this.taskGraphForHashing, task, taskSpecificEnv, this.taskDetails);
152
152
  }