Skip to content

Signal webpack of file dependencies #12

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

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Signal webpack of file dependencies
[#188281476]
  • Loading branch information
alexandrukis committed Sep 17, 2024
commit fe868fb68276ca0844f8d2d64581977124144efa
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sector-labs/postcss-inline-class",
"version": "0.0.6",
"version": "0.0.7",
"description": "Inline the declarations of other CSS classes in your CSS classes.",
"main": "src/index.js",
"repository": "https://github.com/sectorlabs/postcss-inline-class",
Expand All @@ -23,7 +23,7 @@
},
"dependencies": {
"lodash": "latest",
"postcss": "^7.0.1",
"postcss": "^8.0.0",
"resolve": "^1.1.7"
},
"devDependencies": {
Expand Down
25 changes: 22 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const resolveFile = (filePath, options) =>
resolvePath(filePath, options, (err, path) => (err ? reject(err) : resolve(path)));
});

const processAtRule = (onError, atRule, root, targetClass, importPath) => {
const processAtRule = (onError, atRule, root, targetClass, importPath, resolvedPath, result) => {
const matchedDeclarations = findInlineDeclarations(root, targetClass);
const nestedRules = findNestedRules(root, targetClass);
const mediaQueries = findMediaQueries(root, targetClass);
Expand Down Expand Up @@ -48,6 +48,15 @@ const processAtRule = (onError, atRule, root, targetClass, importPath) => {
});

atRule.replaceWith(matchedDeclarations);
if (resolvedPath !== null) {
result.messages.push({
type: 'dependency',
plugin: 'postcss-inline-class',
file: resolvedPath,
parent: result.opts.from,
});
}

return [...nestedRules, ...mediaQueries];
};

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

if (params.length === 1) {
promises.push(Promise.resolve(processAtRule(onError, atRule, root, targetClass)));
promises.push(
Promise.resolve(processAtRule(onError, atRule, root, targetClass, null, null, result)),
);
return;
}

Expand All @@ -71,7 +82,15 @@ const walkAtRule = (root, result, promises, resolve) => (atRule) => {
.then((resolvedPath) =>
readFile(resolvedPath).then((rawData) => {
const importedRoot = postcss.parse(rawData);
return processAtRule(onError, atRule, importedRoot, targetClass, importPath);
return processAtRule(
onError,
atRule,
importedRoot,
targetClass,
importPath,
resolvedPath,
result,
);
}),
)
.catch(() => {
Expand Down
Loading