Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bail on preview file changes #1133

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions node-src/lib/getDependentStoryFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,33 @@ describe('getDependentStoryFiles', () => {
);
});

it('bails on changed preview.js file', async () => {
const changedFiles = ['src/foo.stories.js', 'path/to/storybook-config/preview.js'];
const modules = [
{
id: './path/to/storybook-config/preview.js',
name: './path/to/storybook-config/preview.js',
reasons: [{ moduleName: './path/to/storybook-config/generated-stories-entry.js' }],
},
{
id: CSF_GLOB,
name: CSF_GLOB,
reasons: [{ moduleName: './path/to/storybook-config/generated-stories-entry.js' }],
},
];
const ctx = getContext({ configDir: 'path/to/storybook-config' });
const result = await getDependentStoryFiles(ctx, { modules }, statsPath, changedFiles);
expect(result).toBeUndefined();
expect(ctx.turboSnap.bailReason).toEqual({
changedStorybookFiles: ['path/to/storybook-config/preview.js'],
});
expect(ctx.log.warn).toHaveBeenCalledWith(
expect.stringContaining(
chalk`Found a Storybook config change in {bold path/to/storybook-config/preview.js}`
)
);
});

it('bails on changed dependency of config file', async () => {
const changedFiles = ['src/styles.js'];
const modules = [
Expand Down
12 changes: 9 additions & 3 deletions node-src/lib/getDependentStoryFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ export async function getDependentStoryFiles(
const reasonsById = new Map<Module['id'], NormalizedName[]>();
const csfGlobsByName = new Set<NormalizedName>();

const isStorybookFile = (name: string) =>
name && name.startsWith(`${storybookDirectory}/`) && !storiesEntryFiles.has(name);

stats.modules
.filter((module_) => isUserModule(module_))
// TODO: refactor this function
// eslint-disable-next-line complexity
.map((module_) => {
const normalizedName = normalize(module_.name);
modulesByName.set(normalizedName, module_);
Expand Down Expand Up @@ -176,7 +181,10 @@ export async function getDependentStoryFiles(
reasonsById.set(module_.id, normalizedReasons);
}

if (reasonsById.get(module_.id)?.some((reason) => storiesEntryFiles.has(reason))) {
if (
!isStorybookFile(normalizedName) &&
reasonsById.get(module_.id)?.some((reason) => storiesEntryFiles.has(reason))
) {
csfGlobsByName.add(normalizedName);
}
});
Expand All @@ -203,8 +211,6 @@ export async function getDependentStoryFiles(
}

const isCsfGlob = (name: NormalizedName) => csfGlobsByName.has(name);
const isStorybookFile = (name: string) =>
name && name.startsWith(`${storybookDirectory}/`) && !storiesEntryFiles.has(name);
const isStaticFile = (name: string) =>
staticDirectories.some((directory) => name && name.startsWith(`${directory}/`));

Expand Down
Loading