From c6a1efcff0901d08130c34a385efc61675f23428 Mon Sep 17 00:00:00 2001 From: Caleb Ukle Date: Wed, 2 Nov 2022 10:00:46 -0500 Subject: [PATCH] fix(web): add option for override outputPath for file-server --- docs/generated/packages/web.json | 4 ++++ .../executors/file-server/file-server.impl.ts | 16 +++++++++------- .../web/src/executors/file-server/schema.d.ts | 1 + .../web/src/executors/file-server/schema.json | 4 ++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/generated/packages/web.json b/docs/generated/packages/web.json index 0670cf465ce9c..a6d5e12d8d19b 100644 --- a/docs/generated/packages/web.json +++ b/docs/generated/packages/web.json @@ -999,6 +999,10 @@ "type": "boolean", "description": "Redirect 404 errors to index.html (useful for SPA's)", "default": false + }, + "staticFilePath": { + "type": "string", + "description": "Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath" } }, "additionalProperties": false, diff --git a/packages/web/src/executors/file-server/file-server.impl.ts b/packages/web/src/executors/file-server/file-server.impl.ts index d57b4bb1773bd..32d85829ed5f8 100644 --- a/packages/web/src/executors/file-server/file-server.impl.ts +++ b/packages/web/src/executors/file-server/file-server.impl.ts @@ -3,6 +3,8 @@ import * as chalk from 'chalk'; import { ExecutorContext, joinPathFragments, + parseTargetString, + readTargetOptions, workspaceLayout, } from '@nrwl/devkit'; import ignore from 'ignore'; @@ -57,14 +59,14 @@ function getBuildTargetCommand(options: Schema) { } function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) { + if (options.staticFilePath) { + return options.staticFilePath; + } + let buildOptions; try { - const [project, target, config] = options.buildTarget.split(':'); - - const buildTarget = context.workspace.projects[project].targets[target]; - buildOptions = config - ? { ...buildTarget.options, ...buildTarget.configurations[config] } - : buildTarget.options; + const target = parseTargetString(options.buildTarget); + buildOptions = readTargetOptions(target, context); } catch (e) { throw new Error(`Invalid buildTarget: ${options.buildTarget}`); } @@ -73,7 +75,7 @@ function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) { const outputPath = buildOptions.outputPath; if (!outputPath) { throw new Error( - `Invalid buildTarget: ${options.buildTarget}. The target must contain outputPath property.` + `Unable to get the outputPath from buildTarget ${options.buildTarget}. Make sure ${options.buildTarget} has an outputPath property or manually provide an staticFilePath property` ); } diff --git a/packages/web/src/executors/file-server/schema.d.ts b/packages/web/src/executors/file-server/schema.d.ts index ec5fb0f1eeb1f..6cb580a663c61 100644 --- a/packages/web/src/executors/file-server/schema.d.ts +++ b/packages/web/src/executors/file-server/schema.d.ts @@ -12,4 +12,5 @@ export interface Schema { proxyOptions?: object; watch?: boolean; spa: boolean; + staticFilePath?: string; } diff --git a/packages/web/src/executors/file-server/schema.json b/packages/web/src/executors/file-server/schema.json index c182f19ac5709..3a22f64715df3 100644 --- a/packages/web/src/executors/file-server/schema.json +++ b/packages/web/src/executors/file-server/schema.json @@ -67,6 +67,10 @@ "type": "boolean", "description": "Redirect 404 errors to index.html (useful for SPA's)", "default": false + }, + "staticFilePath": { + "type": "string", + "description": "Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath" } }, "additionalProperties": false,