Skip to content

Commit 34dcbc2

Browse files
Upgrade to PostCSS v8
1 parent ad4c4a7 commit 34dcbc2

File tree

10 files changed

+3341
-7941
lines changed

10 files changed

+3341
-7941
lines changed

.eslintrc.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
11
module.exports = {
22
env: {
3-
browser: true
3+
es6: true,
4+
node: true,
45
},
5-
extends: 'airbnb',
6-
parser: 'babel-eslint',
7-
rules : {
8-
'max-len': ['error', {
9-
'code': 150
10-
}],
11-
'comma-dangle': 0,
12-
'no-plusplus': 0,
13-
'arrow-parens': ['error', 'as-needed'],
14-
'no-multi-assign': 0,
15-
'strict': 0,
16-
'no-console': 0,
17-
'prefer-destructuring': 0,
18-
'function-paren-newline': 0,
19-
'global-require': 0,
20-
'prefer-spread': 0,
21-
'prefer-rest-params': 0,
22-
'prefer-arrow-callback': 0,
23-
'arrow-body-style': 0,
24-
'no-restricted-globals': 0,
25-
'no-restricted-syntax': 0,
26-
'consistent-return': 0,
27-
'no-param-reassign': 0,
28-
'no-underscore-dangle': 0,
29-
'import/no-unresolved': 0,
30-
'import/no-dynamic-require': 0,
31-
'import/no-extraneous-dependencies': 0,
32-
'import/extensions': ['warn', 'ignorePackages']
33-
}
6+
globals: {
7+
Atomics: 'readonly',
8+
SharedArrayBuffer: 'readonly',
9+
},
10+
parserOptions: {
11+
ecmaVersion: 2018,
12+
sourceType: 'module',
13+
},
14+
rules: {},
3415
};

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ logs
88

99
.nyc_output
1010
coverage
11+
12+
.vscode

.prettierrc

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"printWidth": 80,
3+
"singleQuote": true,
4+
"useTabs": false,
5+
"overrides": [
6+
{
7+
"files": "*.css",
8+
"options": {
9+
"parser": "scss",
10+
"singleQuote": false
11+
}
12+
},
13+
{
14+
"files": ["*.json", ".prettierrc", ".eslintrc"],
15+
"options": {
16+
"parser": "json"
17+
}
18+
}
19+
],
20+
"eslintConfig": {
21+
"env": {
22+
"browser": true
23+
},
24+
"extends": "airbnb",
25+
"parser": "babel-eslint",
26+
"rules": {
27+
"max-len": [
28+
"error",
29+
{
30+
"code": 150
31+
}
32+
],
33+
"comma-dangle": 0,
34+
"no-plusplus": 0,
35+
"arrow-parens": ["error", "as-needed"],
36+
"no-multi-assign": 0,
37+
"strict": 0,
38+
"no-console": 0,
39+
"prefer-destructuring": 0,
40+
"function-paren-newline": 0,
41+
"global-require": 0,
42+
"prefer-spread": 0,
43+
"prefer-rest-params": 0,
44+
"prefer-arrow-callback": 0,
45+
"arrow-body-style": 0,
46+
"no-restricted-globals": 0,
47+
"no-restricted-syntax": 0,
48+
"no-unused-expressions": 0,
49+
"consistent-return": 0,
50+
"no-param-reassign": 0,
51+
"no-underscore-dangle": 0,
52+
"import/no-unresolved": 0,
53+
"import/no-dynamic-require": 0,
54+
"import/no-extraneous-dependencies": 0,
55+
"import/extensions": ["warn", "ignorePackages"],
56+
"react/prefer-stateless-function": 0,
57+
"react/jsx-one-expression-per-line": 0,
58+
"implicit-arrow-linebreak": 0
59+
}
60+
}
61+
}

.travis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: node_js
22

33
node_js:
44
- stable
5-
- "8"
5+
- '14'
66

77
install:
88
- npm install
@@ -11,7 +11,3 @@ install:
1111
after_success:
1212
- npm run coverage
1313
- codecov
14-
15-
# Telegram bot
16-
notifications:
17-
webhooks: https://fathomless-fjord-24024.herokuapp.com/notify

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
This project adheres to
44
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## 2.0.0 - 2021-01-02
7+
### Breaking
8+
- Upgrade to PostCSS v8.
9+
610
## 1.1.0 - 2018-08-15
711
### Added
812
- Source for new nodes to generate an accurate source map.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# postcss-import-ext-glob [![Build Status][travis badge]][travis link] [![Coverage Status][coveralls badge]][coveralls link]
22

3-
A [PostCSS][postcss] plugin to extend [postcss-import][postcss-import] path
3+
A [PostCSS][postcss] v8 plugin to extend [postcss-import][postcss-import] path
44
resolver to allow [glob][glob ref] usage as a path.
55

