Skip to content

Commit ebca4e3

Browse files
authored
Merge pull request #12 from SectorLabs/define-file-dependencies
Signal webpack of file dependencies
2 parents 9433170 + fe868fb commit ebca4e3

File tree

3 files changed

+949
-573
lines changed

3 files changed

+949
-573
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sector-labs/postcss-inline-class",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "Inline the declarations of other CSS classes in your CSS classes.",
55
"main": "src/index.js",
66
"repository": "https://github.com/sectorlabs/postcss-inline-class",
@@ -23,7 +23,7 @@
2323
},
2424
"dependencies": {
2525
"lodash": "latest",
26-
"postcss": "^7.0.1",
26+
"postcss": "^8.0.0",
2727
"resolve": "^1.1.7"
2828
},
2929
"devDependencies": {

src/index.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const resolveFile = (filePath, options) =>
1515
resolvePath(filePath, options, (err, path) => (err ? reject(err) : resolve(path)));
1616
});
1717

18-
const processAtRule = (onError, atRule, root, targetClass, importPath) => {
18+
const processAtRule = (onError, atRule, root, targetClass, importPath, resolvedPath, result) => {
1919
const matchedDeclarations = findInlineDeclarations(root, targetClass);
2020
const nestedRules = findNestedRules(root, targetClass);
2121
const mediaQueries = findMediaQueries(root, targetClass);
@@ -48,6 +48,15 @@ const processAtRule = (onError, atRule, root, targetClass, importPath) => {
4848
});
4949

5050
atRule.replaceWith(matchedDeclarations);
51+
if (resolvedPath !== null) {
52+
result.messages.push({
53+
type: 'dependency',
54+
plugin: 'postcss-inline-class',
55+
file: resolvedPath,
56+
parent: result.opts.from,
57+
});
58+
}
59+
5160
return [...nestedRules, ...mediaQueries];
5261
};
5362

@@ -61,7 +70,9 @@ const walkAtRule = (root, result, promises, resolve) => (atRule) => {
6170
};
6271

6372
if (params.length === 1) {
64-
promises.push(Promise.resolve(processAtRule(onError, atRule, root, targetClass)));
73+
promises.push(
74+
Promise.resolve(processAtRule(onError, atRule, root, targetClass, null, null, result)),
75+
);
6576
return;
6677
}
6778

@@ -71,7 +82,15 @@ const walkAtRule = (root, result, promises, resolve) => (atRule) => {
7182
.then((resolvedPath) =>
7283
readFile(resolvedPath).then((rawData) => {
7384
const importedRoot = postcss.parse(rawData);
74-
return processAtRule(onError, atRule, importedRoot, targetClass, importPath);
85+
return processAtRule(
86+
onError,
87+
atRule,
88+
importedRoot,
89+
targetClass,
90+
importPath,
91+
resolvedPath,
92+
result,
93+
);
7594
}),
7695
)
7796
.catch(() => {

0 commit comments

Comments
 (0)