feat(misc): dont generate defaultProject for non standalone workspaces

This commit is contained in:
Victor Savkin 2022-12-20 16:20:06 -05:00
parent 7c65787d5c
commit 82fbb98e7d
31 changed files with 7 additions and 175 deletions

View File

@ -139,11 +139,6 @@
"description": "Whether to configure Tailwind CSS for the application.",
"default": false
},
"skipDefaultProject": {
"description": "Skip setting the project as the default project. When `false` (the default), the project is set as the default project only if there is no default project already set.",
"type": "boolean",
"default": false
},
"standalone": {
"description": "Generate an application that is setup to use standalone components.",
"type": "boolean",

View File

@ -159,11 +159,6 @@
"enum": ["babel", "swc"],
"default": "babel"
},
"skipDefaultProject": {
"description": "Skip setting the project as the default project. When `false` (the default), the project is set as the default project only if there is no default project already set.",
"type": "boolean",
"default": false
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",

View File

@ -20,7 +20,6 @@ import {
enableStrictTypeChecking,
normalizeOptions,
setApplicationStrictDefault,
setDefaultProject,
updateAppComponentTemplate,
updateComponentSpec,
updateConfigFiles,
@ -109,10 +108,6 @@ export async function applicationGenerator(
await addE2e(host, options);
updateEditorTsConfig(host, options);
if (!options.skipDefaultProject) {
setDefaultProject(host, options);
}
if (options.backendProject) {
addProxyConfig(host, options);
}

View File

@ -11,7 +11,6 @@ export * from './nrwl-home-tpl';
export * from './remove-scaffolded-e2e';
export * from './root-router-config';
export * from './set-app-strict-default';
export * from './set-default-project';
export * from './update-component-spec';
export * from './update-app-component-template';
export * from './update-nx-component-template';

View File

@ -1,15 +0,0 @@
import type { Tree } from '@nrwl/devkit';
import {
readWorkspaceConfiguration,
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import type { NormalizedSchema } from './normalized-schema';
export function setDefaultProject(tree: Tree, options: NormalizedSchema): void {
const workspace = readWorkspaceConfiguration(tree);
if (!workspace.defaultProject) {
workspace.defaultProject = options.name;
updateWorkspaceConfiguration(tree, workspace);
}
}

View File

@ -24,7 +24,6 @@ export interface Schema {
port?: number;
setParserOptionsProject?: boolean;
skipPackageJson?: boolean;
skipDefaultProject?: boolean;
standalone?: boolean;
rootProject?: boolean;
}

View File

@ -219,15 +219,6 @@ describe('app', () => {
expect(appTsConfig.extends).toBe('../../tsconfig.json');
});
it('should set default project', async () => {
// ACT
await generateApp(appTree);
// ASSERT
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBe('my-app');
});
it('should not overwrite default project if already set', async () => {
// ARRANGE
const workspace = readWorkspaceConfiguration(appTree);
@ -241,15 +232,6 @@ describe('app', () => {
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBe('some-awesome-project');
});
it('should not set default project when "--skip-default-project=true"', async () => {
// ACT
await generateApp(appTree, 'my-app', { skipDefaultProject: true });
// ASSERT
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBeUndefined();
});
});
describe('nested', () => {

View File

@ -2,7 +2,9 @@ import {
formatFiles,
installPackagesTask,
moveFilesToNewDirectory,
readWorkspaceConfiguration,
Tree,
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter';
import { convertToNxProjectGenerator } from '@nrwl/workspace/generators';
@ -20,7 +22,6 @@ import {
enableStrictTypeChecking,
normalizeOptions,
setApplicationStrictDefault,
setDefaultProject,
updateAppComponentTemplate,
updateComponentSpec,
updateConfigFiles,
@ -121,8 +122,10 @@ export async function applicationGenerator(
await addE2e(tree, options);
updateEditorTsConfig(tree, options);
if (!options.skipDefaultProject) {
setDefaultProject(tree, options);
if (options.rootProject) {
const workspace = readWorkspaceConfiguration(tree);
workspace.defaultProject = options.name;
updateWorkspaceConfiguration(tree, workspace);
}
if (options.backendProject) {

View File

@ -214,15 +214,6 @@ describe('app', () => {
expect(appTsConfig.extends).toBe('../../tsconfig.base.json');
});
it('should set default project', async () => {
// ACT
await generateApp(appTree);
// ASSERT
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBe('my-app');
});
it('should not overwrite default project if already set', async () => {
// ARRANGE
const workspace = readWorkspaceConfiguration(appTree);
@ -236,15 +227,6 @@ describe('app', () => {
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBe('some-awesome-project');
});
it('should not set default project when "--skip-default-project=true"', async () => {
// ACT
await generateApp(appTree, 'my-app', { skipDefaultProject: true });
// ASSERT
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBeUndefined();
});
});
describe('nested', () => {

View File

@ -11,7 +11,6 @@ export * from './nrwl-home-tpl';
export * from './remove-scaffolded-e2e';
export * from './root-router-config';
export * from './set-app-strict-default';
export * from './set-default-project';
export * from './update-component-spec';
export * from './update-app-component-template';
export * from './update-nx-component-template';

View File

@ -1,15 +0,0 @@
import type { Tree } from '@nrwl/devkit';
import {
readWorkspaceConfiguration,
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import type { NormalizedSchema } from './normalized-schema';
export function setDefaultProject(tree: Tree, options: NormalizedSchema): void {
const workspace = readWorkspaceConfiguration(tree);
if (!workspace.defaultProject) {
workspace.defaultProject = options.name;
updateWorkspaceConfiguration(tree, workspace);
}
}

View File

@ -24,7 +24,6 @@ export interface Schema {
port?: number;
setParserOptionsProject?: boolean;
skipPackageJson?: boolean;
skipDefaultProject?: boolean;
standalone?: boolean;
rootProject?: boolean;
}

View File

@ -142,11 +142,6 @@
"description": "Whether to configure Tailwind CSS for the application.",
"default": false
},
"skipDefaultProject": {
"description": "Skip setting the project as the default project. When `false` (the default), the project is set as the default project only if there is no default project already set.",
"type": "boolean",
"default": false
},
"standalone": {
"description": "Generate an application that is setup to use standalone components.",
"type": "boolean",

View File

@ -21,7 +21,6 @@ export async function remote(tree: Tree, options: Schema) {
const appInstallTask = await applicationGenerator(tree, {
...options,
routing: true,
skipDefaultProject: true,
port,
});

View File

@ -27,11 +27,9 @@ describe('app', () => {
js: false,
unitTestRunner: 'none',
});
const workspace = readWorkspaceConfiguration(appTree);
const projects = getProjects(appTree);
expect(projects.get('my-app').root).toEqual('apps/my-app');
expect(workspace.defaultProject).toEqual('my-app');
});
it('should update nx.json', async () => {
@ -105,7 +103,6 @@ describe('app', () => {
const workspaceJson = readWorkspaceConfiguration(appTree);
const projects = getProjects(appTree);
expect(projects.get('my-dir-my-app').root).toEqual('apps/my-dir/my-app');
expect(workspaceJson.defaultProject).toEqual('my-dir-my-app');
expect(
appTree.exists('apps/my-dir/my-app-e2e/.detoxrc.json')
@ -187,7 +184,6 @@ describe('app', () => {
const workspaceJson = readWorkspaceConfiguration(appTree);
const projects = getProjects(appTree);
expect(projects.get('my-app').root).toEqual('apps/my-app');
expect(workspaceJson.defaultProject).toEqual('my-app');
expect(appTree.exists('apps/my-app-e2e/.detoxrc.json')).toBeTruthy();
const detoxrc = appTree.read('apps/my-app-e2e/.detoxrc.json', 'utf-8');
@ -265,7 +261,6 @@ describe('app', () => {
const workspaceJson = readWorkspaceConfiguration(appTree);
const projects = getProjects(appTree);
expect(projects.get('my-app').root).toEqual('apps/my-app');
expect(workspaceJson.defaultProject).toEqual('my-app');
expect(appTree.exists('apps/my-app-e2e/.detoxrc.json')).toBeTruthy();
const detoxrc = appTree.read('apps/my-app-e2e/.detoxrc.json', 'utf-8');

View File

@ -24,14 +24,6 @@ export function addProject(host: Tree, options: NormalizedSchema) {
projectConfiguration,
options.standaloneConfig
);
const workspace = readWorkspaceConfiguration(host);
if (!workspace.defaultProject) {
workspace.defaultProject = options.projectName;
updateWorkspaceConfiguration(host, workspace);
}
}
function getTargets(options: NormalizedSchema) {

View File

@ -19,13 +19,10 @@ describe('app', () => {
});
const workspaceJson = readJson(tree, 'workspace.json');
const nxJson = readJson<NxJsonConfiguration>(tree, 'nx.json');
expect(workspaceJson.projects['my-app'].root).toEqual('apps/my-app');
expect(workspaceJson.projects['my-app-e2e'].root).toEqual(
'apps/my-app-e2e'
);
expect(nxJson.defaultProject).toEqual('my-app');
});
it('should update tags and implicit dependencies', async () => {

View File

@ -9,10 +9,6 @@ import { NormalizedSchema } from './normalize-options';
export function setDefaults(host: Tree, options: NormalizedSchema) {
const workspace = readWorkspaceConfiguration(host);
if (!workspace.defaultProject) {
workspace.defaultProject = options.projectName;
}
workspace.generators = workspace.generators || {};
workspace.generators['@nrwl/next'] = workspace.generators['@nrwl/next'] || {};
const prev = workspace.generators['@nrwl/next'];

View File

@ -89,7 +89,6 @@ describe('app', () => {
},
});
expect(workspaceJson.projects['my-node-app-e2e']).toBeUndefined();
expect(nxJson.defaultProject).toEqual('my-node-app');
});
it('should update tags', async () => {
@ -215,7 +214,6 @@ describe('app', () => {
});
expect(workspaceJson.projects['my-dir-my-node-app-e2e']).toBeUndefined();
expect(nxJson.defaultProject).toEqual('my-dir-my-node-app');
});
it('should update tags', async () => {

View File

@ -107,13 +107,6 @@ function addProject(tree: Tree, options: NormalizedSchema) {
project,
options.standaloneConfig
);
const workspace = readWorkspaceConfiguration(tree);
if (!workspace.defaultProject) {
workspace.defaultProject = options.name;
updateWorkspaceConfiguration(tree, workspace);
}
}
function addAppFiles(tree: Tree, options: NormalizedSchema) {

View File

@ -64,9 +64,6 @@ export function createNxJsonFile(
}
}
nxJson.defaultBase = deduceDefaultBase();
if (defaultProject) {
nxJson.defaultProject = defaultProject;
}
writeJsonFile(nxJsonPath, nxJson);
}

View File

@ -25,11 +25,9 @@ describe('app', () => {
e2eTestRunner: 'none',
install: false,
});
const workspaceJson = readWorkspaceConfiguration(appTree);
const projects = getProjects(appTree);
expect(projects.get('my-app').root).toEqual('apps/my-app');
expect(workspaceJson.defaultProject).toEqual('my-app');
});
it('should update nx.json', async () => {
@ -90,10 +88,8 @@ describe('app', () => {
install: false,
});
const workspaceJson = readWorkspaceConfiguration(appTree);
const projects = getProjects(appTree);
expect(projects.get('my-dir-my-app').root).toEqual('apps/my-dir/my-app');
expect(workspaceJson.defaultProject).toEqual('my-dir-my-app');
expect(
appTree.exists('apps/my-dir/my-app-e2e/.detoxrc.json')
@ -146,12 +142,9 @@ describe('app', () => {
install: false,
});
const workspaceJson = readWorkspaceConfiguration(appTree);
const projects = getProjects(appTree);
expect(projects.get('my-app').root).toEqual('apps/my-app');
expect(workspaceJson.defaultProject).toEqual('my-app');
expect(appTree.exists('apps/my-app-e2e/.detoxrc.json')).toBeTruthy();
const detoxrc = appTree.read('apps/my-app-e2e/.detoxrc.json', 'utf-8');
// Strip trailing commas
const detoxrcJson = JSON.parse(

View File

@ -20,14 +20,6 @@ export function addProject(host: Tree, options: NormalizedSchema) {
addProjectConfiguration(host, options.projectName, {
...project,
});
const workspace = readWorkspaceConfiguration(host);
if (!workspace.defaultProject) {
workspace.defaultProject = options.projectName;
updateWorkspaceConfiguration(host, workspace);
}
}
function getTargets(options: NormalizedSchema) {

View File

@ -37,12 +37,10 @@ describe('app', () => {
it('should update workspace.json', async () => {
await applicationGenerator(appTree, schema);
const workspaceJson = readWorkspaceConfiguration(appTree);
const projects = getProjects(appTree);
expect(projects.get('my-app').root).toEqual('apps/my-app');
expect(projects.get('my-app-e2e').root).toEqual('apps/my-app-e2e');
expect(workspaceJson.defaultProject).toEqual('my-app');
});
it('should not overwrite default project if already set', async () => {
@ -56,17 +54,6 @@ describe('app', () => {
expect(defaultProject).toBe('some-awesome-project');
});
it('should not set defaultProject when "--skip-default-project=true"', async () => {
await applicationGenerator(appTree, {
...schema,
skipDefaultProject: true,
});
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBeUndefined();
});
it('should update tags and implicit dependencies', async () => {
await applicationGenerator(appTree, { ...schema, tags: 'one,two' });

View File

@ -12,7 +12,7 @@ export function setDefaults(host: Tree, options: NormalizedSchema) {
const workspace = readWorkspaceConfiguration(host);
if (!options.skipDefaultProject && !workspace.defaultProject) {
if (options.rootProject) {
workspace.defaultProject = options.projectName;
}

View File

@ -27,7 +27,6 @@ export interface Schema {
compiler?: 'babel' | 'swc';
remotes?: string[];
devServerPort?: number;
skipDefaultProject?: boolean;
skipPackageJson?: boolean;
rootProject?: boolean;
bundler?: 'webpack' | 'vite';

View File

@ -165,11 +165,6 @@
"enum": ["babel", "swc"],
"default": "babel"
},
"skipDefaultProject": {
"description": "Skip setting the project as the default project. When `false` (the default), the project is set as the default project only if there is no default project already set.",
"type": "boolean",
"default": false
},
"skipPackageJson": {
"description": "Do not add dependencies to `package.json`.",
"type": "boolean",

View File

@ -43,7 +43,6 @@ export async function remoteGenerator(host: Tree, schema: Schema) {
const options = normalizeOptions<Schema>(host, schema);
const initAppTask = await applicationGenerator(host, {
...options,
skipDefaultProject: true,
// Only webpack works with module federation for now.
bundler: 'webpack',
});

View File

@ -26,13 +26,10 @@ describe('app', () => {
standaloneConfig: false,
});
const workspaceJson = readJson(tree, '/workspace.json');
const nxJson = readJson<NxJsonConfiguration>(tree, 'nx.json');
expect(workspaceJson.projects['my-app'].root).toEqual('apps/my-app');
expect(workspaceJson.projects['my-app-e2e'].root).toEqual(
'apps/my-app-e2e'
);
expect(nxJson.defaultProject).toEqual('my-app');
});
it('should update tags and implicit dependencies', async () => {

View File

@ -156,14 +156,6 @@ async function addProject(tree: Tree, options: NormalizedSchema) {
if (options.bundler !== 'vite') {
await setupBundler(tree, options);
}
const workspace = readWorkspaceConfiguration(tree);
if (!workspace.defaultProject) {
workspace.defaultProject = options.projectName;
updateWorkspaceConfiguration(tree, workspace);
}
}
function setDefaults(tree: Tree, options: NormalizedSchema) {

View File

@ -47,7 +47,6 @@ describe('update to v13 config locations', () => {
expect(nxJson.generators).toEqual({});
expect(workspaceJson.projects.a.tags).toEqual(['test']);
expect(workspaceJson.cli).not.toBeDefined();
expect(workspaceJson.defaultProject).not.toBeDefined();
});
describe('v1 workspace', () => {
@ -91,7 +90,6 @@ describe('update to v13 config locations', () => {
});
expect(workspaceJson.projects.a.tags).toEqual(['test']);
expect(workspaceJson.cli).not.toBeDefined();
expect(workspaceJson.defaultProject).not.toBeDefined();
});
});
});