diff --git a/docs/shared/using-nx/caching.md b/docs/shared/using-nx/caching.md index 7dd19cdf34..9a5c4b30d4 100644 --- a/docs/shared/using-nx/caching.md +++ b/docs/shared/using-nx/caching.md @@ -211,6 +211,31 @@ nx connect-to-nx-cloud You can also distribute the cache manually using your own storage mechanisms. +### Using Distributed Caching for Internal Commands + +By default, Nx Cloud is not used for Nx commands invoked from within other Nx commands. +For example, in the following configuration build1 and build2 won't be cached individually. + +```json +{ + "executor": "@nrwl/workspace:run-commands", + "options": { + "commands": ["nx build1 proj", "nx build2 proj"] + } +} +``` + +If you would like them to be cached individually, and a separate run to be created for each of them, add the following: + +```json +{ + "executor": "@nrwl/workspace:run-commands", + "options": { + "commands": ["NX_CLOUD=true nx build1 proj", "NX_CLOUD=true nx build2 proj"] + } +} +``` + ## Example - [This is an example repo](https://github.com/vsavkin/large-monorepo) benchmarking Nx's computation caching. It also explains why Nx's computation caching tends to be a lot faster than the caching of other build systems. diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts index f4de4304ee..67e4f6883e 100644 --- a/e2e/utils/index.ts +++ b/e2e/utils/index.ts @@ -354,7 +354,6 @@ export function runCommandAsync( env: { ...(opts.env || process.env), FORCE_COLOR: 'false', - NX_INVOKED_BY_RUNNER: undefined, }, encoding: 'utf-8', }, @@ -382,7 +381,6 @@ export function runCommandUntil( env: { ...process.env, FORCE_COLOR: 'false', - NX_INVOKED_BY_RUNNER: undefined, }, encoding: 'utf-8', }); @@ -440,7 +438,7 @@ export function runNgAdd( packageInstall(packageName, null, version); return execSync(pmc.run(`ng g ${packageName}:ng-add`, command), { cwd: tmpProjPath(), - env: { ...(opts.env || process.env), NX_INVOKED_BY_RUNNER: undefined }, + env: { ...(opts.env || process.env) }, encoding: 'utf-8', }) .toString() @@ -473,7 +471,7 @@ export function runCLI( let r = stripConsoleColors( execSync(`${pm.runNx} ${command}`, { cwd: opts.cwd || tmpProjPath(), - env: { ...(opts.env || process.env), NX_INVOKED_BY_RUNNER: undefined }, + env: { ...(opts.env || process.env) }, encoding: 'utf-8', maxBuffer: 50 * 1024 * 1024, }) @@ -529,7 +527,6 @@ export function runCommand( env: { ...process.env, FORCE_COLOR: 'false', - NX_INVOKED_BY_RUNNER: undefined, }, encoding: 'utf-8', ...options, diff --git a/package.json b/package.json index b3a0cfcf27..bed58ae570 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "@nrwl/linter": "13.10.0-beta.9", "@nrwl/next": "13.10.0-beta.9", "@nrwl/node": "13.10.0-beta.9", - "@nrwl/nx-cloud": "13.2.1", + "@nrwl/nx-cloud": "13.3.0-beta.0", "@nrwl/react": "13.10.0-beta.9", "@nrwl/web": "13.10.0-beta.9", "@nrwl/workspace": "13.10.0-beta.9", diff --git a/packages/nx/src/tasks-runner/forked-process-task-runner.ts b/packages/nx/src/tasks-runner/forked-process-task-runner.ts index ead53c7f80..a585458d03 100644 --- a/packages/nx/src/tasks-runner/forked-process-task-runner.ts +++ b/packages/nx/src/tasks-runner/forked-process-task-runner.ts @@ -276,7 +276,6 @@ export class ForkedProcessTaskRunner { ) { const env: NodeJS.ProcessEnv = { FORCE_COLOR: forceColor, - NX_INVOKED_BY_RUNNER: 'true', NX_WORKSPACE_ROOT: this.workspaceRoot, NX_SKIP_NX_CACHE: this.options.skipNxCache ? 'true' : undefined, }; diff --git a/packages/nx/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.ts b/packages/nx/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.ts index 80bccb965f..ee5ab25e63 100644 --- a/packages/nx/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.ts +++ b/packages/nx/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.ts @@ -27,9 +27,6 @@ export class StaticRunOneTerminalOutputLifeCycle implements LifeCycle { ) {} startCommand(): void { - if (process.env.NX_INVOKED_BY_RUNNER) { - return; - } const numberOfDeps = this.tasks.length - 1; if (numberOfDeps > 0) { @@ -46,10 +43,6 @@ export class StaticRunOneTerminalOutputLifeCycle implements LifeCycle { } endCommand(): void { - // Silent for a single task - if (process.env.NX_INVOKED_BY_RUNNER) { - return; - } output.addNewline(); if (this.failedTasks.length === 0) { diff --git a/scripts/e2e-build-package-publish.ts b/scripts/e2e-build-package-publish.ts index 41598ceb4a..3fc80e3222 100644 --- a/scripts/e2e-build-package-publish.ts +++ b/scripts/e2e-build-package-publish.ts @@ -133,7 +133,7 @@ function build(nxVersion: string) { `npx nx run-many --target=build --all --parallel=8 --exclude=${projectsToExclude}`, { stdio: ['pipe', 'pipe', 'pipe'], - env: { ...process.env, NX_INVOKED_BY_RUNNER: 'false' }, + env: { ...process.env, NX_CLOUD: 'true' }, } ); const a = new Date(); diff --git a/yarn.lock b/yarn.lock index 5dfaa88346..b5b3d1c5d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2837,12 +2837,13 @@ webpack-merge "^5.8.0" webpack-node-externals "^3.0.0" -"@nrwl/nx-cloud@13.2.1": - version "13.2.1" - resolved "https://registry.yarnpkg.com/@nrwl/nx-cloud/-/nx-cloud-13.2.1.tgz#14388d7122761e09bacc1da4ee8b26adb24309b0" - integrity sha512-fiZg0Y6U1amfOnv29wp3gBKc6eqNcEFj6iAlTBFF6ZW+JylH1aVzMHGiBdNLGX2y4aMVPILIfz61LY0Hphi0Gg== +"@nrwl/nx-cloud@13.3.0-beta.0": + version "13.3.0-beta.0" + resolved "https://registry.yarnpkg.com/@nrwl/nx-cloud/-/nx-cloud-13.3.0-beta.0.tgz#2d4a6cf5c35dd0ce5dcc4457735e87a371436afe" + integrity sha512-y2k06YbVc0vd7PszI8km3cRDTR8GWGVKtOgNfi/yg588234q+ugHwW2R2BDV7auAQqSmNZegraCZBloS70QKvA== dependencies: axios "^0.21.1" + chalk "4.1.0" node-machine-id "^1.1.12" strip-json-comments "^3.1.1" tar "6.1.11"