Skip to content

Commit 46f1c80

Browse files
jonathantnealromainmenke
authored andcommitted
update project configuration
1 parent 8147dd6 commit 46f1c80

File tree

8 files changed

+91
-80
lines changed

8 files changed

+91
-80
lines changed

plugins/postcss-env-function/package.json

+21-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"repository": "csstools/postcss-env-function",
88
"homepage": "https://github.com/csstools/postcss-env-function#readme",
99
"bugs": "https://github.com/csstools/postcss-env-function/issues",
10-
"main": "dist/index.js",
10+
"main": "dist/index.cjs",
1111
"module": "dist/index.mjs",
1212
"files": [
1313
"dist"
@@ -32,15 +32,14 @@
3232
"postcss": "^8.3"
3333
},
3434
"devDependencies": {
35-
"@babel/core": "7.15.5",
36-
"@babel/eslint-parser": "7.15.4",
37-
"@babel/preset-env": "7.15.6",
35+
"@babel/core": "7.15.8",
36+
"@babel/preset-env": "7.15.8",
3837
"@rollup/plugin-babel": "5.3.0",
39-
"eslint": "7.32.0",
38+
"eslint": "8.1.0",
4039
"postcss": "8.3.6",
4140
"postcss-tape": "6.0.1",
4241
"pre-commit": "1.2.2",
43-
"rollup": "2.56.3"
42+
"rollup": "2.58.3"
4443
},
4544
"babel": {
4645
"presets": [
@@ -54,11 +53,22 @@
5453
},
5554
"eslintConfig": {
5655
"env": {
57-
"es6": true,
58-
"node": true
56+
"es6": true
5957
},
6058
"extends": "eslint:recommended",
61-
"parser": "@babel/eslint-parser"
59+
"parserOptions": {
60+
"ecmaVersion": 12,
61+
"sourceType": "module",
62+
"ecmaFeatures": {
63+
"modules": true
64+
}
65+
},
66+
"rules": {
67+
"semi": [
68+
"error",
69+
"never"
70+
]
71+
}
6272
},
6373
"rollup": {
6474
"input": "src/index.js",
@@ -67,7 +77,8 @@
6777
],
6878
"output": [
6979
{
70-
"file": "dist/index.js",
80+
"exports": "default",
81+
"file": "dist/index.cjs",
7182
"format": "cjs"
7283
},
7384
{
+12-12
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import getReplacedValue from './lib/get-replaced-value';
2-
import importEnvironmentVariablesFromSources from './lib/import-from';
1+
import getReplacedValue from './lib/get-replaced-value'
2+
import importEnvironmentVariablesFromSources from './lib/import-from'
33

44
/**
55
* @param {{importFrom?: string[]}} opts
66
* @returns {import('postcss').Plugin}
77
*/
8-
module.exports = function creator(opts) {
8+
export default function creator(opts) {
99
// sources to import environment variables from
10-
const importFrom = [].concat(Object(opts).importFrom || []);
10+
const importFrom = [].concat(Object(opts).importFrom || [])
1111

1212
// promise any environment variables are imported
13-
const environmentVariablesPromise = importEnvironmentVariablesFromSources(importFrom);
13+
const environmentVariablesPromise = importEnvironmentVariablesFromSources(importFrom)
1414

1515
return {
1616
postcssPlugin: 'postcss-env-fn',
1717
async AtRule(atRule) {
18-
const replacedValue = getReplacedValue(atRule.params, await environmentVariablesPromise);
18+
const replacedValue = getReplacedValue(atRule.params, await environmentVariablesPromise)
1919

2020
if (replacedValue !== atRule.params) {
21-
atRule.params = replacedValue;
21+
atRule.params = replacedValue
2222
}
2323
},
2424
async Declaration(decl) {
25-
const replacedValue = getReplacedValue(decl.value, await environmentVariablesPromise);
25+
const replacedValue = getReplacedValue(decl.value, await environmentVariablesPromise)
2626

2727
if (replacedValue !== decl.value) {
28-
decl.value = replacedValue;
28+
decl.value = replacedValue
2929
}
3030
}
31-
};
32-
};
31+
}
32+
}
3333

34-
module.exports.postcss = true;
34+
creator.postcss = true
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const dashedMatch = /^--/;
1+
const dashedMatch = /^--/
22

33
// returns the value of a css function as a string
44
export default (node) => {
5-
const value = String(node.nodes);
5+
const value = String(node.nodes)
66

7-
return dashedMatch.test(value) ? value : undefined;
8-
};
7+
return dashedMatch.test(value) ? value : undefined
8+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { parse } from 'postcss-values-parser';
2-
import updateEnvValue from './update-env-value';
3-
import walkEnvFuncs from './walk-env-funcs';
1+
import { parse } from 'postcss-values-parser'
2+
import updateEnvValue from './update-env-value'
3+
import walkEnvFuncs from './walk-env-funcs'
44

55
/**
66
* @param {string} originalValue
@@ -9,14 +9,14 @@ import walkEnvFuncs from './walk-env-funcs';
99
*/
1010
export default (originalValue, variables) => {
1111
// get the ast of the original value
12-
const ast = parse(originalValue);
12+
const ast = parse(originalValue)
1313

1414
// walk all of the css env() functions
1515
walkEnvFuncs(ast, node => {
1616
// update the environment value for the css env() function
17-
updateEnvValue(node, variables);
18-
});
17+
updateEnvValue(node, variables)
18+
})
1919

2020
// return the stringified ast
21-
return String(ast);
22-
};
21+
return String(ast)
22+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import fs from 'fs';
2-
import path from 'path';
3-
import { parse } from 'postcss-values-parser';
1+
import fs from 'fs'
2+
import path from 'path'
3+
import { parse } from 'postcss-values-parser'
44

