Skip to content

web: fix storybook build after npm update#7855

Merged
BeryJu merged 6 commits intomainfrom
web/repair-storybook-build
Dec 18, 2023
Merged

web: fix storybook build after npm update#7855
BeryJu merged 6 commits intomainfrom
web/repair-storybook-build

Conversation

@kensternberg-authentik
Copy link
Contributor

Details

This commit follows the patch for Turnstile and performs a similar operation for the Storybook build, which failed after the latest npm audit and npm update passes.

This patch to Vite fixed a problem with the Vite build in that Vite could not resolve if a CSS import was strictly at the module level or if it was necessary to include the imported CSS at the document level. The fix is to hack a query, ?inline, to the end of the import string, to indicate that it’s a module-only import.

The Storybook for Web Components build recommended by the Open Webcomponent Consortium is a Storybook-Vite implementation. The latest update fully deprecated undecorated CSS imports, and Storybook broke, unable to reconcile the CSS imports.

This patch inlines the inlining of the CSS automatically for Storybook by using the Rollup modify() plug-in which performs string substitutions on the source code before it’s presented to the compiler and bundler; it recognizes the strings that require inlining, those that match the regex:

/^(import \w+ from .*\.css)";/

… and replaces them with a version ending in .css?inline. Because the actual recognizer inside modify() recognizes strings and not regular expressions, a script to build the strings has been added to the scripts folder.

Just like locales, you will have to re-run and re-build build-storybook-import-maps script if you add a new CSS file to the source tree.


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)
  • The translation files have been updated (make i18n-extract)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make website)

@kensternberg-authentik kensternberg-authentik marked this pull request as ready for review December 11, 2023 18:24
@kensternberg-authentik kensternberg-authentik requested a review from a team as a code owner December 11, 2023 18:24
@netlify
Copy link

netlify bot commented Dec 11, 2023

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit c1808bf
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/65805ca00f0a5f00080946a5
😎 Deploy Preview https://deploy-preview-7855--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Dec 11, 2023

Deploy Preview for authentik ready!

Name Link
🔨 Latest commit 5a308bc
🔍 Latest deploy log https://app.netlify.com/sites/authentik/deploys/6577542381eea800081f2f8f
😎 Deploy Preview https://deploy-preview-7855--authentik.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 95 (🔴 down 2 from production)
Accessibility: 90 (no change from production)
Best Practices: 100 (no change from production)
SEO: 80 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@kensternberg-authentik kensternberg-authentik changed the base branch from main to web/npm-update December 11, 2023 18:29
@codecov
Copy link

codecov bot commented Dec 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (36de629) 25.91% compared to head (f81c874) 92.43%.
Report is 4 commits behind head on main.

❗ Current head f81c874 differs from pull request most recent head c1808bf. Consider uploading reports for the commit c1808bf to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #7855       +/-   ##
===========================================
+ Coverage   25.91%   92.43%   +66.52%     
===========================================
  Files         588      588               
  Lines       29200    29200               
===========================================
+ Hits         7566    26991    +19425     
+ Misses      21634     2209    -19425     
Flag Coverage Δ
e2e 49.27% <ø> (?)
integration 25.91% <ø> (ø)
unit 89.70% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from web/npm-update to main December 13, 2023 14:33
This commit follows the [patch for Turnstile](#7854) and
performs a similar operation for the Storybook build, which failed after the latest `npm audit` and
`npm update` passes.

[This patch to Vite](vitejs/vite#10762) fixes a problem with the Vite build
in that Vite could not resolve if a CSS import was strictly at the module level or if it was
necessary to include the imported CSS at the document level.  The fix is to hack a query, `?inline`,
to the end of the import string, to indicate that it's a module-only import.

The Storybook for Web Components build recommended by the Open Webcomponent Consortium is a
Storybook-Vite implementation.  The latest update fully deprecated undecorated CSS imports, and
Storybook broke, unable to reconcile the CSS imports.

This patch inlines the inlining of the CSS automatically for Storybook by using the Rollup
`modify()` plug-in which performs string substitutions on the source code before it's presented to
the compiler and bundler; it recognizes the strings that require inlining, those that match the
regex:

``` JavaScript
/^(import \w+ from .*\.css)";/
```

... and replaces them with a version ending in `.css?inline`.  Because the actual recognizer inside
`modify()` recognizes strings and not regular expressions, a script to build the strings has been
added to the `scripts` folder.

Just like locales, you will have to re-run and re-build `build-storybook-import-maps` script if you
add a new CSS file to the source tree.
@BeryJu BeryJu force-pushed the web/repair-storybook-build branch from 6812071 to c1808bf Compare December 18, 2023 14:52
@netlify
Copy link

netlify bot commented Dec 18, 2023

Deploy Preview for authentik ready!

Name Link
🔨 Latest commit c1808bf
🔍 Latest deploy log https://app.netlify.com/sites/authentik/deploys/65805ca02c123700082cbae5
😎 Deploy Preview https://deploy-preview-7855--authentik.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 96 (🔴 down 1 from production)
Accessibility: 90 (no change from production)
Best Practices: 100 (no change from production)
SEO: 80 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@BeryJu BeryJu merged commit d3cbe26 into main Dec 18, 2023
@BeryJu BeryJu deleted the web/repair-storybook-build branch December 18, 2023 14:57
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.

2 participants