From d3a54cefbd937f2817a676a7d0f3bd449a6f8ced Mon Sep 17 00:00:00 2001 From: Ben Callaghan <44448874+bcallaghan-et@users.noreply.github.com> Date: Tue, 27 Apr 2021 12:56:23 -0600 Subject: [PATCH] fix(core): include serve target only for applications (#30) Do not include serve target for libraries as they cannot be run directly. Fixes #28 Co-authored-by: Ben Callaghan --- .../src/generators/utils/generate-project.spec.ts | 12 ++++++++++++ .../core/src/generators/utils/generate-project.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core/src/generators/utils/generate-project.spec.ts b/packages/core/src/generators/utils/generate-project.spec.ts index f64e8615..5576b8a5 100644 --- a/packages/core/src/generators/utils/generate-project.spec.ts +++ b/packages/core/src/generators/utils/generate-project.spec.ts @@ -42,6 +42,12 @@ describe('nx-dotnet project generator', () => { expect(config).toBeDefined(); }); + it('should not include serve target for libraries', async () => { + await GenerateProject(appTree, options, dotnetClient, 'library'); + const config = readProjectConfiguration(appTree, 'test'); + expect(config.targets.serve).not.toBeDefined(); + }) + it('should tag generated projects', async () => { await GenerateProject(appTree, options, dotnetClient, 'library'); const config = readProjectConfiguration(appTree, 'test'); @@ -66,6 +72,12 @@ describe('nx-dotnet project generator', () => { expect(absoluteDistPath).toEqual(expectedDistPath); }); + it('should include serve target for applications', async () => { + await GenerateProject(appTree, options, dotnetClient, 'application'); + const config = readProjectConfiguration(appTree, 'test'); + expect(config.targets.serve).toBeDefined(); + }) + /** * This test requires a live dotnet client. */ diff --git a/packages/core/src/generators/utils/generate-project.ts b/packages/core/src/generators/utils/generate-project.ts index a3887936..0c4a7969 100644 --- a/packages/core/src/generators/utils/generate-project.ts +++ b/packages/core/src/generators/utils/generate-project.ts @@ -188,7 +188,7 @@ export async function GenerateProject( sourceRoot: `${normalizedOptions.projectRoot}`, targets: { build: GetBuildExecutorConfiguration(normalizedOptions.projectRoot), - serve: GetServeExecutorConfig(), + ...(projectType === 'application' ? { serve: GetServeExecutorConfig() } : {}), }, tags: normalizedOptions.parsedTags, };