nx 20.6.2 → 20.6.3
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.
- package/package.json +11 -11
- package/src/command-line/init/implementation/check-compatible-with-plugins.js +7 -1
- package/src/core/graph/main.js +1 -1
- package/src/devkit-internals.d.ts +1 -0
- package/src/devkit-internals.js +3 -1
- package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +8 -0
- package/src/generators/testing-utils/create-tree.js +5 -1
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/project-graph/utils/project-configuration-utils.js +1 -1
- package/src/tasks-runner/batch/batch-messages.d.ts +2 -0
- package/src/tasks-runner/batch/run-batch.js +2 -3
- package/src/tasks-runner/forked-process-task-runner.d.ts +2 -1
- package/src/tasks-runner/forked-process-task-runner.js +2 -1
- package/src/tasks-runner/task-orchestrator.js +3 -3
- package/src/utils/is-using-prettier.d.ts +3 -0
- package/src/utils/is-using-prettier.js +62 -0
@@ -25,3 +25,4 @@ export * from './project-graph/error-types';
|
|
25
25
|
export { registerTsProject } from './plugins/js/utils/register';
|
26
26
|
export { interpolate } from './tasks-runner/utils';
|
27
27
|
export { isCI } from './utils/is-ci';
|
28
|
+
export { isUsingPrettierInTree } from './utils/is-using-prettier';
|
package/src/devkit-internals.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isCI = exports.interpolate = exports.registerTsProject = exports.LoadedNxPlugin = exports.retrieveProjectConfigurations = exports.findProjectForPath = exports.createProjectRootMappingsFromProjectConfigurations = exports.hashMultiGlobWithWorkspaceContext = exports.hashWithWorkspaceContext = exports.hashObject = exports.splitByColons = exports.readModulePackageJson = exports.stripIndent = exports.sortObjectByKeys = exports.combineOptionsForExecutor = exports.splitTarget = exports.findMatchingConfigFiles = exports.readProjectConfigurationsFromRootMap = exports.mergeTargetConfigurations = exports.retrieveProjectConfigurationsWithAngularProjects = exports.calculateDefaultProjectName = exports.readNxJsonFromDisk = exports.getExecutorInformation = exports.createTempNpmDirectory = void 0;
|
3
|
+
exports.isUsingPrettierInTree = exports.isCI = exports.interpolate = exports.registerTsProject = exports.LoadedNxPlugin = exports.retrieveProjectConfigurations = exports.findProjectForPath = exports.createProjectRootMappingsFromProjectConfigurations = exports.hashMultiGlobWithWorkspaceContext = exports.hashWithWorkspaceContext = exports.hashObject = exports.splitByColons = exports.readModulePackageJson = exports.stripIndent = exports.sortObjectByKeys = exports.combineOptionsForExecutor = exports.splitTarget = exports.findMatchingConfigFiles = exports.readProjectConfigurationsFromRootMap = exports.mergeTargetConfigurations = exports.retrieveProjectConfigurationsWithAngularProjects = exports.calculateDefaultProjectName = exports.readNxJsonFromDisk = exports.getExecutorInformation = exports.createTempNpmDirectory = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
/**
|
6
6
|
* Note to developers: STOP! These exports are available via requireNx in @nx/devkit.
|
@@ -53,3 +53,5 @@ var utils_1 = require("./tasks-runner/utils");
|
|
53
53
|
Object.defineProperty(exports, "interpolate", { enumerable: true, get: function () { return utils_1.interpolate; } });
|
54
54
|
var is_ci_1 = require("./utils/is-ci");
|
55
55
|
Object.defineProperty(exports, "isCI", { enumerable: true, get: function () { return is_ci_1.isCI; } });
|
56
|
+
var is_using_prettier_1 = require("./utils/is-using-prettier");
|
57
|
+
Object.defineProperty(exports, "isUsingPrettierInTree", { enumerable: true, get: function () { return is_using_prettier_1.isUsingPrettierInTree; } });
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatChangedFilesWithPrettierIfAvailable = formatChangedFilesWithPrettierIfAvailable;
|
4
4
|
exports.formatFilesWithPrettierIfAvailable = formatFilesWithPrettierIfAvailable;
|
5
5
|
const path = require("path");
|
6
|
+
const is_using_prettier_1 = require("../../utils/is-using-prettier");
|
6
7
|
/**
|
7
8
|
* Formats all the created or updated files using Prettier
|
8
9
|
* @param tree - the file system tree
|
@@ -19,6 +20,13 @@ async function formatFilesWithPrettierIfAvailable(files, root, options) {
|
|
19
20
|
let prettier;
|
20
21
|
try {
|
21
22
|
prettier = await Promise.resolve().then(() => require('prettier'));
|
23
|
+
/**
|
24
|
+
* Even after we discovered prettier in node_modules, we need to be sure that the user is intentionally using prettier
|
25
|
+
* before proceeding to format with it.
|
26
|
+
*/
|
27
|
+
if (!(0, is_using_prettier_1.isUsingPrettier)(root)) {
|
28
|
+
return results;
|
29
|
+
}
|
22
30
|
}
|
23
31
|
catch { }
|
24
32
|
if (!prettier) {
|
@@ -6,5 +6,9 @@ const tree_1 = require("../tree");
|
|
6
6
|
* Creates a host for testing.
|
7
7
|
*/
|
8
8
|
function createTree() {
|
9
|
-
|
9
|
+
const tree = new tree_1.FsTree('/virtual', false);
|
10
|
+
// Allow prettier formatting to be applied to the tree for backwards compatibility within v20
|
11
|
+
// TODO: Decouple formatFiles and other formatting utilities from prettier to avoid this
|
12
|
+
tree.write('.prettierrc', '{}');
|
13
|
+
return tree;
|
10
14
|
}
|
Binary file
|
@@ -265,7 +265,7 @@ plugins) {
|
|
265
265
|
e
|
266
266
|
: // This represents a single plugin erroring out with a hard error.
|
267
267
|
new error_types_1.AggregateCreateNodesError([[null, e]], []);
|
268
|
-
if (pluginIndex) {
|
268
|
+
if (pluginIndex !== undefined) {
|
269
269
|
error.pluginIndex = pluginIndex;
|
270
270
|
}
|
271
271
|
(0, error_types_1.formatAggregateCreateNodesError)(error, pluginName);
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { TaskResult } from '../../config/misc-interfaces';
|
2
2
|
import type { TaskGraph } from '../../config/task-graph';
|
3
|
+
import type { ProjectGraph } from '../../config/project-graph';
|
3
4
|
export declare enum BatchMessageType {
|
4
5
|
RunTasks = 0,
|
5
6
|
CompleteTask = 1,
|
@@ -18,6 +19,7 @@ export interface BatchTaskResult {
|
|
18
19
|
export interface RunTasksMessage {
|
19
20
|
type: BatchMessageType.RunTasks;
|
20
21
|
executorName: string;
|
22
|
+
projectGraph: ProjectGraph;
|
21
23
|
batchTaskGraph: TaskGraph;
|
22
24
|
fullTaskGraph: TaskGraph;
|
23
25
|
}
|
@@ -11,9 +11,8 @@ function getBatchExecutor(executorName, projects) {
|
|
11
11
|
const [nodeModule, exportName] = executorName.split(':');
|
12
12
|
return (0, executor_utils_1.getExecutorInformation)(nodeModule, exportName, workspace_root_1.workspaceRoot, projects);
|
13
13
|
}
|
14
|
-
async function runTasks(executorName, batchTaskGraph, fullTaskGraph) {
|
14
|
+
async function runTasks(executorName, projectGraph, batchTaskGraph, fullTaskGraph) {
|
15
15
|
const input = {};
|
16
|
-
const projectGraph = await (0, project_graph_1.createProjectGraphAsync)();
|
17
16
|
const projectsConfigurations = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
|
18
17
|
const nxJsonConfiguration = (0, configuration_1.readNxJson)();
|
19
18
|
const batchExecutor = getBatchExecutor(executorName, projectsConfigurations.projects);
|
@@ -66,7 +65,7 @@ async function runTasks(executorName, batchTaskGraph, fullTaskGraph) {
|
|
66
65
|
process.on('message', async (message) => {
|
67
66
|
switch (message.type) {
|
68
67
|
case batch_messages_1.BatchMessageType.RunTasks: {
|
69
|
-
const results = await runTasks(message.executorName, message.batchTaskGraph, message.fullTaskGraph);
|
68
|
+
const results = await runTasks(message.executorName, message.projectGraph, message.batchTaskGraph, message.fullTaskGraph);
|
70
69
|
process.send({
|
71
70
|
type: batch_messages_1.BatchMessageType.CompleteBatchExecution,
|
72
71
|
results,
|
@@ -2,6 +2,7 @@ import { DefaultTasksRunnerOptions } from './default-tasks-runner';
|
|
2
2
|
import { Batch } from './tasks-schedule';
|
3
3
|
import { BatchResults } from './batch/batch-messages';
|
4
4
|
import { Task, TaskGraph } from '../config/task-graph';
|
5
|
+
import { ProjectGraph } from '../config/project-graph';
|
5
6
|
export declare class ForkedProcessTaskRunner {
|
6
7
|
private readonly options;
|
7
8
|
cliPath: string;
|
@@ -10,7 +11,7 @@ export declare class ForkedProcessTaskRunner {
|
|
10
11
|
private pseudoTerminal;
|
11
12
|
constructor(options: DefaultTasksRunnerOptions);
|
12
13
|
init(): Promise<void>;
|
13
|
-
forkProcessForBatch({ executorName, taskGraph: batchTaskGraph }: Batch, fullTaskGraph: TaskGraph, env: NodeJS.ProcessEnv): Promise<BatchResults>;
|
14
|
+
forkProcessForBatch({ executorName, taskGraph: batchTaskGraph }: Batch, projectGraph: ProjectGraph, fullTaskGraph: TaskGraph, env: NodeJS.ProcessEnv): Promise<BatchResults>;
|
14
15
|
forkProcessLegacy(task: Task, { temporaryOutputPath, streamOutput, pipeOutput, taskGraph, env, }: {
|
15
16
|
temporaryOutputPath: string;
|
16
17
|
streamOutput: boolean;
|
@@ -31,7 +31,7 @@ class ForkedProcessTaskRunner {
|
|
31
31
|
this.setupProcessEventListeners();
|
32
32
|
}
|
33
33
|
// TODO: vsavkin delegate terminal output printing
|
34
|
-
forkProcessForBatch({ executorName, taskGraph: batchTaskGraph }, fullTaskGraph, env) {
|
34
|
+
forkProcessForBatch({ executorName, taskGraph: batchTaskGraph }, projectGraph, fullTaskGraph, env) {
|
35
35
|
return new Promise((res, rej) => {
|
36
36
|
try {
|
37
37
|
const count = Object.keys(batchTaskGraph.tasks).length;
|
@@ -83,6 +83,7 @@ class ForkedProcessTaskRunner {
|
|
83
83
|
p.send({
|
84
84
|
type: batch_messages_1.BatchMessageType.RunTasks,
|
85
85
|
executorName,
|
86
|
+
projectGraph,
|
86
87
|
batchTaskGraph,
|
87
88
|
fullTaskGraph,
|
88
89
|
});
|
@@ -134,8 +134,8 @@ class TaskOrchestrator {
|
|
134
134
|
const shouldCopyOutputsFromCache =
|
135
135
|
// No output files to restore
|
136
136
|
!!outputs.length &&
|
137
|
-
// Remote caches are restored to output dirs when applied
|
138
|
-
!cachedResult.remote &&
|
137
|
+
// Remote caches are restored to output dirs when applied and using db cache
|
138
|
+
(!cachedResult.remote || !(0, cache_1.dbCacheEnabled)(this.nxJson)) &&
|
139
139
|
// Output files have not been touched since last run
|
140
140
|
(await this.shouldCopyOutputsFromCache(outputs, task.hash));
|
141
141
|
if (shouldCopyOutputsFromCache) {
|
@@ -182,7 +182,7 @@ class TaskOrchestrator {
|
|
182
182
|
}
|
183
183
|
async runBatch(batch, env) {
|
184
184
|
try {
|
185
|
-
const results = await this.forkedProcessTaskRunner.forkProcessForBatch(batch, this.taskGraph, env);
|
185
|
+
const results = await this.forkedProcessTaskRunner.forkProcessForBatch(batch, this.projectGraph, this.taskGraph, env);
|
186
186
|
const batchResultEntries = Object.entries(results);
|
187
187
|
return batchResultEntries.map(([taskId, result]) => ({
|
188
188
|
...result,
|
@@ -0,0 +1,62 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isUsingPrettier = isUsingPrettier;
|
4
|
+
exports.isUsingPrettierInTree = isUsingPrettierInTree;
|
5
|
+
const node_fs_1 = require("node:fs");
|
6
|
+
const node_path_1 = require("node:path");
|
7
|
+
const json_1 = require("../generators/utils/json");
|
8
|
+
const fileutils_1 = require("./fileutils");
|
9
|
+
/**
|
10
|
+
* Possible configuration files are taken from https://prettier.io/docs/configuration
|
11
|
+
*/
|
12
|
+
const configFiles = [
|
13
|
+
'.prettierrc',
|
14
|
+
'.prettierrc.json',
|
15
|
+
'.prettierrc.yml',
|
16
|
+
'.prettierrc.yaml',
|
17
|
+
'.prettierrc.json5',
|
18
|
+
'.prettierrc.js',
|
19
|
+
'prettier.config.js',
|
20
|
+
'.prettierrc.ts',
|
21
|
+
'prettier.config.ts',
|
22
|
+
'.prettierrc.mjs',
|
23
|
+
'prettier.config.mjs',
|
24
|
+
'.prettierrc.mts',
|
25
|
+
'prettier.config.mts',
|
26
|
+
'.prettierrc.cjs',
|
27
|
+
'prettier.config.cjs',
|
28
|
+
'.prettierrc.cts',
|
29
|
+
'prettier.config.cts',
|
30
|
+
'.prettierrc.toml',
|
31
|
+
];
|
32
|
+
function isUsingPrettier(root) {
|
33
|
+
for (const file of configFiles) {
|
34
|
+
if ((0, node_fs_1.existsSync)(file)) {
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
// Even if no file is present, it is possible the user is configuring prettier via their package.json
|
39
|
+
const packageJsonPath = (0, node_path_1.join)(root, 'package.json');
|
40
|
+
if ((0, node_fs_1.existsSync)(packageJsonPath)) {
|
41
|
+
const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
|
42
|
+
if (packageJson.prettier) {
|
43
|
+
return true;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
function isUsingPrettierInTree(tree) {
|
49
|
+
for (const file of configFiles) {
|
50
|
+
if (tree.exists(file)) {
|
51
|
+
return true;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
// Even if no file is present, it is possible the user is configuring prettier via their package.json
|
55
|
+
if (tree.exists('package.json')) {
|
56
|
+
const packageJson = (0, json_1.readJson)(tree, 'package.json');
|
57
|
+
if (packageJson.prettier) {
|
58
|
+
return true;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
return false;
|
62
|
+
}
|