Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-import-ext-glob

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-import-ext-glob - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

9

CHANGELOG.md

@@ -6,3 +6,8 @@ # Change Log

## 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.

@@ -16,7 +16,7 @@ const postcss = require('postcss');

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 = [];

@@ -38,8 +38,16 @@ const params = valueParser(rule.params).nodes;

.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
});

@@ -51,5 +59,6 @@ }

} 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' }
);
}

@@ -56,0 +65,0 @@ }));

{
"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",

@@ -20,3 +20,4 @@ "license": "MIT",

"extension",
"glob"
"glob",
"postcss-plugin"
],

@@ -28,3 +29,3 @@ "bugs": {

"scripts": {
"publish": "clean-publish --files fixtures"
"publish": "clean-publish --files .nyc_output coverage fixtures"
},

@@ -31,0 +32,0 @@ "dependencies": {

# postcss-import-ext-glob [![Build Status][travis badge]][travis link] [![Coverage Status][coveralls badge]][coveralls link]
A [PostCSS][postcss] plugin to extend [postcss-import][postcss-import] path
resolver to allow [glob][glob ref] usage as path.
A [PostCSS][postcss] plugin to extend [postcss-import][postcss-import] path
resolver to allow [glob][glob ref] usage as a path.
You must use this plugin along with [postcss-import][postcss-import], place this
plugin **before** `postcss-import`.
You must use this plugin along with [postcss-import][postcss-import], place
this plugin **before** `postcss-import`.
```scss
```pcss
@import-glob "components/**/*.css";

@@ -29,3 +29,3 @@ ```

Check out [PostCSS](https://github.com/postcss/postcss) docs for the complete
Check out [PostCSS](https://github.com/postcss/postcss) docs for the complete
installation.

@@ -37,3 +37,3 @@

```scss
```pcss
@import-glob "components/**/*.css";

@@ -44,3 +44,3 @@ ```

```css
```pcss
@import "components/form/input.css";

@@ -55,3 +55,3 @@ @import "components/form/submit.css";

```scss
```pcss
@import-glob "helpers/**/*.css", "components/**/*.css";

@@ -78,6 +78,8 @@ ```

- [postcss-import][postcss-import] - PostCSS plugin to inline @import rules
- [postcss-import][postcss-import] - PostCSS plugin to inline @import rules
content
- [fast-glob][fast-glob] - Module used for getting glob entries
- [fast-sort][fast-sort] - Module used for sorting glob entries
- [ava-postcss-tester][ava-postcss-tester] - Simply test your PostCSS plugin
with AVA

@@ -97,3 +99,4 @@ ## License

[fast-sort]: https://www.npmjs.com/package/fast-sort
[ava-postcss-tester]: https://github.com/dimitrinicolas/ava-postcss-tester
[glob ref]: https://en.wikipedia.org/wiki/Glob_(programming)
import test from 'ava';
import PostcssTester from 'ava-postcss-tester';

@@ -8,66 +9,52 @@ import postcss from 'postcss';

const testPostcss = async (input, output, t, opts = {}) => {
const plugins = [];
const tester = new PostcssTester({
postcss,
plugin: postcssImportExtGlob
});
for (const plugin of opts.pluginsBefore || []) {
plugins.push(plugin);
}
plugins.push(opts.plugin || postcssImportExtGlob());
for (const plugin of opts.pluginsAfter || []) {
plugins.push(plugin);
}
test('simple test', async t => {
const input = /* scss */`
@import-glob "fixtures/css/foo/**/*.css";
`;
const output = /* scss */`
@import "${__dirname}/fixtures/css/foo/bar.css";
@import "${__dirname}/fixtures/css/foo/foo.css";
`;
await tester.test(input, output, t);
});
if (output instanceof Error) {
t.plan(1);
} else {
// t.plan(2);
t.plan(1);
}
await postcss(plugins).process(input, { from: '' }).then(result => {
if (output instanceof Error) {
t.fail();
return;
test('simple test postcss-import', async t => {
const input = /* scss */`
@import-glob "fixtures/css/foo/**/*.css";
`;
const output = /* scss */`
.bar {
display: inline-block;
}
t.is(result.css.replace(/\n|\r/g, ' '), output.replace(/\n|\r/g, ' '));
// t.is(result.warnings().length, 0);
}).catch(err => {
if (!(output instanceof Error)) {
t.fail(err);
return;
.foo {
display: block;
}
t.is(err.message, output.message);
`;
await tester.test(input, output, t, {
pluginsAfter: [postcssImport]
});
};
test('simple test', async t => {
const input = '@import-glob "fixtures/css/foo/**/*.css";';
const output = [
'.bar {',
' display: inline-block;',
'}',
'.foo {',
' display: block;',
'}'
].join(' ');
await testPostcss(input, output, t, {
pluginsAfter: [postcssImport()]
});
});
test('sort option', async t => {
const input = '@import-glob "fixtures/css/foo/**/*.css";';
const output = [
'.foo {',
' display: block;',
'}',
'.bar {',
' display: inline-block;',
'}'
].join(' ');
await testPostcss(input, output, t, {
plugin: postcssImportExtGlob({
const input = /* scss */`
@import-glob "fixtures/css/foo/**/*.css";
`;
const output = /* scss */`
.foo {
display: block;
}
.bar {
display: inline-block;
}
`;
await tester.test(input, output, t, {
pluginOptions: {
sort: 'desc'
}),
pluginsAfter: [postcssImport()]
},
pluginsAfter: [postcssImport]
});

@@ -77,16 +64,19 @@ });

test('multiple globs', async t => {
const input = '@import-glob "fixtures/css/foo/**/*.css"; @import-glob "fixtures/css/*.css";';
const output = [
'.bar {',
' display: inline-block;',
'}',
'.foo {',
' display: block;',
'}',
'div {',
' margin: auto;',
'}'
].join(' ');
await testPostcss(input, output, t, {
pluginsAfter: [postcssImport()]
const input = /* scss */`
@import-glob "fixtures/css/foo/**/*.css";
@import-glob "fixtures/css/*.css";
`;
const output = /* scss */`
.bar {
display: inline-block;
}
.foo {
display: block;
}
div {
margin: auto;
}
`;
await tester.test(input, output, t, {
pluginsAfter: [postcssImport]
});

@@ -96,16 +86,18 @@ });

test('multiple globs inline', async t => {
const input = '@import-glob "fixtures/css/foo/**/*.css", "fixtures/css/*.css";';
const output = [
'.bar {',
' display: inline-block;',
'}',
'.foo {',
' display: block;',
'}',
'div {',
' margin: auto;',
'}'
].join(' ');
await testPostcss(input, output, t, {
pluginsAfter: [postcssImport()]
const input = /* scss */`
@import-glob "fixtures/css/foo/**/*.css", "fixtures/css/*.css";
`;
const output = /* scss */`
.bar {
display: inline-block;
}
.foo {
display: block;
}
div {
margin: auto;
}
`;
await tester.test(input, output, t, {
pluginsAfter: [postcssImport]
});

@@ -115,7 +107,24 @@ });

test('error empty param test', async t => {
const input = '@import-glob';
const output = new Error('No string found with rule @import-glob ');
await testPostcss(input, output, t, {
pluginsAfter: [postcssImport()]
const input = /* scss */`
@import-glob;
`;
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]
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc