nx 19.2.0-canary.20240530-316dcb9 → 19.2.0-canary.20240601-6f22300

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. package/package.json +12 -12
  2. package/src/command-line/deprecated/command-objects.js +2 -1
  3. package/src/command-line/examples.js +59 -5
  4. package/src/command-line/graph/command-object.d.ts +25 -2
  5. package/src/command-line/graph/command-object.js +57 -3
  6. package/src/command-line/graph/graph.js +2 -1
  7. package/src/command-line/init/implementation/react/index.js +1 -1
  8. package/src/command-line/init/implementation/react/rename-js-to-jsx.d.ts +1 -1
  9. package/src/command-line/init/implementation/react/rename-js-to-jsx.js +2 -2
  10. package/src/command-line/init/init-v2.js +1 -1
  11. package/src/command-line/nx-commands.js +1 -1
  12. package/src/command-line/yargs-utils/shared-options.d.ts +0 -21
  13. package/src/command-line/yargs-utils/shared-options.js +2 -52
  14. package/src/daemon/client/client.d.ts +6 -0
  15. package/src/daemon/client/client.js +45 -2
  16. package/src/daemon/is-on-daemon.d.ts +1 -0
  17. package/src/daemon/is-on-daemon.js +7 -0
  18. package/src/daemon/message-types/get-context-file-data.d.ts +5 -0
  19. package/src/daemon/message-types/get-context-file-data.js +11 -0
  20. package/src/daemon/message-types/get-files-in-directory.d.ts +6 -0
  21. package/src/daemon/message-types/get-files-in-directory.js +11 -0
  22. package/src/daemon/message-types/get-nx-workspace-files.d.ts +6 -0
  23. package/src/daemon/message-types/get-nx-workspace-files.js +11 -0
  24. package/src/daemon/message-types/glob.d.ts +7 -0
  25. package/src/daemon/message-types/glob.js +11 -0
  26. package/src/daemon/message-types/hash-glob.d.ts +7 -0
  27. package/src/daemon/message-types/hash-glob.js +11 -0
  28. package/src/daemon/message-types/update-context-files.d.ts +7 -0
  29. package/src/daemon/message-types/update-context-files.js +11 -0
  30. package/src/daemon/server/handle-context-file-data.d.ts +2 -0
  31. package/src/daemon/server/handle-context-file-data.js +13 -0
  32. package/src/daemon/server/handle-get-files-in-directory.d.ts +2 -0
  33. package/src/daemon/server/handle-get-files-in-directory.js +13 -0
  34. package/src/daemon/server/handle-glob.d.ts +2 -0
  35. package/src/daemon/server/handle-glob.js +13 -0
  36. package/src/daemon/server/handle-hash-glob.d.ts +2 -0
  37. package/src/daemon/server/handle-hash-glob.js +13 -0
  38. package/src/daemon/server/handle-nx-workspace-files.d.ts +2 -0
  39. package/src/daemon/server/handle-nx-workspace-files.js +13 -0
  40. package/src/daemon/server/server.js +39 -9
  41. package/src/devkit-exports.d.ts +4 -2
  42. package/src/devkit-exports.js +6 -1
  43. package/src/generators/utils/glob.d.ts +11 -0
  44. package/src/generators/utils/glob.js +20 -3
  45. package/src/generators/utils/project-configuration.js +1 -1
  46. package/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +16 -3
  47. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +2 -1
  48. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js +40 -27
  49. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +2 -1
  50. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +14 -19
  51. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +32 -5
  52. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +146 -47
  53. package/src/plugins/js/utils/resolve-relative-to-dir.d.ts +5 -0
  54. package/src/plugins/js/utils/resolve-relative-to-dir.js +18 -0
  55. package/src/project-graph/error-types.d.ts +37 -19
  56. package/src/project-graph/error-types.js +31 -19
  57. package/src/project-graph/file-map-utils.js +1 -8
  58. package/src/project-graph/file-utils.js +33 -34
  59. package/src/project-graph/plugins/index.d.ts +1 -0
  60. package/src/project-graph/plugins/index.js +3 -1
  61. package/src/project-graph/plugins/internal-api.d.ts +2 -2
  62. package/src/project-graph/plugins/internal-api.js +33 -3
  63. package/src/project-graph/plugins/isolation/plugin-pool.js +10 -9
  64. package/src/project-graph/plugins/public-api.d.ts +34 -3
  65. package/src/project-graph/plugins/utils.d.ts +4 -3
  66. package/src/project-graph/plugins/utils.js +13 -26
  67. package/src/project-graph/utils/project-configuration-utils.js +89 -74
  68. package/src/project-graph/utils/retrieve-workspace-files.d.ts +4 -4
  69. package/src/project-graph/utils/retrieve-workspace-files.js +6 -6
  70. package/src/utils/all-file-data.js +1 -7
  71. package/src/utils/workspace-context.d.ts +13 -5
  72. package/src/utils/workspace-context.js +45 -14
  73. package/src/daemon/server/handle-request-file-data.d.ts +0 -4
  74. package/src/daemon/server/handle-request-file-data.js +0 -13