55
/**
66
* Import Custom Properties from Object
@@ -11,13 +11,13 @@ function importEnvironmentVariablesFromObject(object) {
1111
const environmentVariables = Object.assign(
1212
{},
1313
Object(object).environmentVariables || Object(object)['environment-variables']
14-
);
14+
)
1515

1616
for (const key in environmentVariables) {
17-
environmentVariables[key] = parse(environmentVariables[key]).nodes;
17+
environmentVariables[key] = parse(environmentVariables[key]).nodes
1818
}
1919

20-
return environmentVariables;
20+
return environmentVariables
2121
}
2222

2323
/**
@@ -26,9 +26,9 @@ function importEnvironmentVariablesFromObject(object) {
2626
* @returns {Promise<Record<string, import('postcss-values-parser').Root>>}
2727
*/
2828
async function importEnvironmentVariablesFromJSONFile(from) {
29-
const object = await readJSON(path.resolve(from));
29+
const object = await readJSON(path.resolve(from))
3030

31-
return importEnvironmentVariablesFromObject(object);
31+
return importEnvironmentVariablesFromObject(object)
3232
}
3333

3434
/**
@@ -37,9 +37,9 @@ async function importEnvironmentVariablesFromJSONFile(from) {
3737
* @returns {Promise<Record<string, import('postcss-values-parser').Root>>}
3838
*/
3939
async function importEnvironmentVariablesFromJSFile(from) {
40-
const object = await import(path.resolve(from));
40+
const object = await import(path.resolve(from))
4141

42-
return importEnvironmentVariablesFromObject(object);
42+
return importEnvironmentVariablesFromObject(object)
4343
}
4444

