From a60dd73256aa5f12d2ce17e2df175642b02a0438 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 16 Sep 2024 13:00:45 +0200 Subject: [PATCH] docs: update custom action docs to use resolveSafeChildPath Signed-off-by: Patrik Oldsberg --- docs/features/software-templates/writing-custom-actions.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/features/software-templates/writing-custom-actions.md b/docs/features/software-templates/writing-custom-actions.md index 98457d2e8d..e5a82c09a9 100644 --- a/docs/features/software-templates/writing-custom-actions.md +++ b/docs/features/software-templates/writing-custom-actions.md @@ -43,6 +43,7 @@ After running the command, the CLI will create a new directory with your new sca Let's create a simple action that adds a new file and some contents that are passed as `input` to the function. Within the generated directory, locate the file at `src/actions/example/example.ts`. Feel free to rename this file along with its generated unit test. We will replace the existing placeholder code with our custom action code as follows: ```ts title="With Zod" +import { resolveSafeChildPath } from '@backstage/backend-plugin-api'; import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; import fs from 'fs-extra'; import { z } from 'zod'; @@ -62,7 +63,7 @@ export const createNewFileAction = () => { async handler(ctx) { await fs.outputFile( - `${ctx.workspacePath}/${ctx.input.filename}`, + resolveSafeChildPath(ctx.workspacePath, ctx.input.filename), ctx.input.contents, ); }, @@ -90,6 +91,7 @@ The `createTemplateAction` takes an object which specifies the following: You can also choose to define your custom action using JSON schema instead of `zod`: ```ts title="With JSON Schema" +import { resolveSafeChildPath } from '@backstage/backend-plugin-api'; import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; import { writeFile } from 'fs'; @@ -118,7 +120,7 @@ export const createNewFileAction = () => { async handler(ctx) { const { signal } = ctx; await writeFile( - `${ctx.workspacePath}/${ctx.input.filename}`, + resolveSafeChildPath(ctx.workspacePath, ctx.input.filename), ctx.input.contents, { signal }, _ => {},