Skip to content

Commit

Permalink
Merge pull request #976 from chromaui/fix-storybook-base-dir-check-2
Browse files Browse the repository at this point in the history
Use current working directory as default value for `storybookBaseDir`
  • Loading branch information
ghengeveld committed May 8, 2024
2 parents da800dd + 3d44093 commit 1f20621
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 18 additions & 0 deletions node-src/lib/checkStorybookBaseDir.test.ts
Expand Up @@ -99,4 +99,22 @@ describe('checkStorybookBaseDir', () => {

await expect(() => checkStorybookBaseDir(ctx, stats)).rejects.toThrow();
});

it('should assume current working directory if no storybookBaseDir is specified', async () => {
const ctx = getContext();
const stats = {
modules: [
{
id: './node-src/index.ts',
name: './node-src/index.ts',
},
],
};

getRepositoryRoot.mockResolvedValueOnce(process.cwd());
await expect(checkStorybookBaseDir(ctx, stats)).resolves.toBeUndefined();

getRepositoryRoot.mockResolvedValueOnce(path.resolve(process.cwd(), '..'));
await expect(checkStorybookBaseDir(ctx, stats)).resolves.toBeUndefined();
});
});
7 changes: 4 additions & 3 deletions node-src/lib/checkStorybookBaseDir.ts
Expand Up @@ -8,8 +8,9 @@ import { getRepositoryRoot } from '../git/git';

export async function checkStorybookBaseDir(ctx: Context, stats: Stats) {
const repositoryRoot = await getRepositoryRoot();
const { storybookBaseDir = '' } = ctx.options;
ctx.log.debug('Storybook base directory:', path.join(repositoryRoot, storybookBaseDir));

// Assume CWD if no storybookBaseDir is provided
const { storybookBaseDir = path.relative(repositoryRoot, '') } = ctx.options;

// Find all js(x)/ts(x) files in stats that are not in node_modules
const sourceModuleFiles = stats.modules.filter(
Expand Down Expand Up @@ -39,7 +40,7 @@ export async function checkStorybookBaseDir(ctx: Context, stats: Stats) {
})
);
} catch (err) {
ctx.log.error(invalidStorybookBaseDir());
ctx.log.debug(`Invalid storybookBaseDir: ${storybookBaseDir}`);
setExitCode(ctx, exitCodes.INVALID_OPTIONS, true);
throw new Error(invalidStorybookBaseDir());
}
Expand Down

0 comments on commit 1f20621

Please sign in to comment.