Skip to content

Commit

Permalink
Account for rsbuild stats JSON output and multiple locations
Browse files Browse the repository at this point in the history
  • Loading branch information
codykaup committed Oct 29, 2024
1 parent ce30b2b commit a4eeafe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion node-src/lib/getDependentStoryFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ describe('getDependentStoryFiles', () => {
id: String.raw`./src lazy recursive ^\.\/.*$`,
reasons: [
{
moduleName: './node_modules/.cache/storybook/default/dev-server/storybook-stories.js',
resolvedModule:
'./node_modules/.cache/storybook/default/dev-server/storybook-stories.js',
moduleName:
'./node_modules/.cache/storybook/default/dev-server/storybook-stories.js + 2 modules',
},
],
},
Expand Down
9 changes: 8 additions & 1 deletion node-src/lib/getDependentStoryFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const getPackageName = (modulePath: string) => {
*/
export function normalizePath(posixPath: string, rootPath: string, baseDirectory = '') {
if (!posixPath || posixPath.startsWith('/virtual:')) return posixPath;

return path.posix.isAbsolute(posixPath)
? path.posix.relative(rootPath, posixPath)
: path.posix.join(baseDirectory, posixPath);
Expand Down Expand Up @@ -140,6 +141,7 @@ export async function getDependentStoryFiles(
`/virtual:/@storybook/builder-vite/vite-app.js`,
// rspack builder
`./node_modules/.cache/storybook/default/dev-server/storybook-stories.js`,
`./node_modules/.cache/storybook/storybook-rsbuild-builder/storybook-config-entry.js`,
].map((file) => normalize(file))
);

Expand Down Expand Up @@ -172,7 +174,12 @@ export async function getDependentStoryFiles(
}

const normalizedReasons = module_.reasons
?.map((reason) => normalize(reason.moduleName))
?.map((reason) =>
normalize(
reason.resolvedModule || // rspack sets a resolvedModule that holds the module name
reason.moduleName // vite, webpack, and default
)
)
.filter((reasonName) => reasonName && reasonName !== normalizedName);
if (normalizedReasons) {
reasonsById.set(module_.id, normalizedReasons);
Expand Down
1 change: 1 addition & 0 deletions node-src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ export interface Task {
}

export interface Reason {
resolvedModule?: string; // rspack sets a resolvedModule that holds the module name
moduleName: string;
}
export interface Module {
Expand Down

0 comments on commit a4eeafe

Please sign in to comment.