@@ -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;
@@ -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
  }
@@ -15,7 +15,9 @@ export type { WorkspaceJsonConfiguration, ProjectsConfigurations, TargetDependen
15
15
  */
16
16
  export type { Generator, GeneratorCallback, Executor, ExecutorContext, TaskGraphExecutor, GeneratorsJson, ExecutorsJson, MigrationsJson, CustomHasher, HasherContext, } from './config/misc-interfaces';
17
17
  export { workspaceLayout } from './config/configuration';
18
- export type { NxPlugin, NxPluginV2, CreateNodes, CreateNodesFunction, CreateNodesResult, CreateNodesContext, CreateDependencies, CreateDependenciesContext, CreateMetadata, CreateMetadataContext, ProjectsMetadata, } from './project-graph/plugins';
18
+ export type { NxPlugin, NxPluginV2, CreateNodes, CreateNodesFunction, CreateNodesResult, CreateNodesContext, CreateNodesContextV2, CreateNodesFunctionV2, CreateNodesResultV2, CreateNodesV2, CreateDependencies, CreateDependenciesContext, CreateMetadata, CreateMetadataContext, ProjectsMetadata, } from './project-graph/plugins';
19
+ export { AggregateCreateNodesError } from './project-graph/error-types';
20
+ export { createNodesFromFiles } from './project-graph/plugins';
19
21
  export type { NxPluginV1, ProjectTargetConfigurator, } from './utils/nx-plugin.deprecated';
20
22
  /**
21
23
  * @category Workspace
@@ -56,7 +58,7 @@ export { addProjectConfiguration, readProjectConfiguration, removeProjectConfigu
56
58
  /**
57
59
  * @category Generators
58
60
  */
59
- export { glob } from './generators/utils/glob';
61
+ export { glob, globAsync } from './generators/utils/glob';
60
62
  /**
61
63
  * @category Generators
62
64
  */
@@ -4,9 +4,13 @@
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.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
+ var error_types_1 = require("./project-graph/error-types");
11
+ Object.defineProperty(exports, "AggregateCreateNodesError", { enumerable: true, get: function () { return error_types_1.AggregateCreateNodesError; } });
12
+ var plugins_1 = require("./project-graph/plugins");
13
+ Object.defineProperty(exports, "createNodesFromFiles", { enumerable: true, get: function () { return plugins_1.createNodesFromFiles; } });
10
14
  /**
11
15
  * @category Logger
12
16
  */
@@ -44,6 +48,7 @@ Object.defineProperty(exports, "getProjects", { enumerable: true, get: function
44
48
  */
45
49
  var glob_1 = require("./generators/utils/glob");
46
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; } });
47
52
  /**
48
53
  * @category Generators
49
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,12 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildExplicitDependencies = void 0;
4
- const explicit_project_dependencies_1 = require("./explicit-project-dependencies");
5
4
  const explicit_package_json_dependencies_1 = require("./explicit-package-json-dependencies");
5
+ const explicit_project_dependencies_1 = require("./explicit-project-dependencies");
6
+ const target_project_locator_1 = require("./target-project-locator");
6
7
  function buildExplicitDependencies(jsPluginConfig, ctx) {
7
8
  if (totalNumberOfFilesToProcess(ctx) === 0)
8
9
  return [];
9
10
  let dependencies = [];
11
+ // TODO: TargetProjectLocator is a public API, so we can't change the shape of it
12
+ // We should eventually let it accept Record<string, ProjectConfiguration> s.t. we
13
+ // don't have to reshape the CreateDependenciesContext here.
14
+ const nodes = Object.fromEntries(Object.entries(ctx.projects).map(([key, config]) => [
15
+ key,
16
+ {
17
+ name: key,
18
+ type: null,
19
+ data: config,
20
+ },
21
+ ]));
22
+ const targetProjectLocator = new target_project_locator_1.TargetProjectLocator(nodes, ctx.externalNodes);
10
23
  if (jsPluginConfig.analyzeSourceFiles === undefined ||
11
24
  jsPluginConfig.analyzeSourceFiles === true) {
12
25
  let tsExists = false;
@@ -16,12 +29,12 @@ function buildExplicitDependencies(jsPluginConfig, ctx) {
16
29
  }
17
30
  catch { }
18
31
  if (tsExists) {
19
- dependencies = dependencies.concat((0, explicit_project_dependencies_1.buildExplicitTypeScriptDependencies)(ctx));
32
+ dependencies = dependencies.concat((0, explicit_project_dependencies_1.buildExplicitTypeScriptDependencies)(ctx, targetProjectLocator));
20
33
  }
21
34
  }
22
35
  if (jsPluginConfig.analyzePackageJson === undefined ||
23
36
  jsPluginConfig.analyzePackageJson === true) {
24
- dependencies = dependencies.concat((0, explicit_package_json_dependencies_1.buildExplicitPackageJsonDependencies)(ctx));
37
+ dependencies = dependencies.concat((0, explicit_package_json_dependencies_1.buildExplicitPackageJsonDependencies)(ctx, targetProjectLocator));
25
38
  }
26
39
  return dependencies;
27
40
  }
@@ -1,3 +1,4 @@
1
1
  import { CreateDependenciesContext } from '../../../../project-graph/plugins';
2
2
  import { RawProjectGraphDependency } from '../../../../project-graph/project-graph-builder';
3
- export declare function buildExplicitPackageJsonDependencies(ctx: CreateDependenciesContext): RawProjectGraphDependency[];
3
+ import { TargetProjectLocator } from './target-project-locator';
4
+ export declare function buildExplicitPackageJsonDependencies(ctx: CreateDependenciesContext, targetProjectLocator: TargetProjectLocator): RawProjectGraphDependency[];
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildExplicitPackageJsonDependencies = void 0;
4
- const file_utils_1 = require("../../../../project-graph/file-utils");
5
- const path_1 = require("path");
4
+ const node_path_1 = require("node:path");
6
5
  const project_graph_1 = require("../../../../config/project-graph");
7
- const json_1 = require("../../../../utils/json");
8
- const path_2 = require("../../../../utils/path");
6
+ const file_utils_1 = require("../../../../project-graph/file-utils");
9
7
  const project_graph_builder_1 = require("../../../../project-graph/project-graph-builder");
10
- function buildExplicitPackageJsonDependencies(ctx) {
8
+ const json_1 = require("../../../../utils/json");
9
+ const path_1 = require("../../../../utils/path");
10
+ function buildExplicitPackageJsonDependencies(ctx, targetProjectLocator) {
11
11
  const res = [];
12
12
  let packageNameMap = undefined;
13
13
  const nodes = Object.values(ctx.projects);
@@ -16,7 +16,7 @@ function buildExplicitPackageJsonDependencies(ctx) {
16
16
  if (isPackageJsonAtProjectRoot(nodes, f.file)) {
17
17
  // we only create the package name map once and only if a package.json file changes
18
18
  packageNameMap = packageNameMap || createPackageNameMap(ctx.projects);
19
- processPackageJson(source, f.file, ctx, res, packageNameMap);
19
+ processPackageJson(source, f.file, ctx, targetProjectLocator, res, packageNameMap);
20
20
  }
21
21
  });
22
22
  });
@@ -27,7 +27,7 @@ function createPackageNameMap(projects) {
27
27
  const res = {};
28
28
  for (let projectName of Object.keys(projects)) {
29
29
  try {
30
- const packageJson = (0, json_1.parseJson)((0, file_utils_1.defaultFileRead)((0, path_1.join)(projects[projectName].root, 'package.json')));
30
+ const packageJson = (0, json_1.parseJson)((0, file_utils_1.defaultFileRead)((0, node_path_1.join)(projects[projectName].root, 'package.json')));
31
31
  res[packageJson.name ?? projectName] = projectName;
32
32
  }
33
33
  catch (e) { }
@@ -36,13 +36,12 @@ function createPackageNameMap(projects) {
36
36
  }
37
37
  function isPackageJsonAtProjectRoot(nodes, fileName) {
38
38
  return (fileName.endsWith('package.json') &&
39
- nodes.find((projectNode) => (0, path_2.joinPathFragments)(projectNode.root, 'package.json') === fileName));
39
+ nodes.find((projectNode) => (0, path_1.joinPathFragments)(projectNode.root, 'package.json') === fileName));
40
40
  }
41
- function processPackageJson(sourceProject, fileName, ctx, collectedDeps, packageNameMap) {
41
+ function processPackageJson(sourceProject, fileName, ctx, targetProjectLocator, collectedDeps, packageNameMap) {
42
42
  try {
43
43
  const deps = readDeps((0, json_1.parseJson)((0, file_utils_1.defaultFileRead)(fileName)));
44
- // the name matches the import path
45
- deps.forEach((d) => {
44
+ for (const d of Object.keys(deps)) {
46
45
  // package.json refers to another project in the monorepo
47
46
  if (packageNameMap[d]) {
48
47
  const dependency = {
@@ -53,30 +52,44 @@ function processPackageJson(sourceProject, fileName, ctx, collectedDeps, package
53
52
  };
54
53
  (0, project_graph_builder_1.validateDependency)(dependency, ctx);
55
54
  collectedDeps.push(dependency);
55
+ continue;
56
56
  }
57
- else if (ctx.externalNodes[`npm:${d}`]) {
58
- const dependency = {
59
- source: sourceProject,
60
- target: `npm:${d}`,
61
- sourceFile: fileName,
62
- type: project_graph_1.DependencyType.static,
63
- };
64
- (0, project_graph_builder_1.validateDependency)(dependency, ctx);
65
- collectedDeps.push(dependency);
57
+ const externalNodeName = targetProjectLocator.findNpmProjectFromImport(d, fileName);
58
+ if (!externalNodeName) {
59
+ continue;
66
60
  }
67
- });
61
+ const dependency = {
62
+ source: sourceProject,
63
+ target: externalNodeName,
64
+ sourceFile: fileName,
65
+ type: project_graph_1.DependencyType.static,
66
+ };
67
+ (0, project_graph_builder_1.validateDependency)(dependency, ctx);
68
+ collectedDeps.push(dependency);
69
+ }
68
70
  }
69
71
  catch (e) {
70
72
  if (process.env.NX_VERBOSE_LOGGING === 'true') {
71
- console.log(e);
73
+ console.error(e);
72
74
  }
73
75
  }
74
76
  }
75
77
  function readDeps(packageJson) {
76
- return [
77
- ...Object.keys(packageJson?.dependencies ?? {}),
78
- ...Object.keys(packageJson?.devDependencies ?? {}),
79
- ...Object.keys(packageJson?.peerDependencies ?? {}),
80
- ...Object.keys(packageJson?.optionalDependencies ?? {}),
78
+ const deps = {};
79
+ /**
80
+ * We process dependencies in a rough order of increasing importance such that if a dependency is listed in multiple
81
+ * sections, the version listed under the "most important" one wins, with production dependencies being the most important.
82
+ */
83
+ const depType = [
84
+ 'optionalDependencies',
85
+ 'peerDependencies',
86
+ 'devDependencies',
87
+ 'dependencies',
81
88
  ];
