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

Fix Sass partial changes not triggering recompiles in Dev #2792

Merged
merged 7 commits into from
Mar 9, 2021

Conversation

segovia94
Copy link
Contributor

@segovia94 segovia94 commented Mar 5, 2021

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.

@vercel
Copy link

vercel bot commented Mar 5, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/9hiQXqozkhZcJ6B4ipnkH32XD5Xr
✅ Preview: https://snowpack-git-fork-segovia94-sass-pikapkg.vercel.app

@@ -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;
Copy link
Collaborator

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:'))
Copy link
Collaborator

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'
Copy link
Collaborator

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));
Copy link
Collaborator

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()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏻

Copy link
Collaborator

@drwpow drwpow left a 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!

@drwpow drwpow merged commit edef198 into FredKSchott:main Mar 9, 2021
Triage automation moved this from Pull Request Open to Closed Mar 9, 2021
@drwpow
Copy link
Collaborator

drwpow commented Mar 16, 2021

Just released in v1.3.1! 🎉

@FredKSchott FredKSchott removed this from Closed in Triage Apr 20, 2022
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.

None yet

2 participants