fix(nx): run angular migration in separate process
This commit is contained in:
parent
319c86d93b
commit
1b3f5840aa
@ -3,8 +3,10 @@ import {
|
|||||||
chain,
|
chain,
|
||||||
SchematicContext,
|
SchematicContext,
|
||||||
Tree,
|
Tree,
|
||||||
externalSchematic,
|
TaskConfigurationGenerator,
|
||||||
noop
|
TaskConfiguration,
|
||||||
|
TaskExecutorFactory,
|
||||||
|
externalSchematic
|
||||||
} from '@angular-devkit/schematics';
|
} from '@angular-devkit/schematics';
|
||||||
import { stripIndents } from '@angular-devkit/core/src/utils/literals';
|
import { stripIndents } from '@angular-devkit/core/src/utils/literals';
|
||||||
import {
|
import {
|
||||||
@ -25,9 +27,67 @@ import {
|
|||||||
ReplaceChange
|
ReplaceChange
|
||||||
} from '@nrwl/workspace/src/utils/ast-utils';
|
} from '@nrwl/workspace/src/utils/ast-utils';
|
||||||
import { relative } from 'path';
|
import { relative } from 'path';
|
||||||
|
import { RunSchematicTaskOptions } from '@angular-devkit/schematics/tasks/run-schematic/options';
|
||||||
|
import * as path from 'path';
|
||||||
|
import { platform } from 'os';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { spawn } from 'child_process';
|
||||||
|
|
||||||
const ignore = require('ignore');
|
const ignore = require('ignore');
|
||||||
|
|
||||||
|
export class RunUpdateTask implements TaskConfigurationGenerator<any> {
|
||||||
|
protected _package: string;
|
||||||
|
|
||||||
|
constructor(pkg: string) {
|
||||||
|
this._package = pkg;
|
||||||
|
}
|
||||||
|
|
||||||
|
toConfiguration(): TaskConfiguration<any> {
|
||||||
|
return {
|
||||||
|
name: 'RunUpdate',
|
||||||
|
options: {
|
||||||
|
package: this._package
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createRunUpdateTask(): TaskExecutorFactory<any> {
|
||||||
|
return {
|
||||||
|
name: 'RunUpdate',
|
||||||
|
create: () => {
|
||||||
|
return Promise.resolve((options: any, context: SchematicContext) => {
|
||||||
|
context.logger.info(`Updating ${options.package}`);
|
||||||
|
const spawnOptions = {
|
||||||
|
stdio: [process.stdin, process.stdout, process.stderr],
|
||||||
|
shell: true
|
||||||
|
};
|
||||||
|
const ng =
|
||||||
|
platform() === 'win32'
|
||||||
|
? '.\\node_modules\\.bin\\ng'
|
||||||
|
: './node_modules/.bin/ng';
|
||||||
|
const args = [
|
||||||
|
'update',
|
||||||
|
options.package,
|
||||||
|
'--force',
|
||||||
|
'--allow-dirty'
|
||||||
|
].filter(e => !!e);
|
||||||
|
return new Observable(obs => {
|
||||||
|
spawn(ng, args, spawnOptions).on('close', (code: number) => {
|
||||||
|
if (code === 0) {
|
||||||
|
obs.next();
|
||||||
|
obs.complete();
|
||||||
|
} else {
|
||||||
|
const message = `${options.package} migration failed, see above.`;
|
||||||
|
obs.error(new Error(message));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function addDependencies() {
|
function addDependencies() {
|
||||||
return (host: Tree, context: SchematicContext) => {
|
return (host: Tree, context: SchematicContext) => {
|
||||||
const dependencies = readJsonInTree(host, 'package.json').dependencies;
|
const dependencies = readJsonInTree(host, 'package.json').dependencies;
|
||||||
@ -340,39 +400,20 @@ export const runAngularMigrations: Rule = (
|
|||||||
host: Tree,
|
host: Tree,
|
||||||
context: SchematicContext
|
context: SchematicContext
|
||||||
) => {
|
) => {
|
||||||
const packageJson = readJsonInTree(host, 'package.json');
|
// Should always be there during ng update but not during tests.
|
||||||
|
if (!context.engine.workflow) {
|
||||||
if (!!packageJson.dependencies['@angular/core']) {
|
return;
|
||||||
if (
|
|
||||||
context.engine.workflow &&
|
|
||||||
context.engine.workflow.context.parentContext &&
|
|
||||||
!(context.engine.workflow.context.parentContext
|
|
||||||
.options as any).packages.includes('@angular/core')
|
|
||||||
) {
|
|
||||||
const message = `This migration should be run with the @angular/core migration`;
|
|
||||||
context.logger.error(message);
|
|
||||||
context.logger.info(
|
|
||||||
'\n!!! Please rerun this command as "npm run update -- @angular/core" or "yarn update @angular/core"!\n'
|
|
||||||
);
|
|
||||||
throw new Error(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return chain([
|
const packageJson = readJsonInTree(host, 'package.json');
|
||||||
externalSchematic(
|
|
||||||
'@schematics/update',
|
const engineHost = (context.engine.workflow as any)._engineHost;
|
||||||
'update',
|
engineHost.registerTaskExecutor(createRunUpdateTask());
|
||||||
{
|
const cliUpgrade = context.addTask(new RunUpdateTask('@angular/cli'));
|
||||||
packages: ['@angular/cli'],
|
|
||||||
from: '7.2.2',
|
if (packageJson.dependencies['@angular/core']) {
|
||||||
to: '8.0.0',
|
context.addTask(new RunUpdateTask('@angular/core'), [cliUpgrade]);
|
||||||
force: true
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
interactive: true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateNestDependencies = updateJsonInTree('package.json', json => {
|
const updateNestDependencies = updateJsonInTree('package.json', json => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user