89
+ for (const type of depType) {
90
+ for (const [depName, depVersion] of Object.entries(packageJson[type] || {})) {
91
+ deps[depName] = depVersion;
92
+ }
93
+ }
94
+ return deps;
82
95
  }
@@ -1,3 +1,4 @@
1
1
  import { CreateDependenciesContext } from '../../../../project-graph/plugins';
2
2
  import { RawProjectGraphDependency } from '../../../../project-graph/project-graph-builder';
3
- export declare function buildExplicitTypeScriptDependencies(ctx: CreateDependenciesContext): RawProjectGraphDependency[];
3
+ import { TargetProjectLocator } from './target-project-locator';
4
+ export declare function buildExplicitTypeScriptDependencies(ctx: CreateDependenciesContext, targetProjectLocator: TargetProjectLocator): RawProjectGraphDependency[];
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildExplicitTypeScriptDependencies = void 0;
4
- const target_project_locator_1 = require("./target-project-locator");
5
- const project_graph_1 = require("../../../../config/project-graph");
6
4
  const path_1 = require("path");
7
- const workspace_root_1 = require("../../../../utils/workspace-root");
8
- const path_2 = require("../../../../utils/path");
5
+ const project_graph_1 = require("../../../../config/project-graph");
9
6
  const project_graph_builder_1 = require("../../../../project-graph/project-graph-builder");
