Skip to content

Commit

Permalink
fix(nx): 8.0.0 schematic expected workspace.json
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Aug 6, 2019
1 parent 07d963b commit 238236a
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { stripIndents } from '@angular-devkit/core/src/utils/literals';
export default {
description: `Create nx.json before migrating to Angular CLI 6.`,
run: () => {
if (!existsSync('.angular-cli.json') && existsSync('workspace.json')) {
if (!existsSync('.angular-cli.json') && existsSync('angular.json')) {
console.warn(stripIndents`
You have already upgraded to Angular CLI 6.
We will not be able to recover information about your project's tags for you.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { join } from 'path';
export default {
description: `Switch to Nx 6.0`,
run: () => {
if (!existsSync('.angular-cli.json') && existsSync('workspace.json')) {
if (!existsSync('.angular-cli.json') && existsSync('angular.json')) {
console.warn(stripIndents`
You have already upgraded to Angular CLI 6.
We will not be able to recover information about your project's tags for you.
Expand Down
10 changes: 5 additions & 5 deletions packages/schematics/migrations/update-6-0-0/update-6-0-0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function createTsconfigLibJson(host: Tree, project: any) {
}

function createAdditionalFiles(host: Tree) {
const workspaceJson = readJsonInTree(host, 'workspace.json');
const workspaceJson = readJsonInTree(host, 'angular.json');
Object.entries<any>(workspaceJson.projects).forEach(([key, project]) => {
if (project.architect.test) {
createTsconfigSpecJson(host, project);
Expand All @@ -283,7 +283,7 @@ function createAdditionalFiles(host: Tree) {
}

function moveE2eTests(host: Tree, context: SchematicContext) {
const workspaceJson = readJsonInTree(host, 'workspace.json');
const workspaceJson = readJsonInTree(host, 'angular.json');

Object.entries<any>(workspaceJson.projects).forEach(([key, p]) => {
if (p.projectType === 'application' && !p.architect.e2e) {
Expand Down Expand Up @@ -321,7 +321,7 @@ function deleteUnneededFiles(host: Tree) {
}

function patchLibIndexFiles(host: Tree, context: SchematicContext) {
const workspaceJson = readJsonInTree(host, 'workspace.json');
const workspaceJson = readJsonInTree(host, 'angular.json');

Object.entries<any>(workspaceJson.projects).forEach(([key, p]) => {
if (p.projectType === 'library') {
Expand Down Expand Up @@ -490,7 +490,7 @@ function createDefaultE2eTsConfig(host: Tree, project: any) {
}

function updateTsConfigs(host: Tree) {
const workspaceJson = readJsonInTree(host, 'workspace.json');
const workspaceJson = readJsonInTree(host, 'angular.json');
Object.entries<any>(workspaceJson.projects).forEach(([key, project]) => {
if (
project.architect.build &&
Expand Down Expand Up @@ -682,7 +682,7 @@ function addInstallTask(host: Tree, context: SchematicContext) {
}

function checkCli6Upgraded(host: Tree) {
if (!host.exists('workspace.json') && host.exists('.angular-cli.json')) {
if (!host.exists('angular.json') && host.exists('.angular-cli.json')) {
throw new Error(
'Please install the latest version and run ng update @angular/cli first'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const addImplicitDependencies = updateJsonInTree<NxJson>('nx.json', nxJson => {
return {
...nxJson,
implicitDependencies: {
'workspace.json': '*',
'angular.json': '*',
'package.json': '*',
'tsconfig.json': '*',
'tslint.json': '*',
Expand Down
10 changes: 5 additions & 5 deletions packages/schematics/migrations/update-7-2-0/update-7-2-0.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Update 7.2.0', () => {
scripts: {}
});
createJson('tsconfig.json', {});
createJson('workspace.json', {
createJson('angular.json', {
projects: {
app1: {
root: 'apps/app1',
Expand Down Expand Up @@ -321,7 +321,7 @@ describe('Update 7.2.0', () => {
it('should fix cypress lint configs', async () => {
initialTree = await schematicRunner
.callRule(
updateJsonInTree('workspace.json', json => {
updateJsonInTree('angular.json', json => {
json.projects['app2-e2e'].architect.lint.options.tsConfig =
'e2e/tsconfig.e2e.json';
return json;
Expand All @@ -333,8 +333,8 @@ describe('Update 7.2.0', () => {
.runSchematicAsync('update-7.2.0', {}, initialTree)
.toPromise();
expect(
readJsonInTree(result, 'workspace.json').projects['app2-e2e'].architect
.lint.options.tsConfig
readJsonInTree(result, 'angular.json').projects['app2-e2e'].architect.lint
.options.tsConfig
).toEqual('apps/app2-e2e/tsconfig.e2e.json');
[
'/apps/app1/tsconfig.app.json',
Expand All @@ -358,7 +358,7 @@ describe('Update 7.2.0', () => {
it('should not fail for non-existing tsconfigs', async () => {
initialTree = await schematicRunner
.callRule(
updateJsonInTree('workspace.json', json => {
updateJsonInTree('angular.json', json => {
json.projects['app2'].architect.lint.options.tsConfig =
'apps/nonexistent/tsconfig.app.json';
return json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function updateTsConfigs(project: any): Rule {
}

function fixCypressConfigs(host: Tree, context: SchematicContext): Rule {
const workspaceJson = readJsonInTree(host, 'workspace.json');
const workspaceJson = readJsonInTree(host, 'angular.json');
return chain(
Object.entries<any>(workspaceJson.projects)
.filter(
Expand Down
5 changes: 3 additions & 2 deletions packages/schematics/migrations/update-8-0-0/update-8-0-0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
readJsonInTree,
updateJsonInTree,
addUpdateTask,
updateWorkspaceInTree
updateWorkspaceInTree,
readWorkspace
} from '@nrwl/workspace';
import {
createSourceFile,
Expand All @@ -32,7 +33,7 @@ function addDependencies() {
return (host: Tree, context: SchematicContext) => {
const dependencies = readJsonInTree(host, 'package.json').dependencies;
const builders = new Set<string>();
const projects = readJsonInTree(host, 'workspace.json').projects;
const projects = readWorkspace(host).projects;
Object.values<any>(projects)
.filter(
project =>
Expand Down
3 changes: 2 additions & 1 deletion packages/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export {
addParameterToConstructor,
createOrUpdate,
findNodes,
updatePackageJsonDependencies
updatePackageJsonDependencies,
readWorkspace
} from './src/utils/ast-utils';

export {
Expand Down
5 changes: 5 additions & 0 deletions packages/workspace/src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ export function updateWorkspaceInTree<T = any, O = T>(
};
}

export function readWorkspace(host: Tree): any {
const path = getWorkspacePath(host);
return readJsonInTree(host, path);
}

let installAdded = false;

export function addDepsToPackageJson(
Expand Down

0 comments on commit 238236a

Please sign in to comment.