nx 19.4.0-canary.20240626-3a2e8d4 → 19.4.0-canary.20240628-336d371

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 (39) hide show
  1. package/package.json +14 -14
  2. package/src/command-line/connect/connect-to-nx-cloud.d.ts +1 -1
  3. package/src/command-line/connect/connect-to-nx-cloud.js +16 -25
  4. package/src/command-line/graph/graph.d.ts +1 -0
  5. package/src/command-line/graph/graph.js +46 -2
  6. package/src/command-line/run/command-object.js +2 -1
  7. package/src/config/workspace-json-project-json.d.ts +8 -0
  8. package/src/core/graph/main.js +1 -1
  9. package/src/core/graph/styles.css +1 -1
  10. package/src/daemon/socket-utils.d.ts +1 -0
  11. package/src/daemon/socket-utils.js +6 -1
  12. package/src/executors/run-commands/run-commands.impl.d.ts +1 -1
  13. package/src/executors/run-commands/run-commands.impl.js +26 -15
  14. package/src/executors/run-commands/schema.json +14 -0
  15. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.d.ts +1 -0
  16. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +68 -33
  17. package/src/nx-cloud/generators/connect-to-nx-cloud/schema.json +5 -0
  18. package/src/nx-cloud/utilities/url-shorten.d.ts +2 -1
  19. package/src/nx-cloud/utilities/url-shorten.js +42 -14
  20. package/src/plugins/js/index.js +2 -0
  21. package/src/plugins/js/package-json/create-package-json.js +2 -2
  22. package/src/plugins/js/utils/register.js +38 -0
  23. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +9 -2
  24. package/src/plugins/target-defaults/target-defaults-plugin.d.ts +40 -0
  25. package/src/project-graph/plugins/internal-api.js +1 -1
  26. package/src/project-graph/plugins/isolation/index.d.ts +1 -1
  27. package/src/project-graph/plugins/isolation/index.js +3 -15
  28. package/src/project-graph/plugins/isolation/messaging.d.ts +6 -3
  29. package/src/project-graph/plugins/isolation/messaging.js +9 -3
  30. package/src/project-graph/plugins/isolation/plugin-pool.d.ts +1 -1
  31. package/src/project-graph/plugins/isolation/plugin-pool.js +126 -50
  32. package/src/project-graph/plugins/isolation/plugin-worker.js +128 -107
  33. package/src/tasks-runner/task-env.d.ts +13 -0
  34. package/src/tasks-runner/task-env.js +41 -26
  35. package/src/utils/git-utils.d.ts +1 -1
  36. package/src/utils/git-utils.js +13 -2
  37. package/src/utils/is-ci.js +1 -0
  38. package/src/utils/nx-cloud-utils.d.ts +1 -1
  39. package/src/utils/nx-cloud-utils.js +1 -1
@@ -3,116 +3,137 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const messaging_1 = require("./messaging");
4
4
  const loader_1 = require("../loader");
5
5
  const serializable_error_1 = require("../../../utils/serializable-error");
6
+ const net_1 = require("net");
7
+ const consume_messages_from_socket_1 = require("../../../utils/consume-messages-from-socket");
8
+ const fs_1 = require("fs");
6
9
  if (process.env.NX_PERF_LOGGING === 'true') {
7
10
  require('../../../utils/perf-logging');
8
11
  }
9
12
  global.NX_GRAPH_CREATION = true;
10
13
  let plugin;