6-
You must use this plugin along with [postcss-import][postcss-import], place
6+
You must use this plugin along with [postcss-import][postcss-import], place
77
this plugin **before** `postcss-import`.
88

99
```pcss
@@ -13,7 +13,7 @@ this plugin **before** `postcss-import`.
1313
## Installation
1414

1515
```console
16-
$ npm install postcss-import-ext-glob
16+
$ npm install --save-dev postcss postcss-import postcss-import-ext-glob
1717
```
1818

1919
## Usage
@@ -26,7 +26,7 @@ postcss([
2626
]);
2727
```
2828

29-
Check out [PostCSS](https://github.com/postcss/postcss) docs for the complete
29+
Check out [PostCSS](https://github.com/postcss/postcss) docs for the complete
3030
installation.
3131

3232
### Example
@@ -71,7 +71,7 @@ The sort order is by default ascending.
7171

7272
## Related
7373

74-
- [postcss-import][postcss-import] - PostCSS plugin to inline @import rules
74+
- [postcss-import][postcss-import] - PostCSS plugin to inline @import rules
7575
content
7676
- [fast-glob][fast-glob] - Module used for getting glob entries
7777
- [fast-sort][fast-sort] - Module used for sorting glob entries

index.js

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const postcss = require('postcss');
21
const valueParser = require('postcss-value-parser');
32

43
const path = require('path');
@@ -8,60 +7,71 @@ const sort = require('fast-sort');
87
const SORTERS = ['asc', 'desc'];
98
const DEFAULT_SORTER = 'asc';
109

11-
module.exports = postcss.plugin('postcss-import-ext-glob', (opts = {}) => {
12-
const sorter = SORTERS.indexOf(opts.sort) > -1
13-
? opts.sort
14-
: DEFAULT_SORTER;
10+
module.exports = (opts = {}) => {
11+
const sorter = SORTERS.indexOf(opts.sort) !== -1 ? opts.sort : DEFAULT_SORTER;
1512

16-
return (root, result) => {
17-
const promisesList = [];
13+
return {
14+
postcssPlugin: 'postcss-import-ext-glob',
15+
Once(root, { AtRule, result }) {
16+
const promisesList = [];
1817

19-
root.walkAtRules('import-glob', rule => {
20-
promisesList.push(new Promise(resolve => {
21-
const globList = [];
22-
const params = valueParser(rule.params).nodes;
18+
root.walkAtRules('import-glob', (rule) => {
19+
promisesList.push(
20+
new Promise((resolve) => {
21+
const globList = [];
2322

24-
const dirname = typeof rule.source.input.file === 'string'
25-
? path.dirname(rule.source.input.file)
26-
: __dirname;
23+
const params = valueParser(rule.params).nodes;
2724

28-
for (const param of params) {
29-
if (param.type === 'string') {
30-
globList.push(path.join(dirname, param.value));
31-
}
32-
}
25+
const dirName =
26+
typeof rule.source.input.file === 'string'
27+
? path.dirname(rule.source.input.file)
28+
: __dirname;
3329

34-
if (globList.length) {
35-
fg(globList)
36-
.then(entries => {
37-
if (!entries.length) {
38-
result.warn(
39-
`No file found for @import-glob ${rule.params}`,
40-
{ node: rule }
41-
);
30+
for (const param of params) {
31+
if (param.type === 'string') {
32+
globList.push(path.join(dirName, param.value));
4233
}
34+
}
4335

44-
const sortedEntries = sort(entries)[sorter]();
36+
if (globList.length) {
37+
fg(globList).then((entries) => {
38+
if (!entries.length) {
39+
result.warn(`No file found for @import-glob ${rule.params}`, {
40+
node: rule,
41+
});
42+
}
4543

46-
for (const entry of sortedEntries) {
47-
root.insertBefore(rule, {
48-
name: 'import',
49-
params: `"${entry}"`,
50-
source: rule.source
44+
const sortedEntries = sort(entries)[sorter]();
45+
46+
sortedEntries.forEach((entry) => {
47+
rule.before(
48+
new AtRule({
49+
name: 'import',
50+
params: `"${entry}"`,
51+
source: rule.source,
52+
})
53+
);
5154
});
52-
}
53-
rule.remove();
54-
resolve();
55-
});
56-
} else {
57-
throw rule.error(
58-
`No string found with rule @import-glob ${rule.params}`,
59-
{ plugin: 'postcss-import-ext-glob' }
60-
);
61-
}
62-
}));
63-
});
6455

65-
return Promise.all(promisesList);
56+
rule.remove();
57+
58+
resolve();
59+
});
60+
} else {
61+
throw rule.error(
62+
`No string found with rule @import-glob ${rule.params}`,
63+
{
64+
word: rule.params,
65+
}
66+
);
67+
}
68+
})
69+
);
70+
});
71+
72+
return Promise.all(promisesList);
73+
},
6674
};
67-
});
75+
};
76+
77+
module.exports.postcss = true;

0 commit comments

Comments
 (0)