nx 18.1.0 → 18.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/bin/init-local.js +13 -1
  2. package/package.json +12 -12
  3. package/release/changelog-renderer/index.d.ts +2 -0
  4. package/release/changelog-renderer/index.js +4 -18
  5. package/schemas/nx-schema.json +62 -1
  6. package/schemas/project-schema.json +20 -0
  7. package/src/adapter/angular-json.d.ts +1 -2
  8. package/src/adapter/angular-json.js +0 -1
  9. package/src/adapter/ngcli-adapter.js +3 -3
  10. package/src/command-line/generate/generator-utils.js +2 -2
  11. package/src/command-line/init/implementation/add-nx-to-nest.js +2 -2
  12. package/src/command-line/init/implementation/add-nx-to-npm-repo.js +2 -2
  13. package/src/command-line/init/implementation/utils.d.ts +1 -3
  14. package/src/command-line/init/implementation/utils.js +9 -16
  15. package/src/command-line/init/init-v2.js +3 -2
  16. package/src/command-line/release/changelog.js +17 -14
  17. package/src/command-line/release/command-object.d.ts +1 -0
  18. package/src/command-line/release/config/config.d.ts +12 -15
  19. package/src/command-line/release/config/config.js +151 -22
  20. package/src/command-line/release/config/conventional-commits.d.ts +2 -0
  21. package/src/command-line/release/config/conventional-commits.js +98 -0
  22. package/src/command-line/release/publish.js +4 -3
  23. package/src/command-line/release/release.js +12 -11
  24. package/src/command-line/release/utils/git.js +30 -1
  25. package/src/command-line/release/utils/resolve-semver-specifier.d.ts +2 -1
  26. package/src/command-line/release/utils/resolve-semver-specifier.js +2 -13
  27. package/src/command-line/release/utils/semver.d.ts +2 -8
  28. package/src/command-line/release/utils/semver.js +4 -1
  29. package/src/command-line/release/utils/shared.d.ts +5 -1
  30. package/src/command-line/release/version.d.ts +6 -1
  31. package/src/command-line/release/version.js +71 -19
  32. package/src/command-line/run/executor-utils.js +2 -2
  33. package/src/command-line/run/run.js +16 -6
  34. package/src/config/nx-json.d.ts +31 -0
  35. package/src/config/schema-utils.js +2 -2
  36. package/src/core/graph/main.js +1 -1
  37. package/src/core/graph/polyfills.js +1 -1
  38. package/src/core/graph/styles.css +1 -1
  39. package/src/daemon/server/project-graph-incremental-recomputation.js +1 -0
  40. package/src/devkit-exports.d.ts +1 -2
  41. package/src/devkit-internals.d.ts +0 -1
  42. package/src/devkit-internals.js +1 -3
  43. package/src/executors/run-commands/run-commands.impl.d.ts +7 -1
  44. package/src/executors/run-commands/run-commands.impl.js +120 -55
  45. package/src/executors/run-script/run-script.impl.js +6 -6
  46. package/src/generators/utils/project-configuration.js +2 -2
  47. package/src/hasher/hash-task.js +2 -2
  48. package/src/migrations/update-15-1-0/set-project-names.js +2 -4
  49. package/src/migrations/update-17-2-0/move-default-base.d.ts +1 -1
  50. package/src/migrations/update-17-2-0/move-default-base.js +3 -1
  51. package/src/migrations/update-17-3-0/nx-release-path.js +0 -1
  52. package/src/native/index.d.ts +14 -11
  53. package/src/native/index.js +3 -4
  54. package/src/plugins/js/index.d.ts +1 -1
  55. package/src/plugins/js/index.js +1 -1
  56. package/src/plugins/js/lock-file/lock-file.d.ts +2 -2
  57. package/src/plugins/js/lock-file/lock-file.js +15 -3
  58. package/src/plugins/js/lock-file/npm-parser.d.ts +1 -1
  59. package/src/plugins/js/lock-file/pnpm-parser.d.ts +1 -1
  60. package/src/plugins/js/lock-file/yarn-parser.d.ts +1 -1
  61. package/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
  62. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +1 -1
  63. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +1 -1
  64. package/src/plugins/js/utils/register.js +3 -1
  65. package/src/plugins/package-json-workspaces/create-nodes.d.ts +2 -2
  66. package/src/plugins/package-json-workspaces/create-nodes.js +31 -24
  67. package/src/plugins/package-json-workspaces/index.d.ts +0 -1
  68. package/src/plugins/package-json-workspaces/index.js +0 -2
  69. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +1 -2
  70. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +0 -1
  71. package/src/plugins/project-json/build-nodes/project-json.d.ts +1 -2
  72. package/src/plugins/project-json/build-nodes/project-json.js +0 -1
  73. package/src/plugins/target-defaults/target-defaults-plugin.d.ts +1 -2
  74. package/src/plugins/target-defaults/target-defaults-plugin.js +0 -1
  75. package/src/project-graph/affected/locators/project-glob-changes.js +3 -2
  76. package/src/project-graph/build-project-graph.js +8 -11
  77. package/src/project-graph/file-utils.js +6 -4
  78. package/src/project-graph/project-graph-builder.d.ts +1 -1
  79. package/src/project-graph/project-graph.js +3 -0
  80. package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
  81. package/src/project-graph/utils/project-configuration-utils.d.ts +4 -4
  82. package/src/project-graph/utils/project-configuration-utils.js +58 -17
  83. package/src/project-graph/utils/retrieve-workspace-files.d.ts +4 -8
  84. package/src/project-graph/utils/retrieve-workspace-files.js +18 -20
  85. package/src/tasks-runner/fork.js +7 -7
  86. package/src/tasks-runner/forked-process-task-runner.d.ts +4 -5
  87. package/src/tasks-runner/forked-process-task-runner.js +28 -21
  88. package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +16 -13
  89. package/src/tasks-runner/life-cycles/dynamic-run-one-terminal-output-life-cycle.js +8 -7
  90. package/src/tasks-runner/{psuedo-ipc.d.ts → pseudo-ipc.d.ts} +7 -7
  91. package/src/tasks-runner/{psuedo-ipc.js → pseudo-ipc.js} +9 -9
  92. package/src/tasks-runner/pseudo-terminal.d.ts +43 -0
  93. package/src/tasks-runner/pseudo-terminal.js +159 -0
  94. package/src/tasks-runner/task-orchestrator.js +49 -31
  95. package/src/tasks-runner/tasks-schedule.js +3 -3
  96. package/src/tasks-runner/utils.d.ts +7 -6
  97. package/src/tasks-runner/utils.js +11 -7
  98. package/src/utils/ignore.js +1 -1
  99. package/src/utils/logger.d.ts +0 -1
  100. package/src/utils/logger.js +0 -5
  101. package/src/{project-graph/plugins/public-api.d.ts → utils/nx-plugin.d.ts} +45 -7
  102. package/src/utils/nx-plugin.deprecated.d.ts +2 -4
  103. package/src/utils/nx-plugin.deprecated.js +4 -4
  104. package/src/utils/nx-plugin.js +293 -0
  105. package/src/utils/output.js +1 -1
  106. package/src/utils/plugins/plugin-capabilities.d.ts +1 -1
  107. package/src/utils/plugins/plugin-capabilities.js +7 -8
  108. package/src/project-graph/plugins/index.d.ts +0 -2
  109. package/src/project-graph/plugins/index.js +0 -8
  110. package/src/project-graph/plugins/internal-api.d.ts +0 -18
  111. package/src/project-graph/plugins/internal-api.js +0 -48
  112. package/src/project-graph/plugins/messaging.d.ts +0 -94
  113. package/src/project-graph/plugins/messaging.js +0 -23
  114. package/src/project-graph/plugins/plugin-pool.d.ts +0 -4
  115. package/src/project-graph/plugins/plugin-pool.js +0 -216
  116. package/src/project-graph/plugins/plugin-worker.d.ts +0 -1
  117. package/src/project-graph/plugins/plugin-worker.js +0 -115
  118. package/src/project-graph/plugins/public-api.js +0 -4
  119. package/src/project-graph/plugins/utils.d.ts +0 -9
  120. package/src/project-graph/plugins/utils.js +0 -55
  121. package/src/project-graph/plugins/worker-api.d.ts +0 -26
  122. package/src/project-graph/plugins/worker-api.js +0 -177
