-
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathindex.js
More file actions
75 lines (62 loc) · 2.38 KB
/
Copy pathindex.js
File metadata and controls
75 lines (62 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import getReplacedValue from './lib/get-replaced-value';
import importEnvironmentVariablesFromSources from './lib/import-from';
/**
* @param {{importFrom?: string[]}} opts
* @returns {import('postcss').Plugin}
*/
const creator = (opts) => {
// sources to import environment variables from
const importFrom = [].concat(Object(opts).importFrom || []);
// promise any environment variables are imported
const environmentVariablesPromise = importEnvironmentVariablesFromSources(importFrom);
const disableDeprecationNotice = 'disableDeprecationNotice' in Object(opts) ? Boolean(opts.disableDeprecationNotice) : false;
let didWarn = false;
return {
postcssPlugin: 'postcss-env-fn',
async AtRule(atRule, { result }) {
let replacedValue;
try {
replacedValue = getReplacedValue(atRule.params, await environmentVariablesPromise);
} catch {
atRule.warn(
result,
`Failed to parse params '${atRule.params}' as an environment value. Leaving the original value intact.`,
);
}
if (typeof replacedValue === 'undefined') {
return;
}
if (replacedValue !== atRule.params) {
atRule.params = replacedValue;
if (!disableDeprecationNotice && !didWarn) {
didWarn= true;
atRule.warn(result, 'postcss-env-function is deprecated and will be removed.\nCheck the discussion on github for more details. https://github.com/csstools/postcss-plugins/discussions/192');
}
}
},
async Declaration(decl, { result }) {
let replacedValue;
try {
replacedValue = getReplacedValue(decl.value, await environmentVariablesPromise);
} catch {
decl.warn(
result,
`Failed to parse value '${decl.value}' as an environment value. Leaving the original value intact.`,
);
}
if (typeof replacedValue === 'undefined') {
return;
}
if (replacedValue !== decl.value) {
decl.value = replacedValue;
if (!disableDeprecationNotice && !didWarn) {
didWarn = true;
decl.warn(result, 'postcss-env-function is deprecated and will be removed.\nWe are looking for insights and anecdotes on how these features are used so that we can design the best alternative.\nPlease let us know if our proposal will work for you.\nVisit the discussion on github for more details. https://github.com/csstools/postcss-plugins/discussions/192');
}
}
},
};
};
creator.postcss = true;
export default creator;
export { creator as 'module.exports' };