Angular: Rewrite @storybook/angular imports outside stories in angular-to-angular-vite migration#35365
Draft
valentinpalkovic wants to merge 1 commit into
Draft
Conversation
…r-to-angular-vite migration The `angular-to-angular-vite` automigration only fed `storiesPaths` (strictly *.stories.* files) plus the Storybook config dir into `transformImportFiles`. Any other module that imports from `@storybook/angular` - shared decorators, `moduleMetadata`/`applicationConfig` helpers, mocks, test setup, and so on - was never rewritten, so it kept importing the package right after the migration removed it from `package.json`. Also scan the project directory (the folder that holds the Storybook config) for source files and feed those through the same rewrite, deduped with the existing sets. Scoped to the project rather than the repo root so sibling projects in a monorepo that were not migrated are left untouched, and `transformImportFiles` only rewrites quoted `@storybook/angular` specifiers (leaving `@storybook/angular-vite` alone), so over-including files is safe.
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up bug fix for the
@storybook/angular-vitework (#34202). Found during QA on the Bitwarden clients repo.What I did
:ladybug:The issueAfter automigrating an Angular 21 project from
@storybook/angularto@storybook/angular-vite, some files still import from@storybook/angular- which no longer exists once the migration removes it frompackage.json. The build/typecheck then breaks for any story that pulls one of those files in.Root cause
The import-rewrite step only fed two things into
transformImportFiles:storiesPathsis strictly*.stories.*files (it comes from thestoriesglob), andconfigFilesis only the.storybookconfig dir. Angular projects import from@storybook/angularin a lot of non-story modules though - shared decorators,moduleMetadata/applicationConfighelpers,*.mock.ts, test setup, per-component helpers. None of those are in either set, so they were silently skipped.The fix
Also scan the project directory (the folder that holds the Storybook config) for source files and run them through the same rewrite, deduped with the existing sets:
Two deliberate choices:
@storybook/angularimports in sibling projects that stayed on the Webpack framework, so I globdirname(configDir)rather thangetProjectRoot().transformImportFilesonly rewrites quoted@storybook/angularspecifiers and correctly leaves@storybook/angular-vitealone, so the worst case for an unrelated file is a wasted read.How to test
angular-to-angular-vite.test.ts:@storybook/angularis now included in the rewrite scanstoriesPathsand the project scan is deduped to a single entryyarn vitest run code/lib/cli-storybook/src/automigrate/fixes/angular-to-angular-vite.test.tsDraft while I land the sibling QA fixes.