From 5bb12dc4afa98c2a0da3497e7b661254efe0ab29 Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Mon, 23 Sep 2019 16:12:47 -0400 Subject: [PATCH] fix(nx): add migrate packages --- .../api-workspace/npmscripts/migrate.md | 17 +-- .../react/api-workspace/npmscripts/migrate.md | 17 +-- docs/web/api-workspace/npmscripts/migrate.md | 17 +-- packages/tao/src/commands/migrate.ts | 6 +- packages/tao/src/compat/compat.ts | 4 + packages/workspace/migrations.json | 108 ++++++++++++++++++ .../workspace/src/command-line/nx-commands.ts | 19 +-- 7 files changed, 155 insertions(+), 33 deletions(-) diff --git a/docs/angular/api-workspace/npmscripts/migrate.md b/docs/angular/api-workspace/npmscripts/migrate.md index 947b409c9227e..3116eb22f74b1 100644 --- a/docs/angular/api-workspace/npmscripts/migrate.md +++ b/docs/angular/api-workspace/npmscripts/migrate.md @@ -1,14 +1,15 @@ -# migrate + # migrate + Creates a migrations file or runs migrations from the migrations file. -Creates a migrations file or runs migrations from the migrations file. +- Migrate packages and create migrations.json (e.g., nx migrate @nrwl/workspace@latest) +- Run migrations (e.g., nx migrate --run-migrations=migrations.json) -## Usage + ## Usage + ```bash + nx migrate + ``` -```bash -nx migrate -``` - -Install `@nrwl/cli` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`. + Install `@nrwl/cli` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`. ## Options diff --git a/docs/react/api-workspace/npmscripts/migrate.md b/docs/react/api-workspace/npmscripts/migrate.md index 947b409c9227e..3116eb22f74b1 100644 --- a/docs/react/api-workspace/npmscripts/migrate.md +++ b/docs/react/api-workspace/npmscripts/migrate.md @@ -1,14 +1,15 @@ -# migrate + # migrate + Creates a migrations file or runs migrations from the migrations file. -Creates a migrations file or runs migrations from the migrations file. +- Migrate packages and create migrations.json (e.g., nx migrate @nrwl/workspace@latest) +- Run migrations (e.g., nx migrate --run-migrations=migrations.json) -## Usage + ## Usage + ```bash + nx migrate + ``` -```bash -nx migrate -``` - -Install `@nrwl/cli` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`. + Install `@nrwl/cli` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`. ## Options diff --git a/docs/web/api-workspace/npmscripts/migrate.md b/docs/web/api-workspace/npmscripts/migrate.md index 947b409c9227e..3116eb22f74b1 100644 --- a/docs/web/api-workspace/npmscripts/migrate.md +++ b/docs/web/api-workspace/npmscripts/migrate.md @@ -1,14 +1,15 @@ -# migrate + # migrate + Creates a migrations file or runs migrations from the migrations file. -Creates a migrations file or runs migrations from the migrations file. +- Migrate packages and create migrations.json (e.g., nx migrate @nrwl/workspace@latest) +- Run migrations (e.g., nx migrate --run-migrations=migrations.json) -## Usage + ## Usage + ```bash + nx migrate + ``` -```bash -nx migrate -``` - -Install `@nrwl/cli` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`. + Install `@nrwl/cli` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`. ## Options diff --git a/packages/tao/src/commands/migrate.ts b/packages/tao/src/commands/migrate.ts index ea12c2939fe24..121175c416cf9 100644 --- a/packages/tao/src/commands/migrate.ts +++ b/packages/tao/src/commands/migrate.ts @@ -291,8 +291,8 @@ async function fetch( let migrationsFile = json['nx-migrations'] || json['ng-update']; // migrationsFile is an object - if (migrationsFile.migration) { - migrationsFile = migrationsFile.migration; + if (migrationsFile && migrationsFile.migrations) { + migrationsFile = migrationsFile.migrations; } // packageVersion can be a tag, resolvedVersion works with semver @@ -357,6 +357,8 @@ async function generateMigrationsJsonAndUpdatePackageJson( to: { [p: string]: string }; } ) { + logger.info(`Fetching meta data about packages.`); + logger.info(`It may take a few minutes.`); const migrator = new Migrator({ versions: versions(root), fetch, diff --git a/packages/tao/src/compat/compat.ts b/packages/tao/src/compat/compat.ts index 9a47abd1ddfd1..8dd138c6f9a0b 100644 --- a/packages/tao/src/compat/compat.ts +++ b/packages/tao/src/compat/compat.ts @@ -22,3 +22,7 @@ Module.prototype.require = function() { try { require('@angular-devkit/build-angular/src/utils/version').Version.assertCompatibleAngularVersion = () => {}; } catch (e) {} + +try { + require('@angular-devkit/build-angular/src/utils/version').assertCompatibleAngularVersion = () => {}; +} catch (e) {} diff --git a/packages/workspace/migrations.json b/packages/workspace/migrations.json index e127152c4eafb..0669b3a5337cf 100644 --- a/packages/workspace/migrations.json +++ b/packages/workspace/migrations.json @@ -30,5 +30,113 @@ "description": "Fix the exclude paths in tsconfig.lib.json files for Jest projects", "factory": "./src/migrations/update-8-5-0/fix-tsconfig-lib-json" } + }, + "packageJsonUpdates": { + "852": { + "version": "8.5.2", + "packages": { + "@nrwl/angular": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/cypress": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/eslint-plugin-nx": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/express": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/jest": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/linter": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/nest": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/next": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/node": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/react": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/tao": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + }, + "@nrwl/web": { + "version": "8.5.2", + "alwaysAddToPackageJson": false + } + } + }, + "853": { + "version": "8.5.3", + "packages": { + "@nrwl/angular": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/cypress": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/eslint-plugin-nx": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/express": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/jest": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/linter": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/nest": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/next": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/node": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/react": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/tao": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + }, + "@nrwl/web": { + "version": "8.5.3", + "alwaysAddToPackageJson": false + } + } + } } } diff --git a/packages/workspace/src/command-line/nx-commands.ts b/packages/workspace/src/command-line/nx-commands.ts index ce8a47fe4295b..fa4bb954c0b9d 100644 --- a/packages/workspace/src/command-line/nx-commands.ts +++ b/packages/workspace/src/command-line/nx-commands.ts @@ -8,6 +8,7 @@ import { workspaceSchematic } from './workspace-schematic'; import { generateGraph, OutputType } from './dep-graph'; import { nxVersion } from '../utils/versions'; import { execSync } from 'child_process'; +import { platform } from 'os'; const noop = (yargs: yargs.Argv): yargs.Argv => yargs; @@ -182,15 +183,19 @@ export const commandsObject = yargs ) .command( 'migrate', - 'Creates a migrations file or runs migrations from the migrations file.', + `Creates a migrations file or runs migrations from the migrations file. +- Migrate packages and create migrations.json (e.g., nx migrate @nrwl/workspace@latest) +- Run migrations (e.g., nx migrate --run-migrations=migrations.json) + `, yargs => yargs, () => { - execSync( - `./node_modules/.bin/tao migrate ${process.argv.slice(3).join(' ')}`, - { - stdio: ['inherit', 'inherit', 'inherit'] - } - ); + const executable = + platform() === 'win32' + ? `.\\node_modules\\.bin\\tao` + : `./node_modules/.bin/tao`; + execSync(`${executable} migrate ${process.argv.slice(3).join(' ')}`, { + stdio: ['inherit', 'inherit', 'inherit'] + }); } ) .help('help')