nx 18.3.1 → 18.3.2

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.
Files changed (31) hide show
  1. package/.eslintrc.json +4 -0
  2. package/bin/nx.js +7 -19
  3. package/package.json +12 -12
  4. package/src/command-line/add/add.js +3 -1
  5. package/src/command-line/add/command-object.d.ts +1 -0
  6. package/src/command-line/add/command-object.js +6 -1
  7. package/src/command-line/init/implementation/react/check-for-uncommitted-changes.js +6 -3
  8. package/src/daemon/cache.js +18 -0
  9. package/src/daemon/client/client.js +3 -4
  10. package/src/daemon/server/handle-hash-tasks.js +2 -2
  11. package/src/daemon/server/project-graph-incremental-recomputation.js +1 -2
  12. package/src/daemon/socket-utils.js +2 -2
  13. package/src/native/index.d.ts +1 -4
  14. package/src/native/index.js +67 -259
  15. package/src/native/native-bindings.js +268 -0
  16. package/src/native/transform-objects.js +1 -0
  17. package/src/project-graph/error-types.d.ts +27 -1
  18. package/src/project-graph/error-types.js +52 -1
  19. package/src/project-graph/plugins/isolation/index.js +8 -4
  20. package/src/project-graph/plugins/isolation/plugin-pool.d.ts +1 -1
  21. package/src/project-graph/plugins/isolation/plugin-pool.js +4 -10
  22. package/src/project-graph/project-graph.d.ts +2 -24
  23. package/src/project-graph/project-graph.js +11 -52
  24. package/src/project-graph/utils/retrieve-workspace-files.d.ts +3 -3
  25. package/src/tasks-runner/init-tasks-runner.js +2 -0
  26. package/src/tasks-runner/task-orchestrator.js +47 -29
  27. package/src/utils/dotenv.d.ts +7 -0
  28. package/src/utils/dotenv.js +22 -0
  29. package/src/utils/params.js +20 -17
  30. package/src/daemon/daemon-project-graph-error.d.ts +0 -8
  31. package/src/daemon/daemon-project-graph-error.js +0 -13
