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 Sep 27, 2023
1 parent 3dc9366 commit 6c20939
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 12 deletions.
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
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: 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
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
2 changes: 1 addition & 1 deletion packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export function getRunner(
let runner = nxArgs.runner;
runner = runner || 'default';

if (runner !== 'default' && !nxJson.tasksRunnerOptions[runner]) {
if (runner !== 'default' && !nxJson.tasksRunnerOptions?.[runner]) {
throw new Error(`Could not find runner configuration for ${runner}`);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/tasks-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ export function isCacheableTask(
): boolean {
if (
task.cache !== undefined &&
process.env.NX_ALLOW_PROJECT_LEVEL_CACHE === 'true'
process.env.NX_ALLOW_PROJECT_LEVEL_CACHE === 'true' &&
!longRunningTask(task)
) {
return task.cache;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/nx/src/utils/nx-cloud-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readNxJson } from '../config/configuration';
import { NxJsonConfiguration, readNxJson } from '../config/nx-json';

export function isNxCloudUsed(nxJson = readNxJson()) {
export function isNxCloudUsed(nxJson: NxJsonConfiguration) {
return (
!!nxJson.accessToken ||
Object.values(nxJson.tasksRunnerOptions ?? {}).find(
Expand All @@ -10,7 +10,7 @@ export function isNxCloudUsed(nxJson = readNxJson()) {
}

export function getNxCloudUrl(): string {
const taskRunner = isNxCloudUsed();
const taskRunner = isNxCloudUsed(readNxJson());
if (!taskRunner) throw new Error('nx-cloud runner not find in nx.json');
return (
(typeof taskRunner === 'object' ? taskRunner.options.url : null) ??
Expand Down

0 comments on commit 6c20939

Please sign in to comment.