-
Notifications
You must be signed in to change notification settings - Fork 920
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
Fix Sass partial changes not triggering recompiles in Dev #2792
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/9hiQXqozkhZcJ6B4ipnkH32XD5Xr |
@@ -3,14 +3,37 @@ const path = require('path'); | |||
const execa = require('execa'); | |||
const npmRunPath = require('npm-run-path'); | |||
|
|||
const IMPORT_REGEX = /\@(use|import)\s*['"](.*?)['"]/g; | |||
const IMPORT_REGEX = /\@(use|import|forward)\s*['"](.*?)['"]/g; |
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.
Good addition!
.map((s) => { | ||
return path.resolve(path.dirname(filePath), s); | ||
// Avoid node packages and core sass libraries. | ||
.filter((s) => !s.includes('node_modules') && !s.includes('sass:')) |
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.
Nice check for Sass builtins
@@ -1,2 +1,4 @@ | |||
// folder/_index.sass | |||
@use 'child-partial' |
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.
👍🏻
@@ -94,7 +143,7 @@ module.exports = function sassPlugin(_, {native, compilerOptions = {}} = {}) { | |||
// During development, we need to track changes to Sass dependencies. | |||
if (isDev) { | |||
const sassImports = scanSassImports(contents, filePath, fileExt); | |||
sassImports.forEach((imp) => addImportsToMap(filePath, imp)); | |||
[...sassImports].forEach((imp) => addImportsToMap(filePath, imp)); |
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.
Is a new array ([... ]
) needed here?
|
||
// If it is a directory then look for an _index file. | ||
try { | ||
if (fs.lstatSync(pathName).isDirectory()) { |
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.
👍🏻
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.
This looks good to me. Thank you!
Just released in |
Changes
The @snowpack/plugin-sass plugin does not correctly trigger sass recompiling when partials past the first level of imports are changed during
snowpack dev
. Although Snowpack recognizes that the file has changed, it does not trigger the top file importing it as changed so nothing is recompiled.The
scanSassImports()
function will now recursively find all the child imports. It will also reduce duplicates since it is possible that many partials are importing the same file like a_variables.scss
partial. I also added support for@forward
which is also used for importing partials https://sass-lang.com/documentation/at-rules/forward.Related Discussions:
#1717
#2668
Testing
I first updated the
marks a dependant as changed when an imported changes and isDev=true
test to look for a child of a child dependency. This proved the bug by causing the test to fail. I then wrote the code to allow the test to pass. I also manually tested in a large project with multiple levels of nesting.Docs
Bug fix only.