7
+ const path_2 = require("../../../../utils/path");
8
+ const workspace_root_1 = require("../../../../utils/workspace-root");
10
9
  function isRoot(projects, projectName) {
11
10
  return projects[projectName]?.root === '.';
12
11
  }
13
12
  function convertImportToDependency(importExpr, sourceFile, source, type, targetProjectLocator) {
14
- const target = targetProjectLocator.findProjectWithImport(importExpr, sourceFile) ??
15
- `npm:${importExpr}`;
13
+ const target = targetProjectLocator.findProjectFromImport(importExpr, sourceFile);
14
+ if (!target) {
15
+ return;
16
+ }
16
17
  return {
17
18
  source,
18
19
  target,
@@ -20,19 +21,7 @@ function convertImportToDependency(importExpr, sourceFile, source, type, targetP
20
21
  type,
21
22
  };
22
23
  }
23
- function buildExplicitTypeScriptDependencies(ctx) {
24
- // TODO: TargetProjectLocator is a public API, so we can't change the shape of it
25
- // We should eventually let it accept Record<string, ProjectConfiguration> s.t. we
26
- // don't have to reshape the CreateDependenciesContext here.
27
- const nodes = Object.fromEntries(Object.entries(ctx.projects).map(([key, config]) => [
28
- key,
29
- {
30
- name: key,
31
- type: null,
32
- data: config,
33
- },
34
- ]));
35
- const targetProjectLocator = new target_project_locator_1.TargetProjectLocator(nodes, ctx.externalNodes);
24
+ function buildExplicitTypeScriptDependencies(ctx, targetProjectLocator) {
36
25
  const res = [];
37
26
  const filesToProcess = {};
38
27
  const moduleExtensions = [
@@ -63,6 +52,9 @@ function buildExplicitTypeScriptDependencies(ctx) {
63
52
  const normalizedFilePath = (0, path_2.normalizePath)((0, path_1.relative)(workspace_root_1.workspaceRoot, file));
64
53
  for (const importExpr of staticImportExpressions) {
65
54
  const dependency = convertImportToDependency(importExpr, normalizedFilePath, sourceProject, project_graph_1.DependencyType.static, targetProjectLocator);
55
+ if (!dependency) {
56
+ continue;
57
+ }
66
58
  // TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root
67
59
  if (isRoot(ctx.projects, dependency.source) ||
68
60
  !isRoot(ctx.projects, dependency.target)) {
@@ -71,6 +63,9 @@ function buildExplicitTypeScriptDependencies(ctx) {
71
63
  }
72
64
  for (const importExpr of dynamicImportExpressions) {
73
65
  const dependency = convertImportToDependency(importExpr, normalizedFilePath, sourceProject, project_graph_1.DependencyType.dynamic, targetProjectLocator);
66
+ if (!dependency) {
67
+ continue;
68
+ }
74
69
  // TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root
75
70
  if (isRoot(ctx.projects, dependency.source) ||
76
71
  !isRoot(ctx.projects, dependency.target)) {
@@ -1,21 +1,37 @@
1
1
  import { ProjectGraphExternalNode, ProjectGraphProjectNode } from '../../../../config/project-graph';
2
+ /**
3
+ * The key is a combination of the package name and the workspace relative directory
4
+ * containing the file importing it e.g. `lodash__packages/my-lib`, the value is the
5
+ * resolved external node name from the project graph.
6
+ */
7
+ type NpmResolutionCache = Map<string, string | null>;
8
+ export declare function isBuiltinModuleImport(importExpr: string): boolean;
2
9
  export declare class TargetProjectLocator {
3
10
  private readonly nodes;
4
11
  private readonly externalNodes;
12
+ private readonly npmResolutionCache;
5
13
  private projectRootMappings;
6
14
  private npmProjects;
7
15
  private tsConfig;
8
16
  private paths;
9
17
  private typescriptResolutionCache;
10
- private npmResolutionCache;
11
- constructor(nodes: Record<string, ProjectGraphProjectNode>, externalNodes: Record<string, ProjectGraphExternalNode>);
18
+ constructor(nodes: Record<string, ProjectGraphProjectNode>, externalNodes?: Record<string, ProjectGraphExternalNode>, npmResolutionCache?: NpmResolutionCache);
12
19
  /**
13
- * Find a project based on its import
20
+ * Resolve any workspace or external project that matches the given import expression,
21
+ * originating from the given filePath.
14
22
  *
15
23
  * @param importExpr
16
24
  * @param filePath
17
25
  */
18
- findProjectWithImport(importExpr: string, filePath: string): string;
26
+ findProjectFromImport(importExpr: string, filePath: string): string;
27
+ /**
28
+ * Resolve any external project that matches the given import expression,
29
+ * relative to the given file path.
30
+ *
31
+ * @param importExpr
32
+ * @param projectRoot
33
+ */
34
+ findNpmProjectFromImport(importExpr: string, fromFilePath: string): string | null;
19
35
  /**
20
36
  * Return file paths matching the import relative to the repo root
21
37
  * @param normalizedImportExpr
@@ -24,9 +40,20 @@ export declare class TargetProjectLocator {
24
40
  findPaths(normalizedImportExpr: string): string[] | undefined;
25
41
  private resolveImportWithTypescript;
26
42
  private resolveImportWithRequire;
27
- private findNpmPackage;
28
43
  private findProjectOfResolvedModule;
29
44
  private getAbsolutePath;
30
45
  private getRootTsConfig;
31
46
  private findMatchingProjectFiles;
47
+ /**
48
+ * In many cases the package.json will be directly resolvable, so we try that first.
49
+ * If, however, package exports are used and the package.json is not defined, we will
50
+ * need to resolve the main entry point of the package and traverse upwards to find the
51
+ * package.json.
52
+ *
53
+ * In some cases, such as when multiple module formats are published, the resolved package.json
54
+ * might only contain the "type" field - no "name" or "version", so in such cases we keep traversing
55
+ * until we find a package.json that contains the "name" and "version" fields.
56
+ */
57
+ private readPackageJson;
32
58
  }
59
+ export {};