11
- process.on('message', async (message) => {
12
- if (!(0, messaging_1.isPluginWorkerMessage)(message)) {
13
- return;
14
- }
15
- return (0, messaging_1.consumeMessage)(message, {
16
- load: async ({ plugin: pluginConfiguration, root }) => {
17
- process.chdir(root);
18
- try {
19
- const [promise] = (0, loader_1.loadNxPlugin)(pluginConfiguration, root);
20
- plugin = await promise;
21
- return {
22
- type: 'load-result',
23
- payload: {
24
- name: plugin.name,
25
- include: plugin.include,
26
- exclude: plugin.exclude,
27
- createNodesPattern: plugin.createNodes?.[0],
28
- hasCreateDependencies: 'createDependencies' in plugin && !!plugin.createDependencies,
29
- hasProcessProjectGraph: 'processProjectGraph' in plugin && !!plugin.processProjectGraph,
30
- hasCreateMetadata: 'createMetadata' in plugin && !!plugin.createMetadata,
31
- success: true,
32
- },
33
- };
34
- }
35
- catch (e) {
36
- return {
37
- type: 'load-result',
38
- payload: {
39
- success: false,
40
- error: (0, serializable_error_1.createSerializableError)(e),
41
- },
42
- };
43
- }
44
- },
45
- createNodes: async ({ configFiles, context, tx }) => {
46
- try {
47
- const result = await plugin.createNodes[1](configFiles, context);
48
- return {
49
- type: 'createNodesResult',
50
- payload: { result, success: true, tx },
51
- };
52
- }
53
- catch (e) {
54
- return {
55
- type: 'createNodesResult',
56
- payload: {
57
- success: false,
58
- error: (0, serializable_error_1.createSerializableError)(e),
59
- tx,
60
- },
61
- };
62
- }
63
- },
64
- createDependencies: async ({ context, tx }) => {
65
- try {
66
- const result = await plugin.createDependencies(context);
67
- return {
68
- type: 'createDependenciesResult',
69
- payload: { dependencies: result, success: true, tx },
70
- };
71
- }
72
- catch (e) {
73
- return {
74
- type: 'createDependenciesResult',
75
- payload: {
76
- success: false,
77
- error: (0, serializable_error_1.createSerializableError)(e),
78
- tx,
79
- },
80
- };
81
- }
82
- },
83
- processProjectGraph: async ({ graph, ctx, tx }) => {
84
- try {
85
- const result = await plugin.processProjectGraph(graph, ctx);
86
- return {
87
- type: 'processProjectGraphResult',
88
- payload: { graph: result, success: true, tx },
89
- };
90
- }
91
- catch (e) {
92
- return {
93
- type: 'processProjectGraphResult',
94
- payload: {
95
- success: false,
96
- error: (0, serializable_error_1.createSerializableError)(e),
97
- tx,
98
- },
99
- };
100
- }
101
- },
102
- createMetadata: async ({ graph, context, tx }) => {
103
- try {
104
- const result = await plugin.createMetadata(graph, context);
105
- return {
106
- type: 'createMetadataResult',
107
- payload: { metadata: result, success: true, tx },
108
- };
109
- }
110
- catch (e) {
111
- return {
112
- type: 'createMetadataResult',
113
- payload: { success: false, error: e.stack, tx },
114
- };
115
- }
116
- },
117
- });
14
+ const socketPath = process.argv[2];
15
+ const server = (0, net_1.createServer)((socket) => {
16
+ socket.on('data', (0, consume_messages_from_socket_1.consumeMessagesFromSocket)((raw) => {
17
+ const message = JSON.parse(raw.toString());
18
+ if (!(0, messaging_1.isPluginWorkerMessage)(message)) {
19
+ return;
20
+ }
21
+ return (0, messaging_1.consumeMessage)(socket, message, {
22
+ load: async ({ plugin: pluginConfiguration, root }) => {
23
+ process.chdir(root);
24
+ try {
25
+ const [promise] = (0, loader_1.loadNxPlugin)(pluginConfiguration, root);
26
+ plugin = await promise;
27
+ return {
28
+ type: 'load-result',
29
+ payload: {
30
+ name: plugin.name,
31
+ include: plugin.include,
32
+ exclude: plugin.exclude,
33
+ createNodesPattern: plugin.createNodes?.[0],
34
+ hasCreateDependencies: 'createDependencies' in plugin && !!plugin.createDependencies,
35
+ hasProcessProjectGraph: 'processProjectGraph' in plugin &&
36
+ !!plugin.processProjectGraph,
37
+ hasCreateMetadata: 'createMetadata' in plugin && !!plugin.createMetadata,
38
+ success: true,
39
+ },
40
+ };
41
+ }
42
+ catch (e) {
43
+ return {
44
+ type: 'load-result',
45
+ payload: {
46
+ success: false,
47
+ error: (0, serializable_error_1.createSerializableError)(e),
48
+ },
49
+ };
50
+ }
51
+ },
52
+ createNodes: async ({ configFiles, context, tx }) => {
53
+ try {
54
+ const result = await plugin.createNodes[1](configFiles, context);
55
+ return {
56
+ type: 'createNodesResult',
57
+ payload: { result, success: true, tx },
58
+ };
59
+ }
60
+ catch (e) {
61
+ return {
62
+ type: 'createNodesResult',
63
+ payload: {
64
+ success: false,
65
+ error: (0, serializable_error_1.createSerializableError)(e),
66
+ tx,
67
+ },
68
+ };
69
+ }
70
+ },
71
+ createDependencies: async ({ context, tx }) => {
72
+ try {
73
+ const result = await plugin.createDependencies(context);
74
+ return {
75
+ type: 'createDependenciesResult',
76
+ payload: { dependencies: result, success: true, tx },
77
+ };
78
+ }
79
+ catch (e) {
80
+ return {
81
+ type: 'createDependenciesResult',
82
+ payload: {
83
+ success: false,
84
+ error: (0, serializable_error_1.createSerializableError)(e),
85
+ tx,
86
+ },
87
+ };
88
+ }
89
+ },
90
+ processProjectGraph: async ({ graph, ctx, tx }) => {
91
+ try {
92
+ const result = await plugin.processProjectGraph(graph, ctx);
93
+ return {
94
+ type: 'processProjectGraphResult',
95
+ payload: { graph: result, success: true, tx },
96
+ };
97
+ }
98
+ catch (e) {
99
+ return {
100
+ type: 'processProjectGraphResult',
101
+ payload: {
102
+ success: false,
103
+ error: (0, serializable_error_1.createSerializableError)(e),
104
+ tx,
105
+ },
106
+ };
107
+ }
108
+ },
109
+ createMetadata: async ({ graph, context, tx }) => {
110
+ try {
111
+ const result = await plugin.createMetadata(graph, context);
112
+ return {
113
+ type: 'createMetadataResult',
114
+ payload: { metadata: result, success: true, tx },
115
+ };
116
+ }
117
+ catch (e) {
118
+ return {
119
+ type: 'createMetadataResult',
120
+ payload: { success: false, error: e.stack, tx },
121
+ };
122
+ }
123
+ },
124
+ });
125
+ }));
118
126
  });
127
+ server.listen(socketPath);
128
+ const exitHandler = (exitCode) => () => {
129
+ server.close();
130
+ try {
131
+ (0, fs_1.unlinkSync)(socketPath);
132
+ }
133
+ catch (e) { }
134
+ process.exit(exitCode);
135
+ };
136
+ const events = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'exit'];
137
+ events.forEach((event) => process.once(event, exitHandler(0)));
138
+ process.once('uncaughtException', exitHandler(1));
139
+ process.once('unhandledRejection', exitHandler(1));
@@ -6,3 +6,16 @@ export declare function getEnvVariablesForTask(task: Task, taskSpecificEnv: Node
6
6
  [x: string]: string;
7
7
  TZ?: string;
8
8
  };
9
+ /**
10
+ * This function loads a .env file and expands the variables in it.
11
+ * It is going to override existing environmentVariables.
12
+ * @param filename
13
+ * @param environmentVariables
14
+ */
15
+ export declare function loadAndExpandDotEnvFile(filename: string, environmentVariables: NodeJS.ProcessEnv, override?: boolean): import("dotenv-expand").DotenvExpandOutput;
16
+ /**
17
+ * This function unloads a .env file and removes the variables in it from the environmentVariables.
18
+ * @param filename
19
+ * @param environmentVariables
20
+ */
21
+ export declare function unloadDotEnvFile(filename: string, environmentVariables: NodeJS.ProcessEnv, override?: boolean): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEnvVariablesForTask = exports.getTaskSpecificEnv = exports.getEnvVariablesForBatchProcess = void 0;
3
+ exports.unloadDotEnvFile = exports.loadAndExpandDotEnvFile = exports.getEnvVariablesForTask = exports.getTaskSpecificEnv = exports.getEnvVariablesForBatchProcess = void 0;
4
4
  const dotenv_1 = require("dotenv");
5
5
  const dotenv_expand_1 = require("dotenv-expand");
6
6
  const workspace_root_1 = require("../utils/workspace-root");
@@ -75,9 +75,42 @@ function getNxEnvVariablesForTask(task, forceColor, skipNxCache, captureStderr,
75
75
  ...env,
76
76
  };
77
77
  }
