Skip to content

Commit 85a0d68

Browse files
authored
Mark all included files as dependencies for watch mode (#31)
1 parent 288d3d1 commit 85a0d68

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/index.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,29 @@ const plugin = (opts = {}) => {
115115
(sassError, sassResult) =>
116116
sassError ? reject(sassError) : resolve(sassResult),
117117
),
118-
).then(({ css: sassCSS, map: sassMap }) =>
119-
mergeSourceMaps(postMap.toJSON(), JSON.parse(sassMap)).then(
118+
).then(({ css: sassCSS, map: sassMap, stats }) => {
119+
const parent = pathResolve(postConfig.from);
120+
121+
// use stats.includedFiles to get the full list of dependencies. Importer will not receive relative imports. See https://github.com/sass/dart-sass/issues/574
122+
for (const includedFile of stats.includedFiles) {
123+
// strip the #sass suffix we added
124+
const file = pathResolve(includedFile.replace(/#sass$/, ''));
125+
126+
// don't include the parent as a dependency of itself
127+
if (file === parent) {
128+
continue;
129+
}
130+
131+
// push the dependency to watch tasks
132+
result.messages.push({
133+
type: 'dependency',
134+
plugin: 'postcss-sass',
135+
file,
136+
parent,
137+
});
138+
}
139+
140+
return mergeSourceMaps(postMap.toJSON(), JSON.parse(sassMap)).then(
120141
(prev) => {
121142
// update root to post-node-sass ast
122143
result.root = parse(
@@ -126,8 +147,8 @@ const plugin = (opts = {}) => {
126147
}),
127148
);
128149
},
129-
),
130-
);
150+
);
151+
});
131152
},
132153
};
133154
};

0 commit comments

Comments
 (0)