Skip to content

Commit 329b474

Browse files
committed
feat: include path and silent option
1 parent f791dd2 commit 329b474

File tree

3 files changed

+2264
-3
lines changed

3 files changed

+2264
-3
lines changed

index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ var defaults = {
6060
preserveInjectedVariables: true,
6161
// Will write media queries in the same order as in the original file.
6262
// Currently defaulted to false for legacy behavior. We can update to `true` in a major version
63-
preserveAtRulesOrder: false
63+
preserveAtRulesOrder: false,
64+
65+
includePaths: [],
66+
67+
silent: false,
6468
};
6569

6670
module.exports = (options = {}) => {
@@ -72,7 +76,13 @@ module.exports = (options = {}) => {
7276
postcssPlugin: 'postcss-css-variables',
7377
Once(css, { decl, result, rule }) {
7478
// Transform CSS AST here
79+
80+
const filename = css.source.input.file
7581

82+
if (opts.includePaths.length) {
83+
const matches = opts.includePaths.some(path => filename.includes(path))
84+
if (!matches) return
85+
}
7686
/* * /
7787
try {
7888
/* */
@@ -141,6 +151,9 @@ module.exports = (options = {}) => {
141151
// Chainable helper function to log any messages (warnings)
142152
var logResolveValueResult = function(valueResult) {
143153
// Log any warnings that might of popped up
154+
155+
if (opts.silent) return valueResult;
156+
144157
var warningList = [].concat(valueResult.warnings);
145158
warningList.forEach(function(warningArgs) {
146159
warningArgs = [].concat(warningArgs);
@@ -158,7 +171,7 @@ module.exports = (options = {}) => {
158171
eachCssVariableDeclaration(css, function(decl) {
159172
var declParentRule = decl.parent;
160173

161-
var valueResults = logResolveValueResult(resolveValue(decl, map));
174+
var valueResults = logResolveValueResult(resolveValue(decl, map, undefined, undefined));
162175
// Split out each selector piece into its own declaration for easier logic down the road
163176
decl.parent.selectors.forEach(function(selector) {
164177
// Create a detached clone

playground/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14377,7 +14377,7 @@ System.registerDynamic('npm:postcss-css-variables@0.14.0/lib/resolve-value.js',
1437714377
}
1437814378

1437914379
isResultantValueUndefined = replaceValue === undefined;
14380-
if (isResultantValueUndefined) {
14380+
if (isResultantValueUndefined && !silent) {
1438114381
warnings.push(['variable ' + variableName + ' is undefined and used without a fallback', { node: decl }]);
1438214382
}
1438314383

0 commit comments

Comments
 (0)