From be25f33ab13315ed8147e9ddadfb6573820a9eb9 Mon Sep 17 00:00:00 2001 From: arekkubaczkowski Date: Mon, 1 Apr 2024 18:04:32 +0200 Subject: [PATCH] fix(react-native): storybook relative paths (#22031) Co-authored-by: Emily Xiong (cherry picked from commit 120cde6d52b439b9302176f811202f68a5290b77) --- .../src/executors/storybook/storybook.impl.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/react-native/src/executors/storybook/storybook.impl.ts b/packages/react-native/src/executors/storybook/storybook.impl.ts index ed480ecefe8be..808ae5bbe3279 100644 --- a/packages/react-native/src/executors/storybook/storybook.impl.ts +++ b/packages/react-native/src/executors/storybook/storybook.impl.ts @@ -1,4 +1,4 @@ -import { join } from 'path'; +import { join, relative, resolve, dirname } from 'path'; import { ExecutorContext, logger, readJsonFile } from '@nx/devkit'; import { fileExists } from '@nx/workspace/src/utilities/fileutils'; import * as chalk from 'chalk'; @@ -66,9 +66,15 @@ export function runCliStorybook( workspaceRoot: string, options: ReactNativeStorybookOptions ) { - const storiesFiles: string[] = options.searchDir.flatMap((dir) => - globSync(join(dir, options.pattern)) - ); + const storiesFiles: string[] = options.searchDir.flatMap((dir) => { + const storyFilePaths: string[] = globSync(join(dir, options.pattern)); + + return storyFilePaths.map((storyFilePath) => { + const loaderPath: string = resolve(dirname(options.outputFile)); + return relative(loaderPath, storyFilePath); + }); + }); + if (storiesFiles.length === 0) { logger.warn(`${chalk.bold.yellow('warn')} No stories found.`); }