@@ -1,216 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shutdownPluginWorkers = exports.loadRemoteNxPlugin = void 0;
4
- const child_process_1 = require("child_process");
5
- const path = require("path");
6
- // TODO (@AgentEnder): After scoped verbose logging is implemented, re-add verbose logs here.
7
- // import { logger } from '../../utils/logger';
8
- const internal_api_1 = require("./internal-api");
9
- const messaging_1 = require("./messaging");
10
- const pool = new Set();
11
- const pidMap = new Map();
12
- // transaction id (tx) -> Promise, Resolver, Rejecter
13
- // Makes sure that we can resolve the correct promise when the worker sends back the result
14
- const promiseBank = new Map();
15
- function loadRemoteNxPlugin(plugin, root) {
16
- // this should only really be true when running unit tests within
17
- // the Nx repo. We still need to start the worker in this case,
18
- // but its typescript.
19
- const isWorkerTypescript = path.extname(__filename) === '.ts';
20
- const workerPath = path.join(__dirname, 'plugin-worker');
21
- const worker = (0, child_process_1.fork)(workerPath, [], {
22
- stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
23
- env: {
24
- ...process.env,
25
- ...(isWorkerTypescript
26
- ? {
27
- // Ensures that the worker uses the same tsconfig as the main process
28
- TS_NODE_PROJECT: path.join(__dirname, '../../../tsconfig.lib.json'),
29
- }
30
- : {}),
31
- },
32
- execArgv: [
33
- ...process.execArgv,
34
- // If the worker is typescript, we need to register ts-node
35
- ...(isWorkerTypescript ? ['-r', 'ts-node/register'] : []),
36
- ],
37
- });
38
- worker.send((0, messaging_1.createMessage)({ type: 'load', payload: { plugin, root } }));
39
- pool.add(worker);
40
- // logger.verbose(`[plugin-worker] started worker: ${worker.pid}`);
41
- return new Promise((res, rej) => {
42
- worker.on('message', createWorkerHandler(worker, res, rej));
43
- worker.on('exit', createWorkerExitHandler(worker));
44
- });
45
- }
46
- exports.loadRemoteNxPlugin = loadRemoteNxPlugin;
47
- let pluginWorkersShutdown = false;
48
- async function shutdownPluginWorkers() {
49
- // Clears the plugin cache so no refs to the workers are held
50
- internal_api_1.nxPluginCache.clear();
51
- // Marks the workers as shutdown so that we don't report unexpected exits
52
- pluginWorkersShutdown = true;
53
- // logger.verbose(`[plugin-pool] starting worker shutdown`);
54
- const pending = getPendingPromises(pool, pidMap);
55
- if (pending.length > 0) {
56
- // logger.verbose(
57
- // `[plugin-pool] waiting for ${pending.length} pending operations to complete`
58
- // );
59
- await Promise.all(pending);
60
- }
61
- // logger.verbose(`[plugin-pool] all pending operations completed`);
62
- for (const p of pool) {
63
- p.kill('SIGINT');
64
- }
65
- // logger.verbose(`[plugin-pool] all workers killed`);
66
- }
67
- exports.shutdownPluginWorkers = shutdownPluginWorkers;
68
- /**
69
- * Creates a message handler for the given worker.
70
- * @param worker Instance of plugin-worker
71
- * @param onload Resolver for RemotePlugin promise
72
- * @param onloadError Rejecter for RemotePlugin promise
73
- * @returns Function to handle messages from the worker
74
- */
75
- function createWorkerHandler(worker, onload, onloadError) {
76
- let pluginName;
77
- return function (message) {
78
- const parsed = JSON.parse(message);
79
- // logger.verbose(
80
- // `[plugin-pool] received message: ${parsed.type} from ${
81
- // pluginName ?? worker.pid
82
- // }`
83
- // );
84
- (0, messaging_1.consumeMessage)(parsed, {
85
- 'load-result': (result) => {
86
- if (result.success) {
87
- const { name, createNodesPattern } = result;
88
- pluginName = name;
89
- const pending = new Set();
90
- pidMap.set(worker.pid, { name, pending });
91
- onload({
92
- name,
93
- createNodes: createNodesPattern
94
- ? [
95
- createNodesPattern,
96
- (configFiles, ctx) => {
97
- const tx = pluginName + ':createNodes:' + performance.now();
98
- return registerPendingPromise(tx, pending, () => {
99
- worker.send((0, messaging_1.createMessage)({
100
- type: 'createNodes',
101
- payload: { configFiles, context: ctx, tx },
102
- }));
103
- });
104
- },
105
- ]
106
- : undefined,
107
- createDependencies: result.hasCreateDependencies
108
- ? (opts, ctx) => {
109
- const tx = pluginName + ':createDependencies:' + performance.now();
110
- return registerPendingPromise(tx, pending, () => {
111
- worker.send((0, messaging_1.createMessage)({
112
- type: 'createDependencies',
113
- payload: { context: ctx, tx },
114
- }));
115
- });
116
- }
117
- : undefined,
118
- processProjectGraph: result.hasProcessProjectGraph
119
- ? (graph, ctx) => {
120
- const tx = pluginName + ':processProjectGraph:' + performance.now();
121
- return registerPendingPromise(tx, pending, () => {
122
- worker.send((0, messaging_1.createMessage)({
123
- type: 'processProjectGraph',
124
- payload: { graph, ctx, tx },
125
- }));
126
- });
127
- }
128
- : undefined,
129
- });
130
- }
131
- else if (result.success === false) {
132
- onloadError(result.error);
133
- }
134
- },
135
- createDependenciesResult: ({ tx, ...result }) => {
136
- const { resolver, rejecter } = promiseBank.get(tx);
137
- if (result.success) {
138
- resolver(result.dependencies);
139
- }
140
- else if (result.success === false) {
141
- rejecter(result.error);
142
- }
143
- pidMap.get(worker.pid)?.pending.delete(tx);
144
- promiseBank.delete(tx);
145
- },
146
- createNodesResult: ({ tx, ...result }) => {
147
- const { resolver, rejecter } = promiseBank.get(tx);
148
- if (result.success) {
149
- resolver(result.result);
150
- }
151
- else if (result.success === false) {
152
- rejecter(result.error);
153
- }
154
- pidMap.get(worker.pid)?.pending.delete(tx);
155
- promiseBank.delete(tx);
156
- },
157
- processProjectGraphResult: ({ tx, ...result }) => {
158
- const { resolver, rejecter } = promiseBank.get(tx);
159
- if (result.success) {
160
- resolver(result.graph);
161
- }
162
- else if (result.success === false) {
163
- rejecter(result.error);
164
- }
165
- pidMap.get(worker.pid)?.pending.delete(tx);
166
- promiseBank.delete(tx);
167
- },
168
- });
169
- };
170
- }
171
- function createWorkerExitHandler(worker) {
172
- return () => {
173
- if (!pluginWorkersShutdown) {
174
- pidMap.get(worker.pid)?.pending.forEach((tx) => {
175
- const { rejecter } = promiseBank.get(tx);
176
- rejecter(new Error(`Plugin worker ${pidMap.get(worker.pid).name ?? worker.pid} exited unexpectedly with code ${worker.exitCode}`));
177
- });
178
- shutdownPluginWorkers();
179
- }
180
- };
181
- }
182
- process.on('exit', () => {
183
- if (pool.size) {
184
- shutdownPluginWorkers();
185
- }
186
- });
187
- function getPendingPromises(pool, pidMap) {
188
- const pendingTxs = [];
189
- for (const p of pool) {
190
- const { pending } = pidMap.get(p.pid) ?? { pending: new Set() };
191
- for (const tx of pending) {
192
- pendingTxs.push(promiseBank.get(tx)?.promise);
193
- }
194
- }
195
- return pendingTxs;
196
- }
197
- function registerPendingPromise(tx, pending, callback) {
198
- let resolver, rejecter;
199
- const promise = new Promise((res, rej) => {
200
- resolver = res;
201
- rejecter = rej;
202
- callback();
203
- }).then((val) => {
204
- // Remove the promise from the pending set
205
- pending.delete(tx);
206
- // Return the original value
207
- return val;
208
- });
209
- pending.add(tx);
210
- promiseBank.set(tx, {
211
- promise,
212
- resolver,
213
- rejecter,
214
- });
215
- return promise;
216
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,115 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const installation_directory_1 = require("../../utils/installation-directory");
4
- const worker_api_1 = require("./worker-api");
5
- const messaging_1 = require("./messaging");
6
- const retrieve_workspace_files_1 = require("../utils/retrieve-workspace-files");
7
- const utils_1 = require("./utils");
8
- global.NX_GRAPH_CREATION = true;
9
- let plugin;
10
- let pluginOptions;
11
- process.on('message', async (message) => {
12
- (0, messaging_1.consumeMessage)(message, {
13
- load: async ({ plugin: pluginConfiguration, root }) => {
14
- process.chdir(root);
15
- try {
16
- ({ plugin, options: pluginOptions } = await loadPluginFromWorker(pluginConfiguration, root));
17
- return {
18
- type: 'load-result',
19
- payload: {
20
- name: plugin.name,
21
- createNodesPattern: plugin.createNodes?.[0],
22
- hasCreateDependencies: 'createDependencies' in plugin && !!plugin.createDependencies,
23
- hasProcessProjectGraph: 'processProjectGraph' in plugin && !!plugin.processProjectGraph,
24
- success: true,
25
- },
26
- };
27
- }
28
- catch (e) {
29
- return {
30
- type: 'load-result',
31
- payload: {
32
- success: false,
33
- error: `Could not load plugin ${plugin} \n ${e instanceof Error ? e.stack : ''}`,
34
- },
35
- };
36
- }
37
- },
38
- createNodes: async ({ configFiles, context, tx }) => {
39
- try {
40
- const result = await runCreateNodesInParallel(configFiles, context);
41
- return {
42
- type: 'createNodesResult',
43
- payload: { result, success: true, tx },
44
- };
45
- }
46
- catch (e) {
47
- return {
48
- type: 'createNodesResult',
49
- payload: { success: false, error: e.stack, tx },
50
- };
51
- }
52
- },
53
- createDependencies: async ({ context, tx }) => {
54
- try {
55
- const result = await plugin.createDependencies(pluginOptions, context);
56
- return {
57
- type: 'createDependenciesResult',
58
- payload: { dependencies: result, success: true, tx },
59
- };
60
- }
61
- catch (e) {
62
- return {
63
- type: 'createDependenciesResult',
64
- payload: { success: false, error: e.stack, tx },
65
- };
66
- }
67
- },
68
- processProjectGraph: async ({ graph, ctx, tx }) => {
69
- try {
70
- const result = await plugin.processProjectGraph(graph, ctx);
71
- return {
72
- type: 'processProjectGraphResult',
73
- payload: { graph: result, success: true, tx },
74
- };
75
- }
76
- catch (e) {
77
- return {
78
- type: 'processProjectGraphResult',
79
- payload: { success: false, error: e.stack, tx },
80
- };
81
- }
82
- },
83
- });
84
- });
85
- let projectsWithoutInference;
86
- async function loadPluginFromWorker(plugin, root) {
87
- try {
88
- require.resolve(typeof plugin === 'string' ? plugin : plugin.plugin);
89
- }
90
- catch {
91
- // If a plugin cannot be resolved, we will need projects to resolve it
92
- projectsWithoutInference ??=
93
- await (0, retrieve_workspace_files_1.retrieveProjectConfigurationsWithoutPluginInference)(root);
94
- }
95
- return await (0, worker_api_1.loadNxPluginAsync)(plugin, (0, installation_directory_1.getNxRequirePaths)(root), projectsWithoutInference, root);
96
- }
97
- function runCreateNodesInParallel(configFiles, context) {
98
- const promises = configFiles.map((file) => {
99
- performance.mark(`${plugin.name}:createNodes:${file} - start`);
100
- // Result is either static or a promise, using Promise.resolve lets us
101
- // handle both cases with same logic
102
- const value = Promise.resolve(plugin.createNodes[1](file, pluginOptions, context));
103
- return value
104
- .catch((e) => {
105
- performance.mark(`${plugin.name}:createNodes:${file} - end`);
106
- throw new utils_1.CreateNodesError(`Unable to create nodes for ${file} using plugin ${plugin.name}.`, e);
107
- })
108
- .then((r) => {
109
- performance.mark(`${plugin.name}:createNodes:${file} - end`);
110
- performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
111
- return { ...r, pluginName: plugin.name, file };
112
- });
113
- });
114
- return Promise.all(promises);
115
- }
@@ -1,4 +0,0 @@
1
- "use strict";
2
- // This file represents the public API for plugins which live in nx.json's plugins array.
3
- // For methods to interact with plugins from within Nx, see `./internal-api.ts`.
4
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import type { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
2
- import type { NormalizedPlugin, RemotePlugin } from './internal-api';
3
- import type { NxPlugin, NxPluginV2 } from './public-api';
4
- export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
5
- export declare function isNxPluginV1(plugin: NxPlugin | RemotePlugin): plugin is NxPluginV1;
6
- export declare function normalizeNxPlugin(plugin: NxPlugin): NormalizedPlugin;
7
- export declare class CreateNodesError extends Error {
8
- constructor(msg: any, cause: Error | unknown);
9
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreateNodesError = exports.normalizeNxPlugin = exports.isNxPluginV1 = exports.isNxPluginV2 = void 0;
4
- const node_path_1 = require("node:path");
5
- const workspaces_1 = require("../../config/workspaces");
6
- const globs_1 = require("../../utils/globs");
7
- function isNxPluginV2(plugin) {
8
- return 'createNodes' in plugin || 'createDependencies' in plugin;
9
- }
10
- exports.isNxPluginV2 = isNxPluginV2;
11
- function isNxPluginV1(plugin) {
12
- return 'processProjectGraph' in plugin || 'projectFilePatterns' in plugin;
13
- }
14
- exports.isNxPluginV1 = isNxPluginV1;
15
- function normalizeNxPlugin(plugin) {
16
- if (isNxPluginV2(plugin)) {
17
- return plugin;
18
- }
19
- if (isNxPluginV1(plugin) && plugin.projectFilePatterns) {
20
- return {
21
- ...plugin,
22
- createNodes: [
23
- `*/**/${(0, globs_1.combineGlobPatterns)(plugin.projectFilePatterns)}`,
24
- (configFilePath) => {
25
- const root = (0, node_path_1.dirname)(configFilePath);
26
- return {
27
- projects: {
28
- [root]: {
29
- name: (0, workspaces_1.toProjectName)(configFilePath),
30
- targets: plugin.registerProjectTargets?.(configFilePath),
31
- },
32
- },
33
- };
34
- },
35
- ],
36
- };
37
- }
38
- return plugin;
39
- }
40
- exports.normalizeNxPlugin = normalizeNxPlugin;
41
- class CreateNodesError extends Error {
42
- constructor(msg, cause) {
43
- const message = `${msg} ${!cause
44
- ? ''
45
- : cause instanceof Error
46
- ? `\n\n\t Inner Error: ${cause.stack}`
47
- : cause}`;
48
- // These errors are thrown during a JS callback which is invoked via rust.
49
- // The errors messaging gets lost in the rust -> js -> rust transition, but
50
- // logging the error here will ensure that it is visible in the console.
51
- console.error(message);
52
- super(message, { cause });
53
- }
54
- }
55
- exports.CreateNodesError = CreateNodesError;
@@ -1,26 +0,0 @@
1
- import { ProjectConfiguration } from '../../config/workspace-json-project-json';
2
- import { PluginConfiguration } from '../../config/nx-json';
3
- import { PackageJson } from '../../utils/package-json';
4
- import { NxPlugin } from './public-api';
5
- export type LoadedNxPlugin = {
6
- plugin: NxPlugin;
7
- options?: unknown;
8
- };
9
- export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): Promise<LoadedNxPlugin>;
10
- export declare function readPluginPackageJson(pluginName: string, projects: Record<string, ProjectConfiguration>, paths?: string[]): {
11
- path: string;
12
- json: PackageJson;
13
- };
14
- export declare function resolveLocalNxPlugin(importPath: string, projects: Record<string, ProjectConfiguration>, root?: string): {
15
- path: string;
16
- projectConfig: ProjectConfiguration;
17
- } | null;
18
- /**
19
- * Register swc-node or ts-node if they are not currently registered
20
- * with some default settings which work well for Nx plugins.
21
- */
22
- export declare function registerPluginTSTranspiler(): void;
23
- export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
24
- pluginPath: string;
25
- name: any;
26
- };
@@ -1,177 +0,0 @@
1
- "use strict";
2
- // This file contains methods and utilities that should **only** be used by the plugin worker.
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getPluginPathAndName = exports.registerPluginTSTranspiler = exports.resolveLocalNxPlugin = exports.readPluginPackageJson = exports.loadNxPluginAsync = void 0;
5
- const posix_1 = require("node:path/posix");
6
- const installation_directory_1 = require("../../utils/installation-directory");
7
- const package_json_1 = require("../../utils/package-json");
8
- const fileutils_1 = require("../../utils/fileutils");
9
- const path = require("node:path/posix");
10
- const workspace_root_1 = require("../../utils/workspace-root");
11
- const node_fs_1 = require("node:fs");
12
- const typescript_1 = require("../../utils/typescript");
13
- const register_1 = require("../../plugins/js/utils/register");
14
- const find_project_for_path_1 = require("../utils/find-project-for-path");
15
- const path_1 = require("../../utils/path");
16
- const logger_1 = require("../../utils/logger");
17
- const node_path_1 = require("node:path");
18
- const utils_1 = require("./utils");
19
- async function loadNxPluginAsync(pluginConfiguration, paths, projects, root) {
20
- const { plugin: moduleName, options } = typeof pluginConfiguration === 'object'
21
- ? pluginConfiguration
22
- : { plugin: pluginConfiguration, options: undefined };
23
- performance.mark(`Load Nx Plugin: ${moduleName} - start`);
24
- let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projects, root);
25
- const plugin = (0, utils_1.normalizeNxPlugin)(await importPluginModule(pluginPath));
26
- plugin.name ??= name;
27
- performance.mark(`Load Nx Plugin: ${moduleName} - end`);
28
- performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
29
- return { plugin, options };
30
- }
31
- exports.loadNxPluginAsync = loadNxPluginAsync;
32
- function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
33
- try {
34
- const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
35
- return {
36
- json: result.packageJson,
37
- path: result.path,
38
- };
39
- }
40
- catch (e) {
41
- if (e.code === 'MODULE_NOT_FOUND') {
42
- const localPluginPath = resolveLocalNxPlugin(pluginName, projects);
43
- if (localPluginPath) {
44
- const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
45
- return {
46
- path: localPluginPackageJson,
47
- json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
48
- };
49
- }
50
- }
51
- throw e;
52
- }
53
- }
54
- exports.readPluginPackageJson = readPluginPackageJson;
55
- function resolveLocalNxPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
56
- return lookupLocalPlugin(importPath, projects, root);
57
- }
58
- exports.resolveLocalNxPlugin = resolveLocalNxPlugin;
59
- /**
60
- * Register swc-node or ts-node if they are not currently registered
61
- * with some default settings which work well for Nx plugins.
62
- */
63
- function registerPluginTSTranspiler() {
64
- // Get the first tsconfig that matches the allowed set
65
- const tsConfigName = [
66
- (0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.base.json'),
67
- (0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.json'),
68
- ].find((x) => (0, node_fs_1.existsSync)(x));
69
- const tsConfig = tsConfigName
70
- ? (0, typescript_1.readTsConfig)(tsConfigName)
71
- : {};
72
- (0, register_1.registerTsConfigPaths)(tsConfigName);
73
- (0, register_1.registerTranspiler)({
74
- experimentalDecorators: true,
75
- emitDecoratorMetadata: true,
76
- ...tsConfig.options,
77
- });
78
- }
79
- exports.registerPluginTSTranspiler = registerPluginTSTranspiler;
80
- function lookupLocalPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
81
- const plugin = findNxProjectForImportPath(importPath, projects, root);
82
- if (!plugin) {
83
- return null;
84
- }
85
- const projectConfig = projects[plugin];
86
- return { path: path.join(root, projectConfig.root), projectConfig };
87
- }
88
- function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
89
- const tsConfigPaths = readTsConfigPaths(root);
90
- const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
91
- if (possiblePaths?.length) {
92
- const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappingsFromProjectConfigurations)(projects);
93
- for (const tsConfigPath of possiblePaths) {
94
- const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
95
- if (nxProject) {
96
- return nxProject;
97
- }
98
- }
99
- logger_1.logger.verbose('Unable to find local plugin', possiblePaths, projectRootMappings);
100
- throw new Error('Unable to resolve local plugin with import path ' + importPath);
101
- }
102
- }
103
- let tsconfigPaths;
104
- function readTsConfigPaths(root = workspace_root_1.workspaceRoot) {
105
- if (!tsconfigPaths) {
106
- const tsconfigPath = ['tsconfig.base.json', 'tsconfig.json']
107
- .map((x) => path.join(root, x))
108
- .filter((x) => (0, node_fs_1.existsSync)(x))[0];
109
- if (!tsconfigPath) {
110
- throw new Error('unable to find tsconfig.base.json or tsconfig.json');
111
- }
112
- const { compilerOptions } = (0, fileutils_1.readJsonFile)(tsconfigPath);
113
- tsconfigPaths = compilerOptions?.paths;
114
- }
115
- return tsconfigPaths ?? {};
116
- }
117
- function readPluginMainFromProjectConfiguration(plugin) {
118
- const { main } = Object.values(plugin.targets).find((x) => [
119
- '@nx/js:tsc',
120
- '@nrwl/js:tsc',
121
- '@nx/js:swc',
122
- '@nrwl/js:swc',
123
- '@nx/node:package',
124
- '@nrwl/node:package',
125
- ].includes(x.executor))?.options ||
126
- plugin.targets?.build?.options ||
127
- {};
128
- return main;
129
- }
130
- function getPluginPathAndName(moduleName, paths, projects, root) {
131
- let pluginPath;
132
- let registerTSTranspiler = false;
133
- try {
134
- pluginPath = require.resolve(moduleName, {
135
- paths,
136
- });
137
- const extension = path.extname(pluginPath);
138
- registerTSTranspiler = extension === '.ts';
139
- }
140
- catch (e) {
141
- if (e.code === 'MODULE_NOT_FOUND') {
142
- const plugin = resolveLocalNxPlugin(moduleName, projects, root);
143
- if (plugin) {
144
- registerTSTranspiler = true;
145
- const main = readPluginMainFromProjectConfiguration(plugin.projectConfig);
146
- pluginPath = main ? path.join(root, main) : plugin.path;
147
- }
148
- else {
149
- logger_1.logger.error(`Plugin listed in \`nx.json\` not found: ${moduleName}`);
150
- throw e;
151
- }
152
- }
153
- else {
154
- throw e;
155
- }
156
- }
157
- const packageJsonPath = path.join(pluginPath, 'package.json');
158
- // Register the ts-transpiler if we are pointing to a
159
- // plain ts file that's not part of a plugin project
160
- if (registerTSTranspiler) {
161
- registerPluginTSTranspiler();
162
- }
163
- const { name } = !['.ts', '.js'].some((x) => (0, node_path_1.extname)(moduleName) === x) && // Not trying to point to a ts or js file
164
- (0, node_fs_1.existsSync)(packageJsonPath) // plugin has a package.json
165
- ? (0, fileutils_1.readJsonFile)(packageJsonPath) // read name from package.json
166
- : { name: moduleName };
167
- return { pluginPath, name };
168
- }
169
- exports.getPluginPathAndName = getPluginPathAndName;
170
- async function importPluginModule(pluginPath) {
171
- const m = await Promise.resolve(`${pluginPath}`).then(s => require(s));
172
- if (m.default &&
173
- ('createNodes' in m.default || 'createDependencies' in m.default)) {
174
- return m.default;
175
- }
176
- return m;
177
- }