Skip to content

Commit

Permalink
Add warning when no file found, add source for new nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrinicolas committed Aug 14, 2018
1 parent b0d05fe commit 631f3ce
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 24 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
This project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.0.1 - 2018-08-13
- Initial release.
## 1.1.0 - 2018-08-15
### Added
- Source for new nodes to generate an accurate source map.
- Warning when no file found for a glob.

## 1.0.0 - 2018-08-13
- Initial release.
25 changes: 17 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ module.exports = postcss.plugin('postcss-import-ext-glob', (opts = {}) => {
? opts.sort
: DEFAULT_SORTER;

return css => {
return (root, result) => {
const promisesList = [];

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

Expand All @@ -34,21 +34,30 @@ module.exports = postcss.plugin('postcss-import-ext-glob', (opts = {}) => {
if (globList.length) {
fg(globList)
.then(entries => {
if (!entries.length) {
result.warn(
`No file found for @import-glob ${rule.params}`,
{ node: rule }
);
}

const sortedEntries = sort(entries)[sorter]();

for (const entry of sortedEntries) {
css.insertBefore(rule, {
root.insertBefore(rule, {
name: 'import',
params: `"${entry}"`
params: `"${entry}"`,
source: rule.source
});
}
rule.remove();
resolve();
});
} else {
reject(new Error(
`No string found with rule @import-glob ${rule.params}`
));
throw rule.error(
`No string found with rule @import-glob ${rule.params}`,
{ plugin: 'postcss-import-ext-glob' }
);
}
}));
});
Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-import-ext-glob",
"version": "1.0.0",
"version": "1.1.0",
"description": "A PostCSS plugin to extend postcss-import path resolver to allow glob usage as path",
"license": "MIT",
"main": "index.js",
Expand All @@ -17,14 +17,15 @@
"postcss",
"import",
"extension",
"glob"
"glob",
"postcss-plugin"
],
"bugs": {
"url": "https://github.com/dimitrinicolas/postcss-import-ext-glob/issues"
},
"homepage": "https://github.com/dimitrinicolas/postcss-import-ext-glob",
"scripts": {
"publish": "clean-publish --files fixtures",
"publish": "clean-publish --files .nyc_output coverage fixtures",
"lint": "eslint **/*.js",
"test": "nyc --reporter=lcov --reporter=text ava",
"coverage": "nyc report --reporter=text-lcov | coveralls",
Expand All @@ -37,10 +38,10 @@
"clean-publish": "^1.0.9",
"coveralls": "^3.0.2",
"eslint": "^5.3.0",
"eslint-config-airbnb": "^17.0.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.10.0",
"eslint-plugin-react": "^7.11.1",
"nodemon": "^1.18.3",
"nyc": "^12.0.2",
"postcss-import": "^12.0.0"
Expand Down
19 changes: 17 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,23 @@ test('error empty param test', async t => {
const input = /* scss */`
@import-glob;
`;
const output = new Error('No string found with rule @import-glob ');
await tester.test(input, output, t, {
await tester.test(input, err => {
t.true(/No string found with rule @import-glob/.test(err));
}, t, {
pluginsAfter: [postcssImport]
});
});

test('no entries warning', async t => {
const warningsTester = new PostcssTester({
postcss,
plugin: postcssImportExtGlob,
tolerateWarnings: true
});
const input = /* scss */`
@import-glob "fixtures/css/_unknow/**/*.css";
`;
await warningsTester.test(input, '', t, {
pluginsAfter: [postcssImport]
});
});

0 comments on commit 631f3ce

Please sign in to comment.