-
-
Notifications
You must be signed in to change notification settings - Fork 298
fix(storybook-angular): resolve relative styles from project root #2025
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
Conversation
✅ Deploy Preview for analog-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-blog ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-app ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| .map((extraImport) => { | ||
| if ( | ||
| extraImport.startsWith('.') || | ||
| extraImport.startsWith('src') | ||
| ) { | ||
| // relative to root | ||
| return `import '${resolve(options.angularBuilderContext.workspaceRoot, projectConfig.root, extraImport)}';`; | ||
| } | ||
| // absolute import | ||
| return `import '${extraImport}';`; | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @brandonroberts, actually there is no need in extra conditions here as path.resolve('/abosulte_path_to_project', '/absolute_path_to_style') will resolve to /absolute_path_to_style so all this code code can be replace with a simple return import '${resolve(options.angularBuilderContext.workspaceRoot, projectConfig.root, extraImport)}'; and it will cover all the cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example in our project all the code is located not in the src directory, so specifying styles: ['path/to/our/src/global.scss'] still won't work. I understand that we could start the path with a dot, but why introduce these confusing rules if they can we avoided. 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always use the resolved path won't cover importing styles from node_modules for example. You should be able to use a relative path to import from the correct path if its outside the project root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, why? If project root is /home/user/project then path.resolve('/home/user/project', '../node_modules') will be resolved to /home/user/node_modules. Isn't it what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Nx workspaces, paths are resolved from the root, so we don't want to always resolve from the project root
PR Checklist
Closes #2023
What is the new behavior?
src) are resolved from the workspace root + project root + styles path.Does this PR introduce a breaking change?
Other information
[optional] What gif best describes this PR or how it makes you feel?