4545
/**
@@ -50,39 +50,39 @@ async function importEnvironmentVariablesFromJSFile(from) {
5050
export default function importEnvironmentVariablesFromSources(sources) {
5151
return sources.map(source => {
5252
if (source instanceof Promise) {
53-
return source;
53+
return source
5454
} else if (source instanceof Function) {
55-
return source();
55+
return source()
5656
}
5757

5858
// read the source as an object
59-
const opts = source === Object(source) ? source : { from: String(source) };
59+
const opts = source === Object(source) ? source : { from: String(source) }
6060

6161
// skip objects with Custom Properties
6262
if (opts.environmentVariables || opts['environment-variables']) {
6363
return opts
6464
}
6565

6666
// source pathname
67-
const from = String(opts.from || '');
67+
const from = String(opts.from || '')
6868

6969
// type of file being read from
70-
const type = (opts.type || path.extname(from).slice(1)).toLowerCase();
70+
const type = (opts.type || path.extname(from).slice(1)).toLowerCase()
7171

72-
return { type, from };
72+
return { type, from }
7373
}).reduce(async (environmentVariables, source) => {
74-
const { type, from } = await source;
74+
const { type, from } = await source
7575

7676
if (type === 'js' || type === 'cjs') {
77-
return Object.assign(environmentVariables, await importEnvironmentVariablesFromJSFile(from));
77+
return Object.assign(environmentVariables, await importEnvironmentVariablesFromJSFile(from))
7878
}
7979

8080
if (type === 'json') {
81-
return Object.assign(environmentVariables, await importEnvironmentVariablesFromJSONFile(from));
81+
return Object.assign(environmentVariables, await importEnvironmentVariablesFromJSONFile(from))
8282
}
8383

84-
return Object.assign(environmentVariables, importEnvironmentVariablesFromObject(await source));
85-
}, {});
84+
return Object.assign(environmentVariables, importEnvironmentVariablesFromObject(await source))
85+
}, {})
8686
}
8787

8888
/* Helper utilities
@@ -95,11 +95,11 @@ export default function importEnvironmentVariablesFromSources(sources) {
9595
const readFile = from => new Promise((resolve, reject) => {
9696
fs.readFile(from, 'utf8', (error, result) => {
9797
if (error) {
98-
reject(error);
98+
reject(error)
9999
} else {
100-
resolve(result);
100+
resolve(result)
101101
}
102-
});
103-
});
102+
})
103+
})
104104

105-
const readJSON = async from => JSON.parse(await readFile(from));
105+
const readJSON = async from => JSON.parse(await readFile(from))
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// returns whether a node is a css env() function
2-
export default (node) => node && node.type === 'func' && node.name === 'env';
2+
export default (node) => node && node.type === 'func' && node.name === 'env'
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import getFnValue from './get-fn-value';
1+
import getFnValue from './get-fn-value'
22

33
// update a node with an environment value
44
export default (node, variables) => {
55
// get the value of a css function as a string
6-
const value = getFnValue(node);
6+
const value = getFnValue(node)
77

88
if (typeof value === 'string' && value in variables) {
99
node.replaceWith(
1010
...asClonedArrayWithBeforeSpacing(variables[value], node.raws.before)
11-
);
11+
)
1212
}
13-
};
13+
}
1414

1515
// return an array with its nodes cloned, preserving the raw
1616
const asClonedArrayWithBeforeSpacing = (array, beforeSpacing) => {
17-
const clonedArray = asClonedArray(array, null);
17+
const clonedArray = asClonedArray(array, null)
1818

1919
if (clonedArray[0]) {
20-
clonedArray[0].raws.before = beforeSpacing;
20+
clonedArray[0].raws.before = beforeSpacing
2121
}
2222

23-
return clonedArray;
24-
};
23+
return clonedArray
24+
}
2525

2626
// return an array with its nodes cloned
27-
const asClonedArray = (array, parent) => array.map(node => asClonedNode(node, parent));
27+
const asClonedArray = (array, parent) => array.map(node => asClonedNode(node, parent))
2828

2929
// return a cloned node
3030
const asClonedNode = (node, parent) => {
31-
const cloneNode = new node.constructor(node);
31+
const cloneNode = new node.constructor(node)
3232

3333
for (const key in node) {
3434
if (key === 'parent') {
35-
cloneNode.parent = parent;
35+
cloneNode.parent = parent
3636
} else if (Object(node[key]).constructor === Array) {
37-
cloneNode[key] = asClonedArray(node.nodes, cloneNode);
37+
cloneNode[key] = asClonedArray(node.nodes, cloneNode)
3838
} else if (Object(node[key]).constructor === Object) {
39-
cloneNode[key] = Object.assign({}, node[key]);
39+
cloneNode[key] = Object.assign({}, node[key])
4040
}
4141
}
4242

43-
return cloneNode;
44-
};
43+
return cloneNode
44+
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import isEnvFunc from './is-env-func';
1+
import isEnvFunc from './is-env-func'
22

33
// walks a node recursively and runs a function using its children
44
export default function walk (node, fn) {
55
node.nodes.slice(0).forEach(childNode => {
66
if (childNode.nodes) {
7-
walk(childNode, fn);
7+
walk(childNode, fn)
88
}
99

1010
if (isEnvFunc(childNode)) {
11-
fn(childNode);
11+
fn(childNode)
1212
}
13-
});
13+
})
1414
}

0 commit comments

Comments
 (0)