Skip to content

Commit

Permalink
feat(core): deprecate custom task runners (#28253)
Browse files Browse the repository at this point in the history
## Current Behavior
<!-- This is the behavior we have today -->

Custom task runners are a high level abstraction to customize caching, a
relatively low level mechanism, to utilize other methods of remote
caching. The abstraction of custom task runners makes it hard for Nx to
make guarantees to make it faster.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

Custom task runners are now deprecated. They will still work for Nx 20
but a warning will be shown when they are being used. The migration path
is to use Nx Cloud (the ideal caching solution) or a Nx Powerpack cache
(written by the Nx Core team which we can make guarantees about).

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
FrozenPandaz authored Oct 3, 2024
1 parent 81892b5 commit 23a217d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
5 changes: 4 additions & 1 deletion docs/generated/devkit/NxJsonConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ Dependencies between different target names across all projects

`Optional` **tasksRunnerOptions**: `Object`

Available Task Runners
**`Deprecated`**

Custom task runners will no longer be supported in Nx 21. Use Nx Cloud or Nx Powerpack instead.
Available Task Runners for Nx to use

#### Index signature

Expand Down
5 changes: 4 additions & 1 deletion docs/generated/devkit/Workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ Dependencies between different target names across all projects

`Optional` **tasksRunnerOptions**: `Object`

Available Task Runners
**`Deprecated`**

Custom task runners will no longer be supported in Nx 21. Use Nx Cloud or Nx Powerpack instead.
Available Task Runners for Nx to use

#### Index signature

Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/config/nx-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
appsDir?: string;
};
/**
* Available Task Runners
* @deprecated Custom task runners will no longer be supported in Nx 21. Use Nx Cloud or Nx Powerpack instead.
* Available Task Runners for Nx to use
*/
tasksRunnerOptions?: {
[tasksRunnerName: string]: {
Expand Down
21 changes: 19 additions & 2 deletions packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ export function getRunner(
runnerOptions: any;
} {
let runner = nxArgs.runner;
runner = runner || 'default';
runner = runner ?? 'default';

if (runner !== 'default' && !nxJson.tasksRunnerOptions?.[runner]) {
throw new Error(`Could not find runner configuration for ${runner}`);
Expand All @@ -799,6 +799,16 @@ export function getRunner(
const modulePath: string = getTasksRunnerPath(runner, nxJson);

try {
if (isCustomRunnerPath(modulePath)) {
output.warn({
title: `Custom task runners will no longer be supported in Nx 21.`,
bodyLines: [
`Use Nx Cloud or the Nx Powerpack caches instead.`,
`For more information, see https://nx.dev/features/powerpack/custom-caching`,
],
});
}

const tasksRunner = loadTasksRunner(modulePath);

return {
Expand All @@ -815,6 +825,8 @@ export function getRunner(
}
}

const defaultTasksRunnerPath = require.resolve('./default-tasks-runner');

function getTasksRunnerPath(
runner: string,
nxJson: NxJsonConfiguration<string[] | '*'>
Expand All @@ -838,7 +850,7 @@ function getTasksRunnerPath(
// Nx Cloud ID specified in nxJson
nxJson.nxCloudId;

return isCloudRunner ? 'nx-cloud' : require.resolve('./default-tasks-runner');
return isCloudRunner ? 'nx-cloud' : defaultTasksRunnerPath;
}

export function getRunnerOptions(
Expand Down Expand Up @@ -901,3 +913,8 @@ export function getRunnerOptions(

return result;
}
function isCustomRunnerPath(modulePath: string) {
return !['nx-cloud', '@nrwl/nx-cloud', defaultTasksRunnerPath].includes(
modulePath
);
}
3 changes: 3 additions & 0 deletions packages/nx/src/utils/command-line-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export interface RawNxArgs extends NxArgs {
export interface NxArgs {
targets?: string[];
configuration?: string;
/**
* @deprecated Custom task runners will no longer be supported in Nx 21. Use Nx Cloud or Nx Powerpack instead.
*/
runner?: string;
parallel?: number;
untracked?: boolean;
Expand Down

0 comments on commit 23a217d

Please sign in to comment.