nx 19.2.0-beta.5 → 19.2.0-beta.7

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 (57) hide show
  1. package/bin/post-install.js +8 -8
  2. package/package.json +12 -12
  3. package/src/command-line/deprecated/command-objects.js +2 -1
  4. package/src/command-line/examples.js +59 -5
  5. package/src/command-line/graph/command-object.d.ts +25 -2
  6. package/src/command-line/graph/command-object.js +57 -3
  7. package/src/command-line/graph/graph.js +2 -1
  8. package/src/command-line/init/implementation/react/index.js +1 -1
  9. package/src/command-line/init/implementation/react/rename-js-to-jsx.d.ts +1 -1
  10. package/src/command-line/init/implementation/react/rename-js-to-jsx.js +2 -2
  11. package/src/command-line/init/init-v2.js +1 -1
  12. package/src/command-line/nx-commands.js +1 -1
  13. package/src/command-line/yargs-utils/shared-options.d.ts +0 -21
  14. package/src/command-line/yargs-utils/shared-options.js +2 -52
  15. package/src/daemon/client/client.d.ts +6 -0
  16. package/src/daemon/client/client.js +45 -2
  17. package/src/daemon/is-on-daemon.d.ts +1 -0
  18. package/src/daemon/is-on-daemon.js +7 -0
  19. package/src/daemon/message-types/get-context-file-data.d.ts +5 -0
  20. package/src/daemon/message-types/get-context-file-data.js +11 -0
  21. package/src/daemon/message-types/get-files-in-directory.d.ts +6 -0
  22. package/src/daemon/message-types/get-files-in-directory.js +11 -0
  23. package/src/daemon/message-types/get-nx-workspace-files.d.ts +6 -0
  24. package/src/daemon/message-types/get-nx-workspace-files.js +11 -0
  25. package/src/daemon/message-types/glob.d.ts +7 -0
  26. package/src/daemon/message-types/glob.js +11 -0
  27. package/src/daemon/message-types/hash-glob.d.ts +7 -0
  28. package/src/daemon/message-types/hash-glob.js +11 -0
  29. package/src/daemon/message-types/update-context-files.d.ts +7 -0
  30. package/src/daemon/message-types/update-context-files.js +11 -0
  31. package/src/daemon/server/handle-context-file-data.d.ts +2 -0
  32. package/src/daemon/server/handle-context-file-data.js +13 -0
  33. package/src/daemon/server/handle-get-files-in-directory.d.ts +2 -0
  34. package/src/daemon/server/handle-get-files-in-directory.js +13 -0
  35. package/src/daemon/server/handle-glob.d.ts +2 -0
  36. package/src/daemon/server/handle-glob.js +13 -0
  37. package/src/daemon/server/handle-hash-glob.d.ts +2 -0
  38. package/src/daemon/server/handle-hash-glob.js +13 -0
  39. package/src/daemon/server/handle-nx-workspace-files.d.ts +2 -0
  40. package/src/daemon/server/handle-nx-workspace-files.js +13 -0
  41. package/src/daemon/server/plugins.js +1 -0
  42. package/src/daemon/server/server.js +39 -9
  43. package/src/devkit-exports.d.ts +1 -1
  44. package/src/devkit-exports.js +2 -1
  45. package/src/generators/utils/glob.d.ts +11 -0
  46. package/src/generators/utils/glob.js +20 -3
  47. package/src/generators/utils/project-configuration.js +1 -1
  48. package/src/project-graph/file-map-utils.js +1 -8
  49. package/src/project-graph/file-utils.js +33 -34
  50. package/src/project-graph/plugins/isolation/plugin-pool.js +10 -9
  51. package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
  52. package/src/project-graph/utils/retrieve-workspace-files.js +6 -6
  53. package/src/utils/all-file-data.js +1 -7
  54. package/src/utils/workspace-context.d.ts +13 -5
  55. package/src/utils/workspace-context.js +45 -14
  56. package/src/daemon/server/handle-request-file-data.d.ts +0 -4
  57. package/src/daemon/server/handle-request-file-data.js +0 -13
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHandleGlobMessage = exports.GLOB = void 0;
4
+ exports.GLOB = 'GLOB';
5
+ function isHandleGlobMessage(message) {
6
+ return (typeof message === 'object' &&
7
+ message !== null &&
8
+ 'type' in message &&
9
+ message['type'] === exports.GLOB);
10
+ }
11
+ exports.isHandleGlobMessage = isHandleGlobMessage;
@@ -0,0 +1,7 @@
1
+ export declare const HASH_GLOB: "HASH_GLOB";
2
+ export type HandleHashGlobMessage = {
3
+ type: typeof HASH_GLOB;
4
+ globs: string[];
5
+ exclude?: string[];
6
+ };
7
+ export declare function isHandleHashGlobMessage(message: unknown): message is HandleHashGlobMessage;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHandleHashGlobMessage = exports.HASH_GLOB = void 0;
4
+ exports.HASH_GLOB = 'HASH_GLOB';
5
+ function isHandleHashGlobMessage(message) {
6
+ return (typeof message === 'object' &&
7
+ message !== null &&
8
+ 'type' in message &&
9
+ message['type'] === exports.HASH_GLOB);
10
+ }
11
+ exports.isHandleHashGlobMessage = isHandleHashGlobMessage;
@@ -0,0 +1,7 @@
1
+ export declare const GLOB: "GLOB";
2
+ export type HandleUpdateContextMessage = {
3
+ type: typeof GLOB;
4
+ updatedFiles: string[];
5
+ deletedFiles: string[];
6
+ };
7
+ export declare function isHandleUpdateContextMessage(message: unknown): message is HandleUpdateContextMessage;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHandleUpdateContextMessage = exports.GLOB = void 0;
4
+ exports.GLOB = 'GLOB';
5
+ function isHandleUpdateContextMessage(message) {
6
+ return (typeof message === 'object' &&
7
+ message !== null &&
8
+ 'type' in message &&
9
+ message['type'] === exports.GLOB);
10
+ }
11
+ exports.isHandleUpdateContextMessage = isHandleUpdateContextMessage;
@@ -0,0 +1,2 @@
1
+ import { HandlerResult } from './server';
2
+ export declare function handleContextFileData(): Promise<HandlerResult>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleContextFileData = void 0;
4
+ const workspace_context_1 = require("../../utils/workspace-context");
5
+ const workspace_root_1 = require("../../utils/workspace-root");
6
+ async function handleContextFileData() {
7
+ const files = await (0, workspace_context_1.getAllFileDataInContext)(workspace_root_1.workspaceRoot);
8
+ return {
9
+ response: JSON.stringify(files),
10
+ description: 'handleContextFileData',
11
+ };
12
+ }
13
+ exports.handleContextFileData = handleContextFileData;
@@ -0,0 +1,2 @@
1
+ import { HandlerResult } from './server';
2
+ export declare function handleGetFilesInDirectory(dir: string): Promise<HandlerResult>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleGetFilesInDirectory = void 0;
4
+ const workspace_context_1 = require("../../utils/workspace-context");
5
+ const workspace_root_1 = require("../../utils/workspace-root");
6
+ async function handleGetFilesInDirectory(dir) {
7
+ const files = await (0, workspace_context_1.getFilesInDirectoryUsingContext)(workspace_root_1.workspaceRoot, dir);
8
+ return {
9
+ response: JSON.stringify(files),
10
+ description: 'handleNxWorkspaceFiles',
11
+ };
12
+ }
13
+ exports.handleGetFilesInDirectory = handleGetFilesInDirectory;
@@ -0,0 +1,2 @@
1
+ import { HandlerResult } from './server';
2
+ export declare function handleGlob(globs: string[], exclude?: string[]): Promise<HandlerResult>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleGlob = void 0;
4
+ const workspace_root_1 = require("../../utils/workspace-root");
5
+ const workspace_context_1 = require("../../utils/workspace-context");
6
+ async function handleGlob(globs, exclude) {
7
+ const files = await (0, workspace_context_1.globWithWorkspaceContext)(workspace_root_1.workspaceRoot, globs, exclude);
8
+ return {
9
+ response: JSON.stringify(files),
10
+ description: 'handleGlob',
11
+ };
12
+ }
13
+ exports.handleGlob = handleGlob;
@@ -0,0 +1,2 @@
1
+ import { HandlerResult } from './server';
2
+ export declare function handleHashGlob(globs: string[], exclude?: string[]): Promise<HandlerResult>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleHashGlob = void 0;
4
+ const workspace_root_1 = require("../../utils/workspace-root");
5
+ const workspace_context_1 = require("../../utils/workspace-context");
6
+ async function handleHashGlob(globs, exclude) {
7
+ const files = await (0, workspace_context_1.hashWithWorkspaceContext)(workspace_root_1.workspaceRoot, globs, exclude);
8
+ return {
9
+ response: JSON.stringify(files),
10
+ description: 'handleHashGlob',
11
+ };
12
+ }
13
+ exports.handleHashGlob = handleHashGlob;
@@ -0,0 +1,2 @@
1
+ import { HandlerResult } from './server';
2
+ export declare function handleNxWorkspaceFiles(projectRootMap: Record<string, string>): Promise<HandlerResult>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleNxWorkspaceFiles = void 0;
4
+ const workspace_context_1 = require("../../utils/workspace-context");
5
+ const workspace_root_1 = require("../../utils/workspace-root");
6
+ async function handleNxWorkspaceFiles(projectRootMap) {
7
+ const files = await (0, workspace_context_1.getNxWorkspaceFilesFromContext)(workspace_root_1.workspaceRoot, projectRootMap);
8
+ return {
9
+ response: JSON.stringify(files),
10
+ description: 'handleNxWorkspaceFiles',
11
+ };
12
+ }
13
+ exports.handleNxWorkspaceFiles = handleNxWorkspaceFiles;
@@ -13,6 +13,7 @@ async function getPlugins() {
13
13
  const pluginsConfiguration = (0, nx_json_1.readNxJson)().plugins ?? [];
14
14
  const [result, cleanupFn] = await (0, internal_api_1.loadNxPlugins)(pluginsConfiguration, workspace_root_1.workspaceRoot);
15
15
  cleanup = cleanupFn;
16
+ loadedPlugins = result;
16
17
  return result;
17
18
  }
