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

[bug] Fix automatic Angular module metadata extraction for forRoot imports #7224

Merged
merged 6 commits into from
Jul 25, 2019
Merged

[bug] Fix automatic Angular module metadata extraction for forRoot imports #7224

merged 6 commits into from
Jul 25, 2019

Conversation

pascaliske
Copy link
Contributor

Issues: #7106, #7157

What I did

As described in #7106 the automatic detection for component declarations in Angular storybooks does not work with the really common pattern of forRoot-imports. This PR fixes the behaviour.

The importItem for extracting the NgModule-metadata will be checked for a key ngModule first which exists in the case of an forRoot-import because the method does not return the NgModule directly but an object containing it instead (called ModuleWithProviders<MyModule>).

Besides that this PR fixes the error mentioned in #7157 which will be thrown if the decorator key __annotations__ can not be found on the target which is the case on importing AOT-compiled modules. I added another condition for checking if the decorator key is defined.

How to test

The additional example stories introduced in #6346 will still suffice for testing.

@vercel
Copy link

vercel bot commented Jun 28, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://monorepo-git-fork-pascaliske-7106-angular-fix-auto-2d5086.storybook.now.sh

@pascaliske pascaliske changed the title fix(angular): fix ng module metadata extraction for forRoot imports [bug] Fix automatic Angular module metadata extraction for forRoot imports Jun 28, 2019
@stale stale bot added the inactive label Jul 20, 2019
@MatissJanis
Copy link
Contributor

Please don't close this. Angular is broken currently.

@@ -31,11 +31,14 @@ const createComponentFromTemplate = (template: string) => {
})(componentClass);
};
const extractNgModuleMetadata = (importItem: any): NgModule => {
const target = importItem && importItem.ngModule ? importItem.ngModule : importItem;
Copy link
Member

@kroeder kroeder Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking if importItem exists can we instead add an interface for importItem: any? I haven't checked but maybe angular already provide such an interface. Or we just write down what we need

interface StorybookAngularMetaData {
  ngModule?: AngularModule;
}

Though, as I am writing this I just noticed we need dynamic access to importItem[decoratorKey]

@ndelangen haven't we encountered the same type conflict in one of your PRs where we need some fix types and additionally [key: string]: object ?

@pascaliske what do you think?

Since this is urgent I don't want to achieve the most beautiful solution. We can leave this as is if it'll take further discussion 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would definitely be good to type out importItem with an interface but we still need to check for the existence to gracefully cover edge cases where the item could be undefined, I think...

Copy link
Member

@kroeder kroeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kroeder
Copy link
Member

kroeder commented Jul 23, 2019

One thing before merging this: Can you add a story to the angular example for having at least a manual test for the moment? I can do it as well. Just let me know

@pascaliske
Copy link
Contributor Author

One thing before merging this: Can you add a story to the angular example for having at least a manual test for the moment?

Just pushed a story Feature Module as Context with forRoot based on the existing ChipsModule but with the appropriate forRoot usage. 🙂

@pascaliske
Copy link
Contributor Author

I also added the missing storyshots which I forgot... 😄

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

Successfully merging this pull request may close these issues.

4 participants