Skip to content

Angular: Rewrite @storybook/angular imports outside stories in angular-to-angular-vite migration#35365

Draft
valentinpalkovic wants to merge 1 commit into
nextfrom
valentin/fix-angular-vite-migration-import-rewrites
Draft

Angular: Rewrite @storybook/angular imports outside stories in angular-to-angular-vite migration#35365
valentinpalkovic wants to merge 1 commit into
nextfrom
valentin/fix-angular-vite-migration-import-rewrites

Conversation

@valentinpalkovic

Copy link
Copy Markdown
Contributor

Follow-up bug fix for the @storybook/angular-vite work (#34202). Found during QA on the Bitwarden clients repo.

What I did

:ladybug: The issue

After automigrating an Angular 21 project from @storybook/angular to @storybook/angular-vite, some files still import from @storybook/angular - which no longer exists once the migration removes it from package.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:

const configFiles = configDir ? await globby([`${configDir}/**/*`]) : [];
const allFiles = [...storiesPaths, ...configFiles].filter(Boolean);

storiesPaths is strictly *.stories.* files (it comes from the stories glob), and configFiles is only the .storybook config dir. Angular projects import from @storybook/angular in a lot of non-story modules though - shared decorators, moduleMetadata/applicationConfig helpers, *.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:

const projectSourceFiles = await globby(['**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}'], {
  cwd: dirname(configDir),
  absolute: true,
  gitignore: true,
  ignore: ['**/node_modules/**', '**/dist/**', '**/.storybook-static/**', '**/.angular/**', '**/coverage/**'],
});
const allFiles = [...new Set([...storiesPaths, ...configFiles, ...projectSourceFiles].filter(Boolean))];

Two deliberate choices:

  • Scoped to the project, not the repo root. In a partially-migrated monorepo we must not rewrite @storybook/angular imports in sibling projects that stayed on the Webpack framework, so I glob dirname(configDir) rather than getProjectRoot().
  • Over-including is safe. transformImportFiles only rewrites quoted @storybook/angular specifiers and correctly leaves @storybook/angular-vite alone, so the worst case for an unrelated file is a wasted read.

Heads-up: the same storiesPaths + configDir scanning shape exists in nextjs-to-nextjs-vite.ts, consolidated-imports.ts, and renderer-to-framework.ts. I kept this PR scoped to the Angular fix, but we may want to align the others in a follow-up. WDYT?

How to test

  • New unit tests in angular-to-angular-vite.test.ts:
    • a non-story helper importing @storybook/angular is now included in the rewrite scan
    • a file present in both storiesPaths and the project scan is deduped to a single entry
  • yarn vitest run code/lib/cli-storybook/src/automigrate/fixes/angular-to-angular-vite.test.ts

Draft while I land the sibling QA fixes.

…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.
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
Fails
🚫

PR is not labeled with one of: ["cleanup","BREAKING CHANGE","feature request","bug","documentation","maintenance","build","dependencies"]

🚫

PR is not labeled with one of: ["ci:normal","ci:merged","ci:daily","ci:docs"]

🚫

PR is not labeled with one of: ["qa:needed","qa:skip","qa:success"]

🚫 PR description is missing the mandatory "#### Manual testing" section. Please add it so that reviewers know how to manually test your changes.

Generated by 🚫 dangerJS against a2f53a5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant