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

fix(misc): set schema when converting a project to standalone configuration #13887

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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