18
19
  exports.getPlugins = getPlugins;
@@ -18,7 +18,6 @@ const file_watcher_sockets_1 = require("./file-watching/file-watcher-sockets");
18
18
  const handle_hash_tasks_1 = require("./handle-hash-tasks");
19
19
  const handle_outputs_tracking_1 = require("./handle-outputs-tracking");
20
20
  const handle_process_in_background_1 = require("./handle-process-in-background");
21
- const handle_request_file_data_1 = require("./handle-request-file-data");
22
21
  const handle_request_project_graph_1 = require("./handle-request-project-graph");
23
22
  const handle_request_shutdown_1 = require("./handle-request-shutdown");
24
23
  const logger_1 = require("./logger");
@@ -26,9 +25,20 @@ const outputs_tracking_1 = require("./outputs-tracking");
26
25
  const project_graph_incremental_recomputation_1 = require("./project-graph-incremental-recomputation");
27
26
  const shutdown_utils_1 = require("./shutdown-utils");
28
27
  const watcher_1 = require("./watcher");
28
+ const handle_glob_1 = require("./handle-glob");
29
+ const glob_1 = require("../message-types/glob");
30
+ const get_nx_workspace_files_1 = require("../message-types/get-nx-workspace-files");
31
+ const handle_nx_workspace_files_1 = require("./handle-nx-workspace-files");
32
+ const get_context_file_data_1 = require("../message-types/get-context-file-data");
33
+ const handle_context_file_data_1 = require("./handle-context-file-data");
34
+ const get_files_in_directory_1 = require("../message-types/get-files-in-directory");
35
+ const handle_get_files_in_directory_1 = require("./handle-get-files-in-directory");
36
+ const hash_glob_1 = require("../message-types/hash-glob");
37
+ const handle_hash_glob_1 = require("./handle-hash-glob");
29
38
  let performanceObserver;
