-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): allow using Nx Cloud without nx-cloud installed (#19553)
- Loading branch information
1 parent
6857155
commit d62acec
Showing
39 changed files
with
1,040 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
docs/generated/packages/nx/generators/connect-to-nx-cloud.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "connect-to-nx-cloud", | ||
"factory": "./src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud", | ||
"schema": { | ||
"$schema": "http://json-schema.org/schema", | ||
"id": "NxCloudInit", | ||
"title": "Add Nx Cloud Configuration to the workspace", | ||
"description": "Connect a workspace to Nx Cloud.", | ||
"type": "object", | ||
"cli": "nx", | ||
"properties": { | ||
"analytics": { | ||
"type": "boolean", | ||
"description": "Anonymously store hashed machine ID for task runs", | ||
"default": false | ||
}, | ||
"installationSource": { | ||
"type": "string", | ||
"description": "Name of Nx Cloud installation invoker (ex. user, add-nx-to-monorepo, create-nx-workspace, nx-upgrade", | ||
"default": "user" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [], | ||
"presets": [] | ||
}, | ||
"description": "Connect a workspace to Nx Cloud", | ||
"x-hidden": true, | ||
"implementation": "/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.ts", | ||
"aliases": [], | ||
"hidden": false, | ||
"path": "/packages/nx/src/nx-cloud/generators/connect-to-nx-cloud/schema.json", | ||
"type": "generator" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { cleanupProject, newProject, runCLI } from '@nx/e2e/utils'; | ||
|
||
describe('Nx Cloud', () => { | ||
beforeAll(() => | ||
newProject({ | ||
unsetProjectNameAndRootFormat: false, | ||
}) | ||
); | ||
|
||
const libName = 'test-lib'; | ||
beforeAll(() => { | ||
runCLI('connect --no-interactive', { | ||
env: { | ||
...process.env, | ||
NX_CLOUD_API: 'https://staging.nx.app', | ||
}, | ||
}); | ||
runCLI(`generate @nx/js:lib ${libName} --no-interactive`); | ||
}); | ||
|
||
afterAll(() => cleanupProject()); | ||
|
||
it('should cache tests', async () => { | ||
// Should be able to view logs with Nx Cloud | ||
expect(runCLI(`test ${libName}`)).toContain( | ||
`View logs and investigate cache misses at https://staging.nx.app` | ||
); | ||
|
||
// Reset Local cache | ||
runCLI(`reset`); | ||
|
||
// Should be pull cache from Nx Cloud | ||
expect(runCLI(`test ${libName}`)).toContain( | ||
`Nx Cloud made it possible to reuse test-lib: https://staging.nx.app` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env node | ||
|
||
import { findAncestorNodeModules } from '../src/nx-cloud/resolution-helpers'; | ||
import { getCloudOptions } from '../src/nx-cloud/utilities/get-cloud-options'; | ||
import { | ||
NxCloudClientUnavailableError, | ||
NxCloudEnterpriseOutdatedError, | ||
verifyOrUpdateNxCloudClient, | ||
} from '../src/nx-cloud/update-manager'; | ||
import type { CloudTaskRunnerOptions } from '../src/nx-cloud/nx-cloud-tasks-runner-shell'; | ||
import { output } from '../src/utils/output'; | ||
|
||
const command = process.argv[2]; | ||
|
||
const options = getCloudOptions(); | ||
|
||
Promise.resolve().then(async () => invokeCommandWithNxCloudClient(options)); | ||
|
||
async function invokeCommandWithNxCloudClient(options: CloudTaskRunnerOptions) { | ||
try { | ||
const { nxCloudClient } = await verifyOrUpdateNxCloudClient(options); | ||
|
||
const paths = findAncestorNodeModules(__dirname, []); | ||
nxCloudClient.configureLightClientRequire()(paths); | ||
|
||
if (command in nxCloudClient.commands) { | ||
nxCloudClient.commands[command]() | ||
.then(() => process.exit(0)) | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); | ||
} else { | ||
output.error({ | ||
title: `Unknown Command "${command}"`, | ||
}); | ||
output.log({ | ||
title: 'Available Commands:', | ||
bodyLines: Object.keys(nxCloudClient.commands).map((c) => `- ${c}`), | ||
}); | ||
process.exit(1); | ||
} | ||
} catch (e: any) { | ||
const body = ['Cannot run commands from the `nx-cloud` CLI.']; | ||
|
||
if (e instanceof NxCloudEnterpriseOutdatedError) { | ||
body.push( | ||
'If you are an Nx Enterprise customer, please reach out to your assigned Developer Productivity Engineer.', | ||
'If you are NOT an Nx Enterprise customer but are seeing this message, please reach out to [email protected].' | ||
); | ||
} | ||
|
||
if (e instanceof NxCloudClientUnavailableError) { | ||
body.unshift( | ||
'You may be offline. Please try again when you are back online.' | ||
); | ||
} | ||
|
||
output.error({ | ||
title: e.message, | ||
bodyLines: body, | ||
}); | ||
process.exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"generators": { | ||
"connect-to-nx-cloud": { | ||
"factory": "./src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud", | ||
"schema": "./src/nx-cloud/generators/connect-to-nx-cloud/schema.json", | ||
"description": "Connect a workspace to Nx Cloud", | ||
"x-hidden": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d62acec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app