Skip to content

Commit

Permalink
fix(misc): set schema when converting a project to standalone configu…
Browse files Browse the repository at this point in the history
…ration (#13887)
  • Loading branch information
leosvelperez committed Dec 19, 2022
1 parent 78f3a3c commit a049d6c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
Expand Up @@ -98,6 +98,7 @@ Object {

exports[`workspace --preserve-angular-cli-layout should support multiple projects 2`] = `
Object {
"$schema": "node_modules/nx/schemas/project-schema.json",
"name": "app1",
"sourceRoot": "src",
"targets": Object {
Expand Down Expand Up @@ -125,6 +126,7 @@ Object {

exports[`workspace --preserve-angular-cli-layout should support multiple projects 3`] = `
Object {
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"name": "app2",
"sourceRoot": "projects/app2/src",
"targets": Object {
Expand Down Expand Up @@ -152,6 +154,7 @@ Object {

exports[`workspace --preserve-angular-cli-layout should support multiple projects 4`] = `
Object {
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"name": "lib1",
"sourceRoot": "projects/lib1/src",
"targets": Object {
Expand Down
@@ -1,20 +1,17 @@
import * as devkit from '@nrwl/devkit';
import {
ProjectConfiguration,
readJson,
readProjectConfiguration,
} from '@nrwl/devkit';
import {
createTreeWithEmptyV1Workspace,
createTreeWithEmptyWorkspace,
} from '@nrwl/devkit/testing';
import enquirer = require('enquirer');
import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing';
import { getRelativeProjectJsonSchemaPath } from 'nx/src/generators/utils/project-configuration';
import { libraryGenerator } from '../library/library';
import * as devkit from '@nrwl/devkit';

import convertToNxProject, {
SCHEMA_OPTIONS_ARE_MUTUALLY_EXCLUSIVE,
} from './convert-to-nx-project';
import { getProjectConfigurationPath } from './utils/get-project-configuration-path';
import enquirer = require('enquirer');

jest.mock('fs-extra', () => ({
...jest.requireActual<any>('fs-extra'),
Expand Down Expand Up @@ -88,7 +85,11 @@ describe('convert-to-nx-project', () => {
getProjectConfigurationPath(config)
);

expect(newConfigFile.$schema).toBe(
getRelativeProjectJsonSchemaPath(tree, config)
);
delete config.root;
delete newConfigFile.$schema;
expect(config).toEqual(newConfigFile);
});

Expand Down Expand Up @@ -116,7 +117,11 @@ describe('convert-to-nx-project', () => {
tree,
getProjectConfigurationPath(config)
);
expect(newConfigFile.$schema).toBe(
getRelativeProjectJsonSchemaPath(tree, config)
);
delete config.root;
delete newConfigFile.$schema;
expect(config).toEqual(newConfigFile);
}
});
Expand Down
@@ -1,6 +1,3 @@
import { dirname } from 'path';
import { prompt } from 'enquirer';

import {
convertNxGenerator,
formatFiles,
Expand All @@ -15,7 +12,9 @@ import {
updateJson,
writeJson,
} from '@nrwl/devkit';

import { prompt } from 'enquirer';
import { getRelativeProjectJsonSchemaPath } from 'nx/src/generators/utils/project-configuration';
import { dirname } from 'path';
import { Schema } from './schema';
import { getProjectConfigurationPath } from './utils/get-project-configuration-path';

Expand Down Expand Up @@ -68,9 +67,11 @@ To upgrade change the version number at the top of ${getWorkspacePath(
continue;
}

delete configuration.root;

writeJson(host, configPath, configuration);
writeJson(host, configPath, {
$schema: getRelativeProjectJsonSchemaPath(host, configuration),
...configuration,
root: undefined,
});

updateJson(host, getWorkspacePath(host), (value) => {
value.projects[project] = normalizePath(dirname(configPath));
Expand Down

1 comment on commit a049d6c

@vercel
Copy link

@vercel vercel bot commented on a049d6c Dec 19, 2022

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-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.