Skip to content

Commit 631f3ce

Browse files
Add warning when no file found, add source for new nodes
1 parent b0d05fe commit 631f3ce

File tree

5 files changed

+55
-24
lines changed

5 files changed

+55
-24
lines changed

CHANGELOG.md

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

6-
## 0.0.1 - 2018-08-13
7-
- Initial release.
6+
## 1.1.0 - 2018-08-15
7+
### Added
8+
- Source for new nodes to generate an accurate source map.
9+
- Warning when no file found for a glob.
10+
11+
## 1.0.0 - 2018-08-13
12+
- Initial release.

index.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ module.exports = postcss.plugin('postcss-import-ext-glob', (opts = {}) => {
1313
? opts.sort
1414
: DEFAULT_SORTER;
1515

16-
return css => {
16+
return (root, result) => {
1717
const promisesList = [];
1818

19-
css.walkAtRules('import-glob', rule => {
20-
promisesList.push(new Promise((resolve, reject) => {
19+
root.walkAtRules('import-glob', rule => {
20+
promisesList.push(new Promise(resolve => {
2121
const globList = [];
2222
const params = valueParser(rule.params).nodes;
2323

@@ -34,21 +34,30 @@ module.exports = postcss.plugin('postcss-import-ext-glob', (opts = {}) => {
3434
if (globList.length) {
3535
fg(globList)
3636
.then(entries => {
37+
if (!entries.length) {
38+
result.warn(
39+
`No file found for @import-glob ${rule.params}`,
40+
{ node: rule }
41+
);
42+
}
43+
3744
const sortedEntries = sort(entries)[sorter]();
3845

3946
for (const entry of sortedEntries) {
40-
css.insertBefore(rule, {
47+
root.insertBefore(rule, {
4148
name: 'import',
42-
params: `"${entry}"`
49+
params: `"${entry}"`,
50+
source: rule.source
4351
});
4452
}
4553
rule.remove();
4654
resolve();
4755
});
4856
} else {
49-
reject(new Error(
50-
`No string found with rule @import-glob ${rule.params}`
51-
));
57+
throw rule.error(
58+
`No string found with rule @import-glob ${rule.params}`,
59+
{ plugin: 'postcss-import-ext-glob' }
60+
);
5261
}
5362
}));
5463
});

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-import-ext-glob",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A PostCSS plugin to extend postcss-import path resolver to allow glob usage as path",
55
"license": "MIT",
66
"main": "index.js",
@@ -17,14 +17,15 @@
1717
"postcss",
1818
"import",
1919
"extension",
20-
"glob"
20+
"glob",
21+
"postcss-plugin"
2122
],
2223
"bugs": {
2324
"url": "https://github.com/dimitrinicolas/postcss-import-ext-glob/issues"
2425
},
2526
"homepage": "https://github.com/dimitrinicolas/postcss-import-ext-glob",
2627
"scripts": {
27-
"publish": "clean-publish --files fixtures",
28+
"publish": "clean-publish --files .nyc_output coverage fixtures",
2829
"lint": "eslint **/*.js",
2930
"test": "nyc --reporter=lcov --reporter=text ava",
3031
"coverage": "nyc report --reporter=text-lcov | coveralls",
@@ -37,10 +38,10 @@
3738
"clean-publish": "^1.0.9",
3839
"coveralls": "^3.0.2",
3940
"eslint": "^5.3.0",
40-
"eslint-config-airbnb": "^17.0.0",
41+
"eslint-config-airbnb": "^17.1.0",
4142
"eslint-plugin-import": "^2.13.0",
4243
"eslint-plugin-jsx-a11y": "^6.1.1",
43-
"eslint-plugin-react": "^7.10.0",
44+
"eslint-plugin-react": "^7.11.1",
4445
"nodemon": "^1.18.3",
4546
"nyc": "^12.0.2",
4647
"postcss-import": "^12.0.0"

test.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,23 @@ test('error empty param test', async t => {
104104
const input = /* scss */`
105105
@import-glob;
106106
`;
107-
const output = new Error('No string found with rule @import-glob ');
108-
await tester.test(input, output, t, {
107+
await tester.test(input, err => {
108+
t.true(/No string found with rule @import-glob/.test(err));
109+
}, t, {
110+
pluginsAfter: [postcssImport]
111+
});
112+
});
113+
114+
test('no entries warning', async t => {
115+
const warningsTester = new PostcssTester({
116+
postcss,
117+
plugin: postcssImportExtGlob,
118+
tolerateWarnings: true
119+
});
120+
const input = /* scss */`
121+
@import-glob "fixtures/css/_unknow/**/*.css";
122+
`;
123+
await warningsTester.test(input, '', t, {
109124
pluginsAfter: [postcssImport]
110125
});
111126
});

0 commit comments

Comments
 (0)