30
39
  let workspaceWatcherError;
31
40
  let outputsWatcherError;
41
+ global.NX_DAEMON = true;
32
42
  let numberOfOpenConnections = 0;
33
43
  const server = (0, net_1.createServer)(async (socket) => {
34
44
  numberOfOpenConnections += 1;
@@ -59,8 +69,9 @@ async function handleMessage(socket, data) {
59
69
  if (workspaceWatcherError) {
60
70
  await (0, shutdown_utils_1.respondWithErrorAndExit)(socket, `File watcher error in the workspace '${workspace_root_1.workspaceRoot}'.`, workspaceWatcherError);
61
71
  }
62
- if (daemonIsOutdated()) {
63
- await (0, shutdown_utils_1.respondWithErrorAndExit)(socket, `Lock files changed`, new Error('LOCK-FILES-CHANGED'));
72
+ const outdated = daemonIsOutdated();
73
+ if (outdated) {
74
+ await (0, shutdown_utils_1.respondWithErrorAndExit)(socket, `Daemon outdated`, new Error(outdated));
64
75
  }
65
76
  (0, shutdown_utils_1.resetInactivityTimeout)(handleInactivityTimeout);
66
77
  const unparsedPayload = data;
@@ -80,9 +91,6 @@ async function handleMessage(socket, data) {
80
91
  else if (payload.type === 'HASH_TASKS') {
81
92
  await handleResult(socket, 'HASH_TASKS', () => (0, handle_hash_tasks_1.handleHashTasks)(payload));
82
93
  }
83
- else if (payload.type === 'REQUEST_FILE_DATA') {
84
- await handleResult(socket, 'REQUEST_FILE_DATA', () => (0, handle_request_file_data_1.handleRequestFileData)());
85
- }
86
94
  else if (payload.type === 'PROCESS_IN_BACKGROUND') {
87
95
  await handleResult(socket, 'PROCESS_IN_BACKGROUND', () => (0, handle_process_in_background_1.handleProcessInBackground)(payload));
88
96
  }
@@ -98,6 +106,21 @@ async function handleMessage(socket, data) {
98
106
  else if (payload.type === 'REGISTER_FILE_WATCHER') {
99
107
  file_watcher_sockets_1.registeredFileWatcherSockets.push({ socket, config: payload.config });
100
108
  }
109
+ else if ((0, glob_1.isHandleGlobMessage)(payload)) {
110
+ await handleResult(socket, glob_1.GLOB, () => (0, handle_glob_1.handleGlob)(payload.globs, payload.exclude));
111
+ }
112
+ else if ((0, get_nx_workspace_files_1.isHandleNxWorkspaceFilesMessage)(payload)) {
113
+ await handleResult(socket, get_nx_workspace_files_1.GET_NX_WORKSPACE_FILES, () => (0, handle_nx_workspace_files_1.handleNxWorkspaceFiles)(payload.projectRootMap));
114
+ }
115
+ else if ((0, get_files_in_directory_1.isHandleGetFilesInDirectoryMessage)(payload)) {
116
+ await handleResult(socket, get_files_in_directory_1.GET_FILES_IN_DIRECTORY, () => (0, handle_get_files_in_directory_1.handleGetFilesInDirectory)(payload.dir));
117
+ }
118
+ else if ((0, get_context_file_data_1.isHandleContextFileDataMessage)(payload)) {
119
+ await handleResult(socket, get_context_file_data_1.GET_CONTEXT_FILE_DATA, () => (0, handle_context_file_data_1.handleContextFileData)());
120
+ }
121
+ else if ((0, hash_glob_1.isHandleHashGlobMessage)(payload)) {
122
+ await handleResult(socket, hash_glob_1.HASH_GLOB, () => (0, handle_hash_glob_1.handleHashGlob)(payload.globs, payload.exclude));
123
+ }
101
124
  else {
102
125
  await (0, shutdown_utils_1.respondWithErrorAndExit)(socket, `Invalid payload from the client`, new Error(`Unsupported payload sent to daemon server: ${unparsedPayload}`));
103
126
  }
@@ -145,7 +168,13 @@ function registerProcessTerminationListeners() {
145
168
  }
146
169
  let existingLockHash;
147
170
  function daemonIsOutdated() {
148
- return nxVersionChanged() || lockFileHashChanged();
171
+ if (nxVersionChanged()) {
172
+ return 'NX_VERSION_CHANGED';
173
+ }
174
+ else if (lockFileHashChanged()) {
175
+ return 'LOCK_FILES_CHANGED';
176
+ }
177
+ return null;
149
178
  }
150
179
  function nxVersionChanged() {
151
180
  return versions_1.nxVersion !== getInstalledNxVersion();
@@ -192,10 +221,11 @@ const handleWorkspaceChanges = async (err, changeEvents) => {
192
221
  }
193
222
  try {
194
223
  (0, shutdown_utils_1.resetInactivityTimeout)(handleInactivityTimeout);
195
- if (daemonIsOutdated()) {
224
+ const outdatedReason = daemonIsOutdated();
225
+ if (outdatedReason) {
196
226
  await (0, shutdown_utils_1.handleServerProcessTermination)({
197
227
  server,
198
- reason: 'Lock file changed',
228
+ reason: outdatedReason,
199
229
  });
200
230
  return;
201
231
  }
@@ -58,7 +58,7 @@ export { addProjectConfiguration, readProjectConfiguration, removeProjectConfigu
58
58
  /**
59
59
  * @category Generators
60
60
  */
61
- export { glob } from './generators/utils/glob';
61
+ export { glob, globAsync } from './generators/utils/glob';
62
62
  /**
63
63
  * @category Generators
64
64
  */
@@ -4,7 +4,7 @@
4
4
  * Try hard to not add to this API to reduce the surface area we need to maintain.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.createProjectFileMapUsingProjectGraph = exports.cacheDir = exports.hashArray = exports.defaultTasksRunner = exports.getOutputsForTargetAndConfiguration = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectGraph = exports.createProjectGraphAsync = exports.reverse = exports.appRootPath = exports.workspaceRoot = exports.normalizePath = exports.joinPathFragments = exports.stripIndents = exports.writeJsonFile = exports.readJsonFile = exports.stripJsonComments = exports.serializeJson = exports.parseJson = exports.updateJson = exports.writeJson = exports.readJson = exports.validateDependency = exports.ProjectGraphBuilder = exports.DependencyType = exports.updateNxJson = exports.readNxJson = exports.glob = exports.getProjects = exports.updateProjectConfiguration = exports.removeProjectConfiguration = exports.readProjectConfiguration = exports.addProjectConfiguration = exports.runExecutor = exports.isWorkspacesEnabled = exports.getPackageManagerVersion = exports.detectPackageManager = exports.getPackageManagerCommand = exports.output = exports.logger = exports.createNodesFromFiles = exports.AggregateCreateNodesError = exports.workspaceLayout = void 0;
7
+ exports.createProjectFileMapUsingProjectGraph = exports.cacheDir = exports.hashArray = exports.defaultTasksRunner = exports.getOutputsForTargetAndConfiguration = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectGraph = exports.createProjectGraphAsync = exports.reverse = exports.appRootPath = exports.workspaceRoot = exports.normalizePath = exports.joinPathFragments = exports.stripIndents = exports.writeJsonFile = exports.readJsonFile = exports.stripJsonComments = exports.serializeJson = exports.parseJson = exports.updateJson = exports.writeJson = exports.readJson = exports.validateDependency = exports.ProjectGraphBuilder = exports.DependencyType = exports.updateNxJson = exports.readNxJson = exports.globAsync = exports.glob = exports.getProjects = exports.updateProjectConfiguration = exports.removeProjectConfiguration = exports.readProjectConfiguration = exports.addProjectConfiguration = exports.runExecutor = exports.isWorkspacesEnabled = exports.getPackageManagerVersion = exports.detectPackageManager = exports.getPackageManagerCommand = exports.output = exports.logger = exports.createNodesFromFiles = exports.AggregateCreateNodesError = exports.workspaceLayout = void 0;
8
8
  var configuration_1 = require("./config/configuration");
9
9
  Object.defineProperty(exports, "workspaceLayout", { enumerable: true, get: function () { return configuration_1.workspaceLayout; } });
10
10
  var error_types_1 = require("./project-graph/error-types");
@@ -48,6 +48,7 @@ Object.defineProperty(exports, "getProjects", { enumerable: true, get: function
48
48
  */
49
49
  var glob_1 = require("./generators/utils/glob");
50
50
  Object.defineProperty(exports, "glob", { enumerable: true, get: function () { return glob_1.glob; } });
51
+ Object.defineProperty(exports, "globAsync", { enumerable: true, get: function () { return glob_1.globAsync; } });
51
52
  /**
52
53
  * @category Generators
53
54
  */
@@ -7,5 +7,16 @@ import { Tree } from '../tree';
7
7
  * @param tree The file system tree
8
8
  * @param patterns A list of glob patterns
9
9
  * @returns Normalized paths in the workspace that match the provided glob patterns.
10
+ * @deprecated Use {@link globAsync} instead.
10
11
  */
11
12
  export declare function glob(tree: Tree, patterns: string[]): string[];
13
+ /**
14
+ * Performs a tree-aware glob search on the files in a workspace. Able to find newly
15
+ * created files and hides deleted files before the updates are committed to disk.
16
+ * Paths should be unix-style with forward slashes.
17
+ *
18
+ * @param tree The file system tree
19
+ * @param patterns A list of glob patterns
20
+ * @returns Normalized paths in the workspace that match the provided glob patterns.
21
+ */
22
+ export declare function globAsync(tree: Tree, patterns: string[]): Promise<string[]>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.glob = void 0;
3
+ exports.globAsync = exports.glob = void 0;
4
4
  const minimatch_1 = require("minimatch");
5
5
  const globs_1 = require("../../utils/globs");
6
6
  const workspace_context_1 = require("../../utils/workspace-context");
@@ -12,9 +12,27 @@ const workspace_context_1 = require("../../utils/workspace-context");
12
12
  * @param tree The file system tree
13
13
  * @param patterns A list of glob patterns
14
14
  * @returns Normalized paths in the workspace that match the provided glob patterns.
15
+ * @deprecated Use {@link globAsync} instead.
15
16
  */
16
17
  function glob(tree, patterns) {
17
- const matches = new Set((0, workspace_context_1.globWithWorkspaceContext)(tree.root, patterns));
18
+ return combineGlobResultsWithTree(tree, patterns, (0, workspace_context_1.globWithWorkspaceContextSync)(tree.root, patterns));
19
+ }
20
+ exports.glob = glob;
21
+ /**
22
+ * Performs a tree-aware glob search on the files in a workspace. Able to find newly
23
+ * created files and hides deleted files before the updates are committed to disk.
24
+ * Paths should be unix-style with forward slashes.
25
+ *
26
+ * @param tree The file system tree
27
+ * @param patterns A list of glob patterns
28
+ * @returns Normalized paths in the workspace that match the provided glob patterns.
29
+ */
30
+ async function globAsync(tree, patterns) {
31
+ return combineGlobResultsWithTree(tree, patterns, await (0, workspace_context_1.globWithWorkspaceContext)(tree.root, patterns));
32
+ }
33
+ exports.globAsync = globAsync;
34
+ function combineGlobResultsWithTree(tree, patterns, results) {
35
+ const matches = new Set(results);
18
36
  const combinedGlob = (0, globs_1.combineGlobPatterns)(patterns);
19
37
  const matcher = minimatch_1.minimatch.makeRe(combinedGlob);
20
38
  if (!matcher) {
@@ -32,4 +50,3 @@ function glob(tree, patterns) {
32
50
  }
33
51
  return Array.from(matches);
34
52
  }
35
- exports.glob = glob;
@@ -134,7 +134,7 @@ function readAndCombineAllProjectConfigurations(tree) {
134
134
  'project.json',
135
135
  ...(0, package_json_workspaces_1.getGlobPatternsFromPackageManagerWorkspaces)(tree.root, (p) => (0, json_1.readJson)(tree, p, { expectComments: true })),
136
136
  ];
137
- const globbedFiles = (0, workspace_context_1.globWithWorkspaceContext)(tree.root, patterns);
137
+ const globbedFiles = (0, workspace_context_1.globWithWorkspaceContextSync)(tree.root, patterns);
138
138
  const createdFiles = findCreatedProjectFiles(tree, patterns);
139
139
  const deletedFiles = findDeletedProjectFiles(tree, patterns);
140
140
  const projectFiles = [...globbedFiles, ...createdFiles].filter((r) => deletedFiles.indexOf(r) === -1);
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateFileMap = exports.createFileMap = exports.createFileMapUsingProjectGraph = exports.createProjectFileMapUsingProjectGraph = void 0;
4
- const client_1 = require("../daemon/client/client");
5
4
  const workspace_context_1 = require("../utils/workspace-context");
6
5
  const workspace_root_1 = require("../utils/workspace-root");
7
6
  const project_graph_1 = require("./project-graph");
@@ -14,13 +13,7 @@ exports.createProjectFileMapUsingProjectGraph = createProjectFileMapUsingProject
14
13
  // TODO: refactor this to pull straight from the rust context instead of creating the file map in JS
15
14
  async function createFileMapUsingProjectGraph(graph) {
16
15
  const configs = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(graph);
17
- let files;
18
- if (client_1.daemonClient.enabled()) {
19
- files = await client_1.daemonClient.getAllFileData();
20
- }
21
- else {
22
- files = (0, workspace_context_1.getAllFileDataInContext)(workspace_root_1.workspaceRoot);
23
- }
16
+ let files = await (0, workspace_context_1.getAllFileDataInContext)(workspace_root_1.workspaceRoot);
24
17
  return createFileMap(configs, files);
25
18
  }
26
19
  exports.createFileMapUsingProjectGraph = createFileMapUsingProjectGraph;
@@ -11,11 +11,10 @@ const json_diff_1 = require("../utils/json-diff");
11
11
  const project_graph_1 = require("./project-graph");
12
12
  const angular_json_1 = require("../adapter/angular-json");
13
13
  const ignore_1 = require("../utils/ignore");
14
- const retrieve_workspace_files_1 = require("./utils/retrieve-workspace-files");
15
14
  const project_configuration_utils_1 = require("./utils/project-configuration-utils");
16
- const nx_plugin_deprecated_1 = require("../utils/nx-plugin.deprecated");
17
- const minimatch_1 = require("minimatch");
18
- const package_json_next_to_project_json_1 = require("../plugins/project-json/build-nodes/package-json-next-to-project-json");
15
+ const package_json_workspaces_1 = require("../plugins/package-json-workspaces");
16
+ const workspace_context_1 = require("../utils/workspace-context");
17
+ const project_json_1 = require("../plugins/project-json/build-nodes/project-json");
19
18
  class WholeFileChange {
20
19
  constructor() {
21
20
  this.type = 'WholeFileChange';
@@ -115,7 +114,7 @@ function readWorkspaceConfig(opts) {
115
114
  catch {
116
115
  configuration = {
117
116
  version: 2,
118
- projects: getProjectsSyncNoInference(root, nxJson).projects,
117
+ projects: getProjectsSync(root, nxJson),
119
118
  };
120
119
  }
121
120
  if (opts.format === 'angularCli') {
@@ -142,38 +141,38 @@ exports.readPackageJson = readPackageJson;
142
141
  /**
143
142
  * TODO(v20): Remove this function.
144
143
  */
145
- function getProjectsSyncNoInference(root, nxJson) {
146
- const allConfigFiles = (0, retrieve_workspace_files_1.retrieveProjectConfigurationPaths)(root, (0, nx_plugin_deprecated_1.getDefaultPluginsSync)(root));
147
- const plugins = [
148
- package_json_next_to_project_json_1.PackageJsonProjectsNextToProjectJsonPlugin,
149
- ...(0, nx_plugin_deprecated_1.getDefaultPluginsSync)(root),
144
+ function getProjectsSync(root, nxJson) {
145
+ /**
146
+ * We can't update projects that come from plugins anyways, so we are going
147
+ * to ignore them for now. Plugins should add their own add/create/update methods
148
+ * if they would like to use devkit to update inferred projects.
149
+ */
150
+ const patterns = [
151
+ '**/project.json',
152
+ 'project.json',
153
+ ...(0, package_json_workspaces_1.getGlobPatternsFromPackageManagerWorkspaces)(root, fileutils_1.readJsonFile),
150
154
  ];
151
- const projectRootMap = {};
152
- // We iterate over plugins first - this ensures that plugins specified first take precedence.
153
- for (const plugin of plugins) {
154
- const [pattern, createNodes] = plugin.createNodes ?? [];
155
- if (!pattern) {
156
- continue;
155
+ const projectFiles = (0, workspace_context_1.globWithWorkspaceContextSync)(root, patterns);
156
+ const rootMap = {};
157
+ for (const projectFile of projectFiles) {
158
+ if ((0, path_1.basename)(projectFile) === 'project.json') {
159
+ const json = (0, fileutils_1.readJsonFile)(projectFile);
160
+ const config = (0, project_json_1.buildProjectFromProjectJson)(json, projectFile);
161
+ (0, project_configuration_utils_1.mergeProjectConfigurationIntoRootMap)(rootMap, config, undefined, undefined, true);
157
162
  }
158
- const matchingConfigFiles = allConfigFiles.filter((file) => (0, minimatch_1.minimatch)(file, pattern, { dot: true }));
159
- for (const file of matchingConfigFiles) {
160
- if ((0, minimatch_1.minimatch)(file, pattern, { dot: true })) {
161
- let r = createNodes(file, {}, {
162
- nxJsonConfiguration: nxJson,
163
- workspaceRoot: root,
164
- configFiles: matchingConfigFiles,
165
- });
166
- for (const node in r.projects) {
167
- const project = {
168
- root: node,
169
- ...r.projects[node],
170
- };
171
- (0, project_configuration_utils_1.mergeProjectConfigurationIntoRootMap)(projectRootMap, project);
172
- }
163
+ else if ((0, path_1.basename)(projectFile) === 'package.json') {
164
+ const packageJson = (0, fileutils_1.readJsonFile)(projectFile);
165
+ const config = (0, package_json_workspaces_1.buildProjectConfigurationFromPackageJson)(packageJson, projectFile, nxJson);
166
+ if (!rootMap[config.root]) {
167
+ (0, project_configuration_utils_1.mergeProjectConfigurationIntoRootMap)(rootMap,
168
+ // Inferred targets, tags, etc don't show up when running generators
169
+ // This is to help avoid running into issues when trying to update the workspace
170
+ {
171
+ name: config.name,
172
+ root: config.root,
173
+ }, undefined, undefined, true);
173
174
  }
174
175
  }
175
176
  }
176
- return {
177
- projects: (0, project_configuration_utils_1.readProjectConfigurationsFromRootMap)(projectRootMap),
178
- };
177
+ return (0, project_configuration_utils_1.readProjectConfigurationsFromRootMap)(rootMap);
179
178
  }
@@ -15,17 +15,18 @@ function loadRemoteNxPlugin(plugin, root) {
15
15
  // but its typescript.
16
16
  const isWorkerTypescript = path.extname(__filename) === '.ts';
17
17
  const workerPath = path.join(__dirname, 'plugin-worker');
18
+ const env = {
19
+ ...process.env,
20
+ ...(isWorkerTypescript
21
+ ? {
22
+ // Ensures that the worker uses the same tsconfig as the main process
23
+ TS_NODE_PROJECT: path.join(__dirname, '../../../../tsconfig.lib.json'),
24
+ }
25
+ : {}),
26
+ };
18
27
  const worker = (0, child_process_1.fork)(workerPath, [], {
19
28
  stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
20
- env: {
21
- ...process.env,
22
- ...(isWorkerTypescript
23
- ? {
24
- // Ensures that the worker uses the same tsconfig as the main process
25
- TS_NODE_PROJECT: path.join(__dirname, '../../../tsconfig.lib.json'),
26
- }
27
- : {}),
28
- },
29
+ env,
29
30
  execArgv: [
30
31
  ...process.execArgv,
31
32
  // If the worker is typescript, we need to register ts-node
@@ -23,7 +23,7 @@ export declare function retrieveProjectConfigurations(plugins: LoadedNxPlugin[],
23
23
  export declare function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<ConfigurationResult>;
24
24
  export declare function retrieveProjectConfigurationPaths(root: string, plugins: Array<{
25
25
  createNodes?: readonly [string, ...unknown[]];
26
- } & unknown>): string[];
26
+ } & unknown>): Promise<string[]>;
27
27
  export declare function retrieveProjectConfigurationsWithoutPluginInference(root: string): Promise<Record<string, ProjectConfiguration>>;
28
28
  export declare function configurationGlobs(plugins: Array<{
29
29
  createNodes?: readonly [string, ...unknown[]];
@@ -20,7 +20,7 @@ async function retrieveWorkspaceFiles(workspaceRoot, projectRootMap) {
20
20
  perf_hooks_1.performance.mark('native-file-deps:end');
21
21
  perf_hooks_1.performance.measure('native-file-deps', 'native-file-deps:start', 'native-file-deps:end');
22
22
  perf_hooks_1.performance.mark('get-workspace-files:start');
23
- const { projectFileMap, globalFiles, externalReferences } = (0, workspace_context_1.getNxWorkspaceFilesFromContext)(workspaceRoot, projectRootMap);
23
+ const { projectFileMap, globalFiles, externalReferences } = await (0, workspace_context_1.getNxWorkspaceFilesFromContext)(workspaceRoot, projectRootMap);
24
24
  perf_hooks_1.performance.mark('get-workspace-files:end');
25
25
  perf_hooks_1.performance.measure('get-workspace-files', 'get-workspace-files:start', 'get-workspace-files:end');
26
26
  return {
@@ -36,9 +36,9 @@ exports.retrieveWorkspaceFiles = retrieveWorkspaceFiles;
36
36
  /**
37
37
  * Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
38
38
  */
39
- function retrieveProjectConfigurations(plugins, workspaceRoot, nxJson) {
39
+ async function retrieveProjectConfigurations(plugins, workspaceRoot, nxJson) {
40
40
  const globPatterns = configurationGlobs(plugins);
41
- const workspaceFiles = (0, workspace_context_1.globWithWorkspaceContext)(workspaceRoot, globPatterns);
41
+ const workspaceFiles = await (0, workspace_context_1.globWithWorkspaceContext)(workspaceRoot, globPatterns);
42
42
  return (0, project_configuration_utils_1.createProjectConfigurations)(workspaceRoot, nxJson, workspaceFiles, plugins);
43
43
  }
44
44
  exports.retrieveProjectConfigurations = retrieveProjectConfigurations;
@@ -50,7 +50,7 @@ async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, n
50
50
  pluginsToLoad.push((0, path_1.join)(__dirname, '../../adapter/angular-json'));
51
51
  }
52
52
  const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)(nxJson?.plugins ?? [], workspaceRoot);
53
- const res = retrieveProjectConfigurations(plugins, workspaceRoot, nxJson);
53
+ const res = await retrieveProjectConfigurations(plugins, workspaceRoot, nxJson);
54
54
  cleanup();
55
55
  return res;
56
56
  }
@@ -65,12 +65,12 @@ const projectsWithoutPluginCache = new Map();
65
65
  async function retrieveProjectConfigurationsWithoutPluginInference(root) {
66
66
  const nxJson = (0, nx_json_1.readNxJson)(root);
67
67
  const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)([]); // only load default plugins
68
- const projectGlobPatterns = retrieveProjectConfigurationPaths(root, plugins);
68
+ const projectGlobPatterns = await retrieveProjectConfigurationPaths(root, plugins);
69
69
  const cacheKey = root + ',' + projectGlobPatterns.join(',');
70
70
  if (projectsWithoutPluginCache.has(cacheKey)) {
71
71
  return projectsWithoutPluginCache.get(cacheKey);
72
72
  }
73
- const projectFiles = (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns) ?? [];
73
+ const projectFiles = (await (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns)) ?? [];
74
74
  const { projects } = await (0, project_configuration_utils_1.createProjectConfigurations)(root, nxJson, projectFiles, plugins);
75
75
  projectsWithoutPluginCache.set(cacheKey, projects);
76
76
  cleanup();
@@ -1,15 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.allFileData = void 0;
4
- const client_1 = require("../daemon/client/client");
5
4
  const workspace_context_1 = require("./workspace-context");
6
5
  const workspace_root_1 = require("./workspace-root");
7
6
  function allFileData() {
8
- if (client_1.daemonClient.enabled()) {
9
- return client_1.daemonClient.getAllFileData();
10
- }
11
- else {
12
- return Promise.resolve((0, workspace_context_1.getAllFileDataInContext)(workspace_root_1.workspaceRoot));
13
- }
7
+ return (0, workspace_context_1.getAllFileDataInContext)(workspace_root_1.workspaceRoot);
14
8
  }
15
9
  exports.allFileData = allFileData;
@@ -1,10 +1,18 @@
1
1
  import type { NxWorkspaceFilesExternals } from '../native';
2
2
  export declare function setupWorkspaceContext(workspaceRoot: string): void;
3
- export declare function getNxWorkspaceFilesFromContext(workspaceRoot: string, projectRootMap: Record<string, string>): import("../native").NxWorkspaceFiles;
4
- export declare function globWithWorkspaceContext(workspaceRoot: string, globs: string[], exclude?: string[]): string[];
5
- export declare function hashWithWorkspaceContext(workspaceRoot: string, globs: string[], exclude?: string[]): string;
3
+ export declare function getNxWorkspaceFilesFromContext(workspaceRoot: string, projectRootMap: Record<string, string>): Promise<import("../native").NxWorkspaceFiles>;
4
+ /**
5
+ * Sync method to get files matching globs from workspace context.
6
+ * NOTE: This method will create the workspace context if it doesn't exist.
7
+ * It should only be used within Nx internal in code paths that **must** be sync.
8
+ * If used in an isolated plugin thread this will cause the workspace context
9
+ * to be recreated which is slow.
10
+ */
11
+ export declare function globWithWorkspaceContextSync(workspaceRoot: string, globs: string[], exclude?: string[]): string[];
12
+ export declare function globWithWorkspaceContext(workspaceRoot: string, globs: string[], exclude?: string[]): Promise<string[]>;
13
+ export declare function hashWithWorkspaceContext(workspaceRoot: string, globs: string[], exclude?: string[]): Promise<string>;
6
14
  export declare function updateFilesInContext(updatedFiles: string[], deletedFiles: string[]): Record<string, string>;
7
- export declare function getAllFileDataInContext(workspaceRoot: string): import("../native").FileData[];
8
- export declare function getFilesInDirectoryUsingContext(workspaceRoot: string, dir: string): string[];
15
+ export declare function getAllFileDataInContext(workspaceRoot: string): Promise<import("../native").FileData[]>;
16
+ export declare function getFilesInDirectoryUsingContext(workspaceRoot: string, dir: string): Promise<string[]>;
9
17
  export declare function updateProjectFiles(projectRootMappings: Record<string, string>, rustReferences: NxWorkspaceFilesExternals, updatedFiles: Record<string, string>, deletedFiles: string[]): import("../native").UpdatedWorkspaceFiles;
10
18
  export declare function resetWorkspaceContext(): void;