Skip to content

Commit

Permalink
chore(core): misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Oct 4, 2023
1 parent 6965544 commit d140b5e
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 77 deletions.
28 changes: 14 additions & 14 deletions docs/generated/devkit/NxJsonConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Nx.json configuration

### Properties

- [accessToken](../../devkit/documents/NxJsonConfiguration#accesstoken): string
- [affected](../../devkit/documents/NxJsonConfiguration#affected): NxAffectedConfig
- [cacheDirectory](../../devkit/documents/NxJsonConfiguration#cachedirectory): string
- [cli](../../devkit/documents/NxJsonConfiguration#cli): Object
Expand All @@ -29,6 +28,7 @@ Nx.json configuration
- [installation](../../devkit/documents/NxJsonConfiguration#installation): NxInstallationConfiguration
- [namedInputs](../../devkit/documents/NxJsonConfiguration#namedinputs): Object
- [npmScope](../../devkit/documents/NxJsonConfiguration#npmscope): string
- [nxCloudAccessToken](../../devkit/documents/NxJsonConfiguration#nxcloudaccesstoken): string
- [parallel](../../devkit/documents/NxJsonConfiguration#parallel): number
- [plugins](../../devkit/documents/NxJsonConfiguration#plugins): string[]
- [pluginsConfig](../../devkit/documents/NxJsonConfiguration#pluginsconfig): Record<string, unknown>
Expand All @@ -40,15 +40,6 @@ Nx.json configuration

## Properties

### accessToken

`Optional` **accessToken**: `string`

If specified Nx will use nx-cloud by default with the given token.
To use a different runner that accepts an access token, define it in [tasksRunnerOptions](../../devkit/documents/Workspace#tasksrunneroptions)

---

### affected

`Optional` **affected**: [`NxAffectedConfig`](../../devkit/documents/NxAffectedConfig)
Expand All @@ -61,7 +52,7 @@ Default options for `nx affected`

`Optional` **cacheDirectory**: `string`

Changes the default location of the cache directory.
Changes the directory used by Nx to store its cache.

---

Expand Down Expand Up @@ -169,11 +160,20 @@ NPM Scope that the workspace uses

---

### nxCloudAccessToken

`Optional` **nxCloudAccessToken**: `string`

If specified Nx will use nx-cloud by default with the given token.
To use a different runner that accepts an access token, define it in [tasksRunnerOptions](../../devkit/documents/Workspace#tasksrunneroptions)

---

### parallel

`Optional` **parallel**: `number`

Specifies how many tasks are ran in parallel by Nx for the default tasks runner.
Specifies how many tasks can be run in parallel.

---

Expand Down Expand Up @@ -203,7 +203,7 @@ Configuration for Nx Plugins

### targetDefaults

`Optional` **targetDefaults**: `TargetDefaults`
`Optional` **targetDefaults**: [`TargetDefaults`](../../devkit/documents/TargetDefaults)

Dependencies between different target names across all projects

Expand All @@ -225,7 +225,7 @@ Available Task Runners

`Optional` **useDaemonProcess**: `boolean`

Allows turning the daemon off if set to false explicitly.
Set this to false to disable the daemon.

---

Expand Down
1 change: 1 addition & 0 deletions docs/generated/devkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ It only uses language primitives and immutable objects
- [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency)
- [StaticDependency](../../devkit/documents/StaticDependency)
- [StringChange](../../devkit/documents/StringChange)
- [TargetDefaults](../../devkit/documents/TargetDefaults)
- [TaskGraphExecutor](../../devkit/documents/TaskGraphExecutor)
- [WorkspaceConfiguration](../../devkit/documents/WorkspaceConfiguration)
- [WorkspaceJsonConfiguration](../../devkit/documents/WorkspaceJsonConfiguration)
Expand Down
10 changes: 0 additions & 10 deletions docs/generated/devkit/TargetConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Target's configuration

### Properties

- [cache](../../devkit/documents/TargetConfiguration#cache): boolean
- [command](../../devkit/documents/TargetConfiguration#command): string
- [configurations](../../devkit/documents/TargetConfiguration#configurations): Object
- [defaultConfiguration](../../devkit/documents/TargetConfiguration#defaultconfiguration): string
Expand All @@ -24,15 +23,6 @@ Target's configuration

## Properties

### cache

`Optional` **cache**: `boolean`

Determines if Nx is able to cache a given target.
Currently only supported in `targetDefaults`.

---

### command

`Optional` **command**: `string`
Expand Down
3 changes: 3 additions & 0 deletions docs/generated/devkit/TargetDefaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Type alias: TargetDefaults

Ƭ **TargetDefaults**: `Record`<`string`, `Partial`<[`TargetConfiguration`](../../devkit/documents/TargetConfiguration)\> & { `cache?`: `boolean` }\>
36 changes: 18 additions & 18 deletions docs/generated/devkit/Workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use ProjectsConfigurations or NxJsonConfiguration

### Properties

- [accessToken](../../devkit/documents/Workspace#accesstoken): string
- [affected](../../devkit/documents/Workspace#affected): NxAffectedConfig
- [cacheDirectory](../../devkit/documents/Workspace#cachedirectory): string
- [cli](../../devkit/documents/Workspace#cli): Object
Expand All @@ -27,6 +26,7 @@ use ProjectsConfigurations or NxJsonConfiguration
- [installation](../../devkit/documents/Workspace#installation): NxInstallationConfiguration
- [namedInputs](../../devkit/documents/Workspace#namedinputs): Object
- [npmScope](../../devkit/documents/Workspace#npmscope): string
- [nxCloudAccessToken](../../devkit/documents/Workspace#nxcloudaccesstoken): string
- [parallel](../../devkit/documents/Workspace#parallel): number
- [plugins](../../devkit/documents/Workspace#plugins): string[]
- [pluginsConfig](../../devkit/documents/Workspace#pluginsconfig): Record&lt;string, unknown&gt;
Expand All @@ -40,19 +40,6 @@ use ProjectsConfigurations or NxJsonConfiguration

## Properties

### accessToken

`Optional` **accessToken**: `string`

If specified Nx will use nx-cloud by default with the given token.
To use a different runner that accepts an access token, define it in [tasksRunnerOptions](../../devkit/documents/Workspace#tasksrunneroptions)

#### Inherited from

[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[accessToken](../../devkit/documents/NxJsonConfiguration#accesstoken)

---

### affected

`Optional` **affected**: [`NxAffectedConfig`](../../devkit/documents/NxAffectedConfig)
Expand All @@ -69,7 +56,7 @@ Default options for `nx affected`

`Optional` **cacheDirectory**: `string`

Changes the default location of the cache directory.
Changes the directory used by Nx to store its cache.

#### Inherited from

Expand Down Expand Up @@ -213,11 +200,24 @@ NPM Scope that the workspace uses

---

### nxCloudAccessToken

`Optional` **nxCloudAccessToken**: `string`

If specified Nx will use nx-cloud by default with the given token.
To use a different runner that accepts an access token, define it in [tasksRunnerOptions](../../devkit/documents/Workspace#tasksrunneroptions)

#### Inherited from

[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[nxCloudAccessToken](../../devkit/documents/NxJsonConfiguration#nxcloudaccesstoken)

---

### parallel

`Optional` **parallel**: `number`

Specifies how many tasks are ran in parallel by Nx for the default tasks runner.
Specifies how many tasks can be run in parallel.

#### Inherited from

Expand Down Expand Up @@ -275,7 +275,7 @@ Projects' projects

### targetDefaults

`Optional` **targetDefaults**: `TargetDefaults`
`Optional` **targetDefaults**: [`TargetDefaults`](../../devkit/documents/TargetDefaults)

Dependencies between different target names across all projects

Expand Down Expand Up @@ -305,7 +305,7 @@ Available Task Runners

`Optional` **useDaemonProcess**: `boolean`

Allows turning the daemon off if set to false explicitly.
Set this to false to disable the daemon.

#### Inherited from

Expand Down
1 change: 1 addition & 0 deletions docs/generated/packages/devkit/documents/nx_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ It only uses language primitives and immutable objects
- [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency)
- [StaticDependency](../../devkit/documents/StaticDependency)
- [StringChange](../../devkit/documents/StringChange)
- [TargetDefaults](../../devkit/documents/TargetDefaults)
- [TaskGraphExecutor](../../devkit/documents/TaskGraphExecutor)
- [WorkspaceConfiguration](../../devkit/documents/WorkspaceConfiguration)
- [WorkspaceJsonConfiguration](../../devkit/documents/WorkspaceJsonConfiguration)
Expand Down
16 changes: 16 additions & 0 deletions packages/nx/schemas/nx-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@
"defaultProject": {
"type": "string",
"description": "Default project. When project isn't provided, the default project will be used."
},
"accessToken": {
"type": "string",
"description": "The access token to use for nx-cloud. If set, the default tasks runner will be nx-cloud."
},
"parallel": {
"type": "number",
"description": "Specifies how many tasks are ran in parallel by Nx for the default tasks runner."
},
"cacheDirectory": {
"type": "string",
"description": "Specifies the default location of the cache directory."
},
"useDaemonProcess": {
"type": "boolean",
"description": "Specifies whether the daemon should be used for the default tasks runner."
}
},
"definitions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function connectToNxCloudIfExplicitlyAsked(opts: {
export async function connectToNxCloudCommand(
promptOverride?: string
): Promise<boolean> {
if (isNxCloudUsed()) {
if (isNxCloudUsed(readNxJson())) {
output.log({
title: '✅ This workspace is already connected to Nx Cloud.',
bodyLines: [
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/command-line/connect/view-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { execSync } from 'child_process';
import { isNxCloudUsed } from '../../utils/nx-cloud-utils';
import { output } from '../../utils/output';
import { runNxSync } from '../../utils/child-process';
import { readNxJson } from '../../config/nx-json';

export async function viewLogs(): Promise<number> {
const cloudUsed = isNxCloudUsed();
const cloudUsed = isNxCloudUsed(readNxJson());
if (cloudUsed) {
output.error({
title: 'Your workspace is already connected to Nx Cloud',
Expand Down
9 changes: 5 additions & 4 deletions packages/nx/src/command-line/migrate/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,16 +1203,17 @@ async function generateMigrationsJsonAndUpdatePackageJson(
let originalPackageJson = existsSync(rootPkgJsonPath)
? readJsonFile<PackageJson>(rootPkgJsonPath)
: null;
const originalNxInstallation = readNxJson().installation;
const originalNxJson = readNxJson();
const from =
originalNxInstallation?.version ?? readNxVersion(originalPackageJson);
originalNxJson.installation?.version ??
readNxVersion(originalPackageJson);

try {
if (
['nx', '@nrwl/workspace'].includes(opts.targetPackage) &&
(await isMigratingToNewMajor(from, opts.targetVersion)) &&
!isCI() &&
!isNxCloudUsed()
!isNxCloudUsed(originalNxJson)
) {
const useCloud = await connectToNxCloudCommand(
messages.getPromptMessage('nxCloudMigration')
Expand All @@ -1237,7 +1238,7 @@ async function generateMigrationsJsonAndUpdatePackageJson(

const migrator = new Migrator({
packageJson: originalPackageJson,
nxInstallation: originalNxInstallation,
nxInstallation: originalNxJson.installation,
getInstalledPackageVersion: createInstalledPackageVersionsResolver(root),
fetch: createFetcher(),
from: opts.from,
Expand Down
19 changes: 14 additions & 5 deletions packages/nx/src/config/nx-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ export interface NxAffectedConfig {
defaultBase?: string;
}

export type TargetDefaults = Record<string, Partial<TargetConfiguration>>;
export type TargetDefaults = Record<
string,
Partial<TargetConfiguration> & {
/**
* Determines if Nx is able to cache a given target.
* Currently only supported in `targetDefaults`.
*/
cache?: boolean;
}
>;

export type TargetDependencies = Record<
string,
Expand Down Expand Up @@ -196,20 +205,20 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
* If specified Nx will use nx-cloud by default with the given token.
* To use a different runner that accepts an access token, define it in {@link tasksRunnerOptions}
*/
accessToken?: string;
nxCloudAccessToken?: string;

/**
* Specifies how many tasks are ran in parallel by Nx for the default tasks runner.
* Specifies how many tasks can be run in parallel.
*/
parallel?: number;

/**
* Changes the default location of the cache directory.
* Changes the directory used by Nx to store its cache.
*/
cacheDirectory?: string;

/**
* Allows turning the daemon off if set to false explicitly.
* Set this to false to disable the daemon.
*/
useDaemonProcess?: boolean;
}
Expand Down
6 changes: 0 additions & 6 deletions packages/nx/src/config/workspace-json-project-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,4 @@ export interface TargetConfiguration<T = any> {
* A default named configuration to use when a target configuration is not provided.
*/
defaultConfiguration?: string;

/**
* Determines if Nx is able to cache a given target.
* Currently only supported in `targetDefaults`.
*/
cache?: boolean;
}
1 change: 1 addition & 0 deletions packages/nx/src/daemon/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class DaemonClient {

enabled() {
if (this._enabled === undefined) {
// TODO(v18): Add migration to move it out of existing configs and remove the ?? here.
const useDaemonProcessOption =
this.nxJson.useDaemonProcess ??
this.nxJson.tasksRunnerOptions?.['default']?.options?.useDaemonProcess;
Expand Down
1 change: 1 addition & 0 deletions packages/nx/src/devkit-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type {
ImplicitDependencyEntry,
ImplicitJsonSubsetDependency,
NxJsonConfiguration,
TargetDefaults,
NxAffectedConfig,
} from './config/nx-json';

Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/generators/utils/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function updateWorkspaceConfiguration(
extends: ext,
installation,
release,
accessToken,
nxCloudAccessToken,
cacheDirectory,
parallel,
useDaemonProcess,
Expand All @@ -62,7 +62,7 @@ export function updateWorkspaceConfiguration(
extends: ext,
installation,
release,
accessToken,
nxCloudAccessToken,
cacheDirectory,
parallel,
useDaemonProcess,
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/tasks-runner/create-task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ export class ProcessTasks {
target: qualifiedTarget,
projectRoot: project.data.root,
overrides: interpolateOverrides(overrides, project.name, project.data),
cache: project.data.targets[target].cache,
// TODO(v18): Remove cast here after typing is moved back onto TargetConfiguration
cache: (project.data.targets[target] as any).cache,
};
}

Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/tasks-runner/life-cycles/view-logs-utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { readNxJson } from '../../config/nx-json';
import { isNxCloudUsed } from '../../utils/nx-cloud-utils';
import { output } from '../../utils/output';

const VIEW_LOGS_MESSAGE = `Hint: Try "nx view-logs" to get structured, searchable errors logs in your browser.`;

export function viewLogsFooterRows(failedTasks: number) {
if (failedTasks >= 2 && !isNxCloudUsed()) {
if (failedTasks >= 2 && !isNxCloudUsed(readNxJson())) {
return [``, output.dim(`${output.X_PADDING} ${VIEW_LOGS_MESSAGE}`)];
} else {
return [];
Expand Down
Loading

0 comments on commit d140b5e

Please sign in to comment.