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

Angular: Refactor angular server #14358

Merged
merged 3 commits into from Apr 19, 2021
Merged

Angular: Refactor angular server #14358

merged 3 commits into from Apr 19, 2021

Conversation

ThibaudAV
Copy link
Contributor

@ThibaudAV ThibaudAV commented Mar 26, 2021

Issue: not yet. but if all goes well i would like to eventually allow storybook to be more "Angular friendly". And to use an angular builder like in NX to simplify the use of storybook in angular

What I did

Rework the code of angular-cli_config and angular-cli_utils to add future features
Improvement:

  • Add test for different workspace configuration
    These new tests allow to make sure of the compatibility with angular-cli 🤞. And to avoid (like last time) to update the supported angular version without failing

  • Use angular core to read the workspace instead of doing it by hand

  • Use angular-cli to read the tsconfig

  • Redesigned the code to get out the main steps + added error handling

  • Express more clearly the webpack config from angular-cli

  • Clarification of the logs

  • Improvement of the types with those of angular-cli

I find that it was not easy to understand the code before. I hope to improve it. but if there are still unclear points, do not hesitate to ask questions or suggest improvements.

Test campagne

To avoid regressions I added tests before. And check that after refactoring the tests still work without major changes

Step :

  • Create a new project (npx @angular/cli@6 new angular-v6)
  • Add storybook (npx sb init)
  • cp app/angular dist in node_modules of the new project
  • Start storybook
  • Angular 6
  • Angular 9
  • Angular 10
  • Angular 11
  • angular with NX (only with angular) (I didn't succeed in making a new project with a wokspace.json 🤷‍♂️ )

(Skip 7 and 8 🙈 )

⚠️ The goal is to not make any regression !. If you have any ideas for tests, don't hesitate to do them or ask me 🙏

How to test

  • Is this testable with Jest or Chromatic screenshots? Yes
  • Does this need a new example in the kitchen sink apps? Yes
  • Does this need an update to the documentation? Yes

@ThibaudAV ThibaudAV changed the title Angular: Angular: Refactor angular server Mar 26, 2021
@shilman shilman added angular maintenance User-facing maintenance tasks labels Mar 26, 2021
@ThibaudAV ThibaudAV force-pushed the angular/refactor-server-test branch from 5c41213 to c17feae Compare April 2, 2021 14:44
@ThibaudAV ThibaudAV force-pushed the angular/refactor-server-test branch 7 times, most recently from 5fa4189 to c22fc7f Compare April 11, 2021 19:07
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.

I just took a brief look at the code

It looks pretty clean and understandable 🙂
Especially the "webpack config" merge part really needed a refactoring...

@@ -0,0 +1,189 @@
/**
* This file is to be watched !
* The code must be compatible from @angular-devkit version 6.1.0 to the latest supported
Copy link
Member

Choose a reason for hiding this comment

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

Why v6, though?

https://angular.io/guide/releases#support-policy-and-schedule

Angular versions v4, v5, v6, v7, and v8 are no longer under support.

Angular does not support those versions, why should we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

year but storybook still support these old versions no ?
I referred here :

"@angular-devkit/core": "^0.6.1 || >=7.0.0",

Copy link
Member

@kroeder kroeder Apr 12, 2021

Choose a reason for hiding this comment

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

@shilman @ndelangen What do you think? In the past, I tried to be compatible with the last 4 versions of Angular (8 to 11 right now)

In the link above you can find a table with LTS date ranges. Should we just stick to what Angular does support and write it somewhere down in the docs so we don't need to ask this ourselves over and over again? 🙂

All major releases are typically supported for 18 months.

6 months of active support, during which regularly-scheduled updates and patches are released.

12 months of long-term support (LTS), during which only critical fixes and security patches are released.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can do it with the next storybook major 7 but not before, no ? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Ideally we keep back compat until our 7.0 release, but I think we can compromise on semver if it helps clean things up a lot.

};

export const filterOutStylingRules = (config: Configuration) => {
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

What needs to be ignored here? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hummm 🤔 I took it from the old code. I'll go check it out if it's still nessesary

logger.info(`=> Using angular project '${fondProject.projectName}' for configuring Storybook`);
} catch (error) {
logger.error(`=> Could not find angular project`);
throw error;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I have introduced a change in behavior here 🤔
I throw a lot more "error" than before

To avoid the change of behavior it's necessary to ignores the errors if the project is not found and if it does not contain architect.build. with warn

but I wonder if this is a good thing 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

If certain setups do not make sense at all I think it's ok to introduce a breaking change. In my experience, misconfiguring storybook may not lead to startup errors but runtime errors instead so it's not even breaking, it is "exit what should not work anyway"

@ThibaudAV
Copy link
Contributor Author

thank @kroeder :)
I open the PR to get more feedback

@ThibaudAV ThibaudAV marked this pull request as ready for review April 12, 2021 17:33
@ThibaudAV ThibaudAV requested a review from a team April 12, 2021 17:33
@shilman
Copy link
Member

shilman commented Apr 16, 2021

@ThibaudAV is this ready to merge?

@ThibaudAV
Copy link
Contributor Author

@shilman not yet
I need to improve the error handling. And also add the info when this configuration does not apply.

I tell you when it feels right

Adds tests in order to rework the code in next commit without changing the angular preset behavior
@ThibaudAV ThibaudAV force-pushed the angular/refactor-server-test branch from c22fc7f to a91d9f9 Compare April 18, 2021 21:06
Rework the code of angular-cli_config and angular-cli_utils to add future features
Improvement:
- Add test for NX
- Use angular core to read the workspace instead of doing it by hand
- Use angular-cli to read the tsconfig
- Redesigned the code to get out the main steps + added error handling
- Express more clearly the webpack config from angular-cli
- Clarification of the logs
- Improvement of the types with those of angular-cli
@ThibaudAV ThibaudAV force-pushed the angular/refactor-server-test branch from a91d9f9 to 4f00418 Compare April 18, 2021 21:08
@ThibaudAV
Copy link
Contributor Author

@shilman it's ok for me

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Did only a light review bug LGTM 💯

@shilman shilman merged commit 7eb9f89 into next Apr 19, 2021
@shilman shilman deleted the angular/refactor-server-test branch April 19, 2021 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
angular maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants