Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): support migrating to canary versions of nx for testing #21812

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/shared/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The following environment variables are ones that you can set to change the beha

| Property | Type | Description |
| -------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| NX_ADD_PLUGINS | boolean | If set to false, Nx will not add plugins to infer tasks. This is true by default. Workspaces created before Nx 18 will have this disabled via a migration for backwards compatibility |
| NX_ADD_PLUGINS | boolean | If set to `false`, Nx will not add plugins to infer tasks. This is `true` by default. Workspaces created before Nx 18 will have this disabled via a migration for backwards compatibility |
| NX_BASE | string | The default base branch to use when calculating the affected projects. Can be overridden on the command line with `--base`. |
| NX_CACHE_DIRECTORY | string | The cache for task outputs is stored in `node_modules/.cache/nx` by default. Set this variable to use a different directory. |
| NX_CACHE_PROJECT_GRAPH | boolean | If set to `false`, disables the project graph cache. Most useful when developing a plugin that modifies the project graph. |
Expand All @@ -16,18 +16,19 @@ The following environment variables are ones that you can set to change the beha
| NX_PROJECT_GRAPH_CACHE_DIRECTORY | string | The project graph cache is stored in `node_modules/.cache/nx` by default. Set this variable to use a different directory. |
| NX_PROJECT_GRAPH_MAX_WORKERS | number | The number of workers to use when calculating the project graph. |
| NX_PARALLEL | number | The number of tasks Nx should run in parallel. Overrides any configured value inside nx.json |
| NX_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. Not read if NX_TASKS_RUNNER is set. |
| NX_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. Not read if `NX_TASKS_RUNNER` is set. |
| NX_SKIP_NX_CACHE | boolean | Rerun the tasks even when the results are available in the cache |
| NX_TASKS_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. Preferred over NX_RUNNER. |
| NX_TASKS_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. Preferred over `NX_RUNNER`. |
| NX_TASKS_RUNNER_DYNAMIC_OUTPUT | boolean | If set to `false`, will use non-dynamic terminal output strategy (what you see in CI), even when you terminal can support the dynamic version |
| NX_VERBOSE_LOGGING | boolean | If set to `true`, will print debug information useful for troubleshooting |
| NX_DRY_RUN | boolean | If set to `true`, will perform a dry run of the generator. No files will be created and no packages will be installed. |
| NX_INTERACTIVE | boolean | If set to `true`, will allow Nx to prompt you in the terminal to answer some further questions when running generators. |
| NX_GENERATE_QUIET | boolean | If set to `true`, will prevent Nx logging file operations during generate |
| NX_PREFER_TS_NODE | boolean | If set to `true`, Nx will use ts-node for local execution of plugins even if `@swc-node/register` is installed. |
| NX_PREFER_TS_NODE | boolean | If set to `true`, Nx will use `ts-node` for local execution of plugins even if `@swc-node/register` is installed. |
| NX_IGNORE_CYCLES | boolean | If set to `true`, Nx will ignore errors created by a task graph circular dependency. Can be overriden on the command line with `--nxIgnoreCycles` |
| NX_BATCH_MODE | boolean | If set to `true`, Nx will run task(s) in batches for executors which support batches. |
| NX_SKIP_LOG_GROUPING | boolean | If set to `true`, Nx will not group command's logs on CI. |
| NX_MIGRATE_CLI_VERSION | string | The version of Nx to use for running the `nx migrate` command. If not set, it defaults to `latest`. |

Nx will set the following environment variables so they can be accessible within the process even outside of executors and generators.

Expand Down
5 changes: 2 additions & 3 deletions packages/nx/src/command-line/migrate/command-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ function runMigration() {
}

function nxCliPath() {
const version = process.env.NX_MIGRATE_CLI_VERSION || 'latest';
try {
const packageManager = getPackageManagerCommand();

const { dirSync } = require('tmp');
const tmpDir = dirSync().name;
const version =
process.env.NX_MIGRATE_USE_NEXT === 'true' ? 'next' : 'latest';
writeJsonFile(path.join(tmpDir, 'package.json'), {
dependencies: {
nx: version,
Expand All @@ -157,7 +156,7 @@ function nxCliPath() {
return path.join(tmpDir, `node_modules`, '.bin', 'nx');
} catch (e) {
console.error(
'Failed to install the latest version of the migration script. Using the current version.'
`Failed to install the ${version} version of the migration script. Using the current version.`
);
if (process.env.NX_VERBOSE_LOGGING) {
console.error(e);
Expand Down
6 changes: 6 additions & 0 deletions packages/nx/src/command-line/migrate/migrate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,12 @@ describe('Migration', () => {
targetPackage: 'nx',
targetVersion: 'next',
});
expect(
await parseMigrationsOptions({ packageAndVersion: 'canary' })
).toMatchObject({
targetPackage: 'nx',
targetVersion: 'canary',
});
expect(
await parseMigrationsOptions({ packageAndVersion: '13.10.0' })
).toMatchObject({
Expand Down
6 changes: 4 additions & 2 deletions packages/nx/src/command-line/migrate/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ async function parseTargetPackageAndVersion(
if (
args === 'latest' ||
args === 'next' ||
args === 'canary' ||
valid(args) ||
args.match(/^\d+(?:\.\d+)?(?:\.\d+)?$/)
) {
Expand All @@ -724,7 +725,8 @@ async function parseTargetPackageAndVersion(
// on the registry
const targetVersion = await normalizeVersionWithTagCheck('nx', args);
const targetPackage =
!['latest', 'next'].includes(args) && lt(targetVersion, '14.0.0-beta.0')
!['latest', 'next', 'canary'].includes(args) &&
lt(targetVersion, '14.0.0-beta.0')
? '@nrwl/workspace'
: 'nx';

Expand Down Expand Up @@ -1177,7 +1179,7 @@ async function updateInstallationDetails(

async function isMigratingToNewMajor(from: string, to: string) {
from = normalizeVersion(from);
to = ['latest', 'next'].includes(to) ? to : normalizeVersion(to);
to = ['latest', 'next', 'canary'].includes(to) ? to : normalizeVersion(to);
if (!valid(from)) {
from = await resolvePackageVersionUsingRegistry('nx', from);
}
Expand Down