78
- function loadDotEnvFilesForTask(task, environmentVariables) {
78
+ /**
79
+ * This function loads a .env file and expands the variables in it.
80
+ * It is going to override existing environmentVariables.
81
+ * @param filename
82
+ * @param environmentVariables
83
+ */
84
+ function loadAndExpandDotEnvFile(filename, environmentVariables, override = false) {
85
+ const myEnv = (0, dotenv_1.config)({
86
+ path: filename,
87
+ processEnv: environmentVariables,
88
+ override,
89
+ });
90
+ return (0, dotenv_expand_1.expand)({
91
+ ...myEnv,
92
+ processEnv: environmentVariables,
93
+ });
94
+ }
95
+ exports.loadAndExpandDotEnvFile = loadAndExpandDotEnvFile;
96
+ /**
97
+ * This function unloads a .env file and removes the variables in it from the environmentVariables.
98
+ * @param filename
99
+ * @param environmentVariables
100
+ */
101
+ function unloadDotEnvFile(filename, environmentVariables, override = false) {
102
+ const parsedDotEnvFile = {};
103
+ loadAndExpandDotEnvFile(filename, parsedDotEnvFile, override);
104
+ Object.keys(parsedDotEnvFile).forEach((envVarKey) => {
105
+ if (environmentVariables[envVarKey] === parsedDotEnvFile[envVarKey]) {
106
+ delete environmentVariables[envVarKey];
107
+ }
108
+ });
109
+ }
110
+ exports.unloadDotEnvFile = unloadDotEnvFile;
111
+ function getEnvFilesForTask(task) {
79
112
  // Collect dot env files that may pertain to a task
80
- const dotEnvFiles = [
113
+ return [
81
114
  // Load DotEnv Files for a configuration in the project root
82
115
  ...(task.target.configuration
83
116
  ? [
@@ -122,35 +155,17 @@ function loadDotEnvFilesForTask(task, environmentVariables) {
122
155
  `.env.local`,
123
156
  `.env`,
124
157
  ];
158
+ }
159
+ function loadDotEnvFilesForTask(task, environmentVariables) {
160
+ const dotEnvFiles = getEnvFilesForTask(task);
125
161
  for (const file of dotEnvFiles) {
126
- const myEnv = (0, dotenv_1.config)({
127
- path: file,
128
- processEnv: environmentVariables,
129
- // Do not override existing env variables as we load
130
- override: false,
131
- });
132
- environmentVariables = {
133
- ...(0, dotenv_expand_1.expand)({
134
- ...myEnv,
135
- ignoreProcessEnv: true, // Do not override existing env variables as we load
136
- }).parsed,
137
- ...environmentVariables,
138
- };
162
+ loadAndExpandDotEnvFile(file, environmentVariables);
139
163
  }
140
164
  return environmentVariables;
141
165
  }
142
166
  function unloadDotEnvFiles(environmentVariables) {
143
- const unloadDotEnvFile = (filename) => {
144
- let parsedDotEnvFile = {};
145
- (0, dotenv_1.config)({ path: filename, processEnv: parsedDotEnvFile });
146
- Object.keys(parsedDotEnvFile).forEach((envVarKey) => {
147
- if (environmentVariables[envVarKey] === parsedDotEnvFile[envVarKey]) {
148
- delete environmentVariables[envVarKey];
149
- }
150
- });
151
- };
152
167
  for (const file of ['.env', '.local.env', '.env.local']) {
153
- unloadDotEnvFile(file);
168
+ unloadDotEnvFile(file, environmentVariables);
154
169
  }
155
170
  return environmentVariables;
156
171
  }
@@ -1,4 +1,4 @@
1
1
  export declare function getGithubSlugOrNull(): string | null;
2
2
  export declare function extractUserAndRepoFromGitHubUrl(gitRemotes: string): string | null;
3
- export declare function commitChanges(commitMessage: string): string | null;
3
+ export declare function commitChanges(commitMessage: string, directory?: string): string | null;
4
4
  export declare function getLatestCommitSha(): string | null;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLatestCommitSha = exports.commitChanges = exports.extractUserAndRepoFromGitHubUrl = exports.getGithubSlugOrNull = void 0;
4
4
  const child_process_1 = require("child_process");
5
+ const devkit_exports_1 = require("../devkit-exports");
5
6
  function getGithubSlugOrNull() {
6
7
  try {
7
8
  const gitRemote = (0, child_process_1.execSync)('git remote -v').toString();
@@ -38,17 +39,27 @@ function parseGitHubUrl(url) {
38
39
  }
39
40
  return null;
40
41
  }
41
- function commitChanges(commitMessage) {
42
+ function commitChanges(commitMessage, directory) {
42
43
  try {
43
44
  (0, child_process_1.execSync)('git add -A', { encoding: 'utf8', stdio: 'pipe' });
44
45
  (0, child_process_1.execSync)('git commit --no-verify -F -', {
45
46
  encoding: 'utf8',
46
47
  stdio: 'pipe',
47
48
  input: commitMessage,
49
+ cwd: directory,
48
50
  });
49
51
  }
50
52
  catch (err) {
51
- throw new Error(`Error committing changes:\n${err.stderr}`);
53
+ if (directory) {
54
+ // We don't want to throw during create-nx-workspace
55
+ // because maybe there was an error when setting up git
56
+ // initially.
57
+ devkit_exports_1.logger.verbose(`Git may not be set up correctly for this new workspace.
58
+ ${err}`);
59
+ }
60
+ else {
61
+ throw new Error(`Error committing changes:\n${err.stderr}`);
62
+ }
52
63
  }
53
64
  return getLatestCommitSha();
54
65
  }
@@ -10,6 +10,7 @@ function isCI() {
10
10
  process.env.CIRRUS_CI === 'true' ||
11
11
  process.env.TRAVIS === 'true' ||
12
12
  !!process.env['bamboo.buildKey'] ||
13
+ !!process.env['bamboo_buildKey'] ||
13
14
  !!process.env.CODEBUILD_BUILD_ID ||
14
15
  !!process.env.GITLAB_CI ||
15
16
  !!process.env.HEROKU_TEST_RUN_ID ||
@@ -1,4 +1,4 @@
1
1
  import { NxJsonConfiguration } from '../config/nx-json';
2
- export declare function isNxCloudUsed(nxJson: NxJsonConfiguration): string | boolean;
2
+ export declare function isNxCloudUsed(nxJson: NxJsonConfiguration): boolean;
3
3
  export declare function getNxCloudUrl(nxJson: NxJsonConfiguration): string;
4
4
  export declare function getNxCloudToken(nxJson: NxJsonConfiguration): string;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNxCloudToken = exports.getNxCloudUrl = exports.isNxCloudUsed = void 0;
4
4
  function isNxCloudUsed(nxJson) {
5
- return (process.env.NX_CLOUD_ACCESS_TOKEN ||
5
+ return (!!process.env.NX_CLOUD_ACCESS_TOKEN ||
6
6
  !!nxJson.nxCloudAccessToken ||
7
7
  !!Object.values(nxJson.tasksRunnerOptions ?? {}).find((r) => r.runner == '@nrwl/nx-cloud' || r.runner == 'nx-cloud'));
8
8
  }