@@ -214,37 +214,55 @@ class TaskOrchestrator {
214
214
  if (process.env.NX_RUN_COMMANDS_DIRECTLY !== 'false' &&
215
215
  targetConfiguration.executor === 'nx:run-commands' &&
216
216
  !shouldPrefix) {
217
- const { schema } = (0, utils_1.getExecutorForTask)(task, this.projectGraph);
218
- const isRunOne = this.initiatingProject != null;
219
- const combinedOptions = (0, params_1.combineOptionsForExecutor)(task.overrides, task.target.configuration ?? targetConfiguration.defaultConfiguration, targetConfiguration, schema, task.target.project, (0, path_1.relative)(task.projectRoot ?? workspace_root_1.workspaceRoot, process.cwd()), process.env.NX_VERBOSE_LOGGING === 'true');
220
- if (combinedOptions.env) {
221
- env = {
222
- ...env,
223
- ...combinedOptions.env,
224
- };
225
- }
226
- if (streamOutput) {
227
- const args = (0, utils_1.getPrintableCommandArgsForTask)(task);
228
- output_1.output.logCommand(args.join(' '));
217
+ try {
218
+ const { schema } = (0, utils_1.getExecutorForTask)(task, this.projectGraph);
219
+ const isRunOne = this.initiatingProject != null;
220
+ const combinedOptions = (0, params_1.combineOptionsForExecutor)(task.overrides, task.target.configuration ??
221
+ targetConfiguration.defaultConfiguration, targetConfiguration, schema, task.target.project, (0, path_1.relative)(task.projectRoot ?? workspace_root_1.workspaceRoot, process.cwd()), process.env.NX_VERBOSE_LOGGING === 'true');
222
+ if (combinedOptions.env) {
223
+ env = {
224
+ ...env,
225
+ ...combinedOptions.env,
226
+ };
227
+ }
228
+ if (streamOutput) {
229
+ const args = (0, utils_1.getPrintableCommandArgsForTask)(task);
230
+ output_1.output.logCommand(args.join(' '));
231
+ }
232
+ const { success, terminalOutput } = await (0, run_commands_impl_1.default)({
233
+ ...combinedOptions,
234
+ env,
235
+ usePty: isRunOne && !this.tasksSchedule.hasTasks(),
236
+ streamOutput,
237
+ }, {
238
+ root: workspace_root_1.workspaceRoot, // only root is needed in runCommandsImpl
239
+ });
240
+ const status = success ? 'success' : 'failure';
241
+ if (!streamOutput) {
242
+ this.options.lifeCycle.printTaskTerminalOutput(task, status, terminalOutput);
243
+ }
244
+ (0, fs_1.writeFileSync)(temporaryOutputPath, terminalOutput);
245
+ results.push({
246
+ task,
247
+ status,
248
+ terminalOutput,
249
+ });
229
250
  }
230
- const { success, terminalOutput } = await (0, run_commands_impl_1.default)({
231
- ...combinedOptions,
232
- env,
233
- usePty: isRunOne && !this.tasksSchedule.hasTasks(),
234
- streamOutput,
235
- }, {
236
- root: workspace_root_1.workspaceRoot, // only root is needed in runCommandsImpl
237
- });
238
- const status = success ? 'success' : 'failure';
239
- if (!streamOutput) {
240
- this.options.lifeCycle.printTaskTerminalOutput(task, status, terminalOutput);
251
+ catch (e) {
252
+ if (process.env.NX_VERBOSE_LOGGING === 'true') {
253
+ console.error(e);
254
+ }
255
+ else {
256
+ console.error(e.message);
257
+ }
258
+ const terminalOutput = e.stack ?? e.message ?? '';
259
+ (0, fs_1.writeFileSync)(temporaryOutputPath, terminalOutput);
260
+ results.push({
261
+ task,
262
+ status: 'failure',
263
+ terminalOutput,
264
+ });
241
265
  }
242
- (0, fs_1.writeFileSync)(temporaryOutputPath, terminalOutput);
243
- results.push({
244
- task,
245
- status,
246
- terminalOutput,
247
- });
248
266
  }
249
267
  else {
250
268
  // cache prep
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This loads dotenv files from:
3
+ * - .env
4
+ * - .local.env
5
+ * - .env.local
6
+ */
7
+ export declare function loadRootEnvFiles(root?: string): void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadRootEnvFiles = void 0;
4
+ const dotenv_1 = require("dotenv");
5
+ const dotenv_expand_1 = require("dotenv-expand");
6
+ const workspace_root_1 = require("./workspace-root");
7
+ const path_1 = require("path");
8
+ /**
9
+ * This loads dotenv files from:
10
+ * - .env
11
+ * - .local.env
12
+ * - .env.local
13
+ */
14
+ function loadRootEnvFiles(root = workspace_root_1.workspaceRoot) {
15
+ for (const file of ['.local.env', '.env.local', '.env']) {
16
+ const myEnv = (0, dotenv_1.config)({
17
+ path: (0, path_1.join)(root, file),
18
+ });
19
+ (0, dotenv_expand_1.expand)(myEnv);
20
+ }
21
+ }
22
+ exports.loadRootEnvFiles = loadRootEnvFiles;
@@ -176,26 +176,29 @@ function validateObject(opts, schema, definitions) {
176
176
  }
177
177
  }
178
178
  if (schema.oneOf) {
179
- for (const s of schema.oneOf) {
180
- const errors = [];
181
- for (const s of schema.oneOf) {
182
- try {
183
- validateObject(opts, s, definitions);
184
- }
185
- catch (e) {
186
- errors.push(e);
187
- }
188
- }
189
- if (errors.length === schema.oneOf.length) {
190
- throw new Error(`Options did not match schema. Please fix 1 of the following errors:\n${errors
191
- .map((e) => ' - ' + e.message)
192
- .join('\n')}`);
179
+ const matches = [];
180
+ const errors = [];
181
+ for (const propertyDescription of schema.oneOf) {
182
+ try {
183
+ validateObject(opts, propertyDescription, definitions);
184
+ matches.push(propertyDescription);
193
185
  }
194
- if (errors.length < schema.oneOf.length - 1) {
195
- // TODO: This error could be better.
196
- throw new Error(`Options did not match schema.`);
186
+ catch (error) {
187
+ errors.push(error);
197
188
  }
198
189
  }
190
+ // If the options matched none of the oneOf property descriptions
191
+ if (matches.length === 0) {
192
+ throw new Error(`Options did not match schema: ${JSON.stringify(opts, null, 2)}.\nPlease fix 1 of the following errors:\n${errors
193
+ .map((e) => ' - ' + e.message)
194
+ .join('\n')}`);
195
+ }
196
+ // If the options matched none of the oneOf property descriptions
197
+ if (matches.length > 1) {
198
+ throw new Error(`Options did not match schema: ${JSON.stringify(opts, null, 2)}.\nShould only match one of \n${matches
199
+ .map((m) => ' - ' + JSON.stringify(m))
200
+ .join('\n')}`);
201
+ }
199
202
  }
200
203
  (schema.required ?? []).forEach((p) => {
201
204
  if (opts[p] === undefined) {
@@ -1,8 +0,0 @@
1
- import { ProjectGraph } from '../config/project-graph';
2
- import { ConfigurationSourceMaps } from '../project-graph/utils/project-configuration-utils';
3
- export declare class DaemonProjectGraphError extends Error {
4
- errors: any[];
5
- readonly projectGraph: ProjectGraph;
6
- readonly sourceMaps: ConfigurationSourceMaps;
7
- constructor(errors: any[], projectGraph: ProjectGraph, sourceMaps: ConfigurationSourceMaps);
8
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DaemonProjectGraphError = void 0;
4
- class DaemonProjectGraphError extends Error {
5
- constructor(errors, projectGraph, sourceMaps) {
6
- super(`The Daemon Process threw an error while calculating the project graph. Convert this error to a ProjectGraphError to get more information.`);
7
- this.errors = errors;
8
- this.projectGraph = projectGraph;
9
- this.sourceMaps = sourceMaps;
10
- this.name = this.constructor.name;
11
- }
12
- }
13
- exports.DaemonProjectGraphError = DaemonProjectGraphError;